mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
save tab session to profile database on application quit
This commit is contained in:
parent
dfcc131ce2
commit
881e1b78d6
7 changed files with 92 additions and 15 deletions
|
|
@ -189,4 +189,15 @@ Browser::Browser(
|
||||||
set_child(
|
set_child(
|
||||||
* browserMain
|
* browserMain
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Connect signals
|
||||||
|
signal_close_request().connect(
|
||||||
|
[this]
|
||||||
|
{
|
||||||
|
browserMain->shutdown();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +95,11 @@ void Main::tab_page_navigation_history_forward()
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void Main::shutdown()
|
||||||
|
{
|
||||||
|
mainTab->shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
Glib::ustring Main::get_current_tab_page_title()
|
Glib::ustring Main::get_current_tab_page_title()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ namespace app::browser
|
||||||
void tab_page_navigation_history_back();
|
void tab_page_navigation_history_back();
|
||||||
void tab_page_navigation_history_forward();
|
void tab_page_navigation_history_forward();
|
||||||
|
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
Glib::ustring get_current_tab_page_title();
|
Glib::ustring get_current_tab_page_title();
|
||||||
Glib::ustring get_current_tab_page_subtitle();
|
Glib::ustring get_current_tab_page_subtitle();
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,24 @@ Tab::Tab(
|
||||||
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_UPDATE
|
const Glib::RefPtr<Gio::SimpleAction> & ACTION__TAB_PAGE_NAVIGATION_UPDATE
|
||||||
) {
|
) {
|
||||||
// Init database
|
// Init database
|
||||||
char * errmsg;
|
this->db = db;
|
||||||
|
|
||||||
::sqlite3_exec(
|
char * error;
|
||||||
db,
|
|
||||||
R"SQL(
|
::sqlite3_exec(
|
||||||
CREATE TABLE IF NOT EXISTS `app_browser_main_tab`
|
db,
|
||||||
(
|
R"SQL(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
CREATE TABLE IF NOT EXISTS `app_browser_main_tab`
|
||||||
`time` INTEGER NOT NULL,
|
(
|
||||||
`request` VARCHAR(1024)
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
)
|
`time` INTEGER NOT NULL,
|
||||||
)SQL",
|
`request` VARCHAR(1024)
|
||||||
nullptr,
|
)
|
||||||
nullptr,
|
)SQL",
|
||||||
&errmsg
|
nullptr,
|
||||||
);
|
nullptr,
|
||||||
|
&error
|
||||||
|
);
|
||||||
|
|
||||||
// Init actions
|
// Init actions
|
||||||
action__refresh = ACTION__REFRESH;
|
action__refresh = ACTION__REFRESH;
|
||||||
|
|
@ -56,6 +58,51 @@ Tab::Tab(
|
||||||
// @TODO restore session from DB
|
// @TODO restore session from DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::shutdown()
|
||||||
|
{
|
||||||
|
char * error; // @TODO
|
||||||
|
|
||||||
|
// Delete previous tab session
|
||||||
|
::sqlite3_exec(
|
||||||
|
db,
|
||||||
|
R"SQL(
|
||||||
|
DELETE FROM `app_browser_main_tab`
|
||||||
|
)SQL",
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
&error
|
||||||
|
);
|
||||||
|
|
||||||
|
// Save current tab session
|
||||||
|
for (int page_number = 0; page_number < get_n_pages(); page_number++)
|
||||||
|
{
|
||||||
|
auto tabPage = get_tabPage(
|
||||||
|
page_number
|
||||||
|
);
|
||||||
|
|
||||||
|
::sqlite3_exec(
|
||||||
|
db,
|
||||||
|
Glib::ustring::sprintf(
|
||||||
|
R"SQL(
|
||||||
|
INSERT INTO `app_browser_main_tab` (
|
||||||
|
`time`,
|
||||||
|
`request`
|
||||||
|
) VALUES (
|
||||||
|
CURRENT_TIMESTAMP,
|
||||||
|
'%s'
|
||||||
|
)
|
||||||
|
)SQL",
|
||||||
|
tabPage->get_navigation_request_text()
|
||||||
|
).c_str(),
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
&error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO shutdown children components
|
||||||
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
void Tab::refresh(
|
void Tab::refresh(
|
||||||
const int & PAGE_NUMBER
|
const int & PAGE_NUMBER
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ namespace app::browser::main
|
||||||
|
|
||||||
class Tab : public Gtk::Notebook
|
class Tab : public Gtk::Notebook
|
||||||
{
|
{
|
||||||
|
// Database
|
||||||
|
sqlite3 * db;
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
Glib::RefPtr<Gio::SimpleAction> action__refresh,
|
Glib::RefPtr<Gio::SimpleAction> action__refresh,
|
||||||
action__tab_close_active,
|
action__tab_close_active,
|
||||||
|
|
@ -81,6 +84,8 @@ namespace app::browser::main
|
||||||
const int & PAGE_NUMBER
|
const int & PAGE_NUMBER
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
Glib::ustring get_page_title(
|
Glib::ustring get_page_title(
|
||||||
const int & PAGE_NUMBER
|
const int & PAGE_NUMBER
|
||||||
|
|
|
||||||
|
|
@ -265,4 +265,9 @@ Glib::ustring Page::get_title()
|
||||||
Glib::ustring Page::get_subtitle()
|
Glib::ustring Page::get_subtitle()
|
||||||
{
|
{
|
||||||
return subtitle;
|
return subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::ustring Page::get_navigation_request_text()
|
||||||
|
{
|
||||||
|
return pageNavigation->get_request_text();
|
||||||
}
|
}
|
||||||
|
|
@ -65,6 +65,8 @@ namespace app::browser::main::tab
|
||||||
// Getters
|
// Getters
|
||||||
Glib::ustring get_title();
|
Glib::ustring get_title();
|
||||||
Glib::ustring get_subtitle();
|
Glib::ustring get_subtitle();
|
||||||
|
|
||||||
|
Glib::ustring get_navigation_request_text();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue