Update of /cvsroot/gtkpod/gtkpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv20312/src

Modified Files:
        confirmation.h display_coverart.c display_itdb.c 
        display_itdb.h file.c file.h file_convert.c file_convert.h 
        file_itunesdb.c info.c info.h misc_confirm.c misc_playlist.c 
        misc_track.c prefs_window.c 
Log Message:
  * src/display_coverart.c:
    src/misc_confirm.c: changed '//' to '/*' for compatibility
    reasons.

  * src/confirmation.h
    src/display_coverart.c
    src/display_itdb.c
    src/display_itdb.h
    src/file.c
    src/file.h
    src/file_convert.c
    src/file_convert.h
    src/file_itunesdb.c
    src/info.c
    src/info.h
    src/misc_playlist.c
    src/misc_track.c:

    - Copying of tracks to the iPod in the background.
    - Remove 'oldsize' entry in ExtraTrackData formerly used when
      updating tracks.
    - Reduce SPACE_TIMEOUT from 4 to 1 seconds (probing device for
      free space)



Index: confirmation.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/confirmation.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- confirmation.h      14 May 2006 15:58:54 -0000      1.14
+++ confirmation.h      6 May 2007 14:16:15 -0000       1.15
@@ -1,5 +1,5 @@
 /*
-|  Copyright (C) 2002-2003 Jorg Schuler <jcsjcs at users.sourceforge.net>
+|  Copyright (C) 2002-2007 Jorg Schuler <jcsjcs at users.sourceforge.net>
 |  Part of the gtkpod project.
 |
 |  URL: http://gtkpod.sourceforge.net/
@@ -70,7 +70,8 @@
     CONF_ID_GTKPOD_WARNING,
     CONF_ID_DANGLING0,
     CONF_ID_DANGLING1,
-    CONF_ID_SYNC_SUMMARY
+    CONF_ID_SYNC_SUMMARY,
+    CONF_ID_TRANSFER
 } CONF_ID;
 
 void CONF_NULL_HANDLER (gpointer d1, gpointer d2);

Index: display_coverart.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_coverart.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- display_coverart.c  6 May 2007 09:31:47 -0000       1.15
+++ display_coverart.c  6 May 2007 14:16:15 -0000       1.16
@@ -1513,7 +1513,9 @@
                         * Dont know how it has changed so all I can really do 
is resort the list according
                         * to the current sort order and redisplay
                         */
-                        coverart_set_images (FALSE);
+                       /* for performance reasons we'll ignore track
+                          changes for now */
+/*                      coverart_set_images (FALSE); */
        }
        
        /* cdwidget->block_display_change = FALSE; */

Index: display_itdb.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_itdb.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- display_itdb.c      23 Apr 2007 15:33:31 -0000      1.66
+++ display_itdb.c      6 May 2007 14:16:15 -0000       1.67
@@ -303,16 +303,12 @@
    playlist -- see gp_playlist_remove_track for details */
 void gp_track_remove (Track *track)
 {
-    /* the details window may be accessing the tracks */
-    details_remove_track (track);
-    /* cancel pending conversions */
-    file_convert_cancel_track (track);
-    /* remove from SHA1 hash */
-    sha1_track_remove (track);
-    /* remove from pc_path_hash */
-    gp_itdb_pc_path_hash_remove_track (track);
-    /* remove from database */
-    itdb_track_remove (track);
+    /* call gp_track_unlink() and itdb_track_free() instead of
+       itdb_track_remove() so we don't have to maintain two remove
+       functions separately. If something needs to be done before
+       removing the track do it in gp_track_unlink */
+    gp_track_unlink (track);
+    itdb_track_free (track);
 }
 
 
