banshee r3667 - in trunk/banshee: . src src/Core/Banshee.Services/Banshee.Sources src/Dap/Banshee.Dap src/Dap/Banshee.Dap.MassStorage src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage src/Dap/Banshee.Dap/Banshee.Dap src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio



Author: gburt
Date: Fri Apr  4 02:00:50 2008
New Revision: 3667
URL: http://svn.gnome.org/viewvc/banshee?rev=3667&view=rev

Log:
2008-04-03  Gabriel Burt  <gabriel burt gmail com>

	This patch adds back the extension code from DapCore and completes the
	separation of the MassStorage support from the DapService.

	* src/Core/Banshee.Services/Banshee.Sources/Source.cs:
	* src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs:
	* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs:
	* src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs:
	* src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs: Provide a way for Sources
	to be lazily initialized with a protected virtual Initialize method that
	each subclass overrides, calling base and then its own intialization.

	* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs:
	* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs:
	Rename Initialize method so doesn't conflict with above.

	* src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml:
	Extend the DeviceClass node.

	* src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs:
	Lazily intialize, after its seen that the Initialize (IDevice) will
	succeed.

	* src/Dap/Banshee.Dap/Makefile.am:
	* src/Dap/Banshee.Dap.MassStorage/Makefile.am: Fix build.

	* src/Dap/Banshee.Dap/Banshee.Dap.addin.xml: Define DeviceClass extension
	point, from DapCore.

	* src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs: When new DAP
	DeviceClasses are loaded, check existing devices to see if they are now
	supported.

	* src/Makefile.am: Add Dap back to the build.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs
   trunk/banshee/src/Dap/Banshee.Dap/   (props changed)
   trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
   trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
   trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Makefile.am
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.addin.xml
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Makefile.am
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
   trunk/banshee/src/Makefile.am

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/DatabaseSource.cs	Fri Apr  4 02:00:50 2008
@@ -57,7 +57,7 @@
 
         protected RateLimiter reload_limiter;
         
-        private string type_unique_id;
+        protected string type_unique_id;
         protected override string TypeUniqueId {
             get { return type_unique_id; }
         }
