1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | /* |
5 | This file was originally created by qdbusxml2cpp version 0.8 |
6 | Command line was: |
7 | qdbusxml2cpp -a statusnotifieritem ../../3rdparty/dbus-ifaces/org.kde.StatusNotifierItem.xml |
8 | |
9 | However it is maintained manually, because this adapter needs to do |
10 | significant interface adaptation, and can do it more efficiently using the |
11 | QDBusTrayIcon API directly rather than via QObject::property() and |
12 | QMetaObject::invokeMethod(). |
13 | */ |
14 | |
15 | #include "qstatusnotifieritemadaptor_p.h" |
16 | |
17 | #ifndef QT_NO_SYSTEMTRAYICON |
18 | |
19 | #include <QtCore/QLoggingCategory> |
20 | #include <QtCore/QCoreApplication> |
21 | |
22 | #include "qdbustrayicon_p.h" |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | Q_DECLARE_LOGGING_CATEGORY() |
27 | Q_DECLARE_LOGGING_CATEGORY(qLcTray) |
28 | |
29 | QStatusNotifierItemAdaptor::QStatusNotifierItemAdaptor(QDBusTrayIcon *parent) |
30 | : QDBusAbstractAdaptor(parent), m_trayIcon(parent) |
31 | { |
32 | setAutoRelaySignals(true); |
33 | } |
34 | |
35 | QStatusNotifierItemAdaptor::~QStatusNotifierItemAdaptor() |
36 | { |
37 | } |
38 | |
39 | QString QStatusNotifierItemAdaptor::attentionIconName() const |
40 | { |
41 | return m_trayIcon->attentionIconName(); |
42 | } |
43 | |
44 | QXdgDBusImageVector QStatusNotifierItemAdaptor::attentionIconPixmap() const |
45 | { |
46 | return iconToQXdgDBusImageVector(icon: m_trayIcon->attentionIcon()); |
47 | } |
48 | |
49 | QString QStatusNotifierItemAdaptor::attentionMovieName() const |
50 | { |
51 | return QString(); |
52 | } |
53 | |
54 | QString QStatusNotifierItemAdaptor::category() const |
55 | { |
56 | return m_trayIcon->category(); |
57 | } |
58 | |
59 | QString QStatusNotifierItemAdaptor::iconName() const |
60 | { |
61 | return m_trayIcon->iconName(); |
62 | } |
63 | |
64 | QXdgDBusImageVector QStatusNotifierItemAdaptor::iconPixmap() const |
65 | { |
66 | return iconToQXdgDBusImageVector(icon: m_trayIcon->icon()); |
67 | } |
68 | |
69 | QString QStatusNotifierItemAdaptor::id() const |
70 | { |
71 | // from the API docs: "a name that should be unique for this application and |
72 | // consistent between sessions, such as the application name itself" |
73 | return QCoreApplication::applicationName(); |
74 | } |
75 | |
76 | bool QStatusNotifierItemAdaptor::() const |
77 | { |
78 | // From KDE docs: if this is true, the item only supports the context menu, |
79 | // so the visualization should prefer sending ContextMenu() instead of Activate(). |
80 | // But QSystemTrayIcon doesn't have such a setting: it will emit activated() |
81 | // and the application is free to use it or ignore it; we don't know whether it will. |
82 | return false; |
83 | } |
84 | |
85 | QDBusObjectPath QStatusNotifierItemAdaptor::() const |
86 | { |
87 | return QDBusObjectPath(m_trayIcon->menu() ? "/MenuBar" : "/NO_DBUSMENU" ); |
88 | } |
89 | |
90 | QString QStatusNotifierItemAdaptor::overlayIconName() const |
91 | { |
92 | return QString(); |
93 | } |
94 | |
95 | QXdgDBusImageVector QStatusNotifierItemAdaptor::overlayIconPixmap() const |
96 | { |
97 | QXdgDBusImageVector ret; // empty vector |
98 | return ret; |
99 | } |
100 | |
101 | QString QStatusNotifierItemAdaptor::status() const |
102 | { |
103 | return m_trayIcon->status(); |
104 | } |
105 | |
106 | QString QStatusNotifierItemAdaptor::title() const |
107 | { |
108 | // Shown e.g. when the icon is hidden, in the popup showing all hidden items. |
109 | // Since QSystemTrayIcon doesn't have this property, the application name |
110 | // is the best information we have available. |
111 | return QCoreApplication::applicationName(); |
112 | } |
113 | |
114 | QXdgDBusToolTipStruct QStatusNotifierItemAdaptor::toolTip() const |
115 | { |
116 | QXdgDBusToolTipStruct ret; |
117 | if (m_trayIcon->isRequestingAttention()) { |
118 | ret.title = m_trayIcon->attentionTitle(); |
119 | ret.subTitle = m_trayIcon->attentionMessage(); |
120 | ret.icon = m_trayIcon->attentionIconName(); |
121 | } else { |
122 | ret.title = m_trayIcon->tooltip(); |
123 | } |
124 | return ret; |
125 | } |
126 | |
127 | void QStatusNotifierItemAdaptor::Activate(int x, int y) |
128 | { |
129 | qCDebug(qLcTray) << x << y; |
130 | emit m_trayIcon->activated(reason: QPlatformSystemTrayIcon::Trigger); |
131 | } |
132 | |
133 | void QStatusNotifierItemAdaptor::(int x, int y) |
134 | { |
135 | qCDebug(qLcTray) << x << y; |
136 | emit m_trayIcon->activated(reason: QPlatformSystemTrayIcon::Context); |
137 | } |
138 | |
139 | void QStatusNotifierItemAdaptor::ProvideXdgActivationToken(const QString &token) |
140 | { |
141 | qCDebug(qLcTray) << token; |
142 | qputenv(varName: "XDG_ACTIVATION_TOKEN" , value: token.toUtf8()); |
143 | } |
144 | |
145 | void QStatusNotifierItemAdaptor::Scroll(int w, const QString &s) |
146 | { |
147 | qCDebug(qLcTray) << w << s; |
148 | // unsupported |
149 | } |
150 | |
151 | void QStatusNotifierItemAdaptor::SecondaryActivate(int x, int y) |
152 | { |
153 | qCDebug(qLcTray) << x << y; |
154 | emit m_trayIcon->activated(reason: QPlatformSystemTrayIcon::MiddleClick); |
155 | } |
156 | |
157 | QT_END_NAMESPACE |
158 | |
159 | #include "moc_qstatusnotifieritemadaptor_p.cpp" |
160 | |
161 | #endif // QT_NO_SYSTEMTRAYICON |
162 | |