Merge lp:~nick-dedekind/libdbusmenu-qt/qpaexporter into lp:libdbusmenu-qt
- qpaexporter
- Merge into trunk
Proposed by
Nick Dedekind
Status: | Work in progress |
---|---|
Proposed branch: | lp:~nick-dedekind/libdbusmenu-qt/qpaexporter |
Merge into: | lp:libdbusmenu-qt |
Prerequisite: | lp:~nick-dedekind/libdbusmenu-qt/Qt5-tests |
Diff against target: |
2985 lines (+2413/-149) 31 files modified
CMakeLists.txt (+12/-2) Doxyfile.in (+1/-1) debian/changelog (+7/-0) src/CMakeLists.txt (+35/-28) src/dbusmenuexporter.cpp (+5/-31) src/dbusmenuexporterdbus_p.cpp (+4/-36) src/dbusmenuexporterdbus_p.h (+10/-34) src/dbusmenuexporterdbusinterface_p.cpp (+67/-0) src/dbusmenuexporterdbusinterface_p.h (+80/-0) src/dbusmenuexporterprivate_p.h (+1/-1) src/dbusmenuimporter.cpp (+2/-2) src/dbusmenuinterface.cpp (+63/-0) src/dbusmenuinterface.h (+154/-0) src/dbusmenuproperty.h (+78/-0) src/dbusmenushortcut_p.cpp (+2/-0) src/dbusmenutypes.cpp (+142/-1) src/dbusmenutypes.h (+20/-5) src/qpa/exportedplatformmenubar.cpp (+377/-0) src/qpa/exportedplatformmenubar.h (+136/-0) src/qpa/exportedplatformmenubar_p.cpp (+129/-0) src/qpa/exportedplatformmenubar_p.h (+111/-0) src/qpa/logging_p.h (+38/-0) src/qpa/qpadbusmenuexporter_p.cpp (+357/-0) src/qpa/qpadbusmenuexporter_p.h (+94/-0) src/utils.cpp (+36/-1) src/utils_p.h (+15/-5) tests/CMakeLists.txt (+13/-0) tests/dbusmenuexportertest.cpp (+2/-1) tests/exportedplatformmenutest.cpp (+366/-0) tests/exportedplatformmenutest.h (+55/-0) tests/testutils.h (+1/-1) |
To merge this branch: | bzr merge lp:~nick-dedekind/libdbusmenu-qt/qpaexporter |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
DBus Menu Team | Pending | ||
Review via email: mp+253334@code.launchpad.net |
This proposal supersedes a proposal from 2015-03-05.
Commit message
Description of the change
Added exporter support for Qt platform menus.
Exported dbus interface for com.canonical.
To post a comment you must log in.
- 276. By Nick Dedekind
-
reverted dbus xml
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Unmerged revisions
- 276. By Nick Dedekind
-
reverted dbus xml
- 275. By Nick Dedekind
-
fixed addMenu
- 274. By Nick Dedekind
-
added exported platformmenu test
- 273. By Nick Dedekind
-
merged with test branch
- 272. By Nick Dedekind
-
parent of exporter
- 271. By Nick Dedekind
-
logging & version bump
- 270. By Nick Dedekind
-
added dbusmenuinterface + reworked dbus properties
- 269. By Nick Dedekind
-
more qpa exporter
- 268. By Nick Dedekind
-
app menu qpa exporter
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2015-03-18 11:19:06 +0000 | |||
3 | +++ CMakeLists.txt 2015-03-18 11:19:06 +0000 | |||
4 | @@ -34,12 +34,22 @@ | |||
5 | 34 | endif() | 34 | endif() |
6 | 35 | endif() | 35 | endif() |
7 | 36 | 36 | ||
8 | 37 | find_package(PkgConfig) | ||
9 | 37 | # Detect for which Qt version we're building | 38 | # Detect for which Qt version we're building |
10 | 38 | if (USE_QT5) | 39 | if (USE_QT5) |
11 | 40 | find_package(Qt5Core REQUIRED) | ||
12 | 39 | find_package(Qt5Widgets REQUIRED) | 41 | find_package(Qt5Widgets REQUIRED) |
13 | 40 | find_package(Qt5DBus REQUIRED) | 42 | find_package(Qt5DBus REQUIRED) |
16 | 41 | include_directories(${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) | 43 | find_package(Qt5Gui REQUIRED) |
17 | 42 | find_package(Qt5Core REQUIRED) | 44 | pkg_check_modules(DBUS_CPP dbus-cpp REQUIRED) |
18 | 45 | |||
19 | 46 | include_directories( | ||
20 | 47 | ${Qt5Widgets_INCLUDE_DIRS} | ||
21 | 48 | ${Qt5DBus_INCLUDE_DIRS} | ||
22 | 49 | ${Qt5DBus_PRIVATE_INCLUDE_DIRS} | ||
23 | 50 | ${Qt5Gui_PRIVATE_INCLUDE_DIRS} | ||
24 | 51 | ${DBUS_CPP_INCLUDE_DIRS} | ||
25 | 52 | ) | ||
26 | 43 | set(CMAKE_AUTOMOC ON) | 53 | set(CMAKE_AUTOMOC ON) |
27 | 44 | set(CMAKE_AUTOMOC_RELAXED_MODE ON) | 54 | set(CMAKE_AUTOMOC_RELAXED_MODE ON) |
28 | 45 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) | 55 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
29 | 46 | 56 | ||
30 | === modified file 'Doxyfile.in' | |||
31 | --- Doxyfile.in 2011-03-24 15:04:52 +0000 | |||
32 | +++ Doxyfile.in 2015-03-18 11:19:06 +0000 | |||
33 | @@ -232,7 +232,7 @@ | |||
34 | 232 | SEARCH_INCLUDES = YES | 232 | SEARCH_INCLUDES = YES |
35 | 233 | INCLUDE_PATH = | 233 | INCLUDE_PATH = |
36 | 234 | INCLUDE_FILE_PATTERNS = | 234 | INCLUDE_FILE_PATTERNS = |
38 | 235 | PREDEFINED = | 235 | PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS |
39 | 236 | EXPAND_AS_DEFINED = | 236 | EXPAND_AS_DEFINED = |
40 | 237 | SKIP_FUNCTION_MACROS = YES | 237 | SKIP_FUNCTION_MACROS = YES |
41 | 238 | #--------------------------------------------------------------------------- | 238 | #--------------------------------------------------------------------------- |
42 | 239 | 239 | ||
43 | === modified file 'debian/changelog' | |||
44 | --- debian/changelog 2014-06-19 09:07:18 +0000 | |||
45 | +++ debian/changelog 2015-03-18 11:19:06 +0000 | |||
46 | @@ -1,3 +1,10 @@ | |||
47 | 1 | libdbusmenu-qt (0.9.4) UNRELEASED; urgency=medium | ||
48 | 2 | |||
49 | 3 | [ Nick Dedekind ] | ||
50 | 4 | * Added exported qpa platform menu & dbusmenu interface | ||
51 | 5 | |||
52 | 6 | -- Nick Dedekind <nick.dedekind@canonical.com> Thu, 05 Mar 2015 13:39:12 +0000 | ||
53 | 7 | |||
54 | 1 | libdbusmenu-qt (0.9.3+14.10.20140619-0ubuntu1) utopic; urgency=low | 8 | libdbusmenu-qt (0.9.3+14.10.20140619-0ubuntu1) utopic; urgency=low |
55 | 2 | 9 | ||
56 | 3 | [ Aurélien Gâteau ] | 10 | [ Aurélien Gâteau ] |
57 | 4 | 11 | ||
58 | === modified file 'src/CMakeLists.txt' | |||
59 | --- src/CMakeLists.txt 2015-03-18 11:19:06 +0000 | |||
60 | +++ src/CMakeLists.txt 2015-03-18 11:19:06 +0000 | |||
61 | @@ -1,34 +1,20 @@ | |||
62 | 1 | include(CheckCXXSourceCompiles) | 1 | include(CheckCXXSourceCompiles) |
63 | 2 | 2 | ||
64 | 3 | check_cxx_compiler_flag(-Wall __DBUSMENU_HAVE_W_ALL) | ||
65 | 4 | if (__DBUSMENU_HAVE_W_ALL) | ||
66 | 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") | ||
67 | 6 | endif (__DBUSMENU_HAVE_W_ALL) | ||
68 | 7 | |||
69 | 8 | # Check some compiler flags | 3 | # Check some compiler flags |
70 | 9 | check_cxx_compiler_flag(-fvisibility=hidden __DBUSMENU_HAVE_GCC_VISIBILITY) | ||
71 | 10 | if (__DBUSMENU_HAVE_GCC_VISIBILITY AND NOT WIN32) | ||
72 | 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") | ||
73 | 12 | endif (__DBUSMENU_HAVE_GCC_VISIBILITY AND NOT WIN32) | ||
74 | 13 | |||
75 | 14 | check_cxx_compiler_flag(-Woverloaded-virtual __DBUSMENU_HAVE_W_OVERLOADED_VIRTUAL) | ||
76 | 15 | if (__DBUSMENU_HAVE_W_OVERLOADED_VIRTUAL) | ||
77 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") | ||
78 | 17 | endif (__DBUSMENU_HAVE_W_OVERLOADED_VIRTUAL) | ||
79 | 18 | |||
80 | 19 | check_cxx_compiler_flag(-Wall __DBUSMENU_HAVE_W_ALL) | 4 | check_cxx_compiler_flag(-Wall __DBUSMENU_HAVE_W_ALL) |
81 | 20 | if (__DBUSMENU_HAVE_W_ALL) | 5 | if (__DBUSMENU_HAVE_W_ALL) |
82 | 21 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") | 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") |
83 | 22 | endif (__DBUSMENU_HAVE_W_ALL) | 7 | endif (__DBUSMENU_HAVE_W_ALL) |
84 | 23 | 8 | ||
89 | 24 | check_cxx_compiler_flag(-std=c++11 __DBUSMENU_HAVE_CXX11) | 9 | # Find the dbusxml2cpp tool |
90 | 25 | if (__DBUSMENU_HAVE_CXX11) | 10 | if(DEFINED ENV{DEB_BUILD_MULTIARCH}) |
91 | 26 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | 11 | set(QDBUSXML2CPP_EXECUTABLE "/usr/lib/$ENV{DEB_BUILD_MULTIARCH}/qt5/bin/qdbusxml2cpp") |
92 | 27 | endif (__DBUSMENU_HAVE_CXX11) | 12 | else() |
93 | 13 | FIND_PROGRAM(QDBUSXML2CPP_EXECUTABLE qdbusxml2cpp) | ||
94 | 14 | endif() | ||
95 | 28 | 15 | ||
96 | 29 | # Check whether QIcon::name() exists. It was added in late Qt 4.7 cycle, and is | 16 | # Check whether QIcon::name() exists. It was added in late Qt 4.7 cycle, and is |
97 | 30 | # not present in betas. | 17 | # not present in betas. |
98 | 31 | |||
99 | 32 | if (NOT USE_QT5) | 18 | if (NOT USE_QT5) |
100 | 33 | set(CMAKE_REQUIRED_INCLUDES "${QT_INCLUDE_DIR}") | 19 | set(CMAKE_REQUIRED_INCLUDES "${QT_INCLUDE_DIR}") |
101 | 34 | set(CMAKE_REQUIRED_LIBRARIES "${QT_QTGUI_LIBRARIES};${QT_QTCORE_LIBRARIES}") | 20 | set(CMAKE_REQUIRED_LIBRARIES "${QT_QTGUI_LIBRARIES};${QT_QTCORE_LIBRARIES}") |
102 | @@ -49,34 +35,55 @@ | |||
103 | 49 | endif() | 35 | endif() |
104 | 50 | configure_file(dbusmenu_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbusmenu_config.h @ONLY) | 36 | configure_file(dbusmenu_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbusmenu_config.h @ONLY) |
105 | 51 | 37 | ||
106 | 38 | include_directories( | ||
107 | 39 | ${CMAKE_SOURCE_DIR}/src | ||
108 | 40 | ${CMAKE_BINARY_DIR}/src | ||
109 | 41 | ) | ||
110 | 42 | |||
111 | 52 | set(dbusmenu_qt_SRCS | 43 | set(dbusmenu_qt_SRCS |
112 | 53 | dbusmenu_p.cpp | 44 | dbusmenu_p.cpp |
113 | 54 | dbusmenuexporter.cpp | 45 | dbusmenuexporter.cpp |
114 | 55 | dbusmenuexporterdbus_p.cpp | 46 | dbusmenuexporterdbus_p.cpp |
115 | 47 | dbusmenuexporterdbusinterface_p.cpp | ||
116 | 56 | dbusmenuimporter.cpp | 48 | dbusmenuimporter.cpp |
118 | 57 | dbusmenutypes_p.cpp | 49 | dbusmenuinterface.cpp |
119 | 50 | dbusmenutypes.cpp | ||
120 | 58 | dbusmenushortcut_p.cpp | 51 | dbusmenushortcut_p.cpp |
121 | 59 | utils.cpp | 52 | utils.cpp |
127 | 60 | ) | 53 | dbusmenuproperty.h |
128 | 61 | 54 | ${CMAKE_BINARY_DIR}/src/dbusmenuinterface_p.cpp | |
124 | 62 | include_directories( | ||
125 | 63 | ${CMAKE_SOURCE_DIR}/src | ||
126 | 64 | ${CMAKE_BINARY_DIR}/src | ||
129 | 65 | ) | 55 | ) |
130 | 66 | 56 | ||
131 | 67 | if (NOT USE_QT5) | 57 | if (NOT USE_QT5) |
132 | 68 | qt4_automoc(${dbusmenu_qt_SRCS}) | 58 | qt4_automoc(${dbusmenu_qt_SRCS}) |
133 | 69 | qt4_add_dbus_adaptor(dbusmenu_qt_SRCS | 59 | qt4_add_dbus_adaptor(dbusmenu_qt_SRCS |
134 | 70 | ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.dbusmenu.xml | 60 | ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.dbusmenu.xml |
136 | 71 | ${CMAKE_CURRENT_SOURCE_DIR}/dbusmenuexporterdbus_p.h DBusMenuExporterDBus | 61 | ${CMAKE_CURRENT_SOURCE_DIR}/dbusmenuexporterdbusinterface_p.h DBusMenuExporterDBusInterface |
137 | 72 | ) | 62 | ) |
138 | 73 | else() | 63 | else() |
139 | 64 | set(dbusmenu_qt_SRCS | ||
140 | 65 | ${dbusmenu_qt_SRCS} | ||
141 | 66 | qpa/exportedplatformmenubar.cpp | ||
142 | 67 | qpa/exportedplatformmenubar_p.cpp | ||
143 | 68 | qpa/qpadbusmenuexporter_p.cpp | ||
144 | 69 | ) | ||
145 | 70 | |||
146 | 74 | qt5_add_dbus_adaptor(dbusmenu_qt_SRCS | 71 | qt5_add_dbus_adaptor(dbusmenu_qt_SRCS |
147 | 75 | ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.dbusmenu.xml | 72 | ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.dbusmenu.xml |
149 | 76 | ${CMAKE_CURRENT_SOURCE_DIR}/dbusmenuexporterdbus_p.h DBusMenuExporterDBus | 73 | ${CMAKE_CURRENT_SOURCE_DIR}/dbusmenuexporterdbusinterface_p.h DBusMenuExporterDBusInterface |
150 | 77 | ) | 74 | ) |
151 | 78 | endif() | 75 | endif() |
152 | 79 | 76 | ||
153 | 77 | if(${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.dbusmenu.xml IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/dbusmenuinterface.h) | ||
154 | 78 | execute_process(COMMAND ${QDBUSXML2CPP_EXECUTABLE} | ||
155 | 79 | -c DbusMenuInterfacePrivate | ||
156 | 80 | -p ${CMAKE_CURRENT_BINARY_DIR}/dbusmenuinterface_p | ||
157 | 81 | -i "${CMAKE_SOURCE_DIR}/src/dbusmenutypes.h" | ||
158 | 82 | ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.dbusmenu.xml | ||
159 | 83 | com.canonical.dbusmenu | ||
160 | 84 | ) | ||
161 | 85 | endif() | ||
162 | 86 | |||
163 | 80 | configure_file(dbusmenu_version.h.in | 87 | configure_file(dbusmenu_version.h.in |
164 | 81 | ${CMAKE_CURRENT_BINARY_DIR}/dbusmenu_version.h | 88 | ${CMAKE_CURRENT_BINARY_DIR}/dbusmenu_version.h |
165 | 82 | ) | 89 | ) |
166 | 83 | 90 | ||
167 | === modified file 'src/dbusmenuexporter.cpp' | |||
168 | --- src/dbusmenuexporter.cpp 2012-10-24 14:43:10 +0000 | |||
169 | +++ src/dbusmenuexporter.cpp 2015-03-18 11:19:06 +0000 | |||
170 | @@ -35,7 +35,7 @@ | |||
171 | 35 | #include "dbusmenu_p.h" | 35 | #include "dbusmenu_p.h" |
172 | 36 | #include "dbusmenuexporterdbus_p.h" | 36 | #include "dbusmenuexporterdbus_p.h" |
173 | 37 | #include "dbusmenuexporterprivate_p.h" | 37 | #include "dbusmenuexporterprivate_p.h" |
175 | 38 | #include "dbusmenutypes_p.h" | 38 | #include "dbusmenutypes.h" |
176 | 39 | #include "dbusmenushortcut_p.h" | 39 | #include "dbusmenushortcut_p.h" |
177 | 40 | #include "debug_p.h" | 40 | #include "debug_p.h" |
178 | 41 | #include "utils_p.h" | 41 | #include "utils_p.h" |
179 | @@ -94,7 +94,7 @@ | |||
180 | 94 | QAction *action = button->defaultAction(); | 94 | QAction *action = button->defaultAction(); |
181 | 95 | DMRETURN_VALUE_IF_FAIL(action, map); | 95 | DMRETURN_VALUE_IF_FAIL(action, map); |
182 | 96 | 96 | ||
184 | 97 | map.insert("label", swapMnemonicChar(action->text(), '&', '_')); | 97 | map.insert("label", Utils::swapMnemonicChar(action->text(), '&', '_')); |
185 | 98 | insertIconProperty(&map, action); | 98 | insertIconProperty(&map, action); |
186 | 99 | if (!action->isVisible()) { | 99 | if (!action->isVisible()) { |
187 | 100 | map.insert("visible", false); | 100 | map.insert("visible", false); |
188 | @@ -115,7 +115,7 @@ | |||
189 | 115 | QVariantMap DBusMenuExporterPrivate::propertiesForStandardAction(QAction *action) const | 115 | QVariantMap DBusMenuExporterPrivate::propertiesForStandardAction(QAction *action) const |
190 | 116 | { | 116 | { |
191 | 117 | QVariantMap map; | 117 | QVariantMap map; |
193 | 118 | map.insert("label", swapMnemonicChar(action->text(), '&', '_')); | 118 | map.insert("label", Utils::swapMnemonicChar(action->text(), '&', '_')); |
194 | 119 | if (!action->isEnabled()) { | 119 | if (!action->isEnabled()) { |
195 | 120 | map.insert("enabled", false); | 120 | map.insert("enabled", false); |
196 | 121 | } | 121 | } |
197 | @@ -338,7 +338,7 @@ | |||
198 | 338 | d->m_emittedLayoutUpdatedOnce = false; | 338 | d->m_emittedLayoutUpdatedOnce = false; |
199 | 339 | d->m_itemUpdatedTimer = new QTimer(this); | 339 | d->m_itemUpdatedTimer = new QTimer(this); |
200 | 340 | d->m_layoutUpdatedTimer = new QTimer(this); | 340 | d->m_layoutUpdatedTimer = new QTimer(this); |
202 | 341 | d->m_dbusObject = new DBusMenuExporterDBus(this); | 341 | d->m_dbusObject = new DBusMenuExporterDBus(objectPath, this); |
203 | 342 | 342 | ||
204 | 343 | d->addMenu(d->m_rootMenu, 0); | 343 | d->addMenu(d->m_rootMenu, 0); |
205 | 344 | 344 | ||
206 | @@ -379,33 +379,7 @@ | |||
207 | 379 | QVariantMap updatedProperties; | 379 | QVariantMap updatedProperties; |
208 | 380 | QStringList removedProperties; | 380 | QStringList removedProperties; |
209 | 381 | 381 | ||
237 | 382 | // Find updated and removed properties | 382 | Utils::parsePropertyChanges(oldProperties, newProperties, updatedProperties, removedProperties); |
211 | 383 | QVariantMap::ConstIterator newEnd = newProperties.constEnd(); | ||
212 | 384 | |||
213 | 385 | QVariantMap::ConstIterator | ||
214 | 386 | oldIt = oldProperties.constBegin(), | ||
215 | 387 | oldEnd = oldProperties.constEnd(); | ||
216 | 388 | for(; oldIt != oldEnd; ++oldIt) { | ||
217 | 389 | QString key = oldIt.key(); | ||
218 | 390 | QVariantMap::ConstIterator newIt = newProperties.constFind(key); | ||
219 | 391 | if (newIt != newEnd) { | ||
220 | 392 | if (newIt.value() != oldIt.value()) { | ||
221 | 393 | updatedProperties.insert(key, newIt.value()); | ||
222 | 394 | } | ||
223 | 395 | } else { | ||
224 | 396 | removedProperties << key; | ||
225 | 397 | } | ||
226 | 398 | } | ||
227 | 399 | |||
228 | 400 | // Find new properties (treat them as updated properties) | ||
229 | 401 | QVariantMap::ConstIterator newIt = newProperties.constBegin(); | ||
230 | 402 | for (; newIt != newEnd; ++newIt) { | ||
231 | 403 | QString key = newIt.key(); | ||
232 | 404 | oldIt = oldProperties.constFind(key); | ||
233 | 405 | if (oldIt == oldEnd) { | ||
234 | 406 | updatedProperties.insert(key, newIt.value()); | ||
235 | 407 | } | ||
236 | 408 | } | ||
238 | 409 | 383 | ||
239 | 410 | // Update our data (oldProperties is a reference) | 384 | // Update our data (oldProperties is a reference) |
240 | 411 | oldProperties = newProperties; | 385 | oldProperties = newProperties; |
241 | 412 | 386 | ||
242 | === modified file 'src/dbusmenuexporterdbus_p.cpp' | |||
243 | --- src/dbusmenuexporterdbus_p.cpp 2011-08-29 14:51:01 +0000 | |||
244 | +++ src/dbusmenuexporterdbus_p.cpp 2015-03-18 11:19:06 +0000 | |||
245 | @@ -21,26 +21,19 @@ | |||
246 | 21 | #include "dbusmenuexporterdbus_p.h" | 21 | #include "dbusmenuexporterdbus_p.h" |
247 | 22 | 22 | ||
248 | 23 | // Qt | 23 | // Qt |
250 | 24 | #include <QDBusMessage> | 24 | #include <QEvent> |
251 | 25 | #include <QMenu> | 25 | #include <QMenu> |
252 | 26 | #include <QVariant> | 26 | #include <QVariant> |
253 | 27 | 27 | ||
254 | 28 | // Local | 28 | // Local |
255 | 29 | #include "dbusmenuadaptor.h" | ||
256 | 30 | #include "dbusmenuexporterprivate_p.h" | 29 | #include "dbusmenuexporterprivate_p.h" |
257 | 31 | #include "dbusmenushortcut_p.h" | 30 | #include "dbusmenushortcut_p.h" |
258 | 32 | #include "debug_p.h" | 31 | #include "debug_p.h" |
259 | 33 | 32 | ||
267 | 34 | static const char *DBUSMENU_INTERFACE = "com.canonical.dbusmenu"; | 33 | DBusMenuExporterDBus::DBusMenuExporterDBus(const QString& objectPath, DBusMenuExporter *exporter) |
268 | 35 | static const char *FDO_PROPERTIES_INTERFACE = "org.freedesktop.DBus.Properties"; | 34 | : DBusMenuExporterDBusInterface(objectPath, exporter) |
269 | 36 | 35 | , m_exporter(exporter) | |
263 | 37 | DBusMenuExporterDBus::DBusMenuExporterDBus(DBusMenuExporter *exporter) | ||
264 | 38 | : QObject(exporter) | ||
265 | 39 | , m_exporter(exporter) | ||
266 | 40 | , m_status("normal") | ||
270 | 41 | { | 36 | { |
271 | 42 | DBusMenuTypes_register(); | ||
272 | 43 | new DbusmenuAdaptor(this); | ||
273 | 44 | } | 37 | } |
274 | 45 | 38 | ||
275 | 46 | uint DBusMenuExporterDBus::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) | 39 | uint DBusMenuExporterDBus::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) |
276 | @@ -157,30 +150,5 @@ | |||
277 | 157 | return filter.mChanged; | 150 | return filter.mChanged; |
278 | 158 | } | 151 | } |
279 | 159 | 152 | ||
280 | 160 | void DBusMenuExporterDBus::setStatus(const QString& status) | ||
281 | 161 | { | ||
282 | 162 | if (m_status == status) { | ||
283 | 163 | return; | ||
284 | 164 | } | ||
285 | 165 | m_status = status; | ||
286 | 166 | |||
287 | 167 | QVariantMap map; | ||
288 | 168 | map.insert("Status", QVariant(status)); | ||
289 | 169 | |||
290 | 170 | QDBusMessage msg = QDBusMessage::createSignal(m_exporter->d->m_objectPath, FDO_PROPERTIES_INTERFACE, "PropertiesChanged"); | ||
291 | 171 | QVariantList args = QVariantList() | ||
292 | 172 | << DBUSMENU_INTERFACE | ||
293 | 173 | << map | ||
294 | 174 | << QStringList() // New properties: none | ||
295 | 175 | ; | ||
296 | 176 | msg.setArguments(args); | ||
297 | 177 | QDBusConnection::sessionBus().send(msg); | ||
298 | 178 | } | ||
299 | 179 | |||
300 | 180 | QString DBusMenuExporterDBus::status() const | ||
301 | 181 | { | ||
302 | 182 | return m_status; | ||
303 | 183 | } | ||
304 | 184 | |||
305 | 185 | 153 | ||
306 | 186 | #include "dbusmenuexporterdbus_p.moc" | 154 | #include "dbusmenuexporterdbus_p.moc" |
307 | 187 | 155 | ||
308 | === modified file 'src/dbusmenuexporterdbus_p.h' | |||
309 | --- src/dbusmenuexporterdbus_p.h 2011-08-29 14:51:01 +0000 | |||
310 | +++ src/dbusmenuexporterdbus_p.h 2015-03-18 11:19:06 +0000 | |||
311 | @@ -22,50 +22,26 @@ | |||
312 | 22 | #define DBUSMENUEXPORTERDBUS_P_H | 22 | #define DBUSMENUEXPORTERDBUS_P_H |
313 | 23 | 23 | ||
314 | 24 | // Local | 24 | // Local |
322 | 25 | #include <dbusmenutypes_p.h> | 25 | #include "dbusmenuexporterdbusinterface_p.h" |
316 | 26 | |||
317 | 27 | // Qt | ||
318 | 28 | #include <QtCore/QObject> | ||
319 | 29 | #include <QtCore/QVariant> | ||
320 | 30 | #include <QtDBus/QDBusAbstractAdaptor> | ||
321 | 31 | #include <QtDBus/QDBusVariant> | ||
323 | 32 | 26 | ||
324 | 33 | class DBusMenuExporter; | 27 | class DBusMenuExporter; |
325 | 34 | 28 | ||
332 | 35 | /** | 29 | class DBusMenuExporterDBus : public DBusMenuExporterDBusInterface |
327 | 36 | * Internal class implementing the DBus side of DBusMenuExporter | ||
328 | 37 | * This avoid exposing the implementation of the DBusMenu spec to the outside | ||
329 | 38 | * world. | ||
330 | 39 | */ | ||
331 | 40 | class DBusMenuExporterDBus : public QObject | ||
333 | 41 | { | 30 | { |
334 | 42 | Q_OBJECT | 31 | Q_OBJECT |
335 | 43 | Q_CLASSINFO("D-Bus Interface", "com.canonical.dbusmenu") | 32 | Q_CLASSINFO("D-Bus Interface", "com.canonical.dbusmenu") |
336 | 44 | Q_PROPERTY(uint Version READ Version) | ||
337 | 45 | Q_PROPERTY(QString Status READ status) | ||
338 | 46 | public: | 33 | public: |
357 | 47 | DBusMenuExporterDBus(DBusMenuExporter *m_exporter); | 34 | DBusMenuExporterDBus(const QString& objectPath, DBusMenuExporter *m_exporter); |
358 | 48 | 35 | ||
359 | 49 | uint Version() const { return 2; } | 36 | public: // overrides |
360 | 50 | 37 | void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp) override; | |
361 | 51 | QString status() const; | 38 | QDBusVariant GetProperty(int id, const QString &property) override; |
362 | 52 | void setStatus(const QString &status); | 39 | uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) override; |
363 | 53 | 40 | DBusMenuItemList GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames) override; | |
364 | 54 | public Q_SLOTS: | 41 | bool AboutToShow(int id) override; |
347 | 55 | Q_NOREPLY void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp); | ||
348 | 56 | QDBusVariant GetProperty(int id, const QString &property); | ||
349 | 57 | uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item); | ||
350 | 58 | DBusMenuItemList GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames); | ||
351 | 59 | bool AboutToShow(int id); | ||
352 | 60 | |||
353 | 61 | Q_SIGNALS: | ||
354 | 62 | void ItemsPropertiesUpdated(DBusMenuItemList, DBusMenuItemKeysList); | ||
355 | 63 | void LayoutUpdated(uint revision, int parentId); | ||
356 | 64 | void ItemActivationRequested(int id, uint timeStamp); | ||
365 | 65 | 42 | ||
366 | 66 | private: | 43 | private: |
367 | 67 | DBusMenuExporter *m_exporter; | 44 | DBusMenuExporter *m_exporter; |
368 | 68 | QString m_status; | ||
369 | 69 | 45 | ||
370 | 70 | friend class DBusMenuExporter; | 46 | friend class DBusMenuExporter; |
371 | 71 | friend class DBusMenuExporterPrivate; | 47 | friend class DBusMenuExporterPrivate; |
372 | 72 | 48 | ||
373 | === added file 'src/dbusmenuexporterdbusinterface_p.cpp' | |||
374 | --- src/dbusmenuexporterdbusinterface_p.cpp 1970-01-01 00:00:00 +0000 | |||
375 | +++ src/dbusmenuexporterdbusinterface_p.cpp 2015-03-18 11:19:06 +0000 | |||
376 | @@ -0,0 +1,67 @@ | |||
377 | 1 | /* This file is part of the dbusmenu-qt library | ||
378 | 2 | Copyright 2015 Canonical | ||
379 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
380 | 4 | |||
381 | 5 | This library is free software; you can redistribute it and/or | ||
382 | 6 | modify it under the terms of the GNU Library General Public | ||
383 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
384 | 8 | either version 2 of the License, or (at your option) any later | ||
385 | 9 | version. | ||
386 | 10 | |||
387 | 11 | This library is distributed in the hope that it will be useful, | ||
388 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
389 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
390 | 14 | Library General Public License for more details. | ||
391 | 15 | |||
392 | 16 | You should have received a copy of the GNU Library General Public License | ||
393 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
394 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
395 | 19 | Boston, MA 02110-1301, USA. | ||
396 | 20 | */ | ||
397 | 21 | |||
398 | 22 | #include "dbusmenuexporterdbusinterface_p.h" | ||
399 | 23 | #include "dbusmenuadaptor.h" | ||
400 | 24 | |||
401 | 25 | // Qt | ||
402 | 26 | #include <QDBusMessage> | ||
403 | 27 | #include <QEvent> | ||
404 | 28 | |||
405 | 29 | static const char *DBUSMENU_INTERFACE = "com.canonical.dbusmenu"; | ||
406 | 30 | static const char *FDO_PROPERTIES_INTERFACE = "org.freedesktop.DBus.Properties"; | ||
407 | 31 | |||
408 | 32 | DBusMenuExporterDBusInterface::DBusMenuExporterDBusInterface(const QString& objectPath, QObject *parent) | ||
409 | 33 | : QObject(parent) | ||
410 | 34 | , m_objectPath(objectPath) | ||
411 | 35 | , m_status("normal") | ||
412 | 36 | { | ||
413 | 37 | DBusMenuTypes_register(); | ||
414 | 38 | |||
415 | 39 | new DbusmenuAdaptor(this); | ||
416 | 40 | QDBusConnection::sessionBus().registerObject(objectPath, this, QDBusConnection::ExportAllContents); | ||
417 | 41 | } | ||
418 | 42 | |||
419 | 43 | QString DBusMenuExporterDBusInterface::status() const | ||
420 | 44 | { | ||
421 | 45 | return m_status; | ||
422 | 46 | } | ||
423 | 47 | |||
424 | 48 | void DBusMenuExporterDBusInterface::setStatus(const QString& status) | ||
425 | 49 | { | ||
426 | 50 | if (m_status == status) { | ||
427 | 51 | return; | ||
428 | 52 | } | ||
429 | 53 | m_status = status; | ||
430 | 54 | |||
431 | 55 | QVariantMap map; | ||
432 | 56 | map.insert("Status", QVariant(status)); | ||
433 | 57 | |||
434 | 58 | QDBusMessage msg = QDBusMessage::createSignal(m_objectPath, FDO_PROPERTIES_INTERFACE, "PropertiesChanged"); | ||
435 | 59 | QVariantList args = QVariantList() | ||
436 | 60 | << DBUSMENU_INTERFACE | ||
437 | 61 | << map | ||
438 | 62 | << QStringList() // New properties: none | ||
439 | 63 | ; | ||
440 | 64 | msg.setArguments(args); | ||
441 | 65 | QDBusConnection::sessionBus().send(msg); | ||
442 | 66 | } | ||
443 | 67 | |||
444 | 0 | 68 | ||
445 | === added file 'src/dbusmenuexporterdbusinterface_p.h' | |||
446 | --- src/dbusmenuexporterdbusinterface_p.h 1970-01-01 00:00:00 +0000 | |||
447 | +++ src/dbusmenuexporterdbusinterface_p.h 2015-03-18 11:19:06 +0000 | |||
448 | @@ -0,0 +1,80 @@ | |||
449 | 1 | /* This file is part of the dbusmenu-qt library | ||
450 | 2 | Copyright 2015 Canonical | ||
451 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
452 | 4 | |||
453 | 5 | This library is free software; you can redistribute it and/or | ||
454 | 6 | modify it under the terms of the GNU Library General Public | ||
455 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
456 | 8 | either version 2 of the License, or (at your option) any later | ||
457 | 9 | version. | ||
458 | 10 | |||
459 | 11 | This library is distributed in the hope that it will be useful, | ||
460 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
461 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
462 | 14 | Library General Public License for more details. | ||
463 | 15 | |||
464 | 16 | You should have received a copy of the GNU Library General Public License | ||
465 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
466 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
467 | 19 | Boston, MA 02110-1301, USA. | ||
468 | 20 | */ | ||
469 | 21 | #ifndef DBUSMENUEXPORTERDBUSINTERFACE_P_H | ||
470 | 22 | #define DBUSMENUEXPORTERDBUSINTERFACE_P_H | ||
471 | 23 | |||
472 | 24 | // Local | ||
473 | 25 | #include <dbusmenutypes.h> | ||
474 | 26 | |||
475 | 27 | // Qt | ||
476 | 28 | #include <QtCore/QObject> | ||
477 | 29 | #include <QtCore/QVariant> | ||
478 | 30 | #include <QtDBus/QDBusAbstractAdaptor> | ||
479 | 31 | #include <QtDBus/QDBusVariant> | ||
480 | 32 | |||
481 | 33 | /** | ||
482 | 34 | * Internal class implementing the DBus side of DBusMenuExporter | ||
483 | 35 | * This avoid exposing the implementation of the DBusMenu spec to the outside | ||
484 | 36 | * world. | ||
485 | 37 | */ | ||
486 | 38 | class DBusMenuExporterDBusInterface : public QObject | ||
487 | 39 | { | ||
488 | 40 | Q_OBJECT | ||
489 | 41 | Q_CLASSINFO("D-Bus Interface", "com.canonical.dbusmenu") | ||
490 | 42 | Q_PROPERTY(uint Version READ Version) | ||
491 | 43 | Q_PROPERTY(QString Status READ status) | ||
492 | 44 | public: | ||
493 | 45 | DBusMenuExporterDBusInterface(const QString& objectPath, QObject* parent = nullptr); | ||
494 | 46 | uint Version() const { return 2; } | ||
495 | 47 | |||
496 | 48 | /** | ||
497 | 49 | * The status of the menu. Can be one of "normal" or "notice". This can be | ||
498 | 50 | * used to notify the other side the menu should be made more visible. | ||
499 | 51 | * For example, appmenu uses it to tell Unity panel to show/hide the menubar | ||
500 | 52 | * when the Alt modifier is pressed/released. | ||
501 | 53 | */ | ||
502 | 54 | QString status() const; | ||
503 | 55 | |||
504 | 56 | /** | ||
505 | 57 | * Returns the status of the menu. | ||
506 | 58 | * @ref setStatus | ||
507 | 59 | */ | ||
508 | 60 | void setStatus(const QString &status); | ||
509 | 61 | |||
510 | 62 | public Q_SLOTS: | ||
511 | 63 | virtual Q_NOREPLY void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp) = 0; | ||
512 | 64 | virtual QDBusVariant GetProperty(int id, const QString &property) = 0; | ||
513 | 65 | virtual uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) = 0; | ||
514 | 66 | virtual DBusMenuItemList GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames) = 0; | ||
515 | 67 | virtual bool AboutToShow(int id) = 0; | ||
516 | 68 | |||
517 | 69 | Q_SIGNALS: | ||
518 | 70 | void ItemsPropertiesUpdated(DBusMenuItemList, DBusMenuItemKeysList); | ||
519 | 71 | void LayoutUpdated(uint revision, int parentId); | ||
520 | 72 | void ItemActivationRequested(int id, uint timeStamp); | ||
521 | 73 | |||
522 | 74 | private: | ||
523 | 75 | QString m_objectPath; | ||
524 | 76 | QString m_status; | ||
525 | 77 | }; | ||
526 | 78 | |||
527 | 79 | |||
528 | 80 | #endif // DBUSMENUEXPORTERDBUSINTERFACE_P_H | ||
529 | 0 | 81 | ||
530 | === modified file 'src/dbusmenuexporterprivate_p.h' | |||
531 | --- src/dbusmenuexporterprivate_p.h 2012-03-29 14:23:32 +0000 | |||
532 | +++ src/dbusmenuexporterprivate_p.h 2015-03-18 11:19:06 +0000 | |||
533 | @@ -23,7 +23,7 @@ | |||
534 | 23 | 23 | ||
535 | 24 | // Local | 24 | // Local |
536 | 25 | #include "dbusmenuexporter.h" | 25 | #include "dbusmenuexporter.h" |
538 | 26 | #include "dbusmenutypes_p.h" | 26 | #include "dbusmenutypes.h" |
539 | 27 | 27 | ||
540 | 28 | // Qt | 28 | // Qt |
541 | 29 | #include <QtCore/QHash> | 29 | #include <QtCore/QHash> |
542 | 30 | 30 | ||
543 | === modified file 'src/dbusmenuimporter.cpp' | |||
544 | --- src/dbusmenuimporter.cpp 2014-03-05 09:53:39 +0000 | |||
545 | +++ src/dbusmenuimporter.cpp 2015-03-18 11:19:06 +0000 | |||
546 | @@ -36,7 +36,7 @@ | |||
547 | 36 | #include <QWidgetAction> | 36 | #include <QWidgetAction> |
548 | 37 | 37 | ||
549 | 38 | // Local | 38 | // Local |
551 | 39 | #include "dbusmenutypes_p.h" | 39 | #include "dbusmenutypes.h" |
552 | 40 | #include "dbusmenushortcut_p.h" | 40 | #include "dbusmenushortcut_p.h" |
553 | 41 | #include "debug_p.h" | 41 | #include "debug_p.h" |
554 | 42 | #include "utils_p.h" | 42 | #include "utils_p.h" |
555 | @@ -199,7 +199,7 @@ | |||
556 | 199 | 199 | ||
557 | 200 | void updateActionLabel(QAction *action, const QVariant &value) | 200 | void updateActionLabel(QAction *action, const QVariant &value) |
558 | 201 | { | 201 | { |
560 | 202 | QString text = swapMnemonicChar(value.toString(), '_', '&'); | 202 | QString text = Utils::swapMnemonicChar(value.toString(), '_', '&'); |
561 | 203 | action->setText(text); | 203 | action->setText(text); |
562 | 204 | } | 204 | } |
563 | 205 | 205 | ||
564 | 206 | 206 | ||
565 | === added file 'src/dbusmenuinterface.cpp' | |||
566 | --- src/dbusmenuinterface.cpp 1970-01-01 00:00:00 +0000 | |||
567 | +++ src/dbusmenuinterface.cpp 2015-03-18 11:19:06 +0000 | |||
568 | @@ -0,0 +1,63 @@ | |||
569 | 1 | #include "dbusmenuinterface.h" | ||
570 | 2 | #include "dbusmenuinterface_p.h" | ||
571 | 3 | |||
572 | 4 | DBusMenuInterface::DBusMenuInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) | ||
573 | 5 | : d(new DbusMenuInterfacePrivate(service, path, connection, this)) | ||
574 | 6 | { | ||
575 | 7 | DBusMenuTypes_register(); | ||
576 | 8 | } | ||
577 | 9 | |||
578 | 10 | uint DBusMenuInterface::version() const | ||
579 | 11 | { | ||
580 | 12 | return d->version(); | ||
581 | 13 | } | ||
582 | 14 | |||
583 | 15 | QString DBusMenuInterface::status() const | ||
584 | 16 | { | ||
585 | 17 | return d->status(); | ||
586 | 18 | } | ||
587 | 19 | |||
588 | 20 | bool DBusMenuInterface::isValid() const | ||
589 | 21 | { | ||
590 | 22 | return d->isValid(); | ||
591 | 23 | } | ||
592 | 24 | |||
593 | 25 | QString DBusMenuInterface::service() const | ||
594 | 26 | { | ||
595 | 27 | return d->service(); | ||
596 | 28 | } | ||
597 | 29 | |||
598 | 30 | QString DBusMenuInterface::path() const | ||
599 | 31 | { | ||
600 | 32 | return d->path(); | ||
601 | 33 | } | ||
602 | 34 | |||
603 | 35 | QDBusPendingReply<bool> DBusMenuInterface::AboutToShow(int id) | ||
604 | 36 | { | ||
605 | 37 | return d->AboutToShow(id); | ||
606 | 38 | } | ||
607 | 39 | |||
608 | 40 | QDBusPendingReply<> DBusMenuInterface::Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp) | ||
609 | 41 | { | ||
610 | 42 | return d->Event(id, eventId, data, timestamp); | ||
611 | 43 | } | ||
612 | 44 | |||
613 | 45 | QDBusPendingReply<DBusMenuItemList> DBusMenuInterface::GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames) | ||
614 | 46 | { | ||
615 | 47 | return d->GetGroupProperties(ids, propertyNames); | ||
616 | 48 | } | ||
617 | 49 | |||
618 | 50 | QDBusPendingReply<QDBusVariant> DBusMenuInterface::GetProperty(int id, const QString &name) | ||
619 | 51 | { | ||
620 | 52 | return d->GetProperty(id, name); | ||
621 | 53 | } | ||
622 | 54 | |||
623 | 55 | QDBusPendingReply<uint, DBusMenuLayoutItem> DBusMenuInterface::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames) | ||
624 | 56 | { | ||
625 | 57 | return d->GetLayout(parentId, recursionDepth, propertyNames); | ||
626 | 58 | } | ||
627 | 59 | |||
628 | 60 | QDBusReply<uint> DBusMenuInterface::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &layout) | ||
629 | 61 | { | ||
630 | 62 | return d->GetLayout(parentId, recursionDepth, propertyNames, layout); | ||
631 | 63 | } | ||
632 | 0 | 64 | ||
633 | === added file 'src/dbusmenuinterface.h' | |||
634 | --- src/dbusmenuinterface.h 1970-01-01 00:00:00 +0000 | |||
635 | +++ src/dbusmenuinterface.h 2015-03-18 11:19:06 +0000 | |||
636 | @@ -0,0 +1,154 @@ | |||
637 | 1 | /* This file is part of the dbusmenu-qt library | ||
638 | 2 | Copyright 2015 Canonical | ||
639 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
640 | 4 | |||
641 | 5 | This library is free software; you can redistribute it and/or | ||
642 | 6 | modify it under the terms of the GNU Library General Public | ||
643 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
644 | 8 | either version 2 of the License, or (at your option) any later | ||
645 | 9 | version. | ||
646 | 10 | |||
647 | 11 | This library is distributed in the hope that it will be useful, | ||
648 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
649 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
650 | 14 | Library General Public License for more details. | ||
651 | 15 | |||
652 | 16 | You should have received a copy of the GNU Library General Public License | ||
653 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
654 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
655 | 19 | Boston, MA 02110-1301, USA. | ||
656 | 20 | */ | ||
657 | 21 | #ifndef DBUSMENUINTERFACE_H | ||
658 | 22 | #define DBUSMENUINTERFACE_H | ||
659 | 23 | |||
660 | 24 | // Local | ||
661 | 25 | #include <dbusmenutypes.h> | ||
662 | 26 | class DbusMenuInterfacePrivate; | ||
663 | 27 | |||
664 | 28 | // Qt | ||
665 | 29 | #include <QtCore/QObject> | ||
666 | 30 | #include <QtDBus/QtDBus> | ||
667 | 31 | |||
668 | 32 | /** | ||
669 | 33 | * Internal class implementing the DBus side of DBusMenuExporter | ||
670 | 34 | * This avoid exposing the implementation of the DBusMenu spec to the outside | ||
671 | 35 | * world. | ||
672 | 36 | */ | ||
673 | 37 | class DBUSMENU_EXPORT DBusMenuInterface : public QObject | ||
674 | 38 | { | ||
675 | 39 | Q_OBJECT | ||
676 | 40 | |||
677 | 41 | /** | ||
678 | 42 | * Version of the menu interface. | ||
679 | 43 | */ | ||
680 | 44 | Q_PROPERTY(uint Version READ version) | ||
681 | 45 | |||
682 | 46 | /** | ||
683 | 47 | * Status of the menu. | ||
684 | 48 | */ | ||
685 | 49 | Q_PROPERTY(QString Status READ status) | ||
686 | 50 | public: | ||
687 | 51 | /** | ||
688 | 52 | * Creates a DBusMenuInterface on specified service, path & connection | ||
689 | 53 | */ | ||
690 | 54 | DBusMenuInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject* parent = nullptr); | ||
691 | 55 | |||
692 | 56 | /** | ||
693 | 57 | * Returns the version of the menu interface. | ||
694 | 58 | */ | ||
695 | 59 | uint version() const; | ||
696 | 60 | |||
697 | 61 | /** | ||
698 | 62 | * The status of the menu. Can be one of "normal" or "notice". This can be | ||
699 | 63 | * used to notify the other side the menu should be made more visible. | ||
700 | 64 | * For example, appmenu uses it to tell Unity panel to show/hide the menubar | ||
701 | 65 | * when the Alt modifier is pressed/released. | ||
702 | 66 | */ | ||
703 | 67 | QString status() const; | ||
704 | 68 | |||
705 | 69 | /** | ||
706 | 70 | * Returns true if this is a valid reference to a remote object. | ||
707 | 71 | * It returns false if there was an error during the creation of the interface | ||
708 | 72 | */ | ||
709 | 73 | bool isValid() const; | ||
710 | 74 | |||
711 | 75 | /** | ||
712 | 76 | * Returns the name of the service this interface is associated with. | ||
713 | 77 | */ | ||
714 | 78 | QString service() const; | ||
715 | 79 | |||
716 | 80 | /** | ||
717 | 81 | * Returns the object path that this interface is associated with. | ||
718 | 82 | */ | ||
719 | 83 | QString path() const; | ||
720 | 84 | |||
721 | 85 | public Q_SLOTS: | ||
722 | 86 | /** | ||
723 | 87 | * This is called to notify the application that it is about | ||
724 | 88 | * to show the menu under the specified item. | ||
725 | 89 | */ | ||
726 | 90 | QDBusPendingReply<bool> AboutToShow(int id); | ||
727 | 91 | |||
728 | 92 | /** | ||
729 | 93 | * This is called by the applet to notify the application an event happened on a | ||
730 | 94 | * menu item. | ||
731 | 95 | */ | ||
732 | 96 | QDBusPendingReply<> Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp); | ||
733 | 97 | |||
734 | 98 | /** | ||
735 | 99 | * Returns the list of items which are children of @p parentId. | ||
736 | 100 | */ | ||
737 | 101 | QDBusPendingReply<DBusMenuItemList> GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames); | ||
738 | 102 | |||
739 | 103 | /** | ||
740 | 104 | * Get a signal property on a single item. This is not useful if you're | ||
741 | 105 | * going to implement this interface, it should only be used if you're | ||
742 | 106 | * debugging via a commandline tool. | ||
743 | 107 | */ | ||
744 | 108 | QDBusPendingReply<QDBusVariant> GetProperty(int id, const QString &name); | ||
745 | 109 | |||
746 | 110 | /** | ||
747 | 111 | * Provides the layout and propertiers that are attached to the entries | ||
748 | 112 | * that are in the layout. It only gives the items that are children | ||
749 | 113 | * of the item that is specified in @p parentId. It will return all of the | ||
750 | 114 | * properties or specific ones depending of the value in @p propertyNames. | ||
751 | 115 | */ | ||
752 | 116 | QDBusPendingReply<uint, DBusMenuLayoutItem> GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames); | ||
753 | 117 | |||
754 | 118 | /** | ||
755 | 119 | * Provides the layout and propertiers that are attached to the entries | ||
756 | 120 | * that are in the layout. It only gives the items that are children | ||
757 | 121 | * of the item that is specified in @p parentId. It will return all of the | ||
758 | 122 | * properties or specific ones depending of the value @p propertyNames. | ||
759 | 123 | */ | ||
760 | 124 | QDBusReply<uint> GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &layout); | ||
761 | 125 | |||
762 | 126 | Q_SIGNALS: // SIGNALS | ||
763 | 127 | /** | ||
764 | 128 | * The server is requesting that all clients displaying this | ||
765 | 129 | * menu open it to the user. This would be for things like | ||
766 | 130 | * hotkeys that when the user presses them the menu should | ||
767 | 131 | * open and display itself to the user. | ||
768 | 132 | */ | ||
769 | 133 | void ItemActivationRequested(int id, uint timestamp); | ||
770 | 134 | |||
771 | 135 | /** | ||
772 | 136 | * Triggered when there are lots of property updates across many items | ||
773 | 137 | * so they all get grouped into a single dbus message. The format is | ||
774 | 138 | * the ID of the item with a hashtable of names and values for those | ||
775 | 139 | * properties. | ||
776 | 140 | */ | ||
777 | 141 | void ItemsPropertiesUpdated(DBusMenuItemList updatedProps, DBusMenuItemKeysList removedProps); | ||
778 | 142 | |||
779 | 143 | /** | ||
780 | 144 | * Triggered by the application to notify display of a layout update, up to | ||
781 | 145 | * revision | ||
782 | 146 | */ | ||
783 | 147 | void LayoutUpdated(uint revision, int parent); | ||
784 | 148 | |||
785 | 149 | private: | ||
786 | 150 | DbusMenuInterfacePrivate* d; | ||
787 | 151 | }; | ||
788 | 152 | |||
789 | 153 | |||
790 | 154 | #endif // DBUSMENUINTERFACE_H | ||
791 | 0 | 155 | ||
792 | === added file 'src/dbusmenuproperty.h' | |||
793 | --- src/dbusmenuproperty.h 1970-01-01 00:00:00 +0000 | |||
794 | +++ src/dbusmenuproperty.h 2015-03-18 11:19:06 +0000 | |||
795 | @@ -0,0 +1,78 @@ | |||
796 | 1 | #ifndef DBUSMENUPROPERTY_H | ||
797 | 2 | #define DBUSMENUPROPERTY_H | ||
798 | 3 | |||
799 | 4 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | ||
800 | 5 | |||
801 | 6 | // Qt | ||
802 | 7 | #include <QtCore/QVariantMap> | ||
803 | 8 | |||
804 | 9 | // Local | ||
805 | 10 | #include <dbusmenu_export.h> | ||
806 | 11 | |||
807 | 12 | class QKeySequence; | ||
808 | 13 | class QByteArray; | ||
809 | 14 | class QString; | ||
810 | 15 | |||
811 | 16 | //// DBusMenuProperty | ||
812 | 17 | /** | ||
813 | 18 | * Structure which contains the names of the common properties | ||
814 | 19 | * for a menu item. | ||
815 | 20 | */ | ||
816 | 21 | struct DBUSMENU_EXPORT DBusMenuProperty | ||
817 | 22 | { | ||
818 | 23 | static const char* Type; | ||
819 | 24 | static const char* Label; | ||
820 | 25 | static const char* Enabled; | ||
821 | 26 | static const char* Visible; | ||
822 | 27 | static const char* IconName; | ||
823 | 28 | static const char* IconData; | ||
824 | 29 | static const char* Shortcut; | ||
825 | 30 | static const char* ToggleType; | ||
826 | 31 | static const char* ToggleState; | ||
827 | 32 | static const char* ChildrenDisplay; | ||
828 | 33 | }; | ||
829 | 34 | |||
830 | 35 | //// DBusMenuProperties | ||
831 | 36 | /** | ||
832 | 37 | * A map of properties for the dbus with easy accessors for | ||
833 | 38 | * the common properties | ||
834 | 39 | */ | ||
835 | 40 | struct DBUSMENU_EXPORT DBusMenuProperties: public QVariantMap | ||
836 | 41 | { | ||
837 | 42 | QString type() const; | ||
838 | 43 | void setType(const QString&); | ||
839 | 44 | |||
840 | 45 | QString label() const; | ||
841 | 46 | void setLabel(const QString&); | ||
842 | 47 | |||
843 | 48 | bool enabled() const; | ||
844 | 49 | void setEnabled(bool); | ||
845 | 50 | |||
846 | 51 | bool visible() const; | ||
847 | 52 | void setVisible(bool); | ||
848 | 53 | |||
849 | 54 | QString iconName() const; | ||
850 | 55 | void setIconName(const QString&); | ||
851 | 56 | |||
852 | 57 | QByteArray iconData() const; | ||
853 | 58 | void setIconData(const QByteArray&); | ||
854 | 59 | |||
855 | 60 | QKeySequence shortcut() const; | ||
856 | 61 | void setShortcut(const QKeySequence&); | ||
857 | 62 | |||
858 | 63 | QString toggleType() const; | ||
859 | 64 | void setToggleType(const QString&); | ||
860 | 65 | |||
861 | 66 | int toggleState() const; | ||
862 | 67 | void setToggleState(int); | ||
863 | 68 | |||
864 | 69 | bool childrenDisplay() const; | ||
865 | 70 | void setChildrenDisplay(bool); | ||
866 | 71 | |||
867 | 72 | DBusMenuProperties& operator=(const QVariantMap& rhs); | ||
868 | 73 | }; | ||
869 | 74 | |||
870 | 75 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ | ||
871 | 76 | |||
872 | 77 | |||
873 | 78 | #endif // DBUSMENUPROPERTY_H | ||
874 | 0 | 79 | ||
875 | === modified file 'src/dbusmenushortcut_p.cpp' | |||
876 | --- src/dbusmenushortcut_p.cpp 2011-04-12 09:12:18 +0000 | |||
877 | +++ src/dbusmenushortcut_p.cpp 2015-03-18 11:19:06 +0000 | |||
878 | @@ -44,6 +44,8 @@ | |||
879 | 44 | // cf https://bugs.launchpad.net/libdbusmenu-qt/+bug/712565 | 44 | // cf https://bugs.launchpad.net/libdbusmenu-qt/+bug/712565 |
880 | 45 | {"+", "plus"}, | 45 | {"+", "plus"}, |
881 | 46 | {"-", "minus"}, | 46 | {"-", "minus"}, |
882 | 47 | {"+", "KP_Add"}, | ||
883 | 48 | {"-", "KP_Subtract"}, | ||
884 | 47 | {0, 0} | 49 | {0, 0} |
885 | 48 | }; | 50 | }; |
886 | 49 | 51 | ||
887 | 50 | 52 | ||
888 | === renamed file 'src/dbusmenutypes_p.cpp' => 'src/dbusmenutypes.cpp' | |||
889 | --- src/dbusmenutypes_p.cpp 2011-02-23 13:23:56 +0000 | |||
890 | +++ src/dbusmenutypes.cpp 2015-03-18 11:19:06 +0000 | |||
891 | @@ -18,7 +18,7 @@ | |||
892 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
893 | 19 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. |
894 | 20 | */ | 20 | */ |
896 | 21 | #include "dbusmenutypes_p.h" | 21 | #include "dbusmenutypes.h" |
897 | 22 | 22 | ||
898 | 23 | // Local | 23 | // Local |
899 | 24 | #include <dbusmenushortcut_p.h> | 24 | #include <dbusmenushortcut_p.h> |
900 | @@ -27,6 +27,18 @@ | |||
901 | 27 | // Qt | 27 | // Qt |
902 | 28 | #include <QDBusArgument> | 28 | #include <QDBusArgument> |
903 | 29 | #include <QDBusMetaType> | 29 | #include <QDBusMetaType> |
904 | 30 | #include <QKeySequence> | ||
905 | 31 | |||
906 | 32 | const char* DBusMenuProperty::Type = "type"; | ||
907 | 33 | const char* DBusMenuProperty::Label = "label"; | ||
908 | 34 | const char* DBusMenuProperty::Enabled = "enabled"; | ||
909 | 35 | const char* DBusMenuProperty::Visible = "visible"; | ||
910 | 36 | const char* DBusMenuProperty::IconName = "icon-name"; | ||
911 | 37 | const char* DBusMenuProperty::IconData = "icon-data"; | ||
912 | 38 | const char* DBusMenuProperty::Shortcut = "shortcut"; | ||
913 | 39 | const char* DBusMenuProperty::ToggleType = "toggle-type"; | ||
914 | 40 | const char* DBusMenuProperty::ToggleState = "toggle-state"; | ||
915 | 41 | const char* DBusMenuProperty::ChildrenDisplay = "children-display"; | ||
916 | 30 | 42 | ||
917 | 31 | //// DBusMenuItem | 43 | //// DBusMenuItem |
918 | 32 | QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &obj) | 44 | QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &obj) |
919 | @@ -95,6 +107,16 @@ | |||
920 | 95 | return argument; | 107 | return argument; |
921 | 96 | } | 108 | } |
922 | 97 | 109 | ||
923 | 110 | bool operator==(const DBusMenuLayoutItem& lhs, const DBusMenuLayoutItem& rhs) | ||
924 | 111 | { | ||
925 | 112 | return lhs.id == rhs.id && lhs.properties == rhs.properties && lhs.children == rhs.children; | ||
926 | 113 | } | ||
927 | 114 | |||
928 | 115 | bool operator!=(const DBusMenuLayoutItem& lhs, const DBusMenuLayoutItem& rhs) | ||
929 | 116 | { | ||
930 | 117 | return !(lhs == rhs); | ||
931 | 118 | } | ||
932 | 119 | |||
933 | 98 | void DBusMenuTypes_register() | 120 | void DBusMenuTypes_register() |
934 | 99 | { | 121 | { |
935 | 100 | static bool registered = false; | 122 | static bool registered = false; |
936 | @@ -110,3 +132,122 @@ | |||
937 | 110 | qDBusRegisterMetaType<DBusMenuShortcut>(); | 132 | qDBusRegisterMetaType<DBusMenuShortcut>(); |
938 | 111 | registered = true; | 133 | registered = true; |
939 | 112 | } | 134 | } |
940 | 135 | |||
941 | 136 | QString DBusMenuProperties::type() const | ||
942 | 137 | { | ||
943 | 138 | return value(DBusMenuProperty::Type, "standard").toString(); | ||
944 | 139 | } | ||
945 | 140 | |||
946 | 141 | void DBusMenuProperties::setType(const QString &type) | ||
947 | 142 | { | ||
948 | 143 | insert(DBusMenuProperty::Type, type); | ||
949 | 144 | } | ||
950 | 145 | |||
951 | 146 | QString DBusMenuProperties::label() const | ||
952 | 147 | { | ||
953 | 148 | return value(DBusMenuProperty::Label, "").toString(); | ||
954 | 149 | } | ||
955 | 150 | |||
956 | 151 | void DBusMenuProperties::setLabel(const QString &label) | ||
957 | 152 | { | ||
958 | 153 | insert(DBusMenuProperty::Label, label); | ||
959 | 154 | } | ||
960 | 155 | |||
961 | 156 | bool DBusMenuProperties::enabled() const | ||
962 | 157 | { | ||
963 | 158 | return value(DBusMenuProperty::Enabled, true).toBool(); | ||
964 | 159 | } | ||
965 | 160 | |||
966 | 161 | void DBusMenuProperties::setEnabled(bool enabled) | ||
967 | 162 | { | ||
968 | 163 | insert(DBusMenuProperty::Enabled, enabled); | ||
969 | 164 | } | ||
970 | 165 | |||
971 | 166 | bool DBusMenuProperties::visible() const | ||
972 | 167 | { | ||
973 | 168 | return value(DBusMenuProperty::Visible, true).toBool(); | ||
974 | 169 | } | ||
975 | 170 | |||
976 | 171 | void DBusMenuProperties::setVisible(bool enabled) | ||
977 | 172 | { | ||
978 | 173 | insert(DBusMenuProperty::Visible, enabled); | ||
979 | 174 | } | ||
980 | 175 | |||
981 | 176 | QString DBusMenuProperties::iconName() const | ||
982 | 177 | { | ||
983 | 178 | return value(DBusMenuProperty::IconName, "").toString(); | ||
984 | 179 | } | ||
985 | 180 | |||
986 | 181 | void DBusMenuProperties::setIconName(const QString &iconName) | ||
987 | 182 | { | ||
988 | 183 | insert(DBusMenuProperty::IconName, iconName); | ||
989 | 184 | } | ||
990 | 185 | |||
991 | 186 | QByteArray DBusMenuProperties::iconData() const | ||
992 | 187 | { | ||
993 | 188 | return value(DBusMenuProperty::IconData, QVariant()).toByteArray(); | ||
994 | 189 | } | ||
995 | 190 | |||
996 | 191 | void DBusMenuProperties::setIconData(const QByteArray &iconData) | ||
997 | 192 | { | ||
998 | 193 | insert(DBusMenuProperty::IconData, iconData); | ||
999 | 194 | } | ||
1000 | 195 | |||
1001 | 196 | QKeySequence DBusMenuProperties::shortcut() const | ||
1002 | 197 | { | ||
1003 | 198 | QKeySequence seq; | ||
1004 | 199 | |||
1005 | 200 | QVariant var = value(DBusMenuProperty::Shortcut, QVariant()); | ||
1006 | 201 | |||
1007 | 202 | if (var.userType() == qMetaTypeId<QDBusArgument>()) { | ||
1008 | 203 | QDBusArgument arg = var.value<QDBusArgument>(); | ||
1009 | 204 | |||
1010 | 205 | DBusMenuShortcut shortcut; | ||
1011 | 206 | arg >> shortcut; | ||
1012 | 207 | |||
1013 | 208 | return shortcut.toKeySequence(); | ||
1014 | 209 | } | ||
1015 | 210 | return seq; | ||
1016 | 211 | } | ||
1017 | 212 | |||
1018 | 213 | void DBusMenuProperties::setShortcut(const QKeySequence &keySequence) | ||
1019 | 214 | { | ||
1020 | 215 | insert(DBusMenuProperty::Shortcut, keySequence); | ||
1021 | 216 | } | ||
1022 | 217 | |||
1023 | 218 | QString DBusMenuProperties::toggleType() const | ||
1024 | 219 | { | ||
1025 | 220 | return value(DBusMenuProperty::ToggleType, "").toString(); | ||
1026 | 221 | } | ||
1027 | 222 | |||
1028 | 223 | void DBusMenuProperties::setToggleType(const QString &toggleType) | ||
1029 | 224 | { | ||
1030 | 225 | insert(DBusMenuProperty::ToggleType, toggleType); | ||
1031 | 226 | } | ||
1032 | 227 | |||
1033 | 228 | int DBusMenuProperties::toggleState() const | ||
1034 | 229 | { | ||
1035 | 230 | return value(DBusMenuProperty::ToggleState, -1).toInt(); | ||
1036 | 231 | } | ||
1037 | 232 | |||
1038 | 233 | void DBusMenuProperties::setToggleState(int toggleType) | ||
1039 | 234 | { | ||
1040 | 235 | insert(DBusMenuProperty::ToggleState, toggleType); | ||
1041 | 236 | } | ||
1042 | 237 | |||
1043 | 238 | bool DBusMenuProperties::childrenDisplay() const | ||
1044 | 239 | { | ||
1045 | 240 | return value(DBusMenuProperty::ChildrenDisplay, false).toBool(); | ||
1046 | 241 | } | ||
1047 | 242 | |||
1048 | 243 | void DBusMenuProperties::setChildrenDisplay(bool childrenDisplay) | ||
1049 | 244 | { | ||
1050 | 245 | insert(DBusMenuProperty::ChildrenDisplay, childrenDisplay); | ||
1051 | 246 | |||
1052 | 247 | } | ||
1053 | 248 | |||
1054 | 249 | DBusMenuProperties &DBusMenuProperties::operator=(const QVariantMap &rhs) | ||
1055 | 250 | { | ||
1056 | 251 | QVariantMap::operator=(rhs); | ||
1057 | 252 | return *this; | ||
1058 | 253 | } | ||
1059 | 113 | 254 | ||
1060 | === renamed file 'src/dbusmenutypes_p.h' => 'src/dbusmenutypes.h' | |||
1061 | --- src/dbusmenutypes_p.h 2011-02-23 13:23:56 +0000 | |||
1062 | +++ src/dbusmenutypes.h 2015-03-18 11:19:06 +0000 | |||
1063 | @@ -18,8 +18,8 @@ | |||
1064 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
1065 | 19 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. |
1066 | 20 | */ | 20 | */ |
1069 | 21 | #ifndef DBUSMENUTYPES_P_H | 21 | #ifndef DBUSMENUTYPES_H |
1070 | 22 | #define DBUSMENUTYPES_P_H | 22 | #define DBUSMENUTYPES_H |
1071 | 23 | 23 | ||
1072 | 24 | // Qt | 24 | // Qt |
1073 | 25 | #include <QtCore/QList> | 25 | #include <QtCore/QList> |
1074 | @@ -28,6 +28,7 @@ | |||
1075 | 28 | 28 | ||
1076 | 29 | // Local | 29 | // Local |
1077 | 30 | #include <dbusmenu_export.h> | 30 | #include <dbusmenu_export.h> |
1078 | 31 | #include <dbusmenuproperty.h> | ||
1079 | 31 | 32 | ||
1080 | 32 | class QDBusArgument; | 33 | class QDBusArgument; |
1081 | 33 | 34 | ||
1082 | @@ -37,8 +38,11 @@ | |||
1083 | 37 | */ | 38 | */ |
1084 | 38 | struct DBUSMENU_EXPORT DBusMenuItem | 39 | struct DBUSMENU_EXPORT DBusMenuItem |
1085 | 39 | { | 40 | { |
1086 | 41 | /// Id of the menu item | ||
1087 | 40 | int id; | 42 | int id; |
1089 | 41 | QVariantMap properties; | 43 | |
1090 | 44 | /// Properties for the menu item | ||
1091 | 45 | DBusMenuProperties properties; | ||
1092 | 42 | }; | 46 | }; |
1093 | 43 | 47 | ||
1094 | 44 | Q_DECLARE_METATYPE(DBusMenuItem) | 48 | Q_DECLARE_METATYPE(DBusMenuItem) |
1095 | @@ -57,7 +61,10 @@ | |||
1096 | 57 | */ | 61 | */ |
1097 | 58 | struct DBUSMENU_EXPORT DBusMenuItemKeys | 62 | struct DBUSMENU_EXPORT DBusMenuItemKeys |
1098 | 59 | { | 63 | { |
1099 | 64 | /// Id of the menu item | ||
1100 | 60 | int id; | 65 | int id; |
1101 | 66 | |||
1102 | 67 | /// Properties for the menu item | ||
1103 | 61 | QStringList properties; | 68 | QStringList properties; |
1104 | 62 | }; | 69 | }; |
1105 | 63 | 70 | ||
1106 | @@ -75,11 +82,15 @@ | |||
1107 | 75 | * Represents an item with its children. GetLayout() returns a | 82 | * Represents an item with its children. GetLayout() returns a |
1108 | 76 | * DBusMenuLayoutItemList. | 83 | * DBusMenuLayoutItemList. |
1109 | 77 | */ | 84 | */ |
1110 | 78 | struct DBusMenuLayoutItem; | ||
1111 | 79 | struct DBUSMENU_EXPORT DBusMenuLayoutItem | 85 | struct DBUSMENU_EXPORT DBusMenuLayoutItem |
1112 | 80 | { | 86 | { |
1113 | 87 | /// Id of the menu item | ||
1114 | 81 | int id; | 88 | int id; |
1116 | 82 | QVariantMap properties; | 89 | |
1117 | 90 | /// Id of the menu item | ||
1118 | 91 | DBusMenuProperties properties; | ||
1119 | 92 | |||
1120 | 93 | /// Children of the menu item | ||
1121 | 83 | QList<DBusMenuLayoutItem> children; | 94 | QList<DBusMenuLayoutItem> children; |
1122 | 84 | }; | 95 | }; |
1123 | 85 | 96 | ||
1124 | @@ -88,9 +99,13 @@ | |||
1125 | 88 | DBUSMENU_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &); | 99 | DBUSMENU_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &); |
1126 | 89 | DBUSMENU_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &); | 100 | DBUSMENU_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &); |
1127 | 90 | 101 | ||
1128 | 102 | DBUSMENU_EXPORT bool operator==(const DBusMenuLayoutItem& lhs, const DBusMenuLayoutItem& rhs); | ||
1129 | 103 | DBUSMENU_EXPORT bool operator!=(const DBusMenuLayoutItem& lhs, const DBusMenuLayoutItem& rhs); | ||
1130 | 104 | |||
1131 | 91 | typedef QList<DBusMenuLayoutItem> DBusMenuLayoutItemList; | 105 | typedef QList<DBusMenuLayoutItem> DBusMenuLayoutItemList; |
1132 | 92 | 106 | ||
1133 | 93 | Q_DECLARE_METATYPE(DBusMenuLayoutItemList) | 107 | Q_DECLARE_METATYPE(DBusMenuLayoutItemList) |
1134 | 94 | 108 | ||
1135 | 95 | void DBusMenuTypes_register(); | 109 | void DBusMenuTypes_register(); |
1136 | 110 | |||
1137 | 96 | #endif /* DBUSMENUTYPES_P_H */ | 111 | #endif /* DBUSMENUTYPES_P_H */ |
1138 | 97 | 112 | ||
1139 | === added directory 'src/qpa' | |||
1140 | === added file 'src/qpa/exportedplatformmenubar.cpp' | |||
1141 | --- src/qpa/exportedplatformmenubar.cpp 1970-01-01 00:00:00 +0000 | |||
1142 | +++ src/qpa/exportedplatformmenubar.cpp 2015-03-18 11:19:06 +0000 | |||
1143 | @@ -0,0 +1,377 @@ | |||
1144 | 1 | /* This file is part of the dbusmenu-qt library | ||
1145 | 2 | Copyright 2015 Canonical | ||
1146 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
1147 | 4 | |||
1148 | 5 | This library is free software; you can redistribute it and/or | ||
1149 | 6 | modify it under the terms of the GNU Library General Public | ||
1150 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
1151 | 8 | either version 2 of the License, or (at your option) any later | ||
1152 | 9 | version. | ||
1153 | 10 | |||
1154 | 11 | This library is distributed in the hope that it will be useful, | ||
1155 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1156 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1157 | 14 | Library General Public License for more details. | ||
1158 | 15 | |||
1159 | 16 | You should have received a copy of the GNU Library General Public License | ||
1160 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1161 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1162 | 19 | Boston, MA 02110-1301, USA. | ||
1163 | 20 | */ | ||
1164 | 21 | |||
1165 | 22 | // Local | ||
1166 | 23 | #include "exportedplatformmenubar.h" | ||
1167 | 24 | #include "exportedplatformmenubar_p.h" | ||
1168 | 25 | #include "qpadbusmenuexporter_p.h" | ||
1169 | 26 | #include "logging_p.h" | ||
1170 | 27 | |||
1171 | 28 | // Qt | ||
1172 | 29 | #include <QWindow> | ||
1173 | 30 | #include <QWidget> | ||
1174 | 31 | |||
1175 | 32 | #define MENU_ID(x) (qobject_cast<ExportedPlatformMenu*>(x) ? qobject_cast<ExportedPlatformMenu*>(x)->id() : -1) | ||
1176 | 33 | #define MENU_ITEM_ID(x) (qobject_cast<ExportedPlatformMenuItem*>(x) ? qobject_cast<ExportedPlatformMenuItem*>(x)->id() : -1) | ||
1177 | 34 | |||
1178 | 35 | ExportedPlatformMenuBar::ExportedPlatformMenuBar(const QString& exportPath) | ||
1179 | 36 | : d(new ExportedPlatformMenuBarPrivate) | ||
1180 | 37 | { | ||
1181 | 38 | LOG; | ||
1182 | 39 | |||
1183 | 40 | d->m_objectPath = exportPath; | ||
1184 | 41 | new QPADBusMenuExporter(exportPath, this); | ||
1185 | 42 | } | ||
1186 | 43 | |||
1187 | 44 | ExportedPlatformMenuBar::~ExportedPlatformMenuBar() | ||
1188 | 45 | { | ||
1189 | 46 | LOG; | ||
1190 | 47 | } | ||
1191 | 48 | |||
1192 | 49 | QString ExportedPlatformMenuBar::exportedPath() const | ||
1193 | 50 | { | ||
1194 | 51 | return d->m_objectPath; | ||
1195 | 52 | } | ||
1196 | 53 | |||
1197 | 54 | void | ||
1198 | 55 | ExportedPlatformMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before) | ||
1199 | 56 | { | ||
1200 | 57 | LOG << MENU_ID(menu) << " before:" << before; | ||
1201 | 58 | |||
1202 | 59 | if (!before) { | ||
1203 | 60 | d->m_menus.push_back(menu); | ||
1204 | 61 | } else { | ||
1205 | 62 | for (auto iter = d->m_menus.begin(); iter != d->m_menus.end(); ++iter) { | ||
1206 | 63 | if (*iter == before) { | ||
1207 | 64 | d->m_menus.insert(iter, menu); | ||
1208 | 65 | break; | ||
1209 | 66 | } | ||
1210 | 67 | } | ||
1211 | 68 | } | ||
1212 | 69 | |||
1213 | 70 | Q_EMIT menuInserted(menu); | ||
1214 | 71 | } | ||
1215 | 72 | |||
1216 | 73 | void | ||
1217 | 74 | ExportedPlatformMenuBar::removeMenu(QPlatformMenu *menu) | ||
1218 | 75 | { | ||
1219 | 76 | LOG << menu; | ||
1220 | 77 | |||
1221 | 78 | for (auto iter = d->m_menus.begin(); iter != d->m_menus.end(); ++iter) { | ||
1222 | 79 | if (*iter == menu) { | ||
1223 | 80 | iter = d->m_menus.erase(iter); | ||
1224 | 81 | } | ||
1225 | 82 | } | ||
1226 | 83 | |||
1227 | 84 | Q_EMIT menuRemoved(menu); | ||
1228 | 85 | } | ||
1229 | 86 | |||
1230 | 87 | void | ||
1231 | 88 | ExportedPlatformMenuBar::syncMenu(QPlatformMenu *menu) | ||
1232 | 89 | { | ||
1233 | 90 | LOG_VAR(menu); | ||
1234 | 91 | QMetaObject::invokeMethod(menu, "propertyUpdated"); | ||
1235 | 92 | } | ||
1236 | 93 | |||
1237 | 94 | void | ||
1238 | 95 | ExportedPlatformMenuBar::handleReparent(QWindow *newParentWindow) | ||
1239 | 96 | { | ||
1240 | 97 | LOG_VAR(newParentWindow); | ||
1241 | 98 | } | ||
1242 | 99 | |||
1243 | 100 | QPlatformMenu * | ||
1244 | 101 | ExportedPlatformMenuBar::menuForTag(quintptr tag) const | ||
1245 | 102 | { | ||
1246 | 103 | for (auto iter = d->m_menus.begin(); iter != d->m_menus.end(); ++iter) { | ||
1247 | 104 | if ((*iter)->tag() == tag) { | ||
1248 | 105 | return *iter; | ||
1249 | 106 | } | ||
1250 | 107 | } | ||
1251 | 108 | return nullptr; | ||
1252 | 109 | } | ||
1253 | 110 | |||
1254 | 111 | QPlatformMenu * | ||
1255 | 112 | ExportedPlatformMenuBar::menuAt(int position) const | ||
1256 | 113 | { | ||
1257 | 114 | if (position < 0 || position >= d->m_menus.count()) return nullptr; | ||
1258 | 115 | return d->m_menus.at(position); | ||
1259 | 116 | } | ||
1260 | 117 | |||
1261 | 118 | uint ExportedPlatformMenuBar::menuCount() | ||
1262 | 119 | { | ||
1263 | 120 | return d->m_menus.count(); | ||
1264 | 121 | } | ||
1265 | 122 | |||
1266 | 123 | ////////////////////////////////////////////////////////////// | ||
1267 | 124 | |||
1268 | 125 | ExportedPlatformMenu::ExportedPlatformMenu() | ||
1269 | 126 | : QPlatformMenu() | ||
1270 | 127 | , d(new ExportedPlatformMenuPrivate) | ||
1271 | 128 | { | ||
1272 | 129 | LOG << id(); | ||
1273 | 130 | } | ||
1274 | 131 | |||
1275 | 132 | ExportedPlatformMenu::~ExportedPlatformMenu() | ||
1276 | 133 | { | ||
1277 | 134 | LOG << id(); | ||
1278 | 135 | } | ||
1279 | 136 | |||
1280 | 137 | void ExportedPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) | ||
1281 | 138 | { | ||
1282 | 139 | LOG << MENU_ITEM_ID(menuItem) << " before:" << before << " on: " << id(); | ||
1283 | 140 | |||
1284 | 141 | if (!before) { | ||
1285 | 142 | d->m_menuItems.push_back(menuItem); | ||
1286 | 143 | } else { | ||
1287 | 144 | for (auto iter = d->m_menuItems.begin(); iter != d->m_menuItems.end(); ++iter) { | ||
1288 | 145 | if (*iter == before) { | ||
1289 | 146 | d->m_menuItems.insert(iter, menuItem); | ||
1290 | 147 | break; | ||
1291 | 148 | } | ||
1292 | 149 | } | ||
1293 | 150 | } | ||
1294 | 151 | |||
1295 | 152 | Q_EMIT menuItemInserted(menuItem); | ||
1296 | 153 | } | ||
1297 | 154 | |||
1298 | 155 | void ExportedPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) | ||
1299 | 156 | { | ||
1300 | 157 | LOG_VAR(menuItem) << " on: " << id(); | ||
1301 | 158 | |||
1302 | 159 | QMutableListIterator<QPlatformMenuItem*> iter(d->m_menuItems); | ||
1303 | 160 | while (iter.hasNext()) { | ||
1304 | 161 | if (iter.next() == menuItem) { | ||
1305 | 162 | iter.remove(); | ||
1306 | 163 | } | ||
1307 | 164 | } | ||
1308 | 165 | |||
1309 | 166 | Q_EMIT menuItemRemoved(menuItem); | ||
1310 | 167 | } | ||
1311 | 168 | |||
1312 | 169 | void ExportedPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) | ||
1313 | 170 | { | ||
1314 | 171 | LOG_VAR(menuItem) << " from: " << id(); | ||
1315 | 172 | QMetaObject::invokeMethod(menuItem, "propertyUpdated"); | ||
1316 | 173 | } | ||
1317 | 174 | |||
1318 | 175 | void ExportedPlatformMenu::syncSeparatorsCollapsible(bool enable) | ||
1319 | 176 | { | ||
1320 | 177 | LOG_VAR(enable) << " on: " << id(); | ||
1321 | 178 | Q_EMIT propertyUpdated(); | ||
1322 | 179 | } | ||
1323 | 180 | |||
1324 | 181 | void ExportedPlatformMenu::setTag(quintptr tag) | ||
1325 | 182 | { | ||
1326 | 183 | LOG_VAR(tag) << " on: " << id(); | ||
1327 | 184 | d->m_tag = tag; | ||
1328 | 185 | } | ||
1329 | 186 | |||
1330 | 187 | quintptr ExportedPlatformMenu::tag() const | ||
1331 | 188 | { | ||
1332 | 189 | return d->m_tag; | ||
1333 | 190 | } | ||
1334 | 191 | |||
1335 | 192 | void ExportedPlatformMenu::setText(const QString &text) | ||
1336 | 193 | { | ||
1337 | 194 | LOG_VAR(text) << " on: " << id(); | ||
1338 | 195 | ExportedPlatformMenuPrivate::set_text(this, text); | ||
1339 | 196 | Q_EMIT propertyUpdated(); | ||
1340 | 197 | } | ||
1341 | 198 | |||
1342 | 199 | void ExportedPlatformMenu::setIcon(const QIcon &icon) | ||
1343 | 200 | { | ||
1344 | 201 | LOG_VAR(icon) << " on: " << id(); | ||
1345 | 202 | ExportedPlatformMenuPrivate::set_icon(this, icon); | ||
1346 | 203 | Q_EMIT propertyUpdated(); | ||
1347 | 204 | } | ||
1348 | 205 | |||
1349 | 206 | void ExportedPlatformMenu::setEnabled(bool isEnabled) | ||
1350 | 207 | { | ||
1351 | 208 | LOG_VAR(isEnabled) << " on: " << id(); | ||
1352 | 209 | ExportedPlatformMenuPrivate::set_enabled(this, isEnabled); | ||
1353 | 210 | Q_EMIT propertyUpdated(); | ||
1354 | 211 | } | ||
1355 | 212 | |||
1356 | 213 | void ExportedPlatformMenu::setVisible(bool isVisible) | ||
1357 | 214 | { | ||
1358 | 215 | LOG_VAR(isVisible) << " on: " << id(); | ||
1359 | 216 | ExportedPlatformMenuPrivate::set_visible(this, isVisible); | ||
1360 | 217 | Q_EMIT propertyUpdated(); | ||
1361 | 218 | } | ||
1362 | 219 | |||
1363 | 220 | void ExportedPlatformMenu::setMinimumWidth(int width) | ||
1364 | 221 | { | ||
1365 | 222 | LOG_VAR(width) << " on: " << id(); | ||
1366 | 223 | Q_EMIT propertyUpdated(); | ||
1367 | 224 | } | ||
1368 | 225 | |||
1369 | 226 | void ExportedPlatformMenu::setFont(const QFont &font) | ||
1370 | 227 | { | ||
1371 | 228 | LOG_VAR(font) << " on: " << id(); | ||
1372 | 229 | Q_EMIT propertyUpdated(); | ||
1373 | 230 | } | ||
1374 | 231 | |||
1375 | 232 | QPlatformMenuItem *ExportedPlatformMenu::menuItemAt(int position) const | ||
1376 | 233 | { | ||
1377 | 234 | if (position < 0 || position >= d->m_menuItems.count()) return nullptr; | ||
1378 | 235 | return d->m_menuItems.at(position); | ||
1379 | 236 | } | ||
1380 | 237 | |||
1381 | 238 | QPlatformMenuItem *ExportedPlatformMenu::menuItemForTag(quintptr tag) const | ||
1382 | 239 | { | ||
1383 | 240 | for (auto iter = d->m_menuItems.begin(); iter != d->m_menuItems.end(); ++iter) { | ||
1384 | 241 | if ((*iter)->tag() == tag) { | ||
1385 | 242 | return *iter; | ||
1386 | 243 | } | ||
1387 | 244 | } | ||
1388 | 245 | return nullptr; | ||
1389 | 246 | } | ||
1390 | 247 | |||
1391 | 248 | uint ExportedPlatformMenu::menuItemCount() | ||
1392 | 249 | { | ||
1393 | 250 | return d->m_menuItems.count(); | ||
1394 | 251 | } | ||
1395 | 252 | |||
1396 | 253 | QPlatformMenuItem *ExportedPlatformMenu::createMenuItem() const | ||
1397 | 254 | { | ||
1398 | 255 | return new ExportedPlatformMenuItem(); | ||
1399 | 256 | } | ||
1400 | 257 | |||
1401 | 258 | int ExportedPlatformMenu::id() const | ||
1402 | 259 | { | ||
1403 | 260 | return d->m_id; | ||
1404 | 261 | } | ||
1405 | 262 | |||
1406 | 263 | ////////////////////////////////////////////////////////////// | ||
1407 | 264 | |||
1408 | 265 | ExportedPlatformMenuItem::ExportedPlatformMenuItem() | ||
1409 | 266 | : d(new ExportedPlatformMenuItemPrivate) | ||
1410 | 267 | { | ||
1411 | 268 | LOG << id(); | ||
1412 | 269 | } | ||
1413 | 270 | |||
1414 | 271 | ExportedPlatformMenuItem::~ExportedPlatformMenuItem() | ||
1415 | 272 | { | ||
1416 | 273 | LOG << id(); | ||
1417 | 274 | } | ||
1418 | 275 | |||
1419 | 276 | void ExportedPlatformMenuItem::setTag(quintptr tag) | ||
1420 | 277 | { | ||
1421 | 278 | LOG_VAR(tag) << " on: " << id(); | ||
1422 | 279 | d->m_tag = tag; | ||
1423 | 280 | } | ||
1424 | 281 | |||
1425 | 282 | quintptr ExportedPlatformMenuItem::tag() const | ||
1426 | 283 | { | ||
1427 | 284 | return d->m_tag; | ||
1428 | 285 | } | ||
1429 | 286 | |||
1430 | 287 | void ExportedPlatformMenuItem::setText(const QString &text) | ||
1431 | 288 | { | ||
1432 | 289 | LOG_VAR(text) << " on: " << id(); | ||
1433 | 290 | ExportedPlatformMenuItemPrivate::set_text(this, text); | ||
1434 | 291 | Q_EMIT propertyUpdated(); | ||
1435 | 292 | } | ||
1436 | 293 | |||
1437 | 294 | void ExportedPlatformMenuItem::setIcon(const QIcon &icon) | ||
1438 | 295 | { | ||
1439 | 296 | LOG_VAR(icon) << " on: " << id(); | ||
1440 | 297 | ExportedPlatformMenuItemPrivate::set_icon(this, icon); | ||
1441 | 298 | Q_EMIT propertyUpdated(); | ||
1442 | 299 | } | ||
1443 | 300 | |||
1444 | 301 | void ExportedPlatformMenuItem::setMenu(QPlatformMenu *menu) | ||
1445 | 302 | { | ||
1446 | 303 | LOG << MENU_ID(menu) << " on: " << id(); | ||
1447 | 304 | d->m_menu = menu; | ||
1448 | 305 | Q_EMIT propertyUpdated(); | ||
1449 | 306 | } | ||
1450 | 307 | |||
1451 | 308 | void ExportedPlatformMenuItem::setVisible(bool isVisible) | ||
1452 | 309 | { | ||
1453 | 310 | LOG_VAR(isVisible) << " on: " << id(); | ||
1454 | 311 | ExportedPlatformMenuItemPrivate::set_visible(this, isVisible); | ||
1455 | 312 | Q_EMIT propertyUpdated(); | ||
1456 | 313 | } | ||
1457 | 314 | |||
1458 | 315 | void ExportedPlatformMenuItem::setIsSeparator(bool isSeparator) | ||
1459 | 316 | { | ||
1460 | 317 | LOG_VAR(isSeparator) << " on: " << id(); | ||
1461 | 318 | ExportedPlatformMenuItemPrivate::set_separator(this, isSeparator); | ||
1462 | 319 | Q_EMIT propertyUpdated(); | ||
1463 | 320 | } | ||
1464 | 321 | |||
1465 | 322 | void ExportedPlatformMenuItem::setFont(const QFont &font) | ||
1466 | 323 | { | ||
1467 | 324 | LOG_VAR(font) << " on: " << id(); | ||
1468 | 325 | Q_EMIT propertyUpdated(); | ||
1469 | 326 | } | ||
1470 | 327 | |||
1471 | 328 | void ExportedPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role) | ||
1472 | 329 | { | ||
1473 | 330 | LOG_VAR(role) << " on: " << id(); | ||
1474 | 331 | Q_EMIT propertyUpdated(); | ||
1475 | 332 | } | ||
1476 | 333 | |||
1477 | 334 | void ExportedPlatformMenuItem::setCheckable(bool checkable) | ||
1478 | 335 | { | ||
1479 | 336 | LOG_VAR(checkable) << " on: " << id(); | ||
1480 | 337 | ExportedPlatformMenuItemPrivate::set_checkable(this, checkable); | ||
1481 | 338 | Q_EMIT propertyUpdated(); | ||
1482 | 339 | } | ||
1483 | 340 | |||
1484 | 341 | void ExportedPlatformMenuItem::setChecked(bool isChecked) | ||
1485 | 342 | { | ||
1486 | 343 | LOG_VAR(isChecked) << " on: " << id(); | ||
1487 | 344 | ExportedPlatformMenuItemPrivate::set_checked(this, isChecked); | ||
1488 | 345 | Q_EMIT propertyUpdated(); | ||
1489 | 346 | } | ||
1490 | 347 | |||
1491 | 348 | void ExportedPlatformMenuItem::setShortcut(const QKeySequence &shortcut) | ||
1492 | 349 | { | ||
1493 | 350 | LOG_VAR(shortcut) << " on: " << id(); | ||
1494 | 351 | ExportedPlatformMenuItemPrivate::set_shortcut(this, shortcut); | ||
1495 | 352 | Q_EMIT propertyUpdated(); | ||
1496 | 353 | } | ||
1497 | 354 | |||
1498 | 355 | void ExportedPlatformMenuItem::setEnabled(bool enabled) | ||
1499 | 356 | { | ||
1500 | 357 | LOG_VAR(enabled) << " on: " << id(); | ||
1501 | 358 | ExportedPlatformMenuItemPrivate::set_enabled(this, enabled); | ||
1502 | 359 | Q_EMIT propertyUpdated(); | ||
1503 | 360 | } | ||
1504 | 361 | |||
1505 | 362 | void ExportedPlatformMenuItem::setIconSize(int size) | ||
1506 | 363 | { | ||
1507 | 364 | LOG_VAR(size) << " on: " << id(); | ||
1508 | 365 | ExportedPlatformMenuItemPrivate::set_iconSize(this, size); | ||
1509 | 366 | Q_EMIT propertyUpdated(); | ||
1510 | 367 | } | ||
1511 | 368 | |||
1512 | 369 | int ExportedPlatformMenuItem::id() const | ||
1513 | 370 | { | ||
1514 | 371 | return d->m_id; | ||
1515 | 372 | } | ||
1516 | 373 | |||
1517 | 374 | QPlatformMenu *ExportedPlatformMenuItem::menu() const | ||
1518 | 375 | { | ||
1519 | 376 | return d->m_menu; | ||
1520 | 377 | } | ||
1521 | 0 | 378 | ||
1522 | === added file 'src/qpa/exportedplatformmenubar.h' | |||
1523 | --- src/qpa/exportedplatformmenubar.h 1970-01-01 00:00:00 +0000 | |||
1524 | +++ src/qpa/exportedplatformmenubar.h 2015-03-18 11:19:06 +0000 | |||
1525 | @@ -0,0 +1,136 @@ | |||
1526 | 1 | /* This file is part of the dbusmenu-qt library | ||
1527 | 2 | Copyright 2015 Canonical | ||
1528 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
1529 | 4 | |||
1530 | 5 | This library is free software; you can redistribute it and/or | ||
1531 | 6 | modify it under the terms of the GNU Library General Public | ||
1532 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
1533 | 8 | either version 2 of the License, or (at your option) any later | ||
1534 | 9 | version. | ||
1535 | 10 | |||
1536 | 11 | This library is distributed in the hope that it will be useful, | ||
1537 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1538 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1539 | 14 | Library General Public License for more details. | ||
1540 | 15 | |||
1541 | 16 | You should have received a copy of the GNU Library General Public License | ||
1542 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1543 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1544 | 19 | Boston, MA 02110-1301, USA. | ||
1545 | 20 | */ | ||
1546 | 21 | #ifndef EXPORTEDPLATFORMMENUBAR_H | ||
1547 | 22 | #define EXPORTEDPLATFORMMENUBAR_H | ||
1548 | 23 | |||
1549 | 24 | #include <qpa/qplatformmenu.h> | ||
1550 | 25 | class ExportedPlatformMenuBarPrivate; | ||
1551 | 26 | class ExportedPlatformMenuPrivate; | ||
1552 | 27 | class ExportedPlatformMenuItemPrivate; | ||
1553 | 28 | class ExportedPlatformMenu; | ||
1554 | 29 | class ExportedPlatformMenuItem; | ||
1555 | 30 | |||
1556 | 31 | // Local | ||
1557 | 32 | #include <dbusmenu_export.h> | ||
1558 | 33 | |||
1559 | 34 | class DBUSMENU_EXPORT ExportedPlatformMenuBar : public QPlatformMenuBar | ||
1560 | 35 | { | ||
1561 | 36 | Q_OBJECT | ||
1562 | 37 | public: | ||
1563 | 38 | ExportedPlatformMenuBar(const QString& exportPath); | ||
1564 | 39 | ~ExportedPlatformMenuBar(); | ||
1565 | 40 | |||
1566 | 41 | QString exportedPath() const; | ||
1567 | 42 | |||
1568 | 43 | virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu* before) override; | ||
1569 | 44 | virtual void removeMenu(QPlatformMenu *menu) override; | ||
1570 | 45 | virtual void syncMenu(QPlatformMenu *menuItem) override; | ||
1571 | 46 | virtual void handleReparent(QWindow *newParentWindow) override; | ||
1572 | 47 | virtual QPlatformMenu *menuForTag(quintptr tag) const override; | ||
1573 | 48 | |||
1574 | 49 | QPlatformMenu *menuAt(int position) const; | ||
1575 | 50 | uint menuCount(); | ||
1576 | 51 | |||
1577 | 52 | Q_SIGNALS: | ||
1578 | 53 | void menuInserted(QPlatformMenu *menu); | ||
1579 | 54 | void menuRemoved(QPlatformMenu *menu); | ||
1580 | 55 | |||
1581 | 56 | private: | ||
1582 | 57 | ExportedPlatformMenuBarPrivate *const d; | ||
1583 | 58 | friend class ExportedPlatformMenuBarPrivate; | ||
1584 | 59 | }; | ||
1585 | 60 | |||
1586 | 61 | class DBUSMENU_EXPORT ExportedPlatformMenu : public QPlatformMenu | ||
1587 | 62 | { | ||
1588 | 63 | Q_OBJECT | ||
1589 | 64 | public: | ||
1590 | 65 | ExportedPlatformMenu(); | ||
1591 | 66 | ~ExportedPlatformMenu(); | ||
1592 | 67 | |||
1593 | 68 | virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override; | ||
1594 | 69 | virtual void removeMenuItem(QPlatformMenuItem *menuItem) override; | ||
1595 | 70 | virtual void syncMenuItem(QPlatformMenuItem *menuItem) override; | ||
1596 | 71 | virtual void syncSeparatorsCollapsible(bool enable) override; | ||
1597 | 72 | |||
1598 | 73 | virtual void setTag(quintptr tag) override; | ||
1599 | 74 | virtual quintptr tag() const override; | ||
1600 | 75 | |||
1601 | 76 | virtual void setText(const QString &text) override; | ||
1602 | 77 | virtual void setIcon(const QIcon &icon) override; | ||
1603 | 78 | virtual void setEnabled(bool isEnabled) override; | ||
1604 | 79 | virtual void setVisible(bool isVisible) override; | ||
1605 | 80 | virtual void setMinimumWidth(int width) override; | ||
1606 | 81 | virtual void setFont(const QFont &font) override; | ||
1607 | 82 | |||
1608 | 83 | virtual QPlatformMenuItem *menuItemAt(int position) const override; | ||
1609 | 84 | virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const override; | ||
1610 | 85 | uint menuItemCount(); | ||
1611 | 86 | |||
1612 | 87 | virtual QPlatformMenuItem *createMenuItem() const override; | ||
1613 | 88 | |||
1614 | 89 | int id() const; | ||
1615 | 90 | |||
1616 | 91 | Q_SIGNALS: | ||
1617 | 92 | void menuItemInserted(QPlatformMenuItem *menuItem); | ||
1618 | 93 | void menuItemRemoved(QPlatformMenuItem *menuItem); | ||
1619 | 94 | |||
1620 | 95 | void propertyUpdated(); | ||
1621 | 96 | |||
1622 | 97 | private: | ||
1623 | 98 | ExportedPlatformMenuPrivate *const d; | ||
1624 | 99 | friend class ExportedPlatformMenuPrivate; | ||
1625 | 100 | }; | ||
1626 | 101 | |||
1627 | 102 | |||
1628 | 103 | class DBUSMENU_EXPORT ExportedPlatformMenuItem : public QPlatformMenuItem | ||
1629 | 104 | { | ||
1630 | 105 | Q_OBJECT | ||
1631 | 106 | public: | ||
1632 | 107 | ExportedPlatformMenuItem(); | ||
1633 | 108 | ~ExportedPlatformMenuItem(); | ||
1634 | 109 | |||
1635 | 110 | virtual void setTag(quintptr tag) override; | ||
1636 | 111 | virtual quintptr tag() const override; | ||
1637 | 112 | |||
1638 | 113 | virtual void setText(const QString &text) override; | ||
1639 | 114 | virtual void setIcon(const QIcon &icon) override; | ||
1640 | 115 | virtual void setMenu(QPlatformMenu *menu) override; | ||
1641 | 116 | virtual void setVisible(bool isVisible) override; | ||
1642 | 117 | virtual void setIsSeparator(bool isSeparator) override; | ||
1643 | 118 | virtual void setFont(const QFont &font) override; | ||
1644 | 119 | virtual void setRole(MenuRole role) override; | ||
1645 | 120 | virtual void setCheckable(bool checkable) override; | ||
1646 | 121 | virtual void setChecked(bool isChecked) override; | ||
1647 | 122 | virtual void setShortcut(const QKeySequence& shortcut) override; | ||
1648 | 123 | virtual void setEnabled(bool enabled) override; | ||
1649 | 124 | virtual void setIconSize(int size) override; | ||
1650 | 125 | |||
1651 | 126 | int id() const; | ||
1652 | 127 | QPlatformMenu* menu() const; | ||
1653 | 128 | |||
1654 | 129 | Q_SIGNALS: | ||
1655 | 130 | void propertyUpdated(); | ||
1656 | 131 | |||
1657 | 132 | private: | ||
1658 | 133 | ExportedPlatformMenuItemPrivate *const d; | ||
1659 | 134 | friend class ExportedPlatformMenuItemPrivate; | ||
1660 | 135 | }; | ||
1661 | 136 | #endif // EXPORTEDPLATFORMMENUBAR_H | ||
1662 | 0 | 137 | ||
1663 | === added file 'src/qpa/exportedplatformmenubar_p.cpp' | |||
1664 | --- src/qpa/exportedplatformmenubar_p.cpp 1970-01-01 00:00:00 +0000 | |||
1665 | +++ src/qpa/exportedplatformmenubar_p.cpp 2015-03-18 11:19:06 +0000 | |||
1666 | @@ -0,0 +1,129 @@ | |||
1667 | 1 | /* This file is part of the dbusmenu-qt library | ||
1668 | 2 | Copyright 2015 Canonical | ||
1669 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
1670 | 4 | |||
1671 | 5 | This library is free software; you can redistribute it and/or | ||
1672 | 6 | modify it under the terms of the GNU Library General Public | ||
1673 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
1674 | 8 | either version 2 of the License, or (at your option) any later | ||
1675 | 9 | version. | ||
1676 | 10 | |||
1677 | 11 | This library is distributed in the hope that it will be useful, | ||
1678 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1679 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1680 | 14 | Library General Public License for more details. | ||
1681 | 15 | |||
1682 | 16 | You should have received a copy of the GNU Library General Public License | ||
1683 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1684 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1685 | 19 | Boston, MA 02110-1301, USA. | ||
1686 | 20 | */ | ||
1687 | 21 | |||
1688 | 22 | // Local | ||
1689 | 23 | #include "exportedplatformmenubar_p.h" | ||
1690 | 24 | #include "dbusmenushortcut_p.h" | ||
1691 | 25 | #include "debug_p.h" | ||
1692 | 26 | #include "utils_p.h" | ||
1693 | 27 | |||
1694 | 28 | // Qt | ||
1695 | 29 | #include <QBuffer> | ||
1696 | 30 | |||
1697 | 31 | int nextMenuId = 1; | ||
1698 | 32 | |||
1699 | 33 | void insertIconProperty(QVariantMap *map, const QIcon& icon) | ||
1700 | 34 | { | ||
1701 | 35 | // provide the icon name for per-theme lookups | ||
1702 | 36 | const QString iconName = icon.name(); | ||
1703 | 37 | if (!iconName.isEmpty()) { | ||
1704 | 38 | map->insert(DBusMenuProperty::IconName, iconName); | ||
1705 | 39 | } | ||
1706 | 40 | |||
1707 | 41 | if (!icon.isNull()) { | ||
1708 | 42 | QBuffer buffer; | ||
1709 | 43 | icon.pixmap(16).save(&buffer, "PNG"); | ||
1710 | 44 | map->insert(DBusMenuProperty::IconData, buffer.data()); | ||
1711 | 45 | } | ||
1712 | 46 | } | ||
1713 | 47 | |||
1714 | 48 | ExportedPlatformMenuBarPrivate::ExportedPlatformMenuBarPrivate() | ||
1715 | 49 | { | ||
1716 | 50 | } | ||
1717 | 51 | |||
1718 | 52 | ////////////////////////////////////////////////////// | ||
1719 | 53 | |||
1720 | 54 | ExportedPlatformMenuPrivate::ExportedPlatformMenuPrivate() | ||
1721 | 55 | : m_tag(0) | ||
1722 | 56 | , m_id(nextMenuId++) | ||
1723 | 57 | { | ||
1724 | 58 | |||
1725 | 59 | } | ||
1726 | 60 | |||
1727 | 61 | QVariantMap ExportedPlatformMenuPrivate::propertiesForMenu(const ExportedPlatformMenu *menu) | ||
1728 | 62 | { | ||
1729 | 63 | QVariantMap map; | ||
1730 | 64 | map.insert(DBusMenuProperty::ChildrenDisplay, "submenu"); | ||
1731 | 65 | map.insert(DBusMenuProperty::Label, Utils::swapMnemonicChar(ExportedPlatformMenuPrivate::get_text(menu), '&', '_')); | ||
1732 | 66 | if (!ExportedPlatformMenuPrivate::get_enabled(menu)) { | ||
1733 | 67 | map.insert(DBusMenuProperty::Enabled, false); | ||
1734 | 68 | } | ||
1735 | 69 | if (!ExportedPlatformMenuPrivate::get_visible(menu)) { | ||
1736 | 70 | map.insert(DBusMenuProperty::Visible, false); | ||
1737 | 71 | } | ||
1738 | 72 | insertIconProperty(&map, ExportedPlatformMenuPrivate::get_icon(menu)); | ||
1739 | 73 | return map; | ||
1740 | 74 | } | ||
1741 | 75 | |||
1742 | 76 | ////////////////////////////////////////////////////// | ||
1743 | 77 | |||
1744 | 78 | ExportedPlatformMenuItemPrivate::ExportedPlatformMenuItemPrivate() | ||
1745 | 79 | : m_id(nextMenuId++) | ||
1746 | 80 | , m_menu(nullptr) | ||
1747 | 81 | { | ||
1748 | 82 | } | ||
1749 | 83 | |||
1750 | 84 | QVariantMap ExportedPlatformMenuItemPrivate::propertiesForMenuItem(const ExportedPlatformMenuItem *menuItem) | ||
1751 | 85 | { | ||
1752 | 86 | DMRETURN_VALUE_IF_FAIL(menuItem, QVariantMap()); | ||
1753 | 87 | |||
1754 | 88 | if (ExportedPlatformMenuItemPrivate::get_separator(menuItem)) { | ||
1755 | 89 | return propertiesForSeparatorMenuItem(menuItem); | ||
1756 | 90 | } else { | ||
1757 | 91 | return propertiesForStandardMenuItem(menuItem); | ||
1758 | 92 | } | ||
1759 | 93 | } | ||
1760 | 94 | |||
1761 | 95 | QVariantMap ExportedPlatformMenuItemPrivate::propertiesForSeparatorMenuItem(const ExportedPlatformMenuItem *menuItem) | ||
1762 | 96 | { | ||
1763 | 97 | QVariantMap map; | ||
1764 | 98 | map.insert(DBusMenuProperty::Type, "separator"); | ||
1765 | 99 | if (!ExportedPlatformMenuItemPrivate::get_visible(menuItem)) { | ||
1766 | 100 | map.insert(DBusMenuProperty::Visible, false); | ||
1767 | 101 | } | ||
1768 | 102 | return map; | ||
1769 | 103 | } | ||
1770 | 104 | |||
1771 | 105 | QVariantMap ExportedPlatformMenuItemPrivate::propertiesForStandardMenuItem(const ExportedPlatformMenuItem *menuItem) | ||
1772 | 106 | { | ||
1773 | 107 | QVariantMap map; | ||
1774 | 108 | map.insert(DBusMenuProperty::Label, Utils::swapMnemonicChar(ExportedPlatformMenuItemPrivate::get_text(menuItem), '&', '_')); | ||
1775 | 109 | if (!ExportedPlatformMenuItemPrivate::get_enabled(menuItem)) { | ||
1776 | 110 | map.insert(DBusMenuProperty::Enabled, false); | ||
1777 | 111 | } | ||
1778 | 112 | if (!ExportedPlatformMenuItemPrivate::get_visible(menuItem)) { | ||
1779 | 113 | map.insert(DBusMenuProperty::Visible, false); | ||
1780 | 114 | } | ||
1781 | 115 | if (ExportedPlatformMenuItemPrivate::get_checkable(menuItem)) { | ||
1782 | 116 | map.insert(DBusMenuProperty::ToggleType, "checkmark"); | ||
1783 | 117 | map.insert(DBusMenuProperty::ToggleState, ExportedPlatformMenuItemPrivate::get_checked(menuItem) ? 1 : 0); | ||
1784 | 118 | } | ||
1785 | 119 | if (menuItem->menu()) { | ||
1786 | 120 | map.insert(DBusMenuProperty::ChildrenDisplay, "submenu"); | ||
1787 | 121 | } | ||
1788 | 122 | insertIconProperty(&map, ExportedPlatformMenuItemPrivate::get_icon(menuItem)); | ||
1789 | 123 | QKeySequence keySequence = get_shortcut(menuItem); | ||
1790 | 124 | if (!keySequence.isEmpty()) { | ||
1791 | 125 | DBusMenuShortcut shortcut = DBusMenuShortcut::fromKeySequence(keySequence); | ||
1792 | 126 | map.insert(DBusMenuProperty::Shortcut, QVariant::fromValue(shortcut)); | ||
1793 | 127 | } | ||
1794 | 128 | return map; | ||
1795 | 129 | } | ||
1796 | 0 | 130 | ||
1797 | === added file 'src/qpa/exportedplatformmenubar_p.h' | |||
1798 | --- src/qpa/exportedplatformmenubar_p.h 1970-01-01 00:00:00 +0000 | |||
1799 | +++ src/qpa/exportedplatformmenubar_p.h 2015-03-18 11:19:06 +0000 | |||
1800 | @@ -0,0 +1,111 @@ | |||
1801 | 1 | /* This file is part of the dbusmenu-qt library | ||
1802 | 2 | Copyright 2015 Canonical | ||
1803 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
1804 | 4 | |||
1805 | 5 | This library is free software; you can redistribute it and/or | ||
1806 | 6 | modify it under the terms of the GNU Library General Public | ||
1807 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
1808 | 8 | either version 2 of the License, or (at your option) any later | ||
1809 | 9 | version. | ||
1810 | 10 | |||
1811 | 11 | This library is distributed in the hope that it will be useful, | ||
1812 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1813 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1814 | 14 | Library General Public License for more details. | ||
1815 | 15 | |||
1816 | 16 | You should have received a copy of the GNU Library General Public License | ||
1817 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1818 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1819 | 19 | Boston, MA 02110-1301, USA. | ||
1820 | 20 | */ | ||
1821 | 21 | #ifndef EXPORTEDPLATFORMMENUBAR_P_H | ||
1822 | 22 | #define EXPORTEDPLATFORMMENUBAR_P_H | ||
1823 | 23 | |||
1824 | 24 | // Qt | ||
1825 | 25 | #include <QtCore/QObject> | ||
1826 | 26 | #include <QtDBus/QDBusConnection> | ||
1827 | 27 | #include <qpa/qplatformmenu.h> | ||
1828 | 28 | |||
1829 | 29 | // Local | ||
1830 | 30 | #include "dbusmenuexporterdbusinterface_p.h" | ||
1831 | 31 | #include "exportedplatformmenubar.h" | ||
1832 | 32 | |||
1833 | 33 | class QAction; | ||
1834 | 34 | class QMenu; | ||
1835 | 35 | |||
1836 | 36 | class ExportedPlatformMenuBar; | ||
1837 | 37 | class ExportedPlatformMenu; | ||
1838 | 38 | class ExportedPlatformMenuItem; | ||
1839 | 39 | class QPADBusMenuExporter; | ||
1840 | 40 | |||
1841 | 41 | /** | ||
1842 | 42 | * A QPADBusMenuExporter instance can serialize a qua menu over DBus | ||
1843 | 43 | */ | ||
1844 | 44 | class ExportedPlatformMenuBarPrivate | ||
1845 | 45 | { | ||
1846 | 46 | public: | ||
1847 | 47 | ExportedPlatformMenuBarPrivate(); | ||
1848 | 48 | |||
1849 | 49 | QString m_objectPath; | ||
1850 | 50 | QList<QPlatformMenu*> m_menus; | ||
1851 | 51 | }; | ||
1852 | 52 | |||
1853 | 53 | class ExportedPlatformMenuPrivate | ||
1854 | 54 | { | ||
1855 | 55 | public: | ||
1856 | 56 | ExportedPlatformMenuPrivate(); | ||
1857 | 57 | |||
1858 | 58 | static QVariantMap propertiesForMenu(const ExportedPlatformMenu *menu); | ||
1859 | 59 | |||
1860 | 60 | #define STATIC_PROPERTY(name, type, defaultValue) \ | ||
1861 | 61 | type m_##name = defaultValue; \ | ||
1862 | 62 | static type get_##name(const ExportedPlatformMenu *menu) { return menu->d->m_##name; } \ | ||
1863 | 63 | static void set_##name(ExportedPlatformMenu *menu, const type& value) { menu->d->m_##name = value; } | ||
1864 | 64 | |||
1865 | 65 | STATIC_PROPERTY(text, QString, QString()) | ||
1866 | 66 | STATIC_PROPERTY(visible, bool, true) | ||
1867 | 67 | STATIC_PROPERTY(enabled, bool, true) | ||
1868 | 68 | STATIC_PROPERTY(icon, QIcon, QIcon()) | ||
1869 | 69 | #undef STATIC_PROPERTY | ||
1870 | 70 | |||
1871 | 71 | ExportedPlatformMenu* m_menu; | ||
1872 | 72 | QList<QPlatformMenu*> m_menus; | ||
1873 | 73 | QList<QPlatformMenuItem*> m_menuItems; | ||
1874 | 74 | quintptr m_tag; | ||
1875 | 75 | int m_id; | ||
1876 | 76 | }; | ||
1877 | 77 | |||
1878 | 78 | class ExportedPlatformMenuItemPrivate | ||
1879 | 79 | { | ||
1880 | 80 | public: | ||
1881 | 81 | ExportedPlatformMenuItemPrivate(); | ||
1882 | 82 | |||
1883 | 83 | static QVariantMap propertiesForMenuItem(const ExportedPlatformMenuItem *menuItem); | ||
1884 | 84 | static QVariantMap propertiesForSeparatorMenuItem(const ExportedPlatformMenuItem *menuItem); | ||
1885 | 85 | static QVariantMap propertiesForStandardMenuItem(const ExportedPlatformMenuItem *menuItem); | ||
1886 | 86 | |||
1887 | 87 | #define STATIC_PROPERTY(name, type, defaultValue) \ | ||
1888 | 88 | type m_##name = defaultValue; \ | ||
1889 | 89 | static type get_##name(const ExportedPlatformMenuItem *menuItem) { return menuItem->d->m_##name; } \ | ||
1890 | 90 | static void set_##name(ExportedPlatformMenuItem *menuItem, const type& value) { menuItem->d->m_##name = value; } | ||
1891 | 91 | |||
1892 | 92 | STATIC_PROPERTY(separator, bool, false) | ||
1893 | 93 | STATIC_PROPERTY(visible, bool, true) | ||
1894 | 94 | STATIC_PROPERTY(text, QString, QString()) | ||
1895 | 95 | STATIC_PROPERTY(enabled, bool, true) | ||
1896 | 96 | STATIC_PROPERTY(checkable, bool, false) | ||
1897 | 97 | STATIC_PROPERTY(checked, bool, false) | ||
1898 | 98 | STATIC_PROPERTY(shortcut, QKeySequence, QKeySequence()) | ||
1899 | 99 | STATIC_PROPERTY(icon, QIcon, QIcon()) | ||
1900 | 100 | STATIC_PROPERTY(iconSize, int, 16) | ||
1901 | 101 | #undef STATIC_PROPERTY | ||
1902 | 102 | |||
1903 | 103 | ExportedPlatformMenuItem* m_menuItem; | ||
1904 | 104 | quintptr m_tag; | ||
1905 | 105 | int m_id; | ||
1906 | 106 | QPlatformMenu* m_menu; | ||
1907 | 107 | }; | ||
1908 | 108 | |||
1909 | 109 | extern int nextMenuId; | ||
1910 | 110 | |||
1911 | 111 | #endif // EXPORTEDPLATFORMMENUBAR_P_H | ||
1912 | 0 | 112 | ||
1913 | === added file 'src/qpa/logging_p.h' | |||
1914 | --- src/qpa/logging_p.h 1970-01-01 00:00:00 +0000 | |||
1915 | +++ src/qpa/logging_p.h 2015-03-18 11:19:06 +0000 | |||
1916 | @@ -0,0 +1,38 @@ | |||
1917 | 1 | /* This file is part of the dbusmenu-qt library | ||
1918 | 2 | Copyright 2015 Canonical | ||
1919 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
1920 | 4 | |||
1921 | 5 | This library is free software; you can redistribute it and/or | ||
1922 | 6 | modify it under the terms of the GNU Library General Public | ||
1923 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
1924 | 8 | either version 2 of the License, or (at your option) any later | ||
1925 | 9 | version. | ||
1926 | 10 | |||
1927 | 11 | This library is distributed in the hope that it will be useful, | ||
1928 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1929 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1930 | 14 | Library General Public License for more details. | ||
1931 | 15 | |||
1932 | 16 | You should have received a copy of the GNU Library General Public License | ||
1933 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1934 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1935 | 19 | Boston, MA 02110-1301, USA. | ||
1936 | 20 | */ | ||
1937 | 21 | #ifndef LOGGING_H | ||
1938 | 22 | #define LOGGING_H | ||
1939 | 23 | |||
1940 | 24 | #include <QDebug> | ||
1941 | 25 | |||
1942 | 26 | //#define ENABLE_DEBUG_LOGGING | ||
1943 | 27 | |||
1944 | 28 | #ifdef ENABLE_DEBUG_LOGGING | ||
1945 | 29 | #define LOG qDebug() << __PRETTY_FUNCTION__ | ||
1946 | 30 | #define LOG_VAR(x) qDebug() << __PRETTY_FUNCTION__<< #x ":" << x | ||
1947 | 31 | #else | ||
1948 | 32 | #define LOG QNoDebug() | ||
1949 | 33 | #define LOG_VAR(x) QNoDebug() << __PRETTY_FUNCTION__<< #x ":" << x | ||
1950 | 34 | #endif | ||
1951 | 35 | |||
1952 | 36 | #define WARN qWarning() << __PRETTY_FUNCTION__ | ||
1953 | 37 | |||
1954 | 38 | #endif // LOGGING_H | ||
1955 | 0 | 39 | ||
1956 | === added file 'src/qpa/qpadbusmenuexporter_p.cpp' | |||
1957 | --- src/qpa/qpadbusmenuexporter_p.cpp 1970-01-01 00:00:00 +0000 | |||
1958 | +++ src/qpa/qpadbusmenuexporter_p.cpp 2015-03-18 11:19:06 +0000 | |||
1959 | @@ -0,0 +1,357 @@ | |||
1960 | 1 | /* This file is part of the dbusmenu-qt library | ||
1961 | 2 | Copyright 2015 Canonical | ||
1962 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
1963 | 4 | |||
1964 | 5 | This library is free software; you can redistribute it and/or | ||
1965 | 6 | modify it under the terms of the GNU Library General Public | ||
1966 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
1967 | 8 | either version 2 of the License, or (at your option) any later | ||
1968 | 9 | version. | ||
1969 | 10 | |||
1970 | 11 | This library is distributed in the hope that it will be useful, | ||
1971 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1972 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1973 | 14 | Library General Public License for more details. | ||
1974 | 15 | |||
1975 | 16 | You should have received a copy of the GNU Library General Public License | ||
1976 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1977 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1978 | 19 | Boston, MA 02110-1301, USA. | ||
1979 | 20 | */ | ||
1980 | 21 | |||
1981 | 22 | // Local | ||
1982 | 23 | #include "qpadbusmenuexporter_p.h" | ||
1983 | 24 | #include "exportedplatformmenubar.h" | ||
1984 | 25 | #include "exportedplatformmenubar_p.h" | ||
1985 | 26 | #include "utils_p.h" | ||
1986 | 27 | #include "logging_p.h" | ||
1987 | 28 | |||
1988 | 29 | // Qt | ||
1989 | 30 | #include <QTimer> | ||
1990 | 31 | |||
1991 | 32 | QPADBusMenuExporter::QPADBusMenuExporter(const QString &objectPath, ExportedPlatformMenuBar* menuBar) | ||
1992 | 33 | : DBusMenuExporterDBusInterface(objectPath, menuBar) | ||
1993 | 34 | , m_menuBar(menuBar) | ||
1994 | 35 | , m_revision(1) | ||
1995 | 36 | , m_emittedLayoutUpdatedOnce(false) | ||
1996 | 37 | { | ||
1997 | 38 | LOG << "created exporter menu @ " << objectPath; | ||
1998 | 39 | |||
1999 | 40 | m_propertyTimer = new QTimer(this); | ||
2000 | 41 | m_propertyTimer->setInterval(0); | ||
2001 | 42 | m_propertyTimer->setSingleShot(true); | ||
2002 | 43 | connect(m_propertyTimer, &QTimer::timeout, this, &QPADBusMenuExporter::doMenuPropertyUpdate); | ||
2003 | 44 | |||
2004 | 45 | m_layoutTimer = new QTimer(this); | ||
2005 | 46 | m_layoutTimer->setInterval(0); | ||
2006 | 47 | m_layoutTimer->setSingleShot(true); | ||
2007 | 48 | connect(m_layoutTimer, &QTimer::timeout, this, &QPADBusMenuExporter::doMenuLayoutUpdate); | ||
2008 | 49 | |||
2009 | 50 | for (uint i = 0; i < m_menuBar->menuCount(); i++) { | ||
2010 | 51 | auto exportedMenu = qobject_cast<ExportedPlatformMenu*>(m_menuBar->menuAt(i)); | ||
2011 | 52 | addMenu(exportedMenu, 0); | ||
2012 | 53 | } | ||
2013 | 54 | |||
2014 | 55 | connect(menuBar, &ExportedPlatformMenuBar::menuInserted, this, [this](QPlatformMenu* menu) { | ||
2015 | 56 | addMenu(qobject_cast<ExportedPlatformMenu*>(menu), 0); | ||
2016 | 57 | }); | ||
2017 | 58 | connect(menuBar, &ExportedPlatformMenuBar::menuRemoved, this, [this](QPlatformMenu* menu) { | ||
2018 | 59 | removeMenu(qobject_cast<ExportedPlatformMenu*>(menu), 0); | ||
2019 | 60 | }); | ||
2020 | 61 | } | ||
2021 | 62 | |||
2022 | 63 | QPADBusMenuExporter::~QPADBusMenuExporter() | ||
2023 | 64 | { | ||
2024 | 65 | } | ||
2025 | 66 | |||
2026 | 67 | void QPADBusMenuExporter::Event(int id, const QString &eventType, const QDBusVariant &data, uint timestamp) | ||
2027 | 68 | { | ||
2028 | 69 | Q_UNUSED(data); | ||
2029 | 70 | Q_UNUSED(timestamp); | ||
2030 | 71 | LOG << " id:" << id << ", eventType:" << eventType; | ||
2031 | 72 | |||
2032 | 73 | ExportedPlatformMenuItem* menuItem = m_menuItemForId.value(id, nullptr); | ||
2033 | 74 | if (menuItem) { | ||
2034 | 75 | if (eventType == "clicked") { | ||
2035 | 76 | QMetaObject::invokeMethod(menuItem, "activated"); | ||
2036 | 77 | } else if (eventType == "hovered") { | ||
2037 | 78 | QMetaObject::invokeMethod(menuItem, "hovered"); | ||
2038 | 79 | } | ||
2039 | 80 | } | ||
2040 | 81 | } | ||
2041 | 82 | |||
2042 | 83 | QDBusVariant QPADBusMenuExporter::GetProperty(int id, const QString &property) | ||
2043 | 84 | { | ||
2044 | 85 | if (!m_propertiesForId.contains(id)) return QDBusVariant(); | ||
2045 | 86 | return QDBusVariant(m_propertiesForId.value(id).value(property)); | ||
2046 | 87 | } | ||
2047 | 88 | |||
2048 | 89 | void QPADBusMenuExporter::fillLayout(DBusMenuLayoutItem *item, int id, int depth, const QStringList &propertyNames) | ||
2049 | 90 | { | ||
2050 | 91 | item->id = id; | ||
2051 | 92 | item->properties = getProperties(id, propertyNames); | ||
2052 | 93 | |||
2053 | 94 | if (depth != 0) { | ||
2054 | 95 | if (id == 0) { | ||
2055 | 96 | for (uint i = 0; i < m_menuBar->menuCount(); i++) { | ||
2056 | 97 | auto exportedMenu = qobject_cast<ExportedPlatformMenu*>(m_menuBar->menuAt(i)); | ||
2057 | 98 | if (exportedMenu) { | ||
2058 | 99 | DBusMenuLayoutItem child; | ||
2059 | 100 | fillLayout(&child, exportedMenu->id(), depth - 1, propertyNames); | ||
2060 | 101 | item->children << child; | ||
2061 | 102 | } | ||
2062 | 103 | } | ||
2063 | 104 | } else { | ||
2064 | 105 | // menu with children. | ||
2065 | 106 | ExportedPlatformMenu* menu = m_menuForId.value(id, nullptr); | ||
2066 | 107 | if (menu) { | ||
2067 | 108 | for (uint i = 0; i < menu->menuItemCount(); i++) { | ||
2068 | 109 | auto exportedMenuItem = qobject_cast<ExportedPlatformMenuItem*>(menu->menuItemAt(i)); | ||
2069 | 110 | |||
2070 | 111 | DBusMenuLayoutItem child; | ||
2071 | 112 | fillLayout(&child, exportedMenuItem->id(), depth-1, propertyNames); | ||
2072 | 113 | item->children << child; | ||
2073 | 114 | } | ||
2074 | 115 | } else { | ||
2075 | 116 | // child menu items which has an attached menu | ||
2076 | 117 | ExportedPlatformMenuItem* menuItem = m_menuItemForId.value(id, nullptr); | ||
2077 | 118 | if (menuItem) { | ||
2078 | 119 | auto menu = qobject_cast<ExportedPlatformMenu*>(menuItem->menu()); | ||
2079 | 120 | if (menu) { | ||
2080 | 121 | for (uint i = 0; i < menu->menuItemCount(); i++) { | ||
2081 | 122 | auto exportedMenuItem = qobject_cast<ExportedPlatformMenuItem*>(menu->menuItemAt(i)); | ||
2082 | 123 | |||
2083 | 124 | DBusMenuLayoutItem child; | ||
2084 | 125 | fillLayout(&child, exportedMenuItem->id(), depth-1, propertyNames); | ||
2085 | 126 | item->children << child; | ||
2086 | 127 | } | ||
2087 | 128 | } | ||
2088 | 129 | } | ||
2089 | 130 | } | ||
2090 | 131 | } | ||
2091 | 132 | } | ||
2092 | 133 | } | ||
2093 | 134 | |||
2094 | 135 | uint QPADBusMenuExporter::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) | ||
2095 | 136 | { | ||
2096 | 137 | doMenuPropertyUpdate(); | ||
2097 | 138 | |||
2098 | 139 | fillLayout(&item, parentId, recursionDepth, propertyNames); | ||
2099 | 140 | return m_revision; | ||
2100 | 141 | } | ||
2101 | 142 | |||
2102 | 143 | DBusMenuItemList QPADBusMenuExporter::GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames) | ||
2103 | 144 | { | ||
2104 | 145 | DBusMenuItemList list; | ||
2105 | 146 | Q_FOREACH(int id, ids) { | ||
2106 | 147 | DBusMenuItem item; | ||
2107 | 148 | item.id = id; | ||
2108 | 149 | item.properties = getProperties(item.id, propertyNames); | ||
2109 | 150 | list << item; | ||
2110 | 151 | } | ||
2111 | 152 | return list; | ||
2112 | 153 | } | ||
2113 | 154 | |||
2114 | 155 | bool QPADBusMenuExporter::AboutToShow(int id) | ||
2115 | 156 | { | ||
2116 | 157 | return false; | ||
2117 | 158 | } | ||
2118 | 159 | |||
2119 | 160 | void QPADBusMenuExporter::menuPropertyUpdated(int id) | ||
2120 | 161 | { | ||
2121 | 162 | if (m_propertyUpdates.contains(id)) return; | ||
2122 | 163 | |||
2123 | 164 | m_propertyUpdates << id; | ||
2124 | 165 | if (!m_propertyTimer->isActive()) m_propertyTimer->start(); | ||
2125 | 166 | } | ||
2126 | 167 | |||
2127 | 168 | void QPADBusMenuExporter::menuLayoutUpdated(int id) | ||
2128 | 169 | { | ||
2129 | 170 | if (m_layoutUpdates.contains(id)) return; | ||
2130 | 171 | |||
2131 | 172 | m_layoutUpdates << id; | ||
2132 | 173 | if (!m_layoutTimer->isActive()) m_layoutTimer->start(); | ||
2133 | 174 | } | ||
2134 | 175 | |||
2135 | 176 | inline void logPropertyUpdates(const DBusMenuItemList& updates, const DBusMenuItemKeysList& removals) | ||
2136 | 177 | { | ||
2137 | 178 | Q_FOREACH(const DBusMenuItem& update, updates) { | ||
2138 | 179 | qDebug() << "property updates for " << update.id << endl | ||
2139 | 180 | << " " << update.properties; | ||
2140 | 181 | } | ||
2141 | 182 | Q_FOREACH(const DBusMenuItemKeys& remove, removals) { | ||
2142 | 183 | qDebug() << "property updates for " << remove.id << endl | ||
2143 | 184 | << " " << remove.properties; | ||
2144 | 185 | } | ||
2145 | 186 | } | ||
2146 | 187 | |||
2147 | 188 | void QPADBusMenuExporter::doMenuPropertyUpdate() | ||
2148 | 189 | { | ||
2149 | 190 | if (m_propertyUpdates.isEmpty()) { | ||
2150 | 191 | return; | ||
2151 | 192 | } | ||
2152 | 193 | DBusMenuItemList updatedList; | ||
2153 | 194 | DBusMenuItemKeysList removedList; | ||
2154 | 195 | |||
2155 | 196 | Q_FOREACH(int id, m_propertyUpdates) { | ||
2156 | 197 | QVariantMap newProperties; | ||
2157 | 198 | ExportedPlatformMenuItem* menuItem = m_menuItemForId.value(id, nullptr); | ||
2158 | 199 | // no longer exists? | ||
2159 | 200 | if (menuItem) { | ||
2160 | 201 | newProperties = ExportedPlatformMenuItemPrivate::propertiesForMenuItem(menuItem); | ||
2161 | 202 | } else { | ||
2162 | 203 | ExportedPlatformMenu* menu = m_menuForId.value(id, nullptr); | ||
2163 | 204 | if (menu) { | ||
2164 | 205 | newProperties = ExportedPlatformMenuPrivate::propertiesForMenu(menu); | ||
2165 | 206 | } | ||
2166 | 207 | } | ||
2167 | 208 | |||
2168 | 209 | QVariantMap& oldProperties = m_propertiesForId[id]; | ||
2169 | 210 | QVariantMap updatedProperties; | ||
2170 | 211 | QStringList removedProperties; | ||
2171 | 212 | |||
2172 | 213 | Utils::parsePropertyChanges(oldProperties, newProperties, updatedProperties, removedProperties); | ||
2173 | 214 | |||
2174 | 215 | // Update our data (oldProperties is a reference) | ||
2175 | 216 | oldProperties = newProperties; | ||
2176 | 217 | |||
2177 | 218 | if (!updatedProperties.isEmpty()) { | ||
2178 | 219 | DBusMenuItem item; | ||
2179 | 220 | item.id = id; | ||
2180 | 221 | item.properties = updatedProperties; | ||
2181 | 222 | updatedList << item; | ||
2182 | 223 | } | ||
2183 | 224 | if (!removedProperties.isEmpty()) { | ||
2184 | 225 | DBusMenuItemKeys itemKeys; | ||
2185 | 226 | itemKeys.id = id; | ||
2186 | 227 | itemKeys.properties = removedProperties; | ||
2187 | 228 | removedList << itemKeys; | ||
2188 | 229 | } | ||
2189 | 230 | } | ||
2190 | 231 | m_propertyUpdates.clear(); | ||
2191 | 232 | |||
2192 | 233 | if (!m_emittedLayoutUpdatedOnce) { | ||
2193 | 234 | // No need to tell the world about action changes: nobody knows the | ||
2194 | 235 | // menu layout so nobody knows about the actions. | ||
2195 | 236 | // Note: We still need to reach this method because we want our properties to be | ||
2196 | 237 | // updated, even if we don't announce changes. | ||
2197 | 238 | return; | ||
2198 | 239 | } | ||
2199 | 240 | if (!updatedList.isEmpty() || !removedList.isEmpty()) { | ||
2200 | 241 | #ifdef ENABLE_DEBUG_LOGGING | ||
2201 | 242 | logPropertyUpdates(updatedList, removedList); | ||
2202 | 243 | #endif | ||
2203 | 244 | |||
2204 | 245 | Q_EMIT ItemsPropertiesUpdated(updatedList, removedList); | ||
2205 | 246 | } | ||
2206 | 247 | } | ||
2207 | 248 | |||
2208 | 249 | void QPADBusMenuExporter::doMenuLayoutUpdate() | ||
2209 | 250 | { | ||
2210 | 251 | // Tell the world about the update | ||
2211 | 252 | if (m_emittedLayoutUpdatedOnce) { | ||
2212 | 253 | Q_FOREACH(int id, m_layoutUpdates) { | ||
2213 | 254 | Q_EMIT LayoutUpdated(++m_revision, id); | ||
2214 | 255 | } | ||
2215 | 256 | } else { | ||
2216 | 257 | // First time we emit LayoutUpdated, no need to emit several layout | ||
2217 | 258 | // updates, signals the whole layout (id==0) has been updated | ||
2218 | 259 | Q_EMIT LayoutUpdated(++m_revision, 0); | ||
2219 | 260 | m_emittedLayoutUpdatedOnce = true; | ||
2220 | 261 | } | ||
2221 | 262 | m_layoutUpdates.clear(); | ||
2222 | 263 | } | ||
2223 | 264 | |||
2224 | 265 | void QPADBusMenuExporter::addMenu(ExportedPlatformMenu *menu, int parentId) | ||
2225 | 266 | { | ||
2226 | 267 | if (!menu) return; | ||
2227 | 268 | if (m_menuForId.contains(menu->id())) return; | ||
2228 | 269 | |||
2229 | 270 | for (uint i = 0; i < menu->menuItemCount(); i++) { | ||
2230 | 271 | auto exportedMenuItem = qobject_cast<ExportedPlatformMenuItem*>(menu->menuItemAt(i)); | ||
2231 | 272 | addMenuItem(exportedMenuItem, menu->id()); | ||
2232 | 273 | } | ||
2233 | 274 | |||
2234 | 275 | m_menuForId[menu->id()] = menu; | ||
2235 | 276 | m_propertiesForId[menu->id()] = ExportedPlatformMenuPrivate::propertiesForMenu(menu); | ||
2236 | 277 | connect(menu, &ExportedPlatformMenu::propertyUpdated, this, [&, menu]() { | ||
2237 | 278 | menuPropertyUpdated(menu->id()); | ||
2238 | 279 | }); | ||
2239 | 280 | connect(menu, &ExportedPlatformMenu::menuItemInserted, this, [&, menu](QPlatformMenuItem* menuItem) { | ||
2240 | 281 | addMenuItem(qobject_cast<ExportedPlatformMenuItem*>(menuItem), menu->id()); | ||
2241 | 282 | }); | ||
2242 | 283 | connect(menu, &ExportedPlatformMenu::menuItemRemoved, this, [&, menu](QPlatformMenuItem* menuItem) { | ||
2243 | 284 | removeMenuItem(qobject_cast<ExportedPlatformMenuItem*>(menuItem), menu->id()); | ||
2244 | 285 | }); | ||
2245 | 286 | |||
2246 | 287 | menuLayoutUpdated(parentId); | ||
2247 | 288 | } | ||
2248 | 289 | |||
2249 | 290 | void QPADBusMenuExporter::addMenuItem(ExportedPlatformMenuItem *menuItem, int parentId) | ||
2250 | 291 | { | ||
2251 | 292 | if (!menuItem) return; | ||
2252 | 293 | if (m_menuItemForId.contains(menuItem->id())) return; | ||
2253 | 294 | |||
2254 | 295 | m_menuItemForId[menuItem->id()] = menuItem; | ||
2255 | 296 | m_propertiesForId[menuItem->id()] = ExportedPlatformMenuItemPrivate::propertiesForMenuItem(menuItem); | ||
2256 | 297 | |||
2257 | 298 | connect(menuItem, &ExportedPlatformMenuItem::propertyUpdated, this, [&, menuItem]() { | ||
2258 | 299 | menuPropertyUpdated(menuItem->id()); | ||
2259 | 300 | }); | ||
2260 | 301 | |||
2261 | 302 | auto menu = qobject_cast<ExportedPlatformMenu*>(menuItem->menu()); | ||
2262 | 303 | if (menu) { | ||
2263 | 304 | addMenu(menu, parentId); | ||
2264 | 305 | } | ||
2265 | 306 | menuLayoutUpdated(parentId); | ||
2266 | 307 | } | ||
2267 | 308 | |||
2268 | 309 | void QPADBusMenuExporter::removeMenu(ExportedPlatformMenu *menu, int parentId) | ||
2269 | 310 | { | ||
2270 | 311 | if (!menu) return; | ||
2271 | 312 | |||
2272 | 313 | for (uint i = 0; i < menu->menuItemCount(); i++) { | ||
2273 | 314 | auto exportedMenuItem = qobject_cast<ExportedPlatformMenuItem*>(menu->menuItemAt(i)); | ||
2274 | 315 | removeMenuItem(exportedMenuItem, parentId); | ||
2275 | 316 | } | ||
2276 | 317 | disconnect(menu, 0, this, 0); | ||
2277 | 318 | } | ||
2278 | 319 | |||
2279 | 320 | void QPADBusMenuExporter::removeMenuItem(ExportedPlatformMenuItem *menuItem, int parentId) | ||
2280 | 321 | { | ||
2281 | 322 | if (!menuItem) return; | ||
2282 | 323 | |||
2283 | 324 | auto menu = qobject_cast<ExportedPlatformMenu*>(menuItem->menu()); | ||
2284 | 325 | if (menu) { | ||
2285 | 326 | removeMenu(menu, menuItem->id()); | ||
2286 | 327 | } | ||
2287 | 328 | |||
2288 | 329 | m_menuItemForId.remove(menuItem->id()); | ||
2289 | 330 | m_propertiesForId.remove(menuItem->id()); | ||
2290 | 331 | disconnect(menuItem, 0, this, 0); | ||
2291 | 332 | |||
2292 | 333 | menuLayoutUpdated(parentId); | ||
2293 | 334 | } | ||
2294 | 335 | |||
2295 | 336 | QVariantMap QPADBusMenuExporter::getProperties(int id, const QStringList &names) const | ||
2296 | 337 | { | ||
2297 | 338 | if (id == 0) { | ||
2298 | 339 | QVariantMap map; | ||
2299 | 340 | map.insert(DBusMenuProperty::ChildrenDisplay, "submenu"); | ||
2300 | 341 | return map; | ||
2301 | 342 | } | ||
2302 | 343 | QVariantMap all = m_propertiesForId.value(id); | ||
2303 | 344 | if (names.isEmpty()) { | ||
2304 | 345 | return all; | ||
2305 | 346 | } else { | ||
2306 | 347 | QVariantMap map; | ||
2307 | 348 | Q_FOREACH(const QString &name, names) { | ||
2308 | 349 | QVariant value = all.value(name); | ||
2309 | 350 | if (value.isValid()) { | ||
2310 | 351 | map.insert(name, value); | ||
2311 | 352 | } | ||
2312 | 353 | } | ||
2313 | 354 | return map; | ||
2314 | 355 | } | ||
2315 | 356 | } | ||
2316 | 357 | |||
2317 | 0 | 358 | ||
2318 | === added file 'src/qpa/qpadbusmenuexporter_p.h' | |||
2319 | --- src/qpa/qpadbusmenuexporter_p.h 1970-01-01 00:00:00 +0000 | |||
2320 | +++ src/qpa/qpadbusmenuexporter_p.h 2015-03-18 11:19:06 +0000 | |||
2321 | @@ -0,0 +1,94 @@ | |||
2322 | 1 | /* This file is part of the dbusmenu-qt library | ||
2323 | 2 | Copyright 2015 Canonical | ||
2324 | 3 | Author: Nick Dedekind <nick.dedekind@canonical.com> | ||
2325 | 4 | |||
2326 | 5 | This library is free software; you can redistribute it and/or | ||
2327 | 6 | modify it under the terms of the GNU Library General Public | ||
2328 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
2329 | 8 | either version 2 of the License, or (at your option) any later | ||
2330 | 9 | version. | ||
2331 | 10 | |||
2332 | 11 | This library is distributed in the hope that it will be useful, | ||
2333 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2334 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2335 | 14 | Library General Public License for more details. | ||
2336 | 15 | |||
2337 | 16 | You should have received a copy of the GNU Library General Public License | ||
2338 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
2339 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2340 | 19 | Boston, MA 02110-1301, USA. | ||
2341 | 20 | */ | ||
2342 | 21 | #ifndef QPADBUSMENUEXPORTER_H | ||
2343 | 22 | #define QPADBUSMENUEXPORTER_H | ||
2344 | 23 | |||
2345 | 24 | // Qt | ||
2346 | 25 | #include <QtCore/QObject> | ||
2347 | 26 | #include <QtDBus/QDBusConnection> | ||
2348 | 27 | #include <qpa/qplatformmenu.h> | ||
2349 | 28 | |||
2350 | 29 | // Local | ||
2351 | 30 | #include "dbusmenuexporterdbusinterface_p.h" | ||
2352 | 31 | |||
2353 | 32 | class QAction; | ||
2354 | 33 | class QMenu; | ||
2355 | 34 | |||
2356 | 35 | class ExportedPlatformMenuBar; | ||
2357 | 36 | class ExportedPlatformMenu; | ||
2358 | 37 | class ExportedPlatformMenuItem; | ||
2359 | 38 | |||
2360 | 39 | /** | ||
2361 | 40 | * A QPADBusMenuExporter instance can serialize a qua menu over DBus | ||
2362 | 41 | */ | ||
2363 | 42 | class QPADBusMenuExporter : public DBusMenuExporterDBusInterface | ||
2364 | 43 | { | ||
2365 | 44 | Q_OBJECT | ||
2366 | 45 | Q_CLASSINFO("D-Bus Interface", "com.canonical.dbusmenu") | ||
2367 | 46 | public: | ||
2368 | 47 | QPADBusMenuExporter(const QString& path, ExportedPlatformMenuBar* menuBar); | ||
2369 | 48 | virtual ~QPADBusMenuExporter(); | ||
2370 | 49 | |||
2371 | 50 | // overrides | ||
2372 | 51 | void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp) override; | ||
2373 | 52 | QDBusVariant GetProperty(int id, const QString &property) override; | ||
2374 | 53 | uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) override; | ||
2375 | 54 | DBusMenuItemList GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames) override; | ||
2376 | 55 | bool AboutToShow(int id) override; | ||
2377 | 56 | |||
2378 | 57 | private Q_SLOTS: | ||
2379 | 58 | void menuPropertyUpdated(int id); | ||
2380 | 59 | void menuLayoutUpdated(int id); | ||
2381 | 60 | |||
2382 | 61 | private Q_SLOTS: | ||
2383 | 62 | void doMenuPropertyUpdate(); | ||
2384 | 63 | void doMenuLayoutUpdate(); | ||
2385 | 64 | |||
2386 | 65 | private: | ||
2387 | 66 | Q_DISABLE_COPY(QPADBusMenuExporter) | ||
2388 | 67 | |||
2389 | 68 | void addMenu(ExportedPlatformMenu* menu, int parentId); | ||
2390 | 69 | void addMenuItem(ExportedPlatformMenuItem* menu, int parentId); | ||
2391 | 70 | |||
2392 | 71 | void removeMenu(ExportedPlatformMenu* menu, int parentId); | ||
2393 | 72 | void removeMenuItem(ExportedPlatformMenuItem* menuItem, int parentId); | ||
2394 | 73 | |||
2395 | 74 | void fillLayout(DBusMenuLayoutItem *item, int id, int depth, const QStringList &propertyNames); | ||
2396 | 75 | QVariantMap getProperties(int id, const QStringList &names) const; | ||
2397 | 76 | |||
2398 | 77 | ExportedPlatformMenuBar* m_menuBar; | ||
2399 | 78 | QTimer* m_propertyTimer; | ||
2400 | 79 | QTimer* m_layoutTimer; | ||
2401 | 80 | |||
2402 | 81 | QList<int> m_propertyUpdates; | ||
2403 | 82 | QList<int> m_layoutUpdates; | ||
2404 | 83 | uint m_revision; | ||
2405 | 84 | bool m_emittedLayoutUpdatedOnce; | ||
2406 | 85 | |||
2407 | 86 | QHash<int, ExportedPlatformMenuItem*> m_menuItemForId; | ||
2408 | 87 | QHash<int, ExportedPlatformMenu*> m_menuForId; | ||
2409 | 88 | QHash<int, QVariantMap> m_propertiesForId; | ||
2410 | 89 | |||
2411 | 90 | friend class ExportedPlatformMenu; | ||
2412 | 91 | friend class ExportedPlatformMenuItem; | ||
2413 | 92 | }; | ||
2414 | 93 | |||
2415 | 94 | #endif /* QPADBUSMENUEXPORTER_H */ | ||
2416 | 0 | 95 | ||
2417 | === modified file 'src/utils.cpp' | |||
2418 | --- src/utils.cpp 2010-09-20 08:55:12 +0000 | |||
2419 | +++ src/utils.cpp 2015-03-18 11:19:06 +0000 | |||
2420 | @@ -23,7 +23,7 @@ | |||
2421 | 23 | // Qt | 23 | // Qt |
2422 | 24 | #include <QString> | 24 | #include <QString> |
2423 | 25 | 25 | ||
2425 | 26 | QString swapMnemonicChar(const QString &in, const char src, const char dst) | 26 | QString Utils::swapMnemonicChar(const QString &in, const char src, const char dst) |
2426 | 27 | { | 27 | { |
2427 | 28 | QString out; | 28 | QString out; |
2428 | 29 | bool mnemonicFound = false; | 29 | bool mnemonicFound = false; |
2429 | @@ -62,3 +62,38 @@ | |||
2430 | 62 | 62 | ||
2431 | 63 | return out; | 63 | return out; |
2432 | 64 | } | 64 | } |
2433 | 65 | |||
2434 | 66 | |||
2435 | 67 | void Utils::parsePropertyChanges(const QVariantMap &oldProperties, | ||
2436 | 68 | const QVariantMap &newProperties, | ||
2437 | 69 | QVariantMap &updatedProperties, | ||
2438 | 70 | QStringList &removedProperties) | ||
2439 | 71 | { | ||
2440 | 72 | // Find updated and removed properties | ||
2441 | 73 | QVariantMap::ConstIterator newEnd = newProperties.constEnd(); | ||
2442 | 74 | |||
2443 | 75 | QVariantMap::ConstIterator | ||
2444 | 76 | oldIt = oldProperties.constBegin(), | ||
2445 | 77 | oldEnd = oldProperties.constEnd(); | ||
2446 | 78 | for(; oldIt != oldEnd; ++oldIt) { | ||
2447 | 79 | QString key = oldIt.key(); | ||
2448 | 80 | QVariantMap::ConstIterator newIt = newProperties.constFind(key); | ||
2449 | 81 | if (newIt != newEnd) { | ||
2450 | 82 | if (newIt.value() != oldIt.value()) { | ||
2451 | 83 | updatedProperties.insert(key, newIt.value()); | ||
2452 | 84 | } | ||
2453 | 85 | } else { | ||
2454 | 86 | removedProperties << key; | ||
2455 | 87 | } | ||
2456 | 88 | } | ||
2457 | 89 | |||
2458 | 90 | // Find new properties (treat them as updated properties) | ||
2459 | 91 | QVariantMap::ConstIterator newIt = newProperties.constBegin(); | ||
2460 | 92 | for (; newIt != newEnd; ++newIt) { | ||
2461 | 93 | QString key = newIt.key(); | ||
2462 | 94 | oldIt = oldProperties.constFind(key); | ||
2463 | 95 | if (oldIt == oldEnd) { | ||
2464 | 96 | updatedProperties.insert(key, newIt.value()); | ||
2465 | 97 | } | ||
2466 | 98 | } | ||
2467 | 99 | } | ||
2468 | 65 | 100 | ||
2469 | === modified file 'src/utils_p.h' | |||
2470 | --- src/utils_p.h 2010-09-20 08:55:12 +0000 | |||
2471 | +++ src/utils_p.h 2015-03-18 11:19:06 +0000 | |||
2472 | @@ -22,10 +22,20 @@ | |||
2473 | 22 | #define UTILS_P_H | 22 | #define UTILS_P_H |
2474 | 23 | 23 | ||
2475 | 24 | class QString; | 24 | class QString; |
2481 | 25 | 25 | class QStringList; | |
2482 | 26 | /** | 26 | #include <QVariant> |
2483 | 27 | * Swap mnemonic char: Qt uses '&', while dbusmenu uses '_' | 27 | |
2484 | 28 | */ | 28 | namespace Utils { |
2485 | 29 | QString swapMnemonicChar(const QString &in, const char src, const char dst); | 29 | |
2486 | 30 | /** | ||
2487 | 31 | * Swap mnemonic char: Qt uses '&', while dbusmenu uses '_' | ||
2488 | 32 | */ | ||
2489 | 33 | QString swapMnemonicChar(const QString &in, const char src, const char dst); | ||
2490 | 34 | |||
2491 | 35 | void parsePropertyChanges(const QVariantMap& oldProperties, | ||
2492 | 36 | const QVariantMap& newProperties, | ||
2493 | 37 | QVariantMap& updatedProperties, | ||
2494 | 38 | QStringList& removedProperties); | ||
2495 | 39 | } | ||
2496 | 30 | 40 | ||
2497 | 31 | #endif /* UTILS_P_H */ | 41 | #endif /* UTILS_P_H */ |
2498 | 32 | 42 | ||
2499 | === modified file 'tests/CMakeLists.txt' | |||
2500 | --- tests/CMakeLists.txt 2015-03-18 11:19:06 +0000 | |||
2501 | +++ tests/CMakeLists.txt 2015-03-18 11:19:06 +0000 | |||
2502 | @@ -120,5 +120,18 @@ | |||
2503 | 120 | ${test_LIBRARIES} | 120 | ${test_LIBRARIES} |
2504 | 121 | ) | 121 | ) |
2505 | 122 | 122 | ||
2506 | 123 | |||
2507 | 124 | # exportedplatformmenutest | ||
2508 | 125 | if (USE_QT5) | ||
2509 | 126 | add_test_executable(exportedplatformmenutest | ||
2510 | 127 | exportedplatformmenutest.cpp | ||
2511 | 128 | testutils.cpp | ||
2512 | 129 | ) | ||
2513 | 130 | |||
2514 | 131 | target_link_libraries(exportedplatformmenutest | ||
2515 | 132 | ${test_LIBRARIES} | ||
2516 | 133 | ) | ||
2517 | 134 | endif() | ||
2518 | 135 | |||
2519 | 123 | # Keep this at the end | 136 | # Keep this at the end |
2520 | 124 | create_check_target() | 137 | create_check_target() |
2521 | 125 | 138 | ||
2522 | === modified file 'tests/dbusmenuexportertest.cpp' | |||
2523 | --- tests/dbusmenuexportertest.cpp 2015-03-18 11:19:06 +0000 | |||
2524 | +++ tests/dbusmenuexportertest.cpp 2015-03-18 11:19:06 +0000 | |||
2525 | @@ -31,7 +31,7 @@ | |||
2526 | 31 | 31 | ||
2527 | 32 | // DBusMenuQt | 32 | // DBusMenuQt |
2528 | 33 | #include <dbusmenuexporter.h> | 33 | #include <dbusmenuexporter.h> |
2530 | 34 | #include <dbusmenutypes_p.h> | 34 | #include <dbusmenutypes.h> |
2531 | 35 | #include <dbusmenushortcut_p.h> | 35 | #include <dbusmenushortcut_p.h> |
2532 | 36 | #include <debug_p.h> | 36 | #include <debug_p.h> |
2533 | 37 | 37 | ||
2534 | @@ -114,6 +114,7 @@ | |||
2535 | 114 | if (enabled) { | 114 | if (enabled) { |
2536 | 115 | QVERIFY(!item.properties.contains("enabled")); | 115 | QVERIFY(!item.properties.contains("enabled")); |
2537 | 116 | } else { | 116 | } else { |
2538 | 117 | QVERIFY(item.properties.contains("enabled")); | ||
2539 | 117 | QCOMPARE(item.properties.value("enabled").toBool(), false); | 118 | QCOMPARE(item.properties.value("enabled").toBool(), false); |
2540 | 118 | } | 119 | } |
2541 | 119 | if (iconName.isEmpty()) { | 120 | if (iconName.isEmpty()) { |
2542 | 120 | 121 | ||
2543 | === added file 'tests/exportedplatformmenutest.cpp' | |||
2544 | --- tests/exportedplatformmenutest.cpp 1970-01-01 00:00:00 +0000 | |||
2545 | +++ tests/exportedplatformmenutest.cpp 2015-03-18 11:19:06 +0000 | |||
2546 | @@ -0,0 +1,366 @@ | |||
2547 | 1 | /* This file is part of the dbusmenu-qt library | ||
2548 | 2 | Copyright 2015 Canonical | ||
2549 | 3 | Author: Aurelien Gateau <aurelien.gateau@canonical.com> | ||
2550 | 4 | |||
2551 | 5 | This library is free software; you can redistribute it and/or | ||
2552 | 6 | modify it under the terms of the GNU Library General Public | ||
2553 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
2554 | 8 | either version 2 of the License, or (at your option) any later | ||
2555 | 9 | version. | ||
2556 | 10 | |||
2557 | 11 | This library is distributed in the hope that it will be useful, | ||
2558 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2559 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2560 | 14 | Library General Public License for more details. | ||
2561 | 15 | |||
2562 | 16 | You should have received a copy of the GNU Library General Public License | ||
2563 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
2564 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2565 | 19 | Boston, MA 02110-1301, USA. | ||
2566 | 20 | */ | ||
2567 | 21 | // Self | ||
2568 | 22 | #include "exportedplatformmenutest.h" | ||
2569 | 23 | |||
2570 | 24 | // Qt | ||
2571 | 25 | #include <QDBusConnection> | ||
2572 | 26 | #include <QDBusInterface> | ||
2573 | 27 | #include <QDBusReply> | ||
2574 | 28 | #include <QtTest> | ||
2575 | 29 | |||
2576 | 30 | // DBusMenuQt | ||
2577 | 31 | #include <qpa/exportedplatformmenubar.h> | ||
2578 | 32 | #include <dbusmenutypes.h> | ||
2579 | 33 | #include <dbusmenushortcut_p.h> | ||
2580 | 34 | #include <debug_p.h> | ||
2581 | 35 | |||
2582 | 36 | // Local | ||
2583 | 37 | #include "testutils.h" | ||
2584 | 38 | |||
2585 | 39 | QTEST_MAIN(ExportedPlatformMenuTest) | ||
2586 | 40 | |||
2587 | 41 | static const char *TEST_SERVICE = "org.kde.dbusmenu-qt-test"; | ||
2588 | 42 | static const char *TEST_OBJECT_PATH = "/TestMenuBar"; | ||
2589 | 43 | |||
2590 | 44 | Q_DECLARE_METATYPE(QList<int>) | ||
2591 | 45 | |||
2592 | 46 | static DBusMenuLayoutItemList getChildren(QDBusAbstractInterface* iface, int parentId, const QStringList &propertyNames) | ||
2593 | 47 | { | ||
2594 | 48 | QDBusPendingReply<uint, DBusMenuLayoutItem> reply = iface->call("GetLayout", parentId, /*recursionDepth=*/ 1, propertyNames); | ||
2595 | 49 | reply.waitForFinished(); | ||
2596 | 50 | if (!reply.isValid()) { | ||
2597 | 51 | qFatal("%s", qPrintable(reply.error().message())); | ||
2598 | 52 | return DBusMenuLayoutItemList(); | ||
2599 | 53 | } | ||
2600 | 54 | |||
2601 | 55 | DBusMenuLayoutItem rootItem = reply.argumentAt<1>(); | ||
2602 | 56 | return rootItem.children; | ||
2603 | 57 | } | ||
2604 | 58 | |||
2605 | 59 | void ExportedPlatformMenuTest::init() | ||
2606 | 60 | { | ||
2607 | 61 | QVERIFY(QDBusConnection::sessionBus().registerService(TEST_SERVICE)); | ||
2608 | 62 | QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, false); | ||
2609 | 63 | } | ||
2610 | 64 | |||
2611 | 65 | void ExportedPlatformMenuTest::cleanup() | ||
2612 | 66 | { | ||
2613 | 67 | QVERIFY(QDBusConnection::sessionBus().unregisterService(TEST_SERVICE)); | ||
2614 | 68 | } | ||
2615 | 69 | |||
2616 | 70 | void ExportedPlatformMenuTest::testGetSomeMenuProperties_data() | ||
2617 | 71 | { | ||
2618 | 72 | QTest::addColumn<QString>("label"); | ||
2619 | 73 | QTest::addColumn<QString>("iconName"); | ||
2620 | 74 | QTest::addColumn<bool>("enabled"); | ||
2621 | 75 | |||
2622 | 76 | QTest::newRow("label only") << "label" << QString() << true; | ||
2623 | 77 | QTest::newRow("disabled, label only") << "label" << QString() << false; | ||
2624 | 78 | QTest::newRow("icon name") << "label" << "edit-undo" << true; | ||
2625 | 79 | } | ||
2626 | 80 | |||
2627 | 81 | void ExportedPlatformMenuTest::testGetSomeMenuProperties() | ||
2628 | 82 | { | ||
2629 | 83 | QFETCH(QString, label); | ||
2630 | 84 | QFETCH(QString, iconName); | ||
2631 | 85 | QFETCH(bool, enabled); | ||
2632 | 86 | |||
2633 | 87 | // Create an exporter for a menu with one action, defined by the test data | ||
2634 | 88 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2635 | 89 | ExportedPlatformMenu menu; | ||
2636 | 90 | menu.setText(label); | ||
2637 | 91 | if (!iconName.isEmpty()) { | ||
2638 | 92 | QIcon icon = QIcon::fromTheme(iconName); | ||
2639 | 93 | QVERIFY(!icon.isNull()); | ||
2640 | 94 | menu.setIcon(icon); | ||
2641 | 95 | } | ||
2642 | 96 | menu.setEnabled(enabled); | ||
2643 | 97 | menuBar.insertMenu(&menu, nullptr); | ||
2644 | 98 | |||
2645 | 99 | // Check out exporter is on DBus | ||
2646 | 100 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2647 | 101 | QVERIFY2(iface.isValid(), qPrintable(iface.lastError().message())); | ||
2648 | 102 | |||
2649 | 103 | // Get exported menu info | ||
2650 | 104 | QStringList propertyNames = QStringList() << "type" << "enabled" << "label" << "icon-name"; | ||
2651 | 105 | DBusMenuLayoutItemList list = getChildren(&iface, /*parentId=*/0, propertyNames); | ||
2652 | 106 | QVERIFY(!list.isEmpty()); | ||
2653 | 107 | DBusMenuLayoutItem item = list.first(); | ||
2654 | 108 | |||
2655 | 109 | QVERIFY(item.id != 0); | ||
2656 | 110 | QVERIFY(item.children.isEmpty()); | ||
2657 | 111 | QVERIFY(!item.properties.contains("type")); | ||
2658 | 112 | QCOMPARE(item.properties.value("label").toString(), label); | ||
2659 | 113 | if (enabled) { | ||
2660 | 114 | QVERIFY(!item.properties.contains("enabled")); | ||
2661 | 115 | } else { | ||
2662 | 116 | QVERIFY(item.properties.contains("enabled")); | ||
2663 | 117 | QCOMPARE(item.properties.value("enabled").toBool(), false); | ||
2664 | 118 | } | ||
2665 | 119 | if (iconName.isEmpty()) { | ||
2666 | 120 | QVERIFY(!item.properties.contains("icon-name")); | ||
2667 | 121 | } else { | ||
2668 | 122 | QCOMPARE(item.properties.value("icon-name").toString(), iconName); | ||
2669 | 123 | } | ||
2670 | 124 | } | ||
2671 | 125 | |||
2672 | 126 | void ExportedPlatformMenuTest::testGetSomeMenuItemProperties_data() | ||
2673 | 127 | { | ||
2674 | 128 | QTest::addColumn<QString>("label"); | ||
2675 | 129 | QTest::addColumn<QString>("iconName"); | ||
2676 | 130 | QTest::addColumn<bool>("enabled"); | ||
2677 | 131 | |||
2678 | 132 | QTest::newRow("label only") << "label" << QString() << true; | ||
2679 | 133 | QTest::newRow("disabled, label only") << "label" << QString() << false; | ||
2680 | 134 | QTest::newRow("icon name") << "label" << "edit-undo" << true; | ||
2681 | 135 | } | ||
2682 | 136 | |||
2683 | 137 | void ExportedPlatformMenuTest::testGetSomeMenuItemProperties() | ||
2684 | 138 | { | ||
2685 | 139 | QFETCH(QString, label); | ||
2686 | 140 | QFETCH(QString, iconName); | ||
2687 | 141 | QFETCH(bool, enabled); | ||
2688 | 142 | |||
2689 | 143 | // Create an exporter for a menu with one action, defined by the test data | ||
2690 | 144 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2691 | 145 | ExportedPlatformMenu menu; | ||
2692 | 146 | menuBar.insertMenu(&menu, nullptr); | ||
2693 | 147 | |||
2694 | 148 | ExportedPlatformMenuItem menuItem1; | ||
2695 | 149 | menuItem1.setText(label); | ||
2696 | 150 | if (!iconName.isEmpty()) { | ||
2697 | 151 | QIcon icon = QIcon::fromTheme(iconName); | ||
2698 | 152 | QVERIFY(!icon.isNull()); | ||
2699 | 153 | menuItem1.setIcon(icon); | ||
2700 | 154 | } | ||
2701 | 155 | menuItem1.setEnabled(enabled); | ||
2702 | 156 | menu.insertMenuItem(&menuItem1, nullptr); | ||
2703 | 157 | |||
2704 | 158 | // Check out exporter is on DBus | ||
2705 | 159 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2706 | 160 | QVERIFY2(iface.isValid(), qPrintable(iface.lastError().message())); | ||
2707 | 161 | |||
2708 | 162 | // Get exported menu info | ||
2709 | 163 | QStringList propertyNames = QStringList() << "type" << "enabled" << "label" << "icon-name"; | ||
2710 | 164 | DBusMenuLayoutItemList list = getChildren(&iface, /*parentId=*/0, propertyNames); | ||
2711 | 165 | QVERIFY(!list.isEmpty()); | ||
2712 | 166 | |||
2713 | 167 | // Now get the mennu children (menu items) | ||
2714 | 168 | list = getChildren(&iface, list.first().id, QStringList()); | ||
2715 | 169 | QVERIFY(!list.isEmpty()); | ||
2716 | 170 | DBusMenuLayoutItem item = list.first(); | ||
2717 | 171 | |||
2718 | 172 | QVERIFY(item.id != 0); | ||
2719 | 173 | QVERIFY(item.children.isEmpty()); | ||
2720 | 174 | QVERIFY(!item.properties.contains("type")); | ||
2721 | 175 | QCOMPARE(item.properties.value("label").toString(), label); | ||
2722 | 176 | if (enabled) { | ||
2723 | 177 | QVERIFY(!item.properties.contains("enabled")); | ||
2724 | 178 | } else { | ||
2725 | 179 | QVERIFY(item.properties.contains("enabled")); | ||
2726 | 180 | QCOMPARE(item.properties.value("enabled").toBool(), false); | ||
2727 | 181 | } | ||
2728 | 182 | if (iconName.isEmpty()) { | ||
2729 | 183 | QVERIFY(!item.properties.contains("icon-name")); | ||
2730 | 184 | } else { | ||
2731 | 185 | QCOMPARE(item.properties.value("icon-name").toString(), iconName); | ||
2732 | 186 | } | ||
2733 | 187 | } | ||
2734 | 188 | |||
2735 | 189 | void ExportedPlatformMenuTest::testGetAllProperties() | ||
2736 | 190 | { | ||
2737 | 191 | // set of properties which must be returned because their values are not | ||
2738 | 192 | // the default values | ||
2739 | 193 | const QSet<QString> a1Properties = QSet<QString>() | ||
2740 | 194 | << "label" | ||
2741 | 195 | ; | ||
2742 | 196 | |||
2743 | 197 | const QSet<QString> separatorProperties = QSet<QString>() | ||
2744 | 198 | << "type"; | ||
2745 | 199 | |||
2746 | 200 | const QSet<QString> a2Properties = QSet<QString>() | ||
2747 | 201 | << "label" | ||
2748 | 202 | << "enabled" | ||
2749 | 203 | << "icon-name" | ||
2750 | 204 | << "icon-data" // Icon data is always provided if the icon is valid. | ||
2751 | 205 | << "visible"; | ||
2752 | 206 | |||
2753 | 207 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2754 | 208 | ExportedPlatformMenu menu; | ||
2755 | 209 | menuBar.insertMenu(&menu, nullptr); | ||
2756 | 210 | |||
2757 | 211 | ExportedPlatformMenuItem menuItem1; | ||
2758 | 212 | menuItem1.setText("m1"); | ||
2759 | 213 | menu.insertMenuItem(&menuItem1, nullptr); | ||
2760 | 214 | |||
2761 | 215 | ExportedPlatformMenuItem separator; | ||
2762 | 216 | separator.setIsSeparator(true); | ||
2763 | 217 | menu.insertMenuItem(&separator, nullptr); | ||
2764 | 218 | |||
2765 | 219 | ExportedPlatformMenuItem menuItem2; | ||
2766 | 220 | menuItem2.setText("m2"); | ||
2767 | 221 | menuItem2.setEnabled(false); | ||
2768 | 222 | menuItem2.setVisible(false); | ||
2769 | 223 | QIcon icon = QIcon::fromTheme("edit-undo"); | ||
2770 | 224 | QVERIFY(!icon.isNull()); | ||
2771 | 225 | menuItem2.setIcon(icon); | ||
2772 | 226 | menu.insertMenuItem(&menuItem2, nullptr); | ||
2773 | 227 | |||
2774 | 228 | // Export them | ||
2775 | 229 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2776 | 230 | QVERIFY2(iface.isValid(), qPrintable(iface.lastError().message())); | ||
2777 | 231 | |||
2778 | 232 | // Get menu children | ||
2779 | 233 | DBusMenuLayoutItemList list = getChildren(&iface, menu.id(), QStringList()); | ||
2780 | 234 | QCOMPARE(list.count(), 3); | ||
2781 | 235 | |||
2782 | 236 | // Check we get the right properties | ||
2783 | 237 | DBusMenuLayoutItem item = list.takeFirst(); | ||
2784 | 238 | QCOMPARE(QSet<QString>::fromList(item.properties.keys()), a1Properties); | ||
2785 | 239 | |||
2786 | 240 | item = list.takeFirst(); | ||
2787 | 241 | QCOMPARE(QSet<QString>::fromList(item.properties.keys()), separatorProperties); | ||
2788 | 242 | |||
2789 | 243 | item = list.takeFirst(); | ||
2790 | 244 | QCOMPARE(QSet<QString>::fromList(item.properties.keys()), a2Properties); | ||
2791 | 245 | } | ||
2792 | 246 | |||
2793 | 247 | void ExportedPlatformMenuTest::testGetNonExistentProperty() | ||
2794 | 248 | { | ||
2795 | 249 | const char* NON_EXISTENT_KEY = "i-do-not-exist"; | ||
2796 | 250 | |||
2797 | 251 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2798 | 252 | ExportedPlatformMenu menu; | ||
2799 | 253 | menuBar.insertMenu(&menu, nullptr); | ||
2800 | 254 | |||
2801 | 255 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2802 | 256 | DBusMenuLayoutItemList list = getChildren(&iface, 0, QStringList() << NON_EXISTENT_KEY); | ||
2803 | 257 | QCOMPARE(list.count(), 1); | ||
2804 | 258 | |||
2805 | 259 | DBusMenuLayoutItem item = list.takeFirst(); | ||
2806 | 260 | QVERIFY(!item.properties.contains(NON_EXISTENT_KEY)); | ||
2807 | 261 | } | ||
2808 | 262 | |||
2809 | 263 | void ExportedPlatformMenuTest::testClickedEvent() | ||
2810 | 264 | { | ||
2811 | 265 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2812 | 266 | ExportedPlatformMenu menu; | ||
2813 | 267 | menuBar.insertMenu(&menu, nullptr); | ||
2814 | 268 | |||
2815 | 269 | ExportedPlatformMenuItem menuItem1; | ||
2816 | 270 | menuItem1.setText("m1"); | ||
2817 | 271 | menu.insertMenuItem(&menuItem1, nullptr); | ||
2818 | 272 | |||
2819 | 273 | QSignalSpy spy(&menuItem1, SIGNAL(activated())); | ||
2820 | 274 | |||
2821 | 275 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2822 | 276 | DBusMenuLayoutItemList list = getChildren(&iface, menu.id(), QStringList()); | ||
2823 | 277 | QCOMPARE(list.count(), 1); | ||
2824 | 278 | int id = list.first().id; | ||
2825 | 279 | |||
2826 | 280 | QVariant empty = QVariant::fromValue(QDBusVariant(QString())); | ||
2827 | 281 | uint timestamp = QDateTime::currentDateTime().toTime_t(); | ||
2828 | 282 | iface.call("Event", id, "clicked", empty, timestamp); | ||
2829 | 283 | QTest::qWait(100); | ||
2830 | 284 | |||
2831 | 285 | QCOMPARE(spy.count(), 1); | ||
2832 | 286 | } | ||
2833 | 287 | |||
2834 | 288 | void ExportedPlatformMenuTest::testSubMenu() | ||
2835 | 289 | { | ||
2836 | 290 | // Root | ||
2837 | 291 | // -- submenu | ||
2838 | 292 | // ---- childmenu | ||
2839 | 293 | // ----- hildmenu | ||
2840 | 294 | |||
2841 | 295 | // Create our test menu | ||
2842 | 296 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2843 | 297 | ExportedPlatformMenu menu; | ||
2844 | 298 | menuBar.insertMenu(&menu, nullptr); | ||
2845 | 299 | |||
2846 | 300 | ExportedPlatformMenu subMenu; | ||
2847 | 301 | ExportedPlatformMenuItem subMenuItem; | ||
2848 | 302 | subMenuItem.setMenu(&subMenu); | ||
2849 | 303 | menu.insertMenuItem(&subMenuItem, nullptr); | ||
2850 | 304 | |||
2851 | 305 | ExportedPlatformMenuItem childMenu1; | ||
2852 | 306 | ExportedPlatformMenuItem childMenu2; | ||
2853 | 307 | subMenu.insertMenuItem(&childMenu1, nullptr); | ||
2854 | 308 | subMenu.insertMenuItem(&childMenu2, nullptr); | ||
2855 | 309 | |||
2856 | 310 | // Check the structure | ||
2857 | 311 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2858 | 312 | DBusMenuLayoutItemList list = getChildren(&iface, 0, QStringList()); | ||
2859 | 313 | QCOMPARE(list.count(), 1); | ||
2860 | 314 | |||
2861 | 315 | list = getChildren(&iface, list.first().id, QStringList()); | ||
2862 | 316 | QCOMPARE(list.count(), 1); | ||
2863 | 317 | |||
2864 | 318 | list = getChildren(&iface, list.first().id, QStringList()); | ||
2865 | 319 | QCOMPARE(list.count(), 2); | ||
2866 | 320 | } | ||
2867 | 321 | |||
2868 | 322 | void ExportedPlatformMenuTest::testDynamicSubMenu() | ||
2869 | 323 | { | ||
2870 | 324 | // Root | ||
2871 | 325 | // -- childmenu | ||
2872 | 326 | // -- childmenu | ||
2873 | 327 | |||
2874 | 328 | // Track LayoutUpdated() signal: we don't want this signal to be emitted | ||
2875 | 329 | // too often because it causes refreshes | ||
2876 | 330 | QDBusInterface iface(TEST_SERVICE, TEST_OBJECT_PATH); | ||
2877 | 331 | ManualSignalSpy layoutUpdatedSpy; | ||
2878 | 332 | QDBusConnection::sessionBus().connect(TEST_SERVICE, TEST_OBJECT_PATH, "com.canonical.dbusmenu", "LayoutUpdated", "ui", &layoutUpdatedSpy, SLOT(receiveCall(uint, int))); | ||
2879 | 333 | |||
2880 | 334 | // Create our test menu | ||
2881 | 335 | ExportedPlatformMenuBar menuBar(TEST_OBJECT_PATH); | ||
2882 | 336 | ExportedPlatformMenu menu; | ||
2883 | 337 | menuBar.insertMenu(&menu, nullptr); | ||
2884 | 338 | |||
2885 | 339 | // LayoutUpdated should be emitted once because inputMenu is filled | ||
2886 | 340 | QTest::qWait(100); | ||
2887 | 341 | QCOMPARE(layoutUpdatedSpy.count(), 1); | ||
2888 | 342 | QCOMPARE(layoutUpdatedSpy.takeFirst().at(1).toInt(), 0); | ||
2889 | 343 | |||
2890 | 344 | ExportedPlatformMenu subMenu; | ||
2891 | 345 | ExportedPlatformMenuItem subMenuItem1; | ||
2892 | 346 | subMenuItem1.setMenu(&subMenu); | ||
2893 | 347 | ExportedPlatformMenuItem subMenuItem2; | ||
2894 | 348 | subMenuItem2.setMenu(&subMenu); | ||
2895 | 349 | menu.insertMenuItem(&subMenuItem1, nullptr); | ||
2896 | 350 | menu.insertMenuItem(&subMenuItem2, nullptr); | ||
2897 | 351 | |||
2898 | 352 | QTest::qWait(100); | ||
2899 | 353 | // LayoutUpdated should be emitted once more with the parent menus id | ||
2900 | 354 | // because menu item was inserted. | ||
2901 | 355 | QCOMPARE(layoutUpdatedSpy.count(), 1); | ||
2902 | 356 | QCOMPARE(layoutUpdatedSpy.takeFirst().at(1).toInt(), menu.id()); | ||
2903 | 357 | |||
2904 | 358 | DBusMenuLayoutItemList list = getChildren(&iface, 0, QStringList()); | ||
2905 | 359 | QCOMPARE(list.count(), 1); | ||
2906 | 360 | |||
2907 | 361 | list = getChildren(&iface, list.first().id, QStringList()); | ||
2908 | 362 | QCOMPARE(list.count(), 2); | ||
2909 | 363 | } | ||
2910 | 364 | |||
2911 | 365 | |||
2912 | 366 | #include "exportedplatformmenutest.moc" | ||
2913 | 0 | 367 | ||
2914 | === added file 'tests/exportedplatformmenutest.h' | |||
2915 | --- tests/exportedplatformmenutest.h 1970-01-01 00:00:00 +0000 | |||
2916 | +++ tests/exportedplatformmenutest.h 2015-03-18 11:19:06 +0000 | |||
2917 | @@ -0,0 +1,55 @@ | |||
2918 | 1 | /* This file is part of the dbusmenu-qt library | ||
2919 | 2 | Copyright 2015 Canonical | ||
2920 | 3 | Author: Aurelien Gateau <aurelien.gateau@canonical.com> | ||
2921 | 4 | |||
2922 | 5 | This library is free software; you can redistribute it and/or | ||
2923 | 6 | modify it under the terms of the GNU Library General Public | ||
2924 | 7 | License (LGPL) as published by the Free Software Foundation; | ||
2925 | 8 | either version 2 of the License, or (at your option) any later | ||
2926 | 9 | version. | ||
2927 | 10 | |||
2928 | 11 | This library is distributed in the hope that it will be useful, | ||
2929 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2930 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2931 | 14 | Library General Public License for more details. | ||
2932 | 15 | |||
2933 | 16 | You should have received a copy of the GNU Library General Public License | ||
2934 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
2935 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2936 | 19 | Boston, MA 02110-1301, USA. | ||
2937 | 20 | */ | ||
2938 | 21 | #ifndef EXPORTEDPLATFORMMENUTEST_H | ||
2939 | 22 | #define EXPORTEDPLATFORMMENUTEST_H | ||
2940 | 23 | |||
2941 | 24 | #define QT_GUI_LIB | ||
2942 | 25 | #include <QtGui> | ||
2943 | 26 | |||
2944 | 27 | // Qt | ||
2945 | 28 | #include <QObject> | ||
2946 | 29 | |||
2947 | 30 | // Local | ||
2948 | 31 | |||
2949 | 32 | class ExportedPlatformMenuTest : public QObject | ||
2950 | 33 | { | ||
2951 | 34 | Q_OBJECT | ||
2952 | 35 | private Q_SLOTS: | ||
2953 | 36 | // properties | ||
2954 | 37 | void testGetSomeMenuProperties(); | ||
2955 | 38 | void testGetSomeMenuProperties_data(); | ||
2956 | 39 | void testGetSomeMenuItemProperties(); | ||
2957 | 40 | void testGetSomeMenuItemProperties_data(); | ||
2958 | 41 | void testGetAllProperties(); | ||
2959 | 42 | void testGetNonExistentProperty(); | ||
2960 | 43 | |||
2961 | 44 | // events | ||
2962 | 45 | void testClickedEvent(); | ||
2963 | 46 | |||
2964 | 47 | // heirachy | ||
2965 | 48 | void testSubMenu(); | ||
2966 | 49 | void testDynamicSubMenu(); | ||
2967 | 50 | |||
2968 | 51 | void init(); | ||
2969 | 52 | void cleanup(); | ||
2970 | 53 | }; | ||
2971 | 54 | |||
2972 | 55 | #endif /* EXPORTEDPLATFORMMENUTEST_H */ | ||
2973 | 0 | 56 | ||
2974 | === modified file 'tests/testutils.h' | |||
2975 | --- tests/testutils.h 2011-08-29 14:51:01 +0000 | |||
2976 | +++ tests/testutils.h 2015-03-18 11:19:06 +0000 | |||
2977 | @@ -23,7 +23,7 @@ | |||
2978 | 23 | 23 | ||
2979 | 24 | // Local | 24 | // Local |
2980 | 25 | #include <debug_p.h> | 25 | #include <debug_p.h> |
2982 | 26 | #include <dbusmenutypes_p.h> | 26 | #include <dbusmenutypes.h> |
2983 | 27 | 27 | ||
2984 | 28 | // Qt | 28 | // Qt |
2985 | 29 | #include <QObject> | 29 | #include <QObject> |
FAILED: Continuous integration, rev:276 jenkins. qa.ubuntu. com/job/ libdbusmenu- qt-ci/19/ jenkins. qa.ubuntu. com/job/ libdbusmenu- qt-vivid- amd64-ci/ 2/console jenkins. qa.ubuntu. com/job/ libdbusmenu- qt-vivid- armhf-ci/ 2/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/libdbusmenu -qt-ci/ 19/rebuild
http://