Changeset View
Changeset View
Standalone View
Standalone View
runners/services/servicerunner.cpp
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 128 | if (service->comment().contains(strList[i], Qt::CaseInsensitive)) { | |||
---|---|---|---|---|---|
129 | relevanceIncrement += 0.01; | 129 | relevanceIncrement += 0.01; | ||
130 | } | 130 | } | ||
131 | } | 131 | } | ||
132 | } | 132 | } | ||
133 | 133 | | |||
134 | return relevanceIncrement; | 134 | return relevanceIncrement; | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | QString generateQuery(QVector<QStringRef> &strList) | 137 | QString generateQuery(const QVector<QStringRef> &strList) | ||
138 | { | 138 | { | ||
139 | QString keywordTemplate = QStringLiteral("exist Keywords"); | 139 | QString keywordTemplate = QStringLiteral("exist Keywords"); | ||
140 | QString genericNameTemplate = QStringLiteral("exist GenericName"); | 140 | QString genericNameTemplate = QStringLiteral("exist GenericName"); | ||
141 | QString nameTemplate = QStringLiteral("exist Name"); | 141 | QString nameTemplate = QStringLiteral("exist Name"); | ||
142 | QString commentTemplate = QStringLiteral("exist Comment"); | 142 | QString commentTemplate = QStringLiteral("exist Comment"); | ||
143 | 143 | | |||
144 | // Search for applications which are executable and the term case-insensitive matches any of | 144 | // Search for applications which are executable and the term case-insensitive matches any of | ||
145 | // * a substring of one of the keywords | 145 | // * a substring of one of the keywords | ||
146 | // * a substring of the GenericName field | 146 | // * a substring of the GenericName field | ||
147 | // * a substring of the Name field | 147 | // * a substring of the Name field | ||
148 | // Note that before asking for the content of e.g. Keywords and GenericName we need to ask if | 148 | // Note that before asking for the content of e.g. Keywords and GenericName we need to ask if | ||
149 | // they exist to prevent a tree evaluation error if they are not defined. | 149 | // they exist to prevent a tree evaluation error if they are not defined. | ||
150 | foreach (QStringRef str, strList) | 150 | for (QStringRef str : strList) | ||
151 | { | 151 | { | ||
152 | keywordTemplate += QStringLiteral(" and '%1' ~subin Keywords").arg(str.toString()); | 152 | keywordTemplate += QStringLiteral(" and '%1' ~subin Keywords").arg(str.toString()); | ||
153 | genericNameTemplate += QStringLiteral(" and '%1' ~~ GenericName").arg(str.toString()); | 153 | genericNameTemplate += QStringLiteral(" and '%1' ~~ GenericName").arg(str.toString()); | ||
154 | nameTemplate += QStringLiteral(" and '%1' ~~ Name").arg(str.toString()); | 154 | nameTemplate += QStringLiteral(" and '%1' ~~ Name").arg(str.toString()); | ||
155 | commentTemplate += QStringLiteral(" and '%1' ~~ Comment").arg(str.toString()); | 155 | commentTemplate += QStringLiteral(" and '%1' ~~ Comment").arg(str.toString()); | ||
156 | } | 156 | } | ||
157 | 157 | | |||
158 | QString finalQuery = QStringLiteral("exist Exec and ( (%1) or (%2) or (%3) or ('%4' ~~ Exec) or (%5) )") | 158 | QString finalQuery = QStringLiteral("exist Exec and ( (%1) or (%2) or (%3) or ('%4' ~~ Exec) or (%5) )") | ||
Show All 26 Lines | 184 | { | |||
185 | if (weightedTermLength < 2) { | 185 | if (weightedTermLength < 2) { | ||
186 | return; | 186 | return; | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | // Search for applications which are executable and case-insensitively match the search term | 189 | // Search for applications which are executable and case-insensitively match the search term | ||
190 | // See http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language | 190 | // See http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language | ||
191 | // if the following is unclear to you. | 191 | // if the following is unclear to you. | ||
192 | query = QStringLiteral("exist Exec and ('%1' =~ Name)").arg(term); | 192 | query = QStringLiteral("exist Exec and ('%1' =~ Name)").arg(term); | ||
193 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | 193 | const KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | ||
194 | 194 | | |||
195 | if (services.isEmpty()) { | 195 | if (services.isEmpty()) { | ||
196 | return; | 196 | return; | ||
197 | } | 197 | } | ||
198 | 198 | | |||
199 | foreach (const KService::Ptr &service, services) { | 199 | for (const KService::Ptr &service : services) { | ||
200 | qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); | 200 | qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); | ||
201 | if (disqualify(service)) { | 201 | if (disqualify(service)) { | ||
202 | continue; | 202 | continue; | ||
203 | } | 203 | } | ||
204 | Plasma::QueryMatch match(m_runner); | 204 | Plasma::QueryMatch match(m_runner); | ||
205 | match.setType(Plasma::QueryMatch::ExactMatch); | 205 | match.setType(Plasma::QueryMatch::ExactMatch); | ||
206 | setupMatch(service, match); | 206 | setupMatch(service, match); | ||
207 | match.setRelevance(1); | 207 | match.setRelevance(1); | ||
Show All 13 Lines | 220 | } else { | |||
221 | //Match using subsequences (Bug: 262837) | 221 | //Match using subsequences (Bug: 262837) | ||
222 | query = generateQuery(queryList); | 222 | query = generateQuery(queryList); | ||
223 | } | 223 | } | ||
224 | 224 | | |||
225 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | 225 | KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | ||
226 | services += KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), query); | 226 | services += KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), query); | ||
227 | 227 | | |||
228 | qCDebug(RUNNER_SERVICES) << "got " << services.count() << " services from " << query; | 228 | qCDebug(RUNNER_SERVICES) << "got " << services.count() << " services from " << query; | ||
229 | foreach (const KService::Ptr &service, services) { | 229 | for (const KService::Ptr &service : qAsConst(services)) { | ||
230 | if (disqualify(service)) { | 230 | if (disqualify(service)) { | ||
231 | continue; | 231 | continue; | ||
232 | } | 232 | } | ||
233 | 233 | | |||
234 | const QString id = service->storageId(); | 234 | const QString id = service->storageId(); | ||
235 | const QString name = service->desktopEntryName(); | 235 | const QString name = service->desktopEntryName(); | ||
236 | const QString exec = service->exec(); | 236 | const QString exec = service->exec(); | ||
237 | 237 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
291 | matches << match; | 291 | matches << match; | ||
292 | } | 292 | } | ||
293 | } | 293 | } | ||
294 | 294 | | |||
295 | void matchCategories() | 295 | void matchCategories() | ||
296 | { | 296 | { | ||
297 | //search for applications whose categories contains the query | 297 | //search for applications whose categories contains the query | ||
298 | query = QStringLiteral("exist Exec and (exist Categories and '%1' ~subin Categories)").arg(term); | 298 | query = QStringLiteral("exist Exec and (exist Categories and '%1' ~subin Categories)").arg(term); | ||
299 | auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | 299 | const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), query); | ||
300 | 300 | | |||
301 | foreach (const KService::Ptr &service, services) { | 301 | for (const KService::Ptr &service : services) { | ||
302 | qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); | 302 | qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); | ||
303 | if (disqualify(service)) { | 303 | if (disqualify(service)) { | ||
304 | continue; | 304 | continue; | ||
305 | } | 305 | } | ||
306 | 306 | | |||
307 | Plasma::QueryMatch match(m_runner); | 307 | Plasma::QueryMatch match(m_runner); | ||
308 | match.setType(Plasma::QueryMatch::PossibleMatch); | 308 | match.setType(Plasma::QueryMatch::PossibleMatch); | ||
309 | setupMatch(service, match); | 309 | setupMatch(service, match); | ||
Show All 15 Lines | |||||
325 | 325 | | |||
326 | void matchJumpListActions() | 326 | void matchJumpListActions() | ||
327 | { | 327 | { | ||
328 | if (weightedTermLength < 3) { | 328 | if (weightedTermLength < 3) { | ||
329 | return; | 329 | return; | ||
330 | } | 330 | } | ||
331 | 331 | | |||
332 | query = QStringLiteral("exist Actions"); // doesn't work | 332 | query = QStringLiteral("exist Actions"); // doesn't work | ||
333 | auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query); | 333 | const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query); | ||
334 | 334 | | |||
335 | foreach (const KService::Ptr &service, services) { | 335 | for (const KService::Ptr &service: services) { | ||
336 | if (service->noDisplay()) { | 336 | if (service->noDisplay()) { | ||
337 | continue; | 337 | continue; | ||
338 | } | 338 | } | ||
339 | 339 | | |||
340 | foreach (const KServiceAction &action, service->actions()) { | 340 | const auto actions = service->actions(); | ||
341 | for (const KServiceAction &action : actions) { | ||||
341 | if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) { | 342 | if (action.text().isEmpty() || action.exec().isEmpty() || hasSeen(action)) { | ||
342 | continue; | 343 | continue; | ||
343 | } | 344 | } | ||
344 | seen(action); | 345 | seen(action); | ||
345 | 346 | | |||
346 | const int matchIndex = action.text().indexOf(term, 0, Qt::CaseInsensitive); | 347 | const int matchIndex = action.text().indexOf(term, 0, Qt::CaseInsensitive); | ||
347 | if (matchIndex < 0) { | 348 | if (matchIndex < 0) { | ||
348 | continue; | 349 | continue; | ||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |