File indexing completed on 2024-04-21 16:10:59
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "kcmdbusinterface.h" 0008 #include <QDBusConnection> 0009 #include <QDBusConnectionInterface> 0010 #include <QDBusMessage> 0011 #include <QDebug> 0012 0013 KcmDbusInterface::KcmDbusInterface(QObject *parent) 0014 : QObject(parent) 0015 { 0016 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.plasma.remotecontrollers")) { 0017 QDBusConnection::sessionBus().registerService("org.kde.plasma.remotecontrollers"); 0018 } 0019 QDBusConnection::sessionBus().registerObject("/KCM", this, QDBusConnection::ExportAllSlots); 0020 QDBusConnectionInterface *iface = QDBusConnection::sessionBus().interface(); 0021 QDBusConnection dbus = QDBusConnection::sessionBus(); 0022 0023 if (iface) { 0024 if (iface->isServiceRegistered("org.kde.plasma.remotecontrollers")) { 0025 if (dbus.isConnected()) { 0026 dbus.connect("org.kde.plasma.remotecontrollers", "/EVDEV", "org.kde.plasma.remotecontrollers.EVDEV", "keyPress", this, SLOT(evdevKeyPress(QDBusMessage))); 0027 } else { 0028 qWarning() << "DBus connection is not connected."; 0029 } 0030 } 0031 } 0032 } 0033 0034 KcmDbusInterface::~KcmDbusInterface() 0035 { 0036 } 0037 0038 void KcmDbusInterface::evdevKeyPress(const QDBusMessage& msg) 0039 { 0040 QList<QVariant> arguments = msg.arguments(); 0041 int keyCode = arguments.at(0).toInt(); 0042 emit evdevKeyPressed(keyCode); 0043 }