Skip to content
Snippets Groups Projects
Commit caef9579 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee Committed by Stepan Salenikovich
Browse files

audio: Fix the selectionModel for all audio settings

Refs #72500
parent f50300bd
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
***************************************************************************/ ***************************************************************************/
#include "alsapluginmodel.h" #include "alsapluginmodel.h"
//Qt
#include <QtCore/QItemSelectionModel>
//Ring //Ring
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
...@@ -26,12 +29,18 @@ class AlsaPluginModelPrivate : public QObject ...@@ -26,12 +29,18 @@ class AlsaPluginModelPrivate : public QObject
public: public:
AlsaPluginModelPrivate(Audio::AlsaPluginModel* parent); AlsaPluginModelPrivate(Audio::AlsaPluginModel* parent);
QStringList m_lDeviceList; QStringList m_lDeviceList;
mutable QItemSelectionModel* m_pSelectionModel;
private: private:
Audio::AlsaPluginModel* q_ptr; Audio::AlsaPluginModel* q_ptr;
public Q_SLOTS:
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),
m_pSelectionModel(nullptr)
{ {
} }
...@@ -97,6 +106,19 @@ bool Audio::AlsaPluginModel::setData( const QModelIndex& index, const QVariant & ...@@ -97,6 +106,19 @@ bool Audio::AlsaPluginModel::setData( const QModelIndex& index, const QVariant &
return false; return false;
} }
QItemSelectionModel* Audio::AlsaPluginModel::selectionModel() const
{
if (!d_ptr->m_pSelectionModel) {
d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<Audio::AlsaPluginModel*>(this));
d_ptr->m_pSelectionModel->setCurrentIndex(currentPlugin(), QItemSelectionModel::ClearAndSelect);
connect(d_ptr->m_pSelectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), d_ptr.data(), SLOT(setCurrentPlugin(QModelIndex)));
}
return d_ptr->m_pSelectionModel;
}
///Return the current index ///Return the current index
QModelIndex Audio::AlsaPluginModel::currentPlugin() const QModelIndex Audio::AlsaPluginModel::currentPlugin() const
{ {
...@@ -110,18 +132,19 @@ QModelIndex Audio::AlsaPluginModel::currentPlugin() const ...@@ -110,18 +132,19 @@ QModelIndex Audio::AlsaPluginModel::currentPlugin() const
} }
///Set the current index ///Set the current index
void Audio::AlsaPluginModel::setCurrentPlugin(const QModelIndex& idx) void AlsaPluginModelPrivate::setCurrentPlugin(const QModelIndex& idx)
{ {
if (!idx.isValid()) if (!idx.isValid())
return; return;
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
configurationManager.setAudioPlugin(d_ptr->m_lDeviceList[idx.row()]); configurationManager.setAudioPlugin(m_lDeviceList[idx.row()]);
} }
///Set the current index (qcombobox compatibility shim) ///Set the current index (qcombobox compatibility shim)
void Audio::AlsaPluginModel::setCurrentPlugin(int idx) void AlsaPluginModelPrivate::setCurrentPlugin(int idx)
{ {
setCurrentPlugin(index(idx,0)); setCurrentPlugin(q_ptr->index(idx,0));
} }
///Reload to current daemon state ///Reload to current daemon state
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <typedefs.h> #include <typedefs.h>
class AlsaPluginModelPrivate; class AlsaPluginModelPrivate;
class QItemSelectionModel;
namespace Audio { namespace Audio {
...@@ -45,10 +46,7 @@ public: ...@@ -45,10 +46,7 @@ public:
//Getters //Getters
QModelIndex currentPlugin() const; QModelIndex currentPlugin() const;
QItemSelectionModel* selectionModel() const;
//Setters
void setCurrentPlugin(const QModelIndex& idx);
void setCurrentPlugin(int idx);
//Mutator //Mutator
void reload(); void reload();
......
...@@ -34,6 +34,10 @@ public: ...@@ -34,6 +34,10 @@ public:
private: private:
Audio::InputDeviceModel* q_ptr; Audio::InputDeviceModel* q_ptr;
public Q_SLOTS:
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),
...@@ -113,12 +117,15 @@ QItemSelectionModel* Audio::InputDeviceModel::selectionModel() const ...@@ -113,12 +117,15 @@ QItemSelectionModel* Audio::InputDeviceModel::selectionModel() const
const int idx = currentDevices[static_cast<int>(Settings::DeviceIndex::INPUT)].toInt(); const int idx = currentDevices[static_cast<int>(Settings::DeviceIndex::INPUT)].toInt();
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)));
} }
return d_ptr->m_pSelectionModel; return d_ptr->m_pSelectionModel;
} }
///Set the current input device ///Set the current input device
void Audio::InputDeviceModel::setCurrentDevice(const QModelIndex& index) void InputDeviceModelPrivate::setCurrentDevice(const QModelIndex& index)
{ {
if (index.isValid()) { if (index.isValid()) {
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
...@@ -127,9 +134,9 @@ void Audio::InputDeviceModel::setCurrentDevice(const QModelIndex& index) ...@@ -127,9 +134,9 @@ void Audio::InputDeviceModel::setCurrentDevice(const QModelIndex& index)
} }
///QCombobox signals -> QModelIndex shim ///QCombobox signals -> QModelIndex shim
void Audio::InputDeviceModel::setCurrentDevice(int idx) void InputDeviceModelPrivate::setCurrentDevice(int idx)
{ {
setCurrentDevice(index(idx,0)); setCurrentDevice(q_ptr->index(idx,0));
} }
///Reload input device list ///Reload input device list
......
...@@ -47,10 +47,6 @@ public: ...@@ -47,10 +47,6 @@ public:
//Getters //Getters
QItemSelectionModel* selectionModel() const; QItemSelectionModel* selectionModel() const;
//Setters
void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
//Mutator //Mutator
void reload(); void reload();
......
...@@ -35,6 +35,10 @@ public: ...@@ -35,6 +35,10 @@ public:
private: private:
Audio::OutputDeviceModel* q_ptr; Audio::OutputDeviceModel* q_ptr;
public Q_SLOTS:
void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
}; };
...@@ -112,14 +116,18 @@ QItemSelectionModel* Audio::OutputDeviceModel::selectionModel() const ...@@ -112,14 +116,18 @@ QItemSelectionModel* Audio::OutputDeviceModel::selectionModel() const
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
const QStringList currentDevices = configurationManager.getCurrentAudioDevicesIndex(); const QStringList currentDevices = configurationManager.getCurrentAudioDevicesIndex();
const int idx = currentDevices[static_cast<int>(Audio::Settings::DeviceIndex::OUTPUT)].toInt(); const int idx = currentDevices[static_cast<int>(Audio::Settings::DeviceIndex::OUTPUT)].toInt();
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)));
} }
return d_ptr->m_pSelectionModel; return d_ptr->m_pSelectionModel;
} }
///Set the current output device ///Set the current output device
void Audio::OutputDeviceModel::setCurrentDevice(const QModelIndex& index) void OutputDeviceModelPrivate::setCurrentDevice(const QModelIndex& index)
{ {
if (index.isValid()) { if (index.isValid()) {
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
...@@ -128,9 +136,9 @@ void Audio::OutputDeviceModel::setCurrentDevice(const QModelIndex& index) ...@@ -128,9 +136,9 @@ void Audio::OutputDeviceModel::setCurrentDevice(const QModelIndex& index)
} }
///QCombobox index -> QModelIndex shim ///QCombobox index -> QModelIndex shim
void Audio::OutputDeviceModel::setCurrentDevice(int idx) void OutputDeviceModelPrivate::setCurrentDevice(int idx)
{ {
setCurrentDevice(index(idx,0)); setCurrentDevice(q_ptr->index(idx,0));
} }
///reload output devices list ///reload output devices list
......
...@@ -47,10 +47,6 @@ public: ...@@ -47,10 +47,6 @@ public:
//Getters //Getters
QItemSelectionModel* selectionModel() const; QItemSelectionModel* selectionModel() const;
//Setters
void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
//Mutator //Mutator
void reload(); void reload();
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
***************************************************************************/ ***************************************************************************/
#include "ringtonedevicemodel.h" #include "ringtonedevicemodel.h"
//Qt
#include <QtCore/QItemSelectionModel>
//Ring //Ring
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
#include "settings.h" #include "settings.h"
...@@ -27,12 +30,18 @@ class RingtoneDeviceModelPrivate : public QObject ...@@ -27,12 +30,18 @@ class RingtoneDeviceModelPrivate : public QObject
public: public:
RingtoneDeviceModelPrivate(Audio::RingtoneDeviceModel* parent); RingtoneDeviceModelPrivate(Audio::RingtoneDeviceModel* parent);
QStringList m_lDeviceList; QStringList m_lDeviceList;
mutable QItemSelectionModel* m_pSelectionModel;
private: private:
Audio::RingtoneDeviceModel* q_ptr; Audio::RingtoneDeviceModel* q_ptr;
public Q_SLOTS:
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),
m_pSelectionModel(nullptr)
{ {
} }
...@@ -98,6 +107,23 @@ bool Audio::RingtoneDeviceModel::setData( const QModelIndex& index, const QVaria ...@@ -98,6 +107,23 @@ bool Audio::RingtoneDeviceModel::setData( const QModelIndex& index, const QVaria
return false; return false;
} }
QItemSelectionModel* Audio::RingtoneDeviceModel::selectionModel() const
{
if (!d_ptr->m_pSelectionModel) {
d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<Audio::RingtoneDeviceModel*>(this));
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
const QStringList currentDevices = configurationManager.getCurrentAudioDevicesIndex();
const int idx = currentDevices[static_cast<int>(Settings::DeviceIndex::RINGTONE)].toInt();
if (!(idx >= d_ptr->m_lDeviceList.size()))
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)));
}
return d_ptr->m_pSelectionModel;
}
///Return the current ringtone device ///Return the current ringtone device
QModelIndex Audio::RingtoneDeviceModel::currentDevice() const QModelIndex Audio::RingtoneDeviceModel::currentDevice() const
{ {
...@@ -110,7 +136,7 @@ QModelIndex Audio::RingtoneDeviceModel::currentDevice() const ...@@ -110,7 +136,7 @@ QModelIndex Audio::RingtoneDeviceModel::currentDevice() const
} }
///Set the current ringtone device ///Set the current ringtone device
void Audio::RingtoneDeviceModel::setCurrentDevice(const QModelIndex& index) void RingtoneDeviceModelPrivate::setCurrentDevice(const QModelIndex& index)
{ {
if (index.isValid()) { if (index.isValid()) {
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance(); ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
...@@ -119,9 +145,9 @@ void Audio::RingtoneDeviceModel::setCurrentDevice(const QModelIndex& index) ...@@ -119,9 +145,9 @@ void Audio::RingtoneDeviceModel::setCurrentDevice(const QModelIndex& index)
} }
///QCombobox -> QModelIndex shim ///QCombobox -> QModelIndex shim
void Audio::RingtoneDeviceModel::setCurrentDevice(int idx) void RingtoneDeviceModelPrivate::setCurrentDevice(int idx)
{ {
setCurrentDevice(index(idx,0)); setCurrentDevice(q_ptr->index(idx,0));
} }
///Reload ringtone device list ///Reload ringtone device list
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <typedefs.h> #include <typedefs.h>
class RingtoneDeviceModelPrivate; class RingtoneDeviceModelPrivate;
class QItemSelectionModel;
namespace Audio { namespace Audio {
...@@ -45,10 +46,7 @@ public: ...@@ -45,10 +46,7 @@ public:
//Getters //Getters
QModelIndex currentDevice() const; QModelIndex currentDevice() const;
QItemSelectionModel* selectionModel() const;
//Setters
void setCurrentDevice(const QModelIndex& index);
void setCurrentDevice(int idx);
//Mutator //Mutator
void reload(); void reload();
......
...@@ -139,11 +139,10 @@ bool Audio::Settings::isRoomToneEnabled() ...@@ -139,11 +139,10 @@ bool Audio::Settings::isRoomToneEnabled()
///Reload everything ///Reload everything
void Audio::Settings::reload() void Audio::Settings::reload()
{ {
d_ptr->m_pAlsaPluginModel->reload(); alsaPluginModel ()->reload();
d_ptr->m_pInputDeviceModel->reload(); inputDeviceModel ()->reload();
d_ptr->m_pOutputDeviceModel->reload(); outputDeviceModel ()->reload();
// m_pAudioManagerModel->reload(); ringtoneDeviceModel()->reload();
d_ptr->m_pRingtoneDeviceModel->reload();
} }
///Play room tone ///Play room tone
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment