From cd4033508f8c34dbaf8a7774e5c787c9c3bbaaef Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 9 Apr 2014 15:34:27 +0200 Subject: [PATCH] ll logic for switching containment type --- shell/containmentconfigview.cpp | 36 +++++++++++++++++++++++++++++++++ shell/containmentconfigview.h | 7 +++++++ shell/shellcorona.cpp | 25 +++++++++++++++++------ shell/shellcorona.h | 2 +- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/shell/containmentconfigview.cpp b/shell/containmentconfigview.cpp index 041ff5490..7d22e1191 100644 --- a/shell/containmentconfigview.cpp +++ b/shell/containmentconfigview.cpp @@ -20,6 +20,7 @@ #include "currentcontainmentactionsmodel.h" #include "containmentconfigview.h" #include "configmodel.h" +#include "shellcorona.h" #include @@ -43,6 +44,7 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow m_wallpaperConfigModel(0), m_containmentActionConfigModel(0), m_currentContainmentActionsModel(0), + m_containmentPluginsConfigModel(0), m_currentWallpaperConfig(0), m_ownWallpaperConfig(0) { @@ -94,6 +96,21 @@ QAbstractItemModel *ContainmentConfigView::currentContainmentActionsModel() return m_currentContainmentActionsModel; } +QString ContainmentConfigView::containmentPlugin() const +{ + return m_containment->pluginInfo().pluginName(); +} + +void ContainmentConfigView::setContainmentPlugin(const QString &plugin) +{ + if (plugin.isEmpty() || containmentPlugin() == plugin) { + return; + } + + m_containment = static_cast(m_containment->corona())->setContainmentTypeForScreen(m_containment->screen(), plugin); + emit containmentPluginChanged(); +} + PlasmaQuick::ConfigModel *ContainmentConfigView::wallpaperConfigModel() { if (!m_wallpaperConfigModel) { @@ -124,6 +141,21 @@ PlasmaQuick::ConfigModel *ContainmentConfigView::wallpaperConfigModel() return m_wallpaperConfigModel; } +PlasmaQuick::ConfigModel *ContainmentConfigView::containmentPluginsConfigModel() +{ + if (!m_containmentPluginsConfigModel) { + m_containmentPluginsConfigModel = new PlasmaQuick::ConfigModel(this); + + KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainments(QString()); + + foreach (const KPluginInfo &info, actions) { + m_containmentPluginsConfigModel->appendCategory(info.icon(), info.name(), QString(), info.pluginName()); + } + + } + return m_containmentPluginsConfigModel; +} + KDeclarative::ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const { return m_currentWallpaperConfig; @@ -176,6 +208,10 @@ void ContainmentConfigView::applyWallpaper() void ContainmentConfigView::syncWallpaperObjects() { QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value(); + + if (!wallpaperGraphicsObject) { + return; + } engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject); //FIXME: why m_wallpaperGraphicsObject->property("configuration").value() doesn't work? diff --git a/shell/containmentconfigview.h b/shell/containmentconfigview.h index d4941763e..8c6c2a244 100644 --- a/shell/containmentconfigview.h +++ b/shell/containmentconfigview.h @@ -42,8 +42,10 @@ class ContainmentConfigView : public PlasmaQuick::ConfigView Q_PROPERTY(PlasmaQuick::ConfigModel *containmentActionConfigModel READ containmentActionConfigModel CONSTANT) Q_PROPERTY(QAbstractItemModel *currentContainmentActionsModel READ currentContainmentActionsModel CONSTANT) Q_PROPERTY(PlasmaQuick::ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT) + Q_PROPERTY(PlasmaQuick::ConfigModel *containmentPluginsConfigModel READ containmentPluginsConfigModel CONSTANT) Q_PROPERTY(KDeclarative::ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY wallpaperConfigurationChanged) Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) + Q_PROPERTY(QString containmentPlugin READ containmentPlugin WRITE setContainmentPlugin NOTIFY containmentPluginChanged) public: ContainmentConfigView(Plasma::Containment *interface, QWindow *parent = 0); @@ -54,15 +56,19 @@ public: PlasmaQuick::ConfigModel *containmentActionConfigModel(); QAbstractItemModel *currentContainmentActionsModel(); PlasmaQuick::ConfigModel *wallpaperConfigModel(); + PlasmaQuick::ConfigModel *containmentPluginsConfigModel(); QString currentWallpaper() const; void setCurrentWallpaper(const QString &wallpaper); KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const; + QString containmentPlugin() const; + void setContainmentPlugin(const QString &plugin); Q_INVOKABLE void applyWallpaper(); Q_SIGNALS: void currentWallpaperChanged(); void wallpaperConfigurationChanged(); + void containmentPluginChanged(); protected: void syncWallpaperObjects(); @@ -71,6 +77,7 @@ private: Plasma::Containment *m_containment; PlasmaQuick::ConfigModel *m_wallpaperConfigModel; PlasmaQuick::ConfigModel *m_containmentActionConfigModel; + PlasmaQuick::ConfigModel *m_containmentPluginsConfigModel; CurrentContainmentActionsModel *m_currentContainmentActionsModel; QString m_currentWallpaper; KDeclarative::ConfigPropertyMap *m_currentWallpaperConfig; diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index cadfa209e..64731e81f 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -706,13 +706,16 @@ void ShellCorona::insertActivity(const QString &id, Activity *activity) c->config().writeEntry("lastScreen", 0); } -void ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin) +Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin) { Plasma::Containment *oldContainment = containmentForScreen(screen); //no valid containment in given screen, giving up if (!oldContainment) { - return; + return 0; + } + if (plugin.isEmpty()) { + return oldContainment; } DesktopView *view = 0; @@ -722,9 +725,10 @@ void ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin) break; } } + //no view? give up if (!view) { - return; + return oldContainment; } //create a new containment @@ -732,20 +736,29 @@ void ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin) //if creation failed or invalid plugin, give up if (!newContainment) { - return; + return oldContainment; } else if (!newContainment->pluginInfo().isValid()) { newContainment->deleteLater(); - return; + return oldContainment; } //At this point we have a valid new containment from plugin and a view foreach (Plasma::Applet *applet, oldContainment->applets()) { newContainment->addApplet(applet); } + //TODO: copy all configuration groups + + //remove the "remove" action + QAction *removeAction = newContainment->actions()->action("remove"); + if (removeAction) { + removeAction->deleteLater(); + } view->setContainment(newContainment); newContainment->setActivity(oldContainment->activity()); insertContainment(oldContainment->activity(), screen, newContainment); - oldContainment->deleteLater(); + oldContainment->destroy(); + + return newContainment; } void ShellCorona::checkAddPanelAction(const QStringList &sycocaChanges) diff --git a/shell/shellcorona.h b/shell/shellcorona.h index 009e5236b..d71f64816 100644 --- a/shell/shellcorona.h +++ b/shell/shellcorona.h @@ -77,7 +77,7 @@ public: void insertActivity(const QString &id, Activity *activity); - void setContainmentTypeForScreen(int screen, const QString &plugin); + Plasma::Containment *setContainmentTypeForScreen(int screen, const QString &plugin); public Q_SLOTS: /**