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-10-07 19:54:28 +03:00
|
|
|
use std::sync::Arc;
|
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-10-10 23:34:06 +03:00
|
|
|
//header: Arc<Header>,
|
2024-09-26 01:11:07 +03:00
|
|
|
tab: Arc<Tab>,
|
2024-10-06 05:03:45 +03:00
|
|
|
widget: Arc<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-10-09 10:50:41 +03:00
|
|
|
action_tool_debug: Arc<SimpleAction>,
|
2024-10-11 08:04:29 +03:00
|
|
|
action_tool_profile: Arc<SimpleAction>,
|
2024-10-09 10:50:41 +03:00
|
|
|
action_quit: Arc<SimpleAction>,
|
|
|
|
action_update: Arc<SimpleAction>,
|
|
|
|
action_tab_append: Arc<SimpleAction>,
|
|
|
|
action_tab_close: Arc<SimpleAction>,
|
|
|
|
action_tab_close_all: Arc<SimpleAction>,
|
2024-09-30 16:34:58 +03:00
|
|
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
2024-09-30 17:45:44 +03:00
|
|
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
|
|
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
2024-09-30 14:49:37 +03:00
|
|
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
2024-10-09 10:50:41 +03:00
|
|
|
action_tab_pin: Arc<SimpleAction>,
|
2024-09-28 03:10:07 +03:00
|
|
|
) -> Self {
|
2024-09-22 18:50:47 +03:00
|
|
|
// Init components
|
2024-10-11 02:47:53 +03:00
|
|
|
let tab = Tab::new_arc(
|
|
|
|
action_tab_page_navigation_base.clone(),
|
|
|
|
action_tab_page_navigation_history_back.clone(),
|
|
|
|
action_tab_page_navigation_history_forward.clone(),
|
|
|
|
action_tab_page_navigation_reload.clone(),
|
|
|
|
action_update.clone(),
|
|
|
|
);
|
|
|
|
|
2024-10-10 23:34:06 +03:00
|
|
|
let header = Header::new_arc(
|
|
|
|
// Actions
|
2024-10-09 10:50:41 +03:00
|
|
|
action_tool_debug.clone(),
|
2024-10-11 08:04:29 +03:00
|
|
|
action_tool_profile.clone(),
|
2024-10-09 10:50:41 +03:00
|
|
|
action_quit.clone(),
|
|
|
|
action_tab_append.clone(),
|
|
|
|
action_tab_close.clone(),
|
|
|
|
action_tab_close_all.clone(),
|
|
|
|
action_tab_page_navigation_base.clone(),
|
|
|
|
action_tab_page_navigation_history_back.clone(),
|
|
|
|
action_tab_page_navigation_history_forward.clone(),
|
|
|
|
action_tab_page_navigation_reload.clone(),
|
|
|
|
action_tab_pin.clone(),
|
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-10-09 10:50:41 +03:00
|
|
|
let widget = Arc::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-10-11 02:40:08 +03:00
|
|
|
pub fn tab_append(&self) {
|
|
|
|
self.tab.append();
|
2024-09-22 02:00:54 +03:00
|
|
|
}
|
|
|
|
|
2024-09-30 16:34:58 +03:00
|
|
|
pub fn tab_page_navigation_base(&self) {
|
|
|
|
self.tab.page_navigation_base();
|
|
|
|
}
|
|
|
|
|
2024-09-30 23:23:29 +03:00
|
|
|
pub fn tab_page_navigation_history_back(&self) {
|
|
|
|
self.tab.page_navigation_history_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tab_page_navigation_history_forward(&self) {
|
|
|
|
self.tab.page_navigation_history_forward();
|
|
|
|
}
|
|
|
|
|
2024-09-30 16:34:58 +03:00
|
|
|
pub fn tab_page_navigation_reload(&self) {
|
|
|
|
self.tab.page_navigation_reload();
|
2024-09-25 01:14:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-23 16:03:39 +03:00
|
|
|
pub fn tab_close(&self) {
|
|
|
|
self.tab.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-23 15:44:33 +03:00
|
|
|
pub fn tab_pin(&self) {
|
|
|
|
self.tab.pin();
|
|
|
|
}
|
|
|
|
|
2024-09-24 23:08:40 +03:00
|
|
|
pub fn update(&self) {
|
|
|
|
self.tab.update();
|
|
|
|
}
|
|
|
|
|
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-09-22 18:50:47 +03:00
|
|
|
// Getters
|
2024-10-06 05:16:29 +03:00
|
|
|
pub fn gobject(&self) -> &Box {
|
2024-10-06 05:03:45 +03:00
|
|
|
&self.widget.gobject()
|
2024-09-22 18:50:47 +03:00
|
|
|
}
|
2024-10-07 19:54:28 +03:00
|
|
|
|
|
|
|
// 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
|
2024-10-08 03:41:51 +03:00
|
|
|
Tab::migrate(&tx)?;
|
2024-10-07 19:54:28 +03:00
|
|
|
|
|
|
|
// Success
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|