changeset 4835:7ac9e8b91bbf

Add playlist_shift().
author William Pitcock <nenolod@atheme.org>
date Fri, 13 Mar 2009 14:22:07 -0500
parents 38b491487bd8
children fb3386ba8498
files src/audlegacy/playlist.c src/audlegacy/playlist.h
diffstat 2 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/audlegacy/playlist.c	Thu May 21 19:17:02 2009 +0900
+++ b/src/audlegacy/playlist.c	Fri Mar 13 14:22:07 2009 -0500
@@ -484,6 +484,52 @@
 }
 
 void
+playlist_shift(Playlist *playlist, gint delta)
+{
+    gint orig_delta;
+    GList *n, *tn;
+    g_return_if_fail(playlist != NULL);
+
+    if (delta == 0)
+        return;
+
+    PLAYLIST_LOCK(playlist);
+
+    /* copy the delta over. */
+    orig_delta = delta;
+
+    /* even though it is unlikely we would ever be calling playlist_shift()
+       on an empty playlist... we should probably check for this. --nenolod */
+    if ((n = playlist->entries) == NULL)
+    {
+        PLAYLIST_UNLOCK(playlist);
+        return;
+    }
+
+    MOWGLI_ITER_FOREACH_SAFE(n, tn, playlist->entries)
+    {
+        PlaylistEntry *entry = PLAYLIST_ENTRY(n->data);
+
+        if (!entry->selected)
+            continue;
+
+        if (orig_delta > 0)
+            for (delta = orig_delta; delta > 0; delta--)
+                glist_movedown(n);
+        else (orig_delta < 0)
+            for (delta = orig_delta; delta > 0; delta--)
+                glist_moveup(n);
+    }
+
+    /* do the remaining work. */
+    playlist_generate_shuffle_list(playlist);
+    event_queue("playlist update", playlist);
+    PLAYLIST_INCR_SERIAL(playlist);
+
+    PLAYLIST_UNLOCK(playlist);
+}
+
+void
 playlist_clear(Playlist *playlist)
 {
     if (!playlist)
--- a/src/audlegacy/playlist.h	Thu May 21 19:17:02 2009 +0900
+++ b/src/audlegacy/playlist.h	Fri Mar 13 14:22:07 2009 -0500
@@ -161,6 +161,7 @@
 gint playlist_get_position_nolock(Playlist *playlist);
 gchar *playlist_get_info_text(Playlist *playlist);
 gint playlist_get_current_length(Playlist *playlist);
+void playlist_shift(Playlist *playlist, gint delta);
 
 gboolean playlist_save(Playlist *playlist, const gchar * filename);
 gboolean playlist_load(Playlist *playlist, const gchar * filename);