+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);
+ }
+
+ // FIXME switch to a pure DB storage
+ foreach(NetworkId id, s.networkIds()) {
+ NetworkInfo info = s.networkInfo(id);
+ createNetwork(info);
+ }
+
+ // 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);
+ }
+ }
+ }
+}
+