Handle search engines in MidoriBrowser and simplify sokoke_magic_uri
This commit is contained in:
parent
4bf4e5cd63
commit
713091134f
6 changed files with 47 additions and 60 deletions
|
@ -1848,7 +1848,11 @@ main (int argc,
|
||||||
g_free (current_dir);
|
g_free (current_dir);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
uri_ready = sokoke_magic_uri (uri, NULL, NULL);
|
{
|
||||||
|
uri_ready = sokoke_magic_uri (uri);
|
||||||
|
if (!uri_ready)
|
||||||
|
uri_ready = g_strdup (uri_ready);
|
||||||
|
}
|
||||||
katze_item_set_uri (item, uri_ready);
|
katze_item_set_uri (item, uri_ready);
|
||||||
g_free (uri_ready);
|
g_free (uri_ready);
|
||||||
katze_array_add_item (_session, item);
|
katze_array_add_item (_session, item);
|
||||||
|
|
|
@ -464,7 +464,9 @@ midori_app_command_received (MidoriApp* app,
|
||||||
first = (open_external_pages_in == MIDORI_NEW_PAGE_CURRENT);
|
first = (open_external_pages_in == MIDORI_NEW_PAGE_CURRENT);
|
||||||
while (*uris)
|
while (*uris)
|
||||||
{
|
{
|
||||||
gchar* fixed_uri = sokoke_magic_uri (*uris, NULL, NULL);
|
gchar* fixed_uri = sokoke_magic_uri (*uris);
|
||||||
|
if (!fixed_uri)
|
||||||
|
fixed_uri = g_strdup (*uris);
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
midori_browser_set_current_uri (browser, fixed_uri);
|
midori_browser_set_current_uri (browser, fixed_uri);
|
||||||
|
|
|
@ -2954,7 +2954,9 @@ midori_browser_open_bookmark (MidoriBrowser* browser,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Imported bookmarks may lack a protocol */
|
/* Imported bookmarks may lack a protocol */
|
||||||
uri_fixed = sokoke_magic_uri (uri, NULL, NULL);
|
uri_fixed = sokoke_magic_uri (uri);
|
||||||
|
if (!uri_fixed)
|
||||||
|
uri_fixed = g_strdup (uri);
|
||||||
|
|
||||||
/* FIXME: Use the same binary that is running right now */
|
/* FIXME: Use the same binary that is running right now */
|
||||||
if (katze_item_get_meta_integer (item, "app") != -1)
|
if (katze_item_get_meta_integer (item, "app") != -1)
|
||||||
|
@ -3770,37 +3772,43 @@ _action_location_submit_uri (GtkAction* action,
|
||||||
{
|
{
|
||||||
gchar* stripped_uri;
|
gchar* stripped_uri;
|
||||||
gchar* new_uri;
|
gchar* new_uri;
|
||||||
KatzeItem* item;
|
|
||||||
gint n;
|
gint n;
|
||||||
|
|
||||||
stripped_uri = g_strdup (uri);
|
stripped_uri = g_strdup (uri);
|
||||||
g_strstrip (stripped_uri);
|
g_strstrip (stripped_uri);
|
||||||
item = NULL;
|
new_uri = sokoke_magic_uri (stripped_uri);
|
||||||
new_uri = sokoke_magic_uri (stripped_uri, browser->search_engines, &item);
|
|
||||||
if (!new_uri)
|
if (!new_uri)
|
||||||
new_uri = sokoke_search_uri (browser->location_entry_search, stripped_uri);
|
|
||||||
g_free (stripped_uri);
|
|
||||||
|
|
||||||
if (item)
|
|
||||||
{
|
{
|
||||||
gchar* title;
|
gchar** parts;
|
||||||
GdkPixbuf* icon;
|
gchar* keywords = NULL;
|
||||||
const gchar* icon_name;
|
const gchar* search_uri = NULL;
|
||||||
|
|
||||||
title = g_strdup_printf (_("Search with %s"), katze_item_get_name (item));
|
/* Do we have a keyword and a string? */
|
||||||
icon = midori_search_action_get_icon (item, GTK_WIDGET (browser), &icon_name);
|
parts = g_strsplit (stripped_uri, " ", 2);
|
||||||
if (!icon)
|
if (parts[0])
|
||||||
{
|
{
|
||||||
GdkScreen* screen = gtk_widget_get_screen (GTK_WIDGET (browser));
|
KatzeItem* item;
|
||||||
GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
|
if ((item = katze_array_find_token (browser->search_engines, parts[0])))
|
||||||
icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 16, 0, NULL);
|
{
|
||||||
|
keywords = g_strdup (parts[1] ? parts[1] : "");
|
||||||
|
search_uri = katze_item_get_uri (item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
midori_location_action_add_item (MIDORI_LOCATION_ACTION (action),
|
g_strfreev (parts);
|
||||||
uri, icon, title);
|
|
||||||
if (icon)
|
if (keywords)
|
||||||
g_object_unref (icon);
|
g_free (stripped_uri);
|
||||||
g_free (title);
|
else
|
||||||
|
{
|
||||||
|
keywords = stripped_uri;
|
||||||
|
search_uri = browser->location_entry_search;
|
||||||
|
}
|
||||||
|
new_uri = sokoke_search_uri (search_uri, keywords);
|
||||||
|
|
||||||
|
g_free (keywords);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
g_free (stripped_uri);
|
||||||
|
|
||||||
if (new_tab)
|
if (new_tab)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1307,9 +1307,7 @@ gtk_widget_button_press_event_cb (WebKitWebView* web_view,
|
||||||
/* Hold Alt to search for the selected word */
|
/* Hold Alt to search for the selected word */
|
||||||
if (event->state & GDK_MOD1_MASK)
|
if (event->state & GDK_MOD1_MASK)
|
||||||
{
|
{
|
||||||
KatzeArray* empty_array = katze_array_new (KATZE_TYPE_ITEM);
|
new_uri = sokoke_magic_uri (uri);
|
||||||
new_uri = sokoke_magic_uri (uri, empty_array, NULL);
|
|
||||||
g_object_unref (empty_array);
|
|
||||||
if (!new_uri)
|
if (!new_uri)
|
||||||
{
|
{
|
||||||
gchar* search;
|
gchar* search;
|
||||||
|
@ -1582,7 +1580,9 @@ midori_web_view_menu_new_tab_activate_cb (GtkWidget* widget,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gchar* uri = sokoke_magic_uri (data, NULL, NULL);
|
gchar* uri = sokoke_magic_uri (data);
|
||||||
|
if (!uri)
|
||||||
|
uri = g_strdup (data);
|
||||||
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
g_signal_emit (view, signals[NEW_TAB], 0, uri,
|
||||||
view->open_tabs_in_the_background);
|
view->open_tabs_in_the_background);
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
|
|
|
@ -573,29 +573,21 @@ gchar* sokoke_search_uri (const gchar* uri,
|
||||||
/**
|
/**
|
||||||
* sokoke_magic_uri:
|
* sokoke_magic_uri:
|
||||||
* @uri: a string typed by a user
|
* @uri: a string typed by a user
|
||||||
* @search_engines: search engines
|
|
||||||
* @item: the location to store a #KatzeItem
|
|
||||||
*
|
*
|
||||||
* Takes a string that was typed by a user,
|
* Takes a string that was typed by a user,
|
||||||
* guesses what it is, and returns an URI.
|
* guesses what it is, and returns an URI.
|
||||||
*
|
*
|
||||||
* If it was a search, @item will contain the engine.
|
* If it was a search, %NULL will be returned.
|
||||||
*
|
*
|
||||||
* Return value: a newly allocated URI
|
* Return value: a newly allocated URI, or %NULL
|
||||||
**/
|
**/
|
||||||
gchar*
|
gchar*
|
||||||
sokoke_magic_uri (const gchar* uri,
|
sokoke_magic_uri (const gchar* uri)
|
||||||
KatzeArray* search_engines,
|
|
||||||
KatzeItem** found_item)
|
|
||||||
{
|
{
|
||||||
gchar** parts;
|
gchar** parts;
|
||||||
gchar* search;
|
gchar* search;
|
||||||
const gchar* search_uri;
|
|
||||||
KatzeItem* item;
|
|
||||||
|
|
||||||
g_return_val_if_fail (uri, NULL);
|
g_return_val_if_fail (uri, NULL);
|
||||||
g_return_val_if_fail (!search_engines ||
|
|
||||||
katze_array_is_a (search_engines, KATZE_TYPE_ITEM), NULL);
|
|
||||||
|
|
||||||
/* Just return if it's a javascript: or mailto: uri */
|
/* Just return if it's a javascript: or mailto: uri */
|
||||||
if (!strncmp (uri, "javascript:", 11)
|
if (!strncmp (uri, "javascript:", 11)
|
||||||
|
@ -637,26 +629,9 @@ sokoke_magic_uri (const gchar* uri,
|
||||||
}
|
}
|
||||||
g_strfreev (parts);
|
g_strfreev (parts);
|
||||||
}
|
}
|
||||||
/* We don't want to search? So return early. */
|
return NULL;
|
||||||
if (!search_engines)
|
|
||||||
return g_strdup (uri);
|
|
||||||
search = NULL;
|
|
||||||
search_uri = NULL;
|
|
||||||
/* Do we have a keyword and a string? */
|
|
||||||
parts = g_strsplit (uri, " ", 2);
|
|
||||||
if (parts[0])
|
|
||||||
if ((item = katze_array_find_token (search_engines, parts[0])))
|
|
||||||
{
|
|
||||||
search_uri = katze_item_get_uri (item);
|
|
||||||
search = sokoke_search_uri (search_uri, parts[1] ? parts[1] : "");
|
|
||||||
if (found_item)
|
|
||||||
*found_item = item;
|
|
||||||
}
|
|
||||||
g_strfreev (parts);
|
|
||||||
return search;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sokoke_format_uri_for_display:
|
* sokoke_format_uri_for_display:
|
||||||
* @uri: an URI string
|
* @uri: an URI string
|
||||||
|
|
|
@ -97,9 +97,7 @@ gchar*
|
||||||
sokoke_uri_to_ascii (const gchar* uri);
|
sokoke_uri_to_ascii (const gchar* uri);
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
sokoke_magic_uri (const gchar* uri,
|
sokoke_magic_uri (const gchar* uri);
|
||||||
KatzeArray* search_engines,
|
|
||||||
KatzeItem** found_item);
|
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
sokoke_format_uri_for_display (const gchar* uri);
|
sokoke_format_uri_for_display (const gchar* uri);
|
||||||
|
|
Loading…
Reference in a new issue