Merge lp:~albaguirre/qtubuntu/papi-cleanup into lp:qtubuntu
- papi-cleanup
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~albaguirre/qtubuntu/papi-cleanup |
Merge into: | lp:qtubuntu |
Prerequisite: | lp:~albaguirre/qtubuntu/use-mir-rs-api |
Diff against target: |
2476 lines (+70/-2204) (has conflicts) 23 files modified
debian/qtubuntu-appmenutheme.install (+0/-1) debian/rules (+0/-1) src/src.pro (+1/-1) src/ubuntuappmenu/com.ubuntu.MenuRegistrar.xml (+0/-83) src/ubuntuappmenu/gmenumodelexporter.cpp (+0/-475) src/ubuntuappmenu/gmenumodelexporter.h (+0/-100) src/ubuntuappmenu/gmenumodelplatformmenu.cpp (+0/-518) src/ubuntuappmenu/gmenumodelplatformmenu.h (+0/-181) src/ubuntuappmenu/logging.h (+0/-27) src/ubuntuappmenu/menuregistrar.cpp (+0/-137) src/ubuntuappmenu/menuregistrar.h (+0/-59) src/ubuntuappmenu/qtubuntuextraactionhandler.cpp (+0/-107) src/ubuntuappmenu/qtubuntuextraactionhandler.h (+0/-40) src/ubuntuappmenu/registry.cpp (+0/-97) src/ubuntuappmenu/registry.h (+0/-56) src/ubuntuappmenu/themeplugin.cpp (+0/-36) src/ubuntuappmenu/themeplugin.h (+0/-34) src/ubuntuappmenu/ubuntuappmenu.json (+0/-3) src/ubuntumirclient/qmirclientintegration.cpp (+69/-99) src/ubuntumirclient/qmirclientintegration.h (+0/-15) src/ubuntumirclient/qmirclientplatformservices.cpp (+0/-75) src/ubuntumirclient/qmirclientplatformservices.h (+0/-57) src/ubuntumirclient/ubuntumirclient.pro (+0/-2) Conflict: can't delete src/ubuntuappmenu because it is not empty. Not deleting. Conflict because src/ubuntuappmenu is not versioned, but has versioned children. Versioned directory. Contents conflict in src/ubuntuappmenu/theme.cpp Contents conflict in src/ubuntuappmenu/theme.h Contents conflict in src/ubuntuappmenu/ubuntuappmenu.pro Text conflict in src/ubuntumirclient/qmirclientintegration.cpp |
To merge this branch: | bzr merge lp:~albaguirre/qtubuntu/papi-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michał Sawicz | Needs Fixing | ||
Unity8 CI Bot | continuous-integration | Needs Fixing | |
Review via email: mp+324886@code.launchpad.net |
Commit message
Completely remove dependency on platform-api
Description of the change
The only real use of platform-api was for url launching. Is there something else we can do for that?
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
Michał Sawicz (saviq) wrote : | # |
I suppose whatever the xcb plugin is using for URLs we can use, too (xdg-open?).
LP reports conflicts, can you please update?
Unmerged revisions
- 399. By Alberto Aguirre
-
Remove platform-api dependency.
- 398. By Alberto Aguirre
-
Remove ubuntuappmenu
- 397. By Alberto Aguirre
-
Cleanup #pragmas and unneeded repaints when resizing.
- 396. By Alberto Aguirre
-
Avoid using mir_window_
get_parameters, it will be deprecated - 395. By Alberto Aguirre
-
Remove mir_event_type_key and mir_event_
type_motion as they are deprecated. - 394. By Alberto Aguirre
-
Use MirRenderSurface for pixmap cursors.
Creating buffer streams directly will be deprecated in mir in the near future, instead use render surfaces.
- 393. By Alberto Aguirre
-
Update resizing now that client can drive the buffer size through mir_render_
surface_ set_size. - 392. By Alberto Aguirre
-
Avoid use of deprecated mir EGL related apis.
With the new mesa update, the EGLNativeDispla
yType is MirConnection and the EGLNativeWindowType is a MirRenderSurface.
Ignore deprecation warnings on use of MirRenderSurface - its "deprecated" because it'll be renamed in mir 1.0.
Preview Diff
1 | === removed file 'debian/qtubuntu-appmenutheme.install' | |||
2 | --- debian/qtubuntu-appmenutheme.install 2016-06-17 12:40:26 +0000 | |||
3 | +++ debian/qtubuntu-appmenutheme.install 1970-01-01 00:00:00 +0000 | |||
4 | @@ -1,1 +0,0 @@ | |||
5 | 1 | usr/lib/*/qt5/plugins/platformthemes/* | ||
6 | 2 | 0 | ||
7 | === modified file 'debian/rules' | |||
8 | --- debian/rules 2016-06-17 12:40:26 +0000 | |||
9 | +++ debian/rules 2017-05-31 19:29:52 +0000 | |||
10 | @@ -62,4 +62,3 @@ | |||
11 | 62 | dh_install --sourcedir=$(TMP1_DIR) -pqtubuntu-android | 62 | dh_install --sourcedir=$(TMP1_DIR) -pqtubuntu-android |
12 | 63 | endif | 63 | endif |
13 | 64 | dh_install --sourcedir=$(TMP2_DIR) -pqtubuntu-desktop | 64 | dh_install --sourcedir=$(TMP2_DIR) -pqtubuntu-desktop |
14 | 65 | dh_install --sourcedir=$(TMP2_DIR) -pqtubuntu-appmenutheme | ||
15 | 66 | 65 | ||
16 | === modified file 'src/src.pro' | |||
17 | --- src/src.pro 2016-06-21 16:33:19 +0000 | |||
18 | +++ src/src.pro 2017-05-31 19:29:52 +0000 | |||
19 | @@ -1,3 +1,3 @@ | |||
20 | 1 | TEMPLATE = subdirs | 1 | TEMPLATE = subdirs |
21 | 2 | 2 | ||
23 | 3 | SUBDIRS += ubuntumirclient ubuntuappmenu | 3 | SUBDIRS += ubuntumirclient |
24 | 4 | 4 | ||
25 | === removed file 'src/ubuntuappmenu/com.ubuntu.MenuRegistrar.xml' | |||
26 | --- src/ubuntuappmenu/com.ubuntu.MenuRegistrar.xml 2016-09-29 10:24:29 +0000 | |||
27 | +++ src/ubuntuappmenu/com.ubuntu.MenuRegistrar.xml 1970-01-01 00:00:00 +0000 | |||
28 | @@ -1,83 +0,0 @@ | |||
29 | 1 | <!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> | ||
30 | 2 | <node xmlns:dox="http://www.ayatana.org/dbus/dox.dtd"> | ||
31 | 3 | <dox:d><![CDATA[ | ||
32 | 4 | @mainpage | ||
33 | 5 | |||
34 | 6 | An interface to register menus that are associated with a window in an application. The | ||
35 | 7 | main interface is documented here: @ref com::ubuntu::MenuRegistrar. | ||
36 | 8 | |||
37 | 9 | The actual menus are transported using the gmenumodel protocol | ||
38 | 10 | ]]></dox:d> | ||
39 | 11 | <interface name="com.ubuntu.MenuRegistrar" xmlns:dox="http://www.ayatana.org/dbus/dox.dtd"> | ||
40 | 12 | <dox:d> | ||
41 | 13 | An interface to register a menu from an application to be displayed in another | ||
42 | 14 | window. This manages that association between processes and/or Mir surface IDs and the dbus | ||
43 | 15 | address and object that provides the menus using the org.gtk.Menus interface. | ||
44 | 16 | </dox:d> | ||
45 | 17 | <method name="RegisterAppMenu"> | ||
46 | 18 | <dox:d><![CDATA[ | ||
47 | 19 | Associates a gmenumodel with an application | ||
48 | 20 | |||
49 | 21 | /note this method assumes that the connection from the caller is the DBus connection | ||
50 | 22 | to use for the object. Applications that use multiple DBus connections will need to | ||
51 | 23 | ensure this method is called with the same connection that implements the object. | ||
52 | 24 | ]]></dox:d> | ||
53 | 25 | <arg name="pid" type="u" direction="in"> | ||
54 | 26 | <dox:d>The process ID of the application for which the menu is associated</dox:d> | ||
55 | 27 | </arg> | ||
56 | 28 | <arg name="menuObjectPath" type="o" direction="in"> | ||
57 | 29 | <dox:d>The dbus path where the gmenumodel interface for the application menu has been exported</dox:d> | ||
58 | 30 | </arg> | ||
59 | 31 | <arg name="actionObjectPath" type="o" direction="in"> | ||
60 | 32 | <dox:d>The dbus path where the gactionmenu interface for the application menu actions has been exported</dox:d> | ||
61 | 33 | </arg> | ||
62 | 34 | <arg name="service" type="s" direction="in"> | ||
63 | 35 | <dox:d>The dbus conection name of the client application to be registered (e.g. :1.23 or org.example.service)</dox:d> | ||
64 | 36 | </arg> | ||
65 | 37 | </method> | ||
66 | 38 | <method name="UnregisterAppMenu"> | ||
67 | 39 | <dox:d> | ||
68 | 40 | A method to allow removing an application menu from the database. | ||
69 | 41 | </dox:d> | ||
70 | 42 | <arg name="pid" type="u" direction="in"> | ||
71 | 43 | <dox:d>The process id of the application</dox:d> | ||
72 | 44 | </arg> | ||
73 | 45 | <arg name="menuObjectPath" type="o" direction="in"> | ||
74 | 46 | <dox:d>The dbus path for the registered application menu to be unregistered</dox:d> | ||
75 | 47 | </arg> | ||
76 | 48 | </method> | ||
77 | 49 | |||
78 | 50 | <method name="RegisterSurfaceMenu"> | ||
79 | 51 | <dox:d><![CDATA[ | ||
80 | 52 | Associates a gmenumodel with a surface | ||
81 | 53 | |||
82 | 54 | /note this method assumes that the connection from the caller is the DBus connection | ||
83 | 55 | to use for the object. Applications that use multiple DBus connections will need to | ||
84 | 56 | ensure this method is called with the same connection that implements the object. | ||
85 | 57 | ]]></dox:d> | ||
86 | 58 | <arg name="surface" type="s" direction="in"> | ||
87 | 59 | <dox:d>The surface ID of the surface</dox:d> | ||
88 | 60 | </arg> | ||
89 | 61 | <arg name="menuObjectPath" type="o" direction="in"> | ||
90 | 62 | <dox:d>The dbus path where the gmenumodel interface for the surface menu has been exported</dox:d> | ||
91 | 63 | </arg> | ||
92 | 64 | <arg name="actionObjectPath" type="o" direction="in"> | ||
93 | 65 | <dox:d>The dbus path where the gactionmenu interface for the surface menu actions has been exported</dox:d> | ||
94 | 66 | </arg> | ||
95 | 67 | <arg name="service" type="s" direction="in"> | ||
96 | 68 | <dox:d>The dbus conection name of the client application to be registered (e.g. :1.23 or org.example.service)</dox:d> | ||
97 | 69 | </arg> | ||
98 | 70 | </method> | ||
99 | 71 | <method name="UnregisterSurfaceMenu"> | ||
100 | 72 | <dox:d> | ||
101 | 73 | A method to allow removing a surface menu from the database. | ||
102 | 74 | </dox:d> | ||
103 | 75 | <arg name="surfaceId" type="s" direction="in"> | ||
104 | 76 | <dox:d>The surface id of the surface</dox:d> | ||
105 | 77 | </arg> | ||
106 | 78 | <arg name="menuObjectPath" type="o" direction="in"> | ||
107 | 79 | <dox:d>The dbus path for the registered surface menu to be unregistered</dox:d> | ||
108 | 80 | </arg> | ||
109 | 81 | </method> | ||
110 | 82 | </interface> | ||
111 | 83 | </node> | ||
112 | 84 | 0 | ||
113 | === removed file 'src/ubuntuappmenu/gmenumodelexporter.cpp' | |||
114 | --- src/ubuntuappmenu/gmenumodelexporter.cpp 2017-03-27 08:23:00 +0000 | |||
115 | +++ src/ubuntuappmenu/gmenumodelexporter.cpp 1970-01-01 00:00:00 +0000 | |||
116 | @@ -1,475 +0,0 @@ | |||
117 | 1 | /* | ||
118 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
119 | 3 | * | ||
120 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
121 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
122 | 6 | * the Free Software Foundation. | ||
123 | 7 | * | ||
124 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
125 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
126 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
127 | 11 | * Lesser General Public License for more details. | ||
128 | 12 | * | ||
129 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
130 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
131 | 15 | */ | ||
132 | 16 | |||
133 | 17 | // Local | ||
134 | 18 | #include "gmenumodelexporter.h" | ||
135 | 19 | #include "registry.h" | ||
136 | 20 | #include "logging.h" | ||
137 | 21 | #include "qtubuntuextraactionhandler.h" | ||
138 | 22 | |||
139 | 23 | #include <QDebug> | ||
140 | 24 | #include <QTimerEvent> | ||
141 | 25 | |||
142 | 26 | #include <functional> | ||
143 | 27 | |||
144 | 28 | namespace { | ||
145 | 29 | |||
146 | 30 | // Derive an action name from the label by removing spaces and Capitilizing the words. | ||
147 | 31 | // Also remove mnemonics from the label. | ||
148 | 32 | inline QString getActionString(QString label) | ||
149 | 33 | { | ||
150 | 34 | QRegExp re("\\W"); | ||
151 | 35 | label = label.replace(QRegExp("(&|_)"), ""); | ||
152 | 36 | QStringList parts = label.split(re, QString::SkipEmptyParts); | ||
153 | 37 | |||
154 | 38 | QString result; | ||
155 | 39 | Q_FOREACH(const QString& part, parts) { | ||
156 | 40 | result += part[0].toUpper(); | ||
157 | 41 | result += part.right(part.length()-1); | ||
158 | 42 | } | ||
159 | 43 | return result; | ||
160 | 44 | } | ||
161 | 45 | |||
162 | 46 | static void activate_cb(GSimpleAction *action, GVariant *, gpointer user_data) | ||
163 | 47 | { | ||
164 | 48 | qCDebug(ubuntuappmenu, "Activate menu action '%s'", g_action_get_name(G_ACTION(action))); | ||
165 | 49 | auto item = static_cast<UbuntuPlatformMenuItem*>(user_data); | ||
166 | 50 | item->activated(); | ||
167 | 51 | } | ||
168 | 52 | |||
169 | 53 | static uint s_menuId = 0; | ||
170 | 54 | |||
171 | 55 | #define MENU_OBJECT_PATH "/com/ubuntu/Menu/%1" | ||
172 | 56 | |||
173 | 57 | } // namespace | ||
174 | 58 | |||
175 | 59 | |||
176 | 60 | UbuntuMenuBarExporter::UbuntuMenuBarExporter(UbuntuPlatformMenuBar * bar) | ||
177 | 61 | : UbuntuGMenuModelExporter(bar) | ||
178 | 62 | { | ||
179 | 63 | qCDebug(ubuntuappmenu, "UbuntuMenuBarExporter::UbuntuMenuBarExporter"); | ||
180 | 64 | |||
181 | 65 | connect(bar, &UbuntuPlatformMenuBar::structureChanged, this, [this]() { | ||
182 | 66 | m_structureTimer.start(); | ||
183 | 67 | }); | ||
184 | 68 | connect(&m_structureTimer, &QTimer::timeout, this, [this, bar]() { | ||
185 | 69 | clear(); | ||
186 | 70 | Q_FOREACH(QPlatformMenu *platformMenu, bar->menus()) { | ||
187 | 71 | GMenuItem* item = createSubmenu(platformMenu, nullptr); | ||
188 | 72 | if (item) { | ||
189 | 73 | g_menu_append_item(m_gmainMenu, item); | ||
190 | 74 | g_object_unref(item); | ||
191 | 75 | } | ||
192 | 76 | |||
193 | 77 | UbuntuPlatformMenu* gplatformMenu = static_cast<UbuntuPlatformMenu*>(platformMenu); | ||
194 | 78 | if (gplatformMenu) { | ||
195 | 79 | // Sadly we don't have a better way to propagate a enabled change in a top level menu | ||
196 | 80 | // than reseting the whole menubar | ||
197 | 81 | connect(gplatformMenu, &UbuntuPlatformMenu::enabledChanged, bar, &UbuntuPlatformMenuBar::structureChanged); | ||
198 | 82 | } | ||
199 | 83 | } | ||
200 | 84 | }); | ||
201 | 85 | |||
202 | 86 | connect(bar, &UbuntuPlatformMenuBar::ready, this, [this]() { | ||
203 | 87 | exportModels(); | ||
204 | 88 | }); | ||
205 | 89 | } | ||
206 | 90 | |||
207 | 91 | UbuntuMenuBarExporter::~UbuntuMenuBarExporter() | ||
208 | 92 | { | ||
209 | 93 | qCDebug(ubuntuappmenu, "UbuntuMenuBarExporter::~UbuntuMenuBarExporter"); | ||
210 | 94 | } | ||
211 | 95 | |||
212 | 96 | UbuntuMenuExporter::UbuntuMenuExporter(UbuntuPlatformMenu *menu) | ||
213 | 97 | : UbuntuGMenuModelExporter(menu) | ||
214 | 98 | { | ||
215 | 99 | qCDebug(ubuntuappmenu, "UbuntuMenuExporter::UbuntuMenuExporter"); | ||
216 | 100 | |||
217 | 101 | connect(menu, &UbuntuPlatformMenu::structureChanged, this, [this]() { | ||
218 | 102 | m_structureTimer.start(); | ||
219 | 103 | }); | ||
220 | 104 | connect(&m_structureTimer, &QTimer::timeout, this, [this, menu]() { | ||
221 | 105 | clear(); | ||
222 | 106 | addSubmenuItems(menu, m_gmainMenu); | ||
223 | 107 | }); | ||
224 | 108 | addSubmenuItems(menu, m_gmainMenu); | ||
225 | 109 | } | ||
226 | 110 | |||
227 | 111 | UbuntuMenuExporter::~UbuntuMenuExporter() | ||
228 | 112 | { | ||
229 | 113 | qCDebug(ubuntuappmenu, "UbuntuMenuExporter::~UbuntuMenuExporter"); | ||
230 | 114 | } | ||
231 | 115 | |||
232 | 116 | UbuntuGMenuModelExporter::UbuntuGMenuModelExporter(QObject *parent) | ||
233 | 117 | : QObject(parent) | ||
234 | 118 | , m_connection(nullptr) | ||
235 | 119 | , m_gmainMenu(g_menu_new()) | ||
236 | 120 | , m_gactionGroup(g_simple_action_group_new()) | ||
237 | 121 | , m_exportedModel(0) | ||
238 | 122 | , m_exportedActions(0) | ||
239 | 123 | , m_qtubuntuExtraHandler(nullptr) | ||
240 | 124 | , m_menuPath(QStringLiteral(MENU_OBJECT_PATH).arg(s_menuId++)) | ||
241 | 125 | { | ||
242 | 126 | m_structureTimer.setSingleShot(true); | ||
243 | 127 | m_structureTimer.setInterval(0); | ||
244 | 128 | } | ||
245 | 129 | |||
246 | 130 | UbuntuGMenuModelExporter::~UbuntuGMenuModelExporter() | ||
247 | 131 | { | ||
248 | 132 | unexportModels(); | ||
249 | 133 | clear(); | ||
250 | 134 | |||
251 | 135 | g_object_unref(m_gmainMenu); | ||
252 | 136 | g_object_unref(m_gactionGroup); | ||
253 | 137 | } | ||
254 | 138 | |||
255 | 139 | // Clear the menu and actions that have been created. | ||
256 | 140 | void UbuntuGMenuModelExporter::clear() | ||
257 | 141 | { | ||
258 | 142 | Q_FOREACH(const QVector<QMetaObject::Connection>& menuPropertyConnections, m_propertyConnections) { | ||
259 | 143 | Q_FOREACH(const QMetaObject::Connection& connection, menuPropertyConnections) { | ||
260 | 144 | QObject::disconnect(connection); | ||
261 | 145 | } | ||
262 | 146 | } | ||
263 | 147 | m_propertyConnections.clear(); | ||
264 | 148 | |||
265 | 149 | g_menu_remove_all(m_gmainMenu); | ||
266 | 150 | |||
267 | 151 | Q_FOREACH(const QSet<QByteArray>& menuActions, m_actions) { | ||
268 | 152 | Q_FOREACH(const QByteArray& action, menuActions) { | ||
269 | 153 | g_action_map_remove_action(G_ACTION_MAP(m_gactionGroup), action.constData()); | ||
270 | 154 | } | ||
271 | 155 | } | ||
272 | 156 | m_actions.clear(); | ||
273 | 157 | |||
274 | 158 | m_gmenusForMenus.clear(); | ||
275 | 159 | } | ||
276 | 160 | |||
277 | 161 | void UbuntuGMenuModelExporter::timerEvent(QTimerEvent *e) | ||
278 | 162 | { | ||
279 | 163 | // Find the menu, it's a very short list | ||
280 | 164 | auto it = m_reloadMenuTimers.begin(); | ||
281 | 165 | for (; it != m_reloadMenuTimers.end(); ++it) { | ||
282 | 166 | if (e->timerId() == it.value()) | ||
283 | 167 | break; | ||
284 | 168 | } | ||
285 | 169 | |||
286 | 170 | if (it != m_reloadMenuTimers.end()) { | ||
287 | 171 | UbuntuPlatformMenu* gplatformMenu = it.key(); | ||
288 | 172 | GMenu *menu = m_gmenusForMenus.value(gplatformMenu); | ||
289 | 173 | if (menu) { | ||
290 | 174 | Q_FOREACH(const QMetaObject::Connection& connection, m_propertyConnections[menu]) { | ||
291 | 175 | QObject::disconnect(connection); | ||
292 | 176 | } | ||
293 | 177 | m_propertyConnections.remove(menu); | ||
294 | 178 | Q_FOREACH(const QByteArray& action, m_actions[menu]) { | ||
295 | 179 | g_action_map_remove_action(G_ACTION_MAP(m_gactionGroup), action.constData()); | ||
296 | 180 | } | ||
297 | 181 | m_actions.remove(menu); | ||
298 | 182 | g_menu_remove_all(menu); | ||
299 | 183 | addSubmenuItems(gplatformMenu, menu); | ||
300 | 184 | } else { | ||
301 | 185 | qWarning() << "Got an update timer for a menu that has no GMenu" << gplatformMenu; | ||
302 | 186 | } | ||
303 | 187 | |||
304 | 188 | m_reloadMenuTimers.erase(it); | ||
305 | 189 | } else { | ||
306 | 190 | qWarning() << "Got an update timer for a timer that was not running"; | ||
307 | 191 | } | ||
308 | 192 | killTimer(e->timerId()); | ||
309 | 193 | } | ||
310 | 194 | |||
311 | 195 | // Export the model on dbus | ||
312 | 196 | void UbuntuGMenuModelExporter::exportModels() | ||
313 | 197 | { | ||
314 | 198 | GError *error = nullptr; | ||
315 | 199 | m_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, nullptr, &error); | ||
316 | 200 | if (!m_connection) { | ||
317 | 201 | qCWarning(ubuntuappmenu, "Failed to retreive session bus - %s", error ? error->message : "unknown error"); | ||
318 | 202 | g_error_free (error); | ||
319 | 203 | return; | ||
320 | 204 | } | ||
321 | 205 | |||
322 | 206 | QByteArray menuPath(m_menuPath.toUtf8()); | ||
323 | 207 | |||
324 | 208 | if (m_exportedModel == 0) { | ||
325 | 209 | m_exportedModel = g_dbus_connection_export_menu_model(m_connection, menuPath.constData(), G_MENU_MODEL(m_gmainMenu), &error); | ||
326 | 210 | if (m_exportedModel == 0) { | ||
327 | 211 | qCWarning(ubuntuappmenu, "Failed to export menu - %s", error ? error->message : "unknown error"); | ||
328 | 212 | g_error_free (error); | ||
329 | 213 | error = nullptr; | ||
330 | 214 | } else { | ||
331 | 215 | qCDebug(ubuntuappmenu, "Exported menu on %s", g_dbus_connection_get_unique_name(m_connection)); | ||
332 | 216 | } | ||
333 | 217 | } | ||
334 | 218 | |||
335 | 219 | if (m_exportedActions == 0) { | ||
336 | 220 | m_exportedActions = g_dbus_connection_export_action_group(m_connection, menuPath.constData(), G_ACTION_GROUP(m_gactionGroup), &error); | ||
337 | 221 | if (m_exportedActions == 0) { | ||
338 | 222 | qCWarning(ubuntuappmenu, "Failed to export actions - %s", error ? error->message : "unknown error"); | ||
339 | 223 | g_error_free (error); | ||
340 | 224 | error = nullptr; | ||
341 | 225 | } else { | ||
342 | 226 | qCDebug(ubuntuappmenu, "Exported actions on %s", g_dbus_connection_get_unique_name(m_connection)); | ||
343 | 227 | } | ||
344 | 228 | } | ||
345 | 229 | |||
346 | 230 | if (!m_qtubuntuExtraHandler) { | ||
347 | 231 | m_qtubuntuExtraHandler = new QtUbuntuExtraActionHandler(); | ||
348 | 232 | if (!m_qtubuntuExtraHandler->connect(m_connection, menuPath, this)) { | ||
349 | 233 | delete m_qtubuntuExtraHandler; | ||
350 | 234 | m_qtubuntuExtraHandler = nullptr; | ||
351 | 235 | } | ||
352 | 236 | } | ||
353 | 237 | } | ||
354 | 238 | |||
355 | 239 | void UbuntuGMenuModelExporter::aboutToShow(quint64 tag) | ||
356 | 240 | { | ||
357 | 241 | UbuntuPlatformMenu* gplatformMenu = m_submenusWithTag.value(tag); | ||
358 | 242 | if (!gplatformMenu) { | ||
359 | 243 | qWarning() << "Got an aboutToShow call with an unknown tag"; | ||
360 | 244 | return; | ||
361 | 245 | } | ||
362 | 246 | |||
363 | 247 | gplatformMenu->aboutToShow(); | ||
364 | 248 | } | ||
365 | 249 | |||
366 | 250 | // Unexport the model | ||
367 | 251 | void UbuntuGMenuModelExporter::unexportModels() | ||
368 | 252 | { | ||
369 | 253 | GError *error = nullptr; | ||
370 | 254 | if (!m_connection) { | ||
371 | 255 | qCWarning(ubuntuappmenu, "Failed to retreive session bus - %s", error ? error->message : "unknown error"); | ||
372 | 256 | return; | ||
373 | 257 | } | ||
374 | 258 | |||
375 | 259 | if (m_exportedModel != 0) { | ||
376 | 260 | g_dbus_connection_unexport_menu_model(m_connection, m_exportedModel); | ||
377 | 261 | m_exportedModel = 0; | ||
378 | 262 | } | ||
379 | 263 | if (m_exportedActions != 0) { | ||
380 | 264 | g_dbus_connection_unexport_action_group(m_connection, m_exportedActions); | ||
381 | 265 | m_exportedActions = 0; | ||
382 | 266 | } | ||
383 | 267 | if (m_qtubuntuExtraHandler) { | ||
384 | 268 | m_qtubuntuExtraHandler->disconnect(m_connection); | ||
385 | 269 | delete m_qtubuntuExtraHandler; | ||
386 | 270 | m_qtubuntuExtraHandler = nullptr; | ||
387 | 271 | } | ||
388 | 272 | g_object_unref(m_connection); | ||
389 | 273 | m_connection = nullptr; | ||
390 | 274 | } | ||
391 | 275 | |||
392 | 276 | // Create a submenu for the given platform menu. | ||
393 | 277 | // Returns a gmenuitem entry for the menu, which must be cleaned up using g_object_unref. | ||
394 | 278 | // If forItem is suplied, use it's label. | ||
395 | 279 | GMenuItem *UbuntuGMenuModelExporter::createSubmenu(QPlatformMenu *platformMenu, UbuntuPlatformMenuItem *forItem) | ||
396 | 280 | { | ||
397 | 281 | UbuntuPlatformMenu* gplatformMenu = static_cast<UbuntuPlatformMenu*>(platformMenu); | ||
398 | 282 | if (!gplatformMenu) return nullptr; | ||
399 | 283 | GMenu* menu = g_menu_new(); | ||
400 | 284 | |||
401 | 285 | m_gmenusForMenus.insert(gplatformMenu, menu); | ||
402 | 286 | |||
403 | 287 | QByteArray label; | ||
404 | 288 | bool enabled; | ||
405 | 289 | if (forItem) { | ||
406 | 290 | label = UbuntuPlatformMenuItem::get_text(forItem).toUtf8(); | ||
407 | 291 | enabled = UbuntuPlatformMenuItem::get_enabled(forItem); | ||
408 | 292 | } else { | ||
409 | 293 | label = UbuntuPlatformMenu::get_text(gplatformMenu).toUtf8(); | ||
410 | 294 | enabled = UbuntuPlatformMenu::get_enabled(gplatformMenu); | ||
411 | 295 | } | ||
412 | 296 | |||
413 | 297 | addSubmenuItems(gplatformMenu, menu); | ||
414 | 298 | |||
415 | 299 | Q_FOREACH(QPlatformMenuItem *childItem, gplatformMenu->menuItems()) { | ||
416 | 300 | UbuntuPlatformMenuItem* gplatformMenuItem = static_cast<UbuntuPlatformMenuItem*>(childItem); | ||
417 | 301 | if (!gplatformMenuItem) continue; | ||
418 | 302 | |||
419 | 303 | // Sadly we don't have a better way to propagate a enabled change in a item-that-is-submenu | ||
420 | 304 | // than reseting the whole parent menu | ||
421 | 305 | if (gplatformMenuItem->menu()) { | ||
422 | 306 | connect(gplatformMenuItem, &UbuntuPlatformMenuItem::enabledChanged, gplatformMenu, &UbuntuPlatformMenu::structureChanged); | ||
423 | 307 | } | ||
424 | 308 | connect(gplatformMenuItem, &UbuntuPlatformMenuItem::visibleChanged, gplatformMenu, &UbuntuPlatformMenu::structureChanged); | ||
425 | 309 | } | ||
426 | 310 | |||
427 | 311 | GMenuItem* gmenuItem = g_menu_item_new_submenu(label.constData(), G_MENU_MODEL(menu)); | ||
428 | 312 | const quint64 tag = gplatformMenu->tag(); | ||
429 | 313 | if (tag != 0) { | ||
430 | 314 | g_menu_item_set_attribute_value(gmenuItem, "qtubuntu-tag", g_variant_new_uint64 (tag)); | ||
431 | 315 | m_submenusWithTag.insert(gplatformMenu->tag(), gplatformMenu); | ||
432 | 316 | } | ||
433 | 317 | g_object_unref(menu); | ||
434 | 318 | |||
435 | 319 | g_menu_item_set_attribute_value(gmenuItem, "submenu-enabled", g_variant_new_boolean(enabled)); | ||
436 | 320 | |||
437 | 321 | connect(gplatformMenu, &UbuntuPlatformMenu::structureChanged, this, [this, gplatformMenu] | ||
438 | 322 | { | ||
439 | 323 | if (!m_reloadMenuTimers.contains(gplatformMenu)) { | ||
440 | 324 | const int timerId = startTimer(0); | ||
441 | 325 | m_reloadMenuTimers.insert(gplatformMenu, timerId); | ||
442 | 326 | } | ||
443 | 327 | }); | ||
444 | 328 | |||
445 | 329 | connect(gplatformMenu, &UbuntuPlatformMenu::destroyed, this, [this, tag, gplatformMenu] | ||
446 | 330 | { | ||
447 | 331 | m_submenusWithTag.remove(tag); | ||
448 | 332 | m_gmenusForMenus.remove(gplatformMenu); | ||
449 | 333 | auto timerIdIt = m_reloadMenuTimers.find(gplatformMenu); | ||
450 | 334 | if (timerIdIt != m_reloadMenuTimers.end()) { | ||
451 | 335 | killTimer(*timerIdIt); | ||
452 | 336 | m_reloadMenuTimers.erase(timerIdIt); | ||
453 | 337 | } | ||
454 | 338 | }); | ||
455 | 339 | |||
456 | 340 | return gmenuItem; | ||
457 | 341 | } | ||
458 | 342 | |||
459 | 343 | // Add a platform menu's items to the given gmenu. | ||
460 | 344 | // The items are inserted into menus sections, split by the menu separators. | ||
461 | 345 | void UbuntuGMenuModelExporter::addSubmenuItems(UbuntuPlatformMenu* gplatformMenu, GMenu* menu) | ||
462 | 346 | { | ||
463 | 347 | auto iter = gplatformMenu->menuItems().begin(); | ||
464 | 348 | auto lastSectionStart = iter; | ||
465 | 349 | // Iterate through all the menu items adding sections when a separator is found. | ||
466 | 350 | for (; iter != gplatformMenu->menuItems().end(); ++iter) { | ||
467 | 351 | UbuntuPlatformMenuItem* gplatformMenuItem = static_cast<UbuntuPlatformMenuItem*>(*iter); | ||
468 | 352 | if (!gplatformMenuItem) continue; | ||
469 | 353 | |||
470 | 354 | // don't add a section until we have separator | ||
471 | 355 | if (UbuntuPlatformMenuItem::get_separator(gplatformMenuItem)) { | ||
472 | 356 | if (lastSectionStart != gplatformMenu->menuItems().begin()) { | ||
473 | 357 | GMenuItem* section = createSection(lastSectionStart, iter); | ||
474 | 358 | g_menu_append_item(menu, section); | ||
475 | 359 | g_object_unref(section); | ||
476 | 360 | } | ||
477 | 361 | lastSectionStart = iter + 1; | ||
478 | 362 | } else if (lastSectionStart == gplatformMenu->menuItems().begin()) { | ||
479 | 363 | processItemForGMenu(gplatformMenuItem, menu); | ||
480 | 364 | } | ||
481 | 365 | } | ||
482 | 366 | |||
483 | 367 | // Add the last section | ||
484 | 368 | if (lastSectionStart != gplatformMenu->menuItems().begin() && | ||
485 | 369 | lastSectionStart != gplatformMenu->menuItems().end()) { | ||
486 | 370 | GMenuItem* gsectionItem = createSection(lastSectionStart, gplatformMenu->menuItems().end()); | ||
487 | 371 | g_menu_append_item(menu, gsectionItem); | ||
488 | 372 | g_object_unref(gsectionItem); | ||
489 | 373 | } | ||
490 | 374 | } | ||
491 | 375 | |||
492 | 376 | // Create and return a gmenu item for the given platform menu item. | ||
493 | 377 | // Returned GMenuItem must be cleaned up using g_object_unref | ||
494 | 378 | GMenuItem *UbuntuGMenuModelExporter::createMenuItem(QPlatformMenuItem *platformMenuItem, GMenu *parentMenu) | ||
495 | 379 | { | ||
496 | 380 | UbuntuPlatformMenuItem* gplatformMenuItem = static_cast<UbuntuPlatformMenuItem*>(platformMenuItem); | ||
497 | 381 | if (!gplatformMenuItem) return nullptr; | ||
498 | 382 | |||
499 | 383 | if (!UbuntuPlatformMenuItem::get_visible(gplatformMenuItem)) | ||
500 | 384 | return nullptr; | ||
501 | 385 | |||
502 | 386 | QByteArray label(UbuntuPlatformMenuItem::get_text(gplatformMenuItem).toUtf8()); | ||
503 | 387 | QByteArray actionLabel(getActionString(UbuntuPlatformMenuItem::get_text(gplatformMenuItem)).toUtf8()); | ||
504 | 388 | QByteArray shortcut(UbuntuPlatformMenuItem::get_shortcut(gplatformMenuItem).toString(QKeySequence::NativeText).toUtf8()); | ||
505 | 389 | |||
506 | 390 | GMenuItem* gmenuItem = g_menu_item_new(label.constData(), nullptr); | ||
507 | 391 | g_menu_item_set_attribute(gmenuItem, "accel", "s", shortcut.constData()); | ||
508 | 392 | g_menu_item_set_detailed_action(gmenuItem, ("unity." + actionLabel).constData()); | ||
509 | 393 | |||
510 | 394 | addAction(actionLabel, gplatformMenuItem, parentMenu); | ||
511 | 395 | return gmenuItem; | ||
512 | 396 | } | ||
513 | 397 | |||
514 | 398 | // Create a menu section for a section of separated menu items. | ||
515 | 399 | // Returned GMenuItem must be cleaned up using g_object_unref | ||
516 | 400 | GMenuItem *UbuntuGMenuModelExporter::createSection(QList<QPlatformMenuItem *>::const_iterator iter, QList<QPlatformMenuItem *>::const_iterator end) | ||
517 | 401 | { | ||
518 | 402 | GMenu* gsectionMenu = g_menu_new(); | ||
519 | 403 | for (; iter != end; ++iter) { | ||
520 | 404 | processItemForGMenu(*iter, gsectionMenu); | ||
521 | 405 | } | ||
522 | 406 | GMenuItem* gsectionItem = g_menu_item_new_section("", G_MENU_MODEL(gsectionMenu)); | ||
523 | 407 | g_object_unref(gsectionMenu); | ||
524 | 408 | return gsectionItem; | ||
525 | 409 | } | ||
526 | 410 | |||
527 | 411 | // Add the given platform menu item to the menu. | ||
528 | 412 | // If it has an attached submenu, then create and add the submenu. | ||
529 | 413 | void UbuntuGMenuModelExporter::processItemForGMenu(QPlatformMenuItem *platformMenuItem, GMenu *gmenu) | ||
530 | 414 | { | ||
531 | 415 | UbuntuPlatformMenuItem* gplatformMenuItem = static_cast<UbuntuPlatformMenuItem*>(platformMenuItem); | ||
532 | 416 | if (!gplatformMenuItem) return; | ||
533 | 417 | |||
534 | 418 | GMenuItem* gmenuItem = gplatformMenuItem->menu() ? createSubmenu(gplatformMenuItem->menu(), gplatformMenuItem) : | ||
535 | 419 | createMenuItem(gplatformMenuItem, gmenu); | ||
536 | 420 | if (gmenuItem) { | ||
537 | 421 | g_menu_append_item(gmenu, gmenuItem); | ||
538 | 422 | g_object_unref(gmenuItem); | ||
539 | 423 | } | ||
540 | 424 | } | ||
541 | 425 | |||
542 | 426 | // Create and add an action for a menu item. | ||
543 | 427 | void UbuntuGMenuModelExporter::addAction(const QByteArray &name, UbuntuPlatformMenuItem *gplatformMenuItem, GMenu *parentMenu) | ||
544 | 428 | { | ||
545 | 429 | disconnect(gplatformMenuItem, &UbuntuPlatformMenuItem::checkedChanged, this, 0); | ||
546 | 430 | disconnect(gplatformMenuItem, &UbuntuPlatformMenuItem::enabledChanged, this, 0); | ||
547 | 431 | |||
548 | 432 | QSet<QByteArray> &actions = m_actions[parentMenu]; | ||
549 | 433 | QVector<QMetaObject::Connection> &propertyConnections = m_propertyConnections[parentMenu]; | ||
550 | 434 | |||
551 | 435 | if (actions.contains(name)) { | ||
552 | 436 | g_action_map_remove_action(G_ACTION_MAP(m_gactionGroup), name.constData()); | ||
553 | 437 | actions.remove(name); | ||
554 | 438 | } | ||
555 | 439 | |||
556 | 440 | bool checkable = UbuntuPlatformMenuItem::get_checkable(gplatformMenuItem); | ||
557 | 441 | |||
558 | 442 | GSimpleAction* action = nullptr; | ||
559 | 443 | if (checkable) { | ||
560 | 444 | bool checked = UbuntuPlatformMenuItem::get_checked(gplatformMenuItem); | ||
561 | 445 | action = g_simple_action_new_stateful(name.constData(), nullptr, g_variant_new_boolean(checked)); | ||
562 | 446 | |||
563 | 447 | std::function<void(bool)> updateChecked = [gplatformMenuItem, action](bool checked) { | ||
564 | 448 | auto type = g_action_get_state_type(G_ACTION(action)); | ||
565 | 449 | if (type && g_variant_type_equal(type, G_VARIANT_TYPE_BOOLEAN)) { | ||
566 | 450 | g_simple_action_set_state(action, g_variant_new_boolean(checked ? TRUE : FALSE)); | ||
567 | 451 | } | ||
568 | 452 | }; | ||
569 | 453 | // save the connection to disconnect in UbuntuGMenuModelExporter::clear() | ||
570 | 454 | propertyConnections << connect(gplatformMenuItem, &UbuntuPlatformMenuItem::checkedChanged, this, updateChecked); | ||
571 | 455 | } else { | ||
572 | 456 | action = g_simple_action_new(name.constData(), nullptr); | ||
573 | 457 | } | ||
574 | 458 | |||
575 | 459 | // Enabled update | ||
576 | 460 | std::function<void(bool)> updateEnabled = [gplatformMenuItem, action](bool enabled) { | ||
577 | 461 | GValue value = G_VALUE_INIT; | ||
578 | 462 | g_value_init (&value, G_TYPE_BOOLEAN); | ||
579 | 463 | g_value_set_boolean(&value, enabled ? TRUE : FALSE); | ||
580 | 464 | g_object_set_property(G_OBJECT(action), "enabled", &value); | ||
581 | 465 | }; | ||
582 | 466 | updateEnabled(UbuntuPlatformMenuItem::get_enabled(gplatformMenuItem)); | ||
583 | 467 | // save the connection to disconnect in UbuntuGMenuModelExporter::clear() | ||
584 | 468 | propertyConnections << connect(gplatformMenuItem, &UbuntuPlatformMenuItem::enabledChanged, this, updateEnabled); | ||
585 | 469 | |||
586 | 470 | g_signal_connect(action, "activate", G_CALLBACK(activate_cb), gplatformMenuItem); | ||
587 | 471 | |||
588 | 472 | actions.insert(name); | ||
589 | 473 | g_action_map_add_action(G_ACTION_MAP(m_gactionGroup), G_ACTION(action)); | ||
590 | 474 | g_object_unref(action); | ||
591 | 475 | } | ||
592 | 476 | 0 | ||
593 | === removed file 'src/ubuntuappmenu/gmenumodelexporter.h' | |||
594 | --- src/ubuntuappmenu/gmenumodelexporter.h 2017-03-15 08:47:51 +0000 | |||
595 | +++ src/ubuntuappmenu/gmenumodelexporter.h 1970-01-01 00:00:00 +0000 | |||
596 | @@ -1,100 +0,0 @@ | |||
597 | 1 | /* | ||
598 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
599 | 3 | * | ||
600 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
601 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
602 | 6 | * the Free Software Foundation. | ||
603 | 7 | * | ||
604 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
605 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
606 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
607 | 11 | * Lesser General Public License for more details. | ||
608 | 12 | * | ||
609 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
610 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
611 | 15 | */ | ||
612 | 16 | |||
613 | 17 | #ifndef GMENUMODELEXPORTER_H | ||
614 | 18 | #define GMENUMODELEXPORTER_H | ||
615 | 19 | |||
616 | 20 | #include "gmenumodelplatformmenu.h" | ||
617 | 21 | |||
618 | 22 | #include <gio/gio.h> | ||
619 | 23 | |||
620 | 24 | #include <QTimer> | ||
621 | 25 | #include <QMap> | ||
622 | 26 | #include <QSet> | ||
623 | 27 | #include <QMetaObject> | ||
624 | 28 | |||
625 | 29 | class QtUbuntuExtraActionHandler; | ||
626 | 30 | |||
627 | 31 | // Base class for a gmenumodel exporter | ||
628 | 32 | class UbuntuGMenuModelExporter : public QObject | ||
629 | 33 | { | ||
630 | 34 | Q_OBJECT | ||
631 | 35 | public: | ||
632 | 36 | virtual ~UbuntuGMenuModelExporter(); | ||
633 | 37 | |||
634 | 38 | void exportModels(); | ||
635 | 39 | void unexportModels(); | ||
636 | 40 | |||
637 | 41 | QString menuPath() const { return m_menuPath;} | ||
638 | 42 | |||
639 | 43 | void aboutToShow(quint64 tag); | ||
640 | 44 | |||
641 | 45 | protected: | ||
642 | 46 | UbuntuGMenuModelExporter(QObject *parent); | ||
643 | 47 | |||
644 | 48 | GMenuItem *createSubmenu(QPlatformMenu* platformMenu, UbuntuPlatformMenuItem* forItem); | ||
645 | 49 | GMenuItem *createMenuItem(QPlatformMenuItem* platformMenuItem, GMenu *parentMenu); | ||
646 | 50 | GMenuItem *createSection(QList<QPlatformMenuItem*>::const_iterator iter, QList<QPlatformMenuItem*>::const_iterator end); | ||
647 | 51 | void addAction(const QByteArray& name, UbuntuPlatformMenuItem* gplatformItem, GMenu *parentMenu); | ||
648 | 52 | |||
649 | 53 | void addSubmenuItems(UbuntuPlatformMenu* gplatformMenu, GMenu* menu); | ||
650 | 54 | void processItemForGMenu(QPlatformMenuItem* item, GMenu* gmenu); | ||
651 | 55 | |||
652 | 56 | void clear(); | ||
653 | 57 | |||
654 | 58 | void timerEvent(QTimerEvent *e) override; | ||
655 | 59 | |||
656 | 60 | protected: | ||
657 | 61 | GDBusConnection *m_connection; | ||
658 | 62 | GMenu *m_gmainMenu; | ||
659 | 63 | GSimpleActionGroup *m_gactionGroup; | ||
660 | 64 | guint m_exportedModel; | ||
661 | 65 | guint m_exportedActions; | ||
662 | 66 | QtUbuntuExtraActionHandler *m_qtubuntuExtraHandler; | ||
663 | 67 | QTimer m_structureTimer; | ||
664 | 68 | QString m_menuPath; | ||
665 | 69 | |||
666 | 70 | // UbuntuPlatformMenu::tag -> UbuntuPlatformMenu | ||
667 | 71 | QMap<quint64, UbuntuPlatformMenu*> m_submenusWithTag; | ||
668 | 72 | |||
669 | 73 | // UbuntuPlatformMenu -> reload TimerId (startTimer) | ||
670 | 74 | QHash<UbuntuPlatformMenu*, int> m_reloadMenuTimers; | ||
671 | 75 | |||
672 | 76 | QHash<UbuntuPlatformMenu*, GMenu*> m_gmenusForMenus; | ||
673 | 77 | |||
674 | 78 | QHash<GMenu*, QSet<QByteArray>> m_actions; | ||
675 | 79 | QHash<GMenu*, QVector<QMetaObject::Connection>> m_propertyConnections; | ||
676 | 80 | |||
677 | 81 | }; | ||
678 | 82 | |||
679 | 83 | // Class which exports a qt platform menu bar. | ||
680 | 84 | class UbuntuMenuBarExporter : public UbuntuGMenuModelExporter | ||
681 | 85 | { | ||
682 | 86 | public: | ||
683 | 87 | UbuntuMenuBarExporter(UbuntuPlatformMenuBar *parent); | ||
684 | 88 | ~UbuntuMenuBarExporter(); | ||
685 | 89 | }; | ||
686 | 90 | |||
687 | 91 | // Class which exports a qt platform menu. | ||
688 | 92 | // This will allow exporting of context menus. | ||
689 | 93 | class UbuntuMenuExporter : public UbuntuGMenuModelExporter | ||
690 | 94 | { | ||
691 | 95 | public: | ||
692 | 96 | UbuntuMenuExporter(UbuntuPlatformMenu *parent); | ||
693 | 97 | ~UbuntuMenuExporter(); | ||
694 | 98 | }; | ||
695 | 99 | |||
696 | 100 | #endif // GMENUMODELEXPORTER_H | ||
697 | 101 | 0 | ||
698 | === removed file 'src/ubuntuappmenu/gmenumodelplatformmenu.cpp' | |||
699 | --- src/ubuntuappmenu/gmenumodelplatformmenu.cpp 2017-03-27 08:23:00 +0000 | |||
700 | +++ src/ubuntuappmenu/gmenumodelplatformmenu.cpp 1970-01-01 00:00:00 +0000 | |||
701 | @@ -1,518 +0,0 @@ | |||
702 | 1 | /* | ||
703 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
704 | 3 | * | ||
705 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
706 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
707 | 6 | * the Free Software Foundation. | ||
708 | 7 | * | ||
709 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
710 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
711 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
712 | 11 | * Lesser General Public License for more details. | ||
713 | 12 | * | ||
714 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
715 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
716 | 15 | */ | ||
717 | 16 | |||
718 | 17 | // Local | ||
719 | 18 | #include "gmenumodelplatformmenu.h" | ||
720 | 19 | #include "gmenumodelexporter.h" | ||
721 | 20 | #include "registry.h" | ||
722 | 21 | #include "menuregistrar.h" | ||
723 | 22 | #include "logging.h" | ||
724 | 23 | |||
725 | 24 | // Qt | ||
726 | 25 | #include <QDebug> | ||
727 | 26 | #include <QWindow> | ||
728 | 27 | #include <QCoreApplication> | ||
729 | 28 | |||
730 | 29 | #define BAR_DEBUG_MSG qCDebug(ubuntuappmenu).nospace() << "UbuntuPlatformMenuBar[" << (void*)this <<"]::" << __func__ | ||
731 | 30 | #define MENU_DEBUG_MSG qCDebug(ubuntuappmenu).nospace() << "UbuntuPlatformMenu[" << (void*)this <<"]::" << __func__ | ||
732 | 31 | #define ITEM_DEBUG_MSG qCDebug(ubuntuappmenu).nospace() << "UbuntuPlatformMenuItem[" << (void*)this <<"]::" << __func__ | ||
733 | 32 | |||
734 | 33 | namespace { | ||
735 | 34 | |||
736 | 35 | int logRecusion = 0; | ||
737 | 36 | |||
738 | 37 | } | ||
739 | 38 | |||
740 | 39 | QDebug operator<<(QDebug stream, UbuntuPlatformMenuBar* bar) { | ||
741 | 40 | if (bar) return bar->operator<<(stream); | ||
742 | 41 | return stream; | ||
743 | 42 | } | ||
744 | 43 | QDebug operator<<(QDebug stream, UbuntuPlatformMenu* menu) { | ||
745 | 44 | if (menu) return menu->operator<<(stream); | ||
746 | 45 | return stream; | ||
747 | 46 | } | ||
748 | 47 | QDebug operator<<(QDebug stream, UbuntuPlatformMenuItem* menuItem) { | ||
749 | 48 | if (menuItem) return menuItem->operator<<(stream); | ||
750 | 49 | return stream; | ||
751 | 50 | } | ||
752 | 51 | |||
753 | 52 | UbuntuPlatformMenuBar::UbuntuPlatformMenuBar() | ||
754 | 53 | : m_exporter(new UbuntuMenuBarExporter(this)) | ||
755 | 54 | , m_registrar(new UbuntuMenuRegistrar()) | ||
756 | 55 | , m_ready(false) | ||
757 | 56 | { | ||
758 | 57 | BAR_DEBUG_MSG << "()"; | ||
759 | 58 | |||
760 | 59 | connect(this, &UbuntuPlatformMenuBar::menuInserted, this, &UbuntuPlatformMenuBar::structureChanged); | ||
761 | 60 | connect(this,&UbuntuPlatformMenuBar::menuRemoved, this, &UbuntuPlatformMenuBar::structureChanged); | ||
762 | 61 | } | ||
763 | 62 | |||
764 | 63 | UbuntuPlatformMenuBar::~UbuntuPlatformMenuBar() | ||
765 | 64 | { | ||
766 | 65 | BAR_DEBUG_MSG << "()"; | ||
767 | 66 | } | ||
768 | 67 | |||
769 | 68 | void UbuntuPlatformMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before) | ||
770 | 69 | { | ||
771 | 70 | BAR_DEBUG_MSG << "(menu=" << menu << ", before=" << before << ")"; | ||
772 | 71 | |||
773 | 72 | if (m_menus.contains(menu)) return; | ||
774 | 73 | |||
775 | 74 | if (!before) { | ||
776 | 75 | m_menus.push_back(menu); | ||
777 | 76 | } else { | ||
778 | 77 | for (auto iter = m_menus.begin(); iter != m_menus.end(); ++iter) { | ||
779 | 78 | if (*iter == before) { | ||
780 | 79 | m_menus.insert(iter, menu); | ||
781 | 80 | break; | ||
782 | 81 | } | ||
783 | 82 | } | ||
784 | 83 | } | ||
785 | 84 | Q_EMIT menuInserted(menu); | ||
786 | 85 | } | ||
787 | 86 | |||
788 | 87 | void UbuntuPlatformMenuBar::removeMenu(QPlatformMenu *menu) | ||
789 | 88 | { | ||
790 | 89 | BAR_DEBUG_MSG << "(menu=" << menu << ")"; | ||
791 | 90 | |||
792 | 91 | QMutableListIterator<QPlatformMenu*> iterator(m_menus); | ||
793 | 92 | while(iterator.hasNext()) { | ||
794 | 93 | if (iterator.next() == menu) { | ||
795 | 94 | iterator.remove(); | ||
796 | 95 | break; | ||
797 | 96 | } | ||
798 | 97 | } | ||
799 | 98 | Q_EMIT menuRemoved(menu); | ||
800 | 99 | } | ||
801 | 100 | |||
802 | 101 | void UbuntuPlatformMenuBar::syncMenu(QPlatformMenu *menu) | ||
803 | 102 | { | ||
804 | 103 | BAR_DEBUG_MSG << "(menu=" << menu << ")"; | ||
805 | 104 | |||
806 | 105 | Q_UNUSED(menu) | ||
807 | 106 | } | ||
808 | 107 | |||
809 | 108 | void UbuntuPlatformMenuBar::handleReparent(QWindow *parentWindow) | ||
810 | 109 | { | ||
811 | 110 | BAR_DEBUG_MSG << "(parentWindow=" << parentWindow << ")"; | ||
812 | 111 | |||
813 | 112 | setReady(true); | ||
814 | 113 | m_registrar->registerMenuForWindow(parentWindow, QDBusObjectPath(m_exporter->menuPath())); | ||
815 | 114 | } | ||
816 | 115 | |||
817 | 116 | QPlatformMenu *UbuntuPlatformMenuBar::menuForTag(quintptr tag) const | ||
818 | 117 | { | ||
819 | 118 | Q_FOREACH(QPlatformMenu* menu, m_menus) { | ||
820 | 119 | if (menu->tag() == tag) { | ||
821 | 120 | return menu; | ||
822 | 121 | } | ||
823 | 122 | } | ||
824 | 123 | return nullptr; | ||
825 | 124 | } | ||
826 | 125 | |||
827 | 126 | const QList<QPlatformMenu *> UbuntuPlatformMenuBar::menus() const | ||
828 | 127 | { | ||
829 | 128 | return m_menus; | ||
830 | 129 | } | ||
831 | 130 | |||
832 | 131 | QDebug UbuntuPlatformMenuBar::operator<<(QDebug stream) | ||
833 | 132 | { | ||
834 | 133 | stream.nospace().noquote() << QString("%1").arg("", logRecusion, QLatin1Char('\t')) | ||
835 | 134 | << "UbuntuPlatformMenuBar(this=" << (void*)this << ")" << endl; | ||
836 | 135 | Q_FOREACH(QPlatformMenu* menu, m_menus) { | ||
837 | 136 | auto myMenu = static_cast<UbuntuPlatformMenu*>(menu); | ||
838 | 137 | if (myMenu) { | ||
839 | 138 | logRecusion++; | ||
840 | 139 | stream << myMenu; | ||
841 | 140 | logRecusion--; | ||
842 | 141 | } | ||
843 | 142 | } | ||
844 | 143 | |||
845 | 144 | return stream; | ||
846 | 145 | } | ||
847 | 146 | |||
848 | 147 | #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
849 | 148 | QPlatformMenu *UbuntuPlatformMenuBar::createMenu() const | ||
850 | 149 | { | ||
851 | 150 | return new UbuntuPlatformMenu(); | ||
852 | 151 | } | ||
853 | 152 | #endif | ||
854 | 153 | |||
855 | 154 | void UbuntuPlatformMenuBar::setReady(bool isReady) | ||
856 | 155 | { | ||
857 | 156 | if (m_ready != isReady) { | ||
858 | 157 | m_ready = isReady; | ||
859 | 158 | Q_EMIT ready(); | ||
860 | 159 | } | ||
861 | 160 | } | ||
862 | 161 | |||
863 | 162 | ////////////////////////////////////////////////////////////// | ||
864 | 163 | |||
865 | 164 | UbuntuPlatformMenu::UbuntuPlatformMenu() | ||
866 | 165 | : m_tag(reinterpret_cast<quintptr>(this)) | ||
867 | 166 | , m_parentWindow(nullptr) | ||
868 | 167 | , m_exporter(nullptr) | ||
869 | 168 | , m_registrar(nullptr) | ||
870 | 169 | { | ||
871 | 170 | MENU_DEBUG_MSG << "()"; | ||
872 | 171 | |||
873 | 172 | connect(this, &UbuntuPlatformMenu::menuItemInserted, this, &UbuntuPlatformMenu::structureChanged); | ||
874 | 173 | connect(this, &UbuntuPlatformMenu::menuItemRemoved, this, &UbuntuPlatformMenu::structureChanged); | ||
875 | 174 | } | ||
876 | 175 | |||
877 | 176 | UbuntuPlatformMenu::~UbuntuPlatformMenu() | ||
878 | 177 | { | ||
879 | 178 | MENU_DEBUG_MSG << "()"; | ||
880 | 179 | } | ||
881 | 180 | |||
882 | 181 | void UbuntuPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) | ||
883 | 182 | { | ||
884 | 183 | MENU_DEBUG_MSG << "(menuItem=" << menuItem << ", before=" << before << ")"; | ||
885 | 184 | |||
886 | 185 | if (m_menuItems.contains(menuItem)) return; | ||
887 | 186 | |||
888 | 187 | if (!before) { | ||
889 | 188 | m_menuItems.push_back(menuItem); | ||
890 | 189 | } else { | ||
891 | 190 | for (auto iter = m_menuItems.begin(); iter != m_menuItems.end(); ++iter) { | ||
892 | 191 | if (*iter == before) { | ||
893 | 192 | m_menuItems.insert(iter, menuItem); | ||
894 | 193 | break; | ||
895 | 194 | } | ||
896 | 195 | } | ||
897 | 196 | } | ||
898 | 197 | |||
899 | 198 | Q_EMIT menuItemInserted(menuItem); | ||
900 | 199 | } | ||
901 | 200 | |||
902 | 201 | void UbuntuPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) | ||
903 | 202 | { | ||
904 | 203 | MENU_DEBUG_MSG << "(menuItem=" << menuItem << ")"; | ||
905 | 204 | |||
906 | 205 | QMutableListIterator<QPlatformMenuItem*> iterator(m_menuItems); | ||
907 | 206 | while(iterator.hasNext()) { | ||
908 | 207 | if (iterator.next() == menuItem) { | ||
909 | 208 | iterator.remove(); | ||
910 | 209 | break; | ||
911 | 210 | } | ||
912 | 211 | } | ||
913 | 212 | Q_EMIT menuItemRemoved(menuItem); | ||
914 | 213 | } | ||
915 | 214 | |||
916 | 215 | void UbuntuPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) | ||
917 | 216 | { | ||
918 | 217 | MENU_DEBUG_MSG << "(menuItem=" << menuItem << ")"; | ||
919 | 218 | |||
920 | 219 | Q_UNUSED(menuItem) | ||
921 | 220 | } | ||
922 | 221 | |||
923 | 222 | void UbuntuPlatformMenu::syncSeparatorsCollapsible(bool enable) | ||
924 | 223 | { | ||
925 | 224 | MENU_DEBUG_MSG << "(enable=" << enable << ")"; | ||
926 | 225 | Q_UNUSED(enable) | ||
927 | 226 | } | ||
928 | 227 | |||
929 | 228 | void UbuntuPlatformMenu::setTag(quintptr tag) | ||
930 | 229 | { | ||
931 | 230 | MENU_DEBUG_MSG << "(tag=" << tag << ")"; | ||
932 | 231 | m_tag = tag; | ||
933 | 232 | } | ||
934 | 233 | |||
935 | 234 | quintptr UbuntuPlatformMenu::tag() const | ||
936 | 235 | { | ||
937 | 236 | return m_tag; | ||
938 | 237 | } | ||
939 | 238 | |||
940 | 239 | void UbuntuPlatformMenu::setText(const QString &text) | ||
941 | 240 | { | ||
942 | 241 | MENU_DEBUG_MSG << "(text=" << text << ")"; | ||
943 | 242 | if (m_text != text) { | ||
944 | 243 | m_text = text; | ||
945 | 244 | } | ||
946 | 245 | } | ||
947 | 246 | |||
948 | 247 | void UbuntuPlatformMenu::setIcon(const QIcon &icon) | ||
949 | 248 | { | ||
950 | 249 | MENU_DEBUG_MSG << "(icon=" << icon.name() << ")"; | ||
951 | 250 | |||
952 | 251 | if (!icon.isNull() || (!m_icon.isNull() && icon.isNull())) { | ||
953 | 252 | m_icon = icon; | ||
954 | 253 | } | ||
955 | 254 | } | ||
956 | 255 | |||
957 | 256 | void UbuntuPlatformMenu::setEnabled(bool enabled) | ||
958 | 257 | { | ||
959 | 258 | MENU_DEBUG_MSG << "(enabled=" << enabled << ")"; | ||
960 | 259 | |||
961 | 260 | if (m_enabled != enabled) { | ||
962 | 261 | m_enabled = enabled; | ||
963 | 262 | Q_EMIT enabledChanged(enabled); | ||
964 | 263 | } | ||
965 | 264 | } | ||
966 | 265 | |||
967 | 266 | void UbuntuPlatformMenu::setVisible(bool isVisible) | ||
968 | 267 | { | ||
969 | 268 | MENU_DEBUG_MSG << "(visible=" << isVisible << ")"; | ||
970 | 269 | |||
971 | 270 | if (m_visible != isVisible) { | ||
972 | 271 | m_visible = isVisible; | ||
973 | 272 | } | ||
974 | 273 | } | ||
975 | 274 | |||
976 | 275 | void UbuntuPlatformMenu::setMinimumWidth(int width) | ||
977 | 276 | { | ||
978 | 277 | MENU_DEBUG_MSG << "(width=" << width << ")"; | ||
979 | 278 | |||
980 | 279 | Q_UNUSED(width) | ||
981 | 280 | } | ||
982 | 281 | |||
983 | 282 | void UbuntuPlatformMenu::setFont(const QFont &font) | ||
984 | 283 | { | ||
985 | 284 | MENU_DEBUG_MSG << "(font=" << font << ")"; | ||
986 | 285 | |||
987 | 286 | Q_UNUSED(font) | ||
988 | 287 | } | ||
989 | 288 | |||
990 | 289 | void UbuntuPlatformMenu::showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) | ||
991 | 290 | { | ||
992 | 291 | MENU_DEBUG_MSG << "(parentWindow=" << parentWindow << ", targetRect=" << targetRect << ", item=" << item << ")"; | ||
993 | 292 | |||
994 | 293 | if (!m_exporter) { | ||
995 | 294 | m_exporter.reset(new UbuntuMenuExporter(this)); | ||
996 | 295 | m_exporter->exportModels(); | ||
997 | 296 | } | ||
998 | 297 | |||
999 | 298 | if (parentWindow != m_parentWindow) { | ||
1000 | 299 | if (m_parentWindow) { | ||
1001 | 300 | m_registrar->unregisterMenu(); | ||
1002 | 301 | } | ||
1003 | 302 | |||
1004 | 303 | m_parentWindow = parentWindow; | ||
1005 | 304 | |||
1006 | 305 | if (m_parentWindow) { | ||
1007 | 306 | if (!m_registrar) m_registrar.reset(new UbuntuMenuRegistrar); | ||
1008 | 307 | m_registrar->registerMenuForWindow(const_cast<QWindow*>(m_parentWindow), | ||
1009 | 308 | QDBusObjectPath(m_exporter->menuPath())); | ||
1010 | 309 | } | ||
1011 | 310 | } | ||
1012 | 311 | |||
1013 | 312 | Q_UNUSED(targetRect); | ||
1014 | 313 | Q_UNUSED(item); | ||
1015 | 314 | setVisible(true); | ||
1016 | 315 | } | ||
1017 | 316 | |||
1018 | 317 | void UbuntuPlatformMenu::dismiss() | ||
1019 | 318 | { | ||
1020 | 319 | MENU_DEBUG_MSG << "()"; | ||
1021 | 320 | |||
1022 | 321 | if (m_registrar) { m_registrar->unregisterMenu(); } | ||
1023 | 322 | if (m_exporter) { m_exporter->unexportModels(); } | ||
1024 | 323 | } | ||
1025 | 324 | |||
1026 | 325 | QPlatformMenuItem *UbuntuPlatformMenu::menuItemAt(int position) const | ||
1027 | 326 | { | ||
1028 | 327 | if (position < 0 || position >= m_menuItems.count()) return nullptr; | ||
1029 | 328 | return m_menuItems.at(position); | ||
1030 | 329 | } | ||
1031 | 330 | |||
1032 | 331 | QPlatformMenuItem *UbuntuPlatformMenu::menuItemForTag(quintptr tag) const | ||
1033 | 332 | { | ||
1034 | 333 | Q_FOREACH(QPlatformMenuItem* menuItem, m_menuItems) { | ||
1035 | 334 | if (menuItem->tag() == tag) { | ||
1036 | 335 | return menuItem; | ||
1037 | 336 | } | ||
1038 | 337 | } | ||
1039 | 338 | return nullptr; | ||
1040 | 339 | } | ||
1041 | 340 | |||
1042 | 341 | QPlatformMenuItem *UbuntuPlatformMenu::createMenuItem() const | ||
1043 | 342 | { | ||
1044 | 343 | return new UbuntuPlatformMenuItem(); | ||
1045 | 344 | } | ||
1046 | 345 | |||
1047 | 346 | #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
1048 | 347 | QPlatformMenu *UbuntuPlatformMenu::createSubMenu() const | ||
1049 | 348 | { | ||
1050 | 349 | return new UbuntuPlatformMenu(); | ||
1051 | 350 | } | ||
1052 | 351 | #endif | ||
1053 | 352 | |||
1054 | 353 | const QList<QPlatformMenuItem *> UbuntuPlatformMenu::menuItems() const | ||
1055 | 354 | { | ||
1056 | 355 | return m_menuItems; | ||
1057 | 356 | } | ||
1058 | 357 | |||
1059 | 358 | QDebug UbuntuPlatformMenu::operator<<(QDebug stream) | ||
1060 | 359 | { | ||
1061 | 360 | stream.nospace().noquote() << QString("%1").arg("", logRecusion, QLatin1Char('\t')) | ||
1062 | 361 | << "UbuntuPlatformMenu(this=" << (void*)this << ", text=\"" << m_text << "\")" << endl; | ||
1063 | 362 | Q_FOREACH(QPlatformMenuItem* item, m_menuItems) { | ||
1064 | 363 | logRecusion++; | ||
1065 | 364 | auto myItem = static_cast<UbuntuPlatformMenuItem*>(item); | ||
1066 | 365 | if (myItem) { | ||
1067 | 366 | stream << myItem; | ||
1068 | 367 | } | ||
1069 | 368 | logRecusion--; | ||
1070 | 369 | } | ||
1071 | 370 | return stream; | ||
1072 | 371 | } | ||
1073 | 372 | |||
1074 | 373 | ////////////////////////////////////////////////////////////// | ||
1075 | 374 | |||
1076 | 375 | UbuntuPlatformMenuItem::UbuntuPlatformMenuItem() | ||
1077 | 376 | : m_menu(nullptr) | ||
1078 | 377 | , m_tag(reinterpret_cast<quintptr>(this)) | ||
1079 | 378 | { | ||
1080 | 379 | ITEM_DEBUG_MSG << "()"; | ||
1081 | 380 | } | ||
1082 | 381 | |||
1083 | 382 | UbuntuPlatformMenuItem::~UbuntuPlatformMenuItem() | ||
1084 | 383 | { | ||
1085 | 384 | ITEM_DEBUG_MSG << "()"; | ||
1086 | 385 | } | ||
1087 | 386 | |||
1088 | 387 | void UbuntuPlatformMenuItem::setTag(quintptr tag) | ||
1089 | 388 | { | ||
1090 | 389 | ITEM_DEBUG_MSG << "(tag=" << tag << ")"; | ||
1091 | 390 | m_tag = tag; | ||
1092 | 391 | } | ||
1093 | 392 | |||
1094 | 393 | quintptr UbuntuPlatformMenuItem::tag() const | ||
1095 | 394 | { | ||
1096 | 395 | return m_tag; | ||
1097 | 396 | } | ||
1098 | 397 | |||
1099 | 398 | void UbuntuPlatformMenuItem::setText(const QString &text) | ||
1100 | 399 | { | ||
1101 | 400 | ITEM_DEBUG_MSG << "(text=" << text << ")"; | ||
1102 | 401 | if (m_text != text) { | ||
1103 | 402 | m_text = text; | ||
1104 | 403 | } | ||
1105 | 404 | } | ||
1106 | 405 | |||
1107 | 406 | void UbuntuPlatformMenuItem::setIcon(const QIcon &icon) | ||
1108 | 407 | { | ||
1109 | 408 | ITEM_DEBUG_MSG << "(icon=" << icon.name() << ")"; | ||
1110 | 409 | |||
1111 | 410 | if (!icon.isNull() || (!m_icon.isNull() && icon.isNull())) { | ||
1112 | 411 | m_icon = icon; | ||
1113 | 412 | } | ||
1114 | 413 | } | ||
1115 | 414 | |||
1116 | 415 | void UbuntuPlatformMenuItem::setVisible(bool isVisible) | ||
1117 | 416 | { | ||
1118 | 417 | ITEM_DEBUG_MSG << "(visible=" << isVisible << ")"; | ||
1119 | 418 | if (m_visible != isVisible) { | ||
1120 | 419 | m_visible = isVisible; | ||
1121 | 420 | Q_EMIT visibleChanged(m_visible); | ||
1122 | 421 | } | ||
1123 | 422 | } | ||
1124 | 423 | |||
1125 | 424 | void UbuntuPlatformMenuItem::setIsSeparator(bool isSeparator) | ||
1126 | 425 | { | ||
1127 | 426 | ITEM_DEBUG_MSG << "(separator=" << isSeparator << ")"; | ||
1128 | 427 | if (m_separator != isSeparator) { | ||
1129 | 428 | m_separator = isSeparator; | ||
1130 | 429 | } | ||
1131 | 430 | } | ||
1132 | 431 | |||
1133 | 432 | void UbuntuPlatformMenuItem::setFont(const QFont &font) | ||
1134 | 433 | { | ||
1135 | 434 | ITEM_DEBUG_MSG << "(font=" << font << ")"; | ||
1136 | 435 | Q_UNUSED(font); | ||
1137 | 436 | } | ||
1138 | 437 | |||
1139 | 438 | void UbuntuPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role) | ||
1140 | 439 | { | ||
1141 | 440 | ITEM_DEBUG_MSG << "(role=" << role << ")"; | ||
1142 | 441 | Q_UNUSED(role); | ||
1143 | 442 | } | ||
1144 | 443 | |||
1145 | 444 | void UbuntuPlatformMenuItem::setCheckable(bool checkable) | ||
1146 | 445 | { | ||
1147 | 446 | ITEM_DEBUG_MSG << "(checkable=" << checkable << ")"; | ||
1148 | 447 | if (m_checkable != checkable) { | ||
1149 | 448 | m_checkable = checkable; | ||
1150 | 449 | } | ||
1151 | 450 | } | ||
1152 | 451 | |||
1153 | 452 | void UbuntuPlatformMenuItem::setChecked(bool isChecked) | ||
1154 | 453 | { | ||
1155 | 454 | ITEM_DEBUG_MSG << "(checked=" << isChecked << ")"; | ||
1156 | 455 | if (m_checked != isChecked) { | ||
1157 | 456 | m_checked = isChecked; | ||
1158 | 457 | Q_EMIT checkedChanged(isChecked); | ||
1159 | 458 | } | ||
1160 | 459 | } | ||
1161 | 460 | |||
1162 | 461 | void UbuntuPlatformMenuItem::setShortcut(const QKeySequence &shortcut) | ||
1163 | 462 | { | ||
1164 | 463 | ITEM_DEBUG_MSG << "(shortcut=" << shortcut << ")"; | ||
1165 | 464 | if (m_shortcut != shortcut) { | ||
1166 | 465 | m_shortcut = shortcut; | ||
1167 | 466 | } | ||
1168 | 467 | } | ||
1169 | 468 | |||
1170 | 469 | void UbuntuPlatformMenuItem::setEnabled(bool enabled) | ||
1171 | 470 | { | ||
1172 | 471 | ITEM_DEBUG_MSG << "(enabled=" << enabled << ")"; | ||
1173 | 472 | if (m_enabled != enabled) { | ||
1174 | 473 | m_enabled = enabled; | ||
1175 | 474 | Q_EMIT enabledChanged(enabled); | ||
1176 | 475 | } | ||
1177 | 476 | } | ||
1178 | 477 | |||
1179 | 478 | void UbuntuPlatformMenuItem::setIconSize(int size) | ||
1180 | 479 | { | ||
1181 | 480 | ITEM_DEBUG_MSG << "(size=" << size << ")"; | ||
1182 | 481 | Q_UNUSED(size); | ||
1183 | 482 | } | ||
1184 | 483 | |||
1185 | 484 | void UbuntuPlatformMenuItem::setMenu(QPlatformMenu *menu) | ||
1186 | 485 | { | ||
1187 | 486 | ITEM_DEBUG_MSG << "(menu=" << menu << ")"; | ||
1188 | 487 | if (m_menu != menu) { | ||
1189 | 488 | m_menu = menu; | ||
1190 | 489 | |||
1191 | 490 | if (menu) { | ||
1192 | 491 | connect(menu, &QObject::destroyed, | ||
1193 | 492 | this, [this] { setMenu(nullptr); }); | ||
1194 | 493 | } | ||
1195 | 494 | } | ||
1196 | 495 | } | ||
1197 | 496 | |||
1198 | 497 | QPlatformMenu *UbuntuPlatformMenuItem::menu() const | ||
1199 | 498 | { | ||
1200 | 499 | return m_menu; | ||
1201 | 500 | } | ||
1202 | 501 | |||
1203 | 502 | QDebug UbuntuPlatformMenuItem::operator<<(QDebug stream) | ||
1204 | 503 | { | ||
1205 | 504 | QString properties = "text=\"" + m_text + "\""; | ||
1206 | 505 | |||
1207 | 506 | stream.nospace().noquote() << QString("%1").arg("", logRecusion, QLatin1Char('\t')) | ||
1208 | 507 | << "UbuntuPlatformMenuItem(this=" << (void*)this << ", " | ||
1209 | 508 | << (m_separator ? "Separator" : properties) << ")" << endl; | ||
1210 | 509 | if (m_menu) { | ||
1211 | 510 | auto myMenu = static_cast<UbuntuPlatformMenu*>(m_menu); | ||
1212 | 511 | if (myMenu) { | ||
1213 | 512 | logRecusion++; | ||
1214 | 513 | stream << myMenu; | ||
1215 | 514 | logRecusion--; | ||
1216 | 515 | } | ||
1217 | 516 | } | ||
1218 | 517 | return stream; | ||
1219 | 518 | } | ||
1220 | 519 | 0 | ||
1221 | === removed file 'src/ubuntuappmenu/gmenumodelplatformmenu.h' | |||
1222 | --- src/ubuntuappmenu/gmenumodelplatformmenu.h 2017-03-27 08:23:00 +0000 | |||
1223 | +++ src/ubuntuappmenu/gmenumodelplatformmenu.h 1970-01-01 00:00:00 +0000 | |||
1224 | @@ -1,181 +0,0 @@ | |||
1225 | 1 | /* | ||
1226 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1227 | 3 | * | ||
1228 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1229 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1230 | 6 | * the Free Software Foundation. | ||
1231 | 7 | * | ||
1232 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1233 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1234 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1235 | 11 | * Lesser General Public License for more details. | ||
1236 | 12 | * | ||
1237 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1238 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1239 | 15 | */ | ||
1240 | 16 | |||
1241 | 17 | #ifndef EXPORTEDPLATFORMMENUBAR_H | ||
1242 | 18 | #define EXPORTEDPLATFORMMENUBAR_H | ||
1243 | 19 | |||
1244 | 20 | #include <qpa/qplatformmenu.h> | ||
1245 | 21 | |||
1246 | 22 | // Local | ||
1247 | 23 | class UbuntuGMenuModelExporter; | ||
1248 | 24 | class UbuntuMenuRegistrar; | ||
1249 | 25 | class QWindow; | ||
1250 | 26 | |||
1251 | 27 | class UbuntuPlatformMenuBar : public QPlatformMenuBar | ||
1252 | 28 | { | ||
1253 | 29 | Q_OBJECT | ||
1254 | 30 | public: | ||
1255 | 31 | UbuntuPlatformMenuBar(); | ||
1256 | 32 | ~UbuntuPlatformMenuBar(); | ||
1257 | 33 | |||
1258 | 34 | QString exportedPath() const; | ||
1259 | 35 | |||
1260 | 36 | virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu* before) override; | ||
1261 | 37 | virtual void removeMenu(QPlatformMenu *menu) override; | ||
1262 | 38 | virtual void syncMenu(QPlatformMenu *menu) override; | ||
1263 | 39 | virtual void handleReparent(QWindow *newParentWindow) override; | ||
1264 | 40 | virtual QPlatformMenu *menuForTag(quintptr tag) const override; | ||
1265 | 41 | |||
1266 | 42 | const QList<QPlatformMenu*> menus() const; | ||
1267 | 43 | |||
1268 | 44 | QDebug operator<<(QDebug stream); | ||
1269 | 45 | |||
1270 | 46 | #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
1271 | 47 | virtual QPlatformMenu *createMenu() const override; | ||
1272 | 48 | #endif | ||
1273 | 49 | |||
1274 | 50 | Q_SIGNALS: | ||
1275 | 51 | void menuInserted(QPlatformMenu *menu); | ||
1276 | 52 | void menuRemoved(QPlatformMenu *menu); | ||
1277 | 53 | |||
1278 | 54 | void structureChanged(); | ||
1279 | 55 | void ready(); | ||
1280 | 56 | |||
1281 | 57 | private: | ||
1282 | 58 | void setReady(bool); | ||
1283 | 59 | |||
1284 | 60 | QList<QPlatformMenu*> m_menus; | ||
1285 | 61 | QScopedPointer<UbuntuGMenuModelExporter> m_exporter; | ||
1286 | 62 | QScopedPointer<UbuntuMenuRegistrar> m_registrar; | ||
1287 | 63 | bool m_ready; | ||
1288 | 64 | }; | ||
1289 | 65 | |||
1290 | 66 | #define MENU_PROPERTY(class, name, type, defaultValue) \ | ||
1291 | 67 | static type get_##name(const class *menuItem) { return menuItem->m_##name; } \ | ||
1292 | 68 | type m_##name = defaultValue; | ||
1293 | 69 | |||
1294 | 70 | class Q_DECL_EXPORT UbuntuPlatformMenu : public QPlatformMenu | ||
1295 | 71 | { | ||
1296 | 72 | Q_OBJECT | ||
1297 | 73 | public: | ||
1298 | 74 | UbuntuPlatformMenu(); | ||
1299 | 75 | ~UbuntuPlatformMenu(); | ||
1300 | 76 | |||
1301 | 77 | virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override; | ||
1302 | 78 | virtual void removeMenuItem(QPlatformMenuItem *menuItem) override; | ||
1303 | 79 | virtual void syncMenuItem(QPlatformMenuItem *menuItem) override; | ||
1304 | 80 | virtual void syncSeparatorsCollapsible(bool enable) override; | ||
1305 | 81 | |||
1306 | 82 | virtual void setTag(quintptr tag) override; | ||
1307 | 83 | virtual quintptr tag() const override; | ||
1308 | 84 | |||
1309 | 85 | virtual void setText(const QString &text) override; | ||
1310 | 86 | virtual void setIcon(const QIcon &icon) override; | ||
1311 | 87 | virtual void setEnabled(bool isEnabled) override; | ||
1312 | 88 | virtual void setVisible(bool isVisible) override; | ||
1313 | 89 | virtual void setMinimumWidth(int width) override; | ||
1314 | 90 | virtual void setFont(const QFont &font) override; | ||
1315 | 91 | |||
1316 | 92 | virtual void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override; | ||
1317 | 93 | |||
1318 | 94 | virtual void dismiss() override; // Closes this and all its related menu popups | ||
1319 | 95 | |||
1320 | 96 | virtual QPlatformMenuItem *menuItemAt(int position) const override; | ||
1321 | 97 | virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const override; | ||
1322 | 98 | |||
1323 | 99 | virtual QPlatformMenuItem *createMenuItem() const override; | ||
1324 | 100 | #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
1325 | 101 | virtual QPlatformMenu *createSubMenu() const override; | ||
1326 | 102 | #endif | ||
1327 | 103 | |||
1328 | 104 | int id() const; | ||
1329 | 105 | |||
1330 | 106 | const QList<QPlatformMenuItem*> menuItems() const; | ||
1331 | 107 | |||
1332 | 108 | QDebug operator<<(QDebug stream); | ||
1333 | 109 | |||
1334 | 110 | Q_SIGNALS: | ||
1335 | 111 | void menuItemInserted(QPlatformMenuItem *menuItem); | ||
1336 | 112 | void menuItemRemoved(QPlatformMenuItem *menuItem); | ||
1337 | 113 | void structureChanged(); | ||
1338 | 114 | void enabledChanged(bool); | ||
1339 | 115 | |||
1340 | 116 | private: | ||
1341 | 117 | MENU_PROPERTY(UbuntuPlatformMenu, visible, bool, true) | ||
1342 | 118 | MENU_PROPERTY(UbuntuPlatformMenu, text, QString, QString()) | ||
1343 | 119 | MENU_PROPERTY(UbuntuPlatformMenu, enabled, bool, true) | ||
1344 | 120 | MENU_PROPERTY(UbuntuPlatformMenu, icon, QIcon, QIcon()) | ||
1345 | 121 | |||
1346 | 122 | quintptr m_tag; | ||
1347 | 123 | QList<QPlatformMenuItem*> m_menuItems; | ||
1348 | 124 | const QWindow* m_parentWindow; | ||
1349 | 125 | QScopedPointer<UbuntuGMenuModelExporter> m_exporter; | ||
1350 | 126 | QScopedPointer<UbuntuMenuRegistrar> m_registrar; | ||
1351 | 127 | |||
1352 | 128 | friend class UbuntuGMenuModelExporter; | ||
1353 | 129 | }; | ||
1354 | 130 | |||
1355 | 131 | |||
1356 | 132 | class Q_DECL_EXPORT UbuntuPlatformMenuItem : public QPlatformMenuItem | ||
1357 | 133 | { | ||
1358 | 134 | Q_OBJECT | ||
1359 | 135 | public: | ||
1360 | 136 | UbuntuPlatformMenuItem(); | ||
1361 | 137 | ~UbuntuPlatformMenuItem(); | ||
1362 | 138 | |||
1363 | 139 | virtual void setTag(quintptr tag) override; | ||
1364 | 140 | virtual quintptr tag() const override; | ||
1365 | 141 | |||
1366 | 142 | virtual void setText(const QString &text) override; | ||
1367 | 143 | virtual void setIcon(const QIcon &icon) override; | ||
1368 | 144 | virtual void setMenu(QPlatformMenu *menu) override; | ||
1369 | 145 | virtual void setVisible(bool isVisible) override; | ||
1370 | 146 | virtual void setIsSeparator(bool isSeparator) override; | ||
1371 | 147 | virtual void setFont(const QFont &font) override; | ||
1372 | 148 | virtual void setRole(MenuRole role) override; | ||
1373 | 149 | virtual void setCheckable(bool checkable) override; | ||
1374 | 150 | virtual void setChecked(bool isChecked) override; | ||
1375 | 151 | virtual void setShortcut(const QKeySequence& shortcut) override; | ||
1376 | 152 | virtual void setEnabled(bool enabled) override; | ||
1377 | 153 | virtual void setIconSize(int size) override; | ||
1378 | 154 | |||
1379 | 155 | QPlatformMenu* menu() const; | ||
1380 | 156 | |||
1381 | 157 | QDebug operator<<(QDebug stream); | ||
1382 | 158 | |||
1383 | 159 | Q_SIGNALS: | ||
1384 | 160 | void checkedChanged(bool); | ||
1385 | 161 | void enabledChanged(bool); | ||
1386 | 162 | void visibleChanged(bool); | ||
1387 | 163 | |||
1388 | 164 | private: | ||
1389 | 165 | MENU_PROPERTY(UbuntuPlatformMenuItem, separator, bool, false) | ||
1390 | 166 | MENU_PROPERTY(UbuntuPlatformMenuItem, visible, bool, true) | ||
1391 | 167 | MENU_PROPERTY(UbuntuPlatformMenuItem, text, QString, QString()) | ||
1392 | 168 | MENU_PROPERTY(UbuntuPlatformMenuItem, enabled, bool, true) | ||
1393 | 169 | MENU_PROPERTY(UbuntuPlatformMenuItem, checkable, bool, false) | ||
1394 | 170 | MENU_PROPERTY(UbuntuPlatformMenuItem, checked, bool, false) | ||
1395 | 171 | MENU_PROPERTY(UbuntuPlatformMenuItem, shortcut, QKeySequence, QKeySequence()) | ||
1396 | 172 | MENU_PROPERTY(UbuntuPlatformMenuItem, icon, QIcon, QIcon()) | ||
1397 | 173 | MENU_PROPERTY(UbuntuPlatformMenuItem, iconSize, int, 16) | ||
1398 | 174 | MENU_PROPERTY(UbuntuPlatformMenuItem, menu, QPlatformMenu*, nullptr) | ||
1399 | 175 | |||
1400 | 176 | |||
1401 | 177 | quintptr m_tag; | ||
1402 | 178 | friend class UbuntuGMenuModelExporter; | ||
1403 | 179 | }; | ||
1404 | 180 | |||
1405 | 181 | #endif // EXPORTEDPLATFORMMENUBAR_H | ||
1406 | 182 | 0 | ||
1407 | === removed file 'src/ubuntuappmenu/logging.h' | |||
1408 | --- src/ubuntuappmenu/logging.h 2016-08-24 10:08:05 +0000 | |||
1409 | +++ src/ubuntuappmenu/logging.h 1970-01-01 00:00:00 +0000 | |||
1410 | @@ -1,27 +0,0 @@ | |||
1411 | 1 | /* | ||
1412 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1413 | 3 | * | ||
1414 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1415 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1416 | 6 | * the Free Software Foundation. | ||
1417 | 7 | * | ||
1418 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1419 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1420 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1421 | 11 | * Lesser General Public License for more details. | ||
1422 | 12 | * | ||
1423 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1424 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1425 | 15 | */ | ||
1426 | 16 | |||
1427 | 17 | #ifndef QUBUNTUTHEMELOGGING_H | ||
1428 | 18 | #define QUBUNTUTHEMELOGGING_H | ||
1429 | 19 | |||
1430 | 20 | #include <QLoggingCategory> | ||
1431 | 21 | |||
1432 | 22 | #define ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop()) | ||
1433 | 23 | |||
1434 | 24 | Q_DECLARE_LOGGING_CATEGORY(ubuntuappmenu) | ||
1435 | 25 | Q_DECLARE_LOGGING_CATEGORY(ubuntuappmenuRegistrar) | ||
1436 | 26 | |||
1437 | 27 | #endif // QUBUNTUTHEMELOGGING_H | ||
1438 | 28 | 0 | ||
1439 | === removed file 'src/ubuntuappmenu/menuregistrar.cpp' | |||
1440 | --- src/ubuntuappmenu/menuregistrar.cpp 2016-09-30 16:10:35 +0000 | |||
1441 | +++ src/ubuntuappmenu/menuregistrar.cpp 1970-01-01 00:00:00 +0000 | |||
1442 | @@ -1,137 +0,0 @@ | |||
1443 | 1 | /* | ||
1444 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1445 | 3 | * | ||
1446 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1447 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1448 | 6 | * the Free Software Foundation. | ||
1449 | 7 | * | ||
1450 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1451 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1452 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1453 | 11 | * Lesser General Public License for more details. | ||
1454 | 12 | * | ||
1455 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1456 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1457 | 15 | */ | ||
1458 | 16 | |||
1459 | 17 | #include "menuregistrar.h" | ||
1460 | 18 | #include "registry.h" | ||
1461 | 19 | #include "logging.h" | ||
1462 | 20 | |||
1463 | 21 | #include <QDebug> | ||
1464 | 22 | #include <QDBusObjectPath> | ||
1465 | 23 | #include <QGuiApplication> | ||
1466 | 24 | #include <qpa/qplatformnativeinterface.h> | ||
1467 | 25 | #include <qpa/qplatformwindow.h> | ||
1468 | 26 | |||
1469 | 27 | namespace { | ||
1470 | 28 | |||
1471 | 29 | bool isMirClient() { | ||
1472 | 30 | return qGuiApp->platformName() == "ubuntumirclient"; | ||
1473 | 31 | } | ||
1474 | 32 | |||
1475 | 33 | } | ||
1476 | 34 | |||
1477 | 35 | UbuntuMenuRegistrar::UbuntuMenuRegistrar() | ||
1478 | 36 | : m_connection(nullptr) | ||
1479 | 37 | , m_registeredProcessId(~0) | ||
1480 | 38 | { | ||
1481 | 39 | GError *error = NULL; | ||
1482 | 40 | m_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); | ||
1483 | 41 | if (!m_connection) { | ||
1484 | 42 | qCWarning(ubuntuappmenuRegistrar, "Failed to retreive session bus - %s", error ? error->message : "unknown error"); | ||
1485 | 43 | g_error_free (error); | ||
1486 | 44 | return; | ||
1487 | 45 | } | ||
1488 | 46 | m_service = g_dbus_connection_get_unique_name(m_connection); | ||
1489 | 47 | connect(UbuntuMenuRegistry::instance(), &UbuntuMenuRegistry::serviceChanged, this, &UbuntuMenuRegistrar::onRegistrarServiceChanged); | ||
1490 | 48 | |||
1491 | 49 | if (isMirClient()) { | ||
1492 | 50 | auto nativeInterface = qGuiApp->platformNativeInterface(); | ||
1493 | 51 | connect(nativeInterface, &QPlatformNativeInterface::windowPropertyChanged, this, [this](QPlatformWindow* window, const QString &property) { | ||
1494 | 52 | if (property != QStringLiteral("persistentSurfaceId")) { | ||
1495 | 53 | return; | ||
1496 | 54 | } | ||
1497 | 55 | if (window->window() == m_window) { | ||
1498 | 56 | registerMenuForWindow(m_window, m_path); | ||
1499 | 57 | } | ||
1500 | 58 | }); | ||
1501 | 59 | } | ||
1502 | 60 | } | ||
1503 | 61 | |||
1504 | 62 | UbuntuMenuRegistrar::~UbuntuMenuRegistrar() | ||
1505 | 63 | { | ||
1506 | 64 | if (m_connection) { | ||
1507 | 65 | g_object_unref(m_connection); | ||
1508 | 66 | } | ||
1509 | 67 | unregisterMenu(); | ||
1510 | 68 | } | ||
1511 | 69 | |||
1512 | 70 | void UbuntuMenuRegistrar::registerMenuForWindow(QWindow* window, const QDBusObjectPath& path) | ||
1513 | 71 | { | ||
1514 | 72 | unregisterMenu(); | ||
1515 | 73 | |||
1516 | 74 | m_window = window; | ||
1517 | 75 | m_path = path; | ||
1518 | 76 | |||
1519 | 77 | registerMenu(); | ||
1520 | 78 | } | ||
1521 | 79 | |||
1522 | 80 | void UbuntuMenuRegistrar::registerMenu() | ||
1523 | 81 | { | ||
1524 | 82 | if (UbuntuMenuRegistry::instance()->isConnected() && m_window) { | ||
1525 | 83 | if (isMirClient()) { | ||
1526 | 84 | registerSurfaceMenu(); | ||
1527 | 85 | } else { | ||
1528 | 86 | registerApplicationMenu(); | ||
1529 | 87 | } | ||
1530 | 88 | } | ||
1531 | 89 | } | ||
1532 | 90 | |||
1533 | 91 | void UbuntuMenuRegistrar::unregisterMenu() | ||
1534 | 92 | { | ||
1535 | 93 | if (!m_registeredSurfaceId.isEmpty()) { | ||
1536 | 94 | unregisterSurfaceMenu(); | ||
1537 | 95 | } else if (m_registeredProcessId != ~0) { | ||
1538 | 96 | unregisterApplicationMenu(); | ||
1539 | 97 | } | ||
1540 | 98 | } | ||
1541 | 99 | |||
1542 | 100 | void UbuntuMenuRegistrar::registerSurfaceMenu() | ||
1543 | 101 | { | ||
1544 | 102 | auto nativeInterface = qGuiApp->platformNativeInterface(); | ||
1545 | 103 | QByteArray persistentSurfaceId = nativeInterface->windowProperty(m_window->handle(), "persistentSurfaceId", QByteArray()).toByteArray(); | ||
1546 | 104 | if (persistentSurfaceId.isEmpty()) return; | ||
1547 | 105 | |||
1548 | 106 | UbuntuMenuRegistry::instance()->registerSurfaceMenu(persistentSurfaceId, m_path, m_service); | ||
1549 | 107 | m_registeredSurfaceId = persistentSurfaceId; | ||
1550 | 108 | } | ||
1551 | 109 | |||
1552 | 110 | void UbuntuMenuRegistrar::unregisterSurfaceMenu() | ||
1553 | 111 | { | ||
1554 | 112 | if (UbuntuMenuRegistry::instance()->isConnected()) { | ||
1555 | 113 | UbuntuMenuRegistry::instance()->unregisterSurfaceMenu(m_registeredSurfaceId, m_path); | ||
1556 | 114 | } | ||
1557 | 115 | m_registeredSurfaceId.clear(); | ||
1558 | 116 | } | ||
1559 | 117 | |||
1560 | 118 | void UbuntuMenuRegistrar::registerApplicationMenu() | ||
1561 | 119 | { | ||
1562 | 120 | pid_t pid = getpid(); | ||
1563 | 121 | UbuntuMenuRegistry::instance()->registerApplicationMenu(pid, m_path, m_service); | ||
1564 | 122 | m_registeredProcessId = pid; | ||
1565 | 123 | } | ||
1566 | 124 | |||
1567 | 125 | void UbuntuMenuRegistrar::unregisterApplicationMenu() | ||
1568 | 126 | { | ||
1569 | 127 | if (UbuntuMenuRegistry::instance()->isConnected()) { | ||
1570 | 128 | UbuntuMenuRegistry::instance()->unregisterApplicationMenu(m_registeredProcessId, m_path); | ||
1571 | 129 | } | ||
1572 | 130 | m_registeredProcessId = ~0; | ||
1573 | 131 | } | ||
1574 | 132 | |||
1575 | 133 | void UbuntuMenuRegistrar::onRegistrarServiceChanged() | ||
1576 | 134 | { | ||
1577 | 135 | unregisterMenu(); | ||
1578 | 136 | registerMenu(); | ||
1579 | 137 | } | ||
1580 | 138 | 0 | ||
1581 | === removed file 'src/ubuntuappmenu/menuregistrar.h' | |||
1582 | --- src/ubuntuappmenu/menuregistrar.h 2016-09-30 08:35:16 +0000 | |||
1583 | +++ src/ubuntuappmenu/menuregistrar.h 1970-01-01 00:00:00 +0000 | |||
1584 | @@ -1,59 +0,0 @@ | |||
1585 | 1 | /* | ||
1586 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1587 | 3 | * | ||
1588 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1589 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1590 | 6 | * the Free Software Foundation. | ||
1591 | 7 | * | ||
1592 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1593 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1594 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1595 | 11 | * Lesser General Public License for more details. | ||
1596 | 12 | * | ||
1597 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1598 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1599 | 15 | */ | ||
1600 | 16 | |||
1601 | 17 | #ifndef MENUREGISTRAR_H | ||
1602 | 18 | #define MENUREGISTRAR_H | ||
1603 | 19 | |||
1604 | 20 | #include <QObject> | ||
1605 | 21 | #include <QWindow> | ||
1606 | 22 | #include <QPointer> | ||
1607 | 23 | #include <QDBusObjectPath> | ||
1608 | 24 | |||
1609 | 25 | #include <gio/gio.h> | ||
1610 | 26 | |||
1611 | 27 | class UbuntuMenuRegistrar : public QObject | ||
1612 | 28 | { | ||
1613 | 29 | Q_OBJECT | ||
1614 | 30 | public: | ||
1615 | 31 | UbuntuMenuRegistrar(); | ||
1616 | 32 | ~UbuntuMenuRegistrar(); | ||
1617 | 33 | |||
1618 | 34 | void registerMenuForWindow(QWindow* window, const QDBusObjectPath& path); | ||
1619 | 35 | void unregisterMenu(); | ||
1620 | 36 | |||
1621 | 37 | private Q_SLOTS: | ||
1622 | 38 | void registerSurfaceMenu(); | ||
1623 | 39 | void onRegistrarServiceChanged(); | ||
1624 | 40 | |||
1625 | 41 | private: | ||
1626 | 42 | void registerMenu(); | ||
1627 | 43 | |||
1628 | 44 | void registerApplicationMenu(); | ||
1629 | 45 | void unregisterApplicationMenu(); | ||
1630 | 46 | |||
1631 | 47 | void unregisterSurfaceMenu(); | ||
1632 | 48 | |||
1633 | 49 | GDBusConnection *m_connection; | ||
1634 | 50 | QString m_service; | ||
1635 | 51 | QDBusObjectPath m_path; | ||
1636 | 52 | QPointer<QWindow> m_window; | ||
1637 | 53 | QString m_registeredSurfaceId; | ||
1638 | 54 | pid_t m_registeredProcessId; | ||
1639 | 55 | }; | ||
1640 | 56 | |||
1641 | 57 | |||
1642 | 58 | #endif // MENUREGISTRAR_H | ||
1643 | 59 | |||
1644 | 60 | 0 | ||
1645 | === removed file 'src/ubuntuappmenu/qtubuntuextraactionhandler.cpp' | |||
1646 | --- src/ubuntuappmenu/qtubuntuextraactionhandler.cpp 2017-03-16 09:42:27 +0000 | |||
1647 | +++ src/ubuntuappmenu/qtubuntuextraactionhandler.cpp 1970-01-01 00:00:00 +0000 | |||
1648 | @@ -1,107 +0,0 @@ | |||
1649 | 1 | /* | ||
1650 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1651 | 3 | * | ||
1652 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1653 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1654 | 6 | * the Free Software Foundation. | ||
1655 | 7 | * | ||
1656 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1657 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1658 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1659 | 11 | * Lesser General Public License for more details. | ||
1660 | 12 | * | ||
1661 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1662 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1663 | 15 | */ | ||
1664 | 16 | |||
1665 | 17 | #include "qtubuntuextraactionhandler.h" | ||
1666 | 18 | |||
1667 | 19 | #include "gmenumodelexporter.h" | ||
1668 | 20 | #include "logging.h" | ||
1669 | 21 | |||
1670 | 22 | static const gchar introspection_xml[] = | ||
1671 | 23 | "<node>" | ||
1672 | 24 | " <interface name='qtubuntu.actions.extra'>" | ||
1673 | 25 | " <method name='aboutToShow'>" | ||
1674 | 26 | " <arg type='t' name='tag' direction='in'/>" | ||
1675 | 27 | " </method>" | ||
1676 | 28 | " </interface>" | ||
1677 | 29 | "</node>"; | ||
1678 | 30 | |||
1679 | 31 | static void handle_method_call (GDBusConnection *, | ||
1680 | 32 | const gchar *, | ||
1681 | 33 | const gchar *, | ||
1682 | 34 | const gchar *, | ||
1683 | 35 | const gchar *method_name, | ||
1684 | 36 | GVariant *parameters, | ||
1685 | 37 | GDBusMethodInvocation *invocation, | ||
1686 | 38 | gpointer user_data) | ||
1687 | 39 | { | ||
1688 | 40 | |||
1689 | 41 | if (g_strcmp0 (method_name, "aboutToShow") == 0) | ||
1690 | 42 | { | ||
1691 | 43 | if (g_variant_check_format_string(parameters, "(t)", false)) { | ||
1692 | 44 | auto obj = static_cast<UbuntuGMenuModelExporter*>(user_data); | ||
1693 | 45 | guint64 tag; | ||
1694 | 46 | |||
1695 | 47 | g_variant_get (parameters, "(t)", &tag); | ||
1696 | 48 | obj->aboutToShow(tag); | ||
1697 | 49 | } | ||
1698 | 50 | |||
1699 | 51 | g_dbus_method_invocation_return_value (invocation, NULL); | ||
1700 | 52 | } else { | ||
1701 | 53 | g_dbus_method_invocation_return_error(invocation, | ||
1702 | 54 | G_DBUS_ERROR, | ||
1703 | 55 | G_DBUS_ERROR_UNKNOWN_METHOD, | ||
1704 | 56 | "Unknown method"); | ||
1705 | 57 | } | ||
1706 | 58 | } | ||
1707 | 59 | |||
1708 | 60 | |||
1709 | 61 | static const GDBusInterfaceVTable interface_vtable = | ||
1710 | 62 | { | ||
1711 | 63 | handle_method_call, | ||
1712 | 64 | NULL, | ||
1713 | 65 | NULL, | ||
1714 | 66 | NULL | ||
1715 | 67 | }; | ||
1716 | 68 | |||
1717 | 69 | QtUbuntuExtraActionHandler::QtUbuntuExtraActionHandler() | ||
1718 | 70 | : m_registration_id(0) | ||
1719 | 71 | { | ||
1720 | 72 | m_introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); | ||
1721 | 73 | } | ||
1722 | 74 | |||
1723 | 75 | QtUbuntuExtraActionHandler::~QtUbuntuExtraActionHandler() | ||
1724 | 76 | { | ||
1725 | 77 | g_clear_pointer(&m_introspection_data, g_dbus_node_info_unref); | ||
1726 | 78 | } | ||
1727 | 79 | |||
1728 | 80 | bool QtUbuntuExtraActionHandler::connect(GDBusConnection *connection, const QByteArray &menuPath, UbuntuGMenuModelExporter *gmenuexporter) | ||
1729 | 81 | { | ||
1730 | 82 | if (m_registration_id != 0) { | ||
1731 | 83 | qCWarning(ubuntuappmenu, "Called connect in an already connected QtUbuntuExtraActionHandler"); | ||
1732 | 84 | return false; | ||
1733 | 85 | } | ||
1734 | 86 | |||
1735 | 87 | GError *error = nullptr; | ||
1736 | 88 | m_registration_id = g_dbus_connection_register_object (connection, menuPath.constData(), | ||
1737 | 89 | m_introspection_data->interfaces[0], | ||
1738 | 90 | &interface_vtable, | ||
1739 | 91 | gmenuexporter, | ||
1740 | 92 | nullptr, | ||
1741 | 93 | &error); | ||
1742 | 94 | |||
1743 | 95 | if (!m_registration_id) { | ||
1744 | 96 | qCWarning(ubuntuappmenu, "Failed to extra actions - %s", error ? error->message : "unknown error"); | ||
1745 | 97 | g_clear_error(&error); | ||
1746 | 98 | } | ||
1747 | 99 | |||
1748 | 100 | return m_registration_id != 0; | ||
1749 | 101 | } | ||
1750 | 102 | |||
1751 | 103 | void QtUbuntuExtraActionHandler::disconnect(GDBusConnection *connection) { | ||
1752 | 104 | if (m_registration_id) { | ||
1753 | 105 | g_dbus_connection_unregister_object (connection, m_registration_id); | ||
1754 | 106 | } | ||
1755 | 107 | } | ||
1756 | 108 | 0 | ||
1757 | === removed file 'src/ubuntuappmenu/qtubuntuextraactionhandler.h' | |||
1758 | --- src/ubuntuappmenu/qtubuntuextraactionhandler.h 2017-03-06 16:19:29 +0000 | |||
1759 | +++ src/ubuntuappmenu/qtubuntuextraactionhandler.h 1970-01-01 00:00:00 +0000 | |||
1760 | @@ -1,40 +0,0 @@ | |||
1761 | 1 | /* | ||
1762 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1763 | 3 | * | ||
1764 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1765 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1766 | 6 | * the Free Software Foundation. | ||
1767 | 7 | * | ||
1768 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1769 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1770 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1771 | 11 | * Lesser General Public License for more details. | ||
1772 | 12 | * | ||
1773 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1774 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1775 | 15 | */ | ||
1776 | 16 | |||
1777 | 17 | #ifndef QTUBUNTUEXTRAACTIONHANDLER_H | ||
1778 | 18 | #define QTUBUNTUEXTRAACTIONHANDLER_H | ||
1779 | 19 | |||
1780 | 20 | #include <gio/gio.h> | ||
1781 | 21 | |||
1782 | 22 | class QByteArray; | ||
1783 | 23 | |||
1784 | 24 | class UbuntuGMenuModelExporter; | ||
1785 | 25 | |||
1786 | 26 | class QtUbuntuExtraActionHandler | ||
1787 | 27 | { | ||
1788 | 28 | public: | ||
1789 | 29 | QtUbuntuExtraActionHandler(); | ||
1790 | 30 | ~QtUbuntuExtraActionHandler(); | ||
1791 | 31 | |||
1792 | 32 | bool connect(GDBusConnection *connection, const QByteArray &menuPath, UbuntuGMenuModelExporter *gmenuexporter); | ||
1793 | 33 | void disconnect(GDBusConnection *connection); | ||
1794 | 34 | |||
1795 | 35 | private: | ||
1796 | 36 | GDBusNodeInfo *m_introspection_data; | ||
1797 | 37 | guint m_registration_id; | ||
1798 | 38 | }; | ||
1799 | 39 | |||
1800 | 40 | #endif | ||
1801 | 41 | 0 | ||
1802 | === removed file 'src/ubuntuappmenu/registry.cpp' | |||
1803 | --- src/ubuntuappmenu/registry.cpp 2016-09-29 15:12:29 +0000 | |||
1804 | +++ src/ubuntuappmenu/registry.cpp 1970-01-01 00:00:00 +0000 | |||
1805 | @@ -1,97 +0,0 @@ | |||
1806 | 1 | /* | ||
1807 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1808 | 3 | * | ||
1809 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1810 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1811 | 6 | * the Free Software Foundation. | ||
1812 | 7 | * | ||
1813 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1814 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1815 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1816 | 11 | * Lesser General Public License for more details. | ||
1817 | 12 | * | ||
1818 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1819 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1820 | 15 | */ | ||
1821 | 16 | |||
1822 | 17 | #include "registry.h" | ||
1823 | 18 | #include "logging.h" | ||
1824 | 19 | #include "menuregistrar_interface.h" | ||
1825 | 20 | |||
1826 | 21 | #include <QDBusObjectPath> | ||
1827 | 22 | #include <QDBusServiceWatcher> | ||
1828 | 23 | |||
1829 | 24 | Q_LOGGING_CATEGORY(ubuntuappmenuRegistrar, "ubuntuappmenu.registrar", QtWarningMsg) | ||
1830 | 25 | |||
1831 | 26 | #define REGISTRAR_SERVICE "com.ubuntu.MenuRegistrar" | ||
1832 | 27 | #define REGISTRY_OBJECT_PATH "/com/ubuntu/MenuRegistrar" | ||
1833 | 28 | |||
1834 | 29 | UbuntuMenuRegistry *UbuntuMenuRegistry::instance() | ||
1835 | 30 | { | ||
1836 | 31 | static UbuntuMenuRegistry* registry(new UbuntuMenuRegistry()); | ||
1837 | 32 | return registry; | ||
1838 | 33 | } | ||
1839 | 34 | |||
1840 | 35 | UbuntuMenuRegistry::UbuntuMenuRegistry(QObject* parent) | ||
1841 | 36 | : QObject(parent) | ||
1842 | 37 | , m_serviceWatcher(new QDBusServiceWatcher(REGISTRAR_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this)) | ||
1843 | 38 | , m_interface(new ComUbuntuMenuRegistrarInterface(REGISTRAR_SERVICE, REGISTRY_OBJECT_PATH, QDBusConnection::sessionBus(), this)) | ||
1844 | 39 | , m_connected(m_interface->isValid()) | ||
1845 | 40 | { | ||
1846 | 41 | connect(m_serviceWatcher.data(), &QDBusServiceWatcher::serviceOwnerChanged, this, &UbuntuMenuRegistry::serviceOwnerChanged); | ||
1847 | 42 | } | ||
1848 | 43 | |||
1849 | 44 | UbuntuMenuRegistry::~UbuntuMenuRegistry() | ||
1850 | 45 | { | ||
1851 | 46 | } | ||
1852 | 47 | |||
1853 | 48 | void UbuntuMenuRegistry::registerApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath, const QString &service) | ||
1854 | 49 | { | ||
1855 | 50 | qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::registerMenu(pid=%d, menuObjectPath=%s, service=%s)", | ||
1856 | 51 | pid, | ||
1857 | 52 | qPrintable(menuObjectPath.path()), | ||
1858 | 53 | qPrintable(service)); | ||
1859 | 54 | |||
1860 | 55 | m_interface->RegisterAppMenu(pid, menuObjectPath, menuObjectPath, service); | ||
1861 | 56 | } | ||
1862 | 57 | |||
1863 | 58 | void UbuntuMenuRegistry::unregisterApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath) | ||
1864 | 59 | { | ||
1865 | 60 | qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::unregisterSurfaceMenu(pid=%d, menuObjectPath=%s)", | ||
1866 | 61 | pid, | ||
1867 | 62 | qPrintable(menuObjectPath.path())); | ||
1868 | 63 | |||
1869 | 64 | m_interface->UnregisterAppMenu(pid, menuObjectPath); | ||
1870 | 65 | } | ||
1871 | 66 | |||
1872 | 67 | void UbuntuMenuRegistry::registerSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath, const QString &service) | ||
1873 | 68 | { | ||
1874 | 69 | qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::registerMenu(surfaceId=%s, menuObjectPath=%s, service=%s)", | ||
1875 | 70 | qPrintable(surfaceId), | ||
1876 | 71 | qPrintable(menuObjectPath.path()), | ||
1877 | 72 | qPrintable(service)); | ||
1878 | 73 | |||
1879 | 74 | m_interface->RegisterSurfaceMenu(surfaceId, menuObjectPath, menuObjectPath, service); | ||
1880 | 75 | } | ||
1881 | 76 | |||
1882 | 77 | void UbuntuMenuRegistry::unregisterSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath) | ||
1883 | 78 | { | ||
1884 | 79 | qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::unregisterSurfaceMenu(surfaceId=%s, menuObjectPath=%s)", | ||
1885 | 80 | qPrintable(surfaceId), | ||
1886 | 81 | qPrintable(menuObjectPath.path())); | ||
1887 | 82 | |||
1888 | 83 | m_interface->UnregisterSurfaceMenu(surfaceId, menuObjectPath); | ||
1889 | 84 | } | ||
1890 | 85 | |||
1891 | 86 | |||
1892 | 87 | void UbuntuMenuRegistry::serviceOwnerChanged(const QString &serviceName, const QString& oldOwner, const QString &newOwner) | ||
1893 | 88 | { | ||
1894 | 89 | qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::serviceOwnerChanged(newOwner=%s)", qPrintable(newOwner)); | ||
1895 | 90 | |||
1896 | 91 | if (serviceName != REGISTRAR_SERVICE) return; | ||
1897 | 92 | |||
1898 | 93 | if (oldOwner != newOwner) { | ||
1899 | 94 | m_connected = !newOwner.isEmpty(); | ||
1900 | 95 | Q_EMIT serviceChanged(); | ||
1901 | 96 | } | ||
1902 | 97 | } | ||
1903 | 98 | 0 | ||
1904 | === removed file 'src/ubuntuappmenu/registry.h' | |||
1905 | --- src/ubuntuappmenu/registry.h 2016-09-29 15:03:17 +0000 | |||
1906 | +++ src/ubuntuappmenu/registry.h 1970-01-01 00:00:00 +0000 | |||
1907 | @@ -1,56 +0,0 @@ | |||
1908 | 1 | /* | ||
1909 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1910 | 3 | * | ||
1911 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1912 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1913 | 6 | * the Free Software Foundation. | ||
1914 | 7 | * | ||
1915 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1916 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1917 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1918 | 11 | * Lesser General Public License for more details. | ||
1919 | 12 | * | ||
1920 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1921 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1922 | 15 | */ | ||
1923 | 16 | |||
1924 | 17 | #ifndef UBUNTU_MENU_REGISTRY_H | ||
1925 | 18 | #define UBUNTU_MENU_REGISTRY_H | ||
1926 | 19 | |||
1927 | 20 | #include <QObject> | ||
1928 | 21 | #include <QScopedPointer> | ||
1929 | 22 | |||
1930 | 23 | class ComUbuntuMenuRegistrarInterface; | ||
1931 | 24 | class QDBusObjectPath; | ||
1932 | 25 | class QDBusServiceWatcher; | ||
1933 | 26 | |||
1934 | 27 | class UbuntuMenuRegistry : public QObject | ||
1935 | 28 | { | ||
1936 | 29 | Q_OBJECT | ||
1937 | 30 | public: | ||
1938 | 31 | UbuntuMenuRegistry(QObject* parent = nullptr); | ||
1939 | 32 | virtual ~UbuntuMenuRegistry(); | ||
1940 | 33 | |||
1941 | 34 | static UbuntuMenuRegistry *instance(); | ||
1942 | 35 | |||
1943 | 36 | void registerApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath, const QString &service); | ||
1944 | 37 | void unregisterApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath); | ||
1945 | 38 | |||
1946 | 39 | void registerSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath, const QString &service); | ||
1947 | 40 | void unregisterSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath); | ||
1948 | 41 | |||
1949 | 42 | bool isConnected() const { return m_connected; } | ||
1950 | 43 | |||
1951 | 44 | Q_SIGNALS: | ||
1952 | 45 | void serviceChanged(); | ||
1953 | 46 | |||
1954 | 47 | private Q_SLOTS: | ||
1955 | 48 | void serviceOwnerChanged(const QString &serviceName, const QString& oldOwner, const QString &newOwner); | ||
1956 | 49 | |||
1957 | 50 | private: | ||
1958 | 51 | QScopedPointer<QDBusServiceWatcher> m_serviceWatcher; | ||
1959 | 52 | QScopedPointer<ComUbuntuMenuRegistrarInterface> m_interface; | ||
1960 | 53 | bool m_connected; | ||
1961 | 54 | }; | ||
1962 | 55 | |||
1963 | 56 | #endif // UBUNTU_MENU_REGISTRY_H | ||
1964 | 57 | 0 | ||
1965 | === renamed file 'src/ubuntuappmenu/theme.cpp' => 'src/ubuntuappmenu/theme.cpp.THIS' | |||
1966 | === renamed file 'src/ubuntuappmenu/theme.h' => 'src/ubuntuappmenu/theme.h.THIS' | |||
1967 | === removed file 'src/ubuntuappmenu/themeplugin.cpp' | |||
1968 | --- src/ubuntuappmenu/themeplugin.cpp 2016-09-29 15:03:17 +0000 | |||
1969 | +++ src/ubuntuappmenu/themeplugin.cpp 1970-01-01 00:00:00 +0000 | |||
1970 | @@ -1,36 +0,0 @@ | |||
1971 | 1 | /* | ||
1972 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1973 | 3 | * | ||
1974 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1975 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1976 | 6 | * the Free Software Foundation. | ||
1977 | 7 | * | ||
1978 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1979 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1980 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1981 | 11 | * Lesser General Public License for more details. | ||
1982 | 12 | * | ||
1983 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1984 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1985 | 15 | */ | ||
1986 | 16 | |||
1987 | 17 | #include "themeplugin.h" | ||
1988 | 18 | #include "theme.h" | ||
1989 | 19 | |||
1990 | 20 | #include <QDebug> | ||
1991 | 21 | |||
1992 | 22 | /////////////////////////////////////////////////////////// | ||
1993 | 23 | |||
1994 | 24 | UbuntuAppMenuThemePlugin::UbuntuAppMenuThemePlugin(QObject *parent) | ||
1995 | 25 | : QPlatformThemePlugin(parent) | ||
1996 | 26 | { | ||
1997 | 27 | } | ||
1998 | 28 | |||
1999 | 29 | QPlatformTheme * | ||
2000 | 30 | UbuntuAppMenuThemePlugin::create(const QString &key, const QStringList&) | ||
2001 | 31 | { | ||
2002 | 32 | if (key.compare(QLatin1String(UbuntuAppMenuTheme::name), Qt::CaseInsensitive)) | ||
2003 | 33 | return 0; | ||
2004 | 34 | |||
2005 | 35 | return new UbuntuAppMenuTheme(); | ||
2006 | 36 | } | ||
2007 | 37 | 0 | ||
2008 | === removed file 'src/ubuntuappmenu/themeplugin.h' | |||
2009 | --- src/ubuntuappmenu/themeplugin.h 2016-06-21 16:33:19 +0000 | |||
2010 | +++ src/ubuntuappmenu/themeplugin.h 1970-01-01 00:00:00 +0000 | |||
2011 | @@ -1,34 +0,0 @@ | |||
2012 | 1 | /* | ||
2013 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
2014 | 3 | * | ||
2015 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
2016 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
2017 | 6 | * the Free Software Foundation. | ||
2018 | 7 | * | ||
2019 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
2020 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
2021 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2022 | 11 | * Lesser General Public License for more details. | ||
2023 | 12 | * | ||
2024 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2025 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2026 | 15 | */ | ||
2027 | 16 | |||
2028 | 17 | #ifndef UBUNTUTHEMEPLUGIN_H | ||
2029 | 18 | #define UBUNTUTHEMEPLUGIN_H | ||
2030 | 19 | |||
2031 | 20 | #include <qpa/qplatformthemeplugin.h> | ||
2032 | 21 | |||
2033 | 22 | class UbuntuAppMenuThemePlugin : public QPlatformThemePlugin | ||
2034 | 23 | { | ||
2035 | 24 | Q_OBJECT | ||
2036 | 25 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1" FILE "ubuntuappmenu.json") | ||
2037 | 26 | public: | ||
2038 | 27 | UbuntuAppMenuThemePlugin(QObject *parent = 0); | ||
2039 | 28 | |||
2040 | 29 | virtual QPlatformTheme *create(const QString &key, const QStringList ¶mList); | ||
2041 | 30 | |||
2042 | 31 | static const char *name; | ||
2043 | 32 | }; | ||
2044 | 33 | |||
2045 | 34 | #endif | ||
2046 | 35 | 0 | ||
2047 | === removed file 'src/ubuntuappmenu/ubuntuappmenu.json' | |||
2048 | --- src/ubuntuappmenu/ubuntuappmenu.json 2016-06-21 16:33:19 +0000 | |||
2049 | +++ src/ubuntuappmenu/ubuntuappmenu.json 1970-01-01 00:00:00 +0000 | |||
2050 | @@ -1,3 +0,0 @@ | |||
2051 | 1 | { | ||
2052 | 2 | "Keys": [ "ubuntuappmenu" ] | ||
2053 | 3 | } | ||
2054 | 4 | 0 | ||
2055 | === renamed file 'src/ubuntuappmenu/ubuntuappmenu.pro' => 'src/ubuntuappmenu/ubuntuappmenu.pro.THIS' | |||
2056 | === modified file 'src/ubuntumirclient/qmirclientintegration.cpp' | |||
2057 | --- src/ubuntumirclient/qmirclientintegration.cpp 2017-05-31 19:29:51 +0000 | |||
2058 | +++ src/ubuntumirclient/qmirclientintegration.cpp 2017-05-31 19:29:52 +0000 | |||
2059 | @@ -66,62 +66,95 @@ | |||
2060 | 66 | #include <QOpenGLContext> | 66 | #include <QOpenGLContext> |
2061 | 67 | #include <QOffscreenSurface> | 67 | #include <QOffscreenSurface> |
2062 | 68 | 68 | ||
2063 | 69 | <<<<<<< TREE | ||
2064 | 69 | // platform-api | 70 | // platform-api |
2065 | 70 | #include <ubuntu/application/lifecycle_delegate.h> | 71 | #include <ubuntu/application/lifecycle_delegate.h> |
2066 | 71 | #include <ubuntu/application/id.h> | 72 | #include <ubuntu/application/id.h> |
2067 | 72 | #include <ubuntu/application/options.h> | 73 | #include <ubuntu/application/options.h> |
2068 | 73 | 74 | ||
2069 | 74 | static void resumedCallback(const UApplicationOptions */*options*/, void *context) | 75 | static void resumedCallback(const UApplicationOptions */*options*/, void *context) |
2073 | 75 | { | 76 | ======= |
2074 | 76 | auto integration = static_cast<QMirClientClientIntegration*>(context); | 77 | namespace |
2075 | 77 | integration->appStateController()->setResumed(); | 78 | { |
2076 | 79 | class UbuntuIconTheme : public QGenericUnixTheme | ||
2077 | 80 | { | ||
2078 | 81 | public: | ||
2079 | 82 | UbuntuIconTheme() | ||
2080 | 83 | {} | ||
2081 | 84 | |||
2082 | 85 | // From QPlatformTheme | ||
2083 | 86 | QVariant themeHint(ThemeHint hint) const override | ||
2084 | 87 | { | ||
2085 | 88 | if (hint == QPlatformTheme::SystemIconThemeName) | ||
2086 | 89 | { | ||
2087 | 90 | QByteArray iconTheme = qgetenv("QTUBUNTU_ICON_THEME"); | ||
2088 | 91 | if (iconTheme.isEmpty()) | ||
2089 | 92 | { | ||
2090 | 93 | return QVariant(QStringLiteral("ubuntu-mobile")); | ||
2091 | 94 | } | ||
2092 | 95 | else | ||
2093 | 96 | { | ||
2094 | 97 | return QVariant(QString(iconTheme)); | ||
2095 | 98 | } | ||
2096 | 99 | } | ||
2097 | 100 | else | ||
2098 | 101 | { | ||
2099 | 102 | return QGenericUnixTheme::themeHint(hint); | ||
2100 | 103 | } | ||
2101 | 104 | } | ||
2102 | 105 | }; | ||
2103 | 106 | |||
2104 | 107 | QByteArray generateSessionNameFromQmlFile(QStringList &args) | ||
2105 | 108 | >>>>>>> MERGE-SOURCE | ||
2106 | 109 | { | ||
2107 | 110 | Q_FOREACH (QString arg, args) { | ||
2108 | 111 | if (arg.endsWith(".qml")) { | ||
2109 | 112 | QFileInfo fileInfo(arg); | ||
2110 | 113 | return fileInfo.fileName().toLocal8Bit(); | ||
2111 | 114 | } | ||
2112 | 115 | } | ||
2113 | 116 | |||
2114 | 117 | // give up | ||
2115 | 118 | return "qmlscene"; | ||
2116 | 78 | } | 119 | } |
2117 | 79 | 120 | ||
2119 | 80 | static void aboutToStopCallback(UApplicationArchive */*archive*/, void *context) | 121 | QByteArray generateSessionName(QStringList args) |
2120 | 81 | { | 122 | { |
2125 | 82 | auto integration = static_cast<QMirClientClientIntegration*>(context); | 123 | // Try to come up with some meaningful session name to uniquely identify this session, |
2126 | 83 | auto inputContext = integration->inputContext(); | 124 | // helping with shell debugging |
2127 | 84 | if (inputContext) { | 125 | if (args.count() == 0) { |
2128 | 85 | inputContext->hideInputPanel(); | 126 | return QByteArray("QtUbuntu"); |
2129 | 127 | } if (args[0].contains("qmlscene")) { | ||
2130 | 128 | return generateSessionNameFromQmlFile(args); | ||
2131 | 86 | } else { | 129 | } else { |
2133 | 87 | qCWarning(mirclient) << "aboutToStopCallback(): no input context"; | 130 | // use the executable name |
2134 | 131 | QFileInfo fileInfo(args[0]); | ||
2135 | 132 | return fileInfo.fileName().toLocal8Bit(); | ||
2136 | 88 | } | 133 | } |
2137 | 89 | integration->appStateController()->setSuspended(); | ||
2138 | 90 | } | 134 | } |
2139 | 91 | 135 | ||
2140 | 136 | MirConnection *make_mir_connection() | ||
2141 | 137 | { | ||
2142 | 138 | auto sessionName = generateSessionName(QCoreApplication::arguments()); | ||
2143 | 139 | auto mirConnection = mir_connect_sync(nullptr, sessionName.data()); | ||
2144 | 140 | if (!mir_connection_is_valid(mirConnection)) | ||
2145 | 141 | { | ||
2146 | 142 | qCritical("Mir returned: \"%s\"", mir_connection_get_error_message(mirConnection)); | ||
2147 | 143 | mir_connection_release(mirConnection); | ||
2148 | 144 | exit(EXIT_FAILURE); | ||
2149 | 145 | } | ||
2150 | 146 | return mirConnection; | ||
2151 | 147 | } | ||
2152 | 148 | } | ||
2153 | 92 | 149 | ||
2154 | 93 | QMirClientClientIntegration::QMirClientClientIntegration(int argc, char **argv) | 150 | QMirClientClientIntegration::QMirClientClientIntegration(int argc, char **argv) |
2155 | 94 | : QPlatformIntegration() | 151 | : QPlatformIntegration() |
2156 | 95 | , mNativeInterface(new QMirClientNativeInterface(this)) | 152 | , mNativeInterface(new QMirClientNativeInterface(this)) |
2157 | 96 | , mFontDb(new QGenericUnixFontDatabase) | 153 | , mFontDb(new QGenericUnixFontDatabase) |
2158 | 97 | , mServices(new QMirClientPlatformServices) | ||
2159 | 98 | , mAppStateController(new QMirClientAppStateController) | 154 | , mAppStateController(new QMirClientAppStateController) |
2160 | 99 | , mScaleFactor(1.0) | 155 | , mScaleFactor(1.0) |
2161 | 156 | , mMirConnection(make_mir_connection()) | ||
2162 | 100 | { | 157 | { |
2163 | 101 | QByteArray sessionName; | ||
2164 | 102 | { | ||
2165 | 103 | QStringList args = QCoreApplication::arguments(); | ||
2166 | 104 | setupOptions(args); | ||
2167 | 105 | sessionName = generateSessionName(args); | ||
2168 | 106 | setupDescription(sessionName); | ||
2169 | 107 | } | ||
2170 | 108 | |||
2171 | 109 | // Create new application instance | ||
2172 | 110 | mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions); | ||
2173 | 111 | |||
2174 | 112 | if (mInstance == nullptr) { | ||
2175 | 113 | qCritical("[QPA] QMirClientClientIntegration: connection to Mir server failed.\n"); | ||
2176 | 114 | |||
2177 | 115 | // TODO: add API to platform-api to fetch Mir's error message (bug:1655970). | ||
2178 | 116 | // Workaround by retrying the connection here in order to get the message. | ||
2179 | 117 | auto mirConnection = mir_connect_sync(nullptr, sessionName.data()); | ||
2180 | 118 | qCritical("Mir returned: \"%s\"", mir_connection_get_error_message(mirConnection)); | ||
2181 | 119 | mir_connection_release(mirConnection); | ||
2182 | 120 | exit(EXIT_FAILURE); | ||
2183 | 121 | } | ||
2184 | 122 | |||
2185 | 123 | mMirConnection = u_application_instance_get_mir_connection(mInstance); | ||
2186 | 124 | |||
2187 | 125 | // Choose the default surface format suited to the Mir platform | 158 | // Choose the default surface format suited to the Mir platform |
2188 | 126 | QSurfaceFormat defaultFormat; | 159 | QSurfaceFormat defaultFormat; |
2189 | 127 | defaultFormat.setRedBufferSize(8); | 160 | defaultFormat.setRedBufferSize(8); |
2190 | @@ -184,70 +217,7 @@ | |||
2191 | 184 | eglTerminate(mEglDisplay); | 217 | eglTerminate(mEglDisplay); |
2192 | 185 | delete mInput; | 218 | delete mInput; |
2193 | 186 | delete mInputContext; | 219 | delete mInputContext; |
2258 | 187 | delete mServices; | 220 | mir_connection_release(mMirConnection); |
2195 | 188 | } | ||
2196 | 189 | |||
2197 | 190 | QPlatformServices *QMirClientClientIntegration::services() const | ||
2198 | 191 | { | ||
2199 | 192 | return mServices; | ||
2200 | 193 | } | ||
2201 | 194 | |||
2202 | 195 | void QMirClientClientIntegration::setupOptions(QStringList &args) | ||
2203 | 196 | { | ||
2204 | 197 | int argc = args.size() + 1; | ||
2205 | 198 | char **argv = new char*[argc]; | ||
2206 | 199 | for (int i = 0; i < argc - 1; i++) | ||
2207 | 200 | argv[i] = qstrdup(args.at(i).toLocal8Bit()); | ||
2208 | 201 | argv[argc - 1] = nullptr; | ||
2209 | 202 | |||
2210 | 203 | mOptions = u_application_options_new_from_cmd_line(argc - 1, argv); | ||
2211 | 204 | |||
2212 | 205 | for (int i = 0; i < argc; i++) | ||
2213 | 206 | delete [] argv[i]; | ||
2214 | 207 | delete [] argv; | ||
2215 | 208 | } | ||
2216 | 209 | |||
2217 | 210 | void QMirClientClientIntegration::setupDescription(QByteArray &sessionName) | ||
2218 | 211 | { | ||
2219 | 212 | mDesc = u_application_description_new(); | ||
2220 | 213 | |||
2221 | 214 | UApplicationId* id = u_application_id_new_from_stringn(sessionName.data(), sessionName.count()); | ||
2222 | 215 | u_application_description_set_application_id(mDesc, id); | ||
2223 | 216 | |||
2224 | 217 | UApplicationLifecycleDelegate* delegate = u_application_lifecycle_delegate_new(); | ||
2225 | 218 | u_application_lifecycle_delegate_set_application_resumed_cb(delegate, &resumedCallback); | ||
2226 | 219 | u_application_lifecycle_delegate_set_application_about_to_stop_cb(delegate, &aboutToStopCallback); | ||
2227 | 220 | u_application_lifecycle_delegate_set_context(delegate, this); | ||
2228 | 221 | u_application_description_set_application_lifecycle_delegate(mDesc, delegate); | ||
2229 | 222 | } | ||
2230 | 223 | |||
2231 | 224 | QByteArray QMirClientClientIntegration::generateSessionName(QStringList &args) | ||
2232 | 225 | { | ||
2233 | 226 | // Try to come up with some meaningful session name to uniquely identify this session, | ||
2234 | 227 | // helping with shell debugging | ||
2235 | 228 | |||
2236 | 229 | if (args.count() == 0) { | ||
2237 | 230 | return QByteArray("QtUbuntu"); | ||
2238 | 231 | } if (args[0].contains("qmlscene")) { | ||
2239 | 232 | return generateSessionNameFromQmlFile(args); | ||
2240 | 233 | } else { | ||
2241 | 234 | // use the executable name | ||
2242 | 235 | QFileInfo fileInfo(args[0]); | ||
2243 | 236 | return fileInfo.fileName().toLocal8Bit(); | ||
2244 | 237 | } | ||
2245 | 238 | } | ||
2246 | 239 | |||
2247 | 240 | QByteArray QMirClientClientIntegration::generateSessionNameFromQmlFile(QStringList &args) | ||
2248 | 241 | { | ||
2249 | 242 | Q_FOREACH (QString arg, args) { | ||
2250 | 243 | if (arg.endsWith(".qml")) { | ||
2251 | 244 | QFileInfo fileInfo(arg); | ||
2252 | 245 | return fileInfo.fileName().toLocal8Bit(); | ||
2253 | 246 | } | ||
2254 | 247 | } | ||
2255 | 248 | |||
2256 | 249 | // give up | ||
2257 | 250 | return "qmlscene"; | ||
2259 | 251 | } | 221 | } |
2260 | 252 | 222 | ||
2261 | 253 | QPlatformWindow* QMirClientClientIntegration::createPlatformWindow(QWindow* window) const | 223 | QPlatformWindow* QMirClientClientIntegration::createPlatformWindow(QWindow* window) const |
2262 | 254 | 224 | ||
2263 | === modified file 'src/ubuntumirclient/qmirclientintegration.h' | |||
2264 | --- src/ubuntumirclient/qmirclientintegration.h 2017-05-31 19:29:51 +0000 | |||
2265 | +++ src/ubuntumirclient/qmirclientintegration.h 2017-05-31 19:29:52 +0000 | |||
2266 | @@ -45,13 +45,8 @@ | |||
2267 | 45 | #include <QSharedPointer> | 45 | #include <QSharedPointer> |
2268 | 46 | 46 | ||
2269 | 47 | #include "qmirclientappstatecontroller.h" | 47 | #include "qmirclientappstatecontroller.h" |
2270 | 48 | #include "qmirclientplatformservices.h" | ||
2271 | 49 | #include "qmirclientscreenobserver.h" | 48 | #include "qmirclientscreenobserver.h" |
2272 | 50 | 49 | ||
2273 | 51 | // platform-api | ||
2274 | 52 | #include <ubuntu/application/description.h> | ||
2275 | 53 | #include <ubuntu/application/instance.h> | ||
2276 | 54 | |||
2277 | 55 | #include <EGL/egl.h> | 50 | #include <EGL/egl.h> |
2278 | 56 | 51 | ||
2279 | 57 | class QMirClientDebugExtension; | 52 | class QMirClientDebugExtension; |
2280 | @@ -78,7 +73,6 @@ | |||
2281 | 78 | QStringList themeNames() const override; | 73 | QStringList themeNames() const override; |
2282 | 79 | QPlatformTheme* createPlatformTheme(const QString& name) const override; | 74 | QPlatformTheme* createPlatformTheme(const QString& name) const override; |
2283 | 80 | QVariant styleHint(StyleHint hint) const override; | 75 | QVariant styleHint(StyleHint hint) const override; |
2284 | 81 | QPlatformServices *services() const override; | ||
2285 | 82 | QPlatformWindow* createPlatformWindow(QWindow* window) const override; | 76 | QPlatformWindow* createPlatformWindow(QWindow* window) const override; |
2286 | 83 | QPlatformInputContext* inputContext() const override { return mInputContext; } | 77 | QPlatformInputContext* inputContext() const override { return mInputContext; } |
2287 | 84 | QPlatformClipboard* clipboard() const override; | 78 | QPlatformClipboard* clipboard() const override; |
2288 | @@ -100,14 +94,10 @@ | |||
2289 | 100 | private: | 94 | private: |
2290 | 101 | void setupOptions(QStringList &args); | 95 | void setupOptions(QStringList &args); |
2291 | 102 | void setupDescription(QByteArray &sessionName); | 96 | void setupDescription(QByteArray &sessionName); |
2292 | 103 | static QByteArray generateSessionName(QStringList &args); | ||
2293 | 104 | static QByteArray generateSessionNameFromQmlFile(QStringList &args); | ||
2294 | 105 | 97 | ||
2295 | 106 | QMirClientNativeInterface* mNativeInterface; | 98 | QMirClientNativeInterface* mNativeInterface; |
2296 | 107 | QPlatformFontDatabase* mFontDb; | 99 | QPlatformFontDatabase* mFontDb; |
2297 | 108 | 100 | ||
2298 | 109 | QMirClientPlatformServices* mServices; | ||
2299 | 110 | |||
2300 | 111 | QMirClientInput* mInput; | 101 | QMirClientInput* mInput; |
2301 | 112 | QPlatformInputContext* mInputContext; | 102 | QPlatformInputContext* mInputContext; |
2302 | 113 | mutable QScopedPointer<QPlatformAccessibility> mAccessibility; | 103 | mutable QScopedPointer<QPlatformAccessibility> mAccessibility; |
2303 | @@ -118,11 +108,6 @@ | |||
2304 | 118 | 108 | ||
2305 | 119 | MirConnection *mMirConnection; | 109 | MirConnection *mMirConnection; |
2306 | 120 | 110 | ||
2307 | 121 | // Platform API stuff | ||
2308 | 122 | UApplicationOptions* mOptions; | ||
2309 | 123 | UApplicationDescription* mDesc; | ||
2310 | 124 | UApplicationInstance* mInstance; | ||
2311 | 125 | |||
2312 | 126 | // EGL related | 111 | // EGL related |
2313 | 127 | EGLDisplay mEglDisplay{EGL_NO_DISPLAY}; | 112 | EGLDisplay mEglDisplay{EGL_NO_DISPLAY}; |
2314 | 128 | }; | 113 | }; |
2315 | 129 | 114 | ||
2316 | === removed file 'src/ubuntumirclient/qmirclientplatformservices.cpp' | |||
2317 | --- src/ubuntumirclient/qmirclientplatformservices.cpp 2017-02-07 15:37:20 +0000 | |||
2318 | +++ src/ubuntumirclient/qmirclientplatformservices.cpp 1970-01-01 00:00:00 +0000 | |||
2319 | @@ -1,75 +0,0 @@ | |||
2320 | 1 | /**************************************************************************** | ||
2321 | 2 | ** | ||
2322 | 3 | ** Copyright (C) 2016 Canonical, Ltd. | ||
2323 | 4 | ** Contact: https://www.qt.io/licensing/ | ||
2324 | 5 | ** | ||
2325 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
2326 | 7 | ** | ||
2327 | 8 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
2328 | 9 | ** Commercial License Usage | ||
2329 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
2330 | 11 | ** accordance with the commercial license agreement provided with the | ||
2331 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
2332 | 13 | ** a written agreement between you and The Qt Company. For licensing terms | ||
2333 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | ||
2334 | 15 | ** information use the contact form at https://www.qt.io/contact-us. | ||
2335 | 16 | ** | ||
2336 | 17 | ** GNU Lesser General Public License Usage | ||
2337 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
2338 | 19 | ** General Public License version 3 as published by the Free Software | ||
2339 | 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | ||
2340 | 21 | ** packaging of this file. Please review the following information to | ||
2341 | 22 | ** ensure the GNU Lesser General Public License version 3 requirements | ||
2342 | 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | ||
2343 | 24 | ** | ||
2344 | 25 | ** GNU General Public License Usage | ||
2345 | 26 | ** Alternatively, this file may be used under the terms of the GNU | ||
2346 | 27 | ** General Public License version 2.0 or (at your option) the GNU General | ||
2347 | 28 | ** Public license version 3 or any later version approved by the KDE Free | ||
2348 | 29 | ** Qt Foundation. The licenses are as published by the Free Software | ||
2349 | 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | ||
2350 | 31 | ** included in the packaging of this file. Please review the following | ||
2351 | 32 | ** information to ensure the GNU General Public License requirements will | ||
2352 | 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | ||
2353 | 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | ||
2354 | 35 | ** | ||
2355 | 36 | ** $QT_END_LICENSE$ | ||
2356 | 37 | ** | ||
2357 | 38 | ****************************************************************************/ | ||
2358 | 39 | |||
2359 | 40 | |||
2360 | 41 | #include "qmirclientplatformservices.h" | ||
2361 | 42 | |||
2362 | 43 | #include <QUrl> | ||
2363 | 44 | |||
2364 | 45 | #include <ubuntu/application/url_dispatcher/service.h> | ||
2365 | 46 | #include <ubuntu/application/url_dispatcher/session.h> | ||
2366 | 47 | |||
2367 | 48 | bool QMirClientPlatformServices::openUrl(const QUrl &url) | ||
2368 | 49 | { | ||
2369 | 50 | return callDispatcher(url); | ||
2370 | 51 | } | ||
2371 | 52 | |||
2372 | 53 | bool QMirClientPlatformServices::openDocument(const QUrl &url) | ||
2373 | 54 | { | ||
2374 | 55 | return callDispatcher(url); | ||
2375 | 56 | } | ||
2376 | 57 | |||
2377 | 58 | bool QMirClientPlatformServices::callDispatcher(const QUrl &url) | ||
2378 | 59 | { | ||
2379 | 60 | UAUrlDispatcherSession* session = ua_url_dispatcher_session(); | ||
2380 | 61 | if (!session) | ||
2381 | 62 | return false; | ||
2382 | 63 | |||
2383 | 64 | ua_url_dispatcher_session_open(session, url.toEncoded().constData(), NULL, NULL); | ||
2384 | 65 | |||
2385 | 66 | free(session); | ||
2386 | 67 | |||
2387 | 68 | // We are returning true here because the other option | ||
2388 | 69 | // is spawning a nested event loop and wait for the | ||
2389 | 70 | // callback. But there is no guarantee on how fast | ||
2390 | 71 | // the callback is going to be so we prefer to avoid the | ||
2391 | 72 | // nested event loop. Long term plan is improve Qt API | ||
2392 | 73 | // to support an async openUrl | ||
2393 | 74 | return true; | ||
2394 | 75 | } | ||
2395 | 76 | 0 | ||
2396 | === removed file 'src/ubuntumirclient/qmirclientplatformservices.h' | |||
2397 | --- src/ubuntumirclient/qmirclientplatformservices.h 2017-02-07 15:37:20 +0000 | |||
2398 | +++ src/ubuntumirclient/qmirclientplatformservices.h 1970-01-01 00:00:00 +0000 | |||
2399 | @@ -1,57 +0,0 @@ | |||
2400 | 1 | /**************************************************************************** | ||
2401 | 2 | ** | ||
2402 | 3 | ** Copyright (C) 2016 Canonical, Ltd. | ||
2403 | 4 | ** Contact: https://www.qt.io/licensing/ | ||
2404 | 5 | ** | ||
2405 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
2406 | 7 | ** | ||
2407 | 8 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
2408 | 9 | ** Commercial License Usage | ||
2409 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
2410 | 11 | ** accordance with the commercial license agreement provided with the | ||
2411 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
2412 | 13 | ** a written agreement between you and The Qt Company. For licensing terms | ||
2413 | 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | ||
2414 | 15 | ** information use the contact form at https://www.qt.io/contact-us. | ||
2415 | 16 | ** | ||
2416 | 17 | ** GNU Lesser General Public License Usage | ||
2417 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
2418 | 19 | ** General Public License version 3 as published by the Free Software | ||
2419 | 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | ||
2420 | 21 | ** packaging of this file. Please review the following information to | ||
2421 | 22 | ** ensure the GNU Lesser General Public License version 3 requirements | ||
2422 | 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | ||
2423 | 24 | ** | ||
2424 | 25 | ** GNU General Public License Usage | ||
2425 | 26 | ** Alternatively, this file may be used under the terms of the GNU | ||
2426 | 27 | ** General Public License version 2.0 or (at your option) the GNU General | ||
2427 | 28 | ** Public license version 3 or any later version approved by the KDE Free | ||
2428 | 29 | ** Qt Foundation. The licenses are as published by the Free Software | ||
2429 | 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | ||
2430 | 31 | ** included in the packaging of this file. Please review the following | ||
2431 | 32 | ** information to ensure the GNU General Public License requirements will | ||
2432 | 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | ||
2433 | 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | ||
2434 | 35 | ** | ||
2435 | 36 | ** $QT_END_LICENSE$ | ||
2436 | 37 | ** | ||
2437 | 38 | ****************************************************************************/ | ||
2438 | 39 | |||
2439 | 40 | |||
2440 | 41 | #ifndef QMIRCLIENTPLATFORMSERVICES_H | ||
2441 | 42 | #define QMIRCLIENTPLATFORMSERVICES_H | ||
2442 | 43 | |||
2443 | 44 | #include <qpa/qplatformservices.h> | ||
2444 | 45 | #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h> | ||
2445 | 46 | #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h> | ||
2446 | 47 | |||
2447 | 48 | class QMirClientPlatformServices : public QPlatformServices { | ||
2448 | 49 | public: | ||
2449 | 50 | bool openUrl(const QUrl &url) override; | ||
2450 | 51 | bool openDocument(const QUrl &url) override; | ||
2451 | 52 | |||
2452 | 53 | private: | ||
2453 | 54 | bool callDispatcher(const QUrl &url); | ||
2454 | 55 | }; | ||
2455 | 56 | |||
2456 | 57 | #endif // QMIRCLIENTPLATFORMSERVICES_H | ||
2457 | 58 | 0 | ||
2458 | === modified file 'src/ubuntumirclient/ubuntumirclient.pro' | |||
2459 | --- src/ubuntumirclient/ubuntumirclient.pro 2017-05-31 19:29:51 +0000 | |||
2460 | +++ src/ubuntumirclient/ubuntumirclient.pro 2017-05-31 19:29:52 +0000 | |||
2461 | @@ -24,7 +24,6 @@ | |||
2462 | 24 | qmirclientinput.cpp \ | 24 | qmirclientinput.cpp \ |
2463 | 25 | qmirclientintegration.cpp \ | 25 | qmirclientintegration.cpp \ |
2464 | 26 | qmirclientnativeinterface.cpp \ | 26 | qmirclientnativeinterface.cpp \ |
2465 | 27 | qmirclientplatformservices.cpp \ | ||
2466 | 28 | qmirclientplugin.cpp \ | 27 | qmirclientplugin.cpp \ |
2467 | 29 | qmirclientscreen.cpp \ | 28 | qmirclientscreen.cpp \ |
2468 | 30 | qmirclientscreenobserver.cpp \ | 29 | qmirclientscreenobserver.cpp \ |
2469 | @@ -42,7 +41,6 @@ | |||
2470 | 42 | qmirclientintegration.h \ | 41 | qmirclientintegration.h \ |
2471 | 43 | qmirclientnativeinterface.h \ | 42 | qmirclientnativeinterface.h \ |
2472 | 44 | qmirclientorientationchangeevent_p.h \ | 43 | qmirclientorientationchangeevent_p.h \ |
2473 | 45 | qmirclientplatformservices.h \ | ||
2474 | 46 | qmirclientplugin.h \ | 44 | qmirclientplugin.h \ |
2475 | 47 | qmirclientscreenobserver.h \ | 45 | qmirclientscreenobserver.h \ |
2476 | 48 | qmirclientscreen.h \ | 46 | qmirclientscreen.h \ |
FAILED: Continuous integration, rev:399 /unity8- jenkins. ubuntu. com/job/ lp-qtubuntu- ci/225/ /unity8- jenkins. ubuntu. com/job/ build/4925/ console /unity8- jenkins. ubuntu. com/job/ build-0- fetch/4953/ console
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /unity8- jenkins. ubuntu. com/job/ lp-qtubuntu- ci/225/ rebuild
https:/