2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2015-06-10 21:27:11 +00:00
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-12-21 23:49:39 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "ColumnResizer.h"
|
|
|
|
#include "Formatter.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "StatsDialog.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
REFRESH_INTERVAL_MSEC = (15 * 1000)
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
StatsDialog::StatsDialog(Session& session, QWidget* parent) :
|
|
|
|
BaseDialog(parent),
|
|
|
|
mySession(session),
|
|
|
|
myTimer(new QTimer(this))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.setupUi(this);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ColumnResizer* cr(new ColumnResizer(this));
|
|
|
|
cr->addLayout(ui.currentSessionSectionLayout);
|
|
|
|
cr->addLayout(ui.totalSectionLayout);
|
|
|
|
cr->update();
|
2015-01-21 21:14:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
myTimer->setSingleShot(false);
|
|
|
|
connect(myTimer, SIGNAL(timeout()), &mySession, SLOT(refreshSessionStats()));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
connect(&mySession, SIGNAL(statsUpdated()), this, SLOT(updateStats()));
|
|
|
|
updateStats();
|
|
|
|
mySession.refreshSessionStats();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
StatsDialog::~StatsDialog()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void StatsDialog::setVisible(bool visible)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myTimer->stop();
|
|
|
|
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
myTimer->start(REFRESH_INTERVAL_MSEC);
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseDialog::setVisible(visible);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void StatsDialog::updateStats()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_session_stats const& current(mySession.getStats());
|
|
|
|
tr_session_stats const& total(mySession.getCumulativeStats());
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.currentUploadedValueLabel->setText(Formatter::sizeToString(current.uploadedBytes));
|
|
|
|
ui.currentDownloadedValueLabel->setText(Formatter::sizeToString(current.downloadedBytes));
|
|
|
|
ui.currentRatioValueLabel->setText(Formatter::ratioToString(current.ratio));
|
|
|
|
ui.currentDurationValueLabel->setText(Formatter::timeToString(current.secondsActive));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ui.totalUploadedValueLabel->setText(Formatter::sizeToString(total.uploadedBytes));
|
|
|
|
ui.totalDownloadedValueLabel->setText(Formatter::sizeToString(total.downloadedBytes));
|
|
|
|
ui.totalRatioValueLabel->setText(Formatter::ratioToString(total.ratio));
|
|
|
|
ui.totalDurationValueLabel->setText(Formatter::timeToString(total.secondsActive));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
ui.startCountLabel->setText(tr("Started %Ln time(s)", nullptr, total.sessionCount));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|