Skip to content
Snippets Groups Projects
Unverified Commit 5995d9b5 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

avmodel: use ringtone index and cleanup

Change-Id: If1f76e4c33bfb067769b6d2d81871e156d256aaf
parent a2cba16f
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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()
}
}
......
......@@ -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
......
......@@ -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 "";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment