[banshee/gio-hardware] Implement country selection for Amazon MP3 Store



commit 7da57fdac92268eb8f2aec05ad1ed0594fa6dcf5
Author: Aaron Bockover <abockover novell com>
Date:   Mon Jul 19 16:27:51 2010 -0400

    Implement country selection for Amazon MP3 Store
    
    Allows for manually overriding the geo-IP based automatic storefront
    redirection to allow the user to force-visit store fronts based on
    country.

 .../Banshee.AmazonMp3.Store.csproj                 |    5 +-
 .../Banshee.AmazonMp3.Store/SignOutButton.cs       |   57 ++++++++++++++++++++
 .../Banshee.AmazonMp3.Store/StoreSource.cs         |   12 ++++-
 .../StoreSourcePreferences.cs                      |   57 +++++++++++++++++++-
 .../Banshee.AmazonMp3.Store/StoreView.cs           |    2 +
 .../StoreWebBrowserShell.cs                        |   17 +-----
 src/Extensions/Banshee.AmazonMp3.Store/Makefile.am |    1 +
 7 files changed, 130 insertions(+), 21 deletions(-)
---
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj
index 7d08a05..c7ca8d9 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.csproj
@@ -54,9 +54,6 @@
     <EmbeddedResource Include="Banshee.AmazonMp3.Store.addin.xml">
       <LogicalName>Banshee.AmazonMp3.Store.addin.xml</LogicalName>
     </EmbeddedResource>
-    <EmbeddedResource Include="Resources\loading.html">
-      <LogicalName>loading.html</LogicalName>
-    </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Banshee.AmazonMp3.Store\" />
@@ -116,5 +113,7 @@
     <Compile Include="Banshee.AmazonMp3.Store\StoreSource.cs" />
     <Compile Include="Banshee.AmazonMp3.Store\StoreView.cs" />
     <Compile Include="Banshee.AmazonMp3.Store\StoreWebBrowserShell.cs" />
+    <Compile Include="Banshee.AmazonMp3.Store\StoreSourcePreferences.cs" />
+    <Compile Include="Banshee.AmazonMp3.Store\SignOutButton.cs" />
   </ItemGroup>
 </Project>
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/SignOutButton.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/SignOutButton.cs
new file mode 100644
index 0000000..e70989e
--- /dev/null
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/SignOutButton.cs
@@ -0,0 +1,57 @@
+// 
+// SignOutButton.cs
+// 
+// Author:
+//   Aaron Bockover <abockover novell com>
+// 
+// Copyright 2010 Novell, Inc.
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+using Mono.Unix;
+using Gtk;
+
+namespace Banshee.AmazonMp3.Store
+{
+    public class SignOutButton : Button
+    {
+        private StoreView store_view;
+
+        public SignOutButton (StoreView storeView) : base (Catalog.GetString ("Sign out of Amazon"))
+        {
+            store_view = storeView;
+            store_view.SignInChanged += (o, e) => UpdateSignInButton ();
+            UpdateSignInButton ();
+        }
+
+        protected override void OnClicked ()
+        {
+            base.OnClicked ();
+            store_view.SignOut ();
+        }
+
+        private void UpdateSignInButton ()
+        {
+            Visible = store_view.IsSignedIn;
+        }
+    }
+}
+
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs
index 766f8e3..84c5a20 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSource.cs
@@ -29,12 +29,16 @@ using Mono.Unix;
 
 using Hyena;
 
+using Banshee.WebSource;
+
 namespace Banshee.AmazonMp3.Store
 {
     public class StoreSource : Banshee.WebSource.WebSource, IDisposable
     {
         private StoreSourcePreferences preferences;
 
+        public StoreWebBrowserShell Shell { get; private set; }
+
         public StoreSource () : base (Catalog.GetString ("Amazon MP3 Store"), 150, "amazon-mp3-store")
         {
             preferences = new StoreSourcePreferences (this);
@@ -49,9 +53,13 @@ namespace Banshee.AmazonMp3.Store
             }
         }
 
-        protected override Banshee.WebSource.WebBrowserShell GetWidget ()
+        protected override WebBrowserShell GetWidget ()
         {
-            return new StoreWebBrowserShell (new StoreView ());
+            return (Shell = new StoreWebBrowserShell (new StoreView ()));
+        }
+
+        public override string PreferencesPageId {
+            get { return preferences == null ? null : preferences.PreferencesPageId; }
         }
     }
 }
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSourcePreferences.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSourcePreferences.cs
index 34ea66d..27694d7 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSourcePreferences.cs
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreSourcePreferences.cs
@@ -26,15 +26,20 @@
 
 using System;
 
+using Mono.Unix;
+
 using Banshee.ServiceStack;
 using Banshee.Preferences;
