internal void Sync() { if (Enabled) { Banshee.Base.ThreadAssist.AssertNotInMainThread(); CalculateSync(); sync.Dap.DeleteAllTracks(to_remove); sync.Dap.AddAllTracks(to_add); if (library.SupportsPlaylists && sync.Dap.SupportsPlaylists) { // Now create the playlists, taking snapshots of smart playlists and saving them // as normal playlists IList <AbstractPlaylistSource> playlists = GetSyncPlaylists(); foreach (AbstractPlaylistSource from in playlists) { if (from.Count == 0) { continue; } PlaylistSource to = new PlaylistSource(from.Name, sync.Dap); to.Save(); ServiceManager.DbConnection.Execute( String.Format( @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND MetadataHash IN (SELECT MetadataHash FROM {0} WHERE {1})", from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition), to.DbId, sync.Dap.DbId ); to.UpdateCounts(); if (to.Count == 0) { // If it's empty, don't leave it on the device to.Unmap(); } else { sync.Dap.AddChildSource(to); } } } CalculateSync(); sync.OnUpdated(); } }