Systray icon improvements
[quassel.git] / src / qtui / systraynotificationbackend.cpp
index 6b67b20..ec66bdd 100644 (file)
@@ -41,6 +41,8 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
   notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &)));
 
   connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), SLOT(notificationActivated()));
+  connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+                                            SLOT(notificationActivated(QSystemTrayIcon::ActivationReason)));
 }
 
 void SystrayNotificationBackend::notify(const Notification &notification) {
@@ -67,6 +69,7 @@ void SystrayNotificationBackend::close(uint notificationId) {
   if(_notifications.isEmpty()) {
   */
   _notifications.clear();
+  _activeId = 0;
   closeBubble();
   QtUi::mainWindow()->systemTray()->setAlert(false);
 }
@@ -74,7 +77,8 @@ void SystrayNotificationBackend::close(uint notificationId) {
 void SystrayNotificationBackend::showBubble() {
   // fancy stuff later: show messages in order
   // for now, we just show the last message
-  if(_notifications.isEmpty()) return;
+  if(_notifications.isEmpty())
+    return;
   Notification n = _notifications.takeLast();
   _activeId = n.notificationId;
   QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
@@ -90,7 +94,16 @@ void SystrayNotificationBackend::closeBubble() {
 }
 
 void SystrayNotificationBackend::notificationActivated() {
-  emit activated(_activeId);
+  if(QtUi::mainWindow()->systemTray()->isAlerted()) {
+    QtUi::mainWindow()->systemTray()->setInhibitActivation();
+    emit activated(_activeId);
+  }
+}
+
+void SystrayNotificationBackend::notificationActivated(QSystemTrayIcon::ActivationReason reason) {
+  if(reason == QSystemTrayIcon::Trigger) {
+    notificationActivated();
+  }
 }
 
 void SystrayNotificationBackend::showBubbleChanged(const QVariant &v) {