From de312cdcb0e63de3411057d75160fb8d06e37e9f Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 16 Aug 2024 10:00:23 +0300 Subject: [PATCH] draft gio socket connector --- src/app/browser/main/tab/page.cpp | 62 ++++++++++++++++++++++++++++++- src/app/browser/main/tab/page.hpp | 10 +++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 9e3a7fa0..477edf4b 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -48,8 +48,66 @@ Page::Page() Page::~Page() = default; -// Actions +// Public actions void Page::update() { - // navbar->get_request_value() @TODO + // Route by request protocol + if ("file" == navbar->get_request_scheme()) + { + // @TODO + } + + else if ("gemini" == navbar->get_request_scheme()) + { + connect( + navbar->get_request_host(), + navbar->get_request_port().empty() ? 1965 : stoi( + navbar->get_request_port() + ) + ); + } + + else + { + // @TODO + } } + +// Private helpers +void Page::connect( + const std::string & host, + int port +) { + try + { + socket_client = Gio::SocketClient::create(); + + socket_client->connect_to_host_async( + host, + port, + [this](const Glib::RefPtr & result) + { + try + { + auto socket = socket_client->connect_finish( + result + ); + + // @TODO read/write data + + socket->close(); + } + + catch (const Glib::Error & exception) + { + // @TODO exception.what(); + } + } + ); + } + + catch (const std::exception & exception) + { + // @TODO exception.what(); + } +} \ No newline at end of file diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index bbd61b55..766a7641 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -6,6 +6,10 @@ #include #include +#include +#include +#include + namespace app::browser::main::tab { namespace page @@ -19,10 +23,16 @@ namespace app::browser::main::tab private: Glib::RefPtr action_group; + Glib::RefPtr socket_client; page::Navbar * navbar; page::Content * content; + void connect( + const std::string & host, + int port + ); + public: Page();