Browse Source

implement restore feature for navbar request, change id data type to sqlite3_int64

CPP-GTK4
yggverse 2 months ago
parent
commit
6b6ae753bc
  1. 12
      src/app/browser/main/tab.cpp
  2. 47
      src/app/browser/main/tab/page.cpp
  3. 7
      src/app/browser/main/tab/page.hpp
  4. 47
      src/app/browser/main/tab/page/navigation.cpp
  5. 7
      src/app/browser/main/tab/page/navigation.hpp
  6. 51
      src/app/browser/main/tab/page/navigation/request.cpp
  7. 7
      src/app/browser/main/tab/page/navigation/request.hpp

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

@ -82,7 +82,15 @@ int Tab::restore() @@ -82,7 +82,15 @@ int Tab::restore()
) == 1
);
// @TODO restore child widget sessions
// Restore children components
get_tabPage(
PAGE_NUMBER
)->restore(
sqlite3_column_int64(
statement,
DB::SESSION::ID
)
);
}
}
@ -377,7 +385,7 @@ int Tab::DB::SESSION::clean( @@ -377,7 +385,7 @@ int Tab::DB::SESSION::clean(
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
const int APP_BROWSER_MAIN_TAB__SESSION__ID = sqlite3_column_int(
const sqlite3_int64 APP_BROWSER_MAIN_TAB__SESSION__ID = sqlite3_column_int64(
statement,
DB::SESSION::ID
);

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

@ -70,6 +70,49 @@ void Page::update() @@ -70,6 +70,49 @@ void Page::update()
);
}
int Page::restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
) {
sqlite3_stmt* statement; // @TODO move to the DB model namespace
const int PREPARE_STATUS = sqlite3_prepare_v3(
db,
Glib::ustring::sprintf(
R"SQL(
SELECT * FROM `app_browser_main_tab_page__session`
WHERE `app_browser_main_tab__session__id` = %d
ORDER BY `id` DESC LIMIT 1
)SQL",
APP_BROWSER_MAIN_TAB__SESSION__ID
).c_str(),
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE_STATUS == SQLITE_OK)
{
// Use latest record as order
while (sqlite3_step(statement) == SQLITE_ROW)
{
// Restore children components
pageNavigation->restore(
sqlite3_column_int64(
statement,
DB::SESSION::ID
)
);
}
}
sqlite3_finalize(
statement
);
return PREPARE_STATUS;
}
int Page::save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
) {
@ -390,7 +433,7 @@ int Page::DB::SESSION::init( @@ -390,7 +433,7 @@ int Page::DB::SESSION::init(
int Page::DB::SESSION::clean(
sqlite3 * db,
const int & APP_BROWSER_MAIN_TAB__SESSION__ID
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
) {
char * error; // @TODO
sqlite3_stmt * statement;
@ -413,7 +456,7 @@ int Page::DB::SESSION::clean( @@ -413,7 +456,7 @@ int Page::DB::SESSION::clean(
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
const int APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID = sqlite3_column_int(
const sqlite3_int64 APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID = sqlite3_column_int64(
statement,
DB::SESSION::ID
);

7
src/app/browser/main/tab/page.hpp

@ -48,6 +48,7 @@ namespace app::browser::main::tab @@ -48,6 +48,7 @@ namespace app::browser::main::tab
enum
{
ID,
APP_BROWSER_MAIN_TAB__SESSION__ID,
TIME,
MIME,
TITLE,
@ -60,7 +61,7 @@ namespace app::browser::main::tab @@ -60,7 +61,7 @@ namespace app::browser::main::tab
static int clean(
sqlite3 * db,
const int & APP_BROWSER_MAIN_TAB__SESSION__ID
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
); // return sqlite3_finalize status code
static sqlite3_int64 add(
@ -119,6 +120,10 @@ namespace app::browser::main::tab @@ -119,6 +120,10 @@ namespace app::browser::main::tab
// Actions
void update();
int restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
);
int save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
);

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

@ -108,6 +108,49 @@ void Navigation::update( @@ -108,6 +108,49 @@ void Navigation::update(
);
}
int Navigation::restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
) {
sqlite3_stmt* statement; // @TODO move to the DB model namespace
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
ORDER BY `id` DESC LIMIT 1
)SQL",
APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
).c_str(),
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE_STATUS == SQLITE_OK)
{
// Use latest record as order
while (sqlite3_step(statement) == SQLITE_ROW)
{
// Restore children components
navigationRequest->restore(
sqlite3_column_int64(
statement,
DB::SESSION::ID
)
);
}
}
sqlite3_finalize(
statement
);
return PREPARE_STATUS;
}
int Navigation::save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
) {
@ -225,7 +268,7 @@ int Navigation::DB::SESSION::init( @@ -225,7 +268,7 @@ int Navigation::DB::SESSION::init(
int Navigation::DB::SESSION::clean(
sqlite3 * db,
const int & APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
) {
char * error; // @TODO
sqlite3_stmt * statement;
@ -248,7 +291,7 @@ int Navigation::DB::SESSION::clean( @@ -248,7 +291,7 @@ int Navigation::DB::SESSION::clean(
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
const int APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID = sqlite3_column_int(
const sqlite3_int64 APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID = sqlite3_column_int64(
statement,
DB::SESSION::ID
);

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

@ -36,6 +36,7 @@ namespace app::browser::main::tab::page @@ -36,6 +36,7 @@ namespace app::browser::main::tab::page
enum
{
ID,
APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID,
TIME
}; // table fields index
@ -45,7 +46,7 @@ namespace app::browser::main::tab::page @@ -45,7 +46,7 @@ namespace app::browser::main::tab::page
static int clean(
sqlite3 * db,
const int & APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE__SESSION__ID
); // return sqlite3_finalize status code
static sqlite3_int64 add(
@ -92,6 +93,10 @@ namespace app::browser::main::tab::page @@ -92,6 +93,10 @@ namespace app::browser::main::tab::page
const double & PROGRESS_FRACTION
);
int restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
);
int save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB__SESSION__ID
);

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

@ -84,6 +84,53 @@ void Request::update( @@ -84,6 +84,53 @@ void Request::update(
);
}
int Request::restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
) {
sqlite3_stmt* statement; // @TODO move to the DB model namespace
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
ORDER BY `id` DESC LIMIT 1
)SQL",
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
).c_str(),
-1,
SQLITE_PREPARE_NORMALIZE,
&statement,
nullptr
);
if (PREPARE_STATUS == SQLITE_OK)
{
// Use latest record as order
while (sqlite3_step(statement) == SQLITE_ROW)
{
// Restore widget data
set_text(
reinterpret_cast<const char*>(
sqlite3_column_text(
statement,
DB::SESSION::TEXT
)
)
);
// Restore children components here (on available)
}
}
sqlite3_finalize(
statement
);
return PREPARE_STATUS;
}
int Request::save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
) {
@ -174,7 +221,7 @@ int Request::DB::SESSION::init( @@ -174,7 +221,7 @@ int Request::DB::SESSION::init(
int Request::DB::SESSION::clean(
sqlite3 * db,
const int & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
) {
char * error; // @TODO
sqlite3_stmt * statement;
@ -205,7 +252,7 @@ int Request::DB::SESSION::clean( @@ -205,7 +252,7 @@ int Request::DB::SESSION::clean(
R"SQL(
DELETE FROM `app_browser_main_tab_page_navigation_request__session` WHERE `id` = %d
)SQL",
sqlite3_column_int(
sqlite3_column_int64(
statement,
DB::SESSION::ID
)

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

@ -29,6 +29,7 @@ namespace app::browser::main::tab::page::navigation @@ -29,6 +29,7 @@ namespace app::browser::main::tab::page::navigation
enum
{
ID,
APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID,
TIME,
TEXT
}; // table fields index
@ -39,7 +40,7 @@ namespace app::browser::main::tab::page::navigation @@ -39,7 +40,7 @@ namespace app::browser::main::tab::page::navigation
static int clean(
sqlite3 * db,
const int & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
); // return sqlite3_finalize status code
static sqlite3_int64 add(
@ -95,6 +96,10 @@ namespace app::browser::main::tab::page::navigation @@ -95,6 +96,10 @@ namespace app::browser::main::tab::page::navigation
const double & PROGRESS_FRACTION
);
int restore(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
);
int save(
const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID
);

Loading…
Cancel
Save