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

@ -40,7 +40,7 @@ impl Client {
self.page.escape();
// Deprecate page info but keep it data as is
self.page.info.borrow_mut().deprecate();
self.page.navigation.request.info.borrow_mut().deprecate();
// Initially disable find action
self.page

View file

@ -38,7 +38,7 @@ impl Gemini {
client.socket.connect_event({
let p = page.clone();
move |_, event, _, _| {
let mut i = p.info.borrow_mut();
let mut i = p.navigation.request.info.borrow_mut();
p.set_progress(match event {
// 0.1 reserved for handle begin
SocketClientEvent::Resolving => {
@ -293,7 +293,7 @@ fn handle(
move |result| match result {
Ok((buffer, _ ,_)) => match std::str::from_utf8(&buffer) {
Ok(data) => {
let mut i = page.info.borrow_mut();
let mut i = page.navigation.request.info.borrow_mut();
i
.add_event("Parsing".to_string())
.set_mime(Some(success.mime().to_string()))
@ -396,7 +396,7 @@ fn handle(
page.set_title(&crate::tool::uri_to_title(&uri));
page.content.to_image(&Texture::for_pixbuf(&buffer));
{
let mut i = page.info.borrow_mut();
let mut i = page.navigation.request.info.borrow_mut();
i
.add_event(EVENT_COMPLETED.to_string())
.set_mime(Some(success.mime().to_string()))
@ -409,7 +409,7 @@ fn handle(
s.set_description(Some(e.message()));
page.set_title(&s.title());
{
let mut i = page.info.borrow_mut();
let mut i = page.navigation.request.info.borrow_mut();
i
.add_event(EVENT_COMPLETED.to_string())
.set_mime(Some(success.mime().to_string()))
@ -436,7 +436,7 @@ fn handle(
}
redirects.replace(0); // reset
{
let mut i = page.info.borrow_mut();
let mut i = page.navigation.request.info.borrow_mut();
i
.add_event(EVENT_COMPLETED.to_string())
.set_mime(Some(success.mime().to_string()))
@ -461,7 +461,7 @@ fn handle(
}
redirects.replace(0); // reset
{
let mut i = page.info.borrow_mut();
let mut i = page.navigation.request.info.borrow_mut();
i
.add_event(EVENT_COMPLETED.to_string())
.set_mime(Some(mime.to_string()))
@ -518,14 +518,14 @@ fn handle(
}
redirects.replace(total);
{
let mut i = page.info.take();
let mut i = page.navigation.request.info.take();
i
.add_event(EVENT_COMPLETED.to_string())
.set_mime(None)
.set_request(Some(uri.to_string()))
.set_size(None);
page.info.replace(i.into_redirect());
page.navigation.request.info.replace(i.into_redirect());
}
page.item_action.load.activate(Some(&t), false);
}
@ -618,7 +618,7 @@ fn handle(
/// Apply common page info pattern
fn update_page_info(page: &Page, uri: &Uri, event_name: &str) {
let mut i = page.info.borrow_mut();
let mut i = page.navigation.request.info.borrow_mut();
i.add_event(event_name.to_string())
.set_mime(None)
.set_request(Some(uri.to_string()))

View file

@ -1,6 +1,5 @@
mod content;
mod database;
mod info;
mod input;
mod navigation;
mod search;
@ -10,12 +9,11 @@ use adw::TabPage;
use anyhow::Result;
use content::Content;
use gtk::prelude::WidgetExt;
use info::Info;
use input::Input;
use navigation::Navigation;
use search::Search;
use sqlite::Transaction;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use std::{rc::Rc, sync::Arc};
pub struct Page {
pub profile: Arc<Profile>,
@ -23,7 +21,6 @@ pub struct Page {
pub item_action: Rc<ItemAction>,
pub window_action: Rc<WindowAction>,
// Components
pub info: Rc<RefCell<Info>>,
pub content: Rc<Content>,
pub input: Rc<Input>,
pub navigation: Rc<Navigation>,
@ -57,7 +54,6 @@ impl Page {
(window_action, tab_action, item_action),
));
let input = Rc::new(Input::new());
let info = Rc::new(RefCell::new(Info::new()));
// Done
Self {
@ -67,7 +63,6 @@ impl Page {
item_action: item_action.clone(),
window_action: window_action.clone(),
// Components
info,
content,
input,
navigation,

View file

@ -24,7 +24,7 @@ const MARGIN: i32 = 6;
const SPACING: i32 = 6;
pub struct Navigation {
request: Rc<Request>,
pub request: Rc<Request>,
bookmark: Rc<Bookmark>,
pub g_box: Box,
}

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);
}
}