+ 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, Message::Flags)),
+ this, SLOT(recvMessageFromServer(Message::Type, BufferInfo::Type, QString, QString, QString, Message::Flags)));
+ 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();
+ _connections[id]->userInputHandler()->handleQuit(BufferInfo(), QString());
+}
+
+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) {
+ quError() << "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)
+ quInfo() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
+ else
+ quInfo() << "Local client disconnedted.";
+ disconnect(socket, 0, this, 0);
+ socket->deleteLater();
+}
+
+SignalProxy *CoreSession::signalProxy() const {
+ return _signalProxy;
+}
+
+// FIXME we need a sane way for creating buffers!
+void CoreSession::networkConnected(NetworkId networkid) {
+ Core::bufferInfo(user(), networkid, BufferInfo::StatusBuffer); // create status buffer
+ Core::setNetworkConnected(user(), networkid, true);
+}
+
+// called now only on /quit and requested disconnects, not on normal disconnects!
+void CoreSession::networkDisconnected(NetworkId networkid) {
+ // if the network has already been removed, we don't have a networkconnection left either, so we don't do anything
+ // make sure to not depend on the network still existing when calling this function!
+ if(_connections.contains(networkid)) {
+ Core::setNetworkConnected(user(), networkid, false);
+ _connections.take(networkid)->deleteLater();
+ }
+}
+
+void CoreSession::channelJoined(NetworkId id, const QString &channel, const QString &key) {
+ Core::setChannelPersistent(user(), id, channel, true);
+ Core::setPersistentChannelKey(user(), id, channel, key);
+}
+
+void CoreSession::channelParted(NetworkId id, const QString &channel) {
+ Core::setChannelPersistent(user(), id, channel, false);
+}
+
+QHash<QString, QString> CoreSession::persistentChannels(NetworkId id) const {
+ return Core::persistentChannels(user(), id);
+ return QHash<QString, QString>();
+}
+
+// FIXME switch to BufferId
+void CoreSession::msgFromClient(BufferInfo bufinfo, QString msg) {
+ NetworkConnection *conn = networkConnection(bufinfo.networkId());
+ if(conn) {
+ conn->userInput(bufinfo, msg);