X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.cpp;h=0582d44c6776c48671cae4fa694567219b2dc0e8;hp=05340a36becd126398b10aea92ef9d0d0a217df2;hb=56607f81246f04db3a0e71c9a8757d7f75d6cfcf;hpb=bd1a18355495899b5ce3003599a67e1ea7ca01cc diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 05340a36..0582d44c 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -29,8 +29,12 @@ #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)), + this, SLOT(join(QList))); 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 &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); +} + +void BufferItem::addUsersToCategory(const QList &ircUsers) { Q_ASSERT(_ircChannel); - UserCategoryItem *categoryItem; - int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser)); - if(!(categoryItem = qobject_cast(childById(qHash(categoryId))))) { - categoryItem = new UserCategoryItem(categoryId, this); - newChild(categoryItem); + QHash > categories; + foreach(IrcUser *ircUser, ircUsers) { + UserCategoryItem *categoryItem; + int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser)); + if(!(categoryItem = qobject_cast(childById(qHash(categoryId))))) { + categoryItem = new UserCategoryItem(categoryId, this); + categories[categoryItem] = QList(); + newChild(categoryItem); + } + categories[categoryItem] << ircUser; } - categoryItem->addUser(ircUser); - int totalusers = 0; - for(int i = 0; i < childCount(); i++) { - totalusers += child(i)->childCount(); + QHash >::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) { @@ -282,6 +290,49 @@ void BufferItem::userModeChanged(IrcUser *ircUser) { addUserToCategory(ircUser); } +QString BufferItem::toolTip(int column) const { + Q_UNUSED(column); + QStringList toolTip; + + switch(bufferType()) { + case BufferInfo::StatusBuffer: { + QString netName = Client::network(bufferInfo().networkId())->networkName(); + toolTip.append(QString("Status buffer from %1").arg(netName)); + break; + } + case BufferInfo::ChannelBuffer: + toolTip.append(QString("

Channel %1

").arg(bufferName())); + if(isActive()) { + //TODO: add channel modes + toolTip.append(QString("Users: %1").arg(nickCount())); + + BufferSettings s; + bool showTopic = s.value("DisplayTopicInTooltip", QVariant(false)).toBool(); + if(showTopic) { + QString _topic = topic(); + if(_topic != "") { + _topic.replace(QString("<"), QString("<")); + _topic.replace(QString(">"), QString(">")); + toolTip.append(QString(" ")); + toolTip.append(QString("Topic: %1").arg(_topic)); + } + } + } else { + toolTip.append(QString("Not active
Double-click to join")); + } + break; + case BufferInfo::QueryBuffer: + toolTip.append(QString("Query with %1").arg(bufferName())); + if(topic() != "") toolTip.append(QString("Away Message: %1").arg(topic())); + break; + default: //this should not happen + toolTip.append(QString("%1 - %2").arg(bufferInfo().bufferId().toInt()).arg(bufferName())); + break; + } + + return QString("

%1

").arg(toolTip.join("
")); +} + /* void BufferItem::setLastMsgInsert(QDateTime msgDate) { if(msgDate.isValid() && msgDate > _lastMsgInsert) @@ -405,6 +456,18 @@ void NetworkItem::setCurrentServer(const QString &serverName) { emit dataChanged(1); } + +QString NetworkItem::toolTip(int column) const { + Q_UNUSED(column); + + QStringList toolTip(QString("%1").arg(networkName())); + toolTip.append(QString("Server: %1").arg(currentServer())); + toolTip.append(QString("Users: %1").arg(nickCount())); + + return QString("

%1

").arg(toolTip.join("
")); +} + + /***************************************** * User Category Items (like @vh etc.) *****************************************/ @@ -437,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 &ircUsers) { + QList userItems; + foreach(IrcUser *ircUser, ircUsers) + userItems << new IrcUserItem(ircUser, this); + newChilds(userItems); } bool UserCategoryItem::removeUser(IrcUser *ircUser) { @@ -484,6 +550,8 @@ IrcUserItem::IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent) connect(ircUser, SIGNAL(nickSet(QString)), this, SLOT(setNick(QString))); + connect(ircUser, SIGNAL(awaySet(bool)), + this, SLOT(setAway(bool))); } QString IrcUserItem::nickName() const { @@ -567,6 +635,11 @@ void IrcUserItem::setNick(QString newNick) { emit dataChanged(0); } +void IrcUserItem::setAway(bool away) { + Q_UNUSED(away); + emit dataChanged(0); +} + /***************************************** * NetworkModel *****************************************/