mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactoring audio device initialization in av setting to prevent opening devices twice
This commit is contained in:
parent
7d11e9192c
commit
290f6d4697
|
@ -138,11 +138,13 @@ void AVForm::hideEvent(QHideEvent *)
|
||||||
void AVForm::getAudioInDevices()
|
void AVForm::getAudioInDevices()
|
||||||
{
|
{
|
||||||
QString settingsInDev = Settings::getInstance().getInDev();
|
QString settingsInDev = Settings::getInstance().getInDev();
|
||||||
bool inDevFound = false;
|
int inDevIndex = 0;
|
||||||
bodyUI->inDevCombobox->clear();
|
bodyUI->inDevCombobox->clear();
|
||||||
const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||||
if (pDeviceList)
|
if (pDeviceList)
|
||||||
{
|
{
|
||||||
|
//prevent currentIndexChanged to be fired while adding items
|
||||||
|
bodyUI->inDevCombobox->blockSignals(true);
|
||||||
while (*pDeviceList)
|
while (*pDeviceList)
|
||||||
{
|
{
|
||||||
int len = strlen(pDeviceList);
|
int len = strlen(pDeviceList);
|
||||||
|
@ -154,21 +156,21 @@ void AVForm::getAudioInDevices()
|
||||||
bodyUI->inDevCombobox->addItem(inDev);
|
bodyUI->inDevCombobox->addItem(inDev);
|
||||||
if (settingsInDev == inDev)
|
if (settingsInDev == inDev)
|
||||||
{
|
{
|
||||||
bodyUI->inDevCombobox->setCurrentIndex(bodyUI->inDevCombobox->count()-1);
|
inDevIndex = bodyUI->inDevCombobox->count()-1;
|
||||||
inDevFound = true;
|
|
||||||
}
|
}
|
||||||
pDeviceList += len+1;
|
pDeviceList += len+1;
|
||||||
}
|
}
|
||||||
|
//addItem changes currentIndex -> reset
|
||||||
|
bodyUI->inDevCombobox->setCurrentIndex(-1);
|
||||||
|
bodyUI->inDevCombobox->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
bodyUI->inDevCombobox->setCurrentIndex(inDevIndex);
|
||||||
if (!inDevFound)
|
|
||||||
Settings::getInstance().setInDev(bodyUI->inDevCombobox->itemText(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVForm::getAudioOutDevices()
|
void AVForm::getAudioOutDevices()
|
||||||
{
|
{
|
||||||
QString settingsOutDev = Settings::getInstance().getOutDev();
|
QString settingsOutDev = Settings::getInstance().getOutDev();
|
||||||
bool outDevFound = false;
|
int outDevIndex = 0;
|
||||||
bodyUI->outDevCombobox->clear();
|
bodyUI->outDevCombobox->clear();
|
||||||
const ALchar *pDeviceList;
|
const ALchar *pDeviceList;
|
||||||
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
|
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
|
||||||
|
@ -177,6 +179,8 @@ void AVForm::getAudioOutDevices()
|
||||||
pDeviceList = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
|
pDeviceList = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
|
||||||
if (pDeviceList)
|
if (pDeviceList)
|
||||||
{
|
{
|
||||||
|
//prevent currentIndexChanged to be fired while adding items
|
||||||
|
bodyUI->outDevCombobox->blockSignals(true);
|
||||||
while (*pDeviceList)
|
while (*pDeviceList)
|
||||||
{
|
{
|
||||||
int len = strlen(pDeviceList);
|
int len = strlen(pDeviceList);
|
||||||
|
@ -188,15 +192,15 @@ void AVForm::getAudioOutDevices()
|
||||||
bodyUI->outDevCombobox->addItem(outDev);
|
bodyUI->outDevCombobox->addItem(outDev);
|
||||||
if (settingsOutDev == outDev)
|
if (settingsOutDev == outDev)
|
||||||
{
|
{
|
||||||
bodyUI->outDevCombobox->setCurrentIndex(bodyUI->outDevCombobox->count()-1);
|
outDevIndex = bodyUI->outDevCombobox->count()-1;
|
||||||
outDevFound = true;
|
|
||||||
}
|
}
|
||||||
pDeviceList += len+1;
|
pDeviceList += len+1;
|
||||||
}
|
}
|
||||||
|
//addItem changes currentIndex -> reset
|
||||||
|
bodyUI->outDevCombobox->setCurrentIndex(-1);
|
||||||
|
bodyUI->outDevCombobox->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
bodyUI->outDevCombobox->setCurrentIndex(outDevIndex);
|
||||||
if (!outDevFound)
|
|
||||||
Settings::getInstance().setOutDev(bodyUI->outDevCombobox->itemText(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVForm::onInDevChanged(const QString &deviceDescriptor)
|
void AVForm::onInDevChanged(const QString &deviceDescriptor)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user