Browse Source

update content container init by type

CPP-GTK4
yggverse 7 days ago
parent
commit
afa4261b0e
  1. 3
      src/app/browser/main/tab/page.cpp
  2. 70
      src/app/browser/main/tab/page/content.cpp
  3. 34
      src/app/browser/main/tab/page/content.hpp
  4. 53
      src/app/browser/main/tab/page/content/text.cpp
  5. 27
      src/app/browser/main/tab/page/content/text.hpp
  6. 3
      src/app/browser/main/tab/page/content/text/gemini.cpp
  7. 4
      src/app/browser/main/tab/page/content/text/gemini.hpp

3
src/app/browser/main/tab/page.cpp

@ -319,7 +319,8 @@ void Page::navigation_reload(
progress_fraction = 1; progress_fraction = 1;
// Set content driver // Set content driver
pageContent->set_text_gemini( // @TODO pageContent->update(
page::Content::MIME::TEXT_GEMINI,
buffer buffer
); );

70
src/app/browser/main/tab/page/content.cpp

@ -5,6 +5,7 @@ using namespace app::browser::main::tab::page;
Content::Content() Content::Content()
{ {
// Init widget
set_orientation( set_orientation(
Gtk::Orientation::VERTICAL Gtk::Orientation::VERTICAL
); );
@ -21,53 +22,56 @@ Content::Content()
true true
); );
widget = nullptr; // Init child types
contentText = nullptr;
} }
Content::~Content() Content::~Content()
{ {
delete widget; delete contentText;
}; }
// Public actions // Setters
void Content::set_text_gemini( void Content::update(
const Glib::ustring & GEMTEXT const MIME & MIME,
const Glib::ustring & DATA
) { ) {
auto contentText = new content::Text; // @TODO manage // Cleanup, free memory
if (contentText != nullptr)
{
remove(
* contentText
);
delete contentText;
contentText = nullptr;
} // @TODO other types..
contentText->set_gemini( // Create new content widget for MIME type requested
GEMTEXT switch (MIME)
{
case MIME::TEXT_GEMINI:
contentText = new content::Text(
content::Text::Type::GEMINI,
DATA
); );
set_widget( append(
contentText * contentText
); );
}
void Content::set_text_plain( break;
const Glib::ustring & TEXT
) {
// @TODO
}
// @TODO text_plain, picture, video, etc. case MIME::TEXT_PLAIN:
// Private helpers // @TODO
void Content::set_widget(
Gtk::Widget * object
) {
if (widget != nullptr)
{
remove(
* widget
);
delete widget; break;
}
widget = object; default:
append( throw _("Invalid content MIME type");
* widget }
);
} }

34
src/app/browser/main/tab/page/content.hpp

@ -7,26 +7,38 @@
namespace app::browser::main::tab::page namespace app::browser::main::tab::page
{ {
namespace content
{
class Text;
}
class Content : public Gtk::Box class Content : public Gtk::Box
{ {
Gtk::Widget * widget; /*
* Internal members
*/
private:
void set_widget( // Components
Gtk::Widget * object content::Text * contentText;
);
/*
* Class API
*/
public: public:
Content(); enum MIME
{
TEXT_GEMINI,
TEXT_PLAIN
};
Content();
~Content(); ~Content();
void set_text_gemini( void update(
const Glib::ustring & GEMTEXT const MIME & MIME,
); const Glib::ustring & DATA
void set_text_plain(
const Glib::ustring & TEXT
); );
}; };
} }

53
src/app/browser/main/tab/page/content/text.cpp

@ -4,36 +4,59 @@
using namespace app::browser::main::tab::page::content; using namespace app::browser::main::tab::page::content;
Text::Text() Text::Text(
{ const Type & TYPE,
// @TODO GtkViewport? const Glib::ustring & VALUE
}
void Text::set_gemini(
const Glib::ustring & GEMTEXT
) { ) {
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::H
NULL //Gtk::Adjustment::V NULL //Gtk::Adjustment::V
); ); // @TODO manage, optimize
viewport->set_scroll_to_focus( viewport->set_scroll_to_focus(
false false
); );
// Detect text driver by text type requested
switch (TYPE)
{
case GEMINI:
textGemini = new text::Gemini(
VALUE
);
viewport->set_child( viewport->set_child(
* new text::Gemini( // @TODO manage * textGemini
GEMTEXT
)
); );
break;
case PLAIN:
// @TODO
break;
default:
throw _("Invalid text type enum"); // @TODO
}
set_child( set_child(
* viewport * viewport
); );
} }
void Text::set_plain( Text::~Text()
const Glib::ustring & TEXT {
) { delete textGemini;
delete textPlain;
// @TODO // @TODO
} }

27
src/app/browser/main/tab/page/content/text.hpp

@ -1,26 +1,39 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_HPP
#include <glibmm/ustring.h>
//#include <gtkmm/adjustment.h> @TODO //#include <gtkmm/adjustment.h> @TODO
#include <glibmm/i18n.h>
#include <glibmm/ustring.h>
#include <gtkmm/scrolledwindow.h> #include <gtkmm/scrolledwindow.h>
#include <gtkmm/viewport.h> #include <gtkmm/viewport.h>
namespace app::browser::main::tab::page::content namespace app::browser::main::tab::page::content
{ {
namespace text
{
class Gemini;
class Plain;
}
class Text : public Gtk::ScrolledWindow class Text : public Gtk::ScrolledWindow
{ {
text::Gemini * textGemini;
text::Plain * textPlain;
public: public:
Text(); enum Type
{
GEMINI,
PLAIN
};
void set_gemini( Text(
const Glib::ustring & GEMTEXT const Type & TYPE,
const Glib::ustring & VALUE
); );
void set_plain( ~Text();
const Glib::ustring & TEXT
);
}; };
} }

3
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( Gemini::Gemini(
const Glib::ustring & GEMTEXT const Glib::ustring & GEMTEXT
) { ) {
// Init widget
set_valign( set_valign(
Gtk::Align::START Gtk::Align::START
); );
@ -22,6 +23,6 @@ Gemini::Gemini(
); );
set_markup( set_markup(
GEMTEXT // @TODO GEMTEXT//markup
); );
} }

4
src/app/browser/main/tab/page/content/text/gemini.hpp

@ -1,14 +1,16 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP #ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_TEXT_GEMINI_HPP
#include <glibmm/regex.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/enums.h>
#include <gtkmm/label.h> #include <gtkmm/label.h>
namespace app::browser::main::tab::page::content::text namespace app::browser::main::tab::page::content::text
{ {
class Gemini : public Gtk::Label class Gemini : public Gtk::Label
{ {
Glib::ustring markup;
public: public:
Gemini( Gemini(

Loading…
Cancel
Save