qdbusmenuconnection.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbusmenu/qdbusmenuconnection.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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#ifndef QT_NO_SYSTEMTRAYICON-
35#include "qdbustrayicon_p.h"-
36#endif-
37#include "qdbusmenuconnection_p.h"-
38#include "qdbusmenuadaptor_p.h"-
39#include "qdbusplatformmenu_p.h"-
40-
41#include <QtDBus/QDBusMessage>-
42#include <QtDBus/QDBusServiceWatcher>-
43#include <QtDBus/QDBusConnectionInterface>-
44#include <qdebug.h>-
45#include <qcoreapplication.h>-
46-
47QT_BEGIN_NAMESPACE-
48-
49Q_DECLARE_LOGGING_CATEGORY(qLcMenu)-
50-
51const QString StatusNotifierWatcherService = QLatin1String("org.kde.StatusNotifierWatcher");-
52const QString StatusNotifierWatcherPath = QLatin1String("/StatusNotifierWatcher");-
53const QString StatusNotifierItemPath = QLatin1String("/StatusNotifierItem");-
54const QString MenuBarPath = QLatin1String("/MenuBar");-
55-
56/*!-
57 \class QDBusMenuConnection-
58 \internal-
59 A D-Bus connection which is used for both menu and tray icon services.-
60 Connects to the session bus and registers with the respective watcher services.-
61*/-
62QDBusMenuConnection::QDBusMenuConnection(QObject *parent, const QString &serviceName)-
63 : QObject(parent)-
64 , m_connection(serviceName.isNull() ? QDBusConnection::sessionBus()-
65 : QDBusConnection::connectToBus(QDBusConnection::SessionBus, serviceName))-
66 , m_dbusWatcher(new QDBusServiceWatcher(StatusNotifierWatcherService, m_connection, QDBusServiceWatcher::WatchForRegistration, this))-
67 , m_statusNotifierHostRegistered(false)-
68{-
69#ifndef QT_NO_SYSTEMTRAYICON-
70 QDBusInterface systrayHost(StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService, m_connection);-
71 if (systrayHost.isValid() && systrayHost.property("IsStatusNotifierHostRegistered").toBool())
systrayHost.isValid()Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSystemTrayIcon
systrayHost.pr...red").toBool()Description
TRUEnever evaluated
FALSEnever evaluated
0-1
72 m_statusNotifierHostRegistered = true;
never executed: m_statusNotifierHostRegistered = true;
0
73 else-
74 qCDebug(qLcMenu) << "StatusNotifierHost is not registered";
never executed: QMessageLogger(__FILE__, 74, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << "StatusNotifierHost is not registered";
qt_category_enabledDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSystemTrayIcon
0-1
75#endif-
76}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSystemTrayIcon
1
77-
78void QDBusMenuConnection::dbusError(const QDBusError &error)-
79{-
80 qWarning() << "QDBusTrayIcon encountered a D-Bus error:" << error;-
81}
never executed: end of block
0
82-
83#ifndef QT_NO_SYSTEMTRAYICON-
84bool QDBusMenuConnection::registerTrayIconMenu(QDBusTrayIcon *item)-
85{-
86 bool success = connection().registerObject(MenuBarPath, item->menu());-
87 if (!success) // success == false is normal, because the object may be already registered
!successDescription
TRUEnever evaluated
FALSEnever evaluated
0
88 qCDebug(qLcMenu) << "failed to register" << item->instanceId() << MenuBarPath;
never executed: QMessageLogger(__FILE__, 88, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << "failed to register" << item->instanceId() << MenuBarPath;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 return success;
never executed: return success;
0
90}-
91-
92void QDBusMenuConnection::unregisterTrayIconMenu(QDBusTrayIcon *item)-
93{-
94 if (item->menu())
item->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
95 connection().unregisterObject(MenuBarPath);
never executed: connection().unregisterObject(MenuBarPath);
0
96}
never executed: end of block
0
97-
98bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item)-
99{-
100 bool success = connection().registerService(item->instanceId());-
101 if (!success) {
!successDescription
TRUEnever evaluated
FALSEnever evaluated
0
102 qWarning() << "failed to register service" << item->instanceId();-
103 return false;
never executed: return false;
0
104 }-
105-
106 success = connection().registerObject(StatusNotifierItemPath, item);-
107 if (!success) {
!successDescription
TRUEnever evaluated
FALSEnever evaluated
0
108 unregisterTrayIcon(item);-
109 qWarning() << "failed to register" << item->instanceId() << StatusNotifierItemPath;-
110 return false;
never executed: return false;
0
111 }-
112-
113 if (item->menu())
item->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
114 registerTrayIconMenu(item);
never executed: registerTrayIconMenu(item);
0
115-
116 QDBusMessage registerMethod = QDBusMessage::createMethodCall(-
117 StatusNotifierWatcherService, StatusNotifierWatcherPath, StatusNotifierWatcherService,-
118 QLatin1String("RegisterStatusNotifierItem"));-
119 registerMethod.setArguments(QVariantList() << item->instanceId());-
120 success = m_connection.callWithCallback(registerMethod, this, SIGNAL(trayIconRegistered()), SLOT(dbusError(QDBusError)));-
121-
122 return success;
never executed: return success;
0
123}-
124-
125bool QDBusMenuConnection::unregisterTrayIcon(QDBusTrayIcon *item)-
126{-
127 unregisterTrayIconMenu(item);-
128 connection().unregisterObject(StatusNotifierItemPath);-
129 bool success = connection().unregisterService(item->instanceId());-
130 if (!success)
!successDescription
TRUEnever evaluated
FALSEnever evaluated
0
131 qWarning() << "failed to unregister service" << item->instanceId();
never executed: QMessageLogger(__FILE__, 131, __PRETTY_FUNCTION__).warning() << "failed to unregister service" << item->instanceId();
0
132 return success;
never executed: return success;
0
133}-
134#endif // QT_NO_SYSTEMTRAYICON-
135-
136QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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