- CoreAccountSettings s;
-
- Q_ASSERT(!_socket);
-#ifdef HAVE_SSL
- QSslSocket *sock = new QSslSocket(this);
- // make sure the warning is shown if we happen to connect without SSL support later
- s.setAccountValue("ShowNoClientSslWarning", true);
-#else
- if (_account.useSsl()) {
- if (s.accountValue("ShowNoClientSslWarning", true).toBool()) {
- bool accepted = false;
- emit handleNoSslInClient(&accepted);
- if (!accepted) {
- emit connectionError(tr("Unencrypted connection canceled"));
- return;
- }
- s.setAccountValue("ShowNoClientSslWarning", false);
- }
- }
- QTcpSocket *sock = new QTcpSocket(this);
-#endif
-
-#ifndef QT_NO_NETWORKPROXY
- if (_account.useProxy()) {
- QNetworkProxy proxy(_account.proxyType(), _account.proxyHostName(), _account.proxyPort(), _account.proxyUser(), _account.proxyPassword());
- sock->setProxy(proxy);
- }
-#endif
-
- _socket = sock;
- connect(sock, SIGNAL(connected()), SLOT(coreSocketConnected()));
- connect(sock, SIGNAL(disconnected()), SLOT(coreSocketDisconnected()));
- connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(coreSocketError(QAbstractSocket::SocketError)));
- connect(sock, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(socketStateChanged(QAbstractSocket::SocketState)));
-
- emit connectionMsg(tr("Connecting to %1...").arg(currentAccount().accountName()));
- sock->connectToHost(_account.hostName(), _account.port());
-}
-
-
-void CoreConnection::coreSocketConnected()
-{
- // Create the connection which will handle the incoming data
- Q_ASSERT(!_peer);
- _peer = new LegacyPeer(_socket, this);
- connect(_peer, SIGNAL(dataReceived(QVariant)), SLOT(coreHasData(QVariant)));
- connect(_peer, SIGNAL(transferProgress(int,int)), SLOT(updateProgress(int,int)));
-
- // Phase One: Send client info and wait for core info
-
- emit connectionMsg(tr("Synchronizing to core..."));
-
- QVariantMap clientInit;
- clientInit["MsgType"] = "ClientInit";
- clientInit["ClientVersion"] = Quassel::buildInfo().fancyVersionString;
- clientInit["ClientDate"] = Quassel::buildInfo().buildDate;
- clientInit["ProtocolVersion"] = Quassel::buildInfo().protocolVersion;
- clientInit["UseSsl"] = _account.useSsl();
-#ifndef QT_NO_COMPRESS
- clientInit["UseCompression"] = true;
-#else
- clientInit["UseCompression"] = false;
-#endif
-
- qobject_cast<RemotePeer *>(_peer)->writeSocketData(clientInit);
-}
-
-
-void CoreConnection::clientInitAck(const QVariantMap &msg)
-{
- // Core has accepted our version info and sent its own. Let's see if we accept it as well...
- uint ver = msg["ProtocolVersion"].toUInt();
- if (ver < Quassel::buildInfo().clientNeedsProtocol) {
- emit connectionErrorPopup(tr("<b>The Quassel Core you are trying to connect to is too old!</b><br>"
- "Need at least core/client protocol v%1 to connect.").arg(Quassel::buildInfo().clientNeedsProtocol));
- disconnectFromCore(QString(), false);
- return;
- }
-
- Client::setCoreFeatures((Quassel::Features)msg["CoreFeatures"].toUInt());
-
-#ifndef QT_NO_COMPRESS
- if (msg["SupportsCompression"].toBool()) {
- _socket->setProperty("UseCompression", true);
- }
-#endif
-
- _coreMsgBuffer = msg;
-
+ _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, QVariantList)), SIGNAL(startCoreSetup(QVariantList, 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*)));