Skip to content
Snippets Groups Projects
Commit 50ef71c4 authored by akiraohgaki's avatar akiraohgaki
Browse files

Add XfceTheme class

parent d30cb4e5
Branches
Tags
No related merge requests found
#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;
}
#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_;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment