From 3a7e7bb491d21ff2aac694ba0c47dc04394fdac1 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 26 Aug 2013 21:22:06 +0200 Subject: [PATCH] containment actions config ui fully working --- currentcontainmentactionsmodel.cpp | 34 +++++++++++++++---- currentcontainmentactionsmodel.h | 3 ++ .../configuration/AppletConfiguration.qml | 10 ++++-- .../ConfigurationContainmentActions.qml | 4 +++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/currentcontainmentactionsmodel.cpp b/currentcontainmentactionsmodel.cpp index 7df65bd10..09bbdd668 100644 --- a/currentcontainmentactionsmodel.cpp +++ b/currentcontainmentactionsmodel.cpp @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -37,7 +38,8 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent) : QStandardItemModel(parent), - m_containment(cotainment) + m_containment(cotainment), + m_tempConfigParent(QString(), KConfig::SimpleConfig) { QHash roleNames; roleNames[ActionRole] = "action"; @@ -46,9 +48,11 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme setRoleNames(roleNames); m_baseCfg = KConfigGroup(m_containment->corona()->config(), "ActionPlugins"); + m_baseCfg = KConfigGroup(&m_baseCfg, QString::number(m_containment->containmentType())); QHash actions = cotainment->containmentActions(); + QHashIterator i(actions); while (i.hasNext()) { i.next(); @@ -101,9 +105,10 @@ bool CurrentContainmentActionsModel::append(const QString &action, const QString item->setData(plugin, PluginRole); appendRow(item); m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin); - KConfigGroup cfg(&m_baseCfg, action); m_plugins[action]->setContainment(m_containment); - m_plugins[action]->restore(cfg); + //empty config: the new one will ne in default state + KConfigGroup tempConfig(&m_tempConfigParent, "test"); + m_plugins[action]->restore(tempConfig); return true; } @@ -120,6 +125,10 @@ void CurrentContainmentActionsModel::update(int row, const QString &action, cons if (m_plugins.contains(action) && oldPlugin != plugin) { delete m_plugins[action]; m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin); + m_plugins[action]->setContainment(m_containment); + //empty config: the new one will ne in default state + KConfigGroup tempConfig(&m_tempConfigParent, "test"); + m_plugins[action]->restore(tempConfig); } } } @@ -149,8 +158,9 @@ void CurrentContainmentActionsModel::showConfiguration(int row) configDlg->setLayout(lay); configDlg->setWindowModality(Qt::WindowModal); + Plasma::ContainmentActions *pluginInstance = m_plugins[action]; //put the config in the dialog - QWidget *w = m_plugins[action]->createConfigurationInterface(configDlg); + QWidget *w = pluginInstance->createConfigurationInterface(configDlg); QString title; if (w) { lay->addWidget(w); @@ -163,8 +173,16 @@ void CurrentContainmentActionsModel::showConfiguration(int row) Qt::Horizontal, configDlg); lay->addWidget(buttons); - connect(buttons, SIGNAL(accepted()), this, SLOT(acceptConfig())); - connect(buttons, SIGNAL(rejected()), this, SLOT(rejectConfig())); + QObject::connect(buttons, &QDialogButtonBox::accepted, + [configDlg, pluginInstance] () { + pluginInstance->configurationAccepted(); + configDlg->deleteLater(); + }); + + QObject::connect(buttons, &QDialogButtonBox::rejected, + [configDlg] () { + configDlg->deleteLater(); + }); configDlg->show(); @@ -211,10 +229,12 @@ void CurrentContainmentActionsModel::save() QHashIterator i(m_plugins); while (i.hasNext()) { - m_containment->setContainmentActions(i.key(), i.value()->pluginInfo().pluginName()); i.next(); + KConfigGroup cfg(&m_baseCfg, i.key()); i.value()->save(cfg); + + m_containment->setContainmentActions(i.key(), i.value()->pluginInfo().pluginName()); } } diff --git a/currentcontainmentactionsmodel.h b/currentcontainmentactionsmodel.h index d82872222..340ebbc3f 100644 --- a/currentcontainmentactionsmodel.h +++ b/currentcontainmentactionsmodel.h @@ -22,6 +22,7 @@ #include +#include #include namespace Plasma { @@ -55,6 +56,8 @@ private: Plasma::Containment *m_containment; QHash m_plugins; KConfigGroup m_baseCfg; + KConfigGroup m_tempConfig; + KConfig m_tempConfigParent; }; #endif diff --git a/qmlpackages/desktop/contents/configuration/AppletConfiguration.qml b/qmlpackages/desktop/contents/configuration/AppletConfiguration.qml index a758bfd33..e9e08f085 100644 --- a/qmlpackages/desktop/contents/configuration/AppletConfiguration.qml +++ b/qmlpackages/desktop/contents/configuration/AppletConfiguration.qml @@ -49,9 +49,13 @@ Rectangle { //BEGIN functions function saveConfig() { - for (var key in plasmoid.configuration) { - if (main.currentItem["cfg_"+key] !== undefined) { - plasmoid.configuration[key] = main.currentItem["cfg_"+key] + if (main.currentItem.saveConfig) { + main.currentItem.saveConfig() + } else { + for (var key in plasmoid.configuration) { + if (main.currentItem["cfg_"+key] !== undefined) { + plasmoid.configuration[key] = main.currentItem["cfg_"+key] + } } } } diff --git a/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml b/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml index d7e51e027..98e7d5fca 100644 --- a/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml +++ b/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml @@ -28,6 +28,10 @@ Item { implicitWidth: childrenRect.width implicitHeight: childrenRect.height + function saveConfig() { + configDialog.currentContainmentActionsModel.save(); + } + Column { anchors { top: parent.top