[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/kcontrol/standard_actions
From: Michael Jansen <kde () michael-jansen ! biz>
Date: 2008-07-10 19:51:21
Message-ID: 1215719481.690459.7071.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 830583 by mjansen:
Improved version. Now with saving the changes.
M +53 -8 standard_actions_module.cpp
M +5 -0 standard_actions_module.h
--- trunk/KDE/kdebase/workspace/kcontrol/standard_actions/standard_actions_module.cpp #830582:830583
@@ -19,7 +19,9 @@
#include <QLayout>
+#include <KAction>
#include <KActionCollection>
+#include <KConfigGroup>
#include <KDebug>
#include <KPluginFactory>
#include <KShortcutsEditor>
@@ -28,18 +30,20 @@
K_PLUGIN_FACTORY(StandardActionsModuleFactory, registerPlugin<StandardActionsModule>();)
K_EXPORT_PLUGIN(StandardActionsModuleFactory("kcmstandard_actions"))
+
StandardActionsModule::StandardActionsModule(
QWidget *parent,
const QVariantList &args )
: KCModule(StandardActionsModuleFactory::componentData(), parent, args )
,m_editor(NULL)
+ ,m_actionCollection(NULL)
{
// Configure the KCM
KCModule::setButtons(KCModule::Buttons(KCModule::Default | KCModule::Apply));
// Create and configure the editor
m_editor = new KShortcutsEditor(this, KShortcutsEditor::AllActions);
- connect(m_editor, SIGNAL(keyChange()), this, SIGNAL(changed()));
+ connect(m_editor, SIGNAL(keyChange()), this, SLOT(keyChanged()));
// Make a layout
QVBoxLayout *global = new QVBoxLayout;
@@ -47,36 +51,77 @@
setLayout(global);
}
+
StandardActionsModule::~StandardActionsModule()
{}
+
void StandardActionsModule::defaults()
{
- kDebug();
m_editor->allDefault();
}
+
+void StandardActionsModule::keyChanged()
+ {
+ emit changed(true);
+ }
+
+
void StandardActionsModule::load()
{
- kDebug();
-
// Create a collection to handle the shortcuts
- KActionCollection* col = new KActionCollection(
+ m_actionCollection = new KActionCollection(
this,
StandardActionsModuleFactory::componentData());
// Put all standard shortcuts into the collection
Q_FOREACH(KStandardAction::StandardAction id, KStandardAction::actionIds())
{
- KAction *action = KStandardAction::create(id, NULL, NULL, col);
+ KAction *action = KStandardAction::create(id, NULL, NULL, m_actionCollection);
+ KStandardShortcut::StandardShortcut shortcutId = KStandardAction::shortcutForActionId(id);
+ // We have to manually adjust the action. We want to show the
+ // hardcoded default and the user set shortcut. But action currently
+ // only contain the active shortcuts as default shortcut. So we
+ // have to fill it correctly
+ KShortcut hardcoded = KStandardShortcut::hardcodedDefaultShortcut(shortcutId);
+ KShortcut active = KStandardShortcut::shortcut(shortcutId);
+ // Set the hardcoded default shortcut as default shortcut
+ action->setShortcut(hardcoded, KAction::DefaultShortcut);
+ // Set the user defined values as active shortcuts. If the user only
+ // has overwritten the primary shortcut make sure alternate still
+ // get's shown
+ if (active.alternate()==QKeySequence())
+ {
+ active.setAlternate(hardcoded.alternate());
+ }
+ action->setShortcut(active, KAction::ActiveShortcut);
+ action->setData(shortcutId);
}
- m_editor->addCollection(col);
+ // Hand the collection to the editor
+ m_editor->addCollection(m_actionCollection);
}
+
void StandardActionsModule::save()
{
- kDebug();
+ // TODO Check what this call does
+ m_editor->commit();
+
+ Q_FOREACH(QAction* action, m_actionCollection->actions())
+ {
+ KAction *kaction = qobject_cast<KAction*>(action);
+
+ kDebug() << action->objectName() << ": " << action->data().toInt();
+ KStandardShortcut::saveShortcut(
+ static_cast<KStandardShortcut::StandardShortcut>(action->data().toInt())
+ , kaction->shortcut());
+ }
+
+ KGlobal::config()->sync();
+ KConfigGroup cg(KGlobal::config(), "Shortcuts");
+ cg.sync();
}
#include "standard_actions_module.moc"
--- trunk/KDE/kdebase/workspace/kcontrol/standard_actions/standard_actions_module.h #830582:830583
@@ -20,6 +20,7 @@
#include <KCModule>
+class KActionCollection;
class KShortcutsEditor;
class StandardActionsModule : public KCModule
@@ -34,9 +35,13 @@
/*reimp*/ void load();
/*reimp*/ void defaults();
+private slots:
+ void keyChanged();
+
private:
KShortcutsEditor *m_editor;
+ KActionCollection *m_actionCollection;
}; // class StandardActionsModule
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic