[f-spot/cleanup-backend: 18/23] Add model which makes use of the DatabasePhoto



commit 662c1380fbf6afe74856cf9b9d3a00fc102ce667
Author: Mike Gemünde <mike gemuende de>
Date:   Tue Jul 13 10:54:15 2010 +0200

    Add model which makes use of the DatabasePhoto

 src/Core/IPhotoListModel.cs                   |   26 ++++
 src/Core/Makefile.am                          |    1 +
 src/FSpot.Database/DatabasePhotoListModel.cs  |  177 +++++++++++++++++++++++++
 src/FSpot.Database/DatabasePhotoModelCache.cs |   30 ++++
 src/FSpot.Database/Makefile.am                |    2 +
 5 files changed, 236 insertions(+), 0 deletions(-)
---
diff --git a/src/Core/IPhotoListModel.cs b/src/Core/IPhotoListModel.cs
new file mode 100644
index 0000000..5b82be2
--- /dev/null
+++ b/src/Core/IPhotoListModel.cs
@@ -0,0 +1,26 @@
+//
+// 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.Collections
+{
+
+
+    public interface IPhotoListModel : IListModel<IBrowsableItem>
+    {
+    }
+}
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index 8443bd5..2d55473 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -20,6 +20,7 @@ SOURCES = \
 	IBrowsableItemVersionable.cs \
 	IBrowsableCollection.cs \
 	ILoadable.cs \
+	IPhotoListModel.cs \
 	IPhotoSource.cs \
 	ISource.cs \
 	PhotoChanges.cs \
diff --git a/src/FSpot.Database/DatabasePhotoListModel.cs b/src/FSpot.Database/DatabasePhotoListModel.cs
new file mode 100644
index 0000000..cc85af1
--- /dev/null
+++ b/src/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.Query;
+using FSpot.Collections;
+
+namespace FSpot.Database
+{
+
+
+    public class DatabasePhotoListModel
+        : BaseListModel<IBrowsableItem>, 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 PhotoSelection (this);
+            cache = new DatabasePhotoModelCache (connection, uuid, this, provider);
+        }
+
+#endregion
+
+
+#region IPhotoListModel implementation
+
+        public override IBrowsableItem 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 IBrowsableItem[] Items {
+            get {
+                throw new NotSupportedException ();
+            }
+        }
+
+        public void MarkChanged (int index, IBrowsableItemChanges changes)
+        {
+            throw new System.NotImplementedException ();
+        }
+
+        public bool Contains (IBrowsableItem 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 (IBrowsableItem item)
+        {
+            return (int)cache.IndexOf (item);
+        }
+
+#endregion
+
+    }
+}
diff --git a/src/FSpot.Database/DatabasePhotoModelCache.cs b/src/FSpot.Database/DatabasePhotoModelCache.cs
new file mode 100644
index 0000000..c6d78c7
--- /dev/null
+++ b/src/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/FSpot.Database/Makefile.am b/src/FSpot.Database/Makefile.am
index 2fc8dc1..7da8201 100644
--- a/src/FSpot.Database/Makefile.am
+++ b/src/FSpot.Database/Makefile.am
@@ -4,6 +4,8 @@ LINK = $(REF_FSPOT_DATABASE)
 
 SOURCES = \
 	DatabasePhoto.cs \
+	DatabasePhotoListModel.cs \
+	DatabasePhotoModelCache.cs \
 	DatabasePhotoVersion.cs \
 	FSpotDatabaseConnection.cs \
 	PhotoModelProvider.cs \



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