Changeset View
Changeset View
Standalone View
Standalone View
cuttlefish/src/iconmodel.cpp
Show All 34 Lines | |||||
35 | #include <KConfigGroup> | 35 | #include <KConfigGroup> | ||
36 | #include <KIconLoader> | 36 | #include <KIconLoader> | ||
37 | #include <KIconTheme> | 37 | #include <KIconTheme> | ||
38 | #include <KSharedConfig> | 38 | #include <KSharedConfig> | ||
39 | #include <KPackage/PackageLoader> | 39 | #include <KPackage/PackageLoader> | ||
40 | 40 | | |||
41 | #include <Plasma/Theme> | 41 | #include <Plasma/Theme> | ||
42 | 42 | | |||
43 | #include <algorithm> | ||||
44 | #include <cstring> | ||||
43 | #include <iostream> | 45 | #include <iostream> | ||
44 | 46 | | |||
45 | using namespace CuttleFish; | 47 | using namespace CuttleFish; | ||
46 | 48 | | |||
47 | static QTextStream cout(stdout); | 49 | static QTextStream cout(stdout); | ||
48 | 50 | | |||
49 | IconModel::IconModel(QObject *parent) : | 51 | IconModel::IconModel(QObject *parent) : | ||
50 | QAbstractListModel(parent), | 52 | QAbstractListModel(parent), | ||
Show All 19 Lines | 71 | // qDebug() << "Setting Plasma theme" << themeName; | |||
70 | theme.setUseGlobalSettings(false); | 72 | theme.setUseGlobalSettings(false); | ||
71 | theme.setThemeName(themeName); // needs to happen after setUseGlobalSettings, since that clears themeName | 73 | theme.setThemeName(themeName); // needs to happen after setUseGlobalSettings, since that clears themeName | ||
72 | 74 | | |||
73 | QList<KPluginMetaData> themepackages = KPackage::PackageLoader::self()->listPackages(QString(), "plasma/desktoptheme"); | 75 | QList<KPluginMetaData> themepackages = KPackage::PackageLoader::self()->listPackages(QString(), "plasma/desktoptheme"); | ||
74 | foreach (const KPluginMetaData &pkg, themepackages) { | 76 | foreach (const KPluginMetaData &pkg, themepackages) { | ||
75 | m_plasmathemes << pkg.pluginId(); | 77 | m_plasmathemes << pkg.pluginId(); | ||
76 | } | 78 | } | ||
77 | 79 | | |||
78 | m_svgIcons[QStringLiteral("amarok")] = QStringList() << "amarok"; | | |||
79 | m_svgIcons[QStringLiteral("audio")] = QStringList() << "audio-volume-muted" | | |||
80 | << "audio-volume-low" | | |||
81 | << "audio-volume-medium" | | |||
82 | << "audio-volume-high" ; | | |||
83 | | ||||
84 | m_svgIcons[QStringLiteral("battery")] = QStringList() << "Battery" | | |||
85 | << "Acadapter" | | |||
86 | << "Unavailable" | | |||
87 | << "Fill10" | | |||
88 | << "Fill20" | | |||
89 | << "Fill30" | | |||
90 | << "Fill40" | | |||
91 | << "Fill50" | | |||
92 | << "Fill60" | | |||
93 | << "Fill70" | | |||
94 | << "Fill80" | | |||
95 | << "Fill90" | | |||
96 | << "Fill100"; | | |||
97 | m_svgIcons[QStringLiteral("device")] = QStringList() << "device-notfier"; | | |||
98 | m_svgIcons[QStringLiteral("juk")] = QStringList() << "juk"; | | |||
99 | m_svgIcons[QStringLiteral("kget")] = QStringList() << "kget"; | | |||
100 | m_svgIcons[QStringLiteral("klippper")] = QStringList() << "klippper"; | | |||
101 | m_svgIcons[QStringLiteral("konversation")] = QStringList() << "konversation"; | | |||
102 | m_svgIcons[QStringLiteral("kopete")] = QStringList() << "konversation" | | |||
103 | << "kopete-offline"; | | |||
104 | m_svgIcons[QStringLiteral("korgac")] = QStringList() << "korgac"; | | |||
105 | m_svgIcons[QStringLiteral("ktorrent")] = QStringList() << "ktorrent"; | | |||
106 | m_svgIcons[QStringLiteral("kget")] = QStringList() << "kget"; | | |||
107 | | ||||
108 | m_svgIcons[QStringLiteral("battery")] = QStringList() << "Battery" | | |||
109 | << "Acadapter" | | |||
110 | << "Unavailable" | | |||
111 | << "Fill10" | | |||
112 | << "Fill20" | | |||
113 | << "Fill30" | | |||
114 | << "Fill40" | | |||
115 | << "Fill50" | | |||
116 | << "Fill60" | | |||
117 | << "Fill70" | | |||
118 | << "Fill80" | | |||
119 | << "Fill90" | | |||
120 | << "Fill100"; | | |||
121 | m_svgIcons[QStringLiteral("message-indicator")] = QStringList() << "normal" | | |||
122 | << "new"; | | |||
123 | | ||||
124 | m_svgIcons[QStringLiteral("nepomuk")] = QStringList() << "nepomuk"; | | |||
125 | m_svgIcons[QStringLiteral("network")] = QStringList() << "network-wired-activated" | | |||
126 | << "network-wired" | | |||
127 | << "network-wireless-available" | | |||
128 | << "network-wireless-disconnected" | | |||
129 | << "flightmode-off" | | |||
130 | << "flightmode-on" | | |||
131 | << "network-wireless-0" | | |||
132 | << "network-wireless-20" | | |||
133 | << "network-wireless-25" | | |||
134 | << "network-wireless-40" | | |||
135 | << "network-wireless-50" | | |||
136 | << "network-wireless-60" | | |||
137 | << "network-wireless-75" | | |||
138 | << "network-wireless-80" | | |||
139 | << "network-wireless-100" | | |||
140 | << "network-mobile-20" | | |||
141 | << "network-mobile-40" | | |||
142 | << "network-mobile-60" | | |||
143 | << "network-mobile-80" | | |||
144 | << "network-mobile-100"; | | |||
145 | m_svgIcons[QStringLiteral("preferences")] = QStringList() << "preferences-system-bluetooth" | | |||
146 | << "preferences-system-bluetooth-inactive" | | |||
147 | << "preferences-desktop-texttospeach" | | |||
148 | << "preferences-desktop-display-randr" | | |||
149 | << "preferences-activities"; | | |||
150 | m_svgIcons[QStringLiteral("printer")] = QStringList() << "printer"; | | |||
151 | m_svgIcons[QStringLiteral("quassel")] = QStringList() << "quassel" | | |||
152 | << "quassel_inactive" | | |||
153 | << "quassel_message"; | | |||
154 | m_svgIcons[QStringLiteral("wallet")] = QStringList() << "wallet" | | |||
155 | << "wallet-open" | | |||
156 | << "wallet-closed"; | | |||
157 | | ||||
158 | m_categories = QStringList() << "all" \ | 80 | m_categories = QStringList() << "all" \ | ||
159 | << "actions" | 81 | << "actions" | ||
160 | << "animations" | 82 | << "animations" | ||
161 | << "apps" | 83 | << "apps" | ||
162 | << "categories" | 84 | << "categories" | ||
163 | << "devices" | 85 | << "devices" | ||
164 | << "emblems" | 86 | << "emblems" | ||
165 | << "emotes" | 87 | << "emotes" | ||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | 267 | if (matchIcons(info)) { | |||
346 | add(info, categoryFromPath(info.absoluteFilePath())); | 268 | add(info, categoryFromPath(info.absoluteFilePath())); | ||
347 | } | 269 | } | ||
348 | } | 270 | } | ||
349 | } | 271 | } | ||
350 | } | 272 | } | ||
351 | } | 273 | } | ||
352 | 274 | | |||
353 | svgIcons(); | 275 | svgIcons(); | ||
276 | | ||||
277 | sort(); | ||||
278 | | ||||
354 | endResetModel(); | 279 | endResetModel(); | ||
355 | //qDebug() << "Loading took" << tt.elapsed() << " msec"; | 280 | | ||
356 | m_loading = false; | 281 | m_loading = false; | ||
357 | emit loadingChanged(); | 282 | emit loadingChanged(); | ||
358 | } | 283 | } | ||
359 | 284 | | |||
285 | void IconModel::sort() | ||||
286 | { | ||||
287 | std::sort(m_icons.begin(), m_icons.end()); | ||||
288 | } | ||||
289 | | ||||
360 | bool IconModel::matchIcons(const QFileInfo& info) | 290 | bool IconModel::matchIcons(const QFileInfo& info) | ||
361 | { | 291 | { | ||
362 | bool ok = false; | 292 | bool ok = false; | ||
363 | 293 | | |||
364 | // Category is empty or all? Skip further matching. | 294 | // Category is empty or all? Skip further matching. | ||
365 | bool catmatch = m_category.isEmpty() || m_category == QStringLiteral("all"); | 295 | bool catmatch = m_category.isEmpty() || m_category == QStringLiteral("all"); | ||
366 | // category match? | 296 | // category match? | ||
367 | if (!catmatch && m_category == categoryFromPath(info.absoluteFilePath())) { | 297 | if (!catmatch && m_category == categoryFromPath(info.absoluteFilePath())) { | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 358 | (file.indexOf(m_filter) != -1 || icon.indexOf(m_filter) != -1)) { | |||
442 | } | 372 | } | ||
443 | QVariantMap vm; | 373 | QVariantMap vm; | ||
444 | vm["fileName"] = file; | 374 | vm["fileName"] = file; | ||
445 | vm["iconName"] = icon; | 375 | vm["iconName"] = icon; | ||
446 | out << vm; | 376 | out << vm; | ||
447 | } | 377 | } | ||
448 | } | 378 | } | ||
449 | } | 379 | } | ||
380 | sort(); | ||||
450 | } | 381 | } | ||
451 | 382 | | |||
452 | QString IconModel::categoryFromPath(const QString& path) | 383 | QString IconModel::categoryFromPath(const QString& path) | ||
453 | { | 384 | { | ||
454 | QStringList cats; | 385 | QStringList cats; | ||
455 | Q_FOREACH (auto c, m_categories) { | 386 | Q_FOREACH (auto c, m_categories) { | ||
456 | cats << c.toLower(); | 387 | cats << c.toLower(); | ||
457 | } | 388 | } | ||
Show All 23 Lines |