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 text::Text;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib::Uri,
|
glib::{GString, Uri},
|
||||||
prelude::{BoxExt, WidgetExt},
|
prelude::{BoxExt, WidgetExt},
|
||||||
Box, Orientation,
|
Box, Orientation,
|
||||||
};
|
};
|
||||||
@ -14,6 +14,10 @@ pub enum Mime {
|
|||||||
TextPlain,
|
TextPlain,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ResetResult {
|
||||||
|
pub title: Option<GString>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
widget: Box,
|
widget: Box,
|
||||||
}
|
}
|
||||||
@ -27,16 +31,22 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) {
|
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) -> ResetResult {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
while let Some(child) = self.widget.last_child() {
|
while let Some(child) = self.widget.last_child() {
|
||||||
self.widget.remove(&child)
|
self.widget.remove(&child)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compose
|
// Re-compose
|
||||||
match mime {
|
match mime {
|
||||||
Mime::TextGemini => {
|
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 => {
|
Mime::TextPlain => {
|
||||||
todo!()
|
todo!()
|
||||||
|
@ -2,9 +2,17 @@ mod gemini;
|
|||||||
|
|
||||||
use gemini::Gemini;
|
use gemini::Gemini;
|
||||||
|
|
||||||
use gtk::{glib::Uri, ScrolledWindow};
|
use gtk::{
|
||||||
|
glib::{GString, Uri},
|
||||||
|
ScrolledWindow,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct Meta {
|
||||||
|
title: Option<GString>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
|
meta: Meta,
|
||||||
widget: ScrolledWindow,
|
widget: ScrolledWindow,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,16 +22,25 @@ impl Text {
|
|||||||
// Init components
|
// Init components
|
||||||
let gemini = Gemini::new(gemtext, base);
|
let gemini = Gemini::new(gemtext, base);
|
||||||
|
|
||||||
|
// Init meta
|
||||||
|
let meta = Meta {
|
||||||
|
title: gemini.reader_title().clone(),
|
||||||
|
};
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = ScrolledWindow::builder().build();
|
let widget = ScrolledWindow::builder().build();
|
||||||
|
|
||||||
widget.set_child(Some(gemini.widget()));
|
widget.set_child(Some(gemini.widget()));
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self { widget }
|
Self { meta, widget }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
pub fn meta_title(&self) -> &Option<GString> {
|
||||||
|
&self.meta.title
|
||||||
|
}
|
||||||
|
|
||||||
pub fn widget(&self) -> &ScrolledWindow {
|
pub fn widget(&self) -> &ScrolledWindow {
|
||||||
&self.widget
|
&self.widget
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,13 @@ impl Page {
|
|||||||
meta.borrow_mut().mime = Some(Mime::TextGemini);
|
meta.borrow_mut().mime = Some(Mime::TextGemini);
|
||||||
// Select widget
|
// Select widget
|
||||||
match parts.get(4) {
|
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!(),
|
None => todo!(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -229,20 +235,20 @@ impl Page {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
let _ = widget.activate_action(
|
widget.activate_action(
|
||||||
"win.update",
|
"win.update",
|
||||||
None,
|
None,
|
||||||
);
|
).expect("Action `win.update` not found");
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
meta.borrow_mut().title = Some(gformat!("Oops"));
|
meta.borrow_mut().title = Some(gformat!("Oops"));
|
||||||
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}"));
|
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}"));
|
||||||
meta.borrow_mut().progress_fraction = 1.0;
|
meta.borrow_mut().progress_fraction = 1.0;
|
||||||
|
|
||||||
let _ = widget.activate_action(
|
widget.activate_action(
|
||||||
"win.update",
|
"win.update",
|
||||||
None,
|
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().description = Some(gformat!("Failed to read response: {:?}", e));
|
||||||
meta.borrow_mut().progress_fraction = 1.0;
|
meta.borrow_mut().progress_fraction = 1.0;
|
||||||
|
|
||||||
let _ = widget.activate_action(
|
widget.activate_action(
|
||||||
"win.update",
|
"win.update",
|
||||||
None,
|
None,
|
||||||
);
|
).expect("Action `win.update` not found");
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
if let Err(e) = connection.close(Some(&cancellable)) {
|
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().description = Some(gformat!("Failed to read request: {:?}", e));
|
||||||
meta.borrow_mut().progress_fraction = 1.0;
|
meta.borrow_mut().progress_fraction = 1.0;
|
||||||
|
|
||||||
let _ = widget.activate_action(
|
widget.activate_action(
|
||||||
"win.update",
|
"win.update",
|
||||||
None,
|
None,
|
||||||
);
|
).expect("Action `win.update` not found");
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
if let Err(e) = connection.close(Some(&cancellable)) {
|
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().description = Some(gformat!("Failed to connect: {:?}", e));
|
||||||
meta.borrow_mut().progress_fraction = 1.0;
|
meta.borrow_mut().progress_fraction = 1.0;
|
||||||
|
|
||||||
let _ = widget.activate_action(
|
widget.activate_action(
|
||||||
"win.update",
|
"win.update",
|
||||||
None,
|
None,
|
||||||
);
|
).expect("Action `win.update` not found");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user