containment actions config ui fully working

wilder-5.14
Marco Martin 13 years ago
parent fa866bd096
commit 3a7e7bb491
  1. 34
      currentcontainmentactionsmodel.cpp
  2. 3
      currentcontainmentactionsmodel.h
  3. 10
      qmlpackages/desktop/contents/configuration/AppletConfiguration.qml
  4. 4
      qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml

@ -21,6 +21,7 @@
#include <QMouseEvent>
#include <QDebug>
#include <QDialog>
#include <QVBoxLayout>
#include <QDialogButtonBox>
@ -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<int, QByteArray> 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<QString, Plasma::ContainmentActions*> actions = cotainment->containmentActions();
QHashIterator<QString, Plasma::ContainmentActions*> 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<QString, Plasma::ContainmentActions*> 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());
}
}

@ -22,6 +22,7 @@
#include <QStandardItemModel>
#include <KConfig>
#include <KConfigGroup>
namespace Plasma {
@ -55,6 +56,8 @@ private:
Plasma::Containment *m_containment;
QHash<QString, Plasma::ContainmentActions *> m_plugins;
KConfigGroup m_baseCfg;
KConfigGroup m_tempConfig;
KConfig m_tempConfigParent;
};
#endif

@ -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]
}
}
}
}

@ -28,6 +28,10 @@ Item {
implicitWidth: childrenRect.width
implicitHeight: childrenRect.height
function saveConfig() {
configDialog.currentContainmentActionsModel.save();
}
Column {
anchors {
top: parent.top

Loading…
Cancel
Save