X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fcoreconnection.cpp;h=982e439af0032f2b8ce20167ac14de67b1932607;hp=0e4b4f94646c48bb8e9191cdbe3ef779f21bee0f;hb=fcacaaf16551524c7ebb6114254d005274cc3d63;hpb=695758015a80eb8c158a9ac4c0f1c0b547e70df3 diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index 0e4b4f94..982e439a 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 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,13 +45,13 @@ 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); _qNetworkConfigurationManager = new QNetworkConfigurationManager(this); - connect(_qNetworkConfigurationManager, SIGNAL(onlineStateChanged(bool)), SLOT(onlineStateChanged(bool))); + connect(_qNetworkConfigurationManager.data(), &QNetworkConfigurationManager::onlineStateChanged, this, &CoreConnection::onlineStateChanged); CoreConnectionSettings s; s.initAndNotify("PingTimeoutInterval", this, SLOT(pingTimeoutIntervalChanged(QVariant)), 60); @@ -140,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 { @@ -184,6 +177,15 @@ void CoreConnection::onlineStateChanged(bool isOnline) } +QPointer CoreConnection::peer() const +{ + if (_peer) { + return _peer; + } + return _authHandler ? _authHandler->peer() : nullptr; +} + + bool CoreConnection::isEncrypted() const { return _peer && _peer->isSecure(); @@ -216,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(); } @@ -275,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(); @@ -370,41 +374,40 @@ void CoreConnection::connectToCurrentAccount() 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.data(), &AuthHandler::disconnected, this, &CoreConnection::coreSocketDisconnected); + connect(_authHandler.data(), &ClientAuthHandler::connectionReady, this, &CoreConnection::onConnectionReady); + connect(_authHandler.data(), &AuthHandler::socketError, this, &CoreConnection::coreSocketError); + connect(_authHandler.data(), &ClientAuthHandler::transferProgress, this, &CoreConnection::updateProgress); 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.data(), &ClientAuthHandler::errorMessage, this, &CoreConnection::connectionError); + connect(_authHandler.data(), &ClientAuthHandler::errorPopup, this, &CoreConnection::connectionErrorPopup, Qt::QueuedConnection); + connect(_authHandler.data(), &ClientAuthHandler::statusMessage, this, &CoreConnection::connectionMsg); + connect(_authHandler.data(), &ClientAuthHandler::encrypted, this, &CoreConnection::encrypted); + connect(_authHandler.data(), &ClientAuthHandler::startCoreSetup, this, &CoreConnection::startCoreSetup); + connect(_authHandler.data(), &ClientAuthHandler::coreSetupFailed, this, &CoreConnection::coreSetupFailed); + connect(_authHandler.data(), &ClientAuthHandler::coreSetupSuccessful, this, &CoreConnection::coreSetupSuccess); + connect(_authHandler.data(), &ClientAuthHandler::userAuthenticationRequired, this, &CoreConnection::userAuthenticationRequired); + connect(_authHandler.data(), &ClientAuthHandler::handleNoSslInClient, this, &CoreConnection::handleNoSslInClient); + connect(_authHandler.data(), &ClientAuthHandler::handleNoSslInCore, this, &CoreConnection::handleNoSslInCore); #ifdef HAVE_SSL - connect(_authHandler, SIGNAL(handleSslErrors(const QSslSocket*,bool*,bool*)), SIGNAL(handleSslErrors(const QSslSocket*,bool*,bool*))); + connect(_authHandler.data(), &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.data(), &ClientAuthHandler::loginSuccessful, this, &CoreConnection::onLoginSuccessful); + connect(_authHandler.data(), &ClientAuthHandler::handshakeComplete, this, &CoreConnection::onHandshakeComplete); setState(Connecting); _authHandler->connectToCore(); @@ -443,14 +446,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! @@ -461,9 +464,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); } @@ -496,10 +496,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(); @@ -511,7 +511,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();