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

View File

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

View File

@ -326,6 +326,44 @@ class misc : public QObject{
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()));
}
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