diff --git a/src/controller.cpp b/src/controller.cpp index 19f56f42c..1c46ba3a5 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -60,7 +60,6 @@ using namespace Quotient; Controller::Controller(QObject *parent) : QObject(parent) - , m_mgr(new QNetworkConfigurationManager(this)) { Connection::setRoomType(); Connection::setUserType(); @@ -115,8 +114,6 @@ Controller::Controller(QObject *parent) sigaction(sig, &sa, nullptr); } #endif - - connect(m_mgr, &QNetworkConfigurationManager::onlineStateChanged, this, &Controller::isOnlineChanged); } Controller::~Controller() @@ -563,9 +560,26 @@ void Controller::setActiveConnection(Connection *connection) if (connection == m_connection) { return; } + if (m_connection != nullptr) { + disconnect(connection, &Connection::syncError, this, nullptr); + } m_connection = connection; if (connection != nullptr) { NeoChatConfig::self()->setActiveConnection(connection->userId()); + connect(connection, &Connection::networkError, this, [this](QString message, QString details, int retriesTaken, int nextRetryInMilliseconds) { + if (!m_isOnline) { + return; + } + m_isOnline = false; + Q_EMIT isOnlineChanged(false); + }); + connect(connection, &Connection::syncDone, this, [this] { + if (m_isOnline) { + return; + } + m_isOnline = true; + Q_EMIT isOnlineChanged(true); + }); } else { NeoChatConfig::self()->setActiveConnection(QString()); } @@ -612,7 +626,7 @@ void Controller::createRoom(const QString &name, const QString &topic) bool Controller::isOnline() const { - return m_mgr->isOnline(); + return m_isOnline; } // TODO: Remove in favor of RoomManager::joinRoom diff --git a/src/controller.h b/src/controller.h index 910bd89e1..889f38ac4 100644 --- a/src/controller.h +++ b/src/controller.h @@ -10,7 +10,6 @@ #include class QKeySequences; -class QNetworkConfigurationManager; #include "connection.h" #include "csapi/list_public_rooms.h" @@ -107,6 +106,7 @@ private: void loadSettings(); void saveSettings() const; + bool m_isOnline = true; KAboutData m_aboutData; bool hasWindowSystem() const; @@ -143,9 +143,6 @@ public Q_SLOTS: static void markAllMessagesAsRead(Quotient::Connection *conn); void restoreWindowGeometry(QQuickWindow *); void saveWindowGeometry(QQuickWindow *); - -private: - QNetworkConfigurationManager *m_mgr; }; // TODO libQuotient 0.7: Drop