Notification backends now can emit a signal activated() that tells MainWin to raise...
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 5 Jan 2009 13:00:20 +0000 (14:00 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 5 Jan 2009 13:04:30 +0000 (14:04 +0100)
For now, this signal is emitted by systray, dbus and knotify. Unfortunately, raise() does not seem
to work with kwin and (according to docs) neither on Windows. Furthermore, my knotify seems
to be broken and doesn't signal a click at all. Thus, this whole thing got "limited" testing by me :)

Take it as "might work under some circumstances in some environments". Feedback welcome.

src/qtui/desktopnotificationbackend.cpp
src/qtui/knotificationbackend.cpp
src/qtui/knotificationbackend.h
src/qtui/mainwin.cpp
src/qtui/qtui.cpp
src/qtui/qtui.h
src/qtui/systraynotificationbackend.cpp
src/uisupport/abstractnotificationbackend.h

index e959f52..f174217 100644 (file)
@@ -148,6 +148,7 @@ void DesktopNotificationBackend::desktopNotificationClosed(uint id, uint reason)
 
 void DesktopNotificationBackend::desktopNotificationInvoked(uint id, const QString & action) {
   Q_UNUSED(id); Q_UNUSED(action);
+  emit activated();
 }
 
 SettingsPage *DesktopNotificationBackend::createConfigWidget() const {
index c55bf31..baf0f15 100644 (file)
@@ -38,14 +38,19 @@ KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificati
 void KNotificationBackend::notify(const Notification &n) {
   //QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
   QString message = QString("<b>&lt;%1&gt;</b> %2").arg(n.sender, n.message);
-  KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
-                        KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated);
+  KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
+                                KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated);
+  connect(notification, SIGNAL(activated()), SLOT(notificationActivated()));
 }
 
 void KNotificationBackend::close(uint notificationId) {
   Q_UNUSED(notificationId);
 }
 
+void KNotificationBackend::notificationActivated() {
+  emit activated();
+}
+
 SettingsPage *KNotificationBackend::createConfigWidget() const {
   return new ConfigWidget();
 }
index 706478e..98c42d9 100644 (file)
@@ -37,6 +37,9 @@ public:
   void close(uint notificationId);
   virtual SettingsPage *createConfigWidget() const;
 
+private slots:
+  void notificationActivated();
+
 private:
   class ConfigWidget;
 };
index 01fb3b7..e7205af 100644 (file)
@@ -116,20 +116,6 @@ MainWin::MainWin(QWidget *parent)
 
   installEventFilter(new JumpKeyHandler(this));
 
-#ifndef HAVE_KDE
-    QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
-    QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
-#  ifdef HAVE_PHONON
-    QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
-#  endif
-#  ifdef HAVE_DBUS
-    QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
-#  endif
-
-#else /* HAVE_KDE */
-    QtUi::registerNotificationBackend(new KNotificationBackend(this));
-#endif /* HAVE_KDE */
-
   QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
   connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
   connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
@@ -166,6 +152,20 @@ void MainWin::init() {
   setupSystray();
   setupTitleSetter();
 
+#ifndef HAVE_KDE
+  QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
+  QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
+#  ifdef HAVE_PHONON
+  QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
+#  endif
+#  ifdef HAVE_DBUS
+  QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
+#  endif
+
+#else /* HAVE_KDE */
+  QtUi::registerNotificationBackend(new KNotificationBackend(this));
+#endif /* HAVE_KDE */
+
   // restore mainwin state
   restoreState(s.value("MainWinState").toByteArray());
 
index 1b513a7..231bbf4 100644 (file)
 #include "util.h"
 
 QHash<QString, ActionCollection *> QtUi::_actionCollections;
+QPointer<QtUi> QtUi::_instance = 0;
 QPointer<MainWin> QtUi::_mainWin = 0;
 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
 QtUiStyle *QtUi::_style = 0;
 
 QtUi::QtUi() : AbstractUi() {
-  if(_style != 0) {
+  if(_instance != 0) {
     qWarning() << "QtUi has been instantiated again!";
     return;
   }
+  _instance = this;
 
   _actionProvider = new NetworkModelActionProvider(this);
 
@@ -93,6 +95,7 @@ void QtUi::disconnectedFromCore() {
 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
   if(!_notificationBackends.contains(backend)) {
     _notificationBackends.append(backend);
+    instance()->connect(backend, SIGNAL(activated()), SLOT(notificationActivated()));
   }
 }
 
@@ -147,3 +150,8 @@ const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotification
   return _notifications;
 }
 
+void QtUi::notificationActivated() {
+  // this might not work with some window managers
+  _mainWin->raise();
+  _mainWin->activateWindow();
+}
index 9a00ef4..af267ca 100644 (file)
@@ -46,6 +46,7 @@ public:
   MessageModel *createMessageModel(QObject *parent);
   AbstractMessageProcessor *createMessageProcessor(QObject *parent);
 
+  inline static QtUi *instance();
   inline static QtUiStyle *style();
   inline static MainWin *mainWindow();
 
@@ -75,10 +76,12 @@ public slots:
 protected slots:
   void connectedToCore();
   void disconnectedFromCore();
+  void notificationActivated();
 
 private:
   AbstractActionProvider *_actionProvider;
 
+  static QPointer<QtUi> _instance;
   static QPointer<MainWin> _mainWin;
   static QHash<QString, ActionCollection *> _actionCollections;
   static QtUiStyle *_style;
@@ -86,6 +89,7 @@ private:
   static QList<AbstractNotificationBackend::Notification> _notifications;
 };
 
+QtUi *QtUi::instance() { return _instance ? _instance.data() : new QtUi(); }
 QtUiStyle *QtUi::style() { return _style; }
 MainWin *QtUi::mainWindow() { return _mainWin; }
 AbstractActionProvider *QtUi::actionProvider() const { return _actionProvider; }
index e992980..f761e25 100644 (file)
@@ -41,6 +41,7 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
 
   _iconActive = false;
   connect(&_animationTimer, SIGNAL(timeout()), SLOT(blink()));
+  connect(QtUi::mainWindow()->systemTrayIcon(), SIGNAL(messageClicked()), this, SIGNAL(activated()));
 }
 
 void SystrayNotificationBackend::notify(const Notification &notification) {
index 982855f..8e95c91 100644 (file)
@@ -54,6 +54,11 @@ public:
    * In case you need to communicate with the configWidget directly, make your connections here
    */
   virtual SettingsPage *createConfigWidget() const = 0;
+
+signals:
+  //! May be emitted by the notification to tell the MainWin to raise itself
+  void activated();
+
 };
 
 #endif