Hide network tooltip info when disconnected
[quassel.git] / src / client / networkmodel.cpp
index 6434969..bba2175 100644 (file)
@@ -224,7 +224,7 @@ QString NetworkItem::toolTip(int column) const
     Q_UNUSED(column);
     QString strTooltip;
     QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
-    tooltip << "<qt><style>.bold { font-weight: bold; }</style>";
+    tooltip << "<qt><style>.bold { font-weight: bold; } .italic { font-style: italic; }</style>";
 
     // Function to add a row to the tooltip table
     auto addRow = [&](const QString& key, const QString& value, bool condition) {
@@ -234,15 +234,18 @@ QString NetworkItem::toolTip(int column) const
     };
 
     tooltip << "<p class='bold' align='center'>" << NetworkItem::escapeHTML(networkName(), true) << "</p>";
-    tooltip << "<table cellspacing='5' cellpadding='0'>";
-    addRow(tr("Server"), NetworkItem::escapeHTML(currentServer(), true), true);
-
-    addRow(tr("Users"), QString::number(nickCount()), true);
-
-    if (_network)
-        addRow(tr("Lag"), NetworkItem::escapeHTML(tr("%1 msecs").arg(_network->latency()), true), true);
+    if (isActive()) {
+        tooltip << "<table cellspacing='5' cellpadding='0'>";
+        addRow(tr("Server"), NetworkItem::escapeHTML(currentServer(), true), !currentServer().isEmpty());
+        addRow(tr("Users"), QString::number(nickCount()), true);
+        if (_network)
+            addRow(tr("Lag"), NetworkItem::escapeHTML(tr("%1 msecs").arg(_network->latency()), true), true);
 
-    tooltip << "</table></qt>";
+        tooltip << "</table>";
+    } else {
+        tooltip << "<p class='italic' align='center'>" << tr("Not connected") << "</p>";
+    }
+    tooltip << "</qt>";
     return strTooltip;
 }
 
@@ -569,12 +572,33 @@ QString QueryBufferItem::toolTip(int column) const
                    NetworkItem::escapeHTML(_ircUser->suserHost()),
                    !_ircUser->suserHost().isEmpty());
         }
+
+        // Keep track of whether or not the account information's been added.  Don't show it twice.
+        bool accountAdded = false;
+        if(!_ircUser->account().isEmpty()) {
+            // IRCv3 account-notify is supported by the core and IRC server.
+            // Assume logged out (seems to be more common)
+            QString accountHTML = QString("<p class='italic'>%1</p>").arg(tr("Not logged in"));
+
+            // If account is logged in, replace with the escaped account name.
+            if (_ircUser->account() != "*") {
+                accountHTML = NetworkItem::escapeHTML(_ircUser->account());
+            }
+            addRow(NetworkItem::escapeHTML(tr("Account"), true),
+                   accountHTML,
+                   true);
+            // Mark the row as added
+            accountAdded = true;
+        }
         // whoisServiceReply may return "<nick> is identified for this nick", which should be translated.
         // See https://www.alien.net.au/irc/irc2numerics.html
         if(_ircUser->whoisServiceReply().endsWith("identified for this nick")) {
             addRow(NetworkItem::escapeHTML(tr("Account"), true),
                    NetworkItem::escapeHTML(tr("Identified for this nick")),
-                   true);
+                   !accountAdded);
+            // Don't add the account row again if information's already added via account-notify
+            // Mark the row as added
+            accountAdded = true;
         } else {
             addRow(NetworkItem::escapeHTML(tr("Service Reply"), true),
                    NetworkItem::escapeHTML(_ircUser->whoisServiceReply()),
@@ -1100,12 +1124,33 @@ QString IrcUserItem::toolTip(int column) const
                NetworkItem::escapeHTML(_ircUser->suserHost()),
                !_ircUser->suserHost().isEmpty());
     }
+
+    // Keep track of whether or not the account information's been added.  Don't show it twice.
+    bool accountAdded = false;
+    if(!_ircUser->account().isEmpty()) {
+        // IRCv3 account-notify is supported by the core and IRC server.
+        // Assume logged out (seems to be more common)
+        QString accountHTML = QString("<p class='italic'>%1</p>").arg(tr("Not logged in"));
+
+        // If account is logged in, replace with the escaped account name.
+        if (_ircUser->account() != "*") {
+            accountHTML = NetworkItem::escapeHTML(_ircUser->account());
+        }
+        addRow(NetworkItem::escapeHTML(tr("Account"), true),
+               accountHTML,
+               true);
+        // Mark the row as added
+        accountAdded = true;
+    }
     // whoisServiceReply may return "<nick> is identified for this nick", which should be translated.
     // See https://www.alien.net.au/irc/irc2numerics.html
     if(_ircUser->whoisServiceReply().endsWith("identified for this nick")) {
         addRow(NetworkItem::escapeHTML(tr("Account"), true),
                NetworkItem::escapeHTML(tr("Identified for this nick")),
-               true);
+               !accountAdded);
+        // Don't add the account row again if information's already added via account-notify
+        // Mark the row as added
+        accountAdded = true;
     } else {
         addRow(NetworkItem::escapeHTML(tr("Service Reply"), true),
                NetworkItem::escapeHTML(_ircUser->whoisServiceReply()),