Get the URI from the file dialog rather than the filename.
[raktpdf.git] / src / rakt-window.c
index 24fcf50e8e68a44bba9279cd078447d69022de2d..c1e19611a3c599d06a2206c8e50a447b88b9d8f6 100644 (file)
@@ -65,8 +65,8 @@ static const GtkActionEntry action_entries[] = {
                "HelpMenu", NULL, "_Help", NULL, NULL, NULL
        },
        {
-               "Open", GTK_STOCK_OPEN,
-               "_Open", "<control>O", "Open a PDF file",
+               "Open", GTK_STOCK_OPEN, "_Open",
+               "<control>O", "Open a PDF file",
                G_CALLBACK (on_action_open)
        },
        {
@@ -80,13 +80,13 @@ static const GtkActionEntry action_entries[] = {
                G_CALLBACK (on_action_go_previous)
        },
        {
-               "Quit", GTK_STOCK_QUIT,
-               "_Quit", "<control>Q", "Quit the application",
+               "Quit", GTK_STOCK_QUIT, "_Quit",
+               "<control>Q", "Quit the application",
                G_CALLBACK (on_action_quit)
        },
        {
-               "About", GTK_STOCK_ABOUT,
-               "_About", NULL, "About this application",
+               "About", GTK_STOCK_ABOUT, "_About",
+               NULL, "About this application",
                G_CALLBACK (on_action_about)
        }
 };
@@ -159,20 +159,14 @@ render_page (RaktWindow *window)
 }
 
 static void
-open_document (RaktWindow *window, gchar *file)
+open_document (RaktWindow *window, gchar *uri)
 {
        RaktWindowPriv *priv;
        GError *error = NULL;
-       gchar real[PATH_MAX], buf[16 + PATH_MAX];
 
        priv = GET_PRIV (window);
 
-       realpath (file, real);
-
-       g_strlcpy (buf, "file://", sizeof (buf));
-       g_strlcat (buf, real, sizeof (buf));
-
-       priv->document = poppler_document_new_from_file (buf, NULL, &error);
+       priv->document = poppler_document_new_from_file (uri, NULL, &error);
 
        priv->page_no = 0;
        render_page (window);
@@ -308,10 +302,11 @@ on_action_open (GtkAction *action, RaktWindow *window)
        n = gtk_dialog_run (GTK_DIALOG (dialog));
 
        if (n == GTK_RESPONSE_ACCEPT) {
-               gchar *file;
+               gchar *uri;
 
-               file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-               open_document (window, file);
+               uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+               open_document (window, uri);
+               g_free (uri);
        }
 
        gtk_widget_destroy (dialog);