mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
draft page info dialog components, enshort local variables name
This commit is contained in:
parent
20cbde8ce6
commit
731a55cf47
5 changed files with 305 additions and 85 deletions
87
src/app/browser/window/tab/item/page/info.rs
Normal file
87
src/app/browser/window/tab/item/page/info.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
// Public dependencies
|
||||
|
||||
pub mod event;
|
||||
pub use event::Event;
|
||||
|
||||
// Local dependencies
|
||||
|
||||
use gtk::gio::NetworkAddress;
|
||||
|
||||
/// Common, shared `Page` information holder
|
||||
/// * used for the Information dialog window on request indicator activate
|
||||
/// * collecting by the page driver implementation, using public API
|
||||
pub struct Info {
|
||||
/// Hold page events like connection phase and parsing time
|
||||
event: Vec<Event>,
|
||||
/// Page content type
|
||||
mime: Option<String>,
|
||||
/// Hold redirections chain with handled details
|
||||
/// * the `referrer` member name is reserved for other protocols
|
||||
redirect: Option<Box<Self>>,
|
||||
/// Optional remote host details
|
||||
/// * useful also for geo-location feature
|
||||
remote: Option<NetworkAddress>,
|
||||
/// Key to relate data collected with the specific request
|
||||
request: Option<String>,
|
||||
/// Hold page content size
|
||||
size: Option<usize>,
|
||||
}
|
||||
|
||||
impl Info {
|
||||
// Constructors
|
||||
|
||||
/// Create new empty `Self` with expected default capacity
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
event: Vec::with_capacity(50), // estimated max events quantity for all drivers
|
||||
mime: None,
|
||||
redirect: None,
|
||||
remote: None,
|
||||
request: None,
|
||||
size: None,
|
||||
}
|
||||
}
|
||||
|
||||
// Setters
|
||||
// useful to update `Self` as chain of values
|
||||
|
||||
/// Take `Self`, convert it into the redirect member,
|
||||
/// then, return new `Self` back
|
||||
/// * tip: use on driver redirection events
|
||||
pub fn into_redirect(self) -> Self {
|
||||
let mut this = Self::new();
|
||||
this.redirect = Some(Box::new(self));
|
||||
this
|
||||
}
|
||||
|
||||
pub fn add_event(&mut self, name: String) -> &mut Self {
|
||||
self.event.push(Event::now(name));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_mime(&mut self, mime: Option<String>) -> &mut Self {
|
||||
self.mime = mime;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_remote(&mut self, remote: Option<NetworkAddress>) -> &mut Self {
|
||||
self.remote = remote;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_request(&mut self, request: Option<String>) -> &mut Self {
|
||||
self.request = request;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_size(&mut self, size: Option<usize>) -> &mut Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Info {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
22
src/app/browser/window/tab/item/page/info/event.rs
Normal file
22
src/app/browser/window/tab/item/page/info/event.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Local dependencies
|
||||
|
||||
use gtk::glib::DateTime;
|
||||
|
||||
/// Single event holder
|
||||
/// * used in page info dialog to track page load and parse timings
|
||||
pub struct Event {
|
||||
name: String,
|
||||
time: DateTime,
|
||||
}
|
||||
|
||||
impl Event {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self` with auto-completed current local timestamp
|
||||
pub fn now(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
time: DateTime::now_local().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ impl Request {
|
|||
// Init main widget
|
||||
let entry = Entry::builder()
|
||||
.placeholder_text("URL or search term...")
|
||||
.secondary_icon_tooltip_text("Go to the location")
|
||||
.hexpand(true)
|
||||
.build();
|
||||
|
||||
|
|
@ -317,11 +316,22 @@ fn update_primary_icon(entry: &Entry, profile: &Profile) {
|
|||
}
|
||||
}
|
||||
|
||||
/// GTK `is_focus` / `has_focus` not an option here
|
||||
/// also, this method requires from the `Entry`` to be not empty
|
||||
fn is_focused(entry: &Entry) -> bool {
|
||||
entry.text_length() > 0 && entry.focus_child().is_some_and(|child| child.has_focus())
|
||||
}
|
||||
|
||||
/// Secondary icon has two modes:
|
||||
/// * navigate to the location button (on the entry is focused / has edit mode)
|
||||
/// * page info button with dialog window activation (on the entry is inactive)
|
||||
fn update_secondary_icon(entry: &Entry) {
|
||||
if !entry.text().is_empty() && entry.focus_child().is_some_and(|text| text.has_focus()) {
|
||||
if is_focused(entry) {
|
||||
entry.set_secondary_icon_name(Some("pan-end-symbolic"));
|
||||
entry.set_secondary_icon_tooltip_text(Some("Go to the location"))
|
||||
} else {
|
||||
entry.set_secondary_icon_name(None);
|
||||
entry.set_secondary_icon_name(Some("help-about-symbolic"));
|
||||
entry.set_secondary_icon_tooltip_text(Some("Page info"));
|
||||
entry.select_region(0, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -336,12 +346,12 @@ fn show_identity_dialog(entry: &Entry, profile: &Arc<Profile>) {
|
|||
profile,
|
||||
&uri,
|
||||
&Rc::new({
|
||||
let profile = profile.clone();
|
||||
let entry = entry.clone();
|
||||
let p = profile.clone();
|
||||
let e = entry.clone();
|
||||
move |is_reload| {
|
||||
update_primary_icon(&entry, &profile);
|
||||
update_primary_icon(&e, &p);
|
||||
if is_reload {
|
||||
entry.emit_activate();
|
||||
e.emit_activate();
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue