Addl fix #299: File Compression and Archiving
[geeqie.git] / src / layout_image.c
index cfe0661..949b817 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "main.h"
 #include "color-man.h"
 #include "dnd.h"
 #include "editors.h"
+#include "exif.h"
 #include "filedata.h"
 #include "fullscreen.h"
+#include "history_list.h"
 #include "image.h"
 #include "image-overlay.h"
 #include "img-view.h"
 #include "layout.h"
 #include "layout_util.h"
 #include "menu.h"
+#include "metadata.h"
 #include "misc.h"
 #include "pixbuf_util.h"
 #include "pixbuf-renderer.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
+#define FILE_COLUMN_POINTER 0
 
 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
 static void layout_image_set_buttons(LayoutWindow *lw);
+static gboolean layout_image_animate_new_file(LayoutWindow *lw);
+static void layout_image_animate_update_image(LayoutWindow *lw);
 
 /*
  *----------------------------------------------------------------------------
@@ -64,7 +79,8 @@ static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data
        LayoutWindow *lw = data;
 
        /* restore image window */
-       lw->image = fs->normal_imd;
+       if (lw->image == fs->imd)
+               lw->image = fs->normal_imd;
 
        lw->full_screen = NULL;
 }
@@ -79,7 +95,8 @@ void layout_image_full_screen_start(LayoutWindow *lw)
                                           layout_image_full_screen_stop_func, lw);
 
        /* set to new image window */
-       lw->image = lw->full_screen->imd;
+       if (lw->full_screen->same_region)
+               lw->image = lw->full_screen->imd;
 
        layout_image_set_buttons(lw);
 
@@ -87,12 +104,9 @@ void layout_image_full_screen_start(LayoutWindow *lw)
                         G_CALLBACK(layout_key_press_cb), lw);
 
        layout_actions_add_window(lw, lw->full_screen->window);
-#if 0
-       gtk_widget_set_sensitive(lw->window, FALSE);
-       if (lw->tools) gtk_widget_set_sensitive(lw->tools, FALSE);
-#endif
 
        image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
+       layout_image_animate_update_image(lw);
 }
 
 void layout_image_full_screen_stop(LayoutWindow *lw)
@@ -100,14 +114,12 @@ void layout_image_full_screen_stop(LayoutWindow *lw)
        if (!layout_valid(&lw)) return;
        if (!lw->full_screen) return;
 
-       image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
+       if (lw->image == lw->full_screen->imd)
+               image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
 
        fullscreen_stop(lw->full_screen);
 
-#if 0
-       gtk_widget_set_sensitive(lw->window, TRUE);
-       if (lw->tools) gtk_widget_set_sensitive(lw->tools, TRUE);
-#endif
+       layout_image_animate_update_image(lw);
 }
 
 void layout_image_full_screen_toggle(LayoutWindow *lw)
@@ -260,6 +272,203 @@ static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
        return TRUE;
 }
 
