protected void InitializeExtraWidget()
        {
            PlaylistFormatDescription [] formats = PlaylistFileUtil.ExportFormats;
            int default_export_index = PlaylistFileUtil.GetFormatIndex(formats, playlist);

            // Build custom widget used to select the export format.
            store = new ListStore(typeof(string), typeof(PlaylistFormatDescription));
            foreach (PlaylistFormatDescription format in formats) {
                store.AppendValues(format.FormatName, format);
            }

            HBox hBox = new HBox(false, 2);

            combobox = new ComboBox(store);
            CellRendererText crt = new CellRendererText();
            combobox.PackStart(crt, true);
            combobox.SetAttributes(crt, "text", 0);
            combobox.Active = default_export_index;
            combobox.Changed += OnComboBoxChange;

            hBox.PackStart(new Label(Catalog.GetString("Select Format: ")), false, false, 0);
            hBox.PackStart(combobox, true, true, 0);

            combobox.ShowAll();
            hBox.ShowAll();
            ExtraWidget = hBox;
        }
Example #2
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);
                }
            }));
        }
Example #3
0
        protected void OnComboBoxChange(object o, EventArgs args)
        {
            playlist = GetExportFormat();

            if (playlist != null)
            {
                // Store the export format so that we can default to it the
                // next time the user exports.
                PlaylistFileUtil.SetDefaultExportFormat(playlist);

                // If the filename has an extension, update it to the extension
                // of the export format.
                string file_name = null;

                if (Filename != null)
                {
                    file_name = System.IO.Path.GetFileName(Filename);
                }

                if (file_name != null)
                {
                    CurrentName = System.IO.Path.ChangeExtension(file_name, playlist.FileExtension);
                }
                else
                {
                    CurrentName = System.IO.Path.ChangeExtension(initial_name, playlist.FileExtension);
                }
            }
        }
        public PlaylistExportDialog(string name, Window parent) :
            base(Catalog.GetString("Export Playlist"), parent, FileChooserAction.Save)
        {
            initial_name = FileNamePattern.Escape (name);
            playlist = PlaylistFileUtil.GetDefaultExportFormat();
            CurrentName = System.IO.Path.ChangeExtension(initial_name, playlist.FileExtension);
            DefaultResponse = ResponseType.Ok;
            DoOverwriteConfirmation = true;

            AddButton(Stock.Cancel, ResponseType.Cancel);
            AddButton(Catalog.GetString("Export"), ResponseType.Ok);

            InitializeExtraWidget();
        }
Example #5
0
        private void OnImportFinished(object o, EventArgs args)
        {
            importer.Finished -= OnImportFinished;

            if (CanSyncPlaylists)
            {
                var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand(
                    "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
                foreach (string playlist_path in PlaylistFiles)
                {
                    // playlist_path has a file:// prefix, and GetDirectoryName messes it up,
                    // so we need to convert it to a regular path
                    string base_folder = ms_device.RootPath != null ? BaseDirectory :
                                         System.IO.Path.GetDirectoryName(SafeUri.UriToFilename(playlist_path));

                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load(playlist_path,
                                                                            new Uri(base_folder),
                                                                            ms_device.RootPath);
                    if (loaded_playlist == null)
                    {
                        continue;
                    }

                    string         name     = System.IO.Path.GetFileNameWithoutExtension(SafeUri.UriToFilename(playlist_path));
                    PlaylistSource playlist = new PlaylistSource(name, this);
                    playlist.Save();
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
                    foreach (PlaylistElement element in loaded_playlist.Elements)
                    {
                        string track_path = element.Uri.LocalPath;
                        long   track_id   = DatabaseTrackInfo.GetTrackIdForUri(new SafeUri(track_path), DbId);
                        if (track_id == 0)
                        {
                            Log.DebugFormat("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
                        }
                        else
                        {
                            ServiceManager.DbConnection.Execute(insert_cmd, playlist.DbId, track_id);
                        }
                    }
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false;
                    playlist.UpdateCounts();
                    AddChildSource(playlist);
                }
            }

            import_reset_event.Set();
        }
Example #6
0
        private void OnImportFinished(object o, EventArgs args)
        {
            importer.Finished -= OnImportFinished;

            if (CanSyncPlaylists)
            {
                var insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand(
                    "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)");
                int [] psources = new int [] { DbId };
                foreach (string playlist_path in PlaylistFiles)
                {
                    IPlaylistFormat loaded_playlist = PlaylistFileUtil.Load(playlist_path, new Uri(PlaylistsPath));
                    if (loaded_playlist == null)
                    {
                        continue;
                    }

                    PlaylistSource playlist = new PlaylistSource(System.IO.Path.GetFileNameWithoutExtension(playlist_path), this);
                    playlist.Save();
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
                    foreach (Dictionary <string, object> element in loaded_playlist.Elements)
                    {
                        string track_path = (element["uri"] as Uri).LocalPath;
                        int    track_id   = DatabaseTrackInfo.GetTrackIdForUri(new SafeUri(track_path), psources);
                        if (track_id == 0)
                        {
                            Log.DebugFormat("Failed to find track {0} in DAP library to load it into playlist {1}", track_path, playlist_path);
                        }
                        else
                        {
                            ServiceManager.DbConnection.Execute(insert_cmd, playlist.DbId, track_id);
                        }
                    }
                    //Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = false;
                    playlist.UpdateCounts();
                    AddChildSource(playlist);
                }
            }

            import_reset_event.Set();
        }
        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);
                }
            }
        }