From 770be272db84f069e2f5317ca5b5a5d0570fa5da Mon Sep 17 00:00:00 2001 From: Julien Sopik Date: Fri, 2 Sep 2016 17:46:01 +0200 Subject: [PATCH 1/2] Fix bug 12010. Add a control on a new variable, n_shuffled_items, to insure that (almost) all items are played only once when Shuffle mode is enabled. TODO: Restore the Repeat mode when both Shuffle and Repeat modes are enabled. --- src/parole-medialist.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/parole-medialist.c b/src/parole-medialist.c index 7f26b3a..b7dad86 100644 --- a/src/parole-medialist.c +++ b/src/parole-medialist.c @@ -181,6 +181,10 @@ struct ParoleMediaListPrivate GtkWidget *shuffle_button; char *history[3]; + /* + * n_shuffled_items stores the number of already shuffled items in the list. + */ + guint n_shuffled_items; }; enum @@ -1848,11 +1852,26 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list) return NULL; } + if (nch == list->priv->n_shuffled_items) + { + /* Stop playing since (almost) every items in the list have been chosen */ + list->priv->n_shuffled_items = 0; + return NULL; + } + 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); if (!list->priv->history[0]) + { list->priv->history[0] = g_strdup(path_str); + } + + if (list->priv->n_shuffled_items == 0) + { + list->priv->n_shuffled_items = 1; + } + 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) { @@ -1872,6 +1891,7 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list) if ( gtk_tree_model_get_iter (GTK_TREE_MODEL (list->priv->store), &iter, path)) { row = gtk_tree_row_reference_new (GTK_TREE_MODEL (list->priv->store), path); + list->priv->n_shuffled_items += 1; } gtk_tree_path_free (path); -- 2.7.4 From 859ef9185862950aaa85406daa6694e755ebb0e9 Mon Sep 17 00:00:00 2001 From: Julien Sopik Date: Fri, 2 Sep 2016 17:58:21 +0200 Subject: [PATCH 2/2] Fix bug 12010. Recover the Repeat mode when Shuffle is on by setting n_shuffled_items to the special value -1. Update the value of n_shuffled_items whenever Repeat or Shuffle buttons are toggled to insure consistency between the modes. --- src/parole-medialist.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/parole-medialist.c b/src/parole-medialist.c index b7dad86..b0517ef 100644 --- a/src/parole-medialist.c +++ b/src/parole-medialist.c @@ -183,8 +183,10 @@ struct ParoleMediaListPrivate char *history[3]; /* * n_shuffled_items stores the number of already shuffled items in the list. + * The special value -1 is only used when Repeat mode is on to skip the + * control process on this variable. */ - guint n_shuffled_items; + gint n_shuffled_items; }; enum @@ -1849,10 +1851,10 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list) if ( nch == 1 || nch == 0 ) { - return NULL; + return NULL; } - - if (nch == list->priv->n_shuffled_items) + + if (nch == list->priv->n_shuffled_items && list->priv->n_shuffled_items != -1) { /* Stop playing since (almost) every items in the list have been chosen */ list->priv->n_shuffled_items = 0; @@ -1864,15 +1866,14 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list) if (!list->priv->history[0]) { - list->priv->history[0] = g_strdup(path_str); + list->priv->history[0] = g_strdup(path_str); } - + if (list->priv->n_shuffled_items == 0) { list->priv->n_shuffled_items = 1; } - 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)); @@ -1891,7 +1892,10 @@ GtkTreeRowReference *parole_media_list_get_row_random (ParoleMediaList *list) if ( gtk_tree_model_get_iter (GTK_TREE_MODEL (list->priv->store), &iter, path)) { row = gtk_tree_row_reference_new (GTK_TREE_MODEL (list->priv->store), path); - list->priv->n_shuffled_items += 1; + if (list->priv->n_shuffled_items != -1) + { + list->priv->n_shuffled_items += 1; + } } gtk_tree_path_free (path); @@ -2200,6 +2204,22 @@ void parole_media_list_grab_focus (ParoleMediaList *list) gtk_widget_grab_focus (list->priv->view); } +void +update_media_list_n_shuffled_items(void) +{ + gboolean repeat = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(media_list->priv->repeat_button)); + if (repeat) + { + /* Disable the control on the number of shuffled items in case of randomization */ + media_list->priv->n_shuffled_items = -1; + } + else + { + /* Enable the control on the number of shuffled items in case of randomization */ + media_list->priv->n_shuffled_items = 0; + } +} + static void repeat_action_state_changed (GSimpleAction *simple, GVariant *value, gpointer user_data) { @@ -2209,6 +2229,8 @@ repeat_action_state_changed (GSimpleAction *simple, GVariant *value, gpointer us { gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(media_list->priv->repeat_button), active); } + + update_media_list_n_shuffled_items(); } static void @@ -2230,11 +2252,13 @@ static void shuffle_action_state_changed (GSimpleAction *simple, GVariant *value, gpointer user_data) { gboolean active = g_simple_toggle_action_get_active(simple); - + if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(media_list->priv->shuffle_button)) != active) { gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(media_list->priv->shuffle_button), active); } + + update_media_list_n_shuffled_items(); } static void @@ -2251,3 +2275,4 @@ void parole_media_list_connect_shuffle_action (ParoleMediaList *list, GSimpleAct /* Connect changed event to modify action */ g_signal_connect(G_OBJECT(list->priv->shuffle_button), "clicked", G_CALLBACK(shuffle_toggled), simple); } + -- 2.7.4