From 5ab51db94656d8d925827507fa166f76a50cb95e Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 21 Jan 2025 18:29:09 +0200 Subject: [PATCH] remove deprecated features --- src/app/browser/window/tab.rs | 9 ++-- .../window/tab/item/client/driver/gemini.rs | 54 ++----------------- src/app/browser/window/tab/item/page.rs | 19 ------- .../browser/window/tab/item/page/status.rs | 43 --------------- src/tool.rs | 13 ----- 5 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 src/app/browser/window/tab/item/page/status.rs diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 09b7cb34..b5db8201 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -284,10 +284,7 @@ impl Tab { } pub fn update(&self, item_id: Option) { - let key = match item_id { - Some(value) => value, - None => GString::new(), // @TODO - }; + let key = item_id.unwrap_or_default(); match self.index.borrow().get(&key) { Some(item) => { @@ -296,7 +293,7 @@ impl Tab { // Update tab title on loading indicator inactive if !item.page.is_loading() { - item.widget.tab_page.set_title(&item.page.title()) + item.widget.tab_page.set_title(&item.page.title.borrow()) } } // Update all tabs @@ -307,7 +304,7 @@ impl Tab { // Update tab title on loading indicator inactive if !item.page.is_loading() { - item.widget.tab_page.set_title(&item.page.title()) + item.widget.tab_page.set_title(&item.page.title.borrow()) } } } 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 799eedda..e577be9f 100644 --- a/src/app/browser/window/tab/item/client/driver/gemini.rs +++ b/src/app/browser/window/tab/item/client/driver/gemini.rs @@ -1,7 +1,3 @@ -use crate::tool::now; - -use super::super::super::page::status::Status as PageStatus; // @TODO - use super::{Feature, Page}; use gtk::glib::{GString, UriFlags}; use gtk::prelude::{EditableExt, FileExt}; @@ -84,9 +80,6 @@ impl Gemini { // Reset widgets self.page.search.unset(); self.page.input.unset(); - self.page - .status - .replace(PageStatus::Loading { time: now() }); self.page.title.replace("Loading..".into()); self.page .browser_action @@ -136,7 +129,6 @@ impl Gemini { Some(1024), ); page.title.replace(title.into()); // @TODO - page.status.replace(PageStatus::Input { time: now() }); page.browser_action.update.activate(Some(&page.id)); } Status::SensitiveInput => { @@ -151,7 +143,6 @@ impl Gemini { Some(1024), ); page.title.replace(title.into()); // @TODO - page.status.replace(PageStatus::Input { time: now() }); page.browser_action.update.activate(Some(&page.id)); } // https://geminiprotocol.net/docs/protocol-specification.gmi#status-20 @@ -221,7 +212,6 @@ impl Gemini { } }, ); - page.status.replace(PageStatus::Success { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); }, @@ -248,8 +238,6 @@ impl Gemini { page.search.set(Some(widget.text_view)); // Update page meta - page.status - .replace(PageStatus::Success { time: now() }); page.title.replace(match widget.meta.title { Some(title) => title.into(), // @TODO None => uri_to_title(&uri), @@ -270,7 +258,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); }, @@ -307,8 +294,6 @@ impl Gemini { // Process buffer data match result { Ok(buffer) => { - page.status - .replace(PageStatus::Success { time: now() }); page.title.replace(uri_to_title(&uri)); page.content .to_image(&Texture::for_pixbuf(&buffer)); @@ -319,9 +304,6 @@ impl Gemini { Err(e) => { let status = page.content.to_status_failure(); status.set_description(Some(e.message())); - - page.status - .replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); } }; @@ -333,7 +315,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); } @@ -347,7 +328,6 @@ impl Gemini { .to_status_mime(mime, Some((&page.tab_action, &uri))); status.set_description(Some(&format!("Content type `{mime}` yet not supported"))); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); }, @@ -356,7 +336,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some("MIME type not found")); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); }, @@ -377,7 +356,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some("Redirection limit reached")); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); @@ -390,7 +368,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some("External redirects not allowed by protocol specification")); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); @@ -412,7 +389,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); } @@ -422,45 +398,23 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some("Redirection target not found")); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); } } }, // https://geminiprotocol.net/docs/protocol-specification.gmi#status-60 - Status::CertificateRequest => { - let status = page.content.to_status_identity(); - status.set_description(Some(&match response.meta.data { - Some(data) => data.to_string(), - None => Status::CertificateRequest.to_string(), - })); - - page.status.replace(PageStatus::Success { time: now() }); - page.title.replace(status.title()); - page.browser_action.update.activate(Some(&page.id)); - } + Status::CertificateRequest | // https://geminiprotocol.net/docs/protocol-specification.gmi#status-61-certificate-not-authorized - Status::CertificateUnauthorized => { - let status = page.content.to_status_identity(); - status.set_description(Some(&match response.meta.data { - Some(data) => data.to_string(), - None => Status::CertificateUnauthorized.to_string(), - })); - - page.status.replace(PageStatus::Success { time: now() }); - page.title.replace(status.title()); - page.browser_action.update.activate(Some(&page.id)); - } + Status::CertificateUnauthorized | // https://geminiprotocol.net/docs/protocol-specification.gmi#status-62-certificate-not-valid Status::CertificateInvalid => { let status = page.content.to_status_identity(); status.set_description(Some(&match response.meta.data { Some(data) => data.to_string(), - None => Status::CertificateInvalid.to_string(), + None => response.meta.status.to_string(), })); - page.status.replace(PageStatus::Success { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); } @@ -468,7 +422,6 @@ impl Gemini { let _status = page.content.to_status_failure(); _status.set_description(Some(&format!("Undefined status code `{status}`"))); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(_status.title()); page.browser_action.update.activate(Some(&page.id)); }, @@ -478,7 +431,6 @@ impl Gemini { let status = page.content.to_status_failure(); status.set_description(Some(&e.to_string())); - page.status.replace(PageStatus::Failure { time: now() }); page.title.replace(status.title()); page.browser_action.update.activate(Some(&page.id)); }, diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index b2bc701b..1be9e66e 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -4,7 +4,6 @@ mod error; mod input; mod navigation; mod search; -pub mod status; mod widget; use content::Content; @@ -12,11 +11,9 @@ use error::Error; use input::Input; use navigation::Navigation; use search::Search; -use status::Status; use widget::Widget; use super::{Action as TabAction, BrowserAction, Profile, WindowAction}; -use crate::tool::now; use gtk::{ glib::GString, @@ -28,7 +25,6 @@ use std::{cell::RefCell, rc::Rc}; pub struct Page { pub id: Rc, pub profile: Rc, - pub status: Rc>, pub title: Rc>, // Actions pub browser_action: Rc, @@ -74,8 +70,6 @@ impl Page { &input.widget.clamp, )); - let status = Rc::new(RefCell::new(Status::New { time: now() })); - // Done Self { id: id.clone(), @@ -86,7 +80,6 @@ impl Page { tab_action: tab_action.clone(), window_action: window_action.clone(), // Components - status, content, search, input, @@ -157,9 +150,6 @@ impl Page { transaction: &Transaction, app_browser_window_tab_item_id: i64, ) -> Result<(), String> { - // Update status - self.status.replace(Status::SessionRestore { time: now() }); - // Begin page restore match database::select(transaction, app_browser_window_tab_item_id) { Ok(records) => { @@ -177,10 +167,6 @@ impl Page { } Err(e) => return Err(e.to_string()), } - - // Update status - self.status.replace(Status::SessionRestored { time: now() }); - Ok(()) } @@ -209,11 +195,6 @@ impl Page { // Getters - /// Get `title` copy from `Self` - pub fn title(&self) -> GString { - self.title.borrow().clone() - } - /// Get `Self` loading status pub fn is_loading(&self) -> bool { let progress_fraction = self.navigation.request.widget.entry.progress_fraction(); diff --git a/src/app/browser/window/tab/item/page/status.rs b/src/app/browser/window/tab/item/page/status.rs deleted file mode 100644 index 72a071a9..00000000 --- a/src/app/browser/window/tab/item/page/status.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Global dependencies -use crate::tool::format_time; -use gtk::glib::DateTime; -use std::fmt::{Display, Formatter, Result}; - -/// `Page` status -pub enum Status { - Failure { time: DateTime }, - Input { time: DateTime }, - Loading { time: DateTime }, - New { time: DateTime }, - SessionRestore { time: DateTime }, - SessionRestored { time: DateTime }, - Success { time: DateTime }, -} - -impl Display for Status { - fn fmt(&self, f: &mut Formatter) -> Result { - match self { - Self::Failure { time } => { - write!(f, "[{}] Failure", format_time(time)) - } - Self::Input { time } => { - write!(f, "[{}] Input issue", format_time(time)) - } - Self::Loading { time } => { - write!(f, "[{}] Loading...", format_time(time)) - } - Self::New { time } => { - write!(f, "[{}] New page", format_time(time)) - } - Self::SessionRestore { time } => { - write!(f, "[{}] Session restore...", format_time(time)) - } - Self::SessionRestored { time } => { - write!(f, "[{}] Session restored", format_time(time)) - } - Self::Success { time } => { - write!(f, "[{}] Success", format_time(time)) - } - } - } -} diff --git a/src/tool.rs b/src/tool.rs index e111d38f..b1ec934b 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -1,8 +1,5 @@ //! Some shared helpers collection -// Global dependencies -use gtk::glib::{DateTime, GString}; - /// Format bytes to KB/MB/GB presentation pub fn format_bytes(value: usize) -> String { const KB: f32 = 1024.0; @@ -24,13 +21,3 @@ pub fn format_bytes(value: usize) -> String { format!("{:.2} GB", f / GB) } } - -/// Format given [DateTime](https://docs.gtk.org/glib/struct.DateTime.html) -pub fn format_time(t: &DateTime) -> GString { - t.format_iso8601().unwrap() // @TODO handle? -} - -/// Get current [DateTime](https://docs.gtk.org/glib/struct.DateTime.html) -pub fn now() -> DateTime { - DateTime::now_local().unwrap() // @TODO handle? -}