rename base to home

This commit is contained in:
yggverse 2024-11-01 03:14:11 +02:00
parent 313122e5c3
commit 532ed65ed8
12 changed files with 61 additions and 67 deletions

View file

@ -0,0 +1,66 @@
mod widget;
use widget::Widget;
use gtk::{
gio::SimpleAction,
glib::{gformat, GString, Uri},
Button,
};
use std::{cell::RefCell, sync::Arc};
pub struct Home {
action_page_home: SimpleAction,
uri: RefCell<Option<Uri>>,
widget: Arc<Widget>,
}
impl Home {
// Construct
pub fn new_arc(action_page_home: SimpleAction) -> Arc<Self> {
Arc::new(Self {
action_page_home: action_page_home.clone(),
uri: RefCell::new(None),
widget: Widget::new_arc(action_page_home),
})
}
// Actions
pub fn update(&self, uri: Option<Uri>) {
// Detect sensitivity value
let status = match &uri {
Some(uri) => "/" != uri.path(),
None => false,
};
// Update parsed cache
self.uri.replace(uri);
// Update action status
self.action_page_home.set_enabled(status);
// Update child components
self.widget.update(status);
}
// Getters
pub fn gobject(&self) -> &Button {
&self.widget.gobject()
}
pub fn url(&self) -> Option<GString> {
// Build URL from parsed URI cache
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}/"));
} // @TODO auth params
}
}
None
}
}