From bfc86dda43ce3b9daad906647b7cf466783aa79e Mon Sep 17 00:00:00 2001
From: Akira Ohgaki <akiraohgaki@gmail.com>
Date: Thu, 22 Jun 2017 18:32:55 +0900
Subject: [PATCH] Apply cursor with kde

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

diff --git a/app/src/handlers/systemhandler.cpp b/app/src/handlers/systemhandler.cpp
index 2c8d77d..b7d7bc3 100644
--- a/app/src/handlers/systemhandler.cpp
+++ b/app/src/handlers/systemhandler.cpp
@@ -97,7 +97,8 @@ bool SystemHandler::isApplicableType(const QString &installType) const
 
     if (desktop == "kde") {
         applicableTypes << "wallpapers"
-                        << "icons";
+                        << "icons"
+                        << "cursors";
     }
     else if (desktop == "gnome") {
         applicableTypes << "wallpapers"
@@ -126,6 +127,9 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c
             else if (installType == "icons") {
                 return applyKdeIcon(path);
             }
+            else if (installType == "cursors") {
+                return applyKdeCursor(path);
+            }
         }
         else if (desktop == "gnome") {
             if (installType == "wallpapers") {
@@ -208,6 +212,31 @@ bool SystemHandler::applyKdeIcon(const QString &path) const
     return true;
 }
 
+bool SystemHandler::applyKdeCursor(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('kcminputrc');"
+        << "c.group = 'Mouse';"
+        << "c.writeEntry('cursorTheme', '" + 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 34fa485..a29cf86 100644
--- a/app/src/handlers/systemhandler.h
+++ b/app/src/handlers/systemhandler.h
@@ -25,6 +25,7 @@ private:
 #ifdef QTLIB_UNIX
     bool applyKdeWallpaper(const QString &path) const;
     bool applyKdeIcon(const QString &path) const;
+    bool applyKdeCursor(const QString &path) const;
 
     bool applyGnomeWallpaper(const QString &path) const;
     bool applyGnomeIcon(const QString &path) const;
-- 
GitLab