containment actions config ui fully working

This commit is contained in:
Marco Martin 2013-08-26 21:22:06 +02:00
parent f2f2a2b7c5
commit 9a9ac9f9e5
8 changed files with 61 additions and 14 deletions

View File

@ -45,7 +45,8 @@ configure_file(${CMAKE_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_BINARY_DIR}/CTestCu
################# Enable C++11 features for clang and gcc #################
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x")
add_definitions("-Wall -std=c++0x")
endif()
################# now find all used packages #################

View File

@ -495,8 +495,12 @@ void Containment::setContainmentActions(const QString &trigger, const QString &p
if (pluginName.isEmpty()) {
cfg.deleteEntry(trigger);
} else if (plugin) {
// it already existed, reset the containment so it wil reload config on next show
plugin->setContainment(0);
//it already existed, just reload config
plugin->setContainment(this); //to be safe
//FIXME make a truly unique config group
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
plugin->restore(pluginConfig);
} else {
plugin = PluginLoader::self()->loadContainmentActions(this, pluginName);
@ -504,6 +508,8 @@ void Containment::setContainmentActions(const QString &trigger, const QString &p
cfg.writeEntry(trigger, pluginName);
containmentActions().insert(trigger, plugin);
plugin->setContainment(this);
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
plugin->restore(pluginConfig);
} else {
//bad plugin... gets removed. is this a feature or a bug?
cfg.deleteEntry(trigger);

View File

@ -104,6 +104,11 @@ QWidget *ContainmentActions::createConfigurationInterface(QWidget *parent)
return 0;
}
void ContainmentActions::configurationAccepted()
{
//do nothing by default
}
void ContainmentActions::performNextAction()
{
//do nothing by default, implement in subclasses
@ -169,7 +174,6 @@ QString ContainmentActions::eventToString(QEvent *event)
void ContainmentActions::setContainment(Containment *newContainment)
{
d->containment = newContainment;
restore(config());
}
} // Plasma namespace

View File

@ -95,6 +95,11 @@ class PLASMA_EXPORT ContainmentActions : public QObject
*/
virtual QWidget *createConfigurationInterface(QWidget *parent);
/**
* This method is called when the user's configuration changes are accepted
*/
virtual void configurationAccepted();
/**
* Called when a "next" action is triggered (e.g. by mouse wheel scroll). This
* can be used to scroll through a list of items this plugin manages such as

View File

@ -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());
}
}

View File

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

View File

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

View File

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