mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 16:04:15 +00:00
use local request parser
This commit is contained in:
parent
4da1e4d9c2
commit
75300eb45e
3
Makefile
3
Makefile
@ -24,8 +24,7 @@ SRCS = src/main.cpp\
|
|||||||
src/app/browser/main/tab/data/navbar/update.cpp\
|
src/app/browser/main/tab/data/navbar/update.cpp\
|
||||||
src/app/browser/main/tab/label.cpp\
|
src/app/browser/main/tab/label.cpp\
|
||||||
src/lib/database.cpp\
|
src/lib/database.cpp\
|
||||||
src/lib/database/session.cpp\
|
src/lib/database/session.cpp
|
||||||
src/lib/url.cpp
|
|
||||||
|
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
|
|
||||||
|
@ -17,5 +17,4 @@ src/app/browser/main/tab/data/navbar/update.cpp
|
|||||||
src/app/browser/main/tab/label.cpp
|
src/app/browser/main/tab/label.cpp
|
||||||
src/lib/database.cpp
|
src/lib/database.cpp
|
||||||
src/lib/database/session.cpp
|
src/lib/database/session.cpp
|
||||||
src/lib/url.cpp
|
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include "navbar/request.hpp"
|
#include "navbar/request.hpp"
|
||||||
#include "navbar/update.hpp"
|
#include "navbar/update.hpp"
|
||||||
|
|
||||||
#include "../../../../../lib/url.hpp"
|
|
||||||
|
|
||||||
using namespace app::browser::main::tab::data;
|
using namespace app::browser::main::tab::data;
|
||||||
|
|
||||||
Navbar::Navbar()
|
Navbar::Navbar()
|
||||||
@ -90,24 +88,14 @@ Navbar::~Navbar() = default;
|
|||||||
// Actions
|
// Actions
|
||||||
void Navbar::refresh()
|
void Navbar::refresh()
|
||||||
{
|
{
|
||||||
// Detect request has value
|
|
||||||
bool has_request = request->get_text_length();
|
|
||||||
|
|
||||||
// Toggle base button sensibility
|
// Toggle base button sensibility
|
||||||
auto url = new ::lib::Url(
|
|
||||||
request->get_text()
|
|
||||||
);
|
|
||||||
|
|
||||||
base->set_sensitive(
|
base->set_sensitive(
|
||||||
has_request && !url->host.empty()
|
!empty(request->get_host()) && !empty(request->get_path())
|
||||||
&& !url->path.empty()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
delete url; url = nullptr;
|
|
||||||
|
|
||||||
// Toggle update button sensibility
|
// Toggle update button sensibility
|
||||||
update->set_sensitive(
|
update->set_sensitive(
|
||||||
has_request
|
(bool) request->get_text_length()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "request.hpp"
|
#include "request.hpp"
|
||||||
|
|
||||||
using namespace app::browser::main::tab::data::navbar;
|
using namespace app::browser::main::tab::data::navbar;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
Request::Request()
|
Request::Request()
|
||||||
{
|
{
|
||||||
@ -13,10 +14,14 @@ Request::Request()
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
parse();
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
signal_changed().connect(
|
signal_changed().connect(
|
||||||
[this]
|
[this]
|
||||||
{
|
{
|
||||||
|
parse();
|
||||||
|
|
||||||
activate_action(
|
activate_action(
|
||||||
"navbar.refresh"
|
"navbar.refresh"
|
||||||
);
|
);
|
||||||
@ -26,6 +31,8 @@ Request::Request()
|
|||||||
signal_activate().connect(
|
signal_activate().connect(
|
||||||
[this]
|
[this]
|
||||||
{
|
{
|
||||||
|
parse();
|
||||||
|
|
||||||
activate_action(
|
activate_action(
|
||||||
"data.update"
|
"data.update"
|
||||||
);
|
);
|
||||||
@ -33,4 +40,56 @@ Request::Request()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
string Request::get_scheme()
|
||||||
|
{
|
||||||
|
return scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Request::get_host()
|
||||||
|
{
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Request::get_path()
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Request::get_query()
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Request::get_port()
|
||||||
|
{
|
||||||
|
return stoi(
|
||||||
|
port
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private helpers
|
||||||
|
void Request::parse() // make private??
|
||||||
|
{
|
||||||
|
string subject = get_text();
|
||||||
|
|
||||||
|
smatch results;
|
||||||
|
|
||||||
|
static const regex pattern( // @TODO user:password@#fragment?
|
||||||
|
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex"
|
||||||
|
);
|
||||||
|
|
||||||
|
regex_search(
|
||||||
|
subject,
|
||||||
|
results,
|
||||||
|
pattern
|
||||||
|
);
|
||||||
|
|
||||||
|
scheme = results[2];
|
||||||
|
host = results[3];
|
||||||
|
port = results[5];
|
||||||
|
path = results[6];
|
||||||
|
query = results[8];
|
||||||
|
}
|
||||||
|
|
||||||
Request::~Request() = default;
|
Request::~Request() = default;
|
@ -4,15 +4,35 @@
|
|||||||
#include <glibmm/i18n.h>
|
#include <glibmm/i18n.h>
|
||||||
#include <gtkmm/entry.h>
|
#include <gtkmm/entry.h>
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace app::browser::main::tab::data::navbar
|
namespace app::browser::main::tab::data::navbar
|
||||||
{
|
{
|
||||||
class Request : public Gtk::Entry
|
class Request : public Gtk::Entry
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::string scheme,
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
path,
|
||||||
|
query;
|
||||||
|
|
||||||
|
void parse();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Request();
|
Request();
|
||||||
|
|
||||||
~Request();
|
~Request();
|
||||||
|
|
||||||
|
std::string get_scheme();
|
||||||
|
std::string get_host();
|
||||||
|
std::string get_path();
|
||||||
|
std::string get_query();
|
||||||
|
|
||||||
|
int get_port();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
#include "url.hpp"
|
|
||||||
|
|
||||||
using namespace lib;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Url::Url(
|
|
||||||
string subject
|
|
||||||
) {
|
|
||||||
smatch results;
|
|
||||||
|
|
||||||
static const regex pattern( // @TODO user:password@#fragment?
|
|
||||||
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex"
|
|
||||||
);
|
|
||||||
|
|
||||||
regex_search(
|
|
||||||
subject,
|
|
||||||
results,
|
|
||||||
pattern
|
|
||||||
);
|
|
||||||
|
|
||||||
scheme = results[2];
|
|
||||||
host = results[3];
|
|
||||||
port = results[5];
|
|
||||||
path = results[6];
|
|
||||||
query = results[8];
|
|
||||||
}
|
|
||||||
|
|
||||||
string Url::to_string()
|
|
||||||
{
|
|
||||||
string result;
|
|
||||||
|
|
||||||
if (!scheme.empty()) result += scheme + "://";
|
|
||||||
if (!host.empty()) result += host;
|
|
||||||
if (!port.empty()) result += ":" + port;
|
|
||||||
if (!path.empty()) result += "/" + path;
|
|
||||||
if (!query.empty()) result += "?" + query;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Url::~Url() = default;
|
|
@ -1,29 +0,0 @@
|
|||||||
#ifndef LIB_URL_HPP
|
|
||||||
#define LIB_URL_HPP
|
|
||||||
|
|
||||||
#include <regex>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace lib
|
|
||||||
{
|
|
||||||
class Url
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
std::string scheme,
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
path,
|
|
||||||
query;
|
|
||||||
|
|
||||||
Url(
|
|
||||||
std::string subject
|
|
||||||
);
|
|
||||||
|
|
||||||
std::string to_string();
|
|
||||||
|
|
||||||
~Url();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // LIB_URL_HPP
|
|
Loading…
x
Reference in New Issue
Block a user