commit e7def598f3fe5b79e0f5032712a2ea1d64206a01 Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Sat Jun 4 01:38:27 2011 +0100
Supply GErrors to add functions * Try and avoid displaying multiple dialogs when adding files, directories and playlists. * file.c * Replaces all gtkpod_warnings with population of a GError * gp_private.* * log_error_printf function for convenience in having to duplicate a gchar * each time an error is to be logged * playlist_display_actions.c * File, directory and playlist adddition functions record errors with any additions. These are appended to a single error message which is displayed at the end of the addition process libgtkpod/file.c | 100 +++++++++++----- libgtkpod/file.h | 15 +-- libgtkpod/gp_private.c | 11 ++ libgtkpod/gp_private.h | 2 + libgtkpod/misc_playlist.c | 8 +- libgtkpod/misc_track.c | 19 ++-- libgtkpod/syncdir.c | 2 +- .../playlist_display/playlist_display_actions.c | 121 +++++++++++++++++--- 8 files changed, 207 insertions(+), 71 deletions(-) --- diff --git a/libgtkpod/file.c b/libgtkpod/file.c index b73bb2e..98d3e50 100644 --- a/libgtkpod/file.c +++ b/libgtkpod/file.c @@ -52,6 +52,7 @@ #include "prefs.h" #include "misc_conversion.h" #include "filetype_iface.h" +#include "gp_private.h" #define UNKNOWN_ERROR _("Unknown error") @@ -201,20 +202,21 @@ static gboolean excludefile(gchar *filename) { /* Return value: playlist to which the files were added to or NULL on * error */ Playlist * -add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint plitem_pos, AddTrackFunc addtrackfunc, gpointer data) { +add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint plitem_pos, AddTrackFunc addtrackfunc, gpointer data, GError **error) { gchar *bufp, *plfile_utf8; gchar *dirname = NULL, *plname = NULL; gchar buf[PATH_MAX]; FileType *type = NULL; /* type of playlist file */ gint line, tracks; FILE *fp; - gboolean error; + gboolean errstatus; + GString *errors = g_string_new(""); g_return_val_if_fail (plfile, FALSE); g_return_val_if_fail (itdb, FALSE); if (g_file_test(plfile, G_FILE_TEST_IS_DIR)) { - gtkpod_warning(_("'%s' is a directory, not a playlist file.\n\n"), plfile); + gtkpod_log_error_printf(error, _("'%s' is a directory, not a playlist file.\n\n"), plfile); return FALSE; /* definitely not! */ } @@ -228,7 +230,7 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p *bufp = 0; /* truncate playlist name */ type = determine_filetype(plfile); if (!filetype_is_playlist_filetype(type)) { - gtkpod_warning(_("'%s' is a not a known playlist file.\n\n"), plfile); + gtkpod_log_error_printf(error, _("'%s' is a not a known playlist file.\n\n"), plfile); g_free(plname); return FALSE; } @@ -236,7 +238,7 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p /* attempt to open playlist file */ if (!(fp = fopen(plfile, "r"))) { - gtkpod_warning(_("Could not open '%s' for reading.\n"), plfile); + gtkpod_log_error_printf(error, _("Could not open '%s' for reading.\n"), plfile); g_free(plname); return FALSE; /* definitely not! */ } @@ -254,8 +256,8 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p playlist files */ line = -1; /* nr of line being read */ tracks = 0; /* nr of tracks added */ - error = FALSE; - while (!error && fgets(buf, PATH_MAX, fp)) { + errstatus = FALSE; + while (!errstatus && fgets(buf, PATH_MAX, fp)) { gchar *bufp = buf; gchar *filename = NULL; gint len = strlen(bufp); /* remove newline */ @@ -301,7 +303,7 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p correct the code if you know more */ if (line == 0) { /* check for "[playlist]" */ if (strncasecmp(bufp, "[playlist]", 10) != 0) - error = TRUE; + errstatus = TRUE; } else if (strncasecmp(bufp, "File", 4) == 0) { /* looks like a file entry */ bufp = strchr(bufp, '='); @@ -316,14 +318,26 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p if (filename) { /* do not allow to add directories! */ if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { - gtkpod_warning(_("Skipping '%s' because it is a directory.\n"), filename); + gchar *msg = g_strdup_printf(_("Skipping '%s' because it is a directory.\n"), filename); + g_string_append(errors, msg); + g_free(msg); } /* do not allow to add playlist file recursively */ else if (strcmp(plfile, filename) == 0) { - gtkpod_warning(_("Skipping '%s' to avoid adding playlist file recursively\n"), filename); + gchar *msg = g_strdup_printf(_("Skipping '%s' to avoid adding playlist file recursively\n"), filename); + g_string_append(errors, msg); + g_free(msg); } else { - add_track_by_filename(itdb, filename, plitem, prefs_get_int("add_recursively"), addtrackfunc, data); + GError *trackerror = NULL; + add_track_by_filename(itdb, filename, plitem, prefs_get_int("add_recursively"), addtrackfunc, data, &trackerror); + if (trackerror) { + gchar *msg = g_strdup_printf("%s\n", trackerror->message); + g_string_append(errors, msg); + g_free(msg); + g_error_free(trackerror); + trackerror = NULL; + } } g_free(filename); } @@ -335,8 +349,16 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p duplicates -- but we should reset the list. */ gp_duplicate_remove(NULL, (void *) -1); + if (errors) { + if (errors->len > 0) { + gtkpod_log_error(error, errors->str); + } + g_string_free(errors, TRUE); + } + if (!error) return plitem; + return NULL; } @@ -362,8 +384,9 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint p * value indicating number of added tracks. */ /* */ -gint add_directory_by_name(iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, AddTrackFunc addtrackfunc, gpointer data) { +gint add_directory_by_name(iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, AddTrackFunc addtrackfunc, gpointer data, GError **error) { gint result = 0; + GString *errors = g_string_new(""); g_return_val_if_fail (itdb, 0); g_return_val_if_fail (name, 0); @@ -378,7 +401,15 @@ gint add_directory_by_name(iTunesDB *itdb, gchar *name, Playlist *plitem, gboole if (next != NULL) { gchar *nextfull = g_build_filename(name, next, NULL); if (descend || !g_file_test(nextfull, G_FILE_TEST_IS_DIR)) { - result += add_directory_by_name(itdb, nextfull, plitem, descend, addtrackfunc, data); + GError *direrror = NULL; + result += add_directory_by_name(itdb, nextfull, plitem, descend, addtrackfunc, data, &direrror); + if (direrror) { + gchar *msg = g_strdup_printf("%s\n", direrror->message); + g_string_append(errors, msg); + g_free(msg); + g_error_free(direrror); + direrror = NULL; + } } g_free(nextfull); } @@ -390,9 +421,15 @@ gint add_directory_by_name(iTunesDB *itdb, gchar *name, Playlist *plitem, gboole release_widgets(); } else { - if (add_track_by_filename(itdb, name, plitem, descend, addtrackfunc, data)) + if (add_track_by_filename(itdb, name, plitem, descend, addtrackfunc, data, error)) result++; } + + if (errors->len > 0) { + gtkpod_log_error_printf(error, errors->str); + } + g_string_free(errors, TRUE); + return result; } @@ -1020,13 +1057,12 @@ static void add_coverart(Track *tr) { * pc_path_utf8 and pc_path_locale are not changed if an entry already * exists. time_added is not modified if already set. */ /* Returns NULL on error, a pointer to the Track otherwise */ -Track *get_track_info_from_file(gchar *name, Track *orig_track) { +Track *get_track_info_from_file(gchar *name, Track *orig_track, GError **error) { Track *track = NULL; Track *nti = NULL; FileType *filetype; gint len; gchar *name_utf8 = NULL; - GError *error = NULL; g_return_val_if_fail (name, NULL); @@ -1036,7 +1072,7 @@ Track *get_track_info_from_file(gchar *name, Track *orig_track) { name_utf8 = charset_to_utf8(name); if (!g_file_test(name, G_FILE_TEST_EXISTS)) { - gtkpod_warning(_("The following track could not be processed (file does not exist): '%s'\n"), name_utf8); + gtkpod_log_error_printf(error, _("The following track could not be processed (file does not exist): '%s'\n"), name_utf8); g_free(name_utf8); return NULL; } @@ -1051,21 +1087,22 @@ Track *get_track_info_from_file(gchar *name, Track *orig_track) { filetype = determine_filetype(name); if (!filetype) { - gtkpod_warning( + gtkpod_log_error_printf(error, _("The filetype '%s' is not currently supported.\n\n" "If you have a plugin that supports this filetype then please enable it."), name_utf8); return NULL; } - nti = filetype_get_file_info(filetype, name, &error); - if (error || !nti) { - gtkpod_warning(_("No track information could be retrieved from the file %s due to the following error:\n\n%s"), name_utf8, error->message); - g_error_free(error); - error = NULL; + GError *info_error = NULL; + nti = filetype_get_file_info(filetype, name, &info_error); + if (info_error || !nti) { + gtkpod_log_error_printf(error, _("No track information could be retrieved from the file %s due to the following error:\n\n%s"), name_utf8, info_error->message); + g_error_free(info_error); + info_error = NULL; g_free(name_utf8); return NULL; } else if (!nti) { - gtkpod_warning(_("No track information could be retrieved from the file %s due to the following error:\n\nAn error was not returned."), name_utf8); + gtkpod_log_error_printf(error, _("No track information could be retrieved from the file %s due to the following error:\n\nAn error was not returned."), name_utf8); g_free(name_utf8); return NULL; } @@ -1390,7 +1427,7 @@ void update_track_from_file(iTunesDB *itdb, Track *track) { } } - if (trackpath && get_track_info_from_file(trackpath, track)) { /* update successful */ + if (trackpath && get_track_info_from_file(trackpath, track, NULL)) { /* update successful */ ExtraTrackData *netr = track->userdata; /* remove track from sha1 hash and reinsert it @@ -1496,7 +1533,7 @@ void update_track_from_file(iTunesDB *itdb, Track *track) { /* @addtrackfunc: if != NULL this will be called instead of "add_track_to_playlist () -- used for dropping tracks at a specific position in the track view */ -gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem, gboolean descend, AddTrackFunc addtrackfunc, gpointer data) { +gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem, gboolean descend, AddTrackFunc addtrackfunc, gpointer data, GError **error) { Track *oldtrack; gchar str[PATH_MAX]; gchar *basename; @@ -1515,18 +1552,19 @@ gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem, g plitem = mpl; if (g_file_test(fname, G_FILE_TEST_IS_DIR)) { - return add_directory_by_name(itdb, fname, plitem, descend, addtrackfunc, data); + return add_directory_by_name(itdb, fname, plitem, descend, addtrackfunc, data, error); } /* check if file is a playlist */ filetype = determine_filetype(fname); if (filetype_is_playlist_filetype(filetype)) { - if (add_playlist_by_filename(itdb, fname, plitem, -1, addtrackfunc, data)) + if (add_playlist_by_filename(itdb, fname, plitem, -1, addtrackfunc, data, error)) return TRUE; return FALSE; } if (!filetype_is_audio_filetype(filetype) && !filetype_is_video_filetype(filetype)) { + gtkpod_log_error_printf(error, _("File type of %s is not recognised"), fname); return FALSE; } @@ -1540,7 +1578,7 @@ gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem, g g_free(bn_utf8); if (excludefile(basename)) { - gtkpod_warning(_("Skipping '%s' because it matches exclude masks.\n"), basename); + gtkpod_log_error_printf(error, _("Skipping '%s' because it matches exclude masks.\n"), basename); while (widgets_blocked && gtk_events_pending()) gtk_main_iteration(); g_free(basename); @@ -1569,7 +1607,7 @@ gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem, g } else /* oldtrack == NULL */ { /* OK, the same filename does not already exist */ - Track *track = get_track_info_from_file(fname, NULL); + Track *track = get_track_info_from_file(fname, NULL, error); if (track) { Track *added_track = NULL; ExtraTrackData *etr = track->userdata; @@ -1644,7 +1682,7 @@ gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem, g * to podcasts list and track already exists there */ if (itdb_playlist_is_podcasts(plitem) && g_list_find(plitem->members, added_track)) { gchar *buf = get_track_info(added_track, FALSE); - gtkpod_warning(_("Podcast already present: '%s'\n\n"), buf); + gtkpod_log_error_printf(error, _("Podcast already present: '%s'\n\n"), buf); g_free(buf); } else { diff --git a/libgtkpod/file.h b/libgtkpod/file.h index 9c99785..d365851 100644 --- a/libgtkpod/file.h +++ b/libgtkpod/file.h @@ -59,18 +59,11 @@ FileType *determine_filetype (const gchar *path); * Used inside file functions but also used in file_itunesdb for importing * itdbs. Embedded artwork can be read using this. */ -Track *get_track_info_from_file(gchar *name, Track *orig_track); +Track *get_track_info_from_file(gchar *name, Track *orig_track, GError **error); -gboolean add_track_by_filename (iTunesDB *itdb, gchar *name, - Playlist *plitem, gboolean descend, - AddTrackFunc addtrackfunc, gpointer data); -gboolean add_directory_by_name (iTunesDB *itdb, gchar *name, - Playlist *plitem, gboolean descend, - AddTrackFunc addtrackfunc, gpointer data); -Playlist *add_playlist_by_filename (iTunesDB *itdb, gchar *plfile, - Playlist *plitem, gint plitem_pos, - AddTrackFunc addtrackfunc, - gpointer data); +gboolean add_track_by_filename (iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, AddTrackFunc addtrackfunc, gpointer data, GError **error); +gboolean add_directory_by_name (iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, AddTrackFunc addtrackfunc, gpointer data, GError **error); +Playlist *add_playlist_by_filename (iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint plitem_pos, AddTrackFunc addtrackfunc, gpointer data, GError **error); gboolean write_tags_to_file(Track *s); void update_track_from_file (iTunesDB *itdb, Track *track); void update_tracks (GList *selected_tracks); diff --git a/libgtkpod/gp_private.c b/libgtkpod/gp_private.c index fc05b20..55c006a 100644 --- a/libgtkpod/gp_private.c +++ b/libgtkpod/gp_private.c @@ -121,6 +121,17 @@ GQuark gtkpod_general_error_quark (void) return g_quark_from_static_string ("gtkpod-general-error-quark"); } +void gtkpod_log_error_printf(GError **error, gchar *msg, ...) { + gchar* buf; + va_list args; + va_start (args, msg); + buf = g_strdup_vprintf(msg, args); + va_end (args); + + gtkpod_log_error(error, buf); + g_free(buf); +} + void gtkpod_log_error(GError **error, gchar *msg) { g_set_error (error, GTKPOD_GENERAL_ERROR, /* error domain */ diff --git a/libgtkpod/gp_private.h b/libgtkpod/gp_private.h index 05a0250..3301707 100644 --- a/libgtkpod/gp_private.h +++ b/libgtkpod/gp_private.h @@ -102,6 +102,8 @@ typedef enum { GQuark gtkpod_general_error_quark (void); +void gtkpod_log_error_printf(GError **error, gchar *msg, ...); + void gtkpod_log_error(GError **error, gchar *msg); #endif /* GP_DEFINITIONS_H_ */ diff --git a/libgtkpod/misc_playlist.c b/libgtkpod/misc_playlist.c index daf733b..21ed692 100644 --- a/libgtkpod/misc_playlist.c +++ b/libgtkpod/misc_playlist.c @@ -931,8 +931,10 @@ void check_db(iTunesDB *itdb) { if (localdebug) fprintf(stdout, "to orphaned "); - if ((dupl_track = sha1_file_exists(itdb, fn_orphaned, TRUE))) { /* This orphan has already been added again. - It will be removed with the next sync */ + + if ((dupl_track = sha1_file_exists(itdb, fn_orphaned, TRUE))) { + /* This orphan has already been added again. + It will be removed with the next sync */ Track *track = gp_track_new(); gchar *fn_utf8 = charset_to_utf8(fn_orphaned); const gchar *dir_rel = music_dir + strlen(mountpoint); @@ -951,7 +953,7 @@ void check_db(iTunesDB *itdb) { g_free(fn_utf8); } else { - add_track_by_filename(itdb, fn_orphaned, pl_orphaned, FALSE, NULL, NULL); + add_track_by_filename(itdb, fn_orphaned, pl_orphaned, FALSE, NULL, NULL, NULL); } g_free(fn_orphaned); g_free(num_str); diff --git a/libgtkpod/misc_track.c b/libgtkpod/misc_track.c index 260b879..d0dac50 100644 --- a/libgtkpod/misc_track.c +++ b/libgtkpod/misc_track.c @@ -1785,6 +1785,7 @@ Playlist *add_text_plain_to_playlist(iTunesDB *itdb, Playlist *pl, gchar *str, g gchar **files = NULL, **filesp = NULL; Playlist *pl_playlist = pl; /* playlist for playlist file */ Playlist *pl_playlist_created = NULL; + GError *error = NULL; g_return_val_if_fail (itdb, NULL); @@ -1799,7 +1800,6 @@ Playlist *add_text_plain_to_playlist(iTunesDB *itdb, Playlist *pl, gchar *str, g if (files) { filesp = files; while (*filesp) { - gboolean added = FALSE; gint file_len = -1; gchar *file = NULL; @@ -1829,10 +1829,9 @@ Playlist *add_text_plain_to_playlist(iTunesDB *itdb, Playlist *pl, gchar *str, g if (!pl) break; /* while (*filesp) */ } - add_directory_by_name(itdb, decoded_file, pl, prefs_get_int("add_recursively"), trackaddfunc, data); - added = TRUE; + add_directory_by_name(itdb, decoded_file, pl, prefs_get_int("add_recursively"), trackaddfunc, data, &error); } - if (g_file_test(decoded_file, G_FILE_TEST_IS_REGULAR)) { /* regular file */ + else if (g_file_test(decoded_file, G_FILE_TEST_IS_REGULAR)) { /* regular file */ FileType *filetype = determine_filetype(decoded_file); if (filetype_is_video_filetype(filetype) || filetype_is_audio_filetype(filetype)) { @@ -1841,20 +1840,20 @@ Playlist *add_text_plain_to_playlist(iTunesDB *itdb, Playlist *pl, gchar *str, g if (!pl) break; /* while (*filesp) */ } - add_track_by_filename(itdb, decoded_file, pl, prefs_get_int("add_recursively"), trackaddfunc, data); - added = TRUE; + add_track_by_filename(itdb, decoded_file, pl, prefs_get_int("add_recursively"), trackaddfunc, data, &error); } else if (filetype_is_playlist_filetype(filetype)) { pl_playlist_created - = add_playlist_by_filename(itdb, decoded_file, pl_playlist, pl_pos, trackaddfunc, data); - added = TRUE; + = add_playlist_by_filename(itdb, decoded_file, pl_playlist, pl_pos, trackaddfunc, data, &error); } } g_free(decoded_file); } - if (!added) { + if (error) { if (strlen(*filesp) != 0) - gtkpod_warning(_("drag and drop: ignored '%s'\n"), *filesp); + gtkpod_warning(_("drag and drop: ignored '%s'.\nreason: %s\n"), *filesp, error->message); + g_error_free(error); + error = NULL; } ++filesp; } diff --git a/libgtkpod/syncdir.c b/libgtkpod/syncdir.c index f77d840..58439bf 100644 --- a/libgtkpod/syncdir.c +++ b/libgtkpod/syncdir.c @@ -355,7 +355,7 @@ static void add_files(gpointer key, gpointer value, gpointer user_data) { data.filepath = filename; data.filepath_hash = afd->filepath_hash; - add_track_by_filename(pl->itdb, filename, pl, FALSE, sync_addtrackfunc, &data); + add_track_by_filename(pl->itdb, filename, pl, FALSE, sync_addtrackfunc, &data, NULL); tr = g_hash_table_lookup(afd->filepath_hash, filename); updated = TRUE; diff --git a/plugins/playlist_display/playlist_display_actions.c b/plugins/playlist_display/playlist_display_actions.c index 37c7075..cd612d7 100644 --- a/plugins/playlist_display/playlist_display_actions.c +++ b/plugins/playlist_display/playlist_display_actions.c @@ -48,6 +48,8 @@ /* Callback after directories to add have been selected */ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { gboolean result = TRUE; + GString *errors = g_string_new(""); + GError *error = NULL; g_return_if_fail (names); g_return_if_fail (db_active_pl); @@ -57,7 +59,14 @@ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { GSList* currentnode; for (currentnode = names; currentnode; currentnode = currentnode->next) { result - &= add_directory_by_name(db_active_pl->itdb, currentnode->data, db_active_pl, prefs_get_int("add_recursively"), NULL, NULL); + &= add_directory_by_name(db_active_pl->itdb, currentnode->data, db_active_pl, prefs_get_int("add_recursively"), NULL, NULL, &error); + if (error) { + gchar *buf = g_strdup_printf(_("%s\n"), error->message); + g_string_append(errors, buf); + g_free(buf); + g_error_free(error); + error = NULL; + } } /* Final save of itdb */ @@ -69,13 +78,33 @@ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { /* display log of detected duplicates */ gp_duplicate_remove(NULL, NULL); - if (result == TRUE) - gtkpod_statusbar_message(_("Successfully added files")); - else - gtkpod_statusbar_message(_("Some files were not added successfully")); - - gtkpod_statusbar_busy_pop(); gtkpod_set_current_playlist(db_active_pl); + gtkpod_statusbar_busy_pop(); + + /* Were all files successfully added? */ + if (result == FALSE) { + if (errors->len > 0) { + gtkpod_confirmation(-1, /* gint id, */ + TRUE, /* gboolean modal, */ + _("Directory Addition Errors"), /* title */ + _(" Some directories were not added successfully"), /* label */ + errors->str, /* scrolled text */ + NULL, 0, NULL, /* option 1 */ + NULL, 0, NULL, /* option 2 */ + TRUE, /* gboolean confirm_again, */ + "show_file_addition_errors",/* confirm_again_key,*/ + CONF_NULL_HANDLER, /* ConfHandler ok_handler,*/ + NULL, /* don't show "Apply" button */ + NULL, /* cancel_handler,*/ + NULL, /* gpointer user_data1,*/ + NULL); /* gpointer user_data2,*/ + } + else { + gtkpod_warning(_("Some directories failed to be added but no errors were reported.")); + } + } + + g_string_free(errors, TRUE); } } @@ -126,6 +155,7 @@ static void create_add_directories_dialog(Playlist *pl) { /* OK Button */ static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { GSList* gsl; + GString *errors = g_string_new(""); /* Get the names of the playlist(s) and add them */ @@ -135,7 +165,15 @@ static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { gtkpod_statusbar_busy_push(); for (gsl = names; gsl; gsl = gsl->next) { - add_playlist_by_filename(itdb, gsl->data, NULL, -1, NULL, NULL); + GError *error = NULL; + add_playlist_by_filename(itdb, gsl->data, NULL, -1, NULL, NULL, &error); + if (error) { + gchar *buf = g_strdup_printf(_("'%s'\n"), error->message); + g_string_append(errors, buf); + g_free(buf); + g_error_free(error); + error = NULL; + } } release_widgets(); @@ -151,6 +189,28 @@ static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { gtkpod_statusbar_busy_pop(); gtkpod_tracks_statusbar_update(); gtkpod_set_current_playlist(itdb_playlist_mpl(itdb)); + + if (errors->len > 0) { + gtkpod_confirmation(-1, /* gint id, */ + TRUE, /* gboolean modal, */ + _("Playlist Addition Errors"), /* title */ + _("Some tracks in the playlist were not added successfully"), /* label */ + errors->str, /* scrolled text */ + NULL, 0, NULL, /* option 1 */ + NULL, 0, NULL, /* option 2 */ + TRUE, /* gboolean confirm_again, */ + "show_playlist_addition_errors",/* confirm_again_key,*/ + CONF_NULL_HANDLER, /* ConfHandler ok_handler,*/ + NULL, /* don't show "Apply" button */ + NULL, /* cancel_handler,*/ + NULL, /* gpointer user_data1,*/ + NULL); /* gpointer user_data2,*/ + } + else { + gtkpod_warning(_("Some tracks failed to be added but no errors were reported.")); + } + + g_string_free(errors, TRUE); } /* Open a modal file selection dialog with multiple selction enabled */ @@ -236,6 +296,7 @@ static void create_add_playlists_dialog(iTunesDB *itdb) { static void fileselection_add_files(GSList* names, Playlist *playlist) { GSList* gsl; /* Current node in list */ gboolean result = TRUE; /* Result of file adding */ + GString *errors = g_string_new(""); /* If we don't have a playlist to add to, don't add anything */ g_return_if_fail (playlist); @@ -245,8 +306,19 @@ static void fileselection_add_files(GSList* names, Playlist *playlist) { gtkpod_statusbar_busy_push(); /* Get the filenames and add them */ for (gsl = names; gsl; gsl = gsl->next) { + GError *error = NULL; + /* Might be useful to stick a GError on this to return a message if the + * file fails to be added. + */ result - &= add_track_by_filename(playlist->itdb, gsl->data, playlist, prefs_get_int("add_recursively"), NULL, NULL); + &= add_track_by_filename(playlist->itdb, gsl->data, playlist, prefs_get_int("add_recursively"), NULL, NULL, &error); + if (error) { + gchar *buf = g_strdup_printf(_("%s\n"), error->message); + g_string_append(errors, buf); + g_free(buf); + g_error_free(error); + error = NULL; + } } /* Final save of remaining added tracks */ @@ -260,16 +332,35 @@ static void fileselection_add_files(GSList* names, Playlist *playlist) { /* display log of detected duplicates */ gp_duplicate_remove(NULL, NULL); - /* Were all files successfully added? */ - if (result == TRUE) - gtkpod_statusbar_message(_("Successfully added files")); - else - gtkpod_statusbar_message(_("Some files were not added successfully")); - gtkpod_statusbar_busy_pop(); release_widgets(); gtkpod_set_current_playlist(playlist); + + /* Were all files successfully added? */ + if (result == FALSE) { + if (errors->len > 0) { + gtkpod_confirmation(-1, /* gint id, */ + TRUE, /* gboolean modal, */ + _("File Addition Errors"), /* title */ + _("Some files were not added successfully"), /* label */ + errors->str, /* scrolled text */ + NULL, 0, NULL, /* option 1 */ + NULL, 0, NULL, /* option 2 */ + TRUE, /* gboolean confirm_again, */ + "show_file_addition_errors",/* confirm_again_key,*/ + CONF_NULL_HANDLER, /* ConfHandler ok_handler,*/ + NULL, /* don't show "Apply" button */ + NULL, /* cancel_handler,*/ + NULL, /* gpointer user_data1,*/ + NULL); /* gpointer user_data2,*/ + } + else { + gtkpod_warning(_("Some tracks failed to be added but no errors were reported.")); + } + } + + g_string_free(errors, TRUE); } static gboolean fileselection_add_files_cb(gpointer data) { ------------------------------------------------------------------------------ Simplify data backup and recovery for your virtual environment with vRanger. Installation's a snap, and flexible recovery options mean your data is safe, secure and there when you need it. Discover what all the cheering's about. Get your free trial download today. http://p.sf.net/sfu/quest-dev2dev2 _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2