Mercurial > audlegacy
diff audacious/playlist.c @ 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 | f18a5b617c34 |
children | 185db04b815f |
line wrap: on
line diff
--- 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; }