ll logic for switching containment type

wilder-5.14
Marco Martin 12 years ago
parent e9ac540825
commit cd4033508f
  1. 36
      shell/containmentconfigview.cpp
  2. 7
      shell/containmentconfigview.h
  3. 25
      shell/shellcorona.cpp
  4. 2
      shell/shellcorona.h

@ -20,6 +20,7 @@
#include "currentcontainmentactionsmodel.h" #include "currentcontainmentactionsmodel.h"
#include "containmentconfigview.h" #include "containmentconfigview.h"
#include "configmodel.h" #include "configmodel.h"
#include "shellcorona.h"
#include <kdeclarative/configpropertymap.h> #include <kdeclarative/configpropertymap.h>
@ -43,6 +44,7 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow
m_wallpaperConfigModel(0), m_wallpaperConfigModel(0),
m_containmentActionConfigModel(0), m_containmentActionConfigModel(0),
m_currentContainmentActionsModel(0), m_currentContainmentActionsModel(0),
m_containmentPluginsConfigModel(0),
m_currentWallpaperConfig(0), m_currentWallpaperConfig(0),
m_ownWallpaperConfig(0) m_ownWallpaperConfig(0)
{ {
@ -94,6 +96,21 @@ QAbstractItemModel *ContainmentConfigView::currentContainmentActionsModel()
return m_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<ShellCorona *>(m_containment->corona())->setContainmentTypeForScreen(m_containment->screen(), plugin);
emit containmentPluginChanged();
}
PlasmaQuick::ConfigModel *ContainmentConfigView::wallpaperConfigModel() PlasmaQuick::ConfigModel *ContainmentConfigView::wallpaperConfigModel()
{ {
if (!m_wallpaperConfigModel) { if (!m_wallpaperConfigModel) {
@ -124,6 +141,21 @@ PlasmaQuick::ConfigModel *ContainmentConfigView::wallpaperConfigModel()
return m_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 KDeclarative::ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const
{ {
return m_currentWallpaperConfig; return m_currentWallpaperConfig;
@ -176,6 +208,10 @@ void ContainmentConfigView::applyWallpaper()
void ContainmentConfigView::syncWallpaperObjects() void ContainmentConfigView::syncWallpaperObjects()
{ {
QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value<QObject *>(); QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value<QObject *>();
if (!wallpaperGraphicsObject) {
return;
}
engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject); engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject);
//FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work? //FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work?

@ -42,8 +42,10 @@ class ContainmentConfigView : public PlasmaQuick::ConfigView
Q_PROPERTY(PlasmaQuick::ConfigModel *containmentActionConfigModel READ containmentActionConfigModel CONSTANT) Q_PROPERTY(PlasmaQuick::ConfigModel *containmentActionConfigModel READ containmentActionConfigModel CONSTANT)
Q_PROPERTY(QAbstractItemModel *currentContainmentActionsModel READ currentContainmentActionsModel CONSTANT) Q_PROPERTY(QAbstractItemModel *currentContainmentActionsModel READ currentContainmentActionsModel CONSTANT)
Q_PROPERTY(PlasmaQuick::ConfigModel *wallpaperConfigModel READ wallpaperConfigModel 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(KDeclarative::ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY wallpaperConfigurationChanged)
Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged)
Q_PROPERTY(QString containmentPlugin READ containmentPlugin WRITE setContainmentPlugin NOTIFY containmentPluginChanged)
public: public:
ContainmentConfigView(Plasma::Containment *interface, QWindow *parent = 0); ContainmentConfigView(Plasma::Containment *interface, QWindow *parent = 0);
@ -54,15 +56,19 @@ public:
PlasmaQuick::ConfigModel *containmentActionConfigModel(); PlasmaQuick::ConfigModel *containmentActionConfigModel();
QAbstractItemModel *currentContainmentActionsModel(); QAbstractItemModel *currentContainmentActionsModel();
PlasmaQuick::ConfigModel *wallpaperConfigModel(); PlasmaQuick::ConfigModel *wallpaperConfigModel();
PlasmaQuick::ConfigModel *containmentPluginsConfigModel();
QString currentWallpaper() const; QString currentWallpaper() const;
void setCurrentWallpaper(const QString &wallpaper); void setCurrentWallpaper(const QString &wallpaper);
KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const; KDeclarative::ConfigPropertyMap *wallpaperConfiguration() const;
QString containmentPlugin() const;
void setContainmentPlugin(const QString &plugin);
Q_INVOKABLE void applyWallpaper(); Q_INVOKABLE void applyWallpaper();
Q_SIGNALS: Q_SIGNALS:
void currentWallpaperChanged(); void currentWallpaperChanged();
void wallpaperConfigurationChanged(); void wallpaperConfigurationChanged();
void containmentPluginChanged();
protected: protected:
void syncWallpaperObjects(); void syncWallpaperObjects();
@ -71,6 +77,7 @@ private:
Plasma::Containment *m_containment; Plasma::Containment *m_containment;
PlasmaQuick::ConfigModel *m_wallpaperConfigModel; PlasmaQuick::ConfigModel *m_wallpaperConfigModel;
PlasmaQuick::ConfigModel *m_containmentActionConfigModel; PlasmaQuick::ConfigModel *m_containmentActionConfigModel;
PlasmaQuick::ConfigModel *m_containmentPluginsConfigModel;
CurrentContainmentActionsModel *m_currentContainmentActionsModel; CurrentContainmentActionsModel *m_currentContainmentActionsModel;
QString m_currentWallpaper; QString m_currentWallpaper;
KDeclarative::ConfigPropertyMap *m_currentWallpaperConfig; KDeclarative::ConfigPropertyMap *m_currentWallpaperConfig;

@ -706,13 +706,16 @@ void ShellCorona::insertActivity(const QString &id, Activity *activity)
c->config().writeEntry("lastScreen", 0); 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); Plasma::Containment *oldContainment = containmentForScreen(screen);
//no valid containment in given screen, giving up //no valid containment in given screen, giving up
if (!oldContainment) { if (!oldContainment) {
return; return 0;
}
if (plugin.isEmpty()) {
return oldContainment;
} }
DesktopView *view = 0; DesktopView *view = 0;
@ -722,9 +725,10 @@ void ShellCorona::setContainmentTypeForScreen(int screen, const QString &plugin)
break; break;
} }
} }
//no view? give up //no view? give up
if (!view) { if (!view) {
return; return oldContainment;
} }
//create a new containment //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 creation failed or invalid plugin, give up
if (!newContainment) { if (!newContainment) {
return; return oldContainment;
} else if (!newContainment->pluginInfo().isValid()) { } else if (!newContainment->pluginInfo().isValid()) {
newContainment->deleteLater(); newContainment->deleteLater();
return; return oldContainment;
} }
//At this point we have a valid new containment from plugin and a view //At this point we have a valid new containment from plugin and a view
foreach (Plasma::Applet *applet, oldContainment->applets()) { foreach (Plasma::Applet *applet, oldContainment->applets()) {
newContainment->addApplet(applet); 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); view->setContainment(newContainment);
newContainment->setActivity(oldContainment->activity()); newContainment->setActivity(oldContainment->activity());
insertContainment(oldContainment->activity(), screen, newContainment); insertContainment(oldContainment->activity(), screen, newContainment);
oldContainment->deleteLater(); oldContainment->destroy();
return newContainment;
} }
void ShellCorona::checkAddPanelAction(const QStringList &sycocaChanges) void ShellCorona::checkAddPanelAction(const QStringList &sycocaChanges)

@ -77,7 +77,7 @@ public:
void insertActivity(const QString &id, Activity *activity); 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: public Q_SLOTS:
/** /**

Loading…
Cancel
Save