transmission_gobject/
session_stats_details.rs1use std::cell::Cell;
2
3use glib::Properties;
4use glib::object::ObjectExt;
5use glib::subclass::prelude::{ObjectSubclass, *};
6use transmission_client::StatsDetails;
7
8mod imp {
9 use super::*;
10
11 #[derive(Debug, Default, Properties)]
12 #[properties(wrapper_type = super::TrSessionStatsDetails)]
13 pub struct TrSessionStatsDetails {
14 #[property(get)]
15 pub seconds_active: Cell<i64>,
16 #[property(get)]
17 pub downloaded_bytes: Cell<i64>,
18 #[property(get)]
19 pub uploaded_bytes: Cell<i64>,
20 #[property(get)]
21 pub files_added: Cell<i64>,
22 #[property(get)]
23 pub session_count: Cell<i64>,
24 }
25
26 #[glib::object_subclass]
27 impl ObjectSubclass for TrSessionStatsDetails {
28 const NAME: &'static str = "TrSessionStatsDetails";
29 type ParentType = glib::Object;
30 type Type = super::TrSessionStatsDetails;
31 }
32
33 #[glib::derived_properties]
34 impl ObjectImpl for TrSessionStatsDetails {}
35}
36
37glib::wrapper! {
38 pub struct TrSessionStatsDetails(ObjectSubclass<imp::TrSessionStatsDetails>);
39}
40
41impl TrSessionStatsDetails {
42 pub(crate) fn refresh_values(&self, rpc_details: StatsDetails) {
43 let imp = self.imp();
44
45 if imp.seconds_active.get() != rpc_details.seconds_active {
47 imp.seconds_active.set(rpc_details.seconds_active);
48 self.notify_seconds_active();
49 }
50
51 if imp.downloaded_bytes.get() != rpc_details.downloaded_bytes {
53 imp.downloaded_bytes.set(rpc_details.downloaded_bytes);
54 self.notify_downloaded_bytes();
55 }
56
57 if imp.uploaded_bytes.get() != rpc_details.uploaded_bytes {
59 imp.uploaded_bytes.set(rpc_details.uploaded_bytes);
60 self.notify_uploaded_bytes();
61 }
62
63 if imp.files_added.get() != rpc_details.files_added {
65 imp.files_added.set(rpc_details.files_added);
66 self.notify_files_added();
67 }
68
69 if imp.session_count.get() != rpc_details.session_count {
71 imp.session_count.set(rpc_details.session_count);
72 self.notify_session_count();
73 }
74 }
75}
76
77impl Default for TrSessionStatsDetails {
78 fn default() -> Self {
79 glib::Object::new()
80 }
81}