Fix keysequence strings for Mac again
[quassel.git] / src / qtui / legacysystemtray.cpp
index 18bf02c..d58d1d4 100644 (file)
 #ifndef QT_NO_SYSTEMTRAYICON
 
 #include "legacysystemtray.h"
+#include "mainwin.h"
 #include "qtui.h"
 
 LegacySystemTray::LegacySystemTray(QWidget *parent)
   : SystemTray(parent),
   _blinkState(false),
-  _isVisible(true)
+  _lastMessageId(0)
 {
 #ifndef HAVE_KDE
   _trayIcon = new QSystemTrayIcon(associatedWidget());
@@ -41,14 +42,13 @@ LegacySystemTray::LegacySystemTray(QWidget *parent)
                      SLOT(on_activated(QSystemTrayIcon::ActivationReason)));
 #endif
   connect(_trayIcon, SIGNAL(messageClicked()),
-                     SIGNAL(messageClicked()));
-
-  setTrayMenu(_trayIcon->contextMenu());
-  _trayIcon->setContextMenu(trayMenu());
+                     SLOT(on_messageClicked()));
 
   _blinkTimer.setInterval(500);
   _blinkTimer.setSingleShot(false);
   connect(&_blinkTimer, SIGNAL(timeout()), SLOT(on_blinkTimeout()));
+
+  connect(this, SIGNAL(toolTipChanged(QString,QString)), SLOT(syncLegacyIcon()));
 }
 
 void LegacySystemTray::init() {
@@ -56,17 +56,30 @@ void LegacySystemTray::init() {
     setMode(Legacy);
 
   SystemTray::init();
+
+  _trayIcon->setContextMenu(trayMenu());
 }
 
 void LegacySystemTray::syncLegacyIcon() {
   _trayIcon->setIcon(stateIcon());
-  _trayIcon->setToolTip(toolTipTitle());
+
+#if defined Q_WS_MAC || defined Q_WS_WIN
+  QString tooltip = QString("%1").arg(toolTipTitle());
+  if(!toolTipSubTitle().isEmpty())
+    tooltip += QString("\n%1").arg(toolTipSubTitle());
+#else
+  QString tooltip = QString("<b>%1</b>").arg(toolTipTitle());
+  if(!toolTipSubTitle().isEmpty())
+    tooltip += QString("<br>%1").arg(toolTipSubTitle());
+#endif
+
+  _trayIcon->setToolTip(tooltip);
 }
 
 void LegacySystemTray::setVisible(bool visible) {
-  _isVisible = visible;
+  SystemTray::setVisible(visible);
   if(mode() == Legacy) {
-    if(visible)
+    if(shouldBeVisible())
       _trayIcon->show();
     else
       _trayIcon->hide();
@@ -77,7 +90,7 @@ bool LegacySystemTray::isVisible() const {
   if(mode() == Legacy) {
     return _trayIcon->isVisible();
   }
-  return false;
+  return SystemTray::isVisible();
 }
 
 void LegacySystemTray::setMode(Mode mode_) {
@@ -85,8 +98,10 @@ void LegacySystemTray::setMode(Mode mode_) {
 
   if(mode() == Legacy) {
     syncLegacyIcon();
-    if(_isVisible)
+    if(shouldBeVisible())
       _trayIcon->show();
+    else
+      _trayIcon->hide();
     if(state() == NeedsAttention)
       _blinkTimer.start();
   } else {
@@ -99,7 +114,7 @@ void LegacySystemTray::setState(State state_) {
   State oldstate = state();
   SystemTray::setState(state_);
   if(oldstate != state()) {
-    if(state() == NeedsAttention && mode() == Legacy)
+    if(state() == NeedsAttention && mode() == Legacy && animationEnabled())
       _blinkTimer.start();
     else {
       _blinkTimer.stop();
@@ -125,8 +140,24 @@ void LegacySystemTray::on_activated(QSystemTrayIcon::ActivationReason reason) {
   activate((SystemTray::ActivationReason)reason);
 }
 
-void LegacySystemTray::showMessage(const QString &title, const QString &message, SystemTray::MessageIcon icon, int millisecondsTimeoutHint) {
-  _trayIcon->showMessage(title, message, (QSystemTrayIcon::MessageIcon)icon, millisecondsTimeoutHint);
+void LegacySystemTray::on_messageClicked() {
+  emit messageClicked(_lastMessageId);
+}
+
+void LegacySystemTray::showMessage(const QString &title, const QString &message, SystemTray::MessageIcon icon, int msTimeout, uint id) {
+  // fancy stuff later: show messages in order
+  // for now, we just show the last message
+  _lastMessageId = id;
+  _trayIcon->showMessage(title, message, (QSystemTrayIcon::MessageIcon)icon, msTimeout);
+}
+
+void LegacySystemTray::closeMessage(uint notificationId) {
+  Q_UNUSED(notificationId)
+
+  // there really seems to be no sane way to close the bubble... :(
+#ifdef Q_WS_X11
+  showMessage("", "", NoIcon, 1);
+#endif
 }
 
 #endif /* QT_NO_SYSTEMTRAYICON */