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

Organize functions

parent ad32bc1c
No related branches found
No related tags found
No related merge requests found
......@@ -93,57 +93,58 @@ bool SystemHandler::isApplicableType(const QString &installType) const
{
auto desktop = desktopEnvironment();
if (installType == "wallpapers"
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) {
return true;
QStringList applicableTypes;
if (desktop == "kde") {
applicableTypes << "wallpapers";
}
else if (installType == "icons"
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) {
return true;
else if (desktop == "gnome") {
applicableTypes << "wallpapers" << "icons" << "cursors";
}
else if (installType == "cursors"
&& (desktop == "kde" || desktop == "gnome" || desktop == "xfce")) {
return true;
else if (desktop == "xfce") {
applicableTypes << "wallpapers";
}
/*else if ((installType == "aurorae_themes" && desktop == "kde")
|| (installType == "metacity_themes" && desktop == "gnome")
|| (installType == "xfwm4_themes" && desktop == "xfce")) {
return true;
}*/
return false;
return applicableTypes.contains(installType);
}
#ifdef QTLIB_UNIX
bool SystemHandler::applyFile(const QString &path, const QString &installType) const
{
if (QFileInfo::exists(path) && isApplicableType(installType)) {
auto desktop = desktopEnvironment();
if (desktop == "kde") {
if (installType == "wallpapers") {
return applyKdeWallpaper(path);
}
}
else if (desktop == "gnome") {
if (installType == "wallpapers") {
return applyWallpaper(path);
return applyGnomeWallpaper(path);
}
else if (desktop == "icons") {
return applyGnomeIcon(path);
}
else if (installType == "icons") {
return applyIcon(path);
else if (desktop == "cursors") {
return applyGnomeCursor(path);
}
else if (installType == "cursors") {
return applyCursor(path);
}
/*else if (installType == "aurorae_themes"
|| installType == "metacity_themes"
|| installType == "xfwm4_themes") {
return applyWindowTheme(path);
}*/
else if (desktop == "xfce") {
if (installType == "wallpapers") {
return applyXfceWallpaper(path);
}
}
}
return false;
}
#endif
#ifdef QTLIB_UNIX
bool SystemHandler::applyWallpaper(const QString &path) const
bool SystemHandler::applyKdeWallpaper(const QString &path) const
{
auto desktop = desktopEnvironment();
if (desktop == "kde") {
auto message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell", "evaluateScript");
QVariantList arguments;
QString script;
QTextStream out(&script);
......@@ -154,6 +155,7 @@ bool SystemHandler::applyWallpaper(const QString &path) const
<< "d.writeConfig('Image', 'file://" + path + "');"
<< "}";
QVariantList arguments;
arguments << QVariant(script);
message.setArguments(arguments);
......@@ -163,21 +165,40 @@ bool SystemHandler::applyWallpaper(const QString &path) const
qWarning() << reply.errorMessage();
return false;
}
return true;
}
else if (desktop == "gnome") {
bool SystemHandler::applyGnomeWallpaper(const QString &path) const
{
QStringList arguments{"set", "org.gnome.desktop.background", "picture-uri", "file://" + path};
return QProcess::startDetached("gsettings", arguments);
}
else if (desktop == "xfce") {
bool SystemHandler::applyGnomeIcon(const QString &path) const
{
auto themeName = QFileInfo(path).fileName();
QStringList arguments{"set", "org.gnome.desktop.interface", "icon-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
}
bool SystemHandler::applyGnomeCursor(const QString &path) const
{
auto themeName = QFileInfo(path).fileName();
QStringList arguments{"set", "org.gnome.desktop.interface", "cursor-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
}
bool SystemHandler::applyXfceWallpaper(const QString &path) const
{
auto message = QDBusMessage::createMethodCall("org.xfce.Xfconf", "/org/xfce/Xfconf", "org.xfce.Xfconf", "SetProperty");
QVariantList arguments;
QString channelValue = "xfce4-desktop";
//QString propertyValue = "/backdrop/screen0/monitor0/image-path";
QString propertyValue = "/backdrop/screen0/monitor0/workspace0/last-image";
QDBusVariant valueValue(path);
QVariantList arguments;
arguments << QVariant(channelValue) << QVariant(propertyValue) << QVariant::fromValue(valueValue);
message.setArguments(arguments);
......@@ -187,53 +208,7 @@ bool SystemHandler::applyWallpaper(const QString &path) const
qWarning() << reply.errorMessage();
return false;
}
return true;
}
return false;
}
bool SystemHandler::applyIcon(const QString &path) const
{
auto desktop = desktopEnvironment();
if (desktop == "kde") {
}
else if (desktop == "gnome") {
auto themeName = QFileInfo(path).fileName();
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
{
auto desktop = desktopEnvironment();
if (desktop == "kde") {
}
else if (desktop == "gnome") {
auto themeName = QFileInfo(path).fileName();
QStringList arguments{"set", "org.gnome.desktop.interface", "cursor-theme", themeName};
return QProcess::startDetached("gsettings", arguments);
}
else if (desktop == "xfce") {
}
return false;
}
bool SystemHandler::applyWindowTheme(const QString &path) const
{
auto desktop = desktopEnvironment();
if (desktop == "kde") {
}
else if (desktop == "gnome") {
}
else if (desktop == "xfce") {
}
return false;
return true;
}
#endif
......@@ -23,9 +23,12 @@ public slots:
private:
#ifdef QTLIB_UNIX
bool applyWallpaper(const QString &path) const;
bool applyIcon(const QString &path) const;
bool applyCursor(const QString &path) const;
bool applyWindowTheme(const QString &path) const;
bool applyKdeWallpaper(const QString &path) const;
bool applyGnomeWallpaper(const QString &path) const;
bool applyGnomeIcon(const QString &path) const;
bool applyGnomeCursor(const QString &path) const;
bool applyXfceWallpaper(const QString &path) const;
#endif
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment