X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fcoreconnection.cpp;h=3c62fca68f589d7813a776d5abd3a713f87ec31e;hp=db18ef436c9181d7e1dbdc958977e68e287e78f2;hb=8f2ee00f4edef1693628d3af0bdee84d725eb754;hpb=b654b2f908590b6f69a7edadf9dacf1277a4493b diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index db18ef43..3c62fca6 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -36,14 +36,7 @@ CoreConnection::CoreConnection(QObject *parent) : QObject(parent), - _authHandler(0), - _state(Disconnected), - _wantReconnect(false), - _wasReconnect(false), - _progressMinimum(0), - _progressMaximum(-1), - _progressValue(-1), - _resetting(false) + _authHandler(nullptr) { qRegisterMetaType("CoreConnection::ConnectionState"); } @@ -52,20 +45,18 @@ CoreConnection::CoreConnection(QObject *parent) void CoreConnection::init() { Client::signalProxy()->setHeartBeatInterval(30); - connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), SIGNAL(lagUpdated(int))); + connect(Client::signalProxy(), &SignalProxy::lagUpdated, this, &CoreConnection::lagUpdated); _reconnectTimer.setSingleShot(true); - connect(&_reconnectTimer, SIGNAL(timeout()), SLOT(reconnectTimeout())); + connect(&_reconnectTimer, &QTimer::timeout, this, &CoreConnection::reconnectTimeout); -#ifdef HAVE_KDE - connect(Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)), - SLOT(solidNetworkStatusChanged(Solid::Networking::Status))); -#endif + _qNetworkConfigurationManager = new QNetworkConfigurationManager(this); + connect(_qNetworkConfigurationManager.data(), &QNetworkConfigurationManager::onlineStateChanged, this, &CoreConnection::onlineStateChanged); CoreConnectionSettings s; - s.initAndNotify("PingTimeoutInterval", this, SLOT(pingTimeoutIntervalChanged(QVariant)), 60); - s.initAndNotify("ReconnectInterval", this, SLOT(reconnectIntervalChanged(QVariant)), 60); - s.notify("NetworkDetectionMode", this, SLOT(networkDetectionModeChanged(QVariant))); + s.initAndNotify("PingTimeoutInterval", this, &CoreConnection::pingTimeoutIntervalChanged, 60); + s.initAndNotify("ReconnectInterval", this, &CoreConnection::reconnectIntervalChanged, 60); + s.notify("NetworkDetectionMode", this, &CoreConnection::networkDetectionModeChanged); networkDetectionModeChanged(s.networkDetectionMode()); } @@ -127,16 +118,12 @@ void CoreConnection::reconnectTimeout() if (!_peer) { CoreConnectionSettings s; if (_wantReconnect && s.autoReconnect()) { -#ifdef HAVE_KDE - // If using Solid, we don't want to reconnect if we're offline - if (s.networkDetectionMode() == CoreConnectionSettings::UseSolid) { - if (Solid::Networking::status() != Solid::Networking::Connected - && Solid::Networking::status() != Solid::Networking::Unknown) { + // If using QNetworkConfigurationManager, we don't want to reconnect if we're offline + if (s.networkDetectionMode() == CoreConnectionSettings::UseQNetworkConfigurationManager) { + if (!_qNetworkConfigurationManager->isOnline()) { return; - } + } } -#endif /* HAVE_KDE */ - reconnectToCore(); } } @@ -146,7 +133,7 @@ void CoreConnection::reconnectTimeout() void CoreConnection::networkDetectionModeChanged(const QVariant &vmode) { CoreConnectionSettings s; - CoreConnectionSettings::NetworkDetectionMode mode = (CoreConnectionSettings::NetworkDetectionMode)vmode.toInt(); + auto mode = (CoreConnectionSettings::NetworkDetectionMode)vmode.toInt(); if (mode == CoreConnectionSettings::UsePingTimeout) Client::signalProxy()->setMaxHeartBeatCount(s.pingTimeoutInterval() / 30); else { @@ -169,35 +156,35 @@ void CoreConnection::reconnectIntervalChanged(const QVariant &interval) } -#ifdef HAVE_KDE - -void CoreConnection::solidNetworkStatusChanged(Solid::Networking::Status status) +void CoreConnection::onlineStateChanged(bool isOnline) { CoreConnectionSettings s; - if (s.networkDetectionMode() != CoreConnectionSettings::UseSolid) + if (s.networkDetectionMode() != CoreConnectionSettings::UseQNetworkConfigurationManager) return; - switch (status) { - case Solid::Networking::Unknown: - case Solid::Networking::Connected: - //qDebug() << "Solid: Network status changed to connected or unknown"; + if(isOnline) { + // qDebug() << "QNetworkConfigurationManager reports Online"; if (state() == Disconnected) { if (_wantReconnect && s.autoReconnect()) { reconnectToCore(); } } - break; - case Solid::Networking::Disconnecting: - case Solid::Networking::Unconnected: + } else { + // qDebug() << "QNetworkConfigurationManager reports Offline"; if (state() != Disconnected && !isLocalConnection()) disconnectFromCore(tr("Network is down"), true); - break; - default: - break; } } -#endif + +QPointer CoreConnection::peer() const +{ + if (_peer) { + return _peer; + } + return _authHandler ? _authHandler->peer() : nullptr; +} + bool CoreConnection::isEncrypted() const { @@ -211,8 +198,10 @@ bool CoreConnection::isLocalConnection() const return false; if (currentAccount().isInternal()) return true; - if (_peer->isLocal()) - return true; + if (_authHandler) + return _authHandler->isLocal(); + if (_peer) + return _peer->isLocal(); return false; } @@ -229,6 +218,8 @@ void CoreConnection::setState(ConnectionState state) if (state != _state) { _state = state; emit stateChanged(state); + if (state == Connected) + _wantReconnect = true; if (state == Disconnected) emit disconnected(); } @@ -288,17 +279,17 @@ void CoreConnection::resetConnection(bool wantReconnect) _wantReconnect = wantReconnect; if (_authHandler) { - disconnect(_authHandler, 0, this, 0); + disconnect(_authHandler, nullptr, this, nullptr); _authHandler->close(); _authHandler->deleteLater(); - _authHandler = 0; + _authHandler = nullptr; } if (_peer) { - disconnect(_peer, 0, this, 0); + disconnect(_peer, nullptr, this, nullptr); // peer belongs to the sigproxy and thus gets deleted by it _peer->close(); - _peer = 0; + _peer = nullptr; } _netsToSync.clear(); @@ -378,48 +369,44 @@ void CoreConnection::connectToCurrentAccount() return; } - resetConnection(false); - if (currentAccount().isInternal()) { if (Quassel::runMode() != Quassel::Monolithic) { qWarning() << "Cannot connect to internal core in client-only mode!"; return; } - emit startInternalCore(); - InternalPeer *peer = new InternalPeer(); + auto *peer = new InternalPeer(); _peer = peer; Client::instance()->signalProxy()->addPeer(peer); // sigproxy will take ownership + emit connectionMsg(tr("Initializing...")); emit connectToInternalCore(peer); setState(Connected); - return; } _authHandler = new ClientAuthHandler(currentAccount(), this); - connect(_authHandler, SIGNAL(disconnected()), SLOT(coreSocketDisconnected())); - connect(_authHandler, SIGNAL(connectionReady()), SLOT(onConnectionReady())); - connect(_authHandler, SIGNAL(socketError(QAbstractSocket::SocketError,QString)), SLOT(coreSocketError(QAbstractSocket::SocketError,QString))); - connect(_authHandler, SIGNAL(transferProgress(int,int)), SLOT(updateProgress(int,int))); - connect(_authHandler, SIGNAL(requestDisconnect(QString,bool)), SLOT(disconnectFromCore(QString,bool))); - - connect(_authHandler, SIGNAL(errorMessage(QString)), SIGNAL(connectionError(QString))); - connect(_authHandler, SIGNAL(errorPopup(QString)), SIGNAL(connectionErrorPopup(QString)), Qt::QueuedConnection); - connect(_authHandler, SIGNAL(statusMessage(QString)), SIGNAL(connectionMsg(QString))); - connect(_authHandler, SIGNAL(encrypted(bool)), SIGNAL(encrypted(bool))); - connect(_authHandler, SIGNAL(startCoreSetup(QVariantList)), SIGNAL(startCoreSetup(QVariantList))); - connect(_authHandler, SIGNAL(coreSetupFailed(QString)), SIGNAL(coreSetupFailed(QString))); - connect(_authHandler, SIGNAL(coreSetupSuccessful()), SIGNAL(coreSetupSuccess())); - connect(_authHandler, SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString)), SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString))); - connect(_authHandler, SIGNAL(handleNoSslInClient(bool*)), SIGNAL(handleNoSslInClient(bool*))); - connect(_authHandler, SIGNAL(handleNoSslInCore(bool*)), SIGNAL(handleNoSslInCore(bool*))); + connect(_authHandler, &ClientAuthHandler::disconnected, this, &CoreConnection::coreSocketDisconnected); + connect(_authHandler, &ClientAuthHandler::connectionReady, this, &CoreConnection::onConnectionReady); + connect(_authHandler, &ClientAuthHandler::socketError, this, &CoreConnection::coreSocketError); + connect(_authHandler, &ClientAuthHandler::transferProgress, this, &CoreConnection::updateProgress); + connect(_authHandler, &ClientAuthHandler::requestDisconnect, this, selectOverload(&CoreConnection::disconnectFromCore)); + + connect(_authHandler, &ClientAuthHandler::errorMessage, this, &CoreConnection::connectionError); + connect(_authHandler, &ClientAuthHandler::errorPopup, this, &CoreConnection::connectionErrorPopup, Qt::QueuedConnection); + connect(_authHandler, &ClientAuthHandler::statusMessage, this, &CoreConnection::connectionMsg); + connect(_authHandler, &ClientAuthHandler::encrypted, this, &CoreConnection::encrypted); + connect(_authHandler, &ClientAuthHandler::startCoreSetup, this, &CoreConnection::startCoreSetup); + connect(_authHandler, &ClientAuthHandler::coreSetupFailed, this, &CoreConnection::coreSetupFailed); + connect(_authHandler, &ClientAuthHandler::coreSetupSuccessful, this, &CoreConnection::coreSetupSuccess); + connect(_authHandler, &ClientAuthHandler::userAuthenticationRequired, this, &CoreConnection::userAuthenticationRequired); + connect(_authHandler, &ClientAuthHandler::handleNoSslInClient, this, &CoreConnection::handleNoSslInClient); + connect(_authHandler, &ClientAuthHandler::handleNoSslInCore, this, &CoreConnection::handleNoSslInCore); #ifdef HAVE_SSL - connect(_authHandler, SIGNAL(handleSslErrors(const QSslSocket*,bool*,bool*)), SIGNAL(handleSslErrors(const QSslSocket*,bool*,bool*))); + connect(_authHandler, &ClientAuthHandler::handleSslErrors, this, &CoreConnection::handleSslErrors); #endif - - connect(_authHandler, SIGNAL(loginSuccessful(CoreAccount)), SLOT(onLoginSuccessful(CoreAccount))); - connect(_authHandler, SIGNAL(handshakeComplete(RemotePeer*,Protocol::SessionState)), SLOT(onHandshakeComplete(RemotePeer*,Protocol::SessionState))); + connect(_authHandler, &ClientAuthHandler::loginSuccessful, this, &CoreConnection::onLoginSuccessful); + connect(_authHandler, &ClientAuthHandler::handshakeComplete, this, &CoreConnection::onHandshakeComplete); setState(Connecting); _authHandler->connectToCore(); @@ -458,14 +445,14 @@ void CoreConnection::onHandshakeComplete(RemotePeer *peer, const Protocol::Sessi { updateProgress(100, 100); - disconnect(_authHandler, 0, this, 0); + disconnect(_authHandler, nullptr, this, nullptr); _authHandler->deleteLater(); - _authHandler = 0; + _authHandler = nullptr; _peer = peer; - connect(peer, SIGNAL(disconnected()), SLOT(coreSocketDisconnected())); - connect(peer, SIGNAL(statusMessage(QString)), SIGNAL(connectionMsg(QString))); - connect(peer, SIGNAL(socketError(QAbstractSocket::SocketError,QString)), SLOT(coreSocketError(QAbstractSocket::SocketError,QString))); + connect(peer, &Peer::disconnected, this, &CoreConnection::coreSocketDisconnected); + connect(peer, &RemotePeer::statusMessage, this, &CoreConnection::connectionMsg); + connect(peer, &RemotePeer::socketError, this, &CoreConnection::coreSocketError); Client::signalProxy()->addPeer(_peer); // sigproxy takes ownership of the peer! @@ -476,9 +463,6 @@ void CoreConnection::onHandshakeComplete(RemotePeer *peer, const Protocol::Sessi void CoreConnection::internalSessionStateReceived(const Protocol::SessionState &sessionState) { updateProgress(100, 100); - - Client::setCoreFeatures(Quassel::features()); // mono connection... - setState(Synchronizing); syncToCore(sessionState); } @@ -511,10 +495,10 @@ void CoreConnection::syncToCore(const Protocol::SessionState &sessionState) NetworkId netid = networkid.value(); if (Client::network(netid)) continue; - Network *net = new Network(netid, Client::instance()); + auto *net = new Network(netid, Client::instance()); _netsToSync.insert(net); - connect(net, SIGNAL(initDone()), SLOT(networkInitDone())); - connect(net, SIGNAL(destroyed()), SLOT(networkInitDone())); + connect(net, &SyncableObject::initDone, this, &CoreConnection::networkInitDone); + connect(net, &QObject::destroyed, this, &CoreConnection::networkInitDone); Client::addNetwork(net); } checkSyncState(); @@ -526,7 +510,7 @@ void CoreConnection::networkInitDone() { QObject *net = sender(); Q_ASSERT(net); - disconnect(net, 0, this, 0); + disconnect(net, nullptr, this, nullptr); _netsToSync.remove(net); updateProgress(_numNetsToSync - _netsToSync.count(), _numNetsToSync); checkSyncState();