From 7e8aaef1c5ed02c04a3022e722ea3be925500808 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 10 Sep 2024 20:37:38 +0300 Subject: [PATCH] remake tab session api --- src/app/browser/main.cpp | 5 ++- src/app/browser/main/tab.cpp | 63 +++++++++++++++++-------------- src/app/browser/main/tab.hpp | 17 +++++---- src/app/browser/main/tab/page.cpp | 20 ++++++---- src/app/browser/main/tab/page.hpp | 48 ++++++++++++----------- 5 files changed, 87 insertions(+), 66 deletions(-) diff --git a/src/app/browser/main.cpp b/src/app/browser/main.cpp index faf81d7d..fa42ee27 100644 --- a/src/app/browser/main.cpp +++ b/src/app/browser/main.cpp @@ -47,8 +47,9 @@ void Main::refresh() void Main::tab_append() { - mainTab->set_current_page( - mainTab->append() + mainTab->append( + _("New tab"), + true ); }; diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 00d73815..b532c496 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -23,11 +23,11 @@ Tab::Tab( R"SQL( CREATE TABLE IF NOT EXISTS `app_browser_main_tab__session` ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `time` INTEGER NOT NULL, - `number` INTEGER NOT NULL, - `current` INTEGER NOT NULL, - `request` VARCHAR(1024) + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `time` INTEGER NOT NULL, + `page_number` INTEGER NOT NULL, + `is_current` INTEGER NOT NULL, + `label_text` VARCHAR(1024) ) )SQL", nullptr, @@ -73,7 +73,7 @@ int Tab::restore() const int PREPARE_STATUS = ::sqlite3_prepare_v3( this->db, R"SQL( - SELECT * FROM `app_browser_main_tab__session` ORDER BY `number` ASC + SELECT * FROM `app_browser_main_tab__session` ORDER BY `page_number` ASC )SQL", -1, SQLITE_PREPARE_NORMALIZE, @@ -87,25 +87,18 @@ int Tab::restore() while (::sqlite3_step(statement) == SQLITE_ROW) { - const int PAGE_NUMBER = append(); - - get_tabPage( - PAGE_NUMBER - )->set_navbar_request_text( + const int PAGE_NUMBER = append( reinterpret_cast( ::sqlite3_column_text( statement, - DB::APP_BROWSER_MAIN_TAB__SESSION::REQUEST + DB::APP_BROWSER_MAIN_TAB__SESSION::LABEL_TEXT ) - ) + ), + ::sqlite3_column_int( + statement, + DB::APP_BROWSER_MAIN_TAB__SESSION::IS_CURRENT + ) == 1 ); - - if (::sqlite3_column_int(statement, DB::APP_BROWSER_MAIN_TAB__SESSION::CURRENT) == 1) - { - set_current_page( - PAGE_NUMBER - ); - } } } @@ -136,7 +129,7 @@ int Tab::save() // Save current tab session for (int page_number = 0; page_number < get_n_pages(); page_number++) { - auto tabPage = get_tabPage( + auto tabLabel = get_tabLabel( page_number ); @@ -146,9 +139,9 @@ int Tab::save() R"SQL( INSERT INTO `app_browser_main_tab__session` ( `time`, - `number`, - `current`, - `request` + `page_number`, + `is_current`, + `label_text` ) VALUES ( CURRENT_TIMESTAMP, '%d', @@ -158,7 +151,7 @@ int Tab::save() )SQL", page_number, page_number == get_current_page() ? 1 : 0, - tabPage->get_navigation_request_text() + tabLabel->get_text() ).c_str(), nullptr, nullptr, @@ -195,16 +188,23 @@ void Tab::refresh( ); } -int Tab::append() -{ +int Tab::append( + const Glib::ustring & LABEL_TEXT, + const bool & IS_CURRENT +) { const auto TAB_PAGE = new tab::Page( + + tab::Page::MIME::UNDEFINED, + LABEL_TEXT, + "", // @TODO restore feature + action__refresh, action__tab_page_navigation_history_back, action__tab_page_navigation_history_forward, action__tab_page_navigation_update ); - const auto TAB_LABEL = new tab::Label( + const auto TAB_LABEL = new tab::Label( // @TODO managed action__tab_close_active ); @@ -218,6 +218,13 @@ int Tab::append() REORDERABLE ); + if (IS_CURRENT) + { + set_current_page( + PAGE_NUMBER + ); + } + refresh( PAGE_NUMBER ); diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index ef4c5439..eb47b2f4 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -27,9 +27,9 @@ namespace app::browser::main { ID, TIME, - NUMBER, - CURRENT, - REQUEST + PAGE_NUMBER, + IS_CURRENT, + LABEL_TEXT }; }; @@ -67,12 +67,11 @@ namespace app::browser::main ); // Actions - void refresh( - const int & PAGE_NUMBER + int append( + const Glib::ustring & LABEL_TEXT, + const bool & IS_CURRENT ); - int append(); - void close( const int & PAGE_NUMBER ); @@ -94,6 +93,10 @@ namespace app::browser::main const int & PAGE_NUMBER ); + void refresh( + const int & PAGE_NUMBER + ); + int restore(); int save(); diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 50f01fb2..e0097608 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -5,11 +5,20 @@ using namespace app::browser::main::tab; Page::Page( + const MIME & MIME, + const Glib::ustring & TITLE, + const Glib::ustring & DESCRIPTION, const Glib::RefPtr & ACTION__REFRESH, const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_BACK, const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD, const Glib::RefPtr & ACTION__PAGE_NAVIGATION_UPDATE ) { + // Init meta + mime = MIME; + title = TITLE; + description = DESCRIPTION; + progress_fraction = 0; + // Init actions action__refresh = ACTION__REFRESH; @@ -40,13 +49,8 @@ Page::Page( signal_realize().connect( [this] { - // Make initial data setup - update( - MIME::UNDEFINED, - _("New page"), - "", - 0 - ); + // Refresh parent window + action__refresh->activate(); } ); } @@ -60,7 +64,7 @@ void Page::refresh() } void Page::update( - const MIME & MIME, + const enum MIME & MIME, const Glib::ustring & TITLE, const Glib::ustring & DESCRIPTION, const double & PROGRESS_FRACTION diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 5afd7e82..bf9dc40d 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -25,36 +25,42 @@ namespace app::browser::main::tab class Page : public Gtk::Box { - // Extras - enum class MIME - { - TEXT_PLAIN, - TEXT_GEMINI, - UNDEFINED - }; + public: + + enum class MIME + { + TEXT_PLAIN, + TEXT_GEMINI, + UNDEFINED + }; - // Data - MIME mime; - Glib::ustring title; - Glib::ustring description; - double progress_fraction; + private: - // Actions - Glib::RefPtr action__refresh; + // Meta + MIME mime; + Glib::ustring title; + Glib::ustring description; + double progress_fraction; + + // Actions + Glib::RefPtr action__refresh; - // Socket - char buffer[0xfffff]; // 1Mb + // Socket + char buffer[0xfffff]; // 1Mb - Glib::RefPtr GioSocketClient; - Glib::RefPtr GioSocketConnection; + Glib::RefPtr GioSocketClient; + Glib::RefPtr GioSocketConnection; - // Components - page::Content * pageContent; - page::Navigation * pageNavigation; + // Components + page::Content * pageContent; + page::Navigation * pageNavigation; public: Page( + const MIME & MIME, + const Glib::ustring & TITLE, + const Glib::ustring & DESCRIPTION, const Glib::RefPtr & ACTION__REFRESH, const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_BACK, const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD,