Introduce a notification type and add extra notifications for KNotify
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Apr 2009 08:15:31 +0000 (10:15 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Apr 2009 08:15:31 +0000 (10:15 +0200)
We have 4 types of notifications now: for queries and for highlights,
each with and without Quassel having focus. If using KDE support, each
can now be configured separately (see #571).

The non-KDE notification backends keep the old behavior (i.e. only notify if not
focused) for now, until we get a configuration UI for this.

data/quassel.notifyrc
src/qtui/desktopnotificationbackend.cpp
src/qtui/knotificationbackend.cpp
src/qtui/mainwin.cpp
src/qtui/phononnotificationbackend.cpp
src/qtui/qtui.cpp
src/qtui/qtui.h
src/qtui/systraynotificationbackend.cpp
src/qtui/taskbarnotificationbackend.cpp
src/uisupport/abstractnotificationbackend.h

index 32a4a2d..84ffe2f 100644 (file)
@@ -8,3 +8,20 @@ Comment=A highlighted message has arrived
 Sound=KDE-Im-Highlight-Msg.ogg
 Action=Sound|Popup|Taskbar
 
+[Event/HighlightFocused]
+Name=Highlight when focused
+Comment=A highlighted message has arrived while Quassel is focused
+Sound=KDE-Im-Highlight-Msg.ogg
+Action=Taskbar
+
+[Event/PrivMsg]
+Name=Private Message
+Comment=A private message (query) has arrived
+Sound=KDE-Im-Message-In.ogg
+Action=Sound|Popup|Taskbar
+
+[Event/PrivMsgFocused]
+Name=Private message when focused
+Comment=A private message (query) has arrived while Quassel is focused
+Sound=KDE-Im-Message-In.ogg
+Action=Taskbar
index a703f6a..1f633d3 100644 (file)
@@ -88,7 +88,7 @@ void DesktopNotificationBackend::useTimeoutChanged(const QVariant &v) {
 }
 
 void DesktopNotificationBackend::notify(const Notification &n) {
-  if(_enabled) {
+  if(_enabled && (n.type == Highlight || n.type == PrivMsg)) {
     QStringList actions;
     QMap<QString, QVariant> hints;
 
index fda674d..99d52f8 100644 (file)
@@ -37,9 +37,20 @@ KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificati
 }
 
 void KNotificationBackend::notify(const Notification &n) {
-  //QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
+  QString type;
+  switch(n.type) {
+    case Highlight:
+      type = "Highlight"; break;
+    case HighlightFocused:
+      type = "HighlightFocused"; break;
+    case PrivMsg:
+      type = "PrivMsg"; break;
+    case PrivMsgFocused:
+      type = "PrivMsgFocused"; break;
+  }
+
   QString message = QString("<b>&lt;%1&gt;</b> %2").arg(n.sender, n.message);
-  KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
+  KNotification *notification = KNotification::event(type, message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
                                 KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated);
   connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
   connect(notification, SIGNAL(closed()), SLOT(notificationClosed()));
index 258a9c0..5df3a19 100644 (file)
@@ -828,8 +828,7 @@ void MainWin::toggleMinimizedToTray() {
 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
   Q_UNUSED(parent);
 
-  if(QApplication::activeWindow() != 0)
-    return;
+  bool hasFocus = QApplication::activeWindow() != 0;
 
   for(int i = start; i <= end; i++) {
     QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
@@ -838,18 +837,33 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
       continue;
     }
     Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
-    if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self)) continue;
+    if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
+      continue;
     flags |= Message::Backlog;  // we only want to trigger a highlight once!
     Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
 
     BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
     BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
 
+    if(hasFocus && bufId == _bufferWidget->currentBuffer())
+      continue;
+
     if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
       QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
       QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
       QString contents = idx.data(ChatLineModel::DisplayRole).toString();
-      QtUi::invokeNotification(bufId, sender, contents);
+      AbstractNotificationBackend::NotificationType type;
+
+      if(bufType == BufferInfo::QueryBuffer && !hasFocus)
+        type = AbstractNotificationBackend::PrivMsg;
+      else if(bufType == BufferInfo::QueryBuffer && hasFocus)
+        type = AbstractNotificationBackend::PrivMsgFocused;
+      else if(flags & Message::Highlight && !hasFocus)
+        type = AbstractNotificationBackend::Highlight;
+      else
+        type = AbstractNotificationBackend::HighlightFocused;
+
+      QtUi::invokeNotification(bufId, type, sender, contents);
     }
   }
 }
index 48d1fdb..3f029bf 100644 (file)
@@ -47,8 +47,7 @@ PhononNotificationBackend::~PhononNotificationBackend() {
 }
 
 void PhononNotificationBackend::notify(const Notification &notification) {
-  Q_UNUSED(notification)
-  if(_enabled && _media) {
+  if(_enabled && _media && (notification.type == Highlight || notification.type == PrivMsg)) {
     _media->play();
   }
 }
index 02b6615..8a38005 100644 (file)
@@ -109,10 +109,10 @@ const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
   return _notificationBackends;
 }
 
-uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
+uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text) {
   static int notificationId = 0;
   //notificationId++;
-  AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
+  AbstractNotificationBackend::Notification notification(++notificationId, bufId, type, sender, text);
   _notifications.append(notification);
   foreach(AbstractNotificationBackend *backend, _notificationBackends)
     backend->notify(notification);
index 5885210..7ef22e0 100644 (file)
@@ -49,14 +49,13 @@ public:
   inline static QtUiStyle *style();
   inline static MainWin *mainWindow();
 
-
   /* Notifications */
 
   static void registerNotificationBackend(AbstractNotificationBackend *);
   static void unregisterNotificationBackend(AbstractNotificationBackend *);
   static void unregisterAllNotificationBackends();
   static const QList<AbstractNotificationBackend *> &notificationBackends();
-  static uint invokeNotification(BufferId bufId, const QString &sender, const QString &text);
+  static uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text);
   static void closeNotification(uint notificationId);
   static void closeNotifications(BufferId bufferId = BufferId());
   static const QList<AbstractNotificationBackend::Notification> &activeNotifications();
