From 179618edbf7b3f97bb42a60b3224400d269355a7 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Wed, 24 Oct 2012 13:24:38 +0000 Subject: [PATCH] Added blinking of the systray icon for the notifier and enabled it for private chat. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5721 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/chat/ChatUserNotify.h | 1 + retroshare-gui/src/gui/common/UserNotify.cpp | 34 ++++++++++++++++++++ retroshare-gui/src/gui/common/UserNotify.h | 5 +++ 3 files changed, 40 insertions(+) diff --git a/retroshare-gui/src/gui/chat/ChatUserNotify.h b/retroshare-gui/src/gui/chat/ChatUserNotify.h index ab94d7f1d..faaf27c05 100644 --- a/retroshare-gui/src/gui/chat/ChatUserNotify.h +++ b/retroshare-gui/src/gui/chat/ChatUserNotify.h @@ -43,6 +43,7 @@ private: virtual QIcon getIcon(); virtual QIcon getMainIcon(bool hasNew); virtual unsigned int getNewCount(); + virtual bool isBlinking() { return true; } virtual void iconClicked(); }; diff --git a/retroshare-gui/src/gui/common/UserNotify.cpp b/retroshare-gui/src/gui/common/UserNotify.cpp index 096cf6a63..2dba822bb 100644 --- a/retroshare-gui/src/gui/common/UserNotify.cpp +++ b/retroshare-gui/src/gui/common/UserNotify.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "UserNotify.h" @@ -33,6 +34,12 @@ UserNotify::UserNotify(QObject *parent) : mTrayIcon = NULL; mNotifyIcon = NULL; mNewCount = 0; + mLastBlinking = false; + + mTimer = new QTimer(this); + mTimer->setInterval(500); + + connect(mTimer, SIGNAL(timeout()), this, SLOT(timer())); } void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction) @@ -102,7 +109,11 @@ void UserNotify::updateIcon() if (count) { mTrayIcon->setToolTip("RetroShare\n" + getTrayMessage(count > 1).arg(count)); mTrayIcon->show(); + if (!mTimer->isActive()) { + mTimer->start(); + } } else { + mTimer->stop(); mTrayIcon->hide(); } } @@ -140,3 +151,26 @@ void UserNotify::trayIconClicked(QSystemTrayIcon::ActivationReason e) iconClicked(); } } + +void UserNotify::timer() +{ + bool blinking = isBlinking(); + + if (mTrayIcon) { + if (blinking) { + /* blink icon */ + if (mTrayIcon->icon().isNull()) { + mTrayIcon->setIcon(getIcon()); + } else { + mTrayIcon->setIcon(QIcon()); + } + } else { + if (mLastBlinking) { + /* reset icon */ + mTrayIcon->setIcon(getIcon()); + } + } + } + + mLastBlinking = blinking; +} diff --git a/retroshare-gui/src/gui/common/UserNotify.h b/retroshare-gui/src/gui/common/UserNotify.h index 2637b5a6d..b6bffdef9 100644 --- a/retroshare-gui/src/gui/common/UserNotify.h +++ b/retroshare-gui/src/gui/common/UserNotify.h @@ -28,6 +28,7 @@ class QToolBar; class QToolButton; class QAction; +class QTimer; class UserNotify : public QObject { @@ -52,11 +53,13 @@ public slots: private slots: void trayIconClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger); + void timer(); private: virtual QIcon getIcon() { return QIcon(); } virtual QIcon getMainIcon(bool /*hasNew*/) { return QIcon(); } virtual unsigned int getNewCount() { return 0; } + virtual bool isBlinking() { return false; } virtual QString getTrayMessage(bool plural); virtual QString getNotifyMessage(bool plural); @@ -69,6 +72,8 @@ private: QAction *mNotifyIcon; unsigned int mNewCount; QString mButtonText; + QTimer *mTimer; + bool mLastBlinking; }; #endif // USERNOTIFY_H