+void CoreSession::storeBufferLastSeenMsg(BufferId buffer, const MsgId &msgId) {
+ Core::setBufferLastSeenMsg(user(), buffer, msgId);
+}
+
+void CoreSession::initScriptEngine() {
+ signalProxy()->attachSlot(SIGNAL(scriptRequest(QString)), this, SLOT(scriptRequest(QString)));
+ signalProxy()->attachSignal(this, SIGNAL(scriptResult(QString)));
+
+ // FIXME
+ //QScriptValue storage_ = scriptEngine->newQObject(storage);
+ //scriptEngine->globalObject().setProperty("storage", storage_);
+}
+
+void CoreSession::scriptRequest(QString script) {
+ emit scriptResult(scriptEngine->evaluate(script).toString());
+}
+
+/*** Identity Handling ***/
+
+void CoreSession::createIdentity(const Identity &identity, const QVariantMap &additional) {
+ if(_identities.contains(identity.id())) {
+ qWarning() << "duplicate Identity:" << identity.id();
+ return;
+ }
+
+ int id = identity.id().toInt();
+ bool newId = !identity.isValid();
+ CoreIdentity *coreIdentity = new CoreIdentity(identity, signalProxy(), this);
+ if(additional.contains("KeyPem"))
+ coreIdentity->setSslKey(additional["KeyPem"].toByteArray());
+ if(additional.contains("CertPem"))
+ coreIdentity->setSslCert(additional["CertPem"].toByteArray());
+ if(newId) {
+ // find free ID
+ for(id = 1; id <= _identities.count(); id++) {
+ if(!_identities.keys().contains(id))
+ break;
+ }
+ coreIdentity->setId(id);
+ coreIdentity->save();
+ }
+
+ _identities[id] = coreIdentity;
+ qDebug() << id << coreIdentity->id();
+ signalProxy()->synchronize(coreIdentity);
+
+ if(newId)
+ emit identityCreated(*coreIdentity);
+}
+
+void CoreSession::removeIdentity(IdentityId id) {
+ Identity *i = _identities.take(id);
+ if(i) {
+ emit identityRemoved(id);
+ CoreUserSettings s(user());
+ s.removeIdentity(id);
+ i->deleteLater();
+ }
+}
+
+/*** Network Handling ***/
+
+void CoreSession::createNetwork(const NetworkInfo &info_) {
+ NetworkInfo info = info_;
+ int id;
+
+ if(!info.networkId.isValid())
+ Core::createNetwork(user(), info);
+
+ if(!info.networkId.isValid()) {
+ qWarning() << qPrintable(tr("CoreSession::createNetwork(): Got invalid networkId from Core when trying to create network %1!").arg(info.networkName));
+ return;
+ }
+
+ id = info.networkId.toInt();
+ if(!_networks.contains(id)) {
+ CoreNetwork *net = new CoreNetwork(id, this);
+ connect(net, SIGNAL(displayMsg(Message::Type, BufferInfo::Type, QString, QString, QString, Message::Flags)),
+ this, SLOT(recvMessageFromServer(Message::Type, BufferInfo::Type, QString, QString, QString, Message::Flags)));
+ connect(net, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString)));
+
+ net->setNetworkInfo(info);
+ net->setProxy(signalProxy());
+ _networks[id] = net;
+ signalProxy()->synchronize(net);
+ emit networkCreated(id);
+ } else {
+ qWarning() << qPrintable(tr("CoreSession::createNetwork(): Trying to create a network that already exists, updating instead!"));
+ _networks[info.networkId]->requestSetNetworkInfo(info);
+ }
+}