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

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

    Better random history

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

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);
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to