changeset 840:ffc5ab7b4b2c trunk

[svn] added a 'remove duplicates' option to the playlist removal menu
author giacomo
date Sat, 18 Mar 2006 07:34:43 -0800
parents 247d1f58fbfe
children b2e62b6c452b
files audacious/playlist.c audacious/playlist.h audacious/ui_playlist.c
diffstat 3 files changed, 67 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/audacious/playlist.c	Fri Mar 17 20:07:11 2006 -0800
+++ b/audacious/playlist.c	Sat Mar 18 07:34:43 2006 -0800
@@ -2206,6 +2206,63 @@
     playlist_recalc_total_time();
 }
 
+void
+playlist_remove_duplicates(void)
+{
+    GList *node, *next_node;
+    GList *node_cmp, *next_node_cmp;
+
+    PLAYLIST_LOCK();
+
+    for (node = playlist; node; node = next_node) {
+        PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
+        next_node = g_list_next(node);
+
+        if (!entry || !entry->filename) {
+            g_message(G_STRLOC ": Playlist entry is invalid!");
+            continue;
+        }
+
+        for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) {
+            PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data);
+            next_node_cmp = g_list_next(node_cmp);
+
+            if (!entry_cmp || !entry_cmp->filename) {
+                g_message(G_STRLOC ": Playlist entry is invalid!");
+                continue;
+            }
+
+            /* compare path+filenames, this can/should be optimized */
+            if ( !strcmp( entry->filename , entry_cmp->filename ) ) {
+
+                if (entry_cmp == playlist_position) {
+                    /* Don't remove the currently playing song */
+                    if (bmp_playback_get_playing())
+                        continue;
+
+                    if (next_node_cmp)
+                        playlist_position = PLAYLIST_ENTRY(next_node_cmp->data);
+                    else
+                        playlist_position = NULL;
+                }
+
+                /* check if this was the next item of the external
+                   loop; if true, replace it with the next of the next*/
+                if ( node_cmp == next_node )
+                    next_node = g_list_next(next_node);
+
+                playlist_entry_free(entry_cmp);
+                playlist = g_list_delete_link(playlist, node_cmp);
+            }
+        }
+    }
+
+    PLAYLIST_UNLOCK();
+
+    playlistwin_update_list();
+    playlist_recalc_total_time();
+}
+
 static gulong pl_total_time = 0, pl_selection_time = 0;
 static gboolean pl_total_more = FALSE, pl_selection_more = FALSE;
 
--- a/audacious/playlist.h	Fri Mar 17 20:07:11 2006 -0800
+++ b/audacious/playlist.h	Sat Mar 18 07:34:43 2006 -0800
@@ -100,6 +100,7 @@
 
 void playlist_reverse(void);
 void playlist_random(void);
+void playlist_remove_duplicates(void);
 void playlist_remove_dead_files(void);
 
 void playlist_fileinfo_current(void);
--- a/audacious/ui_playlist.c	Fri Mar 17 20:07:11 2006 -0800
+++ b/audacious/ui_playlist.c	Sat Mar 18 07:34:43 2006 -0800
@@ -63,7 +63,7 @@
 
 enum {
     ADD_URL, ADD_DIR, ADD_FILES,
-    SUB_MISC, SUB_ALL, SUB_CROP, SUB_SELECTED,
+    SUB_MISC, SUB_ALL, SUB_CROP, SUB_SELECTED, SUB_DUPLICATE,
     SEL_INV, SEL_ZERO, SEL_ALL,
     MISC_SORT, MISC_FILEINFO, MISC_MISCOPTS,
     PLIST_NEW, PLIST_SAVE_AS, PLIST_LOAD,
@@ -181,7 +181,11 @@
 
     {N_("/Remove Selected"), "Delete",
      playlistwin_sub_menu_callback,
-     SUB_SELECTED, "<Item>", GTK_STOCK_DELETE}
+     SUB_SELECTED, "<Item>", GTK_STOCK_DELETE},
+
+    {N_("/Remove Duplicates"), NULL,
+     playlistwin_sub_menu_callback,
+     SUB_DUPLICATE, "<Item>", GTK_STOCK_DELETE}
 };
 
 static GtkItemFactoryEntry pllist_menu_entries[] = {
@@ -1879,6 +1883,9 @@
     case SUB_SELECTED:
         playlist_delete(FALSE);
         break;
+    case SUB_DUPLICATE:
+        playlist_remove_duplicates();
+        break;
     case PLAYLISTWIN_REMOVE_DEAD_FILES:
         playlist_remove_dead_files();
         break;