Browse Source

draft gemini connector, remove sigc, implement destructor

CPP-GTK4
yggverse 3 months ago
parent
commit
a741f1edca
  1. 99
      src/app/browser/main/tab/page.cpp
  2. 18
      src/app/browser/main/tab/page.hpp
  3. 7
      src/app/browser/main/tab/page/content.cpp
  4. 4
      src/app/browser/main/tab/page/content.hpp

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

@ -17,10 +17,10 @@ Page::Page()
// Define group actions // Define group actions
action_group->add_action( action_group->add_action(
"update", "update",
sigc::mem_fun( [this]
* this, {
& Page::update Page::update();
) }
); );
insert_action_group( insert_action_group(
@ -46,12 +46,15 @@ Page::Page()
); );
} }
Page::~Page() = default; Page::~Page()
{
delete navbar;
delete content;
}
// Public actions
void Page::update() void Page::update()
{ {
// Route by request protocol // Route by request scheme
if ("file" == navbar->get_request_scheme()) if ("file" == navbar->get_request_scheme())
{ {
// @TODO // @TODO
@ -59,55 +62,61 @@ void Page::update()
else if ("gemini" == navbar->get_request_scheme()) else if ("gemini" == navbar->get_request_scheme())
{ {
connect( // Create new socket connection
navbar->get_request_host(), socket_client = Gio::SocketClient::create();
navbar->get_request_port().empty() ? 1965 : stoi(
navbar->get_request_port() socket_client->set_tls(
) true
); );
}
else socket_client->set_tls_validation_flags(
{ Gio::TlsCertificateFlags::NO_FLAGS
// @TODO );
}
}
// Private helpers socket_client->set_timeout(
void Page::connect( 15 // @TODO
const std::string & host, );
int port
) {
try
{
socket_client = Gio::SocketClient::create();
socket_client->connect_to_host_async( socket_client->connect_to_host_async(
host, navbar->get_request_host(),
port, navbar->get_request_port().empty() ? 1965 : stoi(
navbar->get_request_port()
),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult> & result)
{ {
try socket_connection = socket_client->connect_to_host_finish(
{ result
auto socket = socket_client->connect_finish( );
result
); // Request
const std::string request = navbar->get_request() + "\r\n";
// @TODO read/write data
socket_connection->get_output_stream()->write_async(
socket->close(); request.data(),
} request.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
catch (const Glib::Error & exception) {
{ // Response
// @TODO exception.what(); socket_connection->get_input_stream()->read_all_async( // | read_async
} buffer,
sizeof(buffer) - 1,
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
{
content->set(
buffer
);
socket_connection->close();
}
);
}
);
} }
); );
} }
catch (const std::exception & exception) else
{ {
// @TODO exception.what(); // @TODO
} }
} }

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

@ -1,14 +1,16 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_HPP #ifndef APP_BROWSER_MAIN_TAB_PAGE_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_HPP #define APP_BROWSER_MAIN_TAB_PAGE_HPP
#include <giomm/asyncresult.h>
#include <giomm/inputstream.h>
#include <giomm/outputstream.h>
#include <giomm/simpleactiongroup.h> #include <giomm/simpleactiongroup.h>
#include <giomm/socketclient.h>
#include <giomm/socketconnection.h>
#include <glibmm/refptr.h> #include <glibmm/refptr.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <sigc++/functors/mem_fun.h>
#include <giomm/asyncresult.h> #include <string>
#include <giomm/socketconnection.h>
#include <giomm/socketclient.h>
namespace app::browser::main::tab namespace app::browser::main::tab
{ {
@ -22,17 +24,15 @@ namespace app::browser::main::tab
{ {
private: private:
char buffer[0xfffff];
Glib::RefPtr<Gio::SimpleActionGroup> action_group; Glib::RefPtr<Gio::SimpleActionGroup> action_group;
Glib::RefPtr<Gio::SocketClient> socket_client; Glib::RefPtr<Gio::SocketClient> socket_client;
Glib::RefPtr<Gio::SocketConnection> socket_connection;
page::Navbar * navbar; page::Navbar * navbar;
page::Content * content; page::Content * content;
void connect(
const std::string & host,
int port
);
public: public:
Page(); Page();

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

@ -1,6 +1,7 @@
#include "content.hpp" #include "content.hpp"
using namespace app::browser::main::tab::page; using namespace app::browser::main::tab::page;
using namespace std;
Content::Content() Content::Content()
{ {
@ -14,3 +15,9 @@ Content::Content()
} }
Content::~Content() = default; Content::~Content() = default;
void Content::set(
string buffer
) {
// @TODO
}

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

@ -12,6 +12,10 @@ namespace app::browser::main::tab::page
Content(); Content();
~Content(); ~Content();
void set(
std::string buffer
);
}; };
} }

Loading…
Cancel
Save