1
//=============================================================================
3
// StatuBar for Torrent client.
5
// File : StatusBarApplet.cpp
6
// Creation date : Fri Jan 1 15:42:25 2007 GMT by Alexander Stillich
8
// This file is part of the KVIrc irc client distribution
9
// Copyright (C) 2007-2008 Alexander Stillich (torque at pltn dot org)
11
// This program is FREE software. You can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your opinion) any later version.
16
// This program is distributed in the HOPE that it will be USEFUL,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
// See the GNU General Public License for more details.
21
// You should have received a copy of the GNU General Public License
22
// along with this program. If not, write to the Free Software Foundation,
23
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
//=============================================================================
27
#include "TorrentInterface.h"
28
#include "StatusBarApplet.h"
30
#include "KviLocale.h"
31
#include "KviIconManager.h"
35
StatusBarApplet::StatusBarApplet(KviStatusBar *parent, KviStatusBarAppletDescriptor *desc)
36
: KviStatusBarApplet(parent, desc)
38
QTimer *timer = new QTimer(this);
39
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
40
timer->setInterval(250);
41
timer->setSingleShot(false);
44
setText(__tr2qs_ctx("Torrent Client","torrent"));
47
StatusBarApplet::~StatusBarApplet()
51
static KviStatusBarApplet *CreateTorrentClientApplet(KviStatusBar *bar, KviStatusBarAppletDescriptor *desc)
53
KviStatusBarApplet * pApplet = new StatusBarApplet(bar, desc);
54
pApplet->setIndex(bar->insertPermanentWidgetAtTheEnd(pApplet));
58
void StatusBarApplet::selfRegister(KviStatusBar *bar)
60
KviStatusBarAppletDescriptor *d = new KviStatusBarAppletDescriptor(
61
__tr2qs_ctx("Torrent Client","torrent"),
63
CreateTorrentClientApplet,
64
"torrent", *(g_pIconManager->getSmallIcon(KviIconManager::Away)));
66
bar->registerAppletDescriptor(d);
69
QString formatSize(float sz)
71
if (sz >= 1024.0f*1024.0f*1024.0f)
72
return QString("%1 GiB").arg(sz / (1024.0f*1024.0f*1024.0f), 2, 'f', 2);
73
if (sz >= 1024.0f*1024.0f)
74
return QString("%1 MiB").arg(sz / (1024.0f*1024.0f), 2, 'f', 2);
76
return QString("%1 KiB").arg(sz / 1024.0f, 2, 'f', 2);
77
return QString("%1 B").arg(sz, 2, 'f', 2);
80
void StatusBarApplet::update()
82
if (TorrentInterface::selected())
84
QString msg = QString("up: %1 K/s (%2), dn: %3 K/s (%4)")
85
.arg(TorrentInterface::selected()->speedUp(), 2)
86
.arg(formatSize(TorrentInterface::selected()->trafficUp()))
87
.arg(TorrentInterface::selected()->speedDown(), 2)
88
.arg(formatSize(TorrentInterface::selected()->trafficDown()));
92
setText(__tr2qs_ctx("No client selected!", "torrent"));
96
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
97
#include "StatusBarApplet.moc"
98
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES