OpenCoverage

qdbusmenubar.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbusmenu/qdbusmenubar.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 Dmitry Shachnev <mitya57@gmail.com>-
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 "qdbusmenubar_p.h"-
41#include "qdbusmenuregistrarproxy_p.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45/* note: do not change these to QStringLiteral;-
46 we are unloaded before QtDBus is done using the strings.-
47 */-
48#define REGISTRAR_SERVICE QLatin1String("com.canonical.AppMenu.Registrar")-
49#define REGISTRAR_PATH QLatin1String("/com/canonical/AppMenu/Registrar")-
50-
51QDBusMenuBar::QDBusMenuBar()-
52 : QPlatformMenuBar()-
53 , m_menu(new QDBusPlatformMenu())-
54 , m_menuAdaptor(new QDBusMenuAdaptor(m_menu))-
55 , m_windowId(0)-
56{-
57 QDBusMenuItem::registerDBusTypes();-
58 connect(m_menu, &QDBusPlatformMenu::propertiesUpdated,-
59 m_menuAdaptor, &QDBusMenuAdaptor::ItemsPropertiesUpdated);-
60 connect(m_menu, &QDBusPlatformMenu::updated,-
61 m_menuAdaptor, &QDBusMenuAdaptor::LayoutUpdated);-
62}
never executed: end of block
0
63-
64QDBusMenuBar::~QDBusMenuBar()-
65{-
66 unregisterMenuBar();-
67 delete m_menuAdaptor;-
68 delete m_menu;-
69 qDeleteAll(m_menuItems);-
70}
never executed: end of block
0
71-
72QDBusPlatformMenuItem *QDBusMenuBar::menuItemForMenu(QPlatformMenu *menu)-
73{-
74 if (!menu)
!menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
75 return nullptr;
never executed: return nullptr;
0
76 quintptr tag = menu->tag();-
77 const auto it = m_menuItems.constFind(tag);-
78 if (it != m_menuItems.cend()) {
it != m_menuItems.cend()Description
TRUEnever evaluated
FALSEnever evaluated
0
79 return *it;
never executed: return *it;
0
80 } else {-
81 QDBusPlatformMenuItem *item = new QDBusPlatformMenuItem;-
82 updateMenuItem(item, menu);-
83 m_menuItems.insert(tag, item);-
84 return item;
never executed: return item;
0
85 }-
86}-
87-
88void QDBusMenuBar::updateMenuItem(QDBusPlatformMenuItem *item, QPlatformMenu *menu)-
89{-
90 const QDBusPlatformMenu *ourMenu = qobject_cast<const QDBusPlatformMenu *>(menu);-
91 item->setText(ourMenu->text());-
92 item->setIcon(ourMenu->icon());-
93 item->setEnabled(ourMenu->isEnabled());-
94 item->setVisible(ourMenu->isVisible());-
95 item->setMenu(menu);-
96}
never executed: end of block
0
97-
98void QDBusMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before)-
99{-
100 QDBusPlatformMenuItem *menuItem = menuItemForMenu(menu);-
101 QDBusPlatformMenuItem *beforeItem = menuItemForMenu(before);-
102 m_menu->insertMenuItem(menuItem, beforeItem);-
103 m_menu->emitUpdated();-
104}
never executed: end of block
0
105-
106void QDBusMenuBar::removeMenu(QPlatformMenu *menu)-
107{-
108 QDBusPlatformMenuItem *menuItem = menuItemForMenu(menu);-
109 m_menu->removeMenuItem(menuItem);-
110 m_menu->emitUpdated();-
111}
never executed: end of block
0
112-
113void QDBusMenuBar::syncMenu(QPlatformMenu *menu)-
114{-
115 QDBusPlatformMenuItem *menuItem = menuItemForMenu(menu);-
116 updateMenuItem(menuItem, menu);-
117}
never executed: end of block
0
118-
119void QDBusMenuBar::handleReparent(QWindow *newParentWindow)-
120{-
121 if (newParentWindow && newParentWindow->winId() != m_windowId) {
newParentWindowDescription
TRUEnever evaluated
FALSEnever evaluated
newParentWindo... != m_windowIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
122 unregisterMenuBar();-
123 m_windowId = newParentWindow->winId();-
124 registerMenuBar();-
125 }
never executed: end of block
0
126}
never executed: end of block
0
127-
128QPlatformMenu *QDBusMenuBar::menuForTag(quintptr tag) const-
129{-
130 QDBusPlatformMenuItem *menuItem = m_menuItems.value(tag);-
131 if (menuItem)
menuItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
132 return const_cast<QPlatformMenu *>(menuItem->menu());
never executed: return const_cast<QPlatformMenu *>(menuItem->menu());
0
133 return nullptr;
never executed: return nullptr;
0
134}-
135-
136QPlatformMenu *QDBusMenuBar::createMenu() const-
137{-
138 return new QDBusPlatformMenu;
never executed: return new QDBusPlatformMenu;
0
139}-
140-
141void QDBusMenuBar::registerMenuBar()-
142{-
143 static uint menuBarId = 0;-
144-
145 QDBusConnection connection = QDBusConnection::sessionBus();-
146 m_objectPath = QStringLiteral("/MenuBar/%1").arg(++menuBarId);
never executed: return qstring_literal_temp;
0
147 if (!connection.registerObject(m_objectPath, m_menu))
!connection.re...tPath, m_menu)Description
TRUEnever evaluated
FALSEnever evaluated
0
148 return;
never executed: return;
0
149-
150 QDBusMenuRegistrarInterface registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, connection, this);-
151 QDBusPendingReply<> r = registrar.RegisterWindow(m_windowId, QDBusObjectPath(m_objectPath));-
152 r.waitForFinished();-
153 if (r.isError()) {
r.isError()Description
TRUEnever evaluated
FALSEnever evaluated
0
154 qWarning("Failed to register window menu, reason: %s (\"%s\")",-
155 qUtf8Printable(r.error().name()), qUtf8Printable(r.error().message()));-
156 connection.unregisterObject(m_objectPath);-
157 }
never executed: end of block
0
158}
never executed: end of block
0
159-
160void QDBusMenuBar::unregisterMenuBar()-
161{-
162 QDBusConnection connection = QDBusConnection::sessionBus();-
163-
164 if (m_windowId) {
m_windowIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
165 QDBusMenuRegistrarInterface registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, connection, this);-
166 QDBusPendingReply<> r = registrar.UnregisterWindow(m_windowId);-
167 r.waitForFinished();-
168 if (r.isError())
r.isError()Description
TRUEnever evaluated
FALSEnever evaluated
0
169 qWarning("Failed to unregister window menu, reason: %s (\"%s\")",
never executed: QMessageLogger(__FILE__, 169, __PRETTY_FUNCTION__).warning("Failed to unregister window menu, reason: %s (\"%s\")", QString(r.error().name()).toUtf8().constData(), QString(r.error().message()).toUtf8().constData());
0
170 qUtf8Printable(r.error().name()), qUtf8Printable(r.error().message()));
never executed: QMessageLogger(__FILE__, 169, __PRETTY_FUNCTION__).warning("Failed to unregister window menu, reason: %s (\"%s\")", QString(r.error().name()).toUtf8().constData(), QString(r.error().message()).toUtf8().constData());
0
171 }
never executed: end of block
0
172-
173 if (!m_objectPath.isEmpty())
!m_objectPath.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
174 connection.unregisterObject(m_objectPath);
never executed: connection.unregisterObject(m_objectPath);
0
175}
never executed: end of block
0
176-
177QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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