X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fsystraynotificationbackend.cpp;h=721ee075b4b762a48e04bd67c4208dfdb1288628;hb=25e93f53be9b25f376c4f782f5e77d8e59b6cf10;hp=a45166593c461c6edd903dfa67ce9bf5336d4451;hpb=d452877910888c25d40590b5fff57eb8197ca9b0;p=quassel.git diff --git a/src/qtui/systraynotificationbackend.cpp b/src/qtui/systraynotificationbackend.cpp index a4516659..721ee075 100644 --- a/src/qtui/systraynotificationbackend.cpp +++ b/src/qtui/systraynotificationbackend.cpp @@ -31,7 +31,8 @@ #include "systemtray.h" SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent) - : AbstractNotificationBackend(parent) + : AbstractNotificationBackend(parent), + _blockActivation(false) { NotificationSettings notificationSettings; _showBubble = notificationSettings.value("Systray/ShowBubble", true).toBool(); @@ -40,9 +41,13 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent) notificationSettings.notify("Systray/ShowBubble", this, SLOT(showBubbleChanged(const QVariant &))); notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &))); + connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), SLOT(notificationActivated())); connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)), SLOT(notificationActivated(SystemTray::ActivationReason))); - connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), SLOT(notificationActivated())); + + QApplication::instance()->installEventFilter(this); + + updateToolTip(); } void SystrayNotificationBackend::notify(const Notification ¬ification) { @@ -55,6 +60,8 @@ void SystrayNotificationBackend::notify(const Notification ¬ification) { if(_animate) QtUi::mainWindow()->systemTray()->setAlert(true); + + updateToolTip(); } void SystrayNotificationBackend::close(uint notificationId) { @@ -70,6 +77,8 @@ void SystrayNotificationBackend::close(uint notificationId) { if(!_notifications.count()) QtUi::mainWindow()->systemTray()->setAlert(false); + + updateToolTip(); } void SystrayNotificationBackend::showBubble() { @@ -91,10 +100,13 @@ void SystrayNotificationBackend::closeBubble() { } void SystrayNotificationBackend::notificationActivated() { - if(QtUi::mainWindow()->systemTray()->isAlerted() && !QtUi::mainWindow()->systemTray()->isActivationInhibited()) { - QtUi::mainWindow()->systemTray()->setInhibitActivation(); - uint id = _notifications.count()? _notifications.last().notificationId : 0; - emit activated(id); + if(!_blockActivation) { + if(QtUi::mainWindow()->systemTray()->isAlerted()) { + _blockActivation = true; // prevent double activation because both tray icon and bubble might send a signal + uint id = _notifications.count()? _notifications.last().notificationId : 0; + emit activated(id); + } else + GraphicalUi::toggleMainWidget(); } } @@ -104,6 +116,14 @@ void SystrayNotificationBackend::notificationActivated(SystemTray::ActivationRea } } +// moving the mouse or releasing the button means that we're not dealing with a double activation +bool SystrayNotificationBackend::eventFilter(QObject *obj, QEvent *event) { + if(event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonRelease) { + _blockActivation = false; + } + return AbstractNotificationBackend::eventFilter(obj, event); +} + void SystrayNotificationBackend::showBubbleChanged(const QVariant &v) { _showBubble = v.toBool(); } @@ -112,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(); }