From f31dc84fe6bc23eb76cfc0a2d86eec6c4e36bcc9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 14 Sep 2024 09:33:25 +0300 Subject: [PATCH] implement title detection by content type provider --- src/app/browser/main/tab/page.cpp | 6 ++++++ src/app/browser/main/tab/page/content.cpp | 10 ++++++++++ src/app/browser/main/tab/page/content.hpp | 9 ++++++++- src/app/browser/main/tab/page/content/text.cpp | 9 ++++++++- src/app/browser/main/tab/page/content/text.hpp | 14 ++++++++++++++ .../browser/main/tab/page/content/text/gemini.cpp | 15 +++++++++++---- .../browser/main/tab/page/content/text/gemini.hpp | 6 +++++- .../main/tab/page/content/text/gemini/reader.cpp | 11 +++++++++++ .../main/tab/page/content/text/gemini/reader.hpp | 12 ++++++++++-- 9 files changed, 83 insertions(+), 9 deletions(-) diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index af8ae80d..d8b91714 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -316,6 +316,12 @@ void Page::navigation_reload( buffer ); + // Update title on detected by document provider + if (!pageContent->get_title().empty()) + { + title = pageContent->get_title(); + } + action__update->activate(); } diff --git a/src/app/browser/main/tab/page/content.cpp b/src/app/browser/main/tab/page/content.cpp index ff21c332..ac8938fc 100644 --- a/src/app/browser/main/tab/page/content.cpp +++ b/src/app/browser/main/tab/page/content.cpp @@ -31,6 +31,12 @@ Content::~Content() delete contentText; } +// Getters +Glib::ustring Content::get_title() +{ + return title; +} + // Setters void Content::update( const MIME & MIME, @@ -39,6 +45,8 @@ void Content::update( // Cleanup, free memory if (contentText != nullptr) { + title.clear(); + remove( * contentText ); @@ -58,6 +66,8 @@ void Content::update( DATA ); + title = contentText->get_title(); + append( * contentText ); diff --git a/src/app/browser/main/tab/page/content.hpp b/src/app/browser/main/tab/page/content.hpp index b3f4ae46..9294b37a 100644 --- a/src/app/browser/main/tab/page/content.hpp +++ b/src/app/browser/main/tab/page/content.hpp @@ -22,8 +22,11 @@ namespace app::browser::main::tab::page // Components content::Text * contentText; + // Extra features + Glib::ustring title; + /* - * Class API + * Content class API */ public: @@ -36,10 +39,14 @@ namespace app::browser::main::tab::page Content(); ~Content(); + // Actions void update( const MIME & MIME, const Glib::ustring & DATA ); + + // Getters + Glib::ustring get_title(); }; } diff --git a/src/app/browser/main/tab/page/content/text.cpp b/src/app/browser/main/tab/page/content/text.cpp index 25bfd1cf..0b8c66db 100644 --- a/src/app/browser/main/tab/page/content/text.cpp +++ b/src/app/browser/main/tab/page/content/text.cpp @@ -14,7 +14,8 @@ Text::Text( set_child( * Gtk::make_managed( - TEXT + TEXT, + title ) ); @@ -34,4 +35,10 @@ Text::Text( throw _("Invalid text type enum"); // @TODO } +} + +// Getters +Glib::ustring Text::get_title() +{ + return title; } \ No newline at end of file diff --git a/src/app/browser/main/tab/page/content/text.hpp b/src/app/browser/main/tab/page/content/text.hpp index 972f7ed2..667ca6dd 100644 --- a/src/app/browser/main/tab/page/content/text.hpp +++ b/src/app/browser/main/tab/page/content/text.hpp @@ -9,18 +9,32 @@ namespace app::browser::main::tab::page::content { class Text : public Gtk::ScrolledWindow { + /* + * Private members + */ + Glib::ustring title; + public: + /* + * Extra features + */ enum Type { GEMINI, PLAIN }; + /* + * Text class API + */ Text( const Type & TYPE, const Glib::ustring & TEXT ); + + // Getters + Glib::ustring get_title(); }; } diff --git a/src/app/browser/main/tab/page/content/text/gemini.cpp b/src/app/browser/main/tab/page/content/text/gemini.cpp index e179c21a..ffdfda7f 100644 --- a/src/app/browser/main/tab/page/content/text/gemini.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini.cpp @@ -4,19 +4,26 @@ using namespace app::browser::main::tab::page::content::text; Gemini::Gemini( - const Glib::ustring & GEMTEXT + const Glib::ustring & GEMTEXT, + Glib::ustring & title ) : Gtk::Viewport( // add scrolled window features to childs NULL, NULL ) { + // Init components + auto geminiReader = Gtk::make_managed( + GEMTEXT + ); + + // Grab title + title = geminiReader->get_title(); + // Init widget set_scroll_to_focus( false ); set_child( - * Gtk::make_managed( - GEMTEXT - ) + * geminiReader ); } \ No newline at end of file diff --git a/src/app/browser/main/tab/page/content/text/gemini.hpp b/src/app/browser/main/tab/page/content/text/gemini.hpp index b908de89..4cc0a5f4 100644 --- a/src/app/browser/main/tab/page/content/text/gemini.hpp +++ b/src/app/browser/main/tab/page/content/text/gemini.hpp @@ -8,10 +8,14 @@ namespace app::browser::main::tab::page::content::text { class Gemini : public Gtk::Viewport { + /* + * Gemini class API + */ public: Gemini( - const Glib::ustring & GEMTEXT + const Glib::ustring & GEMTEXT, + Glib::ustring & title ); }; } diff --git a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp index 07849ace..4c28b7de 100644 --- a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp @@ -52,6 +52,12 @@ Reader::Reader( ); } +// Getters +Glib::ustring Reader::get_title() +{ + return title; +} + // Match tools bool Reader::Line::Match::header( const Glib::ustring & GEMTEXT, @@ -152,6 +158,11 @@ Glib::ustring Reader::make( ) ); + if (title.empty()) + { + title = header; + } + continue; } diff --git a/src/app/browser/main/tab/page/content/text/gemini/reader.hpp b/src/app/browser/main/tab/page/content/text/gemini/reader.hpp index a24addef..b826bed5 100644 --- a/src/app/browser/main/tab/page/content/text/gemini/reader.hpp +++ b/src/app/browser/main/tab/page/content/text/gemini/reader.hpp @@ -62,18 +62,26 @@ namespace app::browser::main::tab::page::content::text::gemini ); }; - static Glib::ustring make( + Glib::ustring make( const Glib::ustring & GEMTEXT ); /* - * Gemini class API + * Private members + */ + Glib::ustring title; + + /* + * Reader class API */ public: Reader( const Glib::ustring & GEMTEXT ); + + // Getters + Glib::ustring get_title(); }; }