From c74e9a81f069a51cfabee3313e510b54618b74b3 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 10 Sep 2024 07:43:44 +0300 Subject: [PATCH] add page mime type as refresh method argument --- src/app/browser/main/tab.cpp | 1 + src/app/browser/main/tab/page.cpp | 50 +++++++++++++++++++------------ src/app/browser/main/tab/page.hpp | 38 ++++++++++++----------- 3 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index 08315837..f1d83dae 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -185,6 +185,7 @@ void Tab::refresh( ); TAB_PAGE->refresh( + tab::Page::MIME::UNDEFINED, TAB_PAGE->get_title(), TAB_PAGE->get_subtitle(), 0 // @TODO diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 88299079..6152c509 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -10,11 +10,6 @@ Page::Page( const Glib::RefPtr & ACTION__PAGE_NAVIGATION_HISTORY_FORWARD, const Glib::RefPtr & ACTION__PAGE_NAVIGATION_UPDATE ) { - // Init extras - mime = MIME::UNDEFINED; - title = _("New page"); - subtitle = ""; - // Init components pageNavigation = Gtk::make_managed( ACTION__REFRESH, @@ -39,14 +34,16 @@ Page::Page( ); refresh( - title, - subtitle, + MIME::UNDEFINED, + _("New page"), + "", 0 ); } // Actions void Page::refresh( + const MIME & MIME, const Glib::ustring & TITLE, const Glib::ustring & SUBTITLE, const double & PROGRESS_FRACTION @@ -73,6 +70,7 @@ void Page::navigation_update( // Update page extras refresh( + MIME::UNDEFINED, pageNavigation->get_request_host(), Glib::ustring::sprintf( _("load %s.."), @@ -108,6 +106,7 @@ void Page::navigation_update( [this](const Glib::RefPtr & result) { refresh( + MIME::UNDEFINED, pageNavigation->get_request_host(), Glib::ustring::sprintf( _("connect %s.."), @@ -125,6 +124,7 @@ void Page::navigation_update( catch (const Glib::Error & EXCEPTION) { refresh( + MIME::UNDEFINED, pageNavigation->get_request_host(), EXCEPTION.what(), 1 ); @@ -141,6 +141,7 @@ void Page::navigation_update( [this](const Glib::RefPtr & result) { refresh( + MIME::UNDEFINED, pageNavigation->get_request_host(), Glib::ustring::sprintf( _("request %s.."), @@ -156,6 +157,7 @@ void Page::navigation_update( [this](const Glib::RefPtr & result) { refresh( + MIME::UNDEFINED, pageNavigation->get_request_host(), Glib::ustring::sprintf( _("reading %s.."), @@ -176,7 +178,13 @@ void Page::navigation_update( // Route by mime type or path extension if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavigation->get_request_path(), ".gmi")) { - mime = MIME::TEXT_GEMINI; + refresh( + MIME::TEXT_GEMINI, + pageNavigation->get_request_host(), // @TODO title + pageNavigation->get_request_path().empty() ? pageNavigation->get_request_host() + : pageNavigation->get_request_path() + , 1 + ); pageContent->set_text_gemini( buffer // @TODO @@ -185,10 +193,12 @@ void Page::navigation_update( else { - mime = MIME::UNDEFINED; - - title = _("Oops"); - subtitle = _("MIME type not supported"); + refresh( + MIME::UNDEFINED, + _("Oops"), + _("MIME type not supported") + , 1 + ); pageContent->set_text_plain( // @TODO subtitle @@ -198,13 +208,14 @@ void Page::navigation_update( else { - mime = MIME::UNDEFINED; - - title = _("Oops"); - - subtitle = Glib::ustring::sprintf( - _("Response code %s not supported"), - meta[1] + refresh( + MIME::UNDEFINED, + _("Oops"), + Glib::ustring::sprintf( + _("Response code %s not supported"), + meta[1] + ) + , 1 ); pageContent->set_text_plain( // @TODO @@ -215,6 +226,7 @@ void Page::navigation_update( GioSocketConnection->close(); refresh( + MIME::UNDEFINED, pageNavigation->get_request_host(), // @TODO title pageNavigation->get_request_path().empty() ? pageNavigation->get_request_host() : pageNavigation->get_request_path() diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 8a87aa3e..7b3ce09f 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -25,27 +25,30 @@ 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 + }; + + private: - MIME mime; - Glib::ustring title; - Glib::ustring subtitle; + MIME mime; + Glib::ustring title; + Glib::ustring subtitle; - // 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: @@ -58,6 +61,7 @@ namespace app::browser::main::tab // Actions void refresh( + const MIME & MIME, const Glib::ustring & TITLE, const Glib::ustring & SUBTITLE, const double & PROGRESS_FRACTION