Changeset View
Changeset View
Standalone View
Standalone View
libdiscover/backends/KNSBackend/KNSBackend.cpp
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 99 | { | |||
---|---|---|---|---|---|
129 | 129 | | |||
130 | const QVector<QPair<FilterType, QString>> filters = { {CategoryFilter, fileName } }; | 130 | const QVector<QPair<FilterType, QString>> filters = { {CategoryFilter, fileName } }; | ||
131 | const QSet<QString> backendName = { name() }; | 131 | const QSet<QString> backendName = { name() }; | ||
132 | m_displayName = group.readEntry("Name", QString()); | 132 | m_displayName = group.readEntry("Name", QString()); | ||
133 | if (m_displayName.isEmpty()) { | 133 | if (m_displayName.isEmpty()) { | ||
134 | m_displayName = fileName.mid(0, fileName.indexOf(QLatin1Char('.'))); | 134 | m_displayName = fileName.mid(0, fileName.indexOf(QLatin1Char('.'))); | ||
135 | m_displayName[0] = m_displayName[0].toUpper(); | 135 | m_displayName[0] = m_displayName[0].toUpper(); | ||
136 | } | 136 | } | ||
137 | m_hasApplications = group.readEntry<bool>("X-Discover-HasApplications", false); | ||||
137 | 138 | | |||
138 | const QStringList cats = group.readEntry<QStringList>("Categories", QStringList{}); | 139 | const QStringList cats = group.readEntry<QStringList>("Categories", QStringList{}); | ||
139 | QVector<Category*> categories; | 140 | QVector<Category*> categories; | ||
140 | if (cats.count() > 1) { | 141 | if (cats.count() > 1) { | ||
141 | m_categories += cats; | 142 | m_categories += cats; | ||
142 | for(const auto &cat: cats) | 143 | for(const auto &cat: cats) { | ||
143 | categories << new Category(cat, {}, { {CategoryFilter, cat } }, backendName, {}, {}, true); | 144 | if (m_hasApplications) | ||
145 | categories << new Category(cat, QStringLiteral("applications-other"), { {CategoryFilter, cat } }, backendName, {}, {}, true); | ||||
146 | else | ||||
147 | categories << new Category(cat, QStringLiteral("plasma"), { {CategoryFilter, cat } }, backendName, {}, {}, true); | ||||
148 | } | ||||
144 | } | 149 | } | ||
145 | 150 | | |||
146 | QVector<Category*> topCategories{categories}; | 151 | QVector<Category*> topCategories{categories}; | ||
147 | for (const auto &cat: categories) { | 152 | for (const auto &cat: categories) { | ||
148 | const QString catName = cat->name().append(QLatin1Char('/')); | 153 | const QString catName = cat->name().append(QLatin1Char('/')); | ||
149 | for (const auto& potentialSubCat: categories) { | 154 | for (const auto& potentialSubCat: categories) { | ||
150 | if(potentialSubCat->name().startsWith(catName)) { | 155 | if(potentialSubCat->name().startsWith(catName)) { | ||
151 | cat->addSubcategory(potentialSubCat); | 156 | cat->addSubcategory(potentialSubCat); | ||
Show All 16 Lines | 171 | if (cat->orFilters().count() > 0 && cat->orFilters().first().second == category.name) { | |||
168 | break; | 173 | break; | ||
169 | } | 174 | } | ||
170 | } | 175 | } | ||
171 | } | 176 | } | ||
172 | }); | 177 | }); | ||
173 | m_engine->setPageSize(100); | 178 | m_engine->setPageSize(100); | ||
174 | m_engine->init(m_name); | 179 | m_engine->init(m_name); | ||
175 | 180 | | |||
176 | m_hasApplications = group.readEntry<bool>("X-Discover-HasApplications", false); | | |||
177 | if(m_hasApplications) { | 181 | if(m_hasApplications) { | ||
178 | auto actualCategory = new Category(m_displayName, QStringLiteral("plasma"), filters, backendName, topCategories, QUrl(), false); | 182 | auto actualCategory = new Category(m_displayName, QStringLiteral("applications-other"), filters, backendName, topCategories, QUrl(), false); | ||
179 | auto applicationCategory = new Category(i18n("Applications"), QStringLiteral("applications-internet"), filters, backendName, { actualCategory }, QUrl(), false); | 183 | auto applicationCategory = new Category(i18n("Applications"), QStringLiteral("applications-internet"), filters, backendName, { actualCategory }, QUrl(), false); | ||
180 | applicationCategory->setAndFilter({ {CategoryFilter, QLatin1String("Application")} }); | 184 | applicationCategory->setAndFilter({ {CategoryFilter, QLatin1String("Application")} }); | ||
181 | m_categories.append(applicationCategory->name()); | 185 | m_categories.append(applicationCategory->name()); | ||
182 | m_rootCategories = { applicationCategory }; | 186 | m_rootCategories = { applicationCategory }; | ||
183 | // Make sure we filter out any apps which won't run on the current system architecture | 187 | // Make sure we filter out any apps which won't run on the current system architecture | ||
184 | QStringList tagFilter = m_engine->tagFilter(); | 188 | QStringList tagFilter = m_engine->tagFilter(); | ||
185 | if(QSysInfo::currentCpuArchitecture() == QLatin1String("arm")) { | 189 | if(QSysInfo::currentCpuArchitecture() == QLatin1String("arm")) { | ||
186 | tagFilter << QLatin1String("application##architecture==armhf"); | 190 | tagFilter << QLatin1String("application##architecture==armhf"); | ||
Show All 15 Lines | 203 | static const QSet<QString> knsrcPlasma = { | |||
202 | 206 | | |||
203 | QStringLiteral("cgcgtk3.knsrc"), QStringLiteral("cgcicon.knsrc"), QStringLiteral("cgctheme.knsrc"), //GTK integration | 207 | QStringLiteral("cgcgtk3.knsrc"), QStringLiteral("cgcicon.knsrc"), QStringLiteral("cgctheme.knsrc"), //GTK integration | ||
204 | QStringLiteral("kwinswitcher.knsrc"), QStringLiteral("kwineffect.knsrc"), QStringLiteral("kwinscripts.knsrc"), //KWin | 208 | QStringLiteral("kwinswitcher.knsrc"), QStringLiteral("kwineffect.knsrc"), QStringLiteral("kwinscripts.knsrc"), //KWin | ||
205 | QStringLiteral("comic.knsrc"), QStringLiteral("colorschemes.knsrc"), | 209 | QStringLiteral("comic.knsrc"), QStringLiteral("colorschemes.knsrc"), | ||
206 | QStringLiteral("emoticons.knsrc"), QStringLiteral("plymouth.knsrc"), | 210 | QStringLiteral("emoticons.knsrc"), QStringLiteral("plymouth.knsrc"), | ||
207 | QStringLiteral("sddmtheme.knsrc"), QStringLiteral("wallpaperplugin.knsrc"), | 211 | QStringLiteral("sddmtheme.knsrc"), QStringLiteral("wallpaperplugin.knsrc"), | ||
208 | QStringLiteral("ksplash.knsrc"), QStringLiteral("window-decorations.knsrc") | 212 | QStringLiteral("ksplash.knsrc"), QStringLiteral("window-decorations.knsrc") | ||
209 | }; | 213 | }; | ||
210 | auto actualCategory = new Category(m_displayName, QStringLiteral("plasma"), filters, backendName, categories, QUrl(), true); | 214 | const auto iconName = knsrcPlasma.contains(fileName)? QStringLiteral("plasma") : QStringLiteral("applications-other"); | ||
GB_2: I think we can use the icon `plugins` here. | |||||
ngraham: Submit a patch! :) | |||||
215 | auto actualCategory = new Category(m_displayName, iconName, filters, backendName, categories, QUrl(), true); | ||||
211 | 216 | | |||
212 | const auto topLevelName = knsrcPlasma.contains(fileName)? i18n("Plasma Addons") : i18n("Application Addons"); | 217 | const auto topLevelName = knsrcPlasma.contains(fileName)? i18n("Plasma Addons") : i18n("Application Addons"); | ||
213 | auto addonsCategory = new Category(topLevelName, QStringLiteral("plasma"), filters, backendName, {actualCategory}, QUrl(), true); | 218 | auto addonsCategory = new Category(topLevelName, iconName, filters, backendName, {actualCategory}, QUrl(), true); | ||
214 | m_rootCategories = { addonsCategory }; | 219 | m_rootCategories = { addonsCategory }; | ||
215 | } | 220 | } | ||
216 | } | 221 | } | ||
217 | 222 | | |||
218 | KNSBackend::~KNSBackend() | 223 | KNSBackend::~KNSBackend() | ||
219 | { | 224 | { | ||
220 | qDeleteAll(m_rootCategories); | 225 | qDeleteAll(m_rootCategories); | ||
221 | } | 226 | } | ||
▲ Show 20 Lines • Show All 373 Lines • Show Last 20 Lines |
I think we can use the icon plugins here.