logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

[gtpd-cvs] gtkpod/src display_itdb.c, 1.65, 1.65.2.1 display_itdb.h, 1.41, : msg#00053

ipod.gtkpod.cvs

Subject: [gtpd-cvs] gtkpod/src display_itdb.c, 1.65, 1.65.2.1 display_itdb.h, 1.41, 1.41.2.1 fetchcover.c, 1.4, 1.4.2.1 file.c, 1.198, 1.198.2.1 file.h, 1.59, 1.59.4.1 file_convert.c, 1.5, 1.5.2.1 file_convert.h, 1.4, 1.4.2.1 file_itunesdb.c, 1.117, 1.117.2.1 main.c, 1.63, 1.63.2.1 misc.c, 1.220, 1.220.2.1 misc.h, 1.125, 1.125.2.1 misc_track.c, 1.63, 1.63.2.1 misc_track.h, 1.18, 1.18.2.1

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

Modified Files:
Tag: threaded_conversion_branch
display_itdb.c display_itdb.h fetchcover.c file.c file.h
file_convert.c file_convert.h file_itunesdb.c main.c misc.c
misc.h misc_track.c misc_track.h
Log Message:
Cached multi-threaded background file conversion development branch.



Index: display_itdb.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_itdb.c,v
retrieving revision 1.65
retrieving revision 1.65.2.1
diff -u -d -r1.65 -r1.65.2.1
--- display_itdb.c 7 Apr 2007 14:55:49 -0000 1.65
+++ display_itdb.c 19 Apr 2007 14:46:06 -0000 1.65.2.1
@@ -39,6 +39,7 @@
#include "display.h"
#include "sha1.h"
#include "file.h"
+#include "file_convert.h"
#include "misc.h"
#include "misc_track.h"
#include "info.h"
@@ -124,11 +125,14 @@
etr_dup->year_str = g_strdup (etr->year_str);
etr_dup->pc_path_locale = g_strdup (etr->pc_path_locale);
etr_dup->pc_path_utf8 = g_strdup (etr->pc_path_utf8);
+ etr_dup->converted_file = g_strdup (etr->converted_file);
etr_dup->thumb_path_locale = g_strdup (etr->thumb_path_locale);
etr_dup->thumb_path_utf8 = g_strdup (etr->thumb_path_utf8);
etr_dup->hostname = g_strdup (etr->hostname);
etr_dup->sha1_hash = g_strdup (etr->sha1_hash);
etr_dup->charset = g_strdup (etr->charset);
+ /* clear the pc_path_hashed flag */
+ etr_dup->pc_path_hashed = FALSE;
}
return etr_dup;
}
@@ -150,6 +154,10 @@
{
space_set_ipod_itdb (NULL);
}
+
+ /* cancel all pending conversions */
+ file_convert_cancel_itdb (itdb);
+
itdb_free (itdb);
}

@@ -278,10 +286,13 @@
/* exception: sha1_hash, hostname, charset: these may be NULL. */
gp_track_validate_entries (track);
itdb_track_add (itdb, track, -1);
+ /* add to filename hash */
gp_itdb_pc_path_hash_add_track (track);
+ /* add to background conversion if necessary */
+ file_convert_add_track (track);
result = track;
+ data_changed (itdb);
}
- data_changed (itdb);
return result;
}

@@ -292,8 +303,10 @@
playlist -- see gp_playlist_remove_track for details */
void gp_track_remove (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.41
retrieving revision 1.41.2.1
diff -u -d -r1.41 -r1.41.2.1
--- display_itdb.h 7 Apr 2007 14:55:49 -0000 1.41
+++ display_itdb.h 19 Apr 2007 14:46:06 -0000 1.41.2.1
@@ -64,22 +64,27 @@

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 */
- time_t mtime; /* modification date of PC file */
- gchar *thumb_path_locale; /* same for thumbnail */
- gchar *thumb_path_utf8; /* same for thumbnail */
- gchar *hostname; /* name of host this file has been imported on*/
- gchar *sha1_hash; /* sha1 hash of file (or NULL) */
- gchar *charset; /* charset used for ID3 tags */
- gint32 sortindex; /* used for stable sorting (current order) */
- gboolean tchanged; /* temporary use, e.g. in detail.c */
- guint64 local_itdb_id; /* when using DND from local to iPod: original itdb
*/
- guint64 local_track_dbid;/* when using DND from local to iPod: original
track */
- gboolean pc_path_hashed;/* for programming error detection (see */
- /* gp_itdb_local_path_hash_add_track() */
+ 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 */
+ time_t mtime; /* modification date of PC file */
+ gboolean pc_path_hashed; /* for programming error detection (see
+ gp_itdb_local_path_hash_add_track() */
+ gchar *converted_file; /* if converted file exists: name in utf8 */
+ gint32 orig_filesize; /* size of original file (if converted) */
+ FileConvertStatus conversion_status; /* current status of conversion */
+ gchar *thumb_path_locale;/* same for thumbnail */
+ gchar *thumb_path_utf8; /* same for thumbnail */
+ gchar *hostname; /* name of host this file has been imported on */
+ gchar *sha1_hash; /* sha1 hash of file (or NULL) */
+ gchar *charset; /* charset used for ID3 tags */
+ gint32 sortindex; /* used for stable sorting (current order) */
+ gboolean tchanged; /* temporary use, e.g. in detail.c */
+ guint64 local_itdb_id; /* when using DND from local to iPod:
+ original itdb */
+ guint64 local_track_dbid; /* when using DND from local to iPod:
+ original track */
} ExtraTrackData;

