2024-09-22 13:17:18 +03:00
|
|
|
mod db;
|
2024-09-20 18:02:10 +03:00
|
|
|
mod header;
|
|
|
|
mod main;
|
2024-09-18 20:33:29 +03:00
|
|
|
|
2024-09-24 23:08:40 +03:00
|
|
|
use header::Header;
|
|
|
|
use main::Main;
|
|
|
|
|
|
|
|
use gtk::{
|
2024-09-28 02:15:25 +03:00
|
|
|
gio::SimpleAction,
|
2024-09-30 13:43:46 +03:00
|
|
|
prelude::{ActionMapExt, GtkWindowExt},
|
2024-09-24 23:08:40 +03:00
|
|
|
Application, ApplicationWindow,
|
|
|
|
};
|
2024-09-23 01:57:16 +03:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2024-09-30 13:43:46 +03:00
|
|
|
const DEFAULT_HEIGHT: i32 = 480;
|
|
|
|
const DEFAULT_WIDTH: i32 = 640;
|
|
|
|
|
2024-09-22 02:00:54 +03:00
|
|
|
pub struct Browser {
|
2024-09-23 13:50:59 +03:00
|
|
|
// Extras
|
2024-09-23 18:51:48 +03:00
|
|
|
// db: db::Browser,
|
|
|
|
widget: ApplicationWindow,
|
2024-09-23 13:50:59 +03:00
|
|
|
// Components
|
2024-09-28 01:29:05 +03:00
|
|
|
// header: Arc<Header>,
|
|
|
|
// main: Arc<Main>,
|
2024-09-22 02:00:54 +03:00
|
|
|
}
|
2024-09-21 20:48:12 +03:00
|
|
|
|
2024-09-22 17:34:22 +03:00
|
|
|
impl Browser {
|
2024-09-23 13:58:56 +03:00
|
|
|
// Construct
|
2024-09-22 17:34:22 +03:00
|
|
|
pub fn new(
|
2024-09-23 02:17:53 +03:00
|
|
|
app: &Application,
|
2024-09-23 18:51:48 +03:00
|
|
|
// connection: Arc<sqlite::Connection>,
|
2024-09-30 13:43:46 +03:00
|
|
|
// Actions
|
|
|
|
action_debug: Arc<SimpleAction>,
|
|
|
|
action_quit: Arc<SimpleAction>,
|
|
|
|
action_update: Arc<SimpleAction>,
|
|
|
|
action_tab_append: Arc<SimpleAction>,
|
|
|
|
action_tab_close: Arc<SimpleAction>,
|
|
|
|
action_tab_close_all: Arc<SimpleAction>,
|
|
|
|
action_tab_page_reload: Arc<SimpleAction>,
|
|
|
|
action_tab_pin: Arc<SimpleAction>,
|
2024-09-23 18:51:48 +03:00
|
|
|
) -> Browser {
|
2024-09-30 13:43:46 +03:00
|
|
|
// Init database
|
|
|
|
// let db = db::Browser::new(connection); @TODO
|
2024-09-28 01:53:16 +03:00
|
|
|
|
2024-09-23 01:57:16 +03:00
|
|
|
// Init components
|
2024-09-28 01:53:16 +03:00
|
|
|
let header = Arc::new(Header::new(
|
2024-09-28 03:10:07 +03:00
|
|
|
action_debug.clone(),
|
|
|
|
action_quit.clone(),
|
|
|
|
action_tab_append.clone(),
|
|
|
|
action_tab_close.clone(),
|
|
|
|
action_tab_close_all.clone(),
|
|
|
|
action_tab_page_reload.clone(),
|
|
|
|
action_tab_pin.clone(),
|
2024-09-28 01:53:16 +03:00
|
|
|
));
|
2024-09-28 01:29:05 +03:00
|
|
|
|
2024-09-28 03:10:07 +03:00
|
|
|
let main = Arc::new(Main::new(
|
|
|
|
action_tab_page_reload.clone(),
|
|
|
|
action_update.clone(),
|
|
|
|
));
|
2024-09-23 01:57:16 +03:00
|
|
|
|
2024-09-28 01:29:05 +03:00
|
|
|
// Init widget
|
2024-09-23 18:51:48 +03:00
|
|
|
let widget = ApplicationWindow::builder()
|
|
|
|
.application(app)
|
|
|
|
.titlebar(header.widget())
|
|
|
|
.child(main.widget())
|
2024-09-30 13:43:46 +03:00
|
|
|
.default_height(DEFAULT_HEIGHT)
|
|
|
|
.default_width(DEFAULT_WIDTH)
|
2024-09-23 18:51:48 +03:00
|
|
|
.build();
|
|
|
|
|
2024-09-28 03:10:07 +03:00
|
|
|
widget.add_action(action_debug.as_ref());
|
|
|
|
widget.add_action(action_quit.as_ref());
|
|
|
|
widget.add_action(action_update.as_ref());
|
2024-09-28 01:29:05 +03:00
|
|
|
|
2024-09-28 03:10:07 +03:00
|
|
|
widget.add_action(action_tab_append.as_ref());
|
|
|
|
widget.add_action(action_tab_close.as_ref());
|
|
|
|
widget.add_action(action_tab_close_all.as_ref());
|
|
|
|
widget.add_action(action_tab_page_reload.as_ref());
|
|
|
|
widget.add_action(action_tab_pin.as_ref());
|
2024-09-28 02:11:29 +03:00
|
|
|
|
2024-09-28 01:29:05 +03:00
|
|
|
// Init events
|
|
|
|
action_debug.connect_activate({
|
2024-09-28 01:53:16 +03:00
|
|
|
let widget = widget.clone();
|
2024-09-28 01:29:05 +03:00
|
|
|
move |_, _| {
|
2024-09-28 01:53:16 +03:00
|
|
|
widget.emit_enable_debugging(true);
|
2024-09-28 01:29:05 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action_quit.connect_activate({
|
2024-09-28 01:53:16 +03:00
|
|
|
let widget = widget.clone();
|
2024-09-28 01:29:05 +03:00
|
|
|
move |_, _| {
|
2024-09-28 01:53:16 +03:00
|
|
|
widget.close();
|
2024-09-28 01:29:05 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action_update.connect_activate({
|
|
|
|
let header = header.clone();
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _| {
|
|
|
|
main.update();
|
|
|
|
header.update(main.tab_page_title(), main.tab_page_description());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-28 01:53:16 +03:00
|
|
|
action_tab_append.connect_activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _| {
|
|
|
|
main.tab_append(None);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action_tab_close.connect_activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _| {
|
|
|
|
main.tab_close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action_tab_close_all.connect_activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _| {
|
|
|
|
main.tab_close_all();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action_tab_page_reload.connect_activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _| {
|
|
|
|
main.tab_page_reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
action_tab_pin.connect_activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _| {
|
|
|
|
main.tab_pin();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Return activated browser struct
|
2024-09-23 18:51:48 +03:00
|
|
|
Self {
|
|
|
|
// db,
|
2024-09-23 13:50:59 +03:00
|
|
|
widget,
|
2024-09-28 01:29:05 +03:00
|
|
|
// header,
|
|
|
|
// main,
|
2024-09-23 18:51:48 +03:00
|
|
|
}
|
2024-09-22 17:34:22 +03:00
|
|
|
}
|
2024-09-19 18:08:09 +03:00
|
|
|
|
2024-09-22 17:34:22 +03:00
|
|
|
// Getters
|
2024-09-23 18:51:48 +03:00
|
|
|
pub fn widget(&self) -> &ApplicationWindow {
|
2024-09-22 17:34:22 +03:00
|
|
|
&self.widget
|
2024-09-22 12:42:34 +03:00
|
|
|
}
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|