+void CoreSession::removeNetwork(NetworkId id) {
+ // Make sure the network is disconnected!
+ CoreNetwork *net = network(id);
+ if(!net)
+ return;
+
+ if(net->connectionState() != Network::Disconnected) {
+ connect(net, SIGNAL(disconnected(NetworkId)), this, SLOT(destroyNetwork(NetworkId)));
+ net->disconnectFromIrc();
+ } else {
+ destroyNetwork(id);
+ }
+}
+
+void CoreSession::destroyNetwork(NetworkId id) {
+ 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()) {
+ qWarning() << "CoreSession::removeBufferRequested(): invalid BufferId:" << bufferId << "for User:" << user();
+ return;
+ }
+
+ if(bufferInfo.type() == BufferInfo::StatusBuffer) {
+ qWarning() << "CoreSession::removeBufferRequested(): Status Buffers cannot be removed!";
+ return;
+ }
+
+ if(bufferInfo.type() == BufferInfo::ChannelBuffer) {
+ CoreNetwork *net = network(bufferInfo.networkId());
+ if(!net) {
+ qWarning() << "CoreSession::removeBufferRequested(): Received BufferInfo with unknown networkId!";
+ return;
+ }
+ IrcChannel *chan = net->ircChannel(bufferInfo.bufferName());
+ if(chan) {
+ qWarning() << "CoreSession::removeBufferRequested(): Unable to remove Buffer for joined Channel:" << bufferInfo.bufferName();
+ return;
+ }
+ }
+ if(Core::removeBuffer(user(), bufferId))
+ emit bufferRemoved(bufferId);
+}
+
+// FIXME: use a coreBufferSyncer for this
+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);