/* types for iTunesDB */

Index: fetchcover.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/fetchcover.c,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -d -r1.4 -r1.4.2.1
--- fetchcover.c 16 Apr 2007 21:57:57 -0000 1.4
+++ fetchcover.c 19 Apr 2007 14:46:06 -0000 1.4.2.1
@@ -310,7 +310,7 @@
gchar *template = prefs_get_string("coverart_template");
gchar **template_items = g_strsplit(template, ";", 0);

- gchar *filename = get_string_from_template(fetchcover_track,
*template_items, FALSE);
+ gchar *filename = get_string_from_template(fetchcover_track,
*template_items, FALSE, FALSE);

/* Use the index position of the cover in the glist to create a unique
filename
* Convert the index number to a string and prefix with a dot (hidden
file)

Index: file.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file.c,v
retrieving revision 1.198
retrieving revision 1.198.2.1
diff -u -d -r1.198 -r1.198.2.1
--- file.c 7 Apr 2007 04:43:15 -0000 1.198
+++ file.c 19 Apr 2007 14:46:07 -0000 1.198.2.1
@@ -1000,7 +1000,7 @@
while (*tplp && !filename_local)
{
gchar *filename_utf8;
- gchar *fname = get_string_from_template (tr, *tplp, FALSE);
+ gchar *fname = get_string_from_template (tr, *tplp, FALSE, FALSE);
if (fname)
{
if (strchr (*tplp, '.') != NULL)

Index: file.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file.h,v
retrieving revision 1.59
retrieving revision 1.59.4.1
diff -u -d -r1.59 -r1.59.4.1
--- file.h 10 Feb 2007 09:33:33 -0000 1.59
+++ file.h 19 Apr 2007 14:46:07 -0000 1.59.4.1
@@ -1,4 +1,4 @@
-/* Time-stamp: <2007-02-10 17:52:19 jcs>
+/* Time-stamp: <2007-04-14 13:24:22 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -97,7 +97,6 @@
const gchar *mp, const gchar *name_off,
const gchar *name_loc);
void gp_load_ipods (void);
-iTunesDB *gp_merge_itdb (iTunesDB *old_itdb);
iTunesDB *gp_load_ipod (iTunesDB *itdb);
gboolean gp_eject_ipod(iTunesDB *itdb);
gboolean gp_save_itdb (iTunesDB *itdb);

Index: file_convert.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_convert.c,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -d -r1.5 -r1.5.2.1
--- file_convert.c 9 Apr 2007 13:33:50 -0000 1.5
+++ file_convert.c 19 Apr 2007 14:46:07 -0000 1.5.2.1
@@ -70,8 +70,9 @@
#include "prefs.h"
#include "misc.h" /* T_item */
#include "misc_track.h" /* track_get_item_pointer */
+#include <errno.h>

-/* #define DEBUG_CONV */
+#define DEBUG_CONV
#ifdef DEBUG_CONV
# define _TO_STR(x) #x
# define TO_STR(x) _TO_STR(x)
@@ -83,6 +84,7 @@
[...1703 lines suppressed...]
+ gl = g_list_find (conv->threads, g_thread_self());
+ if (gl)
+ {
+ gl->data = NULL;
+ }
+ else
+ {
+ fprintf (stderr, "***** programming error -- g_thread_self not found in
threads list\n");
+ }
+
+ /* reduce count of running threads */
+ --conv->threads_num;
+
+ g_mutex_unlock (conv->mutex);
+
+ debug ("%p thread exit\n", g_thread_self ());
+
+ return NULL;
}
-#endif

Index: file_convert.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_convert.h,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -d -r1.4 -r1.4.2.1
--- file_convert.h 9 Apr 2007 13:33:50 -0000 1.4
+++ file_convert.h 19 Apr 2007 14:46:07 -0000 1.4.2.1
@@ -36,10 +36,10 @@
# include <config.h>
#endif

-#include <gtk/gtk.h>
#include <itdb.h>
#include <file.h>

+#if 0
typedef struct
{
Track *track; /* Track to convert */
@@ -54,14 +54,31 @@
gboolean aborted;
} TrackConv;

-
GError *file_convert_pre_copy (TrackConv *converter);
GError *file_convert_post_copy (TrackConv *converter);
GError *file_convert_wait_for_conversion (TrackConv *converter);

