From c601b5a27f74b16158adafe429faefbe573e64a2 Mon Sep 17 00:00:00 2001 From: Szymon Tomasz Stefanek Date: Sat, 1 Jan 2011 20:19:56 +0000 Subject: The big rename for modules. Still some details remaining. git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5284 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/torrent/StatusBarApplet.cpp | 98 +++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/modules/torrent/StatusBarApplet.cpp (limited to 'src/modules/torrent/StatusBarApplet.cpp') diff --git a/src/modules/torrent/StatusBarApplet.cpp b/src/modules/torrent/StatusBarApplet.cpp new file mode 100644 index 000000000..a464cd8be --- /dev/null +++ b/src/modules/torrent/StatusBarApplet.cpp @@ -0,0 +1,98 @@ +//============================================================================= +// +// StatuBar for Torrent client. +// +// File : StatusBarApplet.cpp +// Creation date : Fri Jan 1 15:42:25 2007 GMT by Alexander Stillich +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2007-2008 Alexander Stillich (torque at pltn dot org) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "TorrentInterface.h" +#include "StatusBarApplet.h" + +#include "KviLocale.h" +#include "KviIconManager.h" + +#include "QTimer" + +StatusBarApplet::StatusBarApplet(KviStatusBar *parent, KviStatusBarAppletDescriptor *desc) + : KviStatusBarApplet(parent, desc) +{ + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->setInterval(250); + timer->setSingleShot(false); + timer->start(250); + + setText(__tr2qs_ctx("Torrent Client","torrent")); +} + +StatusBarApplet::~StatusBarApplet() +{ +} + +static KviStatusBarApplet *CreateTorrentClientApplet(KviStatusBar *bar, KviStatusBarAppletDescriptor *desc) +{ + KviStatusBarApplet * pApplet = new StatusBarApplet(bar, desc); + pApplet->setIndex(bar->insertPermanentWidgetAtTheEnd(pApplet)); + return pApplet; +} + +void StatusBarApplet::selfRegister(KviStatusBar *bar) +{ + KviStatusBarAppletDescriptor *d = new KviStatusBarAppletDescriptor( + __tr2qs_ctx("Torrent Client","torrent"), + "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 GiB").arg(sz / (1024.0f*1024.0f*1024.0f), 2, 'f', 2); + if (sz >= 1024.0f*1024.0f) + return QString("%1 MiB").arg(sz / (1024.0f*1024.0f), 2, 'f', 2); + if (sz >= 1024.0f) + return QString("%1 KiB").arg(sz / 1024.0f, 2, 'f', 2); + return QString("%1 B").arg(sz, 2, 'f', 2); +} + +void StatusBarApplet::update() +{ + if (TorrentInterface::selected()) + { + QString msg = QString("up: %1 K/s (%2), dn: %3 K/s (%4)") + .arg(TorrentInterface::selected()->speedUp(), 2) + .arg(formatSize(TorrentInterface::selected()->trafficUp())) + .arg(TorrentInterface::selected()->speedDown(), 2) + .arg(formatSize(TorrentInterface::selected()->trafficDown())); + + setText(msg); + } else { + setText(__tr2qs_ctx("No client selected!", "torrent")); + } +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "StatusBarApplet.moc" +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES -- cgit v1.3.1-10-gc9f91