[f-spot] fix HiddenTag



commit 87d9f20b38b9b497ba530d38a8fdeea8562bcb71
Author: Mike Gemünde <mike gemuende de>
Date:   Tue Jul 14 22:55:43 2009 +0200

    fix HiddenTag

 src/FolderQueryWidget.cs           |    6 +++
 src/Makefile.am                    |    1 +
 src/PhotoQuery.cs                  |   56 ++++++++++++++++++++------------
 src/PhotoStore.cs                  |   14 ++++++++
 src/Query/HiddenTag.cs             |   62 ++++++++++++++++++++++++++++++++++++
 src/QueryWidget.cs                 |    4 +-
 src/TagQueryWidget.cs              |    5 +--
 src/UI.Dialog/EditTagIconDialog.cs |    2 +-
 src/Widgets/FindBar.cs             |    4 +-
 9 files changed, 125 insertions(+), 29 deletions(-)
---
diff --git a/src/FolderQueryWidget.cs b/src/FolderQueryWidget.cs
index 1f9780b..875ee96 100644
--- a/src/FolderQueryWidget.cs
+++ b/src/FolderQueryWidget.cs
@@ -98,6 +98,12 @@ namespace FSpot
 			folder_set.Folders = null;
 		}
 		
+		public bool Empty {
+			get {
+				return folder_set.Folders == null || folder_set.Folders.Count () == 0;
+			}
+		}
+		
 		private static TargetEntry [] folder_query_widget_source_table =
 			new TargetEntry [] {
 				DragDropTargets.UriQueryEntry
diff --git a/src/Makefile.am b/src/Makefile.am
index 354a015..1f0848b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -275,6 +275,7 @@ F_SPOT_CSDISTFILES =				\
 	$(srcdir)/Vector.cs			\
 	$(srcdir)/ThumbnailCommand.cs		\
 	$(srcdir)/QueryWidget.cs		\
+	$(srcdir)/Query/HiddenTag.cs		\
 	$(srcdir)/GPhotoCamera.cs		\
 	$(srcdir)/CameraSelectionDialog.cs	\
 	$(srcdir)/CameraFileSelectionDialog.cs	\
diff --git a/src/PhotoQuery.cs b/src/PhotoQuery.cs
index ad2a67e..14bb69d 100644
--- a/src/PhotoQuery.cs
+++ b/src/PhotoQuery.cs
@@ -61,7 +61,6 @@ namespace FSpot {
 		private PhotoStore store;
 		private Term terms;
 		private Tag [] tags;
-		private string extra_condition;
 
 		static int query_count = 0;
 		static int QueryCount {
@@ -170,22 +169,7 @@ namespace FSpot {
 				RequestReload ();
 			}
 		}
-
-		public string ExtraCondition {
-			get { return extra_condition; }
-			set {
-				if (extra_condition == value)
-					return;
-
-				extra_condition = value;
-
-				if (value != null)
-					untagged = false;
-
- 				RequestReload ();
- 			}
- 		}
-		
+	
 		public DateRange Range {
 			get { return GetCondition<DateRange> (); }
 			set {
@@ -200,8 +184,12 @@ namespace FSpot {
 			set {
 				if (untagged != value) {
 					untagged = value;
-					if (untagged)
-						extra_condition = null;
+					
+					if (untagged) {
+						UnSetCondition<TagConditionWrapper> ();
+						UnSetCondition<HiddenTag> ();
+					}
+					
 					RequestReload ();
 				}
 			}
@@ -222,6 +210,32 @@ namespace FSpot {
 					RequestReload ();
 			}
 		}
+		
+		public HiddenTag HiddenTag {
+			get { return GetCondition<HiddenTag> (); }
+			set {
+				if (value == null && UnSetCondition<HiddenTag>() || value != null && SetCondition (value))
+					RequestReload ();
+			}
+		}
+		
+		public TagConditionWrapper TagTerm {
+			get { return GetCondition<TagConditionWrapper> (); }
+			set {
+				if (value == null && UnSetCondition<TagConditionWrapper>()
+				    || value != null && SetCondition (value)) {
+					
+					if (value != null) {
+						untagged = false;
+						SetCondition (HiddenTag.ShowHiddenTag);
+					} else {
+						UnSetCondition<HiddenTag> ();
+					}
+					
+					RequestReload ();
+				}
+			}
+		}
 
 		public OrderByTime OrderByTime {
 			get { return GetCondition<OrderByTime> (); }
@@ -251,7 +265,7 @@ namespace FSpot {
 				i = 1;
 			} else {
 				condition_array = new IQueryCondition[conditions.Count + 2];
-				condition_array[0] = new TagConditionWrapper (extra_condition);
+		//		condition_array[0] = new TagConditionWrapper (extra_condition);
 				condition_array[1] = new TagConditionWrapper (terms != null ? terms.SqlCondition () : null);
 				i = 2;
 			}
@@ -370,7 +384,7 @@ namespace FSpot {
 			ItemsChanged (this, new BrowsableEventArgs (indexes, changes));
 		}
 		
-		private class TagConditionWrapper : IQueryCondition
+		public class TagConditionWrapper : IQueryCondition
 		{
 			string condition;
 			
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index c788e4d..f5b4210 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -774,11 +774,15 @@ public class PhotoStore : DbStore<Photo> {
 		StringBuilder query_builder = new StringBuilder ("SELECT * FROM photos ");
 
 		bool where_added = false;
+		bool hidden_contained = false;
 		foreach (IQueryCondition condition in conditions) {
 			
 			if (condition == null)
 				continue;
 			
+			if (condition is HiddenTag)
+				hidden_contained = true;
+			
 			if (condition is IOrderCondition)
 				continue;
 			
@@ -790,6 +794,16 @@ public class PhotoStore : DbStore<Photo> {
 			query_builder.Append (sql_clause);
 			where_added = true;
 		}
+		
+		/* if a HiddenTag condition is not explicitly given, we add one */
+		if ( ! hidden_contained) {
+			string sql_clause = HiddenTag.HideHiddenTag.SqlClause ();
+			
+			if (sql_clause != null && sql_clause.Trim () != String.Empty) {
+				query_builder.Append (where_added ? " AND " : " WHERE ");
+				query_builder.Append (sql_clause);
+			}
+		}
 
 		bool order_added = false;
 		foreach (IQueryCondition condition in conditions) {
diff --git a/src/Query/HiddenTag.cs b/src/Query/HiddenTag.cs
new file mode 100644
index 0000000..901417b
--- /dev/null
+++ b/src/Query/HiddenTag.cs
@@ -0,0 +1,62 @@
+/*
+ * HiddenTag.cs
+ * 
+ * Author(s):
+ *	Mike Gemuende <mike gemuende de>
+ *
+ * This is free software. See COPYING for details.
+ *
+ */
+
+
+using System;
+
+using FSpot;
+
+
+namespace FSpot.Query
+{
+	
+	public class HiddenTag : IQueryCondition
+	{
+		private static HiddenTag show_hidden_tag;
+		private static HiddenTag hide_hidden_tag;
+		
+		public static HiddenTag ShowHiddenTag {
+			get {
+				if (show_hidden_tag == null)
+					show_hidden_tag = new HiddenTag (true);
+				
+				return show_hidden_tag;
+			}
+		}
+
+		public static HiddenTag HideHiddenTag {
+			get {
+				if (hide_hidden_tag == null)
+					hide_hidden_tag = new HiddenTag (false);
+				
+				return hide_hidden_tag;
+			}
+		}
+		
+		
+		bool show_hidden;
+		
+		private HiddenTag (bool show_hidden)
+		{
+			this.show_hidden = show_hidden;
+		}
+		
+		public string SqlClause ()
+		{
+			Tag hidden = Core.Database.Tags.Hidden;
+			
+			if ( ! show_hidden && hidden != null)
+				return String.Format (" photos.id NOT IN (SELECT photo_id FROM photo_tags WHERE tag_id = {0}) ",
+				                      hidden.Id);
+			else
+				return null;
+		}
+	}
+}
diff --git a/src/QueryWidget.cs b/src/QueryWidget.cs
index e2d2e59..df9f5a3 100644
--- a/src/QueryWidget.cs
+++ b/src/QueryWidget.cs
@@ -163,14 +163,14 @@ namespace FSpot {
 
 		public void HandleChanged (IBrowsableCollection collection) 
 		{
-			if (query.ExtraCondition == null)
+			if (query.TagTerm == null)
 				logic_widget.Clear = true;
 
 			if ( ! logic_widget.Clear
 			    || query.Untagged
 			    || (query.RollSet != null)
 			    || (query.RatingRange != null)
-			    || folder_query_widget.Visible)
+			    || ! folder_query_widget.Empty)
 				ShowBar ();
 			else
 				HideBar ();
diff --git a/src/TagQueryWidget.cs b/src/TagQueryWidget.cs
index f865c27..009b3d2 100644
--- a/src/TagQueryWidget.cs
+++ b/src/TagQueryWidget.cs
@@ -676,11 +676,10 @@ namespace FSpot
 
 			if (rootTerm.Count == 0) {
 				help.Show ();
-				query.ExtraCondition = null;
+				query.TagTerm = null;
 			} else {
 				help.Hide ();
-				query.ExtraCondition = rootTerm.SqlCondition ();
-				//Console.WriteLine ("extra_condition = {0}", query.ExtraCondition);
+				query.TagTerm = new PhotoQuery.TagConditionWrapper (rootTerm.SqlCondition ());
 			}
 
 			EventHandler handler = Changed;
diff --git a/src/UI.Dialog/EditTagIconDialog.cs b/src/UI.Dialog/EditTagIconDialog.cs
index 6bb5cea..89e8b4f 100644
--- a/src/UI.Dialog/EditTagIconDialog.cs
+++ b/src/UI.Dialog/EditTagIconDialog.cs
@@ -56,7 +56,7 @@ namespace FSpot.UI.Dialog
 			query = new FSpot.PhotoQuery (db.Photos);
 			
 			if (db.Tags.Hidden != null)
-				query.Terms = FSpot.OrTerm.FromTags (new Tag []{ t, db.Tags.Hidden });
+				query.Terms = FSpot.OrTerm.FromTags (new Tag [] {t});
 			else 
 				query.Terms = new FSpot.Literal (t);
 
diff --git a/src/Widgets/FindBar.cs b/src/Widgets/FindBar.cs
index 4e29e47..3191ee8 100644
--- a/src/Widgets/FindBar.cs
+++ b/src/Widgets/FindBar.cs
@@ -410,9 +410,9 @@ namespace FSpot.Widgets {
 						root_term = root_parent;
 					}
 					//Log.Debug ("condition = {0}", RootTerm.SqlCondition ());
-					query.ExtraCondition = RootTerm.SqlCondition ();
+					query.TagTerm = new PhotoQuery.TagConditionWrapper (RootTerm.SqlCondition ());
 				} else {
-					query.ExtraCondition = null;
+					query.TagTerm = null;
 					//Log.Debug ("root term is null");
 				}
 			}



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