Fix building with --enable-debug-flags
[geeqie.git] / src / layout_image.c
index 570f77b..deada81 100644 (file)
@@ -283,6 +283,7 @@ static void image_animation_data_free(AnimationData *fd)
        if(!fd) return;
        if(fd->iter) g_object_unref(fd->iter);
        if(fd->gpa) g_object_unref(fd->gpa);
+       if(fd->cancellable) g_object_unref(fd->cancellable);
        g_free(fd);
 }
 
@@ -347,6 +348,10 @@ static gboolean layout_image_animate_check(LayoutWindow *lw)
                if(lw->animation)
                        {
                        lw->animation->valid = FALSE;
+                       if (lw->animation->cancellable)
+                               {
+                               g_cancellable_cancel(lw->animation->cancellable);
+                               }
                        lw->animation = NULL;
                        }
                return FALSE;
@@ -368,32 +373,84 @@ static void layout_image_animate_update_image(LayoutWindow *lw)
                }
 }
 
+
+static void animation_async_ready_cb(GObject *source_object, GAsyncResult *res, gpointer data)
+{
+       GError *error = NULL;
+       AnimationData *animation = data;
+
+       if (animation)
+               {
+               if (g_cancellable_is_cancelled(animation->cancellable))
+                       {
+                       gdk_pixbuf_animation_new_from_stream_finish(res, NULL);
+                       g_object_unref(animation->in_file);
+                       g_object_unref(animation->gfstream);
+                       image_animation_data_free(animation);
+                       return;
+                       }
+
+               animation->gpa = gdk_pixbuf_animation_new_from_stream_finish(res, &error);
+               if (animation->gpa)
+                       {
+                       if (!gdk_pixbuf_animation_is_static_image(animation->gpa))
+                               {
+                               animation->iter = gdk_pixbuf_animation_get_iter(animation->gpa, NULL);
+                               if (animation->iter)
+                                       {
+                                       animation->data_adr = animation->lw->image->image_fd;
+                                       animation->delay = gdk_pixbuf_animation_iter_get_delay_time(animation->iter);
+                                       animation->valid = TRUE;
+
+                                       layout_image_animate_update_image(animation->lw);
+
+                                       g_timeout_add(animation->delay, show_next_frame, animation);
+                                       }
+                               }
+                       }
+               else
+                       {
+                       log_printf("Error reading GIF file: %s\n", error->message);
+                       }
+
+               g_object_unref(animation->in_file);
+               g_object_unref(animation->gfstream);
+               }
+}
+
 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
 {
-       GError *err=NULL;
+       GFileInputStream *gfstream;
+       GError *error = NULL;
+       AnimationData *animation;
+       GFile *in_file;
 
        if(!layout_image_animate_check(lw)) return FALSE;
 
        if(lw->animation) lw->animation->valid = FALSE;
 
-       lw->animation = g_malloc0(sizeof(AnimationData));
-
-       if(!(lw->animation->gpa = gdk_pixbuf_animation_new_from_file(lw->image->image_fd->path,&err)) || err ||
-               gdk_pixbuf_animation_is_static_image(lw->animation->gpa) ||
-               !(lw->animation->iter = gdk_pixbuf_animation_get_iter(lw->animation->gpa,NULL)))
+       if (lw->animation)
                {
-               image_animation_data_free(lw->animation);
-               lw->animation = NULL;
-               return FALSE;
+               g_cancellable_cancel(lw->animation->cancellable);
                }
 
-       lw->animation->data_adr = lw->image->image_fd;
-       lw->animation->delay = gdk_pixbuf_animation_iter_get_delay_time(lw->animation->iter);
-       lw->animation->valid = TRUE;
+       animation = g_new0(AnimationData, 1);
+       lw->animation = animation;
+       animation->lw = lw;
+       animation->cancellable = g_cancellable_new();
 
-       layout_image_animate_update_image(lw);
-
-       g_timeout_add(lw->animation->delay, show_next_frame, lw->animation);
+       in_file = g_file_new_for_path(lw->image->image_fd->path);
+       animation->in_file = in_file;
+       gfstream = g_file_read(in_file, NULL, &error);
+       if (gfstream)
+               {
+               animation->gfstream = gfstream;
+               gdk_pixbuf_animation_new_from_stream_async((GInputStream*)gfstream, animation->cancellable, animation_async_ready_cb, animation);
+               }
+       else
+               {
+               log_printf("Error reading GIF file: %s\nError: %s\n", lw->image->image_fd->path, error->message);
+               }
 
        return TRUE;
 }
