+void CoreSession::saveSessionState() const {
+
+}
+
+void CoreSession::restoreSessionState() {
+ QList<NetworkId> nets = Core::connectedNetworks(user());
+ foreach(NetworkId id, nets) {
+ connectToNetwork(id);
+ }
+}
+
+void CoreSession::updateBufferInfo(UserId uid, const BufferInfo &bufinfo) {
+ if(uid == user()) emit bufferInfoUpdated(bufinfo);
+}
+
+void CoreSession::connectToNetwork(NetworkId id) {
+ Network *net = network(id);
+ if(!net) {
+ qWarning() << "Connect to unknown network requested! net:" << id << "user:" << user();
+ return;
+ }
+
+ NetworkConnection *conn = networkConnection(id);
+ if(!conn) {
+ conn = new NetworkConnection(net, this);
+ _connections[id] = conn;
+ attachNetworkConnection(conn);
+ }
+ conn->connectToIrc();
+}
+
+void CoreSession::attachNetworkConnection(NetworkConnection *conn) {
+ connect(conn, SIGNAL(connected(NetworkId)), this, SLOT(networkConnected(NetworkId)));
+ connect(conn, SIGNAL(quitRequested(NetworkId)), this, SLOT(networkDisconnected(NetworkId)));
+
+ // I guess we don't need these anymore, client-side can just connect the network's signals directly
+ //signalProxy()->attachSignal(conn, SIGNAL(connected(NetworkId)), SIGNAL(networkConnected(NetworkId)));
+ //signalProxy()->attachSignal(conn, SIGNAL(disconnected(NetworkId)), SIGNAL(networkDisconnected(NetworkId)));
+
+ connect(conn, SIGNAL(displayMsg(Message::Type, BufferInfo::Type, QString, QString, QString, quint8)),
+ this, SLOT(recvMessageFromServer(Message::Type, BufferInfo::Type, QString, QString, QString, quint8)));
+ connect(conn, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString)));
+
+ connect(conn, SIGNAL(nickChanged(const NetworkId &, const QString &, const QString &)),
+ this, SLOT(renameBuffer(const NetworkId &, const QString &, const QString &)));
+ connect(conn, SIGNAL(channelJoined(NetworkId, const QString &, const QString &)),
+ this, SLOT(channelJoined(NetworkId, const QString &, const QString &)));
+ connect(conn, SIGNAL(channelParted(NetworkId, const QString &)),
+ this, SLOT(channelParted(NetworkId, const QString &)));
+}
+
+void CoreSession::disconnectFromNetwork(NetworkId id) {
+ if(!_connections.contains(id)) return;
+ _connections[id]->disconnectFromIrc();
+}
+
+void CoreSession::networkStateRequested() {
+}
+
+void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it in signal connections
+ QIODevice *device = qobject_cast<QIODevice *>(dev);
+ if(!device) {
+ qWarning() << "Invoking CoreSession::addClient with a QObject that is not a QIODevice!";
+ } else {
+ signalProxy()->addPeer(device);
+ QVariantMap reply;
+ reply["MsgType"] = "SessionInit";
+ reply["SessionState"] = sessionState();
+ SignalProxy::writeDataToDevice(device, reply);
+ }
+}
+
+void CoreSession::removeClient(QIODevice *iodev) {
+ // no checks for validity check - privateslot...
+ QTcpSocket *socket = qobject_cast<QTcpSocket *>(iodev);
+ if(socket)
+ qDebug() << qPrintable(tr("Client %1 disconnected (UserId: %2).").arg(socket->peerAddress().toString()).arg(user().toInt()));
+ else
+ qDebug() << "Local client disconnedted.";
+ disconnect(socket, 0, this, 0);
+ socket->deleteLater();