Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
070009a5
Commit
070009a5
authored
Mar 10, 2022
by
Alexander Lohnau
Browse files
libtaskmanager: Port away from KServiceTypeTrader
Task:
https://phabricator.kde.org/T15368
parent
248067fa
Pipeline
#150446
passed with stage
in 6 minutes and 44 seconds
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
libtaskmanager/tasktools.cpp
View file @
070009a5
...
...
@@ -14,7 +14,6 @@
#include
<KFileItem>
#include
<KNotificationJobUiDelegate>
#include
<KProcessList>
#include
<KServiceTypeTrader>
#include
<KStartupInfo>
#include
<KWindowSystem>
#include
<kemailsettings.h>
...
...
@@ -29,6 +28,7 @@
#include
<QRegularExpression>
#include
<QScreen>
#include
<QUrlQuery>
#include
<qnamespace.h>
#if HAVE_X11
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include
<private/qtx11extras_p.h>
...
...
@@ -177,7 +177,7 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, KSharedConfig::Ptr
// of wine-Programs-Steam-Steam.desktop. The weighing done by this function makes
// sure the Linux native version gets mapped to the former, while other heuristics
// map the Wine version reliably to the latter.
// In lieu of this weighing we just used whatever K
ServiceType
Trader returned first,
// In lieu of this weighing we just used whatever K
Application
Trader returned first,
// so what we do here can be no worse.
auto
sortServicesByMenuId
=
[](
KService
::
List
&
services
,
const
QString
&
key
)
{
if
(
services
.
count
()
==
1
)
{
...
...
@@ -250,14 +250,16 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, KSharedConfig::Ptr
//
// Source: https://specifications.freedesktop.org/startup-notification-spec/startup-notification-0.1.txt
if
(
services
.
isEmpty
())
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ StartupWMClass)"
).
arg
(
appId
));
services
=
KApplicationTrader
::
query
([
&
appId
](
const
KService
::
Ptr
&
service
)
{
return
service
->
property
(
QStringLiteral
(
"StartupWMClass"
)).
toString
().
compare
(
appId
,
Qt
::
CaseInsensitive
)
==
0
;
});
sortServicesByMenuId
(
services
,
appId
);
}
if
(
services
.
isEmpty
()
&&
!
xWindowsWMClassName
.
isEmpty
())
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ StartupWMClass)"
).
arg
(
xWindowsWMClassName
));
services
=
KApplicationTrader
::
query
([
&
xWindowsWMClassName
](
const
KService
::
Ptr
&
service
)
{
return
service
->
property
(
QStringLiteral
(
"StartupWMClass"
)).
toString
().
compare
(
xWindowsWMClassName
,
Qt
::
CaseInsensitive
)
==
0
;
});
sortServicesByMenuId
(
services
,
xWindowsWMClassName
);
}
...
...
@@ -304,9 +306,9 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, KSharedConfig::Ptr
rewrittenString
=
matchProperty
;
}
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ %2)"
).
arg
(
rewrittenString
,
serviceSearchIdentifier
)
);
services
=
KApplicationTrader
::
query
([
&
rewrittenString
,
&
serviceSearchIdentifier
](
const
KService
::
Ptr
&
service
)
{
return
service
->
property
(
serviceSearchIdentifier
).
toString
().
compare
(
rewrittenString
,
Qt
::
CaseInsensitive
)
==
0
;
}
);
sortServicesByMenuId
(
services
,
serviceSearchIdentifier
);
if
(
!
services
.
isEmpty
())
{
...
...
@@ -334,34 +336,34 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, KSharedConfig::Ptr
// Try matching mapped name against DesktopEntryName.
if
(
!
mapped
.
isEmpty
()
&&
services
.
isEmpty
())
{
services
=
K
ServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ DesktopEntryName) and (not exist NoDisplay or not NoDisplay)"
).
arg
(
mapped
)
);
services
=
K
ApplicationTrader
::
query
([
&
mapped
](
const
KService
::
Ptr
&
service
)
{
return
!
service
->
noDisplay
()
&&
service
->
desktopEntryName
().
compare
(
mapped
,
Qt
::
CaseInsensitive
)
==
0
;
}
);
sortServicesByMenuId
(
services
,
mapped
);
}
// Try matching mapped name against 'Name'.
if
(
!
mapped
.
isEmpty
()
&&
services
.
isEmpty
())
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Name) and (not exist NoDisplay or not NoDisplay)"
).
arg
(
mapped
)
);
services
=
KApplicationTrader
::
query
([
&
mapped
](
const
KService
::
Ptr
&
service
)
{
return
!
service
->
noDisplay
()
&&
service
->
name
().
compare
(
mapped
,
Qt
::
CaseInsensitive
)
==
0
;
}
);
sortServicesByMenuId
(
services
,
mapped
);
}
// Try matching appId against DesktopEntryName.
if
(
services
.
isEmpty
())
{
services
=
K
ServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ DesktopEntryName)"
).
arg
(
appId
)
);
services
=
K
ApplicationTrader
::
query
([
&
appId
](
const
KService
::
Ptr
&
service
)
{
return
service
->
desktopEntryName
().
compare
(
appId
,
Qt
::
CaseInsensitive
)
==
0
;
}
);
sortServicesByMenuId
(
services
,
appId
);
}
// Try matching appId against 'Name'.
// This has a shaky chance of success as appId is untranslated, but 'Name' may be localized.
if
(
services
.
isEmpty
())
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Name) and (not exist NoDisplay or not NoDisplay)"
).
arg
(
appId
)
);
services
=
KApplicationTrader
::
query
([
&
appId
](
const
KService
::
Ptr
&
service
)
{
return
!
service
->
noDisplay
()
&&
service
->
name
().
compare
(
appId
,
Qt
::
CaseInsensitive
)
==
0
;
}
);
sortServicesByMenuId
(
services
,
appId
);
}
...
...
@@ -403,8 +405,10 @@ QUrl windowUrlFromMetadata(const QString &appId, quint32 pid, KSharedConfig::Ptr
// - appId also cannot match the binary because of name mismatch
// - in the following code *.appId can match org.kde.dragonplayer though
if
(
services
.
isEmpty
()
||
services
.
at
(
0
)
->
desktopEntryName
().
isEmpty
())
{
auto
matchingServices
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' ~~ DesktopEntryName)"
).
arg
(
appId
));
auto
matchingServices
=
KApplicationTrader
::
query
([
&
appId
](
const
KService
::
Ptr
&
service
)
{
return
!
service
->
noDisplay
()
&&
service
->
desktopEntryName
().
contains
(
appId
,
Qt
::
CaseInsensitive
);
});
QMutableListIterator
<
KService
::
Ptr
>
it
(
matchingServices
);
while
(
it
.
hasNext
())
{
auto
service
=
it
.
next
();
...
...
@@ -509,15 +513,19 @@ KService::List servicesFromCmdLine(const QString &_cmdLine, const QString &proce
const
int
firstSpace
=
cmdLine
.
indexOf
(
' '
);
int
slash
=
0
;
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Exec)"
).
arg
(
cmdLine
));
services
=
KApplicationTrader
::
query
([
&
cmdLine
](
const
KService
::
Ptr
&
service
)
{
return
service
->
exec
()
==
cmdLine
;
});
if
(
services
.
isEmpty
())
{
// Could not find with complete command line, so strip out the path part ...
slash
=
cmdLine
.
lastIndexOf
(
'/'
,
firstSpace
);
if
(
slash
>
0
)
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Exec)"
).
arg
(
cmdLine
.
mid
(
slash
+
1
)));
const
QStringView
midCmd
=
QStringView
(
cmdLine
).
mid
(
slash
+
1
);
services
=
services
=
KApplicationTrader
::
query
([
&
midCmd
](
const
KService
::
Ptr
&
service
)
{
return
service
->
exec
()
==
midCmd
;
});
}
}
...
...
@@ -525,14 +533,18 @@ KService::List servicesFromCmdLine(const QString &_cmdLine, const QString &proce
// Could not find with arguments, so try without ...
cmdLine
.
truncate
(
firstSpace
);
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Exec)"
).
arg
(
cmdLine
));
services
=
KApplicationTrader
::
query
([
&
cmdLine
](
const
KService
::
Ptr
&
service
)
{
return
service
->
exec
()
==
cmdLine
;
});
if
(
services
.
isEmpty
())
{
slash
=
cmdLine
.
lastIndexOf
(
'/'
);
if
(
slash
>
0
)
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Exec)"
).
arg
(
cmdLine
.
mid
(
slash
+
1
)));
const
QStringView
midCmd
=
QStringView
(
cmdLine
).
mid
(
slash
+
1
);
services
=
KApplicationTrader
::
query
([
&
midCmd
](
const
KService
::
Ptr
&
service
)
{
return
service
->
exec
()
==
midCmd
;
});
}
}
}
...
...
libtaskmanager/xstartuptasksmodel.cpp
View file @
070009a5
...
...
@@ -6,11 +6,11 @@
#include
"xstartuptasksmodel.h"
#include
<KApplicationTrader>
#include
<KConfig>
#include
<KConfigGroup>
#include
<KDirWatch>
#include
<KService>
#include
<KServiceTypeTrader>
#include
<KStartupInfo>
#include
<QIcon>
...
...
@@ -159,7 +159,9 @@ QUrl XStartupTasksModel::Private::launcherUrl(const KStartupInfoData &data)
// turn into KService desktop entry name
appId
.
chop
(
strlen
(
".desktop"
));
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ DesktopEntryName)"
).
arg
(
appId
));
services
=
KApplicationTrader
::
query
([
&
appId
](
const
KService
::
Ptr
&
service
)
{
return
service
->
desktopEntryName
().
compare
(
appId
,
Qt
::
CaseInsensitive
)
==
0
;
});
}
}
...
...
@@ -167,14 +169,18 @@ QUrl XStartupTasksModel::Private::launcherUrl(const KStartupInfoData &data)
// Try StartupWMClass.
if
(
services
.
empty
()
&&
!
wmClass
.
isEmpty
())
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ StartupWMClass)"
).
arg
(
wmClass
));
services
=
KApplicationTrader
::
query
([
&
wmClass
](
const
KService
::
Ptr
&
service
)
{
return
service
->
property
(
QStringLiteral
(
"StartupWMClass"
)).
toString
().
compare
(
wmClass
,
Qt
::
CaseInsensitive
)
==
0
;
});
}
const
QString
name
=
data
.
findName
();
// Try via name ...
if
(
services
.
empty
()
&&
!
name
.
isEmpty
())
{
services
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"Application"
),
QStringLiteral
(
"exist Exec and ('%1' =~ Name)"
).
arg
(
name
));
services
=
KApplicationTrader
::
query
([
&
name
](
const
KService
::
Ptr
&
service
)
{
return
service
->
name
().
compare
(
name
,
Qt
::
CaseInsensitive
)
==
0
;
});
}
if
(
!
services
.
empty
())
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment