Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:epopov:branches:openSUSE:Factory
plasma6-workspace
2003-krunner.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2003-krunner.patch of Package plasma6-workspace
diff --git a/applets/kicker/plugin/runnermatchesmodel.cpp b/applets/kicker/plugin/runnermatchesmodel.cpp index 39bd88047eb45dfe00007d35b46699b167259e23..206fd4d897b87a14ea7f87ad95a69855b7035dc4 100644 --- a/applets/kicker/plugin/runnermatchesmodel.cpp +++ b/applets/kicker/plugin/runnermatchesmodel.cpp @@ -80,6 +80,8 @@ QVariant RunnerMatchesModel::data(const QModelIndex &index, int role) const } return match.icon(); + } else if (role == Kicker::GroupRole) { + return KRunner::ResultsModel::data(index, CategoryRole); } else if (role == Kicker::DescriptionRole) { return match.subtext(); } else if (role == Kicker::FavoriteIdRole) { diff --git a/krunner/view.cpp b/krunner/view.cpp index 5546331a04120294ab499b490c9000546518ce34..7b8482b732a5ca7fd9955f3c512ec41373ac573a 100644 --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -49,10 +49,10 @@ View::View(PlasmaQuick::SharedQmlEngine *engine, QWindow *) setTitle(i18n("KRunner")); m_config = KConfigGroup(KSharedConfig::openConfig(), u"General"_s); - m_stateData = KSharedConfig::openConfig(u"krunnerstaterc"_s, // + m_stateData = KSharedConfig::openConfig(u"krunner/krunnerstaterc"_s, // KConfig::NoGlobals, QStandardPaths::GenericDataLocation) - ->group(u"General"_s); + ->group(u"PlasmaRunnerManager"_s); m_configWatcher = KConfigWatcher::create(KSharedConfig::openConfig()); connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group) { const QLatin1String pluginsGrp("Plugins"); diff --git a/runners/services/servicerunner.cpp b/runners/services/servicerunner.cpp index be6a9fc3890eda744c095fcb37319f43cdbf67ca..9763fb21237c0328a63587db73d7ca3dcc99eec7 100644 --- a/runners/services/servicerunner.cpp +++ b/runners/services/servicerunner.cpp @@ -37,11 +37,6 @@ #include "debug.h" -int weightedLength(const QString &query) -{ - return KStringHandler::logicalLength(query); -} - inline bool contains(const QString &result, const QStringList &queryList) { return std::all_of(queryList.cbegin(), queryList.cend(), [&result](const QString &query) { @@ -58,6 +53,36 @@ inline bool contains(const QStringList &results, const QStringList &queryList) }); } +bool acceptMatch(const QString &text, const QString &query, KRunner::QueryMatch &match, qreal relevance) +{ + if (text.isEmpty() || query.isEmpty()) { + return false; + } + + if (text.compare(query, Qt::CaseInsensitive) == 0) { + match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Highest); + match.setRelevance(relevance); + + return true; + } + + if (text.startsWith(query, Qt::CaseInsensitive)) { + match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::High); + match.setRelevance(relevance * 0.5); + + return true; + } + + if (text.contains(query, Qt::CaseInsensitive)) { + match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Moderate); + match.setRelevance(relevance * 0.25); + + return true; + } + + return false; +} + /** * @brief Finds all KServices for a given runner query */ @@ -76,10 +101,8 @@ public: query = context.query(); // Splitting the query term to match using subsequences queryList = query.split(QLatin1Char(' ')); - weightedTermLength = weightedLength(query); matchNameKeywordAndGenericName(); - matchCategories(); matchJumpListActions(); context.addMatches(matches); @@ -130,10 +153,6 @@ private: if (serviceProperty.contains(str, Qt::CaseInsensitive)) { relevanceIncrement += 0.01; } - } else if (category == Category::Comment) { - if (serviceProperty.contains(str, Qt::CaseInsensitive)) { - relevanceIncrement += 0.01; - } } } @@ -210,136 +229,33 @@ private: void matchNameKeywordAndGenericName() { - const auto nameKeywordAndGenericNameFilter = [this](const KService::Ptr &service) { - // Name - if (contains(service->name(), queryList)) { - return true; - } - // If the term length is < 3, no real point searching the untranslated Name, Keywords and GenericName - if (weightedTermLength < 3) { - return false; - } - if (contains(service->untranslatedName(), queryList)) { - return true; - } - - // Keywords - if (contains(service->keywords(), queryList)) { - return true; - } - // GenericName - if (contains(service->genericName(), queryList) || contains(service->untranslatedGenericName(), queryList)) { - return true; - } - // Comment - if (contains(service->comment(), queryList)) { - return true; - } - - return false; - }; - for (const KService::Ptr &service : m_services) { - if (!nameKeywordAndGenericNameFilter(service) || disqualify(service)) { + if (disqualify(service)) { continue; } - const QString id = service->storageId(); - const QString name = service->name(); - - KRunner::QueryMatch::CategoryRelevance categoryRelevance = KRunner::QueryMatch::CategoryRelevance::Moderate; - qreal relevance(0.6); - - // If the term was < 3 chars and NOT at the beginning of the App's name, then chances are the user doesn't want that app - if (weightedTermLength < 3) { - if (name.startsWith(query, Qt::CaseInsensitive)) { - relevance = 0.9; - } else { - continue; - } - } else if (name.compare(query, Qt::CaseInsensitive) == 0) { - relevance = 1; - categoryRelevance = KRunner::QueryMatch::CategoryRelevance::Highest; - } else if (const int idx = name.indexOf(queryList[0], 0, Qt::CaseInsensitive); idx != -1) { - relevance = 0.8; - relevance += increaseMatchRelavance(name, queryList, Category::Name); - if (idx == 0) { - relevance += 0.1; - categoryRelevance = KRunner::QueryMatch::CategoryRelevance::High; - } - } else if (const int idx = service->genericName().indexOf(queryList[0], 0, Qt::CaseInsensitive); idx != -1) { - relevance = 0.65; - relevance += increaseMatchRelavance(service->genericName(), queryList, Category::GenericName); - if (idx == 0) { - relevance += 0.05; - } - } else if (const int idx = service->comment().indexOf(queryList[0], 0, Qt::CaseInsensitive); idx != -1) { - relevance = 0.5; - relevance += increaseMatchRelavance(service->comment(), queryList, Category::Comment); - if (idx == 0) { - relevance += 0.05; - } - } - KRunner::QueryMatch match(m_runner); - match.setCategoryRelevance(categoryRelevance); setupMatch(service, match); - if (service->categories().contains(QLatin1String("KDE"))) { - qCDebug(RUNNER_SERVICES) << "found a kde thing" << id << match.subtext() << relevance; - relevance += .09; - } - - if (const auto foundIt = m_runner->m_favourites.constFind(service->desktopEntryName()); foundIt != m_runner->m_favourites.cend()) { - if (foundIt->isGlobal || foundIt->linkedActivities.contains(m_currentActivity)) { - qCDebug(RUNNER_SERVICES) << "entry is a favorite" << id << match.subtext() << relevance; - relevance *= 1.25; // Give favorites a relative boost, - } - } - - qCDebug(RUNNER_SERVICES) << name << "is this relevant:" << relevance; - match.setRelevance(relevance); - matches << match; - } - } + static const qreal nameRelevance = 1; + static const qreal genericNameRelevance = 0.9; + static const qreal execRelevance = 0.8; + static const qreal commentRelevance = 0.7; - void matchCategories() - { - // Do not match categories for short queries, BUG: 469769 - if (weightedTermLength < 5) { - return; - } - for (const KService::Ptr &service : m_services) { - const QStringList categories = service->categories(); - if (disqualify(service) || !contains(categories, queryList)) { + if (!acceptMatch(service->name(), query, match, nameRelevance) + && !acceptMatch(service->genericName(), query, match, genericNameRelevance) + && !acceptMatch(service->untranslatedGenericName(), query, match, genericNameRelevance) + && !acceptMatch(service->exec(), query, match, execRelevance) + && !acceptMatch(service->comment(), query, match, commentRelevance)) { continue; } - qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec(); - KRunner::QueryMatch match(m_runner); - setupMatch(service, match); - - qreal relevance = 0.4; - if (std::any_of(categories.begin(), categories.end(), [this](const QString &category) { - return category.compare(query, Qt::CaseInsensitive) == 0; - })) { - relevance = 0.6; - } - - if (service->isApplication()) { - relevance += .04; - } - - match.setRelevance(relevance); matches << match; } } void matchJumpListActions() { - if (weightedTermLength < 3) { - return; - } for (const KService::Ptr &service : m_services) { const auto actions = service->actions(); // Skip SystemSettings as we find KCMs already @@ -353,22 +269,6 @@ private: } seen(action); - const int matchIndex = action.text().indexOf(query, 0, Qt::CaseInsensitive); - if (matchIndex < 0) { - continue; - } - - KRunner::QueryMatch match(m_runner); - if (!action.icon().isEmpty()) { - match.setIconName(action.icon()); - } else { - match.setIconName(service->icon()); - } - match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)", - "%1 - %2", - action.text(), - service->name())); - QUrl url(service->storageId()); url.setScheme(QStringLiteral("applications")); @@ -376,17 +276,19 @@ private: urlQuery.addQueryItem(QStringLiteral("action"), action.name()); url.setQuery(urlQuery); + KRunner::QueryMatch match(m_runner); match.setData(url); + match.setIconName(action.icon().isEmpty() ? service->icon() : action.icon()); + match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)", + "%1 - %2", + action.text(), + service->name())); - qreal relevance = 0.5; - if (action.text().compare(query, Qt::CaseInsensitive) == 0) { - relevance = 0.65; - match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::High); // Give it a higer match type to ensure it is shown, BUG: 455436 - } else if (matchIndex == 0) { - relevance += 0.05; - } + static const qreal textRelevance = 0.95; - match.setRelevance(relevance); + if (!acceptMatch(action.text(), query, match, textRelevance)) { + continue; + } matches << match; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor