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. 17
      src/app/browser/main/tab/page/navbar/request.hpp

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

@ -88,7 +88,7 @@ void Page::update() @@ -88,7 +88,7 @@ void Page::update()
);
// 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(
request.data(),
@ -117,15 +117,13 @@ void Page::update() @@ -117,15 +117,13 @@ void Page::update()
// Scheme not found but host provided, redirect to gemini://
else if (!navbar->get_request_host().empty())
{
std::string request = "gemini://";
Glib::ustring request = "gemini://";
request += navbar->get_request_host(); // @TODO validate
if (!navbar->get_request_port().empty())
{
request += std::stoi(
navbar->get_request_port()
);
request += navbar->get_request_port();
}
request += navbar->get_request_path();

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

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

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

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
#include "content.hpp"
using namespace app::browser::main::tab::page;
using namespace std;
Content::Content()
{
@ -17,7 +16,7 @@ Content::Content() @@ -17,7 +16,7 @@ Content::Content()
Content::~Content() = default;
void Content::set(
const string & buffer
const Glib::ustring & buffer
) {
// @TODO
}

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

@ -2,8 +2,7 @@ @@ -2,8 +2,7 @@
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#include <gtkmm/box.h>
#include <string>
#include <glibmm/ustring.h>
namespace app::browser::main::tab::page
{
@ -16,7 +15,7 @@ namespace app::browser::main::tab::page @@ -16,7 +15,7 @@ namespace app::browser::main::tab::page
~Content();
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() @@ -90,7 +90,7 @@ void Navbar::refresh()
{
// Toggle base button sensibility
base->set_sensitive(
!empty(request->get_host()) && !empty(request->get_path())
!request->get_host().empty() && !request->get_path().empty()
);
// Toggle update button sensibility
@ -101,7 +101,7 @@ void Navbar::refresh() @@ -101,7 +101,7 @@ void Navbar::refresh()
// Setters
void Navbar::set_request(
const std::string value
const Glib::ustring value
) {
request->set_text(
value
@ -116,27 +116,27 @@ Glib::ustring Navbar::get_request() @@ -116,27 +116,27 @@ Glib::ustring Navbar::get_request()
return request->get_text();
}
std::string Navbar::get_request_scheme()
Glib::ustring Navbar::get_request_scheme()
{
return request->get_scheme();
}
std::string Navbar::get_request_host()
Glib::ustring Navbar::get_request_host()
{
return request->get_host();
}
std::string Navbar::get_request_path()
Glib::ustring Navbar::get_request_path()
{
return request->get_path();
}
std::string Navbar::get_request_query()
Glib::ustring Navbar::get_request_query()
{
return request->get_query();
}
std::string Navbar::get_request_port()
Glib::ustring Navbar::get_request_port()
{
return request->get_port();
}

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

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

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

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

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

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

Loading…
Cancel
Save