~ubuntu-branches/ubuntu/quantal/gtkpod-aac/quantal

« back to all changes in this revision

Viewing changes to src/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-07-17 18:25:25 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070717182525-rhl5w4pk8lbk6pna
Tags: 0.99.10-2ubuntu1
* Resynchronise with gtkpod 0.9.10-2.
* Hack in dpatch support, since it was removed.
* Rename debian/patches/03-configure.dpatch to
  debian/patches/aac-configure.dpatch.
* Update debian/gtkpod-aac.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Time-stamp: <2006-09-24 15:25:28 jcs>
2
 
|
 
1
/*
3
2
|  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
4
3
|  Part of the gtkpod project.
5
4
24
23
|
25
24
|  This product is not supported/written/published by Apple!
26
25
|
27
 
|  $Id: file.c,v 1.188 2006/09/24 06:42:52 jcsjcs Exp $
 
26
|  $Id: file.c 1596 2007-06-26 14:33:01Z dforsi $
28
27
*/
29
28
 
30
29
#ifdef HAVE_CONFIG_H
45
44
#include "confirmation.h"
46
45
#include "info.h"
47
46
#include "file.h"
 
47
#include "file_convert.h"
48
48
#include "itdb.h"
49
 
#include "md5.h"
 
49
#include "sha1.h"
50
50
#include "misc.h"
51
51
#include "misc_track.h"
52
52
#include "mp3file.h"
53
53
#include "mp4file.h"
54
54
#include "prefs.h"
55
55
#include "wavfile.h"
56
 
 
57
 
 
 
56
#include "oggfile.h"
 
57
#include "flacfile.h"
 
58
 
 
59
/* The uppercase version of these extensions is tried as well. */
58
60
static const gchar *imageext[] =
59
61
{".jpg", ".jpeg", ".png", ".pbm", ".pgm", ".ppm", ".tif", ".tiff",
60
62
 ".gif", NULL};
95
97
    case FILE_TYPE_PLS:
96
98
    case FILE_TYPE_IMAGE:
97
99
    case FILE_TYPE_DIRECTORY:
 
100
    case FILE_TYPE_OGG:
 
101
    case FILE_TYPE_FLAC:
98
102
        g_free (track);
99
103
        g_return_val_if_reached (NULL);
100
104
    }
110
114
 * -jlt
111
115
 */
112
116
 
113
 
FileType determine_file_type (gchar *path)
 
