From a73bb3aea6ae627033aa914735af40243d187ea2 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 18 Aug 2024 15:19:36 +0300 Subject: [PATCH] draft gemtext route --- Makefile | 1 + po/POTFILES.in | 1 + src/app/browser/main/tab/page.cpp | 28 ++++++++++++- src/app/browser/main/tab/page.hpp | 1 + src/app/browser/main/tab/page/content.cpp | 41 +++++++++++++++++-- src/app/browser/main/tab/page/content.hpp | 13 ++++-- .../main/tab/page/content/text/gemini.cpp | 21 ++++++++++ .../main/tab/page/content/text/gemini.hpp | 21 ++++++++++ 8 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 src/app/browser/main/tab/page/content/text/gemini.cpp create mode 100644 src/app/browser/main/tab/page/content/text/gemini.hpp diff --git a/Makefile b/Makefile index 612d823f..9d0df508 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ SRCS = src/main.cpp\ src/app/browser/main/tab.cpp\ src/app/browser/main/tab/page.cpp\ src/app/browser/main/tab/page/content.cpp\ + src/app/browser/main/tab/page/content/text/gemini.cpp\ src/app/browser/main/tab/page/navbar.cpp\ src/app/browser/main/tab/page/navbar/base.cpp\ src/app/browser/main/tab/page/navbar/bookmark.cpp\ diff --git a/po/POTFILES.in b/po/POTFILES.in index 4c542a98..f98f406d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -6,6 +6,7 @@ src/app/browser/main.cpp src/app/browser/main/tab.cpp src/app/browser/main/tab/page.cpp src/app/browser/main/tab/page/content.cpp +src/app/browser/main/tab/page/content/text/gemini.cpp src/app/browser/main/tab/page/navbar.cpp src/app/browser/main/tab/page/navbar/base.cpp src/app/browser/main/tab/page/navbar/bookmark.cpp diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index ac5108e1..4fb562db 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -96,15 +96,39 @@ void Page::update() [this](const Glib::RefPtr & result) { // Response - socket_connection->get_input_stream()->read_all_async( // | read_async + socket_connection->get_input_stream()->read_async( // | read_all_async buffer, sizeof(buffer) - 1, [this](const Glib::RefPtr & result) { - content->set( + // Parse meta + auto meta = Glib::Regex::split_simple( + R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex", buffer ); + // Route by status code + if (meta[1] == "20") + { + // Route by mime type + if (meta[2] == "text/gemini") + { + content->text_gemini( + buffer // @TODO + ); + } + + else + { + // @TODO exception + } + } + + else + { + // @TODO exception + } + socket_connection->close(); } ); diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 206abb87..97981838 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/src/app/browser/main/tab/page/content.cpp b/src/app/browser/main/tab/page/content.cpp index a1e4311e..c32458ff 100644 --- a/src/app/browser/main/tab/page/content.cpp +++ b/src/app/browser/main/tab/page/content.cpp @@ -1,4 +1,5 @@ #include "content.hpp" +#include "content/text/gemini.hpp" using namespace app::browser::main::tab::page; @@ -11,12 +12,44 @@ Content::Content() set_homogeneous( true ); + + widget = nullptr; } -Content::~Content() = default; +Content::~Content() +{ + delete widget; +}; -void Content::set( - const Glib::ustring & buffer +// Public actions +void Content::text_gemini( + const Glib::ustring & gemtext ) { - // @TODO + update( + new content::text::Gemini( + gemtext + ) + ); } + +// @TODO text_plain, picture, video, etc. + +// Private helpers +void Content::update( + Gtk::Widget * new_widget +) { + if (widget != nullptr) + { + remove( + * widget + ); + + delete widget; + } + + widget = new_widget; + + append( + * widget + ); +} \ 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 0df029ce..f79d1a7f 100644 --- a/src/app/browser/main/tab/page/content.hpp +++ b/src/app/browser/main/tab/page/content.hpp @@ -1,21 +1,28 @@ #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP -#include #include +#include +#include namespace app::browser::main::tab::page { class Content : public Gtk::Box { + Gtk::Widget * widget; + + void update( + Gtk::Widget * new_widget + ); + public: Content(); ~Content(); - void set( - const Glib::ustring & buffer + void text_gemini( + const Glib::ustring & gemtext ); }; } diff --git a/src/app/browser/main/tab/page/content/text/gemini.cpp b/src/app/browser/main/tab/page/content/text/gemini.cpp new file mode 100644 index 00000000..d1fe8e9f --- /dev/null +++ b/src/app/browser/main/tab/page/content/text/gemini.cpp @@ -0,0 +1,21 @@ +#include "gemini.hpp" + +using namespace app::browser::main::tab::page::content::text; + +Gemini::Gemini( + const Glib::ustring & gemtext +) { + set_wrap( + true + ); + + set_selectable( + true + ); + + set_markup( + gemtext // @TODO + ); +} + +Gemini::~Gemini() = default; \ 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 new file mode 100644 index 00000000..ccce9497 --- /dev/null +++ b/src/app/browser/main/tab/page/content/text/gemini.hpp @@ -0,0 +1,21 @@ +#ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP +#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP + +#include +#include + +namespace app::browser::main::tab::page::content::text +{ + class Gemini : public Gtk::Label + { + public: + + Gemini( + const Glib::ustring & gemtext + ); + + ~Gemini(); + }; +} + +#endif // APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP \ No newline at end of file