Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbusmenu/qdbusplatformmenu.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 "qdbusplatformmenu_p.h" | - | ||||||
35 | - | |||||||
36 | #include <QDebug> | - | ||||||
37 | #include <QWindow> | - | ||||||
38 | - | |||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||
40 | - | |||||||
41 | Q_LOGGING_CATEGORY(qLcMenu, "qt.qpa.menu") executed 1 time by 1 test: return category; Executed by:
| 1 | ||||||
42 | - | |||||||
43 | static int nextDBusID = 1; | - | ||||||
44 | QHash<int, QDBusPlatformMenuItem *> menuItemsByID; | - | ||||||
45 | - | |||||||
46 | QDBusPlatformMenuItem::QDBusPlatformMenuItem(quintptr tag) | - | ||||||
47 | : m_tag(tag ? tag : reinterpret_cast<quintptr>(this)) // QMenu will overwrite this later | - | ||||||
48 | , m_subMenu(Q_NULLPTR) | - | ||||||
49 | , m_role(NoRole) | - | ||||||
50 | , m_isEnabled(true) | - | ||||||
51 | , m_isVisible(true) | - | ||||||
52 | , m_isSeparator(false) | - | ||||||
53 | , m_isCheckable(false) | - | ||||||
54 | , m_isChecked(false) | - | ||||||
55 | , m_dbusID(nextDBusID++) | - | ||||||
56 | { | - | ||||||
57 | menuItemsByID.insert(m_dbusID, this); | - | ||||||
58 | } never executed: end of block | 0 | ||||||
59 | - | |||||||
60 | QDBusPlatformMenuItem::~QDBusPlatformMenuItem() | - | ||||||
61 | { | - | ||||||
62 | menuItemsByID.remove(m_dbusID); | - | ||||||
63 | if (m_subMenu)
| 0 | ||||||
64 | static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR); never executed: static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(nullptr); | 0 | ||||||
65 | } never executed: end of block | 0 | ||||||
66 | - | |||||||
67 | void QDBusPlatformMenuItem::setTag(quintptr tag) | - | ||||||
68 | { | - | ||||||
69 | m_tag = tag; | - | ||||||
70 | } never executed: end of block | 0 | ||||||
71 | - | |||||||
72 | void QDBusPlatformMenuItem::setText(const QString &text) | - | ||||||
73 | { | - | ||||||
74 | qCDebug(qLcMenu) << m_dbusID << text; never executed: QMessageLogger(__FILE__, 74, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << m_dbusID << text;
| 0 | ||||||
75 | m_text = text; | - | ||||||
76 | } never executed: end of block | 0 | ||||||
77 | - | |||||||
78 | void QDBusPlatformMenuItem::setIcon(const QIcon &icon) | - | ||||||
79 | { | - | ||||||
80 | m_icon = icon; | - | ||||||
81 | } never executed: end of block | 0 | ||||||
82 | - | |||||||
83 | /*! | - | ||||||
84 | Set a submenu under this menu item. | - | ||||||
85 | */ | - | ||||||
86 | void QDBusPlatformMenuItem::setMenu(QPlatformMenu *menu) | - | ||||||
87 | { | - | ||||||
88 | if (m_subMenu)
| 0 | ||||||
89 | static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR); never executed: static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(nullptr); | 0 | ||||||
90 | m_subMenu = menu; | - | ||||||
91 | if (menu)
| 0 | ||||||
92 | static_cast<QDBusPlatformMenu *>(menu)->setContainingMenuItem(this); never executed: static_cast<QDBusPlatformMenu *>(menu)->setContainingMenuItem(this); | 0 | ||||||
93 | } never executed: end of block | 0 | ||||||
94 | - | |||||||
95 | void QDBusPlatformMenuItem::setEnabled(bool enabled) | - | ||||||
96 | { | - | ||||||
97 | m_isEnabled = enabled; | - | ||||||
98 | } never executed: end of block | 0 | ||||||
99 | - | |||||||
100 | void QDBusPlatformMenuItem::setVisible(bool isVisible) | - | ||||||
101 | { | - | ||||||
102 | m_isVisible = isVisible; | - | ||||||
103 | } never executed: end of block | 0 | ||||||
104 | - | |||||||
105 | void QDBusPlatformMenuItem::setIsSeparator(bool isSeparator) | - | ||||||
106 | { | - | ||||||
107 | m_isSeparator = isSeparator; | - | ||||||
108 | } never executed: end of block | 0 | ||||||
109 | - | |||||||
110 | void QDBusPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role) | - | ||||||
111 | { | - | ||||||
112 | m_role = role; | - | ||||||
113 | } never executed: end of block | 0 | ||||||
114 | - | |||||||
115 | void QDBusPlatformMenuItem::setCheckable(bool checkable) | - | ||||||
116 | { | - | ||||||
117 | m_isCheckable = checkable; | - | ||||||
118 | } never executed: end of block | 0 | ||||||
119 | - | |||||||
120 | void QDBusPlatformMenuItem::setChecked(bool isChecked) | - | ||||||
121 | { | - | ||||||
122 | m_isChecked = isChecked; | - | ||||||
123 | } never executed: end of block | 0 | ||||||
124 | - | |||||||
125 | void QDBusPlatformMenuItem::setShortcut(const QKeySequence &shortcut) | - | ||||||
126 | { | - | ||||||
127 | m_shortcut = shortcut; | - | ||||||
128 | } never executed: end of block | 0 | ||||||
129 | - | |||||||
130 | void QDBusPlatformMenuItem::trigger() | - | ||||||
131 | { | - | ||||||
132 | emit activated(); | - | ||||||
133 | } never executed: end of block | 0 | ||||||
134 | - | |||||||
135 | QDBusPlatformMenuItem *QDBusPlatformMenuItem::byId(int id) | - | ||||||
136 | { | - | ||||||
137 | // We need to check contains because otherwise QHash would insert | - | ||||||
138 | // a default-constructed nullptr value into menuItemsByID | - | ||||||
139 | if (menuItemsByID.contains(id))
| 0 | ||||||
140 | return menuItemsByID[id]; never executed: return menuItemsByID[id]; | 0 | ||||||
141 | return Q_NULLPTR; never executed: return nullptr; | 0 | ||||||
142 | } | - | ||||||
143 | - | |||||||
144 | QList<const QDBusPlatformMenuItem *> QDBusPlatformMenuItem::byIds(const QList<int> &ids) | - | ||||||
145 | { | - | ||||||
146 | QList<const QDBusPlatformMenuItem *> ret; | - | ||||||
147 | Q_FOREACH (int id, ids) { | - | ||||||
148 | if (menuItemsByID.contains(id))
| 0 | ||||||
149 | ret << menuItemsByID[id]; never executed: ret << menuItemsByID[id]; | 0 | ||||||
150 | } never executed: end of block | 0 | ||||||
151 | return ret; never executed: return ret; | 0 | ||||||
152 | } | - | ||||||
153 | - | |||||||
154 | - | |||||||
155 | QDBusPlatformMenu::QDBusPlatformMenu(quintptr tag) | - | ||||||
156 | : m_tag(tag ? tag : reinterpret_cast<quintptr>(this)) | - | ||||||
157 | , m_isEnabled(true) | - | ||||||
158 | , m_isVisible(true) | - | ||||||
159 | , m_isSeparator(false) | - | ||||||
160 | , m_revision(1) | - | ||||||
161 | , m_containingMenuItem(Q_NULLPTR) | - | ||||||
162 | { | - | ||||||
163 | } never executed: end of block | 0 | ||||||
164 | - | |||||||
165 | QDBusPlatformMenu::~QDBusPlatformMenu() | - | ||||||
166 | { | - | ||||||
167 | if (m_containingMenuItem)
| 0 | ||||||
168 | m_containingMenuItem->setMenu(Q_NULLPTR); never executed: m_containingMenuItem->setMenu(nullptr); | 0 | ||||||
169 | } never executed: end of block | 0 | ||||||
170 | - | |||||||
171 | void QDBusPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) | - | ||||||
172 | { | - | ||||||
173 | QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem); | - | ||||||
174 | QDBusPlatformMenuItem *beforeItem = static_cast<QDBusPlatformMenuItem *>(before); | - | ||||||
175 | int idx = m_items.indexOf(beforeItem); | - | ||||||
176 | qCDebug(qLcMenu) << item->dbusID() << item->text(); never executed: QMessageLogger(__FILE__, 176, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << item->dbusID() << item->text();
| 0 | ||||||
177 | if (idx < 0)
| 0 | ||||||
178 | m_items.append(item); never executed: m_items.append(item); | 0 | ||||||
179 | else | - | ||||||
180 | m_items.insert(idx, item); never executed: m_items.insert(idx, item); | 0 | ||||||
181 | m_itemsByTag.insert(item->tag(), item); | - | ||||||
182 | if (item->menu())
| 0 | ||||||
183 | syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu())); never executed: syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu())); | 0 | ||||||
184 | emitUpdated(); | - | ||||||
185 | } never executed: end of block | 0 | ||||||
186 | - | |||||||
187 | void QDBusPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) | - | ||||||
188 | { | - | ||||||
189 | QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem); | - | ||||||
190 | m_items.removeAll(item); | - | ||||||
191 | m_itemsByTag.remove(menuItem->tag()); | - | ||||||
192 | if (item->menu()) {
| 0 | ||||||
193 | // disconnect from the signals we connected to in syncSubMenu() | - | ||||||
194 | const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu()); | - | ||||||
195 | disconnect(menu, &QDBusPlatformMenu::propertiesUpdated, | - | ||||||
196 | this, &QDBusPlatformMenu::propertiesUpdated); | - | ||||||
197 | disconnect(menu, &QDBusPlatformMenu::updated, | - | ||||||
198 | this, &QDBusPlatformMenu::updated); | - | ||||||
199 | } never executed: end of block | 0 | ||||||
200 | emitUpdated(); | - | ||||||
201 | } never executed: end of block | 0 | ||||||
202 | - | |||||||
203 | void QDBusPlatformMenu::syncSubMenu(const QDBusPlatformMenu *menu) | - | ||||||
204 | { | - | ||||||
205 | // The adaptor is only connected to the propertiesUpdated signal of the top-level | - | ||||||
206 | // menu, so the submenus should transfer their signals to their parents. | - | ||||||
207 | connect(menu, &QDBusPlatformMenu::propertiesUpdated, | - | ||||||
208 | this, &QDBusPlatformMenu::propertiesUpdated, Qt::UniqueConnection); | - | ||||||
209 | connect(menu, &QDBusPlatformMenu::updated, | - | ||||||
210 | this, &QDBusPlatformMenu::updated, Qt::UniqueConnection); | - | ||||||
211 | } never executed: end of block | 0 | ||||||
212 | - | |||||||
213 | void QDBusPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) | - | ||||||
214 | { | - | ||||||
215 | QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem); | - | ||||||
216 | // if a submenu was added to this item, we need to connect to its signals | - | ||||||
217 | if (item->menu())
| 0 | ||||||
218 | syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu())); never executed: syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu())); | 0 | ||||||
219 | // TODO keep around copies of the QDBusMenuLayoutItems so they can be updated? | - | ||||||
220 | // or eliminate them by putting dbus streaming operators in this class instead? | - | ||||||
221 | // or somehow tell the dbusmenu client that something has changed, so it will ask for properties again | - | ||||||
222 | QDBusMenuItemList updated; | - | ||||||
223 | QDBusMenuItemKeysList removed; | - | ||||||
224 | updated << QDBusMenuItem(item); | - | ||||||
225 | qCDebug(qLcMenu) << updated; never executed: QMessageLogger(__FILE__, 225, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << updated;
| 0 | ||||||
226 | emit propertiesUpdated(updated, removed); | - | ||||||
227 | } never executed: end of block | 0 | ||||||
228 | - | |||||||
229 | void QDBusPlatformMenu::emitUpdated() | - | ||||||
230 | { | - | ||||||
231 | if (m_containingMenuItem)
| 0 | ||||||
232 | emit updated(++m_revision, m_containingMenuItem->dbusID()); never executed: updated(++m_revision, m_containingMenuItem->dbusID()); | 0 | ||||||
233 | else | - | ||||||
234 | emit updated(++m_revision, 0); never executed: updated(++m_revision, 0); | 0 | ||||||
235 | } | - | ||||||
236 | - | |||||||
237 | void QDBusPlatformMenu::setTag(quintptr tag) | - | ||||||
238 | { | - | ||||||
239 | m_tag = tag; | - | ||||||
240 | } never executed: end of block | 0 | ||||||
241 | - | |||||||
242 | void QDBusPlatformMenu::setText(const QString &text) | - | ||||||
243 | { | - | ||||||
244 | m_text = text; | - | ||||||
245 | } never executed: end of block | 0 | ||||||
246 | - | |||||||
247 | void QDBusPlatformMenu::setIcon(const QIcon &icon) | - | ||||||
248 | { | - | ||||||
249 | m_icon = icon; | - | ||||||
250 | } never executed: end of block | 0 | ||||||
251 | - | |||||||
252 | void QDBusPlatformMenu::setEnabled(bool enabled) | - | ||||||
253 | { | - | ||||||
254 | m_isEnabled = enabled; | - | ||||||
255 | } never executed: end of block | 0 | ||||||
256 | - | |||||||
257 | void QDBusPlatformMenu::setVisible(bool isVisible) | - | ||||||
258 | { | - | ||||||
259 | m_isVisible = isVisible; | - | ||||||
260 | } never executed: end of block | 0 | ||||||
261 | - | |||||||
262 | void QDBusPlatformMenu::setContainingMenuItem(QDBusPlatformMenuItem *item) | - | ||||||
263 | { | - | ||||||
264 | m_containingMenuItem = item; | - | ||||||
265 | } never executed: end of block | 0 | ||||||
266 | - | |||||||
267 | QPlatformMenuItem *QDBusPlatformMenu::menuItemAt(int position) const | - | ||||||
268 | { | - | ||||||
269 | return m_items.value(position); never executed: return m_items.value(position); | 0 | ||||||
270 | } | - | ||||||
271 | - | |||||||
272 | QPlatformMenuItem *QDBusPlatformMenu::menuItemForTag(quintptr tag) const | - | ||||||
273 | { | - | ||||||
274 | return m_itemsByTag[tag]; never executed: return m_itemsByTag[tag]; | 0 | ||||||
275 | } | - | ||||||
276 | - | |||||||
277 | const QList<QDBusPlatformMenuItem *> QDBusPlatformMenu::items() const | - | ||||||
278 | { | - | ||||||
279 | return m_items; never executed: return m_items; | 0 | ||||||
280 | } | - | ||||||
281 | - | |||||||
282 | QPlatformMenuItem *QDBusPlatformMenu::createMenuItem() const | - | ||||||
283 | { | - | ||||||
284 | QDBusPlatformMenuItem *ret = new QDBusPlatformMenuItem(); | - | ||||||
285 | return ret; never executed: return ret; | 0 | ||||||
286 | } | - | ||||||
287 | - | |||||||
288 | QPlatformMenu *QDBusPlatformMenu::createSubMenu() const | - | ||||||
289 | { | - | ||||||
290 | return new QDBusPlatformMenu; never executed: return new QDBusPlatformMenu; | 0 | ||||||
291 | } | - | ||||||
292 | - | |||||||
293 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |