From 924a1fed213a456f168c6dc281b612faf1025add Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sat, 25 Dec 2021 18:20:08 +0100 Subject: [PATCH] Port away from QNetworkConfigurationManager QNetworkConfigurationManager was removed from Qt6 and it's better to check the status of the sync job anyway. Only two issues: * The timeout in quotient is quite high so it might take up to one minute before the message appear. * Only sync job are listened but since they are continuously done, this is not a big issue and other job are affected by the same issue of an high timeout anyway. Fix #414 --- src/controller.cpp | 22 ++++++++++++++++++---- src/controller.h | 5 +---- 2 files changed, 19 insertions(+), 8 deletions(-) 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