mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
add header size, reorganize Size struct, add unset methods
This commit is contained in:
parent
bf4c2c1e84
commit
1a1fa86ac5
4 changed files with 60 additions and 29 deletions
|
|
@ -182,8 +182,8 @@ fn handle(
|
||||||
fn update_page_info(page: &Page, event_name: &str) {
|
fn update_page_info(page: &Page, event_name: &str) {
|
||||||
let mut i = page.navigation.request.info.borrow_mut();
|
let mut i = page.navigation.request.info.borrow_mut();
|
||||||
i.add_event(event_name.to_string())
|
i.add_event(event_name.to_string())
|
||||||
.set_mime(None)
|
.unset_mime()
|
||||||
.set_size(None)
|
.unset_size()
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
// Update socket info at the point, where the connection is active yet
|
// Update socket info at the point, where the connection is active yet
|
||||||
|
|
@ -322,7 +322,7 @@ fn handle(
|
||||||
i
|
i
|
||||||
.add_event("Parsing".to_string())
|
.add_event("Parsing".to_string())
|
||||||
.set_mime(Some(success.mime().to_string()))
|
.set_mime(Some(success.mime().to_string()))
|
||||||
.set_size(Some(data.len()));
|
.set_size(None, Some(data.len()));
|
||||||
let w = if matches!(*feature, Feature::Source) {
|
let w = if matches!(*feature, Feature::Source) {
|
||||||
page.content.to_text_source(data)
|
page.content.to_text_source(data)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -426,7 +426,7 @@ fn handle(
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_mime(Some(success.mime().to_string()))
|
.set_mime(Some(success.mime().to_string()))
|
||||||
.set_size(Some(buffer.byte_length()))
|
.set_size(None, Some(buffer.byte_length()))
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -439,7 +439,7 @@ fn handle(
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_mime(Some(success.mime().to_string()))
|
.set_mime(Some(success.mime().to_string()))
|
||||||
.set_size(None)
|
.unset_size()
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -466,7 +466,7 @@ fn handle(
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_mime(Some(success.mime().to_string()))
|
.set_mime(Some(success.mime().to_string()))
|
||||||
.set_size(None)
|
.unset_size()
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -491,7 +491,7 @@ fn handle(
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_mime(Some(mime.to_string()))
|
.set_mime(Some(mime.to_string()))
|
||||||
.set_size(None)
|
.unset_size()
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -547,8 +547,8 @@ fn handle(
|
||||||
let mut i = page.navigation.request.info.take();
|
let mut i = page.navigation.request.info.take();
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_mime(None)
|
.unset_mime()
|
||||||
.set_size(None)
|
.unset_size()
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
page.navigation.request.info.replace(i.into_redirect());
|
page.navigation.request.info.replace(i.into_redirect());
|
||||||
|
|
@ -640,8 +640,8 @@ fn handle(
|
||||||
let mut i = page.navigation.request.info.borrow_mut();
|
let mut i = page.navigation.request.info.borrow_mut();
|
||||||
i.add_event(EVENT_COMPLETED.to_string())
|
i.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_request(Some(uri.to_string()))
|
.set_request(Some(uri.to_string()))
|
||||||
.set_mime(None)
|
.unset_mime()
|
||||||
.set_size(None)
|
.unset_size()
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
mod dialog;
|
mod dialog;
|
||||||
mod event;
|
mod event;
|
||||||
|
mod size;
|
||||||
mod socket;
|
mod socket;
|
||||||
|
|
||||||
use super::Profile;
|
use super::Profile;
|
||||||
use dialog::Dialog;
|
use dialog::Dialog;
|
||||||
use event::Event;
|
use event::Event;
|
||||||
use gtk::{gio::SocketAddress, prelude::IsA};
|
use gtk::{gio::SocketAddress, prelude::IsA};
|
||||||
|
use size::Size;
|
||||||
use socket::Socket;
|
use socket::Socket;
|
||||||
|
|
||||||
/// Common, shared `Page` information holder
|
/// Common, shared `Page` information holder
|
||||||
|
|
@ -24,8 +26,8 @@ pub struct Info {
|
||||||
redirect: Option<Box<Self>>,
|
redirect: Option<Box<Self>>,
|
||||||
/// Key to relate data collected with the specific request
|
/// Key to relate data collected with the specific request
|
||||||
request: Option<String>,
|
request: Option<String>,
|
||||||
/// Hold page content size
|
/// Hold size info
|
||||||
size: Option<usize>,
|
size: Size,
|
||||||
/// Optional socket details
|
/// Optional socket details
|
||||||
/// * useful also for geo-location feature
|
/// * useful also for geo-location feature
|
||||||
socket: Option<Socket>,
|
socket: Option<Socket>,
|
||||||
|
|
@ -42,7 +44,7 @@ impl Info {
|
||||||
mime: None,
|
mime: None,
|
||||||
redirect: None,
|
redirect: None,
|
||||||
request: None,
|
request: None,
|
||||||
size: None,
|
size: Size::default(),
|
||||||
socket: None,
|
socket: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +89,11 @@ impl Info {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unset_mime(&mut self) -> &mut Self {
|
||||||
|
self.mime = None;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_socket(
|
pub fn set_socket(
|
||||||
&mut self,
|
&mut self,
|
||||||
local_address: SocketAddress,
|
local_address: SocketAddress,
|
||||||
|
|
@ -104,8 +111,13 @@ impl Info {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_size(&mut self, size: Option<usize>) -> &mut Self {
|
pub fn set_size(&mut self, header: Option<usize>, content: Option<usize>) -> &mut Self {
|
||||||
self.size = size;
|
self.size = Size { content, header };
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unset_size(&mut self) -> &mut Self {
|
||||||
|
self.size = Size::default();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,20 +37,34 @@ impl Dialog for PreferencesDialog {
|
||||||
g
|
g
|
||||||
});
|
});
|
||||||
} // @TODO content language, header size, etc.
|
} // @TODO content language, header size, etc.
|
||||||
if this.size.is_some() {
|
if this.size.header.is_some() || this.size.content.is_some() {
|
||||||
p.add(&{
|
p.add(&{
|
||||||
let g = PreferencesGroup::builder().title("Size").build();
|
|
||||||
if let Some(ref size) = this.size {
|
|
||||||
g.add(&{
|
|
||||||
use crate::tool::Format;
|
use crate::tool::Format;
|
||||||
|
/// Common `ActionRow` widget pattern
|
||||||
|
fn r(title: &str, subtitle: &str) -> ActionRow {
|
||||||
ActionRow::builder()
|
ActionRow::builder()
|
||||||
.css_classes(["property"])
|
.css_classes(["property"])
|
||||||
.subtitle_selectable(true)
|
.subtitle_selectable(true)
|
||||||
.subtitle(size.bytes())
|
.subtitle(subtitle)
|
||||||
.title_selectable(true)
|
.title_selectable(true)
|
||||||
.title("Content")
|
.title(title)
|
||||||
.build()
|
.build()
|
||||||
})
|
}
|
||||||
|
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 c) = this.size.header {
|
||||||
|
i += 1;
|
||||||
|
t += c;
|
||||||
|
g.add(&r("Header", &c.bytes()))
|
||||||
|
}
|
||||||
|
if let Some(ref c) = this.size.content {
|
||||||
|
i += 1;
|
||||||
|
t += c;
|
||||||
|
g.add(&r("Content", &c.bytes()))
|
||||||
|
}
|
||||||
|
if i > 1 && t > 0 {
|
||||||
|
g.add(&r("Total", &t.bytes()))
|
||||||
}
|
}
|
||||||
g
|
g
|
||||||
});
|
});
|
||||||
|
|
@ -77,7 +91,7 @@ impl Dialog for PreferencesDialog {
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Build common `ActionRow` widget
|
/// Common `ActionRow` widget pattern
|
||||||
fn r(title: &str, subtitle: &str) -> ActionRow {
|
fn r(title: &str, subtitle: &str) -> ActionRow {
|
||||||
ActionRow::builder()
|
ActionRow::builder()
|
||||||
.css_classes(["property"])
|
.css_classes(["property"])
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Size {
|
||||||
|
pub content: Option<usize>,
|
||||||
|
pub header: Option<usize>,
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue