-void CoreConnection::socketStateChanged(QAbstractSocket::SocketState socketState) {
- QString text;
-
- switch(socketState) {
- case QAbstractSocket::UnconnectedState:
- text = tr("Disconnected.");
- break;
- case QAbstractSocket::HostLookupState:
- text = tr("Looking up %1...").arg(currentAccount().hostName());
- break;
- case QAbstractSocket::ConnectingState:
- text = tr("Connecting to %1...").arg(currentAccount().hostName());
- break;
- case QAbstractSocket::ConnectedState:
- text = tr("Connected to %1.").arg(currentAccount().hostName());
- break;
- case QAbstractSocket::ClosingState:
- text = tr("Disconnecting from %1...").arg(currentAccount().hostName());
- break;
- default:
- break;
- }
-
- if(!text.isEmpty())
- emit progressTextChanged(text);
-
- setState(socketState);
-}
-
-void CoreConnection::setState(QAbstractSocket::SocketState socketState) {
- ConnectionState state;
-
- switch(socketState) {
- case QAbstractSocket::UnconnectedState:
- state = Disconnected;
- break;
- case QAbstractSocket::HostLookupState:
- case QAbstractSocket::ConnectingState:
- state = Connecting;
- break;
- case QAbstractSocket::ConnectedState:
- state = Connected;
- break;
- default:
- state = Disconnected;
- }
-
- setState(state);
-}
-
-void CoreConnection::setState(ConnectionState state) {
- if(state != _state) {
- _state = state;
- emit stateChanged(state);
- if(state == Disconnected)
- emit disconnected();
- }
-}
-
-void CoreConnection::coreSocketError(QAbstractSocket::SocketError) {
- qDebug() << "coreSocketError" << _socket << _socket->errorString();
- emit connectionError(_socket->errorString());
- resetConnection();
-}
-
-void CoreConnection::coreSocketDisconnected() {
- emit disconnected();
- resetConnection();
- // 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 connectionError(tr("The Quassel Core you try to connect to is too old! Please consider upgrading."));
- disconnectFromCore();
- return;
- }
- if(msg["MsgType"] == "ClientInitAck") {
- clientInitAck(msg);
- } else if(msg["MsgType"] == "ClientInitReject") {
- emit connectionError(msg["Error"].toString());
- disconnectFromCore();
- 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 {
- emit connectionError(tr("<b>Invalid data received from core!</b><br>Disconnecting."));
- disconnectFromCore();
- return;
- }
- }
- if(_blockSize > 0) {
- updateProgress(_socket->bytesAvailable(), _blockSize);
- }
-}
-
-void CoreConnection::disconnectFromCore() {
- Client::signalProxy()->removeAllPeers();
- resetConnection();
-}
-
-void CoreConnection::reconnectToCore() {
- if(currentAccount().isValid())
- connectToCore(currentAccount().accountId());
-}
-
-bool CoreConnection::connectToCore(AccountId accId) {
- if(isConnected())