1#ifndef GLOBALSHORTCUTSREGISTRY_H
2#define GLOBALSHORTCUTSREGISTRY_H
3/* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "ksharedconfig.h"
22
23#include <QtCore/QObject>
24#include <QtCore/QHash>
25#include <QtDBus/QDBusObjectPath>
26
27
28class GlobalShortcut;
29class KGlobalAccelImpl;
30
31namespace KdeDGlobalAccel
32 {
33 class Component;
34 }
35
36/**
37 * Global Shortcut Registry.
38 *
39 * Shortcuts are registered by component. A component is for example kmail or
40 * amarok.
41 *
42 * A component can have contexts. Currently on plasma is planned to support
43 * that feature. A context enables plasma to keep track of global shortcut
44 * settings when switching containments.
45 *
46 * A shortcut (WIN+x) can be registered by one component only. The component
47 * is allowed to register it more than once in different contexts.
48 *
49 * @author Michael Jansen <kde@michael-jansen.biz>
50 */
51class GlobalShortcutsRegistry : public QObject
52 {
53 Q_OBJECT
54
55 Q_CLASSINFO("D-Bus Interface", "org.kde.KdedGlobalAccel.GlobalShortcutsRegistry")
56
57public:
58
59 /**
60 * Activate all shortcuts having their application present.
61 */
62 void activateShortcuts();
63
64 /**
65 * Return a list of all main components
66 */
67 QList<KdeDGlobalAccel::Component *> allMainComponents() const;
68
69 /**
70 * Return the root dbus path for the registry.
71 */
72 QDBusObjectPath dbusPath() const;
73
74 /**
75 * Deactivate all currently active shortcuts.
76 */
77 void deactivateShortcuts(bool temporarily=false);
78
79
80 /**
81 * Get the shortcut corresponding to key. Only active shortcut are
82 * considered.
83 */
84 GlobalShortcut *getActiveShortcutByKey(int key) const;
85
86 /**
87 */
88 KdeDGlobalAccel::Component *getComponent(const QString &uniqueName);
89
90 /**
91 * Get the shortcut corresponding to key. Active and inactive shortcuts
92 * are considered. But if the matching application uses contexts only one
93 * shortcut is returned.
94 *
95 * @see getShortcutsByKey(int key)
96 */
97 GlobalShortcut *getShortcutByKey(int key) const;
98
99 /**
100 * Get the shortcuts corresponding to key. Active and inactive shortcuts
101 * are considered.
102 *
103 * @see getShortcutsByKey(int key)
104 */
105 QList<GlobalShortcut*> getShortcutsByKey(int key) const;
106
107 /**
108 * Checks if @p shortcut is available for @p component.
109 *
110 * It is available if not used by another component in any context or used
111 * by @p component only in not active contexts.
112 */
113 bool isShortcutAvailable(
114 int shortcut,
115 const QString &component,
116 const QString &context) const;
117
118 static GlobalShortcutsRegistry *self();
119
120 bool registerKey(int key, GlobalShortcut *shortcut);
121
122 void setAccelManager(KGlobalAccelImpl *manager);
123
124 void setDBusPath(const QDBusObjectPath &path);
125
126 bool unregisterKey(int key, GlobalShortcut *shortcut);
127
128public Q_SLOTS:
129
130 void clear();
131
132 void loadSettings();
133
134 void writeSettings() const;
135
136 // Grab the keys
137 void grabKeys();
138
139 // Ungrab the keys
140 void ungrabKeys();
141
142private:
143
144 friend class KdeDGlobalAccel::Component;
145 friend class KGlobalAccelImpl;
146
147 KdeDGlobalAccel::Component *addComponent(KdeDGlobalAccel::Component *component);
148 KdeDGlobalAccel::Component *takeComponent(KdeDGlobalAccel::Component *component);
149
150 //called by the implementation to inform us about key presses
151 //returns true if the key was handled
152 bool keyPressed(int keyQt);
153
154 GlobalShortcutsRegistry();
155
156 ~GlobalShortcutsRegistry();
157
158 QHash<int, GlobalShortcut*> _active_keys;
159 QHash<QString, KdeDGlobalAccel::Component *> _components;
160
161 KGlobalAccelImpl *_manager;
162
163 mutable KConfig _config;
164
165 QDBusObjectPath _dbusPath;
166 };
167
168
169#endif /* #ifndef GLOBALSHORTCUTSREGISTRY_H */
170