commit 4c4c2c91ed39cd77015a49fa7c80394de468ea28
Author: Christophe Fergeau <cferg...@mandriva.com>
Date:   Wed Sep 29 18:20:21 2010 +0200

    libgpod expects empty strings to be NULL
    
    gtkpod sets empty Itdb_Track strings to "" instead of NULL to make
    things less error-prone. However, this should stay internal to gtkpod,
    and as far as libgpod is concerned, empty fields should be NULL, not "".
    This commit makes sure that empty fields will be set to NULL before
    trying to write the iPod database.

 libgtkpod/file_itunesdb.c |    9 +++++++++
 libgtkpod/gp_itdb.c       |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/libgtkpod/file_itunesdb.c b/libgtkpod/file_itunesdb.c
index 4f7bac3..3ad560e 100644
--- a/libgtkpod/file_itunesdb.c
+++ b/libgtkpod/file_itunesdb.c
@@ -1625,6 +1625,7 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
     GtkWidget *dialog;
     Playlist *mpl;
     TransferData *transferdata;
+    GList *it;
 
     g_return_val_if_fail (itdb, FALSE);
     eitdb = itdb->userdata;
@@ -1720,6 +1721,10 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
             gtk_main_iteration();
     }
 
+    for (it = itdb->tracks; it != NULL; it = it->next) {
+        gp_track_cleanup_empty_strings ((Itdb_Track *)it->data);
+    }
+
     if (success && !get_offline(itdb) && (itdb->usertype & GP_ITDB_TYPE_IPOD)) 
{ /* write to the iPod */
         GError *error = NULL;
         if (!itdb_write(itdb, &error)) { /* an error occurred */
@@ -1831,6 +1836,10 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
         }
     }
 
+    for (it = itdb->tracks; it != NULL; it = it->next) {
+        gp_track_validate_entries ((Itdb_Track *)it->data);
+    }
+
     /* If the ipod supports photos and the photo_data_changed
      * flag has been set to true then wrtie the photo database
      */
diff --git a/libgtkpod/gp_itdb.c b/libgtkpod/gp_itdb.c
index 3cbbcfd..f6e1e93 100644
--- a/libgtkpod/gp_itdb.c
+++ b/libgtkpod/gp_itdb.c
@@ -739,6 +739,44 @@ void gp_track_validate_entries(Track *track) {
     etr->year_str = g_strdup_printf("%d", track->year);
 }
 
+
+static void maybe_cleanup_string (char **str)
+{
+    if (((*str) != NULL) && ((*str)[0] == '\0')) {
+        g_free (*str);
+        *str = NULL;
+    }
+}
+
+void gp_track_cleanup_empty_strings (Track *track)
+{
+    maybe_cleanup_string (&track->title);
+    maybe_cleanup_string (&track->artist);
+    maybe_cleanup_string (&track->album);
+    maybe_cleanup_string (&track->genre);
+    maybe_cleanup_string (&track->composer);
+    maybe_cleanup_string (&track->comment);
+    maybe_cleanup_string (&track->filetype);
+    maybe_cleanup_string (&track->grouping);
+    maybe_cleanup_string (&track->category);
+    maybe_cleanup_string (&track->description);
+    maybe_cleanup_string (&track->podcasturl);
+    maybe_cleanup_string (&track->podcastrss);
+    maybe_cleanup_string (&track->subtitle);
+    maybe_cleanup_string (&track->ipod_path);
+    maybe_cleanup_string (&track->tvshow);
+    maybe_cleanup_string (&track->tvepisode);
+    maybe_cleanup_string (&track->tvnetwork);
+    maybe_cleanup_string (&track->albumartist);
+    maybe_cleanup_string (&track->sort_artist);
+    maybe_cleanup_string (&track->sort_title);
+    maybe_cleanup_string (&track->sort_album);
+    maybe_cleanup_string (&track->sort_albumartist);
+    maybe_cleanup_string (&track->sort_composer);
+    maybe_cleanup_string (&track->sort_tvshow);
+}
+
+
 /* Initialize the itdb data
  *
  * If itdb_n_type/filename/mountpoint... exist in the prefs, that data

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to