117
FileType determine_file_type (const gchar *path)
114
118
{
115
119
    gchar *path_utf8, *suf;
116
120
    FileType type = FILE_TYPE_UNKNOWN;
138
142
 
139
143
        else if (g_strcasecmp (suf, ".m3u") == 0) type = FILE_TYPE_M3U;
140
144
        else if (g_strcasecmp (suf, ".pls") == 0) type = FILE_TYPE_PLS;
 
145
        else if (g_strcasecmp (suf, ".ogg") == 0) type = FILE_TYPE_OGG;
 
146
        else if (g_strcasecmp (suf, ".flac") == 0) type = FILE_TYPE_FLAC;
141
147
 
142
148
        else
143
149
        {
253
259
        case FILE_TYPE_MP4:
254
260
        case FILE_TYPE_MOV:
255
261
        case FILE_TYPE_MPG:
 
262
        case FILE_TYPE_OGG:
 
263
        case FILE_TYPE_FLAC:
256
264
        case FILE_TYPE_IMAGE:
257
265
        case FILE_TYPE_DIRECTORY:
258
266
            gtkpod_warning (_("'%s' is a not a known playlist file.\n\n"),
348
356
        case FILE_TYPE_MP4:
349
357
        case FILE_TYPE_MOV:
350
358
        case FILE_TYPE_MPG:
 
359
        case FILE_TYPE_OGG:
 
360
        case FILE_TYPE_FLAC:
351
361
        case FILE_TYPE_IMAGE:
352
362
            break;
353
363
        }
769
779
 
770
780
 
771
781
/* Copy "new" info read from file to an old Track structure. */
772
 
static void copy_new_info (Track *from, Track *to)
 
782
/* Return value: TRUE: at least one item was changed. FALSE: track was
 
783
   unchanged */
 
784
static gboolean copy_new_info (Track *from, Track *to)
773
785
{
774
786
    ExtraTrackData *efrom, *eto;
 
787
    T_item item;
 
788
    gboolean changed = FALSE;
775
789
 
776
 
    g_return_if_fail (from);
777
 
    g_return_if_fail (to);
 
790
    g_return_val_if_fail (from, FALSE);
 
791
    g_return_val_if_fail (to, FALSE);
778
792
    efrom = from->userdata;
779
793
    eto = to->userdata;
780
 
    g_return_if_fail (efrom);
781
 
    g_return_if_fail (eto);
782
 
 
783
 
    g_free (to->title);
784
 
    to->title = g_strdup (from->title);
785
 
 
786
 
    g_free (to->artist);
787
 
    to->artist = g_strdup (from->artist);
788
 
 
789
 
    g_free (to->album);
790
 
    to->album = g_strdup (from->album);
791
 
 
792
 
    g_free (to->genre);
793
 
    to->genre = g_strdup (from->genre);
794
 
 
795
 
    g_free (to->composer);
796
 
    to->composer = g_strdup (from->composer);
797
 
 
798
 
    g_free (to->comment);
799
 
    to->comment = g_strdup (from->comment);
800
 
 
801
 
    g_free (to->filetype);
802
 
    to->filetype = g_strdup (from->filetype);
803
 
 
804
 
    g_free (to->description);
805
 
    to->description = g_strdup (from->description);
806
 
 
807
 
    g_free (to->podcasturl);
808
 
    to->podcasturl = g_strdup (from->podcasturl);
809
 
 
810
 
    g_free (to->podcastrss);
811
 
    to->podcastrss = g_strdup (from->podcastrss);
812
 
 
813
 
    g_free (to->subtitle);
814
 
    to->subtitle = g_strdup (from->subtitle);
815
 
 
816
 
    g_free (eto->thumb_path_utf8);
817
 
    eto->thumb_path_utf8 = g_strdup (efrom->thumb_path_utf8);
818
 
 
819
 
    g_free (eto->thumb_path_locale);
820
 
    eto->thumb_path_locale = g_strdup (efrom->thumb_path_locale);
821
 
 
822
 
    g_free (eto->pc_path_utf8);
823
 
    eto->pc_path_utf8 = g_strdup (efrom->pc_path_utf8);
824
 
 
825
 
    g_free (eto->pc_path_locale);
826
 
    eto->pc_path_locale = g_strdup (efrom->pc_path_locale);
827
 
 
828
 
    g_free (eto->charset);
829
 
    eto->charset = g_strdup (efrom->charset);
830
 
 
831
 
    g_free (eto->year_str);
832
 
    eto->year_str = g_strdup_printf ("%d", to->year);
 
794
    g_return_val_if_fail (efrom, FALSE);
 
795
    g_return_val_if_fail (eto, FALSE);
 
796
 
 
797
    for (item=0; item<T_ITEM_NUM; ++item)
 
798
    {
 
799
        switch (item)
 
800
        {
 
801
        case T_ALBUM:
 
802
        case T_ARTIST:
 
803
        case T_TITLE:
 
804
        case T_GENRE:
 
805
        case T_COMMENT:
 
806
        case T_COMPOSER:
 
807
        case T_FILETYPE:
 
808
        case T_DESCRIPTION:
 
809
        case T_PODCASTURL:
 
810
        case T_PODCASTRSS:
 
811
        case T_SUBTITLE:
 
812
        case T_TV_SHOW:
 
813
        case T_TV_EPISODE:
 
814
        case T_TV_NETWORK:
 
815
        case T_THUMB_PATH:
 
816
        case T_PC_PATH:
 
817
        case T_ALBUMARTIST:
 
818
        case T_SORT_ARTIST:
 
819
        case T_SORT_TITLE:
 
820
        case T_SORT_ALBUM:
 
821
        case T_SORT_ALBUMARTIST:
 
822
        case T_SORT_COMPOSER:
 
823
        case T_SORT_TVSHOW:
 
824
        case T_YEAR:
 
825
        case T_TRACK_NR:
 
826
        case T_SIZE:
 
827
        case T_TRACKLEN:
 
828
        case T_STARTTIME:
 
829
        case T_STOPTIME:
 
830
        case T_BITRATE:
 
831
        case T_SAMPLERATE:
 
832
        case T_BPM:
 
833
        case T_TIME_ADDED:
 
834
        case T_TIME_MODIFIED:
 
835
        case T_TIME_RELEASED:
 
836
        case T_SOUNDCHECK:
 
837
        case T_CD_NR:
 
838
        case T_COMPILATION:
 
839
        case T_MEDIA_TYPE:
 
840
        case T_SEASON_NR:
 
841
        case T_EPISODE_NR:
 
842
        case T_GROUPING:
 
843
            changed |= track_copy_item (from, to, item);
 
844
            break;
 
845
        case T_CATEGORY:
 
846
            /* not implemented from tags */
 
847
            break;
 
848
        case T_RATING:
 
849
        case T_REMEMBER_PLAYBACK_POSITION:
 
850
        case T_SKIP_WHEN_SHUFFLING:
 
851
        case T_CHECKED:
 
852
        case T_TIME_PLAYED:
 
853
        case T_IPOD_PATH:
 
854
        case T_ALL:
 
855
        case T_IPOD_ID:
 
856
        case T_TRANSFERRED:
 
857
        case T_PLAYCOUNT:
 
858
        case T_VOLUME:
 
859
            /* not applicable */
 
860
            break;
 
861
        case T_ITEM_NUM:
 
862
            g_return_val_if_reached (FALSE);
 
863
        }
 
864
    }
 
865
 
 
866
    if ((eto->charset == NULL) || (strcmp (efrom->charset, eto->charset) != 0))
 
867
    {
 
868
        g_free (eto->charset);
 
869
        eto->charset = g_strdup (efrom->charset);
 
870
        changed = TRUE;
 
871
    }
833
872
 
834
873
    itdb_artwork_free (to->artwork);
835
874
    to->artwork = itdb_artwork_duplicate (from->artwork);
836
 
    to->artwork_size = from->artwork_size;
837
 
    to->artwork_count = from->artwork_count;
838
 
    to->has_artwork = from->has_artwork;
839
 
 
840
 
    to->size = from->size;
841
 
    to->tracklen = from->tracklen;
842
 
    to->cd_nr = from->cd_nr;
843
 
    to->cds = from->cds;
844
 
    to->track_nr = from->track_nr;
845
 
    to->tracks = from->tracks;
846
 
    to->bitrate = from->bitrate;
847
 
    to->samplerate = from->samplerate;
848
 
    to->soundcheck = from->soundcheck;
849
 
    eto->mtime = efrom->mtime;
850
 
    to->time_added = from->time_added;
851
 
    to->time_modified = from->time_modified;
852
 
    to->year = from->year;
853
 
    to->compilation = from->compilation;
854
 
    to->unk208 = from->unk208;
855
 
    to->lyrics_flag = from->lyrics_flag;
856
 
    to->movie_flag = from->movie_flag;
 
875
    if ((to->artwork_size != from->artwork_size) ||
 
876
        (to->artwork_count != from->artwork_count) ||
 
877
        (to->has_artwork != from->has_artwork))
 
878
    {   /* FIXME -- artwork might have changed nevertheless */
 
879
        changed = TRUE;
 
880
        to->artwork_size = from->artwork_size;
 
881
        to->artwork_count = from->artwork_count;
 
882
        to->has_artwork = from->has_artwork;
 
883
    }
 
884
 
 
885
    if ((to->lyrics_flag != from->lyrics_flag) ||
 
886
        (to->movie_flag != from->movie_flag))
 
887
    {
 
888
        changed = TRUE;
 
889
        to->lyrics_flag = from->lyrics_flag;
 
890
        to->movie_flag = from->movie_flag;
 
891
    }
 
892
 
 
893
    if ((to->pregap != from->pregap) ||
 
894
        (to->postgap != from->postgap) ||
 
895
        (to->samplecount != from->samplecount) ||
 
896
        (to->gapless_data != from->gapless_data) ||
 
897
        (to->gapless_track_flag != from->gapless_track_flag))
 
898
    {
 
899
        changed = TRUE;
 
900
        to->pregap = from->pregap;
 
901
        to->postgap = from->postgap;
 
902
        to->samplecount = from->samplecount;
 
903
        to->gapless_data = from->gapless_data;
 
904
        to->gapless_track_flag = from->gapless_track_flag;
 
905
    }
 
906
 
 
907
    return changed;
857
908
}
858
909
 
859
910
/* Updates mserv data (rating only) of @track using filename @name to
982
1033
    while (*tplp && !filename_local)
983
1034
    {
984
1035
        gchar *filename_utf8;
985
 
        gchar *fname = get_string_from_template (tr, *tplp, FALSE);
 
1036
        gchar *fname = get_string_from_template (tr, *tplp, FALSE, FALSE);
986
1037
        if (fname)
987
1038
        {
988
1039
            if (strchr (*tplp, '.') != NULL)
1001
1052
                const gchar **extp = imageext;
1002
1053
                while (*extp && !filename_local)
1003
1054
                {
1004
 
                    gchar *ffname;
1005
 
                    ffname = g_strconcat (fname, *extp, NULL);
 
1055
                    gchar *ffname = g_strconcat (fname, *extp, NULL);
 
1056
                    filename_utf8 = g_build_filename (dirname, ffname, NULL);
 
1057
                    g_free (ffname);
 
1058
                    filename_local = charset_from_utf8 (filename_utf8);
 
1059
                    g_free (filename_utf8);
 
1060
                    if (!g_file_test (filename_local, G_FILE_TEST_EXISTS))
 
1061
                    {
 
1062
                        g_free (filename_local);
 
1063
                        filename_local = NULL;
 
1064
                    }
 
1065
                    ++extp;
 
1066
                }
 
1067
                extp = imageext;
 
1068
                while (*extp && !filename_local)
 
1069
                {   /* try uppercase version of extension */
 
1070
                    gchar *upper_ext = g_ascii_strup (*extp, -1);
 
1071
                    gchar *ffname = g_strconcat (fname, upper_ext, NULL);
 
1072
                    g_free (upper_ext);
1006
1073
                    filename_utf8 = g_build_filename (dirname, ffname, NULL);
1007
1074
                    g_free (ffname);
1008
1075
                    filename_local = charset_from_utf8 (filename_utf8);
1069
1136
    {
1070
1137
    case FILE_TYPE_MP3:
1071
1138
        nti = mp3_get_file_info (name);
1072
 
        /* Set unk208 to audio */
1073
 
        if (nti) nti->unk208 = 0x00000001;
 
1139
        /* Set mediatype to audio */
 
1140
        if (nti) nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1074
1141
        break;
1075
1142
    case FILE_TYPE_M4A:
1076
1143
    case FILE_TYPE_M4P:
 
1144
        nti = mp4_get_file_info (name);
 
1145
        /* Set mediatype to audio */
 
1146
        if (nti)
 
1147
        {
 
1148
            nti->mediatype = ITDB_MEDIATYPE_AUDIO;
 
1149
        }
 
1150
        break;
1077
1151
    case FILE_TYPE_M4B:
1078
1152
        nti = mp4_get_file_info (name);
1079
 
        /* Set unk208 to audio */
 
1153
        /* Set mediatype to audiobook */
1080
1154
        if (nti)
1081
1155
        {
1082
 
            nti->unk208 = 0x00000001;
 
1156
            nti->mediatype = ITDB_MEDIATYPE_AUDIOBOOK;
1083
1157
        }
1084
1158
        break;
1085
1159
    case FILE_TYPE_WAV:
1086
1160
        nti = wav_get_file_info (name);
1087
 
        /* Set unk208 to audio */
 
1161
        /* Set mediatype to audio */
1088
1162
        if (nti)
1089
1163
        {
1090
 
            nti->unk208 = 0x00000001;
 
1164
            nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1091
1165
        }
1092
1166
        break;
 
1167
    case FILE_TYPE_OGG:
 
1168
        nti = ogg_get_file_info (name);
 
1169
        /* Set mediatype to audio */
 
1170
        if (nti)
 
1171
        {
 
1172
            nti->mediatype = ITDB_MEDIATYPE_AUDIO;
 
1173
        }
 
1174
        break;
 
1175
    case FILE_TYPE_FLAC:
 
1176
        nti = flac_get_file_info (name);
 
1177
        /* Set mediatype to audio */
 
1178
        if (nti)
 
1179
        {
 
1180
            nti->mediatype = ITDB_MEDIATYPE_AUDIO;
 
1181
        }
 
1182
        break;
1093
1183
    case FILE_TYPE_M4V:
1094
1184
    case FILE_TYPE_MP4:
1095
1185
        /* I don't know if .m4v and .mp4 can simply be handled like
1096
1186
           this. Let's see if someone complains. */
1097
1187
        nti = mp4_get_file_info (name);
1098
1188
        if (!nti) video_get_file_info (name);
1099
 
        /* Set unk208 to video */
 
1189
        /* Set mediatype to video */
1100
1190
        if (nti)
1101
1191
        {
1102
 
            nti->unk208 = 0x00000002;
 
1192
            nti->mediatype = ITDB_MEDIATYPE_MOVIE;
1103
1193
            nti->movie_flag = 0x01;
1104
1194
        }       
1105
1195
        break;
1107
1197
    case FILE_TYPE_MPG:
1108
1198
        /* for now treat all the same */
1109
1199
        nti = video_get_file_info (name);
1110
 
        /* Set unk208 to video */
 
1200
        /* Set mediatype to video */
1111
1201
        if (nti)
1112
1202
        {
1113
 
            nti->unk208 = 0x00000002;
 
1203
            nti->mediatype = ITDB_MEDIATYPE_MOVIE;
1114
1204
            nti->movie_flag = 0x01;
1115
1205
        }
1116
1206
        break;
1163
1253
        }
1164
1254
 
1165
1255
        /* Set modification date to the files modified date */
1166
 
        nti->time_modified = itdb_time_host_to_mac(enti->mtime);
1167
 
        /* Set added date to *now* */
1168
 
        nti->time_added = itdb_time_get_mac_time ();
 
1256
        nti->time_modified = enti->mtime;
 
1257
        /* Set added date to *now* (unless orig_track is present) */
 
1258
        if (orig_track)
 
1259
        {
 
1260
            nti->time_added = orig_track->time_added;
 
1261
        }
 
1262
        else
 
1263
        {
 
1264
            nti->time_added = time (NULL);
 
1265
        }
1169
1266
 
1170
1267
        /* Make sure all strings are initialized -- that way we don't
1171
1268
           have to worry about it when we are handling the
1172
1269
           strings. Also, validate_entries() will fill in the utf16
1173
1270
           strings if that hasn't already been done. */
1174
 
        /* exception: md5_hash, charset and hostname: these may be
 
1271
        /* exception: sha1_hash, charset and hostname: these may be
1175
1272
         * NULL. */
1176
1273
 
1177
1274
        gp_track_validate_entries (nti);
1179
1276
        if (orig_track)
1180
1277
        { /* we need to copy all information over to the original
1181
1278
           * track */
1182
 
            guint32 time_added = orig_track->time_added;
1183
 
 
1184
 
            copy_new_info (nti, orig_track);
1185
 
 
1186
 
            /* restore time_added */
1187
 
            if (time_added != 0)
1188
 
                orig_track->time_added = time_added;
 
1279
            ExtraTrackData *eorigtr=orig_track->userdata;
 
1280
 
 
1281
            g_return_val_if_fail (eorigtr, NULL);
 
1282
 
 
1283
            eorigtr->tchanged = copy_new_info (nti, orig_track);
1189
1284
 
1190
1285
            track = orig_track;
1191
1286
            itdb_track_free (nti);
1529
1624
   "gp_duplicate_remove (NULL, (void *)-1)"*/
1530
1625
void update_track_from_file (iTunesDB *itdb, Track *track)
1531
1626
{
1532
 
    ExtraTrackData *etr;
 
1627
    ExtraTrackData *oetr;
1533
1628
    Track *oldtrack;
1534
1629
    gchar *prefs_charset = NULL;
1535
1630
    gchar *trackpath = NULL;
1538
1633
 
1539
1634
    g_return_if_fail (itdb);
1540
1635
    g_return_if_fail (track);
1541
 
    etr = track->userdata;
1542
 
    g_return_if_fail (etr);
 
1636
    oetr = track->userdata;
 
1637
    g_return_if_fail (oetr);
1543
1638
    /* remember size of track on iPod */
1544
1639
    if (track->transferred) oldsize = track->size;
1545
1640
    else                    oldsize = 0;
1546
1641
 
1547
1642
    /* remember if charset was set */
1548
 
    if (etr->charset)  charset_set = TRUE;
 
1643
    if (oetr->charset)  charset_set = TRUE;
1549
1644
    else               charset_set = FALSE;
1550
1645
 
1551
1646
    if (!prefs_get_int("update_charset") && charset_set)
1552
1647
    {   /* we should use the initial charset for the update */
1553
1648
        prefs_charset = prefs_get_string("charset");
1554
1649
        /* use the charset used when first importing the track */
1555
 
        prefs_set_string("charset", etr->charset);
 
1650
        prefs_set_string("charset", oetr->charset);
1556
1651
    }
1557
1652
 
1558
1653
    trackpath = get_file_name_from_source (track, SOURCE_PREFER_LOCAL);
1559
1654
 
1560
1655
    
1561
 
    if (!(etr->pc_path_locale && *etr->pc_path_locale))
 
1656
    if (!(oetr->pc_path_locale && *oetr->pc_path_locale))
1562
1657
    { /* no path available */
1563
1658
        if (trackpath)
1564
1659
        {
1576
1671
            }
1577
1672
        }
1578
1673
    }
1579
 
    else if (!g_file_test (etr->pc_path_locale, G_FILE_TEST_EXISTS))
 
1674
    else if (!g_file_test (oetr->pc_path_locale, G_FILE_TEST_EXISTS))
1580
1675
    {
1581
1676
        if (trackpath)
1582
1677
        {
1596
1691
    }
1597
1692
 
1598
1693
    if (trackpath && get_track_info_from_file (trackpath, track))
1599
 
    { /* update successfull */
1600
 
        /* remove track from md5 hash and reinsert it
 
1694
    { /* update successful */
 
1695
        ExtraTrackData *netr = track->userdata;
 
1696
 
 
1697
        /* remove track from sha1 hash and reinsert it
1601
1698
           (hash value may have changed!) */
1602
 
        gchar *name_on_ipod;
1603
 
        gchar *oldhash = etr->md5_hash;
 
1699
        gchar *oldhash = oetr->sha1_hash;
1604
1700
 
1605
 
        md5_track_remove (track);
 
1701
        sha1_track_remove (track);
1606
1702
        /* need to remove the old value manually! */
1607
 
        etr->md5_hash = NULL;
1608
 
        oldtrack = md5_track_exists_insert (itdb, track);
 
1703
        oetr->sha1_hash = NULL;
 
1704
        oldtrack = sha1_track_exists_insert (itdb, track);
1609
1705
        if (oldtrack) { /* track exists, remove old track
1610
1706
                          and register the new version */
1611
 
            md5_track_remove (oldtrack);
 
1707
            sha1_track_remove (oldtrack);
1612
1708
            gp_duplicate_remove (track, oldtrack);
1613
 
            md5_track_exists_insert (itdb, track);
 
1709
            sha1_track_exists_insert (itdb, track);
1614
1710
        }
1615
 
        /* track may have to be copied to iPod on next export */
1616
 
        /* since it will copied under the same name as before, we
1617
 
           don't have to manually remove it */
1618
 
        name_on_ipod = get_file_name_from_source (track, SOURCE_IPOD);
1619
 
        if (name_on_ipod && (strcmp (name_on_ipod, trackpath) != 0))
1620
 
        {   /* trackpath is not on the iPod */
1621
 
            if (oldhash && etr->md5_hash)
1622
 
            {   /* do we really have to copy the track again? */
1623
 
                if (strcmp (oldhash, etr->md5_hash) != 0)
1624
 
                {
1625
 
                    track->transferred = FALSE;
1626
 
                    data_changed (itdb);
 
1711
 
 
1712
        if (itdb->usertype & GP_ITDB_TYPE_IPOD)
 
1713
        {   /* track may have to be copied to iPod on next export */
 
1714
            gchar *name_on_ipod;
 
1715
            gboolean transfer_again = FALSE;
 
1716
 
 
1717
            name_on_ipod = get_file_name_from_source (track, SOURCE_IPOD);
 
1718
            if (name_on_ipod && (strcmp (name_on_ipod, trackpath) != 0))
 
1719
            {   /* trackpath is not on the iPod */
 
1720
                if (oldhash && oetr->sha1_hash)
 
1721
                {   /* do we really have to copy the track again? */
 
1722
                    if (strcmp (oldhash, oetr->sha1_hash) != 0)
 
1723
                    {
 
1724
                        transfer_again = TRUE;
 
1725
                    }
 
1726
                }
 
1727
                else
 
1728
                {   /* no hash available -- copy! */
 
1729
                    transfer_again = TRUE;
1627
1730
                }
1628
1731
            }
1629
1732
            else
1630
 
            {   /* no hash available -- copy! */
 
1733
            {
 
1734
                data_changed (itdb);
 
1735
            }
 
1736
 
 
1737
            if (transfer_again)
 
1738
            {   /* We need to copy the track back to the iPod. That's done
 
1739
                   marking a copy of the original track for deletion and
 
1740
                   then adding the original track to the
 
1741
                   conversion/transfer list */
 
1742
                Track *new_track = gp_track_new ();
 
1743
                ExtraTrackData *new_etr = new_track->userdata;
 
1744
                g_return_if_fail (new_etr);
 
1745
 
 
1746
                new_track->size = oldsize;
 
1747
                new_track->ipod_path = track->ipod_path;
 
1748
                track->ipod_path = g_strdup ("");
1631
1749
                track->transferred = FALSE;
1632
 
                data_changed (itdb);
 
1750
 
 
1751
                /* cancel conversion/transfer of track */
 
1752
                file_convert_cancel_track (track);
 
1753
                /* mark the track for deletion on the ipod */
 
1754
                mark_track_for_deletion (itdb, new_track);
 
1755
                /* reschedule conversion/transfer of track */
 
1756
                file_convert_add_track (track);
 
1757
 
 
1758
                netr->tchanged = TRUE;
1633
1759
            }
 
1760
 
 
1761
            g_free (name_on_ipod);
1634
1762
        }
1635
 
        else
 
1763
 
 
1764
        /* notify display model */
 
1765
        if (netr->tchanged)
1636
1766
        {
 
1767
            pm_track_changed (track);
1637
1768
            data_changed (itdb);
 
1769
            netr->tchanged = FALSE;
1638
1770
        }
1639
 
        g_free (name_on_ipod);
1640
 
        
1641
 
        /* set old size if track has to be transferred (for free space
1642
 
         * calculation) */
1643
 
        if (!track->transferred) etr->oldsize = oldsize;
1644
 
        /* notify display model */
1645
 
        pm_track_changed (track);
1646
1771
        display_updated (track, NULL);
1647
1772
        g_free (oldhash);
1648
1773
    }
1649
1774
    else if (trackpath)
1650
1775
    { /* update not successful -- log this track for later display */
1651
 
        display_non_updated (track, _("update failed (format no supported?)"));
 
1776
        display_non_updated (track, _("update failed (format not supported?)"));
1652
1777
    }
1653
1778
 
1654
1779
    if (!prefs_get_int("update_charset") && charset_set)
1680
1805
   position in the track view */
1681
1806
gboolean add_track_by_filename (iTunesDB *itdb, gchar *fname,
1682
1807
                                Playlist *plitem, gboolean descend,
1683
 
                               AddTrackFunc addtrackfunc, gpointer data)
 
1808
                                AddTrackFunc addtrackfunc, gpointer data)
1684
1809
{
1685
1810
  static gint count = 0; /* do a gtkpod_tracks_statusbar_update() every
1686
1811
                            10 tracks */
1720
1845
  case FILE_TYPE_MP4:
1721
1846
  case FILE_TYPE_MOV:
1722
1847
  case FILE_TYPE_MPG:
 
1848
  case FILE_TYPE_OGG:
 
1849
  case FILE_TYPE_FLAC:
1723
1850
  case FILE_TYPE_IMAGE:
1724
1851
  case FILE_TYPE_UNKNOWN:
1725
1852
  case FILE_TYPE_DIRECTORY:
1737
1864
 
1738
1865
      if (excludefile(basename))
1739
1866
      {
1740
 
          gtkpod_warning (_("File skipped. match exclude masks: '%s'\n"), basename);
 
1867
          gtkpod_warning (_("Skipping '%s' because it matches exclude masks.\n"), basename);
1741
1868
          while (widgets_blocked && gtk_events_pending ())
1742
1869
              gtk_main_iteration ();
1743
1870
          g_free (basename);
1815
1942
              etr->hostname = g_strdup (str);
1816
1943
          }
1817
1944
          /* add_track may return pointer to a different track if an
1818
 
             identical one (MD5 checksum) was found */
 
1945
             identical one (SHA1 checksum) was found */
1819
1946
          added_track = gp_track_add (itdb, track);
1820
1947
          g_return_val_if_fail (added_track, FALSE);
1821
1948
 
1835
1962
              }
1836
1963
          }
1837
1964
          else
1838
 
          {   /* add track to master playlist if it wasn't a
 
1965
          {
 
1966
#if 0 /* initially iTunes didn't add podcasts to the MPL */
 
1967
              /* add track to master playlist if it wasn't a
1839
1968
               * duplicate and plitem is not the podcasts playlist
1840
1969
               */
1841
1970
              if (added_track == track)
1843
1972
                  if (!itdb_playlist_is_podcasts (plitem))
1844
1973
                      gp_playlist_add_track (mpl, added_track, TRUE);
1845
1974
              }
 
1975
#else
 
1976
              if (added_track == track)
 
1977
              {
 
1978
                  gp_playlist_add_track (mpl, added_track, TRUE);
 
1979
              }
 
1980
#endif
1846
1981
              /* add track to specified playlist -- unless adding
1847
1982
               * to podcasts list and track already exists there */
1848
1983
              if (itdb_playlist_is_podcasts (plitem) &&
1905
2040
        return mp4_write_file_info (name, track);
1906
2041
    case FILE_TYPE_WAV:
1907
2042
        return wav_write_file_info (name, track);
 
2043
    case FILE_TYPE_OGG:
 
2044
        return ogg_write_file_info (name, track);
 
2045
    case FILE_TYPE_FLAC:
 
2046
        return flac_write_file_info (name, track);
1908
2047
    case FILE_TYPE_M4V:
1909
2048
    case FILE_TYPE_MP4:
1910
2049
    case FILE_TYPE_MOV:
1981
2120
        }
1982
2121
        g_free (ipod_fullpath);
1983
2122
    }
1984
 
    /* remove track from md5 hash and reinsert it (hash value has changed!) */
1985
 
    md5_track_remove (track);
1986
 
    C_FREE (etr->md5_hash);  /* need to remove the old value manually! */
1987
 
    oldtrack = md5_track_exists_insert (itdb, track);
 
2123
    /* remove track from sha1 hash and reinsert it (hash value has changed!) */
 
2124
    sha1_track_remove (track);
 
2125
    C_FREE (etr->sha1_hash);  /* need to remove the old value manually! */
 
2126
    oldtrack = sha1_track_exists_insert (itdb, track);
1988
2127
    if (oldtrack) { /* track exists, remove and register the new version */
1989
 
        md5_track_remove (oldtrack);
 
2128
        sha1_track_remove (oldtrack);
1990
2129
        gp_duplicate_remove (track, oldtrack);
1991
 
        md5_track_exists_insert (itdb, track);
 
2130
        sha1_track_exists_insert (itdb, track);
1992
2131
    }
1993
2132
 
1994
2133
    if (!prefs_get_int("write_charset") && track_charset_set)
2016
2155
    case SOURCE_PREFER_LOCAL:
2017
2156
        result = get_file_name_from_source (track, SOURCE_LOCAL);
2018
2157
        if (!result)
2019
 
            result = get_file_name_from_source (track, SOURCE_IPOD);
 
2158
        {
 
2159
            if (track->itdb && (track->itdb->usertype & GP_ITDB_TYPE_IPOD))
 
2160
            {
 
2161
                result = get_file_name_from_source (track, SOURCE_IPOD);
 
2162
            }
 
2163
        }
2020
2164
        break;
2021
2165
    case SOURCE_PREFER_IPOD:
2022
2166
        result = get_file_name_from_source (track, SOURCE_IPOD);
2054
2198
   ------------------------------------------------------------ */
2055
2199
 
2056
2200
/* Read the ~/.gtkpod/offline_playcount file and adjust the
2057
 
   playcounts. The tracks will first be matched by their md5 sum, if
 
2201
   playcounts. The tracks will first be matched by their sha1 sum, if
2058
2202
   that fails, by their filename.
2059
2203
   If tracks could not be matched, the user will be queried whether to
2060
2204
   forget about them or write them back into the offline_playcount
2091
2235
        while (fgets (buf, 2*PATH_MAX, file))
2092
2236
        {
2093
2237
            gchar *buf_utf8 = charset_to_utf8 (buf);
2094
 
            gchar *md5=NULL;
 
2238
            gchar *sha1=NULL;
2095
2239
            gchar *filename=NULL;
2096
2240
            gchar *ptr1, *ptr2;
2097
2241
            /* skip strings that do not start with "PLCT:" */
2100
2244
                gtkpod_warning (_("Malformed line in '%s': %s\n"), offlplyc, buf);
2101
2245
                goto cont;
2102
2246
            }
2103
 
            /* start of MD5 string */
 
2247
            /* start of SHA1 string */
2104
2248
            ptr1 = buf + strlen (SOCKET_PLYC);
2105
 
            /* end of MD5 string */
 
2249
            /* end of SHA1 string */
2106
2250
            ptr2 = strchr (ptr1, ' ');
2107
2251
            if (ptr2 == NULL)
2108
2252
            {   /* error! */
2110
2254
                                offlplyc, buf_utf8);
2111
2255
                goto cont;
2112
2256
            }
2113
 
            if (ptr1 != ptr2)    md5 = g_strndup (ptr1, ptr2-ptr1);
 
2257
            if (ptr1 != ptr2)    sha1 = g_strndup (ptr1, ptr2-ptr1);
2114
2258
            /* start of filename */
2115
2259
            ptr1 = ptr2 + 1;
2116
2260
            /* end of filename string */
2131
2275
                                offlplyc, buf_utf8);
2132
2276
                goto cont;
2133
2277
            }
2134
 
            if (gp_increase_playcount (md5, filename, 1) == FALSE)
 
2278
            if (gp_increase_playcount (sha1, filename, 1) == FALSE)
2135
2279
            {   /* didn't find the track -> store */
2136
2280
                gchar *filename_utf8 = charset_to_utf8 (filename);
2137
2281
/*              if (gstr->len == 0) */
2145
2289
            }
2146
2290
          cont:
2147
2291
            g_free (buf_utf8);
2148
 
            g_free (md5);
 
2292
            g_free (sha1);
2149
2293
            g_free (filename);
2150
2294
        }
2151
2295
 
2221
2365
        case FILE_TYPE_M4B:
2222
2366
            result = mp4_read_soundcheck (path, track);
2223
2367
            break;
 
2368
        case FILE_TYPE_OGG: /* FIXME */
 
2369
        case FILE_TYPE_FLAC: /* FIXME */
2224
2370
        case FILE_TYPE_WAV: /* FIXME */
2225
2371
        case FILE_TYPE_M4V:
2226
2372
        case FILE_TYPE_MP4: