add header string dump, reorganize size struct

This commit is contained in:
yggverse 2025-03-25 21:19:48 +02:00
parent 22efd3ef9d
commit 1c29639468
4 changed files with 72 additions and 43 deletions

View file

@ -1,13 +1,11 @@
mod dialog;
mod event;
mod size;
mod socket;
use super::Profile;
use dialog::Dialog;
use event::Event;
use gtk::{gio::SocketAddress, prelude::IsA};
use size::Size;
use socket::Socket;
/// Common, shared `Page` information holder
@ -16,6 +14,9 @@ use socket::Socket;
pub struct Info {
/// Hold page events like connection phase and parsing time
event: Vec<Event>,
/// Hold optional header string to dump it in the info dialog
/// and calculate total size
header: Option<String>,
/// Mark holder as deprecated on handle begin
/// * useful on some driver does not update status properly
is_deprecated: bool,
@ -27,7 +28,7 @@ pub struct Info {
/// Key to relate data collected with the specific request
request: Option<String>,
/// Hold size info
size: Size,
size: Option<usize>,
/// Optional socket details
/// * useful also for geo-location feature
socket: Option<Socket>,
@ -40,11 +41,12 @@ impl Info {
pub fn new() -> Self {
Self {
event: Vec::with_capacity(50), // estimated max events quantity for all drivers
header: None,
is_deprecated: false,
mime: None,
redirect: None,
request: None,
size: Size::default(),
size: None,
socket: None,
}
}
@ -89,13 +91,13 @@ impl Info {
self
}
pub fn set_mime(&mut self, mime: Option<String>) -> &mut Self {
self.mime = mime;
pub fn set_header(&mut self, header: Option<String>) -> &mut Self {
self.header = header;
self
}
pub fn unset_mime(&mut self) -> &mut Self {
self.mime = None;
pub fn set_mime(&mut self, mime: Option<String>) -> &mut Self {
self.mime = mime;
self
}
@ -116,13 +118,8 @@ impl Info {
self
}
pub fn set_size(&mut self, header: Option<usize>, content: Option<usize>) -> &mut Self {
self.size = Size { content, header };
self
}
pub fn unset_size(&mut self) -> &mut Self {
self.size = Size::default();
pub fn set_size(&mut self, size: Option<usize>) -> &mut Self {
self.size = size;
self
}

View file

@ -1,7 +1,9 @@
use super::{Info, Profile};
use adw::{
ActionRow, PreferencesDialog, PreferencesGroup, PreferencesPage,
prelude::{ActionRowExt, PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt},
prelude::{
ActionRowExt, ExpanderRowExt, PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt,
},
};
use gtk::glib::gformat;
@ -37,11 +39,11 @@ impl Dialog for PreferencesDialog {
g
});
} // @TODO content language, header size, etc.
if info.size.header.is_some() || info.size.content.is_some() {
if info.size.is_some() || info.header.is_some() {
p.add(&{
use crate::tool::Format;
/// Common `ActionRow` widget pattern
fn r(title: &str, subtitle: &str) -> ActionRow {
fn r(title: &str, subtitle: String) -> ActionRow {
ActionRow::builder()
.css_classes(["property"])
.subtitle_selectable(true)
@ -53,18 +55,45 @@ impl Dialog for PreferencesDialog {
let g = PreferencesGroup::builder().title("Size").build();
let mut i = 0; // count group members
let mut t = 0; // count total size
if let Some(ref h) = info.size.header {
if let Some(ref h) = info.header {
let l = h.len();
i += 1;
t += h;
g.add(&r("Header", &h.bytes()))
t += l;
g.add(&{
let e = adw::ExpanderRow::builder()
/* @TODO this class does not work with `ExpanderRow`
.css_classes(["property"]) */
.enable_expansion(true)
.expanded(false)
.subtitle(l.bytes())
.title_selectable(true)
.title("Header")
.build();
e.add_row(
&gtk::Label::builder()
.css_classes(["dim-label", "caption"])
.ellipsize(gtk::pango::EllipsizeMode::None)
.halign(gtk::Align::Start)
.label(h)
.margin_bottom(2)
.margin_end(12)
.margin_start(12)
.margin_top(14)
.selectable(true)
.valign(gtk::Align::Center)
.wrap(false)
.build(), // @TODO replace with `ActionRow` after fix empty subtitle issue
);
e
})
}
if let Some(ref c) = info.size.content {
if let Some(ref c) = info.size {
i += 1;
t += c;
g.add(&r("Content", &c.bytes()))
g.add(&r("Content", c.bytes()))
}
if i > 1 && t > 0 {
g.add(&r("Total", &t.bytes()))
g.add(&r("Total", t.bytes()))
}
g
});

View file

@ -1,5 +0,0 @@
#[derive(Default)]
pub struct Size {
pub content: Option<usize>,
pub header: Option<usize>,
}