[Xfce4-commits] <midori:master> Guess a suitable token for a form-based search

Christian Dywan noreply at xfce.org
Wed Jul 25 23:06:03 CEST 2012


Updating branch refs/heads/master
         to 75d7a7024c481cd2fd9c8742312ea36e20df77b6 (commit)
       from 16a0f666da326e97612863748e35bc19c8b55ca7 (commit)

commit 75d7a7024c481cd2fd9c8742312ea36e20df77b6
Author: Paweł Forysiuk <tuxator at o2.pl>
Date:   Wed Jul 25 23:03:37 2012 +0200

    Guess a suitable token for a form-based search

 midori/midori-searchaction.c |   60 ++++++++++++++++++++++++++++++++++++++++-
 midori/midori-view.c         |    4 +++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c
index 9568573..da4f9bd 100644
--- a/midori/midori-searchaction.c
+++ b/midori/midori-searchaction.c
@@ -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,8 +1035,7 @@ 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)
+    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);
     gtk_container_add (GTK_CONTAINER (content_area), hbox);
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 41669ed..5b13ff1 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -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);


More information about the Xfce4-commits mailing list