void ClientConnectionManager::connectionStateChanged(QAbstractSocket::SocketState socketState) { QString state; switch(socketState) { case(QAbstractSocket::UnconnectedState): { state = "The socket is not connected."; break; } case(QAbstractSocket::HostLookupState): { state = "The socket is performing a host name lookup."; break; } case(QAbstractSocket::ConnectingState): { state = "The socket has started establishing a connection."; break; } case(QAbstractSocket::ConnectedState): { state = "A connection is established."; break; } case(QAbstractSocket::BoundState): { state = "The socket is bound to an address and port."; break; } case(QAbstractSocket::ClosingState): { state = "The socket is about to close (data may still be waiting to be written)."; break; } case(QAbstractSocket::ListeningState): { state = "For internal use only."; break; } } // get a pointer to the calling socket QTcpSocket * socket = qobject_cast<QTcpSocket*>(sender()); // get the socket id QString socket_id = QString::number(int(socket->socketDescriptor())); emit connectionChangedState(socket_id, state); }
void ConnectionManager::handleConnectionStateChange(Server* server, Konversation::ConnectionState state) { emit connectionChangedState(server, state); int identityId = server->getIdentity()->id(); if (state == Konversation::SSConnected) { m_overrideAutoReconnect = false; if (!m_activeIdentities.contains(identityId)) { m_activeIdentities.insert(identityId); emit identityOnline(identityId); } } else if (state != Konversation::SSConnecting) { if (m_activeIdentities.contains(identityId)) { m_activeIdentities.remove(identityId); emit identityOffline(identityId); } } if (state == Konversation::SSInvoluntarilyDisconnected && !m_overrideAutoReconnect) { // The asynchronous invocation of handleReconnect() makes sure that // connectionChangedState() is emitted and delivered before it runs // (and causes the next connection state change to occur). emit requestReconnect(server); } else if (state == Konversation::SSInvoluntarilyDisconnected && m_overrideAutoReconnect) { server->getStatusView()->appendServerMessage(i18n("Info"), i18n ("Network is down, will reconnect automatically when it is back up.")); } }