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#ifndef QDBUSTRAYICON_H
42#define QDBUSTRAYICON_H
43
44//
45// W A R N I N G
46// -------------
47//
48// This file is not part of the Qt API. It exists purely as an
49// implementation detail. This header file may change from version to
50// version without notice, or even be removed.
51//
52// We mean it.
53//
54
55#include <QtGui/private/qtguiglobal_p.h>
56
57QT_REQUIRE_CONFIG(systemtrayicon);
58
59#include <QIcon>
60#include <QTemporaryFile>
61#include <QTimer>
62#include "QtGui/qpa/qplatformsystemtrayicon.h"
63#include "private/qdbusmenuconnection_p.h"
64
65QT_BEGIN_NAMESPACE
66
67class QStatusNotifierItemAdaptor;
68class QDBusMenuAdaptor;
69class QDBusPlatformMenu;
70class QXdgNotificationInterface;
71
72class QDBusTrayIcon: public QPlatformSystemTrayIcon
73{
74 Q_OBJECT
75 Q_PROPERTY(QString category READ category NOTIFY categoryChanged)
76 Q_PROPERTY(QString status READ status NOTIFY statusChanged)
77 Q_PROPERTY(QString tooltip READ tooltip NOTIFY tooltipChanged)
78 Q_PROPERTY(QString iconName READ iconName NOTIFY iconChanged)
79 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
80 Q_PROPERTY(bool isRequestingAttention READ isRequestingAttention NOTIFY attention)
81 Q_PROPERTY(QString attentionTitle READ attentionTitle NOTIFY attention)
82 Q_PROPERTY(QString attentionMessage READ attentionMessage NOTIFY attention)
83 Q_PROPERTY(QString attentionIconName READ attentionIconName NOTIFY attention)
84 Q_PROPERTY(QIcon attentionIcon READ attentionIcon NOTIFY attention)
85 Q_PROPERTY(QDBusPlatformMenu *menu READ menu NOTIFY menuChanged)
86 Q_MOC_INCLUDE(<private/qdbusplatformmenu_p.h>)
87
88public:
89 QDBusTrayIcon();
90
91 virtual ~QDBusTrayIcon();
92
93 QDBusMenuConnection * dBusConnection();
94
95 void init() override;
96 void cleanup() override;
97 void updateIcon(const QIcon &icon) override;
98 void updateToolTip(const QString &tooltip) override;
99 void updateMenu(QPlatformMenu *menu) override;
100 QPlatformMenu *createMenu() const override;
101 void showMessage(const QString &title, const QString &msg,
102 const QIcon &icon, MessageIcon iconType, int msecs) override;
103
104 bool isSystemTrayAvailable() const override;
105 bool supportsMessages() const override { return true; }
106 QRect geometry() const override { return QRect(); }
107
108 QString category() const { return m_category; }
109 QString status() const { return m_status; }
110 QString tooltip() const { return m_tooltip; }
111
112 QString iconName() const { return m_iconName; }
113 const QIcon & icon() const { return m_icon; }
114
115 bool isRequestingAttention() const { return m_attentionTimer.isActive(); }
116 QString attentionTitle() const { return m_messageTitle; }
117 QString attentionMessage() const { return m_message; }
118 QString attentionIconName() const { return m_attentionIconName; }
119 const QIcon & attentionIcon() const { return m_attentionIcon; }
120
121 QString instanceId() const { return m_instanceId; }
122
123 QDBusPlatformMenu *menu() { return m_menu; }
124
125signals:
126 void categoryChanged();
127 void statusChanged(QString arg);
128 void tooltipChanged();
129 void iconChanged();
130 void attention();
131 void menuChanged();
132
133private Q_SLOTS:
134 void attentionTimerExpired();
135 void actionInvoked(uint id, const QString &action);
136 void notificationClosed(uint id, uint reason);
137 void watcherServiceRegistered(const QString &serviceName);
138
139private:
140 void setStatus(const QString &status);
141 QTemporaryFile *tempIcon(const QIcon &icon);
142
143private:
144 QDBusMenuConnection* m_dbusConnection;
145 QStatusNotifierItemAdaptor *m_adaptor;
146 QDBusMenuAdaptor *m_menuAdaptor;
147 QDBusPlatformMenu *m_menu;
148 QXdgNotificationInterface *m_notifier;
149 QString m_instanceId;
150 QString m_category;
151 QString m_defaultStatus;
152 QString m_status;
153 QString m_tooltip;
154 QString m_messageTitle;
155 QString m_message;
156 QIcon m_icon;
157 QTemporaryFile *m_tempIcon;
158 QString m_iconName;
159 QIcon m_attentionIcon;
160 QTemporaryFile *m_tempAttentionIcon;
161 QString m_attentionIconName;
162 QTimer m_attentionTimer;
163 bool m_registered;
164};
165
166QT_END_NAMESPACE
167
168#endif // QDBUSTRAYICON_H
169