[Xfce4-commits] <parole:bluesabre/gtk3> Better random history

Sean Davis noreply at xfce.org
Sun Aug 11 15:17:44 CEST 2013


Updating branch refs/heads/bluesabre/gtk3
         to 8b800b59d10ef2f579db823d37772a121a1403f6 (commit)
       from 9cdd010af514f12b2999f28196fd0f7b051a371d (commit)

commit 8b800b59d10ef2f579db823d37772a121a1403f6
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Thu May 2 05:29:36 2013 -0400

    Better random history

 src/parole-medialist.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/parole-medialist.c b/src/parole-medialist.c
index d32ed06..fe301bc 100644
--- a/src/parole-medialist.c
+++ b/src/parole-medialist.c
@@ -201,6 +201,8 @@ struct ParoleMediaListPrivate
     GtkWidget *shuffle_button;
 	GtkWidget *settings_button;
 	GtkWidget *n_items;
+	
+	char *history[3];
 };
 
 enum
@@ -1926,6 +1928,7 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list)
     gchar *current_path;
     gchar *path_str;
     gint nch;
+    int count = 0;
 
     nch = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (list->priv->store), NULL);
     
@@ -1937,8 +1940,20 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list)
     current_path = gtk_tree_path_to_string(gtk_tree_row_reference_get_path(parole_media_list_get_selected_row(list)));
     path_str = g_strdup(current_path);
     
-    while (g_strcmp0(current_path, path_str) == 0)
+    if (!list->priv->history[0])
+        list->priv->history[0] = g_strdup(path_str);
+    
+    while (g_strcmp0(list->priv->history[0], path_str) == 0 || g_strcmp0(list->priv->history[1], path_str) == 0 || g_strcmp0(list->priv->history[2], path_str) == 0 || g_strcmp0(current_path, path_str) == 0)
+    {
         path_str = g_strdup_printf ("%i", g_random_int_range (0, nch));
+        count += 1;
+        if (count >= 10 && g_strcmp0(current_path, path_str) != 0)
+            break;
+    }
+        
+    list->priv->history[2] = list->priv->history[1];
+    list->priv->history[1] = list->priv->history[0];
+    list->priv->history[0] = g_strdup(path_str);
     
     path = gtk_tree_path_new_from_string (path_str);
     g_free (path_str);


More information about the Xfce4-commits mailing list