Trim trailing white spaces on empty lines.
[geeqie.git] / src / slideshow.c
index 386acbc..1d7cb97 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -51,7 +51,7 @@ static GList *generate_list(SlideShowData *ss)
 
        if (ss->from_selection)
                {
-               list = layout_selection_list_by_index(ss->layout);
+               list = layout_selection_list_by_index(ss->lw);
                }
        else
                {
@@ -88,7 +88,7 @@ static GPtrArray *generate_ptr_array_from_list(GList *src_list)
 static void swap(GPtrArray *array, guint index1, guint index2)
 {
        gpointer temp = g_ptr_array_index(array, index1);
-       
+
        g_ptr_array_index(array, index1) = g_ptr_array_index(array, index2);
        g_ptr_array_index(array, index2) = temp;
 }
@@ -116,7 +116,7 @@ static GList *generate_random_list(SlideShowData *ss)
        ptr_array_random_shuffle(src_array);
        g_ptr_array_foreach(src_array, (GFunc) list_prepend, &list);
        g_ptr_array_free(src_array, TRUE);
-       
+
        return list;
 }
 
@@ -152,14 +152,17 @@ static void slideshow_list_init(SlideShowData *ss, gint start_index)
                }
 }
 
-gint slideshow_should_continue(SlideShowData *ss)
+gboolean slideshow_should_continue(SlideShowData *ss)
 {
        FileData *imd_fd;
        FileData *dir_fd;
 
        if (!ss) return FALSE;
 
-       imd_fd = image_get_fd(ss->imd);
+       if (ss->lw)
+               imd_fd = layout_image_get_fd(ss->lw);
+       else
+               imd_fd = image_get_fd(ss->imd);
 
        if ( ((imd_fd == NULL) != (ss->slide_fd == NULL)) ||
            (imd_fd && ss->slide_fd && imd_fd != ss->slide_fd) ) return FALSE;
@@ -174,19 +177,18 @@ gint slideshow_should_continue(SlideShowData *ss)
                        return FALSE;
                }
 
-       if (!ss->layout) return FALSE;
-       dir_fd = ss->layout->dir_fd;
+       dir_fd = ss->lw->dir_fd;
 
        if (dir_fd && ss->dir_fd && dir_fd == ss->dir_fd)
                {
-               if (ss->from_selection && ss->slide_count == layout_selection_count(ss->layout, NULL)) return TRUE;
-               if (!ss->from_selection && ss->slide_count == layout_list_count(ss->layout, NULL)) return TRUE;
+               if (ss->from_selection && ss->slide_count == layout_selection_count(ss->lw, NULL)) return TRUE;
+               if (!ss->from_selection && ss->slide_count == layout_list_count(ss->lw, NULL)) return TRUE;
                }
 
        return FALSE;
 }
 
-static gint slideshow_step(SlideShowData *ss, gboolean forward)
+static gboolean slideshow_step(SlideShowData *ss, gboolean forward)
 {
        gint row;
 
@@ -218,7 +220,10 @@ static gint slideshow_step(SlideShowData *ss, gboolean forward)
        if (ss->filelist)
                {
                ss->slide_fd = file_data_ref((FileData *)g_list_nth_data(ss->filelist, row));
-               image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd));
+               if (ss->lw)
+                       layout_set_fd(ss->lw, ss->slide_fd);
+               else
+                       image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd));
                }
        else if (ss->cd)
                {
@@ -227,20 +232,23 @@ static gint slideshow_step(SlideShowData *ss, gboolean forward)
                info = g_list_nth_data(ss->cd->list, row);
                ss->slide_fd = file_data_ref(info->fd);
 
-               image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd));
+               if (ss->lw)
+                       image_change_from_collection(ss->lw->image, ss->cd, info, image_zoom_get_default(ss->lw->image));
+               else
+                       image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd));
                }
        else
                {
-               ss->slide_fd = file_data_ref(layout_list_get_fd(ss->layout, row));
+               ss->slide_fd = file_data_ref(layout_list_get_fd(ss->lw, row));
 
                if (ss->from_selection)
                        {
-                       image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd));
-                       layout_status_update_info(ss->layout, NULL);
+                       layout_set_fd(ss->lw, ss->slide_fd);
+                       layout_status_update_info(ss->lw, NULL);
                        }
                else
                        {
-                       layout_image_set_index(ss->layout, row);
+                       layout_image_set_index(ss->lw, row);
                        }
                }
 
@@ -255,8 +263,7 @@ static gint slideshow_step(SlideShowData *ss, gboolean forward)
                }
 
        /* read ahead */
-
-       if (options->image.enable_read_ahead)
+       if (options->image.enable_read_ahead && (!ss->lw || ss->from_selection))
                {
                gint r;
                if (forward)
@@ -282,14 +289,14 @@ static gint slideshow_step(SlideShowData *ss, gboolean forward)
                        }
                else if (ss->from_selection)
                        {
-                       image_prebuffer_set(ss->imd, layout_list_get_fd(ss->layout, r));
+                       image_prebuffer_set(ss->lw->image, layout_list_get_fd(ss->lw, r));
                        }
                }
 
        return TRUE;
 }
 
