This commit is contained in:
Mikhail Zolotukhin 2022-02-01 04:00:11 +03:00
parent 8d656203e0
commit 0c81d944b2
No known key found for this signature in database
GPG Key ID: 6732CCDFC718BB67
9 changed files with 32 additions and 89 deletions

View File

@ -5,6 +5,8 @@ project(bismuth-core)
add_library(bismuth_core SHARED)
add_subdirectory(dbus)
target_sources(
bismuth_core
PRIVATE
@ -20,6 +22,7 @@ target_link_libraries(
Qt5::Qml
KF5::ConfigCore
KF5::ConfigGui
Qt5::DBus
)
kconfig_add_kcfg_files(bismuth_core GENERATE_MOC "config.kcfgc")

View File

@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <mail@genda.life>
# SPDX-License-Identifier: MIT
qt_generate_dbus_interface(
"dbus-service.hpp"
"org.kde.bismuth.dbus.xml"
OPTIONS -m
)
target_sources(
bismuth_core
PRIVATE
dbus-service.cpp
"${CMAKE_CURRENT_BINARY_DIR}/org.kde.bismuth.dbus.xml"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/org.kde.bismuth.dbus.xml"
DESTINATION "${DBUS_INTERFACES_INSTALL_DIR}"
)

View File

@ -1,21 +1,22 @@
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
// SPDX-License-Identifier: MIT
#include "dbus-service.h"
#include "dbus-service.hpp"
#include <QDBusConnection>
#include <QDebug>
#include <QString>
DBusService::DBusService(QQuickItem *parent)
: QQuickItem(parent)
{
auto bus = QDBusConnection::sessionBus();
auto result = bus.registerService("org.kde.bismuth.dbus");
auto result = bus.registerService(QStringLiteral("org.kde.bismuth.dbus"));
if (!result) {
qDebug() << "[Bismuth] [DBus Plugin] Cannot register DBus service with the name \"org.kde.bismuth.dbus\"";
}
result = bus.registerObject("/bismuth", this, QDBusConnection::ExportScriptableSlots);
result = bus.registerObject(QStringLiteral("/bismuth"), this, QDBusConnection::ExportScriptableSlots);
if (!result) {
qDebug() << "[Bismuth] [DBus Plugin] Cannot register DBus object with path \"/bismuth\"";
}
@ -24,8 +25,8 @@ DBusService::DBusService(QQuickItem *parent)
DBusService::~DBusService()
{
auto bus = QDBusConnection::sessionBus();
bus.unregisterService("org.kde.bismuth.dbus");
bus.unregisterObject("/bismuth");
bus.unregisterService(QStringLiteral("org.kde.bismuth.dbus"));
bus.unregisterObject(QStringLiteral("/bismuth"));
}
EXTERNAL_REQUEST_MAPPER(bool, toggleLayoutOn, (const QString &layoutId, int screen, int desktop, const QString &activity), { //

View File

@ -5,7 +5,7 @@
#include <QQuickItem>
#include <QString>
#include "macro.h"
#include "macro.hpp"
class DBusService : public QQuickItem
{

View File

@ -15,7 +15,7 @@
* Must contain only the types, that could be converted to the DBus types.
*/
#define EXTERNAL_REQUEST(RETURN_TYPE, REQUEST_NAME, INPUT_PARAMS) \
Q_PROPERTY(QJSValue REQUEST_NAME##_handler READ REQUEST_NAME##_handler WRITE set##REQUEST_NAME##_handler); \
Q_PROPERTY(QJSValue REQUEST_NAME##_handler READ REQUEST_NAME##_handler WRITE set##REQUEST_NAME##_handler) \
\
QJSValue m_##REQUEST_NAME##_handler; \
\

View File

@ -1,45 +0,0 @@
# SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
# SPDX-License-Identifier: MIT
project(bismuth-dbus-plugin)
add_library(dbus_bismuth_plugin SHARED)
qt_generate_dbus_interface(
dbus-service.h
org.kde.bismuth.dbus.xml
OPTIONS -m
)
target_sources(
dbus_bismuth_plugin
PRIVATE
dbus-service.cpp
dbus-plugin.cpp
imports/qmldir
"${CMAKE_CURRENT_BINARY_DIR}/org.kde.bismuth.dbus.xml"
)
target_link_libraries(
dbus_bismuth_plugin
PRIVATE
Qt5::Core
Qt5::Quick
Qt5::Qml
Qt5::DBus
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/org.kde.bismuth.dbus.xml"
DESTINATION "${DBUS_INTERFACES_INSTALL_DIR}"
)
install(
TARGETS dbus_bismuth_plugin
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/dbus"
)
install(
DIRECTORY imports/ # Slash is important
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/dbus"
)

View File

@ -1,14 +0,0 @@
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
// SPDX-License-Identifier: MIT
#include "dbus-plugin.h"
#include "dbus-service.h"
void DBusPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.bismuth.dbus"));
qmlRegisterModule(uri, 1, 0);
qmlRegisterType<DBusService>(uri, 1, 0, "DBusService");
}

View File

@ -1,15 +0,0 @@
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
// SPDX-License-Identifier: MIT
#include <QObject>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
class DBusPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};

View File

@ -1,8 +0,0 @@
# SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
# SPDX-License-Identifier: MIT
module org.kde.bismuth.dbus
# Plugin name is the name of the library in the CMakeLists.txt
plugin dbus_bismuth_plugin
classname DBusPlugin