@@ -459,13 +516,6 @@ static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
        file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
 }
 
-static void li_pop_menu_wallpaper_cb(GtkWidget *widget, gpointer data)
-{
-       LayoutWindow *lw = data;
-
-       layout_image_to_root(lw);
-}
-
 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
@@ -804,6 +854,7 @@ static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *context,
 {
        LayoutWindow *lw = data;
        gint i;
+       gchar *url;
 
 
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
@@ -817,8 +868,13 @@ static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *context,
                layout_image_activate(lw, i, FALSE);
                }
 
-
-       if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
+       if (info == TARGET_TEXT_PLAIN)
+               {
+               url = g_strdup((gchar *)gtk_selection_data_get_data(selection_data));
+               download_web_file(url, FALSE, lw);
+               g_free(url);
+               }
+       else if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
                {
                CollectionData *source;
                GList *list;
@@ -1231,6 +1287,28 @@ gboolean layout_image_get_desaturate(LayoutWindow *lw)
        return image_get_desaturate(lw->image);
 }
 
+void layout_image_set_overunderexposed(LayoutWindow *lw, gboolean overunderexposed)
+{
+       if (!layout_valid(&lw)) return;
+
+       image_set_overunderexposed(lw->image, overunderexposed);
+}
+
+gboolean layout_image_get_overunderexposed(LayoutWindow *lw)
+{
+       if (!layout_valid(&lw)) return FALSE;
+
+       return image_get_overunderexposed(lw->image);
+}
+
+void layout_image_set_ignore_alpha(LayoutWindow *lw, gboolean ignore_alpha)
+{
+   if (!layout_valid(&lw)) return;
+
+   lw->options.ignore_alpha = ignore_alpha;
+   image_set_ignore_alpha(lw->image, ignore_alpha);
+}
+
 /* stereo */
 /*
 gint layout_image_stereo_get(LayoutWindow *lw)
@@ -1323,6 +1401,11 @@ void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
        layout_image_slideshow_continue_check(lw);
        layout_bars_new_image(lw);
        layout_image_animate_new_file(lw);
+
+       if (fd)
+               {
+               image_chain_append_end(fd->path);
+               }
 }
 
 void layout_image_set_with_ahead(LayoutWindow *lw, FileData *fd, FileData *read_ahead_fd)
@@ -1722,7 +1805,6 @@ static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpoi
 {
        LayoutWindow *lw = data;
        GtkWidget *menu;
-       FileData *dir_fd;
 
        switch (event->button)
                {
@@ -1746,16 +1828,6 @@ static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpoi
                                }
                        gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
                        break;
-               case MOUSE_BUTTON_BACK:
-                       dir_fd = file_data_new_dir(history_chain_back());
-                       layout_set_fd(lw, dir_fd);
-                       file_data_unref(dir_fd);
-                       break;
-               case MOUSE_BUTTON_FORWARD:
-                       dir_fd = file_data_new_dir(history_chain_forward());
-                       layout_set_fd(lw, dir_fd);
-                       file_data_unref(dir_fd);
-                       break;
                default:
                        break;
                }
@@ -2056,7 +2128,7 @@ void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
        layout_image_set_buttons(lw);
        image_set_drag_func(lw->image, layout_image_drag_cb, lw);
 
-       image_attach_window(lw->image, lw->window, NULL, GQ_APPNAME, FALSE);
+       image_attach_window(lw->image, lw->window, NULL, g_strcmp0(lw->options.id, "main") == 0 ? GQ_APPNAME : GQ_APPNAME_LC, FALSE);
 
        /* do not hilight selected image in SPLIT_NONE */
        /* maybe the image should be selected always and hilight should be controled by