diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index f2397a0..a0916f0 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -319,7 +319,8 @@ void Page::navigation_reload( progress_fraction = 1; // Set content driver - pageContent->set_text_gemini( // @TODO + pageContent->update( + page::Content::MIME::TEXT_GEMINI, buffer ); diff --git a/src/app/browser/main/tab/page/content.cpp b/src/app/browser/main/tab/page/content.cpp index 0537755..93e8d3b 100644 --- a/src/app/browser/main/tab/page/content.cpp +++ b/src/app/browser/main/tab/page/content.cpp @@ -5,6 +5,7 @@ using namespace app::browser::main::tab::page; Content::Content() { + // Init widget set_orientation( Gtk::Orientation::VERTICAL ); @@ -21,53 +22,56 @@ Content::Content() true ); - widget = nullptr; + // Init child types + contentText = nullptr; } Content::~Content() { - delete widget; -}; + delete contentText; +} -// Public actions -void Content::set_text_gemini( - const Glib::ustring & GEMTEXT +// Setters +void Content::update( + const MIME & MIME, + const Glib::ustring & DATA ) { - auto contentText = new content::Text; // @TODO manage + // Cleanup, free memory + if (contentText != nullptr) + { + remove( + * contentText + ); - contentText->set_gemini( - GEMTEXT - ); + delete contentText; - set_widget( - contentText - ); -} + contentText = nullptr; + } // @TODO other types.. -void Content::set_text_plain( - const Glib::ustring & TEXT -) { - // @TODO -} + // Create new content widget for MIME type requested + switch (MIME) + { + case MIME::TEXT_GEMINI: -// @TODO text_plain, picture, video, etc. + contentText = new content::Text( + content::Text::Type::GEMINI, + DATA + ); -// Private helpers -void Content::set_widget( - Gtk::Widget * object -) { - if (widget != nullptr) - { - remove( - * widget - ); + append( + * contentText + ); - delete widget; - } + break; - widget = object; + case MIME::TEXT_PLAIN: - append( - * widget - ); + // @TODO + + break; + + default: + + throw _("Invalid content MIME type"); + } } \ No newline at end of file diff --git a/src/app/browser/main/tab/page/content.hpp b/src/app/browser/main/tab/page/content.hpp index a6c50ad..a50409c 100644 --- a/src/app/browser/main/tab/page/content.hpp +++ b/src/app/browser/main/tab/page/content.hpp @@ -7,26 +7,38 @@ namespace app::browser::main::tab::page { + namespace content + { + class Text; + } + class Content : public Gtk::Box { - Gtk::Widget * widget; + /* + * Internal members + */ + private: - void set_widget( - Gtk::Widget * object - ); + // Components + content::Text * contentText; + /* + * Class API + */ public: - Content(); + enum MIME + { + TEXT_GEMINI, + TEXT_PLAIN + }; + Content(); ~Content(); - void set_text_gemini( - const Glib::ustring & GEMTEXT - ); - - void set_text_plain( - const Glib::ustring & TEXT + void update( + const MIME & MIME, + const Glib::ustring & DATA ); }; } diff --git a/src/app/browser/main/tab/page/content/text.cpp b/src/app/browser/main/tab/page/content/text.cpp index 66dae9e..82fc9b8 100644 --- a/src/app/browser/main/tab/page/content/text.cpp +++ b/src/app/browser/main/tab/page/content/text.cpp @@ -4,36 +4,59 @@ using namespace app::browser::main::tab::page::content; -Text::Text() -{ - // @TODO GtkViewport? -} - -void Text::set_gemini( - const Glib::ustring & GEMTEXT +Text::Text( + const Type & TYPE, + const Glib::ustring & VALUE ) { - auto viewport = new Gtk::Viewport( // @TODO + // Init components + textGemini = nullptr; + textPlain = nullptr; + + // GtkLabel does not support ScrolledWindow features, create GtkViewport + auto viewport = new Gtk::Viewport( // @TODO manage NULL, //Gtk::Adjustment::H NULL //Gtk::Adjustment::V - ); + ); // @TODO manage, optimize viewport->set_scroll_to_focus( false ); - viewport->set_child( - * new text::Gemini( // @TODO manage - GEMTEXT - ) - ); + // Detect text driver by text type requested + switch (TYPE) + { + case GEMINI: + + textGemini = new text::Gemini( + VALUE + ); + + viewport->set_child( + * textGemini + ); + + break; + + case PLAIN: + + // @TODO + + break; + + default: + + throw _("Invalid text type enum"); // @TODO + } set_child( * viewport ); } -void Text::set_plain( - const Glib::ustring & TEXT -) { +Text::~Text() +{ + delete textGemini; + delete textPlain; + // @TODO } \ 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 7d9288f..1d0c3bf 100644 --- a/src/app/browser/main/tab/page/content/text.hpp +++ b/src/app/browser/main/tab/page/content/text.hpp @@ -1,26 +1,39 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP -#include //#include @TODO +#include +#include #include #include namespace app::browser::main::tab::page::content { + namespace text + { + class Gemini; + class Plain; + } + class Text : public Gtk::ScrolledWindow { + text::Gemini * textGemini; + text::Plain * textPlain; + public: - Text(); + enum Type + { + GEMINI, + PLAIN + }; - void set_gemini( - const Glib::ustring & GEMTEXT + Text( + const Type & TYPE, + const Glib::ustring & VALUE ); - void set_plain( - const Glib::ustring & TEXT - ); + ~Text(); }; } 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 b38f091..d5572f7 100644 --- a/src/app/browser/main/tab/page/content/text/gemini.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini.cpp @@ -5,6 +5,7 @@ using namespace app::browser::main::tab::page::content::text; Gemini::Gemini( const Glib::ustring & GEMTEXT ) { + // Init widget set_valign( Gtk::Align::START ); @@ -22,6 +23,6 @@ Gemini::Gemini( ); set_markup( - GEMTEXT // @TODO + GEMTEXT//markup ); } \ 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 8b8e765..e317888 100644 --- a/src/app/browser/main/tab/page/content/text/gemini.hpp +++ b/src/app/browser/main/tab/page/content/text/gemini.hpp @@ -1,14 +1,16 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP +#include #include -#include #include namespace app::browser::main::tab::page::content::text { class Gemini : public Gtk::Label { + Glib::ustring markup; + public: Gemini(