2008-09-17 [colin] 3.5.0cvs112
[claws.git] / src / image_viewer.c
index b6150799f6f5a3fa44c2487cbc0bda5e2956bb3b..73120d448fb365ecff237449cfd993106eeac683 100644 (file)
@@ -69,7 +69,8 @@ static GtkWidget *image_viewer_get_widget(MimeViewer *_mimeviewer)
 
 static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfile)
 {
-       GdkPixbuf *pixbuf;
+       GdkPixbufAnimation *animation = NULL;
+       GdkPixbuf *pixbuf = NULL;
        gint avail_width;
        gint avail_height;
        GError *error = NULL;
@@ -77,7 +78,7 @@ static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfil
        debug_print("image_viewer_show_mimepart\n");
 
        if (!imageviewer->resize_img) {
-               pixbuf = gdk_pixbuf_new_from_file(imgfile, &error);
+               animation = gdk_pixbuf_animation_new_from_file(imgfile, &error);
        } else {
                gint w, h;
                gdk_pixbuf_get_file_info(imgfile, &w, &h);
@@ -86,40 +87,31 @@ static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfil
                if (avail_width > 8) avail_width -= 8;
                if (avail_height > 8) avail_height -= 8;
                if (avail_width - 100 > 0 &&
-                   (w > avail_width || h > avail_height))
+                   (w > avail_width || h > avail_height)) {
                        pixbuf = gdk_pixbuf_new_from_file_at_scale(imgfile, avail_width,
                                avail_height, TRUE, &error);
-               else
-                       pixbuf = gdk_pixbuf_new_from_file(imgfile, &error);
+               } else {
+                       animation = gdk_pixbuf_animation_new_from_file(imgfile, &error);
+               }
        }
 
-       if (error) {
+       if (error && !pixbuf && !animation) {
                gtk_label_set_text(GTK_LABEL(imageviewer->error_lbl), _("Error:"));
                gtk_label_set_text(GTK_LABEL(imageviewer->error_msg), error->message);
                gtk_notebook_set_current_page(GTK_NOTEBOOK(imageviewer->notebook), 0);
                gtk_widget_hide(imageviewer->load_button);
                g_error_free(error);
        }
-       if (!pixbuf) {
+       if (!pixbuf && !animation) {
                g_warning("Can't load the image.");     
                return;
        }
 
-       if (!imageviewer->image && !imageviewer->resize_img) {
-               imageviewer->image = gtk_image_new();
-
-               gtk_scrolled_window_add_with_viewport
-                       (GTK_SCROLLED_WINDOW(imageviewer->scrolledwin),
-                        imageviewer->image);
+       if (animation)
+               gtk_image_set_from_animation(GTK_IMAGE(imageviewer->image), animation);
+       else
                gtk_image_set_from_pixbuf(GTK_IMAGE(imageviewer->image), pixbuf);
-       }
-       else {
-               imageviewer->image = gtk_image_new_from_file(imgfile);
-               gtk_scrolled_window_add_with_viewport
-                       (GTK_SCROLLED_WINDOW(imageviewer->scrolledwin),
-                        imageviewer->image);
-       }
-       
+
        g_signal_handlers_block_by_func(G_OBJECT(imageviewer->scrolledwin), 
                         G_CALLBACK(scrolledwin_resize_cb), imageviewer);
 
@@ -129,7 +121,10 @@ static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfil
        g_signal_handlers_unblock_by_func(G_OBJECT(imageviewer->scrolledwin), 
                         G_CALLBACK(scrolledwin_resize_cb), imageviewer);
 
-       g_object_unref(pixbuf);
+       if (pixbuf)
+               g_object_unref(pixbuf);
+       if (animation)
+               g_object_unref(animation);
 }
 
 static void image_viewer_set_notebook_page(MimeViewer *_mimeviewer)
@@ -189,11 +184,6 @@ static void image_viewer_clear_viewer(MimeViewer *_mimeviewer)
 
        image_viewer_set_notebook_page(_mimeviewer);
 
-       if (imageviewer->image != NULL) {
-               gtk_widget_destroy(imageviewer->image);
-               imageviewer->image = NULL;
-       }
-
        if (imageviewer->scrolledwin) {
                hadj = gtk_scrolled_window_get_hadjustment
                        (GTK_SCROLLED_WINDOW(imageviewer->scrolledwin));
@@ -390,7 +380,10 @@ static MimeViewer *image_viewer_create(void)
        imageviewer->resize_img   = prefs_common.resize_img;
 
        imageviewer->scrolledwin  = scrolledwin;
-       imageviewer->image        = NULL;
+       imageviewer->image = gtk_image_new();
+       gtk_scrolled_window_add_with_viewport
+               (GTK_SCROLLED_WINDOW(imageviewer->scrolledwin),
+                imageviewer->image);
        imageviewer->notebook     = notebook;
        imageviewer->filename     = filename;
        imageviewer->filesize     = filesize;