index 6b67b20..545c22d 100644 (file)
@@ -44,6 +44,9 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
 }
 
 void SystrayNotificationBackend::notify(const Notification &notification) {
+  if(notification.type != Highlight && notification.type != PrivMsg)
+    return;
+
   /* fancy stuff to be implemented later: show notifications in order
   _notifications.append(notification);
   if(_showBubble && _notifications.count() == 1) {
index 9fda55b..9606012 100644 (file)
@@ -38,8 +38,7 @@ TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent)
 }
 
 void TaskbarNotificationBackend::notify(const Notification &notification) {
-  Q_UNUSED(notification)
-  if(_enabled) {
+  if(_enabled && (notification.type == Highlight || notification.type == PrivMsg)) {
     QApplication::alert(QtUi::mainWindow(), _timeout);
   }
 }
index 01324d4..3685da2 100644 (file)
@@ -32,14 +32,22 @@ class AbstractNotificationBackend : public QObject {
   Q_OBJECT
 
 public:
+  enum NotificationType {
+    Highlight = 0x01,
+    PrivMsg = 0x02,
+    HighlightFocused = 0x11,
+    PrivMsgFocused = 0x12
+  };
+
   struct Notification {
     uint notificationId;
     BufferId bufferId;
+    NotificationType type;
     QString sender;
     QString message;
 
-    Notification(uint id_, BufferId buf_, const QString &sender_, const QString &msg_)
-      : notificationId(id_), bufferId(buf_), sender(sender_), message(msg_) {};
+    Notification(uint id_, BufferId buf_, NotificationType type_, const QString &sender_, const QString &msg_)
+      : notificationId(id_), bufferId(buf_), type(type_), sender(sender_), message(msg_) {};
   };
 
   inline AbstractNotificationBackend(QObject *parent) : QObject(parent) {};