Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbusmenu/qdbusmenutypes.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qdbusmenutypes_p.h" | - | ||||||||||||
35 | - | |||||||||||||
36 | #include <QDBusConnection> | - | ||||||||||||
37 | #include <QDBusMetaType> | - | ||||||||||||
38 | #include <QImage> | - | ||||||||||||
39 | #include <QIcon> | - | ||||||||||||
40 | #include <QImage> | - | ||||||||||||
41 | #include <QPixmap> | - | ||||||||||||
42 | #include <QDebug> | - | ||||||||||||
43 | #include <QtEndian> | - | ||||||||||||
44 | #include <QBuffer> | - | ||||||||||||
45 | #include <private/qkeysequence_p.h> | - | ||||||||||||
46 | #include <qpa/qplatformmenu.h> | - | ||||||||||||
47 | #include "qdbusplatformmenu_p.h" | - | ||||||||||||
48 | - | |||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
50 | - | |||||||||||||
51 | const QDBusArgument &operator<<(QDBusArgument &arg, const QDBusMenuItem &item) | - | ||||||||||||
52 | { | - | ||||||||||||
53 | arg.beginStructure(); | - | ||||||||||||
54 | arg << item.m_id << item.m_properties; | - | ||||||||||||
55 | arg.endStructure(); | - | ||||||||||||
56 | return arg; never executed: return arg; | 0 | ||||||||||||
57 | } | - | ||||||||||||
58 | - | |||||||||||||
59 | const QDBusArgument &operator>>(const QDBusArgument &arg, QDBusMenuItem &item) | - | ||||||||||||
60 | { | - | ||||||||||||
61 | arg.beginStructure(); | - | ||||||||||||
62 | arg >> item.m_id >> item.m_properties; | - | ||||||||||||
63 | arg.endStructure(); | - | ||||||||||||
64 | return arg; never executed: return arg; | 0 | ||||||||||||
65 | } | - | ||||||||||||
66 | - | |||||||||||||
67 | const QDBusArgument &operator<<(QDBusArgument &arg, const QDBusMenuItemKeys &keys) | - | ||||||||||||
68 | { | - | ||||||||||||
69 | arg.beginStructure(); | - | ||||||||||||
70 | arg << keys.id << keys.properties; | - | ||||||||||||
71 | arg.endStructure(); | - | ||||||||||||
72 | return arg; never executed: return arg; | 0 | ||||||||||||
73 | } | - | ||||||||||||
74 | - | |||||||||||||
75 | const QDBusArgument &operator>>(const QDBusArgument &arg, QDBusMenuItemKeys &keys) | - | ||||||||||||
76 | { | - | ||||||||||||
77 | arg.beginStructure(); | - | ||||||||||||
78 | arg >> keys.id >> keys.properties; | - | ||||||||||||
79 | arg.endStructure(); | - | ||||||||||||
80 | return arg; never executed: return arg; | 0 | ||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | uint QDBusMenuLayoutItem::populate(int id, int depth, const QStringList &propertyNames, const QDBusPlatformMenu *topLevelMenu) | - | ||||||||||||
84 | { | - | ||||||||||||
85 | qCDebug(qLcMenu) << id << "depth" << depth << propertyNames; never executed: QMessageLogger(__FILE__, 85, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << id << "depth" << depth << propertyNames;
| 0 | ||||||||||||
86 | m_id = id; | - | ||||||||||||
87 | if (id == 0) {
| 0 | ||||||||||||
88 | m_properties.insert(QLatin1String("children-display"), QLatin1String("submenu")); | - | ||||||||||||
89 | if (topLevelMenu)
| 0 | ||||||||||||
90 | populate(topLevelMenu, depth, propertyNames); never executed: populate(topLevelMenu, depth, propertyNames); | 0 | ||||||||||||
91 | return 1; // revision never executed: return 1; | 0 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id); | - | ||||||||||||
95 | if (item) {
| 0 | ||||||||||||
96 | const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu()); | - | ||||||||||||
97 | - | |||||||||||||
98 | if (menu) {
| 0 | ||||||||||||
99 | if (depth != 0)
| 0 | ||||||||||||
100 | populate(menu, depth, propertyNames); never executed: populate(menu, depth, propertyNames); | 0 | ||||||||||||
101 | return menu->revision(); never executed: return menu->revision(); | 0 | ||||||||||||
102 | } | - | ||||||||||||
103 | } never executed: end of block | 0 | ||||||||||||
104 | - | |||||||||||||
105 | return 1; // revision never executed: return 1; | 0 | ||||||||||||
106 | } | - | ||||||||||||
107 | - | |||||||||||||
108 | void QDBusMenuLayoutItem::populate(const QDBusPlatformMenu *menu, int depth, const QStringList &propertyNames) | - | ||||||||||||
109 | { | - | ||||||||||||
110 | Q_FOREACH (QDBusPlatformMenuItem *item, menu->items()) { | - | ||||||||||||
111 | QDBusMenuLayoutItem child; | - | ||||||||||||
112 | child.populate(item, depth - 1, propertyNames); | - | ||||||||||||
113 | m_children << child; | - | ||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||
115 | } never executed: end of block | 0 | ||||||||||||
116 | - | |||||||||||||
117 | void QDBusMenuLayoutItem::populate(const QDBusPlatformMenuItem *item, int depth, const QStringList &propertyNames) | - | ||||||||||||
118 | { | - | ||||||||||||
119 | m_id = item->dbusID(); | - | ||||||||||||
120 | QDBusMenuItem proxy(item); | - | ||||||||||||
121 | m_properties = proxy.m_properties; | - | ||||||||||||
122 | - | |||||||||||||
123 | const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu()); | - | ||||||||||||
124 | if (depth != 0 && menu)
| 0 | ||||||||||||
125 | populate(menu, depth, propertyNames); never executed: populate(menu, depth, propertyNames); | 0 | ||||||||||||
126 | } never executed: end of block | 0 | ||||||||||||
127 | - | |||||||||||||
128 | const QDBusArgument &operator<<(QDBusArgument &arg, const QDBusMenuLayoutItem &item) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | arg.beginStructure(); | - | ||||||||||||
131 | arg << item.m_id << item.m_properties; | - | ||||||||||||
132 | arg.beginArray(qMetaTypeId<QDBusVariant>()); | - | ||||||||||||
133 | foreach (const QDBusMenuLayoutItem& child, item.m_children) | - | ||||||||||||
134 | arg << QDBusVariant(QVariant::fromValue<QDBusMenuLayoutItem>(child)); never executed: arg << QDBusVariant(QVariant::fromValue<QDBusMenuLayoutItem>(child)); | 0 | ||||||||||||
135 | arg.endArray(); | - | ||||||||||||
136 | arg.endStructure(); | - | ||||||||||||
137 | return arg; never executed: return arg; | 0 | ||||||||||||
138 | } | - | ||||||||||||
139 | - | |||||||||||||
140 | const QDBusArgument &operator>>(const QDBusArgument &arg, QDBusMenuLayoutItem &item) | - | ||||||||||||
141 | { | - | ||||||||||||
142 | arg.beginStructure(); | - | ||||||||||||
143 | arg >> item.m_id >> item.m_properties; | - | ||||||||||||
144 | arg.beginArray(); | - | ||||||||||||
145 | while (!arg.atEnd()) {
| 0 | ||||||||||||
146 | QDBusVariant dbusVariant; | - | ||||||||||||
147 | arg >> dbusVariant; | - | ||||||||||||
148 | QDBusArgument childArgument = dbusVariant.variant().value<QDBusArgument>(); | - | ||||||||||||
149 | - | |||||||||||||
150 | QDBusMenuLayoutItem child; | - | ||||||||||||
151 | childArgument >> child; | - | ||||||||||||
152 | item.m_children.append(child); | - | ||||||||||||
153 | } never executed: end of block | 0 | ||||||||||||
154 | arg.endArray(); | - | ||||||||||||
155 | arg.endStructure(); | - | ||||||||||||
156 | return arg; never executed: return arg; | 0 | ||||||||||||
157 | } | - | ||||||||||||
158 | - | |||||||||||||
159 | void QDBusMenuItem::registerDBusTypes() | - | ||||||||||||
160 | { | - | ||||||||||||
161 | qDBusRegisterMetaType<QDBusMenuItem>(); | - | ||||||||||||
162 | qDBusRegisterMetaType<QDBusMenuItemList>(); | - | ||||||||||||
163 | qDBusRegisterMetaType<QDBusMenuItemKeys>(); | - | ||||||||||||
164 | qDBusRegisterMetaType<QDBusMenuItemKeysList>(); | - | ||||||||||||
165 | qDBusRegisterMetaType<QDBusMenuLayoutItem>(); | - | ||||||||||||
166 | qDBusRegisterMetaType<QDBusMenuLayoutItemList>(); | - | ||||||||||||
167 | qDBusRegisterMetaType<QDBusMenuEvent>(); | - | ||||||||||||
168 | qDBusRegisterMetaType<QDBusMenuEventList>(); | - | ||||||||||||
169 | qDBusRegisterMetaType<QDBusMenuShortcut>(); | - | ||||||||||||
170 | } never executed: end of block | 0 | ||||||||||||
171 | - | |||||||||||||
172 | QDBusMenuItem::QDBusMenuItem(const QDBusPlatformMenuItem *item) | - | ||||||||||||
173 | : m_id(item->dbusID()) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | if (item->isSeparator()) {
| 0 | ||||||||||||
176 | m_properties.insert(QLatin1String("type"), QLatin1String("separator")); | - | ||||||||||||
177 | } else { never executed: end of block | 0 | ||||||||||||
178 | m_properties.insert(QLatin1String("label"), convertMnemonic(item->text())); | - | ||||||||||||
179 | if (item->menu())
| 0 | ||||||||||||
180 | m_properties.insert(QLatin1String("children-display"), QLatin1String("submenu")); never executed: m_properties.insert(QLatin1String("children-display"), QLatin1String("submenu")); | 0 | ||||||||||||
181 | m_properties.insert(QLatin1String("enabled"), item->isEnabled()); | - | ||||||||||||
182 | if (item->isCheckable()) {
| 0 | ||||||||||||
183 | // dbusmenu supports "radio" too, but QPlatformMenuItem doesn't seem to | - | ||||||||||||
184 | // (QAction would have an exclusive actionGroup) | - | ||||||||||||
185 | m_properties.insert(QLatin1String("toggle-type"), QLatin1String("checkmark")); | - | ||||||||||||
186 | m_properties.insert(QLatin1String("toggle-state"), item->isChecked() ? 1 : 0); | - | ||||||||||||
187 | } never executed: end of block | 0 | ||||||||||||
188 | const QKeySequence &scut = item->shortcut(); | - | ||||||||||||
189 | if (!scut.isEmpty()) {
| 0 | ||||||||||||
190 | QDBusMenuShortcut shortcut = convertKeySequence(scut); | - | ||||||||||||
191 | m_properties.insert(QLatin1String("shortcut"), QVariant::fromValue(shortcut)); | - | ||||||||||||
192 | } never executed: end of block | 0 | ||||||||||||
193 | const QIcon &icon = item->icon(); | - | ||||||||||||
194 | if (!icon.name().isEmpty()) {
| 0 | ||||||||||||
195 | m_properties.insert(QLatin1String("icon-name"), icon.name()); | - | ||||||||||||
196 | } else if (!icon.isNull()) { never executed: end of block
| 0 | ||||||||||||
197 | QBuffer buf; | - | ||||||||||||
198 | icon.pixmap(16).save(&buf, "PNG"); | - | ||||||||||||
199 | m_properties.insert(QLatin1String("icon-data"), buf.data()); | - | ||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||
201 | } never executed: end of block | 0 | ||||||||||||
202 | m_properties.insert(QLatin1String("visible"), item->isVisible()); | - | ||||||||||||
203 | } never executed: end of block | 0 | ||||||||||||
204 | - | |||||||||||||
205 | QDBusMenuItemList QDBusMenuItem::items(const QList<int> &ids, const QStringList &propertyNames) | - | ||||||||||||
206 | { | - | ||||||||||||
207 | Q_UNUSED(propertyNames) | - | ||||||||||||
208 | QDBusMenuItemList ret; | - | ||||||||||||
209 | QList<const QDBusPlatformMenuItem *> items = QDBusPlatformMenuItem::byIds(ids); | - | ||||||||||||
210 | ret.reserve(items.size()); | - | ||||||||||||
211 | Q_FOREACH (const QDBusPlatformMenuItem *item, items) | - | ||||||||||||
212 | ret << QDBusMenuItem(item); never executed: ret << QDBusMenuItem(item); | 0 | ||||||||||||
213 | return ret; never executed: return ret; | 0 | ||||||||||||
214 | } | - | ||||||||||||
215 | - | |||||||||||||
216 | QString QDBusMenuItem::convertMnemonic(const QString &label) | - | ||||||||||||
217 | { | - | ||||||||||||
218 | // convert only the first occurrence of ampersand which is not at the end | - | ||||||||||||
219 | // dbusmenu uses underscore instead of ampersand | - | ||||||||||||
220 | int idx = label.indexOf(QLatin1Char('&')); | - | ||||||||||||
221 | if (idx < 0 || idx == label.length() - 1)
| 0 | ||||||||||||
222 | return label; never executed: return label; | 0 | ||||||||||||
223 | QString ret(label); | - | ||||||||||||
224 | ret[idx] = QLatin1Char('_'); | - | ||||||||||||
225 | return ret; never executed: return ret; | 0 | ||||||||||||
226 | } | - | ||||||||||||
227 | - | |||||||||||||
228 | QDBusMenuShortcut QDBusMenuItem::convertKeySequence(const QKeySequence &sequence) | - | ||||||||||||
229 | { | - | ||||||||||||
230 | QDBusMenuShortcut shortcut; | - | ||||||||||||
231 | for (int i = 0; i < sequence.count(); ++i) {
| 0 | ||||||||||||
232 | QStringList tokens; | - | ||||||||||||
233 | int key = sequence[i]; | - | ||||||||||||
234 | if (key & Qt::MetaModifier)
| 0 | ||||||||||||
235 | tokens << QStringLiteral("Super"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "Super")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Super" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
236 | if (key & Qt::ControlModifier)
| 0 | ||||||||||||
237 | tokens << QStringLiteral("Control"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "Control")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Control" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
238 | if (key & Qt::AltModifier)
| 0 | ||||||||||||
239 | tokens << QStringLiteral("Alt"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "Alt")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Alt" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
240 | if (key & Qt::ShiftModifier)
| 0 | ||||||||||||
241 | tokens << QStringLiteral("Shift"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "Shift")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Shift" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
242 | if (key & Qt::KeypadModifier)
| 0 | ||||||||||||
243 | tokens << QStringLiteral("Num"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "Num")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Num" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
244 | - | |||||||||||||
245 | QString keyName = QKeySequencePrivate::keyName(key, QKeySequence::PortableText); | - | ||||||||||||
246 | if (keyName == QLatin1String("+"))
| 0 | ||||||||||||
247 | tokens << QStringLiteral("plus"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "plus")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "plus" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
248 | else if (keyName == QLatin1String("-"))
| 0 | ||||||||||||
249 | tokens << QStringLiteral("minus"); never executed: tokens << ([]() -> QString { enum { Size = sizeof(u"" "minus")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "minus" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); never executed: return qstring_literal_temp; | 0 | ||||||||||||
250 | else | - | ||||||||||||
251 | tokens << keyName; never executed: tokens << keyName; | 0 | ||||||||||||
252 | shortcut << tokens; | - | ||||||||||||
253 | } never executed: end of block | 0 | ||||||||||||
254 | return shortcut; never executed: return shortcut; | 0 | ||||||||||||
255 | } | - | ||||||||||||
256 | - | |||||||||||||
257 | const QDBusArgument &operator<<(QDBusArgument &arg, const QDBusMenuEvent &ev) | - | ||||||||||||
258 | { | - | ||||||||||||
259 | arg.beginStructure(); | - | ||||||||||||
260 | arg << ev.m_id << ev.m_eventId << ev.m_data << ev.m_timestamp; | - | ||||||||||||
261 | arg.endStructure(); | - | ||||||||||||
262 | return arg; never executed: return arg; | 0 | ||||||||||||
263 | } | - | ||||||||||||
264 | - | |||||||||||||
265 | const QDBusArgument &operator>>(const QDBusArgument &arg, QDBusMenuEvent &ev) | - | ||||||||||||
266 | { | - | ||||||||||||
267 | arg.beginStructure(); | - | ||||||||||||
268 | arg >> ev.m_id >> ev.m_eventId >> ev.m_data >> ev.m_timestamp; | - | ||||||||||||
269 | arg.endStructure(); | - | ||||||||||||
270 | return arg; never executed: return arg; | 0 | ||||||||||||
271 | } | - | ||||||||||||
272 | - | |||||||||||||
273 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||
274 | QDebug operator<<(QDebug d, const QDBusMenuItem &item) | - | ||||||||||||
275 | { | - | ||||||||||||
276 | QDebugStateSaver saver(d); | - | ||||||||||||
277 | d.nospace(); | - | ||||||||||||
278 | d << "QDBusMenuItem(id=" << item.m_id << ", properties=" << item.m_properties << ')'; | - | ||||||||||||
279 | return d; never executed: return d; | 0 | ||||||||||||
280 | } | - | ||||||||||||
281 | - | |||||||||||||
282 | QDebug operator<<(QDebug d, const QDBusMenuLayoutItem &item) | - | ||||||||||||
283 | { | - | ||||||||||||
284 | QDebugStateSaver saver(d); | - | ||||||||||||
285 | d.nospace(); | - | ||||||||||||
286 | d << "QDBusMenuLayoutItem(id=" << item.m_id << ", properties=" << item.m_properties << ", " << item.m_children.count() << " children)"; | - | ||||||||||||
287 | return d; never executed: return d; | 0 | ||||||||||||
288 | } | - | ||||||||||||
289 | #endif | - | ||||||||||||
290 | - | |||||||||||||
291 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |