Changeset View
Changeset View
Standalone View
Standalone View
runners/services/servicerunner.cpp
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 76 | private: | |||
---|---|---|---|---|---|
100 | bool disqualify(const KService::Ptr &service) | 100 | bool disqualify(const KService::Ptr &service) | ||
101 | { | 101 | { | ||
102 | auto ret = hasSeen(service) || service->noDisplay(); | 102 | auto ret = hasSeen(service) || service->noDisplay(); | ||
103 | qCDebug(RUNNER_SERVICES) << service->name() << "disqualified?" << ret; | 103 | qCDebug(RUNNER_SERVICES) << service->name() << "disqualified?" << ret; | ||
104 | seen(service); | 104 | seen(service); | ||
105 | return ret; | 105 | return ret; | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | qreal increaseMatchRelavance(const KService::Ptr &service, QVector<QStringRef> &strList, QString category) | 108 | qreal increaseMatchRelavance(const KService::Ptr &service, const QVector<QStringRef> &strList, const QString &category) | ||
109 | { | 109 | { | ||
110 | //Increment the relevance based on all the words (other than the first) of the query list | 110 | //Increment the relevance based on all the words (other than the first) of the query list | ||
111 | qreal relevanceIncrement = 0; | 111 | qreal relevanceIncrement = 0; | ||
112 | 112 | | |||
113 | for(int i=1; i<strList.size(); i++) | 113 | for(int i = 1; i < strList.size(); ++i) { | ||
114 | { | 114 | const auto &str = strList.at(i); | ||
broulik: Perhaps use `.at(i)` | |||||
115 | if (category == QLatin1String("Name")) { | 115 | if (category == QLatin1String("Name")) { | ||
116 | if (service->name().contains(strList[i], Qt::CaseInsensitive)) { | 116 | if (service->name().contains(str, Qt::CaseInsensitive)) { | ||
117 | relevanceIncrement += 0.01; | 117 | relevanceIncrement += 0.01; | ||
118 | } | 118 | } | ||
119 | } else if (category == QLatin1String("GenericName")) { | 119 | } else if (category == QLatin1String("GenericName")) { | ||
120 | if (service->genericName().contains(strList[i], Qt::CaseInsensitive)) { | 120 | if (service->genericName().contains(str, Qt::CaseInsensitive)) { | ||
121 | relevanceIncrement += 0.01; | 121 | relevanceIncrement += 0.01; | ||
122 | } | 122 | } | ||
123 | } else if (category == QLatin1String("Exec")) { | 123 | } else if (category == QLatin1String("Exec")) { | ||
124 | if (service->exec().contains(strList[i], Qt::CaseInsensitive)) { | 124 | if (service->exec().contains(str, Qt::CaseInsensitive)) { | ||
125 | relevanceIncrement += 0.01; | 125 | relevanceIncrement += 0.01; | ||
126 | } | 126 | } | ||
127 | } else if (category == QLatin1String("Comment")) { | 127 | } else if (category == QLatin1String("Comment")) { | ||
128 | if (service->comment().contains(strList[i], Qt::CaseInsensitive)) { | 128 | if (service->comment().contains(str, 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 | | |||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Line(s) | 327 | { | |||
332 | query = QStringLiteral("exist Actions"); // doesn't work | 332 | query = QStringLiteral("exist Actions"); // doesn't work | ||
333 | const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query); | 333 | const auto services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query); | ||
334 | 334 | | |||
335 | for (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 | for (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 All 23 Lines | |||||
372 | } | 373 | } | ||
373 | 374 | | |||
374 | ServiceRunner *m_runner; | 375 | ServiceRunner *m_runner; | ||
375 | QSet<QString> m_seen; | 376 | QSet<QString> m_seen; | ||
376 | 377 | | |||
377 | QList<Plasma::QueryMatch> matches; | 378 | QList<Plasma::QueryMatch> matches; | ||
378 | QString query; | 379 | QString query; | ||
379 | QString term; | 380 | QString term; | ||
380 | int weightedTermLength; | 381 | int weightedTermLength = -1; | ||
381 | }; | 382 | }; | ||
382 | 383 | | |||
383 | ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args) | 384 | ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args) | ||
384 | : Plasma::AbstractRunner(parent, args) | 385 | : Plasma::AbstractRunner(parent, args) | ||
385 | { | 386 | { | ||
386 | Q_UNUSED(args) | 387 | Q_UNUSED(args) | ||
387 | 388 | | |||
388 | setObjectName( QStringLiteral("Application" )); | 389 | setObjectName( QStringLiteral("Application" )); | ||
389 | setPriority(AbstractRunner::HighestPriority); | 390 | setPriority(AbstractRunner::HighestPriority); | ||
390 | 391 | | |||
391 | addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:"))); | 392 | addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds applications whose name or description match :q:"))); | ||
392 | } | 393 | } | ||
393 | 394 | | |||
394 | ServiceRunner::~ServiceRunner() | 395 | ServiceRunner::~ServiceRunner() = default; | ||
395 | { | | |||
396 | } | | |||
397 | 396 | | |||
398 | QStringList ServiceRunner::categories() const | 397 | QStringList ServiceRunner::categories() const | ||
399 | { | 398 | { | ||
400 | QStringList cat; | 399 | QStringList cat; | ||
401 | cat << i18n("Applications") << i18n("System Settings"); | 400 | cat << i18n("Applications") << i18n("System Settings"); | ||
402 | 401 | | |||
403 | return cat; | 402 | return cat; | ||
404 | } | 403 | } | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
450 | { | 449 | { | ||
451 | KService::Ptr service = KService::serviceByStorageId(match.data().toString()); | 450 | KService::Ptr service = KService::serviceByStorageId(match.data().toString()); | ||
452 | if (!service) { | 451 | if (!service) { | ||
453 | return nullptr; | 452 | return nullptr; | ||
454 | } | 453 | } | ||
455 | 454 | | |||
456 | QString path = service->entryPath(); | 455 | QString path = service->entryPath(); | ||
457 | if (!QDir::isAbsolutePath(path)) { | 456 | if (!QDir::isAbsolutePath(path)) { | ||
458 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/") + path); | 457 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kservices5/") + path); | ||
459 | } | 458 | } | ||
460 | 459 | | |||
461 | if (path.isEmpty()) { | 460 | if (path.isEmpty()) { | ||
462 | return nullptr; | 461 | return nullptr; | ||
463 | } | 462 | } | ||
464 | 463 | | |||
465 | QMimeData *data = new QMimeData(); | 464 | auto *data = new QMimeData(); | ||
broulik: Keep the `*` :p | |||||
466 | data->setUrls(QList<QUrl>{QUrl::fromLocalFile(path)}); | 465 | data->setUrls(QList<QUrl>{QUrl::fromLocalFile(path)}); | ||
467 | return data; | 466 | return data; | ||
468 | } | 467 | } | ||
469 | 468 | | |||
470 | K_EXPORT_PLASMA_RUNNER(services, ServiceRunner) | 469 | K_EXPORT_PLASMA_RUNNER(services, ServiceRunner) | ||
471 | 470 | | |||
472 | #include "servicerunner.moc" | 471 | #include "servicerunner.moc" |
Perhaps use .at(i)