X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fknotificationbackend.cpp;h=addba9433eefb430da0341de394368981592a51f;hb=860dfc7ed65d6810cd759b1f92c2c18616c02393;hp=8cc58a9a0a0c3ab5bac69b9b8d03efa200f68992;hpb=6e85a37d1b7d3501f0fd7cc94fd0fcd4ba0c6cc4;p=quassel.git
diff --git a/src/qtui/knotificationbackend.cpp b/src/qtui/knotificationbackend.cpp
index 8cc58a9a..addba943 100644
--- a/src/qtui/knotificationbackend.cpp
+++ b/src/qtui/knotificationbackend.cpp
@@ -33,25 +33,44 @@
#include "qtui.h"
#include "systemtray.h"
-KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
-
+KNotificationBackend::KNotificationBackend(QObject *parent)
+: AbstractNotificationBackend(parent),
+ _lastNotificationId(0)
+{
+ connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ SLOT(notificationActivated(QSystemTrayIcon::ActivationReason)));
}
void KNotificationBackend::notify(const Notification &n) {
QString message = QString("<%1> %2").arg(n.sender, Qt::escape(n.message));
KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
- KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated);
+ KNotification::RaiseWidgetOnActivation
+ |KNotification::CloseWhenWidgetActivated
+ |KNotification::CloseOnTimeout);
connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
connect(notification, SIGNAL(closed()), SLOT(notificationClosed()));
notification->setActions(QStringList("View"));
- _notificationIds[notification] = n.notificationId;
+ _notificationIds[notification] = _lastNotificationId = n.notificationId;
QtUi::mainWindow()->systemTray()->setAlert(true);
}
+void KNotificationBackend::removeNotificationById(uint notificationId) {
+ QHash::iterator i = _notificationIds.begin();
+ while(i != _notificationIds.end()) {
+ if(i.value() == notificationId)
+ i = _notificationIds.erase(i);
+ else
+ ++i;
+ }
+ if(_lastNotificationId == notificationId)
+ _lastNotificationId = 0;
+}
+
void KNotificationBackend::close(uint notificationId) {
- Q_UNUSED(notificationId);
- QtUi::mainWindow()->systemTray()->setAlert(false);
+ removeNotificationById(notificationId);
+ if(!_notificationIds.count())
+ QtUi::mainWindow()->systemTray()->setAlert(false);
}
void KNotificationBackend::notificationActivated() {
@@ -60,13 +79,30 @@ void KNotificationBackend::notificationActivated() {
if(n && _notificationIds.contains(n))
id = _notificationIds.value(n);
- emit activated(id);
+ notificationActivated(id);
+}
+
+void KNotificationBackend::notificationActivated(QSystemTrayIcon::ActivationReason reason) {
+ if(reason == QSystemTrayIcon::Trigger && _lastNotificationId > 0) {
+ notificationActivated(_lastNotificationId); // most recent one
+ }
+}
+
+void KNotificationBackend::notificationActivated(uint notificationId) {
+ removeNotificationById(notificationId);
+
+ QtUi::mainWindow()->systemTray()->setInhibitActivation();
+ emit activated(notificationId);
+
+ if(!_notificationIds.count())
+ QtUi::mainWindow()->systemTray()->setAlert(false);
+
}
void KNotificationBackend::notificationClosed() {
- KNotification *n = qobject_cast(sender());
- if(n && _notificationIds.contains(n))
- _notificationIds.remove(n);
+ //KNotification *n = qobject_cast(sender());
+ //if(n && _notificationIds.contains(n))
+ // _notificationIds.remove(n);
}
SettingsPage *KNotificationBackend::createConfigWidget() const {