properly handling disconnects - this might even fix an antique bug with duplicate...
[quassel.git] / src / core / coresession.cpp
index efdad6e..020950f 100644 (file)
@@ -71,7 +71,6 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
   p->attachSignal(this, SIGNAL(networkCreated(NetworkId)));
   p->attachSignal(this, SIGNAL(networkRemoved(NetworkId)));
   p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &)), this, SLOT(createNetwork(const NetworkInfo &)));
-  p->attachSlot(SIGNAL(updateNetwork(const NetworkInfo &)), this, SLOT(updateNetwork(const NetworkInfo &)));
   p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, SLOT(removeNetwork(NetworkId)));
 
   loadSettings();
@@ -230,11 +229,13 @@ void CoreSession::disconnectFromNetwork(NetworkId id) {
 void CoreSession::networkStateRequested() {
 }
 
-void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it in signal connections
-  QIODevice *device = qobject_cast<QIODevice *>(dev);
+void CoreSession::addClient(QIODevice *device) {
   if(!device) {
     quError() << "Invoking CoreSession::addClient with a QObject that is not a QIODevice!";
   } else {
+    // if the socket is an orphan, the signalProxy adopts it.
+    // -> we don't need to care about it anymore
+    device->setParent(0);
     signalProxy()->addPeer(device);
     QVariantMap reply;
     reply["MsgType"] = "SessionInit";
@@ -243,15 +244,15 @@ void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it
   }
 }
 
+void CoreSession::addClient(SignalProxy *proxy) {
+  signalProxy()->addPeer(proxy);
+  emit sessionState(sessionState());
+}
+
 void CoreSession::removeClient(QIODevice *iodev) {
-  // no checks for validity check - privateslot...
   QTcpSocket *socket = qobject_cast<QTcpSocket *>(iodev);
   if(socket)
     quInfo() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
-  else
-    quInfo() << "Local client disconnedted.";
-  disconnect(socket, 0, this, 0);
-  socket->deleteLater();
 }
 
 SignalProxy *CoreSession::signalProxy() const {
@@ -432,18 +433,8 @@ void CoreSession::createNetwork(const NetworkInfo &info_) {
     emit networkCreated(id);
   } else {
     quWarning() << qPrintable(tr("CoreSession::createNetwork(): Trying to create a network that already exists, updating instead!"));
-    updateNetwork(info);
-  }
-}
-
-// FIXME: move to CoreNetwork
-void CoreSession::updateNetwork(const NetworkInfo &info) {
-  if(!_networks.contains(info.networkId)) {
-    quWarning() << "Update request for unknown network received!";
-    return;
+    _networks[info.networkId]->requestSetNetworkInfo(info);
   }
-  _networks[info.networkId]->setNetworkInfo(info);
-  Core::updateNetwork(user(), info);
 }
 
 void CoreSession::removeNetwork(NetworkId id) {