From eaa4b78dbd6f9c54cc44ca4f1b01966d8f689b26 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 9 Sep 2024 11:08:00 +0300 Subject: [PATCH] restore previous tab session on browser launch --- src/app/browser/main.cpp | 3 +++ src/app/browser/main/tab.cpp | 42 +++++++++++++++++++++++++++++++++--- src/app/browser/main/tab.hpp | 11 ++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index a4a1673..13127eb 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -47,7 +47,10 @@ void Main::refresh() void Main::tab_append() { + const unsigned char * REQUEST; // @TODO + mainTab->append( + REQUEST, true ); }; diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 6dd8fa8..9a1db64 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -46,7 +46,44 @@ Tab::Tab( SCROLLABLE ); - // Init event listeners + // Init events + signal_realize().connect( + [this] + { + // Restore session from DB + sqlite3_stmt* statement; + + int prepare = sqlite3_prepare_v3( + this->db, + R"SQL( + SELECT * FROM `app_browser_main_tab` + )SQL", + -1, + SQLITE_PREPARE_NORMALIZE, + &statement, + nullptr + ); + + if (prepare == SQLITE_OK) + { + while (sqlite3_step(statement) == SQLITE_ROW) + { + append( + sqlite3_column_text( + statement, + DB::APP_BROWSER_MAIN_TAB::REQUEST + ), + true + ); + } + } + + sqlite3_finalize( + statement + ); + } + ); + signal_switch_page().connect( [this](Gtk::Widget*, guint) { @@ -54,8 +91,6 @@ Tab::Tab( action__refresh->activate(); } ); - - // @TODO restore session from DB } void Tab::shutdown() @@ -133,6 +168,7 @@ void Tab::refresh( } void Tab::append( + const unsigned char * REQUEST, const bool & FOCUS ) { auto tabPage = new tab::Page( diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index 4fcd9e0..2d52f1c 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -21,6 +21,16 @@ namespace app::browser::main // Database sqlite3 * db; + struct DB + { + enum APP_BROWSER_MAIN_TAB + { + ID, + TIME, + REQUEST, + }; + }; + // Actions Glib::RefPtr action__refresh, action__tab_close_active, @@ -60,6 +70,7 @@ namespace app::browser::main ); void append( + const unsigned char * REQUEST, const bool & FOCUS );