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

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

Strip spaces around :: in C++ code (Qt client)

  • Property svn:keywords set to Date Rev Author Id
File size: 2.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 14377 2014-12-12 23:05:10Z mikedld $
8 */
9
10#include <QDialogButtonBox>
11#include <QLabel>
12#include <QTimer>
13#include <QVBoxLayout>
14
15#include "formatter.h"
16#include "hig.h"
17#include "session.h"
18#include "stats-dialog.h"
19
20enum
21{
22  REFRESH_INTERVAL_MSEC = (15*1000)
23};
24
25StatsDialog::StatsDialog (Session& session, QWidget * parent):
26  QDialog (parent, Qt::Dialog),
27  mySession (session),
28  myTimer (new QTimer (this))
29{
30  myTimer->setSingleShot (false);
31  connect (myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ()));
32  setWindowTitle (tr ("Statistics"));
33
34  HIG * hig = new HIG ();
35  hig->addSectionTitle (tr ("Current Session"));
36  hig->addRow (tr ("Uploaded:"), myCurrentUp = new QLabel ());
37  hig->addRow (tr ("Downloaded:"), myCurrentDown = new QLabel ());
38  hig->addRow (tr ("Ratio:"), myCurrentRatio = new QLabel ());
39  hig->addRow (tr ("Duration:"), myCurrentDuration = new QLabel ());
40  hig->addSectionDivider ();
41  hig->addSectionTitle (tr ("Total"));
42  hig->addRow (myStartCount = new QLabel (tr ("Started %n time (s)", 0, 1)), 0);
43  hig->addRow (tr ("Uploaded:"), myTotalUp = new QLabel ());
44  hig->addRow (tr ("Downloaded:"), myTotalDown = new QLabel ());
45  hig->addRow (tr ("Ratio:"), myTotalRatio = new QLabel ());
46  hig->addRow (tr ("Duration:"), myTotalDuration = new QLabel ());
47  hig->finish ();
48
49  QLayout * layout = new QVBoxLayout (this);
50  layout->addWidget (hig);
51  QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
52  connect (buttons, SIGNAL (rejected ()), this, SLOT (hide ())); // "close" triggers rejected
53  layout->addWidget (buttons);
54
55  connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (updateStats ()));
56  updateStats ();
57  mySession.refreshSessionStats ();
58}
59
60StatsDialog::~StatsDialog ()
61{
62}
63
64void
65StatsDialog::setVisible (bool visible)
66{
67  myTimer->stop ();
68  if (visible)
69    myTimer->start (REFRESH_INTERVAL_MSEC);
70  QDialog::setVisible (visible);
71}
72
73void
74StatsDialog::onTimer ()
75{
76  mySession.refreshSessionStats ();
77}
78
79void
80StatsDialog::updateStats ()
81{
82  const struct tr_session_stats& current (mySession.getStats ());
83  const struct tr_session_stats& total (mySession.getCumulativeStats ());
84
85  myCurrentUp->setText (Formatter::sizeToString (current.uploadedBytes));
86  myCurrentDown->setText (Formatter::sizeToString (current.downloadedBytes));
87  myCurrentRatio->setText (Formatter::ratioToString (current.ratio));
88  myCurrentDuration->setText (Formatter::timeToString (current.secondsActive));
89
90  myTotalUp->setText (Formatter::sizeToString (total.uploadedBytes));
91  myTotalDown->setText (Formatter::sizeToString (total.downloadedBytes));
92  myTotalRatio->setText (Formatter::ratioToString (total.ratio));
93  myTotalDuration->setText (Formatter::timeToString (total.secondsActive));
94
95  myStartCount->setText (tr ("Started %n time (s)", 0, total.sessionCount));
96}
Note: See TracBrowser for help on using the repository browser.