diff --git a/src/app/App.cpp b/src/app/App.cpp index b907186e6..37dce01c5 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -474,6 +474,8 @@ void App::setTrayIcon () { systemTrayIcon->setIcon(QIcon(WINDOW_ICON_PATH)); systemTrayIcon->setToolTip("Linphone"); systemTrayIcon->show(); + + mSystemTrayIcon = systemTrayIcon; } // ----------------------------------------------------------------------------- diff --git a/src/app/App.hpp b/src/app/App.hpp index 3ef9fce75..dfe0b732c 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -35,6 +35,7 @@ // ============================================================================= class QCommandLineParser; +class QSystemTrayIcon; class Cli; class DefaultTranslator; @@ -72,6 +73,10 @@ public: return mColors; } + QSystemTrayIcon *getSystemTrayIcon () const { + return mSystemTrayIcon; + } + QQuickWindow *getMainWindow () const; bool hasFocus () const; @@ -137,6 +142,8 @@ private: Colors *mColors = nullptr; + QSystemTrayIcon *mSystemTrayIcon = nullptr; + Cli *mCli = nullptr; }; diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp index d795f9677..958224eb1 100644 --- a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp @@ -20,19 +20,75 @@ * Author: Ronan Abhamon */ +#include +#include #include +#include +#include "../../../app/App.hpp" #include "../../../utils/LinphoneUtils.hpp" #include "MessagesCountNotifierLinux.hpp" +#define ICON_WIDTH 256 +#define ICON_HEIGHT 256 + +#define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31" +#define ICON_COUNTER_BACKGROUND_RADIUS 100 +#define ICON_COUNTER_TEXT_COLOR "#FFFBFA" +#define ICON_COUNTER_TEXT_PIXEL_SIZE 144 + // ============================================================================= MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessagesCountNotifier(parent) { - mSvgRenderer = new QSvgRenderer(QStringLiteral(WINDOW_ICON_PATH), this); + QSvgRenderer renderer(QStringLiteral(WINDOW_ICON_PATH)); + if (!renderer.isValid()) + qFatal("Invalid SVG Image."); + + QPixmap buf(ICON_WIDTH, ICON_HEIGHT); + buf.fill(QColor(Qt::transparent)); + + QPainter painter(&buf); + renderer.render(&painter); + + mBuf = new QPixmap(buf); +} + +MessagesCountNotifier::~MessagesCountNotifier () { + delete mBuf; } void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { - // TODO. - (void)n; + QSystemTrayIcon *sysTrayIcon = App::getInstance()->getSystemTrayIcon(); + if (!sysTrayIcon) + return; + + if (!n) { + sysTrayIcon->setIcon(QIcon(*mBuf)); + return; + } + + QPixmap buf(*mBuf); + QPainter p(&buf); + + const int width = buf.width(); + const int height = buf.height(); + + // Draw background. + { + p.setBrush(QColor(ICON_COUNTER_BACKGROUND_COLOR)); + p.drawEllipse(QPointF(width / 2, height / 2), ICON_COUNTER_BACKGROUND_RADIUS, ICON_COUNTER_BACKGROUND_RADIUS); + } + + // Draw text. + { + QFont font = p.font(); + font.setPixelSize(ICON_COUNTER_TEXT_PIXEL_SIZE); + + p.setFont(font); + p.setPen(QPen(QColor(ICON_COUNTER_TEXT_COLOR), 1)); + p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n)); + } + + sysTrayIcon->setIcon(QIcon(buf)); } diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp index ee1a6d208..7f4a932ec 100644 --- a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp @@ -24,15 +24,14 @@ // ============================================================================= -class QSvgRenderer; - class MessagesCountNotifier : public AbstractMessagesCountNotifier { public: MessagesCountNotifier (QObject *parent = Q_NULLPTR); + ~MessagesCountNotifier (); protected: void notifyUnreadMessagesCount (int n) override; private: - QSvgRenderer *mSvgRenderer = nullptr; + const QPixmap *mBuf = nullptr; };