Skip to content
Snippets Groups Projects
Commit 4e2280a2 authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by Stepan Salenikovich
Browse files

audio: Fix invalid QModelIndex for current devices

If ->reload() is called on one of the model, the selection will
be lost. This cause the wrong device to be selected in the
clients ComboBox.

Tuleap: #216
Change-Id: Ifa0821e6b40f279d1908d012f1c0fd510eaa0703
parent 9a2e77f6
Branches
Tags
No related merge requests found
...@@ -36,7 +36,6 @@ private: ...@@ -36,7 +36,6 @@ private:
public Q_SLOTS: public Q_SLOTS:
void setCurrentPlugin(const QModelIndex& idx); void setCurrentPlugin(const QModelIndex& idx);
void setCurrentPlugin(int idx);
}; };
AlsaPluginModelPrivate::AlsaPluginModelPrivate(Audio::AlsaPluginModel* parent) : q_ptr(parent), AlsaPluginModelPrivate::AlsaPluginModelPrivate(Audio::AlsaPluginModel* parent) : q_ptr(parent),
...@@ -113,7 +112,7 @@ QItemSelectionModel* Audio::AlsaPluginModel::selectionModel() const ...@@ -113,7 +112,7 @@ QItemSelectionModel* Audio::AlsaPluginModel::selectionModel() const
d_ptr->m_pSelectionModel->setCurrentIndex(currentPlugin(), QItemSelectionModel::ClearAndSelect); d_ptr->m_pSelectionModel->setCurrentIndex(currentPlugin(), QItemSelectionModel::ClearAndSelect);
connect(d_ptr->m_pSelectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), d_ptr.data(), SLOT(setCurrentPlugin(QModelIndex))); connect(d_ptr->m_pSelectionModel, &QItemSelectionModel::currentChanged, d_ptr.data(), &AlsaPluginModelPrivate::setCurrentPlugin);
} }
return d_ptr->m_pSelectionModel; return d_ptr->m_pSelectionModel;
...@@ -141,21 +140,21 @@ void AlsaPluginModelPrivate::setCurrentPlugin(const QModelIndex& idx) ...@@ -141,21 +140,21 @@ void AlsaPluginModelPrivate::setCurrentPlugin(const QModelIndex& idx)
configurationManager.setAudioPlugin(m_lDeviceList[idx.row()]); configurationManager.setAudioPlugin(m_lDeviceList[idx.row()]);
} }
///Set the current index (qcombobox compatibility shim)
void AlsaPluginModelPrivate::setCurrentPlugin(int idx)
{
setCurrentPlugin(q_ptr->index(idx,0));
}
///Reload to current daemon state ///Reload to current daemon state
void Audio::AlsaPluginModel::reload() void Audio::AlsaPluginModel::reload()
{ {
const int currentRow = selectionModel()->currentIndex().row();
ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
beginResetModel(); beginResetModel();
d_ptr->m_lDeviceList = configurationManager.getAudioPluginList(); d_ptr->m_lDeviceList = configurationManager.getAudioPluginList();
endResetModel(); endResetModel();
emit layoutChanged(); emit layoutChanged();
emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0)); emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0));
// Restore the selection
d_ptr->m_pSelectionModel->setCurrentIndex(index(currentRow,0), QItemSelectionModel::ClearAndSelect);
} }
#include <alsapluginmodel.moc> #include <alsapluginmodel.moc>
...@@ -37,7 +37,6 @@ private: ...@@ -37,7 +37,6 @@ private:
public Q_SLOTS: public Q_SLOTS:
void setCurrentDevice(const QModelIndex& index); void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
}; };
InputDeviceModelPrivate::InputDeviceModelPrivate(Audio::InputDeviceModel* parent) : q_ptr(parent), InputDeviceModelPrivate::InputDeviceModelPrivate(Audio::InputDeviceModel* parent) : q_ptr(parent),
...@@ -118,7 +117,7 @@ QItemSelectionModel* Audio::InputDeviceModel::selectionModel() const ...@@ -118,7 +117,7 @@ QItemSelectionModel* Audio::InputDeviceModel::selectionModel() const
if (!(idx >= d_ptr->m_lDeviceList.size())) if (!(idx >= d_ptr->m_lDeviceList.size()))
d_ptr->m_pSelectionModel->setCurrentIndex(index(idx,0), QItemSelectionModel::ClearAndSelect); d_ptr->m_pSelectionModel->setCurrentIndex(index(idx,0), QItemSelectionModel::ClearAndSelect);
connect(d_ptr->m_pSelectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), d_ptr.data(), SLOT(setCurrentDevice(QModelIndex))); connect(d_ptr->m_pSelectionModel, &QItemSelectionModel::currentChanged, d_ptr.data(), &InputDeviceModelPrivate::setCurrentDevice);
} }
return d_ptr->m_pSelectionModel; return d_ptr->m_pSelectionModel;
...@@ -133,21 +132,19 @@ void InputDeviceModelPrivate::setCurrentDevice(const QModelIndex& index) ...@@ -133,21 +132,19 @@ void InputDeviceModelPrivate::setCurrentDevice(const QModelIndex& index)
} }
} }
///QCombobox signals -> QModelIndex shim
void InputDeviceModelPrivate::setCurrentDevice(int idx)
{
setCurrentDevice(q_ptr->index(idx,0));
}
///Reload input device list ///Reload input device list
void Audio::InputDeviceModel::reload() void Audio::InputDeviceModel::reload()
{ {
const int currentRow = selectionModel()->currentIndex().row();
ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
beginResetModel(); beginResetModel();
d_ptr->m_lDeviceList = configurationManager.getAudioInputDeviceList (); d_ptr->m_lDeviceList = configurationManager.getAudioInputDeviceList ();
endResetModel(); endResetModel();
emit layoutChanged(); emit layoutChanged();
emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0)); emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0));
// Restore the selection
d_ptr->m_pSelectionModel->setCurrentIndex(index(currentRow,0), QItemSelectionModel::ClearAndSelect);
} }
#include <inputdevicemodel.moc> #include <inputdevicemodel.moc>
...@@ -38,7 +38,6 @@ private: ...@@ -38,7 +38,6 @@ private:
public Q_SLOTS: public Q_SLOTS:
void setCurrentDevice(const QModelIndex& index); void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
}; };
...@@ -135,21 +134,21 @@ void OutputDeviceModelPrivate::setCurrentDevice(const QModelIndex& index) ...@@ -135,21 +134,21 @@ void OutputDeviceModelPrivate::setCurrentDevice(const QModelIndex& index)
} }
} }
///QCombobox index -> QModelIndex shim
void OutputDeviceModelPrivate::setCurrentDevice(int idx)
{
setCurrentDevice(q_ptr->index(idx,0));
}
///reload output devices list ///reload output devices list
void Audio::OutputDeviceModel::reload() void Audio::OutputDeviceModel::reload()
{ {
const int currentRow = selectionModel()->currentIndex().row();
ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
beginResetModel(); beginResetModel();
d_ptr->m_lDeviceList = configurationManager.getAudioOutputDeviceList(); d_ptr->m_lDeviceList = configurationManager.getAudioOutputDeviceList();
endResetModel(); endResetModel();
emit layoutChanged(); emit layoutChanged();
emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0)); emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0));
// Restore the selection
d_ptr->m_pSelectionModel->setCurrentIndex(index(currentRow,0), QItemSelectionModel::ClearAndSelect);
} }
void Audio::OutputDeviceModel::playDTMF(const QString& str) void Audio::OutputDeviceModel::playDTMF(const QString& str)
......
...@@ -37,7 +37,6 @@ private: ...@@ -37,7 +37,6 @@ private:
public Q_SLOTS: public Q_SLOTS:
void setCurrentDevice(const QModelIndex& index); void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
}; };
RingtoneDeviceModelPrivate::RingtoneDeviceModelPrivate(Audio::RingtoneDeviceModel* parent) : q_ptr(parent), RingtoneDeviceModelPrivate::RingtoneDeviceModelPrivate(Audio::RingtoneDeviceModel* parent) : q_ptr(parent),
...@@ -144,21 +143,21 @@ void RingtoneDeviceModelPrivate::setCurrentDevice(const QModelIndex& index) ...@@ -144,21 +143,21 @@ void RingtoneDeviceModelPrivate::setCurrentDevice(const QModelIndex& index)
} }
} }
///QCombobox -> QModelIndex shim
void RingtoneDeviceModelPrivate::setCurrentDevice(int idx)
{
setCurrentDevice(q_ptr->index(idx,0));
}
///Reload ringtone device list ///Reload ringtone device list
void Audio::RingtoneDeviceModel::reload() void Audio::RingtoneDeviceModel::reload()
{ {
const int currentRow = selectionModel()->currentIndex().row();
ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
beginResetModel(); beginResetModel();
d_ptr->m_lDeviceList = configurationManager.getAudioOutputDeviceList(); d_ptr->m_lDeviceList = configurationManager.getAudioOutputDeviceList();
endResetModel(); endResetModel();
emit layoutChanged(); emit layoutChanged();
emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0)); emit dataChanged(index(0,0),index(d_ptr->m_lDeviceList.size()-1,0));
// Restore the selection
d_ptr->m_pSelectionModel->setCurrentIndex(index(currentRow,0), QItemSelectionModel::ClearAndSelect);
} }
#include <ringtonedevicemodel.moc> #include <ringtonedevicemodel.moc>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment