2007-11-27 03:29:51 +00:00
|
|
|
/*
|
2021-10-18 20:22:31 +00:00
|
|
|
* This file Copyright (C) 2007-2021 Mnemosyne LLC
|
2007-11-27 03:29:51 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +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.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2007-11-27 03:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <glibmm/i18n.h>
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
#include "HigWorkarea.h"
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "StatsDialog.h"
|
|
|
|
#include "Utils.h"
|
2007-11-27 03:29:51 +00:00
|
|
|
|
2008-04-22 14:07:42 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TR_RESPONSE_RESET = 1
|
2008-04-22 14:07:42 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class StatsDialog::Impl
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2021-11-01 00:11:23 +00:00
|
|
|
Impl(StatsDialog& dialog, Glib::RefPtr<Session> const& core);
|
2021-10-18 20:22:31 +00:00
|
|
|
~Impl();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool updateStats();
|
|
|
|
void dialogResponse(int response);
|
|
|
|
|
|
|
|
private:
|
|
|
|
StatsDialog& dialog_;
|
2021-11-01 00:11:23 +00:00
|
|
|
Glib::RefPtr<Session> const core_;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
Gtk::Label* one_up_lb_;
|
|
|
|
Gtk::Label* one_down_lb_;
|
|
|
|
Gtk::Label* one_ratio_lb_;
|
|
|
|
Gtk::Label* one_time_lb_;
|
2012-12-13 03:00:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Label* all_up_lb_;
|
|
|
|
Gtk::Label* all_down_lb_;
|
|
|
|
Gtk::Label* all_ratio_lb_;
|
|
|
|
Gtk::Label* all_time_lb_;
|
2012-12-13 03:00:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Label* all_sessions_lb_;
|
2012-12-13 03:00:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
sigc::connection update_stats_tag_;
|
2007-11-27 03:29:51 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void setLabel(Gtk::Label* l, Glib::ustring const& str)
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_label_set_text(*l, str);
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void setLabelFromRatio(Gtk::Label* l, double d)
|
|
|
|
{
|
|
|
|
setLabel(l, tr_strlratio(d));
|
2007-11-27 03:29:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool StatsDialog::Impl::updateStats()
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_session_stats one;
|
|
|
|
tr_session_stats all;
|
2007-11-27 03:29:51 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_sessionGetStats(core_->get_session(), &one);
|
|
|
|
tr_sessionGetCumulativeStats(core_->get_session(), &all);
|
|
|
|
|
|
|
|
setLabel(one_up_lb_, tr_strlsize(one.uploadedBytes));
|
|
|
|
setLabel(one_down_lb_, tr_strlsize(one.downloadedBytes));
|
|
|
|
setLabel(one_time_lb_, tr_strltime(one.secondsActive));
|
|
|
|
setLabelFromRatio(one_ratio_lb_, one.ratio);
|
|
|
|
|
|
|
|
setLabel(
|
|
|
|
all_sessions_lb_,
|
|
|
|
gtr_sprintf(ngettext("Started %'d time", "Started %'d times", (int)all.sessionCount), (int)all.sessionCount));
|
|
|
|
|
|
|
|
setLabel(all_up_lb_, tr_strlsize(all.uploadedBytes));
|
|
|
|
setLabel(all_down_lb_, tr_strlsize(all.downloadedBytes));
|
|
|
|
setLabel(all_time_lb_, tr_strltime(all.secondsActive));
|
|
|
|
setLabelFromRatio(all_ratio_lb_, all.ratio);
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return true;
|
2008-06-05 20:41:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
StatsDialog::Impl::~Impl()
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
update_stats_tag_.disconnect();
|
|
|
|
}
|
2008-04-22 14:07:42 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void StatsDialog::Impl::dialogResponse(int response)
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (response == TR_RESPONSE_RESET)
|
2008-04-22 14:07:42 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::MessageDialog w(dialog_, _("Reset your statistics?"), false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
|
|
|
|
w.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
w.add_button(_("_Reset"), TR_RESPONSE_RESET);
|
|
|
|
w.set_secondary_text(
|
|
|
|
_("These statistics are for your information only. "
|
|
|
|
"Resetting them doesn't affect the statistics logged by your BitTorrent trackers."));
|
|
|
|
|
|
|
|
if (w.run() == TR_RESPONSE_RESET)
|
2010-01-03 17:58:33 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_sessionClearStats(core_->get_session());
|
|
|
|
updateStats();
|
2010-01-03 17:58:33 +00:00
|
|
|
}
|
2008-04-22 14:07:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (response == Gtk::RESPONSE_CLOSE)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.hide();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-11-27 03:29:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
std::unique_ptr<StatsDialog> StatsDialog::create(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return std::unique_ptr<StatsDialog>(new StatsDialog(parent, core));
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
StatsDialog::StatsDialog(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
: Gtk::Dialog(_("Statistics"), parent)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, core))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StatsDialog::~StatsDialog() = default;
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
StatsDialog::Impl::Impl(StatsDialog& dialog, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
: dialog_(dialog)
|
|
|
|
, core_(core)
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
guint row = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
dialog_.add_button(_("_Reset"), TR_RESPONSE_RESET);
|
|
|
|
dialog_.add_button(_("_Close"), Gtk::RESPONSE_CLOSE);
|
|
|
|
dialog_.set_default_response(Gtk::RESPONSE_CLOSE);
|
|
|
|
|
|
|
|
auto* t = Gtk::make_managed<HigWorkarea>();
|
|
|
|
t->add_section_title(row, _("Current Session"));
|
|
|
|
|
|
|
|
one_up_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
one_up_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Uploaded:"), *one_up_lb_);
|
|
|
|
one_down_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
one_down_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Downloaded:"), *one_down_lb_);
|
|
|
|
one_ratio_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
one_ratio_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Ratio:"), *one_ratio_lb_);
|
|
|
|
one_time_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
one_time_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Duration:"), *one_time_lb_);
|
|
|
|
|
|
|
|
t->add_section_divider(row);
|
|
|
|
t->add_section_title(row, _("Total"));
|
|
|
|
|
|
|
|
all_sessions_lb_ = Gtk::make_managed<Gtk::Label>(_("Started %'d time"));
|
|
|
|
all_sessions_lb_->set_single_line_mode(true);
|
|
|
|
t->add_label_w(row, *all_sessions_lb_);
|
2019-03-17 05:00:15 +00:00
|
|
|
++row;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
all_up_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
all_up_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Uploaded:"), *all_up_lb_);
|
|
|
|
all_down_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
all_down_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Downloaded:"), *all_down_lb_);
|
|
|
|
all_ratio_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
all_ratio_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Ratio:"), *all_ratio_lb_);
|
|
|
|
all_time_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
all_time_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Duration:"), *all_time_lb_);
|
|
|
|
|
|
|
|
gtr_dialog_set_content(dialog_, *t);
|
|
|
|
|
|
|
|
updateStats();
|
2021-11-12 09:12:50 +00:00
|
|
|
dialog_.signal_response().connect(sigc::mem_fun(*this, &Impl::dialogResponse));
|
2021-10-18 20:22:31 +00:00
|
|
|
update_stats_tag_ = Glib::signal_timeout().connect_seconds(
|
2021-11-12 09:12:50 +00:00
|
|
|
sigc::mem_fun(*this, &Impl::updateStats),
|
2021-10-18 20:22:31 +00:00
|
|
|
SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS);
|
2007-11-27 03:29:51 +00:00
|
|
|
}
|