summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/3rdparty/dbus-ifaces/org.freedesktop.Notifications.xml37
-rw-r--r--src/platformsupport/dbustray/dbustray.pri2
-rw-r--r--src/platformsupport/dbustray/qdbustrayicon.cpp39
-rw-r--r--src/platformsupport/dbustray/qdbustrayicon_p.h4
-rw-r--r--src/platformsupport/dbustray/qxdgnotificationproxy.cpp47
-rw-r--r--src/platformsupport/dbustray/qxdgnotificationproxy_p.h135
6 files changed, 263 insertions, 1 deletions
diff --git a/src/3rdparty/dbus-ifaces/org.freedesktop.Notifications.xml b/src/3rdparty/dbus-ifaces/org.freedesktop.Notifications.xml
new file mode 100644
index 0000000000..62345f2bb3
--- /dev/null
+++ b/src/3rdparty/dbus-ifaces/org.freedesktop.Notifications.xml
@@ -0,0 +1,37 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.freedesktop.Notifications">
+ <signal name="NotificationClosed">
+ <arg name="id" type="u" direction="out"/>
+ <arg name="reason" type="u" direction="out"/>
+ </signal>
+ <signal name="ActionInvoked">
+ <arg name="id" type="u" direction="out"/>
+ <arg name="action_key" type="s" direction="out"/>
+ </signal>
+ <method name="Notify">
+ <annotation name="org.qtproject.QtDBus.QtTypeName.In6" value="QVariantMap"/>
+ <arg type="u" direction="out"/>
+ <arg name="app_name" type="s" direction="in"/>
+ <arg name="replaces_id" type="u" direction="in"/>
+ <arg name="app_icon" type="s" direction="in"/>
+ <arg name="summary" type="s" direction="in"/>
+ <arg name="body" type="s" direction="in"/>
+ <arg name="actions" type="as" direction="in"/>
+ <arg name="hints" type="a{sv}" direction="in"/>
+ <arg name="timeout" type="i" direction="in"/>
+ </method>
+ <method name="CloseNotification">
+ <arg name="id" type="u" direction="in"/>
+ </method>
+ <method name="GetCapabilities">
+ <arg type="as" name="caps" direction="out"/>
+ </method>
+ <method name="GetServerInformation">
+ <arg type="s" name="name" direction="out"/>
+ <arg type="s" name="vendor" direction="out"/>
+ <arg type="s" name="version" direction="out"/>
+ <arg type="s" name="spec_version" direction="out"/>
+ </method>
+ </interface>
+</node>
diff --git a/src/platformsupport/dbustray/dbustray.pri b/src/platformsupport/dbustray/dbustray.pri
index ca1ff8e434..734ee5fb40 100644
--- a/src/platformsupport/dbustray/dbustray.pri
+++ b/src/platformsupport/dbustray/dbustray.pri
@@ -6,8 +6,10 @@ HEADERS += \
$$PWD/qdbustrayicon_p.h \
$$PWD/qdbustraytypes_p.h \
$$PWD/qstatusnotifieritemadaptor_p.h \
+ $$PWD/qxdgnotificationproxy_p.h \
SOURCES += \
$$PWD/qdbustrayicon.cpp \
$$PWD/qdbustraytypes.cpp \
$$PWD/qstatusnotifieritemadaptor.cpp \
+ $$PWD/qxdgnotificationproxy.cpp \
diff --git a/src/platformsupport/dbustray/qdbustrayicon.cpp b/src/platformsupport/dbustray/qdbustrayicon.cpp
index 1c21da849c..d753e94698 100644
--- a/src/platformsupport/dbustray/qdbustrayicon.cpp
+++ b/src/platformsupport/dbustray/qdbustrayicon.cpp
@@ -38,6 +38,7 @@
#include "qstatusnotifieritemadaptor_p.h"
#include "qdbusmenuadaptor_p.h"
#include "dbusmenu/qdbusplatformmenu_p.h"
+#include "qxdgnotificationproxy_p.h"
#include <qplatformmenu.h>
#include <qstring.h>
@@ -54,6 +55,9 @@ Q_LOGGING_CATEGORY(qLcTray, "qt.qpa.tray")
static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2");
static const QString TempFileTemplate = QDir::tempPath() + QStringLiteral("/qt-trayicon-XXXXXX.png");
+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;
/*!
@@ -66,6 +70,7 @@ QDBusTrayIcon::QDBusTrayIcon()
, m_adaptor(new QStatusNotifierItemAdaptor(this))
, m_menuAdaptor(Q_NULLPTR)
, m_menu(Q_NULLPTR)
+ , m_notifier(Q_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.
@@ -152,8 +157,13 @@ QTemporaryFile *QDBusTrayIcon::tempIcon(const QIcon &icon)
QDBusMenuConnection * QDBusTrayIcon::dBusConnection()
{
- if (!m_dbusConnection)
+ if (!m_dbusConnection) {
m_dbusConnection = new QDBusMenuConnection(this);
+ 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;
}
@@ -214,6 +224,7 @@ void QDBusTrayIcon::showMessage(const QString &title, const QString &msg, const
m_messageTitle = title;
m_message = msg;
m_attentionIcon = icon;
+ QStringList notificationActions;
switch (iconType) {
case Information:
m_attentionIconName = QStringLiteral("dialog-information");
@@ -223,6 +234,10 @@ void QDBusTrayIcon::showMessage(const QString &title, const QString &msg, const
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();
@@ -243,6 +258,28 @@ void QDBusTrayIcon::showMessage(const QString &title, const QString &msg, const
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
diff --git a/src/platformsupport/dbustray/qdbustrayicon_p.h b/src/platformsupport/dbustray/qdbustrayicon_p.h
index 1b5f262ef1..97a700917b 100644
--- a/src/platformsupport/dbustray/qdbustrayicon_p.h
+++ b/src/platformsupport/dbustray/qdbustrayicon_p.h
@@ -59,6 +59,7 @@ QT_BEGIN_NAMESPACE
class QStatusNotifierItemAdaptor;
class QDBusMenuAdaptor;
class QDBusPlatformMenu;
+class QXdgNotificationInterface;
class QDBusTrayIcon: public QPlatformSystemTrayIcon
{
@@ -126,6 +127,8 @@ signals:
private Q_SLOTS:
void attentionTimerExpired();
+ void actionInvoked(uint id, const QString &action);
+ void notificationClosed(uint id, uint reason);
private:
void setStatus(const QString &status);
@@ -136,6 +139,7 @@ private:
QStatusNotifierItemAdaptor *m_adaptor;
QDBusMenuAdaptor *m_menuAdaptor;
QDBusPlatformMenu *m_menu;
+ QXdgNotificationInterface *m_notifier;
QString m_instanceId;
QString m_category;
QString m_defaultStatus;
diff --git a/src/platformsupport/dbustray/qxdgnotificationproxy.cpp b/src/platformsupport/dbustray/qxdgnotificationproxy.cpp
new file mode 100644
index 0000000000..a6b623a9e1
--- /dev/null
+++ b/src/platformsupport/dbustray/qxdgnotificationproxy.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $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/platformsupport/dbustray/qxdgnotificationproxy_p.h b/src/platformsupport/dbustray/qxdgnotificationproxy_p.h
new file mode 100644
index 0000000000..2a2a41d8ce
--- /dev/null
+++ b/src/platformsupport/dbustray/qxdgnotificationproxy_p.h
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $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
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#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 = 0);
+
+ ~QXdgNotificationInterface();
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<> closeNotification(uint id)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(id);
+ return asyncCallWithArgumentList(QStringLiteral("CloseNotification"), argumentList);
+ }
+
+ inline QDBusPendingReply<QStringList> getCapabilities()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QStringLiteral("GetCapabilities"), argumentList);
+ }
+
+ inline QDBusPendingReply<QString, QString, QString, QString> getServerInformation()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QStringLiteral("GetServerInformation"), argumentList);
+ }
+ inline QDBusReply<QString> getServerInformation(QString &vendor, QString &version, QString &specVersion)
+ {
+ QList<QVariant> argumentList;
+ QDBusMessage reply = callWithArgumentList(QDBus::Block, QStringLiteral("GetServerInformation"), argumentList);
+ 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;
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(appName) << QVariant::fromValue(replacesId) <<
+ QVariant::fromValue(appIcon) << QVariant::fromValue(summary) <<
+ QVariant::fromValue(body) << QVariant::fromValue(actions) <<
+ QVariant::fromValue(hints) << QVariant::fromValue(timeout);
+ return asyncCallWithArgumentList(QStringLiteral("Notify"), argumentList);
+ }
+
+Q_SIGNALS:
+ void ActionInvoked(uint id, const QString &action_key);
+ void NotificationClosed(uint id, uint reason);
+};
+
+namespace org {
+ namespace freedesktop {
+ typedef ::QXdgNotificationInterface Notifications;
+ }
+}
+
+QT_END_NAMESPACE
+
+#endif