+void CoreSession::loadSettings() {
+ CoreUserSettings s(user());
+
+ 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);
+ }
+
+ foreach(NetworkId id, s.networkIds()) {
+ NetworkInfo info = s.networkInfo(id);
+ createNetwork(info, true);
+ }
+
+ // FIXME Migrate old settings if available...
+ if(!_networks.count()) {
+ QVariantMap networks = s.sessionValue("Networks").toMap();
+ if(networks.keys().count()) {
+ qWarning() << "Migrating your old network settings to the new format!";
+ foreach(QString netname, networks.keys()) {
+ QVariantMap network = networks[netname].toMap();
+ NetworkId netid = Core::networkId(user(), netname);
+ NetworkInfo info;
+ info.networkId = netid;
+ info.networkName = netname;
+ info.identity = 1;
+ info.codecForEncoding = "ISO-8859-15";
+ info.codecForDecoding = "ISO-8859-15";
+ QVariantList slist;
+ foreach(QVariant v, network["Servers"].toList()) {
+ QVariantMap server;
+ server["Host"] = v.toMap()["Address"];
+ server["Port"] = v.toMap()["Port"];
+ slist << server;
+ }
+ info.serverList = slist;
+ createNetwork(info, true);
+ }
+ }
+ }
+}
+
+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;
+ }
+ }
+ if(!net) {
+ qWarning() << "Connect to unknown network requested, ignoring!";
+ return;
+ }
+ connectToNetwork(net->networkId(), previousState);