banshee r3276 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Playlists.Formats src/Core/Banshee.ThickClient src/Core/Banshee.ThickClient/Banshee.Gui src/Core/Banshee.ThickClient/Banshee.Playlist.Gui src/Core/Banshee.ThickClient/Resources



Author: gburt
Date: Tue Feb 19 22:43:27 2008
New Revision: 3276
URL: http://svn.gnome.org/viewvc/banshee?rev=3276&view=rev

Log:
2008-02-19  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs:
	* src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs:
	Uncomment out Save methods, and modify to work with TrackListModel.

	* src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs: Work on
	ImportPlaylistAction - still not enabled/working.

	* src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs: Add
	ExportPlaylistAction handler.

	* src/Core/Banshee.ThickClient/Makefile.am:
	* src/Core/Banshee.ThickClient/Banshee.Playlist.Gui/PlaylistExportDialog.cs:
	Ported from stable.

	* src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml: Add
	Export playlist action to source context menu and edit menu.


Added:
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Playlist.Gui/
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Playlist.Gui/PlaylistExportDialog.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
   trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs	Tue Feb 19 22:43:27 2008
@@ -110,9 +110,11 @@
         
         public override void Save(Stream stream, ITrackModelSource source)
         {
-            /*using(StreamWriter writer = new StreamWriter(stream)) {
+            using(StreamWriter writer = new StreamWriter(stream)) {
                 writer.WriteLine("#EXTM3U");
-                foreach(TrackInfo track in source.Tracks) {
+                TrackInfo track;
+                for (int i = 0; i < source.TrackModel.Count; i++) {
+                    track = source.TrackModel[i];
                     int duration = (int)Math.Round(track.Duration.TotalSeconds);
                     if(duration <= 0) {
                         duration = -1;
@@ -121,8 +123,7 @@
                     writer.WriteLine("#EXTINF:{0},{1} - {2}", duration, track.DisplayArtistName, track.DisplayTrackTitle);
                     writer.WriteLine(ExportUri(track.Uri));
                 }
-            }*/
-            throw new NotImplementedException ();
+            }
         }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs	Tue Feb 19 22:43:27 2008
@@ -128,12 +128,14 @@
         
         public override void Save(Stream stream, ITrackModelSource source)
         {
-            /*using(StreamWriter writer = new StreamWriter(stream)) {
+            using(StreamWriter writer = new StreamWriter(stream)) {
                 int count = 0;
                 
                 writer.WriteLine("[playlist]");
                 
-                foreach(TrackInfo track in source.Tracks) {
+                TrackInfo track;
+                for (int i = 0; i < source.TrackModel.Count; i++) {
+                    track = source.TrackModel[i];
                     count++;
                     
                     writer.WriteLine("File{0}={1}", count, ExportUri(track.Uri));
@@ -143,9 +145,7 @@
                                 
                 writer.WriteLine("NumberOfEntries={0}", count);
                 writer.WriteLine("Version=2");
-            }*/
-            
-            throw new NotImplementedException ();
+            }
         }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs	Tue Feb 19 22:43:27 2008
@@ -52,7 +52,11 @@
                 new ActionEntry ("ImportMusicAction", Stock.Open,
                     Catalog.GetString ("Import _Music..."), "<control>I",
                     Catalog.GetString ("Import music from a variety of sources"), OnImportMusic),
-                    
+
+                new ActionEntry ("ImportPlaylistAction", null,
+                    Catalog.GetString ("Import Playlist..."), null,
+                    Catalog.GetString ("Import a playlist"), OnImportPlaylist),
+
                 new ActionEntry ("OpenLocationAction", null, 
                     Catalog.GetString ("Open _Location..."), "<control>L",
                     Catalog.GetString ("Open a remote location for playback"), OnOpenLocation),
@@ -151,7 +155,7 @@
             }
         }
 
-        /*private void OnImportPlaylist (object o, EventArgs args)
+        private void OnImportPlaylist (object o, EventArgs args)
         {
             // Prompt user for location of the playlist.
             Banshee.Gui.Dialogs.FileChooserDialog chooser = new Banshee.Gui.Dialogs.FileChooserDialog(
@@ -212,7 +216,7 @@
                 md.Destroy();
                 return;
             }
-        }*/
+        }
         
         private void OnQuit (object o, EventArgs args)
         {

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs	Tue Feb 19 22:43:27 2008
@@ -30,12 +30,16 @@
 using Mono.Unix;
 using Gtk;
 
+using Hyena;
+
 using Banshee.Base;
 using Banshee.Collection;
 using Banshee.Configuration;
 using Banshee.ServiceStack;
 using Banshee.Sources;
 using Banshee.Playlist;
+using Banshee.Playlist.Gui;
+using Banshee.Playlists.Formats;
 using Banshee.SmartPlaylist;
 using Banshee.Gui.Dialogs;
 
@@ -82,6 +86,9 @@
                 new ActionEntry ("RenameSourceAction", "gtk-edit", 
                     "Rename", "F2", "Rename", OnRenameSource),
 
+                new ActionEntry ("ExportPlaylistAction", null,
+                    Catalog.GetString ("Export Playlist..."), null,
+                    Catalog.GetString ("Export a playlist"), OnExportPlaylist),
 
                 new ActionEntry ("UnmapSourceAction", Stock.Delete,
                     "Unmap", "<shift>Delete", null, OnUnmapSource),
@@ -194,6 +201,44 @@
             SourceView.BeginRenameSource (ActionSource);
         }
 
