diff --git a/include/ChatPage.h b/include/ChatPage.h
index 7e8bc9e9..12eaf6b7 100644
--- a/include/ChatPage.h
+++ b/include/ChatPage.h
@@ -44,6 +44,7 @@ public:
signals:
void close();
void changeWindowTitle(const QString &msg);
+ void unreadMessages(int count);
private slots:
void showUnreadMessageNotification(int count);
diff --git a/include/MainWindow.h b/include/MainWindow.h
index ae8d1648..a58cc668 100644
--- a/include/MainWindow.h
+++ b/include/MainWindow.h
@@ -27,6 +27,7 @@
#include "OverlayModal.h"
#include "RegisterPage.h"
#include "SlidingStackWidget.h"
+#include "TrayIcon.h"
#include "WelcomePage.h"
class MainWindow : public QMainWindow
@@ -37,7 +38,13 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
+protected:
+ void closeEvent(QCloseEvent *event);
+
private slots:
+ // Handle interaction with the tray icon.
+ void iconActivated(QSystemTrayIcon::ActivationReason reason);
+
// Show the welcome page in the main window.
void showWelcomePage();
@@ -74,4 +81,7 @@ private:
// Matrix Client API provider.
QSharedPointer<MatrixClient> client_;
+
+ // Tray icon that shows the unread message count.
+ TrayIcon *trayIcon_;
};
diff --git a/include/TrayIcon.h b/include/TrayIcon.h
new file mode 100644
index 00000000..bef8564f
--- /dev/null
+++ b/include/TrayIcon.h
@@ -0,0 +1,58 @@
+/*
+ * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QAction>
+#include <QIcon>
+#include <QIconEngine>
+#include <QMenu>
+#include <QPainter>
+#include <QRect>
+#include <QSystemTrayIcon>
+
+class MsgCountComposedIcon : public QIconEngine
+{
+public:
+ MsgCountComposedIcon(const QString &filename);
+
+ virtual void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state);
+ virtual QIconEngine *clone() const;
+
+ int msgCount = 0;
+
+private:
+ const int BubbleDiameter = 15;
+
+ QIcon icon_;
+};
+
+class TrayIcon : public QSystemTrayIcon
+{
+ Q_OBJECT
+public:
+ TrayIcon(const QString &filename, QWidget *parent);
+
+public slots:
+ void setUnreadCount(int count);
+
+private:
+ QAction *viewAction_;
+ QAction *quitAction_;
+
+ MsgCountComposedIcon *icon_;
+};
|