From 6b6ae753bc13b0d91422deb75abf7506508bd8ba Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 11 Sep 2024 04:15:55 +0300 Subject: [PATCH] implement restore feature for navbar request, change id data type to sqlite3_int64 --- src/app/browser/main/tab.cpp | 12 ++++- src/app/browser/main/tab/page.cpp | 47 ++++++++++++++++- src/app/browser/main/tab/page.hpp | 7 ++- src/app/browser/main/tab/page/navigation.cpp | 47 ++++++++++++++++- src/app/browser/main/tab/page/navigation.hpp | 7 ++- .../main/tab/page/navigation/request.cpp | 51 ++++++++++++++++++- .../main/tab/page/navigation/request.hpp | 7 ++- 7 files changed, 167 insertions(+), 11 deletions(-) diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 8eaac89d..466ce48e 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -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( { 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 ); diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 94eb4f72..6444610b 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -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( 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( { 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 ); diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 256c298a..a8cbbd2c 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -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 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 // 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 ); diff --git a/src/app/browser/main/tab/page/navigation.cpp b/src/app/browser/main/tab/page/navigation.cpp index 7833b49c..8299887f 100644 --- a/src/app/browser/main/tab/page/navigation.cpp +++ b/src/app/browser/main/tab/page/navigation.cpp @@ -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( 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( { 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 ); diff --git a/src/app/browser/main/tab/page/navigation.hpp b/src/app/browser/main/tab/page/navigation.hpp index e987f453..8af4f538 100644 --- a/src/app/browser/main/tab/page/navigation.hpp +++ b/src/app/browser/main/tab/page/navigation.hpp @@ -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 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 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 ); diff --git a/src/app/browser/main/tab/page/navigation/request.cpp b/src/app/browser/main/tab/page/navigation/request.cpp index 87a500e9..afcc6fa5 100644 --- a/src/app/browser/main/tab/page/navigation/request.cpp +++ b/src/app/browser/main/tab/page/navigation/request.cpp @@ -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( + 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( 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( 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 ) diff --git a/src/app/browser/main/tab/page/navigation/request.hpp b/src/app/browser/main/tab/page/navigation/request.hpp index b24b0eab..932665d7 100644 --- a/src/app/browser/main/tab/page/navigation/request.hpp +++ b/src/app/browser/main/tab/page/navigation/request.hpp @@ -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 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 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 );