Add a tooltip to the tray icon
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 23 Feb 2010 00:19:43 +0000 (01:19 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 23 Feb 2010 00:20:45 +0000 (01:20 +0100)
src/qtui/knotificationbackend.cpp
src/qtui/knotificationbackend.h
src/qtui/legacysystemtray.cpp
src/qtui/legacysystemtray.h
src/qtui/statusnotifieritem.cpp
src/qtui/systraynotificationbackend.cpp
src/qtui/systraynotificationbackend.h

index e261eac..7a8b2b0 100644 (file)
@@ -36,6 +36,8 @@ KNotificationBackend::KNotificationBackend(QObject *parent)
 {
   connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
                                             SLOT(notificationActivated(SystemTray::ActivationReason)));
+
+  updateToolTip();
 }
 
 void KNotificationBackend::notify(const Notification &n) {
@@ -62,6 +64,7 @@ void KNotificationBackend::notify(const Notification &n) {
 
   _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
 
+  updateToolTip();
   QtUi::mainWindow()->systemTray()->setAlert(true);
 }
 
@@ -75,6 +78,7 @@ void KNotificationBackend::removeNotificationById(uint notificationId) {
     } else
       ++i;
   }
+  updateToolTip();
 }
 
 void KNotificationBackend::close(uint notificationId) {
@@ -105,6 +109,11 @@ void KNotificationBackend::notificationActivated(uint notificationId) {
   emit activated(notificationId);
 }
 
+void KNotificationBackend::updateToolTip() {
+  QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
+                                               _notifications.count()? tr("%n pending highlights", "", _notifications.count()) : QString());
+}
+
 SettingsPage *KNotificationBackend::createConfigWidget() const {
   return new ConfigWidget();
 }
index 925f447..9a870f8 100644 (file)
@@ -47,6 +47,7 @@ private:
   class ConfigWidget;
 
   void removeNotificationById(uint id);
+  void updateToolTip();
 
   QList<QPair<uint, QPointer<KNotification> > > _notifications;
 };
index 9969800..3368b29 100644 (file)
@@ -46,6 +46,8 @@ LegacySystemTray::LegacySystemTray(QWidget *parent)
   _blinkTimer.setInterval(500);
   _blinkTimer.setSingleShot(false);
   connect(&_blinkTimer, SIGNAL(timeout()), SLOT(on_blinkTimeout()));
+
+  connect(this, SIGNAL(toolTipChanged(QString,QString)), SLOT(syncLegacyIcon()));
 }
 
 void LegacySystemTray::init() {
@@ -59,7 +61,11 @@ void LegacySystemTray::init() {
 
 void LegacySystemTray::syncLegacyIcon() {
   _trayIcon->setIcon(stateIcon());
-  _trayIcon->setToolTip(toolTipTitle());
+
+  QString tooltip = QString("<b>%1</b>").arg(toolTipTitle());
+  if(!toolTipSubTitle().isEmpty())
+    tooltip += QString("<br>%1").arg(toolTipSubTitle());
+  _trayIcon->setToolTip(tooltip);
 }
 
 void LegacySystemTray::setVisible(bool visible) {
index 47c5f11..07c1b1d 100644 (file)
@@ -59,9 +59,9 @@ private slots:
   void on_blinkTimeout();
   void on_activated(QSystemTrayIcon::ActivationReason);
 
-private:
   void syncLegacyIcon();
 
+private:
   QTimer _blinkTimer;
   bool _blinkState;
   bool _isVisible;
index 4df13dc..690ed9e 100644 (file)
@@ -50,6 +50,7 @@ void StatusNotifierItem::init() {
   qDBusRegisterMetaType<DBusToolTipStruct>();
 
   _statusNotifierItemDBus = new StatusNotifierItemDBus(this);
+  connect(this, SIGNAL(toolTipChanged(QString,QString)), _statusNotifierItemDBus, SIGNAL(NewToolTip()));
 
   connect(QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
                                                      SLOT(serviceChange(QString,QString,QString)));
index fa7b245..721ee07 100644 (file)
@@ -46,6 +46,8 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
                                             SLOT(notificationActivated(SystemTray::ActivationReason)));
 
   QApplication::instance()->installEventFilter(this);
+
+  updateToolTip();
 }
 
 void SystrayNotificationBackend::notify(const Notification &notification) {
@@ -58,6 +60,8 @@ void SystrayNotificationBackend::notify(const Notification &notification) {
 
   if(_animate)
     QtUi::mainWindow()->systemTray()->setAlert(true);
+
+  updateToolTip();
 }
 
 void SystrayNotificationBackend::close(uint notificationId) {
@@ -73,6 +77,8 @@ void SystrayNotificationBackend::close(uint notificationId) {
 
   if(!_notifications.count())
     QtUi::mainWindow()->systemTray()->setAlert(false);
+
+  updateToolTip();
 }
 
 void SystrayNotificationBackend::showBubble() {
@@ -126,6 +132,11 @@ void SystrayNotificationBackend::animateChanged(const QVariant &v) {
   _animate = v.toBool();
 }
 
+void SystrayNotificationBackend::updateToolTip() {
+  QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
+                                               _notifications.count()? tr("%n pending highlights", "", _notifications.count()) : QString());
+}
+
 SettingsPage *SystrayNotificationBackend::createConfigWidget() const {
   return new ConfigWidget();
 }
index 46591b3..4c8ff79 100644 (file)
@@ -48,6 +48,7 @@ private slots:
 
   void animateChanged(const QVariant &);
   void showBubbleChanged(const QVariant &);
+  void updateToolTip();
 
 private:
   class ConfigWidget;