1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 24_fix_crash_on_failed_write.dpatch by Goedson Teixeira Paixao <goedson@debian.org>
4
## DP: Checks if it is possible to save in the format choosen by the user
5
## DP: before trying to save.
8
diff -urNad gpaint~/src/drawing.c gpaint/src/drawing.c
9
--- gpaint~/src/drawing.c 2009-10-29 20:00:21.000000000 -0200
10
+++ gpaint/src/drawing.c 2009-10-29 22:50:32.925445266 -0200
12
(error && error->message) ? error->message : "");
13
gtk_dialog_run(GTK_DIALOG(dialog));
14
gtk_widget_destroy(GTK_WIDGET(dialog));
15
- g_free(error); /* allocated by gdk-pixbuf library */
16
+ g_error_free(error); /* allocated by gdk-pixbuf library */
20
diff -urNad gpaint~/src/image.c gpaint/src/image.c
21
--- gpaint~/src/image.c 2009-10-29 20:00:21.000000000 -0200
22
+++ gpaint/src/image.c 2009-10-29 22:50:32.937443439 -0200
24
#include <gdk/gdkx.h> /* for gdk_root_parent */
25
#include <gdk-pixbuf/gdk-pixbuf.h>
27
+#define _(String) gettext (String)
29
static int cmp_int(const void *a, const void *b);
30
static void fill_polygon(
37
+is_writable (GSList *formats, gchar *type)
39
+ gboolean writable = FALSE;
41
+ while (!writable && formats != NULL)
43
+ gchar** extensions = gdk_pixbuf_format_get_extensions((GdkPixbufFormat *)(formats->data));
45
+ for (e = extensions; *e; ++e)
47
+ if (!strcmp(*e, type))
53
+ g_strfreev (extensions);
54
+ formats = g_slist_next (formats);
59
+void add_if_writable (GdkPixbufFormat *data, GSList **list)
61
+ if (gdk_pixbuf_format_is_writable (data))
62
+ *list = g_slist_prepend (*list, data);
66
image_write(gpaint_image* image, const gchar* filename, GError **perror)
68
gboolean saved = FALSE;
73
+ GSList *formats = gdk_pixbuf_get_formats ();
74
+ GSList *writable_formats = NULL;
75
+ g_slist_foreach (formats, add_if_writable, &writable_formats);
76
+ g_slist_free (formats);
78
ext = g_strrstr(filename, ".");
83
type = g_ascii_strdown(ext+1,-1);
84
debug1("type=[%s]",type);
85
- saved = gdk_pixbuf_save(image->pixbuf, filename, type, perror, NULL);
86
+ if (is_writable (writable_formats, type))
88
+ saved = gdk_pixbuf_save(image->pixbuf, filename, type, perror, NULL);
91
+ *perror = g_error_new (GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_BAD_OPTION, _("Saving in the '%s' format is not supported by gdk_pixbuf"), type);
95
if (!saved && *perror)
97
g_warning("Could not save image %s: %s\n", filename, (*perror)->message);
100
+ g_slist_free (writable_formats);