- accId = s.lastAccount();
- if(!accId.isValid())
- return false;
- }
- _account = accountModel()->account(accId);
- if(!_account.accountId().isValid()) {
- return false;
- }
-
- s.setLastAccount(accId);
- connectToCurrentAccount();
- return true;
-}
-
-void CoreConnection::connectToCurrentAccount() {
- resetConnection();
-
- Q_ASSERT(!_socket);
-#ifdef HAVE_SSL
- QSslSocket *sock = new QSslSocket(Client::instance());
-#else
- if(_account.useSsl()) {
- emit connectionError(tr("<b>This client is built without SSL Support!</b><br />Disable the usage of SSL in the account settings."));
- return;
- }
- QTcpSocket *sock = new QTcpSocket(Client::instance());
-#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(readyRead()), SLOT(coreHasData()));
- 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() {
- // 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
-
- SignalProxy::writeDataToDevice(_socket, 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 connectionError(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();
- return;
- }
-
-#ifndef QT_NO_COMPRESS
- if(msg["SupportsCompression"].toBool()) {
- _socket->setProperty("UseCompression", true);
- }
-#endif
-
- _coreMsgBuffer = msg;
-#ifdef HAVE_SSL
- if(currentAccount().useSsl()) {
- if(msg["SupportSsl"].toBool()) {
- QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_socket);
- Q_ASSERT(sslSocket);
- connect(sslSocket, SIGNAL(encrypted()), this, SLOT(sslSocketEncrypted()));
- connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
-
- sslSocket->startClientEncryption();
- } else {
- emit connectionError(tr("<b>The Quassel Core you are trying to connect to does not support SSL!</b><br />If you want to connect anyways, disable the usage of SSL in the account settings."));
- disconnectFromCore();