1 #ifndef GLOBALSHORTCUTSREGISTRY_H
2 #define GLOBALSHORTCUTSREGISTRY_H
3 /* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
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.
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.
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.
21 #include "ksharedconfig.h"
23 #include <QtCore/QObject>
24 #include <QtCore/QHash>
25 #include <QtDBus/QDBusObjectPath>
29 class KGlobalAccelImpl
;
31 namespace KdeDGlobalAccel
37 * Global Shortcut Registry.
39 * Shortcuts are registered by component. A component is for example kmail or
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.
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.
49 * @author Michael Jansen <kde@michael-jansen.biz>
51 class GlobalShortcutsRegistry
: public QObject
55 Q_CLASSINFO("D-Bus Interface", "org.kde.KdedGlobalAccel.GlobalShortcutsRegistry")
60 * Activate all shortcuts having their application present.
62 void activateShortcuts();
65 * Return a list of all main components
67 QList
<KdeDGlobalAccel::Component
*> allMainComponents() const;
70 * Return the root dbus path for the registry.
72 QDBusObjectPath
dbusPath() const;
75 * Deactivate all currently active shortcuts.
77 void deactivateShortcuts(bool temporarily
=false);
81 * Get the shortcut corresponding to key. Only active shortcut are
84 GlobalShortcut
*getActiveShortcutByKey(int key
) const;
88 KdeDGlobalAccel::Component
*getComponent(const QString
&uniqueName
);
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.
95 * @see getShortcutsByKey(int key)
97 GlobalShortcut
*getShortcutByKey(int key
) const;
100 * Get the shortcuts corresponding to key. Active and inactive shortcuts
103 * @see getShortcutsByKey(int key)
105 QList
<GlobalShortcut
*> getShortcutsByKey(int key
) const;
108 * Checks if @p shortcut is available for @p component.
110 * It is available if not used by another component in any context or used
111 * by @p component only in not active contexts.
113 bool isShortcutAvailable(
115 const QString
&component
,
116 const QString
&context
) const;
118 static GlobalShortcutsRegistry
*self();
120 bool registerKey(int key
, GlobalShortcut
*shortcut
);
122 void setAccelManager(KGlobalAccelImpl
*manager
);
124 void setDBusPath(const QDBusObjectPath
&path
);
126 bool unregisterKey(int key
, GlobalShortcut
*shortcut
);
130 void invokeAction(const QStringList
&actionId
, qlonglong timestamp
);
136 void writeSettings() const;
140 friend class KdeDGlobalAccel::Component
;
141 friend class KGlobalAccelImpl
;
143 KdeDGlobalAccel::Component
*addComponent(KdeDGlobalAccel::Component
*component
);
144 KdeDGlobalAccel::Component
*takeComponent(KdeDGlobalAccel::Component
*component
);
146 //called by the implementation to inform us about key presses
147 //returns true if the key was handled
148 bool keyPressed(int keyQt
);
150 GlobalShortcutsRegistry();
152 ~GlobalShortcutsRegistry();
154 QHash
<int, GlobalShortcut
*> _active_keys
;
155 QHash
<QString
, KdeDGlobalAccel::Component
*> _components
;
157 KGlobalAccelImpl
*_manager
;
159 mutable KConfig _config
;
161 QDBusObjectPath _dbusPath
;
165 #endif /* #ifndef GLOBALSHORTCUTSREGISTRY_H */