source: trunk/qt/stats-dialog.cc @ 14391

Last change on this file since 14391 was 14391, checked in by mikedld, 8 years ago

Rework statistics dialog in Qt client to load from .ui

Fix "Started %n time(s)" phrase (remove space in "time (s)", add proper
English translation for numeric forms).

  • Property svn:keywords set to Date Rev Author Id
File size: 1.9 KB
Line 
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 14391 2014-12-21 13:57:15Z mikedld $
8 */
9
10#include <QTimer>
11
12#include "formatter.h"
13#include "hig.h"
14#include "session.h"
15#include "stats-dialog.h"
16
17enum
18{
19  REFRESH_INTERVAL_MSEC = (15*1000)
20};
21
22StatsDialog::StatsDialog (Session& session, QWidget * parent):
23  QDialog (parent, Qt::Dialog),
24  mySession (session),
25  myTimer (new QTimer (this))
26{
27  ui.setupUi (this);
28
29  myTimer->setSingleShot (false);
30  connect (myTimer, SIGNAL (timeout ()), &mySession, SLOT (refreshSessionStats ()));
31
32  connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (updateStats ()));
33  updateStats ();
34  mySession.refreshSessionStats ();
35}
36
37StatsDialog::~StatsDialog ()
38{
39}
40
41void
42StatsDialog::setVisible (bool visible)
43{
44  myTimer->stop ();
45  if (visible)
46    myTimer->start (REFRESH_INTERVAL_MSEC);
47  QDialog::setVisible (visible);
48}
49
50void
51StatsDialog::updateStats ()
52{
53  const tr_session_stats& current (mySession.getStats ());
54  const tr_session_stats& total (mySession.getCumulativeStats ());
55
56  ui.currentUploadedValueLabel->setText (Formatter::sizeToString (current.uploadedBytes));
57  ui.currentDownloadedValueLabel->setText (Formatter::sizeToString (current.downloadedBytes));
58  ui.currentRatioValueLabel->setText (Formatter::ratioToString (current.ratio));
59  ui.currentDurationValueLabel->setText (Formatter::timeToString (current.secondsActive));
60
61  ui.totalUploadedValueLabel->setText (Formatter::sizeToString (total.uploadedBytes));
62  ui.totalDownloadedValueLabel->setText (Formatter::sizeToString (total.downloadedBytes));
63  ui.totalRatioValueLabel->setText (Formatter::ratioToString (total.ratio));
64  ui.totalDurationValueLabel->setText (Formatter::timeToString (total.secondsActive));
65
66  ui.startCountLabel->setText (tr ("Started %n time(s)", 0, total.sessionCount));
67}
Note: See TracBrowser for help on using the repository browser.