mod widget;
use widget::Widget;
use gtk::{
gio::SimpleAction,
glib::{gformat, GString, Uri},
Button,
};
use std::{cell::RefCell, sync::Arc};
pub struct Base {
action_tab_page_navigation_base: SimpleAction,
uri: RefCell<Option<Uri>>,
widget: Arc<Widget>,
}
impl Base {
pub fn new_arc(action_tab_page_navigation_base: SimpleAction) -> Arc<Self> {
Arc::new(Self {
action_tab_page_navigation_base: action_tab_page_navigation_base.clone(),
uri: RefCell::new(None),
widget: Widget::new_arc(action_tab_page_navigation_base),
})
}
pub fn update(&self, uri: Option<Uri>) {
let status = match &uri {
Some(uri) => "/" != uri.path(),
None => false,
};
self.uri.replace(uri);
self.action_tab_page_navigation_base.set_enabled(status);
self.widget.update(status);
}
pub fn gobject(&self) -> &Button {
&self.widget.gobject()
}
pub fn url(&self) -> Option<GString> {
if let Some(uri) = self.uri.take() {
let scheme = uri.scheme();
let port = uri.port();
if let Some(host) = uri.host() {
if port.is_positive() {
return Some(gformat!("{scheme}://{host}:{port}/"));
} else {
return Some(gformat!("{scheme}://{host}/"));
} }
}
None
}
}