diff --git a/kcms/lookandfeel/kcm.h b/kcms/lookandfeel/kcm.h --- a/kcms/lookandfeel/kcm.h +++ b/kcms/lookandfeel/kcm.h @@ -139,6 +139,7 @@ KConfig m_config; KConfigGroup m_configGroup; + bool m_applyWallpaper : 1; bool m_applyColors : 1; bool m_applyWidgetStyle : 1; bool m_applyIcons : 1; diff --git a/kcms/lookandfeel/kcm.cpp b/kcms/lookandfeel/kcm.cpp --- a/kcms/lookandfeel/kcm.cpp +++ b/kcms/lookandfeel/kcm.cpp @@ -46,6 +46,10 @@ #include #include +#include +#include +#include + #include #include @@ -57,6 +61,7 @@ : KQuickAddons::ConfigModule(parent, args) , m_config(QStringLiteral("kdeglobals")) , m_configGroup(m_config.group("KDE")) + , m_applyWallpaper(true) , m_applyColors(true) , m_applyWidgetStyle(true) , m_applyIcons(true) @@ -297,6 +302,46 @@ setWidgetStyle(cg.readEntry("widgetStyle", QString())); } + if (m_applyWallpaper) { + KConfigGroup cg(conf, "Wallpaper"); + //cg = KConfigGroup(&cg, "KDE"); + const QString image = cg.readEntry("Image", ""); + if (!image.isEmpty()) { + QString imagePath; + // Distinguish between the case of a file and a Wallpaper package + KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images")); + package.setPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers/") + image, QStandardPaths::LocateDirectory)); + + if (package.isValid()) { + imagePath = image; + } else { + imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers/") + image); + } + + if (!imagePath.isEmpty()) { + QDBusMessage message = QDBusMessage::createMethodCall( + QLatin1String("org.kde.plasmashell"), + QLatin1String("/PlasmaShell"), + QLatin1String("org.kde.PlasmaShell"), + QLatin1String("evaluateScript")); + + message << QStringLiteral("var desktop = desktopForScreen(0);" + "desktop.wallpaperPlugin = \"org.kde.image\";" + "desktop.currentConfigGroup = new Array(\"Wallpaper\", \"org.kde.image\", \"General\");" + "desktop.writeConfig(\"Image\", \"%1\");" + "desktop.reloadConfig();").arg(imagePath); + + QDBusMessage reply = QDBusConnection::sessionBus().call(message); + + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning() << "Error setting the wallpaper" << imagePath << reply.errorMessage(); + } + } else { + qWarning() << "Wallpaper not found: " << image; + } + } + } + if (m_applyColors) { QString colorsFile = package.filePath("colors"); KConfigGroup cg(conf, "kdeglobals");