1#ifndef GLOBALSHORTCUT_H
2#define GLOBALSHORTCUT_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 "kglobalshortcutinfo_p.h"
22
23#include <QtCore/QObject>
24
25
26class GlobalShortcutContext;
27
28/**
29 * Represents a global shortcut.
30 *
31 * @internal
32 *
33 * \note This class can handle multiple keys (default and active). This
34 * feature isn't used currently. kde4 only allows setting one key per global
35 * shortcut.
36 *
37 * @author Michael Jansen <kde@michael-jansen.biz>
38 */
39class GlobalShortcut
40 {
41public:
42
43 GlobalShortcut(const QString &uniqueName, const QString &friendlyName, GlobalShortcutContext *context);
44 GlobalShortcut();
45
46 ~GlobalShortcut();
47
48 //! Returns the context the shortcuts belongs to
49 GlobalShortcutContext *context();
50 GlobalShortcutContext const *context() const;
51
52 //! Returns the default keys for this shortcut.
53 QList<int> defaultKeys() const;
54
55 //! Return the friendly display name for this shortcut.
56 QString friendlyName() const;
57
58 //! Check if the shortcut is active. It's keys are grabbed
59 bool isActive() const;
60
61 //! Check if the shortcut is fresh/new. Is an internal state
62 bool isFresh() const;
63
64 //! Check if the shortcut is present. It application is running.
65 bool isPresent() const;
66
67 //! Returns true if the shortcut is a session shortcut
68 bool isSessionShortcut() const;
69
70 //! Returns a list of keys associated with this shortcut.
71 QList<int> keys() const;
72
73 //! Activates the shortcut. The keys are grabbed.
74 void setActive();
75
76 //! Sets the default keys for this shortcut.
77 void setDefaultKeys(const QList<int>);
78
79 //! Sets the friendly name for the shortcut. For display.
80 void setFriendlyName(const QString &);
81
82 //! Sets the shortcut inactive. No longer grabs the keys.
83 void setInactive();
84
85 void setIsPresent(bool);
86 void setIsFresh(bool);
87
88 //! Sets the keys activated with this shortcut. The old keys are freed.
89 void setKeys(const QList<int>);
90
91 //! Returns the unique name aka id for the shortcuts.
92 QString uniqueName() const;
93
94 operator KGlobalShortcutInfo () const;
95
96 //! Remove this shortcut and it's siblings
97 void unRegister();
98
99private:
100
101 //! means the associated application is present.
102 bool _isPresent:1;
103
104 //! means the shortcut is registered with GlobalShortcutsRegistry
105 bool _isRegistered:1;
106
107 //! means the shortcut is new
108 bool _isFresh:1;
109
110 //! The context the shortcut belongs too
111 GlobalShortcutContext *_context;
112
113 QString _uniqueName;
114 QString _friendlyName; //usually localized
115
116 QList<int> _keys;
117 QList<int> _defaultKeys;
118 };
119
120
121#endif /* #ifndef GLOBALSHORTCUT_H */
122