Browse Source

update content container init by type

CPP-GTK4
yggverse 2 months ago
parent
commit
afa4261b0e
  1. 3
      src/app/browser/main/tab/page.cpp
  2. 74
      src/app/browser/main/tab/page/content.cpp
  3. 34
      src/app/browser/main/tab/page/content.hpp
  4. 57
      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( @@ -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
);

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

@ -5,6 +5,7 @@ using namespace app::browser::main::tab::page; @@ -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() @@ -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");
}
}

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

@ -7,26 +7,38 @@ @@ -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
);
};
}

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

@ -4,36 +4,59 @@ @@ -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
}

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

@ -1,26 +1,39 @@ @@ -1,26 +1,39 @@
#ifndef 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 <glibmm/i18n.h>
#include <glibmm/ustring.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/viewport.h>
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();
};
}

3
src/app/browser/main/tab/page/content/text/gemini.cpp

@ -5,6 +5,7 @@ using namespace app::browser::main::tab::page::content::text; @@ -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( @@ -22,6 +23,6 @@ Gemini::Gemini(
);
set_markup(
GEMTEXT // @TODO
GEMTEXT//markup
);
}

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

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

Loading…
Cancel
Save