2 * Copyright 2008 Michael Jansen <kde@michael-jansen.biz>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include "standard_actions_module.h"
23 #include <KActionCollection>
24 #include <KConfigGroup>
26 #include <KPluginFactory>
27 #include <KShortcutsEditor>
28 #include <KStandardAction>
29 #include <KMessageBox>
32 K_PLUGIN_FACTORY(StandardActionsModuleFactory
, registerPlugin
<StandardActionsModule
>();)
33 K_EXPORT_PLUGIN(StandardActionsModuleFactory("kcmstandard_actions"))
36 StandardActionsModule::StandardActionsModule(
38 const QVariantList
&args
)
39 : KCModule(StandardActionsModuleFactory::componentData(), parent
, args
)
41 ,m_actionCollection(NULL
)
44 KCModule::setButtons(KCModule::Buttons(KCModule::Default
| KCModule::Apply
));
46 // Create and configure the editor
47 m_editor
= new KShortcutsEditor(this, KShortcutsEditor::AllActions
);
48 connect(m_editor
, SIGNAL(keyChange()), this, SLOT(keyChanged()));
51 QVBoxLayout
*global
= new QVBoxLayout
;
52 global
->addWidget(m_editor
);
57 StandardActionsModule::~StandardActionsModule()
61 void StandardActionsModule::defaults()
63 m_editor
->allDefault();
67 void StandardActionsModule::keyChanged()
73 void StandardActionsModule::load()
75 // Create a collection to handle the shortcuts
76 m_actionCollection
= new KActionCollection(
78 StandardActionsModuleFactory::componentData());
80 // Put all standard shortcuts into the collection
81 Q_FOREACH(KStandardAction::StandardAction id
, KStandardAction::actionIds())
83 KStandardShortcut::StandardShortcut shortcutId
= KStandardAction::shortcutForActionId(id
);
84 // If the StandardShortcutId is AccelNone skip configuration for this
86 if (shortcutId
== KStandardShortcut::AccelNone
)
91 KAction
*action
= KStandardAction::create(id
, NULL
, NULL
, m_actionCollection
);
92 // Remember the shortcutId so we know where to save changes.
93 action
->setData(shortcutId
);
94 // We have to manually adjust the action. We want to show the
95 // hardcoded default and the user set shortcut. But action currently
96 // only contain the active shortcuts as default shortcut. So we
97 // have to fill it correctly
98 KShortcut hardcoded
= KStandardShortcut::hardcodedDefaultShortcut(shortcutId
);
99 KShortcut active
= KStandardShortcut::shortcut(shortcutId
);
100 // Set the hardcoded default shortcut as default shortcut
101 action
->setShortcut(hardcoded
, KAction::DefaultShortcut
);
102 // Set the user defined values as active shortcuts. If the user only
103 // has overwritten the primary shortcut make sure the alternate one
105 if (active
.alternate()==QKeySequence())
107 active
.setAlternate(hardcoded
.alternate());
109 action
->setShortcut(active
, KAction::ActiveShortcut
);
112 // Hand the collection to the editor
113 m_editor
->addCollection(m_actionCollection
);
117 void StandardActionsModule::save()
121 Q_FOREACH(QAction
* action
, m_actionCollection
->actions())
123 KAction
*kaction
= qobject_cast
<KAction
*>(action
);
125 KStandardShortcut::saveShortcut(
126 static_cast<KStandardShortcut::StandardShortcut
>(action
->data().toInt())
127 , kaction
->shortcut());
130 KGlobal::config()->sync();
131 KConfigGroup
cg(KGlobal::config(), "Shortcuts");
134 QString title
= i18n("Standard Actions successfully saved");
135 QString message
= i18n(
136 "The changes have been saved. Please consider:"
137 "<ul><li>Applications need to be restarted to see the changes.</li>"
138 " <li>This change could introduce shortcut conflicts in some applications.</li>"
140 KMessageBox::information(this, message
, title
, "shortcuts_saved_info");
143 #include "standard_actions_module.moc"