Hide network tooltip info when disconnected
authorShane Synan <digitalcircuit36939@gmail.com>
Tue, 14 Jun 2016 13:39:31 +0000 (09:39 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 5 Sep 2016 19:50:44 +0000 (21:50 +0200)
Remove network information from tooltip when disconnected, showing a
"Not connected" line instead.

Don't show the server name if empty.

This fixes a slightly confusing state where the tooltip implies the
network's connected when it's actually not.

src/client/networkmodel.cpp

index aea48bf..bba2175 100644 (file)
@@ -224,7 +224,7 @@ QString NetworkItem::toolTip(int column) const
     Q_UNUSED(column);
     QString strTooltip;
     QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
     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) {
 
     // 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 << "<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;
 }
 
     return strTooltip;
 }