From 6cede145d5633dcc28970312adc82a5cebc2f5a3 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 6 Mar 2013 17:53:03 +0100 Subject: [PATCH] configview exposes more stuff for containments: subclass --- src/scriptengines/qml/CMakeLists.txt | 1 + .../qml/plasmoid/appletinterface.cpp | 10 +- src/scriptengines/qml/plasmoid/configview.cpp | 92 +------------- src/scriptengines/qml/plasmoid/configview.h | 16 +-- .../qml/plasmoid/containmentconfigview.cpp | 120 ++++++++++++++++++ .../qml/plasmoid/containmentconfigview.h | 57 +++++++++ 6 files changed, 195 insertions(+), 101 deletions(-) create mode 100644 src/scriptengines/qml/plasmoid/containmentconfigview.cpp create mode 100644 src/scriptengines/qml/plasmoid/containmentconfigview.h diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index c0bf73c2e..01164c8e8 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -19,6 +19,7 @@ set(declarative_appletscript_SRCS declarative/qmlobject.cpp plasmoid/appletinterface.cpp plasmoid/configview.cpp + plasmoid/containmentconfigview.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp plasmoid/wallpaperinterface.cpp diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index a76f8f1dd..189e2c520 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -47,6 +47,7 @@ #include "containmentinterface.h" #include "configview.h" +#include "containmentconfigview.h" #include "declarative/configpropertymap.h" #include "declarative/qmlobject.h" #include "declarative/packageaccessmanagerfactory.h" @@ -620,7 +621,14 @@ void AppletInterface::setConfigurationInterfaceShown(bool show) if (show) { if (!m_configView) { - m_configView = new ConfigView(this); + ContainmentInterface *ci = qobject_cast(this); + + if (ci) { + m_configView = new ContainmentConfigView(ci); + } else { + m_configView = new ConfigView(this); + } + m_configView.data()->init(); } m_configView.data()->show(); diff --git a/src/scriptengines/qml/plasmoid/configview.cpp b/src/scriptengines/qml/plasmoid/configview.cpp index 2c7742740..fe663b3f4 100644 --- a/src/scriptengines/qml/plasmoid/configview.cpp +++ b/src/scriptengines/qml/plasmoid/configview.cpp @@ -145,7 +145,7 @@ QVariant ConfigModel::data(const QModelIndex& index, int role) const return m_categories.at(index.row())->icon(); case SourceRole: if (m_appletInterface) { - return QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("components", m_categories.at(index.row())->source())); + return QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("ui", m_categories.at(index.row())->source())); } else { return m_categories.at(index.row())->source(); } @@ -260,9 +260,7 @@ void ConfigModel::categories_clear(QQmlListProperty *prop) //////////////////////////////ConfigView ConfigView::ConfigView(AppletInterface *interface, QWindow *parent) : QQuickView(parent), - m_appletInterface(interface), - m_wallpaperConfigModel(0), - m_currentWallpaperConfig(0) + m_appletInterface(interface) { qmlRegisterType("org.kde.plasma.configuration", 0, 1, "ConfigModel"); qmlRegisterType("org.kde.plasma.configuration", 0, 1, "ConfigCategory"); @@ -292,102 +290,24 @@ ConfigView::ConfigView(AppletInterface *interface, QWindow *parent) ContainmentInterface *cont = qobject_cast(m_appletInterface); - if (cont) { - setCurrentWallpaper(cont->containment()->wallpaper()); - } - engine()->rootContext()->setContextProperty("plasmoid", interface); engine()->rootContext()->setContextProperty("configDialog", this); - setSource(QUrl::fromLocalFile(m_appletInterface->applet()->containment()->corona()->package().filePath("configurationui"))); } ConfigView::~ConfigView() { } +void ConfigView::init() +{ + setSource(QUrl::fromLocalFile(m_appletInterface->applet()->containment()->corona()->package().filePath("configurationui"))); +} ConfigModel *ConfigView::configModel() const { return m_configModel; } -ConfigModel *ConfigView::wallpaperConfigModel() -{ - if (!m_wallpaperConfigModel) { - m_wallpaperConfigModel = new ConfigModel(this); - QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory)); - Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); - foreach (const QString &dirPath, dirs) { - QDir dir(dirPath); - pkg.setDefaultPackageRoot(dirPath); - QStringList packages; - - foreach (const QString &sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) { - QString metadata = dirPath + '/' + sdir + "/metadata.desktop"; - if (QFile::exists(metadata)) { - packages << sdir; - } - } - - foreach (const QString &package, packages) { - pkg.setPath(package); - ConfigCategory *cat = new ConfigCategory(m_wallpaperConfigModel); - cat->setName(pkg.metadata().name()); - cat->setIcon(pkg.metadata().icon()); - cat->setSource(pkg.filePath("ui", "config.qml")); - cat->setPluginName(package); - m_wallpaperConfigModel->appendCategory(cat); - } - } - } - return m_wallpaperConfigModel; -} - -ConfigPropertyMap *ConfigView::wallpaperConfiguration() const -{ - return m_currentWallpaperConfig; -} - -QString ConfigView::currentWallpaper() const -{ - return m_currentWallpaper; -} - -void ConfigView::setCurrentWallpaper(const QString &wallpaper) -{ - if (m_currentWallpaper == wallpaper) { - return; - } - - ContainmentInterface *cont = qobject_cast(m_appletInterface); - - if (!cont) { - return; - } - - - - if (cont->containment()->wallpaper() == wallpaper) { - delete m_currentWallpaperConfig; - m_currentWallpaperConfig = cont->wallpaperInterface()->configuration(); - } else { - if (cont->containment()->wallpaper() != m_currentWallpaper) { - delete m_currentWallpaperConfig; - } - - //we have to construct an independent ConfigPropertyMap when we want to configure wallpapers that are not the current one - Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); - pkg.setDefaultPackageRoot("plasma/wallpapers"); - pkg.setPath(wallpaper); - QFile file(pkg.filePath("config", "main.xml")); - KConfigGroup cfg = cont->containment()->config(); - cfg = KConfigGroup(&cfg, "Wallpaper"); - m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); - } - - m_currentWallpaper = wallpaper; - emit currentWallpaperChanged(); -} //To emulate Qt::WA_DeleteOnClose that QWindow doesn't have void ConfigView::hideEvent(QHideEvent *ev) diff --git a/src/scriptengines/qml/plasmoid/configview.h b/src/scriptengines/qml/plasmoid/configview.h index 975abd913..436763a80 100644 --- a/src/scriptengines/qml/plasmoid/configview.h +++ b/src/scriptengines/qml/plasmoid/configview.h @@ -117,24 +117,15 @@ class ConfigView : public QQuickView { Q_OBJECT Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT) - Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT) - Q_PROPERTY(ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration CONSTANT) - Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) public: ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0); virtual ~ConfigView(); + void init(); + ConfigModel *configModel() const; - ConfigModel *wallpaperConfigModel(); - QString currentWallpaper() const; - void setCurrentWallpaper(const QString &wallpaper); - ConfigPropertyMap *wallpaperConfiguration() const; - -Q_SIGNALS: - void currentWallpaperChanged(); - protected: void hideEvent(QHideEvent *ev); void resizeEvent(QResizeEvent *re); @@ -142,9 +133,6 @@ protected: private: AppletInterface *m_appletInterface; ConfigModel *m_configModel; - ConfigModel *m_wallpaperConfigModel; - QString m_currentWallpaper; - ConfigPropertyMap *m_currentWallpaperConfig; }; #endif // multiple inclusion guard diff --git a/src/scriptengines/qml/plasmoid/containmentconfigview.cpp b/src/scriptengines/qml/plasmoid/containmentconfigview.cpp new file mode 100644 index 000000000..1bd057e12 --- /dev/null +++ b/src/scriptengines/qml/plasmoid/containmentconfigview.cpp @@ -0,0 +1,120 @@ +/* + * 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 "containmentconfigview.h" +#include "plasmoid/containmentinterface.h" +#include "plasmoid/wallpaperinterface.h" +#include "declarative/configpropertymap.h" + +#include +#include +#include + + +#include + +#include + + +//////////////////////////////ContainmentConfigView +ContainmentConfigView::ContainmentConfigView(ContainmentInterface *interface, QWindow *parent) + : ConfigView(interface, parent), + m_contianmentInterface(interface), + m_wallpaperConfigModel(0), + m_currentWallpaperConfig(0) +{ + engine()->rootContext()->setContextProperty("configDialog", this); + setCurrentWallpaper(interface->containment()->wallpaper()); +} + +ContainmentConfigView::~ContainmentConfigView() +{ +} + +ConfigModel *ContainmentConfigView::wallpaperConfigModel() +{ + if (!m_wallpaperConfigModel) { + m_wallpaperConfigModel = new ConfigModel(this); + QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory)); + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); + foreach (const QString &dirPath, dirs) { + QDir dir(dirPath); + pkg.setDefaultPackageRoot(dirPath); + QStringList packages; + + foreach (const QString &sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) { + QString metadata = dirPath + '/' + sdir + "/metadata.desktop"; + if (QFile::exists(metadata)) { + packages << sdir; + } + } + + foreach (const QString &package, packages) { + pkg.setPath(package); + ConfigCategory *cat = new ConfigCategory(m_wallpaperConfigModel); + cat->setName(pkg.metadata().name()); + cat->setIcon(pkg.metadata().icon()); + cat->setSource(pkg.filePath("ui", "config.qml")); + cat->setPluginName(package); + m_wallpaperConfigModel->appendCategory(cat); + } + } + } + return m_wallpaperConfigModel; +} + +ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const +{ + return m_currentWallpaperConfig; +} + +QString ContainmentConfigView::currentWallpaper() const +{ + return m_currentWallpaper; +} + +void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) +{ + if (m_currentWallpaper == wallpaper) { + return; + } + + if (m_contianmentInterface->containment()->wallpaper() == wallpaper) { + delete m_currentWallpaperConfig; + m_currentWallpaperConfig = m_contianmentInterface->wallpaperInterface()->configuration(); + } else { + if (m_contianmentInterface->containment()->wallpaper() != m_currentWallpaper) { + delete m_currentWallpaperConfig; + } + + //we have to construct an independent ConfigPropertyMap when we want to configure wallpapers that are not the current one + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); + pkg.setDefaultPackageRoot("plasma/wallpapers"); + pkg.setPath(wallpaper); + QFile file(pkg.filePath("config", "main.xml")); + KConfigGroup cfg = m_contianmentInterface->containment()->config(); + cfg = KConfigGroup(&cfg, "Wallpaper"); + m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); + } + + m_currentWallpaper = wallpaper; + emit currentWallpaperChanged(); +} + +#include "moc_containmentconfigview.cpp" diff --git a/src/scriptengines/qml/plasmoid/containmentconfigview.h b/src/scriptengines/qml/plasmoid/containmentconfigview.h new file mode 100644 index 000000000..6cebaa23e --- /dev/null +++ b/src/scriptengines/qml/plasmoid/containmentconfigview.h @@ -0,0 +1,57 @@ +/* + * 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 CONTAINMENTCONFIGVIEW_H +#define CONTAINMENTCONFIGVIEW_H + + +#include "configview.h" + +class ContainmentInterface; +class ConfigPropertyMap; + + +//TODO: is it possible to move this in the shell? +class ContainmentConfigView : public ConfigView +{ + Q_OBJECT + Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT) + Q_PROPERTY(ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration CONSTANT) + Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) + +public: + ContainmentConfigView(ContainmentInterface *interface, QWindow *parent = 0); + virtual ~ContainmentConfigView(); + + ConfigModel *wallpaperConfigModel(); + QString currentWallpaper() const; + void setCurrentWallpaper(const QString &wallpaper); + ConfigPropertyMap *wallpaperConfiguration() const; + +Q_SIGNALS: + void currentWallpaperChanged(); + +private: + ContainmentInterface *m_contianmentInterface; + ConfigModel *m_wallpaperConfigModel; + QString m_currentWallpaper; + ConfigPropertyMap *m_currentWallpaperConfig; +}; + +#endif // multiple inclusion guard