Changeset View
Changeset View
Standalone View
Standalone View
kcms/kded/modulesmodel.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 69 | if (!m_runningModulesKnown) { | |||
---|---|---|---|---|---|
70 | return KDEDConfig::UnknownStatus; | 70 | return KDEDConfig::UnknownStatus; | ||
71 | } | 71 | } | ||
72 | if (m_runningModules.contains(item.moduleName)) { | 72 | if (m_runningModules.contains(item.moduleName)) { | ||
73 | return KDEDConfig::Running; | 73 | return KDEDConfig::Running; | ||
74 | } | 74 | } | ||
75 | return KDEDConfig::NotRunning; | 75 | return KDEDConfig::NotRunning; | ||
76 | } | 76 | } | ||
77 | case ModuleNameRole: return item.moduleName; | 77 | case ModuleNameRole: return item.moduleName; | ||
78 | case ImmutableRole: return item.immutable; | ||||
78 | } | 79 | } | ||
79 | 80 | | |||
80 | return QVariant(); | 81 | return QVariant(); | ||
81 | } | 82 | } | ||
82 | 83 | | |||
84 | bool ModulesModel::representsDefault() const | ||||
ervin: Curly brace should be on its own line | |||||
85 | { | ||||
86 | bool isDefault = true; | ||||
87 | for (int i = 0; i < m_data.count(); ++i) { | ||||
88 | auto &item = m_data[i]; | ||||
89 | if (item.type != KDEDConfig::AutostartType || item.immutable) { | ||||
90 | continue; | ||||
91 | } | ||||
92 | isDefault &= item.autoloadEnabled; | ||||
93 | } | ||||
94 | return isDefault; | ||||
95 | } | ||||
96 | | ||||
97 | bool ModulesModel::needsSave() const | ||||
98 | { | ||||
ervin: Curly brace should be on its own line | |||||
99 | bool save = false; | ||||
100 | for (int i = 0; i < m_data.count(); ++i) { | ||||
101 | auto &item = m_data[i]; | ||||
102 | if (item.type != KDEDConfig::AutostartType || item.immutable) { | ||||
103 | continue; | ||||
104 | } | ||||
105 | save |= item.autoloadEnabled != item.savedAutoloadEnabled; | ||||
106 | } | ||||
107 | return save; | ||||
108 | } | ||||
109 | | ||||
83 | bool ModulesModel::setData(const QModelIndex &index, const QVariant &value, int role) | 110 | bool ModulesModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
84 | { | 111 | { | ||
85 | bool dirty = false; | 112 | bool dirty = false; | ||
86 | 113 | | |||
87 | if (!checkIndex(index)) { | 114 | if (!checkIndex(index)) { | ||
88 | return dirty; | 115 | return dirty; | ||
89 | } | 116 | } | ||
90 | 117 | | |||
91 | auto &item = m_data[index.row()]; | 118 | auto &item = m_data[index.row()]; | ||
92 | 119 | | |||
120 | if (item.type != KDEDConfig::AutostartType || item.immutable) { | ||||
121 | return dirty; | ||||
122 | } | ||||
123 | | ||||
93 | switch (role) { | 124 | switch (role) { | ||
94 | case AutoloadEnabledRole: | 125 | case AutoloadEnabledRole: { | ||
95 | const bool autoloadEnabled = value.toBool(); | 126 | const bool autoloadEnabled = value.toBool(); | ||
96 | if (item.type == KDEDConfig::AutostartType | 127 | if (item.autoloadEnabled != autoloadEnabled) { | ||
Since generally setData only does things for AutostartType, perhaps move that check out of the switch broulik: Since generally `setData` only does things for `AutostartType`, perhaps move that check out of… | |||||
97 | && item.autoloadEnabled != autoloadEnabled) { | 128 | item.autoloadEnabled = autoloadEnabled; | ||
98 | item.autoloadEnabled = value.toBool(); | | |||
99 | dirty = true; | 129 | dirty = true; | ||
100 | | ||||
101 | emit autoloadedModulesChanged(); | | |||
102 | } | 130 | } | ||
131 | emit autoloadedModulesChanged(); | ||||
103 | break; | 132 | break; | ||
104 | } | 133 | } | ||
134 | } | ||||
105 | 135 | | |||
106 | if (dirty) { | 136 | if (dirty) { | ||
107 | emit dataChanged(index, index, {role}); | 137 | emit dataChanged(index, index, {role}); | ||
108 | } | 138 | } | ||
109 | 139 | | |||
110 | return dirty; | 140 | return dirty; | ||
111 | } | 141 | } | ||
112 | 142 | | |||
113 | QHash<int, QByteArray> ModulesModel::roleNames() const | 143 | QHash<int, QByteArray> ModulesModel::roleNames() const | ||
114 | { | 144 | { | ||
115 | return { | 145 | return { | ||
116 | {Qt::DisplayRole, QByteArrayLiteral("display")}, | 146 | {Qt::DisplayRole, QByteArrayLiteral("display")}, | ||
117 | {DescriptionRole, QByteArrayLiteral("description")}, | 147 | {DescriptionRole, QByteArrayLiteral("description")}, | ||
118 | {TypeRole, QByteArrayLiteral("type")}, | 148 | {TypeRole, QByteArrayLiteral("type")}, | ||
119 | {AutoloadEnabledRole, QByteArrayLiteral("autoloadEnabled")}, | 149 | {AutoloadEnabledRole, QByteArrayLiteral("autoloadEnabled")}, | ||
120 | {StatusRole, QByteArrayLiteral("status")}, | 150 | {StatusRole, QByteArrayLiteral("status")}, | ||
121 | {ModuleNameRole, QByteArrayLiteral("moduleName")}, | 151 | {ModuleNameRole, QByteArrayLiteral("moduleName")}, | ||
152 | {ImmutableRole, QByteArrayLiteral("immutable")}, | ||||
122 | }; | 153 | }; | ||
123 | } | 154 | } | ||
124 | 155 | | |||
125 | // This code was copied from kded.cpp | 156 | // This code was copied from kded.cpp | ||
126 | // TODO: move this KCM to the KDED framework and share the code? | 157 | // TODO: move this KCM to the KDED framework and share the code? | ||
127 | static QVector<KPluginMetaData> availableModules() | 158 | static QVector<KPluginMetaData> availableModules() | ||
128 | { | 159 | { | ||
129 | QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("kf5/kded")); | 160 | QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("kf5/kded")); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 193 | { | |||
172 | QVector<ModulesModelData> onDemandModules; | 203 | QVector<ModulesModelData> onDemandModules; | ||
173 | 204 | | |||
174 | const auto modules = availableModules(); | 205 | const auto modules = availableModules(); | ||
175 | for (const KPluginMetaData &module : modules) { | 206 | for (const KPluginMetaData &module : modules) { | ||
176 | QString servicePath = module.metaDataFileName(); | 207 | QString servicePath = module.metaDataFileName(); | ||
177 | 208 | | |||
178 | // autoload defaults to false if it is not found | 209 | // autoload defaults to false if it is not found | ||
179 | const bool autoload = module.rawData().value(QStringLiteral("X-KDE-Kded-autoload")).toVariant().toBool(); | 210 | const bool autoload = module.rawData().value(QStringLiteral("X-KDE-Kded-autoload")).toVariant().toBool(); | ||
211 | | ||||
180 | // keep estimating dbusModuleName in sync with KDEDModule (kdbusaddons) and kded (kded) | 212 | // keep estimating dbusModuleName in sync with KDEDModule (kdbusaddons) and kded (kded) | ||
181 | // currently (KF5) the module name in the D-Bus object path is set by the pluginId | 213 | // currently (KF5) the module name in the D-Bus object path is set by the pluginId | ||
182 | const QString dbusModuleName = module.pluginId(); | 214 | const QString dbusModuleName = module.pluginId(); | ||
183 | qCDebug(KCM_KDED) << "reading kded info from" << servicePath << "autoload =" << autoload << "dbus module name =" << dbusModuleName; | 215 | qCDebug(KCM_KDED) << "reading kded info from" << servicePath << "autoload =" << autoload << "dbus module name =" << dbusModuleName; | ||
184 | 216 | | |||
185 | if (knownModules.contains(dbusModuleName)) { | 217 | if (knownModules.contains(dbusModuleName)) { | ||
186 | continue; | 218 | continue; | ||
187 | } | 219 | } | ||
188 | 220 | | |||
189 | knownModules.append(dbusModuleName); | 221 | knownModules.append(dbusModuleName); | ||
190 | 222 | | |||
191 | KConfigGroup cg(&kdedrc, QStringLiteral("Module-%1").arg(dbusModuleName)); | 223 | KConfigGroup cg(&kdedrc, QStringLiteral("Module-%1").arg(dbusModuleName)); | ||
192 | const bool autoloadEnabled = cg.readEntry("autoload", true); | 224 | const bool autoloadEnabled = cg.readEntry("autoload", true); | ||
225 | const bool immutable = cg.isEntryImmutable("autoload"); | ||||
broulik: Superfluous space | |||||
193 | 226 | | |||
194 | ModulesModelData data{ | 227 | ModulesModelData data{ | ||
195 | module.name(), | 228 | module.name(), | ||
196 | module.description(), | 229 | module.description(), | ||
197 | KDEDConfig::UnknownType, | 230 | KDEDConfig::UnknownType, | ||
198 | autoloadEnabled, | 231 | autoloadEnabled, | ||
199 | dbusModuleName | 232 | dbusModuleName, | ||
233 | immutable, | ||||
234 | autoloadEnabled | ||||
meven: Inserted twice, line 219 | |||||
Yes I insert it twice first one is for autoenable value (that will change when we check or uncheck entry), and the second one is the base value to know if data are dirty or not. bport: Yes I insert it twice first one is for autoenable value (that will change when we check or… | |||||
200 | }; | 235 | }; | ||
201 | 236 | | |||
202 | // The logic has to be identical to Kded::initModules. | 237 | // The logic has to be identical to Kded::initModules. | ||
203 | // They interpret X-KDE-Kded-autoload as false if not specified | 238 | // They interpret X-KDE-Kded-autoload as false if not specified | ||
204 | // X-KDE-Kded-load-on-demand as true if not specified | 239 | // X-KDE-Kded-load-on-demand as true if not specified | ||
205 | if (autoload) { | 240 | if (autoload) { | ||
206 | data.type = KDEDConfig::AutostartType; | 241 | data.type = KDEDConfig::AutostartType; | ||
207 | autostartModules << data; | 242 | autostartModules << data; | ||
Show All 14 Lines | |||||
222 | }; | 257 | }; | ||
223 | 258 | | |||
224 | std::sort(autostartModules.begin(), autostartModules.end(), sortAlphabetically); | 259 | std::sort(autostartModules.begin(), autostartModules.end(), sortAlphabetically); | ||
225 | std::sort(onDemandModules.begin(), onDemandModules.end(), sortAlphabetically); | 260 | std::sort(onDemandModules.begin(), onDemandModules.end(), sortAlphabetically); | ||
226 | 261 | | |||
227 | m_data << autostartModules << onDemandModules; | 262 | m_data << autostartModules << onDemandModules; | ||
228 | 263 | | |||
229 | endResetModel(); | 264 | endResetModel(); | ||
230 | } | 265 | } | ||
broulik: Check whether it actually changed before emitting it | |||||
231 | 266 | | |||
232 | bool ModulesModel::runningModulesKnown() const | 267 | bool ModulesModel::runningModulesKnown() const | ||
233 | { | 268 | { | ||
234 | return m_runningModulesKnown; | 269 | return m_runningModulesKnown; | ||
235 | } | 270 | } | ||
236 | 271 | | |||
237 | void ModulesModel::setRunningModulesKnown(bool known) | 272 | void ModulesModel::setRunningModulesKnown(bool known) | ||
238 | { | 273 | { | ||
Show All 14 Lines | 287 | if (m_runningModules == runningModules) { | |||
253 | return; | 288 | return; | ||
254 | } | 289 | } | ||
255 | 290 | | |||
256 | m_runningModules = runningModules; | 291 | m_runningModules = runningModules; | ||
257 | if (m_runningModulesKnown) { | 292 | if (m_runningModulesKnown) { | ||
258 | emit dataChanged(index(0, 0), index(m_data.count() - 1, 0), {StatusRole}); | 293 | emit dataChanged(index(0, 0), index(m_data.count() - 1, 0), {StatusRole}); | ||
259 | } | 294 | } | ||
260 | } | 295 | } | ||
296 | | ||||
297 | void ModulesModel::refreshAutoloadEnabledSavedState() | ||||
298 | { | ||||
299 | for (int i = 0; i < m_data.count(); ++i) { | ||||
300 | auto &item = m_data[i]; | ||||
301 | item.savedAutoloadEnabled = item.autoloadEnabled; | ||||
302 | } | ||||
303 | } |
Curly brace should be on its own line