Browse Source

replace std constructions with glib

CPP-GTK4
yggverse 3 months ago
parent
commit
cbf786ce4c
  1. 8
      src/app/browser/main/tab/page.cpp
  2. 3
      src/app/browser/main/tab/page.hpp
  3. 3
      src/app/browser/main/tab/page/content.cpp
  4. 5
      src/app/browser/main/tab/page/content.hpp
  5. 14
      src/app/browser/main/tab/page/navbar.cpp
  6. 13
      src/app/browser/main/tab/page/navbar.hpp
  7. 48
      src/app/browser/main/tab/page/navbar/request.cpp
  8. 25
      src/app/browser/main/tab/page/navbar/request.hpp

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

@ -88,7 +88,7 @@ void Page::update()
); );
// Request // Request
const std::string request = navbar->get_request() + "\r\n"; const Glib::ustring request = navbar->get_request() + "\r\n";
socket_connection->get_output_stream()->write_async( socket_connection->get_output_stream()->write_async(
request.data(), request.data(),
@ -117,15 +117,13 @@ 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 (!navbar->get_request_host().empty())
{ {
std::string request = "gemini://"; Glib::ustring request = "gemini://";
request += navbar->get_request_host(); // @TODO validate request += navbar->get_request_host(); // @TODO validate
if (!navbar->get_request_port().empty()) if (!navbar->get_request_port().empty())
{ {
request += std::stoi( request += navbar->get_request_port();
navbar->get_request_port()
);
} }
request += navbar->get_request_path(); request += navbar->get_request_path();

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

@ -8,10 +8,9 @@
#include <giomm/socketclient.h> #include <giomm/socketclient.h>
#include <giomm/socketconnection.h> #include <giomm/socketconnection.h>
#include <glibmm/refptr.h> #include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <string>
namespace app::browser::main::tab namespace app::browser::main::tab
{ {
namespace page namespace page

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

@ -1,7 +1,6 @@
#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()
{ {
@ -17,7 +16,7 @@ Content::Content()
Content::~Content() = default; Content::~Content() = default;
void Content::set( void Content::set(
const string & buffer const Glib::ustring & buffer
) { ) {
// @TODO // @TODO
} }

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

@ -2,8 +2,7 @@
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <glibmm/ustring.h>
#include <string>
namespace app::browser::main::tab::page namespace app::browser::main::tab::page
{ {
@ -16,7 +15,7 @@ namespace app::browser::main::tab::page
~Content(); ~Content();
void set( void set(
const std::string & buffer const Glib::ustring & buffer
); );
}; };
} }

14
src/app/browser/main/tab/page/navbar.cpp

@ -90,7 +90,7 @@ void Navbar::refresh()
{ {
// Toggle base button sensibility // Toggle base button sensibility
base->set_sensitive( base->set_sensitive(
!empty(request->get_host()) && !empty(request->get_path()) !request->get_host().empty() && !request->get_path().empty()
); );
// Toggle update button sensibility // Toggle update button sensibility
@ -101,7 +101,7 @@ void Navbar::refresh()
// Setters // Setters
void Navbar::set_request( void Navbar::set_request(
const std::string value const Glib::ustring value
) { ) {
request->set_text( request->set_text(
value value
@ -116,27 +116,27 @@ Glib::ustring Navbar::get_request()
return request->get_text(); return request->get_text();
} }
std::string Navbar::get_request_scheme() Glib::ustring Navbar::get_request_scheme()
{ {
return request->get_scheme(); return request->get_scheme();
} }
std::string Navbar::get_request_host() Glib::ustring Navbar::get_request_host()
{ {
return request->get_host(); return request->get_host();
} }
std::string Navbar::get_request_path() Glib::ustring Navbar::get_request_path()
{ {
return request->get_path(); return request->get_path();
} }
std::string Navbar::get_request_query() Glib::ustring Navbar::get_request_query()
{ {
return request->get_query(); return request->get_query();
} }
std::string Navbar::get_request_port() Glib::ustring Navbar::get_request_port()
{ {
return request->get_port(); return request->get_port();
} }

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

@ -5,7 +5,6 @@
#include <glibmm/refptr.h> #include <glibmm/refptr.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <string>
namespace app::browser::main::tab::page namespace app::browser::main::tab::page
{ {
@ -44,17 +43,17 @@ namespace app::browser::main::tab::page
// Setters // Setters
void set_request( void set_request(
const std::string value const Glib::ustring value
); );
// Getters // Getters
Glib::ustring get_request(); Glib::ustring get_request();
std::string get_request_scheme(); Glib::ustring get_request_scheme();
std::string get_request_host(); Glib::ustring get_request_host();
std::string get_request_port(); Glib::ustring get_request_port();
std::string get_request_path(); Glib::ustring get_request_path();
std::string get_request_query(); Glib::ustring get_request_query();
}; };
} }

48
src/app/browser/main/tab/page/navbar/request.cpp

@ -1,7 +1,6 @@
#include "request.hpp" #include "request.hpp"
using namespace app::browser::main::tab::page::navbar; using namespace app::browser::main::tab::page::navbar;
using namespace std;
// Construct // Construct
Request::Request() Request::Request()
@ -42,27 +41,27 @@ Request::Request()
Request::~Request() = default; Request::~Request() = default;
// Getters // Getters
string Request::get_scheme() Glib::ustring Request::get_scheme()
{ {
return scheme; return scheme;
} }
string Request::get_host() Glib::ustring Request::get_host()
{ {
return host; return host;
} }
string Request::get_port() Glib::ustring Request::get_port()
{ {
return port; return port;
} }
string Request::get_path() Glib::ustring Request::get_path()
{ {
return path; return path;
} }
string Request::get_query() Glib::ustring Request::get_query()
{ {
return path; return path;
} }
@ -70,23 +69,30 @@ string Request::get_query()
// Private helpers // Private helpers
void Request::parse() void Request::parse()
{ {
string subject = get_text(); auto match = Glib::Regex::split_simple(
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex",
get_text()
);
smatch results; scheme = "";
host = "";
port = "";
path = "";
query = "";
static const regex pattern( // @TODO user:password@#fragment? int index = 0;
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex"
);
regex_search( for (const Glib::ustring & value : match)
subject, {
results, switch (index)
pattern {
); case 2: scheme = value; break;
case 3: host = value; break;
case 5: port = value; break;
case 6: path = value; break;
case 8: query = value; break;
}
scheme = results[2]; index++;
host = results[3]; }
port = results[5];
path = results[6];
query = results[8];
} }

25
src/app/browser/main/tab/page/navbar/request.hpp

@ -2,20 +2,19 @@
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP #define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP
#include <glibmm/i18n.h> #include <glibmm/i18n.h>
#include <glibmm/regex.h>
#include <glibmm/ustring.h>
#include <gtkmm/entry.h> #include <gtkmm/entry.h>
#include <regex>
#include <string>
namespace app::browser::main::tab::page::navbar namespace app::browser::main::tab::page::navbar
{ {
class Request : public Gtk::Entry class Request : public Gtk::Entry
{ {
std::string scheme, Glib::ustring scheme,
host, host,
port, port,
path, path,
query; query;
void parse(); void parse();
@ -25,11 +24,11 @@ namespace app::browser::main::tab::page::navbar
~Request(); ~Request();
std::string get_scheme(); Glib::ustring get_scheme();
std::string get_host(); Glib::ustring get_host();
std::string get_port(); Glib::ustring get_port();
std::string get_path(); Glib::ustring get_path();
std::string get_query(); Glib::ustring get_query();
}; };
} }

Loading…
Cancel
Save