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/*
41 This file was originally created by qdbusxml2cpp version 0.8
42 Command line was:
43 qdbusxml2cpp -a statusnotifieritem ../../3rdparty/dbus-ifaces/org.kde.StatusNotifierItem.xml
44
45 However it is maintained manually, because this adapter needs to do
46 significant interface adaptation, and can do it more efficiently using the
47 QDBusTrayIcon API directly rather than via QObject::property() and
48 QMetaObject::invokeMethod().
49*/
50
51#include "qstatusnotifieritemadaptor_p.h"
52
53#ifndef QT_NO_SYSTEMTRAYICON
54
55#include <QtCore/QLoggingCategory>
56#include <QtCore/QCoreApplication>
57
58#include "qdbustrayicon_p.h"
59
60QT_BEGIN_NAMESPACE
61
62Q_DECLARE_LOGGING_CATEGORY(qLcMenu)
63Q_DECLARE_LOGGING_CATEGORY(qLcTray)
64
65QStatusNotifierItemAdaptor::QStatusNotifierItemAdaptor(QDBusTrayIcon *parent)
66 : QDBusAbstractAdaptor(parent), m_trayIcon(parent)
67{
68 setAutoRelaySignals(true);
69}
70
71QStatusNotifierItemAdaptor::~QStatusNotifierItemAdaptor()
72{
73}
74
75QString QStatusNotifierItemAdaptor::attentionIconName() const
76{
77 return m_trayIcon->attentionIconName();
78}
79
80QXdgDBusImageVector QStatusNotifierItemAdaptor::attentionIconPixmap() const
81{
82 return iconToQXdgDBusImageVector(m_trayIcon->attentionIcon());
83}
84
85QString QStatusNotifierItemAdaptor::attentionMovieName() const
86{
87 return QString();
88}
89
90QString QStatusNotifierItemAdaptor::category() const
91{
92 return m_trayIcon->category();
93}
94
95QString QStatusNotifierItemAdaptor::iconName() const
96{
97 return m_trayIcon->iconName();
98}
99
100QXdgDBusImageVector QStatusNotifierItemAdaptor::iconPixmap() const
101{
102 return iconToQXdgDBusImageVector(m_trayIcon->icon());
103}
104
105QString QStatusNotifierItemAdaptor::id() const
106{
107 // from the API docs: "a name that should be unique for this application and
108 // consistent between sessions, such as the application name itself"
109 return QCoreApplication::applicationName();
110}
111
112bool QStatusNotifierItemAdaptor::itemIsMenu() const
113{
114 // From KDE docs: if this is true, the item only supports the context menu,
115 // so the visualization should prefer sending ContextMenu() instead of Activate().
116 // But QSystemTrayIcon doesn't have such a setting: it will emit activated()
117 // and the application is free to use it or ignore it; we don't know whether it will.
118 return false;
119}
120
121QDBusObjectPath QStatusNotifierItemAdaptor::menu() const
122{
123 return QDBusObjectPath(m_trayIcon->menu() ? "/MenuBar" : "/NO_DBUSMENU");
124}
125
126QString QStatusNotifierItemAdaptor::overlayIconName() const
127{
128 return QString();
129}
130
131QXdgDBusImageVector QStatusNotifierItemAdaptor::overlayIconPixmap() const
132{
133 QXdgDBusImageVector ret; // empty vector
134 return ret;
135}
136
137QString QStatusNotifierItemAdaptor::status() const
138{
139 return m_trayIcon->status();
140}
141
142QString QStatusNotifierItemAdaptor::title() const
143{
144 // Shown e.g. when the icon is hidden, in the popup showing all hidden items.
145 // Since QSystemTrayIcon doesn't have this property, the application name
146 // is the best information we have available.
147 return QCoreApplication::applicationName();
148}
149
150QXdgDBusToolTipStruct QStatusNotifierItemAdaptor::toolTip() const
151{
152 QXdgDBusToolTipStruct ret;
153 if (m_trayIcon->isRequestingAttention()) {
154 ret.title = m_trayIcon->attentionTitle();
155 ret.subTitle = m_trayIcon->attentionMessage();
156 ret.icon = m_trayIcon->attentionIconName();
157 } else {
158 ret.title = m_trayIcon->tooltip();
159 }
160 return ret;
161}
162
163void QStatusNotifierItemAdaptor::Activate(int x, int y)
164{
165 qCDebug(qLcTray) << x << y;
166 emit m_trayIcon->activated(QPlatformSystemTrayIcon::Trigger);
167}
168
169void QStatusNotifierItemAdaptor::ContextMenu(int x, int y)
170{
171 qCDebug(qLcTray) << x << y;
172 emit m_trayIcon->activated(QPlatformSystemTrayIcon::Context);
173}
174
175void QStatusNotifierItemAdaptor::Scroll(int w, const QString &s)
176{
177 qCDebug(qLcTray) << w << s;
178 // unsupported
179}
180
181void QStatusNotifierItemAdaptor::SecondaryActivate(int x, int y)
182{
183 qCDebug(qLcTray) << x << y;
184 emit m_trayIcon->activated(QPlatformSystemTrayIcon::MiddleClick);
185}
186
187QT_END_NAMESPACE
188
189#endif // QT_NO_SYSTEMTRAYICON
190