From 30e3ae691a99b71b29a782d4f37ac7e3957f093c Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 18 Aug 2024 15:32:31 +0300 Subject: [PATCH] add text/plain content support --- Makefile | 1 + po/POTFILES.in | 1 + src/app/browser/main/tab/page.cpp | 8 +++++-- src/app/browser/main/tab/page.hpp | 1 + src/app/browser/main/tab/page/content.cpp | 11 ++++++++++ src/app/browser/main/tab/page/content.hpp | 4 ++++ .../main/tab/page/content/text/plain.cpp | 21 +++++++++++++++++++ .../main/tab/page/content/text/plain.hpp | 21 +++++++++++++++++++ 8 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/app/browser/main/tab/page/content/text/plain.cpp create mode 100644 src/app/browser/main/tab/page/content/text/plain.hpp diff --git a/Makefile b/Makefile index 9d0df50..9dea0e9 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ SRCS = src/main.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/content/text/plain.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 f98f406..ad4e0c2 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,6 +7,7 @@ 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/content/text/plain.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 4fb562d..8b72e22 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -120,13 +120,17 @@ void Page::update() else { - // @TODO exception + content->text_plain( + _("MIME type not supported") + ); } } else { - // @TODO exception + content->text_plain( + _("Could not open page") + ); } socket_connection->close(); diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 9798183..7b085ee 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -7,6 +7,7 @@ #include #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 c32458f..baab354 100644 --- a/src/app/browser/main/tab/page/content.cpp +++ b/src/app/browser/main/tab/page/content.cpp @@ -1,5 +1,6 @@ #include "content.hpp" #include "content/text/gemini.hpp" +#include "content/text/plain.hpp" using namespace app::browser::main::tab::page; @@ -32,6 +33,16 @@ void Content::text_gemini( ); } +void Content::text_plain( + const Glib::ustring & text +) { + update( + new content::text::Plain( + text + ) + ); +} + // @TODO text_plain, picture, video, etc. // Private helpers diff --git a/src/app/browser/main/tab/page/content.hpp b/src/app/browser/main/tab/page/content.hpp index f79d1a7..6560e8c 100644 --- a/src/app/browser/main/tab/page/content.hpp +++ b/src/app/browser/main/tab/page/content.hpp @@ -24,6 +24,10 @@ namespace app::browser::main::tab::page void text_gemini( const Glib::ustring & gemtext ); + + void text_plain( + const Glib::ustring & text + ); }; } diff --git a/src/app/browser/main/tab/page/content/text/plain.cpp b/src/app/browser/main/tab/page/content/text/plain.cpp new file mode 100644 index 0000000..480eaa4 --- /dev/null +++ b/src/app/browser/main/tab/page/content/text/plain.cpp @@ -0,0 +1,21 @@ +#include "plain.hpp" + +using namespace app::browser::main::tab::page::content::text; + +Plain::Plain( + const Glib::ustring & text +) { + set_wrap( + true + ); + + set_selectable( + true + ); + + set_text( + text + ); +} + +Plain::~Plain() = default; \ No newline at end of file diff --git a/src/app/browser/main/tab/page/content/text/plain.hpp b/src/app/browser/main/tab/page/content/text/plain.hpp new file mode 100644 index 0000000..6209b05 --- /dev/null +++ b/src/app/browser/main/tab/page/content/text/plain.hpp @@ -0,0 +1,21 @@ +#ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_PLAIN_HPP +#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_PLAIN_HPP + +#include +#include + +namespace app::browser::main::tab::page::content::text +{ + class Plain : public Gtk::Label + { + public: + + Plain( + const Glib::ustring & text + ); + + ~Plain(); + }; +} + +#endif // APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_PLAIN_HPP \ No newline at end of file