Switch some dirty hacking to using real infrastructure. A Chatline now contains three...
[quassel.git] / src / client / networkmodel.cpp
index 713198a..940feb7 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "util.h" // get rid of this (needed for isChannelName)
 
-
 /*****************************************
 *  Fancy Buffer Items
 *****************************************/
@@ -41,7 +40,8 @@ BufferItem::BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent)
   : PropertyMapItem(QStringList() << "bufferName" << "topic" << "nickCount", parent),
     _bufferInfo(bufferInfo),
     _bufferName(bufferInfo.bufferName()),
-    _activity(Buffer::NoActivity)
+    _activity(Buffer::NoActivity),
+    _ircChannel(0)
 {
   Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
   if(bufferType() == BufferInfo::QueryBuffer)
@@ -69,10 +69,11 @@ bool BufferItem::isActive() const {
     return qobject_cast<NetworkItem *>(parent())->isActive();
 }
 
-bool BufferItem::setActivityLevel(Buffer::ActivityLevel level) {
-  _activity = level;
-  emit dataChanged();
-  return true;
+void BufferItem::setActivityLevel(Buffer::ActivityLevel level) {
+  if(_activity != level) {
+    _activity = level;
+    emit dataChanged();
+  }
 }
 
 void BufferItem::updateActivityLevel(Buffer::ActivityLevel level) {
@@ -106,7 +107,8 @@ QVariant BufferItem::data(int column, int role) const {
 bool BufferItem::setData(int column, const QVariant &value, int role) {
   switch(role) {
   case NetworkModel::BufferActivityRole:
-    return setActivityLevel((Buffer::ActivityLevel)value.toInt());
+    setActivityLevel((Buffer::ActivityLevel)value.toInt());
+    return true;
   default:
     return PropertyMapItem::setData(column, value, role);
   }
@@ -144,6 +146,9 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) {
 }
 
 void BufferItem::ircChannelDestroyed() {
+  Q_CHECK_PTR(_ircChannel);
+  disconnect(_ircChannel, 0, this, 0);
+  _ircChannel = 0;
   emit dataChanged();
   removeAllChilds();
 }
@@ -414,7 +419,9 @@ void NetworkItem::attachNetwork(Network *network) {
          this, SLOT(attachIrcChannel(QString)));
   connect(network, SIGNAL(connectedSet(bool)),
          this, SIGNAL(dataChanged()));
-
+  connect(network, SIGNAL(destroyed()),
+         this, SIGNAL(dataChanged()));
+  
   emit dataChanged();
 }