@@ -322,8 +318,10 @@
    playlist -- see gp_playlist_remove_track for details */
 void gp_track_unlink (Track *track)
 {
-    /* currently only the details window may be accessing the tracks */
+    /* the details window may be accessing the tracks */
     details_remove_track (track);
+    /* cancel pending conversions */
+    file_convert_cancel_track (track);
     /* remove from SHA1 hash */
     sha1_track_remove (track);
     /* remove from pc_path_hash */

Index: display_itdb.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_itdb.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- display_itdb.h      23 Apr 2007 15:33:31 -0000      1.42
+++ display_itdb.h      6 May 2007 14:16:15 -0000       1.43
@@ -44,17 +44,17 @@
 
 typedef struct
 {
-    struct itdbs_head *itdbs_head; /* pointer to the master itdbs_head */
-    GHashTable *sha1hash;          /* sha1 hash information            */
-    GHashTable *pc_path_hash;      /* hash with local filenames        */
+    struct itdbs_head *itdbs_head; /* pointer to the master itdbs_head     */
+    GHashTable *sha1hash;          /* sha1 hash information                */
+    GHashTable *pc_path_hash;      /* hash with local filenames            */
     GList *pending_deletion;       /* tracks marked for removal from
-                                     media                            */
+                                     media                                */
     gchar *offline_filename;       /* filename for offline database
-                                     (only for GP_ITDP_TYPE_IPOD)     */
-    gboolean offline;              /* offline mode?                    */
-    gboolean data_changed;         /* data changed since import?       */
-    gboolean itdb_imported;        /* has in iTunesDB been imported?   */
-    gboolean ipod_ejected;         /* if iPod was ejected              */
+                                     (only for GP_ITDP_TYPE_IPOD)         */
+    gboolean offline;              /* offline mode?                        */
+    gboolean data_changed;         /* data changed since import?           */
+    gboolean itdb_imported;        /* has in iTunesDB been imported?       */
+    gboolean ipod_ejected;         /* if iPod was ejected                  */
 } ExtraiTunesDBData;
 
 typedef struct
@@ -64,7 +64,6 @@
 
 typedef struct
 {
-  gint32  oldsize;          /* used when updating tracks: size on iPod     */
   gchar   *year_str;        /* year as string -- always identical to year  */
   gchar   *pc_path_locale;  /* path on PC (local encoding)                 */
   gchar   *pc_path_utf8;    /* PC filename in utf8 encoding                */

Index: file.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file.c,v
retrieving revision 1.200
retrieving revision 1.201
diff -u -d -r1.200 -r1.201
--- file.c      27 Apr 2007 15:19:53 -0000      1.200
+++ file.c      6 May 2007 14:16:16 -0000       1.201
@@ -44,6 +44,7 @@
 #include "confirmation.h"
 #include "info.h"
 #include "file.h"
+#include "file_convert.h"
 #include "itdb.h"
 #include "sha1.h"
 #include "misc.h"
@@ -1649,7 +1650,6 @@
     { /* update successfull */
        /* remove track from sha1 hash and reinsert it
           (hash value may have changed!) */
-       gchar *name_on_ipod;
        gchar *oldhash = etr->sha1_hash;
 
        sha1_track_remove (track);
@@ -1662,35 +1662,62 @@
            gp_duplicate_remove (track, oldtrack);
            sha1_track_exists_insert (itdb, track);
        }
-       /* track may have to be copied to iPod on next export */
-       /* since it will copied under the same name as before, we
-          don't have to manually remove it */
-       name_on_ipod = get_file_name_from_source (track, SOURCE_IPOD);
-       if (name_on_ipod && (strcmp (name_on_ipod, trackpath) != 0))
-       {   /* trackpath is not on the iPod */
-           if (oldhash && etr->sha1_hash)
-           {   /* do we really have to copy the track again? */
-               if (strcmp (oldhash, etr->sha1_hash) != 0)
-               {
-                   track->transferred = FALSE;
-                   data_changed (itdb);
+
+       if (itdb->usertype & GP_ITDB_TYPE_IPOD)
+       {   /* track may have to be copied to iPod on next export */
+           gchar *name_on_ipod;
+           gboolean transfer_again = FALSE;
+
+           name_on_ipod = get_file_name_from_source (track, SOURCE_IPOD);
+           if (name_on_ipod && (strcmp (name_on_ipod, trackpath) != 0))
+           {   /* trackpath is not on the iPod */
+               if (oldhash && etr->sha1_hash)
+               {   /* do we really have to copy the track again? */
+                   if (strcmp (oldhash, etr->sha1_hash) != 0)
+                   {
+                       transfer_again = TRUE;
+                   }
+               }
+               else
+               {   /* no hash available -- copy! */
+                   transfer_again = TRUE;
                }
            }
            else
-           {   /* no hash available -- copy! */
+           {
+               data_changed (itdb);
+           }
+
+           if (transfer_again)
+           {   /* We need to copy the track back to the iPod. That's done
+                  marking a copy of the original track for deletion and
+                  then adding the original track to the
+                  conversion/transfer list */
+               Track *new_track = gp_track_new ();
+               ExtraTrackData *new_etr = new_track->userdata;
+               g_return_if_fail (new_etr);
+
+               new_track->size = oldsize;
+               new_track->ipod_path = track->ipod_path;
+               track->ipod_path = g_strdup ("");
                track->transferred = FALSE;
+
+               /* cancel conversion/transfer of track */
+               file_convert_cancel_track (track);
+               /* mark the track for deletion on the ipod */
+               mark_track_for_deletion (itdb, new_track);
+               /* reschedule conversion/transfer of track */
+
                data_changed (itdb);
            }
+
+           g_free (name_on_ipod);
        }
        else
        {
            data_changed (itdb);
        }
-       g_free (name_on_ipod);
-       
-       /* set old size if track has to be transferred (for free space
-        * calculation) */
-       if (!track->transferred) etr->oldsize = oldsize;
+
        /* notify display model */
        pm_track_changed (track);
        display_updated (track, NULL);

Index: file.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- file.h      23 Apr 2007 15:33:31 -0000      1.60
+++ file.h      6 May 2007 14:16:16 -0000       1.61
@@ -1,4 +1,4 @@
-/* Time-stamp: <2007-04-23 21:48:53 jcs>
+/* Time-stamp: <2007-05-06 20:20:31 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -107,7 +107,6 @@
 gchar *get_file_name_from_source (Track *track, FileSource source);
 gchar* get_preferred_track_name_format(Track *s);
 void mark_track_for_deletion (iTunesDB *itdb, Track *track);
-void unmark_track_for_deletion (iTunesDB *itdb, Track *track);
 void gp_info_deleted_tracks (iTunesDB *itdb,
                             gdouble *size, guint32 *num);
 void update_charset_info (Track *track);

Index: file_convert.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_convert.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- file_convert.c      1 May 2007 11:55:38 -0000       1.7
+++ file_convert.c      6 May 2007 14:16:17 -0000       1.8
@@ -33,19 +33,20 @@
 #   include <config.h>
 #endif
 
+#include "display_itdb.h"
+#include "file_convert.h"
+#include "info.h"
+#include "misc.h"
+#include "misc_track.h"
+#include "prefs.h"
 #include <errno.h>
 #include <glib/gstdio.h>
[...1637 lines suppressed...]
+                                 conv,        /* user data  */
+                                 0,           /* stack size */
+                                 FALSE,       /* joinable   */
+                                 TRUE,        /* bound      */
+                                 G_THREAD_PRIORITY_NORMAL,
+                                 NULL);       /* error      */
+       }
+       
+    }
+
+    tri->thread = NULL;
+    if (tri->status != FILE_TRANSFER_DISK_FULL)
+       tri->status = FILE_TRANSFER_IDLE;
+
+    g_mutex_unlock (conv->mutex);
+
+    debug ("%p transfer thread exit\n", tri->itdb);
+
+    return NULL;
+}

Index: file_convert.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_convert.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- file_convert.h      1 May 2007 11:55:38 -0000       1.6
+++ file_convert.h      6 May 2007 14:16:17 -0000       1.7
@@ -43,6 +43,7 @@
 extern const gchar *FILE_CONVERT_TEMPLATE;
 extern const gchar *FILE_CONVERT_MAX_THREADS_NUM;
 extern const gchar *FILE_CONVERT_DISPLAY_LOG;
+extern const gchar *FILE_CONVERT_BACKGROUND_TRANSFER;
 
 typedef enum
 {
@@ -55,14 +56,34 @@
     FILE_CONVERT_CONVERTED
 } FileConvertStatus;
 
+typedef enum
+{
+    FILE_TRANSFER_ERROR = -1,
+    FILE_TRANSFER_IDLE = 0,
+    FILE_TRANSFER_ACTIVE,
+    FILE_TRANSFER_DISK_FULL
+} FileTransferStatus;
+
 void file_convert_init (void);
 void file_convert_shutdown (void);
 void file_convert_prefs_changed (void);
 void file_convert_update_default_sizes (void);
 gboolean file_convert_add_track (Track *track);
 void file_convert_itdb_first (iTunesDB *itdb);
+void file_convert_continue (void);
 void file_convert_cancel_itdb (iTunesDB *itdb);
 void file_convert_cancel_track (Track *track);
-Track *file_convert_timed_wait (iTunesDB* itdb, gint ms);
 
+GList *file_transfer_get_failed_tracks (iTunesDB *itdb);
+FileTransferStatus file_transfer_get_status (iTunesDB *itdb,
+                                            gint *to_convert_num,
+                                            gint *converting_num,
+                                            gint *to_transfer_num,
+                                            gint *transferred_num,
+                                            gint *failed_num);
+void file_transfer_ack_itdb (iTunesDB *itdb);
+void file_transfer_continue (iTunesDB *itdb);
+void file_transfer_activate (iTunesDB *itdb, gboolean active);
+void file_transfer_reset (iTunesDB *itdb);
+void file_transfer_reschedule (iTunesDB *itdb);
 #endif

Index: file_itunesdb.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_itunesdb.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- file_itunesdb.c     1 May 2007 11:55:38 -0000       1.120
+++ file_itunesdb.c     6 May 2007 14:16:17 -0000       1.121
@@ -73,7 +73,6 @@
     gchar *charset;
     gchar *hostname;
     gchar *ipod_path;
-    gint32 oldsize;
     guint64 local_itdb_id;
     guint64 local_track_dbid;
     gboolean transferred;
@@ -87,6 +86,7 @@
     Track *track;            /* Current track                  */
     const gchar *filename;   /* Filename to copy/remove        */
     /* Widgets for progress dialog */
+    GtkWidget *dialog;
     GtkWidget *textlabel;
     GtkProgressBar *progressbar;
 } TransferData;
@@ -163,7 +163,6 @@
          etr->converted_file = g_strdup (sei->converted_file);
       etr->local_itdb_id = sei->local_itdb_id;
       etr->local_track_dbid = sei->local_track_dbid;
-      etr->oldsize = sei->oldsize;
       track->transferred = sei->transferred;
       /* don't remove the sha1-hash -- there may be duplicates... */
       if (extendedinfohash)
@@ -370,8 +369,6 @@
            }
            else if (g_ascii_strcasecmp (line, "charset") == 0)
                sei->charset = g_strdup (arg);
