From f3ec123b887a5b6f04bd3631d02fd94a90a8c5ad Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 8 Nov 2010 12:25:49 +0000 Subject: [PATCH] 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 --- .../src/gui/statusbar/dhtstatus.cpp | 33 +++++++++------ retroshare-gui/src/lang/retroshare_de.qm | Bin 277240 -> 277384 bytes retroshare-gui/src/lang/retroshare_de.ts | 32 +++++++++++++-- retroshare-gui/src/util/misc.h | 38 ++++++++++++++++++ 4 files changed, 87 insertions(+), 16 deletions(-) diff --git a/retroshare-gui/src/gui/statusbar/dhtstatus.cpp b/retroshare-gui/src/gui/statusbar/dhtstatus.cpp index 661164bb4..7939955b9 100644 --- a/retroshare-gui/src/gui/statusbar/dhtstatus.cpp +++ b/retroshare-gui/src/gui/statusbar/dhtstatus.cpp @@ -28,6 +28,8 @@ #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" +#include "util/misc.h" + #include #include @@ -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")); + + spaceLabel->setVisible(false); + dhtnetworkLabel->setVisible(false); + dhtnetworksizeLabel->setVisible(false); + + dhtnetworksizeLabel->setText(""); + dhtnetworksizeLabel->setToolTip(""); } - QString dhtsize; - { - std::ostringstream out; - out << (int) config.netDhtRsNetSize << " ( " << (int) config.netDhtNetSize << " )"; - dhtsize = QString::fromStdString(out.str()); - } - - dhtnetworksizeLabel->setText(dhtsize); - dhtnetworksizeLabel->setToolTip(tr("RetroShare users in DHT (Total DHT users)") ); - rsiface->unlockData(); /* UnLock Interface */ } diff --git a/retroshare-gui/src/lang/retroshare_de.qm b/retroshare-gui/src/lang/retroshare_de.qm index 6d006fcf1c1d964aee8808643376479de8142ddd..c928d4d17cb40f401ce65dde497420ef79f0010a 100644 GIT binary patch delta 213 zcmezIRiNX$zyuM-6%$3R9ed@!j&N!vk{Wn2#p;eLm3$X DN0Baz delta 83 zcmeD9F7V^4zyuM-j)|gH8}qNqF!FD9m9-OR`g3=4tBDOKqyO~6M~n)Si|qubXYOJY nYG$=-XSHJlVy5k^cFgnsOxLt#5ueUy%@WSu!N9=4#K;H${!AJM diff --git a/retroshare-gui/src/lang/retroshare_de.ts b/retroshare-gui/src/lang/retroshare_de.ts index ba6a43d49..297a6a11c 100644 --- a/retroshare-gui/src/lang/retroshare_de.ts +++ b/retroshare-gui/src/lang/retroshare_de.ts @@ -2608,22 +2608,22 @@ p, li { white-space: pre-wrap; } DHTStatus - + DHT DHT - + DHT On DHT An - + DHT Off DHT aus - + RetroShare users in DHT (Total DHT users) RetroShare Nutzer in DHT (Totale DHT Nutzer) @@ -11529,5 +11529,29 @@ p, li { white-space: pre-wrap; } e.g: 2 years 2days + + + k + e.g: 3.1 k + k + + + + M + e.g: 3.1 M + M + + + + G + e.g: 3.1 G + G + + + + T + e.g: 3.1 T + T + diff --git a/retroshare-gui/src/util/misc.h b/retroshare-gui/src/util/misc.h index 57cf5ebd8..d9054827f 100644 --- a/retroshare-gui/src/util/misc.h +++ b/retroshare-gui/src/util/misc.h @@ -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