qdbusmenutypes.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9