From 6f5a593d91fbfdd69949941a231e29604a2e22dc Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 1 Mar 2013 15:11:08 +0100 Subject: [PATCH] WallpaperInterface for wallpapers will be used to provide configuration access and a configuration UI --- src/plasma/applet.h | 1 - src/plasma/private/containment_p.cpp | 2 +- src/plasma/scripting/appletscript.cpp | 1 - src/plasma/scripting/appletscript.h | 1 - src/scriptengines/qml/CMakeLists.txt | 1 + .../qml/plasmoid/containmentinterface.cpp | 45 +++---- .../qml/plasmoid/containmentinterface.h | 3 +- .../qml/plasmoid/wallpaperinterface.cpp | 118 ++++++++++++++++++ .../qml/plasmoid/wallpaperinterface.h | 66 ++++++++++ .../qmlpackages/wallpaper/CMakeLists.txt | 2 +- .../qmlpackages/wallpaper/metadata.desktop | 2 +- 11 files changed, 204 insertions(+), 38 deletions(-) create mode 100644 src/scriptengines/qml/plasmoid/wallpaperinterface.cpp create mode 100644 src/scriptengines/qml/plasmoid/wallpaperinterface.h diff --git a/src/plasma/applet.h b/src/plasma/applet.h index 10e0219e1..d6f770960 100644 --- a/src/plasma/applet.h +++ b/src/plasma/applet.h @@ -37,7 +37,6 @@ class QWidget; -class KConfigDialog; class KActionCollection; namespace Plasma diff --git a/src/plasma/private/containment_p.cpp b/src/plasma/private/containment_p.cpp index bfa82bd2a..30f566451 100644 --- a/src/plasma/private/containment_p.cpp +++ b/src/plasma/private/containment_p.cpp @@ -41,7 +41,7 @@ namespace Plasma { -const char ContainmentPrivate::defaultWallpaper[] = "image"; +const char ContainmentPrivate::defaultWallpaper[] = "org.kde.image"; void ContainmentPrivate::addDefaultActions(KActionCollection *actions, Containment *c) { diff --git a/src/plasma/scripting/appletscript.cpp b/src/plasma/scripting/appletscript.cpp index cd21644cd..95b82a180 100644 --- a/src/plasma/scripting/appletscript.cpp +++ b/src/plasma/scripting/appletscript.cpp @@ -20,7 +20,6 @@ #include "scripting/appletscript.h" #include "kconfig.h" -#include "kconfigdialog.h" #include "applet.h" #include "package.h" diff --git a/src/plasma/scripting/appletscript.h b/src/plasma/scripting/appletscript.h index 6f3b917ef..74559ac75 100644 --- a/src/plasma/scripting/appletscript.h +++ b/src/plasma/scripting/appletscript.h @@ -33,7 +33,6 @@ class QAction; class QPainter; class QStyleOptionGraphicsItem; -class KConfigDialog; namespace Plasma { diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index 0e86966e5..c0bf73c2e 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -21,6 +21,7 @@ set(declarative_appletscript_SRCS plasmoid/configview.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp + plasmoid/wallpaperinterface.cpp ) include_directories(${PHONON_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/common) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 8354afe55..7ee26fd64 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -20,6 +20,8 @@ */ #include "containmentinterface.h" +#include "wallpaperinterface.h" +#include "declarative/qmlobject.h" #include #include @@ -34,11 +36,10 @@ #include #include -#include "declarative/qmlobject.h" ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) : AppletInterface(parent), - m_wallpaperQmlObject(0) + m_wallpaperInterface(0) { //TODO: will accept all events specified as registered with containment actions setAcceptedMouseButtons(Qt::RightButton); @@ -162,41 +163,23 @@ void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) void ContainmentInterface::loadWallpaper() { if (m_appletScriptEngine->drawWallpaper()) { - if (m_wallpaperQmlObject) { + if (m_wallpaperInterface) { return; } - Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); - pkg.setDefaultPackageRoot("plasma/wallpapers"); - pkg.setPath("org.kde.wallpaper.image"); + m_wallpaperInterface = new WallpaperInterface(this); + //Qml seems happier if the parent gets set in this way + m_wallpaperInterface->setProperty("parent", QVariant::fromValue(this)); - m_wallpaperQmlObject = new QmlObject(this); - m_wallpaperQmlObject->setSource(QUrl::fromLocalFile(pkg.filePath("mainscript"))); - - if (m_wallpaperQmlObject->mainComponent() && - m_wallpaperQmlObject->rootObject() && - !m_wallpaperQmlObject->mainComponent()->isError()) { - m_wallpaperQmlObject->rootObject()->setProperty("z", -1000); - m_wallpaperQmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this)); - - //set anchors - QQmlExpression expr(qmlObject()->engine()->rootContext(), m_wallpaperQmlObject->rootObject(), "parent"); - QQmlProperty prop(m_wallpaperQmlObject->rootObject(), "anchors.fill"); - prop.write(expr.evaluate()); - - } else if (m_wallpaperQmlObject->mainComponent()) { - qWarning() << "Error loading the wallpaper" << m_wallpaperQmlObject->mainComponent()->errors(); - m_wallpaperQmlObject->deleteLater(); - m_wallpaperQmlObject = 0; - - } else { - qWarning() << "Error loading the wallpaper, package not found"; - } + //set anchors + QQmlExpression expr(qmlObject()->engine()->rootContext(), m_wallpaperInterface, "parent"); + QQmlProperty prop(m_wallpaperInterface, "anchors.fill"); + prop.write(expr.evaluate()); } else { - if (m_wallpaperQmlObject) { - m_wallpaperQmlObject->deleteLater(); - m_wallpaperQmlObject = 0; + if (m_wallpaperInterface) { + m_wallpaperInterface->deleteLater(); + m_wallpaperInterface = 0; } } } diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index 8f2cbebd3..227d8432b 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -28,6 +28,7 @@ #include "appletinterface.h" class QmlObject; +class WallpaperInterface; class ContainmentInterface : public AppletInterface { @@ -86,7 +87,7 @@ protected Q_SLOTS: void loadWallpaper(); private: - QmlObject *m_wallpaperQmlObject; + WallpaperInterface *m_wallpaperInterface; QList m_appletInterfaces; }; diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp new file mode 100644 index 000000000..f46472cbc --- /dev/null +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "wallpaperinterface.h" + +#include "containmentinterface.h" +#include "declarative/configpropertymap.h" +#include "declarative/qmlobject.h" + +#include +#include +#include +#include + +#include +#include + +WallpaperInterface::WallpaperInterface(ContainmentInterface *parent) + : QQuickItem(parent), + m_containmentInterface(parent), + m_qmlObject(0) +{ + if (configScheme()) { + m_configuration = new ConfigPropertyMap(configScheme(), this); + } + + connect(m_containmentInterface->containment(), &Plasma::Containment::wallpaperChanged, + this, &WallpaperInterface::syncWallpaperPackage); + + syncWallpaperPackage(); +} + +WallpaperInterface::~WallpaperInterface() +{} + + +Plasma::Package WallpaperInterface::package() const +{ + return m_pkg; +} + +QObject* WallpaperInterface::configuration() const +{ + return m_configuration; +} + +Plasma::ConfigLoader *WallpaperInterface::configScheme() +{ + if (!m_configLoader) { + const QString xmlPath = m_pkg.filePath("mainconfigxml"); + KConfigGroup cfg = m_containmentInterface->containment()->config(); + cfg = KConfigGroup(&cfg, "Wallpaper"); + if (xmlPath.isEmpty()) { + m_configLoader = new Plasma::ConfigLoader(&cfg, 0); + } else { + QFile file(xmlPath); + m_configLoader = new Plasma::ConfigLoader(&cfg, &file); + } + } + + return m_configLoader; +} + +void WallpaperInterface::syncWallpaperPackage() +{ + if (!m_qmlObject) { + m_qmlObject = new QmlObject(this); + m_qmlObject->setInitializationDelayed(true); + } + + m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); + m_pkg.setDefaultPackageRoot("plasma/wallpapers"); + m_pkg.setPath(m_containmentInterface->containment()->wallpaper()); + + m_qmlObject->setSource(QUrl::fromLocalFile(m_pkg.filePath("mainscript"))); + m_qmlObject->engine()->rootContext()->setContextProperty("wallpaper", this); + m_qmlObject->completeInitialization(); + + if (m_qmlObject->mainComponent() && + m_qmlObject->rootObject() && + !m_qmlObject->mainComponent()->isError()) { + m_qmlObject->rootObject()->setProperty("z", -1000); + m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this)); + + //set anchors + QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_qmlObject->rootObject(), "parent"); + QQmlProperty prop(m_qmlObject->rootObject(), "anchors.fill"); + prop.write(expr.evaluate()); + + } else if (m_qmlObject->mainComponent()) { + qWarning() << "Error loading the wallpaper" << m_qmlObject->mainComponent()->errors(); + m_qmlObject->deleteLater(); + m_qmlObject = 0; + + } else { + qWarning() << "Error loading the wallpaper, package not found"; + } + + emit packageChanged(); +} + +#include "moc_wallpaperinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.h b/src/scriptengines/qml/plasmoid/wallpaperinterface.h new file mode 100644 index 000000000..d7b9814e0 --- /dev/null +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.h @@ -0,0 +1,66 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef WALLPAPERINTERFACE_H +#define WALLPAPERINTERFACE_H + +#include + +#include + +namespace Plasma { + class ConfigLoader; +} + +class ContainmentInterface; +class ConfigPropertyMap; +class QmlObject; + +class WallpaperInterface : public QQuickItem +{ + Q_OBJECT + + //Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) + Q_PROPERTY(QObject* configuration READ configuration CONSTANT) + +public: + WallpaperInterface(ContainmentInterface *parent = 0); + ~WallpaperInterface(); + + Plasma::Package package() const; + + QObject* configuration() const; + + Plasma::ConfigLoader *configScheme(); + +Q_SIGNALS: + void packageChanged(); + +private Q_SLOTS: + void syncWallpaperPackage(); + +private: + ContainmentInterface *m_containmentInterface; + QmlObject *m_qmlObject; + Plasma::Package m_pkg; + ConfigPropertyMap *m_configuration; + Plasma::ConfigLoader *m_configLoader; +}; + +#endif diff --git a/src/shell/qmlpackages/wallpaper/CMakeLists.txt b/src/shell/qmlpackages/wallpaper/CMakeLists.txt index f35c436f6..4a716a70b 100644 --- a/src/shell/qmlpackages/wallpaper/CMakeLists.txt +++ b/src/shell/qmlpackages/wallpaper/CMakeLists.txt @@ -1,4 +1,4 @@ -install(DIRECTORY . DESTINATION ${DATA_INSTALL_DIR}/plasma/wallpapers/org.kde.wallpaper.image PATTERN .svn EXCLUDE PATTERN CMakeLists.txt EXCLUDE PATTERN Messages.sh EXCLUDE) +install(DIRECTORY . DESTINATION ${DATA_INSTALL_DIR}/plasma/wallpapers/org.kde.image PATTERN .svn EXCLUDE PATTERN CMakeLists.txt EXCLUDE PATTERN Messages.sh EXCLUDE) diff --git a/src/shell/qmlpackages/wallpaper/metadata.desktop b/src/shell/qmlpackages/wallpaper/metadata.desktop index 2f0dd871c..24d07a56a 100644 --- a/src/shell/qmlpackages/wallpaper/metadata.desktop +++ b/src/shell/qmlpackages/wallpaper/metadata.desktop @@ -17,7 +17,7 @@ X-KDE-PluginInfo-Author=Marco Martin X-KDE-PluginInfo-Category= X-KDE-PluginInfo-Email=mart@kde.org X-KDE-PluginInfo-License=GPLv2+ -X-KDE-PluginInfo-Name=org.kde.wallpaper.image +X-KDE-PluginInfo-Name=org.kde.image X-KDE-PluginInfo-Version= X-KDE-PluginInfo-Website= X-Plasma-MainScript=ui/main.qml