mod image;
mod status;
mod text;
use image::Image;
use status::Status;
use text::Text;
use gtk::{
gdk_pixbuf::Pixbuf,
gio::SimpleAction,
glib::{GString, Uri},
prelude::{BoxExt, WidgetExt},
Box, Orientation,
};
pub struct Content {
gobject: Box,
action_tab_open: SimpleAction,
action_page_open: SimpleAction,
}
impl Content {
pub fn new(action_tab_open: SimpleAction, action_page_open: SimpleAction) -> Self {
Self {
gobject: Box::builder().orientation(Orientation::Vertical).build(),
action_tab_open,
action_page_open,
}
}
pub fn set_image(&self, buffer: &Pixbuf) {
self.clean();
let image = Image::new_from_pixbuf(buffer);
self.gobject.append(image.gobject());
}
pub fn set_status_failure(&self, title: &str, description: &str) {
self.clean();
let status_default = Status::new_error(title, description);
self.gobject.append(status_default.gobject());
}
pub fn set_text_gemini(&self, base: &Uri, data: &str) -> Option<GString> {
self.clean();
let text_gemini = Text::gemini(
data,
base,
self.action_tab_open.clone(),
self.action_page_open.clone(),
);
self.gobject.append(text_gemini.gobject());
text_gemini.meta_title().clone() }
pub fn clean(&self) {
while let Some(child) = self.gobject.last_child() {
self.gobject.remove(&child);
}
}
pub fn gobject(&self) -> &Box {
&self.gobject
}
}