Commit 78baef0a authored by David Redondo's avatar David Redondo 🏎

Use DBus activation for applications that are dbus activatable

Use dbus activation as per freedesktop desktop entry spec. Applications that
want to use it need to have DBusActivatable=true in their desktop file, have a
dbus-activatable service with the same name as their desktop file and implement
the org.freedesktop.Application interface at the object path that results when
every '.' in the name of the service is replaced by '/'. KDBusService
automatically takes care of registering the name and object that implements
the interface. The application just needs to connect to activate(Action)Requested
signals of KDBusService.
parent 5127d57c
SPDX-FileCopyrightText: 2008 Michael Jansen <>
SPDX-FileCopyrightText: 2016 Marco Martin <>
SPDX-FileCopyrightText: 2020 David Redondo <>
SPDX-License-Identifier: LGPL-2.0-or-later
......@@ -42,6 +43,23 @@ KServiceActionComponent::~KServiceActionComponent()
void KServiceActionComponent::emitGlobalShortcutPressed( const GlobalShortcut &shortcut )
if (m_desktopFile->desktopGroup().readEntry("DBusActivatable", false)) {
QString method;
const QString serviceName = m_serviceStorageId.chopped(strlen(".desktop"));
const QString objectPath = QStringLiteral("/%1").arg(serviceName).replace(QLatin1Char('.'), QLatin1Char('/'));
const QString interface = QStringLiteral("org.freedesktop.Application");
QDBusMessage message;
if (shortcut.uniqueName() == QLatin1String("_launch")) {
message = QDBusMessage::createMethodCall(serviceName, objectPath, interface, QStringLiteral("Activate"));
} else {
message = QDBusMessage::createMethodCall(serviceName, objectPath, interface, QStringLiteral("ActivateAction"));
message << shortcut.uniqueName() << QVariantList();
message << QVariantMap();
QDBusConnectionInterface *dbusDaemon = QDBusConnection::sessionBus().interface();
const bool klauncherAvailable = dbusDaemon->isServiceRegistered(QStringLiteral("org.kde.klauncher5"));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment