diff --git a/Makefile b/Makefile index d35f55e3..f17afdb7 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,7 @@ SRCS = src/main.cpp\ src/app/browser/main/tab/data/navbar/update.cpp\ src/app/browser/main/tab/label.cpp\ src/lib/database.cpp\ - src/lib/database/session.cpp\ - src/lib/url.cpp + src/lib/database/session.cpp OBJS = $(SRCS:.cpp=.o) diff --git a/po/POTFILES.in b/po/POTFILES.in index 1f5e1eb4..39bfdfc9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -17,5 +17,4 @@ src/app/browser/main/tab/data/navbar/update.cpp src/app/browser/main/tab/label.cpp src/lib/database.cpp src/lib/database/session.cpp -src/lib/url.cpp src/main.cpp diff --git a/src/app/browser/main/tab/data/navbar.cpp b/src/app/browser/main/tab/data/navbar.cpp index 9f516723..75f1e82c 100644 --- a/src/app/browser/main/tab/data/navbar.cpp +++ b/src/app/browser/main/tab/data/navbar.cpp @@ -5,8 +5,6 @@ #include "navbar/request.hpp" #include "navbar/update.hpp" -#include "../../../../../lib/url.hpp" - using namespace app::browser::main::tab::data; Navbar::Navbar() @@ -90,24 +88,14 @@ Navbar::~Navbar() = default; // Actions void Navbar::refresh() { - // Detect request has value - bool has_request = request->get_text_length(); - // Toggle base button sensibility - auto url = new ::lib::Url( - request->get_text() - ); - base->set_sensitive( - has_request && !url->host.empty() - && !url->path.empty() + !empty(request->get_host()) && !empty(request->get_path()) ); - delete url; url = nullptr; - // Toggle update button sensibility update->set_sensitive( - has_request + (bool) request->get_text_length() ); } diff --git a/src/app/browser/main/tab/data/navbar/request.cpp b/src/app/browser/main/tab/data/navbar/request.cpp index e4d5cbc6..5ebafb5d 100644 --- a/src/app/browser/main/tab/data/navbar/request.cpp +++ b/src/app/browser/main/tab/data/navbar/request.cpp @@ -1,6 +1,7 @@ #include "request.hpp" using namespace app::browser::main::tab::data::navbar; +using namespace std; Request::Request() { @@ -13,10 +14,14 @@ Request::Request() true ); + parse(); + // Connect events signal_changed().connect( [this] { + parse(); + activate_action( "navbar.refresh" ); @@ -26,6 +31,8 @@ Request::Request() signal_activate().connect( [this] { + parse(); + activate_action( "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; \ No newline at end of file diff --git a/src/app/browser/main/tab/data/navbar/request.hpp b/src/app/browser/main/tab/data/navbar/request.hpp index 83a158f7..f50a8976 100644 --- a/src/app/browser/main/tab/data/navbar/request.hpp +++ b/src/app/browser/main/tab/data/navbar/request.hpp @@ -4,15 +4,35 @@ #include #include +#include +#include + namespace app::browser::main::tab::data::navbar { class Request : public Gtk::Entry { + private: + + std::string scheme, + host, + port, + path, + query; + + void parse(); + public: Request(); ~Request(); + + std::string get_scheme(); + std::string get_host(); + std::string get_path(); + std::string get_query(); + + int get_port(); }; } diff --git a/src/lib/url.cpp b/src/lib/url.cpp deleted file mode 100644 index 1b95a597..00000000 --- a/src/lib/url.cpp +++ /dev/null @@ -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; \ No newline at end of file diff --git a/src/lib/url.hpp b/src/lib/url.hpp deleted file mode 100644 index 62abb79a..00000000 --- a/src/lib/url.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef LIB_URL_HPP -#define LIB_URL_HPP - -#include -#include - -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 \ No newline at end of file