~dobey/ubuntu/natty/banshee/fix-and-amz

« back to all changes in this revision

Viewing changes to src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2011-01-24 22:17:31 UTC
  • mfrom: (6.3.14 experimental)
  • Revision ID: james.westby@ubuntu.com-20110124221731-qdqootsggfidrsjz
Tags: 1.9.2-1ubuntu1
* Merge from Debian Experimental, remaining changes:
  + Enable SoundMenu and Disable NotificationArea by default
  + Disable boo and karma extensions
  + Enable and recommnd u1ms and soundmenu extensions
  + Move desktop file for Meego UI to /usr/share/une/applications
* [0c8acd9] Enable u1ms by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
            SupportsVideo = Device.SupportsVideo;
93
93
 
94
94
            Initialize ();
95
 
            GPod.ITDB.InitIpod (Volume.MountPoint, Device.IpodInfo.ModelNumber, Name);
 
95
            GPod.ITDB.InitIpod (Volume.MountPoint, Device.IpodInfo == null ? null : Device.IpodInfo.ModelNumber, Name);
96
96
 
97
97
            // FIXME: Properly parse the device, color and generation and don't use the fallback strings
98
98
 
171
171
                try {
172
172
                    MediaDatabase = new GPod.ITDB (Device.Mountpoint);
173
173
                } catch (GLib.GException e) {
174
 
                    Log.Exception ("iPod database could be loaded, creating a new one", e);
 
174
                    Log.Exception ("iPod database could not be loaded, creating a new one", e);
175
175
                    if (GPod.ITDB.InitIpod (Volume.MountPoint, null, Volume.Name)) {
176
176
                        // this may throw again. In the future we need to implement some kind of alert
177
177
                        // mechanism to let the user know that something more serious is wrong with their
196
196
                });
197
197
            }
198
198
 
 
199
            var invalid_tracks = new List<GPod.Track> ();
199
200
            foreach (var ipod_track in MediaDatabase.Tracks) {
 
201
 
 
202
                if (String.IsNullOrEmpty (ipod_track.IpodPath)) {
 
203
                    invalid_tracks.Add (ipod_track);
 
204
                    continue;
 
205
                }
 
206
 
200
207
                try {
201
208
                    var track = new AppleDeviceTrackInfo (ipod_track);
202
209
                    if (!tracks_map.ContainsKey (track.TrackId)) {
208
215
                    Log.Exception (e);
209
216
                }
210
217
            }
 
218
            if (invalid_tracks.Count > 0) {
 
219
                Log.Warning (String.Format ("Found {0} invalid tracks on the device", invalid_tracks.Count));
 
220
                foreach (var track in invalid_tracks) {
 
221
                    DeleteTrack (track, false);
 
222
                }
 
223
            }
 
224
 
211
225
 
212
226
            Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
213
227
                @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
402
416
            }
403
417
        }
404
418
 
 
419
 
 
420
        private void DeleteTrack (GPod.Track track, bool removeFile)
 
421
        {
 
422
            foreach (var playlist in MediaDatabase.Playlists) {
 
423
                playlist.Tracks.Remove (track);
 
424
            }
 
425
 
 
426
            if (SupportsPodcasts && track.MediaType == GPod.MediaType.Podcast) {
 
427
                MediaDatabase.PodcastsPlaylist.Tracks.Remove (track);
 
428
            }
 
429
 
 
430
            MediaDatabase.MasterPlaylist.Tracks.Remove (track);
 
431
            MediaDatabase.Tracks.Remove (track);
 
432
 
 
433
            if (removeFile) {
 
434
                Banshee.IO.File.Delete (new SafeUri (GPod.ITDB.GetLocalPath (Device, track)));
 
435
            }
 
436
        }
 
437
 
405
438
        protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri)
406
439
        {
407
440
            lock (sync_mutex) {
569
602
                    if (track.IpodTrack != null) {
570
603
                        UpdateProgress (progressUpdater, message, total - tracks_to_remove.Count, total);
571
604
 
572
 
                        foreach (var playlist in MediaDatabase.Playlists) {
573
 
                            playlist.Tracks.Remove (track.IpodTrack);
574
 
                        }
575
 
 
576
 
                        if (SupportsPodcasts && track.IpodTrack.MediaType == GPod.MediaType.Podcast) {
577
 
                            MediaDatabase.PodcastsPlaylist.Tracks.Remove (track.IpodTrack);
578
 
                        }
579
 
 
580
 
                        MediaDatabase.MasterPlaylist.Tracks.Remove (track.IpodTrack);
581
 
                        MediaDatabase.Tracks.Remove (track.IpodTrack);
582
 
 
583
 
                        Banshee.IO.File.Delete (new SafeUri (GPod.ITDB.GetLocalPath (Device, track.IpodTrack)));
 
605
                        DeleteTrack (track.IpodTrack, true);
584
606
                    } else {
585
607
                        Log.Error ("The ipod track was null");
586
608
                    }