Show the user count of DHT in an userfriendly format.

Hide user count when DHT is off.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3761 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-11-08 12:25:49 +00:00
parent a98367f188
commit f3ec123b88
4 changed files with 87 additions and 16 deletions

View File

@ -28,6 +28,8 @@
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "util/misc.h"
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
@ -46,13 +48,16 @@ DHTStatus::DHTStatus(QWidget *parent)
hbox->addWidget(dhtstatusLabel); hbox->addWidget(dhtstatusLabel);
spaceLabel = new QLabel( " | ", this ); spaceLabel = new QLabel( " | ", this );
spaceLabel->setVisible(false);
hbox->addWidget(spaceLabel); hbox->addWidget(spaceLabel);
dhtnetworkLabel = new QLabel( this ); dhtnetworkLabel = new QLabel( this );
dhtnetworkLabel->setVisible(false);
dhtnetworkLabel->setPixmap(QPixmap(":/images/dht16.png")); dhtnetworkLabel->setPixmap(QPixmap(":/images/dht16.png"));
hbox->addWidget(dhtnetworkLabel); hbox->addWidget(dhtnetworkLabel);
dhtnetworksizeLabel = new QLabel( "0 (0) ",this ); dhtnetworksizeLabel = new QLabel( "0 (0) ",this );
dhtnetworksizeLabel->setVisible(false);
hbox->addWidget(dhtnetworksizeLabel); hbox->addWidget(dhtnetworksizeLabel);
hbox->addSpacing(2); hbox->addSpacing(2);
@ -71,22 +76,26 @@ void DHTStatus::getDHTStatus()
{ {
dhtstatusLabel->setPixmap(QPixmap(":/images/greenled.png")); dhtstatusLabel->setPixmap(QPixmap(":/images/greenled.png"));
dhtstatusLabel->setToolTip(tr("DHT On")); dhtstatusLabel->setToolTip(tr("DHT On"));
spaceLabel->setVisible(true);
dhtnetworkLabel->setVisible(true);
dhtnetworksizeLabel->setVisible(true);
dhtnetworksizeLabel->setText(QString("%1 (%2)").arg(misc::userFriendlyUnit(config.netDhtRsNetSize, 1)).arg(misc::userFriendlyUnit(config.netDhtNetSize, 1)));
dhtnetworksizeLabel->setToolTip(tr("RetroShare users in DHT (Total DHT users)") );
} }
else else
{ {
dhtstatusLabel->setPixmap(QPixmap(":/images/redled.png")); dhtstatusLabel->setPixmap(QPixmap(":/images/redled.png"));
dhtstatusLabel->setToolTip(tr("DHT Off")); dhtstatusLabel->setToolTip(tr("DHT Off"));
}
QString dhtsize; spaceLabel->setVisible(false);
{ dhtnetworkLabel->setVisible(false);
std::ostringstream out; dhtnetworksizeLabel->setVisible(false);
out << (int) config.netDhtRsNetSize << " ( " << (int) config.netDhtNetSize << " )";
dhtsize = QString::fromStdString(out.str());
}
dhtnetworksizeLabel->setText(dhtsize); dhtnetworksizeLabel->setText("");
dhtnetworksizeLabel->setToolTip(tr("RetroShare users in DHT (Total DHT users)") ); dhtnetworksizeLabel->setToolTip("");
}
rsiface->unlockData(); /* UnLock Interface */ rsiface->unlockData(); /* UnLock Interface */
} }

View File

@ -2608,22 +2608,22 @@ p, li { white-space: pre-wrap; }
<context> <context>
<name>DHTStatus</name> <name>DHTStatus</name>
<message> <message>
<location filename="../gui/statusbar/dhtstatus.cpp" line="+41"/> <location filename="../gui/statusbar/dhtstatus.cpp" line="+43"/>
<source>DHT</source> <source>DHT</source>
<translation>DHT</translation> <translation>DHT</translation>
</message> </message>
<message> <message>
<location line="+32"/> <location line="+35"/>
<source>DHT On</source> <source>DHT On</source>
<translation>DHT An</translation> <translation>DHT An</translation>
</message> </message>
<message> <message>
<location line="+5"/> <location line="+12"/>
<source>DHT Off</source> <source>DHT Off</source>
<translation>DHT aus</translation> <translation>DHT aus</translation>
</message> </message>
<message> <message>
<location line="+11"/> <location line="-5"/>
<source>RetroShare users in DHT (Total DHT users)</source> <source>RetroShare users in DHT (Total DHT users)</source>
<translation>RetroShare Nutzer in DHT (Totale DHT Nutzer)</translation> <translation>RetroShare Nutzer in DHT (Totale DHT Nutzer)</translation>
</message> </message>
@ -11529,5 +11529,29 @@ p, li { white-space: pre-wrap; }
<comment>e.g: 2 years 2days </comment> <comment>e.g: 2 years 2days </comment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<location line="+26"/>
<source>k</source>
<comment>e.g: 3.1 k</comment>
<translation>k</translation>
</message>
<message>
<location line="+3"/>
<source>M</source>
<comment>e.g: 3.1 M</comment>
<translation>M</translation>
</message>
<message>
<location line="+3"/>
<source>G</source>
<comment>e.g: 3.1 G</comment>
<translation>G</translation>
</message>
<message>
<location line="+3"/>
<source>T</source>
<comment>e.g: 3.1 T</comment>
<translation>T</translation>
</message>
</context> </context>
</TS> </TS>

View File

@ -326,6 +326,44 @@ class misc : public QObject{
days = days - years * 365; days = days - years * 365;
return tr("%1y %2d", "e.g: 2 years 2days ").arg(QString::fromUtf8(misc::toString(years).c_str())).arg(QString::fromUtf8(misc::toString(days).c_str())); return tr("%1y %2d", "e.g: 2 years 2days ").arg(QString::fromUtf8(misc::toString(years).c_str())).arg(QString::fromUtf8(misc::toString(days).c_str()));
} }
static QString userFriendlyUnit(double count, unsigned int decimal, double factor = 1000)
{
if (count <= 0.0) {
return "0";
}
QString output;
int i;
for (i = 0; i < 5; i++) {
if (count < factor) {
break;
}
count /= factor;
}
QString unit;
switch (i) {
case 0:
decimal = 0; // no decimal
break;
case 1:
unit = tr("k", "e.g: 3.1 k");
break;
case 2:
unit = tr("M", "e.g: 3.1 M");
break;
case 3:
unit = tr("G", "e.g: 3.1 G");
break;
default: // >= 4
unit = tr("T", "e.g: 3.1 T");
}
return QString("%1 %2").arg(count, 0, 'f', decimal).arg(unit);
}
}; };
// Trick to get a portable sleep() function // Trick to get a portable sleep() function