Simplify clean-up-on-network-disconnect handling
[quassel.git] / src / client / networkmodel.cpp
index a38ed11..dc985bd 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-09 by the Quassel Project                          *
+ *   Copyright (C) 2005-2014 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -15,7 +15,7 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
 #include "networkmodel.h"
@@ -153,7 +153,7 @@ void NetworkItem::attachNetwork(Network *network)
     connect(network, SIGNAL(connectedSet(bool)),
         this, SIGNAL(networkDataChanged()));
     connect(network, SIGNAL(destroyed()),
-        this, SIGNAL(networkDataChanged()));
+        this, SLOT(onNetworkDestroyed()));
 
     emit networkDataChanged();
 }
@@ -233,6 +233,14 @@ void NetworkItem::onBeginRemoveChilds(int start, int end)
 }
 
 
+void NetworkItem::onNetworkDestroyed()
+{
+    _network = 0;
+    emit networkDataChanged();
+    removeAllChilds();
+}
+
+
 /*****************************************
 *  Fancy Buffer Items
 *****************************************/
@@ -520,8 +528,10 @@ void QueryBufferItem::setIrcUser(IrcUser *ircUser)
     }
 
     if (ircUser) {
+        connect(ircUser, SIGNAL(destroyed(QObject*)), SLOT(removeIrcUser()));
         connect(ircUser, SIGNAL(quited()), this, SLOT(removeIrcUser()));
         connect(ircUser, SIGNAL(awaySet(bool)), this, SIGNAL(dataChanged()));
+        connect(ircUser, SIGNAL(encryptedSet(bool)), this, SLOT(setEncrypted(bool)));
     }
 
     _ircUser = ircUser;
@@ -594,12 +604,19 @@ QString ChannelBufferItem::toolTip(int column) const
 
 void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel)
 {
-    Q_ASSERT(!_ircChannel && ircChannel);
+    if (_ircChannel) {
+        qWarning() << Q_FUNC_INFO << "IrcChannel already set; cleanup failed!?";
+        disconnect(_ircChannel, 0, this, 0);
+    }
 
     _ircChannel = ircChannel;
 
+    connect(ircChannel, SIGNAL(destroyed(QObject*)),
+        this, SLOT(ircChannelDestroyed()));
     connect(ircChannel, SIGNAL(topicSet(QString)),
         this, SLOT(setTopic(QString)));
+    connect(ircChannel, SIGNAL(encryptedSet(bool)),
+        this, SLOT(setEncrypted(bool)));
     connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *> )),
         this, SLOT(join(QList<IrcUser *> )));
     connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
@@ -630,6 +647,16 @@ void ChannelBufferItem::ircChannelParted()
 }
 
 
+void ChannelBufferItem::ircChannelDestroyed()
+{
+    if (_ircChannel) {
+        _ircChannel = 0;
+        emit dataChanged();
+        removeAllChilds();
+    }
+}
+
+
 void ChannelBufferItem::join(const QList<IrcUser *> &ircUsers)
 {
     addUsersToCategory(ircUsers);