2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
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
|
|
|
};
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
StatsDialog::StatsDialog(Session& session, QWidget* parent)
|
2023-07-18 15:20:17 +00:00
|
|
|
: BaseDialog{ parent }
|
|
|
|
, session_{ session }
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.setupUi(this);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2023-07-18 15:20:17 +00:00
|
|
|
auto* cr = new ColumnResizer{ this };
|
2020-05-27 21:53:12 +00:00
|
|
|
cr->addLayout(ui_.currentSessionSectionLayout);
|
|
|
|
cr->addLayout(ui_.totalSectionLayout);
|
2017-04-19 12:04:45 +00:00
|
|
|
cr->update();
|
2015-01-21 21:14:00 +00:00
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
timer_.setSingleShot(false);
|
|
|
|
connect(&timer_, &QTimer::timeout, &session_, &Session::refreshSessionStats);
|
|
|
|
connect(&session_, &Session::statsUpdated, this, &StatsDialog::updateStats);
|
2017-04-19 12:04:45 +00:00
|
|
|
updateStats();
|
2020-05-27 21:53:12 +00:00
|
|
|
session_.refreshSessionStats();
|
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
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
timer_.stop();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (visible)
|
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
timer_.start(REFRESH_INTERVAL_MSEC);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_session_stats const& current(session_.getStats());
|
|
|
|
tr_session_stats const& total(session_.getCumulativeStats());
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
ui_.currentUploadedValueLabel->setText(Formatter::storage_to_string(current.uploadedBytes));
|
|
|
|
ui_.currentDownloadedValueLabel->setText(Formatter::storage_to_string(current.downloadedBytes));
|
|
|
|
ui_.currentRatioValueLabel->setText(Formatter::ratio_to_string(current.ratio));
|
|
|
|
ui_.currentDurationValueLabel->setText(Formatter::time_to_string(current.secondsActive));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
ui_.totalUploadedValueLabel->setText(Formatter::storage_to_string(total.uploadedBytes));
|
|
|
|
ui_.totalDownloadedValueLabel->setText(Formatter::storage_to_string(total.downloadedBytes));
|
|
|
|
ui_.totalRatioValueLabel->setText(Formatter::ratio_to_string(total.ratio));
|
|
|
|
ui_.totalDurationValueLabel->setText(Formatter::time_to_string(total.secondsActive));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
ui_.startCountLabel->setText(tr("Started %Ln time(s)", nullptr, total.sessionCount));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|