changeset 3477:57f4971b7086 trunk

New functions for associating a filename with a playlist. Made title/filename setting more consistent.
author Kieran Clancy <clancy.kieran+audacious@gmail.com>
date Mon, 10 Sep 2007 13:50:18 +0930
parents 9152829f3c19
children 481a4a88d3ec
files src/audacious/playlist.c src/audacious/playlist.h src/audacious/ui_playlist.c
diffstat 3 files changed, 52 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playlist.c	Mon Sep 10 13:47:16 2007 +0930
+++ b/src/audacious/playlist.c	Mon Sep 10 13:50:18 2007 +0930
@@ -296,6 +296,7 @@
     if (g_list_length(playlists) < 2) {
         playlist_clear(playlist);
         playlist_set_current_name(playlist, NULL);
+        playlist_filename_set(playlist, NULL);
         return;
     }
 
@@ -365,22 +366,50 @@
     return playlist->title;
 }
 
-/* filename is real filename here. --yaz */
+/* This function now sets the playlist title, not the playlist filename.
+ * See playlist_filename_set */
 gboolean
-playlist_set_current_name(Playlist *playlist, const gchar * filename)
+playlist_set_current_name(Playlist *playlist, const gchar * title)
 {
-    if (playlist->title)
-        g_free(playlist->title);
-
-    if (!filename) {
+    gchar *oldtitle;
+    oldtitle = playlist->title;
+
+    if (!title) {
         playlist->title = NULL;
+        if(oldtitle) g_free(oldtitle);
         return FALSE;
     }
 
-    playlist->title = filename_to_utf8(filename);
+    playlist->title = str_to_utf8(title);
+    if(oldtitle) g_free(oldtitle);
     return TRUE;
 }
 
+/* Setting the filename allows the original playlist to be modified later */
+gboolean
+playlist_filename_set(Playlist *playlist, const gchar * filename)
+{
+    gchar *old;
+    old = playlist->filename;
+
+    if(!filename) {
+        playlist->filename = NULL;
+        if(old) g_free(old);
+        return FALSE;
+    }
+
+    playlist->filename = filename_to_utf8(filename);
+    if(old) g_free(old);
+    return TRUE;
+}
+
+gchar *
+playlist_filename_get(Playlist *playlist)
+{
+    if(!playlist->filename) return NULL;
+    return g_filename_from_utf8(playlist->filename, -1, NULL, NULL, NULL);
+}
+
 static GList *
 find_playlist_position_list(Playlist *playlist)
 {
@@ -1576,9 +1605,6 @@
 
     ext = strrchr(filename, '.') + 1;
 
-    if (!playlist->title || !playlist->title[0])
-        playlist_set_current_name(playlist, filename);
-
     if ((plc = playlist_container_find(ext)) == NULL)
         return FALSE;
 
@@ -1606,6 +1632,10 @@
     g_return_val_if_fail(playlist != NULL, FALSE);
 
     playlist->loading_playlist = TRUE;
+    if(!playlist_get_length(playlist)) {
+        /* Loading new playlist */
+        playlist_filename_set(playlist, filename);
+    }
     ret = playlist_load_ins(playlist, filename, -1);
     playlist->loading_playlist = FALSE;
 
@@ -3240,8 +3270,8 @@
     Playlist *playlist = g_new0(Playlist, 1);
     playlist->mutex = g_mutex_new();
     playlist->loading_playlist = FALSE;
-
-    playlist_set_current_name(playlist, NULL);
+    playlist->title = NULL;
+    playlist->filename = NULL;
     playlist_clear(playlist);
 
     return playlist;
--- a/src/audacious/playlist.h	Mon Sep 10 13:47:16 2007 +0930
+++ b/src/audacious/playlist.h	Mon Sep 10 13:50:18 2007 +0930
@@ -213,8 +213,13 @@
 void playlist_clear_selected(Playlist *playlist);
 
 GList *get_playlist_nth(Playlist *playlist, guint);
-gboolean playlist_set_current_name(Playlist *playlist, const gchar * filename);
+
+gboolean playlist_set_current_name(Playlist *playlist, const gchar * title);
 const gchar *playlist_get_current_name(Playlist *playlist);
+
+gboolean playlist_filename_set(Playlist *playlist, const gchar * filename);
+gchar *playlist_filename_get(Playlist *playlist);
+
 Playlist *playlist_new(void);
 void playlist_free(Playlist *playlist);
 Playlist *playlist_new_from_selected(void);
--- a/src/audacious/ui_playlist.c	Mon Sep 10 13:47:16 2007 +0930
+++ b/src/audacious/ui_playlist.c	Mon Sep 10 13:50:18 2007 +0930
@@ -828,6 +828,7 @@
 static void
 playlistwin_load_playlist(const gchar * filename)
 {
+    const gchar *title;
     Playlist *playlist = playlist_get_active();
 
     g_return_if_fail(filename != NULL);
@@ -838,7 +839,9 @@
     mainwin_clear_song_info();
 
     playlist_load(playlist, filename);
-    playlist_set_current_name(playlist, filename);
+    title = playlist_get_current_name(playlist);
+    if(!title || !title[0])
+        playlist_set_current_name(playlist, filename);
 }
 
 static gchar *