From: Manuel Nickschas Date: Sun, 12 Apr 2009 08:15:31 +0000 (+0200) Subject: Introduce a notification type and add extra notifications for KNotify X-Git-Tag: 0.5-rc1~225 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=9ea27e456f4163c37118f6dc34188809fc37d6d9 Introduce a notification type and add extra notifications for KNotify 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. --- diff --git a/data/quassel.notifyrc b/data/quassel.notifyrc index 32a4a2d8..84ffe2f0 100644 --- a/data/quassel.notifyrc +++ b/data/quassel.notifyrc @@ -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 diff --git a/src/qtui/desktopnotificationbackend.cpp b/src/qtui/desktopnotificationbackend.cpp index a703f6af..1f633d30 100644 --- a/src/qtui/desktopnotificationbackend.cpp +++ b/src/qtui/desktopnotificationbackend.cpp @@ -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 hints; diff --git a/src/qtui/knotificationbackend.cpp b/src/qtui/knotificationbackend.cpp index fda674d2..99d52f83 100644 --- a/src/qtui/knotificationbackend.cpp +++ b/src/qtui/knotificationbackend.cpp @@ -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("<%1> %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())); diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 258a9c0d..5df3a193 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -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(); 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); } } } diff --git a/src/qtui/phononnotificationbackend.cpp b/src/qtui/phononnotificationbackend.cpp index 48d1fdb5..3f029bfe 100644 --- a/src/qtui/phononnotificationbackend.cpp +++ b/src/qtui/phononnotificationbackend.cpp @@ -47,8 +47,7 @@ PhononNotificationBackend::~PhononNotificationBackend() { } void PhononNotificationBackend::notify(const Notification ¬ification) { - Q_UNUSED(notification) - if(_enabled && _media) { + if(_enabled && _media && (notification.type == Highlight || notification.type == PrivMsg)) { _media->play(); } } diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index 02b6615e..8a38005a 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -109,10 +109,10 @@ const QList &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); diff --git a/src/qtui/qtui.h b/src/qtui/qtui.h index 5885210a..7ef22e0d 100644 --- a/src/qtui/qtui.h +++ b/src/qtui/qtui.h @@ -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 ¬ificationBackends(); - 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 &activeNotifications(); diff --git a/src/qtui/systraynotificationbackend.cpp b/src/qtui/systraynotificationbackend.cpp index 6b67b202..545c22dd 100644 --- a/src/qtui/systraynotificationbackend.cpp +++ b/src/qtui/systraynotificationbackend.cpp @@ -44,6 +44,9 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent) } void SystrayNotificationBackend::notify(const Notification ¬ification) { + 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) { diff --git a/src/qtui/taskbarnotificationbackend.cpp b/src/qtui/taskbarnotificationbackend.cpp index 9fda55b6..96060128 100644 --- a/src/qtui/taskbarnotificationbackend.cpp +++ b/src/qtui/taskbarnotificationbackend.cpp @@ -38,8 +38,7 @@ TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent) } void TaskbarNotificationBackend::notify(const Notification ¬ification) { - Q_UNUSED(notification) - if(_enabled) { + if(_enabled && (notification.type == Highlight || notification.type == PrivMsg)) { QApplication::alert(QtUi::mainWindow(), _timeout); } } diff --git a/src/uisupport/abstractnotificationbackend.h b/src/uisupport/abstractnotificationbackend.h index 01324d40..3685da21 100644 --- a/src/uisupport/abstractnotificationbackend.h +++ b/src/uisupport/abstractnotificationbackend.h @@ -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) {};