Author: cazfi Date: Fri Mar 6 05:25:37 2015 New Revision: 28425 URL: http://svn.gna.org/viewcvs/freeciv?rev=28425&view=rev Log: Instead of assuming that gtk2-client supports "xpm" and "png", and gtk3-client "png", check the support runtime.
See patch #5736 Modified: trunk/client/gui-gtk-2.0/sprite.c trunk/client/gui-gtk-3.0/sprite.c Modified: trunk/client/gui-gtk-2.0/sprite.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/sprite.c?rev=28425&r1=28424&r2=28425&view=diff ============================================================================== --- trunk/client/gui-gtk-2.0/sprite.c (original) +++ trunk/client/gui-gtk-2.0/sprite.c Fri Mar 6 05:25:37 2015 @@ -24,6 +24,8 @@ #include "colors.h" #include "sprite.h" + +#define MAX_FILE_EXTENSIONS 50 /**************************************************************************** Create a new sprite by cropping and taking only the given portion of @@ -202,12 +204,37 @@ ****************************************************************************/ const char **gfx_fileextensions(void) { - static const char *ext[] = + /* Includes space for termination NULL */ + static const char *ext[MAX_FILE_EXTENSIONS + 1] = { - "png", - "xpm", NULL }; + + if (ext[0] == NULL) { + int count = 0; + GSList *formats = gdk_pixbuf_get_formats(); + GSList *next = formats; + + while ((next = g_slist_next(next)) != NULL && count < MAX_FILE_EXTENSIONS) { + GdkPixbufFormat *format = g_slist_nth_data(next, 0); + gchar **mimes = gdk_pixbuf_format_get_mime_types(format); + int i; + + for (i = 0; mimes[i] != NULL && count < MAX_FILE_EXTENSIONS; i++) { + char *end = strstr(mimes[i], "/"); + + if (end != NULL) { + ext[count++] = fc_strdup(end + 1); + } + } + + g_strfreev(mimes); + } + + g_slist_free(formats); + + ext[count] = NULL; + } return ext; } Modified: trunk/client/gui-gtk-3.0/sprite.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/sprite.c?rev=28425&r1=28424&r2=28425&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/sprite.c (original) +++ trunk/client/gui-gtk-3.0/sprite.c Fri Mar 6 05:25:37 2015 @@ -24,6 +24,8 @@ #include "colors.h" #include "sprite.h" + +#define MAX_FILE_EXTENSIONS 50 /**************************************************************************** Create a new sprite by cropping and taking only the given portion of @@ -107,11 +109,37 @@ ****************************************************************************/ const char **gfx_fileextensions(void) { - static const char *ext[] = + /* Includes space for termination NULL */ + static const char *ext[MAX_FILE_EXTENSIONS + 1] = { - "png", NULL }; + + if (ext[0] == NULL) { + int count = 0; + GSList *formats = gdk_pixbuf_get_formats(); + GSList *next = formats; + + while ((next = g_slist_next(next)) != NULL && count < MAX_FILE_EXTENSIONS) { + GdkPixbufFormat *format = g_slist_nth_data(next, 0); + gchar **mimes = gdk_pixbuf_format_get_mime_types(format); + int i; + + for (i = 0; mimes[i] != NULL && count < MAX_FILE_EXTENSIONS; i++) { + char *end = strstr(mimes[i], "/"); + + if (end != NULL) { + ext[count++] = fc_strdup(end + 1); + } + } + + g_strfreev(mimes); + } + + g_slist_free(formats); + + ext[count] = NULL; + } return ext; } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits