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.
void DesktopNotificationBackend::desktopNotificationInvoked(uint id, const QString & action) {
Q_UNUSED(id); Q_UNUSED(action);
+ emit activated();
}
SettingsPage *DesktopNotificationBackend::createConfigWidget() const {
void KNotificationBackend::notify(const Notification &n) {
//QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
QString message = QString("<b><%1></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();
}
void close(uint notificationId);
virtual SettingsPage *createConfigWidget() const;
+private slots:
+ void notificationActivated();
+
private:
class ConfigWidget;
};
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&)));
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());
#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);
void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
if(!_notificationBackends.contains(backend)) {
_notificationBackends.append(backend);
+ instance()->connect(backend, SIGNAL(activated()), SLOT(notificationActivated()));
}
}
return _notifications;
}
+void QtUi::notificationActivated() {
+ // this might not work with some window managers
+ _mainWin->raise();
+ _mainWin->activateWindow();
+}
MessageModel *createMessageModel(QObject *parent);
AbstractMessageProcessor *createMessageProcessor(QObject *parent);
+ inline static QtUi *instance();
inline static QtUiStyle *style();
inline static MainWin *mainWindow();
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;
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; }
_iconActive = false;
connect(&_animationTimer, SIGNAL(timeout()), SLOT(blink()));
+ connect(QtUi::mainWindow()->systemTrayIcon(), SIGNAL(messageClicked()), this, SIGNAL(activated()));
}
void SystrayNotificationBackend::notify(const Notification ¬ification) {
* 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