banshee r4207 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.Services/Banshee.Web src/Core/Banshee.ThickClient/Banshee.Gui src/Core/Banshee.ThickClient/Banshee.Sources.Gui src/Extensions/Banshee.Daap/Banshee.Daap src/Extensions/Banshee.Daap/Daap src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data src/Libraries/Migo/Migo.Net



Author: gburt
Date: Fri Jun 27 18:04:08 2008
New Revision: 4207
URL: http://svn.gnome.org/viewvc/banshee?rev=4207&view=rev

Log:
2008-06-27  Gabriel Burt  <gabriel burt gmail com>

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastFeedModel.cs:
	Sort podcasts by case-insensitive title.

	* src/Extensions/Banshee.Daap/Daap/Database.cs: Fix bug with not
	specifying what meta fields to return when fetching playlists (actually
	crashed new RB and got bad data from old RB).

	* src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs: Proxy UI
	actions to the main loop, and don't flash new shares within 5 seconds of
	starting the locator.

	* src/Extensions/Banshee.Daap/Banshee.Daap/DaapSource.cs: Make Disconnect
	and Import actions insensitive unless connected.  Handle disconnecting
	while loading the tracks (BGO #526817).  When we disconnect, show the
	disconnected error view.  Proxy ui actions to main loop.  While loading
	tracks, reload fewer times for big collections.

	* src/Extensions/Banshee.Daap/Banshee.Daap/DaapPlaylistSource.cs: Proxy
	OnUpdated call to main.

	* src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs: Listen for
	the active source's Updated event and UpdateActions when it is raised.

	* src/Core/Banshee.Services/Banshee.Web/Browser.cs: Fix typo in UserAgent
	string (no closing parenthesis.

	* src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs:
	* src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs:
	* src/Core/Banshee.Services/Banshee.Sources/Source.cs: Don't set a source
	as the active source unless source.CanActivate is true.

	* src/Libraries/Migo/Migo.Net/AsyncWebClient.cs: Some servers seem to
	return Bad Request when HttpWebRequest auto redirects (because it sets
	Content-Length:0, apparently) - so work around that by grabbing the final
	URI directly.  Fixes, for example, the ogg podcast of "this WEEK in Tech".



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Web/Browser.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
   trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapPlaylistSource.cs
   trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs
   trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapSource.cs
   trunk/banshee/src/Extensions/Banshee.Daap/Daap/Database.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastFeedModel.cs
   trunk/banshee/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs	Fri Jun 27 18:04:08 2008
@@ -184,7 +184,9 @@
                 child_sources.Remove (child);
                 
                 if (ServiceManager.SourceManager.ActiveSource == child) {
-                    ServiceManager.SourceManager.SetActiveSource (this);
+                    if (CanActivate) {
+                        ServiceManager.SourceManager.SetActiveSource (this);
+                    }
                 }
                 
                 OnChildSourceRemoved (child);

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs	Fri Jun 27 18:04:08 2008
@@ -313,7 +313,7 @@
         
         public void SetActiveSource(Source source, bool notify)
         {
-            if(source == null || active_source == source) {
+            if(source == null || !source.CanActivate || active_source == source) {
                 return;
             }
             

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Web/Browser.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Web/Browser.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Web/Browser.cs	Fri Jun 27 18:04:08 2008
@@ -65,7 +65,7 @@
             }
         }
 
-        public static readonly string UserAgent = String.Format ("Banshee {0} (http://banshee-project.org/";, 
+        public static readonly string UserAgent = String.Format ("Banshee {0} (http://banshee-project.org/)", 
             Application.Version);
     }
 }

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	Fri Jun 27 18:04:08 2008
@@ -144,12 +144,25 @@
         private void HandleActiveSourceChanged (SourceEventArgs args)
         {
             UpdateActions ();
+            
+            if (last_source != null) {
+                last_source.Updated -= HandleActiveSourceUpdated;
+            }
+            
+            if (ActiveSource != null) {
+                ActiveSource.Updated += HandleActiveSourceUpdated;
+            }
         }
 
         private void HandleEditMenuActivated (object sender, EventArgs args)
         {
             UpdateActions ();
         }
+        
+        private void HandleActiveSourceUpdated (object o, EventArgs args)
+        {
+            UpdateActions (true);
+        }
 
 #endregion
 
@@ -319,9 +332,14 @@
         private Source last_source = null;
         private void UpdateActions ()
         {
+            UpdateActions (false);
+        }
+        
+        private void UpdateActions (bool force)
+        {
             Source source = ActionSource;
 
-            if (source != last_source && source != null) {
+            if ((force || source != last_source) && source != null) {
                 IUnmapableSource unmapable = (source as IUnmapableSource);
                 IImportSource import_source = (source as IImportSource);
                 SmartPlaylistSource smart_playlist = (source as SmartPlaylistSource);

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs	Fri Jun 27 18:04:08 2008
@@ -191,6 +191,11 @@
                 OnPopupMenu ();
                 return true;
             }
+            
+            if (!source.CanActivate) {
+                return false;
+            }
+            
 
             if (press.Button == 1) {
                 if (ServiceManager.SourceManager.ActiveSource != source) {

Modified: trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapPlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapPlaylistSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapPlaylistSource.cs	Fri Jun 27 18:04:08 2008
@@ -33,6 +33,7 @@
 using Hyena;
 using Hyena.Data.Sqlite;
 
+using Banshee.Base;
 using Banshee.ServiceStack;
 using Banshee.Collection;
 using Banshee.Collection.Database;
@@ -77,7 +78,10 @@
                 }
             }
             SavedCount = count;
-            OnUpdated ();
+            
+            ThreadAssist.ProxyToMain (delegate {
+                OnUpdated ();
+            });
         }
         
         public override bool CanDeleteTracks {

Modified: trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs	Fri Jun 27 18:04:08 2008
@@ -41,6 +41,7 @@
     public class DaapService : IExtensionService, IDisposable, IDelayedInitializeService
     {
         private ServiceLocator locator;
+        private DateTime locator_started;
         private static DaapProxyWebServer proxy_server;
         
         private DaapContainerSource container;
@@ -84,38 +85,46 @@
         
         private void OnServiceFound (object o, ServiceArgs args)
         {
-            DaapSource source = new DaapSource (args.Service);
-            string key = String.Format ("{0}:{1}", args.Service.Name, args.Service.Port);
-            
-            if (source_map.Count == 0) {
-                ServiceManager.SourceManager.AddSource (container);
-            }
-            
-            if (source_map.ContainsKey (key)) {
-                // Received new connection info for service
-                container.RemoveChildSource (source_map [key]);
-                source_map [key] = source;
-            } else {
-                // New service information
-                source_map.Add (key, source);
-            }
-            
-            container.AddChildSource (source);
-            source.NotifyUser ();
+            ThreadAssist.ProxyToMain (delegate {
+                DaapSource source = new DaapSource (args.Service);
+                string key = String.Format ("{0}:{1}", args.Service.Name, args.Service.Port);
+                
+                if (source_map.Count == 0) {
+                    ServiceManager.SourceManager.AddSource (container);
+                }
+                
+                if (source_map.ContainsKey (key)) {
+                    // Received new connection info for service
+                    container.RemoveChildSource (source_map [key]);
+                    source_map [key] = source;
+                } else {
+                    // New service information
+                    source_map.Add (key, source);
+                }
+                
+                container.AddChildSource (source);
+                
+                // Don't flash shares we find on startup (well, within 5s of startup)
+                if ((DateTime.Now - locator_started).TotalSeconds > 5) {
+                    source.NotifyUser ();
+                }
+            });
         }
         
         private void OnServiceRemoved (object o, ServiceArgs args)
         {
-            string key = String.Format ("{0}:{1}", args.Service.Name, args.Service.Port);
-            DaapSource source = source_map [key];
-            
-            source.Disconnect (true);
-            container.RemoveChildSource (source);
-            source_map.Remove (key);
-            
-            if (source_map.Count == 0) {
-                ServiceManager.SourceManager.RemoveSource (container);
-            }
+            ThreadAssist.ProxyToMain (delegate {
+                string key = String.Format ("{0}:{1}", args.Service.Name, args.Service.Port);
+                DaapSource source = source_map [key];
+                
+                source.Disconnect (true);
+                container.RemoveChildSource (source);
+                source_map.Remove (key);
+                
+                if (source_map.Count == 0) {
+                    ServiceManager.SourceManager.RemoveSource (container);
+                }
+            });
         }
 
         public void DelayedInitialize ()
@@ -133,6 +142,7 @@
             locator.Found += OnServiceFound;
             locator.Removed += OnServiceRemoved;
             locator.ShowLocalServices = true;
+            locator_started = DateTime.Now;
             locator.Start ();
             
             proxy_server = new DaapProxyWebServer ();

Modified: trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Daap/Banshee.Daap/DaapSource.cs	Fri Jun 27 18:04:08 2008
@@ -48,6 +48,7 @@
         private DAAP.Service service;
         private DAAP.Client client;
         private DAAP.Database database;
+        private bool connected = false;
         
         public DAAP.Database Database {
             get { return database; }
@@ -69,6 +70,8 @@
             AfterInitialized ();
         }
         
+        
+        
         private void UpdateIcon ()
         {
             if (service != null && !service.IsProtected) {
@@ -122,6 +125,8 @@
         
         private void ShowErrorView (DaapErrorType error_type)
         {
+            PurgeTracks ();
+            Reload ();
             client = null;
             DaapErrorView error_view = new DaapErrorView (this, error_type);
             error_view.Show ();
@@ -146,6 +151,8 @@
                 }
             } catch {}
             
+            connected = false;
+            
             // Remove tracks associated with this source, since we don't want
             // them after we unmap - we'll refetch.
             PurgeTracks ();
@@ -176,7 +183,7 @@
                 }
             }
             
-            ClearChildSources();
+            ClearChildSources ();
             
             return true;
         }
@@ -217,48 +224,64 @@
         
         private void OnClientUpdated (object o, EventArgs args)
         {
-            if (database == null && client.Databases.Count > 0) {
-                database = client.Databases[0];
-                DaapService.ProxyServer.RegisterDatabase (database);
-                database.TrackAdded += OnDatabaseTrackAdded;
-                database.TrackRemoved += OnDatabaseTrackRemoved;
-                
-                SetStatus (String.Format (Catalog.GetString ("Loading {0} tracks."), database.Tracks.Count), false);
-                
-                int count = 0;
-                DaapTrackInfo daap_track = null;
-                foreach (DAAP.Track track in database.Tracks) {
-                    daap_track = new DaapTrackInfo (track, this);
-                    // Only notify once every 250 tracks
-                    daap_track.Save (++count % 250 == 0);
+            try {
+                if (database == null && client.Databases.Count > 0) {
+                    database = client.Databases[0];
+                    DaapService.ProxyServer.RegisterDatabase (database);
+                    database.TrackAdded += OnDatabaseTrackAdded;
+                    database.TrackRemoved += OnDatabaseTrackRemoved;
+                    
+                    SetStatus (String.Format (Catalog.GetString ("Loading {0} tracks."), database.Tracks.Count), false);
+                    
+                    // Notify (eg reload the source before sync is done) at most 5 times
+                    int notify_every = Math.Max (250, (database.Tracks.Count / 4));
+                    notify_every -= notify_every % 250;
+                    
+                    int count = 0;
+                    DaapTrackInfo daap_track = null;
+                    foreach (DAAP.Track track in database.Tracks) {
+                        daap_track = new DaapTrackInfo (track, this);
+                        
+                        // Only notify once in a while because otherwise the source Reloading slows things way down
+                        daap_track.Save (++count % notify_every == 0);
+                    }
+                    
+                    // Save the last track once more to trigger the NotifyTrackAdded
+                    if (daap_track != null) {
+                        daap_track.Save ();
+                    }
+                    
+                    SetStatus (Catalog.GetString ("Loading playlists"), false);
+                    AddPlaylistSources ();
+                    connected = true;
+                    Reload ();
+                    HideStatus ();
                 }
                 
-                // Save the last track once more to trigger the NotifyTrackAdded
-                if (daap_track != null) {
-                    daap_track.Save ();
-                }
+                Name = client.Name;
                 
-                SetStatus (Catalog.GetString ("Loading playlists"), false);
-                AddPlaylistSources ();
-                Reload ();
-                HideStatus ();
+                UpdateIcon ();
+                OnUpdated ();
+            } catch (Exception e) {
+                Hyena.Log.Exception ("Caught exception while loading daap share", e);
+                ThreadAssist.ProxyToMain (delegate {
+                    HideStatus ();
+                    ShowErrorView (DaapErrorType.UserDisconnect);
+                });
             }
-            
-            Name = client.Name;
-            
-            UpdateIcon ();
-            OnUpdated ();
         }
         
         private void AddPlaylistSources ()
         {
             foreach (DAAP.Playlist pl in database.Playlists) {
                 DaapPlaylistSource source = new DaapPlaylistSource (pl, this);
-                if (source.Count == 0) {
-                    source.Unmap ();
-                } else {
-                    AddChildSource (source);
-                }
+                ThreadAssist.ProxyToMain (delegate {
+                    if (source.Count == 0) {
+                        source.Unmap ();
+                    } else {
+                        AddChildSource (source);
+                    }
+                });
             }
         }
         
@@ -289,12 +312,13 @@
         {
             // Disconnect and clear out our tracks and such.
             Disconnect (true);
+            ShowErrorView (DaapErrorType.UserDisconnect);
             
             return true;
         }
         
         public bool CanUnmap {
-            get { return true; }
+            get { return connected; }
         }
         
         public bool ConfirmBeforeUnmap {
@@ -307,7 +331,7 @@
         }
         
         public bool CanImport {
-            get { return true; }
+            get { return connected; }
         }
         
         public string [] IconNames {

Modified: trunk/banshee/src/Extensions/Banshee.Daap/Daap/Database.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Daap/Daap/Database.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Daap/Daap/Database.cs	Fri Jun 27 18:04:08 2008
@@ -265,7 +265,7 @@
             byte[] playlistsData;
 
             try {
-                playlistsData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers", id, revquery));
+                playlistsData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers", id), revquery);
             } catch (WebException) {
                 return;
             }
@@ -304,8 +304,9 @@
 
             // add/remove tracks in the playlists
             foreach (Playlist pl in playlists) {
-                byte[] playlistTracksData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers/{1}/items",
-                                                                                id, pl.Id), revquery);
+                byte [] playlistTracksData = client.Fetcher.Fetch (String.Format (
+                    "/databases/{0}/containers/{1}/items", id, pl.Id), String.Format ("meta=dmap.itemid,dmap.containeritemid&{0}", revquery)
+                );
                 ContentNode playlistTracksNode = ContentParser.Parse (client.Bag, playlistTracksData);
 
                 if (IsUpdateResponse (playlistTracksNode))

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastFeedModel.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastFeedModel.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastFeedModel.cs	Fri Jun 27 18:04:08 2008
@@ -52,7 +52,7 @@
                         WHERE ItemID IN
                             (SELECT CoreTracks.ExternalID FROM CoreTracks, CoreCache{0}
                                 WHERE CoreCache.ModelID = {1} AND CoreCache.ItemId = {2}))
-                    ORDER BY Title";
+                    ORDER BY lower(Title)";
         }
         
         public override string FilterColumn {

Modified: trunk/banshee/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs	Fri Jun 27 18:04:08 2008
@@ -461,7 +461,7 @@
         {
             try {
                 tsm.Reset ();
-                request = PrepRequest (uri);             
+                request = PrepRequest (uri);
 
                 IAsyncResult ar = request.BeginGetResponse (
                     OnResponseCallback, null
@@ -566,7 +566,7 @@
                 }
             }
             
-			responseHeaders = null;                        
+			responseHeaders = null;                       
             
             return req;
         }         
@@ -574,6 +574,7 @@
         private void OnResponseCallback (IAsyncResult ar)
         {    
             Exception err = null;
+            bool redirect_workaround = false;
             
             try {
                 //Console.WriteLine ("0");
@@ -594,12 +595,23 @@
                     //Console.WriteLine ("Why {1}:  {0}", we.Status, this.fileName);
                     //Console.WriteLine ("Cancelled:  {0}", this.Cancelled);
                     err = we;
+                    
+                    HttpWebResponse response = we.Response as HttpWebResponse;
+                    if (response != null && response.StatusCode == HttpStatusCode.BadRequest && response.ResponseUri != request.RequestUri) {
+                        Hyena.Log.DebugFormat ("Identified Content-Length: 0 redirection bug for {0}; trying to get {1} directly", request.RequestUri, response.ResponseUri);
+                        redirect_workaround = true;
+                        uri = response.ResponseUri;
+                        ImplDownloadAsync ();
+                    }
                 }
             } catch (Exception e) {
                 //Console.WriteLine ("GetResponseCallback:  {0}", e.Message);
                 err = e;                
+                //Console.WriteLine (request.
             } finally {
-                Completed (err);
+                if (!redirect_workaround) {
+                    Completed (err);
+                }
                 //Console.WriteLine ("3");  
             }
         }        



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