Author: cazfi
Date: Fri Mar  6 05:25:47 2015
New Revision: 28426

URL: http://svn.gna.org/viewcvs/freeciv?rev=28426&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:
    branches/S2_6/client/gui-gtk-2.0/sprite.c
    branches/S2_6/client/gui-gtk-3.0/sprite.c

Modified: branches/S2_6/client/gui-gtk-2.0/sprite.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/sprite.c?rev=28426&r1=28425&r2=28426&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/sprite.c   (original)
+++ branches/S2_6/client/gui-gtk-2.0/sprite.c   Fri Mar  6 05:25:47 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: branches/S2_6/client/gui-gtk-3.0/sprite.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/sprite.c?rev=28426&r1=28425&r2=28426&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/sprite.c   (original)
+++ branches/S2_6/client/gui-gtk-3.0/sprite.c   Fri Mar  6 05:25:47 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

Reply via email to