[banshee] [Last.fm] Start move of auth dialog to Preferences



commit 5d4b44ae52988f29bc588e77d83edd3b9370dc31
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Mon Nov 9 23:07:55 2009 -0800

    [Last.fm] Start move of auth dialog to Preferences

 .../Banshee.Lastfm.Radio/LastfmSource.cs           |   81 ++++++++++++++++++++
 .../Banshee.Lastfm.Radio/StationSource.cs          |    2 +-
 .../Banshee.Lastfm/Resources/GlobalUI.xml          |    2 +-
 3 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
index fa4ab92..a81589e 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
@@ -42,6 +42,7 @@ using Banshee.Sources;
 using Banshee.MediaEngine;
 using Banshee.ServiceStack;
 using Banshee.Networking;
+using Banshee.Preferences;
 
 using Banshee.Sources.Gui;
 
@@ -109,6 +110,7 @@ namespace Banshee.Lastfm.Radio
             Properties.Set<bool> ("Nereid.SourceContents.HeaderVisible", false);
 
             actions = new LastfmActions (this);
+            InstallPreferences ();
 
             ServiceManager.SourceManager.AddSource (this);
 
@@ -120,6 +122,7 @@ namespace Banshee.Lastfm.Radio
             ServiceManager.Get<DBusCommandService> ().ArgumentPushed -= OnCommandLineArgument;
             Connection.StateChanged -= HandleConnectionStateChanged;
             Connection.Dispose ();
+            UninstallPreferences ();
             actions.Dispose ();
             
             actions = null;
@@ -263,6 +266,84 @@ namespace Banshee.Lastfm.Radio
             status_message.ThawNotify ();
         }
 
+        private SourcePage pref_page;
+        private Section pref_section;
+
+        private void InstallPreferences ()
+        {
+            PreferenceService service = ServiceManager.Get<PreferenceService> ();
+            if (service == null) {
+                return;
+            }
+
+            service.InstallWidgetAdapters += OnPreferencesServiceInstallWidgetAdapters;
+            pref_page = new Banshee.Preferences.SourcePage (this);
+            pref_section = pref_page.Add (new Section ("mediatypes", Catalog.GetString ("Account"), 20));
+            pref_section.ShowLabel = false;
+
+            pref_section.Add (new SchemaPreference<string> (LastUserSchema,
+                Catalog.GetString ("_Username"), Catalog.GetString ("")));
+            pref_section.Add (new VoidPreference ("lastfm-auth-banshee"));
+            pref_section.Add (new VoidPreference ("lastfm-authorized"));
+        }
+
+        private void UninstallPreferences ()
+        {
+            PreferenceService service = ServiceManager.Get<PreferenceService> ();
+            if (service == null || pref_page == null) {
+                return;
+            }
+
+            service.InstallWidgetAdapters -= OnPreferencesServiceInstallWidgetAdapters;
+            pref_page.Dispose ();
+            pref_page = null;
+        }
+
+        private void OnPreferencesServiceInstallWidgetAdapters (object o, EventArgs args)
+        {
+            if (pref_section == null) {
+                return;
+            }
+
+            var auth_button = new Gtk.Button (Catalog.GetString ("Authorize Banshee with Last.fm"));
+            auth_button.Clicked += delegate {
+                account.SessionKey = null;
+                account.RequestAuthorization ();
+            };
+
+            var auth_label = new Gtk.Label (String.IsNullOrEmpty (account.UserName) || account.SessionKey == null
+                    ? Catalog.GetString ("Banshee not authorized")
+                    : Catalog.GetString ("Banshee authorized!")) {
+                Xalign = 0f
+            };
+
+            var auth_refresh_button = new Gtk.Button (Gtk.Stock.Refresh);
+            auth_refresh_button.Clicked += delegate {
+                if (String.IsNullOrEmpty (account.UserName) || account.SessionKey == null) {
+                    account.UserName = LastUserSchema.Get ();
+                    account.FetchSessionKey ();
+                    account.Save ();
+                    LastSessionKeySchema.Set (account.SessionKey);
+                }
+
+                auth_label.Text = account.SessionKey != null
+                    ? Catalog.GetString ("Banshee authorized!")
+                    : Catalog.GetString ("Banshee not authorized");
+            };
+
+            var auth_box = new Gtk.HBox ();
+            auth_box.PackStart (auth_button, false, false, 0);
+            auth_box.PackEnd (auth_refresh_button, false, false, 0);
+            auth_box.ShowAll ();
+
+            pref_section["lastfm-auth-banshee"].DisplayWidget = auth_box;
+            pref_section["lastfm-authorized"].DisplayWidget = auth_label;
+        }
+
+        public override string PreferencesPageId {
+            get { return pref_page.Id; }
+        }
+
         public static readonly SchemaEntry<bool> EnabledSchema = new SchemaEntry<bool> (
             "plugins.lastfm", "enabled", false, "Extension enabled", "Last.fm extension enabled"
         );
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
index e74426f..d03d3f0 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
@@ -544,7 +544,7 @@ namespace Banshee.Lastfm.Radio
         public override bool HasProperties {
             get { return true; }
         }
-        
+
         public static List<StationSource> LoadAll (LastfmSource lastfm, string creator)
         {
             List<StationSource> stations = new List<StationSource> ();
diff --git a/src/Extensions/Banshee.Lastfm/Resources/GlobalUI.xml b/src/Extensions/Banshee.Lastfm/Resources/GlobalUI.xml
index 2393f24..50025e0 100644
--- a/src/Extensions/Banshee.Lastfm/Resources/GlobalUI.xml
+++ b/src/Extensions/Banshee.Lastfm/Resources/GlobalUI.xml
@@ -4,7 +4,7 @@
         <menuitem name="Connect" action="LastfmConnectAction" />
         <menu name='SortChildren' action='SortChildrenAction' />
         <separator />
-        <menuitem name="SourceProperties" action="SourcePropertiesAction" />
+        <menuitem name="SourcePreferences" action="SourcePreferencesAction"/>
     </popup>
 
     <popup name="LastfmStationSourcePopup" action="LastfmStationSourcePopupAction">



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