diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index d8b91714..1e5e4832 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -177,6 +177,13 @@ void Page::navigation_reload( } } + // Parse request string + uri = g_uri_parse( + pageNavigation->get_request_text().c_str(), + G_URI_FLAGS_NONE, + NULL // @TODO GError * + ); + // Reset page data mime = MIME::UNDEFINED; @@ -191,13 +198,36 @@ void Page::navigation_reload( action__update->activate(); + if (NULL == uri || NULL == g_uri_get_scheme(uri)) + { + // Scheme not found but host provided, redirect to gemini:// + if (NULL != g_uri_get_host(uri)) + { + pageNavigation->set_request_text( + "gemini://" + pageNavigation->get_request_text() + ); + + navigation_reload( + false + ); + } + + // Make search request + else + { + throw _("Search request not implemented yet"); // @TODO + } + } + // Connect scheme driver - if ("file" == pageNavigation->get_request_scheme()) + else + if (g_uri_get_scheme(uri) == Glib::ustring("file")) { // @TODO } - else if ("gemini" == pageNavigation->get_request_scheme()) + else + if (g_uri_get_scheme(uri) == Glib::ustring("gemini")) { // Create new socket connection GioSocketClient = Gio::SocketClient::create(); @@ -223,7 +253,9 @@ void Page::navigation_reload( description = Glib::ustring::sprintf( _("Connecting to %s.."), - pageNavigation->get_request_host() + g_uri_get_host( + uri + ) ); progress_fraction = .25; @@ -264,7 +296,9 @@ void Page::navigation_reload( description = Glib::ustring::sprintf( _("Begin request to %s.."), - pageNavigation->get_request_host() + g_uri_get_host( + uri + ) ); progress_fraction = .5; @@ -282,7 +316,9 @@ void Page::navigation_reload( description = Glib::ustring::sprintf( _("Reading response from %s.."), - pageNavigation->get_request_host() + g_uri_get_host( + uri + ) ); progress_fraction = .75; @@ -299,14 +335,16 @@ void Page::navigation_reload( if (meta[1] == "20") { // Route by mime type or path extension - if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavigation->get_request_path(), ".gmi")) + if (meta[2] == "text/gemini" || Glib::str_has_suffix(g_uri_get_path(uri), ".gmi")) { // Update mime = MIME::TEXT_GEMINI; title = _("Done"); // @TODO page title - description = pageNavigation->get_request_host(); + description = g_uri_get_host( + uri + ); progress_fraction = 1; @@ -363,21 +401,9 @@ void Page::navigation_reload( ); } - // Scheme not found but host provided, redirect to gemini:// - else if (pageNavigation->get_request_scheme().empty() && !pageNavigation->get_request_host().empty()) - { - pageNavigation->set_request_text( - "gemini://" + pageNavigation->get_request_text() - ); - - navigation_reload( - false - ); - } - else { - // @TODO search request + throw _("Exception"); // @TODO } } diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 1112f12e..d9a168f6 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -88,6 +88,8 @@ namespace app::browser::main::tab // Tools double progress_fraction; // async load indication (progress bar) + GUri * uri; + // Actions Glib::RefPtr action__update; diff --git a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp index b0d6263c..7155b6b5 100644 --- a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp @@ -265,6 +265,21 @@ Glib::ustring Reader::Make::link( ); } + /* @TODO + + GError * error; + + g_uri_resolve_relative( + get_text().c_str(), + get_text().c_str(), + G_URI_FLAGS_NONE, + &error + ); + + if (NULL) + + */ + return Glib::ustring::sprintf( "%s\n", Glib::Markup::escape_text( diff --git a/src/app/browser/main/tab/page/navigation.cpp b/src/app/browser/main/tab/page/navigation.cpp index e1e77722..969a5327 100644 --- a/src/app/browser/main/tab/page/navigation.cpp +++ b/src/app/browser/main/tab/page/navigation.cpp @@ -91,8 +91,16 @@ void Navigation::update( const double & PROGRESS_FRACTION ) { // Toggle base button sensibility + GUri * uri = g_uri_parse( + navigationRequest->get_text().c_str(), + G_URI_FLAGS_NONE, + NULL // @TODO GError * + ); + navigationBase->set_sensitive( - !navigationRequest->get_host().empty() && !navigationRequest->get_path().empty() + NULL != uri && + NULL != g_uri_get_host(uri) && + NULL != g_uri_get_path(uri) ); // Update history widget @@ -246,31 +254,6 @@ Glib::ustring Navigation::get_request_text() return navigationRequest->get_text(); } -Glib::ustring Navigation::get_request_scheme() -{ - return navigationRequest->get_scheme(); -} - -Glib::ustring Navigation::get_request_host() -{ - return navigationRequest->get_host(); -} - -Glib::ustring Navigation::get_request_path() -{ - return navigationRequest->get_path(); -} - -Glib::ustring Navigation::get_request_query() -{ - return navigationRequest->get_query(); -} - -Glib::ustring Navigation::get_request_port() -{ - return navigationRequest->get_port(); -} - // Setters void Navigation::set_request_text( const Glib::ustring & VALUE diff --git a/src/app/browser/main/tab/page/navigation.hpp b/src/app/browser/main/tab/page/navigation.hpp index b3f1c901..d5d726d4 100644 --- a/src/app/browser/main/tab/page/navigation.hpp +++ b/src/app/browser/main/tab/page/navigation.hpp @@ -124,12 +124,6 @@ namespace app::browser::main::tab::page // Getters Glib::ustring get_request_text(); - 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(); - // Setters void set_request_text( const Glib::ustring & VALUE diff --git a/src/app/browser/main/tab/page/navigation/request.cpp b/src/app/browser/main/tab/page/navigation/request.cpp index de11ba15..7339731b 100644 --- a/src/app/browser/main/tab/page/navigation/request.cpp +++ b/src/app/browser/main/tab/page/navigation/request.cpp @@ -34,8 +34,6 @@ Request::Request( signal_changed().connect( [this] { - parse(); - action__update->activate(); } ); @@ -43,8 +41,6 @@ Request::Request( signal_activate().connect( [this] { - parse(); - action__reload->activate(); } ); @@ -146,60 +142,6 @@ int Request::save( ); } -void Request::parse() // @TODO https://docs.gtk.org/glib/struct.Uri.html -{ - scheme.clear(); - host.clear(); - port.clear(); - path.clear(); - query.clear(); - - auto match = Glib::Regex::split_simple( - R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex", - get_text() - ); - - int index = 0; 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; - } - - index++; - } -} - -// Getters -Glib::ustring Request::get_scheme() -{ - return scheme; -} - -Glib::ustring Request::get_host() -{ - return host; -} - -Glib::ustring Request::get_port() -{ - return port; -} - -Glib::ustring Request::get_path() -{ - return path; -} - -Glib::ustring Request::get_query() -{ - return query; -} - // Database model int Request::DB::SESSION::init( sqlite3 * db diff --git a/src/app/browser/main/tab/page/navigation/request.hpp b/src/app/browser/main/tab/page/navigation/request.hpp index 90c31315..56f16164 100644 --- a/src/app/browser/main/tab/page/navigation/request.hpp +++ b/src/app/browser/main/tab/page/navigation/request.hpp @@ -66,20 +66,11 @@ namespace app::browser::main::tab::page::navigation // Extras double progress_fraction; - Glib::ustring scheme, - host, - port, - path, - query; - // Defaults const bool HEXPAND = true; const double PROGRESS_PULSE_STEP = .1; const int PROGRESS_ANIMATION_TIME = 10; - // Private helpers - void parse(); - /* * Class API */ @@ -103,13 +94,6 @@ namespace app::browser::main::tab::page::navigation int save( const sqlite3_int64 & APP_BROWSER_MAIN_TAB_PAGE_NAVIGATION__SESSION__ID ); - - // Getters - Glib::ustring get_scheme(); - Glib::ustring get_host(); - Glib::ustring get_port(); - Glib::ustring get_path(); - Glib::ustring get_query(); }; }