utils/serviceutils: Improve Exec key parsing

Take into account Exec field codes.

The change makes possible to have both X-KDE-Wayland-Interfaces field
(for example, kde_lockscreen_overlay_v1)
(and additional arguments for Exec field (for example, %U).

See also:

https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html

Contributes to:

https://invent.kde.org/plasma-mobile/plasma-dialer/-/merge_requests/105
This commit is contained in:
Alexey Andreyev 2022-11-17 23:43:01 +03:00
parent c01569e4b8
commit 462d5f0642

View file

@ -17,6 +17,7 @@
// Qt // Qt
#include <QFileInfo> #include <QFileInfo>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QProcess>
// KF // KF
#include <KApplicationTrader> #include <KApplicationTrader>
@ -31,11 +32,11 @@ static QStringList fetchProcessServiceField(const QString &executablePath, const
// needed to be able to use the logging category in a header static function // needed to be able to use the logging category in a header static function
static QLoggingCategory KWIN_UTILS("KWIN_UTILS", QtWarningMsg); static QLoggingCategory KWIN_UTILS("KWIN_UTILS", QtWarningMsg);
const auto servicesFound = KApplicationTrader::query([&executablePath](const KService::Ptr &service) { const auto servicesFound = KApplicationTrader::query([&executablePath](const KService::Ptr &service) {
if (service->exec().isEmpty() || QFileInfo(service->exec()).canonicalFilePath() != executablePath) { const auto splitCommandList = QProcess::splitCommand(service->exec());
if (splitCommandList.isEmpty()) {
return false; return false;
} }
return QFileInfo(splitCommandList.first()).canonicalFilePath() == executablePath;
return true;
}); });
if (servicesFound.isEmpty()) { if (servicesFound.isEmpty()) {