2024-09-22 13:17:18 +03:00
|
|
|
mod db;
|
2024-09-20 18:02:10 +03:00
|
|
|
mod header;
|
|
|
|
mod main;
|
2024-09-22 17:34:22 +03:00
|
|
|
mod widget;
|
2024-09-18 20:33:29 +03:00
|
|
|
|
2024-09-23 02:17:53 +03:00
|
|
|
use gtk::gio::ActionEntry;
|
|
|
|
use gtk::{Application, ApplicationWindow};
|
2024-09-23 01:57:16 +03:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use gtk::prelude::{ActionMapExtManual, GtkWindowExt};
|
2024-09-18 20:33:29 +03:00
|
|
|
|
2024-09-22 02:00:54 +03:00
|
|
|
pub struct Browser {
|
2024-09-23 13:50:59 +03:00
|
|
|
// Extras
|
2024-09-22 13:17:18 +03:00
|
|
|
db: db::Browser,
|
2024-09-22 17:34:22 +03:00
|
|
|
widget: widget::Browser,
|
2024-09-23 13:50:59 +03:00
|
|
|
// Components
|
|
|
|
header: Arc<header::Header>,
|
|
|
|
main: Arc<main::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 {
|
|
|
|
// Construct new browser
|
|
|
|
pub fn new(
|
2024-09-23 02:17:53 +03:00
|
|
|
app: &Application,
|
|
|
|
connection: Arc<sqlite::Connection>, // @TODO glib clone macro?
|
2024-09-22 17:36:31 +03:00
|
|
|
default_width: i32,
|
|
|
|
default_height: i32,
|
2024-09-22 17:34:22 +03:00
|
|
|
) -> Browser {
|
2024-09-23 01:57:16 +03:00
|
|
|
// Init components
|
|
|
|
let db = db::Browser::new(connection);
|
|
|
|
let header = header::Header::new();
|
|
|
|
let main = main::Main::new();
|
|
|
|
|
2024-09-22 17:34:22 +03:00
|
|
|
let widget = widget::Browser::new(
|
|
|
|
app,
|
2024-09-23 01:57:16 +03:00
|
|
|
header.widget().gtk(),
|
|
|
|
main.widget().gtk(),
|
2024-09-22 17:36:31 +03:00
|
|
|
default_width,
|
|
|
|
default_height,
|
2024-09-22 17:34:22 +03:00
|
|
|
);
|
|
|
|
|
2024-09-23 01:57:16 +03:00
|
|
|
// Init actions @TODO separated module
|
|
|
|
widget.gtk().add_action_entries([
|
2024-09-23 02:17:53 +03:00
|
|
|
ActionEntry::builder("debug")
|
|
|
|
.activate(|this: &ApplicationWindow, _, _| {
|
2024-09-23 01:57:16 +03:00
|
|
|
this.emit_enable_debugging(true);
|
|
|
|
})
|
|
|
|
.build(),
|
2024-09-23 02:17:53 +03:00
|
|
|
ActionEntry::builder("quit")
|
|
|
|
.activate(|this: &ApplicationWindow, _, _| {
|
2024-09-23 01:57:16 +03:00
|
|
|
this.close();
|
|
|
|
})
|
|
|
|
.build(),
|
2024-09-23 02:17:53 +03:00
|
|
|
ActionEntry::builder("tab_append")
|
2024-09-23 01:57:16 +03:00
|
|
|
.activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _, _| {
|
|
|
|
main.tab_append();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.build(),
|
|
|
|
]);
|
2024-09-22 17:34:22 +03:00
|
|
|
|
|
|
|
// Return
|
|
|
|
Self {
|
2024-09-23 01:57:16 +03:00
|
|
|
db,
|
2024-09-23 13:50:59 +03:00
|
|
|
widget,
|
2024-09-23 01:57:16 +03:00
|
|
|
header,
|
|
|
|
main,
|
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
|
|
|
|
pub fn widget(&self) -> &widget::Browser {
|
|
|
|
&self.widget
|
2024-09-22 12:42:34 +03:00
|
|
|
}
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|