Beispiel #1
0
        public override void SyncPlaylists()
        {
            lock (mtp_device) {
                List <MTP.Playlist> device_playlists = new List <MTP.Playlist> (mtp_device.GetPlaylists());
                foreach (MTP.Playlist playlist in device_playlists)
                {
                    playlist.Remove();
                }
                device_playlists.Clear();

                // Add playlists from Banshee to the device
                List <Source> children = new List <Source> (Children);
                foreach (Source child in children)
                {
                    PlaylistSource from = child as PlaylistSource;
                    if (from != null && from.Count > 0)
                    {
                        MTP.Playlist playlist = new MTP.Playlist(mtp_device, from.Name);
                        foreach (uint track_id in ServiceManager.DbConnection.QueryEnumerable <uint> (String.Format(
                                                                                                          "SELECT CoreTracks.ExternalID FROM {0} WHERE {1}",
                                                                                                          from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                        {
                            playlist.AddTrack(track_id);
                        }
                        playlist.Save();
                    }
                }
            }
        }
Beispiel #2
0
        public override void SyncPlaylists ()
        {
            lock (mtp_device) {
                List<MTP.Playlist> device_playlists = new List<MTP.Playlist> (mtp_device.GetPlaylists ());
                foreach (MTP.Playlist playlist in device_playlists) {
                    playlist.Remove ();
                }
                device_playlists.Clear ();

                // Add playlists from Banshee to the device
                List<Source> children = new List<Source> (Children);
                foreach (Source child in children) {
                    PlaylistSource from = child as PlaylistSource;
                    if (from != null && from.Count > 0) {
                        MTP.Playlist playlist = new MTP.Playlist (mtp_device, from.Name);
                        foreach (uint track_id in ServiceManager.DbConnection.QueryEnumerable<uint> (String.Format (
                            "SELECT CoreTracks.ExternalID FROM {0} WHERE {1}",
                            from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                        {
                            playlist.AddTrack (track_id);
                        }
                        playlist.Save ();
                    }
                }
            }
        }
Beispiel #3
0
        protected override void LoadFromDevice()
        {
            if (null == mtp_device)
            {
                return;
            }

            // Translators: {0} is the file currently being loaded
            // and {1} is the total # of files that will be loaded.
            string format = Catalog.GetString("Reading File - {0} of {1}");

            track_map = new Dictionary <long, Track> ();
            try {
                List <Track> files = null;
                lock (mtp_device) {
                    files = mtp_device.GetAllTracks(delegate(ulong current, ulong total, IntPtr data) {
                        SetStatus(String.Format(format, current + 1, total), false);
                        return(0);
                    });
                }

                /*if (user_event.IsCancelRequested) {
                 *  return;
                 * }*/

                // Delete any empty albums
                lock (mtp_device) {
                    foreach (Album album in mtp_device.GetAlbums())
                    {
                        if (album.Count == 0)
                        {
                            album.Remove();
                        }
                    }
                }

                // Translators: {0} is the track currently being loaded
                // and {1} is the total # of tracks that will be loaded.
                format = Catalog.GetString("Loading Track - {0} of {1}");
                for (int current = 0, total = files.Count; current < total; ++current)
                {
                    SetStatus(String.Format(format, current + 1, total), false);
                    Track mtp_track = files [current];
                    long  track_id;
                    if ((track_id = DatabaseTrackInfo.GetTrackIdForUri(MtpTrackInfo.GetPathFromMtpTrack(mtp_track), DbId)) > 0)
                    {
                        track_map[track_id] = mtp_track;
                    }
                    else
                    {
                        MtpTrackInfo track = new MtpTrackInfo(mtp_device, mtp_track);
                        track.PrimarySource = this;
                        track.Save(false);
                        track_map[track.TrackId] = mtp_track;
                    }
                }

                Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand(
                    @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                        SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");

                // Translators: {0} is the playlist currently being loaded
                // and {1} is the total # of playlists that will be loaded.
                format = Catalog.GetString("Loading Playlist - {0} of {1}");
                lock (mtp_device) {
                    var playlists = mtp_device.GetPlaylists();
                    if (playlists != null)
                    {
                        for (int current = 0, total = playlists.Count; current < total; ++current)
                        {
                            MTP.Playlist playlist = playlists [current];
                            SetStatus(String.Format(format, current + 1, total), false);
                            PlaylistSource pl_src = new PlaylistSource(playlist.Name, this);
                            pl_src.Save();
                            // TODO a transaction would make sense here (when the threading issue is fixed)
                            foreach (uint id in playlist.TrackIds)
                            {
                                ServiceManager.DbConnection.Execute(insert_cmd, pl_src.DbId, this.DbId, id);
                            }
                            pl_src.UpdateCounts();
                            AddChildSource(pl_src);
                        }
                    }
                }
            } catch (Exception e) {
                Log.Error(e);
            }
            OnTracksAdded();
        }
Beispiel #4
0
 public List <Playlist> GetPlaylists()
 {
     return(Playlist.GetPlaylists(this));
 }