From d30cb4e572b0507458f002b30a1c9a8122a0808a Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Sun, 9 Jul 2017 10:30:21 +0900 Subject: [PATCH] Add GnomeTheme class --- app/src/desktopthemes/gnometheme.cpp | 41 ++++++++++++++++++++++++++++ app/src/desktopthemes/gnometheme.h | 23 ++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app/src/desktopthemes/gnometheme.cpp create mode 100644 app/src/desktopthemes/gnometheme.h diff --git a/app/src/desktopthemes/gnometheme.cpp b/app/src/desktopthemes/gnometheme.cpp new file mode 100644 index 0000000..118efc1 --- /dev/null +++ b/app/src/desktopthemes/gnometheme.cpp @@ -0,0 +1,41 @@ +#include "gnometheme.h" + +#include <QStringList> +#include <QDir> +#include <QProcess> + +GnomeTheme::GnomeTheme(const QString &path, QObject *parent) + : QObject(parent), path_(path) +{ + themeName_ = QDir(path_).dirName(); +} + +bool GnomeTheme::applyAsWallpaper() const +{ + return setConfig("org.gnome.desktop.background", "picture-uri", "file://" + path_); +} + +bool GnomeTheme::applyAsIcon() const +{ + return setConfig("org.gnome.desktop.interface", "icon-theme", themeName_); +} + +bool GnomeTheme::applyAsCursor() const +{ + return setConfig("org.gnome.desktop.interface", "cursor-theme", themeName_); +} + +bool GnomeTheme::applyAsGtk3Theme() const +{ + return setConfig("org.gnome.desktop.interface", "gtk-theme", themeName_); +} + +bool GnomeTheme::applyAsGnomeShellTheme() const +{ + return setConfig("org.gnome.shell.extensions.user-theme", "name", themeName_); +} + +bool GnomeTheme::setConfig(const QString &schema, const QString &key, const QString &value) const +{ + return QProcess::startDetached("gsettings", QStringList() << "set" << schema << key << value); +} diff --git a/app/src/desktopthemes/gnometheme.h b/app/src/desktopthemes/gnometheme.h new file mode 100644 index 0000000..c27e7fe --- /dev/null +++ b/app/src/desktopthemes/gnometheme.h @@ -0,0 +1,23 @@ +#pragma once + +#include <QObject> + +class GnomeTheme : public QObject +{ + Q_OBJECT + +public: + explicit GnomeTheme(const QString &path, QObject *parent = nullptr); + + bool applyAsWallpaper() const; + bool applyAsIcon() const; + bool applyAsCursor() const; + bool applyAsGtk3Theme() const; + bool applyAsGnomeShellTheme() const; + +private: + bool setConfig(const QString &schema, const QString &key, const QString &value) const; + + QString path_; + QString themeName_; +}; -- GitLab