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