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

Merge branch 'feature/apply' into develop

parents 01f92bac 86fb1cae
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,7 @@ bool SystemHandler::openUrl(const QString &url) const ...@@ -64,7 +64,7 @@ bool SystemHandler::openUrl(const QString &url) const
QString SystemHandler::desktopEnvironment() const QString SystemHandler::desktopEnvironment() const
{ {
QString desktop = "unknown"; QString desktop = "";
QString currentDesktop = ""; QString currentDesktop = "";
if (!qgetenv("XDG_CURRENT_DESKTOP").isEmpty()) { if (!qgetenv("XDG_CURRENT_DESKTOP").isEmpty()) {
...@@ -93,157 +93,146 @@ bool SystemHandler::isApplicableType(const QString &installType) const ...@@ -93,157 +93,146 @@ bool SystemHandler::isApplicableType(const QString &installType) const
{ {
auto desktop = desktopEnvironment(); auto desktop = desktopEnvironment();
if (installType == "wallpapers" QStringList applicableTypes;
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) {
return true; if (desktop == "kde") {
applicableTypes << "wallpapers";
} }
else if (installType == "icons" else if (desktop == "gnome") {
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) { applicableTypes << "wallpapers"
return true; << "icons"
<< "cursors"
<< "gtk3_themes"
<< "gnome_shell_themes";
} }
/*else if (installType == "cursors" else if (desktop == "xfce") {
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) { applicableTypes << "wallpapers";
return true;
} }
else if ((installType == "aurorae_themes" && desktop == "kde")
|| (installType == "metacity_themes" && desktop == "gnome") return applicableTypes.contains(installType);
|| (installType == "xfwm4_themes" && desktop == "xfce")) {
return true;
}*/
return false;
} }
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool SystemHandler::applyFile(const QString &path, const QString &installType) const bool SystemHandler::applyFile(const QString &path, const QString &installType) const
{ {
if (QFileInfo::exists(path) && isApplicableType(installType)) { if (QFileInfo::exists(path) && isApplicableType(installType)) {
if (installType == "wallpapers") { auto desktop = desktopEnvironment();
return applyWallpaper(path);
if (desktop == "kde") {
if (installType == "wallpapers") {
return applyKdeWallpaper(path);
}
} }
else if (installType == "icons") { else if (desktop == "gnome") {
return applyIcon(path); if (installType == "wallpapers") {
return applyGnomeWallpaper(path);
}
else if (installType == "icons") {
return applyGnomeIcon(path);
}
else if (installType == "cursors") {
return applyGnomeCursor(path);
}
else if (installType == "gtk3_themes") {
return applyGnomeGtk3Theme(path);
}
else if (installType == "gnome_shell_themes") {
return applyGnomeGnomeShellTheme(path);
}
} }
/*else if (installType == "cursors") { else if (desktop == "xfce") {
return applyCursor(path); if (installType == "wallpapers") {
return applyXfceWallpaper(path);
}
} }
else if (installType == "aurorae_themes"
|| installType == "metacity_themes"
|| installType == "xfwm4_themes") {
return applyWindowTheme(path);
}*/
} }
return false; return false;
} }
#endif #endif
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool SystemHandler::applyWallpaper(const QString &path) const bool SystemHandler::applyKdeWallpaper(const QString &path) const
{ {
auto desktop = desktopEnvironment(); auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
if (desktop == "kde") {
// plasma5.6+
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QVariantList arguments;
QString script;
QTextStream out(&script);
out << "for (var key in desktops()) {"
<< "var d = desktops()[key];"
<< "d.wallpaperPlugin = 'org.kde.image';"
<< "d.currentConfigGroup = ['Wallpaper', 'org.kde.image', 'General'];"
<< "d.writeConfig('Image', 'file://" + path + "');"
<< "}";
arguments << QVariant(script);
message.setArguments(arguments);
auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
}
return true;
}
else if (desktop == "gnome") {
// gnome3
QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path};
return QProcess::startDetached("gsettings", arguments);
// gnome2
//QStringList arguments{"--type=string", "--set", "/desktop/gnome/background/picture_filename", path};
//return QProcess::startDetached("gconftool-2", arguments);
}
else if (desktop == "xfce") {
auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty");
QVariantList arguments;
QString channelValue = "xfce4-desktop"; QString script;
//QString propertyValue = "/backdrop/screen0/monitor0/image-path"; QTextStream out(&script);
QString propertyValue = "/backdrop/screen0/monitor0/workspace0/last-image"; out << "for (var key in desktops()) {"
QDBusVariant valueValue(path); << "var d = desktops()[key];"
<< "d.wallpaperPlugin = 'org.kde.image';"
<< "d.currentConfigGroup = ['Wallpaper', 'org.kde.image', 'General'];"
<< "d.writeConfig('Image', 'file://" + path + "');"
<< "}";
arguments << QVariant(channelValue) << QVariant(propertyValue) << QVariant::fromValue(valueValue); QVariantList arguments;
message.setArguments(arguments); arguments << QVariant(script);
message.setArguments(arguments);
auto reply = QDBusConnection::sessionBus().call(message); auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) { if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage(); qWarning() << reply.errorMessage();
return false; return false;
}
return true;
} }
return false;
return true;
} }
bool SystemHandler::applyIcon(const QString &path) const bool SystemHandler::applyGnomeWallpaper(const QString &path) const
{ {
auto desktop = desktopEnvironment(); QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path};
return QProcess::startDetached("gsettings", arguments);
if (path.endsWith("/")) { }
}
if (desktop == "kde") { bool SystemHandler::applyGnomeIcon(const QString &path) const
} {
else if (desktop == "gnome") { auto themeName = QFileInfo(path).fileName();
// gnome3 QStringList arguments{"set", "org.gnome.desktop.interface", "icon-theme", themeName};
auto themeName = QFileInfo(path).fileName(); return QProcess::startDetached("gsettings", arguments);
QStringList arguments{"set", "org.gnome.desktop.interface", "icon-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
}
else if (desktop == "xfce") {
}
return false;
} }
bool SystemHandler::applyCursor(const QString &path) const bool SystemHandler::applyGnomeCursor(const QString &path) const
{ {
qDebug() << path; auto themeName = QFileInfo(path).fileName();
QStringList arguments{"set", "org.gnome.desktop.interface", "cursor-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
}
auto desktop = desktopEnvironment(); bool SystemHandler::applyGnomeGtk3Theme(const QString &path) const
{
auto themeName = QFileInfo(path).fileName();
QStringList arguments{"set", "org.gnome.desktop.interface", "gtk-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
}
if (desktop == "kde") { bool SystemHandler::applyGnomeGnomeShellTheme(const QString &path) const
} {
else if (desktop == "gnome") { auto themeName = QFileInfo(path).fileName();
} QStringList arguments{"set", "org.gnome.shell.extensions.user-theme", "name", themeName};
else if (desktop == "xfce") { return QProcess::startDetached("gsettings", arguments);
}
return false;
} }
bool SystemHandler::applyWindowTheme(const QString &path) const bool SystemHandler::applyXfceWallpaper(const QString &path) const
{ {
qDebug() << path; auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty");
auto desktop = desktopEnvironment(); QString channelValue = "xfce4-desktop";
//QString propertyValue = "/backdrop/screen0/monitor0/image-path";
QString propertyValue = "/backdrop/screen0/monitor0/workspace0/last-image";
QDBusVariant valueValue(path);
if (desktop == "kde") { QVariantList arguments;
} arguments << QVariant(channelValue) << QVariant(propertyValue) << QVariant::fromValue(valueValue);
else if (desktop == "gnome") { message.setArguments(arguments);
}
else if (desktop == "xfce") { auto reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << reply.errorMessage();
return false;
} }
return false;
return true;
} }
#endif #endif
...@@ -23,9 +23,14 @@ public slots: ...@@ -23,9 +23,14 @@ public slots:
private: private:
#ifdef QTLIB_UNIX #ifdef QTLIB_UNIX
bool applyWallpaper(const QString &path) const; bool applyKdeWallpaper(const QString &path) const;
bool applyIcon(const QString &path) const;
bool applyCursor(const QString &path) const; bool applyGnomeWallpaper(const QString &path) const;
bool applyWindowTheme(const QString &path) const; bool applyGnomeIcon(const QString &path) const;
bool applyGnomeCursor(const QString &path) const;
bool applyGnomeGtk3Theme(const QString &path) const;
bool applyGnomeGnomeShellTheme(const QString &path) const;
bool applyXfceWallpaper(const QString &path) const;
#endif #endif
}; };
...@@ -15,7 +15,7 @@ int main(int argc, char *argv[]) ...@@ -15,7 +15,7 @@ int main(int argc, char *argv[])
// Init // Init
QGuiApplication app(argc, argv); // This is backend program, but need GUI module QGuiApplication app(argc, argv); // This is backend program, but need GUI module
auto *configHandler = new ConfigHandler(); auto *configHandler = new ConfigHandler(&app);
auto appConfigApplication = configHandler->getAppConfigApplication(); auto appConfigApplication = configHandler->getAppConfigApplication();
app.setApplicationName(appConfigApplication["name"].toString()); app.setApplicationName(appConfigApplication["name"].toString());
......
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