]> spindle.queued.net Git - midori/commitdiff
Unify how search URI and keywords are combined
authorChristian Dywan <christian@twotoasts.de>
Sun, 19 Apr 2009 22:39:36 +0000 (00:39 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 19 Apr 2009 22:39:36 +0000 (00:39 +0200)
This handles the presence of a %1 and encoding the keywords.

midori/midori-browser.c
midori/midori-locationaction.c
midori/midori-view.c
midori/sokoke.c

index 32fd16eca4ec4065d5d9b9d112746ffcca1d4c82..1a89ff45f679731cc4fc8fcd42bb32a82af45e29 100644 (file)
@@ -2587,14 +2587,7 @@ _action_location_submit_uri (GtkAction*     action,
 
     new_uri = sokoke_magic_uri (uri, browser->search_engines);
     if (!new_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_);
-    }
+        new_uri = sokoke_search_uri (browser->location_entry_search, uri);
 
     if (new_tab)
     {
@@ -2648,10 +2641,7 @@ _action_search_submit (GtkAction*     action,
     else /* The location entry search is our fallback */
         url = browser->location_entry_search;
 
-    if (strstr (url, "%s"))
-        search = g_strdup_printf (url, keywords);
-    else
-        search = g_strconcat (url, " ", keywords, NULL);
+    search = sokoke_search_uri (url, keywords);
 
     if (new_tab)
         midori_browser_add_uri (browser, search);
index 7d4ae7332ab7a3dc298bdef10b68fe079cd32cbe..54cdaedaee059b53e27af53c96e965214d4cd95b 100644 (file)
@@ -750,10 +750,7 @@ midori_location_entry_action_activated_cb (GtkEntryCompletion*   completion,
         gchar* search;
         if (!item)
             return;
-        if (strstr (uri, "%s"))
-            search = g_strdup_printf (uri, keywords);
-        else
-            search = g_strconcat (uri, " ", keywords, NULL);
+        search = sokoke_search_uri (uri, keywords);
         midori_location_action_set_uri (location_action, search);
         g_signal_emit (location_action, signals[SUBMIT_URI], 0, search, FALSE);
         g_free (search);
index bb10bfe553f6852fc10b17517bd1853c505c7402..8b1e4d232d78795d915c6a11d3bee2acd3cdaa06 100644 (file)
@@ -893,10 +893,7 @@ midori_web_view_menu_search_web_activate_cb (GtkWidget*  widget,
     else
         g_object_get (view->settings, "location-entry-search",
                       &search, NULL);
-    if (strstr (search, "%s"))
-        uri = g_strdup_printf (search, view->selected_text);
-    else
-        uri = g_strconcat (search, view->selected_text, NULL);
+    uri = sokoke_search_uri (search, view->selected_text);
     g_free (search);
 
     g_signal_emit (view, signals[NEW_TAB], 0, uri,
index adda646904eb3d60376292b3aeef53710e48c1ed..914d99dcda92609487b1c8e60cd372e99645c2f3 100644 (file)
@@ -213,6 +213,36 @@ sokoke_idn_to_punycode (gchar* uri)
     #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*
 sokoke_magic_uri (const gchar* uri,
                   KatzeArray*  search_engines)
@@ -279,13 +309,8 @@ sokoke_magic_uri (const gchar* uri,
     if (parts[0] && parts[1])
         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);
-            if (strstr (search_uri, "%s"))
-                search = g_strdup_printf (search_uri, uri_);
-            else
-                search = g_strconcat (search_uri, uri_, NULL);
-            g_free (uri_);
+            search = sokoke_search_uri (search_uri, parts[1]);
         }
     g_strfreev (parts);
     return search;