Updating branch refs/heads/master
         to c382eb25af0b13debd047d44947adcb682e03181 (commit)
       from 9da062efdd93d3eaf6bffcd1bd53c93ff920a6b9 (commit)

commit c382eb25af0b13debd047d44947adcb682e03181
Author: Christian Dywan <christ...@twotoasts.de>
Date:   Mon Mar 11 01:00:52 2013 +0100

    Merge sokoke_prepare_uri into _magic_uri
    
    Add flag to consider search an error.

 midori/main.c            |    6 +++---
 midori/midori-app.c      |    2 +-
 midori/midori-browser.c  |    4 ++--
 midori/midori-frontend.c |    8 ++++----
 midori/midori-session.c  |    2 +-
 midori/midori-view.c     |    6 +++---
 midori/sokoke.c          |   36 ++++++++++++++++--------------------
 midori/sokoke.h          |    7 +++----
 8 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/midori/main.c b/midori/main.c
index e999b2d..f0ea8a0 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -266,7 +266,7 @@ main (int    argc,
         g_signal_connect (web_view, "load-finished",
             G_CALLBACK (snapshot_load_finished_cb), filename);
         #endif
-        uri = sokoke_prepare_uri (snapshot);
+        uri = sokoke_magic_uri (snapshot, FALSE, TRUE);
         webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), uri);
         g_free (uri);
         gtk_main ();
@@ -281,8 +281,8 @@ main (int    argc,
         GtkWidget* scrolled = gtk_scrolled_window_new (NULL, NULL);
 #endif
         GtkWidget* web_view = webkit_web_view_new ();
-        gchar* uri = sokoke_prepare_uri (
-            (uris != NULL && uris[0]) ? uris[0] : "http://www.example.com";);
+        gchar* uri = sokoke_magic_uri (
+            (uris != NULL && uris[0]) ? uris[0] : "http://www.example.com";, 
FALSE, TRUE);
         katze_window_set_sensible_default_size (GTK_WINDOW (window));
 
 #ifndef HAVE_WEBKIT2
diff --git a/midori/midori-app.c b/midori/midori-app.c
index 2a587c9..df2a060 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -1071,7 +1071,7 @@ midori_app_instance_send_uris (MidoriApp* app,
         int i = 0;
         while (uris[i] != NULL)
         {
-            gchar* new_uri = sokoke_prepare_uri (uris[i]);
+            gchar* new_uri = sokoke_magic_uri (uris[i], TRUE, TRUE);
             gchar* escaped_uri = g_uri_escape_string (new_uri, NULL, FALSE);
             g_free (new_uri);
             katze_assign (uris[i], escaped_uri);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index ae716b3..d9b70f0 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -2929,7 +2929,7 @@ midori_browser_open_bookmark (MidoriBrowser* browser,
         return;
 
     /* Imported bookmarks may lack a protocol */
-    uri_fixed = sokoke_magic_uri (uri);
+    uri_fixed = sokoke_magic_uri (uri, TRUE, FALSE);
     if (!uri_fixed)
         uri_fixed = g_strdup (uri);
 
@@ -3789,7 +3789,7 @@ _action_location_submit_uri (GtkAction*     action,
     }
 
     uri = katze_skip_whitespace (uri);
-    new_uri = sokoke_magic_uri (uri);
+    new_uri = sokoke_magic_uri (uri, TRUE, FALSE);
     if (!new_uri)
     {
         const gchar* keywords = NULL;
diff --git a/midori/midori-frontend.c b/midori/midori-frontend.c
index a578042..963cb6a 100644
--- a/midori/midori-frontend.c
+++ b/midori/midori-frontend.c
@@ -79,7 +79,7 @@ midori_web_app_new (const gchar* config,
 
     if (webapp != NULL)
     {
-        gchar* tmp_uri = sokoke_prepare_uri (webapp);
+        gchar* tmp_uri = sokoke_magic_uri (webapp, FALSE, TRUE);
         g_object_set (settings, "homepage", tmp_uri, NULL);
         midori_browser_add_uri (browser, tmp_uri);
         g_free (tmp_uri);
@@ -92,7 +92,7 @@ midori_web_app_new (const gchar* config,
     if (open_uris != NULL)
         for (i = 0; open_uris[i] != NULL; i++)
         {
-            gchar* new_uri = sokoke_prepare_uri (open_uris[i]);
+            gchar* new_uri = sokoke_magic_uri (open_uris[i], FALSE, TRUE);
             midori_browser_add_uri (browser, new_uri);
             g_free (new_uri);
         }
@@ -206,7 +206,7 @@ midori_private_app_new (const gchar* config,
 
     if (webapp != NULL)
     {
-        gchar* tmp_uri = sokoke_prepare_uri (webapp);
+        gchar* tmp_uri = sokoke_magic_uri (webapp, FALSE, TRUE);
         g_object_set (settings, "homepage", tmp_uri, NULL);
         midori_browser_add_uri (browser, tmp_uri);
         g_free (tmp_uri);
@@ -219,7 +219,7 @@ midori_private_app_new (const gchar* config,
     if (open_uris != NULL)
         for (i = 0; open_uris[i] != NULL; i++)
         {
-            gchar* new_uri = sokoke_prepare_uri (open_uris[i]);
+            gchar* new_uri = sokoke_magic_uri (open_uris[i], FALSE, TRUE);
             midori_browser_add_uri (browser, new_uri);
             g_free (new_uri);
         }
diff --git a/midori/midori-session.c b/midori/midori-session.c
index 5808f0d..e194b4c 100644
--- a/midori/midori-session.c
+++ b/midori/midori-session.c
@@ -519,7 +519,7 @@ midori_load_session (gpointer data)
         guint i = 0;
         while (open_uris[i])
         {
-            gchar* uri = sokoke_prepare_uri (open_uris[i]);
+            gchar* uri = sokoke_magic_uri (open_uris[i], TRUE, TRUE);
             midori_browser_add_uri (browser, uri);
             g_free (uri);
             i++;
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 54b9000..079ef17 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -710,7 +710,7 @@ midori_view_web_view_navigation_decision_cb (WebKitWebView* 
            web_view
     const gchar* uri = webkit_network_request_get_uri (request);
     if (g_str_has_prefix (uri, "geo:") && strstr (uri, ","))
     {
-        gchar* new_uri = sokoke_magic_uri (uri);
+        gchar* new_uri = sokoke_magic_uri (uri, TRUE, FALSE);
         midori_view_set_uri (view, new_uri);
         g_free (new_uri);
         return TRUE;
@@ -1755,7 +1755,7 @@ midori_view_web_view_button_press_event_cb 
(WebKitWebView*  web_view,
                     /* Hold Alt to search for the selected word */
                     if (event->state & GDK_MOD1_MASK)
                     {
-                        new_uri = sokoke_magic_uri (uri);
+                        new_uri = sokoke_magic_uri (uri, TRUE, FALSE);
                         if (!new_uri)
                         {
                             gchar* search = katze_object_get_string (
@@ -2280,7 +2280,7 @@ midori_web_view_menu_new_tab_activate_cb (GtkWidget*  
widget,
         }
         else
         {
-            gchar* uri = sokoke_magic_uri (data);
+            gchar* uri = sokoke_magic_uri (data, TRUE, FALSE);
             if (!uri)
                 uri = g_strdup (data);
             g_signal_emit (view, signals[NEW_TAB], 0, uri,
diff --git a/midori/sokoke.c b/midori/sokoke.c
index 3a79807..0d76914 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -470,25 +470,6 @@ sokoke_external_uri (const gchar* uri)
     return info != NULL;
 }
 
-gchar*
-sokoke_prepare_uri (const gchar *uri)
-{
-    gchar* uri_ready;
-
-    if (g_str_has_prefix (uri, "javascript:"))
-        return g_strdup (uri);
-    else if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)
-         && !g_path_is_absolute (uri))
-    {
-        GFile* file = g_file_new_for_commandline_arg (uri);
-        uri_ready = g_file_get_uri (file);
-        g_object_unref (file);
-        return uri_ready;
-    }
-
-    return sokoke_magic_uri (uri);
-}
-
 /**
  * sokoke_magic_uri:
  * @uri: a string typed by a user
@@ -501,7 +482,9 @@ sokoke_prepare_uri (const gchar *uri)
  * Return value: a newly allocated URI, or %NULL
  **/
 gchar*
-sokoke_magic_uri (const gchar* uri)
+sokoke_magic_uri (const gchar* uri,
+                  gboolean     allow_search,
+                  gboolean     allow_relative)
 {
     gchar** parts;
     gchar* search;
@@ -511,6 +494,14 @@ sokoke_magic_uri (const gchar* uri)
     /* Add file:// if we have a local path */
     if (g_path_is_absolute (uri))
         return g_filename_to_uri (uri, NULL, NULL);
+    if (allow_relative
+     && g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+    {
+        GFile* file = g_file_new_for_commandline_arg (uri);
+        gchar* uri_ready = g_file_get_uri (file);
+        g_object_unref (file);
+        return uri_ready;
+    }
     /* Parse geo URI geo:48.202778,16.368472;crs=wgs84;u=40 as a location */
     if (!strncmp (uri, "geo:", 4))
     {
@@ -565,6 +556,11 @@ sokoke_magic_uri (const gchar* uri)
         }
         g_strfreev (parts);
     }
+    if (!allow_search)
+    {
+        g_printerr ("%s - %s\n", _("Midori"), _("Invalid URI"));
+        exit (1);
+    }
     return NULL;
 }
 
diff --git a/midori/sokoke.h b/midori/sokoke.h
index aa5e5f9..7074b96 100644
--- a/midori/sokoke.h
+++ b/midori/sokoke.h
@@ -63,10 +63,9 @@ gboolean
 sokoke_external_uri                     (const gchar*    uri);
 
 gchar*
-sokoke_prepare_uri                      (const gchar*    uri);
-
-gchar*
-sokoke_magic_uri                        (const gchar*    uri);
+sokoke_magic_uri                        (const gchar*    uri,
+                                         gboolean        allow_search,
+                                         gboolean        allow_realtive);
 
 void
 sokoke_widget_set_visible               (GtkWidget*      widget,
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to