Changeset View
Changeset View
Standalone View
Standalone View
runners/services/servicerunner.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org> | 2 | * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org> | ||
3 | * Copyright (C) 2014 Vishesh Handa <vhanda@kde.org> | 3 | * Copyright (C) 2014 Vishesh Handa <vhanda@kde.org> | ||
4 | * Copyright (C) 2016 Harald Sitter <sitter@kde.org> | ||||
4 | * | 5 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Library General Public License version 2 as | 7 | * it under the terms of the GNU Library General Public License version 2 as | ||
7 | * published by the Free Software Foundation | 8 | * published by the Free Software Foundation | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
Show All 14 Lines | |||||
26 | #include <QUrl> | 27 | #include <QUrl> | ||
27 | 28 | | |||
28 | #include <KActivities/ResourceInstance> | 29 | #include <KActivities/ResourceInstance> | ||
29 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
30 | #include <KRun> | 31 | #include <KRun> | ||
31 | #include <KService> | 32 | #include <KService> | ||
32 | #include <KServiceTypeTrader> | 33 | #include <KServiceTypeTrader> | ||
33 | 34 | | |||
34 | ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args) | 35 | #include "debug.h" | ||
35 | : Plasma::AbstractRunner(parent, args) | 36 | | ||
37 | /** | ||||
38 | * @brief Finds all KServices for a given runner query | ||||
39 | */ | ||||
40 | class ServiceFinder | ||||
36 | { | 41 | { | ||
37 | Q_UNUSED(args) | 42 | public: | ||
43 | ServiceFinder(ServiceRunner *runner) | ||||
44 | : m_runner(runner) | ||||
45 | {} | ||||
38 | 46 | | |||
39 | setObjectName( QStringLiteral("Application" )); | | |||
40 | setPriority(AbstractRunner::HighestPriority); | | |||
41 | 47 | | |||
42 | addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:"))); | 48 | void match(Plasma::RunnerContext &context) | ||
49 | { | ||||
50 | if (!context.isValid()) { | ||||
51 | return; | ||||
43 | } | 52 | } | ||
44 | 53 | | |||
45 | ServiceRunner::~ServiceRunner() | 54 | term = context.query(); | ||
55 | | ||||
56 | matchExectuables(); | ||||
57 | matchNameKeywordAndGenericName(); | ||||
58 | matchCategories(); | ||||
59 | matchJumpListActions(); | ||||
60 | | ||||
61 | context.addMatches(matches); | ||||
62 | } | ||||
63 | | ||||
64 | private: | ||||
65 | | ||||
66 | void seen(const KService::Ptr &service) | ||||
46 | { | 67 | { | ||
68 | m_seen.insert(service->storageId()); | ||||
69 | m_seen.insert(service->exec()); | ||||
47 | } | 70 | } | ||
48 | 71 | | |||
49 | QStringList ServiceRunner::categories() const | 72 | void seen(const KServiceAction &action) | ||
50 | { | 73 | { | ||
51 | QStringList cat; | 74 | m_seen.insert(action.exec()); | ||
52 | cat << i18n("Applications") << i18n("System Settings"); | 75 | } | ||
53 | 76 | | |||
54 | return cat; | 77 | bool hasSeen(const KService::Ptr &service) | ||
78 | { | ||||
79 | return m_seen.contains(service->storageId()) || | ||||
80 | m_seen.contains(service->exec()); | ||||
55 | } | 81 | } | ||
56 | 82 | | |||
57 | QIcon ServiceRunner::categoryIcon(const QString& category) const | 83 | bool hasSeen(const KServiceAction &action) | ||
58 | { | 84 | { | ||
59 | if (category == i18n("Applications")) { | 85 | return m_seen.contains(action.exec()); | ||
60 | return QIcon::fromTheme(QStringLiteral("applications-other")); | | |||
61 | } else if (category == i18n("System Settings")) { | | |||
62 | return QIcon::fromTheme(QStringLiteral("preferences-system")); | | |||
63 | } | 86 | } | ||
64 | 87 | | |||
65 | return Plasma::AbstractRunner::categoryIcon(category); | 88 | void setupMatch(const KService::Ptr &service, Plasma::QueryMatch &match) | ||
89 | { | ||||
90 | const QString name = service->name(); | ||||
91 | | ||||
92 | match.setText(name); | ||||
93 | match.setData(service->storageId()); | ||||
94 | | ||||
95 | if (!service->genericName().isEmpty() && service->genericName() != name) { | ||||
96 | match.setSubtext(service->genericName()); | ||||
97 | } else if (!service->comment().isEmpty()) { | ||||
98 | match.setSubtext(service->comment()); | ||||
66 | } | 99 | } | ||
67 | 100 | | |||
101 | if (!service->icon().isEmpty()) { | ||||
102 | match.setIconName(service->icon()); | ||||
103 | } | ||||
104 | } | ||||
68 | 105 | | |||
69 | void ServiceRunner::match(Plasma::RunnerContext &context) | 106 | void matchExectuables() | ||
70 | { | 107 | { | ||
71 | const QString term = context.query(); | 108 | if (term.length() < 2) { | ||
72 | 109 | return; | |||
73 | QList<Plasma::QueryMatch> matches; | 110 | } | ||
74 | QSet<QString> seen; | | |||
75 | QString query; | | |||
76 | 111 | | |||
77 | if (term.length() > 1) { | | |||
78 | // Search for applications which are executable and case-insensitively match the search term | 112 | // Search for applications which are executable and case-insensitively match the search term | ||
79 | // See http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language | 113 | // See http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language | ||
80 | // if the following is unclear to you. | 114 | // if the following is unclear to you. | ||
81 | query = QStringLiteral("exist Exec and ('%1' =~ Name)").arg(term); | 115 | query = QStringLiteral("exist Exec and ('%1' =~ Name)").arg(term); | ||
82 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | 116 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | ||
83 | 117 | | |||
84 | if (!services.isEmpty()) { | 118 | if (services.isEmpty()) { | ||
85 | //qDebug() << service->name() << "is an exact match!" << service->storageId() << service->exec(); | 119 | return; | ||
120 | } | ||||
121 | | ||||
86 | foreach (const KService::Ptr &service, services) { | 122 | foreach (const KService::Ptr &service, services) { | ||
87 | if (!service->noDisplay() && service->property(QStringLiteral("NotShowIn"), QVariant::String) != "KDE") { | 123 | qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); | ||
88 | Plasma::QueryMatch match(this); | 124 | if (service->noDisplay() || service->property(QStringLiteral("NotShowIn"), QVariant::String) == "KDE") { | ||
broulik: isnt NotShowIn a list property? Doesn't KService have a getter for that or even take that into… | |||||
something to consider in a follow up, for now I'd like to get the refactor landed. e.g. if (!service->isApplication()) { further down also seems weird considering we already queried for applications specifically. sitter: something to consider in a follow up, for now I'd like to get the refactor landed.
e.g. `if (! | |||||
125 | continue; | ||||
126 | } | ||||
127 | Plasma::QueryMatch match(m_runner); | ||||
89 | match.setType(Plasma::QueryMatch::ExactMatch); | 128 | match.setType(Plasma::QueryMatch::ExactMatch); | ||
90 | setupMatch(service, match); | 129 | setupMatch(service, match); | ||
91 | match.setRelevance(1); | 130 | match.setRelevance(1); | ||
92 | matches << match; | 131 | matches << match; | ||
93 | seen.insert(service->storageId()); | 132 | seen(service); | ||
94 | seen.insert(service->exec()); | | |||
95 | } | 133 | } | ||
96 | } | 134 | } | ||
97 | } | | |||
98 | } | | |||
99 | | ||||
100 | if (!context.isValid()) { | | |||
101 | return; | | |||
102 | } | | |||
103 | 135 | | |||
136 | void matchNameKeywordAndGenericName() | ||||
137 | { | ||||
104 | // If the term length is < 3, no real point searching the Keywords and GenericName | 138 | // If the term length is < 3, no real point searching the Keywords and GenericName | ||
105 | if (term.length() < 3) { | 139 | if (term.length() < 3) { | ||
106 | query = QStringLiteral("exist Exec and ( (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) )").arg(term); | 140 | query = QStringLiteral("exist Exec and ( (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) )").arg(term); | ||
107 | } else { | 141 | } else { | ||
108 | // Search for applications which are executable and the term case-insensitive matches any of | 142 | // Search for applications which are executable and the term case-insensitive matches any of | ||
109 | // * a substring of one of the keywords | 143 | // * a substring of one of the keywords | ||
110 | // * a substring of the GenericName field | 144 | // * a substring of the GenericName field | ||
111 | // * a substring of the Name field | 145 | // * a substring of the Name field | ||
112 | // Note that before asking for the content of e.g. Keywords and GenericName we need to ask if | 146 | // Note that before asking for the content of e.g. Keywords and GenericName we need to ask if | ||
113 | // they exist to prevent a tree evaluation error if they are not defined. | 147 | // they exist to prevent a tree evaluation error if they are not defined. | ||
114 | query = QStringLiteral("exist Exec and ( (exist Keywords and '%1' ~subin Keywords) or (exist GenericName and '%1' ~~ GenericName) or (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) or (exist Comment and '%1' ~~ Comment) )").arg(term); | 148 | query = QStringLiteral("exist Exec and ( (exist Keywords and '%1' ~subin Keywords) or (exist GenericName and '%1' ~~ GenericName) or (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) or (exist Comment and '%1' ~~ Comment) )").arg(term); | ||
115 | } | 149 | } | ||
116 | 150 | | |||
117 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | 151 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | ||
118 | services += KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), query); | 152 | services += KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), query); | ||
119 | 153 | | |||
120 | //qDebug() << "got " << services.count() << " services from " << query; | 154 | qCDebug(RUNNER_SERVICES) << "got " << services.count() << " services from " << query; | ||
121 | foreach (const KService::Ptr &service, services) { | 155 | foreach (const KService::Ptr &service, services) { | ||
122 | if (service->noDisplay()) { | 156 | if (service->noDisplay()) { | ||
123 | continue; | 157 | continue; | ||
124 | } | 158 | } | ||
125 | 159 | | |||
126 | const QString id = service->storageId(); | 160 | const QString id = service->storageId(); | ||
127 | const QString name = service->desktopEntryName(); | 161 | const QString name = service->desktopEntryName(); | ||
128 | const QString exec = service->exec(); | 162 | const QString exec = service->exec(); | ||
129 | 163 | | |||
130 | if (seen.contains(id) || seen.contains(exec)) { | 164 | if (hasSeen(service)) { | ||
131 | //qDebug() << "already seen" << id << exec; | | |||
132 | continue; | 165 | continue; | ||
133 | } | 166 | } | ||
167 | seen(service); | ||||
134 | 168 | | |||
135 | //qDebug() << "haven't seen" << id << "so processing now"; | 169 | Plasma::QueryMatch match(m_runner); | ||
136 | seen.insert(id); | | |||
137 | seen.insert(exec); | | |||
138 | | ||||
139 | Plasma::QueryMatch match(this); | | |||
140 | match.setType(Plasma::QueryMatch::PossibleMatch); | 170 | match.setType(Plasma::QueryMatch::PossibleMatch); | ||
141 | setupMatch(service, match); | 171 | setupMatch(service, match); | ||
142 | qreal relevance(0.6); | 172 | qreal relevance(0.6); | ||
143 | 173 | | |||
144 | // If the term was < 3 chars and NOT at the beginning of the App's name or Exec, then | 174 | // If the term was < 3 chars and NOT at the beginning of the App's name or Exec, then | ||
145 | // chances are the user doesn't want that app. | 175 | // chances are the user doesn't want that app. | ||
146 | if (term.length() < 3) { | 176 | if (term.length() < 3) { | ||
147 | if (name.startsWith(term) || exec.startsWith(term)) { | 177 | if (name.startsWith(term) || exec.startsWith(term)) { | ||
Show All 23 Lines | 200 | } else if (service->comment().contains(term, Qt::CaseInsensitive)) { | |||
171 | relevance = 0.5; | 201 | relevance = 0.5; | ||
172 | 202 | | |||
173 | if (service->comment().startsWith(term, Qt::CaseInsensitive)) { | 203 | if (service->comment().startsWith(term, Qt::CaseInsensitive)) { | ||
174 | relevance += 0.05; | 204 | relevance += 0.05; | ||
175 | } | 205 | } | ||
176 | } | 206 | } | ||
177 | 207 | | |||
178 | if (service->categories().contains(QStringLiteral("KDE")) || service->serviceTypes().contains(QStringLiteral("KCModule"))) { | 208 | if (service->categories().contains(QStringLiteral("KDE")) || service->serviceTypes().contains(QStringLiteral("KCModule"))) { | ||
179 | //qDebug() << "found a kde thing" << id << match.subtext() << relevance; | 209 | qCDebug(RUNNER_SERVICES) << "found a kde thing" << id << match.subtext() << relevance; | ||
180 | if (id.startsWith(QLatin1String("kde-"))) { | 210 | if (id.startsWith(QLatin1String("kde-"))) { | ||
181 | //qDebug() << "old" << service->type(); | 211 | qCDebug(RUNNER_SERVICES) << "old" << !service->isApplication(); | ||
182 | if (!service->isApplication()) { | 212 | if (!service->isApplication()) { | ||
183 | // avoid showing old kcms and what not | 213 | // avoid showing old kcms and what not | ||
184 | continue; | 214 | continue; | ||
185 | } | 215 | } | ||
186 | 216 | | |||
187 | // This is an older version, let's disambiguate it | 217 | // This is an older version, let's disambiguate it | ||
188 | QString subtext(QStringLiteral("KDE3")); | 218 | QString subtext(QStringLiteral("KDE3")); | ||
189 | 219 | | |||
190 | if (!match.subtext().isEmpty()) { | 220 | if (!match.subtext().isEmpty()) { | ||
191 | subtext.append(", " + match.subtext()); | 221 | subtext.append(", " + match.subtext()); | ||
192 | } | 222 | } | ||
193 | 223 | | |||
194 | match.setSubtext(subtext); | 224 | match.setSubtext(subtext); | ||
195 | } else { | 225 | } else { | ||
196 | relevance += .09; | 226 | relevance += .09; | ||
197 | } | 227 | } | ||
198 | } | 228 | } | ||
199 | 229 | | |||
200 | //qDebug() << service->name() << "is this relevant:" << relevance; | 230 | qCDebug(RUNNER_SERVICES) << service->name() << "is this relevant:" << relevance; | ||
201 | match.setRelevance(relevance); | 231 | match.setRelevance(relevance); | ||
202 | if (service->serviceTypes().contains(QStringLiteral("KCModule"))) { | 232 | if (service->serviceTypes().contains(QStringLiteral("KCModule"))) { | ||
203 | match.setMatchCategory(i18n("System Settings")); | 233 | match.setMatchCategory(i18n("System Settings")); | ||
204 | } | 234 | } | ||
205 | matches << match; | 235 | matches << match; | ||
206 | } | 236 | } | ||
237 | } | ||||
207 | 238 | | |||
239 | void matchCategories() | ||||
240 | { | ||||
208 | //search for applications whose categories contains the query | 241 | //search for applications whose categories contains the query | ||
209 | query = QStringLiteral("exist Exec and (exist Categories and '%1' ~subin Categories)").arg(term); | 242 | query = QStringLiteral("exist Exec and (exist Categories and '%1' ~subin Categories)").arg(term); | ||
210 | services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | 243 | auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | ||
211 | 244 | | |||
212 | //qDebug() << service->name() << "is an exact match!" << service->storageId() << service->exec(); | | |||
213 | foreach (const KService::Ptr &service, services) { | 245 | foreach (const KService::Ptr &service, services) { | ||
246 | qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); | ||||
214 | if (!service->noDisplay()) { | 247 | if (!service->noDisplay()) { | ||
215 | QString id = service->storageId(); | | |||
216 | QString exec = service->exec(); | | |||
217 | if (seen.contains(id) || seen.contains(exec)) { | | |||
218 | //qDebug() << "already seen" << id << exec; | | |||
219 | continue; | 248 | continue; | ||
220 | } | 249 | } | ||
221 | Plasma::QueryMatch match(this); | 250 | | ||
251 | if (hasSeen(service)) { | ||||
252 | continue; | ||||
253 | } | ||||
254 | Plasma::QueryMatch match(m_runner); | ||||
222 | match.setType(Plasma::QueryMatch::PossibleMatch); | 255 | match.setType(Plasma::QueryMatch::PossibleMatch); | ||
223 | setupMatch(service, match); | 256 | setupMatch(service, match); | ||
224 | 257 | | |||
225 | qreal relevance = 0.6; | 258 | qreal relevance = 0.6; | ||
226 | if (service->categories().contains(QStringLiteral("X-KDE-More")) || | 259 | if (service->categories().contains(QStringLiteral("X-KDE-More")) || | ||
227 | !service->showInCurrentDesktop()) { | 260 | !service->showInCurrentDesktop()) { | ||
228 | relevance = 0.5; | 261 | relevance = 0.5; | ||
229 | } | 262 | } | ||
230 | 263 | | |||
231 | if (service->isApplication()) { | 264 | if (service->isApplication()) { | ||
232 | relevance += .04; | 265 | relevance += .04; | ||
233 | } | 266 | } | ||
234 | 267 | | |||
235 | match.setRelevance(relevance); | 268 | match.setRelevance(relevance); | ||
236 | matches << match; | 269 | matches << match; | ||
237 | } | 270 | } | ||
238 | } | 271 | } | ||
239 | 272 | | |||
240 | // search for jump list actions | 273 | void matchJumpListActions() | ||
241 | if (term.length() >= 3) { | 274 | { | ||
275 | if (term.length() < 3) { | ||||
276 | return; | ||||
277 | } | ||||
278 | | ||||
242 | query = QStringLiteral("exist Actions"); // doesn't work | 279 | query = QStringLiteral("exist Actions"); // doesn't work | ||
243 | services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query); | 280 | auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query); | ||
244 | 281 | | |||
245 | foreach (const KService::Ptr &service, services) { | 282 | foreach (const KService::Ptr &service, services) { | ||
246 | if (service->noDisplay()) { | 283 | if (service->noDisplay()) { | ||
247 | continue; | 284 | continue; | ||
248 | } | 285 | } | ||
249 | 286 | | |||
250 | foreach (const KServiceAction &action, service->actions()) { | 287 | foreach (const KServiceAction &action, service->actions()) { | ||
251 | if (action.text().isEmpty() || action.exec().isEmpty() || seen.contains(action.exec())) { | 288 | if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) { | ||
252 | continue; | 289 | continue; | ||
253 | } | 290 | } | ||
291 | seen(action); | ||||
292 | | ||||
254 | 293 | | |||
255 | if (!action.text().contains(term, Qt::CaseInsensitive)) { | 294 | if (!action.text().contains(term, Qt::CaseInsensitive)) { | ||
256 | continue; | 295 | continue; | ||
257 | } | 296 | } | ||
258 | 297 | | |||
259 | Plasma::QueryMatch match(this); | 298 | Plasma::QueryMatch match(m_runner); | ||
260 | match.setType(Plasma::QueryMatch::HelperMatch); | 299 | match.setType(Plasma::QueryMatch::HelperMatch); | ||
261 | if (!action.icon().isEmpty()) { | 300 | if (!action.icon().isEmpty()) { | ||
262 | match.setIconName(action.icon()); | 301 | match.setIconName(action.icon()); | ||
263 | } else { | 302 | } else { | ||
264 | match.setIconName(service->icon()); | 303 | match.setIconName(service->icon()); | ||
265 | } | 304 | } | ||
266 | match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)", | 305 | match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)", | ||
267 | "%1 - %2", action.text(), service->name())); | 306 | "%1 - %2", action.text(), service->name())); | ||
268 | match.setData(action.exec()); | 307 | match.setData(action.exec()); | ||
269 | 308 | | |||
270 | qreal relevance = 0.5; | 309 | qreal relevance = 0.5; | ||
271 | if (action.text().startsWith(term, Qt::CaseInsensitive)) { | 310 | if (action.text().startsWith(term, Qt::CaseInsensitive)) { | ||
272 | relevance += 0.05; | 311 | relevance += 0.05; | ||
273 | } | 312 | } | ||
274 | 313 | | |||
275 | match.setRelevance(relevance); | 314 | match.setRelevance(relevance); | ||
276 | 315 | | |||
277 | matches << match; | 316 | matches << match; | ||
278 | } | 317 | } | ||
279 | } | 318 | } | ||
280 | } | 319 | } | ||
281 | 320 | | |||
282 | //context.addMatches(term, matches); | 321 | ServiceRunner *m_runner; | ||
283 | context.addMatches(matches); | 322 | QSet<QString> m_seen; | ||
323 | | ||||
324 | QList<Plasma::QueryMatch> matches; | ||||
325 | QString query; | ||||
326 | QString term; | ||||
327 | }; | ||||
328 | | ||||
329 | ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args) | ||||
330 | : Plasma::AbstractRunner(parent, args) | ||||
331 | { | ||||
332 | Q_UNUSED(args) | ||||
333 | | ||||
334 | setObjectName( QStringLiteral("Application" )); | ||||
335 | setPriority(AbstractRunner::HighestPriority); | ||||
336 | | ||||
337 | addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:"))); | ||||
338 | } | ||||
339 | | ||||
340 | ServiceRunner::~ServiceRunner() | ||||
341 | { | ||||
342 | } | ||||
343 | | ||||
344 | QStringList ServiceRunner::categories() const | ||||
345 | { | ||||
346 | QStringList cat; | ||||
347 | cat << i18n("Applications") << i18n("System Settings"); | ||||
348 | | ||||
349 | return cat; | ||||
350 | } | ||||
351 | | ||||
352 | QIcon ServiceRunner::categoryIcon(const QString& category) const | ||||
353 | { | ||||
354 | if (category == i18n("Applications")) { | ||||
355 | return QIcon::fromTheme(QStringLiteral("applications-other")); | ||||
356 | } else if (category == i18n("System Settings")) { | ||||
357 | return QIcon::fromTheme(QStringLiteral("preferences-system")); | ||||
358 | } | ||||
359 | | ||||
360 | return Plasma::AbstractRunner::categoryIcon(category); | ||||
361 | } | ||||
362 | | ||||
363 | | ||||
364 | void ServiceRunner::match(Plasma::RunnerContext &context) | ||||
365 | { | ||||
366 | // This helper class aids in keeping state across numerous | ||||
367 | // different queries that together form the matches set. | ||||
368 | ServiceFinder finder(this); | ||||
369 | finder.match(context); | ||||
284 | } | 370 | } | ||
285 | 371 | | |||
286 | void ServiceRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) | 372 | void ServiceRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) | ||
287 | { | 373 | { | ||
288 | Q_UNUSED(context); | 374 | Q_UNUSED(context); | ||
289 | if (match.type() == Plasma::QueryMatch::HelperMatch) { // Jump List Action | 375 | if (match.type() == Plasma::QueryMatch::HelperMatch) { // Jump List Action | ||
290 | KRun::run(match.data().toString(), {}, nullptr); | 376 | KRun::run(match.data().toString(), {}, nullptr); | ||
291 | return; | 377 | return; | ||
292 | } | 378 | } | ||
293 | 379 | | |||
294 | KService::Ptr service = KService::serviceByStorageId(match.data().toString()); | 380 | KService::Ptr service = KService::serviceByStorageId(match.data().toString()); | ||
295 | if (service) { | 381 | if (service) { | ||
296 | KActivities::ResourceInstance::notifyAccessed( | 382 | KActivities::ResourceInstance::notifyAccessed( | ||
297 | QUrl(QStringLiteral("applications:") + service->storageId()), | 383 | QUrl(QStringLiteral("applications:") + service->storageId()), | ||
298 | QStringLiteral("org.kde.krunner") | 384 | QStringLiteral("org.kde.krunner") | ||
299 | ); | 385 | ); | ||
300 | 386 | | |||
301 | KRun::runService(*service, {}, nullptr, true); | 387 | KRun::runService(*service, {}, nullptr, true); | ||
302 | } | 388 | } | ||
303 | } | 389 | } | ||
304 | 390 | | |||
305 | void ServiceRunner::setupMatch(const KService::Ptr &service, Plasma::QueryMatch &match) | | |||
306 | { | | |||
307 | const QString name = service->name(); | | |||
308 | | ||||
309 | match.setText(name); | | |||
310 | match.setData(service->storageId()); | | |||
311 | | ||||
312 | if (!service->genericName().isEmpty() && service->genericName() != name) { | | |||
313 | match.setSubtext(service->genericName()); | | |||
314 | } else if (!service->comment().isEmpty()) { | | |||
315 | match.setSubtext(service->comment()); | | |||
316 | } | | |||
317 | | ||||
318 | if (!service->icon().isEmpty()) { | | |||
319 | match.setIconName(service->icon()); | | |||
320 | } | | |||
321 | } | | |||
322 | | ||||
323 | QMimeData * ServiceRunner::mimeDataForMatch(const Plasma::QueryMatch &match) | 391 | QMimeData * ServiceRunner::mimeDataForMatch(const Plasma::QueryMatch &match) | ||
324 | { | 392 | { | ||
325 | KService::Ptr service = KService::serviceByStorageId(match.data().toString()); | 393 | KService::Ptr service = KService::serviceByStorageId(match.data().toString()); | ||
326 | if (service) { | 394 | if (service) { | ||
327 | QMimeData * result = new QMimeData(); | 395 | QMimeData * result = new QMimeData(); | ||
328 | QList<QUrl> urls; | 396 | QList<QUrl> urls; | ||
329 | urls << QUrl::fromLocalFile(service->entryPath()); | 397 | urls << QUrl::fromLocalFile(service->entryPath()); | ||
330 | qDebug() << urls; | 398 | qCDebug(RUNNER_SERVICES) << urls; | ||
331 | result->setUrls(urls); | 399 | result->setUrls(urls); | ||
332 | return result; | 400 | return result; | ||
333 | } | 401 | } | ||
334 | 402 | | |||
335 | return 0; | 403 | return 0; | ||
336 | } | 404 | } | ||
337 | 405 | | |||
338 | K_EXPORT_PLASMA_RUNNER(services, ServiceRunner) | 406 | K_EXPORT_PLASMA_RUNNER(services, ServiceRunner) | ||
339 | 407 | | |||
340 | #include "servicerunner.moc" | 408 | #include "servicerunner.moc" | ||
341 | |
isnt NotShowIn a list property? Doesn't KService have a getter for that or even take that into account in noDisplay()?