-           else if (g_ascii_strcasecmp (line, "oldsize") == 0)
-               sei->oldsize = atoi (arg);
            else if (g_ascii_strcasecmp (line, "transferred") == 0)
                sei->transferred = atoi (arg);
            else if (g_ascii_strcasecmp (line, "filename_ipod") == 0)
@@ -1071,51 +1068,28 @@
        etr = tr->userdata;
        g_return_if_fail (tr);
 
-       if (itdb->usertype & GP_ITDB_TYPE_IPOD)
-       {
-           if (tr->transferred)
-           {   /* I don't understand why "- etr->oldsize" (JCS) --
-                * supposedly related to update_track_from_file() but
-                I can't see how. */
-               if (size)  *size += tr->size - etr->oldsize;
-           }
-       }
-       if (itdb->usertype & GP_ITDB_TYPE_LOCAL)
-       {   /* total size on hard disk */
-           if (size) *size += tr->size;
-       }
-
+       if (size)  *size += tr->size;
        if (num)   *num += 1;
     }
 }
 
+
+/* Adds @track to the list of tracks to be deleted. The following
+   information is required: 
+   - userdata with ExtraTrackData
+   - size of track to be deleted
+   - either track->ipod_path or etr->pc_path_local */
 void mark_track_for_deletion (iTunesDB *itdb, Track *track)
 {
     ExtraiTunesDBData *eitdb;
-    g_return_if_fail (itdb);
-    g_return_if_fail (track);
+    g_return_if_fail (itdb && itdb->userdata && track);
     g_return_if_fail (track->itdb == NULL);
     eitdb = itdb->userdata;
-    g_return_if_fail (eitdb);
 
     eitdb->pending_deletion = g_list_append (eitdb->pending_deletion,
                                             track);
 }
 
-/* It might be necessary to unmark for deletion like in case of
-   dangling tracks with no real files on ipod */
-void unmark_track_for_deletion (iTunesDB *itdb, Track *track)
-{
-    ExtraiTunesDBData *eitdb;
-    g_return_if_fail (itdb);
-    g_return_if_fail (track);
-    eitdb = itdb->userdata;
-    g_return_if_fail (eitdb);
-
-    if (track != NULL)
-        eitdb->pending_deletion = g_list_remove (
-           eitdb->pending_deletion, track);
-}
 
 
 /*------------------------------------------------------------------*\
@@ -1195,8 +1169,6 @@
          fprintf (fp, "sha1_hash=%s\n", etr->sha1_hash);
       if (etr->charset && *etr->charset)
          fprintf (fp, "charset=%s\n", etr->charset);
-      if (!track->transferred && etr->oldsize)
-         fprintf (fp, "oldsize=%d\n", etr->oldsize);
       if (etr->mtime)
          fprintf (fp, "pc_mtime=%llu\n", (unsigned long long)etr->mtime);
       if (etr->local_itdb_id)
@@ -1262,29 +1234,6 @@
     return GINT_TO_POINTER(result);
 }
 
-/* Threaded copy of ipod track */
-/* Returns: GError *error */
-static gpointer th_copy (gpointer data)
-{
-    TransferData *td = data;
-    ExtraTrackData *etr;
-    GError *error = NULL;
-    g_return_val_if_fail (td && td->filename &&
-                         td->track && td->track->userdata, NULL);
-    etr = td->track->userdata;
-
-/*    fprintf (stderr, "Trying to copy: %s\n", td->filename);*/
-    itdb_cp_track_to_ipod (td->track, td->filename, &error);
-
-    /* delete old size */
-    if (td->track->transferred) etr->oldsize = 0;
-    g_mutex_lock (td->mutex);
-    td->finished = TRUE;   /* signal that thread will end */
-    g_cond_signal (td->finished_cond);
-    g_mutex_unlock (td->mutex);
-    return error;
-}
-
 /* This function is called when the user presses the abort button
  * during transfer_tracks() or delete_tracks() */
 static void file_dialog_abort (TransferData *transfer_data)
@@ -1344,6 +1293,9 @@
     dialog = gtkpod_xml_get_widget (dialog_xml, 
"file_transfer_information_dialog");
     g_return_val_if_fail (dialog, NULL);
 
+    /* the window itself */
+    td->dialog = dialog;
+
     /* text label */
     td->textlabel = gtkpod_xml_get_widget (dialog_xml, "textlabel");
 
@@ -1367,22 +1319,32 @@
 
 
 static void set_progressbar (GtkProgressBar *progressbar,
-                            time_t start, gint n, gint count)
+                            time_t start, gint n, gint count, gint init_count)
 {
+    gchar *progtext;
+    gdouble fraction;
+
     g_return_if_fail (progressbar);
 
-    gchar *progtext;
+    if (n==0)
+    {
+       fraction = 1;
+    }
+    else
+    {
+       fraction = (gdouble)count/n;
+    }
 
-    if (count == 0)
+    if (count-init_count == 0)
     {
-       progtext = g_strdup (_("0% (First Track)"));
+       progtext = g_strdup_printf (_("%d%%"), (gint)(fraction*100));
     }
     else
     {
        time_t diff, fullsecs, hrs, mins, secs;
 
        diff = time(NULL) - start;
-       fullsecs = (diff*n/count)-diff+5;
+       fullsecs = (diff*(n-init_count)/(count-init_count))-diff+5;
        hrs  = fullsecs / 3600;
        mins = (fullsecs % 3600) / 60;
        secs = ((fullsecs % 60) / 5) * 5;
@@ -1390,10 +1352,10 @@
        /* left = ((mins < left) || (100*mins >= 110*left)) ? mins : left;*/
        progtext = g_strdup_printf (
            _("%d%% (%d/%d  %d:%02d:%02d left)"),
-           count*100/n, count, n, (gint)hrs, (gint)mins, (gint)secs);
+           (gint)(fraction*100), count, n, (gint)hrs, (gint)mins, (gint)secs);
     }
 
-    gtk_progress_bar_set_fraction(progressbar, (gdouble)count/n);
+    gtk_progress_bar_set_fraction(progressbar, fraction);
     gtk_progress_bar_set_text(progressbar, progtext);
     g_free (progtext);
 }
@@ -1427,6 +1389,10 @@
       g_return_val_if_fail (itdb_get_mountpoint (itdb), FALSE);
   }
 
