Browse Source

update variables namespace

CPP-GTK4
yggverse 3 months ago
parent
commit
360b5e5f08
  1. 90
      src/app/browser/main/tab/page.cpp
  2. 13
      src/app/browser/main/tab/page.hpp

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

@ -14,10 +14,10 @@ Page::Page(
); );
// Init actions group // Init actions group
action_group = Gio::SimpleActionGroup::create(); auto GioSimpleActionGroup_RefPtr = Gio::SimpleActionGroup::create();
// Define group actions // Define group actions
action_group->add_action( GioSimpleActionGroup_RefPtr->add_action(
"update", "update",
[this] [this]
{ {
@ -27,106 +27,106 @@ Page::Page(
insert_action_group( insert_action_group(
"page", "page",
action_group GioSimpleActionGroup_RefPtr
); );
// Init components // Init components
navbar = new page::Navbar( pageNavbar = new page::Navbar(
navbar_request_text navbar_request_text
); );
append( append(
* navbar * pageNavbar
); );
// Refresh children elements view (e.g. buttons sensitivity) // Refresh children elements view (e.g. buttons sensitivity)
// because of insert_action_group + append here @TODO // because of insert_action_group + append here @TODO
navbar->refresh(); pageNavbar->refresh();
progressbar = new page::Progressbar(); pageProgressbar = new page::Progressbar();
append( append(
* progressbar * pageProgressbar
); );
content = new page::Content(); pageContent = new page::Content();
append( append(
* content * pageContent
); );
} }
Page::~Page() Page::~Page()
{ {
delete navbar; delete pageNavbar;
delete content; delete pageContent;
delete progressbar; delete pageProgressbar;
} }
void Page::update() void Page::update()
{ {
// Reset progress // Reset progress
progressbar->set( pageProgressbar->set(
0 0
); );
// Connect scheme driver // Connect scheme driver
if ("file" == navbar->get_request_scheme()) if ("file" == pageNavbar->get_request_scheme())
{ {
// @TODO // @TODO
} }
else if ("gemini" == navbar->get_request_scheme()) else if ("gemini" == pageNavbar->get_request_scheme())
{ {
// Create new socket connection // Create new socket connection
socket_client = Gio::SocketClient::create(); GioSocketClient_RefPtr = Gio::SocketClient::create();
socket_client->set_tls( GioSocketClient_RefPtr->set_tls(
true true
); );
socket_client->set_tls_validation_flags( GioSocketClient_RefPtr->set_tls_validation_flags(
Gio::TlsCertificateFlags::NO_FLAGS Gio::TlsCertificateFlags::NO_FLAGS
); );
socket_client->set_timeout( GioSocketClient_RefPtr->set_timeout(
15 // @TODO 15 // @TODO
); );
socket_client->connect_to_host_async( GioSocketClient_RefPtr->connect_to_host_async(
navbar->get_request_host(), pageNavbar->get_request_host(),
navbar->get_request_port().empty() ? 1965 : std::stoi( pageNavbar->get_request_port().empty() ? 1965 : std::stoi(
navbar->get_request_port() pageNavbar->get_request_port()
), ),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set( pageProgressbar->set(
.25 .25
); );
socket_connection = socket_client->connect_to_host_finish( GioSocketConnection_RefPtr = GioSocketClient_RefPtr->connect_to_host_finish(
result result
); );
// Request // Request
const Glib::ustring navbar_request_text = navbar->get_request_text() + "\r\n"; const Glib::ustring navbar_request_text = pageNavbar->get_request_text() + "\r\n";
socket_connection->get_output_stream()->write_async( GioSocketConnection_RefPtr->get_output_stream()->write_async(
navbar_request_text.data(), navbar_request_text.data(),
navbar_request_text.size(), navbar_request_text.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set( pageProgressbar->set(
.5 .5
); );
// Response // Response
socket_connection->get_input_stream()->read_async( // | read_all_async GioSocketConnection_RefPtr->get_input_stream()->read_async( // | read_all_async
buffer, buffer,
sizeof(buffer) - 1, sizeof(buffer) - 1,
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
progressbar->set( pageProgressbar->set(
.75 .75
); );
@ -140,16 +140,16 @@ void Page::update()
if (meta[1] == "20") if (meta[1] == "20")
{ {
// Route by mime type or path extension // Route by mime type or path extension
if (meta[2] == "text/gemini" || Glib::str_has_suffix(navbar->get_request_path(), ".gmi")) if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavbar->get_request_path(), ".gmi"))
{ {
content->set_text_gemini( pageContent->set_text_gemini(
buffer // @TODO buffer // @TODO
); );
} }
else else
{ {
content->set_text_plain( pageContent->set_text_plain(
_("MIME type not supported") _("MIME type not supported")
); );
} }
@ -157,14 +157,14 @@ void Page::update()
else else
{ {
content->set_text_plain( pageContent->set_text_plain(
_("Could not open page") _("Could not open page")
); );
} }
socket_connection->close(); GioSocketConnection_RefPtr->close();
progressbar->set( pageProgressbar->set(
1 1
); );
} }
@ -176,25 +176,25 @@ void Page::update()
} }
// Scheme not found but host provided, redirect to gemini:// // Scheme not found but host provided, redirect to gemini://
else if (!navbar->get_request_host().empty()) else if (!pageNavbar->get_request_host().empty())
{ {
Glib::ustring navbar_request_text = "gemini://"; Glib::ustring navbar_request_text = "gemini://";
navbar_request_text += navbar->get_request_host(); // @TODO validate navbar_request_text += pageNavbar->get_request_host(); // @TODO validate
if (!navbar->get_request_port().empty()) if (!pageNavbar->get_request_port().empty())
{ {
navbar_request_text += navbar->get_request_port(); navbar_request_text += pageNavbar->get_request_port();
} }
navbar_request_text += navbar->get_request_path(); navbar_request_text += pageNavbar->get_request_path();
if (!navbar->get_request_query().empty()) if (!pageNavbar->get_request_query().empty())
{ {
navbar_request_text += "?" + navbar->get_request_query(); navbar_request_text += "?" + pageNavbar->get_request_query();
} }
navbar->set_request_text( pageNavbar->set_request_text(
navbar_request_text navbar_request_text
); );

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

@ -25,15 +25,14 @@ namespace app::browser::main::tab
class Page : public Gtk::Box class Page : public Gtk::Box
{ {
char buffer[0xfffff]; char buffer[0xfffff]; // 1Mb
Glib::RefPtr<Gio::SimpleActionGroup> action_group; Glib::RefPtr<Gio::SocketClient> GioSocketClient_RefPtr;
Glib::RefPtr<Gio::SocketClient> socket_client; Glib::RefPtr<Gio::SocketConnection> GioSocketConnection_RefPtr;
Glib::RefPtr<Gio::SocketConnection> socket_connection;
page::Content * content; page::Content * pageContent;
page::Navbar * navbar; page::Navbar * pageNavbar;
page::Progressbar * progressbar; page::Progressbar * pageProgressbar;
public: public:

Loading…
Cancel
Save