Changeset View
Changeset View
Standalone View
Standalone View
cuttlefish/src/iconmodel.cpp
Show All 33 Lines | |||||
34 | 34 | | |||
35 | #include <KConfigGroup> | 35 | #include <KConfigGroup> | ||
36 | #include <KColorSchemeManager> | 36 | #include <KColorSchemeManager> | ||
37 | #include <KIconLoader> | 37 | #include <KIconLoader> | ||
38 | #include <KIconTheme> | 38 | #include <KIconTheme> | ||
39 | #include <KSharedConfig> | 39 | #include <KSharedConfig> | ||
40 | #include <KPackage/PackageLoader> | 40 | #include <KPackage/PackageLoader> | ||
41 | 41 | | |||
42 | #include <Plasma/Theme> | | |||
43 | | ||||
44 | #include <algorithm> | 42 | #include <algorithm> | ||
45 | #include <cstring> | 43 | #include <cstring> | ||
46 | #include <iostream> | 44 | #include <iostream> | ||
47 | 45 | | |||
48 | using namespace CuttleFish; | 46 | using namespace CuttleFish; | ||
49 | 47 | | |||
50 | static QTextStream cout(stdout); | 48 | static QTextStream cout(stdout); | ||
51 | 49 | | |||
52 | IconModel::IconModel(QObject *parent) : | 50 | IconModel::IconModel(QObject *parent) : | ||
53 | QAbstractListModel(parent), | 51 | QAbstractListModel(parent) | ||
54 | m_theme(QStringLiteral("breeze")) | | |||
55 | , m_loading(false) | 52 | , m_loading(false) | ||
56 | { | 53 | { | ||
57 | m_roleNames.insert(FileName, "fileName"); | 54 | m_roleNames.insert(FileName, "fileName"); | ||
58 | m_roleNames.insert(IconName, "iconName"); | 55 | m_roleNames.insert(IconName, "iconName"); | ||
59 | m_roleNames.insert(Icon, "icon"); | 56 | m_roleNames.insert(Icon, "icon"); | ||
60 | m_roleNames.insert(FullPath, "fullPath"); | 57 | m_roleNames.insert(FullPath, "fullPath"); | ||
61 | m_roleNames.insert(Category, "category"); | 58 | m_roleNames.insert(Category, "category"); | ||
62 | m_roleNames.insert(Scalable, "scalable"); | 59 | m_roleNames.insert(Scalable, "scalable"); | ||
63 | m_roleNames.insert(Sizes, "sizes"); | 60 | m_roleNames.insert(Sizes, "sizes"); | ||
64 | m_roleNames.insert(Theme, "iconTheme"); | 61 | m_roleNames.insert(Theme, "iconTheme"); | ||
65 | m_roleNames.insert(Type, "type"); | 62 | m_roleNames.insert(Type, "type"); | ||
66 | 63 | | |||
67 | connect(this, &IconModel::categoryChanged, this, &IconModel::load); | 64 | connect(this, &IconModel::categoryChanged, this, &IconModel::load); | ||
68 | KConfigGroup cg(KSharedConfig::openConfig("cuttlefishrc"), "CuttleFish"); | | |||
69 | const QString themeName = cg.readEntry("theme", "default"); | | |||
70 | | ||||
71 | Plasma::Theme theme; | | |||
72 | // qDebug() << "Setting Plasma theme" << themeName; | | |||
73 | theme.setUseGlobalSettings(false); | | |||
74 | theme.setThemeName(themeName); // needs to happen after setUseGlobalSettings, since that clears themeName | | |||
75 | | ||||
76 | QList<KPluginMetaData> themepackages = KPackage::PackageLoader::self()->listPackages(QString(), "plasma/desktoptheme"); | | |||
77 | foreach (const KPluginMetaData &pkg, themepackages) { | | |||
78 | m_plasmathemes << pkg.pluginId(); | | |||
79 | } | | |||
80 | 65 | | |||
81 | m_categories = QStringList() << "all" \ | 66 | m_categories = QStringList() << "all" \ | ||
82 | << "actions" | 67 | << "actions" | ||
83 | << "animations" | 68 | << "animations" | ||
84 | << "apps" | 69 | << "apps" | ||
85 | << "categories" | 70 | << "categories" | ||
86 | << "devices" | 71 | << "devices" | ||
87 | << "emblems" | 72 | << "emblems" | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | |||||
210 | 195 | | |||
211 | void IconModel::setFilter(const QString &filter) | 196 | void IconModel::setFilter(const QString &filter) | ||
212 | { | 197 | { | ||
213 | //qDebug() << "Filter: " << filter; | 198 | //qDebug() << "Filter: " << filter; | ||
214 | if (m_filter != filter) { | 199 | if (m_filter != filter) { | ||
215 | m_filter = filter; | 200 | m_filter = filter; | ||
216 | load(); | 201 | load(); | ||
217 | emit filterChanged(); | 202 | emit filterChanged(); | ||
218 | emit svgIconsChanged(); | | |||
219 | } | 203 | } | ||
220 | } | 204 | } | ||
221 | 205 | | |||
222 | void IconModel::load() | 206 | void IconModel::load() | ||
223 | { | 207 | { | ||
224 | //qDebug() << "\n -- Loading (category / filter) : " << m_category << m_filter; | 208 | //qDebug() << "\n -- Loading (category / filter) : " << m_category << m_filter; | ||
225 | m_loading = true; | 209 | m_loading = true; | ||
226 | emit loadingChanged(); | 210 | emit loadingChanged(); | ||
Show All 22 Lines | |||||
249 | } | 233 | } | ||
250 | 234 | | |||
251 | QStringList hicolorThemePaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("icons/hicolor"), QStandardPaths::LocateDirectory); | 235 | QStringList hicolorThemePaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("icons/hicolor"), QStandardPaths::LocateDirectory); | ||
252 | if (hicolorThemePaths.count() > 0) { | 236 | if (hicolorThemePaths.count() > 0) { | ||
253 | searchPaths << hicolorThemePaths; | 237 | searchPaths << hicolorThemePaths; | ||
254 | } | 238 | } | ||
255 | 239 | | |||
256 | foreach (const QString &iconPath, searchPaths) { | 240 | foreach (const QString &iconPath, searchPaths) { | ||
257 | | ||||
258 | QDirIterator cats(iconPath, nameFilters, QDir::Dirs, QDirIterator::NoIteratorFlags); | 241 | QDirIterator cats(iconPath, nameFilters, QDir::Dirs, QDirIterator::NoIteratorFlags); | ||
259 | while (cats.hasNext()) { | 242 | while (cats.hasNext()) { | ||
260 | cats.next(); | 243 | cats.next(); | ||
261 | const QString fpath = cats.filePath(); | 244 | const QString fpath = cats.filePath(); | ||
262 | const QString category = cats.fileName(); | 245 | const QString category = cats.fileName(); | ||
263 | if (category != "." && category != "..") { | 246 | if (category != "." && category != "..") { | ||
264 | QDirIterator it(fpath, nameFilters, QDir::Files, flags); | 247 | QDirIterator it(fpath, nameFilters, QDir::Files, flags); | ||
265 | while (it.hasNext()) { | 248 | while (it.hasNext()) { | ||
266 | it.next(); | 249 | it.next(); | ||
267 | const QFileInfo &info = it.fileInfo(); | 250 | const QFileInfo &info = it.fileInfo(); | ||
268 | if (matchIcons(info)) { | 251 | if (matchIcons(info)) { | ||
269 | add(info, categoryFromPath(info.absoluteFilePath())); | 252 | add(info, categoryFromPath(info.absoluteFilePath())); | ||
270 | } | 253 | } | ||
271 | } | 254 | } | ||
272 | } | 255 | } | ||
273 | } | 256 | } | ||
274 | } | 257 | } | ||
275 | 258 | | |||
276 | svgIcons(); | | |||
277 | | ||||
278 | sort(); | 259 | sort(); | ||
279 | 260 | | |||
280 | endResetModel(); | 261 | endResetModel(); | ||
281 | 262 | | |||
282 | m_loading = false; | 263 | m_loading = false; | ||
283 | emit loadingChanged(); | 264 | emit loadingChanged(); | ||
284 | } | 265 | } | ||
285 | 266 | | |||
Show All 17 Lines | 273 | { | |||
303 | if (m_filter.isEmpty() || info.fileName().indexOf(m_filter) != -1) { | 284 | if (m_filter.isEmpty() || info.fileName().indexOf(m_filter) != -1) { | ||
304 | if (catmatch) { | 285 | if (catmatch) { | ||
305 | ok = true; | 286 | ok = true; | ||
306 | } | 287 | } | ||
307 | } | 288 | } | ||
308 | return ok; | 289 | return ok; | ||
309 | } | 290 | } | ||
310 | 291 | | |||
311 | | ||||
312 | QStringList IconModel::themes() const | | |||
313 | { | | |||
314 | return m_themes; | | |||
315 | } | | |||
316 | | ||||
317 | QString IconModel::theme() const | | |||
318 | { | | |||
319 | return m_theme; | | |||
320 | } | | |||
321 | | ||||
322 | void IconModel::setTheme(const QString& theme) | | |||
323 | { | | |||
324 | if (theme != m_theme) { | | |||
325 | m_theme = theme; | | |||
326 | load(); | | |||
327 | emit themeChanged(); | | |||
328 | } | | |||
329 | } | | |||
330 | | ||||
331 | QString IconModel::plasmaTheme() const | | |||
332 | { | | |||
333 | return m_plasmatheme; | | |||
334 | } | | |||
335 | | ||||
336 | void IconModel::setPlasmaTheme(const QString& ptheme) | | |||
337 | { | | |||
338 | if (m_plasmatheme != ptheme) { | | |||
339 | m_plasmatheme = ptheme; | | |||
340 | Plasma::Theme theme; | | |||
341 | theme.setThemeName(ptheme); | | |||
342 | load(); | | |||
343 | emit plasmaThemeChanged(); | | |||
344 | } | | |||
345 | } | | |||
346 | | ||||
347 | QStringList IconModel::plasmathemes() const | | |||
348 | { | | |||
349 | return m_plasmathemes; | | |||
350 | } | | |||
351 | | ||||
352 | void IconModel::svgIcons() | | |||
353 | { | | |||
354 | QVariantList out; | | |||
355 | | ||||
356 | foreach (const QString &file, m_svgIcons.keys()) { | | |||
357 | foreach (const QString &icon, m_svgIcons[file].toStringList()) { | | |||
358 | if (m_filter.isEmpty() || | | |||
359 | (file.indexOf(m_filter) != -1 || icon.indexOf(m_filter) != -1)) { | | |||
360 | | ||||
361 | QVariantMap &data = m_data[icon]; | | |||
362 | if (!m_icons.contains(icon)) { | | |||
363 | | ||||
364 | data["fullPath"] = ""; | | |||
365 | data["iconName"] = icon; | | |||
366 | data["fileName"] = file; | | |||
367 | data["category"] = "system"; | | |||
368 | data["type"] = QStringLiteral("svg"); | | |||
369 | data["scalable"] = true; | | |||
370 | data["iconTheme"] = m_plasmatheme; | | |||
371 | | ||||
372 | m_icons << icon; | | |||
373 | } | | |||
374 | QVariantMap vm; | | |||
375 | vm["fileName"] = file; | | |||
376 | vm["iconName"] = icon; | | |||
377 | out << vm; | | |||
378 | } | | |||
379 | } | | |||
380 | } | | |||
381 | sort(); | | |||
382 | } | | |||
383 | | ||||
384 | QString IconModel::categoryFromPath(const QString& path) | 292 | QString IconModel::categoryFromPath(const QString& path) | ||
385 | { | 293 | { | ||
386 | QStringList cats; | 294 | QStringList cats; | ||
387 | Q_FOREACH (auto c, m_categories) { | 295 | Q_FOREACH (auto c, m_categories) { | ||
388 | cats << c.toLower(); | 296 | cats << c.toLower(); | ||
389 | } | 297 | } | ||
390 | //cats << "actions" << "apps" << "places" << "status"; | 298 | //cats << "actions" << "apps" << "places" << "status"; | ||
391 | const QStringList _p1 = path.split("/icons/"); | 299 | const QStringList _p1 = path.split("/icons/"); | ||
Show All 32 Lines |