Commit a8c234d8 authored by Bruno Coudoin's avatar Bruno Coudoin

Fixed a crash in an image missing callback in image_selector

Added a new api entry to load an image and get a NULL return
if not found instead of the default 1x1 pixmap.

svn path=/branches/gcomprixogoo/; revision=3736
parent 524efe8b
......@@ -105,7 +105,7 @@ void gc_dialog(gchar *str, DialogBoxCallBack dbcb)
"#BUTTON_TEXT",
_("OK"),
(GtkSignalFunc) item_event_ok,
"ok");
dbcb);
}
/* Callback for the bar operations */
......
......@@ -60,7 +60,8 @@ static const guint8 null_img[] __attribute__ ((__aligned__ (4))) =
/* pixel_data: */
"%%%\0"};
/** load a pixmap from the filesystem
/** load a pixmap from the filesystem, return NULL if
* not found and do not display an error message.
*
* \param format: If format contains $LOCALE, it will be first replaced by the current long locale
* and if not found the short locale name. It support printf formating.
......@@ -68,7 +69,7 @@ static const guint8 null_img[] __attribute__ ((__aligned__ (4))) =
*
* \return a new allocated pixbuf or NULL
*/
GdkPixbuf *gc_pixmap_load(const gchar *format, ...)
GdkPixbuf *gc_pixmap_load_or_null(const gchar *format, ...)
{
va_list args;
gchar *filename;
......@@ -88,6 +89,42 @@ GdkPixbuf *gc_pixmap_load(const gchar *format, ...)
if(filename)
pixmap = gc_net_load_pixmap(filename);
g_free(pixmapfile);
g_free(filename);
return(pixmap);
}
/** load a pixmap from the filesystem, if not found display
* an error message and return an small 1x1 pixmap.
*
* \param format: If format contains $LOCALE, it will be first replaced by the current long locale
* and if not found the short locale name. It support printf formating.
* \param ...: additional params for the format (printf like)
*
* \return a new allocated pixbuf or a 1x1 pixmap
*/
GdkPixbuf *gc_pixmap_load(const gchar *format, ...)
{
va_list args;
gchar *filename;
gchar *pixmapfile;
GdkPixbuf *pixmap=NULL;
if (!format)
return NULL;
va_start (args, format);
pixmapfile = g_strdup_vprintf (format, args);
va_end (args);
/* Search */
filename = gc_file_find_absolute(pixmapfile);
if(filename)
pixmap = gc_pixmap_load_or_null(filename);
if (!filename || !pixmap)
{
char *str;
......
......@@ -69,6 +69,7 @@ gchar *g_utf8_strndup(gchar*,gint);
gchar *reactivate_newline(char *str);
GdkPixbuf *gc_pixmap_load(const gchar *filename, ...);
GdkPixbuf *gc_pixmap_load_or_null(const gchar *format, ...);
RsvgHandle *gc_rsvg_load(const gchar *format, ...);
void gc_item_focus_init(GooCanvasItem *source_item,
GooCanvasItem *target_item);
......
......@@ -319,7 +319,7 @@ display_image(gchar *imagename, GooCanvasItem *root_item)
if (imagename==NULL || !images_selector_displayed)
return;
pixmap = gc_pixmap_load(imagename);
pixmap = gc_pixmap_load_or_null(imagename);
/* Sad, the image is not found */
if(!pixmap)
......@@ -376,7 +376,9 @@ display_image_set(gchar *imagename, GSList *imagelist)
if (imagename == NULL || !images_selector_displayed)
return;
pixmap = gc_pixmap_load(imagename);
pixmap = gc_pixmap_load_or_null(imagename);
if (!pixmap)
return;
iw = LIST_IMAGE_WIDTH * gc_zoom_factor_get();
ih = LIST_IMAGE_HEIGHT * gc_zoom_factor_get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment