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
This commit is contained in:
Carl Schwan
2021-12-25 18:20:08 +01:00
parent b0a1de7572
commit 924a1fed21
2 changed files with 19 additions and 8 deletions

View File

@@ -60,7 +60,6 @@ using namespace Quotient;
Controller::Controller(QObject *parent)
: QObject(parent)
, m_mgr(new QNetworkConfigurationManager(this))
{
Connection::setRoomType<NeoChatRoom>();
Connection::setUserType<NeoChatUser>();
@@ -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