From deafe0845db672e5116c8ac381af273a5d73bde9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 18 Oct 2024 05:14:38 +0300 Subject: [PATCH] draft image controller --- src/app/browser/window/tab/item/page.rs | 30 +++++++++++++++++++ .../browser/window/tab/item/page/content.rs | 11 ++++++- .../window/tab/item/page/content/image.rs | 19 ++++++++++++ src/app/browser/window/tab/item/page/meta.rs | 4 +++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/app/browser/window/tab/item/page/content/image.rs diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 7cf62698..e5341f40 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -350,6 +350,36 @@ impl Page { action_update.activate(Some(&id)); todo!() }, + "image/png" | "image/gif" | "image/jpeg" | "image/webp" => { + // Update meta + meta.borrow_mut().status = Some(Status::Success); + meta.borrow_mut().title = Some(gformat!("Picture")); // @TODO + meta.borrow_mut().mime = match mime.as_str() { + "image/png" => Some(Mime::ImagePng), + "image/gif" => Some(Mime::ImageGif), + "image/jpeg" => Some(Mime::ImageJpeg), + "image/webp" => Some(Mime::ImageWebp), + _ => panic!() + }; + + // Update content + content.set_image(); // @TODO + + // Add new history record + let request = uri.to_str(); + + match navigation.history_current() { + Some(current) => { + if current != request { + navigation.history_add(request); + } + } + None => navigation.history_add(request), + } + + // Update window components + action_update.activate(Some(&id)); + }, _ => { // Define common data let status = Status::Failure; diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 24c58d2b..327a4d1f 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -1,7 +1,8 @@ -// @TODO mod image; +mod image; mod status; mod text; +use image::Image; use status::Status; use text::Text; @@ -33,6 +34,14 @@ impl Content { } // Actions + pub fn set_image(&self) { + self.clean(); + + let image = Image::new(); + + self.gobject.append(image.gobject()); + } + pub fn set_status_failure(&self, title: &str, description: &str) { self.clean(); diff --git a/src/app/browser/window/tab/item/page/content/image.rs b/src/app/browser/window/tab/item/page/content/image.rs new file mode 100644 index 00000000..824c86e4 --- /dev/null +++ b/src/app/browser/window/tab/item/page/content/image.rs @@ -0,0 +1,19 @@ +use gtk::Picture; + +pub struct Image { + gobject: Picture, +} + +impl Image { + // Construct + pub fn new() -> Self { + Self { + gobject: Picture::new(), + } + } + + // Getters + pub fn gobject(&self) -> &Picture { + &self.gobject + } +} diff --git a/src/app/browser/window/tab/item/page/meta.rs b/src/app/browser/window/tab/item/page/meta.rs index 29ab627e..6d719157 100644 --- a/src/app/browser/window/tab/item/page/meta.rs +++ b/src/app/browser/window/tab/item/page/meta.rs @@ -5,6 +5,10 @@ use gtk::glib::GString; pub enum Mime { TextGemini, TextPlain, + ImagePng, + ImageGif, + ImageJpeg, + ImageWebp, } // Internal page status (not related with gemini status code)