Guess a suitable token for a form-based search
This commit is contained in:
parent
16a0f666da
commit
75d7a7024c
2 changed files with 62 additions and 2 deletions
|
@ -877,6 +877,63 @@ midori_search_action_editor_name_changed_cb (GtkWidget* entry,
|
|||
GTK_RESPONSE_ACCEPT, text && *text);
|
||||
}
|
||||
|
||||
gchar*
|
||||
midori_search_action_token_for_uri (const gchar* uri)
|
||||
{
|
||||
guint len, i;
|
||||
gchar** parts;
|
||||
gchar* hostname = NULL, *path = NULL;
|
||||
|
||||
path = midori_uri_parse_hostname (uri, NULL);
|
||||
parts = g_strsplit (path, ".", -1);
|
||||
g_free (path);
|
||||
|
||||
len = g_strv_length (parts);
|
||||
if (len > 2)
|
||||
{
|
||||
for (i = len; i == 0; i--)
|
||||
{
|
||||
if (parts[i] && *parts[i])
|
||||
if (strlen (parts[i]) > 3)
|
||||
{
|
||||
hostname = g_strdup (parts[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
hostname = g_strdup (parts[0]);
|
||||
|
||||
if (!hostname)
|
||||
hostname = g_strdup (parts[1]);
|
||||
|
||||
g_strfreev (parts);
|
||||
|
||||
if (strlen (hostname) > 4)
|
||||
{
|
||||
GString* str = g_string_new (NULL);
|
||||
int j, count = 0;
|
||||
|
||||
for (j = 0; count < 4; j++)
|
||||
{
|
||||
if (hostname[j] == 'a'
|
||||
|| hostname[j] == 'e'
|
||||
|| hostname[j] == 'i'
|
||||
|| hostname[j] == 'o'
|
||||
|| hostname[j] == 'u')
|
||||
continue;
|
||||
else
|
||||
{
|
||||
g_string_append_c (str, hostname[j]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return g_string_free (str, FALSE);
|
||||
}
|
||||
return g_strdup (hostname);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
midori_search_action_get_editor (MidoriSearchAction* search_action,
|
||||
KatzeItem* item,
|
||||
|
@ -978,7 +1035,6 @@ midori_search_action_get_editor (MidoriSearchAction* search_action,
|
|||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||
entry_token = gtk_entry_new ();
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (entry_token), TRUE);
|
||||
if (!new_engine)
|
||||
gtk_entry_set_text (GTK_ENTRY (entry_token)
|
||||
, katze_str_non_null (katze_item_get_token (item)));
|
||||
gtk_box_pack_start (GTK_BOX (hbox), entry_token, TRUE, TRUE, 0);
|
||||
|
|
|
@ -2441,6 +2441,9 @@ midori_view_menu_add_search_engine_cb (GtkWidget* widget,
|
|||
midori_search_action_get_editor (MIDORI_SEARCH_ACTION (action), item, TRUE);
|
||||
}
|
||||
|
||||
gchar*
|
||||
midori_search_action_token_for_uri (const gchar* uri);
|
||||
|
||||
static KatzeItem*
|
||||
midori_view_search_engine_for_form (MidoriView* view,
|
||||
WebKitWebView* web_view)
|
||||
|
@ -2512,6 +2515,7 @@ midori_view_search_engine_for_form (MidoriView* view,
|
|||
|
||||
item = katze_item_new ();
|
||||
katze_item_set_uri (item, g_string_free (uri_str, FALSE));
|
||||
item->token = midori_search_action_token_for_uri (view->uri);
|
||||
|
||||
if (strstr (title, " - "))
|
||||
parts = g_strsplit (title, " - ", 2);
|
||||
|
|
Loading…
Reference in a new issue