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) 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 | - | |||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
48 | - | |||||||||||||
49 | Q_DECLARE_LOGGING_CATEGORY(qLcMenu) | - | ||||||||||||
50 | - | |||||||||||||
51 | const QString StatusNotifierWatcherService = QLatin1String("org.kde.StatusNotifierWatcher"); | - | ||||||||||||
52 | const QString StatusNotifierWatcherPath = QLatin1String("/StatusNotifierWatcher"); | - | ||||||||||||
53 | const QString StatusNotifierItemPath = QLatin1String("/StatusNotifierItem"); | - | ||||||||||||
54 | const 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 | */ | - | ||||||||||||
62 | QDBusMenuConnection::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())
| 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";
| 0-1 | ||||||||||||
75 | #endif | - | ||||||||||||
76 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
77 | - | |||||||||||||
78 | void 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 | - | ||||||||||||
84 | bool 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
| 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;
| 0 | ||||||||||||
89 | return success; never executed: return success; | 0 | ||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | void QDBusMenuConnection::unregisterTrayIconMenu(QDBusTrayIcon *item) | - | ||||||||||||
93 | { | - | ||||||||||||
94 | if (item->menu())
| 0 | ||||||||||||
95 | connection().unregisterObject(MenuBarPath); never executed: connection().unregisterObject(MenuBarPath); | 0 | ||||||||||||
96 | } never executed: end of block | 0 | ||||||||||||
97 | - | |||||||||||||
98 | bool QDBusMenuConnection::registerTrayIcon(QDBusTrayIcon *item) | - | ||||||||||||
99 | { | - | ||||||||||||
100 | bool success = connection().registerService(item->instanceId()); | - | ||||||||||||
101 | if (!success) {
| 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) {
| 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())
| 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 | - | |||||||||||||
125 | bool QDBusMenuConnection::unregisterTrayIcon(QDBusTrayIcon *item) | - | ||||||||||||
126 | { | - | ||||||||||||
127 | unregisterTrayIconMenu(item); | - | ||||||||||||
128 | connection().unregisterObject(StatusNotifierItemPath); | - | ||||||||||||
129 | bool success = connection().unregisterService(item->instanceId()); | - | ||||||||||||
130 | if (!success)
| 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 | - | |||||||||||||
136 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |