- }
- s.setAccountValue("ShowNoClientSslWarning", false);
- }
- }
- 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 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;
- }
-
-#ifndef QT_NO_COMPRESS
- if(msg["SupportsCompression"].toBool()) {
- _socket->setProperty("UseCompression", true);
- }
-#endif
-
- _coreMsgBuffer = msg;
-
-#ifdef HAVE_SSL
- CoreAccountSettings s;
- if(currentAccount().useSsl()) {
- if(msg["SupportSsl"].toBool()) {
- // Make sure the warning is shown next time we don't have SSL in the core
- s.setAccountValue("ShowNoCoreSslWarning", true);
-
- QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_socket);
- Q_ASSERT(sslSocket);
- connect(sslSocket, SIGNAL(encrypted()), SLOT(sslSocketEncrypted()));
- connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), SLOT(sslErrors()));
- sslSocket->startClientEncryption();
- } else {
- if(s.accountValue("ShowNoCoreSslWarning", true).toBool()) {
- bool accepted = false;
- emit handleNoSslInCore(&accepted);
- if(!accepted) {
- disconnectFromCore(tr("Unencrypted connection canceled"), false);
- return;
- }
- s.setAccountValue("ShowNoCoreSslWarning", false);
- s.setAccountValue("SslCert", QString());
- }
- connectionReady();
- }
- return;
- }
-#endif
- // if we use SSL we wait for the next step until every SSL warning has been cleared
- connectionReady();
-}
-
-#ifdef HAVE_SSL