Move tray icon outside C++ and allow hiding tray icon.
This commit is contained in:
@@ -28,19 +28,11 @@
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
Controller::Controller(QObject* parent)
|
||||
: QObject(parent), tray(this), notificationsManager(this) {
|
||||
: QObject(parent), notificationsManager(this) {
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
connect(¬ificationsManager, &NotificationsManager::notificationClicked,
|
||||
this, &Controller::notificationClicked);
|
||||
tray.setIcon(QIcon(":/assets/img/icon.png"));
|
||||
tray.setToolTip("Spectral");
|
||||
connect(&tray, &QSystemTrayIcon::activated,
|
||||
[this](QSystemTrayIcon::ActivationReason r) {
|
||||
if (r != QSystemTrayIcon::Context) emit showWindow();
|
||||
});
|
||||
trayMenu.addAction("Hide Window", [=] { emit hideWindow(); });
|
||||
trayMenu.addAction("Quit", [=] { QApplication::quit(); });
|
||||
tray.setContextMenu(&trayMenu);
|
||||
tray.show();
|
||||
|
||||
Connection::setRoomType<SpectralRoom>();
|
||||
Connection::setUserType<SpectralUser>();
|
||||
|
||||
@@ -18,6 +18,8 @@ class Controller : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY
|
||||
connectionDropped)
|
||||
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE
|
||||
setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
||||
|
||||
public:
|
||||
explicit Controller(QObject* parent = nullptr);
|
||||
@@ -35,13 +37,21 @@ class Controller : public QObject {
|
||||
// All the Q_PROPERTYs.
|
||||
int accountCount() { return m_connections.count(); }
|
||||
|
||||
bool quitOnLastWindowClosed() {
|
||||
return QApplication::quitOnLastWindowClosed();
|
||||
}
|
||||
void setQuitOnLastWindowClosed(bool value) {
|
||||
if (quitOnLastWindowClosed() != value) {
|
||||
QApplication::setQuitOnLastWindowClosed(value);
|
||||
emit quitOnLastWindowClosedChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Q_INVOKABLE QColor color(QString userId);
|
||||
Q_INVOKABLE void setColor(QString userId, QColor newColor);
|
||||
|
||||
private:
|
||||
QClipboard* m_clipboard = QApplication::clipboard();
|
||||
QSystemTrayIcon tray;
|
||||
QMenu trayMenu;
|
||||
NotificationsManager notificationsManager;
|
||||
QVector<Connection*> m_connections;
|
||||
|
||||
@@ -57,12 +67,11 @@ class Controller : public QObject {
|
||||
signals:
|
||||
void busyChanged();
|
||||
void errorOccured(QString error, QString detail);
|
||||
void showWindow();
|
||||
void hideWindow();
|
||||
void connectionAdded(Connection* conn);
|
||||
void connectionDropped(Connection* conn);
|
||||
void initiated();
|
||||
void notificationClicked(const QString roomId, const QString eventId);
|
||||
void quitOnLastWindowClosedChanged();
|
||||
|
||||
public slots:
|
||||
void logout(Connection* conn);
|
||||
@@ -73,7 +82,8 @@ class Controller : public QObject {
|
||||
void playAudio(QUrl localFile);
|
||||
void postNotification(const QString& roomId, const QString& eventId,
|
||||
const QString& roomName, const QString& senderName,
|
||||
const QString& text, const QImage& icon, const QUrl& iconPath);
|
||||
const QString& text, const QImage& icon,
|
||||
const QUrl& iconPath);
|
||||
|
||||
static QImage safeImage(QImage image);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QNetworkProxy>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
@@ -33,8 +33,6 @@ int main(int argc, char *argv[]) {
|
||||
app.setApplicationName("Spectral");
|
||||
app.setWindowIcon(QIcon(":/assets/img/icon.png"));
|
||||
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
qmlRegisterType<qqsfpm::QQmlSortFilterProxyModel>("SortFilterProxyModel", 0,
|
||||
2, "SortFilterProxyModel");
|
||||
qmlRegisterType<ImageItem>("Spectral", 0, 1, "ImageItem");
|
||||
|
||||
Reference in New Issue
Block a user