@@ -65,6 +65,21 @@
         public DatabaseSource (string generic_name, string name, string id, int order) : base (generic_name, name, order)
         {
             type_unique_id = id;
+            DatabaseSourceInitialize ();
+        }
+
+        protected DatabaseSource () : base ()
+        {
+        }
+
+        protected override void Initialize ()
+        {
+            base.Initialize ();
+            DatabaseSourceInitialize ();
+        }
+
+        private void DatabaseSourceInitialize ()
+        {
             track_model = new TrackListDatabaseModel (ServiceManager.DbConnection, UniqueId);
             artist_model = new ArtistListDatabaseModel (track_model, ServiceManager.DbConnection, UniqueId);
             album_model = new AlbumListDatabaseModel (track_model, artist_model, ServiceManager.DbConnection, UniqueId);

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	Fri Apr  4 02:00:50 2008
@@ -113,16 +113,31 @@
 
         protected PrimarySource (string generic_name, string name, string id, int order) : base (generic_name, name, id, order)
         {
-            dbid = ServiceManager.DbConnection.Query<int> ("SELECT PrimarySourceID FROM CorePrimarySources WHERE StringID = ?", id);
+            type_unique_id = id;
+            PrimarySourceInitialize ();
+        }
+
+        protected PrimarySource () : base ()
+        {
+        }
+
+        protected override void Initialize ()
+        {
+            base.Initialize ();
+            PrimarySourceInitialize ();
+        }
+
+        private void PrimarySourceInitialize ()
+        {
+            dbid = ServiceManager.DbConnection.Query<int> ("SELECT PrimarySourceID FROM CorePrimarySources WHERE StringID = ?", TypeUniqueId);
             if (dbid == 0) {
-                dbid = ServiceManager.DbConnection.Execute ("INSERT INTO CorePrimarySources (StringID) VALUES (?)", id);
+                dbid = ServiceManager.DbConnection.Execute ("INSERT INTO CorePrimarySources (StringID) VALUES (?)", TypeUniqueId);
             }
 
             track_model.Condition = String.Format ("CoreTracks.PrimarySourceID = {0}", dbid);
 
             primary_sources[dbid] = this;
             
-            
             foreach (PlaylistSource pl in PlaylistSource.LoadAll ())
                 if (pl.PrimarySourceId == dbid)
                     AddChildSource (pl);

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 Apr  4 02:00:50 2008
@@ -65,6 +65,22 @@
             Name = name;
             Order = order;
 
+            SourceInitialize ();
+        }
+
+        protected Source ()
+        {
+        }
+
+        // This method is chained to subclasses intialize methods,
+        // allowing at any state for delayed intialization by using the empty ctor.
+        protected virtual void Initialize ()
+        {
+            SourceInitialize ();
+        }
+
+        private void SourceInitialize ()
+        {
             // If this source is not defined in Banshee.Services, set its
             // ResourceAssembly to the assembly where it is defined.
             Assembly asm = Assembly.GetAssembly (this.GetType ());//Assembly.GetCallingAssembly ();

Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage.addin.xml	Fri Apr  4 02:00:50 2008
@@ -12,11 +12,11 @@
     defaultEnabled="true">
 
   <Dependencies>
-    <Addin id="Banshee.Services" version="1.0"/>
+    <Addin id="Banshee.Dap" version="1.0"/>
   </Dependencies>
 
-  <Extension path="/Banshee/ServiceManager/Service">
-    <Service class="Banshee.Dap.MassStorage.DapService"/>
+  <Extension path="/Banshee/Dap/DeviceClass">
+    <DeviceClass class="Banshee.Dap.MassStorage.MassStorageSource"/>
   </Extension>
 
 </Addin>

Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs	Fri Apr  4 02:00:50 2008
@@ -48,9 +48,27 @@
             get { return volume; }
         }
 
-        public MassStorageSource (IVolume volume) : base (Catalog.GetString ("Media"), volume.Name ?? "Media" , volume.Uuid)
+        public MassStorageSource () : base ()
         {
-            this.volume = volume;
+        }
+
+        // Override PrimarySource's Initialize method
+        protected override void Initialize ()
+        {
+            base.Initialize ();
+        }
+
+        public override bool Initialize (IDevice device)
+        {
+            this.volume = device as IVolume;
+            if (volume == null)
+                return false;
+
+            type_unique_id = volume.Uuid;
+            Name = volume.Name;
+            GenericName = Catalog.GetString ("Media");
+
+            Initialize ();
 
             Properties.SetStringList ("Icon.Name", "harddrive");
 
@@ -67,6 +85,8 @@
                 importer.ImportFinished += delegate  { HideStatus (); };
                 importer.QueueSource (new string [] { volume.MountPoint });
             });