+using Banshee.Configuration;
 
 namespace Banshee.AmazonMp3.Store
 {
     public class StoreSourcePreferences : IDisposable
     {
-       // private StoreSource source;
+        private StoreSource source;
         private SourcePage source_page;
+        private PreferenceBase country_pref;
+        // private PreferenceBase logout_pref;
 
         public StoreSourcePreferences (StoreSource source)
         {
@@ -43,10 +48,22 @@ namespace Banshee.AmazonMp3.Store
                 return;
             }
 
-          //  this.source = source;
+            this.source = source;
 
             service.InstallWidgetAdapters += OnPreferencesServiceInstallWidgetAdapters;
+
             source_page = new SourcePage (source);
+
+            var country_section = source_page.Add (new Section ("country", Catalog.GetString ("Country"), 20));
+            country_section.Add (country_pref = new SchemaPreference<string> (StoreCountry,
+                null,
+                Catalog.GetString ("Which Amazon MP3 storefront to use by default.")));
+
+            /*var session_section = source_page.Add (new Section ("session", Catalog.GetString ("Session"), 30));
+            session_section.Add (new SchemaPreference<bool> (PersistLogin,
+                Catalog.GetString ("_Keep me logged in"),
+                Catalog.GetString ("Keep any session cookies that Amazon MP3 may set across instances.")));
+            session_section.Add (logout_pref = new VoidPreference ("log-out-button"));*/
         }
 
         public void Dispose ()
@@ -63,7 +80,43 @@ namespace Banshee.AmazonMp3.Store
 
         private void OnPreferencesServiceInstallWidgetAdapters (object sender, EventArgs args)
         {
+            /*if (source != null && source.Shell != null && source.Shell.StoreView != null) {
+                logout_pref.DisplayWidget = new SignOutButton (source.Shell.StoreView);
+            }*/
+
+            var combo = new Banshee.Widgets.DictionaryComboBox<string> ();
+            combo.Add (Catalog.GetString ("Automatic (Geo IP detection)"), "geo");
+            combo.Add (null, null);
+            combo.Add (Catalog.GetString ("France (amazon.fr)"), "FR");
+            combo.Add (Catalog.GetString ("Germany, Switzerland, Austria (amazon.de)"), "DE");
+            combo.Add (Catalog.GetString ("Japan (amazon.co.jp)"), "JP");
+            combo.Add (Catalog.GetString ("United Kingdom (amazon.co.uk)"), "UK");
+            combo.Add (Catalog.GetString ("United States (amazon.com)"), "US");
+            combo.RowSeparatorFunc = (model, iter) => model.GetValue (iter, 0) == null;
+            combo.ActiveValue = StoreCountry.Get ();
+            combo.Changed += (o, e) => {
+                StoreCountry.Set (combo.ActiveValue);
+                if (source != null && source.Shell != null && source.Shell.StoreView != null) {
+                    source.Shell.StoreView.Country = combo.ActiveValue;
+                    source.Shell.StoreView.GoHome ();
+                }
+            };
+            country_pref.DisplayWidget = combo;
         }
+
+        public string PreferencesPageId {
+            get { return source_page == null ? null : source_page.Id; }
+        }
+
+        public static readonly SchemaEntry<string> StoreCountry = new SchemaEntry<string> (
+            "plugins.amazonmp3store", "country",
+            "geo",
+            "Which store front to use (\"geo\" for auto-detect, US, UK, FR, DE, or JP", null);
+
+        public static readonly SchemaEntry<bool> PersistLogin = new SchemaEntry<bool> (
+            "plugins.amazonmp3store", "persist-login",
+            true,
+            "Persist the Amazon MP3 store account login across sessions (via cookies)", null);
     }
 }
 
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs
index e0105a2..b94e611 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreView.cs
@@ -66,6 +66,8 @@ namespace Banshee.AmazonMp3.Store
                 AmzMp3Downloader.AmazonMp3DownloaderCompatVersion,
                 ".amazon.com", "/", TimeSpan.FromDays (365.2422));
 
+            Country = StoreSourcePreferences.StoreCountry.Get ();
+
             CheckSignIn ();
             FullReload ();
         }
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs
index 0218d23..ad2fc14 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store/StoreWebBrowserShell.cs
@@ -29,35 +29,24 @@ using System;
 using Gtk;
 using Mono.Unix;
 
-using Banshee.WebBrowser;
-
 namespace Banshee.AmazonMp3.Store
 {
     public class StoreWebBrowserShell : Banshee.WebSource.WebBrowserShell
     {
-        private StoreView store_view;
-        private Button sign_out_button = new Button (Catalog.GetString ("Sign out of Amazon")) { Relief = ReliefStyle.None };
+        public StoreView StoreView { get; private set; }
 
         public StoreWebBrowserShell (StoreView store_view) : base (Catalog.GetString ("Amazon MP3 Store"), store_view)
         {
-            this.store_view = store_view;
-            sign_out_button.Clicked += (o, e) => store_view.SignOut ();
+            StoreView = store_view;
 
-            Attach (sign_out_button, 2, 3, 0, 1,
+            Attach (new SignOutButton (StoreView) { Relief = ReliefStyle.None }, 2, 3, 0, 1,
                 AttachOptions.Shrink,
                 AttachOptions.Shrink,
                 0, 0);
 
             SearchEntry.EmptyMessage = String.Format (Catalog.GetString ("Search the Amazon MP3 Store"));
 
-            store_view.SignInChanged += (o, e) => UpdateSignInButton ();
             ShowAll ();
-            UpdateSignInButton ();
-        }
-
-        private void UpdateSignInButton ()
-        {
-            sign_out_button.Visible = store_view.IsSignedIn;
         }
     }
 }
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am b/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am
index 0435529..b98caa5 100644
--- a/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am
+++ b/src/Extensions/Banshee.AmazonMp3.Store/Makefile.am
@@ -4,6 +4,7 @@ LINK = $(REF_EXTENSION_AMAZONMP3_STORE)
 INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
 
 SOURCES =  \
+	Banshee.AmazonMp3.Store/SignOutButton.cs \
 	Banshee.AmazonMp3.Store/StoreSource.cs \
 	Banshee.AmazonMp3.Store/StoreSourcePreferences.cs \
 	Banshee.AmazonMp3.Store/StoreView.cs \



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