diff --git a/libtaskmanager/taskitem.cpp b/libtaskmanager/taskitem.cpp --- a/libtaskmanager/taskitem.cpp +++ b/libtaskmanager/taskitem.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "groupmanager.h" @@ -673,6 +674,48 @@ return launcherUrl; } + KConfigGroup rewriteRulesGroup(&cfg, QStringLiteral("Rewrite Rules")); + if (rewriteRulesGroup.hasGroup(task->classClass())) { + KConfigGroup rewriteGroup(&rewriteRulesGroup, task->classClass()); + + const QStringList &rules = rewriteGroup.groupList(); + for (const QString &rule : rules) { + KConfigGroup ruleGroup(&rewriteGroup, rule); + + const QString propertyConfig = ruleGroup.readEntry(QStringLiteral("Property")); + + QString matchProperty = task->classClass(); + if (propertyConfig == QLatin1String("ClassName")) { + matchProperty = task->className(); + } // TODO other sources? + + const QString serviceSearchIdentifier = ruleGroup.readEntry(QStringLiteral("Identifier"), QStringLiteral("DesktopEntryName")); + + QRegularExpression regExp(ruleGroup.readEntry(QStringLiteral("Match"))); + const auto match = regExp.match(matchProperty); + + if (match.hasMatch()) { + // Find the named match 'match', otherwise use the first match + QString actualMatch = match.captured(QStringLiteral("match")); + if (actualMatch.isEmpty()) { + actualMatch = match.captured(0); + } + + if (actualMatch.isEmpty()) { + continue; + } + + const QString rewrittenString = ruleGroup.readEntry(QStringLiteral("Target")).arg(actualMatch); + + services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), QStringLiteral("exist Exec and ('%1' =~ %2)").arg(rewrittenString, serviceSearchIdentifier)); + + if (!services.isEmpty()) { + break; + } + } + } + } + if (!mapped.isEmpty()) { services = KServiceTypeTrader::self()->query(QStringLiteral("Application"), QStringLiteral("exist Exec and ('%1' =~ DesktopEntryName)").arg(mapped)); } diff --git a/libtaskmanager/taskmanagerrulesrc b/libtaskmanager/taskmanagerrulesrc --- a/libtaskmanager/taskmanagerrulesrc +++ b/libtaskmanager/taskmanagerrulesrc @@ -15,3 +15,9 @@ [Settings] ManualOnly=Wine MatchCommandLineFirst=VirtualBox + +[Rewrite Rules][google-chrome][1] +Property=ClassName +Identifier=DesktopEntryName +Match=(?<=crx_)(?'match'[a-z]+) +Target=chrome-%1-default