From 1f475fb7ed3247294f5c60d5865683e982a4fe3c Mon Sep 17 00:00:00 2001
From: Dennis Schridde <devurandom@gna.org>
Date: Mon, 19 May 2008 15:27:52 +0200
Subject: [PATCH] Intial support for the org.freedesktop.Notifications DBus interface (very basic).

---
 build/targets/mono.pri     |    2 +-
 build/targets/qtclient.pri |    2 +-
 src/qtui/mainwin.cpp       |   36 +++++++++++++++++++++++++++++++++---
 src/qtui/mainwin.h         |    3 ++-
 4 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/build/targets/mono.pri b/build/targets/mono.pri
index de74d3d..3805ffd 100644
--- a/build/targets/mono.pri
+++ b/build/targets/mono.pri
@@ -4,4 +4,4 @@ TARGET  = quassel
 MODULES = core qtui uisupport client common
 DEFINES = BUILD_MONO
 
-QT += network sql script
+QT += network sql script dbus
diff --git a/build/targets/qtclient.pri b/build/targets/qtclient.pri
index 9ae0b45..cd0a3e5 100644
--- a/build/targets/qtclient.pri
+++ b/build/targets/qtclient.pri
@@ -4,6 +4,6 @@ TARGET  = quasselclient
 MODULES = qtui uisupport client common
 DEFINES = BUILD_QTUI
 
-QT += network script
+QT += network script dbus
 
 #RESOURCES *= ../../src/icons/icons.qrc
diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp
index 64d4fd7..78c408a 100644
--- a/src/qtui/mainwin.cpp
+++ b/src/qtui/mainwin.cpp
@@ -60,6 +60,8 @@
 #include "global.h"
 #include "qtuistyle.h"
 
+#include <Qt/QtDBus>
+
 
 MainWin::MainWin(QtUi *_gui, QWidget *parent)
   : QMainWindow(parent),
@@ -218,7 +220,7 @@ void MainWin::removeBufferView(int bufferViewConfigId) {
     actionData = action->data();
     if(!actionData.isValid())
       continue;
-    
+
     if(actionData.toString() == "__EOBV__")
       break;
 
@@ -404,7 +406,7 @@ void MainWin::connectedToCore() {
   connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
   connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
   connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
-  
+
   foreach(BufferInfo id, Client::allBufferInfos()) {
     Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
   }
@@ -454,7 +456,7 @@ void MainWin::disconnectedFromCore() {
     actionData = action->data();
     if(!actionData.isValid())
       continue;
-    
+
     if(actionData.toString() == "__EOBV__")
       break;
 
@@ -572,6 +574,7 @@ void MainWin::receiveMessage(const Message &msg) {
       // FIXME don't invoke style engine for this!
       QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText;
       displayTrayIconMessage(title, text);
+	  sendDesktopNotification(title, text);
     }
 #endif
     if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
@@ -587,6 +590,33 @@ bool MainWin::event(QEvent *event) {
   return QMainWindow::event(event);
 }
 
+
+/*
+Using the notification-daemon from Freedesktop's Galago project
+http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
+*/
+void MainWin::sendDesktopNotification(const QString &title, const QString &message)
+{
+	QStringList actions;
+	QMap<QString, QVariant> 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
+
+	(void)QDBusConnection::sessionBus().call(msg); // Would return a message containing the id of this notification
+}
+
+
 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
   systray->showMessage(title, message);
 }
diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h
index e2e703f..6d1752f 100644
--- a/src/qtui/mainwin.h
+++ b/src/qtui/mainwin.h
@@ -53,6 +53,7 @@ class MainWin : public QMainWindow {
     void addBufferView(BufferViewConfig *config = 0);
 
     void displayTrayIconMessage(const QString &title, const QString &message);
+    void sendDesktopNotification(const QString &title, const QString &message);
 
     virtual bool event(QEvent *event);
 
@@ -95,7 +96,7 @@ class MainWin : public QMainWindow {
 
     void loadLayout();
     void saveLayout();
-  
+
   signals:
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
-- 
1.5.5.1

