Browse Source

draft status pages

master
yggverse 1 month ago
parent
commit
db3c5366fd
  1. 23
      src/app/browser/window/tab/item/page.rs
  2. 48
      src/app/browser/window/tab/item/page/content.rs
  3. 23
      src/app/browser/window/tab/item/page/content/status.rs
  4. 15
      src/app/browser/window/tab/item/page/content/status/error.rs
  5. 14
      src/app/browser/window/tab/item/page/content/text.rs

23
src/app/browser/window/tab/item/page.rs

@ -275,8 +275,7 @@ impl Page {
meta.borrow_mut().status = Some(Status::Success); meta.borrow_mut().status = Some(Status::Success);
// This content type may return parsed title // This content type may return parsed title
let result = content.reset(content::Mime::TextGemini, &uri, &source); meta.borrow_mut().title = content.set_text_gemini(&uri, &source);
meta.borrow_mut().title = result.title.clone();
// Add new history record // Add new history record
let request = uri.to_str(); let request = uri.to_str();
@ -326,8 +325,7 @@ impl Page {
// Select widget // Select widget
match parts.get(3) { match parts.get(3) {
Some(source) => { Some(source) => {
let _ = content.reset( let _ = content.set_text_gemini(
content::Mime::TextGemini,
&uri, &uri,
// @TODO use template file // @TODO use template file
&gformat!("# Redirect\n\nAuto-follow disabled, click on link below to continue\n\n=> {source}") &gformat!("# Redirect\n\nAuto-follow disabled, click on link below to continue\n\n=> {source}")
@ -410,12 +408,19 @@ impl Page {
"nex" => {} "nex" => {}
*/ */
scheme => { scheme => {
// Update let status = Status::Failure;
meta.borrow_mut().status = Some(Status::Failure); let title = gformat!("Oops");
meta.borrow_mut().title = Some(gformat!("Oops")); let description = gformat!("Protocol {scheme} not supported");
meta.borrow_mut().description =
Some(gformat!("Protocol {scheme} not supported")); // Update widget
content.set_status_error(title.as_str(), description.as_str());
// Update meta
meta.borrow_mut().status = Some(status);
meta.borrow_mut().title = Some(title);
meta.borrow_mut().description = Some(description);
// Update window
action_update.activate(Some(&self.id.to_variant())); action_update.activate(Some(&self.id.to_variant()));
} }
} }

48
src/app/browser/window/tab/item/page/content.rs

@ -1,6 +1,8 @@
// @TODO mod image; // @TODO mod image;
mod status;
mod text; mod text;
use status::Status;
use text::Text; use text::Text;
use gtk::{ use gtk::{
@ -12,18 +14,9 @@ use gtk::{
use std::sync::Arc; use std::sync::Arc;
pub enum Mime {
TextGemini,
// TextPlain,
}
pub struct ResetResult {
pub title: Option<GString>,
}
pub struct Content { pub struct Content {
// GTK // GTK
widget: Box, gobject: Box,
// Actions // Actions
action_tab_open: Arc<SimpleAction>, action_tab_open: Arc<SimpleAction>,
action_page_open: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>,
@ -33,43 +26,44 @@ impl Content {
// Construct // Construct
pub fn new(action_tab_open: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>) -> Self { pub fn new(action_tab_open: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>) -> Self {
Self { Self {
widget: Box::builder().orientation(Orientation::Vertical).build(), gobject: Box::builder().orientation(Orientation::Vertical).build(),
action_tab_open, action_tab_open,
action_page_open, action_page_open,
} }
} }
// Actions // Actions
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) -> ResetResult { pub fn set_status_error(&self, title: &str, description: &str) {
// Cleanup self.clean();
while let Some(child) = self.widget.last_child() {
self.widget.remove(&child) let status_default = Status::new_error(title, description);
self.gobject.append(status_default.gobject());
} }
// Re-compose pub fn set_text_gemini(&self, base: &Uri, data: &str) -> Option<GString> {
match mime { self.clean();
Mime::TextGemini => {
let child = Text::gemini( let text_gemini = Text::gemini(
data, data,
base, base,
self.action_tab_open.clone(), self.action_tab_open.clone(),
self.action_page_open.clone(), self.action_page_open.clone(),
); );
self.widget.append(child.widget()); self.gobject.append(text_gemini.gobject());
ResetResult { text_gemini.meta_title().clone() // @TODO
title: child.meta_title().clone(),
} }
} /* @TODO
Mime::TextPlain => { pub fn clean(&self) {
todo!() while let Some(child) = self.gobject.last_child() {
} */ self.gobject.remove(&child);
} }
} }
// Getters // Getters
pub fn gobject(&self) -> &Box { pub fn gobject(&self) -> &Box {
&self.widget &self.gobject
} }
} }

23
src/app/browser/window/tab/item/page/content/status.rs

@ -0,0 +1,23 @@
mod error;
use error::Error;
use adw::StatusPage;
pub struct Status {
gobject: StatusPage,
}
impl Status {
// Construct
pub fn new_error(title: &str, description: &str) -> Self {
Self {
gobject: Error::new(title, description),
}
}
// Getters
pub fn gobject(&self) -> &StatusPage {
&self.gobject
}
}

15
src/app/browser/window/tab/item/page/content/status/error.rs

@ -0,0 +1,15 @@
use adw::StatusPage;
pub struct Error {
gobject: StatusPage,
}
impl Error {
pub fn new(title: &str, description: &str) -> StatusPage {
StatusPage::builder()
.description(description)
.icon_name("dialog-error-symbolic")
.title(title)
.build()
}
}

14
src/app/browser/window/tab/item/page/content/text.rs

@ -16,7 +16,7 @@ pub struct Meta {
pub struct Text { pub struct Text {
meta: Meta, meta: Meta,
widget: ScrolledWindow, gobject: ScrolledWindow,
} }
impl Text { impl Text {
@ -35,13 +35,13 @@ impl Text {
title: gemini.reader_title().clone(), title: gemini.reader_title().clone(),
}; };
// Init widget // Init gobject
let widget = ScrolledWindow::builder().build(); let gobject = ScrolledWindow::builder().build();
widget.set_child(Some(gemini.gobject())); gobject.set_child(Some(gemini.gobject()));
// Result // Result
Self { meta, widget } Self { meta, gobject }
} }
// Getters // Getters
@ -49,7 +49,7 @@ impl Text {
&self.meta.title &self.meta.title
} }
pub fn widget(&self) -> &ScrolledWindow { pub fn gobject(&self) -> &ScrolledWindow {
&self.widget &self.gobject
} }
} }

Loading…
Cancel
Save