示例#1
0
        /*public override void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, UserJob job)
         * {
         *  Banshee.IO.File.Copy (track.Uri, uri, false);
         * }*/

        protected override void AddTrack(DatabaseTrackInfo track)
        {
            // Ignore if already have it
            if (track.PrimarySourceId == DbId)
            {
                return;
            }

            PrimarySource source = track.PrimarySource;

            // If it's from a local primary source, change its PrimarySource
            if (source.IsLocal || source is LibrarySource)
            {
                track.PrimarySource = this;

                if (!(source is LibrarySource))
                {
                    track.CopyToLibraryIfAppropriate(false);
                }

                track.Save(false);

                // TODO optimize, remove this?  I think it makes moving items
                // between local libraries very slow.
                //source.NotifyTracksChanged ();
            }
            else
            {
                // Figure out where we should put it if were to copy it
                var     pattern = this.PathPattern ?? MusicLibrarySource.MusicFileNamePattern;
                string  path    = pattern.BuildFull(BaseDirectory, track);
                SafeUri uri     = new SafeUri(path);

                // Make sure it's not already in the library
                // TODO optimize - no need to recreate this int [] every time
                if (DatabaseTrackInfo.ContainsUri(uri, new int [] { DbId }))
                {
                    return;
                }

                // Since it's not, copy it and create a new TrackInfo object
                track.PrimarySource.CopyTrackTo(track, uri, AddTrackJob);

                // Create a new entry in CoreTracks for the copied file
                DatabaseTrackInfo new_track = new DatabaseTrackInfo(track);
                new_track.Uri           = uri;
                new_track.PrimarySource = this;
                new_track.Save(false);
            }
        }