X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=2ae203d9aaba1e1ccfc0746c8563917df5f5f21f;hp=4c3f16b4181e42e22934892119aca15d004ae704;hb=d3f60cb05a682113f75ff21beb1c7fcdf9a85b67;hpb=cd3dc8132fa88bd81e8aa2c9947d3540e1f56f37 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 4c3f16b4..2ae203d9 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -65,9 +65,6 @@ #include "global.h" #include "qtuistyle.h" -#include - - MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui), @@ -103,6 +100,21 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) installEventFilter(new JumpKeyHandler(this)); + UiSettings uiSettings; + QString style = uiSettings.value("Style", QString("")).toString(); + if(style != "") { + QApplication::setStyle(style); + } + +#ifdef HAVE_DBUS + desktopNotifications = new org::freedesktop::Notifications( + "org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this); + notificationId = 0; + connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint))); + connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&))); +#endif } void MainWin::init() { @@ -596,11 +608,15 @@ void MainWin::receiveMessage(const Message &msg) { UiSettings uiSettings; #ifndef SPUTDEV - if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) { + bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool(); + bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool(); + if(displayBubble || displayDesktop) { // FIXME don't invoke style engine for this! QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText; - displayTrayIconMessage(title, text); - sendDesktopNotification(title, text); + if(displayBubble) displayTrayIconMessage(title, text); +# ifdef HAVE_DBUS + if(displayDesktop) sendDesktopNotification(title, text); +# endif } #endif if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) { @@ -616,32 +632,56 @@ bool MainWin::event(QEvent *event) { return QMainWindow::event(event); } +#ifdef HAVE_DBUS /* 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 hints; - QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify"); +void MainWin::sendDesktopNotification(const QString &title, const QString &message) { + QStringList actions; + QMap hints; + UiSettings uiSettings; + + hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up + hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up + + 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%3").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 + uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds + ); + + if(!reply.isValid()) { + /* ERROR */ + qDebug() << "Error on sending notification..."; + return; + } + + notificationId = reply.value(); - 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 + 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; +} - 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::desktopNotificationInvoked(uint id, const QString & action) { + qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); } +#endif /* HAVE_DBUS */ void MainWin::displayTrayIconMessage(const QString &title, const QString &message) { systray->showMessage(title, message);