Beispiel #1
0
        private void OnImportPlaylist(object o, EventArgs args)
        {
            // Prompt user for location of the playlist.
            var chooser = Banshee.Gui.Dialogs.FileChooserDialog.CreateForImport(Catalog.GetString("Import Playlist"), true);

            chooser.AddFilter(Hyena.Gui.GtkUtilities.GetFileFilter(Catalog.GetString("Playlists"), PlaylistFileUtil.PlaylistExtensions));

            int response = chooser.Run();

            string [] uris = null;
            if (response == (int)ResponseType.Ok)
            {
                uris = chooser.Uris;
                chooser.Destroy();
            }
            else
            {
                chooser.Destroy();
                return;
            }

            if (uris == null || uris.Length == 0)
            {
                return;
            }

            Banshee.Kernel.Scheduler.Schedule(new Banshee.Kernel.DelegateJob(delegate {
                foreach (string uri in uris)
                {
                    PlaylistFileUtil.ImportPlaylistToLibrary(uri);
                }
            }));
        }
        public void Enqueue(string path)
        {
            try {
                SafeUri uri = new SafeUri(path);
                if (uri.IsLocalPath && !String.IsNullOrEmpty(uri.LocalPath))
                {
                    path = uri.LocalPath;
                }
            } catch {
            }

            lock (this) {
                if (importer == null)
                {
                    importer = new DatabaseImportManager(this);
                    importer.KeepUserJobHidden = true;
                    importer.ImportResult     += delegate(object o, DatabaseImportResultArgs args) {
                        Banshee.ServiceStack.Application.Invoke(delegate {
                            if (args.Error != null || path_to_play != null)
                            {
                                return;
                            }

                            path_to_play = args.Path;
                            if (args.Track == null)
                            {
                                // Play immediately if the track is already in the source,
                                // otherwise the call will be deferred until the track has
                                // been imported and loaded into the cache
                                PlayEnqueued();
                            }
                        });
                    };

                    importer.Finished += delegate {
                        if (visible)
                        {
                            Banshee.Base.ThreadAssist.ProxyToMain(delegate {
                                TrackInfo current_track = ServiceManager.PlaybackController.CurrentTrack;
                                // Don't switch to FSQ if the current item is a video
                                if (current_track == null || !current_track.HasAttribute(TrackMediaAttributes.VideoStream))
                                {
                                    ServiceManager.SourceManager.SetActiveSource(this);
                                }
                            });
                        }
                    };
                }

                if (PlaylistFileUtil.PathHasPlaylistExtension(path))
                {
                    Banshee.Kernel.Scheduler.Schedule(new DelegateJob(delegate {
                        // If it's in /tmp it probably came from Firefox - just play it
                        if (path.StartsWith(Paths.SystemTempDir))
                        {
                            Banshee.Streaming.RadioTrackInfo.OpenPlay(path);
                        }
                        else
                        {
                            PlaylistFileUtil.ImportPlaylistToLibrary(path, this, importer);
                        }
                    }));
                }
                else
                {
                    importer.Enqueue(path);
                }
            }
        }