+/*
+ *----------------------------------------------------------------------------
+ * Animation
+ *----------------------------------------------------------------------------
+ */
+
+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);
+}
+
+static gboolean animation_should_continue(AnimationData *fd)
+{
+       if (!fd->valid)
+               return FALSE;
+
+       return TRUE;
+}
+
+static gboolean show_next_frame(gpointer data)
+{
+       AnimationData *fd = (AnimationData*)data;
+       int delay;
+       PixbufRenderer *pr;
+
+       if(animation_should_continue(fd)==FALSE)
+               {
+               image_animation_data_free(fd);
+               return FALSE;
+               }
+
+       pr = (PixbufRenderer*)fd->iw->pr;
+
+       if (gdk_pixbuf_animation_iter_advance(fd->iter,NULL)==FALSE)
+               {
+               /* This indicates the animation is complete.
+                  Return FALSE here to disable looping. */
+               }
+
+       fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
+       image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
+
+       if (fd->iw->func_update)
+               fd->iw->func_update(fd->iw, fd->iw->data_update);
+
+       delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
+       if (delay!=fd->delay)
+               {
+               if (delay>0) /* Current frame not static. */
+                       {
+                       fd->delay=delay;
+                       g_timeout_add(delay,show_next_frame,fd);
+                       }
+               else
+                       {
+                       image_animation_data_free(fd);
+                       }
+               return FALSE;
+               }
+
+       return TRUE;
+}
+
+static gboolean layout_image_animate_check(LayoutWindow *lw)
+{
+       if (!layout_valid(&lw)) return FALSE;
+
+       if(!lw->options.animate || lw->image->image_fd == NULL || lw->image->image_fd->extension == NULL || g_ascii_strcasecmp(lw->image->image_fd->extension,".GIF")!=0)
+               {
+               if(lw->animation)
+                       {
+                       lw->animation->valid = FALSE;
+                       if (lw->animation->cancellable)
+                               {
+                               g_cancellable_cancel(lw->animation->cancellable);
+                               }
+                       lw->animation = NULL;
+                       }
+               return FALSE;
+               }
+
+       return TRUE;
+}
+
+static void layout_image_animate_update_image(LayoutWindow *lw)
+{
+       if (!layout_valid(&lw)) return;
+
+       if(lw->options.animate && lw->animation)
+               {
+               if (lw->full_screen && lw->image != lw->full_screen->imd)
+                       lw->animation->iw = lw->full_screen->imd;
+               else
+                       lw->animation->iw = lw->image;
+               }
+}
+
+
+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)
+{
+       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;
+
+       if (lw->animation)
+               {
+               g_cancellable_cancel(lw->animation->cancellable);
+               }
+
+       animation = g_new0(AnimationData, 1);
+       lw->animation = animation;
+       animation->lw = lw;
+       animation->cancellable = g_cancellable_new();
+
+       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;
+}
+
+void layout_image_animate_toggle(LayoutWindow *lw)
+{
+       GtkAction *action;
+
+       if (!lw) return;
+
+       lw->options.animate = !lw->options.animate;
+
+       action = gtk_action_group_get_action(lw->action_group, "Animate");
+       gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
+
+       layout_image_animate_new_file(lw);
+}
+
 /*
  *----------------------------------------------------------------------------
  * pop-up menus
@@ -307,12 +516,14 @@ 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);
 }
 
+#if !GTK_CHECK_VERSION(3,0,0)
 static void li_pop_menu_wallpaper_cb(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
 
        layout_image_to_root(lw);
 }
+#endif
 
 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
 {
@@ -322,7 +533,7 @@ static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
        lw = submenu_item_get_data(widget);
        type = (AlterType)GPOINTER_TO_INT(data);
 
-       image_alter_orientation(lw->image, type);
+       image_alter_orientation(lw->image, lw->image->image_fd, type);
 }
 
 static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data)
@@ -362,7 +573,25 @@ static void li_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
 
-       file_util_copy_path_to_clipboard(layout_image_get_fd(lw));
+       file_util_copy_path_to_clipboard(layout_image_get_fd(lw), TRUE);
+}
+
+static void li_pop_menu_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+
+       file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE);
+}
+
+static void li_pop_menu_copy_image_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+       ImageWindow *imd = lw->image;
+
+       GdkPixbuf *pixbuf;
+       pixbuf = image_get_pixbuf(imd);
+       if (!pixbuf) return;
+       gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
 }
 
 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
@@ -385,6 +614,16 @@ static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
 
+       options->file_ops.safe_delete_enable = FALSE;
+       file_util_delete(layout_image_get_fd(lw), NULL,
+                        li_pop_menu_click_parent(widget, lw));
+}
+
+static void li_pop_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+
+       options->file_ops.safe_delete_enable = TRUE;
        file_util_delete(layout_image_get_fd(lw), NULL,
                         li_pop_menu_click_parent(widget, lw));
 }
@@ -417,6 +656,13 @@ static void li_pop_menu_full_screen_cb(GtkWidget *widget, gpointer data)
        layout_image_full_screen_toggle(lw);
 }
 
+static void li_pop_menu_animate_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+
+       layout_image_animate_toggle(lw);
+}
+
 static void li_pop_menu_hide_cb(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
@@ -435,6 +681,27 @@ static void li_set_layout_path_cb(GtkWidget *widget, gpointer data)
        if (fd) layout_set_fd(lw, fd);
 }
 
+static void li_open_archive_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+       LayoutWindow *lw_new;
+       gchar *dest_dir;
+
+       if (!layout_valid(&lw)) return;
+
+       dest_dir = open_archive(layout_image_get_fd(lw));
+       if (dest_dir)
+               {
+               lw_new = layout_new_from_default();
+               layout_set_path(lw_new, dest_dir);
+               g_free(dest_dir);
+               }
+       else
+               {
+               warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GTK_STOCK_DIALOG_WARNING, NULL);
+               }
+}
+
 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
 {
        gchar *dirname;
@@ -468,10 +735,29 @@ static GList *layout_image_get_fd_list(LayoutWindow *lw)
                else
                        list = g_list_append(NULL, file_data_ref(fd));
                }
-       
+
        return list;
 }
 
+/**
+ * @brief Add file selection list to a collection
+ * @param[in] widget 
+ * @param[in] data Index to the collection list menu item selected, or -1 for new collection
+ * 
+ * 
+ */
+static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw;
+       GList *selection_list = NULL;
+
+       lw = submenu_item_get_data(widget);
+       selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
+       pop_menu_collections(selection_list, data);
+
+       filelist_free(selection_list);
+}
+
 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
 {
        GtkWidget *menu;
@@ -498,8 +784,9 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
        submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
        if (!path) gtk_widget_set_sensitive(item, FALSE);
        menu_item_add_divider(submenu);
+#if !GTK_CHECK_VERSION(3,0,0)
        menu_item_add(submenu, _("Set as _wallpaper"), G_CALLBACK(li_pop_menu_wallpaper_cb), lw);
-
+#endif
        item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
 
        item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
@@ -508,6 +795,12 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
        item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
        if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
 
+       item = menu_item_add_stock(menu, _("Open archive"), GTK_STOCK_OPEN, G_CALLBACK(li_open_archive_cb), lw);
+       if (!path || lw->image->image_fd->format_class != FORMAT_CLASS_ARCHIVE)
+               {
+               gtk_widget_set_sensitive(item, FALSE);
+               }
+
        menu_item_add_divider(menu);
 
        item = menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
@@ -516,12 +809,27 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
        if (!path) gtk_widget_set_sensitive(item, FALSE);
        item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
        if (!path) gtk_widget_set_sensitive(item, FALSE);
-       item = menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(li_pop_menu_delete_cb), lw);
-       if (!path) gtk_widget_set_sensitive(item, FALSE);
-       
        item = menu_item_add(menu, _("_Copy path"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
+       item = menu_item_add(menu, _("_Copy path unquoted"), G_CALLBACK(li_pop_menu_copy_path_unquoted_cb), lw);
+       item = menu_item_add(menu, _("Copy _image"), G_CALLBACK(li_pop_menu_copy_image_cb), lw);
+       if (!path) gtk_widget_set_sensitive(item, FALSE);
+       menu_item_add_divider(menu);
+
+       item = menu_item_add_stock(menu,
+                               options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
+                                       _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH,
+                                                               G_CALLBACK(li_pop_menu_move_to_trash_cb), lw);
+       if (!path) gtk_widget_set_sensitive(item, FALSE);
+       item = menu_item_add_stock(menu,
+                               options->file_ops.confirm_delete ? _("_Delete...") :
+                                       _("_Delete"), GTK_STOCK_DELETE,
+                                                               G_CALLBACK(li_pop_menu_delete_cb), lw);
        if (!path) gtk_widget_set_sensitive(item, FALSE);
+       menu_item_add_divider(menu);
 
+       submenu = submenu_add_collections(menu, &item,
+                               G_CALLBACK(layout_pop_menu_collections_cb), lw);
+       gtk_widget_set_sensitive(item, TRUE);
        menu_item_add_divider(menu);
 
        if (layout_image_slideshow_active(lw))
@@ -554,6 +862,8 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
                menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
                }
 
+       menu_item_add_check(menu, _("_Animate"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
+
        menu_item_add_divider(menu);
 
        item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
@@ -567,7 +877,7 @@ static void layout_image_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *
 {
        LayoutWindow *lw = data;
 
-       gdk_window_get_origin(lw->image->pr->window, x, y);
+       gdk_window_get_origin(gtk_widget_get_window(lw->image->pr), x, y);
        popup_menu_position_clamp(menu, x, y, 0);
 }
 
@@ -592,6 +902,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++)
@@ -605,8 +916,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;
@@ -614,13 +930,13 @@ static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *context,
 
                if (info == TARGET_URI_LIST)
                        {
-                       list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
+                       list = uri_filelist_from_gtk_selection_data(selection_data);
                        source = NULL;
                        info_list = NULL;
                        }
                else
                        {
-                       source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
+                       source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list);
                        }
 
                if (list)
@@ -692,34 +1008,15 @@ static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *context,
 
        if (fd)
                {
-               gchar *text = NULL;
-               gint len;
-               gboolean plain_text;
                GList *list;
 
-               switch (info)
-                       {
-                       case TARGET_URI_LIST:
-                               plain_text = FALSE;
-                               break;
-                       case TARGET_TEXT_PLAIN:
-                       default:
-                               plain_text = TRUE;
-                               break;
-                       }
                list = g_list_append(NULL, fd);
-               text = uri_text_from_filelist(list, &len, plain_text);
+               uri_selection_data_set_uris_from_filelist(selection_data, list);
                g_list_free(list);
-               if (text)
-                       {
-                       gtk_selection_data_set(selection_data, selection_data->target,
-                                              8, (guchar *)text, len);
-                       g_free(text);
-                       }
                }
        else
                {
-               gtk_selection_data_set(selection_data, selection_data->target,
+               gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
                                       8, NULL, 0);
                }
 }
@@ -727,7 +1024,7 @@ static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *context,
 static void layout_image_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
 {
        LayoutWindow *lw = data;
-       if (context->action == GDK_ACTION_MOVE)
+       if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
                {
                FileData *fd;
                gint row;
@@ -797,12 +1094,17 @@ void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scro
 
        image_scroll(lw->image, x, y);
 
+       if (lw->full_screen && lw->image != lw->full_screen->imd)
+               {
+               image_scroll(lw->full_screen->imd, x, y);
+               }
+
        if (!connect_scroll) return;
 
        image_get_image_size(lw->image, &width, &height);
        dx = (gdouble) x / width;
        dy = (gdouble) y / height;
-       
+
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
                {
                if (lw->split_images[i] && lw->split_images[i] != lw->image)
@@ -824,6 +1126,11 @@ void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean conn
 
        image_zoom_adjust(lw->image, increment);
 
+       if (lw->full_screen && lw->image != lw->full_screen->imd)
+               {
+               image_zoom_adjust(lw->full_screen->imd, increment);
+               }
+
        if (!connect_zoom) return;
 
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
@@ -840,11 +1147,16 @@ void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint
 
        image_zoom_adjust_at_point(lw->image, increment, x, y);
 
-       if (!connect_zoom) return;
+       if (lw->full_screen && lw->image != lw->full_screen->imd)
+               {
+               image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
+               }
+       if (!connect_zoom && !lw->split_mode) return;
 
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
                {
-               if (lw->split_images[i] && lw->split_images[i] != lw->image)
+               if (lw->split_images[i] && lw->split_images[i] != lw->image &&
+                                               lw->split_images[i]->mouse_wheel_mode)
                        image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
                }
 }
@@ -856,6 +1168,11 @@ void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom
 
        image_zoom_set(lw->image, zoom);
 
+       if (lw->full_screen && lw->image != lw->full_screen->imd)
+               {
+               image_zoom_set(lw->full_screen->imd, zoom);
+               }
+
        if (!connect_zoom) return;
 
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
@@ -872,6 +1189,11 @@ void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gb
 
        image_zoom_set_fill_geometry(lw->image, vertical);
 
+       if (lw->full_screen && lw->image != lw->full_screen->imd)
+               {
+               image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
+               }
+
        if (!connect_zoom) return;
 
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
@@ -885,7 +1207,125 @@ void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
 {
        if (!layout_valid(&lw)) return;
 
-       image_alter_orientation(lw->image, type);
+       GtkTreeModel *store;
+       GList *work;
+       GtkTreeSelection *selection;
+       GtkTreePath *tpath;
+       FileData *fd_n;
+       GtkTreeIter iter;
+
+       if (!lw || !lw->vf) return;
+
+       if (lw->vf->type == FILEVIEW_ICON)
+               {
+               if (!VFICON(lw->vf)->selection) return;
+               work = VFICON(lw->vf)->selection;
+               }
+       else
+               {
+               selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
+               work = gtk_tree_selection_get_selected_rows(selection, &store);
+               }
+
+       while (work)
+               {
+               if (lw->vf->type == FILEVIEW_ICON)
+                       {
+                       fd_n = work->data;
+                       work = work->next;
+                       }
+               else
+                       {
+                       tpath = work->data;
+                       gtk_tree_model_get_iter(store, &iter, tpath);
+                       gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
+                       work = work->next;
+                       }
+
+               image_alter_orientation(lw->image, fd_n, type);
+               }
+}
+
+static void image_alter_rating(FileData *fd_n, const gchar *rating)
+{
+       metadata_write_string(fd_n, RATING_KEY, rating);
+       read_rating_data(fd_n);
+}
+
+void layout_image_rating(LayoutWindow *lw, const gchar *rating)
+{
+       if (!layout_valid(&lw)) return;
+
+       GtkTreeModel *store;
+       GList *work;
+       GtkTreeSelection *selection;
+       GtkTreePath *tpath;
+       FileData *fd_n;
+       GtkTreeIter iter;
+
+       if (!lw || !lw->vf) return;
+
+       if (lw->vf->type == FILEVIEW_ICON)
+               {
+               if (!VFICON(lw->vf)->selection) return;
+               work = VFICON(lw->vf)->selection;
+               }
+       else
+               {
+               selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
+               work = gtk_tree_selection_get_selected_rows(selection, &store);
+               }
+
+       while (work)
+               {
+               if (lw->vf->type == FILEVIEW_ICON)
+                       {
+                       fd_n = work->data;
+                       work = work->next;
+                       }
+               else
+                       {
+                       tpath = work->data;
+                       gtk_tree_model_get_iter(store, &iter, tpath);
+                       gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
+                       work = work->next;
+                       }
+
+               image_alter_rating(fd_n, rating);
+               }
+}
+
+void layout_image_reset_orientation(LayoutWindow *lw)
+{
+       ImageWindow *imd= lw->image;
+
+       if (!layout_valid(&lw)) return;
+       if (!imd || !imd->pr || !imd->image_fd) return;
+
+       if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
+
+       if (options->image.exif_rotate_enable)
+               {
+               if (g_strcmp0(imd->image_fd->format_name, "heif") != 0)
+                       {
+                       imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
+                       }
+               else
+                       {
+                       imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
+                       }
+               }
+       else
+               {
+               imd->orientation = 1;
+               }
+
+       if (imd->image_fd->user_orientation != 0)
+               {
+                imd->orientation = imd->image_fd->user_orientation;
+               }
+
+       pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
 }
 
 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
@@ -902,6 +1342,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)
@@ -984,9 +1446,21 @@ void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
 
        image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));
 
