From: Dennis Schridde Date: Wed, 21 May 2008 13:03:29 +0000 (+0200) Subject: Improved support for org.freedesktop.Notifications. X-Git-Tag: 0.3.0~237 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=85c2a2a853e4f4d4488344672d47c2aa77172f69;hp=cd3dc8132fa88bd81e8aa2c9947d3540e1f56f37 Improved support for org.freedesktop.Notifications. Add a DesktopNotifications class derived from QDBusAbstractInterface, to be able to call the interface more conveniently. Replace notifications if possible, instead of spamming new ones. React on NotificationClosed signals to properly decide which replace_id to use. Add a dummy button for demonstration to the notification. --- diff --git a/src/client/desktopnotifications.cpp b/src/client/desktopnotifications.cpp new file mode 100644 index 00000000..ddbc7529 --- /dev/null +++ b/src/client/desktopnotifications.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by dbusxml2cpp version 0.6 + * Command line was: dbusxml2cpp -p desktopnotifications org.freedesktop.Notifications.xml + * + * dbusxml2cpp is Copyright (C) 2006 Trolltech ASA. All rights reserved. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "desktopnotifications.h" + +/* + * Implementation of interface class OrgFreedesktopNotificationsInterface + */ + +OrgFreedesktopNotificationsInterface::OrgFreedesktopNotificationsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNotificationsInterface::~OrgFreedesktopNotificationsInterface() +{ +} + diff --git a/src/client/desktopnotifications.h b/src/client/desktopnotifications.h new file mode 100644 index 00000000..ec26b5fe --- /dev/null +++ b/src/client/desktopnotifications.h @@ -0,0 +1,80 @@ +/* + * This file was generated by dbusxml2cpp version 0.6 + * Command line was: dbusxml2cpp -p desktopnotifications org.freedesktop.Notifications.xml + * + * dbusxml2cpp is Copyright (C) 2006 Trolltech ASA. All rights reserved. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DESKTOPNOTIFICATIONS_H_1211193208 +#define DESKTOPNOTIFICATIONS_H_1211193208 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.Notifications + */ +class OrgFreedesktopNotificationsInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.freedesktop.Notifications"; } + +public: + OrgFreedesktopNotificationsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~OrgFreedesktopNotificationsInterface(); + +public Q_SLOTS: // METHODS + inline QDBusReply CloseNotification(uint id) + { + QList argumentList; + argumentList << qVariantFromValue(id); + return callWithArgumentList(QDBus::Block, QLatin1String("CloseNotification"), argumentList); + } + + inline QDBusReply GetCapabilities() + { + QList argumentList; + return callWithArgumentList(QDBus::Block, QLatin1String("GetCapabilities"), argumentList); + } + + inline QDBusReply GetServerInformation(QString &vendor, QString &version) + { + QList argumentList; + QDBusMessage reply = callWithArgumentList(QDBus::Block, QLatin1String("GetServerInformation"), argumentList); + if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 3) { + vendor = qdbus_cast(reply.arguments().at(1)); + version = qdbus_cast(reply.arguments().at(2)); + } + return reply; + } + + inline QDBusReply Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout) + { + QList argumentList; + argumentList << qVariantFromValue(app_name) << qVariantFromValue(replaces_id) << qVariantFromValue(app_icon) << qVariantFromValue(summary) << qVariantFromValue(body) << qVariantFromValue(actions) << qVariantFromValue(hints) << qVariantFromValue(expire_timeout); + return callWithArgumentList(QDBus::Block, QLatin1String("Notify"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void ActionInvoked(uint id, const QString &action); + void NotificationClosed(uint id, uint reason); +}; + +namespace org { + namespace freedesktop { + typedef ::OrgFreedesktopNotificationsInterface Notifications; + } +} +#endif diff --git a/src/client/org.freedesktop.Notifications.xml b/src/client/org.freedesktop.Notifications.xml new file mode 100644 index 00000000..0827cba1 --- /dev/null +++ b/src/client/org.freedesktop.Notifications.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 4c3f16b4..abeeb488 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -65,7 +65,7 @@ #include "global.h" #include "qtuistyle.h" -#include +#include "desktopnotifications.h" MainWin::MainWin(QtUi *_gui, QWidget *parent) @@ -82,7 +82,12 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) timer(new QTimer(this)), channelListDlg(new ChannelListDlg(this)), settingsDlg(new SettingsDlg(this)), - debugConsole(new DebugConsole(this)) + debugConsole(new DebugConsole(this)), + desktopNotifications(new org::freedesktop::Notifications( + "org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this)), + notificationId(0) { UiSettings uiSettings; loadTranslation(uiSettings.value("Locale", QLocale::system()).value()); @@ -103,6 +108,14 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) installEventFilter(new JumpKeyHandler(this)); + UiSettings uiSettings; + QString style = uiSettings.value("Style", QString("")).toString(); + if(style != "") { + QApplication::setStyle(style); + } + + connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint))); + connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&))); } void MainWin::init() { @@ -625,21 +638,46 @@ void MainWin::sendDesktopNotification(const QString &title, const QString &messa { QStringList actions; QMap hints; - QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify"); hints["x"] = 100; // Standard hint: x location for the popup to show up hints["y"] = 100; // Standard hint: y location for the popup to show up - msg << "Quassel"; // Application name - msg << quint32(0); // ID of previous notification to replace - msg << ""; // Icon to display - msg << "Quassel: " + title; // Summary / Header of the message to display - msg << message; // Body of the message to display - msg << actions; // Actions from which the user may choose - msg << hints; // Hints to the server displaying the message - msg << qint32(10000); // Timeout in milliseconds + actions << "click" << "Click Me!"; + + QDBusReply reply = desktopNotifications->Notify( + "Quassel", // Application name + notificationId, // ID of previous notification to replace + "", // Icon to display + title, // Summary / Header of the message to display + QString("%1: %2:\n%2").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display + actions, // Actions from which the user may choose + hints, // Hints to the server displaying the message + 5000 // Timeout in milliseconds + ); + + if (!reply.isValid()) + { + /* ERROR */ + qDebug() << "Error on sending notification..."; + return; + } + + notificationId = reply.value(); - (void)QDBusConnection::sessionBus().call(msg); // Would return a message containing the id of this notification + qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); +} + + +void MainWin::desktopNotificationClosed(uint id, uint reason) +{ + qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString(); + notificationId = 0; +} + + +void MainWin::desktopNotificationInvoked(uint id, const QString & action) +{ + qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); } diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 0abcf56c..9787832c 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -41,6 +41,7 @@ class Message; class NickListWidget; class DebugConsole; +#include "desktopnotifications.h" //!\brief The main window of Quassel's QtUi. class MainWin : public QMainWindow { @@ -102,6 +103,9 @@ class MainWin : public QMainWindow { void loadLayout(); void saveLayout(); + void desktopNotificationClosed(uint id, uint reason); + void desktopNotificationInvoked(uint id, const QString & action); + signals: void connectToCore(const QVariantMap &connInfo); void disconnectFromCore(); @@ -150,6 +154,9 @@ class MainWin : public QMainWindow { QList _netViews; NickListWidget *nickListWidget; + org::freedesktop::Notifications *desktopNotifications; + quint32 notificationId; + friend class QtUi; };