1
/****************************************************************************
5
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
7
Distributed under the terms of the GNU General Public License version 2.
9
****************************************************************************/
13
#include "action_data/action_data_group.h"
14
#include "action_data/menuentry_shortcut_action_data.h"
15
#include "actions/actions.h"
17
#include "shortcuts_handler.h"
19
#include "triggers/gestures.h"
22
#include <kaboutdata.h>
24
#include <kglobalaccel.h>
25
#include <kpluginfactory.h>
26
#include <kpluginloader.h>
30
#define COMPONENT_NAME "khotkeys"
32
K_PLUGIN_FACTORY(KHotKeysModuleFactory,
33
registerPlugin<KHotKeysModule>();
35
K_EXPORT_PLUGIN(KHotKeysModuleFactory(COMPONENT_NAME))
37
using namespace KHotKeys;
41
KHotKeysModule::KHotKeysModule(QObject* parent, const QList<QVariant>&)
48
kDebug() << "Installing the delayed initialization callback.";
49
QMetaObject::invokeMethod( this, "initialize", Qt::QueuedConnection);
53
void KHotKeysModule::initialize()
60
kDebug() << "Delayed initialization.";
63
// Initialize the global data, grab keys
64
KHotKeys::init_global_data( true, this );
66
// If a shortcut was changed (global shortcuts kcm), save
68
keyboard_handler.data(), SIGNAL(shortcutChanged()),
71
// Read the configuration from file khotkeysrc
72
reread_configuration();
74
KGlobalAccel::cleanComponent(COMPONENT_NAME);
76
if (_settings.update())
84
KHotKeysModule::~KHotKeysModule()
86
// actions_root belongs to _settings.
91
void KHotKeysModule::reread_configuration()
93
kDebug() << "Reloading the khotkeys configuration";
96
actions_root = NULL; // Disables the dbus interface effectively
97
KHotKeys::khotkeys_set_active( false );
100
_settings.reread_settings(true);
102
KHotKeys::gesture_handler->set_mouse_button( _settings.gestureMouseButton() );
103
KHotKeys::gesture_handler->set_timeout( _settings.gestureTimeOut() );
104
kDebug() << _settings.areGesturesDisabled();
105
KHotKeys::gesture_handler->enable( !_settings.areGesturesDisabled() );
106
KHotKeys::gesture_handler->set_exclude( _settings.gesturesExclude() );
108
// KHotKeys::voice_handler->set_shortcut( _settings.voice_shortcut );
109
actions_root = _settings.actions();
110
KHotKeys::khotkeys_set_active( true );
116
SimpleActionData* KHotKeysModule::menuentry_action(const QString &storageId)
118
ActionDataGroup *menuentries = _settings.get_system_group(
119
ActionDataGroup::SYSTEM_MENUENTRIES);
121
// Now try to find the action
122
Q_FOREACH(ActionDataBase* element, menuentries->children())
124
SimpleActionData *actionData = dynamic_cast<SimpleActionData*>(element);
126
if (actionData && actionData->action())
128
MenuEntryAction *action = dynamic_cast<MenuEntryAction*>(actionData->action());
129
if (action && action->service() && (action->service()->storageId() == storageId))
140
QString KHotKeysModule::get_menuentry_shortcut(const QString &storageId)
142
SimpleActionData* actionData = menuentry_action(storageId);
145
if (actionData == NULL) return "";
147
// The action must have a shortcut trigger. but don't assume to much
148
ShortcutTrigger* shortcutTrigger = dynamic_cast<ShortcutTrigger*>(actionData->trigger());
150
Q_ASSERT(shortcutTrigger);
151
if (shortcutTrigger == NULL) return "";
153
return shortcutTrigger->shortcut().primary();
157
QString KHotKeysModule::register_menuentry_shortcut(
158
const QString &storageId,
159
const QString &sequence)
161
kDebug() << storageId << "(" << sequence << ")";
163
// Check the service we got. If it is invalid there is no need to
165
KService::Ptr wantedService = KService::serviceByStorageId(storageId);
166
if (wantedService.isNull())
168
kError() << "Storage Id " << storageId << "not valid";
172
// Look for the action
173
SimpleActionData* actionData = menuentry_action(storageId);
175
// No action found. Create on if sequence is != ""
176
if (actionData == NULL)
178
kDebug() << "No action found";
180
// If the sequence is empty there is no need to create a action.
181
if (sequence.isEmpty()) return "";
183
kDebug() << "Creating a new action";
186
ActionDataGroup *menuentries = _settings.get_system_group(
187
ActionDataGroup::SYSTEM_MENUENTRIES);
189
MenuEntryShortcutActionData *newAction = new MenuEntryShortcutActionData(
191
wantedService->name(),
200
// Return the real shortcut
201
return newAction->trigger()->shortcut().primary();
206
if (sequence.isEmpty())
208
kDebug() << "Deleting the action";
209
actionData->aboutToBeErased();
216
kDebug() << "Changing the action";
217
// The action must have a shortcut trigger. but don't assume to much
218
ShortcutTrigger* shortcutTrigger =
219
dynamic_cast<ShortcutTrigger*>(actionData->trigger());
220
Q_ASSERT(shortcutTrigger);
221
if (shortcutTrigger == NULL) return "";
223
// Change the actionData
224
shortcutTrigger->set_key_sequence(sequence);
227
// Remove the resulting real shortcut
228
return shortcutTrigger->shortcut().primary();
237
void KHotKeysModule::quit()
243
void KHotKeysModule::save()
245
KHotKeys::khotkeys_set_active( false );
247
KHotKeys::khotkeys_set_active( true );