+  /* stop file transfer while we're deleting to avoid time-consuming
+     interference with slow access harddisks */
+  file_transfer_activate (itdb, FALSE);
+
   gtk_label_set_text (GTK_LABEL (td->textlabel), _("Status: Deleting File"));
 
   n = g_list_length (eitdb->pending_deletion);
@@ -1440,16 +1406,16 @@
       Track *track = eitdb->pending_deletion->data;
       g_return_val_if_fail (track, FALSE);
 
+      track->itdb = itdb;
       if (itdb->usertype & GP_ITDB_TYPE_IPOD)
       {
-         track->itdb = itdb;
          filename = get_file_name_from_source (track, SOURCE_IPOD);
-         track->itdb = NULL;
       }
       if (itdb->usertype & GP_ITDB_TYPE_LOCAL)
       {
          filename = get_file_name_from_source (track, SOURCE_LOCAL);
       }
+      track->itdb = NULL;
 
       if(filename)
       {
@@ -1466,7 +1432,7 @@
          {
              GTimeVal gtime;
 
-             set_progressbar (td->progressbar, start, n, count);
+             set_progressbar (td->progressbar, start, n, count, 0);
 
              g_mutex_unlock (td->mutex);
 
@@ -1503,210 +1469,265 @@
          eitdb->pending_deletion, eitdb->pending_deletion);
   }
 
-  set_progressbar (td->progressbar, start, n, count);
+  set_progressbar (td->progressbar, start, n, count, 0);
 
   while (widgets_blocked && gtk_events_pending ())
       gtk_main_iteration ();
 
   if (td->abort) result = FALSE;
 
+  file_transfer_reset (itdb);
+
   return result;
 }
 
 
+/* Reschedule tracks that failed during transfer. This is a hack as
+ * the @itdb could have been removed in the meanwhile. The clean
+ * solution would be to integrate the error display into the
+ * file_convert.c framework */
+static void transfer_reschedule (gpointer user_data1, gpointer user_data2)
+{
+    struct itdbs_head *ihead = gp_get_itdbs_head (gtkpod_window);
+    iTunesDB *itdb = user_data1;
+    GList *gl;
 
+    g_return_if_fail (itdb && ihead);
 
+    for (gl=ihead->itdbs; gl; gl=gl->next)
+    {
+       iTunesDB *it = gl->data;
+       g_return_if_fail (it);
+       if (it == itdb)
+       {   /* itdb is still valid --> reschedule tracks */
+           file_transfer_reschedule (itdb);
+           break;
+       }
+    }
+}
 
 
-/* Flushes all non-transferred tracks to the iPod filesystem
-   Returns TRUE on success, FALSE if some error occurred or not all
-   tracks were written. */
-static gboolean transfer_tracks (iTunesDB *itdb, TransferData *td)
+
+/* Show an error message that not all tracks were transferred */
+static void transfer_tracks_show_failed (iTunesDB *itdb, TransferData *td)
 {
-  GList *gl;
-  gint count, n, trackserrnum, tracksleftnum;
-  gboolean result = TRUE;
-  time_t start;
-  ExtraiTunesDBData *eitdb;
-  GThread *thread = NULL;
+    GString *string_transfer, *string_convert, *string;
+    gint failed_transfer, failed_conversion;
+    GList *tracks, *gl;
 
-  g_return_val_if_fail (itdb, FALSE);
-  eitdb = itdb->userdata;
-  g_return_val_if_fail (eitdb, FALSE);
+    g_return_if_fail (itdb && td);
 
-  n = itdb_tracks_number_nontransferred (itdb);
+    gtk_widget_hide (td->dialog);
 
-  if (n == 0) return TRUE;
+    string_transfer = g_string_sized_new (1000);
+    string_convert = g_string_sized_new (1000);
+    string = g_string_sized_new (1000);
+    failed_transfer = 0;
+    failed_conversion = 0;
 
-  /* count number of tracks to be transferred */
-  count = 0; /* tracks transferred */
-  start = time (NULL);
+    tracks = file_transfer_get_failed_tracks (itdb);
+    /* since failed_num is not 0, tracks cannot be empty */
+    g_return_if_fail (tracks);
+    /* Add information about failed tracks to the respective
+       string */
+    for (gl=tracks; gl; gl=gl->next)
+    {
+       ExtraTrackData *etr;
+       gchar *buf;
+       Track *tr = gl->data;
+       g_return_if_fail (tr && tr->userdata);
 
-  do
-  {
-      trackserrnum = 0;
-      for (gl=itdb->tracks; gl && !td->abort; gl=gl->next)
-      {
-         const gchar *file_to_transfer = NULL;
-         Track *track = gl->data;
-         ExtraTrackData *etr;
-         g_return_val_if_fail (track && track->userdata, FALSE);
-         etr = track->userdata;
+       etr = tr->userdata;
 
-         if (!track->transferred)
-         {
-             GError *error = NULL;
+       buf = get_track_info (tr, FALSE);
 
-             gchar *buf = get_track_info (track, TRUE);
-             switch (etr->conversion_status)
-             {
-             case FILE_CONVERT_INACTIVE:
-                 /* No conversion is scheduled or carried out. */
-                 file_to_transfer = etr->pc_path_locale;
-                 break;
-             case FILE_CONVERT_CONVERTED:
-                 /* Conversion has finished */
-                 file_to_transfer = etr->converted_file;
-                 /* Verify if file is still present */
-                 if (!g_file_test (file_to_transfer, G_FILE_TEST_IS_REGULAR))
-                 {   /* no -- someone deleted it :-/ convert again */
-                     /* Remove from conversion list */
-                     file_convert_cancel_track (track);
-                     file_convert_add_track (track);
-                     file_to_transfer = NULL;
-                 }
-                 break;
-             case FILE_CONVERT_FAILED:
-                 /* Conversion of this track has failed. */
-                 gtkpod_warning (_("Conversion of file '%s' has failed. The 
original file will be transferred instead.\n\n"), buf);
-                 file_to_transfer = etr->pc_path_locale;
-                 break;
-             case FILE_CONVERT_REQUIRED_FAILED:
-                 /* This track needs conversion, but conversion failed
-                    for some reason */
-                 gtkpod_warning (_("The type of file '%s' is not supported by 
the iPod and conversion failed. Please go to the Preferences to set up a 
suitable conversion script.\n\n"), buf);
-                 ++trackserrnum;
-                 /* Remove from conversion list */
-                 file_convert_cancel_track (track);
-                 break;
-             case FILE_CONVERT_REQUIRED:
-                 /* This track needs conversion, but conversion was not
-                    set up */
-                 gtkpod_warning (_("The type of file '%s' is not supported by 
the iPod. Please go to the Preferences to set up and turn on a suitable 
conversion script.\n\n"), buf);
-                 ++trackserrnum;
-                 /* Remove from conversion list */
-                 file_convert_cancel_track (track);
-                 break;
-             case FILE_CONVERT_KILLED:
-                 /* This should not happen. Ignore */
-                 fprintf (stderr, "Programming error: reached 
FILE_CONVERT_KILLED.\n");
-                 file_convert_cancel_track (track);
-                 ++trackserrnum;
-                 break;
-             case FILE_CONVERT_SCHEDULED:
-                 /* Try again later */
-                 break;
-             }
-             g_free (buf);
-             buf = NULL;
+       switch (etr->conversion_status)
+       {
+       case FILE_CONVERT_INACTIVE:
+       case FILE_CONVERT_CONVERTED:     
+   /* This track was converted successfully (or did not
+            * neeed conversion) and failed during transfer */
+           ++failed_transfer;
+           g_string_append_printf (string_transfer, "%s\n", buf);
+           break;
+       default:
+           /* These tracks failed during conversion */
+           ++failed_conversion;
+           g_string_append_printf (string_convert, "%s\n", buf);
+           break;
+       }
+       g_free (buf);
+    }
 
-             if (file_to_transfer)
-             {
-                 td->finished = FALSE;
-                 td->track = track;
-                 td->filename = file_to_transfer;
+    if (failed_conversion != 0)
+    {
+       g_string_append (string,
+                        ngettext ("The following track could not be converted 
successfully:\n\n",
+                                  "The following tracks could not be converted 
successfully:\n\n",
+                                  failed_conversion));
+       g_string_append (string, string_convert->str);
+       g_string_append (string, "\n\n");
+    }
 
-                 gtk_label_set_text (GTK_LABEL(td->textlabel),
-                                     _("Status: Copying track"));
+    if (failed_transfer != 0)
+    {
+       g_string_append (string,
+                        ngettext ("The following track could not be 
transferred successfully:\n\n",
+                                  "The following tracks could not be 
transferred successfully:\n\n",
+                                  failed_transfer));
+       g_string_append (string, string_transfer->str);
+       g_string_append (string, "\n\n");
+    }
 
-                 g_mutex_lock (td->mutex);
+    gtkpod_confirmation (CONF_ID_TRANSFER,    /* ID     */
+                        FALSE,               /* modal, */
+                        _("Warning"),        /* title  */
+                        _("The iPod could not be ejected. Please fix the 
problems mentioned below and then eject the iPod again. Pressing 'OK' will 
re-schedule the failed tracks for conversion and transfer."),
+                        string->str,         /* text to be displayed */
+                        NULL, 0, NULL,       /* option 1 */
+                        NULL, 0, NULL,       /* option 2 */
+                        TRUE,                /* gboolean confirm_again, */
+                        NULL,                /* confirm_again_key, */
+                        transfer_reschedule, /* ConfHandler ok_handler,*/
+                        NULL,                /* don't show "Apply" */
+                        CONF_NULL_HANDLER,   /* cancel_handler,*/
+                        itdb,                /* gpointer user_data1,*/
+                        NULL);               /* gpointer user_data2,*/
 
-                 thread = g_thread_create (th_copy, td, TRUE, NULL);
+    g_string_free (string_transfer, TRUE);
+    g_string_free (string_convert, TRUE);
+    g_string_free (string, TRUE);
+}
 
-                 do
-                 {
-                     GTimeVal gtime;
 
-                     set_progressbar (td->progressbar, start, n, 
count+trackserrnum);
 
-                     g_mutex_unlock (td->mutex);
+/* Initiates and waits for transfer of tracks to the iPod */
+static gboolean transfer_tracks (iTunesDB *itdb, TransferData *td)
+{
+    gint to_convert_num, converting_num, to_transfer_num;
+    gint transferred_num, failed_num, transferred_init;
+    gboolean result = TRUE;
+    FileTransferStatus status;
+    ExtraiTunesDBData *eitdb;
+    time_t start;
 
-                     while (widgets_blocked && gtk_events_pending ())
-                         gtk_main_iteration ();
+    g_return_val_if_fail (itdb && td, FALSE);
+    eitdb = itdb->userdata;
+    g_return_val_if_fail (eitdb, FALSE);
 
-                     g_mutex_lock (td->mutex);
+    /* make sure background transfer is running */
+    file_transfer_activate (itdb, TRUE);
+    file_transfer_continue (itdb);
+    /* reschedule previously failed tracks */
+    file_transfer_reschedule (itdb);
 
-                     /* wait a maximum of 20 ms */
-                     g_get_current_time (&gtime);
-                     g_time_val_add (&gtime, 20*1000);
-                     g_cond_timed_wait (td->finished_cond,
-                                        td->mutex, &gtime);
+    /* find out how many tracks have already been processed */
+    file_transfer_get_status (itdb,
+                             NULL, NULL, NULL, &transferred_num, &failed_num);
+    transferred_init = transferred_num + failed_num;
 
-                 } while(!td->finished);
+    start = time (NULL);
 
-                 g_mutex_unlock (td->mutex);
-                 error = g_thread_join (thread);
+    do
+    {
+       gchar *buf;
 
-                 /* Remove from conversion list, now that we have
-                  * copied the file */
-                 file_convert_cancel_track (track);
+       status = file_transfer_get_status (itdb,
+                                          &to_convert_num, &converting_num,
+                                          &to_transfer_num, &transferred_num,
+                                          &failed_num);
 
-                 if (error)
-                 {   /* an error occurred */
-                     if(!td->abort) {
-                         result = FALSE;
-                         if (error->message)
-                             gtkpod_warning ("%s\n\n", error->message);
-                         else
-                             g_warning ("error->message == NULL!\n");
-                     }
-                     g_error_free (error);
-                     ++trackserrnum;
-                 }
-                 else
-                 {
-                     ++count;
-                 }
+       set_progressbar (td->progressbar, start,
+                        
to_convert_num+to_transfer_num+failed_num+transferred_num,
+                        transferred_num+failed_num,
+                        transferred_init);
 
-                 data_changed (itdb); /* otherwise new free space status from
-                                         iPod is never read and free space
-                                         keeps increasing while we copy more
-                                         and more files to the iPod */
-             }
-         }
-      } /* for (gl=itdb->tracks;.;.) */
+       if (to_transfer_num > 0)
+       {
+           buf = g_strdup_printf (_("Status: Copying track"));
+       }
+       else
+       {
+           if ((to_convert_num + converting_num) > 0)
+           {
+               buf = g_strdup_printf (_("Status: Waiting for conversion to 
complete"));
+           }
+           else
+           {
+               buf = g_strdup_printf (_("Status: Finished transfer"));
+           }
+       }
 
-      set_progressbar (td->progressbar, start, n, count+trackserrnum);
+/*     buf = g_strdup_printf (_("Status: %d. To convert: %d. To transfer: %d\n"
+                                "Transferred: %d. Failed: %d"),
+                              status, to_convert_num, to_transfer_num,
+                              transferred_num, failed_num);*/
+       gtk_label_set_text (GTK_LABEL(td->textlabel), buf);
+       g_free (buf);
 
-      tracksleftnum = itdb_tracks_number_nontransferred (itdb);
-      if (tracksleftnum > trackserrnum)
-      {   /* waiting for files to finish conversion */
-         do
-         {
-             set_progressbar (td->progressbar, start, n, count+trackserrnum);
+       if ((to_convert_num != 0) && (converting_num == 0))
+       {   /* Force the conversion to continue. Not sure if this scenario
+            * is likely to happen, but better be safe then sorry */
+           file_convert_continue ();
+       }
 
-             gtk_label_set_text (GTK_LABEL(td->textlabel),
-                                 _("Status: Waiting for conversion to 
complete"));
+       while (widgets_blocked && gtk_events_pending ())
+           gtk_main_iteration ();
 
-             while (widgets_blocked && gtk_events_pending ())
-                 gtk_main_iteration ();
+       /* sleep 20 ms */
+       g_usleep (20*1000);
+    } while (!td->abort &&
+            (status != FILE_TRANSFER_DISK_FULL) &&
+            (to_convert_num + to_transfer_num) > 0);
 
-         } while (!td->abort &&
-                  !file_convert_timed_wait (itdb, 20));
-      }
-  } while (!td->abort &&
-          (itdb_tracks_number_nontransferred (itdb) > trackserrnum));
+    /* reset background transfer to value in prefs */
+    file_transfer_reset (itdb);
 
+    if (td->abort)
+    {
+       result = FALSE;
+    }
+    else if (status == FILE_TRANSFER_DISK_FULL)
+    {
+       gchar *buf;
+       GtkWidget *dialog;
 
-  if (td->abort)  result = FALSE;   /* negative result if user aborted */
+       gtk_widget_hide (td->dialog);
 
-  if (result == FALSE)
-      gtkpod_statusbar_message (_("Some tracks were not written to iPod. 
Export aborted!"));
+       buf = g_strdup_printf (ngettext (
+                                  "One track could not be transferred because 
your iPod is full. Either delete some tracks or otherwise create space on the 
iPod before ejecting the iPod again.",
+                                  "%d tracks could not be transferred because 
your iPod is full. Either delete some tracks or otherwise create space on the 
iPod before ejecting the iPod again.", to_transfer_num),
+                              to_transfer_num);
 
-  return result;
+       dialog = gtk_message_dialog_new (
+           GTK_WINDOW (gtkpod_window),
+           GTK_DIALOG_DESTROY_WITH_PARENT,
+           GTK_MESSAGE_WARNING,
+           GTK_BUTTONS_OK,
+           buf);
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (dialog);
+       g_free (buf);
+       result = FALSE;
+    }
+    else if (failed_num != 0)    /* one error message is enough -> else{... */
+    {
+       transfer_tracks_show_failed (itdb, td);
+       result = FALSE;
+    }
+
+    if (result == TRUE)
+    {
+       /* remove transferred tracks from list so they won't be removed
+          when deleting the itdb */
+       file_transfer_ack_itdb (itdb);
+    }
+
+    return result;
 }
 
 
+
 static gboolean gp_write_itdb (iTunesDB *itdb)
 {
   gchar *cfgdir;
@@ -1796,7 +1817,7 @@
          success = delete_files (itdb, transferdata);
          if (!success)
          {
-             gtkpod_statusbar_message (_("Some tracks could not be deleted 
from the iPod. Export aborted!"));
+             gtkpod_warning (_("Some tracks could not be deleted from the 
iPod. Export aborted!"));
          }
       }
       if (success)

Index: info.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/info.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- info.c      23 Apr 2007 15:33:31 -0000      1.48
+++ info.c      6 May 2007 14:16:17 -0000       1.49
@@ -1,6 +1,5 @@
-/* Time-stamp: <2007-04-23 22:22:23 jcs>
-|
-|  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
+/*
+|  Copyright (C) 2002-2007 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
 | 
 |  URL: http://www.gtkpod.org/
@@ -52,6 +51,7 @@
 static guint statusbar_timeout_id = 0;
 static guint statusbar_timeout = STATUSBAR_TIMEOUT;
 
+#define SPACE_TIMEOUT 1000
 /* lock for size related variables (used by child and parent) */
 static GMutex *space_mutex = NULL;
 static GThread *space_thread = NULL;

Index: info.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/info.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- info.h      23 Jun 2006 16:46:12 -0000      1.15
+++ info.h      6 May 2007 14:16:17 -0000       1.16
@@ -1,6 +1,5 @@
-/* Time-stamp: <2006-06-24 01:39:23 jcs>
-|
-|  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
+/*
+|  Copyright (C) 2002-2007 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
 | 
 |  URL: http://www.gtkpod.org/
@@ -58,7 +57,6 @@
 void gtkpod_tracks_statusbar_update(void);
 
 /* space stuff */
-#define SPACE_TIMEOUT 4000   /* update interval in ms */
 void space_set_ipod_itdb (iTunesDB *itdb);
 iTunesDB *space_get_ipod_itdb (void);
 void space_data_update (void);

Index: misc_confirm.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_confirm.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- misc_confirm.c      22 Apr 2007 18:06:16 -0000      1.53
+++ misc_confirm.c      6 May 2007 14:16:17 -0000       1.54
@@ -541,7 +541,7 @@
                msg = g_strdup_printf (_("Removed all podcasts from the iPod"));
                if (pm_get_selected_playlist () == dd->pl)
                    st_redisplay (0);
-//             display_reset (0);
+/*             display_reset (0);*/
            }
            else
            {

Index: misc_playlist.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_playlist.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- misc_playlist.c     7 Apr 2007 04:43:15 -0000       1.41
+++ misc_playlist.c     6 May 2007 14:16:17 -0000       1.42
@@ -926,6 +926,7 @@
           (hash value may have changed!) */
        sha1_track_remove (track);
        /* need to remove the old value manually! */
+       g_free (etr->sha1_hash);
        etr->sha1_hash = NULL;
        oldtrack = sha1_track_exists_insert (itdb, track);
        if (oldtrack) { /* track exists, remove old track
@@ -934,6 +935,8 @@
            gp_duplicate_remove (track, oldtrack);
            sha1_track_exists_insert (itdb, track);
        }
+       /* mark for conversion / transfer */
+       file_convert_add_track (track);
     }
     g_list_free(l_dangling);
     data_changed (itdb);

Index: misc_track.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_track.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- misc_track.c        27 Apr 2007 15:19:53 -0000      1.65
+++ misc_track.c        6 May 2007 14:16:17 -0000       1.66
@@ -1639,7 +1639,7 @@
        g_return_if_fail (etr);
        if (!tr->transferred)
        {
-           if (size)  *size += tr->size - etr->oldsize;
+           if (size)  *size += tr->size;
            if (num)   *num += 1;
        }
     }

Index: prefs_window.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs_window.c,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -d -r1.198 -r1.199
--- prefs_window.c      27 Apr 2007 15:50:44 -0000      1.198
+++ prefs_window.c      6 May 2007 14:16:17 -0000       1.199
@@ -332,6 +332,7 @@
        "sync_delete_tracks_toggle",
        "sync_show_summary_toggle",
        "file_convert_display_log_button",
+       "file_convert_background_transfer_button",
        NULL
     };
     /* ... and corresponding keys */
@@ -340,6 +341,7 @@
        KEY_SYNC_DELETE_TRACKS,
        KEY_SYNC_SHOW_SUMMARY,
        FILE_CONVERT_DISPLAY_LOG,
+       FILE_CONVERT_BACKGROUND_TRANSFER,
        NULL
     };
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to