[banshee] [U1MS] Ensure that u1ms uris passed to Banshee at startup get loaded by the store extension



commit b57437bb82d33e1415c50bba80be915b6f5352bc
Author: Alex Launi <alex launi canonical com>
Date:   Thu Sep 22 16:16:46 2011 -0400

    [U1MS] Ensure that u1ms uris passed to Banshee at startup get loaded by the store extension

 .../UbuntuOneMusicStoreSource.cs                   |   41 +++++++++++++++++--
 1 files changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/src/Extensions/Banshee.UbuntuOneMusicStore/Banshee.UbuntuOneMusicStore/UbuntuOneMusicStoreSource.cs b/src/Extensions/Banshee.UbuntuOneMusicStore/Banshee.UbuntuOneMusicStore/UbuntuOneMusicStoreSource.cs
index e06ea9c..b2703a1 100644
--- a/src/Extensions/Banshee.UbuntuOneMusicStore/Banshee.UbuntuOneMusicStore/UbuntuOneMusicStoreSource.cs
+++ b/src/Extensions/Banshee.UbuntuOneMusicStore/Banshee.UbuntuOneMusicStore/UbuntuOneMusicStoreSource.cs
@@ -47,6 +47,7 @@ namespace Banshee.UbuntuOneMusicStore
         // In the sources TreeView, sets the order value for this source, small on top
         const int sort_order = 190;
         CustomView custom_view;
+        string cached_startup_uri;
 
         public UbuntuOneMusicStoreSource () : base (
             Catalog.GetString ("Ubuntu One Music Store"),
@@ -61,6 +62,15 @@ namespace Banshee.UbuntuOneMusicStore
 
             // So we can handle u1ms:// URIs
             ServiceManager.Get<DBusCommandService> ().ArgumentPushed += OnCommandLineArgument;
+            custom_view.store.UrlLoaded += OnDefaultStoreUrlLoaded;
+
+            // make sure that the u1ms uri gets handled on banshee startup
+            foreach (string uri in ApplicationContext.CommandLine.Files) {
+                if (IsU1msUri (uri)) {
+                    cached_startup_uri = uri;
+                    break;
+                }
+            }
         }
 
         ~UbuntuOneMusicStoreSource ()
@@ -68,24 +78,45 @@ namespace Banshee.UbuntuOneMusicStore
             ServiceManager.Get<DBusCommandService> ().ArgumentPushed -= OnCommandLineArgument;
         }
 
+        // A count of 0 will be hidden in the source TreeView
+        public override int Count {
+            get { return 0; }
+        }
+
+        private void OnDefaultStoreUrlLoaded (object o, UbuntuOne.UrlLoadedArgs args)
+        {
+            if (args.Url.StartsWith( "http://stores.7digital.com/default";)) {
+                // we just do this the first time we load the default store view
+                // so that we can switch to the passed u1ms uri and not have it switch out on us.
+                custom_view.store.UrlLoaded -= OnDefaultStoreUrlLoaded;
+                if (!string.IsNullOrEmpty (cached_startup_uri))
+                    LoadU1msUri (cached_startup_uri);
+            }
+        }
+
         private void OnCommandLineArgument (string uri, object value, bool isFile)
         {
             if (!isFile || String.IsNullOrEmpty (uri)) {
                 return;
             }
 
+            LoadU1msUri (uri);
+        }
+
+        private void LoadU1msUri (string uri)
+        {
             Log.Debug ("U1MS: URI requested: ", uri);
             // Handle u1ms:// URIs
-            if (uri.StartsWith ("u1ms://")) {
+            if (IsU1msUri (uri)) {
                 string http_url = uri.Replace ("u1ms://", "http://";);
                 custom_view.Store.LoadStoreLink (http_url);
                 ServiceManager.SourceManager.SetActiveSource (this);
             }
         }
 
-        // A count of 0 will be hidden in the source TreeView
-        public override int Count {
-            get { return 0; }
+        private bool IsU1msUri (string uri)
+        {
+            return uri.StartsWith ("u1ms://");
         }
 
         public class StoreWrapper: UbuntuOne.U1MusicStore, IDisableKeybindings
@@ -140,7 +171,7 @@ namespace Banshee.UbuntuOneMusicStore
 
         private class CustomView : ISourceContents
         {
-            StoreWrapper store = new StoreWrapper ();
+            internal StoreWrapper store = new StoreWrapper ();
 
             public bool SetSource (ISource source) { return true; }
             public void ResetSource () { }



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