[f-spot/hyena-models: 3/6] Add DatabasePhotoListModel



commit 791e485202ca0d63c9a14b3fa75e098061aecc02
Author: Mike Gemünde <mike gemuende de>
Date:   Mon Oct 4 10:51:52 2010 +0200

    Add DatabasePhotoListModel

 .../FSpot.Database/DatabasePhotoListModel.cs       |  177 ++++++++++++++++++++
 .../FSpot.Database/DatabasePhotoModelCache.cs      |   30 ++++
 src/Clients/MainApp/MainApp.csproj                 |    2 +
 src/Clients/MainApp/Makefile.am                    |    2 +
 src/Core/FSpot.Core/FSpot.Core.csproj              |    1 +
 src/Core/FSpot.Core/FSpot.Core/IPhotoListModel.cs  |   25 +++
 src/Core/FSpot.Core/Makefile.am                    |    1 +
 7 files changed, 238 insertions(+), 0 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.Database/DatabasePhotoListModel.cs b/src/Clients/MainApp/FSpot.Database/DatabasePhotoListModel.cs
new file mode 100644
index 0000000..8c18b17
--- /dev/null
+++ b/src/Clients/MainApp/FSpot.Database/DatabasePhotoListModel.cs
@@ -0,0 +1,177 @@
+//
+// DatabasePhotoListModel.cs
+//
+// Author:
+//   Mike Gemuende <mike gemuende de>
+//
+// Copyright (c) 2010 Mike Gemuende <mike gemuende de>
+//
+// This is free software. See COPYING for details.
+//
+
+using System;
+
+using Hyena;
+using Hyena.Data;
+using Hyena.Data.Sqlite;
+using Hyena.Collections;
+
+using System.Text;
+using System.Collections.Generic;
+
+using FSpot;
+using FSpot.Core;
+using FSpot.Query;
+
+namespace FSpot.Database
+{
+
+
+    public class DatabasePhotoListModel
+        : BaseListModel<IPhoto>, ICacheableDatabaseModel, IPhotoListModel, IBrowsableCollection
+    {
+#region Private Fields
+
+        private DatabasePhotoModelCache cache;
+        private int filtered_count;
+
+#endregion
+
+#region Constructors
+
+        public DatabasePhotoListModel (HyenaSqliteConnection connection, string uuid, PhotoModelProvider provider)
+        {
+            Selection = new Selection ();// new PhotoSelection (this);
+            cache = new DatabasePhotoModelCache (connection, uuid, this, provider);
+        }
+
+#endregion
+
+
+#region IPhotoListModel implementation
+
+        public override IPhoto this[int index] {
+            get {
+                lock (this) {
+                    return cache.GetValue (index);
+                }
+            }
+        }
+
+        public override int Count {
+            get { return filtered_count; }
+        }
+
+        public override void Reload ()
+        {
+            UpdateReloadFragment ();
+
+            cache.SaveSelection ();
+            cache.Reload ();
+            cache.RestoreSelection ();
+            cache.UpdateAggregates ();
+
+            filtered_count = (int)cache.Count;
+
+            OnReloaded ();
+        }
+
+        public override void Clear ()
+        {
+            cache.Clear ();
+            filtered_count = 0;
+
+            OnCleared ();
+        }
+
+#endregion
+
+#region Private Methods
+
+        private void UpdateReloadFragment ()
+        {
+            StringBuilder query_builder = new StringBuilder ("FROM photos ");
+
+            ReloadFragment = query_builder.ToString ();
+        }
+
+#endregion
+
+#region ICacheableDatabaseModel Implementation
+
+        public int FetchCount {
+            get { return 200; }
+        }
+
+        public string ReloadFragment { get; private set; }
+
+        public string SelectAggregates {
+            get { return null; }
+        }
+
+        public string JoinTable {
+            get { return null; }
+        }
+
+        public string JoinFragment {
+            get { return null; }
+        }
+
+        public string JoinPrimaryKey {
+            get { return null; }
+        }
+
+        public string JoinColumn {
+            get { return null; }
+        }
+
+        public bool CachesJoinTableEntries {
+            get { return false; }
+        }
+
+        public bool CachesValues {
+            get { return false; }
+        }
+
+#endregion
+
+#region IBrowsableCollection Compatibility
+
+        public IPhoto[] Items {
+            get {
+                throw new NotSupportedException ();
+            }
+        }
+
+        public void MarkChanged (int index, IBrowsableItemChanges changes)
+        {
+            throw new System.NotImplementedException ();
+        }
+
+        public bool Contains (IPhoto item)
+        {
+            DatabasePhoto photo = item as DatabasePhoto;
+
+            if (photo == null)
+                return false;
+
+            if (photo.CacheModelId != cache.CacheId)
+                return false;
+
+            return cache.ContainsKey (photo.Id);
+        }
+
+        //public PhotoSelection Selection { get; protected set; }
+
+        public event IBrowsableCollectionChangedHandler Changed;
+        public event IBrowsableCollectionItemsChangedHandler ItemsChanged;
+
+        public int IndexOf (IPhoto item)
+        {
+            return (int)cache.IndexOf (item);
+        }
+
+#endregion
+
+    }
+}
diff --git a/src/Clients/MainApp/FSpot.Database/DatabasePhotoModelCache.cs b/src/Clients/MainApp/FSpot.Database/DatabasePhotoModelCache.cs
new file mode 100644
index 0000000..c6d78c7
--- /dev/null
+++ b/src/Clients/MainApp/FSpot.Database/DatabasePhotoModelCache.cs
@@ -0,0 +1,30 @@
+//
+// DatabasePhotoModelCache.cs
+//
+// Author:
+//   Mike Gemuende <mike gemuende de>
+// 
+// Copyright (c) 2010 Mike Gemuende <mike gemuende de>
+//
+// This is free software. See COPYING for details.
+//
+
+using System;
+
+using Hyena.Data.Sqlite;
+
+
+namespace FSpot.Database
+{
+
+    public class DatabasePhotoModelCache : SqliteModelCache<DatabasePhoto>
+    {
+#region Constructors
+
+        public DatabasePhotoModelCache (HyenaSqliteConnection connection, string uuid, ICacheableDatabaseModel model, PhotoModelProvider provider) : base(connection, uuid, model, provider)
+        {
+        }
+        
+        #endregion
+    }
+}
diff --git a/src/Clients/MainApp/MainApp.csproj b/src/Clients/MainApp/MainApp.csproj
index 0fc2bb4..c62bef8 100644
--- a/src/Clients/MainApp/MainApp.csproj
+++ b/src/Clients/MainApp/MainApp.csproj
@@ -210,6 +210,8 @@
     <Compile Include="FSpot.Database\PhotoModelProvider.cs" />
     <Compile Include="FSpot.Database\PhotoVersionModelProvider.cs" />
     <Compile Include="FSpot.Database\DatabaseSource.cs" />
