correctly save and restore containmentactions config
This commit is contained in:
parent
b44f9d17cb
commit
6617a26726
@ -98,6 +98,11 @@ QString CurrentContainmentActionsModel::wheelEventString(const QPointF &delta, i
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CurrentContainmentActionsModel::isTriggerUsed(const QString &trigger)
|
||||||
|
{
|
||||||
|
return m_plugins.contains(trigger);
|
||||||
|
}
|
||||||
|
|
||||||
bool CurrentContainmentActionsModel::append(const QString &action, const QString &plugin)
|
bool CurrentContainmentActionsModel::append(const QString &action, const QString &plugin)
|
||||||
{
|
{
|
||||||
if (m_plugins.contains(action)) {
|
if (m_plugins.contains(action)) {
|
||||||
@ -114,6 +119,7 @@ bool CurrentContainmentActionsModel::append(const QString &action, const QString
|
|||||||
KConfigGroup tempConfig(&m_tempConfigParent, "test");
|
KConfigGroup tempConfig(&m_tempConfigParent, "test");
|
||||||
m_plugins[action]->restore(tempConfig);
|
m_plugins[action]->restore(tempConfig);
|
||||||
item->setData(m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
|
item->setData(m_plugins[action]->pluginInfo().property("X-Plasma-HasConfigurationInterface").toBool(), HasConfigurationInterfaceRole);
|
||||||
|
m_removedTriggers.removeAll(action);
|
||||||
|
|
||||||
appendRow(item);
|
appendRow(item);
|
||||||
return true;
|
return true;
|
||||||
@ -134,6 +140,13 @@ void CurrentContainmentActionsModel::update(int row, const QString &action, cons
|
|||||||
setData(idx, action, ActionRole);
|
setData(idx, action, ActionRole);
|
||||||
setData(idx, plugin, PluginNameRole);
|
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) {
|
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);
|
||||||
@ -154,6 +167,7 @@ void CurrentContainmentActionsModel::remove(int row)
|
|||||||
if (m_plugins.contains(action)) {
|
if (m_plugins.contains(action)) {
|
||||||
delete m_plugins[action];
|
delete m_plugins[action];
|
||||||
m_plugins.remove(action);
|
m_plugins.remove(action);
|
||||||
|
m_removedTriggers << action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,16 +243,10 @@ void CurrentContainmentActionsModel::showAbout(int row)
|
|||||||
void CurrentContainmentActionsModel::save()
|
void CurrentContainmentActionsModel::save()
|
||||||
{
|
{
|
||||||
|
|
||||||
//TODO: this configuration save is still a stub, not completely "correct" yet
|
foreach (const QString &removedTrigger, m_removedTriggers) {
|
||||||
//clean old config, just i case
|
m_containment->setContainmentActions(removedTrigger, QString());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
m_removedTriggers.clear();
|
||||||
|
|
||||||
QHashIterator<QString, Plasma::ContainmentActions*> i(m_plugins);
|
QHashIterator<QString, Plasma::ContainmentActions*> i(m_plugins);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);
|
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);
|
||||||
~CurrentContainmentActionsModel();
|
~CurrentContainmentActionsModel();
|
||||||
|
|
||||||
|
Q_INVOKABLE bool isTriggerUsed(const QString &trigger);
|
||||||
Q_INVOKABLE QString mouseEventString(int mouseButtons, int modifiers);
|
Q_INVOKABLE QString mouseEventString(int mouseButtons, int modifiers);
|
||||||
Q_INVOKABLE QString wheelEventString(const QPointF &delta, 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);
|
Q_INVOKABLE bool append(const QString &action, const QString &plugin);
|
||||||
@ -59,6 +60,7 @@ private:
|
|||||||
KConfigGroup m_baseCfg;
|
KConfigGroup m_baseCfg;
|
||||||
KConfigGroup m_tempConfig;
|
KConfigGroup m_tempConfig;
|
||||||
KConfig m_tempConfigParent;
|
KConfig m_tempConfigParent;
|
||||||
|
QStringList m_removedTriggers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,8 +20,6 @@ import QtQuick 2.0
|
|||||||
import QtQuick.Controls 1.0 as QtControls
|
import QtQuick.Controls 1.0 as QtControls
|
||||||
import QtQuick.Layouts 1.0
|
import QtQuick.Layouts 1.0
|
||||||
|
|
||||||
import org.kde.qtextracomponents 2.0
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
@ -43,8 +41,12 @@ Item {
|
|||||||
model: configDialog.currentContainmentActionsModel
|
model: configDialog.currentContainmentActionsModel
|
||||||
delegate: RowLayout {
|
delegate: RowLayout {
|
||||||
width: root.width
|
width: root.width
|
||||||
QtControls.Button {
|
MouseEventInputButton {
|
||||||
text: model.action
|
defaultText: model.action
|
||||||
|
eventString: model.action
|
||||||
|
onEventStringChanged: {
|
||||||
|
configDialog.currentContainmentActionsModel.update(index, eventString, model.pluginName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QtControls.ComboBox {
|
QtControls.ComboBox {
|
||||||
id: pluginsCombo
|
id: pluginsCombo
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user