mod text;
use text::Text;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
prelude::{BoxExt, WidgetExt},
Box, Orientation,
};
use std::sync::Arc;
pub enum Mime {
TextGemini,
}
pub struct ResetResult {
pub title: Option<GString>,
}
pub struct Content {
widget: Box,
action_page_open: Arc<SimpleAction>,
}
impl Content {
pub fn new(action_page_open: Arc<SimpleAction>) -> Self {
Self {
widget: Box::builder().orientation(Orientation::Vertical).build(),
action_page_open,
}
}
pub fn reset(&self, mime: Mime, base: &Uri, data: &str) -> ResetResult {
while let Some(child) = self.widget.last_child() {
self.widget.remove(&child)
}
match mime {
Mime::TextGemini => {
let child = Text::gemini(data, base, self.action_page_open.clone());
self.widget.append(child.widget());
ResetResult {
title: child.meta_title().clone(),
}
}
}
}
pub fn widget(&self) -> &Box {
&self.widget
}
}