Browse Source

implement navigation request session save

CPP-GTK4
yggverse 3 months ago
parent
commit
309bf1b587
  1. 20
      src/app/browser/main/tab.cpp
  2. 16
      src/app/browser/main/tab/page.cpp
  3. 125
      src/app/browser/main/tab/page/navigation.cpp
  4. 63
      src/app/browser/main/tab/page/navigation.hpp
  5. 128
      src/app/browser/main/tab/page/navigation/request.cpp
  6. 84
      src/app/browser/main/tab/page/navigation/request.hpp

20
src/app/browser/main/tab.cpp

@ -35,8 +35,7 @@ Tab::Tab(
signal_realize().connect( signal_realize().connect(
[this] [this]
{ {
// Restore session from DB restore(); // last session from DB
restore();
} }
); );
@ -82,6 +81,8 @@ int Tab::restore()
DB::APP_BROWSER_MAIN_TAB__SESSION::IS_CURRENT DB::APP_BROWSER_MAIN_TAB__SESSION::IS_CURRENT
) == 1 ) == 1
); );
// @TODO restore child widget sessions
} }
} }
@ -382,7 +383,7 @@ int Tab::DB::APP_BROWSER_MAIN_TAB__SESSION::clean(
); );
// Delete record // Delete record
sqlite3_exec( const int EXEC_STATUS = sqlite3_exec(
db, db,
Glib::ustring::sprintf( Glib::ustring::sprintf(
R"SQL( R"SQL(
@ -395,11 +396,14 @@ int Tab::DB::APP_BROWSER_MAIN_TAB__SESSION::clean(
&error &error
); );
// Delegate cleanup childs // Delegate children dependencies cleanup
tab::Page::DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::clean( if (EXEC_STATUS == SQLITE_OK)
db, {
APP_BROWSER_MAIN_TAB__SESSION_ID tab::Page::DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::clean(
); db,
APP_BROWSER_MAIN_TAB__SESSION_ID
);
}
} }
} }

16
src/app/browser/main/tab/page.cpp

