diff --git a/app/src/desktopthemes/xfcetheme.cpp b/app/src/desktopthemes/xfcetheme.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6937bd88c833cdc8c9c4a85686efb9016c98a4d2 --- /dev/null +++ b/app/src/desktopthemes/xfcetheme.cpp @@ -0,0 +1,53 @@ +#include "xfcetheme.h" + +#include <QVariantList> +#include <QDir> +#include <QProcess> +#include <QDBusMessage> +#include <QDBusConnection> +#include <QDBusVariant> +#include <QDebug> + +XfceTheme::XfceTheme(const QString &path, QObject *parent) + : QObject(parent), path_(path) +{ + themeName_ = QDir(path_).dirName(); +} + +bool XfceTheme::applyAsWallpaper() const +{ + return setConfig("xfce4-desktop", "/backdrop/screen0/monitor0/workspace0/last-image", path_); +} + +bool XfceTheme::applyAsIcon() const +{ + return setConfig("xsettings", "/Net/IconThemeName", themeName_); +} + +bool XfceTheme::applyAsCursor() const +{ + return setConfig("xsettings", "/Gtk/CursorThemeName", themeName_); +} + +bool XfceTheme::applyAsGtk2Theme() const +{ + return setConfig("xsettings", "/Net/ThemeName", themeName_); +} + +bool XfceTheme::applyAsXfwm4Theme() const +{ + return setConfig("xfwm4", "/general/theme", themeName_); +} + +bool XfceTheme::setConfig(const QString &channel, const QString &property, const QString &value) const +{ + auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty"); + message.setArguments(QVariantList() << QVariant(channel) << QVariant(property) << QVariant::fromValue(QDBusVariant(value))); + auto reply = QDBusConnection::sessionBus().call(message); + + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << reply.errorMessage(); + return false; + } + return true; +} diff --git a/app/src/desktopthemes/xfcetheme.h b/app/src/desktopthemes/xfcetheme.h new file mode 100644 index 0000000000000000000000000000000000000000..4cb1a3e268ed229a34f5dde3035d2e56db93f356 --- /dev/null +++ b/app/src/desktopthemes/xfcetheme.h @@ -0,0 +1,23 @@ +#pragma once + +#include <QObject> + +class XfceTheme : public QObject +{ + Q_OBJECT + +public: + explicit XfceTheme(const QString &path, QObject *parent = nullptr); + + bool applyAsWallpaper() const; + bool applyAsIcon() const; + bool applyAsCursor() const; + bool applyAsGtk2Theme() const; + bool applyAsXfwm4Theme() const; + +private: + bool setConfig(const QString &channel, const QString &property, const QString &value) const; + + QString path_; + QString themeName_; +};