changeset 2120:1d67cf383e32 trunk

[svn] - dynamically allocate the playlist at startup and fix some lingering improper uses of playlist_get()
author nenolod
date Fri, 15 Dec 2006 07:20:41 -0800
parents 6d7381072a45
children 185db04b815f
files ChangeLog audacious/main.c audacious/playlist.c audacious/playlist.h
diffstat 4 files changed, 60 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Dec 13 23:15:44 2006 -0800
+++ b/ChangeLog	Fri Dec 15 07:20:41 2006 -0800
@@ -1,3 +1,11 @@
+2006-12-14 07:15:44 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [3243]
+  - fix example
+  
+  trunk/libaudacious++/configdb.hh |    4 ++--
+  1 file changed, 2 insertions(+), 2 deletions(-)
+
+
 2006-12-14 06:46:29 +0000  William Pitcock <nenolod@nenolod.net>
   revision [3241]
   - add the starting point of some audacious C++ bindings
--- a/audacious/main.c	Wed Dec 13 23:15:44 2006 -0800
+++ b/audacious/main.c	Fri Dec 15 07:20:41 2006 -0800
@@ -1109,6 +1109,9 @@
 
     plugin_system_init();
 
+    /* Initialize the playlist system. */
+    playlist_init();
+
     if (options.headless != 1)
     {
 
@@ -1124,6 +1127,7 @@
         GDK_THREADS_ENTER();
     }
 
+    /* Load the default playlist in. */
     playlist = playlist_get_active();
     playlist_load(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]);
     playlist_set_position(playlist, cfg.playlist_position);
--- a/audacious/playlist.c	Wed Dec 13 23:15:44 2006 -0800
+++ b/audacious/playlist.c	Fri Dec 15 07:20:41 2006 -0800
@@ -64,6 +64,7 @@
 G_LOCK_DEFINE(playlists);
 
 static GList *playlists = NULL;
+static GList *playlists_iter;
 
 static Playlist default_playlist = {
 	"Default",
@@ -143,6 +144,8 @@
 static void playlist_recalc_total_time(Playlist *);
 static gboolean playlist_entry_get_info(PlaylistEntry * entry);
 
+/* *********************** playlist entry code ********************** */
+
 PlaylistEntry *
 playlist_entry_new(const gchar * filename,
                    const gchar * title,
@@ -230,6 +233,40 @@
     return TRUE;
 }
 
+/* *********************** playlist selector code ************************* */
+
+void
+playlist_init(void)
+{
+    Playlist *initial_pl;
+
+    REQUIRE_STATIC_LOCK(playlists);
+
+    initial_pl = playlist_new();
+
+    playlist_add_playlist(initial_pl);
+}
+
+void
+playlist_add_playlist(Playlist *playlist)
+{
+    playlists = g_list_append(playlists, playlist);
+
+    if (playlists_iter == NULL)
+        playlists_iter = playlists;
+}
+
+void
+playlist_remove_playlist(Playlist *playlist)
+{
+    playlists = g_list_remove(playlists, playlist);
+
+    if (playlists_iter == NULL)
+        playlists_iter = playlists;
+}
+
+/* *********************** playlist code ********************** */
+
 const gchar *
 playlist_get_current_name(Playlist *playlist)
 {
@@ -239,9 +276,8 @@
 gboolean
 playlist_set_current_name(Playlist *playlist, const gchar * filename)
 {
-#ifdef NOTYET
-    g_free(playlist->title);
-#endif
+    if (playlist->title)
+        g_free(playlist->title);
 
     if (!filename) {
         playlist->title = NULL;
@@ -2627,7 +2663,7 @@
     playlist->pl_total_more = FALSE;
     playlist->pl_selection_more = FALSE;
 
-    for (list = playlist_get(); list; list = g_list_next(list)) {
+    for (list = playlist->entries; list; list = g_list_next(list)) {
         entry = list->data;
 
         if (entry->length != -1)
@@ -2789,8 +2825,11 @@
 Playlist *
 playlist_get_active(void)
 {
-    return &default_playlist;
-};
+    if (playlists_iter != NULL)
+        return (Playlist *) playlists_iter->data;
+
+    return (Playlist *) playlists->data;
+}
 
 void
 playlist_set_shuffle(gboolean shuffle)
@@ -2812,8 +2851,6 @@
 
     playlist_set_current_name(playlist, NULL);
     playlist_clear(playlist);
-    mainwin_clear_song_info();
-    mainwin_set_info_text();
 
     return playlist;
 }
--- a/audacious/playlist.h	Wed Dec 13 23:15:44 2006 -0800
+++ b/audacious/playlist.h	Fri Dec 15 07:20:41 2006 -0800
@@ -95,6 +95,9 @@
                                   PlaylistAssociation assoc, gint pos);
 
 void playlist_init(void);
+void playlist_add_playlist(Playlist *);
+void playlist_remove_playlist(Playlist *);
+
 void playlist_clear(Playlist *playlist);
 void playlist_delete(Playlist *playlist, gboolean crop);