+        private void OnExportPlaylist (object o, EventArgs args)
+        {
+            AbstractPlaylistSource source = ActionSource as AbstractPlaylistSource;
+            if (source == null) {
+                return;
+            }
+
+            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));
+                    Console.WriteLine (playlist.BaseUri.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);
+            }
+        }
+
         private void OnUnmapSource (object o, EventArgs args)
         {
             IUnmapableSource source = ActionSource as IUnmapableSource;
@@ -234,6 +279,7 @@
                 UpdateAction ("UnmapSourceAction", unmapable != null, unmapable != null && unmapable.CanUnmap, source);
                 UpdateAction ("RenameSourceAction", source.CanRename, true, null);
                 UpdateAction ("ImportSourceAction", source is IImportable, true, source);
+                UpdateAction ("ExportPlaylistAction", source is AbstractPlaylistSource, true, source);
                 UpdateAction ("SourcePropertiesAction", source.HasProperties, true, source);
                 UpdateAction ("RefreshSmartPlaylistAction", smart_playlist != null && smart_playlist.CanRefresh, true, source);
                 last_source = source;

Added: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Playlist.Gui/PlaylistExportDialog.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Playlist.Gui/PlaylistExportDialog.cs	Tue Feb 19 22:43:27 2008
@@ -0,0 +1,101 @@
+using System;
+
+using Mono.Unix;
+using Gtk;
+
+using Banshee.Widgets;
+using Banshee.Playlists.Formats;
+
+namespace Banshee.Playlist.Gui
+{
+    public class PlaylistExportDialog : Banshee.Gui.Dialogs.FileChooserDialog
+    {
+        protected ComboBox combobox;
+        protected ListStore store;    
+        protected PlaylistFormatDescription playlist;
+        protected string initial_name;
+                
+        public PlaylistExportDialog(string name, Window parent) : 
+            base(Catalog.GetString("Export Playlist"), parent, FileChooserAction.Save)
+        {
+            initial_name = 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();                   
+        }
+        
+        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; 
+        }
+        
+        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 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;
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am	Tue Feb 19 22:43:27 2008
@@ -64,6 +64,7 @@
 	Banshee.Library.Gui/FileImportSource.cs \
 	Banshee.Library.Gui/FolderImportSource.cs \
 	Banshee.Library.Gui/ImportDialog.cs \
+	Banshee.Playlist.Gui/PlaylistExportDialog.cs \
 	Banshee.Query.Gui/BansheeQueryBox.cs \
 	Banshee.Query.Gui/PlaylistQueryValueEntry.cs \
 	Banshee.Query.Gui/RatingQueryValueEntry.cs \

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml	Tue Feb 19 22:43:27 2008
@@ -18,6 +18,7 @@
       <menuitem name="NewSmartPlaylistFromSearch" action="NewSmartPlaylistFromSearchAction"/>
       <separator/>
       <menuitem name="ImportMusic" action="ImportMusicAction"/>
+      <!--<menuitem name="ImportPlaylist" action="ImportPlaylistAction"/>-->
       <menuitem name="OpenLocation" action="OpenLocationAction"/>
       <separator/>
       <placeholder name="ClosePlaceholder"/>
@@ -37,7 +38,7 @@
       <separator/>
       <menuitem name="RenameSource" action="RenameSourceAction"/>
       <menuitem name="RefreshSmartPlaylist" action="RefreshSmartPlaylistAction"/>
-      <!--<menuitem name="ExportPlaylist" action="ExportPlaylistAction"/>-->
+      <menuitem name="ExportPlaylist" action="ExportPlaylistAction"/>
       <menuitem name="SourceProperties" action="SourcePropertiesAction"/>
       <menuitem name="UnmapSource" action="UnmapSourceAction"/>
       <separator/>
@@ -108,8 +109,8 @@
     <separator/>
     <menuitem name="RenameSource" action="RenameSourceAction"/>
     <menuitem name="RefreshSmartPlaylist" action="RefreshSmartPlaylistAction"/>
+    <menuitem name="ExportPlaylist" action="ExportPlaylistAction"/>
     <menuitem name="UnmapSource" action="UnmapSourceAction"/>
-    <!--<menuitem name="ExportPlaylist" action="ExportPlaylistAction"/>-->
     <!--<menuitem name="SyncDap" action="SyncDapAction"/>-->
     <separator/>
     <menuitem name="SourceProperties" action="SourcePropertiesAction"/>
@@ -143,7 +144,6 @@
   <menuitem name="ImportFiles" action="ImportFilesAction"/>*/
   <separator/>
   <menuitem name="ImportMusic" action="ImportMusicAction"/>
-  <menuitem name="ImportPlaylist" action="ImportPlaylistAction"/>
   <menuitem name="OpenLocation" action="OpenLocationAction"/>
   <placeholder name="MusicMenuAdditions"/>
   <separator/>
@@ -159,7 +159,6 @@
   <menuitem name="DeleteSongsFromDrive" action="DeleteSongsFromDriveAction"/>
   <menuitem name="RenameSource" action="RenameSourceAction"/>
   <menuitem name="UnmapSource" action="UnmapSourceAction"/>
-  <menuitem name="ExportPlaylist" action="ExportPlaylistAction"/>
   <separator/>
   <menuitem name="SelectAll" action="SelectAllAction"/>
   <menuitem name="SelectNone" action="SelectNoneAction"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]