2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-19 01:09:44 +00:00
|
|
|
* It may be used under the GNU Public License v2 or v3 licenses,
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2010-07-03 01:10:36 +00:00
|
|
|
#include "formatter.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "hig.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "stats-dialog.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
REFRESH_INTERVAL_MSEC = (15*1000)
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
StatsDialog :: StatsDialog (Session & session, QWidget * parent):
|
|
|
|
QDialog (parent, Qt::Dialog),
|
|
|
|
mySession (session),
|
|
|
|
myTimer (new QTimer (this))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
myTimer->setSingleShot (false);
|
|
|
|
connect (myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ()));
|
|
|
|
setWindowTitle (tr ("Statistics"));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
HIG * hig = new HIG ();
|
|
|
|
hig->addSectionTitle (tr ("Current Session"));
|
|
|
|
hig->addRow (tr ("Uploaded:"), myCurrentUp = new QLabel ());
|
|
|
|
hig->addRow (tr ("Downloaded:"), myCurrentDown = new QLabel ());
|
|
|
|
hig->addRow (tr ("Ratio:"), myCurrentRatio = new QLabel ());
|
|
|
|
hig->addRow (tr ("Duration:"), myCurrentDuration = new QLabel ());
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Total"));
|
|
|
|
hig->addRow (myStartCount = new QLabel (tr ("Started %n time (s)", 0, 1)), 0);
|
|
|
|
hig->addRow (tr ("Uploaded:"), myTotalUp = new QLabel ());
|
|
|
|
hig->addRow (tr ("Downloaded:"), myTotalDown = new QLabel ());
|
|
|
|
hig->addRow (tr ("Ratio:"), myTotalRatio = new QLabel ());
|
|
|
|
hig->addRow (tr ("Duration:"), myTotalDuration = new QLabel ());
|
|
|
|
hig->finish ();
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
QLayout * layout = new QVBoxLayout (this);
|
|
|
|
layout->addWidget (hig);
|
|
|
|
QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
|
|
|
|
connect (buttons, SIGNAL (rejected ()), this, SLOT (hide ())); // "close" triggers rejected
|
|
|
|
layout->addWidget (buttons);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (updateStats ()));
|
|
|
|
updateStats ();
|
|
|
|
mySession.refreshSessionStats ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
StatsDialog :: ~StatsDialog ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-03 19:40:20 +00:00
|
|
|
StatsDialog :: setVisible (bool visible)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
myTimer->stop ();
|
|
|
|
if (visible)
|
|
|
|
myTimer->start (REFRESH_INTERVAL_MSEC);
|
|
|
|
QDialog::setVisible (visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-03 19:40:20 +00:00
|
|
|
StatsDialog :: onTimer ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
mySession.refreshSessionStats ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-03 19:40:20 +00:00
|
|
|
StatsDialog :: updateStats ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
const struct tr_session_stats& current (mySession.getStats ());
|
|
|
|
const struct tr_session_stats& total (mySession.getCumulativeStats ());
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
myCurrentUp->setText (Formatter::sizeToString (current.uploadedBytes));
|
|
|
|
myCurrentDown->setText (Formatter::sizeToString (current.downloadedBytes));
|
|
|
|
myCurrentRatio->setText (Formatter::ratioToString (current.ratio));
|
|
|
|
myCurrentDuration->setText (Formatter::timeToString (current.secondsActive));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
myTotalUp->setText (Formatter::sizeToString (total.uploadedBytes));
|
|
|
|
myTotalDown->setText (Formatter::sizeToString (total.downloadedBytes));
|
|
|
|
myTotalRatio->setText (Formatter::ratioToString (total.ratio));
|
|
|
|
myTotalDuration->setText (Formatter::timeToString (total.secondsActive));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
myStartCount->setText (tr ("Started %n time (s)", 0, total.sessionCount));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|