~ubuntu-branches/debian/jessie/gpaint/jessie

« back to all changes in this revision

Viewing changes to debian/patches/24_fix_crash_on_failed_write.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Goedson Teixeira Paixao, Matt Wheeler, Goedson Teixeira Paixao
  • Date: 2009-10-30 23:28:02 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091030232802-tfo8zpy0lkk8avfg
Tags: 0.3.3-4
[ Matt Wheeler ] (merged from Ubuntu)
* debian/patches/23_add_accelerator_keys.dpatch:
  added various keyboard shortcuts (LP: #444750) (Closes: #550305)

[ Goedson Teixeira Paixao ]
* debian/patches/24_fix_crash_on_failed_write.dpatch:
  check if is possible to save in the format chosen by the user before
  trying to save. (LP: #386234)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 24_fix_crash_on_failed_write.dpatch by Goedson Teixeira Paixao <goedson@debian.org>
 
3
##
 
4
## DP: Checks if it is possible to save in the format choosen by the user
 
5
## DP: before trying to save.
 
6
 
 
7
@DPATCH@
 
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
 
11
@@ -262,7 +262,7 @@
 
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 */
 
17
     }
 
18
     return saved;
 
19
 }
 
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
 
23
@@ -32,6 +32,7 @@
 
24
 #include <gdk/gdkx.h>  /* for gdk_root_parent */
 
25
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
26
 
 
27
+#define _(String) gettext (String)
 
28
 
 
29
 static int cmp_int(const void *a, const void *b);
 
30
 static void fill_polygon(
 
31
@@ -191,13 +192,48 @@
 
32
     return image;
 
33
 }
 
34
 
 
35
+
 
36
+gboolean
 
37
+is_writable (GSList *formats, gchar *type)
 
38
+{
 
39
+    gboolean writable = FALSE;
 
40
+
 
41
+    while (!writable && formats != NULL)
 
42
+    {
 
43
+        gchar** extensions = gdk_pixbuf_format_get_extensions((GdkPixbufFormat *)(formats->data));
 
44
+        gchar** e = NULL;
 
45
+        for (e = extensions; *e; ++e)
 
46
+        {
 
47
+            if (!strcmp(*e, type))
 
48
+            {
 
49
+                writable = TRUE;
 
50
+                break;
 
51
+            }
 
52
+        }
 
53
+        g_strfreev (extensions);
 
54
+        formats = g_slist_next (formats);
 
55
+    }
 
56
+    return writable;
 
57
+}
 
58
+
 
59
+void add_if_writable (GdkPixbufFormat *data, GSList **list)
 
60
+{
 
61
+  if (gdk_pixbuf_format_is_writable (data))
 
62
+    *list = g_slist_prepend (*list, data);
 
63
+}
 
64
+
 
65
 int
 
66
 image_write(gpaint_image* image, const gchar* filename, GError **perror)
 
67
 {
 
68
     gboolean saved = FALSE;
 
69
     gchar *ext = NULL;
 
70
     gchar *type = NULL;
 
71
-    
 
72
+
 
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);
 
77
+
 
78
     ext = g_strrstr(filename, ".");
 
79
     if (!ext)
 
80
     {
 
81
@@ -214,13 +250,20 @@
 
82
     {
 
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))
 
87
+        {
 
88
+            saved = gdk_pixbuf_save(image->pixbuf, filename, type, perror, NULL);
 
89
+        } else {
 
90
+            saved = FALSE;
 
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);
 
92
+        }
 
93
         g_free(type);
 
94
     }
 
95
     if (!saved && *perror)
 
96
     {
 
97
         g_warning("Could not save image %s: %s\n", filename, (*perror)->message);
 
98
-    }      
 
99
+    }
 
100
+       g_slist_free (writable_formats);
 
101
     return saved;
 
102
 }
 
103