commit 16af7ed2fc79576d8ffeec0e4427b05d6a1b61f8 Merge: 2410f7c 947484e Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Wed Jul 7 22:04:46 2010 +0100
Merge branch 'master' into plugin-framework CMakeLists.txt | 12 ++++++- ChangeLog | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ INSTALL | 6 ++-- NEWS | 12 ++++++ README | 20 +++++----- cmake/config.h.in | 16 ++++++--- src/file.c | 58 +++++++++++++++++++------------ src/file_itunesdb.c | 25 +++++++++---- src/help.c | 30 ++++++++-------- src/misc.c | 2 +- src/sort_window.c | 2 + 11 files changed, 212 insertions(+), 66 deletions(-) --- diff --cc src/file.c index cb6df09,3503c05..b5a5caa --- a/src/file.c +++ b/src/file.c @@@ -1174,53 -1297,58 +1174,54 @@@ static Track *get_track_info_from_file( } /* reset the auto detection charset (see explanation in charset.c) */ - charset_reset_auto (); + charset_reset_auto(); /* check for filetype */ - len = strlen (name); - if (len < 4) return NULL; + len = strlen(name); + if (len < 4) + return NULL; filetype = determine_file_type(name); - switch (filetype) - { + switch (filetype) { case FILE_TYPE_MP3: - nti = mp3_get_file_info(name); - /* Set mediatype to audio */ - if (nti) { - if (g_strcasecmp(nti->genre, "audiobook") == 0) - nti->mediatype = ITDB_MEDIATYPE_AUDIOBOOK; - else if (g_strcasecmp(nti->genre, "podcast") == 0) - nti->mediatype = ITDB_MEDIATYPE_PODCAST; - else - nti->mediatype = ITDB_MEDIATYPE_AUDIO; - } - break; + nti = mp3_get_file_info (name); + /* Set mediatype to audio */ + if (nti) + { + nti->mediatype = ITDB_MEDIATYPE_AUDIO; + if (nti->genre) + { + if (g_strcasecmp (nti->genre, "audiobook") == 0) nti->mediatype = ITDB_MEDIATYPE_AUDIOBOOK; + else if (g_strcasecmp (nti->genre, "podcast") == 0) nti->mediatype = ITDB_MEDIATYPE_PODCAST; + } + } + break; case FILE_TYPE_M4A: case FILE_TYPE_M4P: - nti = mp4_get_file_info (name); - /* Set mediatype to audio */ - if (nti && !nti->mediatype) - { - nti->mediatype = ITDB_MEDIATYPE_AUDIO; - } - break; + nti = mp4_get_file_info(name); + /* Set mediatype to audio */ + if (nti && !nti->mediatype) { + nti->mediatype = ITDB_MEDIATYPE_AUDIO; + } + break; case FILE_TYPE_M4B: - nti = mp4_get_file_info (name); - /* Set mediatype to audiobook */ - if (nti) - { - nti->mediatype = ITDB_MEDIATYPE_AUDIOBOOK; - } - break; + nti = mp4_get_file_info(name); + /* Set mediatype to audiobook */ + if (nti) { + nti->mediatype = ITDB_MEDIATYPE_AUDIOBOOK; + } + break; case FILE_TYPE_WAV: - nti = wav_get_file_info (name); - /* Set mediatype to audio */ - if (nti) - { - nti->mediatype = ITDB_MEDIATYPE_AUDIO; - } - break; + nti = wav_get_file_info(name); + /* Set mediatype to audio */ + if (nti) { + nti->mediatype = ITDB_MEDIATYPE_AUDIO; + } + break; case FILE_TYPE_OGG: - nti = ogg_get_file_info (name); + nti = ogg_get_file_info(name); /* Set mediatype to audio */ - if (nti) - { + if (nti) { nti->mediatype = ITDB_MEDIATYPE_AUDIO; } break; @@@ -2357,20 -2649,22 +2360,23 @@@ gboolean read_lyrics_from_file(Track *t case FILE_TYPE_DIRECTORY: break; } - g_free (path); + g_free(path); } - else { - buf = get_track_info(track, FALSE); - gtkpod_warning(_("Lyrics not found, file not available (%s).\n\n"), buf); - g_free(buf); + else + { + buf = get_track_info (track, FALSE); + *lyrics=g_strdup_printf( + _("Error: Lyrics not found, file not available (%s).\n\n"), + buf); + g_free (buf); } - if (result) - { - if (!*lyrics) *lyrics=g_strdup(""); - if (etr->lyrics) g_free(etr->lyrics); - etr->lyrics=g_strdup(*lyrics); - } + if (result) { - if (!*lyrics) - *lyrics = g_strdup(""); - if (etr->lyrics) - g_free(etr->lyrics); - etr->lyrics = g_strdup(*lyrics); - } ++ if (!*lyrics) ++ *lyrics=g_strdup(""); ++ if (etr->lyrics) ++ g_free(etr->lyrics); ++ etr->lyrics=g_strdup(*lyrics); ++ } return result; } @@@ -2387,24 -2682,37 +2393,30 @@@ gboolean write_lyrics_to_file(Track *tr g_return_val_if_fail (track, FALSE); etr = track->userdata; g_return_val_if_fail (etr,FALSE); + + if (g_str_has_prefix(etr->lyrics, _("Error:"))) { + /* Not writing lyrics as there are only errors */ + return FALSE; + } + itdb = track->itdb; g_return_val_if_fail (itdb, FALSE); - path = get_file_name_from_source (track, SOURCE_IPOD); - if (!path) - { - if (prefs_get_int("id3_write")) - { - path = get_file_name_from_source (track, SOURCE_LOCAL); - } - else - { - buf = get_track_info (track, FALSE); - gtkpod_warning ( - _("iPod File not available and ID3 saving disabled in options, cannot save lyrics to: %s.\n\n"), - buf); - g_free (buf); - warned=TRUE; - } + path = get_file_name_from_source(track, SOURCE_IPOD); + if (!path) { + if (prefs_get_int("id3_write")) { + path = get_file_name_from_source(track, SOURCE_LOCAL); + } + else { + buf = get_track_info(track, FALSE); + gtkpod_warning(_("iPod File not available and ID3 saving disabled in options, cannot save lyrics to: %s.\n\n"), buf); + g_free(buf); + warned = TRUE; + } } - if (path!=NULL) - { - switch (determine_file_type (path)) - { + if (path != NULL) { + switch (determine_file_type(path)) { case FILE_TYPE_MP3: - result = id3_lyrics_save (path, etr->lyrics); + result = id3_lyrics_save(path, etr->lyrics); break; case FILE_TYPE_M4A: case FILE_TYPE_M4P: diff --cc src/file_itunesdb.c index 19819a6,1c058be..1654c72 --- a/src/file_itunesdb.c +++ b/src/file_itunesdb.c @@@ -397,96 -446,143 +397,105 @@@ iTunesDB *gp_import_itdb(iTunesDB *old_ g_return_val_if_fail (cfgdir, NULL); if (old_itdb) - offline = get_offline (old_itdb); + offline = get_offline(old_itdb); else - offline = FALSE; - - - block_widgets (); - if (offline || (type & GP_ITDB_TYPE_LOCAL)) - { /* offline or local database - requires extended info */ - gchar *name_ext; - gchar *name_db; - - if (type & GP_ITDB_TYPE_LOCAL) - { - name_ext = g_strdup_printf ("%s.ext", name_loc); - name_db = g_strdup (name_loc); - } - else - { - name_ext = g_strdup_printf ("%s.ext", name_off); - name_db = g_strdup (name_off); - } - - if (g_file_test (name_db, G_FILE_TEST_EXISTS)) - { - if (WRITE_EXTENDED_INFO) - { - if (!read_extended_info (name_ext, name_db)) - { - gchar *msg = g_strdup_printf(_("The repository %s does not have a readable extended database.\n"), name_db); - msg = g_strconcat(msg, - _("This database identifies the track on disk with the track data in the repository database."), - _("Any tracks already in the database cannot be transferred between repositories without the extended database."), - _("A new extended database will be created upon saving but existing tracks will need to be reimported to be linked to the file on disk."), - NULL); - - gtkpod_warning (msg); - g_free(msg); - } - } - itdb = itdb_parse_file (name_db, &error); - if (itdb && !error) - { - if (type & GP_ITDB_TYPE_IPOD) - gtkpod_statusbar_message( - _("Offline iPod database successfully imported")); - else - gtkpod_statusbar_message( - _("Local database successfully imported")); - } - else - { - if (error) - { - if (type & GP_ITDB_TYPE_IPOD) - gtkpod_warning ( - _("Offline iPod database import failed: '%s'\n\n"), - error->message); - else - gtkpod_warning ( - _("Local database import failed: '%s'\n\n"), - error->message); - } - else - { - if (type & GP_ITDB_TYPE_IPOD) - gtkpod_warning ( - _("Offline iPod database import failed: \n\n")); - else - gtkpod_warning ( - _("Local database import failed: \n\n")); - } - } - } - else - { - gtkpod_warning ( - _("'%s' does not exist. Import aborted.\n\n"), - name_db); - } - g_free (name_ext); - g_free (name_db); + offline = FALSE; + + block_widgets(); + if (offline || (type & GP_ITDB_TYPE_LOCAL)) { /* offline or local database - requires extended info */ + gchar *name_ext; + gchar *name_db; + + if (type & GP_ITDB_TYPE_LOCAL) { + name_ext = g_strdup_printf("%s.ext", name_loc); + name_db = g_strdup(name_loc); + } + else { + name_ext = g_strdup_printf("%s.ext", name_off); + name_db = g_strdup(name_off); + } + + if (g_file_test(name_db, G_FILE_TEST_EXISTS)) { + if (WRITE_EXTENDED_INFO) { + if (!read_extended_info(name_ext, name_db)) { - gtkpod_warning(_("Extended info will not be used. If you have non-transferred tracks,\nthese will be lost.\n")); ++ gchar ++ *msg = ++ g_strdup_printf(_("The repository %s does not have a readable extended database.\n"), name_db); ++ msg ++ = g_strconcat(msg, _("This database identifies the track on disk with the track data in the repository database."), ++ _("Any tracks already in the database cannot be transferred between repositories without the extended database."), ++ _("A new extended database will be created upon saving but existing tracks will need to be reimported to be linked to the file on disk."), ++ NULL); ++ ++ gtkpod_warning(msg); + } + } + itdb = itdb_parse_file(name_db, &error); + if (itdb && !error) { + if (type & GP_ITDB_TYPE_IPOD) + gtkpod_statusbar_message(_("Offline iPod database successfully imported")); + else + gtkpod_statusbar_message(_("Local database successfully imported")); + } + else { + if (error) { + if (type & GP_ITDB_TYPE_IPOD) + gtkpod_warning(_("Offline iPod database import failed: '%s'\n\n"), error->message); + else + gtkpod_warning(_("Local database import failed: '%s'\n\n"), error->message); + } + else { + if (type & GP_ITDB_TYPE_IPOD) + gtkpod_warning(_("Offline iPod database import failed: \n\n")); + else + gtkpod_warning(_("Local database import failed: \n\n")); + } + } + } + else { + gtkpod_warning(_("'%s' does not exist. Import aborted.\n\n"), name_db); + } + g_free(name_ext); + g_free(name_db); } - else - { /* GP_ITDB_TYPE_IPOD _and_ iPod is connected */ - gchar *name_ext=NULL, *name_db=NULL; - - name_db = itdb_get_itunesdb_path (mp); - if (name_db) - { - name_ext = g_strdup_printf("%s.ext", name_db); - - if (WRITE_EXTENDED_INFO) - { - if (!read_extended_info (name_ext, name_db)) - { - gtkpod_warning (_("Extended info will not be used.\n")); - } - } - itdb = itdb_parse (mp, &error); - if(itdb && !error) - { - gtkpod_statusbar_message ( - _("iPod Database Successfully Imported")); - } - else - { - if (error) - { - gtkpod_warning ( - _("iPod Database Import Failed: '%s'\n\n"), - error->message); - } - else - { - gtkpod_warning ( - _("iPod Database Import Failed.\n\n")); - } - } - } - else - { - gchar *name = g_build_filename ( - mp, - "iPod_Control","iTunes","iTunesDB",NULL); - gtkpod_warning (_("'%s' (or similar) does not exist. Import aborted.\n\n"), - name); - g_free (name); - } - g_free (name_ext); - g_free (name_db); - } - g_free (cfgdir); - - if (!itdb) - { - release_widgets (); - return NULL; + else { /* GP_ITDB_TYPE_IPOD _and_ iPod is connected */ + gchar *name_ext = NULL, *name_db = NULL; + + name_db = itdb_get_itunesdb_path(mp); + if (name_db) { + name_ext = g_strdup_printf("%s.ext", name_db); + + if (WRITE_EXTENDED_INFO) { + if (!read_extended_info(name_ext, name_db)) { + gtkpod_warning(_("Extended info will not be used.\n")); + } + } + itdb = itdb_parse(mp, &error); + if (itdb && !error) { + gtkpod_statusbar_message(_("iPod Database Successfully Imported")); + } + else { + if (error) { + gtkpod_warning(_("iPod Database Import Failed: '%s'\n\n"), error->message); + } + else { + gtkpod_warning(_("iPod Database Import Failed.\n\n")); + } + } + } + else { + gchar *name = g_build_filename(mp, "iPod_Control", "iTunes", "iTunesDB", NULL); + gtkpod_warning(_("'%s' (or similar) does not exist. Import aborted.\n\n"), name); + g_free(name); + } + g_free(name_ext); + g_free(name_db); + } + g_free(cfgdir); + + if (!itdb) { + release_widgets(); + return NULL; } /* add Extra*Data */ @@@ -1573,257 -1827,313 +1582,257 @@@ static gboolean transfer_tracks(iTunesD return result; } +static gboolean gp_write_itdb(iTunesDB *itdb) { + gchar *cfgdir; + gboolean success = TRUE; + ExtraiTunesDBData *eitdb; + GtkWidget *dialog; + Playlist *mpl; + TransferData *transferdata; + g_return_val_if_fail (itdb, FALSE); + eitdb = itdb->userdata; + g_return_val_if_fail (eitdb, FALSE); -static gboolean gp_write_itdb (iTunesDB *itdb) -{ - gchar *cfgdir; - gboolean success = TRUE; - ExtraiTunesDBData *eitdb; - GtkWidget *dialog; - Playlist *mpl; - TransferData *transferdata; - - g_return_val_if_fail (itdb, FALSE); - eitdb = itdb->userdata; - g_return_val_if_fail (eitdb, FALSE); - - cfgdir = prefs_get_cfgdir (); - g_return_val_if_fail (cfgdir, FALSE); - - mpl = itdb_playlist_mpl (itdb); - g_return_val_if_fail (mpl, FALSE); - - if (!eitdb->itdb_imported) - { /* No iTunesDB was read but user wants to export current - data. If an iTunesDB is present on the iPod or in cfgdir, - this is most likely an error. We should tell the user */ - gchar *tunes = NULL; - /* First check if we can find an existing iTunesDB. */ - if (itdb->usertype & GP_ITDB_TYPE_LOCAL) - { - tunes = g_strdup (itdb->filename); - } - else if (itdb->usertype & GP_ITDB_TYPE_IPOD) - { - if (get_offline (itdb)) - { - tunes = g_strdup (eitdb->offline_filename); - } - else - { - const gchar *mountpoint = itdb_get_mountpoint (itdb); - g_return_val_if_fail (mountpoint, FALSE); - tunes = itdb_get_itunesdb_path (mountpoint); - } - } - else - { - g_free (cfgdir); - g_return_val_if_reached (FALSE); - } - if (g_file_test (tunes, G_FILE_TEST_EXISTS)) - { - gchar *str = g_strdup_printf (_("You did not import the existing iTunesDB ('%s'). This is most likely incorrect and will result in the loss of the existing database.\n\nIf you skip storing, you can import the existing database before calling this function again.\n"), tunes); - - gint result = gtkpod_confirmation_hig (GTK_WINDOW (gtkpod_window), - GTK_MESSAGE_WARNING, - _("Existing iTunes database not imported"), - str, - _("Proceed anyway"), - _("Skip storing"), - NULL, - NULL); - - g_free (str); - - if (result == GTK_RESPONSE_CANCEL) - { - g_free (cfgdir); - return FALSE; - } - } - } - - block_widgets (); - - transferdata = transfer_data_new (); - dialog = create_transfer_information_dialog (transferdata); - gtk_widget_show (dialog); - - if((itdb->usertype & GP_ITDB_TYPE_IPOD) && !get_offline (itdb)) - { - const gchar *mountpoint = itdb_get_mountpoint (itdb); - g_return_val_if_fail (mountpoint, FALSE); - /* check if iPod directories are present */ - if (!ipod_dirs_present (mountpoint)) - { /* no -- create them */ - gp_ipod_init (itdb); - /* if still not present abort */ - if (!ipod_dirs_present (mountpoint)) - { - gtkpod_warning (_("iPod directory structure must be present before synching to the iPod can be performed.\n")); - success = FALSE; - } - } - if (success) - { /* remove deleted files */ - success = delete_files (itdb, transferdata); - if (!success) - { - gtkpod_warning (_("Some tracks could not be deleted from the iPod. Export aborted!")); - } - } - if (success) - { - /* write tracks to iPod */ - success = transfer_tracks (itdb, transferdata); - } - } - - if (itdb->usertype & GP_ITDB_TYPE_LOCAL) - { - success = delete_files (itdb, transferdata); - } - - if (success) - { - gchar *buf; - buf = g_strdup_printf (_("Now writing database '%s'. Please wait..."), mpl->name); - gtk_label_set_text (GTK_LABEL (transferdata->textlabel), buf); - g_free (buf); - - while (widgets_blocked && gtk_events_pending ()) - gtk_main_iteration (); - } - - if (success && !get_offline (itdb) && - (itdb->usertype & GP_ITDB_TYPE_IPOD)) - { /* write to the iPod */ - GError *error = NULL; - if (!itdb_write (itdb, &error)) - { /* an error occurred */ - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - g_error_free (error); - error = NULL; - } - - if (success) - { /* write shuffle data */ - if (!itdb_shuffle_write (itdb, &error)) - { /* an error occurred */ - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - g_error_free (error); - error = NULL; - } - } - if (success) - { - if (WRITE_EXTENDED_INFO) - { /* write extended information */ - success = write_extended_info (itdb); - } - else - { /* delete extended information if present */ - gchar *ext = g_strdup_printf ("%s.ext", itdb->filename); - if (g_file_test (ext, G_FILE_TEST_EXISTS)) - { - if (remove (ext) != 0) - { - gtkpod_statusbar_message (_("Extended information file not deleted: '%s\'"), ext); - } - } - g_free (ext); - } - } - if (success) - { /* copy to cfgdir */ - GError *error = NULL; - if (! g_file_test (eitdb->offline_filename, G_FILE_TEST_EXISTS)) - { - /* Possible that plugging an ipod into a different pc can lead to an offline filename - * that does not exist. This results in the save process failing as it cannot write a - * backup. Attempt to mitigate this situation with a reserve backup path. - */ - gchar *ipod_model = get_itdb_prefs_string (itdb, KEY_IPOD_MODEL); - gchar *backup_name = g_strconcat ("backupDB_", ipod_model, NULL); - g_free (ipod_model); - g_free (eitdb->offline_filename); - eitdb->offline_filename = g_build_filename(cfgdir, backup_name, NULL); - g_free (backup_name); - gtkpod_warning ("Backup database could not be found so backing up database to %s\n", eitdb->offline_filename); - } - - if (!itdb_cp (itdb->filename, eitdb->offline_filename, &error)) - { - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - g_error_free (error); - error = NULL; - } - if (WRITE_EXTENDED_INFO) - { - gchar *from, *to; - from = g_strdup_printf ("%s.ext", itdb->filename); - to = g_strdup_printf ("%s.ext", eitdb->offline_filename); - if (!itdb_cp (from, to, &error)) - { - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - g_error_free (error); - } - g_free (from); - g_free (to); - } - } - } - - if (success && get_offline (itdb) && - (itdb->usertype & GP_ITDB_TYPE_IPOD)) - { /* write to cfgdir */ - GError *error = NULL; - if (!itdb_write_file (itdb, eitdb->offline_filename, &error)) - { /* an error occurred */ - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - g_error_free (error); - error = NULL; - } - if (success && WRITE_EXTENDED_INFO) - { /* write extended information */ - success = write_extended_info (itdb); - } - } - - - if (success && (itdb->usertype & GP_ITDB_TYPE_LOCAL)) - { /* write to cfgdir */ - GError *error = NULL; - if (!itdb_write_file (itdb, NULL, &error)) - { /* an error occurred */ - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - g_error_free (error); - error = NULL; - } - if (success) - { /* write extended information */ - success = write_extended_info (itdb); - } - } - - /* If the ipod supports photos and the photo_data_changed - * flag has been set to true then wrtie the photo database - */ - if (success && - (itdb->usertype & GP_ITDB_TYPE_IPOD) && - itdb_device_supports_photo (itdb->device) && - eitdb->photodb != NULL && - eitdb->photo_data_changed == TRUE) - { - GError *error = NULL; - if (!itdb_photodb_write (eitdb->photodb, &error)) - { - success = FALSE; - if (error && error->message) - gtkpod_warning ("%s\n\n", error->message); - else - g_warning ("error->message == NULL!\n"); - - g_error_free (error); - error = NULL; - } - } - - /* indicate that files and/or database is saved */ - if (success) - { - data_unchanged (itdb); - if (itdb->usertype & GP_ITDB_TYPE_IPOD) - { - gtkpod_statusbar_message(_("%s: Database saved"), mpl->name); - } - else - { - gtkpod_statusbar_message(_("%s: Changes saved"), mpl->name); - } - } - - g_free (cfgdir); - - gtk_widget_destroy (dialog); - transfer_data_free (transferdata); - - release_widgets (); - - return success; -} + cfgdir = prefs_get_cfgdir(); + g_return_val_if_fail (cfgdir, FALSE); + + mpl = itdb_playlist_mpl(itdb); + g_return_val_if_fail (mpl, FALSE); + + if (!eitdb->itdb_imported) { /* No iTunesDB was read but user wants to export current + data. If an iTunesDB is present on the iPod or in cfgdir, + this is most likely an error. We should tell the user */ + gchar *tunes = NULL; + /* First check if we can find an existing iTunesDB. */ + if (itdb->usertype & GP_ITDB_TYPE_LOCAL) { + tunes = g_strdup(itdb->filename); + } + else if (itdb->usertype & GP_ITDB_TYPE_IPOD) { + if (get_offline(itdb)) { + tunes = g_strdup(eitdb->offline_filename); + } + else { + const gchar *mountpoint = itdb_get_mountpoint(itdb); + g_return_val_if_fail (mountpoint, FALSE); + tunes = itdb_get_itunesdb_path(mountpoint); + } + } + else { + g_free(cfgdir); + g_return_val_if_reached (FALSE); + } + if (g_file_test(tunes, G_FILE_TEST_EXISTS)) { + gchar + *str = + g_strdup_printf(_("You did not import the existing iTunesDB ('%s'). This is most likely incorrect and will result in the loss of the existing database.\n\nIf you skip storing, you can import the existing database before calling this function again.\n"), tunes); + + gint + result = + gtkpod_confirmation_hig(GTK_MESSAGE_WARNING, _("Existing iTunes database not imported"), str, _("Proceed anyway"), _("Skip storing"), NULL, NULL); + + g_free(str); + + if (result == GTK_RESPONSE_CANCEL) { + g_free(cfgdir); + return FALSE; + } + } + } + block_widgets(); + + transferdata = transfer_data_new(); + dialog = create_transfer_information_dialog(transferdata); + gtk_widget_show(dialog); + + if ((itdb->usertype & GP_ITDB_TYPE_IPOD) && !get_offline(itdb)) { + const gchar *mountpoint = itdb_get_mountpoint(itdb); + g_return_val_if_fail (mountpoint, FALSE); + /* check if iPod directories are present */ + if (!ipod_dirs_present(mountpoint)) { /* no -- create them */ + gtkpod_init_repository(itdb); + /* if still not present abort */ + if (!ipod_dirs_present(mountpoint)) { + gtkpod_warning(_("iPod directory structure must be present before synching to the iPod can be performed.\n")); + success = FALSE; + } + } + if (success) { /* remove deleted files */ + success = delete_files(itdb, transferdata); + if (!success) { + gtkpod_warning(_("Some tracks could not be deleted from the iPod. Export aborted!")); + } + } + if (success) { + /* write tracks to iPod */ + success = transfer_tracks(itdb, transferdata); + } + } + if (itdb->usertype & GP_ITDB_TYPE_LOCAL) { + success = delete_files(itdb, transferdata); + } + + if (success) { + gchar *buf; + buf = g_strdup_printf(_("Now writing database '%s'. Please wait..."), mpl->name); + gtk_label_set_text(GTK_LABEL (transferdata->textlabel), buf); + g_free(buf); + + while (widgets_blocked && gtk_events_pending()) + gtk_main_iteration(); + } + + if (success && !get_offline(itdb) && (itdb->usertype & GP_ITDB_TYPE_IPOD)) { /* write to the iPod */ + GError *error = NULL; + if (!itdb_write(itdb, &error)) { /* an error occurred */ + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + g_error_free(error); + error = NULL; + } + + if (success) { /* write shuffle data */ + if (!itdb_shuffle_write(itdb, &error)) { /* an error occurred */ + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + g_error_free(error); + error = NULL; + } + } + if (success) { + if (WRITE_EXTENDED_INFO) { /* write extended information */ + success = write_extended_info(itdb); + } + else { /* delete extended information if present */ + gchar *ext = g_strdup_printf("%s.ext", itdb->filename); + if (g_file_test(ext, G_FILE_TEST_EXISTS)) { + if (remove(ext) != 0) { + gtkpod_statusbar_message(_("Extended information file not deleted: '%s\'"), ext); + } + } + g_free(ext); + } + } + if (success) { /* copy to cfgdir */ + GError *error = NULL; + if (!g_file_test(eitdb->offline_filename, G_FILE_TEST_EXISTS)) { + /* Possible that plugging an ipod into a different pc can lead to an offline filename + * that does not exist. This results in the save process failing as it cannot write a + * backup. Attempt to mitigate this situation with a reserve backup path. + */ + gchar *ipod_model = get_itdb_prefs_string(itdb, KEY_IPOD_MODEL); + gchar *backup_name = g_strconcat("backupDB_", ipod_model, NULL); + g_free(ipod_model); + eitdb->offline_filename = g_build_filename(cfgdir, backup_name, NULL); + g_free(backup_name); + gtkpod_warning("Backup database could not be found so backing up database to %s\n", eitdb->offline_filename); + } + + if (!itdb_cp(itdb->filename, eitdb->offline_filename, &error)) { + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + g_error_free(error); + error = NULL; + } + if (WRITE_EXTENDED_INFO) { + gchar *from, *to; + from = g_strdup_printf("%s.ext", itdb->filename); + to = g_strdup_printf("%s.ext", eitdb->offline_filename); + if (!itdb_cp(from, to, &error)) { + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + g_error_free(error); + } + g_free(from); + g_free(to); + } + } + } + + if (success && get_offline(itdb) && (itdb->usertype & GP_ITDB_TYPE_IPOD)) { /* write to cfgdir */ + GError *error = NULL; + if (!itdb_write_file(itdb, eitdb->offline_filename, &error)) { /* an error occurred */ + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + g_error_free(error); + error = NULL; + } + if (success && WRITE_EXTENDED_INFO) { /* write extended information */ + success = write_extended_info(itdb); + } + } + + if (success && (itdb->usertype & GP_ITDB_TYPE_LOCAL)) { /* write to cfgdir */ + GError *error = NULL; + if (!itdb_write_file(itdb, NULL, &error)) { /* an error occurred */ + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + g_error_free(error); + error = NULL; + } + if (success) { /* write extended information */ + success = write_extended_info(itdb); + } + } + + /* If the ipod supports photos and the photo_data_changed + * flag has been set to true then wrtie the photo database + */ + if (success && (itdb->usertype & GP_ITDB_TYPE_IPOD) && itdb_device_supports_photo(itdb->device) && eitdb->photodb + != NULL && eitdb->photo_data_changed == TRUE) { + GError *error = NULL; + if (!itdb_photodb_write(eitdb->photodb, &error)) { + success = FALSE; + if (error && error->message) + gtkpod_warning("%s\n\n", error->message); - else ++ else + g_warning ("error->message == NULL!\n"); + + g_error_free(error); + error = NULL; + } + } + + /* indicate that files and/or database is saved */ + if (success) { + data_unchanged(itdb); + if (itdb->usertype & GP_ITDB_TYPE_IPOD) { + gtkpod_statusbar_message(_("%s: Database saved"), mpl->name); + } + else { + gtkpod_statusbar_message(_("%s: Changes saved"), mpl->name); + } + } + + g_free(cfgdir); + + gtk_widget_destroy(dialog); + transfer_data_free(transferdata); + + release_widgets(); + + return success; +} /* used to handle export of database */ /* ATTENTION: directly used as callback in gtkpod.glade -- if you diff --cc src/misc.c index 0080f10,9133de7..409de17 --- a/src/misc.c +++ b/src/misc.c @@@ -158,22 -60,8 +158,22 @@@ void update_blocked_widget(GtkWidget *w * * * Miscellaneous * * * - \*------------------------------------------------------------------*/ + \*------------------------------------------------------------------*/ +/* Concats @base_dir and @rel_dir if and only if @rel_dir is not + * absolute (does not start with '~' or '/'). Otherwise simply return + * a copy of @rel_dir. Must free return value after use */ +gchar *concat_dir_if_relative(G_CONST_RETURN gchar *base_dir, G_CONST_RETURN gchar *rel_dir) { + /* sanity */ + if (!rel_dir || !*rel_dir) + return g_build_filename(base_dir, rel_dir, NULL); + /* this constellation is nonsense... */ + if ((*rel_dir == '/') || (*rel_dir == '~')) + return g_strdup(rel_dir); /* rel_dir is absolute */ + /* make absolute path */ + return g_build_filename(base_dir, rel_dir, NULL); +} + gchar *utf8_strcasestr(const gchar *haystack, const gchar *needle) { g_return_val_if_fail (haystack != NULL, NULL); g_return_val_if_fail (needle != NULL, NULL); diff --cc src/sort_window.c index 8c4f0a0,57d3fa4..b1aa06d --- a/src/sort_window.c +++ b/src/sort_window.c @@@ -123,117 -148,133 +123,119 @@@ static void sort_window_read_sort_ign( * Create, Initialize, and Show the sorting preferences window * allocate a static sort struct for temporary variables */ -void sort_window_create (void) -{ - if (sort_window) - { - /* sort options already open --> simply raise to the top */ - gdk_window_raise(sort_window->window); +void sort_window_create(void) { + if (sort_window) { + /* sort options already open --> simply raise to the top */ + gdk_window_raise(sort_window->window); } - else - { - GList *sort_ign_strings; - GList *current; /* current sort ignore item */ - GtkWidget *w; - GtkTextView *tv; - GtkTextBuffer *tb; - gint i; - GtkTextIter ti; - gchar *str; - GtkTooltips *tooltips; - gint *tm_listed_order, tm_list_pos; - - sort_temp_prefs = temp_prefs_create(); - sort_temp_lists = temp_lists_create(); - - sort_window_xml = gtkpod_xml_new (xml_file, "sort_window"); - glade_xml_signal_autoconnect (sort_window_xml); - - sort_window = gtkpod_xml_get_widget (sort_window_xml, "sort_window"); - - /* label the ignore-field checkbox-labels */ - for (i=0; sort_ign_fields[i] != -1; ++i) - { - gchar *buf = g_strdup_printf ("sort_ign_field_%d", - sort_ign_fields[i]); - GtkWidget *w = gtkpod_xml_get_widget (sort_window_xml, buf); - g_return_if_fail (w); - gtk_button_set_label ( - GTK_BUTTON (w), - gettext (get_t_string (sort_ign_fields[i]))); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (w), - prefs_get_int (buf)); - g_free (buf); - } - /* set the ignore strings */ - tv = GTK_TEXT_VIEW (gtkpod_xml_get_widget (sort_window_xml, - "sort_ign_strings")); - tb = gtk_text_view_get_buffer (tv); - if (!tb) - { /* text buffer doesn't exist yet */ - tb = gtk_text_buffer_new (NULL); - gtk_text_view_set_buffer(tv, tb); - gtk_text_view_set_editable(tv, FALSE); - gtk_text_view_set_cursor_visible(tv, FALSE); - } - - sort_ign_strings = prefs_get_list("sort_ign_string_"); - current = sort_ign_strings; - while (current) - { - str = (gchar *)current->data; - current = g_list_next(current); - - /* append new text to the end */ - gtk_text_buffer_get_end_iter (tb, &ti); - gtk_text_buffer_insert (tb, &ti, str, -1); - /* append newline */ - gtk_text_buffer_get_end_iter (tb, &ti); - gtk_text_buffer_insert (tb, &ti, "\n", -1); - } - - prefs_free_list(sort_ign_strings); - - sort_window_read_sort_ign (); - - /* Set Sort-Column-Combo */ - /* create the list in the order of the columns displayed */ - tm_store_col_order (); - - /* Here we store the order of TM_Items in the - * GtkComboBox */ - tm_listed_order = g_new (gint, TM_NUM_COLUMNS); - tm_list_pos = 1; - - w = gtkpod_xml_get_widget (sort_window_xml, "sort_combo"); - gtk_combo_box_remove_text (GTK_COMBO_BOX (w), 0); - - gtk_combo_box_append_text (GTK_COMBO_BOX (w), _("No sorting")); - - for (i = 0; i < TM_NUM_COLUMNS; ++i) - { /* first the visible columns */ - TM_item col = prefs_get_int_index("col_order", i); - if (col != -1) - { - if (prefs_get_int_index("col_visible", col)) - { - gtk_combo_box_append_text (GTK_COMBO_BOX (w), gettext (get_tm_string (col))); - tm_listed_order[col] = tm_list_pos; - ++tm_list_pos; - } - } - } - - for (i=0; i<TM_NUM_COLUMNS; ++i) - { /* now the hidden colums */ - TM_item col = prefs_get_int_index("col_order", i); - if (col != -1) - { - if (!prefs_get_int_index("col_visible", col)) - { - gtk_combo_box_append_text (GTK_COMBO_BOX (w), gettext (get_tm_string (col))); - tm_listed_order[col] = tm_list_pos; - ++tm_list_pos; - } - } - } - - /* associate tm_listed_order with sort_window */ - g_object_set_data (G_OBJECT (sort_window), "tm_listed_order", tm_listed_order); - - tooltips = gtk_tooltips_new (); - gtk_tooltips_set_tip (tooltips, w, _("You can also use the table headers, but this allows you to sort according to a column that is not displayed."), NULL); - - sort_window_update (); - - sort_window_show_hide_tooltips (); - gtk_window_set_transient_for (GTK_WINDOW (sort_window), GTK_WINDOW (gtkpod_window)); - gtk_widget_show (sort_window); + else { + GList *sort_ign_strings; + GList *current; /* current sort ignore item */ + GtkWidget *w; + GtkTextView *tv; + GtkTextBuffer *tb; + gint i; + GtkTextIter ti; + gchar *str; + GtkTooltips *tooltips; + gint *tm_listed_order, tm_list_pos; + + sort_temp_prefs = temp_prefs_create(); + sort_temp_lists = temp_lists_create(); + + gchar *glade_path = g_build_filename(get_glade_dir(), "track_display.glade", NULL); + sort_window_xml = gtkpod_xml_new(glade_path, "sort_window"); + glade_xml_signal_autoconnect(sort_window_xml); + g_free(glade_path); + + sort_window = gtkpod_xml_get_widget(sort_window_xml, "sort_window"); + + /* label the ignore-field checkbox-labels */ + for (i = 0; sort_ign_fields[i] != -1; ++i) { + gchar *buf = g_strdup_printf("sort_ign_field_%d", sort_ign_fields[i]); + GtkWidget *w = gtkpod_xml_get_widget(sort_window_xml, buf); + g_return_if_fail (w); + gtk_button_set_label(GTK_BUTTON (w), gettext (get_t_string (sort_ign_fields[i]))); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (w), prefs_get_int(buf)); + g_free(buf); + } + /* set the ignore strings */ + tv = GTK_TEXT_VIEW (gtkpod_xml_get_widget (sort_window_xml, + "sort_ign_strings")); + tb = gtk_text_view_get_buffer(tv); + if (!tb) { /* text buffer doesn't exist yet */ + tb = gtk_text_buffer_new(NULL); + gtk_text_view_set_buffer(tv, tb); + gtk_text_view_set_editable(tv, FALSE); + gtk_text_view_set_cursor_visible(tv, FALSE); + } + + sort_ign_strings = prefs_get_list("sort_ign_string_"); + current = sort_ign_strings; + while (current) { + str = (gchar *) current->data; + current = g_list_next(current); + + /* append new text to the end */ + gtk_text_buffer_get_end_iter(tb, &ti); + gtk_text_buffer_insert(tb, &ti, str, -1); + /* append newline */ + gtk_text_buffer_get_end_iter(tb, &ti); + gtk_text_buffer_insert(tb, &ti, "\n", -1); + } + + prefs_free_list(sort_ign_strings); + + sort_window_read_sort_ign(); + + /* Set Sort-Column-Combo */ + /* create the list in the order of the columns displayed */ + tm_store_col_order(); + + /* Here we store the order of TM_Items in the + * GtkComboBox */ + tm_listed_order = g_new (gint, TM_NUM_COLUMNS); + tm_list_pos = 1; + + w = gtkpod_xml_get_widget(sort_window_xml, "sort_combo"); + gtk_combo_box_remove_text(GTK_COMBO_BOX (w), 0); + + gtk_combo_box_append_text(GTK_COMBO_BOX (w), _("No sorting")); + + for (i = 0; i < TM_NUM_COLUMNS; ++i) { /* first the visible columns */ + TM_item col = prefs_get_int_index("col_order", i); + if (col != -1) { + if (prefs_get_int_index("col_visible", col)) { + gtk_combo_box_append_text(GTK_COMBO_BOX (w), gettext (get_tm_string (col))); + tm_listed_order[col] = tm_list_pos; + ++tm_list_pos; + } + } + } + + for (i = 0; i < TM_NUM_COLUMNS; ++i) { /* now the hidden colums */ + TM_item col = prefs_get_int_index("col_order", i); + if (col != -1) { + if (!prefs_get_int_index("col_visible", col)) { + gtk_combo_box_append_text(GTK_COMBO_BOX (w), gettext (get_tm_string (col))); + tm_listed_order[col] = tm_list_pos; + ++tm_list_pos; + } + } + } + + /* associate tm_listed_order with sort_window */ + g_object_set_data(G_OBJECT (sort_window), "tm_listed_order", tm_listed_order); + + tooltips = gtk_tooltips_new(); + gtk_tooltips_set_tip(tooltips, w, _("You can also use the table headers, but this allows you to sort according to a column that is not displayed."), NULL); + + sort_window_update(); + + sort_window_show_hide_tooltips(); ++ gtk_window_set_transient_for (GTK_WINDOW (sort_window), GTK_WINDOW (gtkpod_app)); + gtk_widget_show(sort_window); ++ } } ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2