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-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-14 08:51:14 +02:00
|
|
|
use crate::Profile;
|
2024-11-11 05:11:48 +02:00
|
|
|
use gtk::glib::GString;
|
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-28 01:35:48 +02:00
|
|
|
pub action: Rc<Action>,
|
|
|
|
pub tab: Rc<Tab>,
|
|
|
|
pub 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-11-14 08:51:14 +02:00
|
|
|
pub fn new(profile: Rc<Profile>, browser_action: Rc<BrowserAction>) -> 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-14 08:51:14 +02:00
|
|
|
let tab = Rc::new(Tab::new(profile, (browser_action.clone(), action.clone())));
|
2024-11-28 01:35:48 +02:00
|
|
|
let header = Header::new(browser_action, action.clone(), &tab.widget.gobject);
|
|
|
|
let widget = Rc::new(Widget::new(&header.widget.gobject, &tab.widget.gobject));
|
2024-09-23 15:56:09 +03:00
|
|
|
|
2024-11-10 08:51:08 +02:00
|
|
|
// Init events
|
2024-11-28 01:35:48 +02:00
|
|
|
action.append.connect_activate({
|
2024-11-10 08:51:08 +02:00
|
|
|
let tab = tab.clone();
|
2024-11-11 14:47:51 +02:00
|
|
|
move |position, request, is_pinned, is_selected, is_attention, is_load| {
|
|
|
|
tab.append(
|
|
|
|
position,
|
|
|
|
request,
|
|
|
|
is_pinned,
|
|
|
|
is_selected,
|
|
|
|
is_attention,
|
|
|
|
is_load,
|
|
|
|
);
|
2024-11-10 08:51:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.bookmark.connect_activate({
|
2024-11-12 18:02:35 +02:00
|
|
|
let tab = tab.clone();
|
2024-11-14 12:48:58 +02:00
|
|
|
move |position| {
|
|
|
|
if tab.bookmark(position).is_err() {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2024-11-12 18:02:35 +02:00
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.pin.connect_activate({
|
2024-11-10 10:07:16 +02:00
|
|
|
let tab = tab.clone();
|
2024-11-10 10:30:10 +02:00
|
|
|
move |position| tab.pin(position)
|
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.reload.connect_activate({
|
2024-11-10 10:30:10 +02:00
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| tab.page_reload(position)
|
2024-11-10 10:07:16 +02:00
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.home.connect_activate({
|
2024-11-10 10:46:46 +02:00
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| tab.page_home(position)
|
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.close.connect_activate({
|
2024-11-10 11:53:43 +02:00
|
|
|
let tab = tab.clone();
|
2024-11-12 18:05:44 +02:00
|
|
|
move |position| tab.close(position)
|
2024-11-10 11:53:43 +02:00
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.close_all.connect_activate({
|
2024-11-10 11:53:43 +02:00
|
|
|
let tab = tab.clone();
|
2024-11-12 18:05:44 +02:00
|
|
|
move |_| tab.close_all()
|
2024-11-10 11:53:43 +02:00
|
|
|
});
|
|
|
|
|
2024-12-11 16:19:37 +02:00
|
|
|
action.save_as.connect_activate({
|
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| tab.save_as(position)
|
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.history_back.connect_activate({
|
2024-11-10 11:53:43 +02:00
|
|
|
let tab = tab.clone();
|
|
|
|
move |position| {
|
|
|
|
tab.page_history_back(position);
|
|
|
|
} // @TODO rename destination method
|
|
|
|
});
|
|
|
|
|
2024-11-28 01:35:48 +02:00
|
|
|
action.history_forward.connect_activate({
|
2024-11-10 11:53:43 +02:00
|
|
|
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-11-10 08:51:08 +02:00
|
|
|
action,
|
2024-11-11 05:11:48 +02:00
|
|
|
tab,
|
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> {
|
2024-11-13 11:45:33 +02:00
|
|
|
match database::select(transaction, app_browser_id) {
|
2024-10-06 18:20:36 +03:00
|
|
|
Ok(records) => {
|
|
|
|
for record in records {
|
2024-11-12 17:22:07 +02: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> {
|
2024-11-13 11:45:33 +02:00
|
|
|
match database::select(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> {
|
2024-11-13 11:45:33 +02:00
|
|
|
match database::insert(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
|
2024-11-12 17:22:07 +02:00
|
|
|
.save(transaction, &database::last_insert_id(transaction))
|
2024-10-07 21:10:12 +03:00
|
|
|
{
|
|
|
|
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-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-12 17:22:07 +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
|
|
|
}
|