2024-10-06 18:20:36 +03:00
|
|
|
mod database;
|
2024-10-09 10:50:41 +03:00
|
|
|
mod header;
|
2024-09-20 18:02:10 +03:00
|
|
|
mod tab;
|
2024-10-06 05:03:45 +03:00
|
|
|
mod widget;
|
2024-09-26 01:11:07 +03:00
|
|
|
|
2024-10-06 18:20:36 +03:00
|
|
|
use database::Database;
|
2024-10-09 10:50:41 +03:00
|
|
|
use header::Header;
|
2024-10-07 19:54:28 +03:00
|
|
|
use sqlite::Transaction;
|
2024-09-23 18:51:48 +03:00
|
|
|
use tab::Tab;
|
2024-10-06 05:03:45 +03:00
|
|
|
use widget::Widget;
|
2024-09-23 01:57:16 +03:00
|
|
|
|
2024-11-08 05:21:08 +02:00
|
|
|
use std::rc::Rc;
|
2024-10-06 05:03:45 +03:00
|
|
|
|
2024-10-11 04:37:06 +03:00
|
|
|
use gtk::{gio::SimpleAction, Box};
|
2024-09-23 15:56:09 +03:00
|
|
|
|
2024-10-05 17:10:31 +03:00
|
|
|
pub struct Window {
|
2024-11-08 05:21:08 +02:00
|
|
|
//header: Rc<Header>,
|
|
|
|
tab: Rc<Tab>,
|
|
|
|
widget: Rc<Widget>,
|
2024-09-22 02:00:54 +03:00
|
|
|
}
|
|
|
|
|
2024-10-05 17:10:31 +03:00
|
|
|
impl Window {
|
2024-09-22 18:50:47 +03:00
|
|
|
// Construct
|
2024-09-28 03:10:07 +03:00
|
|
|
pub fn new(
|
2024-10-06 18:20:36 +03:00
|
|
|
// Actions
|
2024-11-03 19:57:44 +02:00
|
|
|
action_about: SimpleAction,
|
2024-11-01 03:09:09 +02:00
|
|
|
action_debug: SimpleAction,
|
|
|
|
action_profile: SimpleAction,
|
2024-10-27 12:50:36 +02:00
|
|
|
action_quit: SimpleAction,
|
|
|
|
action_update: SimpleAction,
|
2024-11-01 03:09:09 +02:00
|
|
|
action_page_new: SimpleAction,
|
|
|
|
action_page_close: SimpleAction,
|
|
|
|
action_page_close_all: SimpleAction,
|
2024-11-01 03:14:11 +02:00
|
|
|
action_page_home: SimpleAction,
|
2024-11-01 03:09:09 +02:00
|
|
|
action_page_history_back: SimpleAction,
|
|
|
|
action_page_history_forward: SimpleAction,
|
|
|
|
action_page_reload: SimpleAction,
|
|
|
|
action_page_pin: SimpleAction,
|
2024-09-28 03:10:07 +03:00
|
|
|
) -> Self {
|
2024-09-22 18:50:47 +03:00
|
|
|
// Init components
|
2024-11-08 05:21:08 +02:00
|
|
|
let tab = Tab::new_rc(
|
2024-11-04 22:15:47 +02:00
|
|
|
action_page_close.clone(),
|
|
|
|
action_page_close_all.clone(),
|
2024-11-01 03:14:11 +02:00
|
|
|
action_page_home.clone(),
|
2024-11-01 03:09:09 +02:00
|
|
|
action_page_history_back.clone(),
|
|
|
|
action_page_history_forward.clone(),
|
2024-11-04 23:04:57 +02:00
|
|
|
action_page_pin.clone(),
|
2024-11-01 03:09:09 +02:00
|
|
|
action_page_reload.clone(),
|
2024-10-11 02:47:53 +03:00
|
|
|
action_update.clone(),
|
|
|
|
);
|
|
|
|
|
2024-11-08 05:21:08 +02:00
|
|
|
let header = Header::new_rc(
|
2024-10-10 23:34:06 +03:00
|
|
|
// Actions
|
2024-11-03 19:57:44 +02:00
|
|
|
action_about,
|
|
|
|
action_debug,
|
|
|
|
action_profile,
|
|
|
|
action_quit,
|
|
|
|
action_page_new,
|
|
|
|
action_page_close,
|
|
|
|
action_page_close_all,
|
|
|
|
action_page_home,
|
|
|
|
action_page_history_back,
|
|
|
|
action_page_history_forward,
|
|
|
|
action_page_reload,
|
|
|
|
action_page_pin,
|
2024-10-10 23:34:06 +03:00
|
|
|
// Widgets
|
2024-10-11 02:47:53 +03:00
|
|
|
tab.gobject(),
|
2024-10-10 23:34:06 +03:00
|
|
|
);
|
2024-09-22 18:50:47 +03:00
|
|
|
|
2024-09-28 02:27:34 +03:00
|
|
|
// GTK
|
2024-11-08 05:21:08 +02:00
|
|
|
let widget = Rc::new(Widget::new(header.gobject(), tab.gobject()));
|
2024-09-23 15:56:09 +03:00
|
|
|
|
2024-09-22 18:50:47 +03:00
|
|
|
// Init struct
|
2024-10-09 10:50:41 +03:00
|
|
|
Self {
|
2024-10-10 23:34:06 +03:00
|
|
|
//header,
|
2024-10-09 10:50:41 +03:00
|
|
|
tab,
|
|
|
|
widget,
|
|
|
|
}
|
2024-09-22 18:50:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
2024-11-04 20:22:27 +02:00
|
|
|
pub fn tab_append(&self, page_position: Option<i32>) {
|
|
|
|
self.tab.append(page_position);
|
2024-09-22 02:00:54 +03:00
|
|
|
}
|
|
|
|
|
2024-11-05 03:19:52 +02:00
|
|
|
pub fn tab_page_home(&self, page_position: Option<i32>) {
|
|
|
|
self.tab.page_home(page_position);
|
2024-09-30 16:34:58 +03:00
|
|
|
}
|
|
|
|
|
2024-11-05 03:19:52 +02:00
|
|
|
pub fn tab_page_history_back(&self, page_position: Option<i32>) {
|
|
|
|
self.tab.page_history_back(page_position);
|
2024-09-30 23:23:29 +03:00
|
|
|
}
|
|
|
|
|
2024-11-05 03:19:52 +02:00
|
|
|
pub fn tab_page_history_forward(&self, page_position: Option<i32>) {
|
|
|
|
self.tab.page_history_forward(page_position);
|
2024-09-30 23:23:29 +03:00
|
|
|
}
|
|
|
|
|
2024-11-04 20:22:27 +02:00
|
|
|
/// Reload page at given position or selected page on `None` given
|
2024-11-05 03:19:52 +02:00
|
|
|
pub fn tab_page_reload(&self, position: Option<i32>) {
|
|
|
|
self.tab.page_reload(position);
|
2024-09-25 01:14:45 +03:00
|
|
|
}
|
|
|
|
|
2024-11-04 20:22:27 +02:00
|
|
|
/// Close page at given position or selected page on `None` given
|
|
|
|
pub fn tab_close(&self, page_position: Option<i32>) {
|
|
|
|
self.tab.close(page_position);
|
2024-09-23 16:03:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tab_close_all(&self) {
|
2024-09-24 00:56:46 +03:00
|
|
|
self.tab.close_all();
|
2024-09-23 16:03:39 +03:00
|
|
|
}
|
|
|
|
|
2024-11-04 23:04:57 +02:00
|
|
|
pub fn tab_pin(&self, page_position: Option<i32>) {
|
|
|
|
self.tab.pin(page_position);
|
2024-09-23 15:44:33 +03:00
|
|
|
}
|
|
|
|
|
2024-10-15 08:45:44 +03:00
|
|
|
pub fn update(&self, id: &str) {
|
|
|
|
self.tab.update(id);
|
2024-09-24 23:08:40 +03:00
|
|
|
}
|
|
|
|
|
2024-10-07 21:10:12 +03:00
|
|
|
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
|
|
|
|
match Database::records(transaction, app_browser_id) {
|
2024-10-06 18:20:36 +03:00
|
|
|
Ok(records) => {
|
|
|
|
for record in records {
|
2024-10-07 21:10:12 +03:00
|
|
|
match Database::delete(transaction, &record.id) {
|
2024-10-06 18:20:36 +03:00
|
|
|
Ok(_) => {
|
|
|
|
// Delegate clean action to childs
|
2024-10-08 03:41:51 +03:00
|
|
|
self.tab.clean(transaction, &record.id)?;
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
Err(e) => return Err(e.to_string()),
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
Err(e) => return Err(e.to_string()),
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
|
|
|
|
Ok(())
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
|
|
|
|
2024-10-07 21:10:12 +03:00
|
|
|
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
|
|
|
|
match Database::records(transaction, app_browser_id) {
|
2024-10-06 18:20:36 +03:00
|
|
|
Ok(records) => {
|
|
|
|
for record in records {
|
|
|
|
// Delegate restore action to childs
|
2024-10-08 03:41:51 +03:00
|
|
|
self.tab.restore(transaction, &record.id)?;
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
Err(e) => return Err(e.to_string()),
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
|
|
|
|
Ok(())
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
|
|
|
|
2024-10-07 21:10:12 +03:00
|
|
|
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
|
|
|
|
match Database::add(transaction, app_browser_id) {
|
2024-10-06 18:20:36 +03:00
|
|
|
Ok(_) => {
|
|
|
|
// Delegate save action to childs
|
2024-10-07 21:10:12 +03:00
|
|
|
if let Err(e) = self
|
|
|
|
.tab
|
|
|
|
.save(transaction, &Database::last_insert_id(transaction))
|
|
|
|
{
|
|
|
|
return Err(e.to_string());
|
|
|
|
}
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
Err(e) => return Err(e.to_string()),
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
2024-10-07 21:10:12 +03:00
|
|
|
|
|
|
|
Ok(())
|
2024-10-06 18:20:36 +03:00
|
|
|
}
|
|
|
|
|
2024-10-12 01:08:16 +03:00
|
|
|
pub fn init(&self) {
|
|
|
|
self.tab.init();
|
|
|
|
}
|
|
|
|
|
2024-09-22 18:50:47 +03:00
|
|
|
// Getters
|
2024-10-06 05:16:29 +03:00
|
|
|
pub fn gobject(&self) -> &Box {
|
2024-11-08 05:09:19 +02:00
|
|
|
self.widget.gobject()
|
2024-09-22 18:50:47 +03:00
|
|
|
}
|
2024-11-03 17:05:32 +02:00
|
|
|
}
|
2024-10-07 19:54:28 +03:00
|
|
|
|
2024-11-03 17:05:32 +02:00
|
|
|
// Tools
|
|
|
|
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
|
|
|
// Migrate self components
|
2024-11-08 05:03:02 +02:00
|
|
|
if let Err(e) = Database::init(tx) {
|
2024-11-03 17:05:32 +02:00
|
|
|
return Err(e.to_string());
|
|
|
|
}
|
2024-10-07 19:54:28 +03:00
|
|
|
|
2024-11-03 17:05:32 +02:00
|
|
|
// Delegate migration to childs
|
2024-11-08 05:03:02 +02:00
|
|
|
tab::migrate(tx)?;
|
2024-10-07 19:54:28 +03:00
|
|
|
|
2024-11-03 17:05:32 +02:00
|
|
|
// Success
|
|
|
|
Ok(())
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|