Esempio n. 1
0
        private void OnFinished(object o, EventArgs args)
        {
            job.Finish();

            if (cancelled)
            {
                return;
            }

            //Hyena.Log.DebugFormat ("Have {0} items before delete", ServiceManager.DbConnection.Query<int>("select count(*) from coretracks where primarysourceid=?", psource.DbId));

            // Delete tracks that are under the BaseDirectory and that weren't rescanned just now
            string condition = String.Format(
                "WHERE PrimarySourceID = ? AND Uri LIKE '{0}%' AND LastSyncedStamp IS NOT NULL AND LastSyncedStamp < ?",
                new SafeUri(psource.BaseDirectoryWithSeparator).AbsoluteUri
                );

            ServiceManager.DbConnection.Execute(String.Format(@"BEGIN;
                    DELETE FROM CorePlaylistEntries WHERE TrackID IN (SELECT TrackID FROM CoreTracks {0});
                    DELETE FROM CoreSmartPlaylistEntries WHERE TrackID IN (SELECT TrackID FROM CoreTracks {0});
                    DELETE FROM CoreTracks {0}; COMMIT",
                                                              condition),
                                                psource.DbId, scan_started,
                                                psource.DbId, scan_started,
                                                psource.DbId, scan_started
                                                );

            // TODO prune artists/albums
            psource.Reload();
            psource.NotifyTracksChanged();
            //Hyena.Log.DebugFormat ("Have {0} items after delete", ServiceManager.DbConnection.Query<int>("select count(*) from coretracks where primarysourceid=?", psource.DbId));
        }
Esempio n. 2
0
        public void Save(bool notify, params QueryField [] fields_changed)
        {
            // If either the artist or album changed,
            if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true)
            {
                DatabaseArtistInfo artist = Artist;
                ArtistId = artist.DbId;

                DatabaseAlbumInfo album = Album;
                AlbumId = album.DbId;

                // TODO get rid of unused artists/albums
            }

            // If PlayCountField is not transient we still want to update the file only if it's from the music library
            var transient = transient_fields;

            if (!transient.Contains(BansheeQuery.PlayCountField) &&
                !ServiceManager.SourceManager.MusicLibrary.Equals(PrimarySource))
            {
                transient = new HashSet <QueryField> (transient_fields);
                transient.Add(BansheeQuery.PlayCountField);
            }

            if (fields_changed.Length == 0 || !transient.IsSupersetOf(fields_changed))
            {
                DateUpdated = DateTime.Now;
            }

            bool is_new = (TrackId == 0);

            if (is_new)
            {
                LastSyncedStamp = DateAdded = DateUpdated = DateTime.Now;
            }

            ProviderSave();

            if (notify && PrimarySource != null)
            {
                if (is_new)
                {
                    PrimarySource.NotifyTracksAdded();
                }
                else
                {
                    PrimarySource.NotifyTracksChanged(fields_changed);
                }
            }
        }
Esempio n. 3
0
        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 it's PrimarySource
            if (source.IsLocal || source is LibrarySource)
            {
                track.PrimarySource = this;

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

                track.Save(false);
                source.NotifyTracksChanged();
            }
            else
            {
                // Figure out where we should put it if were to copy it
                string  path = FileNamePattern.BuildFull(BaseDirectory, track);
                SafeUri uri  = new SafeUri(path);

                // Make sure it's not already in the library
                // TODO optimize - no need to recrate 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);
            }
        }
Esempio n. 4
0
        public void Save()
        {
            List <int> primary_sources = new List <int> ();

            // TODO: wrap in db transaction
            try {
                DatabaseTrackInfo.NotifySaved = false;

                for (int i = 0; i < TrackCount; i++)
                {
                    // Save any tracks that were actually loaded into the editor
                    EditorTrackInfo track = LoadTrack(i, false);
                    if (track == null || track.SourceTrack == null)
                    {
                        continue;
                    }

                    SaveTrack(track);

                    if (track.SourceTrack is DatabaseTrackInfo)
                    {
                        // If the source track is from the database, save its parent for notification later
                        int id = (track.SourceTrack as DatabaseTrackInfo).PrimarySourceId;
                        if (!primary_sources.Contains(id))
                        {
                            primary_sources.Add(id);
                        }
                    }
                }

                // Finally, notify the affected primary sources
                foreach (int id in primary_sources)
                {
                    PrimarySource psrc = PrimarySource.GetById(id);
                    if (psrc != null)
                    {
                        psrc.NotifyTracksChanged();
                    }
                }
            } finally {
                DatabaseTrackInfo.NotifySaved = true;
            }
        }
        public void Save(bool notify, params QueryField [] fields_changed)
        {
            // If either the artist or album changed,
            if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true)
            {
                DatabaseArtistInfo artist = Artist;
                ArtistId = artist.DbId;

                DatabaseAlbumInfo album = Album;
                AlbumId = album.DbId;

                // TODO get rid of unused artists/albums
            }

            if (fields_changed.Length == 0 || !transient_fields.IsSupersetOf(fields_changed))
            {
                DateUpdated = DateTime.Now;
            }

            bool is_new = (TrackId == 0);

            if (is_new)
            {
                DateAdded = DateUpdated = DateTime.Now;
            }

            ProviderSave();

            if (notify && PrimarySource != null)
            {
                if (is_new)
                {
                    PrimarySource.NotifyTracksAdded();
                }
                else
                {
                    PrimarySource.NotifyTracksChanged(fields_changed);
                }
            }
        }
Esempio n. 6
0
 private void Refresh()
 {
     psource.Reload();
     psource.NotifyTracksChanged();
 }