diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp index 09e4ea5..be0deba 100644 --- a/sources/awdebug.cpp +++ b/sources/awdebug.cpp @@ -21,6 +21,7 @@ Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget", QtMsgType::QtWarningMsg) +Q_LOGGING_CATEGORY(LOG_DBUS, "org.kde.plasma.awdbus", QtMsgType::QtWarningMsg) Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel", QtMsgType::QtWarningMsg) Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg) diff --git a/sources/awdebug.h b/sources/awdebug.h index a18a65e..1f5d6ed 100644 --- a/sources/awdebug.h +++ b/sources/awdebug.h @@ -31,6 +31,7 @@ const char LOG_FORMAT[] = "[%{time " Q_DECLARE_LOGGING_CATEGORY(LOG_AW) +Q_DECLARE_LOGGING_CATEGORY(LOG_DBUS) Q_DECLARE_LOGGING_CATEGORY(LOG_DP) Q_DECLARE_LOGGING_CATEGORY(LOG_ESM) Q_DECLARE_LOGGING_CATEGORY(LOG_ESS) diff --git a/sources/awesome-widget/plugin/awdbusadaptor.cpp b/sources/awesome-widget/plugin/awdbusadaptor.cpp new file mode 100644 index 0000000..42e7c73 --- /dev/null +++ b/sources/awesome-widget/plugin/awdbusadaptor.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awdbusadaptor.h" + +#include "awdebug.h" +#include "awkeys.h" + + +AWDBusAdaptor::AWDBusAdaptor(AWKeys *parent) + : QDBusAbstractAdaptor(parent) + , m_plugin(parent) +{ + qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__; +} + + +AWDBusAdaptor::~AWDBusAdaptor() +{ + qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__; +} + + +qlonglong AWDBusAdaptor::whoAmI() const +{ + return reinterpret_cast(m_plugin); +} diff --git a/sources/awesome-widget/plugin/awdbusadaptor.h b/sources/awesome-widget/plugin/awdbusadaptor.h new file mode 100644 index 0000000..caa3c02 --- /dev/null +++ b/sources/awesome-widget/plugin/awdbusadaptor.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef AWDBUSADAPTOR_H +#define AWDBUSADAPTOR_H + +#include + +#include "version.h" + + +class AWKeys; + +class AWDBusAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", AWDBUS_SERVICE_NAME) + +public: + explicit AWDBusAdaptor(AWKeys *parent = nullptr); + ~AWDBusAdaptor(); + +public slots: + qlonglong whoAmI() const; + +private: + AWKeys *m_plugin = nullptr; +}; + + +#endif /* AWDBUSADAPTOR_H */ diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index b80b57a..b2d84fc 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -17,7 +17,8 @@ #include "awkeys.h" -#include +#include +#include #include #include #include @@ -25,6 +26,7 @@ #include "awdataaggregator.h" #include "awdataengineaggregator.h" +#include "awdbusadaptor.h" #include "awdebug.h" #include "awkeycache.h" #include "awkeyoperations.h" @@ -52,6 +54,8 @@ AWKeys::AWKeys(QObject *parent) m_timer = new QTimer(this); m_timer->setSingleShot(false); + createDBusInterface(); + // update key data if required connect(m_keyOperator, SIGNAL(updateKeys(QStringList)), this, SLOT(reinitKeys(QStringList))); @@ -74,6 +78,11 @@ AWKeys::~AWKeys() m_timer->stop(); delete m_timer; + // delete dbus session + long id = reinterpret_cast(this); + QDBusConnection::sessionBus().unregisterObject(QString("/%1").arg(id)); + QDBusConnection::sessionBus().unregisterService(AWDBUS_SERVICE); + // core delete m_dataEngineAggregator; delete m_threadPool; @@ -319,6 +328,23 @@ void AWKeys::calculateValues() } +void AWKeys::createDBusInterface() +{ + // get this object id + long id = reinterpret_cast(this); + + // create session + QDBusConnection bus = QDBusConnection::sessionBus(); + if (!bus.registerService(AWDBUS_SERVICE)) + qCWarning(LOG_AW) << "Could not register DBus service, last error" + << bus.lastError().message(); + if (!bus.registerObject(QString("/%1").arg(id), new AWDBusAdaptor(this), + QDBusConnection::ExportAllContents)) + qCWarning(LOG_AW) << "Could not register DBus object, last error" + << bus.lastError().message(); +} + + QString AWKeys::parsePattern(QString pattern) const { // screen sign diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index 0f70d36..75a6423 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -76,6 +76,7 @@ private slots: private: // methods void calculateValues(); + void createDBusInterface(); QString parsePattern(QString pattern) const; void setDataBySource(const QString &sourceName, const QVariantMap &data); // objects diff --git a/sources/desktop-panel/plugin/dpadds.h b/sources/desktop-panel/plugin/dpadds.h index a9d2e0d..9905587 100644 --- a/sources/desktop-panel/plugin/dpadds.h +++ b/sources/desktop-panel/plugin/dpadds.h @@ -45,7 +45,8 @@ public: virtual ~DPAdds(); Q_INVOKABLE bool isDebugEnabled() const; Q_INVOKABLE int currentDesktop() const; - Q_INVOKABLE QStringList dictKeys(const bool = true, const QString = QString()) const; + Q_INVOKABLE QStringList dictKeys(const bool = true, + const QString = QString()) const; Q_INVOKABLE int numberOfDesktops() const; Q_INVOKABLE QString toolTipImage(const int desktop) const; Q_INVOKABLE QString parsePattern(const QString pattern, diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 2a903bf..07e9e9b 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -45,6 +45,7 @@ foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awactions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awdataaggregator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awdataengineaggregator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awdbusadaptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awformatterhelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeycache.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeyoperations.cpp diff --git a/sources/version.h.in b/sources/version.h.in index f97e97d..b59f5bd 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -38,6 +38,10 @@ const int AWEWAPI = 3; const int AWEFAPI = 2; // telemetry api version const int AWTEAPI = 1; +// dbus adaptor properties +// use define here instead of normal const definition for moc +#define AWDBUS_SERVICE_NAME "org.kde.plasma.awesomewidget" +const char AWDBUS_SERVICE[] = AWDBUS_SERVICE_NAME; // network requests timeout, ms const int REQUEST_TIMEOUT = 3000; // available time keys