From 5b2b93411731f019e80820142ab64cd65d459b67 Mon Sep 17 00:00:00 2001
From: Akira Ohgaki <akiraohgaki@gmail.com>
Date: Thu, 22 Jun 2017 19:24:09 +0900
Subject: [PATCH] Apply aurorae theme with kde

---
 app/src/handlers/systemhandler.cpp | 32 +++++++++++++++++++++++++++++-
 app/src/handlers/systemhandler.h   |  1 +
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/app/src/handlers/systemhandler.cpp b/app/src/handlers/systemhandler.cpp
index 52ef97a..0264398 100644
--- a/app/src/handlers/systemhandler.cpp
+++ b/app/src/handlers/systemhandler.cpp
@@ -99,7 +99,8 @@ bool SystemHandler::isApplicableType(const QString &installType) const
         applicableTypes << "wallpapers"
                         << "icons"
                         << "cursors"
-                        << "plasma_desktopthemes";
+                        << "plasma_desktopthemes"
+                        << "aurorae_themes";
     }
     else if (desktop == "gnome") {
         applicableTypes << "wallpapers"
@@ -134,6 +135,9 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c
             else if (installType == "plasma_desktopthemes") {
                 return applyKdePlasmaDesktoptheme(path);
             }
+            else if (installType == "aurorae_themes") {
+                return applyKdeAuroraeTheme(path);
+            }
         }
         else if (desktop == "gnome") {
             if (installType == "wallpapers") {
@@ -266,6 +270,32 @@ bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const
     return true;
 }
 
+bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const
+{
+    auto themeName = QFileInfo(path).fileName();
+    auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
+
+    QString script;
+    QTextStream out(&script);
+    out << "var c = ConfigFile('kwinrc');"
+        << "c.group = 'org.kde.kdecoration2';"
+        << "c.writeEntry('library', 'org.kde.kwin.aurorae');"
+        << "c.writeEntry('theme', '__aurorae__svg__" + themeName + "');";
+
+    QVariantList arguments;
+    arguments << QVariant(script);
+    message.setArguments(arguments);
+
+    auto reply = QDBusConnection::sessionBus().call(message);
+
+    if (reply.type() == QDBusMessage::ErrorMessage) {
+        qWarning() << reply.errorMessage();
+        return false;
+    }
+
+    return true;
+}
+
 bool SystemHandler::applyGnomeWallpaper(const QString &path) const
 {
     QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path};
diff --git a/app/src/handlers/systemhandler.h b/app/src/handlers/systemhandler.h
index 764a38e..f9bd1ee 100644
--- a/app/src/handlers/systemhandler.h
+++ b/app/src/handlers/systemhandler.h
@@ -27,6 +27,7 @@ private:
     bool applyKdeIcon(const QString &path) const;
     bool applyKdeCursor(const QString &path) const;
     bool applyKdePlasmaDesktoptheme(const QString &path) const;
+    bool applyKdeAuroraeTheme(const QString &path) const;
 
     bool applyGnomeWallpaper(const QString &path) const;
     bool applyGnomeIcon(const QString &path) const;
-- 
GitLab