move info component into navigation request level

This commit is contained in:
yggverse 2025-03-21 22:44:33 +02:00
parent d1623bda9e
commit 05a8647f28
7 changed files with 34 additions and 23 deletions

View file

@ -1,5 +1,6 @@
mod database;
mod identity;
mod info;
mod primary_icon;
mod search;
mod suggestion;
@ -12,9 +13,14 @@ use gtk::{
glib::{GString, Uri, UriFlags, gformat},
prelude::{EditableExt, EntryExt, WidgetExt},
};
use info::Info;
use primary_icon::PrimaryIcon;
use sqlite::Transaction;
use std::{cell::Cell, rc::Rc, sync::Arc};
use std::{
cell::{Cell, RefCell},
rc::Rc,
sync::Arc,
};
use suggestion::Suggestion;
const PREFIX_DOWNLOAD: &str = "download:";
@ -22,6 +28,7 @@ const PREFIX_SOURCE: &str = "source:";
pub struct Request {
pub entry: Entry,
pub info: Rc<RefCell<Info>>,
suggestion: Rc<Suggestion>,
profile: Arc<Profile>,
}
@ -31,6 +38,9 @@ impl Request {
/// Build new `Self`
pub fn build(item_action: &Rc<ItemAction>, profile: &Arc<Profile>) -> Self {
// Init components
let info = Rc::new(RefCell::new(Info::new()));
// Init main widget
let entry = Entry::builder()
.placeholder_text("URL or search term...")
@ -95,7 +105,7 @@ impl Request {
}
});
entry.connect_has_focus_notify(update_secondary_icon);
entry.connect_has_focus_notify(|this| update_secondary_icon(this, false));
suggestion
.signal_handler_id
@ -111,7 +121,7 @@ impl Request {
// Update icons
update_primary_icon(this, &profile);
update_secondary_icon(this);
update_secondary_icon(this, false);
// Show search suggestions
if this.focus_child().is_some() {
@ -162,6 +172,7 @@ impl Request {
Self {
entry,
info,
suggestion,
profile: profile.clone(),
}
@ -325,13 +336,18 @@ fn is_focused(entry: &Entry) -> bool {
/// 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) {
fn update_secondary_icon(entry: &Entry, has_info: bool) {
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(Some("help-about-symbolic"));
entry.set_secondary_icon_tooltip_text(Some("Page info"));
if has_info {
entry.set_secondary_icon_name(Some("help-about-symbolic"));
entry.set_secondary_icon_tooltip_text(Some("Page info"));
} else {
entry.set_secondary_icon_name(None);
entry.set_secondary_icon_tooltip_text(None);
}
entry.select_region(0, 0);
}
}

View file

@ -0,0 +1,104 @@
// 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>,
/// Mark holder as deprecated on handle begin
/// * useful on some driver does not update status properly
is_deprecated: bool,
/// 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
is_deprecated: false,
mime: None,
redirect: None,
remote: None,
request: None,
size: None,
}
}
// Actions
/// Mark `Self` as deprecated
/// * tip: usually called on page handler begin
pub fn deprecate(&mut self) {
self.is_deprecated = true;
}
// 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.is_deprecated = false;
self
}
pub fn set_mime(&mut self, mime: Option<String>) -> &mut Self {
self.mime = mime;
self.is_deprecated = false;
self
}
pub fn set_remote(&mut self, remote: Option<NetworkAddress>) -> &mut Self {
self.remote = remote;
self.is_deprecated = false;
self
}
pub fn set_request(&mut self, request: Option<String>) -> &mut Self {
self.request = request;
self.is_deprecated = false;
self
}
pub fn set_size(&mut self, size: Option<usize>) -> &mut Self {
self.size = size;
self.is_deprecated = false;
self
}
}
impl Default for Info {
fn default() -> Self {
Self::new()
}
}

View 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(),
}
}
}