mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
use parsed header as title on available
This commit is contained in:
parent
8b521e459a
commit
841c4a4a99
@ -4,7 +4,7 @@ mod text;
|
||||
use text::Text;
|
||||
|
||||
use gtk::{
|
||||
glib::Uri,
|
||||
glib::{GString, Uri},
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Box, Orientation,
|
||||
};
|
||||
@ -14,6 +14,10 @@ pub enum Mime {
|
||||
TextPlain,
|
||||
}
|
||||
|
||||
pub struct ResetResult {
|
||||
pub title: Option<GString>,
|
||||
}
|
||||
|
||||
pub struct Content {
|
||||
widget: Box,
|
||||
}
|
||||
@ -27,16 +31,22 @@ impl Content {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) {
|
||||
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) -> ResetResult {
|
||||
// Cleanup
|
||||
while let Some(child) = self.widget.last_child() {
|
||||
self.widget.remove(&child)
|
||||
}
|
||||
|
||||
// Compose
|
||||
// Re-compose
|
||||
match mime {
|
||||
Mime::TextGemini => {
|
||||
self.widget.append(Text::gemini(data, base).widget());
|
||||
let child = Text::gemini(data, base);
|
||||
|
||||
self.widget.append(child.widget());
|
||||
|
||||
ResetResult {
|
||||
title: child.meta_title().clone(),
|
||||
}
|
||||
}
|
||||
Mime::TextPlain => {
|
||||
todo!()
|
||||
|
@ -2,9 +2,17 @@ mod gemini;
|
||||
|
||||
use gemini::Gemini;
|
||||
|
||||
use gtk::{glib::Uri, ScrolledWindow};
|
||||
use gtk::{
|
||||
glib::{GString, Uri},
|
||||
ScrolledWindow,
|
||||
};
|
||||
|
||||
pub struct Meta {
|
||||
title: Option<GString>,
|
||||
}
|
||||
|
||||
pub struct Text {
|
||||
meta: Meta,
|
||||
widget: ScrolledWindow,
|
||||
}
|
||||
|
||||
@ -14,16 +22,25 @@ impl Text {
|
||||
// Init components
|
||||
let gemini = Gemini::new(gemtext, base);
|
||||
|
||||
// Init meta
|
||||
let meta = Meta {
|
||||
title: gemini.reader_title().clone(),
|
||||
};
|
||||
|
||||
// Init widget
|
||||
let widget = ScrolledWindow::builder().build();
|
||||
|
||||
widget.set_child(Some(gemini.widget()));
|
||||
|
||||
// Result
|
||||
Self { widget }
|
||||
Self { meta, widget }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn meta_title(&self) -> &Option<GString> {
|
||||
&self.meta.title
|
||||
}
|
||||
|
||||
pub fn widget(&self) -> &ScrolledWindow {
|
||||
&self.widget
|
||||
}
|
||||
|
@ -203,7 +203,13 @@ impl Page {
|
||||
meta.borrow_mut().mime = Some(Mime::TextGemini);
|
||||
// Select widget
|
||||
match parts.get(4) {
|
||||
Some(source) => content.reset(content::Mime::TextGemini, &uri, &source),
|
||||
Some(source) => {
|
||||
// Update component
|
||||
let result = content.reset(content::Mime::TextGemini, &uri, &source);
|
||||
|
||||
// This content type may return parsed title
|
||||
meta.borrow_mut().title = result.title.clone();
|
||||
},
|
||||
None => todo!(),
|
||||
}
|
||||
},
|
||||
@ -229,20 +235,20 @@ impl Page {
|
||||
};
|
||||
|
||||
// Update
|
||||
let _ = widget.activate_action(
|
||||
widget.activate_action(
|
||||
"win.update",
|
||||
None,
|
||||
);
|
||||
).expect("Action `win.update` not found");
|
||||
}
|
||||
Err(e) => {
|
||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}"));
|
||||
meta.borrow_mut().progress_fraction = 1.0;
|
||||
|
||||
let _ = widget.activate_action(
|
||||
widget.activate_action(
|
||||
"win.update",
|
||||
None,
|
||||
);
|
||||
).expect("Action `win.update` not found");
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,10 +263,10 @@ impl Page {
|
||||
meta.borrow_mut().description = Some(gformat!("Failed to read response: {:?}", e));
|
||||
meta.borrow_mut().progress_fraction = 1.0;
|
||||
|
||||
let _ = widget.activate_action(
|
||||
widget.activate_action(
|
||||
"win.update",
|
||||
None,
|
||||
);
|
||||
).expect("Action `win.update` not found");
|
||||
|
||||
// Close connection
|
||||
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||
@ -276,10 +282,10 @@ impl Page {
|
||||
meta.borrow_mut().description = Some(gformat!("Failed to read request: {:?}", e));
|
||||
meta.borrow_mut().progress_fraction = 1.0;
|
||||
|
||||
let _ = widget.activate_action(
|
||||
widget.activate_action(
|
||||
"win.update",
|
||||
None,
|
||||
);
|
||||
).expect("Action `win.update` not found");
|
||||
|
||||
// Close connection
|
||||
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||
@ -295,10 +301,10 @@ impl Page {
|
||||
meta.borrow_mut().description = Some(gformat!("Failed to connect: {:?}", e));
|
||||
meta.borrow_mut().progress_fraction = 1.0;
|
||||
|
||||
let _ = widget.activate_action(
|
||||
widget.activate_action(
|
||||
"win.update",
|
||||
None,
|
||||
);
|
||||
).expect("Action `win.update` not found");
|
||||
}
|
||||
},
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user