From 054c30b2387d1ea20d4b17fcd9fcd9ccbec8a0a7 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 23 Jan 2025 16:11:19 +0200 Subject: [PATCH] remove extra title member --- src/app/browser/window/tab/item/client.rs | 4 +-- .../window/tab/item/client/driver/gemini.rs | 35 +++++++++---------- src/app/browser/window/tab/item/page.rs | 11 ++---- .../browser/window/tab/item/page/database.rs | 19 +++------- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/app/browser/window/tab/item/client.rs b/src/app/browser/window/tab/item/client.rs index 9c12ccf2..7205c88d 100644 --- a/src/app/browser/window/tab/item/client.rs +++ b/src/app/browser/window/tab/item/client.rs @@ -61,7 +61,7 @@ impl Client { // Reset widgets self.subject.page.search.unset(); self.subject.page.input.unset(); - self.subject.page.title.replace("Loading..".into()); + self.subject.tab_page.set_title("Loading.."); self.subject .page .navigation @@ -91,7 +91,7 @@ impl Client { status.set_description(Some(&format!( "Scheme `{scheme}` yet not supported" ))); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject .page .navigation diff --git a/src/app/browser/window/tab/item/client/driver/gemini.rs b/src/app/browser/window/tab/item/client/driver/gemini.rs index d126e4c2..31bfe959 100644 --- a/src/app/browser/window/tab/item/client/driver/gemini.rs +++ b/src/app/browser/window/tab/item/client/driver/gemini.rs @@ -129,8 +129,7 @@ impl Gemini { todo!()*/ } }); - - self.subject.page.title.replace("Titan input".into()); + self.subject.tab_page.set_title("Titan input"); self.subject .page .navigation @@ -199,7 +198,7 @@ fn handle( Some(1024), ); } - subject.page.title.replace(title.into()); + subject.tab_page.set_title(&title); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -271,7 +270,7 @@ fn handle( } }, ); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -294,7 +293,7 @@ fn handle( subject.page.search.set(Some(widget.text_view)); // Update page meta - subject.page.title.replace(match widget.meta.title { + subject.tab_page.set_title(&match widget.meta.title { Some(title) => title.into(), // @TODO None => uri_to_title(&uri), }); @@ -313,7 +312,7 @@ fn handle( Err(e) => { let status = subject.page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -348,13 +347,13 @@ fn handle( move |result| { match result { Ok(buffer) => { - subject.page.title.replace(uri_to_title(&uri)); + subject.tab_page.set_title(&uri_to_title(&uri)); subject.page.content.to_image(&Texture::for_pixbuf(&buffer)); } Err(e) => { let status = subject.page.content.to_status_failure(); status.set_description(Some(e.message())); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); } } subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); @@ -367,7 +366,7 @@ fn handle( let status = subject.page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -381,7 +380,7 @@ fn handle( .content .to_status_mime(mime, Some((&subject.page.tab_action, &uri))); status.set_description(Some(&format!("Content type `{mime}` yet not supported"))); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -390,7 +389,7 @@ fn handle( None => { let status = subject.page.content.to_status_failure(); status.set_description(Some("MIME type not found")); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -428,7 +427,7 @@ fn handle( if total > 5 { let status = subject.page.content.to_status_failure(); status.set_description(Some("Redirection limit reached")); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -439,7 +438,7 @@ fn handle( || uri.host() != target.host() { let status = subject.page.content.to_status_failure(); status.set_description(Some("External redirects not allowed by protocol specification")); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -459,7 +458,7 @@ fn handle( Err(e) => { let status = subject.page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -468,7 +467,7 @@ fn handle( None => { let status = subject.page.content.to_status_failure(); status.set_description(Some("Redirection target not found")); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -487,7 +486,7 @@ fn handle( None => response.meta.status.to_string(), })); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -495,7 +494,7 @@ fn handle( status => { let _status = subject.page.content.to_status_failure(); _status.set_description(Some(&format!("Undefined status code `{status}`"))); - subject.page.title.replace(_status.title()); + subject.tab_page.set_title(&_status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset @@ -505,7 +504,7 @@ fn handle( Err(e) => { let status = subject.page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - subject.page.title.replace(status.title()); + subject.tab_page.set_title(&status.title()); subject.page.navigation.request.widget.entry.set_progress_fraction(0.0); subject.tab_page.set_loading(false); redirects.replace(0); // reset diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 0289f3c6..99c38320 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -17,12 +17,11 @@ use super::{Action as TabAction, BrowserAction, Profile, WindowAction}; use gtk::{glib::GString, prelude::EditableExt}; use sqlite::Transaction; -use std::{cell::RefCell, rc::Rc}; +use std::rc::Rc; pub struct Page { pub id: Rc, pub profile: Rc, - pub title: Rc>, // Actions pub browser_action: Rc, pub tab_action: Rc, @@ -71,7 +70,6 @@ impl Page { Self { id: id.clone(), profile: profile.clone(), - title: Rc::new(RefCell::new("New page".into())), // Actions browser_action: browser_action.clone(), tab_action: tab_action.clone(), @@ -152,7 +150,6 @@ impl Page { Ok(records) => { for record in records { // Restore self by last record - self.title.replace(record.title.into()); // Delegate restore action to the item childs self.navigation.restore(transaction, &record.id)?; // Make initial page history snap using `navigation` values restored @@ -173,11 +170,7 @@ impl Page { transaction: &Transaction, app_browser_window_tab_item_id: i64, ) -> Result<(), String> { - match database::insert( - transaction, - app_browser_window_tab_item_id, - self.title.borrow().as_str(), - ) { + match database::insert(transaction, app_browser_window_tab_item_id) { Ok(_) => { let id = database::last_insert_id(transaction); diff --git a/src/app/browser/window/tab/item/page/database.rs b/src/app/browser/window/tab/item/page/database.rs index b1480eb4..1f0ea6b3 100644 --- a/src/app/browser/window/tab/item/page/database.rs +++ b/src/app/browser/window/tab/item/page/database.rs @@ -3,7 +3,6 @@ use sqlite::{Error, Transaction}; pub struct Table { pub id: i64, // pub app_browser_window_tab_item_id: i64, not in use, - pub title: String, } pub fn init(tx: &Transaction) -> Result { @@ -12,7 +11,6 @@ pub fn init(tx: &Transaction) -> Result { ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_window_tab_item_id` INTEGER NOT NULL, - `title` VARCHAR(1024), FOREIGN KEY (`app_browser_window_tab_item_id`) REFERENCES `app_browser_window_tab_item`(`id`) )", @@ -20,25 +18,19 @@ pub fn init(tx: &Transaction) -> Result { ) } -pub fn insert( - tx: &Transaction, - app_browser_window_tab_item_id: i64, - title: &str, -) -> Result { +pub fn insert(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result { tx.execute( "INSERT INTO `app_browser_window_tab_item_page` ( - `app_browser_window_tab_item_id`, - `title` - ) VALUES (?, ?)", - (app_browser_window_tab_item_id, title), + `app_browser_window_tab_item_id` + ) VALUES (?)", + [app_browser_window_tab_item_id], ) } pub fn select(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result, Error> { let mut stmt = tx.prepare( "SELECT `id`, - `app_browser_window_tab_item_id`, - `title` + `app_browser_window_tab_item_id` FROM `app_browser_window_tab_item_page` WHERE `app_browser_window_tab_item_id` = ?", )?; @@ -47,7 +39,6 @@ pub fn select(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result