diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index ed257ac4..d9da0e71 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -71,7 +71,7 @@ int Tab::restore() sqlite3_stmt* statement; const int PREPARE_STATUS = ::sqlite3_prepare_v3( - this->db, + db, R"SQL( SELECT * FROM `app_browser_main_tab__session` ORDER BY `page_number` ASC )SQL", @@ -161,7 +161,11 @@ int Tab::save() // Delegate save action to the page component get_tabPage( page_number - )->save(); + )->save( + ::sqlite3_last_insert_rowid( + db + ) + ); } } @@ -198,7 +202,7 @@ int Tab::append( const bool & IS_CURRENT ) { const auto TAB_PAGE = new tab::Page( - + db, tab::Page::MIME::UNDEFINED, LABEL_TEXT, "", // @TODO restore feature diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 380858f8..024a6517 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -5,6 +5,7 @@ using namespace app::browser::main::tab; Page::Page( + sqlite3 * db, const MIME & MIME, const Glib::ustring & TITLE, const Glib::ustring & DESCRIPTION, @@ -22,6 +23,28 @@ Page::Page( // Init actions action__refresh = ACTION__REFRESH; + // Init database + this->db = db; + + char * error; + + ::sqlite3_exec( + db, + R"SQL( + CREATE TABLE IF NOT EXISTS `app_browser_main_tab_page__session` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_main_tab__session_id` INTEGER NOT NULL, + `time` INTEGER NOT NULL, + `mime` INTEGER NOT NULL, + `title` VARCHAR(1024) NOT NULL, + `description` VARCHAR(1024) NOT NULL + ) + )SQL", + nullptr, + nullptr, + &error + ); + // Init components pageNavigation = Gtk::make_managed( ACTION__REFRESH, @@ -63,9 +86,46 @@ void Page::refresh() ); } -int Page::save() -{ - pageNavigation->save(); +int Page::save( + const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB__SESSION_ID +) { + char * error; // @TODO + + ::sqlite3_exec( + db, + Glib::ustring::sprintf( + R"SQL( + INSERT INTO `app_browser_main_tab_page__session` ( + `app_browser_main_tab__session_id`, + `time`, + `mime`, + `title`, + `description` + ) VALUES ( + '%d', + CURRENT_TIMESTAMP, + '%d', + '%d', + '%s', + '%s' + ) + )SQL", + DB__APP_BROWSER_MAIN_TAB__SESSION_ID, + mime, + title, + description + ).c_str(), + nullptr, + nullptr, + &error + ); // @TODO auto-clean old records somewhere + + // Delegate save action to child components + pageNavigation->save( + ::sqlite3_last_insert_rowid( + db + ) + ); return 1; // @TODO SQL } diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 94294ac7..510341ea 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace app::browser::main::tab { @@ -45,6 +46,21 @@ namespace app::browser::main::tab // Actions Glib::RefPtr action__refresh; + // Database + sqlite3 * db; + + struct DB + { + enum APP_BROWSER_MAIN_TAB_PAGE__DATA + { + ID, + TIME, + MIME, + TITLE, + DESCRIPTION + }; + }; + // Socket char buffer[0xfffff]; // 1Mb @@ -58,6 +74,7 @@ namespace app::browser::main::tab public: Page( + sqlite3 * db, const MIME & MIME, const Glib::ustring & TITLE, const Glib::ustring & DESCRIPTION, @@ -70,7 +87,9 @@ namespace app::browser::main::tab // Actions void refresh(); - int save(); + int save( + const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB__SESSION_ID + ); void update( const MIME & MIME, diff --git a/src/app/browser/main/tab/page/navigation.cpp b/src/app/browser/main/tab/page/navigation.cpp index 0b7cf91f..853259c5 100644 --- a/src/app/browser/main/tab/page/navigation.cpp +++ b/src/app/browser/main/tab/page/navigation.cpp @@ -101,8 +101,9 @@ void Navigation::refresh( ); } -int Navigation::save() -{ +int Navigation::save( + const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB_PAGE__SESSION_ID +) { navigationRequest->save(); return 1; // @TODO SQL diff --git a/src/app/browser/main/tab/page/navigation.hpp b/src/app/browser/main/tab/page/navigation.hpp index 9c4bd193..5833c22f 100644 --- a/src/app/browser/main/tab/page/navigation.hpp +++ b/src/app/browser/main/tab/page/navigation.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace app::browser::main::tab::page { @@ -45,7 +46,9 @@ namespace app::browser::main::tab::page const double & PROGRESS_FRACTION ); - int save(); + int save( + const sqlite3_int64 & DB__APP_BROWSER_MAIN_TAB__SESSION_ID + ); void history_add( const Glib::ustring & REQUEST,