diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
commit | a6d58bb6052ac8cb01805a48c4ad2f129126116f (patch) | |
tree | dd867a099fcbb263a8009a9fb22695b87855dad6 /src/modules/torrent/tc_statusbarapplet.cpp | |
download | kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip |
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/modules/torrent/tc_statusbarapplet.cpp')
-rw-r--r-- | src/modules/torrent/tc_statusbarapplet.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/modules/torrent/tc_statusbarapplet.cpp b/src/modules/torrent/tc_statusbarapplet.cpp new file mode 100644 index 00000000..5d23a299 --- /dev/null +++ b/src/modules/torrent/tc_statusbarapplet.cpp @@ -0,0 +1,69 @@ +#include "qtimer.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "tc_interface.h" +#include "tc_statusbarapplet.h" + +KviTorrentStatusBarApplet::KviTorrentStatusBarApplet(KviStatusBar *parent, KviStatusBarAppletDescriptor *desc) + : KviStatusBarApplet(parent, desc) +{ + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(250, FALSE); +// updateDisplay(); +// + setText("torrent client"); +} + +KviTorrentStatusBarApplet::~KviTorrentStatusBarApplet() +{ +} + +static KviStatusBarApplet *CreateTorrentClientApplet(KviStatusBar *bar, KviStatusBarAppletDescriptor *desc) +{ + debug("CreateTorrentClientApplet"); + return new KviTorrentStatusBarApplet(bar, desc); +} + +void KviTorrentStatusBarApplet::selfRegister(KviStatusBar *bar) +{ + KviStatusBarAppletDescriptor *d = new KviStatusBarAppletDescriptor( + __tr2qs("Torrent Client"), + "torrentapplet", + CreateTorrentClientApplet, + "torrent", *(g_pIconManager->getSmallIcon(KVI_SMALLICON_AWAY))); + + bar->registerAppletDescriptor(d); +} + +QString formatSize(float sz) +{ + if (sz >= 1024.0f*1024.0f*1024.0f) + return QString("%1 GB").arg(sz / (1024.0f*1024.0f*1024.0f), 2, 'f', 2); + if (sz >= 1024.0f*1024.0f) + return QString("%1 MB").arg(sz / (1024.0f*1024.0f), 2, 'f', 2); + if (sz >= 1024.0f) + return QString("%1 KB").arg(sz / 1024.0f, 2, 'f', 2); + return QString("%1 B").arg(sz, 2, 'f', 2); +} + +void KviTorrentStatusBarApplet::update() +{ + if (KviTorrentInterface::selected()) + { + QString msg = QString("up: %1 K/s (%2), dn: %3 K/s (%4)") + .arg(KviTorrentInterface::selected()->speedUp(), 2) + .arg(formatSize(KviTorrentInterface::selected()->trafficUp())) + .arg(KviTorrentInterface::selected()->speedDown(), 2) + .arg(formatSize(KviTorrentInterface::selected()->trafficDown())); + + setText(msg); + + } else + { + setText(__tr2qs_ctx("No client selected!", "torrent")); + } +} + +#include "tc_statusbarapplet.moc" + |