Unify how search URI and keywords are combined
This handles the presence of a %1 and encoding the keywords.
This commit is contained in:
parent
8f58355014
commit
192084d48e
4 changed files with 35 additions and 26 deletions
|
@ -2587,14 +2587,7 @@ _action_location_submit_uri (GtkAction* action,
|
||||||
|
|
||||||
new_uri = sokoke_magic_uri (uri, browser->search_engines);
|
new_uri = sokoke_magic_uri (uri, browser->search_engines);
|
||||||
if (!new_uri)
|
if (!new_uri)
|
||||||
{
|
new_uri = sokoke_search_uri (browser->location_entry_search, uri);
|
||||||
gchar* uri_ = g_uri_escape_string (uri, " :/", TRUE);
|
|
||||||
if (strstr (browser->location_entry_search, "%s"))
|
|
||||||
new_uri = g_strdup_printf (browser->location_entry_search, uri_);
|
|
||||||
else if (!new_uri)
|
|
||||||
new_uri = g_strconcat (browser->location_entry_search, uri_, NULL);
|
|
||||||
g_free (uri_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_tab)
|
if (new_tab)
|
||||||
{
|
{
|
||||||
|
@ -2648,10 +2641,7 @@ _action_search_submit (GtkAction* action,
|
||||||
else /* The location entry search is our fallback */
|
else /* The location entry search is our fallback */
|
||||||
url = browser->location_entry_search;
|
url = browser->location_entry_search;
|
||||||
|
|
||||||
if (strstr (url, "%s"))
|
search = sokoke_search_uri (url, keywords);
|
||||||
search = g_strdup_printf (url, keywords);
|
|
||||||
else
|
|
||||||
search = g_strconcat (url, " ", keywords, NULL);
|
|
||||||
|
|
||||||
if (new_tab)
|
if (new_tab)
|
||||||
midori_browser_add_uri (browser, search);
|
midori_browser_add_uri (browser, search);
|
||||||
|
|
|
@ -750,10 +750,7 @@ midori_location_entry_action_activated_cb (GtkEntryCompletion* completion,
|
||||||
gchar* search;
|
gchar* search;
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
if (strstr (uri, "%s"))
|
search = sokoke_search_uri (uri, keywords);
|
||||||
search = g_strdup_printf (uri, keywords);
|
|
||||||
else
|
|
||||||
search = g_strconcat (uri, " ", keywords, NULL);
|
|
||||||
midori_location_action_set_uri (location_action, search);
|
midori_location_action_set_uri (location_action, search);
|
||||||
g_signal_emit (location_action, signals[SUBMIT_URI], 0, search, FALSE);
|
g_signal_emit (location_action, signals[SUBMIT_URI], 0, search, FALSE);
|
||||||
g_free (search);
|
g_free (search);
|
||||||
|
|
|
@ -893,10 +893,7 @@ midori_web_view_menu_search_web_activate_cb (GtkWidget* widget,
|
||||||
else
|
else
|
||||||
g_object_get (view->settings, "location-entry-search",
|
g_object_get (view->settings, "location-entry-search",
|
||||||
&search, NULL);
|
&search, NULL);
|
||||||
if (strstr (search, "%s"))
|
uri = sokoke_search_uri (search, view->selected_text);
|
||||||
uri = g_strdup_printf (search, view->selected_text);
|
|
||||||
else
|
|
||||||
uri = g_strconcat (search, view->selected_text, NULL);
|
|
||||||
g_free (search);
|
g_free (search);
|
||||||
|
|
||||||
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
||||||
|
|
|
@ -213,6 +213,36 @@ sokoke_idn_to_punycode (gchar* uri)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sokoke_search_uri:
|
||||||
|
* @uri: a search URI with or without %s
|
||||||
|
* @keywords: keywords
|
||||||
|
*
|
||||||
|
* Takes a search engine URI and inserts the specified
|
||||||
|
* keywords. The @keywords are percent encoded. If the
|
||||||
|
* search URI contains a %s they keywords are inserted
|
||||||
|
* in that place, otherwise appended to the URI.
|
||||||
|
*
|
||||||
|
* Return value: a newly allocated search URI
|
||||||
|
**/
|
||||||
|
gchar* sokoke_search_uri (const gchar* uri,
|
||||||
|
const gchar* keywords)
|
||||||
|
{
|
||||||
|
gchar* escaped;
|
||||||
|
gchar* search;
|
||||||
|
|
||||||
|
g_return_val_if_fail (uri != NULL, NULL);
|
||||||
|
g_return_val_if_fail (keywords != NULL, NULL);
|
||||||
|
|
||||||
|
escaped = g_uri_escape_string (keywords, " :/", TRUE);
|
||||||
|
if (strstr (uri, "%s"))
|
||||||
|
search = g_strdup_printf (uri, escaped);
|
||||||
|
else
|
||||||
|
search = g_strconcat (uri, escaped, NULL);
|
||||||
|
g_free (escaped);
|
||||||
|
return search;
|
||||||
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
sokoke_magic_uri (const gchar* uri,
|
sokoke_magic_uri (const gchar* uri,
|
||||||
KatzeArray* search_engines)
|
KatzeArray* search_engines)
|
||||||
|
@ -279,13 +309,8 @@ sokoke_magic_uri (const gchar* uri,
|
||||||
if (parts[0] && parts[1])
|
if (parts[0] && parts[1])
|
||||||
if ((item = katze_array_find_token (search_engines, parts[0])))
|
if ((item = katze_array_find_token (search_engines, parts[0])))
|
||||||
{
|
{
|
||||||
gchar* uri_ = g_uri_escape_string (parts[1], " :/", TRUE);
|
|
||||||
search_uri = katze_item_get_uri (item);
|
search_uri = katze_item_get_uri (item);
|
||||||
if (strstr (search_uri, "%s"))
|
search = sokoke_search_uri (search_uri, parts[1]);
|
||||||
search = g_strdup_printf (search_uri, uri_);
|
|
||||||
else
|
|
||||||
search = g_strconcat (search_uri, uri_, NULL);
|
|
||||||
g_free (uri_);
|
|
||||||
}
|
}
|
||||||
g_strfreev (parts);
|
g_strfreev (parts);
|
||||||
return search;
|
return search;
|
||||||
|
|
Loading…
Reference in a new issue