Commit ef3cbf50 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(MessagesCountNotifier): use a blink in sys tray icon on GNU/Linux

parent 7fc1047e
...@@ -24,9 +24,11 @@ ...@@ -24,9 +24,11 @@
#include <QPainter> #include <QPainter>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QTimer>
#include "../../../app/App.hpp" #include "../../../app/App.hpp"
#include "../../../utils/LinphoneUtils.hpp" #include "../../../utils/LinphoneUtils.hpp"
#include "../../../utils/Utils.hpp"
#include "MessagesCountNotifierLinux.hpp" #include "MessagesCountNotifierLinux.hpp"
...@@ -35,6 +37,7 @@ ...@@ -35,6 +37,7 @@
#define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31" #define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31"
#define ICON_COUNTER_BACKGROUND_RADIUS 100 #define ICON_COUNTER_BACKGROUND_RADIUS 100
#define ICON_COUNTER_BLINK_INTERVAL 1000
#define ICON_COUNTER_TEXT_COLOR "#FFFBFA" #define ICON_COUNTER_TEXT_COLOR "#FFFBFA"
#define ICON_COUNTER_TEXT_PIXEL_SIZE 144 #define ICON_COUNTER_TEXT_PIXEL_SIZE 144
...@@ -52,10 +55,21 @@ MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessage ...@@ -52,10 +55,21 @@ MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessage
renderer.render(&painter); renderer.render(&painter);
mBuf = new QPixmap(buf); mBuf = new QPixmap(buf);
mBufWithCounter = new QPixmap();
mBlinkTimer = new QTimer(this);
mBlinkTimer->setInterval(ICON_COUNTER_BLINK_INTERVAL);
QObject::connect(mBlinkTimer, &QTimer::timeout, this, &MessagesCountNotifier::update);
Utils::connectOnce(
App::getInstance(), &App::focusWindowChanged,
this, &MessagesCountNotifier::updateUnreadMessagesCount
);
} }
MessagesCountNotifier::~MessagesCountNotifier () { MessagesCountNotifier::~MessagesCountNotifier () {
delete mBuf; delete mBuf;
delete mBufWithCounter;
} }
void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
...@@ -64,15 +78,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { ...@@ -64,15 +78,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
return; return;
if (!n) { if (!n) {
mBlinkTimer->stop();
sysTrayIcon->setIcon(QIcon(*mBuf)); sysTrayIcon->setIcon(QIcon(*mBuf));
return; return;
} }
QPixmap buf(*mBuf); *mBufWithCounter = *mBuf;
QPainter p(&buf); QPainter p(mBufWithCounter);
const int width = buf.width(); const int width = mBufWithCounter->width();
const int height = buf.height(); const int height = mBufWithCounter->height();
// Draw background. // Draw background.
{ {
...@@ -90,5 +105,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { ...@@ -90,5 +105,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) {
p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n)); p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n));
} }
sysTrayIcon->setIcon(QIcon(buf)); // Change counter.
mBlinkTimer->stop();
mBlinkTimer->start();
mDisplayCounter = true;
update();
}
void MessagesCountNotifier::update () {
QSystemTrayIcon *sysTrayIcon = App::getInstance()->getSystemTrayIcon();
Q_CHECK_PTR(sysTrayIcon);
sysTrayIcon->setIcon(QIcon(mDisplayCounter ? *mBufWithCounter : *mBuf));
mDisplayCounter = !mDisplayCounter;
} }
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
// ============================================================================= // =============================================================================
class QTimer;
class MessagesCountNotifier : public AbstractMessagesCountNotifier { class MessagesCountNotifier : public AbstractMessagesCountNotifier {
public: public:
MessagesCountNotifier (QObject *parent = Q_NULLPTR); MessagesCountNotifier (QObject *parent = Q_NULLPTR);
...@@ -33,5 +35,10 @@ protected: ...@@ -33,5 +35,10 @@ protected:
void notifyUnreadMessagesCount (int n) override; void notifyUnreadMessagesCount (int n) override;
private: private:
void update ();
const QPixmap *mBuf = nullptr; const QPixmap *mBuf = nullptr;
QPixmap *mBufWithCounter = nullptr;
QTimer *mBlinkTimer = nullptr;
bool mDisplayCounter = false;
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment