From 0034c7da79a50186a58620b059fa3944b819d49f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 24 Apr 2013 22:54:46 +0200 Subject: [PATCH 1/7] move the config dialog in the shell it still doesn't successfully load --- CMakeLists.txt | 2 + configview.cpp | 332 ++++++++++++++++++++++++++++++++++++++ configview.h | 141 ++++++++++++++++ containmentconfigview.cpp | 138 ++++++++++++++++ containmentconfigview.h | 62 +++++++ desktopcorona.cpp | 31 +++- desktopcorona.h | 5 + 7 files changed, 710 insertions(+), 1 deletion(-) create mode 100644 configview.cpp create mode 100644 configview.h create mode 100644 containmentconfigview.cpp create mode 100644 containmentconfigview.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ff12f232..009ff5a4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,8 @@ set(widgetexplorer_SRC add_executable(plasma-shell main.cpp + configview.cpp + containmentconfigview.cpp desktopcorona.cpp panelview.cpp shellpluginloader.cpp diff --git a/configview.cpp b/configview.cpp new file mode 100644 index 000000000..00646c0c2 --- /dev/null +++ b/configview.cpp @@ -0,0 +1,332 @@ +/* + * 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 "configview.h" +#include "Plasma/Applet" +#include "Plasma/Containment" +//#include "plasmoid/wallpaperinterface.h" +#include "kdeclarative/configpropertymap.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +///////////////////////ConfigCategory + +ConfigCategory::ConfigCategory(QObject *parent) + : QObject(parent) +{ +} + +ConfigCategory::~ConfigCategory() +{} + +QString ConfigCategory::name() const +{ + return m_name; +} + +void ConfigCategory::setName(const QString &name) +{ + if (m_name == name) { + return; + } + + m_name = name; + emit nameChanged(); +} + + +QString ConfigCategory::icon() const +{ + return m_icon; +} + +void ConfigCategory::setIcon(const QString &icon) +{ + if (m_icon == icon) { + return; + } + + m_icon = icon; + emit iconChanged(); +} + + +QString ConfigCategory::source() const +{ + return m_source; +} + +void ConfigCategory::setSource(const QString &source) +{ + if (m_source == source) { + return; + } + + m_source = source; + emit sourceChanged(); +} + +QString ConfigCategory::pluginName() const +{ + return m_pluginName; +} + +void ConfigCategory::setPluginName(const QString &name) +{ + if (m_pluginName == name) { + return; + } + + m_pluginName = name; + emit pluginNameChanged(); +} + + + +//////////////////////////////ConfigModel +ConfigModel::ConfigModel(QObject *parent) + : QAbstractListModel(parent) +{ + QHash roleNames; + roleNames[NameRole] = "name"; + roleNames[IconRole] = "icon"; + roleNames[SourceRole] = "source"; + roleNames[PluginNameRole] = "pluginName"; + + setRoleNames(roleNames); + qDebug() << " XXX loaded QALM"; +} + +ConfigModel::~ConfigModel() +{} + +int ConfigModel::rowCount(const QModelIndex &index) const +{ + if (index.column() > 0) { + return 0; + } + return m_categories.count(); +} + +QVariant ConfigModel::data(const QModelIndex& index, int role) const +{ + if (index.row() < 0 || index.row() >= m_categories.count()) { + return QVariant(); + } + switch (role) { + case NameRole: + return m_categories.at(index.row())->name(); + case IconRole: + return m_categories.at(index.row())->icon(); + case SourceRole: + if (m_appletInterface) { + return QUrl::fromLocalFile(m_appletInterface.data()->package().filePath("ui", m_categories.at(index.row())->source())); + } else { + return m_categories.at(index.row())->source(); + } + case PluginNameRole: + return m_categories.at(index.row())->pluginName(); + default: + return QVariant(); + } +} + +QVariant ConfigModel::get(int row) const +{ + QVariantMap value; + if (row < 0 || row >= m_categories.count()) { + return value; + } + + value["name"] = m_categories.at(row)->name(); + value["icon"] = m_categories.at(row)->icon(); + if (m_appletInterface) { + value["source"] = QUrl::fromLocalFile(m_appletInterface.data()->package().filePath("components", m_categories.at(row)->source())); + } else { + value["source"] = m_categories.at(row)->source(); + } + return value; +} + +void ConfigModel::appendCategory(ConfigCategory *c) +{ + beginInsertRows(QModelIndex(), m_categories.size(), m_categories.size()); + m_categories.append(c); + endInsertRows(); + emit countChanged(); +} + +void ConfigModel::clear() +{ + beginResetModel(); + while (!m_categories.isEmpty()) { + m_categories.first()->setParent(0); + m_categories.pop_front(); + } + endResetModel(); + emit countChanged(); +} + +void ConfigModel::setApplet(Plasma::Applet *interface) +{ + m_appletInterface = interface; +} + +Plasma::Applet *ConfigModel::applet() const +{ + return m_appletInterface.data(); +} + +QQmlListProperty ConfigModel::categories() +{ + return QQmlListProperty(this, 0, ConfigModel::categories_append, + ConfigModel::categories_count, + ConfigModel::categories_at, + ConfigModel::categories_clear); + +} + +ConfigCategory *ConfigModel::categories_at(QQmlListProperty *prop, int index) +{ + ConfigModel *model = qobject_cast(prop->object); + if (!model || index >= model->m_categories.count() || index < 0) + return 0; + else + return model->m_categories.at(index); +} + +void ConfigModel::categories_append(QQmlListProperty *prop, ConfigCategory *o) +{ + ConfigModel *model = qobject_cast(prop->object); + if (!o || !model) { + return; + } + + if (o->parent() == prop->object) { + o->setParent(0); + } + + o->setParent(prop->object); + model->appendCategory(o); +} + +int ConfigModel::categories_count(QQmlListProperty *prop) +{ + ConfigModel *model = qobject_cast(prop->object); + if (model) { + return model->m_categories.count(); + } else { + return 0; + } +} + +void ConfigModel::categories_clear(QQmlListProperty *prop) +{ + ConfigModel *model = qobject_cast(prop->object); + if (!model) { + return; + } + + model->clear(); +} + + + +//////////////////////////////ConfigView +ConfigView::ConfigView(Plasma::Applet *interface, QWindow *parent) + : QQuickView(parent), + m_applet(interface) +{ + qmlRegisterType("org.kde.plasma.configuration", 2, 0, "ConfigModel"); + qmlRegisterType("org.kde.plasma.configuration", 2, 0, "ConfigCategory"); + + //FIXME: problem on nvidia, all windows should be transparent or won't show + setColor(Qt::transparent); + setTitle(i18n("%1 Settings", m_applet->title())); + + + if (!m_applet->containment()->corona()->package().isValid()) { + qWarning() << "Invalid home screen package"; + } + + setResizeMode(QQuickView::SizeViewToRootObject); + + + //config model local of the applet + QQmlComponent *component = new QQmlComponent(engine(), QUrl::fromLocalFile(m_applet->package().filePath("configmodel")), this); + QObject *object = component->create(engine()->rootContext()); + m_configModel = qobject_cast(object); + if (m_configModel) { + m_configModel->setApplet(m_applet); + } else { + delete object; + } + delete component; + + Plasma::Containment *cont = qobject_cast(m_applet); + + engine()->rootContext()->setContextProperty("plasmoid", interface); + engine()->rootContext()->setContextProperty("configDialog", this); +} + +ConfigView::~ConfigView() +{ +} + +void ConfigView::init() +{ + setSource(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("configurationui"))); +} + +ConfigModel *ConfigView::configModel() const +{ + return m_configModel; +} + + +//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have +void ConfigView::hideEvent(QHideEvent *ev) +{ + QQuickWindow::hideEvent(ev); + deleteLater(); +} + +void ConfigView::resizeEvent(QResizeEvent *re) +{ + if (!rootObject()) { + return; + } + rootObject()->setWidth(re->size().width()); + rootObject()->setHeight(re->size().height()); + QQuickWindow::resizeEvent(re); +} + + +#include "moc_configview.cpp" diff --git a/configview.h b/configview.h new file mode 100644 index 000000000..064e54a6e --- /dev/null +++ b/configview.h @@ -0,0 +1,141 @@ +/* + * 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 CONFIGUILOADER_H +#define CONFIGUILOADER_H + + +#include +#include +#include +#include + +namespace Plasma { + class Applet; +} + +class ConfigPropertyMap; + + +class ConfigCategory : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) + Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY pluginNameChanged) + +public: + ConfigCategory(QObject *parent = 0); + ~ConfigCategory(); + + QString name() const; + void setName(const QString &name); + + QString icon() const; + void setIcon(const QString &icon); + + QString source() const; + void setSource(const QString &source); + + QString pluginName() const; + void setPluginName(const QString &pluginName); + +Q_SIGNALS: + void nameChanged(); + void iconChanged(); + void sourceChanged(); + void pluginNameChanged(); + +private: + QString m_name; + QString m_icon; + QString m_source; + QString m_pluginName; +}; + +class ConfigModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty categories READ categories CONSTANT) + Q_CLASSINFO("DefaultProperty", "categories") + Q_PROPERTY(int count READ count NOTIFY countChanged) + +public: + enum Roles { + NameRole = Qt::UserRole+1, + IconRole, + SourceRole, + PluginNameRole + }; + ConfigModel(QObject *parent = 0); + ~ConfigModel(); + + void appendCategory(ConfigCategory *c); + void clear(); + + void setApplet(Plasma::Applet *interface); + Plasma::Applet *applet() const; + + int count() {return rowCount();} + virtual int rowCount(const QModelIndex &index = QModelIndex()) const; + virtual QVariant data(const QModelIndex&, int) const; + Q_INVOKABLE QVariant get(int row) const; + + QQmlListProperty categories(); + + static ConfigCategory *categories_at(QQmlListProperty *prop, int index); + static void categories_append(QQmlListProperty *prop, ConfigCategory *o); + static int categories_count(QQmlListProperty *prop); + static void categories_clear(QQmlListProperty *prop); + +Q_SIGNALS: + void countChanged(); + +private: + QListm_categories; + QWeakPointer m_appletInterface; +}; + + +//TODO: the config view for the containment should be a subclass +//TODO: is it possible to move this in the shell? +class ConfigView : public QQuickView +{ + Q_OBJECT + Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT) + +public: + ConfigView(Plasma::Applet *applet, QWindow *parent = 0); + virtual ~ConfigView(); + + void init(); + + ConfigModel *configModel() const; + +protected: + void hideEvent(QHideEvent *ev); + void resizeEvent(QResizeEvent *re); + +private: + Plasma::Applet *m_applet; + ConfigModel *m_configModel; +}; + +#endif // multiple inclusion guard diff --git a/containmentconfigview.cpp b/containmentconfigview.cpp new file mode 100644 index 000000000..481255e74 --- /dev/null +++ b/containmentconfigview.cpp @@ -0,0 +1,138 @@ +/* + * 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 +//#include "plasmoid/wallpaperinterface.h" +#include + +#include +#include +#include +#include + + +#include + +#include + + +//////////////////////////////ContainmentConfigView +ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent) + : ConfigView(cont, parent), + m_containment(cont), + m_wallpaperConfigModel(0), + m_currentWallpaperConfig(0) +{ + engine()->rootContext()->setContextProperty("configDialog", this); + setCurrentWallpaper(cont->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); + if (!pkg.isValid()) { + continue; + } + 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_containment->containment()->wallpaper() == wallpaper) { + delete m_currentWallpaperConfig; + if (m_containment->wallpaperInterface()) { + m_currentWallpaperConfig = m_containment->wallpaperInterface()->configuration(); + } + } else { + if (m_containment->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_containment->containment()->config(); + cfg = KConfigGroup(&cfg, "Wallpaper"); + m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); + }*/ + + m_currentWallpaper = wallpaper; + emit currentWallpaperChanged(); + emit wallpaperConfigurationChanged(); +} + +void ContainmentConfigView::applyWallpaper() +{ + /*m_containment->containment()->setWallpaper(m_currentWallpaper); + + if (m_currentWallpaperConfig != m_containment->wallpaperInterface()->configuration()) { + delete m_currentWallpaperConfig; + m_currentWallpaperConfig = m_containment->wallpaperInterface()->configuration(); + emit wallpaperConfigurationChanged(); + }*/ +} + +#include "moc_containmentconfigview.cpp" diff --git a/containmentconfigview.h b/containmentconfigview.h new file mode 100644 index 000000000..1d2dfb16a --- /dev/null +++ b/containmentconfigview.h @@ -0,0 +1,62 @@ +/* + * 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" + +namespace Plasma { + class Containment; +} +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 NOTIFY wallpaperConfigurationChanged) + Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) + +public: + ContainmentConfigView(Plasma::Containment *interface, QWindow *parent = 0); + virtual ~ContainmentConfigView(); + + ConfigModel *wallpaperConfigModel(); + QString currentWallpaper() const; + void setCurrentWallpaper(const QString &wallpaper); + ConfigPropertyMap *wallpaperConfiguration() const; + + Q_INVOKABLE void applyWallpaper(); + +Q_SIGNALS: + void currentWallpaperChanged(); + void wallpaperConfigurationChanged(); + +private: + Plasma::Containment *m_containment; + ConfigModel *m_wallpaperConfigModel; + QString m_currentWallpaper; + ConfigPropertyMap *m_currentWallpaperConfig; +}; + +#endif // multiple inclusion guard diff --git a/desktopcorona.cpp b/desktopcorona.cpp index 0f33b368a..6265cd031 100644 --- a/desktopcorona.cpp +++ b/desktopcorona.cpp @@ -29,6 +29,7 @@ #include #include +#include "containmentconfigview.h" #include "panelview.h" #include "view.h" #include "scripting/desktopscriptengine.h" @@ -266,7 +267,10 @@ void DesktopCorona::updateScreenOwner(int wasScreen, int isScreen, Plasma::Conta void DesktopCorona::handleContainmentAdded(Plasma::Containment* c) { - connect(c, &Plasma::Containment::showAddWidgetsInterface, this, &DesktopCorona::showWidgetExplorer); + connect(c, &Plasma::Containment::showAddWidgetsInterface, + this, &DesktopCorona::showWidgetExplorer); + connect(c, &Plasma::Containment::configureRequested, + this, &DesktopCorona::showConfigurationInterface); } void DesktopCorona::showWidgetExplorer() @@ -300,5 +304,30 @@ void DesktopCorona::printScriptMessage(const QString &message) qDebug() << message; } +void DesktopCorona::showConfigurationInterface(Plasma::Applet *applet) +{ + if (m_configView) { + m_configView.data()->hide(); + m_configView.data()->deleteLater(); + } + + if (!applet || !applet->containment()) { + return; + } + + if (!m_configView) { + Plasma::Containment *cont = qobject_cast(applet); + + if (cont) { + m_configView = new ContainmentConfigView(cont); + } else { + m_configView = new ConfigView(applet); + } + m_configView.data()->init(); + } + + m_configView.data()->show(); +} + #include "desktopcorona.moc" diff --git a/desktopcorona.h b/desktopcorona.h index a0a8dcf08..ea110d483 100644 --- a/desktopcorona.h +++ b/desktopcorona.h @@ -23,6 +23,8 @@ class * Free Software Foundation, Inc., #include "plasma/corona.h" +#include "configview.h" + class QDesktopWidget; class QQuickView; class PanelView; @@ -83,6 +85,8 @@ protected Q_SLOTS: void printScriptError(const QString &error); void printScriptMessage(const QString &message); + void showConfigurationInterface(Plasma::Applet *applet); + private Q_SLOTS: void handleContainmentAdded(Plasma::Containment *c); void showWidgetExplorer(); @@ -93,6 +97,7 @@ private: WidgetExplorerView *m_widgetExplorerView; QHash m_panelViews; KConfigGroup m_desktopDefaultsConfig; + QWeakPointer m_configView; }; #endif From 421870aedf9e62ef2a474ab68e69ad02f86b3c75 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 25 Apr 2013 11:43:00 +0200 Subject: [PATCH 2/7] config ui of applets should work again --- containmentconfigview.cpp | 10 +++++----- desktopcorona.cpp | 14 ++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/containmentconfigview.cpp b/containmentconfigview.cpp index 481255e74..edbc8824f 100644 --- a/containmentconfigview.cpp +++ b/containmentconfigview.cpp @@ -99,13 +99,13 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) return; } - if (m_containment->containment()->wallpaper() == wallpaper) { + if (m_containment->wallpaper() == wallpaper) { delete m_currentWallpaperConfig; if (m_containment->wallpaperInterface()) { m_currentWallpaperConfig = m_containment->wallpaperInterface()->configuration(); } } else { - if (m_containment->containment()->wallpaper() != m_currentWallpaper) { + if (m_containment->wallpaper() != m_currentWallpaper) { delete m_currentWallpaperConfig; } @@ -114,7 +114,7 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) pkg.setDefaultPackageRoot("plasma/wallpapers"); pkg.setPath(wallpaper); QFile file(pkg.filePath("config", "main.xml")); - KConfigGroup cfg = m_containment->containment()->config(); + KConfigGroup cfg = m_containment->config(); cfg = KConfigGroup(&cfg, "Wallpaper"); m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); }*/ @@ -126,9 +126,9 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) void ContainmentConfigView::applyWallpaper() { - /*m_containment->containment()->setWallpaper(m_currentWallpaper); + m_containment->setWallpaper(m_currentWallpaper); - if (m_currentWallpaperConfig != m_containment->wallpaperInterface()->configuration()) { + /*if (m_currentWallpaperConfig != m_containment->wallpaperInterface()->configuration()) { delete m_currentWallpaperConfig; m_currentWallpaperConfig = m_containment->wallpaperInterface()->configuration(); emit wallpaperConfigurationChanged(); diff --git a/desktopcorona.cpp b/desktopcorona.cpp index 6265cd031..6fd727f5e 100644 --- a/desktopcorona.cpp +++ b/desktopcorona.cpp @@ -315,16 +315,14 @@ void DesktopCorona::showConfigurationInterface(Plasma::Applet *applet) return; } - if (!m_configView) { - Plasma::Containment *cont = qobject_cast(applet); + Plasma::Containment *cont = qobject_cast(applet); - if (cont) { - m_configView = new ContainmentConfigView(cont); - } else { - m_configView = new ConfigView(applet); - } - m_configView.data()->init(); + if (cont) { + m_configView = new ContainmentConfigView(cont); + } else { + m_configView = new ConfigView(applet); } + m_configView.data()->init(); m_configView.data()->show(); } From 7b6478fd0adb8598f671b07d77a088d91ad0fb03 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 25 Apr 2013 14:11:53 +0200 Subject: [PATCH 3/7] correctly build the wallpaper model --- CMakeLists.txt | 1 + containmentconfigview.cpp | 23 +++++++++++++++-------- containmentconfigview.h | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 009ff5a4e..c4529baac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,7 @@ target_link_libraries(plasma-shell ${KDE4_KDEUI_LIBS} KDE4__kde4support ${Solid_LIBRARIES} + kdeclarative ) message("+++ kde4support : ${kde4support_LIBRARY}") diff --git a/containmentconfigview.cpp b/containmentconfigview.cpp index edbc8824f..e73f561fa 100644 --- a/containmentconfigview.cpp +++ b/containmentconfigview.cpp @@ -42,6 +42,14 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow { engine()->rootContext()->setContextProperty("configDialog", this); setCurrentWallpaper(cont->containment()->wallpaper()); + + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); + pkg.setDefaultPackageRoot("plasma/wallpapers"); + pkg.setPath(m_containment->wallpaper()); + QFile file(pkg.filePath("config", "main.xml")); + KConfigGroup cfg = m_containment->config(); + cfg = KConfigGroup(&cfg, "Wallpaper"); + m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); } ContainmentConfigView::~ContainmentConfigView() @@ -95,15 +103,13 @@ QString ContainmentConfigView::currentWallpaper() const void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) { - /*if (m_currentWallpaper == wallpaper) { + if (m_currentWallpaper == wallpaper) { return; } if (m_containment->wallpaper() == wallpaper) { delete m_currentWallpaperConfig; - if (m_containment->wallpaperInterface()) { - m_currentWallpaperConfig = m_containment->wallpaperInterface()->configuration(); - } + m_currentWallpaperConfig = m_ownWallpaperConfig; } else { if (m_containment->wallpaper() != m_currentWallpaper) { delete m_currentWallpaperConfig; @@ -117,7 +123,7 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) KConfigGroup cfg = m_containment->config(); cfg = KConfigGroup(&cfg, "Wallpaper"); m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); - }*/ + } m_currentWallpaper = wallpaper; emit currentWallpaperChanged(); @@ -128,11 +134,12 @@ void ContainmentConfigView::applyWallpaper() { m_containment->setWallpaper(m_currentWallpaper); - /*if (m_currentWallpaperConfig != m_containment->wallpaperInterface()->configuration()) { + if (m_currentWallpaperConfig != m_ownWallpaperConfig) { delete m_currentWallpaperConfig; - m_currentWallpaperConfig = m_containment->wallpaperInterface()->configuration(); + m_currentWallpaperConfig = m_ownWallpaperConfig; emit wallpaperConfigurationChanged(); - }*/ + } } + #include "moc_containmentconfigview.cpp" diff --git a/containmentconfigview.h b/containmentconfigview.h index 1d2dfb16a..b1ee6b8ed 100644 --- a/containmentconfigview.h +++ b/containmentconfigview.h @@ -57,6 +57,7 @@ private: ConfigModel *m_wallpaperConfigModel; QString m_currentWallpaper; ConfigPropertyMap *m_currentWallpaperConfig; + ConfigPropertyMap *m_ownWallpaperConfig; }; #endif // multiple inclusion guard From f3c06cd48193f94e9fd13180f28ae93e9cc5ac50 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 25 Apr 2013 15:07:02 +0200 Subject: [PATCH 4/7] correctly load containment config ui --- configview.cpp | 2 +- configview.h | 2 +- containmentconfigview.cpp | 6 +++ containmentconfigview.h | 2 + ...figuration.qml => AppletConfiguration.qml} | 16 +------ .../components/ContainmentConfiguration.qml | 47 +++++++++++++++++++ shellpackage.cpp | 3 +- 7 files changed, 61 insertions(+), 17 deletions(-) rename qmlpackages/desktop/contents/components/{Configuration.qml => AppletConfiguration.qml} (94%) create mode 100644 qmlpackages/desktop/contents/components/ContainmentConfiguration.qml diff --git a/configview.cpp b/configview.cpp index 00646c0c2..50f9dbd61 100644 --- a/configview.cpp +++ b/configview.cpp @@ -302,7 +302,7 @@ ConfigView::~ConfigView() void ConfigView::init() { - setSource(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("configurationui"))); + setSource(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("appletconfigurationui"))); } ConfigModel *ConfigView::configModel() const diff --git a/configview.h b/configview.h index 064e54a6e..a4c7ffb3c 100644 --- a/configview.h +++ b/configview.h @@ -125,7 +125,7 @@ public: ConfigView(Plasma::Applet *applet, QWindow *parent = 0); virtual ~ConfigView(); - void init(); + virtual void init(); ConfigModel *configModel() const; diff --git a/containmentconfigview.cpp b/containmentconfigview.cpp index e73f561fa..b26a70bfa 100644 --- a/containmentconfigview.cpp +++ b/containmentconfigview.cpp @@ -30,6 +30,7 @@ #include +#include #include @@ -56,6 +57,11 @@ ContainmentConfigView::~ContainmentConfigView() { } +void ContainmentConfigView::init() +{ + setSource(QUrl::fromLocalFile(m_containment->containment()->corona()->package().filePath("containmentconfigurationui"))); +} + ConfigModel *ContainmentConfigView::wallpaperConfigModel() { if (!m_wallpaperConfigModel) { diff --git a/containmentconfigview.h b/containmentconfigview.h index b1ee6b8ed..19f719c4a 100644 --- a/containmentconfigview.h +++ b/containmentconfigview.h @@ -41,6 +41,8 @@ public: ContainmentConfigView(Plasma::Containment *interface, QWindow *parent = 0); virtual ~ContainmentConfigView(); + virtual void init(); + ConfigModel *wallpaperConfigModel(); QString currentWallpaper() const; void setCurrentWallpaper(const QString &wallpaper); diff --git a/qmlpackages/desktop/contents/components/Configuration.qml b/qmlpackages/desktop/contents/components/AppletConfiguration.qml similarity index 94% rename from qmlpackages/desktop/contents/components/Configuration.qml rename to qmlpackages/desktop/contents/components/AppletConfiguration.qml index bfd68f1a6..0bab3fa70 100644 --- a/qmlpackages/desktop/contents/components/Configuration.qml +++ b/qmlpackages/desktop/contents/components/AppletConfiguration.qml @@ -36,7 +36,8 @@ Rectangle { //END properties //BEGIN model - property ConfigModel globalConfigModel: plasmoid.containmentType !== undefined ? globalContainmentConfigModel : globalAppletConfigModel + property ConfigModel globalConfigModel: globalAppletConfigModel + ConfigModel { id: globalAppletConfigModel ConfigCategory { @@ -45,19 +46,6 @@ Rectangle { source: "ConfigurationShortcuts.qml" } } - ConfigModel { - id: globalContainmentConfigModel - ConfigCategory { - name: "Appearance" - icon: "preferences-desktop-wallpaper" - source: "ConfigurationContainmentAppearance.qml" - } - ConfigCategory { - name: "Mouse Actions" - icon: "preferences-desktop-mouse" - source: "ConfigurationContainmentActions.qml" - } - } //END model //BEGIN functions diff --git a/qmlpackages/desktop/contents/components/ContainmentConfiguration.qml b/qmlpackages/desktop/contents/components/ContainmentConfiguration.qml new file mode 100644 index 000000000..c500657b0 --- /dev/null +++ b/qmlpackages/desktop/contents/components/ContainmentConfiguration.qml @@ -0,0 +1,47 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. + */ + +import QtQuick 2.0 +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.configuration 2.0 + + +AppletConfiguration { + id: root + +//BEGIN model + globalConfigModel: globalContainmentConfigModel + + ConfigModel { + id: globalContainmentConfigModel + ConfigCategory { + name: "Appearance" + icon: "preferences-desktop-wallpaper" + source: "ConfigurationContainmentAppearance.qml" + } + ConfigCategory { + name: "Mouse Actions" + icon: "preferences-desktop-mouse" + source: "ConfigurationContainmentActions.qml" + } + } +//END model + +} diff --git a/shellpackage.cpp b/shellpackage.cpp index 3d9c6e5c7..623021649 100644 --- a/shellpackage.cpp +++ b/shellpackage.cpp @@ -45,7 +45,8 @@ void ShellPackageStructure::initPackage(Plasma::Package *package) package->addFileDefinition("appleterror", "components/AppletError.qml", i18n("Error message shown when an applet fails to load")); package->addFileDefinition("compactapplet", "components/CompactApplet.qml", i18n("QML component that shows an applet in a popup")); - package->addFileDefinition("configurationui", "components/Configuration.qml", i18n("QML component for the configuration dialog")); + package->addFileDefinition("appletconfigurationui", "components/AppletConfiguration.qml", i18n("QML component for the configuration dialog for applets")); + package->addFileDefinition("containmentconfigurationui", "components/ContainmentConfiguration.qml", i18n("QML component for the configuration dialog for containments")); package->addFileDefinition("defaultcompactrepresentation", "components/DefaultCompactRepresentation.qml", i18n("Compact representation of an applet when collapsed in a popup, for instance as an icon. applets can override this component.")); package->addFileDefinition("widgetexplorer", "explorer/WidgetExplorer.qml", i18n("Widgets explorer UI")); package->addFileDefinition("panelconfigurationui", "components/PanelConfiguration.qml", i18n("Panel configuration UI")); From 1c846350c526c0597bcb144edd2764b917fd663b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 25 Apr 2013 22:38:27 +0200 Subject: [PATCH 5/7] panelconfigview is a subclass of configview --- panelconfigview.cpp | 39 +++++++-------------------------------- panelconfigview.h | 9 ++++----- panelview.cpp | 1 + 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/panelconfigview.cpp b/panelconfigview.cpp index caf9c641c..bce420ac0 100644 --- a/panelconfigview.cpp +++ b/panelconfigview.cpp @@ -36,27 +36,13 @@ //////////////////////////////PanelConfigView PanelConfigView::PanelConfigView(Plasma::Containment *containment, PanelView *panelView, QWindow *parent) - : QQuickView(parent), + : ConfigView(containment, parent), m_containment(containment), m_panelView(panelView) { setFlags(Qt::FramelessWindowHint); - //FIXME: problem on nvidia, all windows should be transparent or won't show - setColor(Qt::transparent); - setTitle(i18n("%1 Settings", m_containment->title())); - - if (!m_containment->corona()->package().isValid()) { - qWarning() << "Invalid home screen package"; - } - - setResizeMode(QQuickView::SizeViewToRootObject); - - engine()->rootContext()->setContextProperty("panel", panelView); - engine()->rootContext()->setContextProperty("configDialog", this); - setSource(QUrl::fromLocalFile(panelView->corona()->package().filePath("panelconfigurationui"))); - syncGeometry(); connect(containment, &Plasma::Containment::formFactorChanged, this, &PanelConfigView::syncGeometry); } @@ -65,6 +51,12 @@ PanelConfigView::~PanelConfigView() { } +void PanelConfigView::init() +{ + setSource(QUrl::fromLocalFile(m_containment->corona()->package().filePath("panelconfigurationui"))); + syncGeometry(); +} + void PanelConfigView::syncGeometry() { if (!m_containment) { @@ -91,22 +83,5 @@ void PanelConfigView::syncGeometry() } } -//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have -void PanelConfigView::hideEvent(QHideEvent *ev) -{ - QQuickWindow::hideEvent(ev); - deleteLater(); -} - -void PanelConfigView::resizeEvent(QResizeEvent *re) -{ - if (!rootObject()) { - return; - } - rootObject()->setWidth(re->size().width()); - rootObject()->setHeight(re->size().height()); - QQuickWindow::resizeEvent(re); -} - #include "moc_panelconfigview.cpp" diff --git a/panelconfigview.h b/panelconfigview.h index b215f435f..dfd202977 100644 --- a/panelconfigview.h +++ b/panelconfigview.h @@ -20,6 +20,7 @@ #ifndef PANELCONFIGVIEW_H #define PANELCONFIGVIEW_H +#include "configview.h" #include #include #include @@ -36,7 +37,7 @@ namespace Plasma { //TODO: this should be a subclass of ConfigView currently in the scriptengine //TODO: that class should be moved here -class PanelConfigView : public QQuickView +class PanelConfigView : public ConfigView { Q_OBJECT @@ -44,13 +45,11 @@ public: PanelConfigView(Plasma::Containment *interface, PanelView *panelView, QWindow *parent = 0); virtual ~PanelConfigView(); + void init(); + protected Q_SLOTS: void syncGeometry(); -protected: - void hideEvent(QHideEvent *ev); - void resizeEvent(QResizeEvent *re); - private: Plasma::Containment *m_containment; PanelView *m_panelView; diff --git a/panelview.cpp b/panelview.cpp index c408b922f..c4e33da89 100644 --- a/panelview.cpp +++ b/panelview.cpp @@ -167,6 +167,7 @@ void PanelView::showPanelController() { if (!m_panelConfigView) { m_panelConfigView = new PanelConfigView(containment(), this); + m_panelConfigView->init(); } m_panelConfigView->show(); } From 7854da7476822a8af0f19edd2e6a9981b2f46277 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 26 Apr 2013 10:46:42 +0200 Subject: [PATCH 6/7] bind the panel again to the config dialog --- panelconfigview.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/panelconfigview.cpp b/panelconfigview.cpp index bce420ac0..eebd11c7d 100644 --- a/panelconfigview.cpp +++ b/panelconfigview.cpp @@ -43,6 +43,8 @@ PanelConfigView::PanelConfigView(Plasma::Containment *containment, PanelView *pa setFlags(Qt::FramelessWindowHint); + engine()->rootContext()->setContextProperty("panel", panelView); + engine()->rootContext()->setContextProperty("configDialog", this); connect(containment, &Plasma::Containment::formFactorChanged, this, &PanelConfigView::syncGeometry); } From cc66f6e6e1f1620336e78fa6480662386f78d29b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 26 Apr 2013 13:00:07 +0200 Subject: [PATCH 7/7] create config uis always from the same point --- desktopcorona.cpp | 25 ------------------------- desktopcorona.h | 3 --- panelconfigview.h | 1 + view.cpp | 32 ++++++++++++++++++++++++++++++++ view.h | 5 +++++ 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/desktopcorona.cpp b/desktopcorona.cpp index 6fd727f5e..fc04abd1d 100644 --- a/desktopcorona.cpp +++ b/desktopcorona.cpp @@ -269,8 +269,6 @@ void DesktopCorona::handleContainmentAdded(Plasma::Containment* c) { connect(c, &Plasma::Containment::showAddWidgetsInterface, this, &DesktopCorona::showWidgetExplorer); - connect(c, &Plasma::Containment::configureRequested, - this, &DesktopCorona::showConfigurationInterface); } void DesktopCorona::showWidgetExplorer() @@ -304,28 +302,5 @@ void DesktopCorona::printScriptMessage(const QString &message) qDebug() << message; } -void DesktopCorona::showConfigurationInterface(Plasma::Applet *applet) -{ - if (m_configView) { - m_configView.data()->hide(); - m_configView.data()->deleteLater(); - } - - if (!applet || !applet->containment()) { - return; - } - - Plasma::Containment *cont = qobject_cast(applet); - - if (cont) { - m_configView = new ContainmentConfigView(cont); - } else { - m_configView = new ConfigView(applet); - } - m_configView.data()->init(); - - m_configView.data()->show(); -} - #include "desktopcorona.moc" diff --git a/desktopcorona.h b/desktopcorona.h index ea110d483..cbdc1a6e8 100644 --- a/desktopcorona.h +++ b/desktopcorona.h @@ -85,8 +85,6 @@ protected Q_SLOTS: void printScriptError(const QString &error); void printScriptMessage(const QString &message); - void showConfigurationInterface(Plasma::Applet *applet); - private Q_SLOTS: void handleContainmentAdded(Plasma::Containment *c); void showWidgetExplorer(); @@ -97,7 +95,6 @@ private: WidgetExplorerView *m_widgetExplorerView; QHash m_panelViews; KConfigGroup m_desktopDefaultsConfig; - QWeakPointer m_configView; }; #endif diff --git a/panelconfigview.h b/panelconfigview.h index dfd202977..ce7b56948 100644 --- a/panelconfigview.h +++ b/panelconfigview.h @@ -21,6 +21,7 @@ #define PANELCONFIGVIEW_H #include "configview.h" + #include #include #include diff --git a/view.cpp b/view.cpp index 81e359d45..2e48be3ba 100644 --- a/view.cpp +++ b/view.cpp @@ -17,6 +17,10 @@ */ #include "view.h" +#include "containmentconfigview.h" +#include "panelconfigview.h" +#include "panelview.h" + #include #include @@ -99,6 +103,8 @@ void View::setContainment(Plasma::Containment *cont) this, &View::locationChanged); connect(cont, &Plasma::Containment::formFactorChanged, this, &View::formFactorChanged); + connect(cont, &Plasma::Containment::configureRequested, + this, &View::showConfigurationInterface); } else { return; } @@ -152,4 +158,30 @@ QRectF View::screenGeometry() return screen()->geometry(); } +void View::showConfigurationInterface(Plasma::Applet *applet) +{ + if (m_configView) { + m_configView.data()->hide(); + m_configView.data()->deleteLater(); + } + + if (!applet || !applet->containment()) { + return; + } + + Plasma::Containment *cont = qobject_cast(applet); + PanelView *pv = qobject_cast< PanelView* >(this); + + if (cont && pv) { + m_configView = new PanelConfigView(cont, pv); + } else if (cont) { + m_configView = new ContainmentConfigView(cont); + } else { + m_configView = new ConfigView(applet); + } + m_configView.data()->init(); + + m_configView.data()->show(); +} + #include "moc_view.cpp" diff --git a/view.h b/view.h index d01a889e7..ff859ee89 100644 --- a/view.h +++ b/view.h @@ -25,6 +25,7 @@ #include "plasma/corona.h" #include "plasma/containment.h" +#include "configview.h" class View : public QQuickView { @@ -54,6 +55,9 @@ public: QRectF screenGeometry(); +protected Q_SLOTS: + void showConfigurationInterface(Plasma::Applet *applet); + Q_SIGNALS: void locationChanged(Plasma::Location location); void formFactorChanged(Plasma::FormFactor formFactor); @@ -63,6 +67,7 @@ Q_SIGNALS: private: Plasma::Corona *m_corona; QWeakPointer m_containment; + QWeakPointer m_configView; }; #endif // VIEW_H