+
+            return true;
         }
         
         public override long BytesUsed {

Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Makefile.am
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Makefile.am	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Makefile.am	Fri Apr  4 02:00:50 2008
@@ -1,6 +1,6 @@
 ASSEMBLY = Banshee.Dap.MassStorage
 TARGET = library
-LINK = $(REF_EXTENSION_DAP_MASS_STORAGE)
+LINK = $(REF_DAP_MASS_STORAGE)
 INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
 
 SOURCES =  \

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.addin.xml
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.addin.xml	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap.addin.xml	Fri Apr  4 02:00:50 2008
@@ -3,11 +3,11 @@
     id="Banshee.Dap"
     version="1.0"
     compatVersion="1.0"
-    copyright="Â 2008 Novell Inc. Licensed under the MIT X11 license."
+    copyright="Â 2007-2008 Novell Inc. Licensed under the MIT X11 license."
     name="Digital Audio Player Support"
     category="Hardware"
     description="Provides support for Digital Audio Players."
-    author="Gabriel Burt"
+    author="Gabriel Burt, Aaron Bockover, Ruben Vermeersch"
     url="http://banshee-project.org/";
     defaultEnabled="true">
 
@@ -19,4 +19,8 @@
     <Service class="Banshee.Dap.DapService"/>
   </Extension>
 
+  <ExtensionPoint path="/Banshee/Dap/DeviceClass">
+    <ExtensionNode name="DeviceClass"/>
+  </ExtensionPoint>
+
 </Addin>

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs	Fri Apr  4 02:00:50 2008
@@ -1,10 +1,12 @@
 //
 // DapService.cs
 //
-// Author:
+// Authors:
 //   Gabriel Burt <gburt novell com>
+//   Aaron Bockover <abockover novell com>
+//   Ruben Vermeersch <ruben savanne be>
 //
-// Copyright (C) 2008 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -30,6 +32,7 @@
 using System.Collections.Generic;
 using System.Threading;
 using Mono.Unix;
+using Mono.Addins;
 
 using Hyena;
 using Banshee.Base;
@@ -44,6 +47,7 @@
     public class DapService : IExtensionService, IDisposable
     {
         private Dictionary<string, DapSource> sources;
+        private List<TypeExtensionNode> supported_dap_types = new List<TypeExtensionNode>();
         
         public DapService ()
         {
@@ -51,18 +55,31 @@
         
         public void Initialize ()
         {
-            lock (this) {
-                sources = new Dictionary<string, DapSource> ();
-                
-                foreach (IDiskDevice device in ServiceManager.HardwareManager.GetAllDiskDevices ()) {
-                    MapDiskDevice (device);
+            sources = new Dictionary<string, DapSource> ();
+            AddinManager.AddExtensionNodeHandler ("/Banshee/Dap/DeviceClass", OnExtensionChanged);
+            ServiceManager.HardwareManager.DeviceAdded += OnHardwareDeviceAdded;
+            ServiceManager.HardwareManager.DeviceRemoved += OnHardwareDeviceRemoved;
+        }
+
+        private void OnExtensionChanged (object o, ExtensionNodeEventArgs args) {
+            TypeExtensionNode node = (TypeExtensionNode) args.ExtensionNode;
+            if (args.Change == ExtensionChange.Add) {
+                Log.DebugFormat ("Dap support extension loaded: {0}", node.Addin.Id);
+                supported_dap_types.Add (node);
+
+                // See if any existing devices are handled by this new DAP support
+                foreach (IBlockDevice device in ServiceManager.HardwareManager.GetAllBlockDevices ()) {
+                    MapDevice (device);
+                    foreach (IVolume volume in device.Volumes) {
+                        MapDevice (volume);
+                    }
                 }
-                
-                ServiceManager.HardwareManager.DeviceAdded += OnHardwareDeviceAdded;
-                ServiceManager.HardwareManager.DeviceRemoved += OnHardwareDeviceRemoved;
+            } else {
+                // TODO remove/dispose all loaded DAPs of this type?
+                supported_dap_types.Remove (node);
             }
         }
-        
+
         public void Dispose ()
         {
             lock (this) {
@@ -78,28 +95,30 @@
             }
         }
         
-        private void MapDiskDevice (IDiskDevice device)
-        {
-            lock (this) {
-                foreach (IVolume volume in device) {
-                    MapDiskVolume (volume);
-                }
-            }
-        }
-        
-        private void MapDiskVolume (IVolume volume)
+        private void MapDevice (IDevice device)
         {
             lock (this) {
-                if (!volume.ShouldIgnore && volume.Parent.IsRemovable && !sources.ContainsKey (volume.Uuid)) {
-                    Log.DebugFormat ("Mapping disk device ({0}, mount point: {1})", volume.Uuid, volume.MountPoint);
-                    MassStorageSource source = new MassStorageSource (volume);
-                    sources.Add (volume.Uuid, source);
+                if (sources.ContainsKey (device.Uuid))
+                    return;
+
+                if (device is ICdromDevice || device is IDiscVolume)
+                    return;
+
+                if (device is IVolume && (device as IVolume).ShouldIgnore)
+                    return;
+
+                DapSource source = FindDeviceType (device);
+                if (source != null) {
+                    Log.DebugFormat ("Found DAP support for device {0}", source.Name);
+                    sources.Add (device.Uuid, source);
                     ServiceManager.SourceManager.AddSource (source);
+                } else {
+                    //Log.DebugFormat ("Did not find DAP support for device {0}", device.Uuid);
                 }
             }
         }
         
-        internal void UnmapDiskVolume (string uuid)
+        internal void UnmapDevice (string uuid)
         {
             lock (this) {
                 if (sources.ContainsKey (uuid)) {
@@ -114,19 +133,30 @@
         private void OnHardwareDeviceAdded (object o, DeviceAddedArgs args)
         {
             lock (this) {
-                if (args.Device is IVolume) {
-                    if ((args.Device as IVolume).Parent is IDiskDevice) {
-                        MapDiskVolume ((IVolume)args.Device);
-                    }
-                }
+                MapDevice (args.Device);
             }
         }
         
         private void OnHardwareDeviceRemoved (object o, DeviceRemovedArgs args)
         {
             lock (this) {
-                UnmapDiskVolume (args.DeviceUuid);
+                UnmapDevice (args.DeviceUuid);
+            }
+        }
+
+        private DapSource FindDeviceType (IDevice device)
+        {
+            foreach (TypeExtensionNode node in supported_dap_types) {
+                try {
+                    DapSource src = (DapSource) node.CreateInstance ();
+                    if (src.Initialize (device)) {
+                        return src;
+                    }
+                } catch (Exception e) {
+                    Log.Exception (e);
+                }
             }
+            return null;
         }
         
         string IService.ServiceName {

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	Fri Apr  4 02:00:50 2008
@@ -43,9 +43,16 @@
 {
     public abstract class DapSource : RemovableSource
     {
-        public DapSource (string name, string generic_name, string uuid) : base (generic_name, name, uuid)
+        protected DapSource () : base ()
         {
+        }
+
+        protected override void Initialize ()
+        {
+            base.Initialize ();
             Properties.SetStringList ("Icon.Name", "multimedia-player");
         }
+
+        public abstract bool Initialize (IDevice device);
     }
 }

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs	Fri Apr  4 02:00:50 2008
@@ -43,10 +43,15 @@
 {
     public abstract class RemovableSource : PrimarySource, IUnmapableSource, IDisposable
     {
-        public RemovableSource (string name, string generic_name, string uuid) : base (generic_name, name, uuid, 175)
+        protected RemovableSource () : base ()
         {
-            Name = name;
+        }
+
+        protected override void Initialize ()
+        {
+            base.Initialize ();
 
+            Order = 175;
             Properties.SetString ("UnmapSourceActionIconName", "media-eject");
             Properties.SetString ("GtkActionPath", "/RemovableSourceContextMenu");
             AfterInitialized ();

Modified: trunk/banshee/src/Dap/Banshee.Dap/Makefile.am
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Makefile.am	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Makefile.am	Fri Apr  4 02:00:50 2008
@@ -1,6 +1,6 @@
 ASSEMBLY = Banshee.Dap
 TARGET = library
-LINK = $(REF_EXTENSION_DAP)
+LINK = $(REF_DAP)
 INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
 
 SOURCES =  \

Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSource.cs	Fri Apr  4 02:00:50 2008
@@ -96,7 +96,8 @@
                 connection.UpdateNetworkState (args.Connected);
             };
 
-            Initialize ();
+            Connection.StateChanged += HandleConnectionStateChanged;
+            UpdateUI ();
 
             Properties.SetString ("ActiveSourceUIResource", "ActiveSourceUI.xml");
             Properties.SetString ("GtkActionPath", "/LastfmSourcePopup");
@@ -112,17 +113,6 @@
             ServiceManager.SourceManager.AddSource (this);
         }
 
-        public void Initialize ()
-        {
-            Connection.StateChanged += HandleConnectionStateChanged;
-            
-            /*if (Account.UserName != null && Account.CryptedPassword != null) {
-                Connection.Connect ();
-            }*/
-            
-            UpdateUI ();
-        }
-
         public void Dispose ()
         {
             Connection.StateChanged -= HandleConnectionStateChanged;

Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs	Fri Apr  4 02:00:50 2008
@@ -106,7 +106,7 @@
             PlayCount = playCount;
             Station = Type.GetStationFor (arg);
 
-            Initialize ();
+            StationInitialize ();
         }
 
         public StationSource (LastfmSource lastfm, string name, string type, string arg) : base (generic_name, name, 150)
@@ -118,10 +118,10 @@
 
             Save ();
 
-            Initialize ();
+            StationInitialize ();
         }
 
-        private void Initialize ()
+        private void StationInitialize ()
         {
             track_model = new MemoryTrackListModel ();
 

Modified: trunk/banshee/src/Makefile.am
==============================================================================
--- trunk/banshee/src/Makefile.am	(original)
+++ trunk/banshee/src/Makefile.am	Fri Apr  4 02:00:50 2008
@@ -3,6 +3,7 @@
 	Core \
 	Clients \
 	Backends \
+	Dap \
 	Extensions
 
 EXTRA_DIST = AssemblyInfo.cs.in



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