Show channel-specific modes in nick tooltips
authorShane Synan <digitalcircuit36939@gmail.com>
Thu, 10 Mar 2016 03:47:27 +0000 (21:47 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 13 Jun 2016 20:36:10 +0000 (22:36 +0200)
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

src/client/networkmodel.cpp
src/client/networkmodel.h

index 1edbb24..6434969 100644 (file)
@@ -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 << "<table cellspacing='5' cellpadding='0'>";
+    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<UserCategoryItem *>(parent());
+    if (!category)
+        return QString();
+
+    ChannelBufferItem *channel = qobject_cast<ChannelBufferItem *>(category->parent());
+    if (!channel)
+        return QString();
+
+    return channel->nickChannelModes(nickName());
+}
+
 
 /*****************************************
  * NetworkModel
index cc230d0..b2d3a3b 100644 (file)
@@ -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<IrcUser *> &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); }