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

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

Rework session dialog in Qt client to load from .ui

  • 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 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
16enum
17{
18  REFRESH_INTERVAL_MSEC = (15*1000)
19};
20
21StatsDialog::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
36StatsDialog::~StatsDialog ()
37{
38}
39
40void
41StatsDialog::setVisible (bool visible)
42{
43  myTimer->stop ();
44  if (visible)
45    myTimer->start (REFRESH_INTERVAL_MSEC);
46  QDialog::setVisible (visible);
47}
48
49void
50StatsDialog::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}
Note: See TracBrowser for help on using the repository browser.