mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
use anyhow crate, return id on insert
This commit is contained in:
parent
e859b97d79
commit
5effd63575
42 changed files with 496 additions and 1164 deletions
|
|
@ -11,6 +11,7 @@ use window::Window;
|
|||
|
||||
use crate::Profile;
|
||||
use adw::{prelude::AdwDialogExt, AboutDialog, Application};
|
||||
use anyhow::Result;
|
||||
use gtk::{
|
||||
gio::{Cancellable, File},
|
||||
prelude::GtkWindowExt,
|
||||
|
|
@ -109,70 +110,43 @@ impl Browser {
|
|||
|
||||
// Actions
|
||||
|
||||
pub fn clean(&self, transaction: &Transaction, app_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to childs
|
||||
self.window.clean(transaction, record.id)?;
|
||||
self.widget.clean(transaction, record.id)?;
|
||||
|
||||
/* @TODO
|
||||
self.header.clean(transaction, &record.id)?; */
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn clean(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_id)? {
|
||||
database::delete(transaction, record.id)?;
|
||||
// Delegate clean action to childs
|
||||
self.window.clean(transaction, record.id)?;
|
||||
self.widget.clean(transaction, record.id)?;
|
||||
/* @TODO
|
||||
self.header.clean(transaction, &record.id)?; */
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(&self, transaction: &Transaction, app_id: i64) -> Result<(), String> {
|
||||
match database::select(transaction, app_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Delegate restore action to childs
|
||||
self.widget.restore(transaction, record.id)?;
|
||||
self.window.restore(transaction, record.id)?;
|
||||
|
||||
/* @TODO
|
||||
self.header.restore(transaction, &record.id)?; */
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
pub fn restore(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
|
||||
for record in database::select(transaction, app_id)? {
|
||||
// Delegate restore action to childs
|
||||
self.widget.restore(transaction, record.id)?;
|
||||
self.window.restore(transaction, record.id)?;
|
||||
/* @TODO
|
||||
self.header.restore(transaction, &record.id)?; */
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_id: i64) -> Result<(), String> {
|
||||
match database::insert(transaction, app_id) {
|
||||
Ok(_) => {
|
||||
let id = database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
self.widget.save(transaction, id)?;
|
||||
self.window.save(transaction, id)?;
|
||||
|
||||
/* @TODO
|
||||
self.header.save(transaction, &id)?; */
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
pub fn save(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
|
||||
let id = database::insert(transaction, app_id)?;
|
||||
// Delegate save action to childs
|
||||
self.widget.save(transaction, id)?;
|
||||
self.window.save(transaction, id)?;
|
||||
/* @TODO
|
||||
self.header.save(transaction, &id)?; */
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init(&self, application: Option<&Application>) -> &Self {
|
||||
// Assign browser window to this application
|
||||
self.widget.application_window.set_application(application); // @TODO
|
||||
|
||||
// Init main window
|
||||
// Init main window
|
||||
self.window.init();
|
||||
self
|
||||
}
|
||||
|
|
@ -184,11 +158,9 @@ impl Browser {
|
|||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
pub fn migrate(tx: &Transaction) -> Result<()> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
database::init(tx)?;
|
||||
|
||||
// Delegate migration to childs
|
||||
/* @TODO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue