[banshee] Support default internet radio stations (bgo#548197)



commit 8b73d84c147ab9cfb0cc8bd352c55cf664c2dc8c
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Fri Jun 24 15:08:30 2011 +0200

    Support default internet radio stations (bgo#548197)
    
    At first start, read DATADIR/stations/*.xspf and import them into the user DB
    in the InternetRadio extension. This allows distros or admins to provide
    some default radio stations; since we support multiple ones, these can
    even be locale specific when language packs or region specific packages
    install them.
    
    We only look once for those xspf files, on the first start, and never
    again, even if there were no files found or errors while loading the
    files.
    
    Signed-off-by: Bertrand Lorentz <bertrand lorentz gmail com>

 .../Banshee.InternetRadio/InternetRadioSource.cs   |    3 +-
 .../Banshee.InternetRadio/XspfMigrator.cs          |   25 ++++++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs
index 78011f2..e0381c7 100644
--- a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs
+++ b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs
@@ -144,7 +144,8 @@ namespace Banshee.InternetRadio
                     radio_track.ParentTrack as DatabaseTrackInfo, a);
             };
 
-            if (new XspfMigrator (this).Migrate ()) {
+            var migrator = new XspfMigrator (this);
+            if (migrator.Migrate () | migrator.LoadDefaults ()) {
                 Reload ();
             }
         }
diff --git a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/XspfMigrator.cs b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/XspfMigrator.cs
index 345ff92..2ae850b 100644
--- a/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/XspfMigrator.cs
+++ b/src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/XspfMigrator.cs
@@ -49,6 +49,27 @@ namespace Banshee.InternetRadio
             this.source = source;
         }
 
+        public bool LoadDefaults ()
+        {
+            // Load system-wide defaults into user DB on first start
+            if (DatabaseConfigurationClient.Client.Get<bool> ("InternetRadio.SystemXspfLoaded", false)) {
+                return false;
+            }
+            DatabaseConfigurationClient.Client.Set<bool> ("InternetRadio.SystemXspfLoaded", true);
+
+            string xspf_system_path = Hyena.Paths.GetInstalledDataDirectory ("stations");
+            try {
+                foreach (string file in Directory.GetFiles (xspf_system_path, "*.xspf")) {
+                    Log.DebugFormat ("Loading default Internet Radio Stations from {0}", file);
+                    MigrateXspf (file);
+                }
+            } catch (Exception e) {
+                Log.Exception ("Error loading Internet Radio Stations from system default", e);
+            }
+
+            return true;
+        }
+
         public bool Migrate ()
         {
             if (DatabaseConfigurationClient.Client.Get<bool> ("InternetRadio.LegacyXspfMigrated", false)) {
@@ -68,7 +89,7 @@ namespace Banshee.InternetRadio
                     MigrateXspf (file);
                 }
             } catch (Exception e) {
-                Hyena.Log.Exception ("Migrating Internet Radio Stations", e);
+                Log.Exception ("Error migrating Internet Radio Stations", e);
             }
 
             return true;
@@ -88,7 +109,7 @@ namespace Banshee.InternetRadio
                     }
                 }
             } catch (Exception e) {
-                Log.Exception ("Could not migrat XSPF playlist", e);
+                Log.Exception ("Could not migrate XSPF playlist", e);
             }
         }
 



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