+       if (lw->full_screen && lw->image != lw->full_screen->imd)
+               {
+               image_change_fd(lw->full_screen->imd, fd, image_zoom_get_default(lw->full_screen->imd));
+               }
+
+
        layout_list_sync_fd(lw, 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)
@@ -1178,7 +1652,12 @@ void layout_image_next(LayoutWindow *lw)
                        if (y->next)
                                layout_image_set_index(lw, GPOINTER_TO_INT(y->next->data));
                        else
-                               layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
+                               {
+                               if (options->circular_selection_lists)
+                                       {
+                                       layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
+                                       }
+                               }
                        }
                while (x)
                        x = g_list_remove(x, x->data);
@@ -1251,7 +1730,12 @@ void layout_image_prev(LayoutWindow *lw)
                        if (y->prev)
                                layout_image_set_index(lw, GPOINTER_TO_INT(y->prev->data));
                        else
-                               layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
+                               {
+                               if (options->circular_selection_lists)
+                                       {
+                                       layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
+                                       }
+                               }
                        }
                while (x)
                        x = g_list_remove(x, x->data);
@@ -1386,15 +1870,35 @@ static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpoi
 {
        LayoutWindow *lw = data;
        GtkWidget *menu;
+       LayoutWindow *lw_new;
+       gchar *dest_dir;
 
        switch (event->button)
                {
                case MOUSE_BUTTON_LEFT:
-                       if (lw->split_mode == SPLIT_NONE)
+                       if (options->image_l_click_archive && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_ARCHIVE)
+                               {
+                               dest_dir = open_archive(imd->image_fd);
+                               if (dest_dir)
+                                       {
+                                       lw_new = layout_new_from_default();
+                                       layout_set_path(lw_new, dest_dir);
+                                       g_free(dest_dir);
+                                       }
+                               else
+                                       {
+                                       warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GTK_STOCK_DIALOG_WARNING, NULL);
+                                       }
+                               }
+                       else if (options->image_l_click_video && options->image_l_click_video_editor && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_VIDEO)
+                               {
+                               start_editor_from_file(options->image_l_click_video_editor, imd->image_fd);
+                               }
+                       else if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
                                layout_image_next(lw);
                        break;
                case MOUSE_BUTTON_MIDDLE:
-                       if (lw->split_mode == SPLIT_NONE)
+                       if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
                                layout_image_prev(lw);
                        break;
                case MOUSE_BUTTON_RIGHT:
@@ -1423,7 +1927,8 @@ static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpoi
                }
 
 
