From: Andrew Stanley-J. <as...@cb...> - 2006-02-02 01:23:37
|
Sorry for the delay, I've been traveling and just got home, plus sf wasn't cooperating on Sunday so I couldn't do a checkout with my account correctly. This patch needs a bug fix, it doesn't save the information right the first time it sees the file. I also had to toss a bunch of lines from the patch for checking on the double free on double sync so it may not apply cleanly. Anyways, it'll give you an idea of what my idea was. I'll clean it up over the next couple of days. --- Andrew Stanley-Jones | "It's kind of fun to do the impossible." EE, LongEz N87KJ | -- Walt Disney diff -u -r1.53 context_menus.c --- context_menus.c 14 Dec 2005 14:58:55 -0000 1.53 +++ context_menus.c 2 Feb 2006 01:14:58 -0000 @@ -378,7 +378,7 @@ G_CALLBACK (create_playlist_file), NULL); hookup_mi (menu[type], _("Edit Details"), NULL, G_CALLBACK (edit_details_entries), NULL); - hookup_mi (menu[type], _("Update"), GTK_STOCK_REFRESH, + hookup_mi (menu[type], _("Refresh Meta Info from Files"), GTK_STOCK_REFRESH, G_CALLBACK (update_entries), NULL); hookup_mi (menu[type], _("Sync Dirs"), GTK_STOCK_REFRESH, G_CALLBACK (sync_dirs_entries), NULL); diff -u -r1.24 display_itdb.h --- display_itdb.h 5 Dec 2005 16:35:17 -0000 1.24 +++ display_itdb.h 2 Feb 2006 01:14:59 -0000 @@ -78,6 +78,7 @@ gchar *hostname; /* name of host this file has been imported on*/ gchar *md5_hash; /* md5 hash of file (or NULL) */ gchar *charset; /* charset used for ID3 tags */ + time_t mtime; /* file modification time */ gint32 sortindex; /* used for stable sorting (current order) */ gboolean tchanged; /* temporary use, e.g. in detail.c */ } ExtraTrackData; Index: file.c =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/file.c,v retrieving revision 1.152 diff -u -r1.152 file.c --- file.c 10 Dec 2005 17:04:28 -0000 1.152 +++ file.c 2 Feb 2006 01:15:06 -0000 @@ -328,7 +328,7 @@ } else if (add_track_by_filename (itdb, filename, plitem, prefs_get_add_recursively (), - addtrackfunc, data)) + addtrackfunc, data, 0)) { ++tracks; } @@ -367,7 +367,8 @@ position in the track view */ gboolean add_directory_by_name (iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, - AddTrackFunc addtrackfunc, gpointer data) + AddTrackFunc addtrackfunc, gpointer data, + gboolean nocache) { gboolean result = TRUE; @@ -389,7 +390,7 @@ !g_file_test (nextfull, G_FILE_TEST_IS_DIR)) result &= add_directory_by_name ( itdb, nextfull, plitem, - descend, addtrackfunc, data); + descend, addtrackfunc, data, nocache); g_free (nextfull); } } while (next != NULL); @@ -400,7 +401,7 @@ else { result = add_track_by_filename (itdb, name, plitem, - descend, addtrackfunc, data); + descend, addtrackfunc, data, nocache); } return result; } @@ -756,6 +763,7 @@ g_free (eto->charset); g_free (eto->thumb_path_utf8); g_free (eto->thumb_path_locale); + itdb_artwork_free (to->artwork); /* copy strings */ to->album = g_strdup (from->album); @@ -787,6 +795,7 @@ eto->peak_signal_set = efrom->peak_signal_set; eto->radio_gain_set = efrom->radio_gain_set; eto->audiophile_gain_set = efrom->audiophile_gain_set; + eto->mtime = efrom->mtime; to->time_added = from->time_added; to->time_modified = from->time_modified; to->year = from->year; @@ -1169,7 +1183,7 @@ get_track_info (track, TRUE)); gtkpod_statusbar_message (buf); g_free (buf); - update_track_from_file (track->itdb, track); + update_track_from_file (track->itdb, track, 1); } } release_widgets (); @@ -1297,7 +1311,7 @@ g_free (dir_utf8); /* sync dir */ - add_directory_by_name (itdb, dir, pl, FALSE, sync_addtrackfunc, NULL); + add_directory_by_name (itdb, dir, pl, FALSE, sync_addtrackfunc, NULL, 0); /* reset charset */ if (!prefs_get_update_charset () && charset) @@ -1856,14 +1870,17 @@ a list of those can be displayed by calling "remove_duplicate (NULL, NULL)", that list can be deleted by calling "remove_duplicate (NULL, (void *)-1)"*/ -void update_track_from_file (iTunesDB *itdb, Track *track) +void update_track_from_file (iTunesDB *itdb, Track *track, gboolean nocache) { ExtraTrackData *etr; Track *oldtrack; gchar *prefs_charset = NULL; gchar *trackpath = NULL; gint32 oldsize = 0; + gint32 no_change = 0; gboolean charset_set; + struct stat filestat; + g_return_if_fail (itdb); g_return_if_fail (track); @@ -1893,14 +1910,34 @@ get_track_info_from_file () since track->pc_path gets g_freed there */ trackpath = g_strdup (etr->pc_path_locale); + + if(nocache == 0){ + if (stat(trackpath,&filestat) == 0){ + if(filestat.st_size == track->size && + filestat.st_mtime == etr->mtime){ + no_change = 1; + } + } + else { + perror("Can't stat file"); + } + } } if (!(etr->pc_path_locale && *etr->pc_path_locale)) { /* no path available */ display_non_updated (track, _("no filename available")); } + else if (no_change){ + } else if (get_track_info_from_file (trackpath, track)) { /* update successfull */ + /* save the modification time so updates are faster */ + if(stat(trackpath,&filestat) == 0){ + printf("Size: %ld date: %ld\n", filestat.st_size, filestat.st_mtime); + etr->mtime = filestat.st_mtime; + } + /* remove track from md5 hash and reinsert it (hash value may have changed!) */ gchar *oldhash = etr->md5_hash; @@ -1978,7 +2015,7 @@ position in the track view */ gboolean add_track_by_filename (iTunesDB *itdb, gchar *fname, Playlist *plitem, gboolean descend, - AddTrackFunc addtrackfunc, gpointer data) + AddTrackFunc addtrackfunc, gpointer data, gboolean nocache) { static gint count = 0; /* do a gtkpod_tracks_statusbar_update() every 10 tracks */ @@ -1997,9 +2034,11 @@ 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, nocache); } + + /* check if file is a playlist */ switch (determine_file_type(fname)) { @@ -2043,7 +2082,7 @@ { if (prefs_get_update_existing ()) { /* update the information */ - update_track_from_file (itdb, oldtrack); + update_track_from_file (itdb, oldtrack, nocache); } /* add to current playlist if it's not already in there */ if (!itdb_playlist_is_mpl (plitem)) Index: file.h =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/file.h,v retrieving revision 1.47 diff -u -r1.47 file.h --- file.h 10 Dec 2005 17:04:28 -0000 1.47 +++ file.h 2 Feb 2006 01:15:06 -0000 @@ -70,16 +70,16 @@ FileType determine_file_type(gchar *path); gboolean add_track_by_filename (iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, - AddTrackFunc addtrackfunc, gpointer data); + AddTrackFunc addtrackfunc, gpointer data, gboolean nocache); gboolean add_directory_by_name (iTunesDB *itdb, gchar *name, Playlist *plitem, gboolean descend, - AddTrackFunc addtrackfunc, gpointer data); + AddTrackFunc addtrackfunc, gpointer data, gboolean nocache); Playlist *add_playlist_by_filename (iTunesDB *itdb, gchar *plfile, Playlist *plitem, gint plitem_pos, AddTrackFunc addtrackfunc, gpointer data); gboolean write_tags_to_file(Track *s); -void update_track_from_file (iTunesDB *itdb, Track *track); +void update_track_from_file (iTunesDB *itdb, Track *track, gboolean nocache); void update_tracks (GList *selected_tracks); void mserv_from_file_tracks (GList *selected_tracks); void sync_tracks (GList *selected_tracks); Index: file_itunesdb.c =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/file_itunesdb.c,v retrieving revision 1.72 diff -u -r1.72 file_itunesdb.c --- file_itunesdb.c 4 Dec 2005 16:00:39 -0000 1.72 +++ file_itunesdb.c 2 Feb 2006 01:15:09 -0000 @@ -64,6 +64,7 @@ gchar *hostname; gchar *ipod_path; gint32 oldsize; + gint32 mtime; guint32 playcount; guint32 rating; /* still read but never written */ guint32 peak_signal; @@ -146,6 +147,7 @@ if (sei->hostname && !etr->hostname) etr->hostname = g_strdup (sei->hostname); etr->oldsize = sei->oldsize; + etr->mtime = sei->mtime; track->playcount += sei->playcount; if (sei->peak_signal_set) { @@ -382,6 +384,8 @@ sei->rating = atoi (arg); else if (g_ascii_strcasecmp (line, "transferred") == 0) sei->transferred = atoi (arg); + else if (g_ascii_strcasecmp (line, "mtime") == 0) + sei->mtime = atoi (arg); else if (g_ascii_strcasecmp (line, "filename_ipod") == 0) sei->ipod_path = g_strdup (arg); else if (g_ascii_strcasecmp (line, "peak_signal") == 0) @@ -931,6 +935,8 @@ fprintf (fp, "md5_hash=%s\n", etr->md5_hash); if (etr->charset && *etr->charset) fprintf (fp, "charset=%s\n", etr->charset); + if (etr->mtime != 0) + fprintf (fp, "mtime=%ld\n", etr->mtime); if (!track->transferred && etr->oldsize) fprintf (fp, "oldsize=%d\n", etr->oldsize); if (etr->peak_signal_set) Index: fileselection.c =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/fileselection.c,v retrieving revision 1.4 diff -u -r1.4 fileselection.c --- fileselection.c 4 Dec 2005 10:24:38 -0000 1.4 +++ fileselection.c 2 Feb 2006 01:15:10 -0000 @@ -105,7 +105,7 @@ (gchar*)current->data, playlist, prefs_get_add_recursively(), - NULL, NULL); + NULL, NULL, 0); current = current->next; } @@ -460,7 +460,7 @@ Playlist *plitem = pm_get_selected_playlist (); add_directory_by_name (db_active_itdb, dir, plitem, prefs_get_add_recursively (), - NULL, NULL); + NULL, NULL, 0); prefs_set_last_dir_browse(dir); gtkpod_tracks_statusbar_update(); } Index: misc_playlist.c =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/misc_playlist.c,v retrieving revision 1.27 diff -u -r1.27 misc_playlist.c --- misc_playlist.c 23 Nov 2005 04:16:12 -0000 1.27 +++ misc_playlist.c 2 Feb 2006 01:15:13 -0000 @@ -1138,7 +1138,7 @@ { add_track_by_filename(itdb, fn_orphaned, pl_orphaned, - FALSE, NULL, NULL); + FALSE, NULL, NULL, 0); } g_free (fn_orphaned); g_free (num_str); Index: misc_track.c =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/misc_track.c,v retrieving revision 1.33 diff -u -r1.33 misc_track.c --- misc_track.c 10 Dec 2005 17:04:29 -0000 1.33 +++ misc_track.c 2 Feb 2006 01:15:14 -0000 @@ -1348,7 +1348,7 @@ } add_directory_by_name (itdb, decoded_file, pl, prefs_get_add_recursively (), - trackaddfunc, data); + trackaddfunc, data, 0); added = TRUE; } if (g_file_test (decoded_file, G_FILE_TEST_IS_REGULAR)) @@ -1373,7 +1373,7 @@ } add_track_by_filename (itdb, decoded_file, pl, prefs_get_add_recursively (), - trackaddfunc, data); + trackaddfunc, data, 0); added = TRUE; break; case FILE_TYPE_M3U: |