/* extern gchar **cmdline_to_argv(const gchar *cmdline, Track *track); */
+#endif

-void conversion_init (void);
-void conversion_shutdown (void);
+typedef enum
+{
+ FILE_CONVERT_INACTIVE = 0,
+ FILE_CONVERT_REQUIRED,
+ FILE_CONVERT_SCHEDULED,
+ FILE_CONVERT_PROCESSING,
+ FILE_CONVERT_FAILED,
+ FILE_CONVERT_REQUIRED_FAILED,
+ FILE_CONVERT_KILLED,
+ FILE_CONVERT_CONVERTED
+} FileConvertStatus;
+
+void file_convert_init (void);
+void file_convert_shutdown (void);
+gboolean file_convert_add_track (Track *track);
+void file_convert_itdb_first (iTunesDB *itdb);
+void file_convert_cancel_itdb (iTunesDB *itdb);
+void file_convert_cancel_track (Track *track);
+Track *file_convert_timed_wait (iTunesDB* itdb, gint ms);

#endif

Index: file_itunesdb.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_itunesdb.c,v
retrieving revision 1.117
retrieving revision 1.117.2.1
diff -u -d -r1.117 -r1.117.2.1
--- file_itunesdb.c 8 Apr 2007 10:12:15 -0000 1.117
+++ file_itunesdb.c 19 Apr 2007 14:46:07 -0000 1.117.2.1
@@ -61,7 +61,7 @@
\*------------------------------------------------------------------*/

/* only used when reading extended info from file */
-/* see definition of Track in track.h for explanations */
+/* see definition of ExtraTrackData in display_itdb.h for explanations */
struct track_extended_info
{
guint ipod_id;
@@ -70,6 +70,7 @@
time_t mtime;
gchar *thumb_path_locale;
gchar *thumb_path_utf8;
+ gchar *converted_file;
gchar *sha1_hash;
gchar *charset;
gchar *hostname;
@@ -84,16 +85,14 @@
GMutex *mutex; /* lock when modifying struct! */
gboolean abort; /* TRUE = abort */
Track *track; /* Current track */
- GPid converter_pid; /* Converter used for track */
+ const gchar *filename; /* Filename to copy */
} TransferData;


-#ifdef G_THREADS_ENABLED
/* Thread specific */
static GMutex *mutex = NULL;
static GCond *cond = NULL;
static gboolean mutex_data = FALSE;
-#endif
/* Used to keep the "extended information" until the iTunesDB is
loaded */
static GHashTable *extendedinfohash = NULL;
@@ -203,6 +202,8 @@
etr->charset = g_strdup (sei->charset);
if (sei->hostname && !etr->hostname)
etr->hostname = g_strdup (sei->hostname);
+ if (sei->converted_file && !etr->converted_file)
+ 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;
@@ -228,6 +229,7 @@
g_free (sei->sha1_hash);
g_free (sei->charset);
g_free (sei->hostname);
+ g_free (sei->converted_file);
g_free (sei->ipod_path);
g_free (sei);
}
@@ -389,6 +391,8 @@
}
else if (g_ascii_strcasecmp (line, "hostname") == 0)
sei->hostname = g_strdup (arg);
+ else if (g_ascii_strcasecmp (line, "converted_file") == 0)
+ sei->converted_file = g_strdup (arg);
else if (g_ascii_strcasecmp (line, "filename_locale") == 0)
sei->pc_path_locale = g_strdup (arg);
else if (g_ascii_strcasecmp (line, "filename_utf8") == 0)
@@ -890,6 +894,7 @@
g_return_val_if_fail (eitdb, NULL);
g_return_val_if_fail (eitdb->itdb_imported == FALSE, NULL);

+
mountpoint = get_itdb_prefs_string (itdb, KEY_MOUNTPOINT);
call_script ("gtkpod.load", mountpoint, NULL);

@@ -1054,6 +1059,11 @@
gboolean success;
g_return_val_if_fail (itdb, FALSE);

+ if (itdb->usertype & GP_ITDB_TYPE_IPOD)
+ { /* handle conversions for this repository with priority */
+ file_convert_itdb_first (itdb);
+ }
+
/* update smart playlists before writing */
itdb_spl_update_live (itdb);
pl = pm_get_selected_playlist ();
@@ -1214,6 +1224,8 @@
fprintf (fp, "id=%d\n", track->id);
if (etr->hostname)
fprintf (fp, "hostname=%s\n", etr->hostname);
+ if (etr->converted_file)
+ fprintf (fp, "converted_file=%s\n", etr->converted_file);
if (etr->pc_path_locale && *etr->pc_path_locale)
fprintf (fp, "filename_locale=%s\n", etr->pc_path_locale);
if (etr->pc_path_utf8 && *etr->pc_path_utf8)
@@ -1269,7 +1281,6 @@
TransferData *transfer_data;
transfer_data = g_new0 (TransferData, 1);
transfer_data->mutex = g_mutex_new ();
- transfer_data->converter_pid = -1;
return transfer_data;
}