-       if (event->state & GDK_CONTROL_MASK)
+       if ((event->state & GDK_CONTROL_MASK) ||
+                               (imd->mouse_wheel_mode && !options->image_lm_click_nav))
                {
                switch (event->direction)
                        {
@@ -1473,10 +1978,27 @@ static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpoi
                }
 }
 
-static void layout_image_drag_cb(ImageWindow *imd, GdkEventButton *event, gdouble dx, gdouble dy, gpointer data)
+static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
 {
        gint i;
        LayoutWindow *lw = data;
+       gdouble sx, sy;
+
+       if (lw->full_screen && lw->image != lw->full_screen->imd &&
+           imd != lw->full_screen->imd)
+               {
+               if (event->state & GDK_CONTROL_MASK)
+                       {
+                       image_get_scroll_center(imd, &sx, &sy);
+                       }
+               else
+                       {
+                       image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
+                       sx += dx;
+                       sy += dy;
+                       }
+               image_set_scroll_center(lw->full_screen->imd, sx, sy);
+               }
 
        if (!(event->state & GDK_SHIFT_MASK)) return;
 
@@ -1484,7 +2006,6 @@ static void layout_image_drag_cb(ImageWindow *imd, GdkEventButton *event, gdoubl
                {
                if (lw->split_images[i] && lw->split_images[i] != imd)
                        {
-                       gdouble sx, sy;
 
                        if (event->state & GDK_CONTROL_MASK)
                                {
@@ -1528,7 +2049,7 @@ static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *ev
 
 }
 
-static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventButton *event, gdouble dx, gdouble dy, gpointer data)
+static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
 {
        LayoutWindow *lw = data;
        gint i = image_idx(lw, imd);
@@ -1583,19 +2104,19 @@ void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
        if (width < 1 || height < 1) return;
 
        pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
-       
+
        if(x_pixel >= 0 && y_pixel >= 0)
                {
                gint r_mouse, g_mouse, b_mouse;
-                       
+
                pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
-                                                &r_mouse, &g_mouse, &b_mouse);                 
-               
+                                                &r_mouse, &g_mouse, &b_mouse);
+
                text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
                                         num_length(width - 1), x_pixel,
                                         num_length(height - 1), y_pixel,
                                         r_mouse, g_mouse, b_mouse);
-               
+
                }
        else
                {
@@ -1633,11 +2154,7 @@ GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
                {
                lw->split_images[i] = image_new(TRUE);
 
-#if GTK_CHECK_VERSION(2,12,0)
                g_object_ref(lw->split_images[i]->widget);
-#else
-               gtk_widget_ref(lw->split_images[i]->widget);
-#endif
 
                g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
                                 G_CALLBACK(layout_status_update_pixel_cb), lw);
@@ -1694,8 +2211,8 @@ void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
 
        image_attach_window(lw->image, lw->window, NULL, GQ_APPNAME, FALSE);
 
-       /* do not hilight selected image in SPLIT_NONE */
-       /* maybe the image should be selected always and hilight should be controled by
+       /* do not highlight selected image in SPLIT_NONE */
+       /* maybe the image should be selected always and highlight should be controlled by
           another image option */
        if (lw->split_mode != SPLIT_NONE)
                image_select(lw->split_images[i], TRUE);
@@ -1709,6 +2226,7 @@ void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
 //             layout_list_sync_path(lw, path);
                layout_set_fd(lw, fd);
                }
+       layout_status_update_image(lw);
 }
 
 
