1 | /* |
2 | This file is part of the KDE libraries |
3 | |
4 | Copyright (c) 2007 Andreas Hartmetz <ahartmetz@gmail.com> |
5 | Copyright (c) 2008 Michael Jansen <kde@michael-jansen.biz> |
6 | |
7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. |
11 | |
12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. |
21 | */ |
22 | #ifndef KGLOBALACCELD_H |
23 | #define KGLOBALACCELD_H |
24 | |
25 | #include <kglobalshortcutinfo.h> |
26 | #include <kdemacros.h> |
27 | |
28 | #include <QtCore/QStringList> |
29 | #include <QtCore/QList> |
30 | #include <QtDBus/QtDBus> |
31 | |
32 | struct KGlobalAccelDPrivate; |
33 | |
34 | /** |
35 | * @todo get rid of all of those QStringList parameters. |
36 | */ |
37 | class KGlobalAccelD : public QObject, protected QDBusContext |
38 | { |
39 | Q_OBJECT |
40 | Q_CLASSINFO("D-Bus Interface" , "org.kde.KGlobalAccel" ) |
41 | Q_ENUMS(SetShortcutFlag) |
42 | |
43 | public: |
44 | |
45 | enum SetShortcutFlag |
46 | { |
47 | SetPresent = 2, |
48 | NoAutoloading = 4, |
49 | IsDefault = 8 |
50 | }; |
51 | Q_FLAGS(SetShortcutFlags) |
52 | |
53 | KGlobalAccelD(QObject* parent = NULL); |
54 | ~KGlobalAccelD(); |
55 | |
56 | bool init(); |
57 | |
58 | public Q_SLOTS: |
59 | |
60 | /** |
61 | * Get the dbus path for all known components. |
62 | * |
63 | * The returned path is absolute. No need to prepend anything. |
64 | */ |
65 | Q_SCRIPTABLE QList<QDBusObjectPath> allComponents() const; |
66 | |
67 | Q_SCRIPTABLE QList<QStringList> allMainComponents() const; |
68 | |
69 | Q_SCRIPTABLE QList<QStringList> allActionsForComponent(const QStringList &actionId) const; |
70 | |
71 | Q_SCRIPTABLE QStringList action(int key) const; |
72 | |
73 | //to be called by main components not owning the action |
74 | Q_SCRIPTABLE QList<int> shortcut(const QStringList &actionId) const; |
75 | |
76 | //to be called by main components not owning the action |
77 | Q_SCRIPTABLE QList<int> defaultShortcut(const QStringList &actionId) const; |
78 | |
79 | /** |
80 | * Get the dbus path for @ componentUnique |
81 | * |
82 | * @param componentUnique the components unique identifier |
83 | * |
84 | * @return the absolute dbus path |
85 | */ |
86 | Q_SCRIPTABLE QDBusObjectPath getComponent(const QString &componentUnique) const; |
87 | |
88 | //to be called by main components owning the action |
89 | Q_SCRIPTABLE QList<int> setShortcut(const QStringList &actionId, |
90 | const QList<int> &keys, uint flags); |
91 | |
92 | //this is used if application A wants to change shortcuts of application B |
93 | Q_SCRIPTABLE void setForeignShortcut(const QStringList &actionId, const QList<int> &keys); |
94 | |
95 | //to be called when a KAction is destroyed. The shortcut stays in the data structures for |
96 | //conflict resolution but won't trigger. |
97 | Q_SCRIPTABLE void setInactive(const QStringList &actionId); |
98 | |
99 | Q_SCRIPTABLE void doRegister(const QStringList &actionId); |
100 | |
101 | //! @see unregister |
102 | Q_SCRIPTABLE KDE_DEPRECATED void unRegister(const QStringList &actionId); |
103 | |
104 | Q_SCRIPTABLE void activateGlobalShortcutContext( |
105 | const QString &component, |
106 | const QString &context); |
107 | |
108 | |
109 | /** |
110 | * Returns the shortcuts registered for @p key. |
111 | * |
112 | * If there is more than one shortcut they are guaranteed to be from the |
113 | * same component but different contexts. All shortcuts are searched. |
114 | */ |
115 | Q_SCRIPTABLE QList<KGlobalShortcutInfo> getGlobalShortcutsByKey(int key) const; |
116 | |
117 | /** |
118 | * Return true if the @p shortcut is available for @p component. |
119 | */ |
120 | Q_SCRIPTABLE bool isGlobalShortcutAvailable( |
121 | int key, |
122 | const QString &component) const; |
123 | |
124 | /** |
125 | * Delete the shortcut with @a component and @name. |
126 | * |
127 | * The shortcut is removed from the registry even if it is currently |
128 | * present. It is removed from all contexts. |
129 | * |
130 | * @param componentUnique the components unique identifier |
131 | * @param shortcutUnique the shortcut id |
132 | * |
133 | * @return @c true if the shortcuts was deleted, @c false if it didn't * exist. |
134 | */ |
135 | Q_SCRIPTABLE bool unregister( |
136 | const QString &componentUnique, |
137 | const QString &shortcutUnique); |
138 | |
139 | Q_SIGNALS: |
140 | |
141 | Q_SCRIPTABLE void yourShortcutGotChanged(const QStringList &actionId, const QList<int> &newKeys); |
142 | |
143 | private Q_SLOTS: |
144 | |
145 | void blockGlobalShortcuts(int); |
146 | |
147 | |
148 | private: |
149 | |
150 | Q_PRIVATE_SLOT(d, void _k_newGlobalShortcutNotification() ) |
151 | |
152 | void scheduleWriteSettings() const; |
153 | |
154 | KGlobalAccelDPrivate *const d; |
155 | }; |
156 | |
157 | #endif //KGLOBALACCELD_H |
158 | |