correctly save and restore containmentactions config

This commit is contained in:
Marco Martin 2013-08-27 15:23:19 +02:00
parent b44f9d17cb
commit 6617a26726
4 changed files with 91 additions and 13 deletions

View File

@ -98,6 +98,11 @@ QString CurrentContainmentActionsModel::wheelEventString(const QPointF &delta, i
return string;
}
bool CurrentContainmentActionsModel::isTriggerUsed(const QString &trigger)
{
return m_plugins.contains(trigger);
}
bool CurrentContainmentActionsModel::append(const QString &action, const QString &plugin)
{
if (m_plugins.contains(action)) {
@ -114,6 +119,7 @@ bool CurrentContainmentActionsModel::append(const QString &action, const QString
KConfigGroup tempConfig(&m_tempConfigParent, "test");
m_plugins[action]->restore(tempConfig);
item->setData(m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
m_removedTriggers.removeAll(action);
appendRow(item);
return true;
@ -134,6 +140,13 @@ void CurrentContainmentActionsModel::update(int row, const QString &action, cons
setData(idx, action, ActionRole);
setData(idx, plugin, PluginNameRole);
delete m_plugins[oldTrigger];
m_plugins.remove(oldTrigger);
if (oldPlugin != plugin) {
m_removedTriggers << oldTrigger;
}
if (!m_plugins.contains(action) || oldPlugin != plugin) {
delete m_plugins[action];
m_plugins[action] = Plasma::PluginLoader::self()->loadContainmentActions(m_containment, plugin);
@ -154,6 +167,7 @@ void CurrentContainmentActionsModel::remove(int row)
if (m_plugins.contains(action)) {
delete m_plugins[action];
m_plugins.remove(action);
m_removedTriggers << action;
}
}
@ -229,16 +243,10 @@ void CurrentContainmentActionsModel::showAbout(int row)
void CurrentContainmentActionsModel::save()
{
//TODO: this configuration save is still a stub, not completely "correct" yet
//clean old config, just i case
foreach (const QString &group, m_baseCfg.groupList()) {
KConfigGroup cfg = KConfigGroup(&m_baseCfg, group);
cfg.deleteGroup();
if (m_plugins.contains(group)) {
m_containment->setContainmentActions(group, QString());
}
foreach (const QString &removedTrigger, m_removedTriggers) {
m_containment->setContainmentActions(removedTrigger, QString());
}
m_removedTriggers.clear();
QHashIterator<QString, Plasma::ContainmentActions*> i(m_plugins);
while (i.hasNext()) {

View File

@ -44,6 +44,7 @@ public:
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);
~CurrentContainmentActionsModel();
Q_INVOKABLE bool isTriggerUsed(const QString &trigger);
Q_INVOKABLE QString mouseEventString(int mouseButtons, int modifiers);
Q_INVOKABLE QString wheelEventString(const QPointF &delta, int mouseButtons, int modifiers);
Q_INVOKABLE bool append(const QString &action, const QString &plugin);
@ -59,6 +60,7 @@ private:
KConfigGroup m_baseCfg;
KConfigGroup m_tempConfig;
KConfig m_tempConfigParent;
QStringList m_removedTriggers;
};
#endif

View File

@ -20,8 +20,6 @@ import QtQuick 2.0
import QtQuick.Controls 1.0 as QtControls
import QtQuick.Layouts 1.0
import org.kde.qtextracomponents 2.0
Item {
id: root
@ -43,8 +41,12 @@ Item {
model: configDialog.currentContainmentActionsModel
delegate: RowLayout {
width: root.width
QtControls.Button {
text: model.action
MouseEventInputButton {
defaultText: model.action
eventString: model.action
onEventStringChanged: {
configDialog.currentContainmentActionsModel.update(index, eventString, model.pluginName);
}
}
QtControls.ComboBox {
id: pluginsCombo

View File

@ -0,0 +1,66 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.0
import QtQuick.Controls 1.0 as QtControls
import QtQuick.Layouts 1.0
QtControls.Button {
id: mouseInputButton
property string defaultText: i18n("Add Action")
text: defaultText
checkable: true
property string eventString
onCheckedChanged: {
if (checked) {
text = i18n("Input Here");
mouseInputArea.enabled = true;
}
}
MouseArea {
id: mouseInputArea
anchors.fill: parent
acceptedButtons: Qt.AllButtons
enabled: false
onClicked: {
var newEventString = configDialog.currentContainmentActionsModel.mouseEventString(mouse.button, mouse.modifiers);
if (eventString === newEventString || !configDialog.currentContainmentActionsModel.isTriggerUsed(newEventString)) {
eventString = newEventString;
mouseInputButton.text = defaultText;
mouseInputButton.checked = false;
enabled = false;
}
}
onWheel: {
var newEventString = configDialog.currentContainmentActionsModel.wheelEventString(wheel.pixelDelta, wheel.buttons, wheel.modifiers);
if (eventString === newEventString || !configDialog.currentContainmentActionsModel.isTriggerUsed(newEventString)) {
eventString = newEventString;
mouseInputButton.text = defaultText;
mouseInputButton.checked = false;
enabled = false;
}
}
}
}