Updating branch refs/heads/0.5
         to 95f32035b80c1ba8d06a7006d922560ce83ae432 (commit)
       from 4f17bbef7315210f8022926427dd2935de1f5629 (commit)

commit 95f32035b80c1ba8d06a7006d922560ce83ae432
Author: Sean Davis <smd.seanda...@gmail.com>
Date:   Tue Oct 29 23:58:58 2013 -0400

    Make remove-duplicates work again

 src/parole-medialist.c |   67 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 15 deletions(-)

diff --git a/src/parole-medialist.c b/src/parole-medialist.c
index 85aad22..f63eadd 100644
--- a/src/parole-medialist.c
+++ b/src/parole-medialist.c
@@ -260,31 +260,67 @@ parole_media_list_add (ParoleMediaList *list, ParoleFile 
*file, gboolean disc, g
     GtkTreeIter iter;
     gint nch;
     
+    /* Objects used for the remove-duplicates functionality. */
+    gchar *filename;
+    ParoleFile *row_file;
+    gboolean remove_duplicates;
+    g_object_get (G_OBJECT (list->priv->conf),
+                  "remove-duplicated", &remove_duplicates,
+                  NULL);
+    
+    /* Set the list_store variable based on with store we're viewing. */
     if (disc)
         list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW 
(list->priv->disc_view)));
     else
         list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW 
(list->priv->view)));
+        
+    /* Remove duplicates functionality. If the file being added is already in 
the
+     * playlist, remove it from its current position in the playlist before
+     * adding it again. */
+    if (!disc && remove_duplicates && gtk_tree_model_iter_n_children 
(GTK_TREE_MODEL(list_store), NULL) != 0)
+    {
+        filename = g_strdup(parole_file_get_file_name(file));
+                
+        /* Check the first row */
+        gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
+        gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, DATA_COL, 
&row_file, -1);
+        if (g_strcmp0(filename, parole_file_get_file_name(row_file)) == 0)
+        {
+            gtk_list_store_remove (GTK_LIST_STORE(list_store), &iter);
+        }
+        
+        /* Check subsequent rows */
+        while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)) {
+            gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, DATA_COL, 
&row_file, -1);
+            if (g_strcmp0(filename, parole_file_get_file_name(row_file)) == 0)
+            {
+                gtk_list_store_remove (GTK_LIST_STORE(list_store), &iter);
+            }
+        }
+        
+        g_object_unref(row_file);
+    }
     
+    /* Add the file to the playlist */
     gtk_list_store_append (list_store, &iter);
-    
     gtk_list_store_set (list_store, 
-                       &iter, 
-                       NAME_COL, parole_file_get_display_name (file),
-                       DATA_COL, file,
-                       LENGTH_COL, parole_taglibc_get_media_length (file),
-                       PIXBUF_COL, NULL,
-                       -1);
+                        &iter, 
+                        NAME_COL, parole_file_get_display_name (file),
+                        DATA_COL, file,
+                        LENGTH_COL, parole_taglibc_get_media_length (file),
+                        PIXBUF_COL, NULL,
+                        -1);
     
     if ( emit || select_row )
     {
-       path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_store), &iter);
-       row = gtk_tree_row_reference_new (GTK_TREE_MODEL (list_store), path);
-       if ( select_row )
-           parole_media_list_select_path (list, disc, path);
-       gtk_tree_path_free (path);
-       if ( emit )
-           g_signal_emit (G_OBJECT (list), signals [MEDIA_ACTIVATED], 0, row);
-       gtk_tree_row_reference_free (row);
+        path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_store), &iter);
+        row = gtk_tree_row_reference_new (GTK_TREE_MODEL (list_store), path);
+        if ( select_row )
+            parole_media_list_select_path (list, disc, path);
+        gtk_tree_path_free (path);
+        if ( emit )
+            g_signal_emit (G_OBJECT (list), signals [MEDIA_ACTIVATED], 0, row);
+        gtk_tree_row_reference_free (row);
     }
   
     /*
@@ -293,6 +329,7 @@ parole_media_list_add (ParoleMediaList *list, ParoleFile 
*file, gboolean disc, g
      */
     g_object_unref (file);
     
+    /* Update the playlist count. */    
     if (disc)
     nch = gtk_tree_model_iter_n_children (GTK_TREE_MODEL 
(list->priv->disc_store), NULL); 
     else
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to