summaryrefslogtreecommitdiffstats
path: root/src/gui/platform/unix/dbustray
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/platform/unix/dbustray')
-rw-r--r--src/gui/platform/unix/dbustray/dbustray.pri11
-rw-r--r--src/gui/platform/unix/dbustray/qdbustrayicon.cpp356
-rw-r--r--src/gui/platform/unix/dbustray/qdbustrayicon_p.h168
-rw-r--r--src/gui/platform/unix/dbustray/qdbustraytypes.cpp212
-rw-r--r--src/gui/platform/unix/dbustray/qdbustraytypes_p.h109
-rw-r--r--src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor.cpp189
-rw-r--r--src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor_p.h206
-rw-r--r--src/gui/platform/unix/dbustray/qxdgnotificationproxy.cpp53
-rw-r--r--src/gui/platform/unix/dbustray/qxdgnotificationproxy_p.h143
9 files changed, 1447 insertions, 0 deletions
diff --git a/src/gui/platform/unix/dbustray/dbustray.pri b/src/gui/platform/unix/dbustray/dbustray.pri
new file mode 100644
index 0000000000..cc5b40ef42
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/dbustray.pri
@@ -0,0 +1,11 @@
+HEADERS += \
+ platform/unix/dbustray/qdbustrayicon_p.h \
+ platform/unix/dbustray/qdbustraytypes_p.h \
+ platform/unix/dbustray/qstatusnotifieritemadaptor_p.h \
+ platform/unix/dbustray/qxdgnotificationproxy_p.h
+
+SOURCES += \
+ platform/unix/dbustray/qdbustrayicon.cpp \
+ platform/unix/dbustray/qdbustraytypes.cpp \
+ platform/unix/dbustray/qstatusnotifieritemadaptor.cpp \
+ platform/unix/dbustray/qxdgnotificationproxy.cpp
diff --git a/src/gui/platform/unix/dbustray/qdbustrayicon.cpp b/src/gui/platform/unix/dbustray/qdbustrayicon.cpp
new file mode 100644
index 0000000000..e8fcb83c38
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qdbustrayicon.cpp
@@ -0,0 +1,356 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdbustrayicon_p.h"
+
+#ifndef QT_NO_SYSTEMTRAYICON
+
+#include <private/qdbusmenuconnection_p.h>
+#include "qstatusnotifieritemadaptor_p.h"
+#include <private/qdbusmenuadaptor_p.h>
+#include <private/qdbusplatformmenu_p.h>
+#include "qxdgnotificationproxy_p.h"
+
+#include <qpa/qplatformmenu.h>
+#include <qstring.h>
+#include <qdebug.h>
+#include <qrect.h>
+#include <qloggingcategory.h>
+#include <qstandardpaths.h>
+#include <qdir.h>
+#include <qmetaobject.h>
+#include <qpa/qplatformintegration.h>
+#include <qpa/qplatformservices.h>
+#include <qdbusconnectioninterface.h>
+#include <private/qlockfile_p.h>
+#include <private/qguiapplication_p.h>
+
+// Defined in Windows headers which get included by qlockfile_p.h
+#undef interface
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(qLcTray, "qt.qpa.tray")
+
+static QString iconTempPath()
+{
+ QString tempPath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
+ if (!tempPath.isEmpty())
+ return tempPath;
+
+ tempPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
+
+ if (!tempPath.isEmpty()) {
+ QDir tempDir(tempPath);
+ if (tempDir.exists())
+ return tempPath;
+
+ if (tempDir.mkpath(QStringLiteral("."))) {
+ const QFile::Permissions permissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner;
+ if (QFile(tempPath).setPermissions(permissions))
+ return tempPath;
+ }
+ }
+
+ return QDir::tempPath();
+}
+
+static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2");
+static const QString KDEWatcherService = QStringLiteral("org.kde.StatusNotifierWatcher");
+static const QString XdgNotificationService = QStringLiteral("org.freedesktop.Notifications");
+static const QString XdgNotificationPath = QStringLiteral("/org/freedesktop/Notifications");
+static const QString DefaultAction = QStringLiteral("default");
+static int instanceCount = 0;
+
+static inline QString tempFileTemplate()
+{
+ static const QString TempFileTemplate = iconTempPath() + QLatin1String("/qt-trayicon-XXXXXX.png");
+ return TempFileTemplate;
+}
+
+/*!
+ \class QDBusTrayIcon
+ \internal
+*/
+
+QDBusTrayIcon::QDBusTrayIcon()
+ : m_dbusConnection(nullptr)
+ , m_adaptor(new QStatusNotifierItemAdaptor(this))
+ , m_menuAdaptor(nullptr)
+ , m_menu(nullptr)
+ , m_notifier(nullptr)
+ , m_instanceId(KDEItemFormat.arg(QCoreApplication::applicationPid()).arg(++instanceCount))
+ , m_category(QStringLiteral("ApplicationStatus"))
+ , m_defaultStatus(QStringLiteral("Active")) // be visible all the time. QSystemTrayIcon has no API to control this.
+ , m_status(m_defaultStatus)
+ , m_tempIcon(nullptr)
+ , m_tempAttentionIcon(nullptr)
+ , m_registered(false)
+{
+ qCDebug(qLcTray);
+ if (instanceCount == 1) {
+ QDBusMenuItem::registerDBusTypes();
+ qDBusRegisterMetaType<QXdgDBusImageStruct>();
+ qDBusRegisterMetaType<QXdgDBusImageVector>();
+ qDBusRegisterMetaType<QXdgDBusToolTipStruct>();
+ }
+ connect(this, SIGNAL(statusChanged(QString)), m_adaptor, SIGNAL(NewStatus(QString)));
+ connect(this, SIGNAL(tooltipChanged()), m_adaptor, SIGNAL(NewToolTip()));
+ connect(this, SIGNAL(iconChanged()), m_adaptor, SIGNAL(NewIcon()));
+ connect(this, SIGNAL(attention()), m_adaptor, SIGNAL(NewAttentionIcon()));
+ connect(this, SIGNAL(menuChanged()), m_adaptor, SIGNAL(NewMenu()));
+ connect(this, SIGNAL(attention()), m_adaptor, SIGNAL(NewTitle()));
+ connect(&m_attentionTimer, SIGNAL(timeout()), this, SLOT(attentionTimerExpired()));
+ m_attentionTimer.setSingleShot(true);
+}
+
+QDBusTrayIcon::~QDBusTrayIcon()
+{
+}
+
+void QDBusTrayIcon::init()
+{
+ qCDebug(qLcTray) << "registering" << m_instanceId;
+ m_registered = dBusConnection()->registerTrayIcon(this);
+ QObject::connect(dBusConnection()->dbusWatcher(), &QDBusServiceWatcher::serviceRegistered,
+ this, &QDBusTrayIcon::watcherServiceRegistered);
+}
+
+void QDBusTrayIcon::cleanup()
+{
+ qCDebug(qLcTray) << "unregistering" << m_instanceId;
+ if (m_registered)
+ dBusConnection()->unregisterTrayIcon(this);
+ delete m_dbusConnection;
+ m_dbusConnection = nullptr;
+ delete m_notifier;
+ m_notifier = nullptr;
+ m_registered = false;
+}
+
+void QDBusTrayIcon::watcherServiceRegistered(const QString &serviceName)
+{
+ Q_UNUSED(serviceName);
+ // We have the icon registered, but the watcher has restarted or
+ // changed, so we need to tell it about our icon again
+ if (m_registered)
+ dBusConnection()->registerTrayIconWithWatcher(this);
+}
+
+void QDBusTrayIcon::attentionTimerExpired()
+{
+ m_messageTitle = QString();
+ m_message = QString();
+ m_attentionIcon = QIcon();
+ emit attention();
+ emit tooltipChanged();
+ setStatus(m_defaultStatus);
+}
+
+void QDBusTrayIcon::setStatus(const QString &status)
+{
+ qCDebug(qLcTray) << status;
+ if (m_status == status)
+ return;
+ m_status = status;
+ emit statusChanged(m_status);
+}
+
+QTemporaryFile *QDBusTrayIcon::tempIcon(const QIcon &icon)
+{
+ // Hack for indicator-application, which doesn't handle icons sent across D-Bus:
+ // save the icon to a temp file and set the icon name to that filename.
+ static bool necessity_checked = false;
+ static bool necessary = false;
+ if (!necessity_checked) {
+ QDBusConnection session = QDBusConnection::sessionBus();
+ uint pid = session.interface()->servicePid(KDEWatcherService).value();
+ QString processName = QLockFilePrivate::processNameByPid(pid);
+ necessary = processName.endsWith(QLatin1String("indicator-application-service"));
+ if (!necessary && QGuiApplication::desktopSettingsAware()) {
+ // Accessing to process name might be not allowed if the application
+ // is confined, thus we can just rely on the current desktop in use
+ const QPlatformServices *services = QGuiApplicationPrivate::platformIntegration()->services();
+ necessary = services->desktopEnvironment().split(':').contains("UNITY");
+ }
+ necessity_checked = true;
+ }
+ if (!necessary)
+ return nullptr;
+ qreal dpr = qGuiApp->devicePixelRatio();
+ QTemporaryFile *ret = new QTemporaryFile(tempFileTemplate(), this);
+ ret->open();
+ icon.pixmap(QSize(22 * dpr, 22 * dpr)).save(ret);
+ ret->close();
+ return ret;
+}
+
+QDBusMenuConnection * QDBusTrayIcon::dBusConnection()
+{
+ if (!m_dbusConnection) {
+ m_dbusConnection = new QDBusMenuConnection(this, m_instanceId);
+ m_notifier = new QXdgNotificationInterface(XdgNotificationService,
+ XdgNotificationPath, m_dbusConnection->connection(), this);
+ connect(m_notifier, SIGNAL(NotificationClosed(uint,uint)), this, SLOT(notificationClosed(uint,uint)));
+ connect(m_notifier, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(actionInvoked(uint,QString)));
+ }
+ return m_dbusConnection;
+}
+
+void QDBusTrayIcon::updateIcon(const QIcon &icon)
+{
+ m_iconName = icon.name();
+ m_icon = icon;
+ if (m_iconName.isEmpty()) {
+ if (m_tempIcon)
+ delete m_tempIcon;
+ m_tempIcon = tempIcon(icon);
+ if (m_tempIcon)
+ m_iconName = m_tempIcon->fileName();
+ }
+ qCDebug(qLcTray) << m_iconName << icon.availableSizes();
+ emit iconChanged();
+}
+
+void QDBusTrayIcon::updateToolTip(const QString &tooltip)
+{
+ qCDebug(qLcTray) << tooltip;
+ m_tooltip = tooltip;
+ emit tooltipChanged();
+}
+
+QPlatformMenu *QDBusTrayIcon::createMenu() const
+{
+ return new QDBusPlatformMenu();
+}
+
+void QDBusTrayIcon::updateMenu(QPlatformMenu * menu)
+{
+ qCDebug(qLcTray) << menu;
+ QDBusPlatformMenu *newMenu = qobject_cast<QDBusPlatformMenu *>(menu);
+ if (m_menu != newMenu) {
+ if (m_menu) {
+ dBusConnection()->unregisterTrayIconMenu(this);
+ delete m_menuAdaptor;
+ }
+ m_menu = newMenu;
+ m_menuAdaptor = new QDBusMenuAdaptor(m_menu);
+ // TODO connect(m_menu, , m_menuAdaptor, SIGNAL(ItemActivationRequested(int,uint)));
+ connect(m_menu, SIGNAL(propertiesUpdated(QDBusMenuItemList,QDBusMenuItemKeysList)),
+ m_menuAdaptor, SIGNAL(ItemsPropertiesUpdated(QDBusMenuItemList,QDBusMenuItemKeysList)));
+ connect(m_menu, SIGNAL(updated(uint,int)),
+ m_menuAdaptor, SIGNAL(LayoutUpdated(uint,int)));
+ dBusConnection()->registerTrayIconMenu(this);
+ emit menuChanged();
+ }
+}
+
+void QDBusTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon,
+ QPlatformSystemTrayIcon::MessageIcon iconType, int msecs)
+{
+ m_messageTitle = title;
+ m_message = msg;
+ m_attentionIcon = icon;
+ QStringList notificationActions;
+ switch (iconType) {
+ case Information:
+ m_attentionIconName = QStringLiteral("dialog-information");
+ break;
+ case Warning:
+ m_attentionIconName = QStringLiteral("dialog-warning");
+ break;
+ case Critical:
+ m_attentionIconName = QStringLiteral("dialog-error");
+ // If there are actions, the desktop notification may appear as a message dialog
+ // with button(s), which will interrupt the user and require a response.
+ // That is an optional feature in implementations of org.freedesktop.Notifications
+ notificationActions << DefaultAction << tr("OK");
+ break;
+ default:
+ m_attentionIconName.clear();
+ break;
+ }
+ if (m_attentionIconName.isEmpty()) {
+ if (m_tempAttentionIcon)
+ delete m_tempAttentionIcon;
+ m_tempAttentionIcon = tempIcon(icon);
+ if (m_tempAttentionIcon)
+ m_attentionIconName = m_tempAttentionIcon->fileName();
+ }
+ qCDebug(qLcTray) << title << msg <<
+ QPlatformSystemTrayIcon::metaObject()->enumerator(
+ QPlatformSystemTrayIcon::staticMetaObject.indexOfEnumerator("MessageIcon")).valueToKey(iconType)
+ << m_attentionIconName << msecs;
+ setStatus(QStringLiteral("NeedsAttention"));
+ m_attentionTimer.start(msecs);
+ emit tooltipChanged();
+ emit attention();
+
+ // Desktop notification
+ QVariantMap hints;
+ // urgency levels according to https://developer.gnome.org/notification-spec/#urgency-levels
+ // 0 low, 1 normal, 2 critical
+ int urgency = static_cast<int>(iconType) - 1;
+ if (urgency < 0) // no icon
+ urgency = 0;
+ hints.insert(QLatin1String("urgency"), QVariant(urgency));
+ m_notifier->notify(QCoreApplication::applicationName(), 0,
+ m_attentionIconName, title, msg, notificationActions, hints, msecs);
+}
+
+void QDBusTrayIcon::actionInvoked(uint id, const QString &action)
+{
+ qCDebug(qLcTray) << id << action;
+ emit messageClicked();
+}
+
+void QDBusTrayIcon::notificationClosed(uint id, uint reason)
+{
+ qCDebug(qLcTray) << id << reason;
+}
+
+bool QDBusTrayIcon::isSystemTrayAvailable() const
+{
+ QDBusMenuConnection * conn = const_cast<QDBusTrayIcon *>(this)->dBusConnection();
+ qCDebug(qLcTray) << conn->isStatusNotifierHostRegistered();
+ return conn->isStatusNotifierHostRegistered();
+}
+
+QT_END_NAMESPACE
+#endif //QT_NO_SYSTEMTRAYICON
diff --git a/src/gui/platform/unix/dbustray/qdbustrayicon_p.h b/src/gui/platform/unix/dbustray/qdbustrayicon_p.h
new file mode 100644
index 0000000000..04eefe3154
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qdbustrayicon_p.h
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef QDBUSTRAYICON_H
+#define QDBUSTRAYICON_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+
+QT_REQUIRE_CONFIG(systemtrayicon);
+
+#include <QIcon>
+#include <QTemporaryFile>
+#include <QTimer>
+#include "QtGui/qpa/qplatformsystemtrayicon.h"
+#include "private/qdbusmenuconnection_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QStatusNotifierItemAdaptor;
+class QDBusMenuAdaptor;
+class QDBusPlatformMenu;
+class QXdgNotificationInterface;
+
+class QDBusTrayIcon: public QPlatformSystemTrayIcon
+{
+ Q_OBJECT
+ Q_PROPERTY(QString category READ category NOTIFY categoryChanged)
+ Q_PROPERTY(QString status READ status NOTIFY statusChanged)
+ Q_PROPERTY(QString tooltip READ tooltip NOTIFY tooltipChanged)
+ Q_PROPERTY(QString iconName READ iconName NOTIFY iconChanged)
+ Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
+ Q_PROPERTY(bool isRequestingAttention READ isRequestingAttention NOTIFY attention)
+ Q_PROPERTY(QString attentionTitle READ attentionTitle NOTIFY attention)
+ Q_PROPERTY(QString attentionMessage READ attentionMessage NOTIFY attention)
+ Q_PROPERTY(QString attentionIconName READ attentionIconName NOTIFY attention)
+ Q_PROPERTY(QIcon attentionIcon READ attentionIcon NOTIFY attention)
+ Q_PROPERTY(QDBusPlatformMenu *menu READ menu NOTIFY menuChanged)
+ Q_MOC_INCLUDE(<private/qdbusplatformmenu_p.h>)
+
+public:
+ QDBusTrayIcon();
+
+ virtual ~QDBusTrayIcon();
+
+ QDBusMenuConnection * dBusConnection();
+
+ void init() override;
+ void cleanup() override;
+ void updateIcon(const QIcon &icon) override;
+ void updateToolTip(const QString &tooltip) override;
+ void updateMenu(QPlatformMenu *menu) override;
+ QPlatformMenu *createMenu() const override;
+ void showMessage(const QString &title, const QString &msg,
+ const QIcon &icon, MessageIcon iconType, int msecs) override;
+
+ bool isSystemTrayAvailable() const override;
+ bool supportsMessages() const override { return true; }
+ QRect geometry() const override { return QRect(); }
+
+ QString category() const { return m_category; }
+ QString status() const { return m_status; }
+ QString tooltip() const { return m_tooltip; }
+
+ QString iconName() const { return m_iconName; }
+ const QIcon & icon() const { return m_icon; }
+
+ bool isRequestingAttention() const { return m_attentionTimer.isActive(); }
+ QString attentionTitle() const { return m_messageTitle; }
+ QString attentionMessage() const { return m_message; }
+ QString attentionIconName() const { return m_attentionIconName; }
+ const QIcon & attentionIcon() const { return m_attentionIcon; }
+
+ QString instanceId() const { return m_instanceId; }
+
+ QDBusPlatformMenu *menu() { return m_menu; }
+
+signals:
+ void categoryChanged();
+ void statusChanged(QString arg);
+ void tooltipChanged();
+ void iconChanged();
+ void attention();
+ void menuChanged();
+
+private Q_SLOTS:
+ void attentionTimerExpired();
+ void actionInvoked(uint id, const QString &action);
+ void notificationClosed(uint id, uint reason);
+ void watcherServiceRegistered(const QString &serviceName);
+
+private:
+ void setStatus(const QString &status);
+ QTemporaryFile *tempIcon(const QIcon &icon);
+
+private:
+ QDBusMenuConnection* m_dbusConnection;
+ QStatusNotifierItemAdaptor *m_adaptor;
+ QDBusMenuAdaptor *m_menuAdaptor;
+ QDBusPlatformMenu *m_menu;
+ QXdgNotificationInterface *m_notifier;
+ QString m_instanceId;
+ QString m_category;
+ QString m_defaultStatus;
+ QString m_status;
+ QString m_tooltip;
+ QString m_messageTitle;
+ QString m_message;
+ QIcon m_icon;
+ QTemporaryFile *m_tempIcon;
+ QString m_iconName;
+ QIcon m_attentionIcon;
+ QTemporaryFile *m_tempAttentionIcon;
+ QString m_attentionIconName;
+ QTimer m_attentionTimer;
+ bool m_registered;
+};
+
+QT_END_NAMESPACE
+
+#endif // QDBUSTRAYICON_H
diff --git a/src/gui/platform/unix/dbustray/qdbustraytypes.cpp b/src/gui/platform/unix/dbustray/qdbustraytypes.cpp
new file mode 100644
index 0000000000..97cc8b7f36
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qdbustraytypes.cpp
@@ -0,0 +1,212 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Marco Martin <notmart@gmail.com>
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_SYSTEMTRAYICON
+
+#include "qdbustraytypes_p.h"
+
+#include <QDBusConnection>
+#include <QDBusMetaType>
+#include <QImage>
+#include <QIcon>
+#include <QImage>
+#include <QPixmap>
+#include <QDebug>
+#include <QtEndian>
+#include <QPainter>
+#include <QGuiApplication>
+#include <qpa/qplatformmenu.h>
+#include <private/qdbusplatformmenu_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static const int IconSizeLimit = 64;
+static const int IconNormalSmallSize = 22;
+static const int IconNormalMediumSize = 64;
+
+QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon)
+{
+ QXdgDBusImageVector ret;
+ QList<QSize> sizes = icon.availableSizes();
+
+ // Omit any size larger than 64 px, to save D-Bus bandwidth;
+ // ensure that 22px or smaller exists, because it's a common size;
+ // and ensure that something between 22px and 64px exists, for better scaling to other sizes.
+ bool hasSmallIcon = false;
+ bool hasMediumIcon = false;
+ qreal dpr = qGuiApp->devicePixelRatio();
+ QList<QSize> toRemove;
+ for (const QSize &size : qAsConst(sizes)) {
+ int maxSize = qMax(size.width(), size.height());
+ if (maxSize <= IconNormalSmallSize * dpr)
+ hasSmallIcon = true;
+ else if (maxSize <= IconNormalMediumSize * dpr)
+ hasMediumIcon = true;
+ else if (maxSize > IconSizeLimit * dpr)
+ toRemove << size;
+ }
+ for (const QSize &size : qAsConst(toRemove))
+ sizes.removeOne(size);
+ if (!hasSmallIcon)
+ sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr));
+ if (!hasMediumIcon)
+ sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr));
+
+ ret.reserve(sizes.size());
+ for (const QSize &size : qAsConst(sizes)) {
+ // Protocol specifies ARGB32 format in network byte order
+ QImage im = icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32);
+ // letterbox if necessary to make it square
+ if (im.height() != im.width()) {
+ int maxSize = qMax(im.width(), im.height());
+ QImage padded(maxSize, maxSize, QImage::Format_ARGB32);
+ padded.fill(Qt::transparent);
+ QPainter painter(&padded);
+ painter.drawImage((maxSize - im.width()) / 2, (maxSize - im.height()) / 2, im);
+ im = padded;
+ }
+ // copy and endian-convert
+ QXdgDBusImageStruct kim(im.width(), im.height());
+ const uchar *end = im.constBits() + im.sizeInBytes();
+ uchar *dest = reinterpret_cast<uchar *>(kim.data.data());
+ for (const uchar *src = im.constBits(); src < end; src += 4, dest += 4)
+ qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest);
+
+ ret << kim;
+ }
+ return ret;
+}
+
+// Marshall the ImageStruct data into a D-Bus argument
+const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusImageStruct &icon)
+{
+ argument.beginStructure();
+ argument << icon.width;
+ argument << icon.height;
+ argument << icon.data;
+ argument.endStructure();
+ return argument;
+}
+
+// Retrieve the ImageStruct data from the D-Bus argument
+const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusImageStruct &icon)
+{
+ qint32 width;
+ qint32 height;
+ QByteArray data;
+
+ argument.beginStructure();
+ argument >> width;
+ argument >> height;
+ argument >> data;
+ argument.endStructure();
+
+ icon.width = width;
+ icon.height = height;
+ icon.data = data;
+
+ return argument;
+}
+
+// Marshall the ImageVector data into a D-Bus argument
+const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusImageVector &iconVector)
+{
+ argument.beginArray(qMetaTypeId<QXdgDBusImageStruct>());
+ for (int i = 0; i < iconVector.size(); ++i) {
+ argument << iconVector[i];
+ }
+ argument.endArray();
+ return argument;
+}
+
+// Retrieve the ImageVector data from the D-Bus argument
+const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusImageVector &iconVector)
+{
+ argument.beginArray();
+ iconVector.clear();
+
+ while (!argument.atEnd()) {
+ QXdgDBusImageStruct element;
+ argument >> element;
+ iconVector.append(element);
+ }
+
+ argument.endArray();
+
+ return argument;
+}
+
+// Marshall the ToolTipStruct data into a D-Bus argument
+const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusToolTipStruct &toolTip)
+{
+ argument.beginStructure();
+ argument << toolTip.icon;
+ argument << toolTip.image;
+ argument << toolTip.title;
+ argument << toolTip.subTitle;
+ argument.endStructure();
+ return argument;
+}
+
+// Retrieve the ToolTipStruct data from the D-Bus argument
+const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusToolTipStruct &toolTip)
+{
+ QString icon;
+ QXdgDBusImageVector image;
+ QString title;
+ QString subTitle;
+
+ argument.beginStructure();
+ argument >> icon;
+ argument >> image;
+ argument >> title;
+ argument >> subTitle;
+ argument.endStructure();
+
+ toolTip.icon = icon;
+ toolTip.image = image;
+ toolTip.title = title;
+ toolTip.subTitle = subTitle;
+
+ return argument;
+}
+
+QT_END_NAMESPACE
+#endif // QT_NO_SYSTEMTRAYICON
diff --git a/src/gui/platform/unix/dbustray/qdbustraytypes_p.h b/src/gui/platform/unix/dbustray/qdbustraytypes_p.h
new file mode 100644
index 0000000000..3f75555579
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qdbustraytypes_p.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Marco Martin <notmart@gmail.com>
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDBUSTRAYTYPES_P_H
+#define QDBUSTRAYTYPES_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+
+QT_REQUIRE_CONFIG(systemtrayicon);
+
+#include <QObject>
+#include <QString>
+#include <QDBusArgument>
+#include <QDBusConnection>
+#include <QDBusObjectPath>
+#include <QPixmap>
+
+QT_BEGIN_NAMESPACE
+
+// Custom message type to send icons across D-Bus
+struct QXdgDBusImageStruct
+{
+ QXdgDBusImageStruct() { }
+ QXdgDBusImageStruct(int w, int h)
+ : width(w), height(h), data(width * height * 4, 0) { }
+ int width;
+ int height;
+ QByteArray data;
+};
+Q_DECLARE_TYPEINFO(QXdgDBusImageStruct, Q_MOVABLE_TYPE);
+
+typedef QVector<QXdgDBusImageStruct> QXdgDBusImageVector;
+
+QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon);
+
+// Custom message type to send tooltips across D-Bus
+struct QXdgDBusToolTipStruct
+{
+ QString icon;
+ QXdgDBusImageVector image;
+ QString title;
+ QString subTitle;
+};
+Q_DECLARE_TYPEINFO(QXdgDBusToolTipStruct, Q_MOVABLE_TYPE);
+
+const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusImageStruct &icon);
+const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusImageStruct &icon);
+
+const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusImageVector &iconVector);
+const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusImageVector &iconVector);
+
+const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusToolTipStruct &toolTip);
+const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusToolTipStruct &toolTip);
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QXdgDBusImageStruct)
+Q_DECLARE_METATYPE(QXdgDBusImageVector)
+Q_DECLARE_METATYPE(QXdgDBusToolTipStruct)
+
+#endif // QDBUSTRAYTYPES_P_H
diff --git a/src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor.cpp b/src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor.cpp
new file mode 100644
index 0000000000..ef2d330959
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ This file was originally created by qdbusxml2cpp version 0.8
+ Command line was:
+ qdbusxml2cpp -a statusnotifieritem ../../3rdparty/dbus-ifaces/org.kde.StatusNotifierItem.xml
+
+ However it is maintained manually, because this adapter needs to do
+ significant interface adaptation, and can do it more efficiently using the
+ QDBusTrayIcon API directly rather than via QObject::property() and
+ QMetaObject::invokeMethod().
+*/
+
+#include "qstatusnotifieritemadaptor_p.h"
+
+#ifndef QT_NO_SYSTEMTRAYICON
+
+#include <QtCore/QLoggingCategory>
+#include <QtCore/QCoreApplication>
+
+#include "qdbustrayicon_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qLcMenu)
+Q_DECLARE_LOGGING_CATEGORY(qLcTray)
+
+QStatusNotifierItemAdaptor::QStatusNotifierItemAdaptor(QDBusTrayIcon *parent)
+ : QDBusAbstractAdaptor(parent), m_trayIcon(parent)
+{
+ setAutoRelaySignals(true);
+}
+
+QStatusNotifierItemAdaptor::~QStatusNotifierItemAdaptor()
+{
+}
+
+QString QStatusNotifierItemAdaptor::attentionIconName() const
+{
+ return m_trayIcon->attentionIconName();
+}
+
+QXdgDBusImageVector QStatusNotifierItemAdaptor::attentionIconPixmap() const
+{
+ return iconToQXdgDBusImageVector(m_trayIcon->attentionIcon());
+}
+
+QString QStatusNotifierItemAdaptor::attentionMovieName() const
+{
+ return QString();
+}
+
+QString QStatusNotifierItemAdaptor::category() const
+{
+ return m_trayIcon->category();
+}
+
+QString QStatusNotifierItemAdaptor::iconName() const
+{
+ return m_trayIcon->iconName();
+}
+
+QXdgDBusImageVector QStatusNotifierItemAdaptor::iconPixmap() const
+{
+ return iconToQXdgDBusImageVector(m_trayIcon->icon());
+}
+
+QString QStatusNotifierItemAdaptor::id() const
+{
+ // from the API docs: "a name that should be unique for this application and
+ // consistent between sessions, such as the application name itself"
+ return QCoreApplication::applicationName();
+}
+
+bool QStatusNotifierItemAdaptor::itemIsMenu() const
+{
+ // From KDE docs: if this is true, the item only supports the context menu,
+ // so the visualization should prefer sending ContextMenu() instead of Activate().
+ // But QSystemTrayIcon doesn't have such a setting: it will emit activated()
+ // and the application is free to use it or ignore it; we don't know whether it will.
+ return false;
+}
+
+QDBusObjectPath QStatusNotifierItemAdaptor::menu() const
+{
+ return QDBusObjectPath(m_trayIcon->menu() ? "/MenuBar" : "/NO_DBUSMENU");
+}
+
+QString QStatusNotifierItemAdaptor::overlayIconName() const
+{
+ return QString();
+}
+
+QXdgDBusImageVector QStatusNotifierItemAdaptor::overlayIconPixmap() const
+{
+ QXdgDBusImageVector ret; // empty vector
+ return ret;
+}
+
+QString QStatusNotifierItemAdaptor::status() const
+{
+ return m_trayIcon->status();
+}
+
+QString QStatusNotifierItemAdaptor::title() const
+{
+ // Shown e.g. when the icon is hidden, in the popup showing all hidden items.
+ // Since QSystemTrayIcon doesn't have this property, the application name
+ // is the best information we have available.
+ return QCoreApplication::applicationName();
+}
+
+QXdgDBusToolTipStruct QStatusNotifierItemAdaptor::toolTip() const
+{
+ QXdgDBusToolTipStruct ret;
+ if (m_trayIcon->isRequestingAttention()) {
+ ret.title = m_trayIcon->attentionTitle();
+ ret.subTitle = m_trayIcon->attentionMessage();
+ ret.icon = m_trayIcon->attentionIconName();
+ } else {
+ ret.title = m_trayIcon->tooltip();
+ }
+ return ret;
+}
+
+void QStatusNotifierItemAdaptor::Activate(int x, int y)
+{
+ qCDebug(qLcTray) << x << y;
+ emit m_trayIcon->activated(QPlatformSystemTrayIcon::Trigger);
+}
+
+void QStatusNotifierItemAdaptor::ContextMenu(int x, int y)
+{
+ qCDebug(qLcTray) << x << y;
+ emit m_trayIcon->activated(QPlatformSystemTrayIcon::Context);
+}
+
+void QStatusNotifierItemAdaptor::Scroll(int w, const QString &s)
+{
+ qCDebug(qLcTray) << w << s;
+ // unsupported
+}
+
+void QStatusNotifierItemAdaptor::SecondaryActivate(int x, int y)
+{
+ qCDebug(qLcTray) << x << y;
+ emit m_trayIcon->activated(QPlatformSystemTrayIcon::MiddleClick);
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SYSTEMTRAYICON
diff --git a/src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor_p.h b/src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor_p.h
new file mode 100644
index 0000000000..f2bb156b1d
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qstatusnotifieritemadaptor_p.h
@@ -0,0 +1,206 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ This file was originally created by qdbusxml2cpp version 0.8
+ Command line was:
+ qdbusxml2cpp -a statusnotifieritem ../../3rdparty/dbus-ifaces/org.kde.StatusNotifierItem.xml
+
+ However it is maintained manually.
+
+ It is also not part of the public API. This header file may change from
+ version to version without notice, or even be removed.
+*/
+
+#ifndef QSTATUSNOTIFIERITEMADAPTER_P_H
+#define QSTATUSNOTIFIERITEMADAPTER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+
+QT_REQUIRE_CONFIG(systemtrayicon);
+
+#include <QtCore/QObject>
+#include <QtDBus/QtDBus>
+
+#include "qdbustraytypes_p.h"
+
+QT_BEGIN_NAMESPACE
+class QDBusTrayIcon;
+
+/*
+ Adaptor class for interface org.kde.StatusNotifierItem
+ see http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/
+ (also http://www.notmart.org/misc/statusnotifieritem/)
+*/
+class QStatusNotifierItemAdaptor: public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.kde.StatusNotifierItem")
+ Q_CLASSINFO("D-Bus Introspection", ""
+" <interface name=\"org.kde.StatusNotifierItem\">\n"
+" <property access=\"read\" type=\"s\" name=\"Category\"/>\n"
+" <property access=\"read\" type=\"s\" name=\"Id\"/>\n"
+" <property access=\"read\" type=\"s\" name=\"Title\"/>\n"
+" <property access=\"read\" type=\"s\" name=\"Status\"/>\n"
+" <property access=\"read\" type=\"i\" name=\"WindowId\"/>\n"
+" <property access=\"read\" type=\"s\" name=\"IconThemePath\"/>\n"
+" <property access=\"read\" type=\"o\" name=\"Menu\"/>\n"
+" <property access=\"read\" type=\"b\" name=\"ItemIsMenu\"/>\n"
+" <property access=\"read\" type=\"s\" name=\"IconName\"/>\n"
+" <property access=\"read\" type=\"a(iiay)\" name=\"IconPixmap\">\n"
+" <annotation value=\"QXdgDBusImageVector\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
+" </property>\n"
+" <property access=\"read\" type=\"s\" name=\"OverlayIconName\"/>\n"
+" <property access=\"read\" type=\"a(iiay)\" name=\"OverlayIconPixmap\">\n"
+" <annotation value=\"QXdgDBusImageVector\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
+" </property>\n"
+" <property access=\"read\" type=\"s\" name=\"AttentionIconName\"/>\n"
+" <property access=\"read\" type=\"a(iiay)\" name=\"AttentionIconPixmap\">\n"
+" <annotation value=\"QXdgDBusImageVector\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
+" </property>\n"
+" <property access=\"read\" type=\"s\" name=\"AttentionMovieName\"/>\n"
+" <property access=\"read\" type=\"(sa(iiay)ss)\" name=\"ToolTip\">\n"
+" <annotation value=\"QXdgDBusToolTipStruct\" name=\"org.qtproject.QtDBus.QtTypeName\"/>\n"
+" </property>\n"
+" <method name=\"ContextMenu\">\n"
+" <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
+" <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
+" </method>\n"
+" <method name=\"Activate\">\n"
+" <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
+" <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
+" </method>\n"
+" <method name=\"SecondaryActivate\">\n"
+" <arg direction=\"in\" type=\"i\" name=\"x\"/>\n"
+" <arg direction=\"in\" type=\"i\" name=\"y\"/>\n"
+" </method>\n"
+" <method name=\"Scroll\">\n"
+" <arg direction=\"in\" type=\"i\" name=\"delta\"/>\n"
+" <arg direction=\"in\" type=\"s\" name=\"orientation\"/>\n"
+" </method>\n"
+" <signal name=\"NewTitle\"/>\n"
+" <signal name=\"NewIcon\"/>\n"
+" <signal name=\"NewAttentionIcon\"/>\n"
+" <signal name=\"NewOverlayIcon\"/>\n"
+" <signal name=\"NewMenu\"/>\n"
+" <signal name=\"NewToolTip\"/>\n"
+" <signal name=\"NewStatus\">\n"
+" <arg type=\"s\" name=\"status\"/>\n"
+" </signal>\n"
+" </interface>\n"
+ "")
+public:
+ QStatusNotifierItemAdaptor(QDBusTrayIcon *parent);
+ virtual ~QStatusNotifierItemAdaptor();
+
+public: // PROPERTIES
+ Q_PROPERTY(QString AttentionIconName READ attentionIconName)
+ QString attentionIconName() const;
+
+ Q_PROPERTY(QXdgDBusImageVector AttentionIconPixmap READ attentionIconPixmap)
+ QXdgDBusImageVector attentionIconPixmap() const;
+
+ Q_PROPERTY(QString AttentionMovieName READ attentionMovieName)
+ QString attentionMovieName() const;
+
+ Q_PROPERTY(QString Category READ category)
+ QString category() const;
+
+ Q_PROPERTY(QString IconName READ iconName)
+ QString iconName() const;
+
+ Q_PROPERTY(QXdgDBusImageVector IconPixmap READ iconPixmap)
+ QXdgDBusImageVector iconPixmap() const;
+
+ Q_PROPERTY(QString Id READ id)
+ QString id() const;
+
+ Q_PROPERTY(bool ItemIsMenu READ itemIsMenu)
+ bool itemIsMenu() const;
+
+ Q_PROPERTY(QDBusObjectPath Menu READ menu)
+ QDBusObjectPath menu() const;
+
+ Q_PROPERTY(QString OverlayIconName READ overlayIconName)
+ QString overlayIconName() const;
+
+ Q_PROPERTY(QXdgDBusImageVector OverlayIconPixmap READ overlayIconPixmap)
+ QXdgDBusImageVector overlayIconPixmap() const;
+
+ Q_PROPERTY(QString Status READ status)
+ QString status() const;
+
+ Q_PROPERTY(QString Title READ title)
+ QString title() const;
+
+ Q_PROPERTY(QXdgDBusToolTipStruct ToolTip READ toolTip)
+ QXdgDBusToolTipStruct toolTip() const;
+
+public Q_SLOTS: // METHODS
+ void Activate(int x, int y);
+ void ContextMenu(int x, int y);
+ void Scroll(int delta, const QString &orientation);
+ void SecondaryActivate(int x, int y);
+Q_SIGNALS: // SIGNALS
+ void NewAttentionIcon();
+ void NewIcon();
+ void NewOverlayIcon();
+ void NewMenu();
+ void NewStatus(const QString &status);
+ void NewTitle();
+ void NewToolTip();
+
+private:
+ QDBusTrayIcon *m_trayIcon;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSTATUSNOTIFIERITEMADAPTER_P_H
diff --git a/src/gui/platform/unix/dbustray/qxdgnotificationproxy.cpp b/src/gui/platform/unix/dbustray/qxdgnotificationproxy.cpp
new file mode 100644
index 0000000000..ef2aa799c8
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qxdgnotificationproxy.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qxdgnotificationproxy_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QXdgNotificationInterface::QXdgNotificationInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+QXdgNotificationInterface::~QXdgNotificationInterface()
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/platform/unix/dbustray/qxdgnotificationproxy_p.h b/src/gui/platform/unix/dbustray/qxdgnotificationproxy_p.h
new file mode 100644
index 0000000000..495208f873
--- /dev/null
+++ b/src/gui/platform/unix/dbustray/qxdgnotificationproxy_p.h
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ This file was originally created by qdbusxml2cpp version 0.8
+ Command line was:
+ qdbusxml2cpp -p qxdgnotificationproxy ../../3rdparty/dbus-ifaces/org.freedesktop.Notifications.xml
+
+ However it is maintained manually.
+
+ It is also not part of the public API. This header file may change from
+ version to version without notice, or even be removed.
+*/
+
+#ifndef QXDGNOTIFICATIONPROXY_P_H
+#define QXDGNOTIFICATIONPROXY_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QLoggingCategory>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qLcTray)
+
+/*
+ * Proxy class for interface org.freedesktop.Notifications
+ */
+class QXdgNotificationInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "org.freedesktop.Notifications"; }
+
+public:
+ QXdgNotificationInterface(const QString &service, const QString &path,
+ const QDBusConnection &connection, QObject *parent = nullptr);
+
+ ~QXdgNotificationInterface();
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<> closeNotification(uint id)
+ {
+ return asyncCall(QStringLiteral("CloseNotification"), id);
+ }
+
+ inline QDBusPendingReply<QStringList> getCapabilities()
+ {
+ return asyncCall(QStringLiteral("GetCapabilities"));
+ }
+
+ inline QDBusPendingReply<QString, QString, QString, QString> getServerInformation()
+ {
+ return asyncCall(QStringLiteral("GetServerInformation"));
+ }
+ inline QDBusReply<QString> getServerInformation(QString &vendor, QString &version, QString &specVersion)
+ {
+ QDBusMessage reply = call(QDBus::Block, QStringLiteral("GetServerInformation"));
+ if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 4) {
+ vendor = qdbus_cast<QString>(reply.arguments().at(1));
+ version = qdbus_cast<QString>(reply.arguments().at(2));
+ specVersion = qdbus_cast<QString>(reply.arguments().at(3));
+ }
+ return reply;
+ }
+
+ // see https://developer.gnome.org/notification-spec/#basic-design
+ inline QDBusPendingReply<uint> notify(const QString &appName, uint replacesId, const QString &appIcon,
+ const QString &summary, const QString &body, const QStringList &actions,
+ const QVariantMap &hints, int timeout)
+ {
+ qCDebug(qLcTray) << appName << replacesId << appIcon << summary << body << actions << hints << timeout;
+ return asyncCall(QStringLiteral("Notify"), appName, replacesId, appIcon, summary, body, actions, hints, timeout);
+ }
+
+Q_SIGNALS:
+ void ActionInvoked(uint id, const QString &action_key);
+ void NotificationClosed(uint id, uint reason);
+};
+
+QT_END_NAMESPACE
+
+namespace org {
+ namespace freedesktop {
+ using Notifications = QT_PREPEND_NAMESPACE(QXdgNotificationInterface);
+ }
+}
+
+#endif