add upload/download session stats per torrent to gtk

This commit is contained in:
simplepad 2023-10-14 03:12:48 +08:00
parent 7add8d48fb
commit bd0d1f2260
No known key found for this signature in database
GPG Key ID: 00DB76DD9FB623EC
4 changed files with 191 additions and 30 deletions

View File

@ -157,7 +157,9 @@ private:
Gtk::Label* state_lb_ = nullptr;
Gtk::Label* have_lb_ = nullptr;
Gtk::Label* dl_lb_ = nullptr;
Gtk::Label* dl_ts_lb_ = nullptr;
Gtk::Label* ul_lb_ = nullptr;
Gtk::Label* ul_ts_lb_ = nullptr;
Gtk::Label* error_lb_ = nullptr;
Gtk::Label* date_started_lb_ = nullptr;
Gtk::Label* eta_lb_ = nullptr;
@ -995,6 +997,40 @@ void DetailsDialog::Impl::refreshInfo(std::vector<tr_torrent*> const& torrents)
dl_lb_->set_text(str);
// dl_ts_lb
if (stats.empty())
{
str = no_torrent;
}
else
{
auto const downloaded_str = tr_strlsize(std::accumulate(
std::begin(stats),
std::end(stats),
uint64_t{ 0 },
[](auto sum, auto const* st) { return sum + st->downloadedThisSession; }));
auto const failed = std::accumulate(
std::begin(stats),
std::end(stats),
uint64_t{ 0 },
[](auto sum, auto const* st) { return sum + st->corruptThisSession; });
if (failed != 0)
{
str = fmt::format(
_("{downloaded_size} (+{discarded_size} discarded after failed checksum)"),
fmt::arg("downloaded_size", downloaded_str),
fmt::arg("discarded_size", tr_strlsize(failed)));
}
else
{
str = downloaded_str;
}
}
dl_ts_lb_->set_text(str);
/* ul_lb */
if (stats.empty())
{
@ -1020,6 +1056,23 @@ void DetailsDialog::Impl::refreshInfo(std::vector<tr_torrent*> const& torrents)
ul_lb_->set_text(str);
/* ul_ts_lb */
if (stats.empty())
{
str = no_torrent;
}
else
{
auto const uploaded = std::accumulate(
std::begin(stats),
std::end(stats),
uint64_t{},
[](auto sum, auto const* st) { return sum + st->uploadedThisSession; });
str = fmt::format(_("{uploaded_size}"), fmt::arg("uploaded_size", tr_strlsize(uploaded)));
}
ul_ts_lb_->set_text(str);
/* hash_lb */
if (infos.empty())
{
@ -2555,7 +2608,9 @@ DetailsDialog::Impl::Impl(DetailsDialog& dialog, Glib::RefPtr<Gtk::Builder> cons
, state_lb_(gtr_get_widget<Gtk::Label>(builder, "state_value_label"))
, have_lb_(gtr_get_widget<Gtk::Label>(builder, "have_value_label"))
, dl_lb_(gtr_get_widget<Gtk::Label>(builder, "downloaded_value_label"))
, dl_ts_lb_(gtr_get_widget<Gtk::Label>(builder, "downloaded_this_session_value_label"))
, ul_lb_(gtr_get_widget<Gtk::Label>(builder, "uploaded_value_label"))
, ul_ts_lb_(gtr_get_widget<Gtk::Label>(builder, "uploaded_this_session_value_label"))
, error_lb_(gtr_get_widget<Gtk::Label>(builder, "error_value_label"))
, date_started_lb_(gtr_get_widget<Gtk::Label>(builder, "running_time_value_label"))
, eta_lb_(gtr_get_widget<Gtk::Label>(builder, "remaining_time_value_label"))

View File

@ -146,6 +146,7 @@ public:
Storage size_when_done;
Storage total_size;
Storage uploaded_ever;
Storage uploaded_this_session;
Speed speed_down;
Speed speed_up;
@ -333,6 +334,11 @@ Torrent::ChangeFlags Torrent::Impl::update_cache()
Storage{ stats->uploadedEver, Storage::Units::Bytes },
result,
ChangeFlag::LONG_PROGRESS);
update_cache_value(
cache_.uploaded_this_session,
Storage{ stats->uploadedThisSession, Storage::Units::Bytes },
result,
ChangeFlag::LONG_PROGRESS);
update_cache_value(
cache_.metadata_percent_complete,
@ -470,14 +476,15 @@ Glib::ustring Torrent::Impl::get_long_progress_text() const
}
else if (!isSeed && cache_.has_seed_ratio) // partial seed, seed ratio
{
// 50 MB of 200 MB (25%), uploaded 30 MB (Ratio: X%, Goal: Y%)
// 50 MB of 200 MB (25%), uploaded 30 MB (15 MB this session) (Ratio: X%, Goal: Y%)
gstr += fmt::format(
// xgettext:no-c-format
_("{current_size} of {complete_size} ({percent_complete}%), uploaded {uploaded_size} (Ratio: {ratio}, Goal: {seed_ratio})"),
_("{current_size} of {complete_size} ({percent_complete}%), uploaded {uploaded_size} ({uploaded_this_session} this session) (Ratio: {ratio}, Goal: {seed_ratio})"),
fmt::arg("current_size", tr_strlsize(haveTotal)),
fmt::arg("complete_size", tr_strlsize(cache_.total_size)),
fmt::arg("percent_complete", cache_.percent_complete.to_string()),
fmt::arg("uploaded_size", tr_strlsize(cache_.uploaded_ever)),
fmt::arg("uploaded_this_session", tr_strlsize(cache_.uploaded_this_session)),
fmt::arg("ratio", tr_strlratio(cache_.ratio)),
fmt::arg("seed_ratio", tr_strlratio(cache_.seed_ratio)));
}
@ -485,28 +492,31 @@ Glib::ustring Torrent::Impl::get_long_progress_text() const
{
gstr += fmt::format(
// xgettext:no-c-format
_("{current_size} of {complete_size} ({percent_complete}%), uploaded {uploaded_size} (Ratio: {ratio})"),
_("{current_size} of {complete_size} ({percent_complete}%), uploaded {uploaded_size} ({uploaded_this_session} this session) (Ratio: {ratio})"),
fmt::arg("current_size", tr_strlsize(haveTotal)),
fmt::arg("complete_size", tr_strlsize(cache_.total_size)),
fmt::arg("percent_complete", cache_.percent_complete.to_string()),
fmt::arg("uploaded_size", tr_strlsize(cache_.uploaded_ever)),
fmt::arg("uploaded_this_session", tr_strlsize(cache_.uploaded_this_session)),
fmt::arg("ratio", tr_strlratio(cache_.ratio)));
}
else if (cache_.has_seed_ratio) // seed, seed ratio
{
gstr += fmt::format(
_("{complete_size}, uploaded {uploaded_size} (Ratio: {ratio}, Goal: {seed_ratio})"),
_("{complete_size}, uploaded {uploaded_size} ({uploaded_this_session} this session) (Ratio: {ratio}, Goal: {seed_ratio})"),
fmt::arg("complete_size", tr_strlsize(cache_.total_size)),
fmt::arg("uploaded_size", tr_strlsize(cache_.uploaded_ever)),
fmt::arg("uploaded_this_session", tr_strlsize(cache_.uploaded_this_session)),
fmt::arg("ratio", tr_strlratio(cache_.ratio)),
fmt::arg("seed_ratio", tr_strlratio(cache_.seed_ratio)));
}
else // seed, no seed ratio
{
gstr += fmt::format(
_("{complete_size}, uploaded {uploaded_size} (Ratio: {ratio})"),
_("{complete_size}, uploaded {uploaded_size} ({uploaded_this_session} this session) (Ratio: {ratio})"),
fmt::arg("complete_size", tr_strlsize(cache_.total_size)),
fmt::arg("uploaded_size", tr_strlsize(cache_.uploaded_ever)),
fmt::arg("uploaded_this_session", tr_strlsize(cache_.uploaded_this_session)),
fmt::arg("ratio", tr_strlratio(cache_.ratio)));
}

View File

@ -66,7 +66,7 @@
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=9 -->
<!-- n-columns=2 n-rows=11 -->
<object class="GtkGrid" id="activity_section_layout">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -109,6 +109,18 @@
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="uploaded_this_session_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Uploaded this session:</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="downloaded_label">
<property name="visible">True</property>
@ -118,7 +130,19 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="downloaded_this_session_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Downloaded this session:</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
@ -130,7 +154,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
@ -142,7 +166,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="top-attach">7</property>
</packing>
</child>
<child>
@ -154,7 +178,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
@ -166,7 +190,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">7</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
@ -179,7 +203,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">8</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
@ -222,7 +246,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="downloaded_value_label">
<object class="GtkLabel" id="uploaded_this_session_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
@ -235,7 +259,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="state_value_label">
<object class="GtkLabel" id="downloaded_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
@ -248,7 +272,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="running_time_value_label">
<object class="GtkLabel" id="downloaded_this_session_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
@ -261,7 +285,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="remaining_time_value_label">
<object class="GtkLabel" id="state_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
@ -274,7 +298,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="last_activity_value_label">
<object class="GtkLabel" id="running_time_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
@ -286,6 +310,32 @@
<property name="top-attach">7</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="remaining_time_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="label">...</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="last_activity_value_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="label">...</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="error_value_label">
<property name="visible">True</property>
@ -300,7 +350,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">8</property>
<property name="top-attach">10</property>
</packing>
</child>
</object>
@ -1200,7 +1250,9 @@
<widget name="torrent_size_label"/>
<widget name="have_label"/>
<widget name="uploaded_label"/>
<widget name="uploaded_this_session_label"/>
<widget name="downloaded_label"/>
<widget name="downloaded_this_session_label"/>
<widget name="state_label"/>
<widget name="running_time_label"/>
<widget name="remaining_time_label"/>

View File

@ -64,13 +64,33 @@
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="uploaded_this_session_label">
<property name="label" translatable="1">Uploaded this session:</property>
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="downloaded_label">
<property name="label" translatable="1">Downloaded:</property>
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">3</property>
<property name="row">4</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="downloaded_this_session_label">
<property name="label" translatable="1">Downloaded this session:</property>
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">5</property>
</layout>
</object>
</child>
@ -80,7 +100,7 @@
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">4</property>
<property name="row">6</property>
</layout>
</object>
</child>
@ -90,7 +110,7 @@
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">5</property>
<property name="row">7</property>
</layout>
</object>
</child>
@ -100,7 +120,7 @@
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">6</property>
<property name="row">8</property>
</layout>
</object>
</child>
@ -110,7 +130,7 @@
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">7</property>
<property name="row">9</property>
</layout>
</object>
</child>
@ -121,7 +141,7 @@
<property name="yalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">8</property>
<property name="row">10</property>
</layout>
</object>
</child>
@ -159,7 +179,7 @@
</object>
</child>
<child>
<object class="GtkLabel" id="downloaded_value_label">
<object class="GtkLabel" id="uploaded_this_session_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
@ -170,7 +190,7 @@
</object>
</child>
<child>
<object class="GtkLabel" id="state_value_label">
<object class="GtkLabel" id="downloaded_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
@ -181,7 +201,7 @@
</object>
</child>
<child>
<object class="GtkLabel" id="running_time_value_label">
<object class="GtkLabel" id="downloaded_this_session_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
@ -192,7 +212,7 @@
</object>
</child>
<child>
<object class="GtkLabel" id="remaining_time_value_label">
<object class="GtkLabel" id="state_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
@ -203,7 +223,7 @@
</object>
</child>
<child>
<object class="GtkLabel" id="last_activity_value_label">
<object class="GtkLabel" id="running_time_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
@ -213,6 +233,28 @@
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="remaining_time_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
<layout>
<property name="column">1</property>
<property name="row">8</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="last_activity_value_label">
<property name="hexpand">1</property>
<property name="label">...</property>
<property name="xalign">0</property>
<layout>
<property name="column">1</property>
<property name="row">9</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel" id="error_value_label">
<property name="hexpand">1</property>
@ -225,7 +267,7 @@
<property name="xalign">0</property>
<layout>
<property name="column">1</property>
<property name="row">8</property>
<property name="row">10</property>
</layout>
</object>
</child>
@ -856,7 +898,9 @@
<widget name="torrent_size_label"/>
<widget name="have_label"/>
<widget name="uploaded_label"/>
<widget name="uploaded_this_session_label"/>
<widget name="downloaded_label"/>
<widget name="downloaded_this_session_label"/>
<widget name="state_label"/>
<widget name="running_time_label"/>
<widget name="remaining_time_label"/>