Commit 22c0987e authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): add a message counter on sys tray icon (GNU/Linux)

parent ca214de2
......@@ -474,6 +474,8 @@ void App::setTrayIcon () {
systemTrayIcon->setIcon(QIcon(WINDOW_ICON_PATH));
systemTrayIcon->setToolTip("Linphone");
systemTrayIcon->show();
mSystemTrayIcon = systemTrayIcon;
}
// -----------------------------------------------------------------------------
......
......@@ -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;
};
......
......@@ -20,19 +20,75 @@
* Author: Ronan Abhamon
*/
#include <QIcon>
#include <QPainter>
#include <QSvgRenderer>
#include <QSystemTrayIcon>
#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));
}
......@@ -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;
};
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