X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.cpp;h=8b9dfad846061233aca85dda38024d58eedafbb4;hp=48a6b8c4c31a777d04a4c3ea72b0b3cbe3f86b5d;hb=b2cf1b73760eadbeb3452d8d2260e1dc876e6fe5;hpb=c4507cf512b6fd04e5c75a7ac00b9c2888fb646f diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 48a6b8c4..8b9dfad8 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -171,40 +171,42 @@ void BufferItem::join(IrcUser *ircUser) { void BufferItem::addUserToCategory(IrcUser *ircUser) { Q_ASSERT(_ircChannel); - + UserCategoryItem *categoryItem; int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser)); if(!(categoryItem = qobject_cast(childById(qHash(categoryId))))) { categoryItem = new UserCategoryItem(categoryId, this); emit newChild(categoryItem); } - categoryItem->addUser(ircUser); } void BufferItem::part(IrcUser *ircUser) { - Q_UNUSED(ircUser); + if(!ircUser) + return; + + removeUserFromCategory(ircUser); emit dataChanged(2); } void BufferItem::removeUserFromCategory(IrcUser *ircUser) { + Q_ASSERT(_ircChannel); + UserCategoryItem *categoryItem = 0; - IrcUserItem *userItem; for(int i = 0; i < childCount(); i++) { categoryItem = qobject_cast(child(i)); - if((userItem = qobject_cast(categoryItem->childById((quint64)ircUser)))) { - userItem->deleteLater(); - return; - } + categoryItem->removeChildById((quint64)ircUser); + if(categoryItem->childCount() == 0) + removeChild(i); } } void BufferItem::userModeChanged(IrcUser *ircUser) { Q_ASSERT(_ircChannel); - + UserCategoryItem *categoryItem; int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser)); - if((categoryItem = qobject_cast(childById(qHash(categoryId))))) + if((categoryItem = qobject_cast(childById(qHash(categoryId)))) && categoryItem->childById((quint64)(ircUser))) return; // already in the right category; removeUserFromCategory(ircUser); @@ -312,19 +314,18 @@ void NetworkItem::setCurrentServer(const QString &serverName) { *****************************************/ // we hardcode this even though we have PREFIX in network... but that wouldn't help with mapping modes to // category strings anyway. -const QList UserCategoryItem::categories = QList() << UserCategoryItem::Category('q', "Owners") - << UserCategoryItem::Category('a', "Admins") - << UserCategoryItem::Category('a', "Admins") - << UserCategoryItem::Category('o', "Operators") - << UserCategoryItem::Category('h', "Half-Ops") - << UserCategoryItem::Category('v', "Voiced"); +const QList UserCategoryItem::categories = QList() + << UserCategoryItem::Category('q', "Owners") + << UserCategoryItem::Category('a', "Admins") + << UserCategoryItem::Category('a', "Admins") + << UserCategoryItem::Category('o', "Operators") + << UserCategoryItem::Category('h', "Half-Ops") + << UserCategoryItem::Category('v', "Voiced"); UserCategoryItem::UserCategoryItem(int category, AbstractTreeItem *parent) : PropertyMapItem(QStringList() << "categoryId", parent), _category(category) { - connect(this, SIGNAL(childRemoved(int)), - this, SLOT(checkNoChilds())); } QString UserCategoryItem::categoryId() { @@ -334,11 +335,6 @@ QString UserCategoryItem::categoryId() { return QString("Users"); } -void UserCategoryItem::checkNoChilds() { - if(childCount() == 0) - deleteLater(); -} - quint64 UserCategoryItem::id() const { return qHash(_category); } @@ -362,14 +358,14 @@ IrcUserItem::IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent) : PropertyMapItem(QStringList() << "nickName", parent), _ircUser(ircUser) { - connect(ircUser, SIGNAL(destroyed()), - this, SLOT(ircUserDestroyed())); + // we don't need to handle the ircUser's destroyed signal since it's automatically removed + // by the IrcChannel::ircUserParted(); connect(ircUser, SIGNAL(nickSet(QString)), this, SLOT(setNick(QString))); } -QString IrcUserItem::nickName() { +QString IrcUserItem::nickName() const { return _ircUser->nick(); } @@ -381,13 +377,17 @@ quint64 IrcUserItem::id() const { return (quint64)_ircUser; } +QVariant IrcUserItem::data(int column, int role) const { + if(role != Qt::ToolTipRole) + return PropertyMapItem::data(column, role); + + return "

" + nickName() + "
" + _ircUser->hostmask() + "

"; +} + void IrcUserItem::setNick(QString newNick) { Q_UNUSED(newNick); emit dataChanged(0); } -void IrcUserItem::ircUserDestroyed() { - deleteLater(); -} /***************************************** * NetworkModel