[totem] TotemPlaylist: Use totem_pl_parser_save().



commit 647909128b0c587b26e1e13e42da7036982f68b2
Author: Carlos Garnacho <carlos lanedo com>
Date:   Wed Dec 23 16:33:29 2009 +0100

    TotemPlaylist: Use totem_pl_parser_save().
    
    Use newer TotemPlPlaylist and totem_pl_parser_save() in order
    to save playlists.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=605312

 configure.in         |    2 +-
 src/totem-playlist.c |   53 ++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 42 insertions(+), 13 deletions(-)
---
diff --git a/configure.in b/configure.in
index c815fd0..9c05acd 100644
--- a/configure.in
+++ b/configure.in
@@ -38,7 +38,7 @@ AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
 # Requirements
 GLIB_REQS=2.22
 GTK_REQS=2.19.1
-TOTEM_PLPARSER_REQS=2.27.0
+TOTEM_PLPARSER_REQS=2.29.1
 GNOMEICON_REQS=2.15.90
 DBUS_REQS=0.61
 VALA_REQS=0.7.5
diff --git a/src/totem-playlist.c b/src/totem-playlist.c
index 78045ac..84b4d3f 100644
--- a/src/totem-playlist.c
+++ b/src/totem-playlist.c
@@ -397,16 +397,33 @@ totem_playlist_update_save_button (TotemPlaylist *playlist)
 	gtk_widget_set_sensitive (button, state);
 }
 
-static void
-totem_playlist_save_get_iter_func (GtkTreeModel *model,
-		GtkTreeIter *iter, char **uri, char **title,
-		gboolean *custom_title, gpointer user_data)
-{
+static gboolean
+totem_playlist_save_iter_foreach (GtkTreeModel *model,
+				  GtkTreePath  *path,
+				  GtkTreeIter  *iter,
+				  gpointer      user_data)
+{
+	TotemPlPlaylist *playlist = user_data;
+	TotemPlPlaylistIter pl_iter;
+	gchar *uri, *title;
+	gboolean custom_title;
+
 	gtk_tree_model_get (model, iter,
-			URI_COL, uri,
-			FILENAME_COL, title,
-			TITLE_CUSTOM_COL, custom_title,
-			-1);
+			    URI_COL, &uri,
+			    FILENAME_COL, &title,
+			    TITLE_CUSTOM_COL, &custom_title,
+			    -1);
+
+	totem_pl_playlist_append (playlist, &pl_iter);
+	totem_pl_playlist_set (playlist, &pl_iter,
+			       TOTEM_PL_PARSER_FIELD_URI, uri,
+			       TOTEM_PL_PARSER_FIELD_TITLE, (custom_title) ? title : NULL,
+			       NULL);
+
+	g_free (uri);
+	g_free (title);
+
+	return FALSE;
 }
 
 void
@@ -418,13 +435,22 @@ totem_playlist_save_current_playlist (TotemPlaylist *playlist, const char *outpu
 void
 totem_playlist_save_current_playlist_ext (TotemPlaylist *playlist, const char *output, TotemPlParserType type)
 {
+	TotemPlPlaylist *pl_playlist;
 	GError *error = NULL;
+	GFile *output_file;
 	gboolean retval;
 
-	retval = totem_pl_parser_write (playlist->priv->parser,
-			playlist->priv->model,
-                        totem_playlist_save_get_iter_func,
-			output, type, NULL, &error);
+	pl_playlist = totem_pl_playlist_new ();
+	output_file = g_file_new_for_commandline_arg (output);
+
+	gtk_tree_model_foreach (playlist->priv->model,
+				totem_playlist_save_iter_foreach,
+				pl_playlist);
+
+	retval = totem_pl_parser_save (playlist->priv->parser,
+				       pl_playlist,
+				       output_file,
+				       NULL, type, &error);
 
 	if (retval == FALSE)
 	{
@@ -432,6 +458,9 @@ totem_playlist_save_current_playlist_ext (TotemPlaylist *playlist, const char *o
 				error->message, playlist);
 		g_error_free (error);
 	}
+
+	g_object_unref (pl_playlist);
+	g_object_unref (output_file);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]