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