[Webkit-unassigned] [Bug 39944] [GTK] GtkLauncher should support relative file paths

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jun 1 05:11:50 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=39944


Xan Lopez <xan.lopez at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #57449|review?                     |review-
               Flag|                            |




--- Comment #5 from Xan Lopez <xan.lopez at gmail.com>  2010-06-01 05:11:50 PST ---
(From update of attachment 57449)
>+static gchar* filenameToURL(const char* filename)
>+{
>+    GFile *gFile = g_file_new_for_path(filename);
>+    if (!g_file_query_exists(gFile, 0)) {
>+        g_object_unref(gFile);
>+        return 0;
>+    }
>+    g_object_unref(gFile);

Maybe use g_file_test if you only create the object to check that the path is valid?

>+
>+    gchar *fullPath = realpath(filename, 0);
>+    if (!fullPath)
>+        return 0;
>+
>+    gchar *fileURL = g_filename_to_uri(fullPath, 0, 0);
>+    free(fullPath);

GOwnPtr for fullPath.

>+
>+    return fileURL;
>+}
>+
> int
> main (int argc, char* argv[])
> {
>@@ -201,8 +221,15 @@ main (int argc, char* argv[])
>     main_window = create_window ();
>     gtk_container_add (GTK_CONTAINER (main_window), vbox);
> 
>-    gchar* uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/");
>-    webkit_web_view_load_uri (web_view, uri);
>+    gchar *uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/");
>+    gchar *fileURL = filenameToURL(uri);
>+
>+    if (fileURL) {
>+        webkit_web_view_load_uri(web_view, fileURL);
>+        g_free(fileURL);
>+    } else {
>+        webkit_web_view_load_uri(web_view, uri);
>+    }

You can use GOwnPtr for fileURL, and have only one branch with fileURI ? fileURI : uri

> 
>     gtk_widget_grab_focus (GTK_WIDGET (web_view));
>     gtk_widget_show_all (main_window);

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list