Yet another protocol break (I warned you...).
[quassel.git] / src / client / networkmodel.cpp
index a72b71e..0582d44 100644 (file)
 #include "ircchannel.h"
 #include "ircuser.h"
 
+#include "buffersettings.h"
+
 #include "util.h" // get rid of this (needed for isChannelName)
 
+// #define PHONDEV
+
 /*****************************************
 *  Fancy Buffer Items
 *****************************************/
@@ -127,8 +131,8 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) {
 
   connect(ircChannel, SIGNAL(topicSet(QString)),
          this, SLOT(setTopic(QString)));
-  connect(ircChannel, SIGNAL(ircUserJoined(IrcUser *)),
-         this, SLOT(join(IrcUser *)));
+  connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *>)),
+         this, SLOT(join(QList<IrcUser *>)));
   connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
          this, SLOT(part(IrcUser *)));
   connect(ircChannel, SIGNAL(destroyed()),
@@ -142,9 +146,7 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) {
 
   if(!ircChannel->ircUsers().isEmpty()) {
     qWarning() << "Channel" << ircChannel->name() << "has already users which is quite surprising :)";
-    foreach(IrcUser *ircUser, ircChannel->ircUsers()) {
-      join(ircUser);
-    }
+    join(ircChannel->ircUsers());
   }
   
   emit dataChanged();
@@ -196,30 +198,41 @@ void BufferItem::setTopic(const QString &topic) {
   emit dataChanged(1);
 }
 
-void BufferItem::join(IrcUser *ircUser) {
-  if(!ircUser)
-    return;
+void BufferItem::join(const QList<IrcUser *> &ircUsers) {
+  addUsersToCategory(ircUsers);
 
-  addUserToCategory(ircUser);
-  connect(ircUser, SIGNAL(destroyed()),
-         this, SLOT(ircUserDestroyed()));
+  foreach(IrcUser *ircUser, ircUsers) {
+    if(!ircUser)
+      continue;
+    connect(ircUser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed()));
+  }
+  
   emit dataChanged(2);
 }
 
 void BufferItem::addUserToCategory(IrcUser *ircUser) {
+  addUsersToCategory(QList<IrcUser *>() << ircUser);
+}
+
+void BufferItem::addUsersToCategory(const QList<IrcUser *> &ircUsers) {
   Q_ASSERT(_ircChannel);
 
-  UserCategoryItem *categoryItem;
-  int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser));
-  if(!(categoryItem = qobject_cast<UserCategoryItem *>(childById(qHash(categoryId))))) {
-    categoryItem = new UserCategoryItem(categoryId, this);
-    newChild(categoryItem);
+  QHash<UserCategoryItem *, QList<IrcUser *> > categories;
+  foreach(IrcUser *ircUser, ircUsers) {
+    UserCategoryItem *categoryItem;
+    int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser));
+    if(!(categoryItem = qobject_cast<UserCategoryItem *>(childById(qHash(categoryId))))) {
+      categoryItem = new UserCategoryItem(categoryId, this);
+      categories[categoryItem] = QList<IrcUser *>();
+      newChild(categoryItem);
+    }
+    categories[categoryItem] << ircUser;
   }
-  categoryItem->addUser(ircUser);
 
-  int totalusers = 0;
-  for(int i = 0; i < childCount(); i++) {
-    totalusers += child(i)->childCount();
+  QHash<UserCategoryItem *, QList<IrcUser *> >::const_iterator catIter = categories.constBegin();
+  while(catIter != categories.constEnd()) {
+    catIter.key()->addUsers(catIter.value());
+    catIter++;
   }
 }
 
@@ -263,11 +276,6 @@ void BufferItem::removeUserFromCategory(IrcUser *ircUser) {
     qDebug() << "==== End Of Childlist for Item:" << this << id() << bufferName() << "====";
   }
   Q_ASSERT(success);
-
-  int totalusers = 0;
-  for(int i = 0; i < childCount(); i++) {
-    totalusers += child(i)->childCount();
-  }
 }
 
 void BufferItem::userModeChanged(IrcUser *ircUser) {
@@ -293,10 +301,22 @@ QString BufferItem::toolTip(int column) const {
       break;
     }
     case BufferInfo::ChannelBuffer:
-      toolTip.append(QString("<b>Channel %1</b>").arg(bufferName()));
+      toolTip.append(QString("<h4>Channel %1</h4>").arg(bufferName()));
       if(isActive()) {
-        toolTip.append(QString("Topic: %1").arg(topic()));
-        toolTip.append(QString("Users: %1").arg(nickCount()));
+        //TODO: add channel modes 
+        toolTip.append(QString("<b>Users:</b> %1").arg(nickCount()));
+
+        BufferSettings s;
+        bool showTopic = s.value("DisplayTopicInTooltip", QVariant(false)).toBool();
+        if(showTopic) {
+          QString _topic = topic();
+          if(_topic != "") {
+            _topic.replace(QString("<"), QString("&lt;"));
+            _topic.replace(QString(">"), QString("&gt;"));
+            toolTip.append(QString("<font size='-2'>&nbsp;</font>"));
+            toolTip.append(QString("<b>Topic:</b> %1").arg(_topic));
+          }
+        }
       } else {
         toolTip.append(QString("Not active <br /> Double-click to join"));
       }
@@ -480,8 +500,11 @@ quint64 UserCategoryItem::id() const {
   return qHash(_category);
 }
 
-void UserCategoryItem::addUser(IrcUser *ircUser) {
-  newChild(new IrcUserItem(ircUser, this));
+void UserCategoryItem::addUsers(const QList<IrcUser *> &ircUsers) {
+  QList<AbstractTreeItem *> userItems;
+  foreach(IrcUser *ircUser, ircUsers)
+    userItems << new IrcUserItem(ircUser, this);
+  newChilds(userItems);
 }
 
 bool UserCategoryItem::removeUser(IrcUser *ircUser) {