+void CoreSession::identityUpdated(const QVariantMap &data) {
+ IdentityId id = data.value("identityId", 0).value<IdentityId>();
+ if(!id.isValid() || !_identities.contains(id)) {
+ quWarning() << "Update request for unknown identity received!";
+ return;
+ }
+ CoreUserSettings s(user());
+ s.storeIdentity(*_identities.value(id));
+}
+
+/*** 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()) {
+ quWarning() << 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(connectRequested(NetworkId)), this, SLOT(connectToNetwork(NetworkId)));
+ connect(net, SIGNAL(disconnectRequested(NetworkId)), this, SLOT(disconnectFromNetwork(NetworkId)));
+ net->setNetworkInfo(info);
+ net->setProxy(signalProxy());
+ _networks[id] = net;
+ signalProxy()->synchronize(net);
+ emit networkCreated(id);
+ } else {
+ quWarning() << qPrintable(tr("CoreSession::createNetwork(): Trying to create a network that already exists, updating instead!"));
+ _networks[info.networkId]->requestSetNetworkInfo(info);
+ }
+}
+
+void CoreSession::removeNetwork(NetworkId id) {
+ // Make sure the network is disconnected!
+ NetworkConnection *conn = _connections.value(id, 0);
+ if(conn) {
+ if(conn->connectionState() != Network::Disconnected) {
+ connect(conn, SIGNAL(disconnected(NetworkId)), this, SLOT(destroyNetwork(NetworkId)));
+ conn->disconnectFromIrc();
+ } else {
+ _connections.take(id)->deleteLater(); // TODO make this saner
+ destroyNetwork(id);
+ }
+ } else {
+ destroyNetwork(id);
+ }
+}
+
+void CoreSession::destroyNetwork(NetworkId id) {
+ if(_connections.contains(id)) {
+ // this can happen if the network was reconnecting while being removed
+ _connections.take(id)->deleteLater();
+ }
+ QList<BufferId> removedBuffers = Core::requestBufferIdsForNetwork(user(), id);
+ Network *net = _networks.take(id);
+ if(net && Core::removeNetwork(user(), id)) {
+ foreach(BufferId bufferId, removedBuffers) {
+ _bufferSyncer->removeBuffer(bufferId);
+ }
+ emit networkRemoved(id);
+ net->deleteLater();
+ }
+}
+
+void CoreSession::removeBufferRequested(BufferId bufferId) {
+ BufferInfo bufferInfo = Core::getBufferInfo(user(), bufferId);
+ if(!bufferInfo.isValid()) {
+ quWarning() << "CoreSession::removeBufferRequested(): invalid BufferId:" << bufferId << "for User:" << user();
+ return;
+ }
+
+ if(bufferInfo.type() == BufferInfo::StatusBuffer) {
+ quWarning() << "CoreSession::removeBufferRequested(): Status Buffers cannot be removed!";
+ return;
+ }
+
+ if(bufferInfo.type() == BufferInfo::ChannelBuffer) {
+ CoreNetwork *net = network(bufferInfo.networkId());
+ if(!net) {
+ quWarning() << "CoreSession::removeBufferRequested(): Received BufferInfo with unknown networkId!";
+ return;
+ }
+ IrcChannel *chan = net->ircChannel(bufferInfo.bufferName());
+ if(chan) {
+ quWarning() << "CoreSession::removeBufferRequested(): Unable to remove Buffer for joined Channel:" << bufferInfo.bufferName();
+ return;
+ }
+ }
+ if(Core::removeBuffer(user(), bufferId))
+ emit bufferRemoved(bufferId);
+}
+
+void CoreSession::renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName) {
+ BufferId bufferId = Core::renameBuffer(user(), networkId, newName, oldName);
+ if(bufferId.isValid()) {
+ emit bufferRenamed(bufferId, newName);
+ }
+}