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