[banshee] Refactor some model classes



commit 940094497b41a240e4d9a2ba8d2cf3f14d1fdcdb
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Wed Jul 1 15:44:29 2009 -0500

    Refactor some model classes

 .../Banshee.Collection/BansheeListModel.cs         |   77 +++++-----------
 .../Banshee.Collection/ExportableModel.cs          |   54 -----------
 src/Core/Banshee.Services/Makefile.am              |    1 -
 src/Libraries/Hyena/Hyena.Data/BaseListModel.cs    |   97 ++++++++++++++++++++
 src/Libraries/Hyena/Makefile.am                    |    1 +
 5 files changed, 120 insertions(+), 110 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection/BansheeListModel.cs b/src/Core/Banshee.Services/Banshee.Collection/BansheeListModel.cs
index c653e06..896e089 100644
--- a/src/Core/Banshee.Services/Banshee.Collection/BansheeListModel.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection/BansheeListModel.cs
@@ -1,5 +1,5 @@
 //
-// ListModel.cs
+// BansheeListModel.cs
 //
 // Author:
 //   Aaron Bockover <abockover novell com>
@@ -35,73 +35,40 @@ using Banshee.ServiceStack;
 
 namespace Banshee.Collection
 {
-    public abstract class BansheeListModel<T> : ExportableModel, IListModel<T>
+    public abstract class BansheeListModel<T> : BaseListModel<T>, IDBusExportable
     {
-        protected Selection selection;
+        private IDBusExportable parent;
 
-        public event EventHandler Cleared;
-        public event EventHandler Reloaded;
-
-        public BansheeListModel () : base ()
-        {
-        }
-        
-        public BansheeListModel (IDBusExportable parent) : base (parent)
-        {
-        }
-        
-        protected virtual void OnCleared ()
+        public BansheeListModel ()
         {
-            Banshee.Base.ThreadAssist.ProxyToMain (delegate {
-                EventHandler handler = Cleared;
-                if(handler != null) {
-                    handler(this, EventArgs.Empty);
-                }
-            });
-        }
-        
-        protected virtual void OnReloaded ()
-        {
-            Banshee.Base.ThreadAssist.ProxyToMain (delegate {
-                EventHandler handler = Reloaded;
-                if(handler != null) {
-                    handler(this, EventArgs.Empty);
-                }
-            });
         }
 
-        public void RaiseReloaded ()
+        public BansheeListModel (IDBusExportable parent)
         {
-            OnReloaded ();
+            Parent = parent;
         }
-        
-        public abstract void Clear();
-        
-        public abstract void Reload();
-    
-        public abstract T this[int index] { get; }
-
-        public abstract int Count { get; }
 
-        public virtual Selection Selection {
-            get { return selection; }
+        public virtual string ServiceName {
+            get { return GetType().Name; }
         }
 
-        protected ModelSelection<T> model_selection;
-        public virtual ModelSelection<T> SelectedItems {
-            get {
-                return model_selection ?? (model_selection = new ModelSelection<T> (this, Selection));
-            }
+        public virtual IDBusExportable Parent {
+            set { parent = value; }
+            get { return parent; }
         }
-        
-        public T FocusedItem {
-            get { return Selection.FocusedIndex == -1 ? default(T) : this[Selection.FocusedIndex]; }
+
+        protected override void OnCleared ()
+        {
+            Banshee.Base.ThreadAssist.ProxyToMain (delegate {
+                base.OnCleared ();
+            });
         }
 
-        private bool can_reorder = false;
-        public bool CanReorder {
-            get { return can_reorder; }
-            set { can_reorder = value; }
+        protected override void OnReloaded ()
+        {
+            Banshee.Base.ThreadAssist.ProxyToMain (delegate {
+                base.OnReloaded ();
+            });
         }
     }
 }
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index 3bff0de..9e776fd 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -38,7 +38,6 @@ SOURCES =  \
 	Banshee.Collection/AlbumListModel.cs \
 	Banshee.Collection/ArtistListModel.cs \
 	Banshee.Collection/BansheeListModel.cs \
-	Banshee.Collection/ExportableModel.cs \
 	Banshee.Collection/FilterListModel.cs \
 	Banshee.Collection/IExportableModel.cs \
 	Banshee.Collection/IFilterListModel.cs \
diff --git a/src/Libraries/Hyena/Hyena.Data/BaseListModel.cs b/src/Libraries/Hyena/Hyena.Data/BaseListModel.cs
new file mode 100644
index 0000000..4066059
--- /dev/null
+++ b/src/Libraries/Hyena/Hyena.Data/BaseListModel.cs
@@ -0,0 +1,97 @@
+//
+// BaseListModel.cs
+//
+// Author:
+//   Gabriel Burt <gburt novell com>
+//   Aaron Bockover <abockover novell com>
+//
+// 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
+// "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 Hyena.Collections;
+
+namespace Hyena.Data
+{
+    public abstract class BaseListModel<T> : IListModel<T>
+    {
+        protected Selection selection;
+
+        public event EventHandler Cleared;
+        public event EventHandler Reloaded;
+
+        public BaseListModel () : base ()
+        {
+        }
+        
+        protected virtual void OnCleared ()
+        {
+            EventHandler handler = Cleared;
+            if(handler != null) {
+                handler(this, EventArgs.Empty);
+            }
+        }
+        
+        protected virtual void OnReloaded ()
+        {
+            EventHandler handler = Reloaded;
+            if(handler != null) {
+                handler(this, EventArgs.Empty);
+            }
+        }
+
+        public void RaiseReloaded ()
+        {
+            OnReloaded ();
+        }
+        
+        public abstract void Clear();
+        
+        public abstract void Reload();
+    
+        public abstract T this[int index] { get; }
+
+        public abstract int Count { get; }
+
+        public virtual Selection Selection {
+            get { return selection; }
+        }
+
+        protected ModelSelection<T> model_selection;
+        public virtual ModelSelection<T> SelectedItems {
+            get {
+                return model_selection ?? (model_selection = new ModelSelection<T> (this, Selection));
+            }
+        }
+        
+        public T FocusedItem {
+            get { return Selection.FocusedIndex == -1 ? default(T) : this[Selection.FocusedIndex]; }
+        }
+
+        private bool can_reorder = false;
+        public bool CanReorder {
+            get { return can_reorder; }
+            set { can_reorder = value; }
+        }
+    }
+}
diff --git a/src/Libraries/Hyena/Makefile.am b/src/Libraries/Hyena/Makefile.am
index 9a4699e..0e6f070 100644
--- a/src/Libraries/Hyena/Makefile.am
+++ b/src/Libraries/Hyena/Makefile.am
@@ -33,6 +33,7 @@ SOURCES =  \
 	Hyena.Data.Sqlite/Tests/SqliteModelProviderTests.cs \
 	Hyena.Data.Sqlite/Tests/SqliteUtilTests.cs \
 	Hyena.Data/ArrayModelCache.cs \
+	Hyena.Data/BaseListModel.cs \
 	Hyena.Data/ColumnDescription.cs \
 	Hyena.Data/DictionaryModelCache.cs \
 	Hyena.Data/ICacheableItem.cs \



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