KGlobalAccel

globalshortcutsregistry.h
1 /*
2  SPDX-FileCopyrightText: 2008 Michael Jansen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef GLOBALSHORTCUTSREGISTRY_H
8 #define GLOBALSHORTCUTSREGISTRY_H
9 
10 #include <KSharedConfig>
11 
12 #include <QDBusObjectPath>
13 #include <QHash>
14 #include <QObject>
15 
16 class GlobalShortcut;
18 
19 namespace KdeDGlobalAccel
20 {
21 class Component;
22 }
23 
24 /**
25  * Global Shortcut Registry.
26  *
27  * Shortcuts are registered by component. A component is for example kmail or
28  * amarok.
29  *
30  * A component can have contexts. Currently on plasma is planned to support
31  * that feature. A context enables plasma to keep track of global shortcut
32  * settings when switching containments.
33  *
34  * A shortcut (WIN+x) can be registered by one component only. The component
35  * is allowed to register it more than once in different contexts.
36  *
37  * @author Michael Jansen <[email protected]>
38  */
40 {
41  Q_OBJECT
42 
43  Q_CLASSINFO("D-Bus Interface", "org.kde.KdedGlobalAccel.GlobalShortcutsRegistry")
44 
45 public:
46  /**
47  * Use GlobalShortcutsRegistry::self()
48  *
49  * @internal
50  */
53 
54  /**
55  * Activate all shortcuts having their application present.
56  */
57  void activateShortcuts();
58 
59  /**
60  * Return a list of all main components
61  */
62  QList<KdeDGlobalAccel::Component *> allMainComponents() const;
63 
64  /**
65  * Return the root dbus path for the registry.
66  */
67  QDBusObjectPath dbusPath() const;
68 
69  /**
70  * Deactivate all currently active shortcuts.
71  */
72  void deactivateShortcuts(bool temporarily = false);
73 
74  /**
75  * Get the shortcut corresponding to key. Only active shortcut are
76  * considered.
77  */
78  GlobalShortcut *getActiveShortcutByKey(int key) const;
79 
80  /**
81  */
82  KdeDGlobalAccel::Component *getComponent(const QString &uniqueName);
83 
84  /**
85  * Get the shortcut corresponding to key. Active and inactive shortcuts
86  * are considered. But if the matching application uses contexts only one
87  * shortcut is returned.
88  *
89  * @see getShortcutsByKey(int key)
90  */
91  GlobalShortcut *getShortcutByKey(int key) const;
92 
93  /**
94  * Get the shortcuts corresponding to key. Active and inactive shortcuts
95  * are considered.
96  *
97  * @see getShortcutsByKey(int key)
98  */
99  QList<GlobalShortcut *> getShortcutsByKey(int key) const;
100 
101  /**
102  * Checks if @p shortcut is available for @p component.
103  *
104  * It is available if not used by another component in any context or used
105  * by @p component only in not active contexts.
106  */
107  bool isShortcutAvailable(int shortcut, const QString &component, const QString &context) const;
108 
109  static GlobalShortcutsRegistry *self();
110 
111  bool registerKey(int key, GlobalShortcut *shortcut);
112 
113  void setAccelManager(KGlobalAccelInterface *manager);
114 
115  void setDBusPath(const QDBusObjectPath &path);
116 
117  bool unregisterKey(int key, GlobalShortcut *shortcut);
118 
119 public Q_SLOTS:
120 
121  void clear();
122 
123  void loadSettings();
124 
125  void writeSettings() const;
126 
127  // Grab the keys
128  void grabKeys();
129 
130  // Ungrab the keys
131  void ungrabKeys();
132 
133 private:
134  friend class KdeDGlobalAccel::Component;
135  friend class KGlobalAccelInterface;
136 
137  KdeDGlobalAccel::Component *addComponent(KdeDGlobalAccel::Component *component);
138  KdeDGlobalAccel::Component *takeComponent(KdeDGlobalAccel::Component *component);
139 
140  // called by the implementation to inform us about key presses
141  // returns true if the key was handled
142  bool keyPressed(int keyQt);
143 
144  QHash<int, GlobalShortcut *> _active_keys;
146 
147  KGlobalAccelInterface *_manager;
148 
149  mutable KConfig _config;
150 
151  QDBusObjectPath _dbusPath;
152 };
153 
154 #endif /* #ifndef GLOBALSHORTCUTSREGISTRY_H */
Global Shortcut Registry.
Abstract interface for plugins to implement.
bool keyPressed(int keyQt)
called by the implementation to inform us about key presses
Represents a global shortcut.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun May 16 2021 22:53:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.