- return false;
-}
-
-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:
- case QAbstractSocket::ConnectedState: // we'll set it to Connected in connectionReady()
- state = Connecting;
- 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();
- disconnectFromCore(_socket->errorString(), true);
-}
-
-void CoreConnection::coreSocketDisconnected() {
- emit disconnected();
- qDebug() << Q_FUNC_INFO;
- 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;