Browse Source

draft gemtext route

CPP-GTK4
yggverse 4 months ago
parent
commit
a73bb3aea6
  1. 1
      Makefile
  2. 1
      po/POTFILES.in
  3. 28
      src/app/browser/main/tab/page.cpp
  4. 1
      src/app/browser/main/tab/page.hpp
  5. 41
      src/app/browser/main/tab/page/content.cpp
  6. 13
      src/app/browser/main/tab/page/content.hpp
  7. 21
      src/app/browser/main/tab/page/content/text/gemini.cpp
  8. 21
      src/app/browser/main/tab/page/content/text/gemini.hpp

1
Makefile

@ -14,6 +14,7 @@ SRCS = src/main.cpp\ @@ -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\

1
po/POTFILES.in

@ -6,6 +6,7 @@ src/app/browser/main.cpp @@ -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

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

@ -96,15 +96,39 @@ void Page::update() @@ -96,15 +96,39 @@ void Page::update()
[this](const Glib::RefPtr<Gio::AsyncResult> & 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<Gio::AsyncResult> & 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();
}
);

1
src/app/browser/main/tab/page.hpp

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
#include <giomm/socketclient.h>
#include <giomm/socketconnection.h>
#include <glibmm/refptr.h>
#include <glibmm/regex.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>

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

@ -1,4 +1,5 @@ @@ -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() @@ -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
);
}

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

@ -1,21 +1,28 @@ @@ -1,21 +1,28 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#include <gtkmm/box.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <gtkmm/widget.h>
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
);
};
}

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

@ -0,0 +1,21 @@ @@ -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;

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

@ -0,0 +1,21 @@ @@ -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 <glibmm/ustring.h>
#include <gtkmm/label.h>
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
Loading…
Cancel
Save