public static void SetDefaultExportFormat(PlaylistFormatDescription format) { try { DefaultExportFormat.Set(format.FileExtension); } catch (Exception) { } }
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 static PlaylistFormatDescription GetDefaultExportFormat() { PlaylistFormatDescription default_format = null; try { string exportFormat = DefaultExportFormat.Get(); PlaylistFormatDescription [] formats = PlaylistFileUtil.ExportFormats; foreach (PlaylistFormatDescription format in formats) { if (format.FileExtension.Equals(exportFormat)) { default_format = format; break; } } } catch { // Ignore errors, return our default if we encounter an error. } finally { if (default_format == null) { default_format = M3uPlaylistFormat.FormatDescription; } } return(default_format); }
public static int GetFormatIndex(PlaylistFormatDescription [] formats, PlaylistFormatDescription playlist) { int default_export_index = -1; foreach (PlaylistFormatDescription format in formats) { default_export_index++; if (format.FileExtension.Equals(playlist.FileExtension)) { break; } } return(default_export_index); }
public PlaylistFormatDescription GetExportFormat() { PlaylistFormatDescription selected_playlist = null; // Get the format that the user selected. if (combobox != null && store != null) { TreeIter iter; if (combobox.GetActiveIter(out iter)) { selected_playlist = store.GetValue(iter, 1) as PlaylistFormatDescription; } } return selected_playlist; }
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(); }
public static IPlaylistFormat Load(string playlistUri, Uri baseUri, Uri rootPath) { PlaylistFormatDescription [] formats = PlaylistFileUtil.ExportFormats; // If the file has an extenstion, rearrange the format array so that the // appropriate format is tried first. if (System.IO.Path.HasExtension(playlistUri)) { string extension = System.IO.Path.GetExtension(playlistUri); extension = extension.ToLower(); int index = -1; foreach (PlaylistFormatDescription format in formats) { index++; if (extension.Equals("." + format.FileExtension)) { break; } } if (index != -1 && index != 0 && index < formats.Length) { // Move to first position in array. PlaylistFormatDescription preferredFormat = formats[index]; formats[index] = formats[0]; formats[0] = preferredFormat; } } foreach (PlaylistFormatDescription format in formats) { try { IPlaylistFormat playlist = (IPlaylistFormat)Activator.CreateInstance(format.Type); playlist.BaseUri = baseUri; playlist.RootPath = rootPath; playlist.Load(Banshee.IO.File.OpenRead(new SafeUri(playlistUri)), true); return(playlist); } catch (InvalidPlaylistException) { } } return(null); }
private void OnExportPlaylist(object o, EventArgs args) { AbstractPlaylistSource source = ActionSource as AbstractPlaylistSource; if (source == null) { return; } source.Activate(); PlaylistExportDialog chooser = new PlaylistExportDialog(source.Name, PrimaryWindow); string uri = null; PlaylistFormatDescription format = null; int response = chooser.Run(); if (response == (int)ResponseType.Ok) { uri = chooser.Uri; // Get the format that the user selected. format = chooser.GetExportFormat(); } chooser.Destroy(); if (uri == null) { // User cancelled export. return; } try { IPlaylistFormat playlist = (IPlaylistFormat)Activator.CreateInstance(format.Type); SafeUri suri = new SafeUri(uri); if (suri.IsLocalPath) { playlist.BaseUri = new Uri(System.IO.Path.GetDirectoryName(suri.LocalPath)); } playlist.Save(Banshee.IO.File.OpenWrite(new SafeUri(uri), true), source); } catch (Exception e) { Console.WriteLine(e); Log.Error(Catalog.GetString("Could not export playlist"), e.Message, true); } }