draft ggemini 0.11.0 version api

This commit is contained in:
yggverse 2024-11-27 04:20:56 +02:00
parent 5152d915d1
commit 88a37c545b
4 changed files with 404 additions and 609 deletions

View File

@ -17,7 +17,7 @@ features = ["v1_6"]
[dependencies.gemini] [dependencies.gemini]
package = "ggemini" package = "ggemini"
version = "0.10.0" version = "0.11.0"
[dependencies.gemtext] [dependencies.gemtext]
package = "ggemtext" package = "ggemtext"

View File

@ -135,10 +135,10 @@ impl Tab {
// Register dynamically created tab components in the HashMap index // Register dynamically created tab components in the HashMap index
self.index self.index
.borrow_mut() .borrow_mut()
.insert(item.id().clone(), item.clone()); .insert(item.id.clone(), item.clone());
item.page() item.page
.navigation() .navigation
.request() .request()
.widget() .widget()
.gobject() .gobject()
@ -163,7 +163,7 @@ impl Tab {
if let Some(page) = self.widget.page(page_position) { if let Some(page) = self.widget.page(page_position) {
if let Some(id) = page.keyword() { if let Some(id) = page.keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
return match item.page().bookmark() { return match item.page.bookmark() {
Ok(result) => Ok(result), Ok(result) => Ok(result),
Err(_) => Err(Error::Bookmark), Err(_) => Err(Error::Bookmark),
}; };
@ -182,7 +182,7 @@ impl Tab {
if let Some(page) = self.widget.page(page_position) { if let Some(page) = self.widget.page(page_position) {
if let Some(id) = page.keyword() { if let Some(id) = page.keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page().home(); item.page.home();
} }
} }
} }
@ -192,7 +192,7 @@ impl Tab {
if let Some(page) = self.widget.page(page_position) { if let Some(page) = self.widget.page(page_position) {
if let Some(id) = page.keyword() { if let Some(id) = page.keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page().history_back(); item.page.history_back();
} }
} }
} }
@ -202,7 +202,7 @@ impl Tab {
if let Some(page) = self.widget.page(page_position) { if let Some(page) = self.widget.page(page_position) {
if let Some(id) = page.keyword() { if let Some(id) = page.keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page().history_forward(); item.page.history_forward();
} }
} }
} }
@ -213,7 +213,7 @@ impl Tab {
if let Some(page) = self.widget.page(page_position) { if let Some(page) = self.widget.page(page_position) {
if let Some(id) = page.keyword() { if let Some(id) = page.keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page().reload(); item.page.reload();
} }
} }
} }
@ -231,10 +231,10 @@ impl Tab {
item.update(); item.update();
// Update tab title on loading indicator inactive // Update tab title on loading indicator inactive
if !item.page().is_loading() { if !item.page.is_loading() {
item.widget() item.widget
.gobject() .gobject()
.set_title(item.page().meta().title().as_str()) .set_title(item.page.meta.title().as_str())
} }
} }
// Update all tabs on ID not found @TODO change initial update method // Update all tabs on ID not found @TODO change initial update method
@ -244,10 +244,10 @@ impl Tab {
item.update(); item.update();
// Update tab title on loading indicator inactive // Update tab title on loading indicator inactive
if !item.page().is_loading() { if !item.page.is_loading() {
item.widget() item.widget
.gobject() .gobject()
.set_title(item.page().meta().title().as_str()) .set_title(item.page.meta.title().as_str())
} }
} }
} }
@ -299,7 +299,7 @@ impl Tab {
// Register dynamically created tab item in the HashMap index // Register dynamically created tab item in the HashMap index
self.index self.index
.borrow_mut() .borrow_mut()
.insert(item.id().clone(), item.clone()); .insert(item.id.clone(), item.clone());
} }
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
@ -327,10 +327,10 @@ impl Tab {
item.save( item.save(
transaction, transaction,
&id, &id,
&self.widget.gobject().page_position(item.widget().gobject()), &self.widget.gobject().page_position(item.widget.gobject()),
&item.widget().gobject().is_pinned(), &item.widget.gobject().is_pinned(),
&item.widget().gobject().is_selected(), &item.widget.gobject().is_selected(),
&item.widget().gobject().needs_attention(), &item.widget.gobject().needs_attention(),
)?; )?;
} }
} }

View File

@ -24,10 +24,10 @@ use std::rc::Rc;
pub struct Item { pub struct Item {
// Auto-generated unique item ID // Auto-generated unique item ID
// useful as widget name in GTK actions callback // useful as widget name in GTK actions callback
id: GString, pub id: GString,
// Components // Components
page: Rc<Page>, pub page: Rc<Page>,
widget: Rc<Widget>, pub widget: Rc<Widget>,
} }
impl Item { impl Item {
@ -57,7 +57,7 @@ impl Item {
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
id.as_str(), id.as_str(),
tab_view, tab_view,
page.widget().gobject(), page.widget.gobject(),
None, None,
position, position,
(is_pinned, is_selected, is_attention), (is_pinned, is_selected, is_attention),
@ -66,11 +66,7 @@ impl Item {
// Init events // Init events
if let Some(text) = request { if let Some(text) = request {
page.navigation() page.navigation.request().widget().gobject().set_text(&text);
.request()
.widget()
.gobject()
.set_text(&text);
if is_load { if is_load {
page.load(true); page.load(true);
@ -83,7 +79,7 @@ impl Item {
let parent = tab_view.clone().upcast::<gtk::Widget>(); let parent = tab_view.clone().upcast::<gtk::Widget>();
move || { move || {
// Request should match valid URI for all drivers supported // Request should match valid URI for all drivers supported
if let Some(uri) = page.navigation().request().uri() { if let Some(uri) = page.navigation.request().uri() {
// Rout by scheme // Rout by scheme
if uri.scheme().to_lowercase() == "gemini" { if uri.scheme().to_lowercase() == "gemini" {
return identity::new_gemini(profile.clone(), actions.1.clone(), uri) return identity::new_gemini(profile.clone(), actions.1.clone(), uri)
@ -100,11 +96,7 @@ impl Item {
let page = page.clone(); let page = page.clone();
move |request, is_history| { move |request, is_history| {
if let Some(text) = request { if let Some(text) = request {
page.navigation() page.navigation.request().widget().gobject().set_text(&text);
.request()
.widget()
.gobject()
.set_text(&text);
} }
page.load(is_history); page.load(is_history);
} }
@ -120,7 +112,7 @@ impl Item {
self.page.update(); self.page.update();
// Update tab loading indicator // Update tab loading indicator
self.widget.gobject().set_loading(self.page().is_loading()); self.widget.gobject().set_loading(self.page.is_loading());
} }
pub fn clean( pub fn clean(
@ -222,20 +214,6 @@ impl Item {
Ok(()) Ok(())
} }
// Getters
pub fn id(&self) -> &GString {
&self.id
}
pub fn page(&self) -> &Rc<Page> {
&self.page
}
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
} }
// Tools // Tools

File diff suppressed because it is too large Load Diff