~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/modules/torrent/StatusBarApplet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   StatuBar for Torrent client.
 
4
//
 
5
//   File : StatusBarApplet.cpp
 
6
//   Creation date : Fri Jan 1 15:42:25 2007 GMT by Alexander Stillich
 
7
//
 
8
//   This file is part of the KVIrc irc client distribution
 
9
//   Copyright (C) 2007-2008 Alexander Stillich (torque at pltn dot org)
 
10
//
 
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.
 
15
//
 
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.
 
20
//
 
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.
 
24
//
 
25
//=============================================================================
 
26
 
 
27
#include "TorrentInterface.h"
 
28
#include "StatusBarApplet.h"
 
29
 
 
30
#include "KviLocale.h"
 
31
#include "KviIconManager.h"
 
32
 
 
33
#include "QTimer"
 
34
 
 
35
StatusBarApplet::StatusBarApplet(KviStatusBar *parent, KviStatusBarAppletDescriptor *desc)
 
36
        : KviStatusBarApplet(parent, desc)
 
37
{
 
38
        QTimer *timer = new QTimer(this);
 
39
        connect(timer, SIGNAL(timeout()), this, SLOT(update()));
 
40
        timer->setInterval(250);
 
41
        timer->setSingleShot(false);
 
42
        timer->start(250);
 
43
 
 
44
        setText(__tr2qs_ctx("Torrent Client","torrent"));
 
45
}
 
46
 
 
47
StatusBarApplet::~StatusBarApplet()
 
48
{
 
49
}
 
50
 
 
51
static KviStatusBarApplet *CreateTorrentClientApplet(KviStatusBar *bar, KviStatusBarAppletDescriptor *desc)
 
52
{
 
53
        KviStatusBarApplet * pApplet = new StatusBarApplet(bar, desc);
 
54
        pApplet->setIndex(bar->insertPermanentWidgetAtTheEnd(pApplet));
 
55
        return pApplet;
 
56
}
 
57
 
 
58
void StatusBarApplet::selfRegister(KviStatusBar *bar)
 
59
{
 
60
        KviStatusBarAppletDescriptor *d = new KviStatusBarAppletDescriptor(
 
61
                __tr2qs_ctx("Torrent Client","torrent"),
 
62
                        "torrentapplet",
 
63
                        CreateTorrentClientApplet,
 
64
                        "torrent", *(g_pIconManager->getSmallIcon(KviIconManager::Away)));
 
65
 
 
66
        bar->registerAppletDescriptor(d);
 
67
}
 
68
 
 
69
QString formatSize(float sz)
 
70
{
 
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);
 
75
        if (sz >= 1024.0f)
 
76
                return QString("%1 KiB").arg(sz / 1024.0f, 2, 'f', 2);
 
77
        return QString("%1 B").arg(sz, 2, 'f', 2);
 
78
}
 
79
 
 
80
void StatusBarApplet::update()
 
81
{
 
82
        if (TorrentInterface::selected())
 
83
        {
 
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()));
 
89
 
 
90
                setText(msg);
 
91
        } else {
 
92
                setText(__tr2qs_ctx("No client selected!", "torrent"));
 
93
        }
 
94
}
 
95
 
 
96
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
 
97
#include "StatusBarApplet.moc"
 
98
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES