2024-08-10 17:57:15 +03:00
|
|
|
#include "browser.hpp"
|
|
|
|
#include "browser/header.hpp"
|
2024-08-11 22:04:34 +03:00
|
|
|
#include "browser/main.hpp"
|
2024-08-05 03:15:41 +03:00
|
|
|
|
2024-08-08 12:44:27 +03:00
|
|
|
using namespace app;
|
2024-08-05 03:15:41 +03:00
|
|
|
|
2024-08-11 09:55:10 +03:00
|
|
|
Browser::Browser(
|
2024-09-09 05:06:36 +03:00
|
|
|
sqlite3 * db,
|
2024-09-08 08:15:17 +03:00
|
|
|
const Glib::RefPtr<Gtk::Application> & APP
|
2024-08-11 09:55:10 +03:00
|
|
|
) {
|
2024-09-08 02:09:54 +03:00
|
|
|
// Init window actions
|
2024-09-11 07:49:01 +03:00
|
|
|
const auto ACTION__UPDATE = add_action(
|
|
|
|
"update",
|
2024-08-16 19:45:42 +03:00
|
|
|
[this]
|
|
|
|
{
|
2024-09-11 02:34:02 +03:00
|
|
|
browserMain->update();
|
2024-08-11 09:55:10 +03:00
|
|
|
|
2024-09-11 02:34:02 +03:00
|
|
|
browserHeader->update(
|
2024-09-08 07:47:39 +03:00
|
|
|
browserMain->get_current_tab_page_title(),
|
2024-09-10 07:50:15 +03:00
|
|
|
browserMain->get_current_tab_page_description()
|
2024-09-05 16:40:41 +03:00
|
|
|
);
|
2024-08-16 19:45:42 +03:00
|
|
|
}
|
2024-08-14 07:11:24 +03:00
|
|
|
);
|
|
|
|
|
2024-09-11 08:00:47 +03:00
|
|
|
const auto ACTION__CLEAN = add_action(
|
|
|
|
"clean",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->clean();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-09-10 03:23:29 +03:00
|
|
|
const auto ACTION__RESTORE = add_action(
|
|
|
|
"restore",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->restore();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const auto ACTION__SAVE = add_action(
|
|
|
|
"save",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->save();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-09-08 17:48:19 +03:00
|
|
|
const auto ACTION__DEBUG = add_action(
|
2024-09-05 16:40:41 +03:00
|
|
|
"debug",
|
2024-08-16 19:45:42 +03:00
|
|
|
[this]
|
|
|
|
{
|
2024-09-05 16:40:41 +03:00
|
|
|
// @TODO https://gitlab.gnome.org/GNOME/gtkmm/-/commit/5f3b82537d3daad7bda59dd01e719788070f4b6c
|
|
|
|
gtk_window_set_interactive_debugging(
|
|
|
|
true
|
|
|
|
);
|
2024-08-16 19:45:42 +03:00
|
|
|
}
|
2024-08-12 19:11:00 +03:00
|
|
|
);
|
|
|
|
|
2024-09-08 08:15:17 +03:00
|
|
|
APP->set_accel_for_action(
|
|
|
|
"win.debug",
|
|
|
|
"<Primary>i"
|
2024-08-12 20:24:06 +03:00
|
|
|
);
|
|
|
|
|
2024-09-08 17:48:19 +03:00
|
|
|
const auto ACTION__MAIN_TAB_APPEND = add_action(
|
2024-09-08 08:15:17 +03:00
|
|
|
"main_tab_append",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_append();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
APP->set_accel_for_action(
|
|
|
|
"win.main_tab_append",
|
|
|
|
"<Primary>t"
|
2024-08-12 20:24:06 +03:00
|
|
|
);
|
|
|
|
|
2024-09-08 17:58:40 +03:00
|
|
|
const auto ACTION__MAIN_TAB_CLOSE_ACTIVE = add_action(
|
|
|
|
"main_tab_close_active",
|
2024-09-08 08:15:17 +03:00
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_close();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-09-08 18:08:54 +03:00
|
|
|
ACTION__MAIN_TAB_CLOSE_ACTIVE->set_enabled(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
APP->set_accel_for_action(
|
|
|
|
"win.main_tab_close_active",
|
|
|
|
"<Primary>Escape"
|
|
|
|
);
|
|
|
|
|
2024-09-08 08:15:17 +03:00
|
|
|
add_action(
|
|
|
|
"main_tab_close_left",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_close_left();
|
|
|
|
}
|
|
|
|
)->set_enabled(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
"main_tab_close_right",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_close_right();
|
|
|
|
}
|
|
|
|
)->set_enabled(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2024-09-08 17:58:40 +03:00
|
|
|
const auto ACTION__MAIN_TAB_CLOSE_ALL = add_action(
|
2024-09-08 08:15:17 +03:00
|
|
|
"main_tab_close_all",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_close_all();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-09-08 17:58:40 +03:00
|
|
|
ACTION__MAIN_TAB_CLOSE_ALL->set_enabled(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2024-09-11 07:33:53 +03:00
|
|
|
const auto ACTION__MAIN_TAB_PAGE_NAVIGATION_RELOAD = add_action(
|
|
|
|
"main_tab_page_navigation_reload",
|
2024-09-08 08:18:23 +03:00
|
|
|
[this]
|
|
|
|
{
|
2024-09-11 07:33:53 +03:00
|
|
|
browserMain->tab_page_navigation_reload();
|
2024-09-08 08:18:23 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-09-11 07:33:53 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_RELOAD->set_enabled(
|
2024-09-08 08:18:23 +03:00
|
|
|
false
|
2024-08-12 20:24:06 +03:00
|
|
|
);
|
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
APP->set_accel_for_action(
|
2024-09-11 07:33:53 +03:00
|
|
|
"win.main_tab_page_navigation_reload",
|
2024-09-08 08:18:23 +03:00
|
|
|
"<Primary>r"
|
|
|
|
);
|
2024-09-08 08:15:17 +03:00
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
const auto ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK = add_action(
|
|
|
|
"main_tab_page_navigation_history_back",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_page_navigation_history_back();
|
|
|
|
}
|
|
|
|
);
|
2024-09-08 08:15:17 +03:00
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK->set_enabled(
|
|
|
|
false
|
2024-09-05 02:31:23 +03:00
|
|
|
);
|
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
APP->set_accel_for_action(
|
|
|
|
"win.main_tab_page_navigation_history_back",
|
|
|
|
"<Primary>Left"
|
|
|
|
);
|
2024-09-08 08:15:17 +03:00
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
const auto ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD = add_action(
|
|
|
|
"main_tab_page_navigation_history_forward",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
browserMain->tab_page_navigation_history_forward();
|
|
|
|
}
|
|
|
|
);
|
2024-09-08 08:15:17 +03:00
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD->set_enabled(
|
|
|
|
false
|
2024-09-05 02:31:23 +03:00
|
|
|
);
|
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
APP->set_accel_for_action(
|
|
|
|
"win.main_tab_page_navigation_history_forward",
|
|
|
|
"<Primary>Right"
|
|
|
|
);
|
2024-09-08 02:09:54 +03:00
|
|
|
|
2024-09-09 07:45:17 +03:00
|
|
|
const auto ACTION__QUIT = add_action(
|
|
|
|
"quit",
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
APP->set_accel_for_action(
|
|
|
|
"win.quit",
|
|
|
|
"<Primary>q"
|
|
|
|
);
|
|
|
|
|
2024-09-08 02:09:54 +03:00
|
|
|
// Init widget
|
|
|
|
set_title(
|
|
|
|
_("Yoda")
|
|
|
|
);
|
|
|
|
|
|
|
|
set_default_size(
|
|
|
|
WIDTH,
|
|
|
|
HEIGHT
|
|
|
|
);
|
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
// Init components
|
2024-09-08 17:48:19 +03:00
|
|
|
browserHeader = Gtk::make_managed<browser::Header>(
|
|
|
|
ACTION__DEBUG,
|
2024-09-09 07:45:17 +03:00
|
|
|
ACTION__QUIT,
|
2024-09-11 08:00:47 +03:00
|
|
|
ACTION__CLEAN,
|
2024-09-10 03:23:29 +03:00
|
|
|
ACTION__RESTORE,
|
|
|
|
ACTION__SAVE,
|
2024-09-08 17:48:19 +03:00
|
|
|
ACTION__MAIN_TAB_APPEND,
|
2024-09-08 17:58:40 +03:00
|
|
|
ACTION__MAIN_TAB_CLOSE_ACTIVE,
|
|
|
|
ACTION__MAIN_TAB_CLOSE_ALL,
|
2024-09-08 17:48:19 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
|
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
|
2024-09-11 07:33:53 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_RELOAD
|
2024-09-08 17:48:19 +03:00
|
|
|
);
|
2024-09-08 02:09:54 +03:00
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
set_titlebar(
|
|
|
|
* browserHeader
|
|
|
|
);
|
2024-09-08 02:09:54 +03:00
|
|
|
|
2024-09-08 03:49:08 +03:00
|
|
|
browserMain = Gtk::make_managed<browser::Main>(
|
2024-09-08 22:13:52 +03:00
|
|
|
db,
|
2024-09-11 07:49:01 +03:00
|
|
|
ACTION__UPDATE,
|
2024-09-08 17:58:40 +03:00
|
|
|
ACTION__MAIN_TAB_CLOSE_ACTIVE,
|
2024-09-08 18:19:29 +03:00
|
|
|
ACTION__MAIN_TAB_CLOSE_ALL,
|
2024-09-08 03:49:08 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_BACK,
|
2024-09-08 04:20:25 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_HISTORY_FORWARD,
|
2024-09-11 07:33:53 +03:00
|
|
|
ACTION__MAIN_TAB_PAGE_NAVIGATION_RELOAD
|
2024-09-08 03:49:08 +03:00
|
|
|
);
|
2024-09-08 02:09:54 +03:00
|
|
|
|
2024-09-08 08:18:23 +03:00
|
|
|
set_child(
|
|
|
|
* browserMain
|
|
|
|
);
|
2024-09-09 07:18:49 +03:00
|
|
|
|
|
|
|
// Connect signals
|
|
|
|
signal_close_request().connect(
|
|
|
|
[this]
|
|
|
|
{
|
2024-09-10 03:47:12 +03:00
|
|
|
browserMain->save();
|
2024-09-09 07:18:49 +03:00
|
|
|
|
2024-09-09 10:58:12 +03:00
|
|
|
// @TODO sqlite3_close(db);
|
|
|
|
|
2024-09-09 07:18:49 +03:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2024-08-16 19:45:42 +03:00
|
|
|
}
|