Browse Source

draft gemini connector, remove sigc, implement destructor

CPP-GTK4
yggverse 3 months ago
parent
commit
a741f1edca
  1. 87
      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

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

@ -17,10 +17,10 @@ Page::Page() @@ -17,10 +17,10 @@ Page::Page()
// Define group actions
action_group->add_action(
"update",
sigc::mem_fun(
* this,
& Page::update
)
[this]
{
Page::update();
}
);
insert_action_group(
@ -46,12 +46,15 @@ Page::Page() @@ -46,12 +46,15 @@ Page::Page()
);
}
Page::~Page() = default;
Page::~Page()
{
delete navbar;
delete content;
}
// Public actions
void Page::update()
{
// Route by request protocol
// Route by request scheme
if ("file" == navbar->get_request_scheme())
{
// @TODO
@ -59,55 +62,61 @@ void Page::update() @@ -59,55 +62,61 @@ void Page::update()
else if ("gemini" == navbar->get_request_scheme())
{
connect(
navbar->get_request_host(),
navbar->get_request_port().empty() ? 1965 : stoi(
navbar->get_request_port()
)
// Create new socket connection
socket_client = Gio::SocketClient::create();
socket_client->set_tls(
true
);
}
else
{
// @TODO
}
}
socket_client->set_tls_validation_flags(
Gio::TlsCertificateFlags::NO_FLAGS
);
// Private helpers
void Page::connect(
const std::string & host,
int port
) {
try
{
socket_client = Gio::SocketClient::create();
socket_client->set_timeout(
15 // @TODO
);
socket_client->connect_to_host_async(
host,
port,
navbar->get_request_host(),
navbar->get_request_port().empty() ? 1965 : stoi(
navbar->get_request_port()
),
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
{
try
{
auto socket = socket_client->connect_finish(
socket_connection = socket_client->connect_to_host_finish(
result
);
// @TODO read/write data
// Request
const std::string request = navbar->get_request() + "\r\n";
socket->close();
}
catch (const Glib::Error & exception)
socket_connection->get_output_stream()->write_async(
request.data(),
request.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
{
// @TODO exception.what();
// Response
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 @@ @@ -1,14 +1,16 @@
#ifndef 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/socketclient.h>
#include <giomm/socketconnection.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.h>
#include <sigc++/functors/mem_fun.h>
#include <giomm/asyncresult.h>
#include <giomm/socketconnection.h>
#include <giomm/socketclient.h>
#include <string>
namespace app::browser::main::tab
{
@ -22,17 +24,15 @@ namespace app::browser::main::tab @@ -22,17 +24,15 @@ namespace app::browser::main::tab
{
private:
char buffer[0xfffff];
Glib::RefPtr<Gio::SimpleActionGroup> action_group;
Glib::RefPtr<Gio::SocketClient> socket_client;
Glib::RefPtr<Gio::SocketConnection> socket_connection;
page::Navbar * navbar;
page::Content * content;
void connect(
const std::string & host,
int port
);
public:
Page();

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#include "content.hpp"
using namespace app::browser::main::tab::page;
using namespace std;
Content::Content()
{
@ -14,3 +15,9 @@ Content::Content() @@ -14,3 +15,9 @@ Content::Content()
}
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 @@ -12,6 +12,10 @@ namespace app::browser::main::tab::page
Content();
~Content();
void set(
std::string buffer
);
};
}

Loading…
Cancel
Save