2024-11-10 08:51:08 +02:00
|
|
|
mod action;
|
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-11-10 08:51:08 +02:00
|
|
|
use action::Action;
|
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 09:19:16 +02:00
|
|
|
use crate::app::browser::action::Action as BrowserAction;
|
2024-11-10 11:53:43 +02:00
|
|
|
use gtk::{glib::GString, Box};
|
2024-11-08 06:47:58 +02:00
|
|
|
use std::rc::Rc;
|
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>,
|
2024-11-10 08:51:08 +02:00
|
|
|
action: Rc<Action>,
|
2024-11-08 05:21:08 +02:00
|
|
|
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-08 06:47:58 +02:00
|
|
|
browser_action: Rc<BrowserAction>,
|
2024-09-28 03:10:07 +03:00
|
|
|
) -> Self {
|
2024-11-10 08:51:08 +02:00
|
|
|
// Init local actions
|
|
|
|
let action = Rc::new(Action::new());
|
|
|
|
|
2024-09-22 18:50:47 +03:00
|
|
|
// Init components
|
2024-11-10 11:53:43 +02:00
|
|
|
let tab = Tab::new_rc(browser_action.clone(), action.clone());
|
|
|
|
let header = Header::new_rc(browser_action, action.clone(), tab.gobject());
|
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-11-10 08:51:08 +02:00
|
|
|
// Init events
|
|
|
|
action.append().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move || {
|
|
|
|
tab.append(None);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-11-10 10:07:16 +02:00
|
|
|
action.pin().connect_activate({
|
|
|
|
let tab = tab.clone();
|
2024-11-10 10:30:10 +02:00
|
|
|
move |position| tab.pin(position)
|
|
|
|
});
|
|
|
|
|
|
|
|
action.reload().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| tab.page_reload(position)
|
2024-11-10 10:07:16 +02:00
|
|
|
});
|
|
|
|
|
2024-11-10 10:46:46 +02:00
|
|
|
action.home().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| tab.page_home(position)
|
|
|
|
});
|
|
|
|
|
2024-11-10 11:53:43 +02:00
|
|
|
action.close().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| {
|
|
|
|
tab.close(position);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action.close_all().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |_| {
|
|
|
|
tab.close_all();
|
|
|
|
} // @TODO position not in use
|
|
|
|
});
|
|
|
|
|
|
|
|
action.history_back().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| {
|
|
|
|
tab.page_history_back(position);
|
|
|
|
} // @TODO rename destination method
|
|
|
|
});
|
|
|
|
|
|
|
|
action.history_forward().connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| {
|
|
|
|
tab.page_history_forward(position);
|
|
|
|
} // @TODO rename destination method
|
|
|
|
});
|
|
|
|
|
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,
|
2024-11-10 08:51:08 +02:00
|
|
|
action,
|
2024-10-09 10:50:41 +03:00
|
|
|
widget,
|
|
|
|
}
|
2024-09-22 18:50:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
2024-11-10 07:09:55 +02:00
|
|
|
pub fn update(&self, tab_item_id: Option<GString>) {
|
|
|
|
self.tab.update(tab_item_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-11-10 08:07:44 +02:00
|
|
|
|
2024-11-10 08:51:08 +02:00
|
|
|
pub fn action(&self) -> &Rc<Action> {
|
|
|
|
&self.action
|
|
|
|
}
|
|
|
|
|
2024-11-10 08:07:44 +02:00
|
|
|
pub fn tab(&self) -> &Rc<Tab> {
|
|
|
|
&self.tab
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|