diff --git a/src/app/audiodevicemodel.cpp b/src/app/audiodevicemodel.cpp index 228d7f63d4a076ccd9030614fb868b9c5dc364ce..f34af01f21b79b0c31851be0c672df7d49901aa4 100644 --- a/src/app/audiodevicemodel.cpp +++ b/src/app/audiodevicemodel.cpp @@ -119,8 +119,16 @@ AudioDeviceModel::reset() int AudioDeviceModel::getCurrentIndex() const { - auto currentId = type_ == Type::Record ? lrcInstance_->avModel().getInputDevice() - : lrcInstance_->avModel().getOutputDevice(); + QString currentId; + if (type_ != Type::Record) { + if (type_ == Type::Ringtone) { + currentId = lrcInstance_->avModel().getRingtoneDevice(); + } else { + currentId = lrcInstance_->avModel().getOutputDevice(); + } + } else { + currentId = lrcInstance_->avModel().getInputDevice(); + } auto resultList = match(index(0, 0), Qt::DisplayRole, QVariant(currentId)); return resultList.size() > 0 ? resultList[0].row() : 0; } diff --git a/src/app/settingsview/components/AudioSettings.qml b/src/app/settingsview/components/AudioSettings.qml index 00f4b0479eda63f7b6220e659100448d9a026095..dc46ab3b34d9a9a20e6b8f77e45e3202018b10ed 100644 --- a/src/app/settingsview/components/AudioSettings.qml +++ b/src/app/settingsview/components/AudioSettings.qml @@ -41,7 +41,7 @@ ColumnLayout { function populateAudioSettings() { inputComboBoxSetting.modelIndex = inputComboBoxSetting.comboModel.getCurrentIndex() outputComboBoxSetting.modelIndex = outputComboBoxSetting.comboModel.getCurrentIndex() - ringtoneComboBoxSetting.modelIndex = outputComboBoxSetting.comboModel.getCurrentIndex() + ringtoneComboBoxSetting.modelIndex = ringtoneComboBoxSetting.comboModel.getCurrentIndex() if(audioManagerComboBoxSetting.comboModel.rowCount() > 0) { audioManagerComboBoxSetting.modelIndex = audioManagerComboBoxSetting.comboModel.getCurrentSettingIndex() @@ -77,9 +77,7 @@ ColumnLayout { onActivated: { AvAdapter.stopAudioMeter() - AVModel.setInputDevice(comboModel.data( - comboModel.index(modelIndex, 0), - AudioDeviceModel.RawDeviceName)) + AVModel.setInputDevice(modelIndex) AvAdapter.startAudioMeter() } } @@ -116,9 +114,7 @@ ColumnLayout { onActivated: { AvAdapter.stopAudioMeter() - AVModel.setOutputDevice(comboModel.data( - comboModel.index(modelIndex, 0), - AudioDeviceModel.RawDeviceName)) + AVModel.setOutputDevice(modelIndex) AvAdapter.startAudioMeter() } } @@ -142,9 +138,7 @@ ColumnLayout { onActivated: { AvAdapter.stopAudioMeter() - AVModel.setRingtoneDevice(comboModel.data( - comboModel.index(modelIndex, 0), - AudioDeviceModel.RawDeviceName)) + AVModel.setRingtoneDevice(modelIndex) AvAdapter.startAudioMeter() } } diff --git a/src/libclient/api/avmodel.h b/src/libclient/api/avmodel.h index f76d1682c0575577433a64301de1a4ed4ab38313..5bcdc5dc4010c71947715df47d898b0d01bc4054 100644 --- a/src/libclient/api/avmodel.h +++ b/src/libclient/api/avmodel.h @@ -170,19 +170,19 @@ public: Q_INVOKABLE bool setAudioManager(const QString& name); /** * Set current ringtone device - * @param name of the new ringtone device + * @param idx of the new ringtone device */ - Q_INVOKABLE void setRingtoneDevice(const QString& name); + Q_INVOKABLE void setRingtoneDevice(int idx); /** * Set current output device - * @param name of the new output device + * @param idx of the new output device */ - Q_INVOKABLE void setOutputDevice(const QString& name); + Q_INVOKABLE void setOutputDevice(int idx); /** * Set current input device - * @param name of the new input device + * @param idx of the new input device */ - Q_INVOKABLE void setInputDevice(const QString& name); + Q_INVOKABLE void setInputDevice(int idx); /** * Stop local record at given path * @param path diff --git a/src/libclient/avmodel.cpp b/src/libclient/avmodel.cpp index 0254eb0ddc1b6d3b31172bdfaf58adf4914ec10f..932e3fbee048bedcd5a64ec5a34fec4912874311 100644 --- a/src/libclient/avmodel.cpp +++ b/src/libclient/avmodel.cpp @@ -427,23 +427,20 @@ AVModel::setAudioManager(const QString& name) } void -AVModel::setRingtoneDevice(const QString& name) +AVModel::setRingtoneDevice(int idx) { - int idx = ConfigurationManager::instance().getAudioOutputDeviceIndex(name); ConfigurationManager::instance().setAudioRingtoneDevice(idx); } void -AVModel::setOutputDevice(const QString& name) +AVModel::setOutputDevice(int idx) { - int idx = ConfigurationManager::instance().getAudioOutputDeviceIndex(name); ConfigurationManager::instance().setAudioOutputDevice(idx); } void -AVModel::setInputDevice(const QString& name) +AVModel::setInputDevice(int idx) { - int idx = ConfigurationManager::instance().getAudioInputDeviceIndex(name); ConfigurationManager::instance().setAudioInputDevice(idx); } @@ -805,24 +802,11 @@ AVModelPimpl::getDevice(int type) const return ""; } auto deviceIdx = currentDevicesIdx[type].toInt(); - for (const auto& dev : devices) { - int idx {-1}; - switch (type) { - case 1: // INPUT - idx = ConfigurationManager::instance().getAudioInputDeviceIndex(dev); - break; - case 0: // OUTPUT - case 2: // RINGTONE - idx = ConfigurationManager::instance().getAudioOutputDeviceIndex(dev); - break; - default: - break; - } - if (idx == deviceIdx) { - return dev; - } + if (deviceIdx > devices.size()) { + // Should not happen, but cannot retrieve current ringtone device + return ""; } - return ""; + result = devices[deviceIdx]; } catch (std::bad_alloc& ba) { qWarning() << "bad_alloc caught: " << ba.what(); return "";