@@ -1726,7 +2244,7 @@ static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
                        layout_image_new(lw, i);
                        image_set_frame(lw->split_images[i], frame);
                        image_set_selectable(lw->split_images[i], (n > 1));
-                       
+
                        if (lw->image)
                                {
                                image_osd_copy_status(lw->image, lw->split_images[i]);
@@ -1736,17 +2254,20 @@ static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
                                {
                                GList *work = g_list_last(layout_selection_list(lw));
                                gint j = 0;
-                               
-                               if (work) work = work->prev;
 
                                while (work && j < i)
                                        {
                                        FileData *fd = work->data;
                                        work = work->prev;
-                                       
-                                       j++;
-                                       if (!fd || !*fd->path) continue;
+
+                                       if (!fd || !*fd->path || fd->parent ||
+                                                                               fd == lw->split_images[0]->image_fd)
+                                               {
+                                               continue;
+                                               }
                                        img_fd = fd;
+
+                                       j++;
                                        }
                                }
 
@@ -1775,15 +2296,11 @@ static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
                {
                if (lw->split_images[i])
                        {
-#if GTK_CHECK_VERSION(2,12,0)
                        g_object_unref(lw->split_images[i]->widget);
-#else
-                       gtk_widget_unref(lw->split_images[i]->widget);
-#endif
                        lw->split_images[i] = NULL;
                        }
                }
-       
+
        if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
                {
                layout_image_activate(lw, 0, TRUE);
@@ -1799,7 +2316,7 @@ static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
 {
        lw->split_mode = SPLIT_NONE;
-       
+
        layout_image_setup_split_common(lw, 1);
 
        lw->split_image_widget = lw->split_images[0]->widget;
@@ -1811,16 +2328,22 @@ GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
 {
        GtkWidget *paned;
-       
+
        lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
 
        layout_image_setup_split_common(lw, 2);
 
        /* horizontal split means vpaned and vice versa */
        if (horizontal)
+               {
                paned = gtk_vpaned_new();
+               DEBUG_NAME(paned);
+               }
        else
+               {
                paned = gtk_hpaned_new();
+               DEBUG_NAME(paned);
+               }
 
        gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
        gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
@@ -1846,8 +2369,11 @@ GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
        layout_image_setup_split_common(lw, 4);
 
        hpaned = gtk_hpaned_new();
+       DEBUG_NAME(hpaned);
        vpaned1 = gtk_vpaned_new();
+       DEBUG_NAME(vpaned1);
        vpaned2 = gtk_vpaned_new();
+       DEBUG_NAME(vpaned2);
 
        gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
        gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
@@ -1923,8 +2449,8 @@ static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
                                }
                        layout_image_set_fd(lw, NULL);
                        }
-                       
-               /* the image will be set to the next image from the list soon,  
+
+               /* the image will be set to the next image from the list soon,
                   setting it to NULL here is not necessary*/
                }
 }
@@ -1937,7 +2463,7 @@ void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
        if (!(type & NOTIFY_CHANGE) || !fd->change) return;
 
        DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
-       
+
        switch (fd->change->type)
                {
                case FILEDATA_CHANGE_MOVE: