1 | /* |
---|
2 | * This file Copyright (C) 2009-2014 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU Public License v2 or v3 licenses, |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: stats-dialog.cc 14393 2014-12-21 23:46:31Z mikedld $ |
---|
8 | */ |
---|
9 | |
---|
10 | #include <QTimer> |
---|
11 | |
---|
12 | #include "formatter.h" |
---|
13 | #include "session.h" |
---|
14 | #include "stats-dialog.h" |
---|
15 | |
---|
16 | enum |
---|
17 | { |
---|
18 | REFRESH_INTERVAL_MSEC = (15*1000) |
---|
19 | }; |
---|
20 | |
---|
21 | StatsDialog::StatsDialog (Session& session, QWidget * parent): |
---|
22 | QDialog (parent, Qt::Dialog), |
---|
23 | mySession (session), |
---|
24 | myTimer (new QTimer (this)) |
---|
25 | { |
---|
26 | ui.setupUi (this); |
---|
27 | |
---|
28 | myTimer->setSingleShot (false); |
---|
29 | connect (myTimer, SIGNAL (timeout ()), &mySession, SLOT (refreshSessionStats ())); |
---|
30 | |
---|
31 | connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (updateStats ())); |
---|
32 | updateStats (); |
---|
33 | mySession.refreshSessionStats (); |
---|
34 | } |
---|
35 | |
---|
36 | StatsDialog::~StatsDialog () |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | void |
---|
41 | StatsDialog::setVisible (bool visible) |
---|
42 | { |
---|
43 | myTimer->stop (); |
---|
44 | if (visible) |
---|
45 | myTimer->start (REFRESH_INTERVAL_MSEC); |
---|
46 | QDialog::setVisible (visible); |
---|
47 | } |
---|
48 | |
---|
49 | void |
---|
50 | StatsDialog::updateStats () |
---|
51 | { |
---|
52 | const tr_session_stats& current (mySession.getStats ()); |
---|
53 | const tr_session_stats& total (mySession.getCumulativeStats ()); |
---|
54 | |
---|
55 | ui.currentUploadedValueLabel->setText (Formatter::sizeToString (current.uploadedBytes)); |
---|
56 | ui.currentDownloadedValueLabel->setText (Formatter::sizeToString (current.downloadedBytes)); |
---|
57 | ui.currentRatioValueLabel->setText (Formatter::ratioToString (current.ratio)); |
---|
58 | ui.currentDurationValueLabel->setText (Formatter::timeToString (current.secondsActive)); |
---|
59 | |
---|
60 | ui.totalUploadedValueLabel->setText (Formatter::sizeToString (total.uploadedBytes)); |
---|
61 | ui.totalDownloadedValueLabel->setText (Formatter::sizeToString (total.downloadedBytes)); |
---|
62 | ui.totalRatioValueLabel->setText (Formatter::ratioToString (total.ratio)); |
---|
63 | ui.totalDurationValueLabel->setText (Formatter::timeToString (total.secondsActive)); |
---|
64 | |
---|
65 | ui.startCountLabel->setText (tr ("Started %n time(s)", 0, total.sessionCount)); |
---|
66 | } |
---|