summaryrefslogtreecommitdiffstats
path: root/src/modules/torrent/tc_statusbarapplet.cpp
blob: 45b32dba1916d542b2b2aae85e20f278eb6ea0ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "tqtimer.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)
{
	TQTimer *timer = new TQTimer(this);
	connect(timer, TQT_SIGNAL(timeout()), this, TQT_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);
}

TQString formatSize(float sz)
{
	if (sz >= 1024.0f*1024.0f*1024.0f)
		return TQString("%1 GB").tqarg(sz / (1024.0f*1024.0f*1024.0f), 2, 'f', 2);
	if (sz >= 1024.0f*1024.0f)
		return TQString("%1 MB").tqarg(sz / (1024.0f*1024.0f), 2, 'f', 2);
	if (sz >= 1024.0f)
		return TQString("%1 KB").tqarg(sz / 1024.0f, 2, 'f', 2);
	return TQString("%1 B").tqarg(sz, 2, 'f', 2);
}

void KviTorrentStatusBarApplet::update()
{
	if (KviTorrentInterface::selected())
	{
		TQString msg = TQString("up: %1 K/s (%2), dn: %3 K/s (%4)")
					.tqarg(KviTorrentInterface::selected()->speedUp(), 2)
					.tqarg(formatSize(KviTorrentInterface::selected()->trafficUp()))
					.tqarg(KviTorrentInterface::selected()->speedDown(), 2)
					.tqarg(formatSize(KviTorrentInterface::selected()->trafficDown()));

		setText(msg);

	} else
	{
		setText(__tr2qs_ctx("No client selected!", "torrent"));
	}
}

#include "tc_statusbarapplet.moc"