@ -30,6 +30,7 @@ Page::Page(
// Init components // Init components
pageNavigation = Gtk::make_managed<page::Navigation>( pageNavigation = Gtk::make_managed<page::Navigation>(
this->db,
ACTION__REFRESH, ACTION__REFRESH,
ACTION__PAGE_NAVIGATION_HISTORY_BACK, ACTION__PAGE_NAVIGATION_HISTORY_BACK,
ACTION__PAGE_NAVIGATION_HISTORY_FORWARD, ACTION__PAGE_NAVIGATION_HISTORY_FORWARD,
@ -74,7 +75,7 @@ int Page::save(
) { ) {
// Delegate save action to child components // Delegate save action to child components
return pageNavigation->save( return pageNavigation->save(
Page::DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::add( DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::add(
db, db,
DB__APP_BROWSER_MAIN_TAB__SESSION_ID, DB__APP_BROWSER_MAIN_TAB__SESSION_ID,
mime, mime,
@ -417,10 +418,8 @@ int Page::DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::clean(
DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::ID DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::ID
); );
// @TODO Delegate cleanup to the child components
// Delete record // Delete record
sqlite3_exec( const int EXEC_STATUS = sqlite3_exec(
db, db,
Glib::ustring::sprintf( Glib::ustring::sprintf(
R"SQL( R"SQL(
@ -432,6 +431,15 @@ int Page::DB::APP_BROWSER_MAIN_TAB_PAGE__SESSION::clean(
nullptr, nullptr,
&error &error
); );
// Delegate children dependencies cleanup
if (EXEC_STATUS == SQLITE_OK)
{
page::Navigation::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::clean(
db,
APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
);
}
} }
} }

125
src/app/browser/main/tab/page/navigation.cpp

@ -8,11 +8,17 @@
using namespace app::browser::main::tab::page; using namespace app::browser::main::tab::page;
Navigation::Navigation( Navigation::Navigation(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH, const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_BACK, const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_FORWARD, const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_FORWARD,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_UPDATE const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_UPDATE
) { ) {
// Init database
DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::init(
this->db = db
);
// Init container // Init container
set_orientation( set_orientation(
Gtk::Orientation::HORIZONTAL Gtk::Orientation::HORIZONTAL
@ -63,6 +69,7 @@ Navigation::Navigation(
); );
navigationRequest = Gtk::make_managed<navigation::Request>( navigationRequest = Gtk::make_managed<navigation::Request>(
db,
ACTION__REFRESH, ACTION__REFRESH,
ACTION__NAVIGATION_UPDATE ACTION__NAVIGATION_UPDATE
); );
@ -104,9 +111,12 @@ void Navigation::refresh(
int Navigation::save( int Navigation::save(
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
) { ) {
navigationRequest->save(); return navigationRequest->save(
DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::add(
return 1; // @TODO SQL db,
DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
)
);
} }
void Navigation::history_add( void Navigation::history_add(
@ -191,3 +201,112 @@ void Navigation::set_request_text(
VALUE VALUE
); );
} }
// Database model
int Navigation::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::init(
sqlite3 * db
) {
char * error;
return sqlite3_exec(
db,
R"SQL(
CREATE TABLE IF NOT EXISTS `app_browser_main_tab_page_navigation__session`
(
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab_page__session_id` INTEGER NOT NULL,
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP
)
)SQL",
nullptr,
nullptr,
&error
);
}
int Navigation::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::clean(
sqlite3 * db,
const int & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
) {
char * error; // @TODO
sqlite3_stmt * statement;
const int PREPARE_STATUS = sqlite3_prepare_v3(
db,
Glib::ustring::sprintf(
R"SQL(
SELECT * FROM `app_browser_main_tab_page_navigation__session` WHERE `app_browser_main_tab_page__session_id` = %d
)SQL",
DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
).c_str(),
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE_STATUS == SQLITE_OK)
{
while (::sqlite3_step(statement) == SQLITE_ROW)
{
const int APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID = sqlite3_column_int(
statement,
DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::ID
);
// Delete record
const int EXEC_STATUS = sqlite3_exec(
db,
Glib::ustring::sprintf(
R"SQL(
DELETE FROM `app_browser_main_tab_page_navigation__session` WHERE `id` = %d
)SQL",
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
).c_str(),
nullptr,
nullptr,
&error
);
// Delegate children dependencies cleanup
if (EXEC_STATUS == SQLITE_OK)
{
navigation::Request::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::clean(
db,
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
);
}
}
}
return sqlite3_finalize(
statement
);
}
sqlite3_int64 Navigation::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION::add(
sqlite3 * db,
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
) {
char * error; // @TODO
sqlite3_exec(
db,
Glib::ustring::sprintf(
R"SQL(
INSERT INTO `app_browser_main_tab_page_navigation__session` (
`app_browser_main_tab_page__session_id`
) VALUES (
'%d'
)
)SQL",
DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
).c_str(),
nullptr,
nullptr,
&error
);
return sqlite3_last_insert_rowid(
db
);
}

63
src/app/browser/main/tab/page/navigation.hpp

@ -21,20 +21,65 @@ namespace app::browser::main::tab::page
class Navigation : public Gtk::Box class Navigation : public Gtk::Box
{ {
// Components public:
navigation::Base * navigationBase;
navigation::Bookmark * navigationBookmark; /*
navigation::History * navigationHistory; * Class database
navigation::Request * navigationRequest; *
navigation::Update * navigationUpdate; * Allowed parental access to enums and relationship methods
*/
struct DB
{
struct APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION
{
enum
{
ID,
TIME
}; // table fields index
static int init(
sqlite3 * db
); // return sqlite3_exec status code
static int clean(
sqlite3 * db,
const int & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
); // return sqlite3_finalize status code
static sqlite3_int64 add(
sqlite3 * db,
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID
); // return sqlite3_last_insert_rowid
};
};
/*
* Internal members
*/
private:
// Database
sqlite3 * db;
// Components
navigation::Base * navigationBase;
navigation::Bookmark * navigationBookmark;
navigation::History * navigationHistory;
navigation::Request * navigationRequest;
navigation::Update * navigationUpdate;
// Defaults // Defaults
const int SPACING = 8; const int SPACING = 8;
const int MARGIN = 8; const int MARGIN = 8;
/*
* Class API
*/
public: public:
Navigation( Navigation(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH, const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_BACK, const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_BACK,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_FORWARD, const Glib::RefPtr<Gio::SimpleAction> & ACTION__NAVIGATION_HISTORY_FORWARD,

128
src/app/browser/main/tab/page/navigation/request.cpp

@ -4,9 +4,15 @@ using namespace app::browser::main::tab::page::navigation;
// Construct // Construct
Request::Request( Request::Request(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH, const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE
) { ) {
// Init database
DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::init(
this->db = db
);
// Init actions // Init actions
action__refresh = ACTION__REFRESH; action__refresh = ACTION__REFRESH;
action__update = ACTION__UPDATE; action__update = ACTION__UPDATE;
@ -78,9 +84,14 @@ void Request::refresh(
); );
} }
int Request::save() int Request::save(
{ const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
return 1; // @TODO SQL ) {
return DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::add(
db,
DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID,
get_text()
);
} }
void Request::parse() void Request::parse()
@ -138,3 +149,114 @@ Glib::ustring Request::get_query()
{ {
return path; return path;
} }
// Database model
int Request::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::init(
sqlite3 * db
) {
char * error;
return sqlite3_exec(
db,
R"SQL(
CREATE TABLE IF NOT EXISTS `app_browser_main_tab_page_navigation_request__session`
(
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab_page_navigation__session_id` INTEGER NOT NULL,
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
`text` VARCHAR (1024) NOT NULL
)
)SQL",
nullptr,
nullptr,
&error
);
}
int Request::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::clean(
sqlite3 * db,
const int & DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
) {
char * error; // @TODO
sqlite3_stmt * statement;
const int PREPARE_STATUS = sqlite3_prepare_v3(
db,
Glib::ustring::sprintf(
R"SQL(
SELECT * FROM `app_browser_main_tab_page_navigation_request__session` WHERE `app_browser_main_tab_page_navigation__session_id` = %d
)SQL",
DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
).c_str(),
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE_STATUS == SQLITE_OK)
{
while (::sqlite3_step(statement) == SQLITE_ROW)
{
const int APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION_ID = sqlite3_column_int(
statement,
DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::ID
);
// Delete record
const int EXEC_STATUS = sqlite3_exec(
db,
Glib::ustring::sprintf(
R"SQL(
DELETE FROM `app_browser_main_tab_page_navigation_request__session` WHERE `id` = %d
)SQL",
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION_ID
).c_str(),
nullptr,
nullptr,
&error
);
// Delegate children dependencies cleanup
if (EXEC_STATUS == SQLITE_OK)
{
// nothing here.
}
}
}
return sqlite3_finalize(
statement
);
}
sqlite3_int64 Request::DB::APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION::add(
sqlite3 * db,
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID,
const Glib::ustring & TEXT
) {
char * error; // @TODO
sqlite3_exec(
db,
Glib::ustring::sprintf(
R"SQL(
INSERT INTO `app_browser_main_tab_page_navigation_request__session` (
`app_browser_main_tab_page_navigation__session_id`,
`text`
) VALUES (
'%d',
'%s'
)
)SQL",
DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID,
TEXT
).c_str(),
nullptr,
nullptr,
&error
);
return sqlite3_last_insert_rowid(
db
);
}

84
src/app/browser/main/tab/page/navigation/request.hpp

@ -8,35 +8,83 @@
#include <glibmm/regex.h> #include <glibmm/regex.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/entry.h> #include <gtkmm/entry.h>
#include <sqlite3.h>
namespace app::browser::main::tab::page::navigation namespace app::browser::main::tab::page::navigation
{ {
class Request : public Gtk::Entry class Request : public Gtk::Entry
{ {
// Actions public:
Glib::RefPtr<Gio::SimpleAction> action__refresh,
action__update; /*
* Class database
*
* Allowed parental access to enums and relationship methods
*/
struct DB
{
struct APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION_REQUEST__SESSION
{
enum
{
ID,
TIME,
TEXT
}; // table fields index
static int init(
sqlite3 * db
); // return sqlite3_exec status code
static int clean(
sqlite3 * db,
const int & DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
); // return sqlite3_finalize status code
static sqlite3_int64 add(
sqlite3 * db,
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID,
const Glib::ustring & TEXT
); // return sqlite3_last_insert_rowid
};
};
// Extras /*
double progress_fraction; * Internal members
*/
private:
Glib::ustring scheme, // Database
host, sqlite3 * db;
port,
path,
query;
// Defaults // Actions
const bool HEXPAND = true; Glib::RefPtr<Gio::SimpleAction> action__refresh,
const double PROGRESS_PULSE_STEP = .1; action__update;
const int PROGRESS_ANIMATION_TIME = 10;
// Extras
double progress_fraction;
Glib::ustring scheme,
host,
port,
path,
query;
// Private helpers // Defaults
void parse(); const bool HEXPAND = true;
const double PROGRESS_PULSE_STEP = .1;
const int PROGRESS_ANIMATION_TIME = 10;
// Private helpers
void parse();
/*
* Class API
*/
public: public:
Request( Request(
sqlite3 * db,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH, const Glib::RefPtr<Gio::SimpleAction> & ACTION__REFRESH,
const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE const Glib::RefPtr<Gio::SimpleAction> & ACTION__UPDATE
); );
@ -46,7 +94,9 @@ namespace app::browser::main::tab::page::navigation
const double & PROGRESS_FRACTION const double & PROGRESS_FRACTION
); );
int save(); int save(
const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION_ID
);
// Getters // Getters
Glib::ustring get_scheme(); Glib::ustring get_scheme();

Loading…
Cancel
Save