containment actions config ui fully working
This commit is contained in:
parent
f2f2a2b7c5
commit
9a9ac9f9e5
@ -45,7 +45,8 @@ configure_file(${CMAKE_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_BINARY_DIR}/CTestCu
|
|||||||
################# Enable C++11 features for clang and gcc #################
|
################# Enable C++11 features for clang and gcc #################
|
||||||
|
|
||||||
if(UNIX)
|
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()
|
endif()
|
||||||
|
|
||||||
################# now find all used packages #################
|
################# now find all used packages #################
|
||||||
|
@ -495,8 +495,12 @@ void Containment::setContainmentActions(const QString &trigger, const QString &p
|
|||||||
if (pluginName.isEmpty()) {
|
if (pluginName.isEmpty()) {
|
||||||
cfg.deleteEntry(trigger);
|
cfg.deleteEntry(trigger);
|
||||||
} else if (plugin) {
|
} else if (plugin) {
|
||||||
// it already existed, reset the containment so it wil reload config on next show
|
//it already existed, just reload config
|
||||||
plugin->setContainment(0);
|
plugin->setContainment(this); //to be safe
|
||||||
|
//FIXME make a truly unique config group
|
||||||
|
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
|
||||||
|
plugin->restore(pluginConfig);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
plugin = PluginLoader::self()->loadContainmentActions(this, pluginName);
|
plugin = PluginLoader::self()->loadContainmentActions(this, pluginName);
|
||||||
|
|
||||||
@ -504,6 +508,8 @@ void Containment::setContainmentActions(const QString &trigger, const QString &p
|
|||||||
cfg.writeEntry(trigger, pluginName);
|
cfg.writeEntry(trigger, pluginName);
|
||||||
containmentActions().insert(trigger, plugin);
|
containmentActions().insert(trigger, plugin);
|
||||||
plugin->setContainment(this);
|
plugin->setContainment(this);
|
||||||
|
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
|
||||||
|
plugin->restore(pluginConfig);
|
||||||
} else {
|
} else {
|
||||||
//bad plugin... gets removed. is this a feature or a bug?
|
//bad plugin... gets removed. is this a feature or a bug?
|
||||||
cfg.deleteEntry(trigger);
|
cfg.deleteEntry(trigger);
|
||||||
|
@ -104,6 +104,11 @@ QWidget *ContainmentActions::createConfigurationInterface(QWidget *parent)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContainmentActions::configurationAccepted()
|
||||||
|
{
|
||||||
|
//do nothing by default
|
||||||
|
}
|
||||||
|
|
||||||
void ContainmentActions::performNextAction()
|
void ContainmentActions::performNextAction()
|
||||||
{
|
{
|
||||||
//do nothing by default, implement in subclasses
|
//do nothing by default, implement in subclasses
|
||||||
@ -169,7 +174,6 @@ QString ContainmentActions::eventToString(QEvent *event)
|
|||||||
void ContainmentActions::setContainment(Containment *newContainment)
|
void ContainmentActions::setContainment(Containment *newContainment)
|
||||||
{
|
{
|
||||||
d->containment = newContainment;
|
d->containment = newContainment;
|
||||||
restore(config());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
@ -95,6 +95,11 @@ class PLASMA_EXPORT ContainmentActions : public QObject
|
|||||||
*/
|
*/
|
||||||
virtual QWidget *createConfigurationInterface(QWidget *parent);
|
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
|
* 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
|
* can be used to scroll through a list of items this plugin manages such as
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
@ -37,7 +38,8 @@
|
|||||||
|
|
||||||
CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent)
|
CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent)
|
||||||
: QStandardItemModel(parent),
|
: QStandardItemModel(parent),
|
||||||
m_containment(cotainment)
|
m_containment(cotainment),
|
||||||
|
m_tempConfigParent(QString(), KConfig::SimpleConfig)
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roleNames;
|
QHash<int, QByteArray> roleNames;
|
||||||
roleNames[ActionRole] = "action";
|
roleNames[ActionRole] = "action";
|
||||||
@ -46,9 +48,11 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme
|
|||||||
setRoleNames(roleNames);
|
setRoleNames(roleNames);
|
||||||
|
|
||||||
m_baseCfg = KConfigGroup(m_containment->corona()->config(), "ActionPlugins");
|
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();
|
QHash<QString, Plasma::ContainmentActions*> actions = cotainment->containmentActions();
|
||||||
|
|
||||||
|
|
||||||
QHashIterator<QString, Plasma::ContainmentActions*> i(actions);
|
QHashIterator<QString, Plasma::ContainmentActions*> i(actions);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
@ -101,9 +105,10 @@ bool CurrentContainmentActionsModel::append(const QString &action, const QString
|
|||||||
item->setData(plugin, PluginRole);
|
item->setData(plugin, PluginRole);
|
||||||
appendRow(item);
|
appendRow(item);
|
||||||
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
||||||
KConfigGroup cfg(&m_baseCfg, action);
|
|
||||||
m_plugins[action]->setContainment(m_containment);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +125,10 @@ void CurrentContainmentActionsModel::update(int row, const QString &action, cons
|
|||||||
if (m_plugins.contains(action) && oldPlugin != plugin) {
|
if (m_plugins.contains(action) && oldPlugin != plugin) {
|
||||||
delete m_plugins[action];
|
delete m_plugins[action];
|
||||||
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
|
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->setLayout(lay);
|
||||||
configDlg->setWindowModality(Qt::WindowModal);
|
configDlg->setWindowModality(Qt::WindowModal);
|
||||||
|
|
||||||
|
Plasma::ContainmentActions *pluginInstance = m_plugins[action];
|
||||||
//put the config in the dialog
|
//put the config in the dialog
|
||||||
QWidget *w = m_plugins[action]->createConfigurationInterface(configDlg);
|
QWidget *w = pluginInstance->createConfigurationInterface(configDlg);
|
||||||
QString title;
|
QString title;
|
||||||
if (w) {
|
if (w) {
|
||||||
lay->addWidget(w);
|
lay->addWidget(w);
|
||||||
@ -163,8 +173,16 @@ void CurrentContainmentActionsModel::showConfiguration(int row)
|
|||||||
Qt::Horizontal, configDlg);
|
Qt::Horizontal, configDlg);
|
||||||
lay->addWidget(buttons);
|
lay->addWidget(buttons);
|
||||||
|
|
||||||
connect(buttons, SIGNAL(accepted()), this, SLOT(acceptConfig()));
|
QObject::connect(buttons, &QDialogButtonBox::accepted,
|
||||||
connect(buttons, SIGNAL(rejected()), this, SLOT(rejectConfig()));
|
[configDlg, pluginInstance] () {
|
||||||
|
pluginInstance->configurationAccepted();
|
||||||
|
configDlg->deleteLater();
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(buttons, &QDialogButtonBox::rejected,
|
||||||
|
[configDlg] () {
|
||||||
|
configDlg->deleteLater();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
configDlg->show();
|
configDlg->show();
|
||||||
@ -211,10 +229,12 @@ void CurrentContainmentActionsModel::save()
|
|||||||
|
|
||||||
QHashIterator<QString, Plasma::ContainmentActions*> i(m_plugins);
|
QHashIterator<QString, Plasma::ContainmentActions*> i(m_plugins);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
m_containment->setContainmentActions(i.key(), i.value()->pluginInfo().pluginName());
|
|
||||||
i.next();
|
i.next();
|
||||||
|
|
||||||
KConfigGroup cfg(&m_baseCfg, i.key());
|
KConfigGroup cfg(&m_baseCfg, i.key());
|
||||||
i.value()->save(cfg);
|
i.value()->save(cfg);
|
||||||
|
|
||||||
|
m_containment->setContainmentActions(i.key(), i.value()->pluginInfo().pluginName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
|
#include <KConfig>
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
@ -55,6 +56,8 @@ private:
|
|||||||
Plasma::Containment *m_containment;
|
Plasma::Containment *m_containment;
|
||||||
QHash<QString, Plasma::ContainmentActions *> m_plugins;
|
QHash<QString, Plasma::ContainmentActions *> m_plugins;
|
||||||
KConfigGroup m_baseCfg;
|
KConfigGroup m_baseCfg;
|
||||||
|
KConfigGroup m_tempConfig;
|
||||||
|
KConfig m_tempConfigParent;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,9 +49,13 @@ Rectangle {
|
|||||||
|
|
||||||
//BEGIN functions
|
//BEGIN functions
|
||||||
function saveConfig() {
|
function saveConfig() {
|
||||||
for (var key in plasmoid.configuration) {
|
if (main.currentItem.saveConfig) {
|
||||||
if (main.currentItem["cfg_"+key] !== undefined) {
|
main.currentItem.saveConfig()
|
||||||
plasmoid.configuration[key] = main.currentItem["cfg_"+key]
|
} 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
|
implicitWidth: childrenRect.width
|
||||||
implicitHeight: childrenRect.height
|
implicitHeight: childrenRect.height
|
||||||
|
|
||||||
|
function saveConfig() {
|
||||||
|
configDialog.currentContainmentActionsModel.save();
|
||||||
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
|
Loading…
x
Reference in New Issue
Block a user