[eog] Make it possible to select a random image from the collection



commit 9221716bc34aa8cf78293b89160920260018fe48
Author: Quinten Lansu <knight666 gmail com>
Date:   Fri Feb 5 15:54:05 2010 +0100

    Make it possible to select a random image from the collection
    
    This allows the user to crawl randomly through his collection.
    Patch posted to eog-list:
    http://mail.gnome.org/archives/eog-list/2009-December/msg00003.html

 src/eog-thumb-view.c |    9 +++++++++
 src/eog-thumb-view.h |    3 ++-
 src/eog-window.c     |   21 +++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/src/eog-thumb-view.c b/src/eog-thumb-view.c
index 73c9600..b3a4962 100644
--- a/src/eog-thumb-view.c
+++ b/src/eog-thumb-view.c
@@ -816,6 +816,10 @@ eog_thumb_view_select_single (EogThumbView *thumbview,
 		case EOG_THUMB_VIEW_SELECT_LEFT:
 		case EOG_THUMB_VIEW_SELECT_LAST:
 			path = gtk_tree_path_new_from_indices (n_items - 1, -1);
+			break;
+		case EOG_THUMB_VIEW_SELECT_RANDOM:
+			path = gtk_tree_path_new_from_indices ((int)(((float)(n_items - 1) * rand()) / (float)(RAND_MAX + 1.f)), -1);
+			break;
 		}
 	} else {
 		list = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (thumbview));
@@ -849,6 +853,11 @@ eog_thumb_view_select_single (EogThumbView *thumbview,
 		case EOG_THUMB_VIEW_SELECT_LAST:
 			gtk_tree_path_free (path);
 			path = gtk_tree_path_new_from_indices (n_items - 1, -1);
+			break;
+		case EOG_THUMB_VIEW_SELECT_RANDOM:
+			gtk_tree_path_free (path);
+			path = gtk_tree_path_new_from_indices ((int)(((float)(n_items - 1) * rand()) / (float)(RAND_MAX + 1.f)), -1);
+			break;
 		}
 	}
 
diff --git a/src/eog-thumb-view.h b/src/eog-thumb-view.h
index 48015c2..74a4d9e 100644
--- a/src/eog-thumb-view.h
+++ b/src/eog-thumb-view.h
@@ -43,7 +43,8 @@ typedef enum {
 	EOG_THUMB_VIEW_SELECT_LEFT,
 	EOG_THUMB_VIEW_SELECT_RIGHT,
 	EOG_THUMB_VIEW_SELECT_FIRST,
-	EOG_THUMB_VIEW_SELECT_LAST
+	EOG_THUMB_VIEW_SELECT_LAST,
+	EOG_THUMB_VIEW_SELECT_RANDOM
 } EogThumbViewSelectionChange;
 
 struct _EogThumbView {
diff --git a/src/eog-window.c b/src/eog-window.c
index bade485..c3a1297 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -3732,6 +3732,21 @@ eog_window_cmd_go_last (GtkAction *action, gpointer user_data)
 				      EOG_THUMB_VIEW_SELECT_LAST);
 }
 
+static void
+eog_window_cmd_go_random (GtkAction *action, gpointer user_data)
+{
+	EogWindowPrivate *priv;
+
+	g_return_if_fail (EOG_IS_WINDOW (user_data));
+
+	eog_debug (DEBUG_WINDOW);
+
+	priv = EOG_WINDOW (user_data)->priv;
+
+	eog_thumb_view_select_single (EOG_THUMB_VIEW (priv->thumbview),
+				      EOG_THUMB_VIEW_SELECT_RANDOM);
+}
+
 static const GtkActionEntry action_entries_window[] = {
 	{ "File",  NULL, N_("_File") },
 	{ "Edit",  NULL, N_("_Edit") },
@@ -3861,6 +3876,9 @@ static const GtkActionEntry action_entries_collection[] = {
 	{ "GoLast", GTK_STOCK_GOTO_LAST, N_("_Last Image"), "<Alt>End",
 	  N_("Go to the last image of the collection"),
 	  G_CALLBACK (eog_window_cmd_go_last) },
+	{ "GoRandom", GTK_STOCK_JUMP_TO, N_("Random Image"), "<control>M",
+	  N_("Go to the a random image in the collection"),
+	  G_CALLBACK (eog_window_cmd_go_random) },
 	{ "BackSpace", NULL, N_("_Previous Image"), "BackSpace",
 	  NULL,
 	  G_CALLBACK (eog_window_cmd_go_prev) },
@@ -3947,6 +3965,9 @@ set_action_properties (GtkActionGroup *window_group,
         g_object_set (action, "short_label", _("Next"), NULL);
         g_object_set (action, "is-important", TRUE, NULL);
 
+	action = gtk_action_group_get_action (collection_group, "GoRandom");
+	g_object_set (action, "short_label", _("Random image"), NULL);
+
         action = gtk_action_group_get_action (image_group, "EditRotate90");
         g_object_set (action, "short_label", _("Right"), NULL);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]