- _identities[i->id()] = i;
- }
- if(!_identities.count()) {
- Identity i(1);
- i.setToDefaults();
- i.setIdentityName(tr("Default Identity"));
- createIdentity(i);
- }
-
- //p->attachSlot(SIGNAL(requestNetworkStates()), this, SLOT(networkStateRequested()));
- p->attachSlot(SIGNAL(requestConnect(QString)), this, SLOT(connectToNetwork(QString)));
- p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromClient(BufferInfo, QString)));
- p->attachSlot(SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)), this, SLOT(sendBacklog(BufferInfo, QVariant, QVariant)));
- p->attachSignal(this, SIGNAL(displayMsg(Message)));
- p->attachSignal(this, SIGNAL(displayStatusMsg(QString, QString)));
- p->attachSignal(this, SIGNAL(backlogData(BufferInfo, QVariantList, bool)));
- p->attachSignal(this, SIGNAL(bufferInfoUpdated(BufferInfo)));
-
- p->attachSignal(this, SIGNAL(sessionDataChanged(const QString &, const QVariant &)), SIGNAL(coreSessionDataChanged(const QString &, const QVariant &)));
- p->attachSlot(SIGNAL(clientSessionDataChanged(const QString &, const QVariant &)), this, SLOT(storeSessionData(const QString &, const QVariant &)));
-
- p->attachSignal(this, SIGNAL(identityCreated(const Identity &)));
- p->attachSignal(this, SIGNAL(identityRemoved(IdentityId)));
- p->attachSlot(SIGNAL(createIdentity(const Identity &)), this, SLOT(createIdentity(const Identity &)));
- p->attachSlot(SIGNAL(updateIdentity(const Identity &)), this, SLOT(updateIdentity(const Identity &)));
- p->attachSlot(SIGNAL(removeIdentity(IdentityId)), this, SLOT(removeIdentity(IdentityId)));
-
- initScriptEngine();
-
- foreach(Identity *id, _identities.values()) {
- p->synchronize(id);
- }
-
- // Load and init networks.
- // FIXME For now we use the old info from sessionData...
-
- QVariantMap networks = retrieveSessionData("Networks").toMap();
- foreach(QString netname, networks.keys()) {
- QVariantMap network = networks[netname].toMap();
- NetworkId netid = Core::networkId(user(), netname);
- Network *net = new Network(netid, this);
- connect(net, SIGNAL(connectRequested(NetworkId)), this, SLOT(connectToNetwork(NetworkId)));
- net->setNetworkName(netname);
- net->setIdentity(1); // FIXME default identity for now
- net->setCodecForEncoding("ISO-8859-15"); // FIXME
- net->setCodecForDecoding("ISO-8859-15"); // FIXME
- QList<QVariantMap> slist;
- foreach(QVariant v, network["Servers"].toList()) slist << v.toMap();
- net->setServerList(slist);
- net->setProxy(p);
- _networks[netid] = net;
- p->synchronize(net);
- }
-
- // Restore session state
- if(restoreState) restoreSessionState();
-
- emit initialized();
-}
-
-CoreSession::~CoreSession() {
- saveSessionState();
-}
-
-UserId CoreSession::user() const {
- return _user;
-}
-
-Network *CoreSession::network(NetworkId id) const {
- if(_networks.contains(id)) return _networks[id];
- return 0;
-}
-
-NetworkConnection *CoreSession::networkConnection(NetworkId id) const {
- if(_connections.contains(id)) return _connections[id];
- return 0;
-}
-
-Identity *CoreSession::identity(IdentityId id) const {
- if(_identities.contains(id)) return _identities[id];
- return 0;
-}
-
-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"]);
- }
-}