diff --git a/src/app.rs b/src/app.rs index ff80175d..af92d593 100644 --- a/src/app.rs +++ b/src/app.rs @@ -120,7 +120,11 @@ impl App { match Database::records(&transaction) { Ok(records) => { for record in records { - browser.restore(&transaction, &record.id); + if let Err(e) = + browser.restore(&transaction, &record.id) + { + todo!("{e}") + } } } Err(e) => todo!("{e}"), @@ -158,7 +162,11 @@ impl App { match Database::delete(&transaction, &record.id) { Ok(_) => { // Delegate clean action to childs - browser.clean(&transaction, &record.id); + if let Err(e) = + browser.clean(&transaction, &record.id) + { + todo!("{e}") + } } Err(e) => todo!("{e}"), } @@ -168,10 +176,12 @@ impl App { match Database::add(&transaction) { Ok(_) => { // Delegate save action to childs - browser.save( + if let Err(e) = browser.save( &transaction, &Database::last_insert_id(&transaction), - ); + ) { + todo!("{e}") + } } Err(e) => todo!("{e}"), } diff --git a/src/app/browser.rs b/src/app/browser.rs index 370f9841..1b5ef76f 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -191,54 +191,84 @@ impl Browser { } // Actions - pub fn clean(&self, tx: &Transaction, app_id: &i64) { - match Database::records(tx, app_id) { + pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { + match Database::records(transaction, app_id) { Ok(records) => { for record in records { - match Database::delete(tx, &record.id) { + match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs - // @TODO - // self.header.clean(record.id); - self.window.clean(tx, &record.id); - self.widget.clean(tx, &record.id); + if let Err(e) = self.window.clean(transaction, &record.id) { + return Err(e.to_string()); + } + + if let Err(e) = self.widget.clean(transaction, &record.id) { + return Err(e.to_string()); + } + + /* @TODO + if let Err(e) = self.header.clean(transaction, &record.id) { + return Err(e.to_string()); + } */ } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn restore(&self, tx: &Transaction, app_id: &i64) { - match Database::records(tx, app_id) { + pub fn restore(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { + match Database::records(transaction, app_id) { Ok(records) => { for record in records { // Delegate restore action to childs - // @TODO - // self.header.restore(record.id); - self.window.restore(tx, &record.id); - self.widget.restore(tx, &record.id); + if let Err(e) = self.widget.restore(transaction, &record.id) { + return Err(e.to_string()); + } + + if let Err(e) = self.window.restore(transaction, &record.id) { + return Err(e.to_string()); + } + + /* @TODO + if let Err(e) = self.header.restore(transaction, &record.id) { + return Err(e.to_string()); + } */ } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn save(&self, tx: &Transaction, app_id: &i64) { - match Database::add(tx, app_id) { + pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { + match Database::add(transaction, app_id) { Ok(_) => { - // Delegate save action to childs - let id = Database::last_insert_id(tx); + let id = Database::last_insert_id(transaction); - // @TODO - // self.header.save(id); - self.window.save(tx, &id); - self.widget.save(tx, &id); + // Delegate save action to childs + if let Err(e) = self.widget.save(transaction, &id) { + return Err(e.to_string()); + } + + if let Err(e) = self.window.save(transaction, &id) { + return Err(e.to_string()); + } + + /* @TODO + if let Err(e) = self.header.save(transaction, &id) { + return Err(e.to_string()); + } */ } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } // Getters diff --git a/src/app/browser/widget.rs b/src/app/browser/widget.rs index fa22ae0b..21b8cd66 100644 --- a/src/app/browser/widget.rs +++ b/src/app/browser/widget.rs @@ -31,25 +31,27 @@ impl Widget { } // Actions - pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) { - match Database::records(tx, app_browser_id) { + pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { + match Database::records(transaction, app_browser_id) { Ok(records) => { for record in records { - match Database::delete(tx, &record.id) { + match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs // nothing yet.. } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) { - match Database::records(tx, app_browser_id) { + pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { + match Database::records(transaction, app_browser_id) { Ok(records) => { for record in records { // Restore widget @@ -61,13 +63,15 @@ impl Widget { // nothing yet.. } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn save(&self, tx: &Transaction, app_browser_id: &i64) { + pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { match Database::add( - tx, + transaction, app_browser_id, &self.gobject.default_width(), &self.gobject.default_height(), @@ -75,11 +79,13 @@ impl Widget { ) { Ok(_) => { // Delegate save action to childs - // let id = self.database.last_insert_id(tx); + // let id = self.database.last_insert_id(transaction); // nothing yet.. } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } // Getters diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 2d0bad36..85970c67 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -80,43 +80,58 @@ impl Window { self.tab.update(); } - pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) { - match Database::records(tx, app_browser_id) { + pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { + match Database::records(transaction, app_browser_id) { Ok(records) => { for record in records { - match Database::delete(tx, &record.id) { + match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs - self.tab.clean(tx, &record.id); + if let Err(e) = self.tab.clean(transaction, &record.id) { + return Err(e.to_string()); + } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) { - match Database::records(tx, app_browser_id) { + pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { + match Database::records(transaction, app_browser_id) { Ok(records) => { for record in records { // Delegate restore action to childs - self.tab.restore(tx, &record.id); + if let Err(e) = self.tab.restore(transaction, &record.id) { + return Err(e.to_string()); + } } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn save(&self, tx: &Transaction, app_browser_id: &i64) { - match Database::add(tx, app_browser_id) { + pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { + match Database::add(transaction, app_browser_id) { Ok(_) => { // Delegate save action to childs - self.tab.save(tx, &Database::last_insert_id(tx)); + if let Err(e) = self + .tab + .save(transaction, &Database::last_insert_id(transaction)) + { + return Err(e.to_string()); + } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } // Getters diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index f799b084..a71c8a09 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -213,46 +213,66 @@ impl Tab { } } - pub fn clean(&self, tx: &Transaction, app_browser_window_id: &i64) { - match Database::records(tx, app_browser_window_id) { + pub fn clean( + &self, + transaction: &Transaction, + app_browser_window_id: &i64, + ) -> Result<(), String> { + match Database::records(transaction, app_browser_window_id) { Ok(records) => { for record in records { - match Database::delete(tx, &record.id) { + match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs for (_, item) in self.index.borrow().iter() { - item.label.clean(tx, &record.id); - // @TODO item.page.clean(tx, &record.id); + if let Err(e) = item.label.clean(transaction, &record.id) { + return Err(e.to_string()); + } + // @TODO item.page.clean(transaction, &record.id); } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn restore(&self, tx: &Transaction, app_browser_window_id: &i64) { - match Database::records(tx, app_browser_window_id) { + pub fn restore( + &self, + transaction: &Transaction, + app_browser_window_id: &i64, + ) -> Result<(), String> { + match Database::records(transaction, app_browser_window_id) { Ok(records) => { for record in records { let item = self.append(None, record.is_current); // Delegate restore action to childs - item.label.restore(tx, &record.id); - // item.page.restore(tx, record.id); + if let Err(e) = item.label.restore(transaction, &record.id) { + return Err(e.to_string()); + } + // item.page.restore(transaction, record.id); } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn save(&self, tx: &Transaction, app_browser_window_id: &i64) { + pub fn save( + &self, + transaction: &Transaction, + app_browser_window_id: &i64, + ) -> Result<(), String> { let mut page_number = 0; for (_, item) in self.index.borrow().iter() { match Database::add( - tx, + transaction, app_browser_window_id, &match self.widget.gobject().current_page() { Some(number) => number == page_number, @@ -261,18 +281,22 @@ impl Tab { ) { Ok(_) => { // Delegate save action to childs - let id = Database::last_insert_id(tx); + let id = Database::last_insert_id(transaction); - item.label.save(tx, &id); + if let Err(e) = item.label.save(transaction, &id) { + return Err(e.to_string()); + } // @TODO // item.page.save() } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } page_number += 1; } + + Ok(()) } // Getters diff --git a/src/app/browser/window/tab/label.rs b/src/app/browser/window/tab/label.rs index 737fb7a2..faaccdee 100644 --- a/src/app/browser/window/tab/label.rs +++ b/src/app/browser/window/tab/label.rs @@ -35,25 +35,35 @@ impl Label { } // Actions - pub fn clean(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { - match Database::records(tx, app_browser_window_tab_id) { + pub fn clean( + &self, + transaction: &Transaction, + app_browser_window_tab_id: &i64, + ) -> Result<(), String> { + match Database::records(transaction, app_browser_window_tab_id) { Ok(records) => { for record in records { - match Database::delete(tx, &record.id) { + match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs // nothing yet.. } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn restore(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { - match Database::records(tx, app_browser_window_tab_id) { + pub fn restore( + &self, + transaction: &Transaction, + app_browser_window_tab_id: &i64, + ) -> Result<(), String> { + match Database::records(transaction, app_browser_window_tab_id) { Ok(records) => { for record in records { self.pin(record.is_pinned); @@ -62,18 +72,26 @@ impl Label { // nothing yet.. } } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } - pub fn save(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { - match Database::add(tx, app_browser_window_tab_id, &self.is_pinned()) { + pub fn save( + &self, + transaction: &Transaction, + app_browser_window_tab_id: &i64, + ) -> Result<(), String> { + match Database::add(transaction, app_browser_window_tab_id, &self.is_pinned()) { Ok(_) => { // Delegate save action to childs // nothing yet.. } - Err(e) => todo!("{e}"), + Err(e) => return Err(e.to_string()), } + + Ok(()) } pub fn update(&self, title: Option<&GString>) {