implement navigation history session save

This commit is contained in:
yggverse 2024-09-13 02:41:53 +03:00
parent ab21f58adb
commit a9d00188f4
4 changed files with 328 additions and 35 deletions

View file

@ -8,6 +8,7 @@
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/object.h>
#include <sqlite3.h>
#include <vector>
namespace app::browser::main::tab::page::navigation
@ -20,26 +21,77 @@ namespace app::browser::main::tab::page::navigation
class History : public Gtk::Box
{
// Components
history::Back * historyBack;
history::Forward * historyForward;
private:
/*
* History class database
*
* Allowed parental access to enums and relationship methods
*/
struct DB
{
// APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__*
struct SESSION
{
enum
{
ID,
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID,
TIME,
REQUEST,
IS_CURRENT
}; // table fields index
int index = -1;
static int init(
sqlite3 * db
); // return sqlite3_exec status code
static int clean(
sqlite3 * db,
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
); // return sqlite3_finalize status code
static sqlite3_int64 add(
sqlite3 * db,
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID,
const int & TIME,
const Glib::ustring & REQUEST,
const bool & IS_CURRENT
); // return sqlite3_last_insert_rowid
};
};
/*
* Internal members
*/
private:
// Database
sqlite3 * db;
// Components
history::Back * historyBack;
history::Forward * historyForward;
// Extras
int index = -1;
/*
* History class API
*/
public:
// Extras
struct Memory
{
Glib::ustring request;
std::time_t time; // event unix time
bool permanent; // save in database (on application close) @TODO
std::time_t time; // event unix time
};
// Define navigation history storage
std::vector<Memory> memory;
History(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__HISTORY_FORWARD
);
@ -50,9 +102,15 @@ namespace app::browser::main::tab::page::navigation
const bool & UPDATE_MEMORY_INDEX
);
void update();
int restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
); // return sqlite3_finalize status code
void save(); // @TODO save history to the permanent storage
void save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
);
void update();
bool try_back(
Memory & match,