Skip to content
Snippets Groups Projects
Commit 0c7fc789 authored by akiraohgaki's avatar akiraohgaki
Browse files

Merge branch 'feature/apply' into develop

parents 8ca4d230 ee8779f4
No related branches found
No related tags found
No related merge requests found
...@@ -110,7 +110,11 @@ bool SystemHandler::isApplicableType(const QString &installType) const ...@@ -110,7 +110,11 @@ bool SystemHandler::isApplicableType(const QString &installType) const
<< "gnome_shell_themes"; << "gnome_shell_themes";
} }
else if (desktop == "xfce") { else if (desktop == "xfce") {
applicableTypes << "wallpapers"; applicableTypes << "wallpapers"
<< "icons"
<< "cursors"
<< "gtk2_themes"
<< "xfwm4_themes";
} }
return applicableTypes.contains(installType); return applicableTypes.contains(installType);
...@@ -121,22 +125,23 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c ...@@ -121,22 +125,23 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c
{ {
if (QFileInfo::exists(path) && isApplicableType(installType)) { if (QFileInfo::exists(path) && isApplicableType(installType)) {
auto desktop = desktopEnvironment(); auto desktop = desktopEnvironment();
auto themeName = QFileInfo(path).fileName();
if (desktop == "kde") { if (desktop == "kde") {
if (installType == "wallpapers") { if (installType == "wallpapers") {
return applyKdeWallpaper(path); return applyKdeWallpaper(path);
} }
else if (installType == "icons") { else if (installType == "icons") {
return applyKdeIcon(path); return applyKdeIcon(themeName);
} }
else if (installType == "cursors") { else if (installType == "cursors") {
return applyKdeCursor(path); return applyKdeCursor(themeName);
} }
else if (installType == "plasma5_desktopthemes") { else if (installType == "plasma5_desktopthemes") {
return applyKdePlasmaDesktoptheme(path); return applyKdePlasmaDesktoptheme(themeName);
} }
else if (installType == "aurorae_themes") { else if (installType == "aurorae_themes") {
return applyKdeAuroraeTheme(path); return applyKdeAuroraeTheme(themeName);
} }
} }
else if (desktop == "gnome") { else if (desktop == "gnome") {
...@@ -144,22 +149,34 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c ...@@ -144,22 +149,34 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c
return applyGnomeWallpaper(path); return applyGnomeWallpaper(path);
} }
else if (installType == "icons") { else if (installType == "icons") {
return applyGnomeIcon(path); return applyGnomeIcon(themeName);
} }
else if (installType == "cursors") { else if (installType == "cursors") {
return applyGnomeCursor(path); return applyGnomeCursor(themeName);
} }
else if (installType == "gtk3_themes") { else if (installType == "gtk3_themes") {
return applyGnomeGtk3Theme(path); return applyGnomeGtk3Theme(themeName);
} }
else if (installType == "gnome_shell_themes") { else if (installType == "gnome_shell_themes") {
return applyGnomeGnomeShellTheme(path); return applyGnomeGnomeShellTheme(themeName);
} }
} }
else if (desktop == "xfce") { else if (desktop == "xfce") {
if (installType == "wallpapers") { if (installType == "wallpapers") {
return applyXfceWallpaper(path); return applyXfceWallpaper(path);
} }
else if (installType == "icons") {
return applyXfceIcon(themeName);
}
else if (installType == "cursors") {
return applyXfceCursor(themeName);
}
else if (installType == "gtk2_themes") {
return applyXfceGtk2Theme(themeName);
}
else if (installType == "xfwm4_themes") {
return applyXfceXfwm4Theme(themeName);
}
} }
} }
...@@ -168,7 +185,7 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c ...@@ -168,7 +185,7 @@ bool SystemHandler::applyFile(const QString &path, const QString &installType) c
#endif #endif
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool SystemHandler::evaluateScriptWithPlasmaShell(const QString &script) const bool SystemHandler::setConfigWithPlasmaShell(const QString &script) const
{ {
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript"); auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
message.setArguments(QVariantList() << QVariant(script)); message.setArguments(QVariantList() << QVariant(script));
...@@ -192,62 +209,52 @@ bool SystemHandler::applyKdeWallpaper(const QString &path) const ...@@ -192,62 +209,52 @@ bool SystemHandler::applyKdeWallpaper(const QString &path) const
<< "d.writeConfig('Image', 'file://" + path + "');" << "d.writeConfig('Image', 'file://" + path + "');"
<< "}"; << "}";
return evaluateScriptWithPlasmaShell(script); return setConfigWithPlasmaShell(script);
} }
bool SystemHandler::applyKdeIcon(const QString &path) const bool SystemHandler::applyKdeIcon(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName();
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
out << "var c = ConfigFile('kdeglobals');" out << "var c = ConfigFile('kdeglobals');"
<< "c.group = 'Icons';" << "c.group = 'Icons';"
<< "c.writeEntry('Theme', '" + themeName + "');"; << "c.writeEntry('Theme', '" + themeName + "');";
if (evaluateScriptWithPlasmaShell(script)) { if (setConfigWithPlasmaShell(script)) {
QProcess::startDetached("kquitapp5 plasmashell"); QProcess::startDetached("kquitapp5 plasmashell && kstart5 plasmashell");
QProcess::startDetached("kstart5 plasmashell");
return true; return true;
} }
return false; return false;
} }
bool SystemHandler::applyKdeCursor(const QString &path) const bool SystemHandler::applyKdeCursor(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName();
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
out << "var c = ConfigFile('kcminputrc');" out << "var c = ConfigFile('kcminputrc');"
<< "c.group = 'Mouse';" << "c.group = 'Mouse';"
<< "c.writeEntry('cursorTheme', '" + themeName + "');"; << "c.writeEntry('cursorTheme', '" + themeName + "');";
return evaluateScriptWithPlasmaShell(script); return setConfigWithPlasmaShell(script);
} }
bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &path) const bool SystemHandler::applyKdePlasmaDesktoptheme(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName();
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
out << "var c = ConfigFile('plasmarc');" out << "var c = ConfigFile('plasmarc');"
<< "c.group = 'Theme';" << "c.group = 'Theme';"
<< "c.writeEntry('name', '" + themeName + "');"; << "c.writeEntry('name', '" + themeName + "');";
if (evaluateScriptWithPlasmaShell(script)) { if (setConfigWithPlasmaShell(script)) {
QProcess::startDetached("kquitapp5 plasmashell"); QProcess::startDetached("kquitapp5 plasmashell && kstart5 plasmashell");
QProcess::startDetached("kstart5 plasmashell");
return true; return true;
} }
return false; return false;
} }
bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const bool SystemHandler::applyKdeAuroraeTheme(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName();
QString script; QString script;
QTextStream out(&script); QTextStream out(&script);
out << "var c = ConfigFile('kwinrc');" out << "var c = ConfigFile('kwinrc');"
...@@ -255,57 +262,48 @@ bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const ...@@ -255,57 +262,48 @@ bool SystemHandler::applyKdeAuroraeTheme(const QString &path) const
<< "c.writeEntry('library', 'org.kde.kwin.aurorae');" << "c.writeEntry('library', 'org.kde.kwin.aurorae');"
<< "c.writeEntry('theme', '__aurorae__svg__" + themeName + "');"; << "c.writeEntry('theme', '__aurorae__svg__" + themeName + "');";
if (evaluateScriptWithPlasmaShell(script)) { if (setConfigWithPlasmaShell(script)) {
auto refreshMessage = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "reconfigure"); auto message = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "reconfigure");
QDBusConnection::sessionBus().call(refreshMessage); QDBusConnection::sessionBus().call(message);
return true; return true;
} }
return false; return false;
} }
bool SystemHandler::applyGnomeWallpaper(const QString &path) const bool SystemHandler::setConfigWithGsettings(const QString &schema, const QString &key, const QString &value) const
{ {
QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path}; return QProcess::startDetached("gsettings", QStringList() << "set" << schema << key << value);
return QProcess::startDetached("gsettings", arguments);
} }
bool SystemHandler::applyGnomeIcon(const QString &path) const bool SystemHandler::applyGnomeWallpaper(const QString &path) const
{ {
auto themeName = QFileInfo(path).fileName(); return setConfigWithGsettings("org.gnome.desktop.background", "picture-uri", "file://" + path);
QStringList arguments{"set", "org.gnome.desktop.interface", "icon-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
} }
bool SystemHandler::applyGnomeCursor(const QString &path) const bool SystemHandler::applyGnomeIcon(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName(); return setConfigWithGsettings("org.gnome.desktop.interface", "icon-theme", themeName);
QStringList arguments{"set", "org.gnome.desktop.interface", "cursor-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
} }
bool SystemHandler::applyGnomeGtk3Theme(const QString &path) const bool SystemHandler::applyGnomeCursor(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName(); return setConfigWithGsettings("org.gnome.desktop.interface", "cursor-theme", themeName);
QStringList arguments{"set", "org.gnome.desktop.interface", "gtk-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
} }
bool SystemHandler::applyGnomeGnomeShellTheme(const QString &path) const bool SystemHandler::applyGnomeGtk3Theme(const QString &themeName) const
{ {
auto themeName = QFileInfo(path).fileName(); return setConfigWithGsettings("org.gnome.desktop.interface", "gtk-theme", themeName);
QStringList arguments{"set", "org.gnome.shell.extensions.user-theme", "name", themeName};
return QProcess::startDetached("gsettings", arguments);
} }
bool SystemHandler::applyXfceWallpaper(const QString &path) const bool SystemHandler::applyGnomeGnomeShellTheme(const QString &themeName) const
{ {
QString channelValue = "xfce4-desktop"; return setConfigWithGsettings("org.gnome.shell.extensions.user-theme", "name", themeName);
//QString propertyValue = "/backdrop/screen0/monitor0/image-path"; }
QString propertyValue = "/backdrop/screen0/monitor0/workspace0/last-image";
QDBusVariant valueValue(path);
bool SystemHandler::setConfigWithXfconf(const QString &channel, const QString &property, const QString &value) const
{
auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty"); auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty");
message.setArguments(QVariantList() << QVariant(channelValue) << QVariant(propertyValue) << QVariant::fromValue(valueValue)); message.setArguments(QVariantList() << QVariant(channel) << QVariant(property) << QVariant::fromValue(QDBusVariant(value)));
auto reply = QDBusConnection::sessionBus().call(message); auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) { if (reply.type() == QDBusMessage::ErrorMessage) {
...@@ -314,4 +312,29 @@ bool SystemHandler::applyXfceWallpaper(const QString &path) const ...@@ -314,4 +312,29 @@ bool SystemHandler::applyXfceWallpaper(const QString &path) const
} }
return true; return true;
} }
bool SystemHandler::applyXfceWallpaper(const QString &path) const
{
return setConfigWithXfconf("xfce4-desktop", "/backdrop/screen0/monitor0/workspace0/last-image", path);
}
bool SystemHandler::applyXfceIcon(const QString &themeName) const
{
return setConfigWithXfconf("xsettings", "/Net/IconThemeName", themeName);
}
bool SystemHandler::applyXfceCursor(const QString &themeName) const
{
return setConfigWithXfconf("xsettings", "/Gtk/CursorThemeName", themeName);
}
bool SystemHandler::applyXfceGtk2Theme(const QString &themeName) const
{
return setConfigWithXfconf("xsettings", "/Net/ThemeName", themeName);
}
bool SystemHandler::applyXfceXfwm4Theme(const QString &themeName) const
{
return setConfigWithXfconf("xfwm4", "/general/theme", themeName);
}
#endif #endif
...@@ -23,19 +23,25 @@ public slots: ...@@ -23,19 +23,25 @@ public slots:
private: private:
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool evaluateScriptWithPlasmaShell(const QString &script) const; bool setConfigWithPlasmaShell(const QString &script) const;
bool applyKdeWallpaper(const QString &path) const; bool applyKdeWallpaper(const QString &path) const;
bool applyKdeIcon(const QString &path) const; bool applyKdeIcon(const QString &themeName) const;
bool applyKdeCursor(const QString &path) const; bool applyKdeCursor(const QString &themeName) const;
bool applyKdePlasmaDesktoptheme(const QString &path) const; bool applyKdePlasmaDesktoptheme(const QString &themeName) const;
bool applyKdeAuroraeTheme(const QString &path) const; bool applyKdeAuroraeTheme(const QString &themeName) const;
bool setConfigWithGsettings(const QString &schema, const QString &key, const QString &value) const;
bool applyGnomeWallpaper(const QString &path) const; bool applyGnomeWallpaper(const QString &path) const;
bool applyGnomeIcon(const QString &path) const; bool applyGnomeIcon(const QString &themeName) const;
bool applyGnomeCursor(const QString &path) const; bool applyGnomeCursor(const QString &themeName) const;
bool applyGnomeGtk3Theme(const QString &path) const; bool applyGnomeGtk3Theme(const QString &themeName) const;
bool applyGnomeGnomeShellTheme(const QString &path) const; bool applyGnomeGnomeShellTheme(const QString &themeName) const;
bool setConfigWithXfconf(const QString &channel, const QString &property, const QString &value) const;
bool applyXfceWallpaper(const QString &path) const; bool applyXfceWallpaper(const QString &path) const;
bool applyXfceIcon(const QString &themeName) const;
bool applyXfceCursor(const QString &themeName) const;
bool applyXfceGtk2Theme(const QString &themeName) const;
bool applyXfceXfwm4Theme(const QString &themeName) const;
#endif #endif
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment