+void CoreConnection::coreSocketDisconnected()
+{
+ // qDebug() << Q_FUNC_INFO;
+ _wasReconnect = !_requestedDisconnect;
+ resetConnection(true);
+ // FIXME handle disconnects gracefully
+}
+
+
+void CoreConnection::coreHasData()
+{
+ QVariant item;
+ while (SignalProxy::readDataFromDevice(_socket, _blockSize, item)) {
+ QVariantMap msg = item.toMap();
+ if (!msg.contains("MsgType")) {
+ // This core is way too old and does not even speak our init protocol...
+ emit connectionErrorPopup(tr("The Quassel Core you try to connect to is too old! Please consider upgrading."));
+ disconnectFromCore(QString(), false);
+ return;
+ }
+ if (msg["MsgType"] == "ClientInitAck") {
+ clientInitAck(msg);
+ }
+ else if (msg["MsgType"] == "ClientInitReject") {
+ emit connectionErrorPopup(msg["Error"].toString());
+ disconnectFromCore(QString(), false);
+ return;
+ }
+ else if (msg["MsgType"] == "CoreSetupAck") {
+ emit coreSetupSuccess();
+ }
+ else if (msg["MsgType"] == "CoreSetupReject") {
+ emit coreSetupFailed(msg["Error"].toString());
+ }
+ else if (msg["MsgType"] == "ClientLoginReject") {
+ loginFailed(msg["Error"].toString());
+ }
+ else if (msg["MsgType"] == "ClientLoginAck") {
+ loginSuccess();
+ }
+ else if (msg["MsgType"] == "SessionInit") {
+ // that's it, let's hand over to the signal proxy
+ // if the socket is an orphan, the signalProxy adopts it.
+ // -> we don't need to care about it anymore
+ _socket->setParent(0);
+ Client::signalProxy()->addPeer(_socket);
+
+ sessionStateReceived(msg["SessionState"].toMap());
+ break; // this is definitively the last message we process here!
+ }
+ else {
+ disconnectFromCore(tr("Invalid data received from core"), false);
+ return;
+ }
+ }
+ if (_blockSize > 0) {
+ updateProgress(_socket->bytesAvailable(), _blockSize);
+ }
+}
+
+
+void CoreConnection::disconnectFromCore()
+{
+ _requestedDisconnect = true;
+ disconnectFromCore(QString(), false); // requested disconnect, so don't try to reconnect
+}
+
+
+void CoreConnection::disconnectFromCore(const QString &errorString, bool wantReconnect)
+{
+ if (!wantReconnect)
+ _reconnectTimer.stop();
+
+ _wasReconnect = wantReconnect; // store if disconnect was requested