Add online status indicator.
Attempt to resync as soon as system goes online. #145
This commit is contained in:
@@ -41,6 +41,8 @@ ApplicationWindow {
|
|||||||
|
|
||||||
iconSource: ":/assets/img/icon.png"
|
iconSource: ":/assets/img/icon.png"
|
||||||
|
|
||||||
|
isOnline: spectralController.isOnline
|
||||||
|
|
||||||
onShowWindow: window.showWindow()
|
onShowWindow: window.showWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ Controller::Controller(QObject* parent) : QObject(parent) {
|
|||||||
Connection::setRoomType<SpectralRoom>();
|
Connection::setRoomType<SpectralRoom>();
|
||||||
Connection::setUserType<SpectralUser>();
|
Connection::setUserType<SpectralUser>();
|
||||||
|
|
||||||
|
connect(&m_ncm, &QNetworkConfigurationManager::onlineStateChanged, this,
|
||||||
|
&Controller::isOnlineChanged);
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(invokeLogin()));
|
QTimer::singleShot(0, this, SLOT(invokeLogin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +137,14 @@ void Controller::addConnection(Connection* c) {
|
|||||||
c->saveState();
|
c->saveState();
|
||||||
});
|
});
|
||||||
connect(c, &Connection::loggedOut, this, [=] { dropConnection(c); });
|
connect(c, &Connection::loggedOut, this, [=] { dropConnection(c); });
|
||||||
|
connect(&m_ncm, &QNetworkConfigurationManager::onlineStateChanged,
|
||||||
|
[=](bool status) {
|
||||||
|
if (!status)
|
||||||
|
return;
|
||||||
|
|
||||||
|
c->stopSync();
|
||||||
|
c->sync(30000);
|
||||||
|
});
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMediaPlayer>
|
#include <QMediaPlayer>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QNetworkConfigurationManager>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ class Controller : public QObject {
|
|||||||
setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
||||||
Q_PROPERTY(Connection* connection READ connection WRITE setConnection NOTIFY
|
Q_PROPERTY(Connection* connection READ connection WRITE setConnection NOTIFY
|
||||||
connectionChanged)
|
connectionChanged)
|
||||||
|
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged)
|
||||||
Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
|
Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -54,6 +56,8 @@ class Controller : public QObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isOnline() { return m_ncm.isOnline(); }
|
||||||
|
|
||||||
bool busy() { return m_busy; }
|
bool busy() { return m_busy; }
|
||||||
void setBusy(bool busy) {
|
void setBusy(bool busy) {
|
||||||
if (m_busy == busy) {
|
if (m_busy == busy) {
|
||||||
@@ -79,6 +83,7 @@ class Controller : public QObject {
|
|||||||
private:
|
private:
|
||||||
QVector<Connection*> m_connections;
|
QVector<Connection*> m_connections;
|
||||||
QPointer<Connection> m_connection;
|
QPointer<Connection> m_connection;
|
||||||
|
QNetworkConfigurationManager m_ncm;
|
||||||
bool m_busy = false;
|
bool m_busy = false;
|
||||||
|
|
||||||
QByteArray loadAccessTokenFromFile(const AccountSettings& account);
|
QByteArray loadAccessTokenFromFile(const AccountSettings& account);
|
||||||
@@ -105,6 +110,7 @@ class Controller : public QObject {
|
|||||||
void quitOnLastWindowClosedChanged();
|
void quitOnLastWindowClosedChanged();
|
||||||
void unreadCountChanged();
|
void unreadCountChanged();
|
||||||
void connectionChanged();
|
void connectionChanged();
|
||||||
|
void isOnlineChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void logout(Connection* conn);
|
void logout(Connection* conn);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void MsgCountComposedIcon::paint(QPainter* painter,
|
|||||||
|
|
||||||
icon_.paint(painter, rect, Qt::AlignCenter, mode, state);
|
icon_.paint(painter, rect, Qt::AlignCenter, mode, state);
|
||||||
|
|
||||||
if (msgCount <= 0)
|
if (isOnline && msgCount <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QColor backgroundColor("red");
|
QColor backgroundColor("red");
|
||||||
@@ -46,10 +46,12 @@ void MsgCountComposedIcon::paint(QPainter* painter,
|
|||||||
painter->drawEllipse(bubble);
|
painter->drawEllipse(bubble);
|
||||||
painter->setPen(QPen(textColor));
|
painter->setPen(QPen(textColor));
|
||||||
painter->setBrush(Qt::NoBrush);
|
painter->setBrush(Qt::NoBrush);
|
||||||
if (msgCount < 100) {
|
if (!isOnline) {
|
||||||
painter->drawText(bubble, Qt::AlignCenter, QString::number(msgCount));
|
painter->drawText(bubble, Qt::AlignCenter, "x");
|
||||||
} else {
|
} else if (msgCount >= 100) {
|
||||||
painter->drawText(bubble, Qt::AlignCenter, "99+");
|
painter->drawText(bubble, Qt::AlignCenter, "99+");
|
||||||
|
} else {
|
||||||
|
painter->drawText(bubble, Qt::AlignCenter, QString::number(msgCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +113,7 @@ void TrayIcon::setNotificationCount(int count) {
|
|||||||
#elif defined(Q_OS_WIN)
|
#elif defined(Q_OS_WIN)
|
||||||
// FIXME: Find a way to use Windows apis for the badge counter (if any).
|
// FIXME: Find a way to use Windows apis for the badge counter (if any).
|
||||||
#else
|
#else
|
||||||
if (count == icon_->msgCount)
|
if (!icon_ || count == icon_->msgCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Custom drawing on Linux.
|
// Custom drawing on Linux.
|
||||||
@@ -126,6 +128,23 @@ void TrayIcon::setNotificationCount(int count) {
|
|||||||
emit notificationCountChanged();
|
emit notificationCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayIcon::setIsOnline(bool online) {
|
||||||
|
m_isOnline = online;
|
||||||
|
|
||||||
|
if (!icon_ || online == icon_->isOnline)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Custom drawing on Linux.
|
||||||
|
MsgCountComposedIcon* tmp =
|
||||||
|
static_cast<MsgCountComposedIcon*>(icon_->clone());
|
||||||
|
tmp->isOnline = online;
|
||||||
|
|
||||||
|
setIcon(QIcon(tmp));
|
||||||
|
|
||||||
|
icon_ = tmp;
|
||||||
|
emit isOnlineChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void TrayIcon::setIconSource(const QString& source) {
|
void TrayIcon::setIconSource(const QString& source) {
|
||||||
m_iconSource = source;
|
m_iconSource = source;
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||||
@@ -133,6 +152,8 @@ void TrayIcon::setIconSource(const QString& source) {
|
|||||||
#else
|
#else
|
||||||
icon_ = new MsgCountComposedIcon(source);
|
icon_ = new MsgCountComposedIcon(source);
|
||||||
setIcon(QIcon(icon_));
|
setIcon(QIcon(icon_));
|
||||||
|
icon_->isOnline = m_isOnline;
|
||||||
|
icon_->msgCount = m_notificationCount;
|
||||||
#endif
|
#endif
|
||||||
emit iconSourceChanged();
|
emit iconSourceChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class MsgCountComposedIcon : public QIconEngine {
|
|||||||
QIcon::State state);
|
QIcon::State state);
|
||||||
|
|
||||||
int msgCount = 0;
|
int msgCount = 0;
|
||||||
|
bool isOnline = true; // Default to false?
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int BubbleDiameter = 14;
|
const int BubbleDiameter = 14;
|
||||||
@@ -39,6 +40,7 @@ class TrayIcon : public QSystemTrayIcon {
|
|||||||
iconSourceChanged)
|
iconSourceChanged)
|
||||||
Q_PROPERTY(int notificationCount READ notificationCount WRITE
|
Q_PROPERTY(int notificationCount READ notificationCount WRITE
|
||||||
setNotificationCount NOTIFY notificationCountChanged)
|
setNotificationCount NOTIFY notificationCountChanged)
|
||||||
|
Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged)
|
||||||
public:
|
public:
|
||||||
TrayIcon(QObject* parent = nullptr);
|
TrayIcon(QObject* parent = nullptr);
|
||||||
|
|
||||||
@@ -48,15 +50,20 @@ class TrayIcon : public QSystemTrayIcon {
|
|||||||
int notificationCount() { return m_notificationCount; }
|
int notificationCount() { return m_notificationCount; }
|
||||||
void setNotificationCount(int count);
|
void setNotificationCount(int count);
|
||||||
|
|
||||||
|
bool isOnline() { return m_isOnline; }
|
||||||
|
void setIsOnline(bool online);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void notificationCountChanged();
|
void notificationCountChanged();
|
||||||
void iconSourceChanged();
|
void iconSourceChanged();
|
||||||
|
void isOnlineChanged();
|
||||||
|
|
||||||
void showWindow();
|
void showWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_iconSource;
|
QString m_iconSource;
|
||||||
int m_notificationCount = 0;
|
int m_notificationCount = 0;
|
||||||
|
bool m_isOnline = true;
|
||||||
|
|
||||||
QAction* viewAction_;
|
QAction* viewAction_;
|
||||||
QAction* quitAction_;
|
QAction* quitAction_;
|
||||||
|
|||||||
Reference in New Issue
Block a user