-static gint slideshow_loop_cb(gpointer data)
+static gboolean slideshow_loop_cb(gpointer data)
 {
        SlideShowData *ss = data;
 
@@ -297,7 +304,7 @@ static gint slideshow_loop_cb(gpointer data)
 
        if (!slideshow_step(ss, TRUE))
                {
-               ss->timeout_id = -1;
+               ss->timeout_id = 0;
                slideshow_free(ss);
                return FALSE;
                }
@@ -307,17 +314,17 @@ static gint slideshow_loop_cb(gpointer data)
 
 static void slideshow_timer_stop(SlideShowData *ss)
 {
-       if (ss->timeout_id == -1) return;
+       if (!ss->timeout_id) return;
 
        g_source_remove(ss->timeout_id);
-       ss->timeout_id = -1;
+       ss->timeout_id = 0;
 }
 
 static void slideshow_timer_reset(SlideShowData *ss)
 {
        if (options->slideshow.delay < 1) options->slideshow.delay = 1;
 
-       if (ss->timeout_id != -1) g_source_remove(ss->timeout_id);
+       if (ss->timeout_id) g_source_remove(ss->timeout_id);
        ss->timeout_id = g_timeout_add(options->slideshow.delay * 1000 / SLIDESHOW_SUBSECOND_PRECISION,
                                       slideshow_loop_cb, ss);
 }
@@ -345,7 +352,7 @@ void slideshow_prev(SlideShowData *ss)
        slideshow_move(ss, FALSE);
 }
 
-static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw,
+static SlideShowData *real_slideshow_start(LayoutWindow *target_lw, ImageWindow *imd,
                                           GList *filelist, gint start_point,
                                           CollectionData *cd, CollectInfo *start_info,
                                           void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data)
@@ -353,26 +360,14 @@ static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw,
        SlideShowData *ss;
        gint start_index = -1;
 
-       if (!filelist && !cd && layout_list_count(lw, NULL) < 1) return NULL;
+       if (!filelist && !cd && layout_list_count(target_lw, NULL) < 1) return NULL;
 
        ss = g_new0(SlideShowData, 1);
 
-       ss->imd = imd;
-
+       ss->lw = target_lw;
+       ss->imd = imd; /* FIXME: ss->imd is used only for img-view.c and can be dropped with it */
        ss->filelist = filelist;
        ss->cd = cd;
-       ss->layout = lw;
-       ss->dir_fd = NULL;
-
-       ss->list = NULL;
-       ss->list_done = NULL;
-
-       ss->from_selection = FALSE;
-
-       ss->stop_func = NULL;
-
-       ss->timeout_id = -1;
-       ss->paused = FALSE;
 
        if (ss->filelist)
                {
@@ -391,11 +386,11 @@ static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw,
                {
                /* layout method */
 
-               ss->slide_count = layout_selection_count(ss->layout, NULL);
-               ss->dir_fd = file_data_ref(ss->layout->dir_fd);
+               ss->slide_count = layout_selection_count(ss->lw, NULL);
+               ss->dir_fd = file_data_ref(ss->lw->dir_fd);
                if (ss->slide_count < 2)
                        {
-                       ss->slide_count = layout_list_count(ss->layout, NULL);
+                       ss->slide_count = layout_list_count(ss->lw, NULL);
                        if (!options->slideshow.random && start_point >= 0 && (guint) start_point < ss->slide_count)
                                {
                                start_index = start_point;
@@ -409,7 +404,11 @@ static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw,
 
        slideshow_list_init(ss, start_index);
 
-       ss->slide_fd = file_data_ref(image_get_fd(ss->imd));
+       if (ss->lw)
+               ss->slide_fd = file_data_ref(layout_image_get_fd(ss->lw));
+       else
+               ss->slide_fd = file_data_ref(image_get_fd(ss->imd));
+
        if (slideshow_step(ss, TRUE))
                {
                slideshow_timer_reset(ss);
@@ -426,40 +425,40 @@ static SlideShowData *real_slideshow_start(ImageWindow *imd, LayoutWindow *lw,
        return ss;
 }
 
-SlideShowData *slideshow_start_from_filelist(ImageWindow *imd, GList *list,
+SlideShowData *slideshow_start_from_filelist(LayoutWindow *target_lw, ImageWindow *imd, GList *list,
                                              void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data)
 {
-       return real_slideshow_start(imd, NULL, list, -1, NULL, NULL, stop_func, stop_data);
+       return real_slideshow_start(target_lw, imd, list, -1, NULL, NULL, stop_func, stop_data);
 }
 
-SlideShowData *slideshow_start_from_collection(ImageWindow *imd, CollectionData *cd,
+SlideShowData *slideshow_start_from_collection(LayoutWindow *target_lw, ImageWindow *imd, CollectionData *cd,
                                               void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data,
                                               CollectInfo *start_info)
 {
-       return real_slideshow_start(imd, NULL, NULL, -1, cd, start_info, stop_func, stop_data);
+       return real_slideshow_start(target_lw, imd, NULL, -1, cd, start_info, stop_func, stop_data);
 }
 
-SlideShowData *slideshow_start(ImageWindow *imd, LayoutWindow *lw, gint start_point,
+SlideShowData *slideshow_start(LayoutWindow *lw, gint start_point,
                               void (*stop_func)(SlideShowData *, gpointer), gpointer stop_data)
 {
-       return real_slideshow_start(imd, lw, NULL, start_point, NULL, NULL, stop_func, stop_data);
+       return real_slideshow_start(lw, NULL, NULL, start_point, NULL, NULL, stop_func, stop_data);
 }
 
-gint slideshow_paused(SlideShowData *ss)
+gboolean slideshow_paused(SlideShowData *ss)
 {
        if (!ss) return FALSE;
 
        return ss->paused;
 }
 
-void slideshow_pause_set(SlideShowData *ss, gint paused)
+void slideshow_pause_set(SlideShowData *ss, gboolean paused)
 {
        if (!ss) return;
 
        ss->paused = paused;
 }
 
-gint slideshow_pause_toggle(SlideShowData *ss)
+gboolean slideshow_pause_toggle(SlideShowData *ss)
 {
        slideshow_pause_set(ss, !slideshow_paused(ss));
        return slideshow_paused(ss);