- } else {
- Server *server = new Server(userId(), net);
- connect(this, SIGNAL(serverStateRequested()), server, SLOT(sendState()));
- connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString)));
- connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString)));
- connect(this, SIGNAL(msgFromGui(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString)));
-
- connect(server, SIGNAL(connected(QString)), this, SLOT(serverConnected(QString)));
- connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString)));
-
- connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap)));
- //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message)));
- connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8)));
- connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString)));
- connect(server, SIGNAL(modeSet(QString, QString, QString)), coreProxy, SLOT(csModeSet(QString, QString, QString)));
- connect(server, SIGNAL(topicSet(QString, QString, QString)), coreProxy, SLOT(csTopicSet(QString, QString, QString)));
- connect(server, SIGNAL(nickAdded(QString, QString, VarMap)), coreProxy, SLOT(csNickAdded(QString, QString, VarMap)));
- connect(server, SIGNAL(nickRenamed(QString, QString, QString)), coreProxy, SLOT(csNickRenamed(QString, QString, QString)));
- connect(server, SIGNAL(nickRemoved(QString, QString)), coreProxy, SLOT(csNickRemoved(QString, QString)));
- connect(server, SIGNAL(nickUpdated(QString, QString, VarMap)), coreProxy, SLOT(csNickUpdated(QString, QString, VarMap)));
- connect(server, SIGNAL(ownNickSet(QString, QString)), coreProxy, SLOT(csOwnNickSet(QString, QString)));
- connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString)));
- // TODO add error handling
- connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString)));
- connect(server, SIGNAL(disconnected(QString)), coreProxy, SLOT(csServerDisconnected(QString)));
-
- server->start();
- servers[net] = server;
+ foreach(IdentityId id, s.identityIds()) {
+ Identity *i = new Identity(s.identity(id), this);
+ if(!i->isValid()) {
+ qWarning() << QString("Invalid identity! Removing...");
+ s.removeIdentity(id);
+ delete i;
+ continue;
+ }
+ if(_identities.contains(i->id())) {
+ qWarning() << "Duplicate identity, ignoring!";
+ delete i;
+ continue;
+ }
+ _identities[i->id()] = i;
+ signalProxy()->synchronize(i);
+ }
+ if(!_identities.count()) {
+ Identity i(1);
+ i.setToDefaults();
+ i.setIdentityName(tr("Default Identity"));
+ createIdentity(i);
+ }
+
+
+ // migration to pure DB storage
+ QList<NetworkId> netIds = s.networkIds();
+ if(!netIds.isEmpty()) {
+ qDebug() << "Migrating Networksettings to DB Storage for User:" << user();
+ foreach(NetworkId id, netIds) {
+ NetworkInfo info = s.networkInfo(id);
+ Core::updateNetwork(user(), info);
+ s.removeNetworkInfo(id);
+ }
+ }
+
+ foreach(NetworkInfo info, Core::networks(user())) {
+ createNetwork(info);
+ }
+}
+
+void CoreSession::saveSessionState() const {
+ QVariantMap res;
+ QVariantList conn;
+ foreach(NetworkConnection *net, _connections.values()) {
+ QVariantMap m;
+ m["NetworkId"] = QVariant::fromValue<NetworkId>(net->networkId());
+ m["State"] = net->state();
+ conn << m;
+ }
+ res["CoreBuild"] = Global::quasselBuild;
+ res["ConnectedNetworks"] = conn;
+ CoreUserSettings s(user());
+ s.setSessionState(res);
+}
+
+void CoreSession::restoreSessionState() {
+ CoreUserSettings s(user());
+ uint build = s.sessionState().toMap()["CoreBuild"].toUInt();
+ if(build < 362) {
+ qWarning() << qPrintable(tr("Session state does not exist or is too old!"));
+ return;
+ }
+ QVariantList conn = s.sessionState().toMap()["ConnectedNetworks"].toList();
+ foreach(QVariant v, conn) {
+ NetworkId id = v.toMap()["NetworkId"].value<NetworkId>();
+ if(_networks.keys().contains(id)) connectToNetwork(id, v.toMap()["State"]);
+ }
+}
+
+void CoreSession::updateBufferInfo(UserId uid, const BufferInfo &bufinfo) {
+ if(uid == user()) emit bufferInfoUpdated(bufinfo);
+}
+
+// FIXME remove
+void CoreSession::connectToNetwork(QString netname, const QVariant &previousState) {
+ Network *net = 0;
+ foreach(Network *n, _networks.values()) {
+ if(n->networkName() == netname) {
+ net = n; break;