From 8635a64057ad87a944fc12fc09040c3347d57c4a Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 4 Jan 2007 21:47:38 +0000 Subject: [PATCH] Fixed [ 1628085 ] PNG file not created/not recognized by WINXP, where the actual problem was that Windows defaults to not displaying extensions >< --- src/dialogs/export.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp index 387474485..80aaf9c91 100644 --- a/src/dialogs/export.cpp +++ b/src/dialogs/export.cpp @@ -8,8 +8,9 @@ * Authors: * Lauris Kaplinski * bulia byak + * Johan Engelen * - * Copyright (C) 1999-2005 Authors + * Copyright (C) 1999-2007 Authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -1124,6 +1125,31 @@ sp_export_export_clicked (GtkButton *button, GtkObject *base) return; } // end of sp_export_export_clicked() + +// FIXME: Some lib function should be available to do this ... +static gchar * +filename_add_extension (const gchar *filename, const gchar *extension) +{ + gchar *dot; + + dot = strrchr (filename, '.'); + if ( !dot ) + return g_strconcat (filename, ".", extension, NULL); + { + if (dot[1] == '\0') + return g_strconcat (filename, extension, NULL); + else + { + if (g_strncasecmp (dot + 1, extension,-1) == 0) + return g_strdup (filename); + else + { + return g_strconcat (filename, ".", extension, NULL); + } + } + } +} + /// Called when Browse button is clicked static void sp_export_browse_clicked (GtkButton *button, gpointer userdata) @@ -1157,11 +1183,16 @@ sp_export_browse_clicked (GtkButton *button, gpointer userdata) gchar *file; file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs)); - gchar * utf8file = g_filename_to_utf8( file, -1, NULL, NULL, NULL ); + // make sure that .png is the extension of the file: + gchar * file_ext = filename_add_extension(file, "png"); + + gchar * utf8file = g_filename_to_utf8( file_ext, -1, NULL, NULL, NULL ); gtk_entry_set_text (GTK_ENTRY (fe), utf8file); - g_free(utf8file); g_object_set_data (G_OBJECT (dlg), "filename", fe); + + g_free(file_ext); + g_free(utf8file); g_free(file); } -- 2.39.5