Fix warnings from GCC 4.3 about suggested parentheses.
[quassel.git] / src / client / clientsyncer.cpp
index 952860a..be5c95b 100644 (file)
@@ -20,7 +20,9 @@
 
 #include "clientsyncer.h"
 
-#include <QNetworkProxy>
+#ifndef QT_NO_NETWORKPROXY
+#  include <QNetworkProxy>
+#endif
 
 #include "client.h"
 #include "global.h"
 #include "signalproxy.h"
 
 
-ClientSyncer::ClientSyncer(QObject *parent) : QObject(parent) {
+ClientSyncer::ClientSyncer(QObject *parent)
+  : QObject(parent)
+{
   socket = 0;
   blockSize = 0;
 
   connect(Client::signalProxy(), SIGNAL(disconnected()), this, SLOT(coreSocketDisconnected()));
-
 }
 
 ClientSyncer::~ClientSyncer() {
-
-
 }
 
 void ClientSyncer::coreHasData() {
@@ -125,13 +126,19 @@ void ClientSyncer::connectToCore(const QVariantMap &conn) {
 #ifndef QT_NO_OPENSSL
     QSslSocket *sock = new QSslSocket(Client::instance());
 #else
+    if(conn["useSsl"].toBool()) {
+       emit connectionError(tr("<b>This client is built without SSL Support!</b><br />Disable the usage of SSL in the account settings."));
+       emit encrypted(false);
+       return;
+    }
     QTcpSocket *sock = new QTcpSocket(Client::instance());
 #endif
-
+#ifndef QT_NO_NETWORKPROXY
     if(conn.contains("useProxy") && conn["useProxy"].toBool()) {
       QNetworkProxy proxy((QNetworkProxy::ProxyType)conn["proxyType"].toInt(), conn["proxyHost"].toString(), conn["proxyPort"].toUInt(), conn["proxyUser"].toString(), conn["proxyPassword"].toString());
       sock->setProxy(proxy);
     }
+#endif
     socket = sock;
     connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData()));
     connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
@@ -150,10 +157,16 @@ void ClientSyncer::coreSocketConnected() {
   QVariantMap clientInit;
   clientInit["MsgType"] = "ClientInit";
   clientInit["ClientVersion"] = Global::quasselVersion;
-  clientInit["ClientDate"] = Global::quasselDate;
-  clientInit["ClientBuild"] = Global::quasselBuild; // this is a minimum, since we probably won't update for every commit
+  clientInit["ClientBuild"] = 860; // FIXME legacy!
+  clientInit["ClientDate"] = Global::quasselBuildDate;
+  clientInit["ProtocolVersion"] = Global::protocolVersion;
   clientInit["UseSsl"] = coreConnectionInfo["useSsl"];
-  
+#ifndef QT_NO_COMPRESS
+  clientInit["UseCompression"] = true;
+#else
+  clientInit["UseCompression"] = false;
+#endif
+
   SignalProxy::writeDataToDevice(socket, clientInit);
 }
 
@@ -173,26 +186,24 @@ void ClientSyncer::coreSocketDisconnected() {
 
 void ClientSyncer::clientInitAck(const QVariantMap &msg) {
   // Core has accepted our version info and sent its own. Let's see if we accept it as well...
-  if(msg["CoreBuild"].toUInt() < Global::coreBuildNeeded) {
+  if((msg.contains("CoreBuild") && msg["CoreBuild"].toUInt() < 732)  // legacy!
+     || (!msg.contains("CoreBuild") && msg["ProtocolVersion"].toUInt() < Global::clientNeedsProtocol)) {
     emit connectionError(tr("<b>The Quassel Core you are trying to connect to is too old!</b><br>"
-        "Need at least a Core Version %1 (Build >= %2) to connect.").arg(Global::quasselVersion).arg(Global::coreBuildNeeded));
+        "Need at least core/client protocol v%1 to connect.").arg(Global::clientNeedsProtocol));
     disconnectFromCore();
     return;
   }
   emit connectionMsg(msg["CoreInfo"].toString());
+
+#ifndef QT_NO_OPENSSL
   if(coreConnectionInfo["useSsl"].toBool()) {
     if(msg["SupportSsl"].toBool()) {
       QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
-      if(sslSocket) {
-       connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
-       sslSocket->startClientEncryption();
-       emit encrypted(true);
-      } else {
-       emit connectionError(tr("<b>This client is built without SSL Support!</b><br />Disable the usage of SSL in the account settings."));
-       emit encrypted(false);
-       disconnectFromCore();
-       return;
-      }
+      Q_ASSERT(sslSocket);
+      connect(sslSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
+      sslSocket->startClientEncryption();
+      emit encrypted(true);
+      Client::instance()->setSecuredConnection();
     } 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."));
       emit encrypted(false);
@@ -200,7 +211,14 @@ void ClientSyncer::clientInitAck(const QVariantMap &msg) {
       return;
     }
   }
+#endif
 
+#ifndef QT_NO_COMPRESS
+  if(msg["SupportsCompression"].toBool()) {
+    socket->setProperty("UseCompression", true);
+  }
+#endif
+  
   if(!msg["Configured"].toBool()) {
     // start wizard
     emit startCoreSetup(msg["StorageBackends"].toList());
@@ -359,6 +377,7 @@ void ClientSyncer::checkSyncState() {
   }
 }
 
+#ifndef QT_NO_OPENSSL
 void ClientSyncer::sslErrors(const QList<QSslError> &errors) {
   qDebug() << "SSL Errors:";
   foreach(QSslError err, errors)
@@ -368,3 +387,4 @@ void ClientSyncer::sslErrors(const QList<QSslError> &errors) {
   if(socket)
     socket->ignoreSslErrors();
 }
+#endif