Changeset View
Changeset View
Standalone View
Standalone View
src/modulemanager.cpp
Show All 17 Lines | 1 | /* | |||
---|---|---|---|---|---|
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | 21 | | |||
22 | #include "modulemanager.h" | 22 | #include "modulemanager.h" | ||
23 | #include "module.h" | 23 | #include "module.h" | ||
24 | #include "../config.h" | 24 | #include "../config.h" | ||
25 | 25 | | |||
26 | #if HAVE_GCONF | 26 | #if USE_GSETTINGS | ||
27 | #include "gsettingsitem.h" | ||||
28 | | ||||
29 | #define PA_SETTINGS_PATH_MODULES "/org/freedesktop/pulseaudio/module-groups" | ||||
30 | #endif | ||||
31 | | ||||
32 | #if USE_GCONF | ||||
27 | #include "gconfitem.h" | 33 | #include "gconfitem.h" | ||
28 | #define PA_GCONF_ROOT "/system/pulseaudio" | 34 | #define PA_SETTINGS_PATH_MODULES "/system/pulseaudio/modules" | ||
29 | #define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules" | | |||
30 | #endif | 35 | #endif | ||
31 | 36 | | |||
32 | #include <QTimer> | 37 | #include <QTimer> | ||
33 | 38 | | |||
34 | namespace QPulseAudio | 39 | namespace QPulseAudio | ||
35 | { | 40 | { | ||
36 | 41 | | |||
37 | #if HAVE_GCONF | 42 | #if USE_GCONF || USE_GSETTINGS | ||
38 | class GConfModule : public GConfItem | 43 | | ||
44 | #if USE_GSETTINGS | ||||
45 | class ConfigModule : public GSettingsItem | ||||
46 | #elif USE_GCONF | ||||
47 | class ConfigModule : public GConfItem | ||||
48 | #endif | ||||
39 | { | 49 | { | ||
40 | public: | 50 | public: | ||
41 | GConfModule(const QString &configName, const QString &moduleName, QObject *parent); | 51 | ConfigModule(const QString &configName, const QString &moduleName, QObject *parent); | ||
42 | bool isEnabled() const; | 52 | bool isEnabled() const; | ||
43 | void setEnabled(bool enabled, const QVariant &args=QVariant()); | 53 | void setEnabled(bool enabled, const QVariant &args=QVariant()); | ||
44 | private: | 54 | private: | ||
45 | QString m_moduleName; | 55 | QString m_moduleName; | ||
46 | }; | 56 | }; | ||
47 | 57 | | |||
48 | GConfModule::GConfModule(const QString &configName, const QString &moduleName, QObject *parent) : | 58 | ConfigModule::ConfigModule(const QString &configName, const QString &moduleName, QObject *parent) : | ||
49 | GConfItem(QStringLiteral(PA_GCONF_PATH_MODULES"/") + configName, parent), | 59 | #if USE_GSETTINGS | ||
60 | GSettingsItem(QStringLiteral(PA_SETTINGS_PATH_MODULES"/") + configName + QStringLiteral("/"), parent), | ||||
61 | #elif USE_GCONF | ||||
62 | GConfItem(QStringLiteral(PA_SETTINGS_PATH_MODULES"/") + configName, parent), | ||||
63 | #endif | ||||
50 | m_moduleName(moduleName) | 64 | m_moduleName(moduleName) | ||
51 | { | 65 | { | ||
52 | } | 66 | } | ||
53 | 67 | | |||
54 | bool GConfModule::isEnabled() const | 68 | bool ConfigModule::isEnabled() const | ||
55 | { | 69 | { | ||
56 | return value(QStringLiteral("enabled")).toBool(); | 70 | return value(QStringLiteral("enabled")).toBool(); | ||
57 | } | 71 | } | ||
58 | 72 | | |||
59 | void GConfModule::setEnabled(bool enabled, const QVariant &args) | 73 | void ConfigModule::setEnabled(bool enabled, const QVariant &args) | ||
60 | { | 74 | { | ||
61 | set(QStringLiteral("locked"), true); | 75 | set(QStringLiteral("locked"), true); | ||
62 | 76 | | |||
63 | if (enabled) { | 77 | if (enabled) { | ||
64 | set(QStringLiteral("name0"), m_moduleName); | 78 | set(QStringLiteral("name0"), m_moduleName); | ||
65 | set(QStringLiteral("args0"), args); | 79 | set(QStringLiteral("args0"), args); | ||
66 | set(QStringLiteral("enabled"), true); | 80 | set(QStringLiteral("enabled"), true); | ||
67 | } else { | 81 | } else { | ||
68 | set(QStringLiteral("enabled"), false); | 82 | set(QStringLiteral("enabled"), false); | ||
69 | } | 83 | } | ||
70 | set(QStringLiteral("locked"), false); | 84 | set(QStringLiteral("locked"), false); | ||
71 | } | 85 | } | ||
72 | #endif | | |||
73 | 86 | | |||
87 | #endif | ||||
74 | 88 | | |||
75 | ModuleManager::ModuleManager(QObject *parent) : | 89 | ModuleManager::ModuleManager(QObject *parent) : | ||
76 | QObject(parent) | 90 | QObject(parent) | ||
77 | { | 91 | { | ||
78 | #if HAVE_GCONF | 92 | #if USE_GCONF || USE_GSETTINGS | ||
drosca: newline | |||||
79 | m_combineSinks = new GConfModule(QStringLiteral("combine"), QStringLiteral("module-combine"), this); | 93 | m_combineSinks = new ConfigModule(QStringLiteral("combine"), QStringLiteral("module-combine"), this); | ||
80 | m_switchOnConnect = new GConfModule(QStringLiteral("switch-on-connect"), QStringLiteral("module-switch-on-connect"), this); | 94 | m_switchOnConnect = new ConfigModule(QStringLiteral("switch-on-connect"), QStringLiteral("module-switch-on-connect"), this); | ||
81 | m_deviceManager = new GConfModule(QStringLiteral("device-manager"), QStringLiteral("module-device-manager"), this); | 95 | m_deviceManager = new ConfigModule(QStringLiteral("device-manager"), QStringLiteral("module-device-manager"), this); | ||
82 | 96 | | |||
83 | connect(m_combineSinks, &GConfItem::subtreeChanged, this, &ModuleManager::combineSinksChanged); | 97 | connect(m_combineSinks, &ConfigModule::subtreeChanged, this, &ModuleManager::combineSinksChanged); | ||
84 | connect(m_switchOnConnect, &GConfItem::subtreeChanged, this, &ModuleManager::switchOnConnectChanged); | 98 | connect(m_switchOnConnect, &ConfigModule::subtreeChanged, this, &ModuleManager::switchOnConnectChanged); | ||
85 | connect(m_deviceManager, &GConfItem::subtreeChanged, this, &ModuleManager::switchOnConnectChanged); | 99 | connect(m_deviceManager, &ConfigModule::subtreeChanged, this, &ModuleManager::switchOnConnectChanged); | ||
86 | #endif | 100 | #endif | ||
87 | 101 | | |||
88 | QTimer *updateModulesTimer = new QTimer(this); | 102 | QTimer *updateModulesTimer = new QTimer(this); | ||
89 | updateModulesTimer->setInterval(500); | 103 | updateModulesTimer->setInterval(500); | ||
90 | updateModulesTimer->setSingleShot(true); | 104 | updateModulesTimer->setSingleShot(true); | ||
91 | connect(updateModulesTimer, &QTimer::timeout, this, &ModuleManager::updateLoadedModules); | 105 | connect(updateModulesTimer, &QTimer::timeout, this, &ModuleManager::updateLoadedModules); | ||
92 | connect(&Context::instance()->modules(), &MapBaseQObject::added, updateModulesTimer, static_cast<void(QTimer::*)(void)>(&QTimer::start)); | 106 | connect(&Context::instance()->modules(), &MapBaseQObject::added, updateModulesTimer, static_cast<void(QTimer::*)(void)>(&QTimer::start)); | ||
93 | connect(&Context::instance()->modules(), &MapBaseQObject::removed, updateModulesTimer, static_cast<void(QTimer::*)(void)>(&QTimer::start)); | 107 | connect(&Context::instance()->modules(), &MapBaseQObject::removed, updateModulesTimer, static_cast<void(QTimer::*)(void)>(&QTimer::start)); | ||
94 | updateLoadedModules(); | 108 | updateLoadedModules(); | ||
95 | } | 109 | } | ||
96 | 110 | | |||
97 | ModuleManager::~ModuleManager() | 111 | ModuleManager::~ModuleManager() | ||
98 | { | 112 | { | ||
99 | }; | 113 | }; | ||
100 | 114 | | |||
101 | bool ModuleManager::settingsSupported() const | 115 | bool ModuleManager::settingsSupported() const | ||
102 | { | 116 | { | ||
103 | #if HAVE_GCONF | 117 | #if USE_GCONF || USE_GSETTINGS | ||
104 | return true; | 118 | return true; | ||
105 | #else | 119 | #else | ||
106 | return false; | 120 | return false; | ||
107 | #endif | 121 | #endif | ||
108 | } | 122 | } | ||
109 | 123 | | |||
110 | bool ModuleManager::combineSinks() const | 124 | bool ModuleManager::combineSinks() const | ||
111 | { | 125 | { | ||
112 | #if HAVE_GCONF | 126 | #if USE_GCONF || USE_GSETTINGS | ||
113 | return m_combineSinks->isEnabled(); | 127 | return m_combineSinks->isEnabled(); | ||
114 | #else | 128 | #else | ||
115 | return false; | 129 | return false; | ||
116 | #endif | 130 | #endif | ||
117 | } | 131 | } | ||
118 | 132 | | |||
119 | void ModuleManager::setCombineSinks(bool combineSinks) | 133 | void ModuleManager::setCombineSinks(bool combineSinks) | ||
120 | { | 134 | { | ||
121 | #if HAVE_GCONF | 135 | #if USE_GCONF || USE_GSETTINGS | ||
122 | m_combineSinks->setEnabled(combineSinks); | 136 | m_combineSinks->setEnabled(combineSinks); | ||
123 | #else | 137 | #else | ||
124 | Q_UNUSED(combineSinks) | 138 | Q_UNUSED(combineSinks() | ||
125 | #endif | 139 | #endif | ||
126 | } | 140 | } | ||
127 | 141 | | |||
128 | bool ModuleManager::switchOnConnect() const | 142 | bool ModuleManager::switchOnConnect() const | ||
129 | { | 143 | { | ||
144 | #if USE_GCONF || USE_GSETTINGS | ||||
130 | //switch on connect and device-manager do the same task. Only one should be enabled | 145 | //switch on connect and device-manager do the same task. Only one should be enabled | ||
131 | 146 | | |||
132 | //Note on the first run m_deviceManager will appear to be disabled even though it's actually running | 147 | //Note on the first run m_deviceManager will appear to be disabled even though it's actually running | ||
133 | //because there is no gconf entry, however m_switchOnConnect will only exist if set by Plasma PA | 148 | //because there is no gconf entry, however m_switchOnConnect will only exist if set by Plasma PA | ||
134 | //hence only check this entry | 149 | //hence only check this entry | ||
135 | #if HAVE_GCONF | | |||
136 | return m_switchOnConnect->isEnabled() ; | 150 | return m_switchOnConnect->isEnabled() ; | ||
137 | #else | 151 | #else | ||
138 | return false; | 152 | return false; | ||
139 | #endif | 153 | #endif | ||
140 | } | 154 | } | ||
141 | 155 | | |||
142 | void ModuleManager::setSwitchOnConnect(bool switchOnConnect) | 156 | void ModuleManager::setSwitchOnConnect(bool switchOnConnect) | ||
143 | { | 157 | { | ||
144 | #if HAVE_GCONF | 158 | #if USE_GCONF || USE_GSETTINGS | ||
145 | m_deviceManager->setEnabled(!switchOnConnect); | 159 | m_deviceManager->setEnabled(!switchOnConnect); | ||
146 | m_switchOnConnect->setEnabled(switchOnConnect); | 160 | m_switchOnConnect->setEnabled(switchOnConnect); | ||
147 | #else | 161 | #else | ||
148 | Q_UNUSED(switchOnConnect) | 162 | Q_UNUSED(switchOnConnect) | ||
149 | #endif | 163 | #endif | ||
150 | } | 164 | } | ||
151 | 165 | | |||
152 | QStringList ModuleManager::loadedModules() const | 166 | QStringList ModuleManager::loadedModules() const | ||
153 | { | 167 | { | ||
154 | return m_loadedModules; | 168 | return m_loadedModules; | ||
155 | } | 169 | } | ||
156 | 170 | | |||
157 | void ModuleManager::updateLoadedModules() | 171 | void ModuleManager::updateLoadedModules() | ||
158 | { | 172 | { | ||
159 | m_loadedModules.clear(); | 173 | m_loadedModules.clear(); | ||
160 | const auto modules = Context::instance()->modules().data(); | 174 | const auto modules = Context::instance()->modules().data(); | ||
161 | for (Module *module : modules) { | 175 | for (Module *module : modules) { | ||
162 | m_loadedModules.append(module->name()); | 176 | m_loadedModules.append(module->name()); | ||
163 | } | 177 | } | ||
164 | Q_EMIT loadedModulesChanged(); | 178 | Q_EMIT loadedModulesChanged(); | ||
165 | } | 179 | } | ||
166 | 180 | | |||
181 | bool ModuleManager::configModuleLoaded() const | ||||
182 | { | ||||
183 | return m_loadedModules.contains(configModuleName()); | ||||
184 | } | ||||
185 | | ||||
186 | QString ModuleManager::configModuleName() const | ||||
187 | { | ||||
188 | #if USE_GCONF | ||||
189 | return QStringLiteral("module-gconf"); | ||||
190 | #elif USE_GSETTINGS | ||||
191 | return QStringLiteral("module-gsettings"); | ||||
192 | #else | ||||
193 | return QString(); | ||||
194 | #endif | ||||
195 | } | ||||
167 | } | 196 | } |
newline