Allow overriding of socket handling methods
[quassel.git] / src / client / clientauthhandler.cpp
index 4317453..6661119 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2014 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -78,7 +78,7 @@ void ClientAuthHandler::connectToCore()
     setSocket(socket);
     // handled by the base class for now; may need to rethink for protocol detection
     //connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
-    //connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
+    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
     connect(socket, SIGNAL(connected()), SLOT(onSocketConnected()));
 
     emit statusMessage(tr("Connecting to %1...").arg(_account.accountName()));
@@ -87,45 +87,37 @@ void ClientAuthHandler::connectToCore()
 
 
 // TODO: handle protocol detection
-// This method might go away anyway, unless we really need our own states...
-/*
 void ClientAuthHandler::onSocketStateChanged(QAbstractSocket::SocketState socketState)
 {
-    qDebug() << Q_FUNC_INFO << socketState;
     QString text;
-    AuthHandler::State state = UnconnectedState;
 
     switch(socketState) {
         case QAbstractSocket::UnconnectedState:
             text = tr("Disconnected");
-            state = UnconnectedState;
+            // Ensure the disconnected() signal is sent even if we haven't reached the Connected state yet.
+            // The baseclass implementation will make sure to only send the signal once.
+            onSocketDisconnected();
             break;
         case QAbstractSocket::HostLookupState:
             text = tr("Looking up %1...").arg(_account.hostName());
-            state = HostLookupState;
             break;
         case QAbstractSocket::ConnectingState:
             text = tr("Connecting to %1...").arg(_account.hostName());
-            state = ConnectingState;
             break;
         case QAbstractSocket::ConnectedState:
             text = tr("Connected to %1").arg(_account.hostName());
-            state = ConnectedState;
             break;
         case QAbstractSocket::ClosingState:
             text = tr("Disconnecting from %1...").arg(_account.hostName());
-            state = ClosingState;
             break;
         default:
             break;
     }
 
     if (!text.isEmpty()) {
-        setState(state);
         emit statusMessage(text);
     }
 }
-*/
 
 // TODO: handle protocol detection
 /*
@@ -144,6 +136,8 @@ void ClientAuthHandler::onSocketConnected()
         return;
     }
 
+    socket()->setSocketOption(QAbstractSocket::KeepAliveOption, true);
+
     _peer = new LegacyPeer(this, socket(), this);
 
     connect(_peer, SIGNAL(transferProgress(int,int)), SIGNAL(transferProgress(int,int)));