상속: Banshee.Collection.Database.DatabaseTrackInfo
예제 #1
0
        void SyncTracksToAdd(UserJob progressUpdater)
        {
            string message = Catalog.GetString("Adding track {0} of {1}");
            int    total   = tracks_to_add.Count;
            int    i       = 0;

            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.Error("Cannot save track to the Apple device", e);
                }
            }
            if (total > 0)
            {
                OnTracksAdded();
                OnUserNotifyUpdated();
            }
        }
예제 #2
0
        void SyncTracksToRemove(UserJob progressUpdater)
        {
            string message = Catalog.GetString("Removing track {0} of {1}");
            int    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.Error("Cannot remove track from iPod", e);
                }
            }

            SyncRemovalOfInvalidTracks(progressUpdater);
        }
예제 #3
0
        void SyncTracksToUpdate()
        {
            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);
                }
            }
        }
예제 #4
0
        protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri)
        {
            lock (sync_mutex) {
                if (track.PrimarySourceId == DbId)
                {
                    return;
                }

                if (track.Duration.Equals(TimeSpan.Zero))
                {
                    throw new Exception(Catalog.GetString("Track duration is zero"));
                }

                AppleDeviceTrackInfo ipod_track = new AppleDeviceTrackInfo(track);
                ipod_track.Uri           = fromUri;
                ipod_track.PrimarySource = this;

                tracks_to_add.Enqueue(ipod_track);
            }
        }
예제 #5
0
        void SyncTracksToUpdate(UserJob progressUpdater)
        {
            string message = Catalog.GetString("Updating metadata in track {0} of {1}");
            int    total   = tracks_to_update.Count;

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

                try {
                    UpdateProgress(progressUpdater, message, total - tracks_to_update.Count, total);

                    track.CommitToIpod(MediaDatabase);
                } catch (Exception e) {
                    Log.Error("Cannot save track to iPod", e);
                }
            }
        }
예제 #6
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");
        }
예제 #7
0
        private void LoadFromDevice(bool refresh)
        {
            tracks_map.Clear();
            if (refresh || MediaDatabase == null)
            {
                if (MediaDatabase != null)
                {
                    MediaDatabase.Dispose();
                }

                try {
                    MediaDatabase = new GPod.ITDB(Device.Mountpoint);
                } catch (GLib.GException e) {
                    Log.Exception("iPod database could not be loaded, creating a new one", e);
                    if (GPod.ITDB.InitIpod(Volume.MountPoint, null, Volume.Name))
                    {
                        // this may throw again. In the future we need to implement some kind of alert
                        // mechanism to let the user know that something more serious is wrong with their
                        // apple device a la the other iPod extension.
                        MediaDatabase = new GPod.ITDB(Device.Mountpoint);
                    }
                    else
                    {
                        Log.Error("Failed to init iPod database");
                        return;
                    }
                }
            }

            if (MediaDatabase.MasterPlaylist == null)
            {
                MediaDatabase.Playlists.Add(new GPod.Playlist(Name)
                {
                    IsMaster = true
                });
            }

            if (SupportsPodcasts && MediaDatabase.PodcastsPlaylist == null)
            {
                MediaDatabase.Playlists.Add(new GPod.Playlist(Catalog.GetString("Podcasts"))
                {
                    IsPodcast = true
                });
            }

            var invalid_tracks = new List <GPod.Track> ();

            foreach (var ipod_track in MediaDatabase.Tracks)
            {
                if (String.IsNullOrEmpty(ipod_track.IpodPath))
                {
                    invalid_tracks.Add(ipod_track);
                    continue;
                }

                try {
                    var track = new AppleDeviceTrackInfo(ipod_track);
                    if (!tracks_map.ContainsKey(track.TrackId))
                    {
                        track.PrimarySource = this;
                        track.Save(false);
                        tracks_map.Add(track.TrackId, track);
                    }
                } catch (Exception e) {
                    Log.Exception(e);
                }
            }
            if (invalid_tracks.Count > 0)
            {
                Log.Warning(String.Format("Found {0} invalid tracks on the device", invalid_tracks.Count));
                foreach (var track in invalid_tracks)
                {
                    DeleteTrack(track, false);
                }
            }


            Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand(
                @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                    SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");
            foreach (var playlist in MediaDatabase.Playlists)
            {
                if (playlist.IsMaster || playlist.IsPodcast)
                {
                    continue;
                }

                PlaylistSource pl_src = new PlaylistSource(playlist.Name, this);
                pl_src.Save();
                // We use the GPod.Track.DBID here b/c we just shoved it into ExternalID above when we loaded
                // the tracks, however when we sync, the Track.DBID values may/will change.
                foreach (var track in playlist.Tracks)
                {
                    // DBID will be stored in a long, so we need to cast it. See bgo#650011
                    ServiceManager.DbConnection.Execute(insert_cmd, pl_src.DbId, this.DbId, (long)track.DBID);
                }
                pl_src.UpdateCounts();
                AddChildSource(pl_src);
            }

            RaiseReadyToScrobble();
        }
        protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri)
        {
            lock (sync_mutex) {
                if (track.PrimarySourceId == DbId) {
                    return;
                }

                if (track.Duration.Equals (TimeSpan.Zero)) {
                    throw new Exception (Catalog.GetString ("Track duration is zero"));
                }

                AppleDeviceTrackInfo ipod_track = new AppleDeviceTrackInfo (track);
                ipod_track.Uri = fromUri;
                ipod_track.PrimarySource = this;
                ipod_track.Save (false);

                tracks_to_add.Enqueue (ipod_track);
            }
        }
        private void LoadFromDevice (bool refresh)
        {
            tracks_map.Clear ();
            if (refresh || MediaDatabase  == null) {
                if (MediaDatabase != null)
                    MediaDatabase.Dispose ();

                MediaDatabase = new GPod.ITDB (Device.Mountpoint);
            }

            foreach (var ipod_track in MediaDatabase.Tracks) {
                try {
                    var track = new AppleDeviceTrackInfo (ipod_track);
                    if (!tracks_map.ContainsKey (track.TrackId)) {
                        track.PrimarySource = this;
                        track.Save (false);
                        tracks_map.Add (track.TrackId, track);
                    }
                } catch (Exception e) {
                    Log.Exception (e);
                }
            }

//                Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
//                    @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
//                        SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");
//                foreach (IPod.Playlist playlist in ipod_device.TrackDatabase.Playlists) {
//                    if (playlist.IsOnTheGo) { // || playlist.IsPodcast) {
//                        continue;
//                    }
//                    PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
//                    pl_src.Save ();
//                    // We use the IPod.Track.Id here b/c we just shoved it into ExternalID above when we loaded
//                    // the tracks, however when we sync, the Track.Id values may/will change.
//                    foreach (IPod.Track track in playlist.Tracks) {
//                        ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, track.Id);
//                    }
//                    pl_src.UpdateCounts ();
//                    AddChildSource (pl_src);
//                }
            /*else {
                BuildDatabaseUnsupportedWidget ();
            }*/

            /*if(previous_database_supported != database_supported) {
                OnPropertiesChanged();
            }*/
        }
예제 #10
0
        private void LoadFromDevice (bool refresh)
        {
            tracks_map.Clear ();
            if (refresh || MediaDatabase  == null) {
                if (MediaDatabase != null)
                    MediaDatabase.Dispose ();

                try {
                    MediaDatabase = new GPod.ITDB (Device.Mountpoint);
                } catch (GLib.GException e) {
                    Log.Exception ("iPod database could be loaded, creating a new one", e);
                    if (GPod.ITDB.InitIpod (Volume.MountPoint, null, Volume.Name)) {
                        // this may throw again. In the future we need to implement some kind of alert
                        // mechanism to let the user know that something more serious is wrong with their
                        // apple device a la the other iPod extension.
                        MediaDatabase = new GPod.ITDB (Device.Mountpoint);
                    } else {
                        Log.Error ("Failed to init iPod database");
                        return;
                    }
                }
            }

            if (MediaDatabase.MasterPlaylist == null) {
                MediaDatabase.Playlists.Add (new GPod.Playlist (Name) {
                    IsMaster = true
                });
            }

            if (SupportsPodcasts && MediaDatabase.PodcastsPlaylist == null) {
                MediaDatabase.Playlists.Add (new GPod.Playlist (Catalog.GetString ("Podcasts")) {
                    IsPodcast = true
                });
            }

            foreach (var ipod_track in MediaDatabase.Tracks) {
                try {
                    var track = new AppleDeviceTrackInfo (ipod_track);
                    if (!tracks_map.ContainsKey (track.TrackId)) {
                        track.PrimarySource = this;
                        track.Save (false);
                        tracks_map.Add (track.TrackId, track);
                    }
                } catch (Exception e) {
                    Log.Exception (e);
                }
            }

            Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                    SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");
            foreach (var playlist in MediaDatabase.Playlists) {
                if (playlist.IsMaster || playlist.IsPodcast)
                    continue;

                PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
                pl_src.Save ();
                // We use the IPod.Track.Id here b/c we just shoved it into ExternalID above when we loaded
                // the tracks, however when we sync, the Track.Id values may/will change.
                foreach (var track in playlist.Tracks) {
                    ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, track.DBID);
                }
                pl_src.UpdateCounts ();
                AddChildSource (pl_src);
            }
        }