mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
implement request session restore
This commit is contained in:
parent
d7b781f604
commit
6a4790c92b
4 changed files with 179 additions and 9 deletions
|
|
@ -1,10 +1,14 @@
|
|||
mod database;
|
||||
|
||||
use database::Database;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{timeout_add_local, ControlFlow, GString, SourceId, Uri, UriFlags},
|
||||
prelude::{ActionExt, EditableExt, EntryExt},
|
||||
Entry,
|
||||
};
|
||||
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::RefCell, sync::Arc, time::Duration};
|
||||
|
||||
// Progressbar animation setup
|
||||
|
|
@ -97,6 +101,78 @@ impl Request {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match Database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match Database::delete(transaction, &record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match Database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
if let Some(text) = record.text {
|
||||
self.widget.set_text(&text);
|
||||
}
|
||||
|
||||
// Delegate restore action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
let text = self.widget.text();
|
||||
|
||||
match Database::add(
|
||||
transaction,
|
||||
app_browser_window_tab_item_page_navigation_id,
|
||||
match text.is_empty() {
|
||||
true => None,
|
||||
false => Some(text.as_str()),
|
||||
},
|
||||
) {
|
||||
Ok(_) => {
|
||||
// let id = Database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Setters
|
||||
pub fn set_text(&self, value: &GString) {
|
||||
self.widget.set_text(value);
|
||||
|
|
@ -121,4 +197,18 @@ impl Request {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
// Migrate self components
|
||||
if let Err(e) = Database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
|
||||
// Delegate migration to childs
|
||||
// nothing yet..
|
||||
|
||||
// Success
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue