diff --git a/kcms/lookandfeel/kcm.h b/kcms/lookandfeel/kcm.h --- a/kcms/lookandfeel/kcm.h +++ b/kcms/lookandfeel/kcm.h @@ -40,6 +40,7 @@ Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged) Q_PROPERTY(int selectedPluginIndex READ selectedPluginIndex NOTIFY selectedPluginIndexChanged) + Q_PROPERTY(bool applyWallpaper READ applyWallpaper WRITE setApplyWallpaper NOTIFY applyWallpaperChanged) Q_PROPERTY(bool applyColors READ applyColors WRITE setApplyColors NOTIFY applyColorsChanged) Q_PROPERTY(bool applyWidgetStyle READ applyWidgetStyle WRITE setApplyWidgetStyle NOTIFY applyWidgetStyleChanged) Q_PROPERTY(bool applyIcons READ applyIcons WRITE setApplyIcons NOTIFY applyIconsChanged) @@ -91,6 +92,8 @@ void setDesktopSwitcher(const QString &theme); void setWindowDecoration(const QString &library, const QString &theme); + void setApplyWallpaper(bool apply); + bool applyWallpaper() const; void setApplyColors(bool apply); bool applyColors() const; void setApplyWidgetStyle(bool apply); @@ -118,6 +121,7 @@ Q_SIGNALS: void selectedPluginChanged(); + void applyWallpaperChanged(); void applyColorsChanged(); void applyWidgetStyleChanged(); void applyIconsChanged(); @@ -139,6 +143,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"); @@ -727,6 +772,21 @@ QDBusConnection::sessionBus().send(message); } +void KCMLookandFeel::setApplyWallpaper(bool apply) +{ + if (m_applyWallpaper == apply) { + return; + } + + m_applyWallpaper = apply; + emit applyWallpaperChanged(); +} + +bool KCMLookandFeel::applyWallpaper() const +{ + return m_applyWallpaper; +} + void KCMLookandFeel::setApplyColors(bool apply) { if (m_applyColors == apply) {