~ubuntu-branches/ubuntu/raring/banshee/raring

« back to all changes in this revision

Viewing changes to src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2012-01-23 23:16:49 UTC
  • mfrom: (6.3.22 experimental)
  • Revision ID: package-import@ubuntu.com-20120123231649-safm1f8eycltcgsf
Tags: 2.3.4.ds-1ubuntu1
* Merge from Debian Experimental, remaining changes:
  + Enable and recommend SoundMenu and Disable NotificationArea by default
  + Disable boo and karma extensions
  + Enable and suggest u1ms
  + Move desktop file for Meego UI to /usr/share/une/applications
  + Change the url for the Amazon store redirector
  + [08dea2c] Revert "Fix invalid cast causing ftbfs with libgpod"
* [b617fe0] Convert Ubuntu-specific patches to gbp-pq patches
* Also fixes Launchpad bugs:
  - Fixes race condition while starting (LP: #766303)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
using Banshee.Base;
39
39
using Banshee.ServiceStack;
40
40
using Banshee.Library;
 
41
using Banshee.Query;
41
42
using Banshee.Sources;
42
43
using Banshee.Collection;
43
44
using Banshee.Collection.Database;
164
165
            if (CanSyncPlaylists) {
165
166
                var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
166
167
                    "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
167
 
                int [] psources = new int [] {DbId};
168
168
                foreach (string playlist_path in PlaylistFiles) {
169
169
                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load (playlist_path, new Uri (PlaylistsPath));
170
170
                    if (loaded_playlist == null)
176
176
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
177
177
                    foreach (Dictionary<string, object> element in loaded_playlist.Elements) {
178
178
                        string track_path = (element["uri"] as Uri).LocalPath;
179
 
                        int track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), psources);
 
179
                        int track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), DbId);
180
180
                        if (track_id == 0) {
181
181
                            Log.DebugFormat ("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
182
182
                        } else {
485
485
            set { cover_art_file_type = value; }
486
486
        }
487
487
 
 
488
        public override void UpdateMetadata (DatabaseTrackInfo track)
 
489
        {
 
490
            SafeUri new_uri = new SafeUri (GetTrackPath (track, System.IO.Path.GetExtension (track.Uri)));
 
491
 
 
492
            if (new_uri.ToString () != track.Uri.ToString ()) {
 
493
                Directory.Create (System.IO.Path.GetDirectoryName (new_uri.LocalPath));
 
494
                Banshee.IO.File.Move (track.Uri, new_uri);
 
495
 
 
496
                //to remove the folder if it's not needed anymore:
 
497
                DeleteTrackFile (track);
 
498
 
 
499
                track.Uri = new_uri;
 
500
                track.Save (true, BansheeQuery.UriField);
 
501
            }
 
502
 
 
503
            base.UpdateMetadata (track);
 
504
        }
 
505
 
488
506
        protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri)
489
507
        {
490
508
            if (track.PrimarySourceId == DbId)
561
579
 
562
580
        protected override bool DeleteTrack (DatabaseTrackInfo track)
563
581
        {
 
582
            if (ms_device != null && !ms_device.DeleteTrackHook (track)) {
 
583
                return false;
 
584
            }
 
585
            DeleteTrackFile (track);
 
586
            return true;
 
587
        }
 
588
 
 
589
        private void DeleteTrackFile (DatabaseTrackInfo track)
 
590
        {
564
591
            try {
565
 
                if (ms_device != null && !ms_device.DeleteTrackHook (track)) {
566
 
                    return false;
567
 
                }
568
 
 
569
592
                string track_file = System.IO.Path.GetFileName (track.Uri.LocalPath);
570
593
                string track_dir = System.IO.Path.GetDirectoryName (track.Uri.LocalPath);
571
594
                int files = 0;
585
608
                    System.IO.File.Delete (Paths.Combine (track_dir, CoverArtFileName));
586
609
                }
587
610
 
588
 
                Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
 
611
                if (Banshee.IO.File.Exists (track.Uri)) {
 
612
                    Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
 
613
                } else {
 
614
                    Banshee.IO.Utilities.TrimEmptyDirectories (track.Uri);
 
615
                }
589
616
            } catch (System.IO.FileNotFoundException) {
590
617
            } catch (System.IO.DirectoryNotFoundException) {
591
618
            }
592
 
 
593
 
            return true;
594
619
        }
595
620
 
596
621
        protected override void Eject ()
690
715
 
691
716
            return file_path;
692
717
        }
 
718
 
 
719
        public override bool HasEditableTrackProperties {
 
720
            get { return true; }
 
721
        }
693
722
    }
694
723
}