@@ -1279,7 +1290,6 @@
g_free (transfer_data);
}

-#ifdef G_THREADS_ENABLED
/* Threaded remove file */
/* returns: int result (of remove()) */
static gpointer th_remove (gpointer filename)
@@ -1293,113 +1303,27 @@
g_mutex_unlock (mutex);
return GUINT_TO_POINTER(result);
}
-#endif

/* Threaded copy of ipod track */
/* Returns: GError *error */
static gpointer th_copy (gpointer data)
{
- TransferData *transfer_data = data;
- Track *track;
+ TransferData *td = data;
ExtraTrackData *etr;
- FileType type;
- TrackConv *converter = NULL;
GError *error = NULL;
- g_return_val_if_fail (transfer_data, NULL);
- track = transfer_data->track;
- g_return_val_if_fail (track, NULL);
- etr = track->userdata;
- g_return_val_if_fail (etr, NULL);
- const gchar *file_to_transfer=etr->pc_path_locale;
- gboolean convert = FALSE, must_convert = FALSE;
- const gchar *typestr = "";
-
- /* check if we need to convert the file */
- type = determine_file_type (file_to_transfer);
- switch (type)
- {
- case FILE_TYPE_UNKNOWN:
- case FILE_TYPE_M4P:
- case FILE_TYPE_M4B:
- case FILE_TYPE_M4V:
- case FILE_TYPE_MP4:
- case FILE_TYPE_MOV:
- case FILE_TYPE_MPG:
- case FILE_TYPE_M3U:
- case FILE_TYPE_PLS:
- case FILE_TYPE_IMAGE:
- case FILE_TYPE_DIRECTORY:
- break;
- case FILE_TYPE_M4A:
- convert = prefs_get_int ("convert_m4a");
- break;
- case FILE_TYPE_WAV:
- convert = prefs_get_int ("convert_wav");
- break;
- case FILE_TYPE_MP3:
- convert = prefs_get_int ("convert_mp3");
- break;
- case FILE_TYPE_OGG:
- convert = prefs_get_int ("convert_ogg");
- must_convert = TRUE;
- typestr = _("Ogg Vorbis");
- break;
- case FILE_TYPE_FLAC:
- convert = prefs_get_int ("convert_flac");
- must_convert = TRUE;
- typestr = _("FLAC");
- break;
- }
-
- if (convert)
- {
- converter = g_new0 (TrackConv, 1);
- converter->type = type;
- converter->track = track;
- error = file_convert_pre_copy (converter);
- if (!error)
- {
- g_mutex_lock (transfer_data->mutex);
- transfer_data->converter_pid = converter->child_pid;
- g_mutex_unlock (transfer_data->mutex);
-
- error = file_convert_wait_for_conversion (converter);
-
- g_mutex_lock (transfer_data->mutex);
- transfer_data->converter_pid = -1;
- g_mutex_unlock (transfer_data->mutex);
-
- if (!error)
- file_to_transfer = converter->converted_file;
- }
- }
- else if (must_convert)
- {
- error = g_error_new(G_FILE_ERROR, 0,
- _("\"%s\" wasn't copied because iPods do not support %s files
natively.\n"
- "Go to the Preferences to set up and turn on a suitable conversion
script.\n"),
- file_to_transfer, typestr );
- }
+ g_return_val_if_fail (td && td->filename &&
+ td->track && td->track->userdata, NULL);
+ etr = td->track->userdata;

- if (error == NULL)
- {
- fprintf (stderr, "Trying to copy: %s\n", file_to_transfer);
- itdb_cp_track_to_ipod (track, file_to_transfer, &error);
- if (converter)
- {
- file_convert_post_copy (converter);
- g_free (converter);
- }
- }
+ fprintf (stderr, "Trying to copy: %s\n", td->filename);
+ itdb_cp_track_to_ipod (td->track, td->filename, &error);

/* delete old size */
- if (track->transferred) etr->oldsize = 0;
-#ifdef G_THREADS_ENABLED
+ if (td->track->transferred) etr->oldsize = 0;
g_mutex_lock (mutex);
mutex_data = TRUE; /* signal that thread will end */
g_cond_signal (cond);
g_mutex_unlock (mutex);
-#endif
return error;
}

@@ -1413,12 +1337,6 @@

transfer_data->abort = TRUE;

- /* kill conversion if in progress */
- if (transfer_data->converter_pid != -1)
- {
- kill (transfer_data->converter_pid, SIGTERM);
- }
-
g_mutex_unlock (transfer_data->mutex);
}

@@ -1549,12 +1467,10 @@
gint w, h;
TransferData *transfer_data;
ExtraiTunesDBData *eitdb;
-#ifdef G_THREADS_ENABLED
GThread *thread = NULL;
GTimeVal gtime;
if (!mutex) mutex = g_mutex_new ();
if (!cond) cond = g_cond_new ();
-#endif

g_return_val_if_fail (itdb, FALSE);
eitdb = itdb->userdata;
@@ -1599,7 +1515,6 @@
if(filename)
{
guint rmres;
-#ifdef G_THREADS_ENABLED
mutex_data = FALSE;
thread = g_thread_create (th_remove, filename, TRUE, NULL);
if (thread)
@@ -1626,13 +1541,6 @@
g_warning ("Thread creation failed, falling back to default.\n");
remove (filename);
}
-#else
- rmres = remove(filename);
- if (rmres == -1) result = FALSE;
-/* fprintf(stderr, "Removed %s-%s(%d)\n%s\n", track->artist,
- track->title, track->ipod_id,
- filename);*/
-#endif
g_free(filename);
}
itdb_track_free (track);
@@ -1662,19 +1570,18 @@
static gboolean flush_tracks (iTunesDB *itdb)
{
GList *gl;
- gint count, n, w, h;
+ gint count, n, w, h, trackserrnum, tracksleftnum;
gboolean result = TRUE;
TransferData *transfer_data;
GtkWidget *dialog, *progress_bar;
time_t start;
gchar *progtext = NULL;
ExtraiTunesDBData *eitdb;
-#ifdef G_THREADS_ENABLED
GThread *thread = NULL;
GTimeVal gtime;
+
if (!mutex) mutex = g_mutex_new ();
if (!cond) cond = g_cond_new ();
-#endif

g_return_val_if_fail (itdb, FALSE);
eitdb = itdb->userdata;
@@ -1690,10 +1597,6 @@
dialog = create_file_dialog (&progress_bar,
(GtkWidget**)&details_log,
transfer_data);
- progtext = g_strdup (_("preparing to copy..."));
- gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar), progtext);
- while (widgets_blocked && gtk_events_pending ()) gtk_main_iteration ();
- g_free (progtext);

transfer_data->abort = FALSE;

@@ -1701,93 +1604,173 @@
count = 0; /* tracks transferred */
start = time (NULL);

- for (gl=itdb->tracks; gl && !transfer_data->abort; gl=gl->next)
+ gtkpod_statusbar_timeout (3*STATUSBAR_TIMEOUT);
+
+ do
{
time_t diff, fullsecs, hrs, mins, secs;
- Track *track = gl->data;
- g_return_val_if_fail (track, FALSE); /* this will hang the
- application :-( */
- g_mutex_lock (transfer_data->mutex);
- transfer_data->track = track;
- g_mutex_unlock (transfer_data->mutex);

- if (!track->transferred) /* but this would crash
- it otherwise... */
+ trackserrnum = 0;
+ for (gl=itdb->tracks; gl && !transfer_data->abort; gl=gl->next)
{
- GError *error = NULL;
-#ifdef G_THREADS_ENABLED
- mutex_data = FALSE;
- thread = g_thread_create (th_copy, transfer_data, TRUE, NULL);
- if (thread)
+ const gchar *file_to_transfer = NULL;
+ Track *track = gl->data;
+ ExtraTrackData *etr;
+ g_return_val_if_fail (track && track->userdata, FALSE);
+ etr = track->userdata;
+
+ if (!track->transferred)
{
- g_mutex_lock (mutex);
- do
+ GError *error = NULL;
+
+ 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;
+ /* Remove from conversion list */
+ file_convert_cancel_track (track);
+ 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;
+ /* Remove from conversion list */
+ file_convert_cancel_track (track);
+ 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;
+ 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:
+ case FILE_CONVERT_PROCESSING:
+ /* Try again later */
+ break;
+ }
+ g_free (buf);
+ buf = NULL;
+
+ if (file_to_transfer)
+ {
+ transfer_data->track = track;
+ transfer_data->filename = file_to_transfer;
+
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progress_bar),
+ (gdouble) count/n);
+ if (count == 0)
+ {
+ progtext = g_strdup (_("0% (Copying first track)"));
+ }
+ else
+ {
+ diff = time(NULL) - start;
+ fullsecs = (diff*n/count)-diff+5;
+ hrs = fullsecs / 3600;
+ mins = (fullsecs % 3600) / 60;
+ secs = ((fullsecs % 60) / 5) * 5;
+ /* don't bounce up too quickly (>10% change only) */
+ /* left = ((mins < left) || (100*mins >= 110*left)) ?
mins : left;*/
+ progtext = g_strdup_printf (
+ _("%d%% (%d:%02d:%02d left)"),
+ count*100/n, (int)hrs, (int)mins, (int)secs);
+ }
+ gtk_progress_bar_set_text(GTK_PROGRESS_BAR (progress_bar),
+ progtext);
+ g_free (progtext);
+
while (widgets_blocked && gtk_events_pending ())
gtk_main_iteration ();
- /* wait a maximum of 20 ms */
- g_get_current_time (&gtime);
- g_time_val_add (&gtime, 20000);
- g_cond_timed_wait (cond, mutex, &gtime);
- } while(!mutex_data);
- g_mutex_unlock (mutex);
- error = g_thread_join (thread);
- }
- else {
- g_warning ("Thread creation failed, falling back to default.\n");
- error = th_copy (transfer_data);
- }
-#else
- error = th_copy (transfer_data);
-#endif
- if (error)
- { /* an error occurred */
- if(!transfer_data->abort) {
- result = FALSE;
- if (error->message)
- gtkpod_warning ("%s\n\n", error->message);
- else
- g_warning ("error->message == NULL!\n");
- }
- g_error_free (error);
- }
- 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 */
- ++count;
- if (count == 1) /* we need longer timeout */
- {
- gtkpod_statusbar_timeout (3*STATUSBAR_TIMEOUT);
+
+ thread = g_thread_create (th_copy, transfer_data, TRUE, NULL);
+ if (thread)
+ {
+ g_mutex_lock (mutex);
+ do
+ {
+ /* wait a maximum of 20 ms */
+ g_get_current_time (&gtime);
+ g_time_val_add (&gtime, 20*1000);
+ g_cond_timed_wait (cond, mutex, &gtime);
+ while (widgets_blocked && gtk_events_pending ())
+ gtk_main_iteration ();
+ } while(!mutex_data);
+ g_mutex_unlock (mutex);
+ error = g_thread_join (thread);
+ }
+ else {
+ g_warning ("Thread creation failed, falling back to
default.\n");
+ error = th_copy (transfer_data);
+ }
+ if (error)
+ { /* an error occurred */
+ if(!transfer_data->abort) {
+ result = FALSE;
+ if (error->message)
+ gtkpod_warning ("%s\n\n", error->message);
+ else
+ g_warning ("error->message == NULL!\n");
+ }
+ g_error_free (error);
+ }
+ 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 */
+ ++count;
+
+ gtkpod_statusbar_message (
+ ngettext ("Copied %d of %d new track.",
+ "Copied %d of %d new tracks.", n),
+ count, n);
+ while (widgets_blocked && gtk_events_pending ())
+ gtk_main_iteration ();
+ }
}
- if (count == n) /* we need to reset timeout */
- {
- gtkpod_statusbar_timeout (0);
- }
- gtkpod_statusbar_message (
- ngettext ("Copied %d of %d new track.",
- "Copied %d of %d new tracks.", n),
- count, n);
+ } /* for (gl=itdb->tracks;.;.) */

- gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progress_bar),
- (gdouble) count/n);
-
- diff = time(NULL) - start;
- fullsecs = (diff*n/count)-diff+5;
- hrs = fullsecs / 3600;
- mins = (fullsecs % 3600) / 60;
- secs = ((fullsecs % 60) / 5) * 5;
- /* don't bounce up too quickly (>10% change only) */
-/* left = ((mins < left) || (100*mins >= 110*left)) ? mins : left;*/
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progress_bar),
+ (gdouble) count/n);
+
+ tracksleftnum = itdb_tracks_number_nontransferred (itdb);
+ if (tracksleftnum > trackserrnum)
+ { /* waiting for files to finish conversion */
progtext = g_strdup_printf (
- _("%d%% (%d:%02d:%02d left)"),
- count*100/n, (int)hrs, (int)mins, (int)secs);
+ _("%d%% (Waiting for file conversion to complete)"), count*100/n);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR (progress_bar),
progtext);
g_free (progtext);
+
+ do
+ {
+ while (widgets_blocked && gtk_events_pending ())
+ gtk_main_iteration ();
+ } while (!transfer_data->abort &&
+ !file_convert_timed_wait (itdb, 20));
}
- while (widgets_blocked && gtk_events_pending ()) gtk_main_iteration ();
- } /* for (.;.;.) */
+ } while (!transfer_data->abort &&
+ (itdb_tracks_number_nontransferred (itdb) > trackserrnum));
+
+ gtkpod_statusbar_timeout (0);

if (transfer_data->abort) result = FALSE; /* negative result if user
aborted */
if (result == FALSE)

Index: main.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/main.c,v
retrieving revision 1.63
retrieving revision 1.63.2.1
diff -u -d -r1.63 -r1.63.2.1
--- main.c 9 Apr 2007 13:33:50 -0000 1.63
+++ main.c 19 Apr 2007 14:46:07 -0000 1.63.2.1
@@ -53,18 +53,20 @@
g_thread_init (NULL);
/* FIXME: this call causes gtkpod to freeze as soon as tracks should be
displayed */
-/* gdk_threads_init (); */
+ gdk_threads_init ();
#endif

+ gdk_threads_enter ();
+
gtk_init (&argc, &argv);

srand(time(NULL));

gtkpod_init (argc, argv);

-/* gdk_threads_enter (); */
gtk_main ();
-/* gdk_threads_leave (); */
+
+ gdk_threads_leave ();

/* all the cleanup is already done in gtkpod_main_shutdown () in misc.c */
return 0;

Index: misc.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc.c,v
retrieving revision 1.220
retrieving revision 1.220.2.1
diff -u -d -r1.220 -r1.220.2.1
--- misc.c 15 Apr 2007 13:27:42 -0000 1.220
+++ misc.c 19 Apr 2007 14:46:07 -0000 1.220.2.1
@@ -33,13 +33,14 @@

#include <errno.h>
#include <gtk/gtk.h>
-#include <stdlib.h>
+#include <glib/gstdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include "charset.h"
#include "clientserver.h"
+#include "file_convert.h"
#include "misc.h"
#include "prefs.h"
#include "misc_track.h"
@@ -343,6 +344,7 @@
*
**************************************************************************/

+
/* tries to call "/bin/sh @script" with command line options */
static void do_script (const gchar *script, va_list args)
{
@@ -422,6 +424,37 @@



+/* Create a NULL-terminated array of strings given in the command
+ line. The last argument must be NULL.
+ You must free the returned array with g_strfreev() after use. */
+gchar **build_argv_from_strings (const gchar *first_arg, ...)
+{
+ gchar **argv;
+ va_list args;
+ const gchar *str;
+ GPtrArray *ptra = g_ptr_array_sized_new (20);
+
+ g_ptr_array_add (ptra, g_strdup (first_arg));
+ /* add the rest of the strings */
+ if (first_arg)
+ {
+ va_start (args, first_arg);
+ do
+ {
+ str = va_arg (args, const gchar *);
+ g_ptr_array_add (ptra, g_strdup (str));
+ }
+ while (str);
+ va_end (args);
+ }
+ argv = (gchar **)g_ptr_array_free (ptra, FALSE);
+
+ return argv;
+}
+
+
+
+
/* compare @str1 and @str2 case-sensitively or case-insensitively
* depending on prefs settings */
gint compare_string (const gchar *str1, const gchar *str2)
@@ -980,10 +1013,14 @@

/* Return a string for @track built according to @template.

- @is_filename: if TRUE, remove potentially harmful characters.*/
+ @is_filename: if TRUE, remove potentially harmful characters.
+ @silent: don't print error messages (no gtk_*() calls -- thread
+ safe)
+*/
gchar *get_string_from_template (Track *track,
const gchar *template,
- gboolean is_filename)
+ gboolean is_filename,
+ gboolean silent)
{
GString *result;
gchar *res_utf8;
@@ -1086,8 +1123,11 @@
tmp = "%";
break;
default:
- gtkpod_warning (_("Unknown token '%%%c' in template '%s'"),
- *p, template);
+ if (!silent)
+ {
+ gtkpod_warning (_("Unknown token '%%%c' in template '%s'"),
+ *p, template);
+ }
break;
}
if (tmp)
@@ -1186,7 +1226,7 @@
}
}

- res_utf8 = get_string_from_template (track, template, is_filename);
+ res_utf8 = get_string_from_template (track, template, is_filename, FALSE);

g_free (template);

@@ -1224,9 +1264,12 @@

/**
* Recursively make directories.
+ *
+ * @silent: don't print error messages via gtk (->thread safe)
+ *
* @return FALSE is this is not possible.
*/
-gboolean mkdirhier(const gchar *dirname)
+gboolean mkdirhier(const gchar *dirname, gboolean silent)
{
gchar *dn, *p;

@@ -1247,10 +1290,13 @@

if (!g_file_test(dn, G_FILE_TEST_EXISTS))
{
- if (mkdir(dn, 0777) == -1)
+ if (g_mkdir(dn, 0777) == -1)
{
- gtkpod_warning (_("Error creating %s: %s\n"),
- dn, g_strerror(errno));
+ if (!silent)
+ {
+ gtkpod_warning (_("Error creating %s: %s\n"),
+ dn, g_strerror(errno));
+ }
g_free (dn);
return FALSE;
}
@@ -1270,7 +1316,7 @@
{
gboolean result;
gchar *dirname = g_path_get_dirname (filename);
- result = mkdirhier (dirname);
+ result = mkdirhier (dirname, FALSE);
g_free (dirname);
return result;
}
@@ -1295,6 +1341,51 @@
}


+/**
+ * get_size_of_directory
+ *
+ * Determine the total size in bytes of all files in @dir including
+ * subdirectories. This function ignores errors in the sense that if a
+ * directory or file cannot be accessed, a size of 0 is assumed.
+ */
+gint64 get_size_of_directory (const gchar *dir)
+{
+ GDir *gdir;
+ const gchar *fname;
+ gint64 tsize = 0;
+
+ g_return_val_if_fail (dir, 0);
+
+ gdir = g_dir_open (dir, 0, NULL);
+
+ /* Check for error */
+ if (!gdir)
+ return 0;
+
+ while ((fname = g_dir_read_name (gdir)))
+ {
+ gchar *fullname = g_build_filename (dir, fname, NULL);
+ if (g_file_test (fullname, G_FILE_TEST_IS_DIR))
+ {
+ tsize += get_size_of_directory (fullname);
+ }
+ else if (g_file_test (fullname, G_FILE_TEST_IS_REGULAR))
+ {
+ struct stat statbuf;
+ if (g_stat (fullname, &statbuf) == 0)
+ { /* OK, add size */
+ tsize += statbuf.st_size;
+ }
+ }
+ g_free (fullname);
+ }
+
+ g_dir_close (gdir);
+
+ return tsize;
+}
+
+

/**
* Wrapper for gtkpod_xml_get_widget() giving out a warning if widget
@@ -1692,7 +1783,7 @@

coverart_init (argv[0]);

- conversion_init ();
+ file_convert_init ();

display_create ();

@@ -1729,7 +1820,7 @@
display_update_default_sizes();

/* shut down conversion infrastructure */
- conversion_shutdown ();
+ file_convert_shutdown ();

/* Save prefs */
prefs_save ();

Index: misc.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc.h,v
retrieving revision 1.125
retrieving revision 1.125.2.1
diff -u -d -r1.125 -r1.125.2.1
--- misc.h 15 Apr 2007 13:27:42 -0000 1.125
+++ misc.h 19 Apr 2007 14:46:07 -0000 1.125.2.1
@@ -138,6 +138,8 @@
void unmount_ipod(void);*/
void call_script (gchar *script, ...);

+gchar **build_argv_from_strings (const gchar *first_arg, ...);
+
void delete_track_ok (struct DeleteData *dd);

void gtkpod_warning (const gchar *format, ...);
@@ -187,8 +189,9 @@

void check_db (iTunesDB *db);

-gboolean mkdirhier(const gchar *dirname);
+gboolean mkdirhier(const gchar *dirname, gboolean silent);
gboolean mkdirhierfile(const gchar *filename);
+gint64 get_size_of_directory (const gchar *dir);
gchar *convert_filename (const gchar *filename);

guint32 replaygain_to_soundcheck (gdouble gain);
@@ -226,7 +229,8 @@

gchar *get_string_from_template (Track *track,
const gchar *template,
- gboolean is_filename);
+ gboolean is_filename,
+ gboolean silent);
gchar *get_string_from_full_template (Track *track,
const gchar *full_template,
gboolean is_filename);

Index: misc_track.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_track.c,v
retrieving revision 1.63
retrieving revision 1.63.2.1
diff -u -d -r1.63 -r1.63.2.1
--- misc_track.c 8 Apr 2007 10:12:16 -0000 1.63
+++ misc_track.c 19 Apr 2007 14:46:07 -0000 1.63.2.1
@@ -520,7 +520,7 @@
repository and concatenates the results into one list.

Return value: a GList with matching tracks. You must call
- g_list_free() on the list when it is no longer neede.
+ g_list_free() on the list when it is no longer needed.
*/
GList *gp_itdb_find_same_tracks_in_local_itdbs (Track *track)
{
@@ -545,6 +545,35 @@



+/* Find @track in all repositories (local and iPod) and return a list.
+
+ This function calls gp_itdb_find_same_tracks() for each
+ repository and concatenates the results into one list.
+
+ Return value: a GList with matching tracks. You must call
+ g_list_free() on the list when it is no longer needed.
+*/
+GList *gp_itdb_find_same_tracks_in_itdbs (Track *track)
+{
+ GList *gl, *tracks=NULL;
+ struct itdbs_head *ih = gp_get_itdbs_head (gtkpod_window);
+
+ g_return_val_if_fail (ih, NULL);
+ g_return_val_if_fail (track, NULL);
+
+ for (gl=ih->itdbs; gl; gl=gl->next)
+ {
+ GList *addtracks;
+ iTunesDB *itdb = gl->data;
+ g_return_val_if_fail (itdb, tracks);
+ addtracks = gp_itdb_find_same_tracks (itdb, track);
+ tracks = g_list_concat (tracks, addtracks);
+ }
+ return tracks;
+}
+
+
+
/* ------------------------------------------------------------ *\
| |
| functions for local path hashtable |

Index: misc_track.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_track.h,v
retrieving revision 1.18
retrieving revision 1.18.2.1
diff -u -d -r1.18 -r1.18.2.1
--- misc_track.h 8 Apr 2007 10:12:16 -0000 1.18
+++ misc_track.h 19 Apr 2007 14:46:07 -0000 1.18.2.1
@@ -47,6 +47,7 @@
void gp_itdb_pc_path_hash_remove_track (Track *track);
GList *gp_itdb_pc_path_hash_find_tracks (iTunesDB *itdb, const gchar
*filename);
GList *gp_itdb_find_same_tracks (iTunesDB *itdb, Track *track);
+GList *gp_itdb_find_same_tracks_in_itdbs (Track *track);
GList *gp_itdb_find_same_tracks_in_local_itdbs (Track *track);

gchar **track_get_item_pointer (Track *track, T_item t_item);


-------------------------------------------------------------------------
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/





Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo