mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 20:04:24 -04:00
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:
parent
a98367f188
commit
f3ec123b88
4 changed files with 87 additions and 16 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue