commit 543ce28c633e2631db7fbfe6b60680091c152eaa Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Sun Dec 5 14:30:46 2010 +0000
Fixes to update gui if convert goes wrong * file_convert.c * conversion_get_track_info does not need a conv since it is never called with one * Another attempt at sorting a deadlock with the conversion mutex * If a track fail to copy then ensure the gui knows to remove the failed track * gp_itdb.c * misc_track.c * Drag n drop adds the track to the given ipod before the conversion has a chance to fail. If conversion does fail before the thread runs, eg. no installed script then remove the track using the g_idle callback * gp_remove_track_cb callback for removing a track . Used with g_idle_add, it ensures that it runs on the correct thread. libgtkpod/file_convert.c | 47 ++++++++++++++++++++------------------------- libgtkpod/gp_itdb.c | 5 +++- libgtkpod/misc_track.c | 15 ++++++++++++++ libgtkpod/misc_track.h | 1 + 4 files changed, 41 insertions(+), 27 deletions(-) --- diff --git a/libgtkpod/file_convert.c b/libgtkpod/file_convert.c index ae75a1f..fe2d883 100644 --- a/libgtkpod/file_convert.c +++ b/libgtkpod/file_convert.c @@ -929,8 +929,6 @@ static gboolean conversion_add_track(Conversion *conv, Track *track) { return TRUE; } - - /* Create ConvTrack structure */ ctr = g_new0 (ConvTrack, 1); ctr->track = track; @@ -963,7 +961,7 @@ static gboolean conversion_add_track(Conversion *conv, Track *track) { filetype = determine_filetype(etr->pc_path_locale); - if (!g_file_test(etr->pc_path_locale, G_FILE_TEST_IS_REGULAR) || ! filetype) { + if (!g_file_test(etr->pc_path_locale, G_FILE_TEST_IS_REGULAR) || !filetype) { gchar *buf = get_track_info(track, FALSE); gtkpod_warning(_("Filename '%s' is no longer valid for '%s'.\n"), etr->pc_path_utf8, buf); g_free(buf); @@ -978,7 +976,7 @@ static gboolean conversion_add_track(Conversion *conv, Track *track) { } /* Find the correct script for conversion */ - if (! filetype_can_convert(filetype)) { + if (!filetype_can_convert(filetype)) { /* we don't convert these (yet) */ etr->conversion_status = FILE_CONVERT_INACTIVE; /* add to finished */ @@ -1098,12 +1096,9 @@ static void conversion_convtrack_free(ConvTrack *ctr) { /* return some sensible input about @ctrack. You must free the returned string after use. */ -static gchar *conversion_get_track_info(Conversion *conv, ConvTrack *ctr) { +static gchar *conversion_get_track_info(ConvTrack *ctr) { gchar *str = NULL; - if (conv) - g_mutex_lock (conv->mutex); - if ((ctr->title && strlen(ctr->title))) { str = g_strdup(ctr->title); } @@ -1117,9 +1112,6 @@ static gchar *conversion_get_track_info(Conversion *conv, ConvTrack *ctr) { str = g_strdup(_("No information available")); } - if (conv) - g_mutex_unlock (conv->mutex); - return str; } @@ -1410,12 +1402,12 @@ static gboolean conversion_scheduler_unlocked(Conversion *conv) { increasing while we copy more and more files to the iPod */ debug ("transfer finalized: %s (%d)\n", - conversion_get_track_info (NULL, ctr), + conversion_get_track_info (ctr), ctr->track->transferred); } else { /* error!? */ tri->failed = g_list_prepend(tri->failed, ctr); - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); gtkpod_warning(_("Transfer of '%s' failed. %s\n\n"), buf, error ? error->message : ""); g_free(buf); if (error) { @@ -1486,7 +1478,7 @@ static gboolean conversion_scheduler(gpointer data) { debug ("conversion_scheduler enter\n"); gdk_threads_enter(); - if (! g_mutex_trylock(conv->mutex)) { + if (!g_mutex_trylock(conv->mutex)) { gdk_threads_leave(); return FALSE; } @@ -1770,7 +1762,7 @@ static gchar *conversion_get_fname_extension(Conversion *conv, ConvTrack *ctr) { if (conv) g_mutex_lock (conv->mutex); if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: '%s'.\n\n"), buf, error->message); g_free(buf); } @@ -1783,7 +1775,7 @@ static gchar *conversion_get_fname_extension(Conversion *conv, ConvTrack *ctr) { if (conv) g_mutex_lock (conv->mutex); if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: '%s %s' returned exit status %d.\n\n"), buf, argv[0], argv[1], WEXITSTATUS (exit_status)); @@ -1808,7 +1800,7 @@ static gchar *conversion_get_fname_extension(Conversion *conv, ConvTrack *ctr) { if (conv) g_mutex_lock (conv->mutex); if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: '\"%s\" %s' did not return filename extension as expected.\n\n"), buf, argv[0], argv[1]); g_free(buf); @@ -1872,7 +1864,7 @@ static gboolean conversion_set_valid_filename(Conversion *conv, ConvTrack *ctr) } } else { /* error reading original file */ - char *buf = conversion_get_track_info(NULL, ctr); + char *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: Could not access original file '%s' (%s).\n\n"), buf, ctr->orig_file, strerror(errno)); g_free(buf); @@ -1915,7 +1907,7 @@ static gboolean conversion_set_valid_filename(Conversion *conv, ConvTrack *ctr) result = mkdirhier(rootdir, TRUE); if (result == FALSE) { if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: Could not create directory '%s'.\n\n"), buf, rootdir); g_free(buf); @@ -1967,6 +1959,7 @@ static gboolean conversion_convert_track(Conversion *conv, ConvTrack *ctr) { if (ctr->converted_file && ctr->valid) { if (g_file_test(ctr->converted_file, G_FILE_TEST_EXISTS)) { /* a valid converted file already exists. */ result = TRUE; + g_mutex_unlock (conv->mutex); } else { /* start conversion */ gchar **argv; @@ -1994,7 +1987,7 @@ static gboolean conversion_convert_track(Conversion *conv, ConvTrack *ctr) { if (result == FALSE) { if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: '%s'.\n\n"), buf, error->message); g_free(buf); } @@ -2016,9 +2009,11 @@ static gboolean conversion_convert_track(Conversion *conv, ConvTrack *ctr) { ctr->pid = 0; - if (WIFEXITED(status) && (WEXITSTATUS(status) != 0)) { /* script exited normally but with an error */ + if ( + WIFEXITED(status) && ( + WEXITSTATUS(status) != 0)) { /* script exited normally but with an error */ if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: '%s' returned exit status %d.\n\n"), buf, ctr->conversion_cmd, WEXITSTATUS (status)); @@ -2039,9 +2034,8 @@ static gboolean conversion_convert_track(Conversion *conv, ConvTrack *ctr) { ctr->converted_file = NULL; result = FALSE; } - - g_mutex_unlock (conv->mutex); } + g_mutex_unlock (conv->mutex); } } @@ -2052,7 +2046,7 @@ static gboolean conversion_convert_track(Conversion *conv, ConvTrack *ctr) { ctr->converted_size = statbuf.st_size; } else { /* an error occured after all */ - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Conversion of '%s' failed: could not stat the converted file '%s'.\n\n"), buf, ctr->converted_file); g_free(buf); @@ -2167,6 +2161,7 @@ static gpointer conversion_thread(gpointer data) { else { /* track is no longer valid -> remove converted file * and drop the entry */ /* remove (converted_file) */ + g_idle_add((GSourceFunc) gp_remove_track_cb, ctr->track); g_list_free(gl); conversion_convtrack_free(ctr); } @@ -2639,7 +2634,7 @@ static FileTransferStatus transfer_transfer_track(TransferItdb *tri, ConvTrack * } else { if (ctr->valid) { - gchar *buf = conversion_get_track_info(NULL, ctr); + gchar *buf = conversion_get_track_info(ctr); ctr->errormessage = g_strdup_printf(_("Transfer of '%s' failed. %s\n\n"), buf, error ? error->message : ""); g_free(buf); diff --git a/libgtkpod/gp_itdb.c b/libgtkpod/gp_itdb.c index 0c0de3f..2d84e52 100644 --- a/libgtkpod/gp_itdb.c +++ b/libgtkpod/gp_itdb.c @@ -250,7 +250,10 @@ Track *gp_track_add(iTunesDB *itdb, Track *track) { /* add to filename hash */ gp_itdb_pc_path_hash_add_track(track); /* add to background conversion if necessary */ - file_convert_add_track (track); + if (! file_convert_add_track (track)) { + g_idle_add((GSourceFunc) gp_remove_track_cb, track); + return NULL; + } result = track; data_changed(itdb); } diff --git a/libgtkpod/misc_track.c b/libgtkpod/misc_track.c index cb35011..39d238c 100644 --- a/libgtkpod/misc_track.c +++ b/libgtkpod/misc_track.c @@ -1651,6 +1651,10 @@ static void intern_add_track(Playlist *pl, Track *track) { same track already exists in the database, the already existing track is returned and @duptr is freed */ addtr = gp_track_add(to_itdb, duptr); + if (!addtr) { + /* Track was rendered invalid, possibly by the conversion routine */ + return; + } /* set flags to 'podcast' if adding to podcast list */ if (itdb_playlist_is_podcasts(pl)) @@ -1916,6 +1920,17 @@ gchar *get_track_info(Track *track, gboolean prefer_filename) { * * \*------------------------------------------------------------------*/ +/** + * + * Callback that could be used with g_idle_add method for + * removing a track. + */ +gboolean gp_remove_track_cb(gpointer data) { + Track *track = data; + gp_playlist_remove_track(NULL, track, DELETE_ACTION_DATABASE); + return FALSE; +} + /* cancel handler for delete track */ /* @user_data1 the selected playlist, @user_data2 are the selected tracks */ void delete_track_cancel(struct DeleteData *dd) { diff --git a/libgtkpod/misc_track.h b/libgtkpod/misc_track.h index 51a7d62..6d4cce1 100644 --- a/libgtkpod/misc_track.h +++ b/libgtkpod/misc_track.h @@ -73,6 +73,7 @@ gchar **track_get_item_pointer (Track *track, T_item t_item); gchar *track_get_text(Track *track, T_item item); gboolean track_set_text(Track *track, const gchar *new_text, T_item item); +gboolean gp_remove_track_cb(gpointer data); void delete_track_head (DeleteAction deleteaction); void delete_track_ok(struct DeleteData *dd); void delete_track_cancel(struct DeleteData *dd); ------------------------------------------------------------------------------ What happens now with your Lotus Notes apps - do you make another costly upgrade, or settle for being marooned without product support? Time to move off Lotus Notes and onto the cloud with Force.com, apps are easier to build, use, and manage than apps on traditional platforms. Sign up for the Lotus Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2