Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindecoration/decorationmodel.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
55 | { | 55 | { | ||
56 | if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= int(m_plugins.size())) { | 56 | if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= int(m_plugins.size())) { | ||
57 | return QVariant(); | 57 | return QVariant(); | ||
58 | } | 58 | } | ||
59 | const Data &d = m_plugins.at(index.row()); | 59 | const Data &d = m_plugins.at(index.row()); | ||
60 | switch (role) { | 60 | switch (role) { | ||
61 | case Qt::DisplayRole: | 61 | case Qt::DisplayRole: | ||
62 | return d.visibleName; | 62 | return d.visibleName; | ||
63 | case Qt::UserRole +4: | 63 | case PluginNameRole: | ||
64 | return d.pluginName; | 64 | return d.pluginName; | ||
65 | case Qt::UserRole +5: | 65 | case ThemeNameRole: | ||
66 | return d.themeName; | 66 | return d.themeName; | ||
67 | case Qt::UserRole +6: | 67 | case ConfigurationRole: | ||
68 | return d.configuration; | 68 | return d.configuration; | ||
69 | } | 69 | } | ||
70 | | ||||
71 | return QVariant(); | 70 | return QVariant(); | ||
72 | } | 71 | } | ||
73 | 72 | | |||
74 | QHash< int, QByteArray > DecorationsModel::roleNames() const | 73 | QHash< int, QByteArray > DecorationsModel::roleNames() const | ||
75 | { | 74 | { | ||
76 | QHash<int, QByteArray> roles({ | 75 | QHash<int, QByteArray> roles({ | ||
77 | {Qt::DisplayRole, QByteArrayLiteral("display")}, | 76 | {Qt::DisplayRole, QByteArrayLiteral("display")}, | ||
78 | {Qt::UserRole + 4, QByteArrayLiteral("plugin")}, | 77 | {PluginNameRole, QByteArrayLiteral("plugin")}, | ||
79 | {Qt::UserRole + 5, QByteArrayLiteral("theme")}, | 78 | {ThemeNameRole, QByteArrayLiteral("theme")}, | ||
80 | {Qt::UserRole +6, QByteArrayLiteral("configureable")} | 79 | {ConfigurationRole, QByteArrayLiteral("configureable")} | ||
81 | }); | 80 | }); | ||
82 | return roles; | 81 | return roles; | ||
83 | } | 82 | } | ||
84 | 83 | | |||
85 | static bool isThemeEngine(const QVariantMap &decoSettingsMap) | 84 | static bool isThemeEngine(const QVariantMap &decoSettingsMap) | ||
86 | { | 85 | { | ||
87 | auto it = decoSettingsMap.find(QStringLiteral("themes")); | 86 | auto it = decoSettingsMap.find(QStringLiteral("themes")); | ||
88 | if (it == decoSettingsMap.end()) { | 87 | if (it == decoSettingsMap.end()) { | ||
Show All 40 Lines | 125 | for (const auto &info : plugins) { | |||
129 | if (!factory) { | 128 | if (!factory) { | ||
130 | continue; | 129 | continue; | ||
131 | } | 130 | } | ||
132 | auto metadata = loader.metaData().value(QStringLiteral("MetaData")).toObject().value(s_pluginName); | 131 | auto metadata = loader.metaData().value(QStringLiteral("MetaData")).toObject().value(s_pluginName); | ||
133 | bool config = false; | 132 | bool config = false; | ||
134 | if (!metadata.isUndefined()) { | 133 | if (!metadata.isUndefined()) { | ||
135 | const auto decoSettingsMap = metadata.toObject().toVariantMap(); | 134 | const auto decoSettingsMap = metadata.toObject().toVariantMap(); | ||
136 | const QString &kns = findKNewStuff(decoSettingsMap); | 135 | const QString &kns = findKNewStuff(decoSettingsMap); | ||
137 | if (!kns.isEmpty()) { | 136 | if (!kns.isEmpty() && !m_knsProviders.contains(kns)) { | ||
138 | m_knsProvides.insert(kns, info.name().isEmpty() ? info.pluginName() : info.name()); | 137 | m_knsProviders.append(kns); | ||
139 | } | 138 | } | ||
140 | if (isThemeEngine(decoSettingsMap)) { | 139 | if (isThemeEngine(decoSettingsMap)) { | ||
141 | const QString keyword = themeListKeyword(decoSettingsMap); | 140 | const QString keyword = themeListKeyword(decoSettingsMap); | ||
142 | if (keyword.isNull()) { | 141 | if (keyword.isNull()) { | ||
143 | // We cannot list the themes | 142 | // We cannot list the themes | ||
144 | continue; | 143 | continue; | ||
145 | } | 144 | } | ||
146 | QScopedPointer<QObject> themeFinder(factory->create<QObject>(keyword)); | 145 | QScopedPointer<QObject> themeFinder(factory->create<QObject>(keyword)); | ||
147 | if (themeFinder.isNull()) { | 146 | if (themeFinder.isNull()) { | ||
148 | continue; | 147 | continue; | ||
149 | } | 148 | } | ||
150 | QVariant themes = themeFinder->property("themes"); | 149 | QVariant themes = themeFinder->property("themes"); | ||
151 | if (!themes.isValid()) { | 150 | if (!themes.isValid()) { | ||
152 | continue; | 151 | continue; | ||
153 | } | 152 | } | ||
154 | const auto themesMap = themes.toMap(); | 153 | const auto themesMap = themes.toMap(); | ||
155 | for (auto it = themesMap.begin(); it != themesMap.end(); ++it) { | 154 | for (auto it = themesMap.begin(); it != themesMap.end(); ++it) { | ||
156 | Data d; | 155 | Data d; | ||
157 | d.pluginName = info.pluginName(); | 156 | d.pluginName = info.pluginName(); | ||
158 | d.themeName = it.value().toString(); | 157 | d.themeName = it.value().toString(); | ||
159 | d.visibleName = it.key(); | 158 | d.visibleName = it.key(); | ||
160 | QMetaObject::invokeMethod(themeFinder.data(), "hasConfiguration", | 159 | QMetaObject::invokeMethod(themeFinder.data(), "hasConfiguration", | ||
161 | Q_RETURN_ARG(bool, d.configuration), | 160 | Q_RETURN_ARG(bool, d.configuration), | ||
162 | Q_ARG(QString, d.themeName)); | 161 | Q_ARG(QString, d.themeName)); | ||
163 | m_plugins.emplace_back(std::move(d)); | 162 | m_plugins.emplace_back(std::move(d)); | ||
zzag: Unrelated whitespace change. | |||||
164 | } | 163 | } | ||
165 | 164 | | |||
166 | // it's a theme engine, we don't want to show this entry | 165 | // it's a theme engine, we don't want to show this entry | ||
167 | continue; | 166 | continue; | ||
168 | } | 167 | } | ||
169 | config = isConfigureable(decoSettingsMap); | 168 | config = isConfigureable(decoSettingsMap); | ||
170 | } | 169 | } | ||
171 | Data data; | 170 | Data data; | ||
172 | data.pluginName = info.pluginName(); | 171 | data.pluginName = info.pluginName(); | ||
173 | data.visibleName = info.name().isEmpty() ? info.pluginName() : info.name(); | 172 | data.visibleName = info.name().isEmpty() ? info.pluginName() : info.name(); | ||
zzag: It seems like that's unrelated change. | |||||
it's not, findDecoration() below might fail to find a theme because it only searches for themeName and not on visibleName vpilo: it's not, findDecoration() below might fail to find a theme because it only searches for… | |||||
Introduction of name variable is unrelated change. Given that info is a const ref, I think we can do data.visibleName = info.name().isEmpty() ? info.pluginName() : info.name(); data.themeName = data.visibleName; zzag: Introduction of `name` variable is unrelated change. Given that `info` is a const ref, I think… | |||||
Ah right- it only made sense before I ditched the GHNS id->name data map. vpilo: Ah right- it only made sense before I ditched the GHNS id->name data map. | |||||
173 | data.themeName = data.visibleName; | ||||
174 | data.configuration = config; | 174 | data.configuration = config; | ||
175 | 175 | | |||
176 | m_plugins.emplace_back(std::move(data)); | 176 | m_plugins.emplace_back(std::move(data)); | ||
177 | } | 177 | } | ||
178 | endResetModel(); | 178 | endResetModel(); | ||
179 | } | 179 | } | ||
180 | 180 | | |||
181 | QModelIndex DecorationsModel::findDecoration(const QString &pluginName, const QString &themeName) const | 181 | QModelIndex DecorationsModel::findDecoration(const QString &pluginName, const QString &themeName) const | ||
Show All 15 Lines |
Unrelated whitespace change.