From a0ae7d9fbb033c321a5db1e79896308933d64f84 Mon Sep 17 00:00:00 2001
From: Akira Ohgaki <akiraohgaki@gmail.com>
Date: Sat, 15 Jul 2017 04:47:49 +0900
Subject: [PATCH] Apply themes with Mate

wallpaper, icon, cursor, gtk2 theme, metacity theme
---
 app/app.pri                              |  6 ++--
 app/src/desktopthemes/matetheme.cpp      | 41 ++++++++++++++++++++++++
 app/src/desktopthemes/matetheme.h        | 23 +++++++++++++
 app/src/handlers/desktopthemehandler.cpp | 29 +++++++++++++++++
 4 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 app/src/desktopthemes/matetheme.cpp
 create mode 100644 app/src/desktopthemes/matetheme.h

diff --git a/app/app.pri b/app/app.pri
index 3dc35f8..1df830d 100644
--- a/app/app.pri
+++ b/app/app.pri
@@ -32,11 +32,13 @@ unix:!ios:!android {
         $${PWD}/src/handlers/desktopthemehandler.h \
         $${PWD}/src/desktopthemes/kdetheme.h \
         $${PWD}/src/desktopthemes/gnometheme.h \
-        $${PWD}/src/desktopthemes/xfcetheme.h
+        $${PWD}/src/desktopthemes/xfcetheme.h \
+        $${PWD}/src/desktopthemes/matetheme.h
 
     SOURCES += \
         $${PWD}/src/handlers/desktopthemehandler.cpp \
         $${PWD}/src/desktopthemes/kdetheme.cpp \
         $${PWD}/src/desktopthemes/gnometheme.cpp \
-        $${PWD}/src/desktopthemes/xfcetheme.cpp
+        $${PWD}/src/desktopthemes/xfcetheme.cpp \
+        $${PWD}/src/desktopthemes/matetheme.cpp
 }
diff --git a/app/src/desktopthemes/matetheme.cpp b/app/src/desktopthemes/matetheme.cpp
new file mode 100644
index 0000000..6e10f45
--- /dev/null
+++ b/app/src/desktopthemes/matetheme.cpp
@@ -0,0 +1,41 @@
+#include "matetheme.h"
+
+#include <QStringList>
+#include <QDir>
+#include <QProcess>
+
+MateTheme::MateTheme(const QString &path, QObject *parent)
+    : QObject(parent), path_(path)
+{
+    themeName_ = QDir(path_).dirName();
+}
+
+bool MateTheme::applyAsWallpaper() const
+{
+    return setConfig("org.mate.background", "picture-filename", path_);
+}
+
+bool MateTheme::applyAsIcon() const
+{
+    return setConfig("org.mate.interface", "icon-theme", themeName_);
+}
+
+bool MateTheme::applyAsCursor() const
+{
+    return setConfig("org.mate.peripherals-mouse", "cursor-theme", themeName_);
+}
+
+bool MateTheme::applyAsGtk2Theme() const
+{
+    return setConfig("org.mate.interface", "gtk-theme", themeName_);
+}
+
+bool MateTheme::applyAsMetacityTheme() const
+{
+    return setConfig("org.mate.Marco.general", "theme", themeName_);
+}
+
+bool MateTheme::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/matetheme.h b/app/src/desktopthemes/matetheme.h
new file mode 100644
index 0000000..35032c4
--- /dev/null
+++ b/app/src/desktopthemes/matetheme.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <QObject>
+
+class MateTheme : public QObject
+{
+    Q_OBJECT
+
+public:
+    explicit MateTheme(const QString &path, QObject *parent = nullptr);
+
+    bool applyAsWallpaper() const;
+    bool applyAsIcon() const;
+    bool applyAsCursor() const;
+    bool applyAsGtk2Theme() const;
+    bool applyAsMetacityTheme() const;
+
+private:
+    bool setConfig(const QString &schema, const QString &key, const QString &value) const;
+
+    QString path_;
+    QString themeName_;
+};
diff --git a/app/src/handlers/desktopthemehandler.cpp b/app/src/handlers/desktopthemehandler.cpp
index 923883c..ea978dc 100644
--- a/app/src/handlers/desktopthemehandler.cpp
+++ b/app/src/handlers/desktopthemehandler.cpp
@@ -8,6 +8,7 @@
 #include "desktopthemes/kdetheme.h"
 #include "desktopthemes/gnometheme.h"
 #include "desktopthemes/xfcetheme.h"
+#include "desktopthemes/matetheme.h"
 #endif
 
 DesktopThemeHandler::DesktopThemeHandler(QObject *parent)
@@ -38,6 +39,9 @@ QString DesktopThemeHandler::desktopEnvironment() const
     else if (currentDesktop.contains("xfce")) {
         desktop = "xfce";
     }
+    else if (currentDesktop.contains("mate")) {
+        desktop = "mate";
+    }
 
     return desktop;
 }
@@ -69,6 +73,13 @@ bool DesktopThemeHandler::isApplicableType(const QString &installType) const
                         << "gtk2_themes"
                         << "xfwm4_themes";
     }
+    else if (desktop == "mate") {
+        applicableTypes << "wallpapers"
+                        << "icons"
+                        << "cursors"
+                        << "gtk2_themes"
+                        << "metacity_themes";
+    }
 
     return applicableTypes.contains(installType);
 }
@@ -133,6 +144,24 @@ bool DesktopThemeHandler::applyTheme(const QString &path, const QString &install
                 return xfceTheme.applyAsXfwm4Theme();
             }
         }
+        else if (desktop == "mate") {
+            MateTheme mateTheme(path);
+            if (installType == "wallpapers") {
+                return mateTheme.applyAsWallpaper();
+            }
+            else if (installType == "icons") {
+                return mateTheme.applyAsIcon();
+            }
+            else if (installType == "cursors") {
+                return mateTheme.applyAsCursor();
+            }
+            else if (installType == "gtk2_themes") {
+                return mateTheme.applyAsGtk2Theme();
+            }
+            else if (installType == "metacity_themes") {
+                return mateTheme.applyAsMetacityTheme();
+            }
+        }
     }
 
     return false;
-- 
GitLab