Changeset View
Changeset View
Standalone View
Standalone View
src/client/appmenu.h
- This file was added.
1 | /**************************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2017 David Edmundson <kde@davidedmundson.co.uk> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
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 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | ****************************************************************************/ | ||||
20 | #ifndef KWAYLAND_CLIENT_APPMENU_H | ||||
21 | #define KWAYLAND_CLIENT_APPMENU_H | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | | ||||
25 | #include <KWayland/Client/kwaylandclient_export.h> | ||||
26 | | ||||
27 | struct org_kde_kwin_appmenu_manager; | ||||
28 | struct org_kde_kwin_appmenu; | ||||
29 | | ||||
30 | namespace KWayland | ||||
31 | { | ||||
32 | namespace Client | ||||
33 | { | ||||
34 | | ||||
35 | class EventQueue; | ||||
36 | class Surface; | ||||
37 | class AppMenu; | ||||
38 | | ||||
39 | /** | ||||
40 | * @short Wrapper for the org_kde_kwin_appmenu_manager interface. | ||||
41 | * | ||||
42 | * This class provides a convenient wrapper for the org_kde_kwin_appmenu_manager interface. | ||||
43 | * | ||||
44 | * To use this class one needs to interact with the Registry. There are two | ||||
45 | * possible ways to create the AppMenuManager interface: | ||||
46 | * @code | ||||
47 | * AppMenuManager *c = registry->createAppMenuManager(name, version); | ||||
48 | * @endcode | ||||
49 | * | ||||
50 | * This creates the AppMenuManager and sets it up directly. As an alternative this | ||||
51 | * can also be done in a more low level way: | ||||
52 | * @code | ||||
53 | * AppMenuManager *c = new AppMenuManager; | ||||
54 | * c->setup(registry->bindAppMenuManager(name, version)); | ||||
55 | * @endcode | ||||
56 | * | ||||
57 | * The AppMenuManager can be used as a drop-in replacement for any org_kde_kwin_appmenu_manager | ||||
58 | * pointer as it provides matching cast operators. | ||||
59 | * | ||||
60 | * @see Registry | ||||
61 | **/ | ||||
62 | class KWAYLANDCLIENT_EXPORT AppMenuManager : public QObject | ||||
63 | { | ||||
64 | Q_OBJECT | ||||
65 | public: | ||||
66 | /** | ||||
67 | * Creates a new AppMenuManager. | ||||
68 | * Note: after constructing the AppMenuManager it is not yet valid and one needs | ||||
69 | * to call setup. In order to get a ready to use AppMenuManager prefer using | ||||
70 | * Registry::createAppMenuManager. | ||||
71 | **/ | ||||
72 | explicit AppMenuManager(QObject *parent = nullptr); | ||||
73 | virtual ~AppMenuManager(); | ||||
74 | | ||||
75 | /** | ||||
76 | * Setup this AppMenuManager to manage the @p appmenumanager. | ||||
77 | * When using Registry::createAppMenuManager there is no need to call this | ||||
78 | * method. | ||||
79 | **/ | ||||
80 | void setup(org_kde_kwin_appmenu_manager *appmenumanager); | ||||
81 | /** | ||||
82 | * @returns @c true if managing a org_kde_kwin_appmenu_manager. | ||||
83 | **/ | ||||
84 | bool isValid() const; | ||||
85 | /** | ||||
86 | * Releases the org_kde_kwin_appmenu_manager interface. | ||||
87 | * After the interface has been released the AppMenuManager instance is no | ||||
88 | * longer valid and can be setup with another org_kde_kwin_appmenu_manager interface. | ||||
89 | **/ | ||||
90 | void release(); | ||||
91 | /** | ||||
92 | * Destroys the data held by this AppMenuManager. | ||||
93 | * This method is supposed to be used when the connection to the Wayland | ||||
94 | * server goes away. If the connection is not valid anymore, it's not | ||||
95 | * possible to call release anymore as that calls into the Wayland | ||||
96 | * connection and the call would fail. This method cleans up the data, so | ||||
97 | * that the instance can be deleted or set up to a new org_kde_kwin_appmenu_manager interface | ||||
98 | * once there is a new connection available. | ||||
99 | * | ||||
100 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
101 | * @code | ||||
102 | * connect(connection, &ConnectionThread::connectionDied, appmenumanager, &AppMenuManager::destroy); | ||||
103 | * @endcode | ||||
104 | * | ||||
105 | * @see release | ||||
106 | **/ | ||||
107 | void destroy(); | ||||
108 | | ||||
109 | /** | ||||
110 | * Sets the @p queue to use for creating objects with this AppMenuManager. | ||||
111 | **/ | ||||
112 | void setEventQueue(EventQueue *queue); | ||||
113 | /** | ||||
114 | * @returns The event queue to use for creating objects with this AppMenuManager. | ||||
115 | **/ | ||||
116 | EventQueue *eventQueue(); | ||||
117 | | ||||
118 | AppMenu *create(Surface *surface, QObject *parent = nullptr); | ||||
119 | | ||||
120 | operator org_kde_kwin_appmenu_manager*(); | ||||
121 | operator org_kde_kwin_appmenu_manager*() const; | ||||
122 | | ||||
123 | Q_SIGNALS: | ||||
124 | /** | ||||
125 | * The corresponding global for this interface on the Registry got removed. | ||||
126 | * | ||||
127 | * This signal gets only emitted if the AppMenuManager got created by | ||||
128 | * Registry::createAppMenuManager | ||||
129 | **/ | ||||
130 | void removed(); | ||||
131 | | ||||
132 | private: | ||||
133 | class Private; | ||||
134 | QScopedPointer<Private> d; | ||||
135 | }; | ||||
136 | | ||||
137 | class KWAYLANDCLIENT_EXPORT AppMenu : public QObject | ||||
138 | { | ||||
139 | Q_OBJECT | ||||
140 | public: | ||||
141 | virtual ~AppMenu(); | ||||
142 | | ||||
143 | /** | ||||
144 | * Setup this Appmenu to manage the @p appmenu. | ||||
145 | * When using AppMenuManager::createAppmenu there is no need to call this | ||||
146 | * method. | ||||
147 | **/ | ||||
148 | void setup(org_kde_kwin_appmenu *appmenu); | ||||
149 | /** | ||||
150 | * @returns @c true if managing a org_kde_kwin_appmenu. | ||||
151 | **/ | ||||
152 | bool isValid() const; | ||||
153 | /** | ||||
154 | * Releases the org_kde_kwin_appmenu interface. | ||||
155 | * After the interface has been released the Appmenu instance is no | ||||
156 | * longer valid and can be setup with another org_kde_kwin_appmenu interface. | ||||
157 | **/ | ||||
158 | void release(); | ||||
159 | /** | ||||
160 | * Destroys the data held by this Appmenu. | ||||
161 | * This method is supposed to be used when the connection to the Wayland | ||||
162 | * server goes away. If the connection is not valid anymore, it's not | ||||
163 | * possible to call release anymore as that calls into the Wayland | ||||
164 | * connection and the call would fail. This method cleans up the data, so | ||||
165 | * that the instance can be deleted or set up to a new org_kde_kwin_appmenu interface | ||||
166 | * once there is a new connection available. | ||||
167 | * | ||||
168 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
169 | * @code | ||||
170 | * connect(connection, &ConnectionThread::connectionDied, appmenu, &Appmenu::destroy); | ||||
171 | * @endcode | ||||
172 | * | ||||
173 | * @see release | ||||
174 | **/ | ||||
175 | void destroy(); | ||||
176 | | ||||
177 | void setAddress(const QString & serviceName, const QString & objectPath); | ||||
178 | | ||||
179 | operator org_kde_kwin_appmenu*(); | ||||
180 | operator org_kde_kwin_appmenu*() const; | ||||
181 | | ||||
182 | private: | ||||
183 | friend class AppMenuManager; | ||||
184 | explicit AppMenu(QObject *parent = nullptr); | ||||
185 | class Private; | ||||
186 | QScopedPointer<Private> d; | ||||
187 | }; | ||||
188 | | ||||
189 | | ||||
190 | } | ||||
191 | } | ||||
192 | | ||||
193 | #endif |