Skip to content

Commit

Permalink
Rewrite dbus calls to system calls of dbus-send
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Feb 20, 2020
1 parent c5b431c commit 3041966
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ add_executable(plasma-theme
utils/plasma.cpp
utils/plasma.h
exceptions/RuntimeException.cpp
exceptions/RuntimeException.h)
exceptions/RuntimeException.h
utils/signals.cpp
utils/signals.h)

target_link_libraries(plasma-theme KF5::ConfigCore Qt5::DBus)
target_link_libraries(plasma-theme KF5::ConfigCore)
24 changes: 4 additions & 20 deletions utils/plasma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusConnection>
#include <QtCore/QFileInfo>
#include "signals.h"
#include "exceptions/RuntimeException.h"

enum KdeGlobalsChangeType {
ColorSchemeChanged = 0,
WidgetStyleChanged = 2
};

void configMerge(const KSharedConfigPtr &srcConf, const KSharedConfigPtr &dstConf) {
for (const QString &group: srcConf->groupList()) {
// General group contains no color information and the name will be applied via another call
Expand Down Expand Up @@ -56,17 +52,6 @@ void applyColorSchemeToFile(const QString &src, const QString &dst) {
dstConf->sync();
}

void kdeGlobalSettingsNotifyChange(KdeGlobalsChangeType changeType) {
QDBusMessage message = QDBusMessage::createSignal(
"/KGlobalSettings",
"org.kde.KGlobalSettings",
"notifyChange"
);

message.setArguments(QList<QVariant>{changeType, 0});
QDBusConnection::sessionBus().send(message);
}

inline QString locateKdeGlobals() {
return QStandardPaths::locate(QStandardPaths::GenericConfigLocation, "kdeglobals");
}
Expand Down Expand Up @@ -113,13 +98,12 @@ void emitWidgetStyleChangedSignals(const QString &widgetStyle) {
kdeGlobalSettingsNotifyChange(WidgetStyleChanged);

for (const QString &intf: QStringList{"org.freedesktop.impl.portal.Settings", "org.freedesktop.portal.Settings"}) {
QDBusMessage message = QDBusMessage::createSignal(
dbusSignal(
"/org/freedesktop/portal/desktop",
intf,
"SettingChanged"
"SettingChanged",
QStringList{"org.kde.kdeglobals.KDE", "widgetStyle", widgetStyle}
);
message.setArguments(QList<QVariant>{"org.kde.kdeglobals.KDE", "widgetStyle", widgetStyle});
QDBusConnection::sessionBus().send(message);
}
}

Expand Down
19 changes: 19 additions & 0 deletions utils/signals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <QString>
#include <QtCore/QProcess>
#include "signals.h"

void dbusSignal(const QString &path, const QString &interface, const QString &name, QStringList arguments) {
arguments.prepend(interface + "." + name);
arguments.prepend(path);
arguments.prepend("--type=signal");

QProcess process;
process.start("dbus-send", arguments);
process.waitForFinished();
}

void kdeGlobalSettingsNotifyChange(KdeGlobalsChangeType changeType) {
auto type = QString("int32:%0").arg(changeType);

dbusSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange", QStringList{type, "int32:0"});
}
10 changes: 10 additions & 0 deletions utils/signals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <QString>
#include <QStringList>

enum KdeGlobalsChangeType {
ColorSchemeChanged = 0,
WidgetStyleChanged = 2
};

void kdeGlobalSettingsNotifyChange(KdeGlobalsChangeType changeType);
void dbusSignal(const QString &path, const QString &interface, const QString &name, QStringList arguments);

0 comments on commit 3041966

Please sign in to comment.