From: Shane Synan Date: Thu, 10 Mar 2016 03:47:27 +0000 (-0600) Subject: Show channel-specific modes in nick tooltips X-Git-Tag: travis-deploy-test~479 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=2261829376bf9f404f2b27e77050202e9bb3b1ca Show channel-specific modes in nick tooltips Add a row labeled Modes for channel modes applied to a user. This fixes channel modes not showing (more noticeable with multi-prefix). Channel modes are found with the parent of the parent of the IrcUserItem, in order of UserCategoryItem -> ChannelBufferItem. Closes GH-186, finishes the fix in pull request GH-188 --- diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 1edbb241..64349690 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -744,6 +744,16 @@ void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel) emit dataChanged(); } +QString ChannelBufferItem::nickChannelModes(const QString &nick) const +{ + if (!_ircChannel) { + qDebug() << Q_FUNC_INFO << "IrcChannel not set, can't get user modes"; + return QString(); + } + + return _ircChannel->userModes(nick); +} + void ChannelBufferItem::ircChannelParted() { @@ -1065,6 +1075,9 @@ QString IrcUserItem::toolTip(int column) const }; tooltip << ""; + addRow(tr("Modes"), + NetworkItem::escapeHTML(channelModes()), + !channelModes().isEmpty()); if (_ircUser->isAway()) { QString awayMessage(tr("(unknown)")); if(!_ircUser->awayMessage().isEmpty()) { @@ -1128,6 +1141,21 @@ QString IrcUserItem::toolTip(int column) const return strTooltip; } +QString IrcUserItem::channelModes() const +{ + // IrcUserItems are parented to UserCategoryItem, which are parented to ChannelBufferItem. + // We want the channel buffer item in order to get the channel-specific user modes. + UserCategoryItem *category = qobject_cast(parent()); + if (!category) + return QString(); + + ChannelBufferItem *channel = qobject_cast(category->parent()); + if (!channel) + return QString(); + + return channel->nickChannelModes(nickName()); +} + /***************************************** * NetworkModel diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index cc230d02..b2d3a3b8 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -213,6 +213,14 @@ public: void attachIrcChannel(IrcChannel *ircChannel); + /** + * Gets the list of channel modes for a given nick. + * + * @param[in] nick IrcUser nickname to check + * @returns Channel modes as a string if any, otherwise empty string + */ + QString nickChannelModes(const QString &nick) const; + public slots: void join(const QList &ircUsers); void part(IrcUser *ircUser); @@ -279,6 +287,13 @@ public : virtual QVariant data(int column, int role) const; virtual QString toolTip(int column) const; + /** + * Gets the list of channel modes for this nick if parented to channel. + * + * @returns Channel modes as a string if any, otherwise empty string + */ + QString channelModes() const; + private slots: inline void ircUserQuited() { parent()->removeChild(this); }