Exemplo n.º 1
0
        void SyncTracksToPlaylists()
        {
            if (!SupportsPlaylists)
            {
                return;
            }

            // Remove playlists on the device
            var device_playlists = new List <GPod.Playlist> (MediaDatabase.Playlists);

            foreach (var playlist in device_playlists)
            {
                if (!playlist.IsMaster && !playlist.IsPodcast)
                {
                    MediaDatabase.Playlists.Remove(playlist);
                }
            }

            // Add playlists from Banshee to the device
            foreach (Source child in Children)
            {
                PlaylistSource from = child as PlaylistSource;
                if (from != null && from.Count > 0)
                {
                    var playlist = new GPod.Playlist(from.Name);
                    MediaDatabase.Playlists.Add(playlist);
                    foreach (long track_id in ServiceManager.DbConnection.QueryEnumerable <long> (String.Format(
                                                                                                      "SELECT CoreTracks.TrackID FROM {0} WHERE {1}",
                                                                                                      from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                    {
                        if (tracks_map.ContainsKey(track_id))
                        {
                            playlist.Tracks.Add(tracks_map[track_id].IpodTrack);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void PerformSyncThreadCycle()
        {
            Hyena.Log.Debug("Starting AppleDevice sync thread cycle");

            string message;
            int    total, i = 0;
            var    progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"),
                                                 Catalog.GetString("Preparing to synchronize..."), GetIconNames());

            progressUpdater.Register();
            MediaDatabase.StartSync();
            message = Catalog.GetString("Adding track {0} of {1}");
            total   = tracks_to_add.Count;
            while (tracks_to_add.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    total = tracks_to_add.Count + i;
                    track = tracks_to_add.Dequeue();
                }

                try {
                    UpdateProgress(progressUpdater, message, ++i, total);
                    track.CommitToIpod(MediaDatabase);
                    track.Save(false);
                    tracks_map[track.TrackId] = track;
                } catch (Exception e) {
                    Log.Exception("Cannot save track to the Apple device", e);
                }
            }
            if (total > 0)
            {
                OnTracksAdded();
                OnUserNotifyUpdated();
            }

            while (tracks_to_update.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_update.Dequeue();
                }

                try {
                    track.CommitToIpod(MediaDatabase);
                } catch (Exception e) {
                    Log.Exception("Cannot save track to iPod", e);
                }
            }

            message = Catalog.GetString("Removing track {0} of {1}");
            total   = tracks_to_remove.Count;
            while (tracks_to_remove.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_remove.Dequeue();
                }

                if (tracks_map.ContainsKey(track.TrackId))
                {
                    tracks_map.Remove(track.TrackId);
                }

                try {
                    if (track.IpodTrack != null)
                    {
                        UpdateProgress(progressUpdater, message, total - tracks_to_remove.Count, total);

                        DeleteTrack(track.IpodTrack, true);
                    }
                    else
                    {
                        Log.Error("The ipod track was null");
                    }
                } catch (Exception e) {
                    Log.Exception("Cannot remove track from iPod", e);
                }
            }

            if (SupportsPlaylists)
            {
                // Remove playlists on the device
                var device_playlists = new List <GPod.Playlist> (MediaDatabase.Playlists);
                foreach (var playlist in device_playlists)
                {
                    if (!playlist.IsMaster && !playlist.IsPodcast)
                    {
                        MediaDatabase.Playlists.Remove(playlist);
                    }
                }

                // Add playlists from Banshee to the device
                foreach (Source child in Children)
                {
                    PlaylistSource from = child as PlaylistSource;
                    if (from != null && from.Count > 0)
                    {
                        var playlist = new GPod.Playlist(from.Name);
                        MediaDatabase.Playlists.Add(playlist);
                        foreach (int track_id in ServiceManager.DbConnection.QueryEnumerable <int> (String.Format(
                                                                                                        "SELECT CoreTracks.TrackID FROM {0} WHERE {1}",
                                                                                                        from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                        {
                            if (tracks_map.ContainsKey(track_id))
                            {
                                playlist.Tracks.Add(tracks_map[track_id].IpodTrack);
                            }
                        }
                    }
                }
            }

            try {
                message = Catalog.GetString("Writing media database");
                UpdateProgress(progressUpdater, message, 1, 1);

                lock (write_mutex) {
                    MediaDatabase.Write();
                }

                Log.Information("Wrote iPod database");
            } catch (Exception e) {
                Log.Exception("Failed to save iPod database", e);
            }
            MediaDatabase.StopSync();
            progressUpdater.Finish();

            Hyena.Log.Debug("Ending AppleDevice sync thread cycle");
        }
Exemplo n.º 3
0
        private void PerformSyncThreadCycle ()
        {
            Hyena.Log.Debug ("Starting AppleDevice sync thread cycle");

            string message;
            int total, i = 0;
            var progressUpdater = new UserJob (Catalog.GetString ("Syncing iPod"),
                                               Catalog.GetString ("Preparing to synchronize..."), GetIconNames ());
            progressUpdater.Register ();
            MediaDatabase.StartSync ();
            message = Catalog.GetString ("Adding track {0} of {1}");
            total = tracks_to_add.Count;
            while (tracks_to_add.Count > 0) {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    total = tracks_to_add.Count + i;
                    track = tracks_to_add.Dequeue ();
                }

                try {
                    UpdateProgress (progressUpdater, message, ++i, total);
                    track.CommitToIpod (MediaDatabase);
                    track.Save (false);
                    tracks_map[track.TrackId] = track;
                } catch (Exception e) {
                    Log.Exception ("Cannot save track to iPod", e);
                }
            }
            if (total > 0) {
                OnTracksAdded ();
                OnUserNotifyUpdated ();
            }

            while (tracks_to_update.Count > 0) {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_update.Dequeue ();
                }

                try {
                    track.CommitToIpod (MediaDatabase);
                } catch (Exception e) {
                    Log.Exception ("Cannot save track to iPod", e);
                }
            }

            message = Catalog.GetString ("Removing track {0} of {1}");
            total = tracks_to_remove.Count;
            while (tracks_to_remove.Count > 0) {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_remove.Dequeue ();
                }

                if (tracks_map.ContainsKey (track.TrackId)) {
                    tracks_map.Remove (track.TrackId);
                }

                try {
                    if (track.IpodTrack != null) {
                        UpdateProgress (progressUpdater, message, total - tracks_to_remove.Count, total);

                        foreach (var playlist in MediaDatabase.Playlists) {
                            playlist.Tracks.Remove (track.IpodTrack);
                        }

                        if (SupportsPodcasts && track.IpodTrack.MediaType == GPod.MediaType.Podcast) {
                            MediaDatabase.PodcastsPlaylist.Tracks.Remove (track.IpodTrack);
                        }

                        MediaDatabase.MasterPlaylist.Tracks.Remove (track.IpodTrack);
                        MediaDatabase.Tracks.Remove (track.IpodTrack);

                        Banshee.IO.File.Delete (new SafeUri (GPod.ITDB.GetLocalPath (Device, track.IpodTrack)));
                    } else {
                        Log.Error ("The ipod track was null");
                    }
                } catch (Exception e) {
                    Log.Exception ("Cannot remove track from iPod", e);
                }
            }

            if (SupportsPlaylists) {
                // Remove playlists on the device
                var device_playlists = new List<GPod.Playlist> (MediaDatabase.Playlists);
                foreach (var playlist in device_playlists) {
                    if (!playlist.IsMaster && !playlist.IsPodcast) {
                        MediaDatabase.Playlists.Remove (playlist);
                    }
                }

                // Add playlists from Banshee to the device
                foreach (Source child in Children) {
                    PlaylistSource from = child as PlaylistSource;
                    if (from != null && from.Count > 0) {
                        var playlist = new GPod.Playlist (from.Name);
                        MediaDatabase.Playlists.Add (playlist);
                        foreach (int track_id in ServiceManager.DbConnection.QueryEnumerable<int> (String.Format (
                            "SELECT CoreTracks.TrackID FROM {0} WHERE {1}",
                            from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                        {
                            if (tracks_map.ContainsKey (track_id)) {
                                playlist.Tracks.Add (tracks_map[track_id].IpodTrack);
                            }
                        }
                    }
                }
            }

            try {
                message = Catalog.GetString ("Writing media database");
                UpdateProgress (progressUpdater, message, 1, 1);
                MediaDatabase.Write ();
                Log.Information ("Wrote iPod database");
            } catch (Exception e) {
                Log.Exception ("Failed to save iPod database", e);
            }
            MediaDatabase.StopSync ();
            progressUpdater.Finish ();

            Hyena.Log.Debug ("Ending AppleDevice sync thread cycle");
        }
Exemplo n.º 4
0
        void SyncTracksToPlaylists ()
        {
            if (!SupportsPlaylists) {
                return;
            }

            // Remove playlists on the device
            var device_playlists = new List<GPod.Playlist> (MediaDatabase.Playlists);
            foreach (var playlist in device_playlists) {
                if (!playlist.IsMaster && !playlist.IsPodcast) {
                    MediaDatabase.Playlists.Remove (playlist);
                }
            }

            // Add playlists from Banshee to the device
            foreach (Source child in Children) {
                PlaylistSource from = child as PlaylistSource;
                if (from != null && from.Count > 0) {
                    var playlist = new GPod.Playlist (from.Name);
                    MediaDatabase.Playlists.Add (playlist);
                    foreach (int track_id in ServiceManager.DbConnection.QueryEnumerable<int> (String.Format (
                        "SELECT CoreTracks.TrackID FROM {0} WHERE {1}",
                        from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                    {
                        if (tracks_map.ContainsKey (track_id)) {
                            playlist.Tracks.Add (tracks_map[track_id].IpodTrack);
                        }
                    }
                }
            }
        }