[Libtaskmanager] Add support for regular expression mapping

This allows more complicated rules, useful for matching Chrome webapps to their
respective desktop file where we need to change crx_foo to chrome-foo-default.

BUG: 358277
CCBUG: 356609
FIXED-IN: 5.7.0

Differential Revision: https://phabricator.kde.org/D1673
wilder-5.14
Kai Uwe Broulik 10 years ago
parent a246d0eada
commit 92efc6ca6e
  1. 6
      libtaskmanager/taskmanagerrulesrc
  2. 47
      libtaskmanager/xwindowtasksmodel.cpp

@ -15,3 +15,9 @@ Dragon=dragonplayer
[Settings]
ManualOnly=Wine
MatchCommandLineFirst=VirtualBox
[Rewrite Rules][google-chrome][1]
Property=ClassName
Identifier=DesktopEntryName
Match=(?<=crx_)(?'match'[a-z]+)
Target=chrome-%1-default

@ -40,6 +40,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <QIcon>
#include <QFile>
#include <QGuiApplication>
#include <QRegularExpression>
#include <QScreen>
#include <QSet>
#include <QStandardPaths>
@ -526,6 +527,52 @@ QUrl XWindowTasksModel::Private::windowUrl(WId window)
return url;
}
KConfigGroup rewriteRulesGroup(rulesConfig, QStringLiteral("Rewrite Rules"));
if (rewriteRulesGroup.hasGroup(classClass)) {
KConfigGroup rewriteGroup(&rewriteRulesGroup, classClass);
const QStringList &rules = rewriteGroup.groupList();
for (const QString &rule : rules) {
KConfigGroup ruleGroup(&rewriteGroup, rule);
const QString propertyConfig = ruleGroup.readEntry(QStringLiteral("Property"), QString());
QString matchProperty;
if (propertyConfig == QLatin1String("ClassClass")) {
matchProperty = classClass;
} else if (propertyConfig == QLatin1String("ClassName")) {
matchProperty = className;
}
if (matchProperty.isEmpty()) {
continue;
}
const QString serviceSearchIdentifier = ruleGroup.readEntry(QStringLiteral("Identifier"), QString());
if (serviceSearchIdentifier.isEmpty()) {
continue;
}
QRegularExpression regExp(ruleGroup.readEntry(QStringLiteral("Match")));
const auto match = regExp.match(matchProperty);
if (match.hasMatch()) {
const QString actualMatch = match.captured(QStringLiteral("match"));
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));
}

Loading…
Cancel
Save