[f-spot/cleanup-backend: 24/24] add rudimentary tag support for DatabasePhoto based on the old TagStore
- From: Mike Gemünde <mgemuende src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/cleanup-backend: 24/24] add rudimentary tag support for DatabasePhoto based on the old TagStore
- Date: Mon, 19 Jul 2010 06:43:20 +0000 (UTC)
commit cacfeab6dbfcdd7d4c2be599b7b1196e54bb03d6
Author: Mike Gemünde <mike gemuende de>
Date: Sat Jul 17 18:06:05 2010 +0200
add rudimentary tag support for DatabasePhoto based on the old TagStore
The database files needed to be compiled with f-spot.exe because of the
dependencies. This should be fixed when a better tag support for the
new database is there.
src/FSpot.Database/DatabasePhoto.cs | 13 ++++++--
src/FSpot.Database/DatabasePhotoModelCache.cs | 4 ++-
src/FSpot.Database/Makefile.am | 10 +-----
src/FSpot.Database/PhotoModelProvider.cs | 38 +++++++++++++++++++------
src/Makefile.am | 15 +++++++++-
5 files changed, 57 insertions(+), 23 deletions(-)
---
diff --git a/src/FSpot.Database/DatabasePhoto.cs b/src/FSpot.Database/DatabasePhoto.cs
index b9cf6a3..27cba3d 100644
--- a/src/FSpot.Database/DatabasePhoto.cs
+++ b/src/FSpot.Database/DatabasePhoto.cs
@@ -32,8 +32,6 @@ namespace FSpot.Database
public DatabasePhoto ()
{
- /* To be removed */
- Tags = new Tag[] {};
}
#endregion
@@ -68,7 +66,9 @@ namespace FSpot.Database
#region Remaining IBrowsableItem Implementation
- public Tag[] Tags { get; private set; }
+ public Tag[] Tags {
+ get { return tags.ToArray (); }
+ }
public IBrowsableItemVersion DefaultVersion {
get {
@@ -82,7 +82,6 @@ namespace FSpot.Database
}
}
- private List<DatabasePhotoVersion> versions;
public IEnumerable<IBrowsableItemVersion> Versions {
get {
foreach (IBrowsableItemVersion version in versions)
@@ -103,10 +102,16 @@ namespace FSpot.Database
#region Remaining IBrowsableItem Implementation
+ private List<DatabasePhotoVersion> versions;
internal List<DatabasePhotoVersion> VersionList {
get { return versions ?? (versions = new List<DatabasePhotoVersion> ()); }
}
+ private List<Tag> tags;
+ internal List<Tag> TagList {
+ get { return tags ?? (tags = new List<Tag> ()); }
+ }
+
#endregion
#region ICachableItem Implementation
diff --git a/src/FSpot.Database/DatabasePhotoModelCache.cs b/src/FSpot.Database/DatabasePhotoModelCache.cs
index 1a8c6ec..3f5001d 100644
--- a/src/FSpot.Database/DatabasePhotoModelCache.cs
+++ b/src/FSpot.Database/DatabasePhotoModelCache.cs
@@ -50,7 +50,9 @@ namespace FSpot.Database
lock (this) {
using (IDataReader reader = connection.Query (select_range_command, offset, limit)) {
foreach (DatabasePhoto photo in provider.LoadAll (reader)) {
- Add (offset, photo);
+ if ( ! ContainsKey (offset))
+ Add (offset, photo);
+
offset ++;
}
}
diff --git a/src/FSpot.Database/Makefile.am b/src/FSpot.Database/Makefile.am
index 7da8201..6ba0db2 100644
--- a/src/FSpot.Database/Makefile.am
+++ b/src/FSpot.Database/Makefile.am
@@ -3,14 +3,8 @@ TARGET = library
LINK = $(REF_FSPOT_DATABASE)
SOURCES = \
- DatabasePhoto.cs \
- DatabasePhotoListModel.cs \
- DatabasePhotoModelCache.cs \
- DatabasePhotoVersion.cs \
- FSpotDatabaseConnection.cs \
- PhotoModelProvider.cs \
- PhotoVersionModelProvider.cs \
- SqliteCachedModelProvider.cs
+ FSpotDatabaseConnection.cs
+
RESOURCES =
diff --git a/src/FSpot.Database/PhotoModelProvider.cs b/src/FSpot.Database/PhotoModelProvider.cs
index de0fe9e..d9b6d49 100644
--- a/src/FSpot.Database/PhotoModelProvider.cs
+++ b/src/FSpot.Database/PhotoModelProvider.cs
@@ -10,6 +10,7 @@
//
using System;
+using System.Data;
using System.Text;
using System.Collections.Generic;
@@ -17,10 +18,6 @@ using Hyena;
using Hyena.Data.Sqlite;
-/* obsolete references */
-//using FSpot.Query;
-//using System.Data;
-
namespace FSpot.Database
{
@@ -52,7 +49,7 @@ namespace FSpot.Database
/// <remarks>
/// This method is mainly used to provide efficient loading of photos for a DatabasePhotoModelCache.
/// </remarks>
- public IEnumerable<DatabasePhoto> LoadAll (System.Data.IDataReader reader)
+ public IEnumerable<DatabasePhoto> LoadAll (IDataReader reader)
{
Dictionary<int, DatabasePhoto> photo_lookup = new Dictionary<int, DatabasePhoto> ();
List<DatabasePhoto> photo_list = new List<DatabasePhoto> ();
@@ -75,13 +72,25 @@ namespace FSpot.Database
photo_id_query.Append (")");
- IEnumerator<DatabasePhoto> photo_enum = photo_list.GetEnumerator ();
- photo_enum.MoveNext ();
-
+ // Add Versions
foreach (DatabasePhotoVersion version in photo_versions.FetchAllMatching (photo_id_query.ToString ())) {
photo_lookup [version.PhotoId].VersionList.Add (version);
}
+ // Add Tags
+ IDataReader tag_reader =
+ Connection.Query (String.Format ("SELECT photo_id, tag_id FROM photo_tags WHERE {0}",
+ photo_id_query.ToString ()));
+
+ using (tag_reader) {
+ while (tag_reader.Read ()) {
+ int photo_id = Convert.ToInt32 (tag_reader ["photo_id"]);
+ int tag_id = Convert.ToInt32 (tag_reader ["tag_id"]);
+
+ photo_lookup [photo_id].TagList.Add (App.Instance.Database.Tags.Get ((uint) tag_id));
+ }
+ }
+
return photo_list;
}
@@ -97,6 +106,17 @@ namespace FSpot.Database
if (photo.VersionList.Count == 0)
Log.DebugFormat ("No versions for photo ({0}) found.", photo.Id);
+
+ IDataReader tag_reader =
+ Connection.Query ("SELECT photo_id, tag_id FROM photo_tags WHERE photo_id = ?", photo.Id);
+
+ using (tag_reader) {
+ while (tag_reader.Read ()) {
+ int tag_id = Convert.ToInt32 (tag_reader ["tag_id"]);
+
+ photo.TagList.Add (App.Instance.Database.Tags.Get ((uint) tag_id));
+ }
+ }
}
#endregion
@@ -104,7 +124,7 @@ namespace FSpot.Database
#region Override SqliteModelProvider Behavior
- public override DatabasePhoto Load (System.Data.IDataReader reader)
+ public override DatabasePhoto Load (IDataReader reader)
{
DatabasePhoto photo = base.Load (reader);
Populate (photo);
diff --git a/src/Makefile.am b/src/Makefile.am
index 648dec4..2ac3c88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -190,7 +190,20 @@ SOURCES = \
Widgets/Wipe.cs \
main.cs \
Tests/ImageFileTests.cs \
- Tests/UpdaterTests.cs
+ Tests/UpdaterTests.cs \
+ FSpot.Collections.Gui/IPhotoGridCaptionRenderer.cs \
+ FSpot.Collections.Gui/PhotoGridDateCaptionRenderer.cs \
+ FSpot.Collections.Gui/PhotoGridTextCaptionRenderer.cs \
+ FSpot.Collections.Gui/PhotoGridView.cs \
+ FSpot.Collections.Gui/PhotoGridViewChild.cs \
+ FSpot.Collections.Gui/PhotoGridViewLayout.cs \
+ FSpot.Database/DatabasePhoto.cs \
+ FSpot.Database/DatabasePhotoListModel.cs \
+ FSpot.Database/DatabasePhotoModelCache.cs \
+ FSpot.Database/DatabasePhotoVersion.cs \
+ FSpot.Database/PhotoModelProvider.cs \
+ FSpot.Database/PhotoVersionModelProvider.cs \
+ FSpot.Database/SqliteCachedModelProvider.cs
RESOURCES = \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]