fixed renaming issue for queries
[quassel.git] / src / client / networkmodel.cpp
index 94d90b8..6b1a785 100644 (file)
@@ -55,21 +55,13 @@ BufferItem::BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent)
   setFlags(flags);
 }
 
-const BufferInfo &BufferItem::bufferInfo() const {
-  return _bufferInfo;
-}
-
 quint64 BufferItem::id() const {
   return qHash(bufferInfo().bufferId());
 }
 
-bool BufferItem::isStatusBuffer() const {
-  return bufferType() == BufferInfo::StatusBuffer;
-}
-
-BufferInfo::Type BufferItem::bufferType() const {
-  return bufferInfo().type();
-}
+// bool BufferItem::isStatusBuffer() const {
+//   return bufferType() == BufferInfo::StatusBuffer;
+// }
 
 bool BufferItem::isActive() const {
   if(bufferType() == BufferInfo::ChannelBuffer)
@@ -131,8 +123,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()),
@@ -146,9 +138,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();
@@ -170,7 +160,7 @@ void BufferItem::setBufferName(const QString &name) {
   _bufferName = name;
   // as long as we need those bufferInfos, we have to update that one aswell.
   // pretty ugly though :/
-  _bufferInfo = BufferInfo(_bufferInfo.bufferId(), _bufferInfo.networkId(), _bufferInfo.type(), _bufferInfo.groupId(), _bufferInfo.bufferName());
+  _bufferInfo = BufferInfo(_bufferInfo.bufferId(), _bufferInfo.networkId(), _bufferInfo.type(), _bufferInfo.groupId(), name);
   emit dataChanged(0);
 }
 
@@ -200,30 +190,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++;
   }
 }
 
@@ -267,11 +268,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) {
@@ -419,8 +415,6 @@ void NetworkItem::attachNetwork(Network *network) {
          this, SLOT(attachIrcChannel(QString)));
   connect(network, SIGNAL(connectedSet(bool)),
          this, SIGNAL(dataChanged()));
-  
-  // FIXME: connect this and that...
 
   emit dataChanged();
 }
@@ -496,8 +490,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) {
@@ -589,11 +586,12 @@ QVariant IrcUserItem::data(int column, int role) const {
 QString IrcUserItem::toolTip(int column) const {
   Q_UNUSED(column);
   QStringList toolTip(QString("<b>%1</b>").arg(nickName()));
+  if(_ircUser->userModes() != "") toolTip[0].append(QString(" (%1)").arg(_ircUser->userModes()));
   if(_ircUser->isAway()) toolTip[0].append(" is away");
   if(!_ircUser->awayMessage().isEmpty()) toolTip[0].append(QString(" (%1)").arg(_ircUser->awayMessage()));
   if(!_ircUser->realName().isEmpty()) toolTip.append(_ircUser->realName());
   if(!_ircUser->ircOperator().isEmpty()) toolTip.append(_ircUser->ircOperator());
-  toolTip.append(_ircUser->hostmask());
+  toolTip.append(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!")+1));
 
   if(_ircUser->idleTime().isValid()) {
     QDateTime now = QDateTime::currentDateTime();
@@ -617,6 +615,9 @@ QString IrcUserItem::toolTip(int column) const {
     }
     toolTip.append(tr("idling since %1").arg(idleString));
   }
+  if(_ircUser->loginTime().isValid()) {
+    toolTip.append(tr("login time: %1").arg(_ircUser->loginTime().toString()));
+  }
 
   if(!_ircUser->server().isEmpty()) toolTip.append(tr("server: %1").arg(_ircUser->server()));