From 5995d9b5d196f7e8a6588badfe9586b208a54351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Wed, 24 Aug 2022 14:04:36 -0400 Subject: [PATCH] avmodel: use ringtone index and cleanup Change-Id: If1f76e4c33bfb067769b6d2d81871e156d256aaf --- src/app/audiodevicemodel.cpp | 12 ++++++-- .../settingsview/components/AudioSettings.qml | 14 +++------ src/libclient/api/avmodel.h | 12 ++++---- src/libclient/avmodel.cpp | 30 +++++-------------- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/app/audiodevicemodel.cpp b/src/app/audiodevicemodel.cpp index 228d7f63d..f34af01f2 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 00f4b0479..dc46ab3b3 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 f76d1682c..5bcdc5dc4 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 0254eb0dd..932e3fbee 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 ""; -- GitLab