+    <Compile Include="FSpot.Database\DatabasePhotoListModel.cs" />
+    <Compile Include="FSpot.Database\DatabasePhotoModelCache.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="..\..\..\COPYING">
diff --git a/src/Clients/MainApp/Makefile.am b/src/Clients/MainApp/Makefile.am
index 1aa85d9..bd4f594 100644
--- a/src/Clients/MainApp/Makefile.am
+++ b/src/Clients/MainApp/Makefile.am
@@ -11,6 +11,8 @@ SOURCES =  \
 	FSpot.ColorAdjustment/FullColorAdjustment.cs \
 	FSpot.ColorAdjustment/SepiaTone.cs \
 	FSpot.Database/DatabasePhoto.cs \
+	FSpot.Database/DatabasePhotoListModel.cs \
+	FSpot.Database/DatabasePhotoModelCache.cs \
 	FSpot.Database/DatabasePhotoVersion.cs \
 	FSpot.Database/DatabaseSource.cs \
 	FSpot.Database/Db.cs \
diff --git a/src/Core/FSpot.Core/FSpot.Core.csproj b/src/Core/FSpot.Core/FSpot.Core.csproj
index 724fdcd..965b6d1 100644
--- a/src/Core/FSpot.Core/FSpot.Core.csproj
+++ b/src/Core/FSpot.Core/FSpot.Core.csproj
@@ -46,6 +46,7 @@
     <Compile Include="FSpot.Core\PhotoList.cs" />
     <Compile Include="FSpot.Core\ISource.cs" />
     <Compile Include="FSpot.Core\IPhotoSource.cs" />
+    <Compile Include="FSpot.Core\IPhotoListModel.cs" />
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>
diff --git a/src/Core/FSpot.Core/FSpot.Core/IPhotoListModel.cs b/src/Core/FSpot.Core/FSpot.Core/IPhotoListModel.cs
new file mode 100644
index 0000000..938a812
--- /dev/null
+++ b/src/Core/FSpot.Core/FSpot.Core/IPhotoListModel.cs
@@ -0,0 +1,25 @@
+//
+// IPhotoListModel.cs
+//
+// Author:
+//   Mike Gemuende <mike gemuende de>
+// 
+// Copyright (c) 2010 Mike Gemuende <mike gemuende de>
+//
+// This is free software. See COPYING for details.
+//
+
+using System;
+
+using FSpot;
+
+using Hyena.Data;
+
+
+namespace FSpot.Core
+{
+
+    public interface IPhotoListModel : IListModel<IPhoto>
+    {
+    }
+}
diff --git a/src/Core/FSpot.Core/Makefile.am b/src/Core/FSpot.Core/Makefile.am
index 2539a97..914866c 100644
--- a/src/Core/FSpot.Core/Makefile.am
+++ b/src/Core/FSpot.Core/Makefile.am
@@ -18,6 +18,7 @@ SOURCES =  \
 	FSpot.Core/IPhoto.cs \
 	FSpot.Core/IPhotoComparer.cs \
 	FSpot.Core/IPhotoExtensions.cs \
+	FSpot.Core/IPhotoListModel.cs \
 	FSpot.Core/IPhotoSource.cs \
 	FSpot.Core/IPhotoVersion.cs \
 	FSpot.Core/IPhotoVersionable.cs \



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