]> www.fi.muni.cz Git - evince.git/commitdiff
Check all extensions when saving an image to avoid adding the extension twice
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 30 Jan 2011 12:25:11 +0000 (13:25 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 30 Jan 2011 12:27:25 +0000 (13:27 +0100)
Fixes bug #637461.

shell/ev-window.c

index af8a83f364a151a68652b221a8b2ab3d84b244fa..3c41017d46c141b4d1d1f2981acc8fa468516b40 100644 (file)
@@ -6300,6 +6300,30 @@ ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
                                   ev_action);
 }
 
+static GFile *
+create_file_from_uri_for_format (const gchar     *uri,
+                                GdkPixbufFormat *format)
+{
+       GFile  *target_file;
+       gchar **extensions;
+       gchar  *uri_extension;
+       gint    i;
+
+       extensions = gdk_pixbuf_format_get_extensions (format);
+       for (i = 0; extensions[i]; i++) {
+               if (g_str_has_suffix (uri, extensions[i])) {
+                       g_strfreev (extensions);
+                       return g_file_new_for_uri (uri);
+               }
+       }
+
+       uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
+       target_file = g_file_new_for_uri (uri_extension);
+       g_free (uri_extension);
+       g_strfreev (extensions);
+
+       return target_file;
+}
 
 static void
 image_save_dialog_response_cb (GtkWidget *fc,
@@ -6311,7 +6335,6 @@ image_save_dialog_response_cb (GtkWidget *fc,
        GError          *error = NULL;
        GdkPixbuf       *pixbuf;
        gchar           *uri;
-       gchar          **extensions;
        gchar           *filename;
        gchar           *file_format;
        GdkPixbufFormat *format;
@@ -6349,19 +6372,9 @@ image_save_dialog_response_cb (GtkWidget *fc,
                return;
        }
 
-       extensions = gdk_pixbuf_format_get_extensions (format);
-       if (!g_str_has_suffix (uri, extensions[0])) {
-               gchar *uri_extension;
-               
-               uri_extension = g_strconcat (uri, ".", extensions[0], NULL);
-               target_file = g_file_new_for_uri (uri_extension);
-               g_free (uri_extension);
-       } else {
-               target_file = g_file_new_for_uri (uri);
-       }
-       g_strfreev (extensions);
+       target_file = create_file_from_uri_for_format (uri, format);
        g_free (uri);
-       
+
        is_native = g_file_is_native (target_file);
        if (is_native) {
                filename = g_file_get_path (target_file);