f-spot r3545 - in trunk: . src



Author: sdelcroix
Date: Wed Jan 16 13:06:25 2008
New Revision: 3545
URL: http://svn.gnome.org/viewvc/f-spot?rev=3545&view=rev

Log:
2008-01-16  Stephane Delcroix  <sdelcroix novell com>

	* src/RatingRange.cs:
	* src/DateRange.cs:
	* src/Untagged.cs:
	* src/Makefile.am: make those IQueryCondition

	* src/PhotoStore.cs: simplifying the query things,
	iteration 1.

	* src/DateCommands.cs:
	* src/PhotoQuery.cs:
	* src/PhotoStore.cs:
	* src/RatingFilter.cs:
	* src/RollSet.cs:
	* sc/SimpleCalendar.cs:
	* src/TimeAdaptor.cs: minor namespace changes.	


Added:
   trunk/src/DateRange.cs
   trunk/src/RatingRange.cs
   trunk/src/Untagged.cs
Modified:
   trunk/ChangeLog
   trunk/src/DateCommands.cs
   trunk/src/Makefile.am
   trunk/src/PhotoQuery.cs
   trunk/src/PhotoStore.cs
   trunk/src/RatingFilter.cs
   trunk/src/RollSet.cs
   trunk/src/SimpleCalendar.cs
   trunk/src/TimeAdaptor.cs

Modified: trunk/src/DateCommands.cs
==============================================================================
--- trunk/src/DateCommands.cs	(original)
+++ trunk/src/DateCommands.cs	Wed Jan 16 13:06:25 2008
@@ -13,6 +13,7 @@
 using Gnome;
 using System;
 using Mono.Unix;
+using FSpot;
 
 public class DateCommands {
 	public class Set : FSpot.GladeDialog {
@@ -89,12 +90,12 @@
 			}	
 		}
 
-		private PhotoStore.DateRange QueryRange (int index)
+		private DateRange QueryRange (int index)
 		{
 			return QueryRange ( ranges [index]);
 		}
 
-		private PhotoStore.DateRange QueryRange (string rangename)
+		private DateRange QueryRange (string rangename)
 		{
 			System.DateTime today = System.DateTime.Today;
 			System.DateTime startdate = today;
@@ -165,7 +166,7 @@
 				break;
 			}	
 			if (!clear)
-				return new PhotoStore.DateRange (startdate, enddate.Add (new System.TimeSpan(23,59,59)));
+				return new DateRange (startdate, enddate.Add (new System.TimeSpan(23,59,59)));
 			else
 				return null;
 		}
@@ -191,7 +192,7 @@
 			start_dateedit.Sensitive = (combo.Active != System.Array.IndexOf (ranges, "alldates"));
 			end_dateedit.Sensitive = (combo.Active != System.Array.IndexOf (ranges, "alldates"));
 
-			PhotoStore.DateRange range = QueryRange (period_combobox.Active);
+			DateRange range = QueryRange (period_combobox.Active);
 			if (range != null) {
 				start_dateedit.Time = range.Start;
 				end_dateedit.Time = range.End;

Added: trunk/src/DateRange.cs
==============================================================================
--- (empty file)
+++ trunk/src/DateRange.cs	Wed Jan 16 13:06:25 2008
@@ -0,0 +1,39 @@
+/*
+ * DateRange.cs
+ * 
+ * Author(s):
+ *	Stephane Delcroix <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ *
+ */
+
+using System;
+
+namespace FSpot {
+	public class DateRange : IQueryCondition
+	{
+		private DateTime start;		
+		public DateTime Start {
+			get { return start; }
+		}
+
+		private DateTime end;
+		public DateTime End {
+			get { return end; }
+		}
+
+		public DateRange (DateTime start, DateTime end)
+		{
+			this.start = start;
+			this.end = end;
+		}
+
+		public string SqlClause ()
+		{
+			return String.Format (" photos.time >= {0} AND photos.time <= {1}", 
+					DbUtils.UnixTimeFromDateTime (start), 
+					DbUtils.UnixTimeFromDateTime (end));
+		}
+	}
+}

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Wed Jan 16 13:06:25 2008
@@ -60,6 +60,7 @@
 	$(srcdir)/ControlOverlay.cs		\
 	$(srcdir)/Core.cs			\
 	$(srcdir)/DateCommands.cs		\
+	$(srcdir)/DateRange.cs			\
 	$(srcdir)/Db.cs				\
 	$(srcdir)/DBusProxy.cs			\
 	$(srcdir)/Delay.cs			\
@@ -177,6 +178,7 @@
 	$(srcdir)/ProgressDialog.cs		\
 	$(srcdir)/RatingFilter.cs		\
 	$(srcdir)/RatingMenu.cs			\
+	$(srcdir)/RatingRange.cs		\
 	$(srcdir)/QueuedSqliteDatabase.cs	\
 	$(srcdir)/RepairDialog.cs		\
 	$(srcdir)/RotateCommand.cs		\
@@ -203,6 +205,7 @@
 	$(srcdir)/TimeDialog.cs			\
 	$(srcdir)/TipWindow.cs			\
 	$(srcdir)/Unix.cs			\
+	$(srcdir)/Untagged.cs			\
 	$(srcdir)/Updater.cs			\
 	$(srcdir)/UriCollection.cs		\
 	$(srcdir)/Utils/ScreenSaver.cs		\

Modified: trunk/src/PhotoQuery.cs
==============================================================================
--- trunk/src/PhotoQuery.cs	(original)
+++ trunk/src/PhotoQuery.cs	Wed Jan 16 13:06:25 2008
@@ -10,9 +10,9 @@
 		private Term terms;
 		private Tag [] tags;
 		private string extra_condition;
-		private PhotoStore.DateRange range = null;
+		private DateRange range = null;
 		private RollSet roll_set = null;
-		private PhotoStore.RatingRange ratingrange = null;
+		private RatingRange ratingrange = null;
 		
 		// Constructor
 		public PhotoQuery (PhotoStore store)
@@ -91,16 +91,13 @@
  			}
  		}
 		
-		public PhotoStore.DateRange Range {
-			get {
-				return range;
-			}
+		public DateRange Range {
+			get { return range; }
 			set {
 				if (value == range)
 					return;
 
 				range = value;
-				
 				RequestReload ();
 			}
 		}
@@ -135,10 +132,8 @@
  			}
 		}
 
-		public PhotoStore.RatingRange RatingRange {
-			get {
-				return ratingrange;
-			}
+		public RatingRange RatingRange {
+			get { return ratingrange; }
 			set {
 				if (value == ratingrange)
 					return;
@@ -150,16 +145,14 @@
 
 		private bool unrated = false;
 		public bool Unrated {
-			get {
-				return unrated;
-			}
+			get { return unrated; }
 			set {
 				if (value == unrated)
 					return;
 
 				unrated = value;
 				if (unrated)
-					ratingrange = new PhotoStore.RatingRange (PhotoStore.RatingRange.RatingType.Unrated);
+					ratingrange = new RatingRange (RatingRange.RatingType.Unrated);
 				else
 					ratingrange = null;
 				RequestReload ();

Modified: trunk/src/PhotoStore.cs
==============================================================================
--- trunk/src/PhotoStore.cs	(original)
+++ trunk/src/PhotoStore.cs	Wed Jan 16 13:06:25 2008
@@ -1197,29 +1197,6 @@
 		}
 	}
 	
-	public class DateRange 
-	{
-		private DateTime start;		
-		public DateTime Start {
-			get {
-				return start;
-			}
-		}
-
-		private DateTime end;
-		public DateTime End {
-			get {
-				return end;
-			}
-		}
-
-		public DateRange (DateTime start, DateTime end)
-		{
-			this.start = start;
-			this.end = end;
-		}
-	}
-
 	// Dbus
 	public event ItemsAddedHandler ItemsAddedOverDBus;
 	public event ItemsRemovedHandler ItemsRemovedOverDBus;
@@ -1255,77 +1232,6 @@
 		 	ItemsRemovedOverDBus (this, new DbItemEventArgs (photos)); 
 	}
 
-	public class RatingRange 
-	{
-		public enum RatingType {
-			Unrated,
-			Rated
-		};
-
-		private RatingType ratetype;
-		public RatingType RateType {
-			get { 
-				return ratetype;
-			}
-			set { 
-				ratetype = value;
-			}
-		}
-
-		private uint minRating;		
-		public uint MinRating {
-			get {
-				return minRating;
-			}
-			set {
-				minRating = value;	
-			}
-		}
-
-		private uint maxRating;		
-		public uint MaxRating {
-			get {
-				return maxRating;
-			}
-			set {
-				maxRating = value;	
-			}
-		}
-
-		public RatingRange (RatingType ratetype) {
-			this.ratetype = ratetype;
-		}
-
-		public RatingRange (uint newRating)
-		{
-			this.ratetype = RatingType.Rated;
-			this.minRating = newRating;
-			this.maxRating = System.UInt32.MaxValue;
-		}
-
-		public RatingRange (uint newRating1, uint newRating2)
-		{
-			this.ratetype = RatingType.Rated;
-			this.minRating = newRating1;
-			this.maxRating = newRating2;
-		}
-
-		public string SqlClause ()
-		{
-			switch (this.ratetype) {
-			case (RatingType.Unrated) :
-				return String.Format (" photos.rating is NULL");
-				break;
-			case (RatingType.Rated) :
-				return String.Format (" photos.rating >= {0} AND photos.rating <= {1} ", minRating, maxRating);
-				break;
-			default :
-				return String.Empty;
-				break;
-			}
-		}
-
-	}
 
 	// Queries.
 
@@ -1338,29 +1244,35 @@
 		return  String.Format (" {0}{1}", added_where ? " AND " : " WHERE ", roll_set.SqlClause () );
 	}
 	
-	public Photo [] Query (Tag [] tags, DateTime start, DateTime end, Roll [] rolls, uint minRating, uint maxRating)
-	{
-		return Query (tags, null, new DateRange (start, end), new RollSet (rolls), new RatingRange (minRating, maxRating));
+	[Obsolete ("drop this, use IQueryCondition correctly instead")]
+	public Photo [] Query (Tag [] tags) {
+		return Query (tags, null, null, null, null);
 	}
 
-	public Photo [] Query (Tag [] tags, DateTime start, DateTime end, Roll [] rolls, uint minRating)
+	public Photo [] Query (params IQueryCondition [] conditions)
 	{
-		return Query (tags, null, new DateRange (start, end), new RollSet (rolls), new RatingRange (minRating));
+		StringBuilder query_builder = new StringBuilder ("SELECT * FROM photos ");
+		
+		bool where_added = false;
+		foreach (IQueryCondition condition in conditions)
+			if (condition != null) {
+				query_builder.Append (where_added ? " AND " : " WHERE ");
+				query_builder.Append (condition.SqlClause ());
+				where_added = true;
+			}
+		query_builder.Append("ORDER BY time");
+		return Query (query_builder.ToString ());
 	}
 
-	public Photo [] Query (Tag [] tags, Roll [] rolls)
+	public Photo [] Query (IQueryCondition condition, params IQueryCondition [] conditions)
 	{
-		return Query (tags, null, null, rolls == null ? null : new RollSet (rolls), null);
+		IQueryCondition [] conds = new IQueryCondition [conditions.Length + 1];
+		conds [0] = condition;
+		for (int i=0; i < conditions.Length; i++)
+			conds [i + 1] = conditions [i];
+		return Query (conds);
 	}
 
-	public Photo [] Query (Tag [] tags, DateTime start, DateTime end)
-	{
-		return Query (tags, null, new DateRange (start, end), null, null);
-	}
-	
-	public Photo [] Query (Tag [] tags) {
-		return Query (tags, null, null, null, null);
-	}
 
 	public Photo [] Query (string query)
 	{
@@ -1429,52 +1341,25 @@
 		return Query (query_string);
 	}
 
-	public Photo [] QueryUntagged (DateRange range, RollSet importidrange)
+	[Obsolete ("drop this, use IQueryCondition correctly instead")]
+	public Photo [] QueryUntagged (params IQueryCondition [] conditions)
 	{
-		return QueryUntagged (range, importidrange, null);
-	}
-
-	public Photo [] QueryUntagged (DateRange range, RollSet importidrange, RatingRange ratingrange)
-	{
-		StringBuilder query_builder = new StringBuilder ();
-
-		query_builder.Append ("SELECT * FROM photos WHERE id NOT IN " +
-					"(SELECT DISTINCT photo_id FROM photo_tags) ");
-		
-		bool added_where = true;
-		if (range != null) {
-			query_builder.Append (String.Format ("AND photos.time >= {0} AND photos.time <= {1} ",
-							     DbUtils.UnixTimeFromDateTime (range.Start), 
-							     DbUtils.UnixTimeFromDateTime (range.End)));
-			added_where = true;
-		}
-
-		if (importidrange != null) {
-			query_builder.Append (AddLastImportFilter (importidrange, added_where));
-			added_where = true;
- 		}
-
-		if (ratingrange != null) {
-			query_builder.Append (" AND");
-			query_builder.Append (ratingrange.SqlClause ());
-			added_where = true;
- 		}
-
-		query_builder.Append("ORDER BY time");
-
-		return Query (query_builder.ToString ());
+		return Query (new Untagged (), conditions);
 	}
 
+	[Obsolete ("drop this, use IQueryCondition correctly instead")]
 	public Photo [] Query (Tag [] tags, string extra_condition, DateRange range, RollSet importidrange)
 	{
 		return Query (OrTerm.FromTags(tags), extra_condition, range, importidrange, null);
 	}
 
+	[Obsolete ("drop this, use IQueryCondition correctly instead")]
 	public Photo [] Query (Tag [] tags, string extra_condition, DateRange range, RollSet importidrange, RatingRange ratingrange)
 	{
 		return Query (OrTerm.FromTags(tags), extra_condition, range, importidrange, ratingrange);
 	}
 
+	[Obsolete ("drop this, use IQueryCondition correctly instead")]
 	public Photo [] Query (Term searchexpression, string extra_condition, DateRange range, RollSet importidrange, RatingRange ratingrange)
 	{
 		bool hide = (extra_condition == null);

Modified: trunk/src/RatingFilter.cs
==============================================================================
--- trunk/src/RatingFilter.cs	(original)
+++ trunk/src/RatingFilter.cs	Wed Jan 16 13:06:25 2008
@@ -2,12 +2,15 @@
  * Rating.cs
  *
  * Author[s]
- *    Bengt Thuree <bengt thuree com>
+ * 	Bengt Thuree <bengt thuree com>
+ *	Stephane Delcroix <stephane delcroix org>
  *
+ * This is free software. See COPYING for details.
  */
 
 using Gtk;
 using Gnome;
+using FSpot;
 
 public class RatingFilter {
 	public class Set : FSpot.GladeDialog {
@@ -41,7 +44,7 @@
 			bool success = false;
 
 			if (response == ResponseType.Ok) {
-				query.RatingRange = new PhotoStore.RatingRange ((uint) minrating.Value, (uint) maxrating.Value);
+				query.RatingRange = new RatingRange ((uint) minrating.Value, (uint) maxrating.Value);
 				success = true;
 			}
 			

Added: trunk/src/RatingRange.cs
==============================================================================
--- (empty file)
+++ trunk/src/RatingRange.cs	Wed Jan 16 13:06:25 2008
@@ -0,0 +1,69 @@
+/*
+ * RatingRange.cs
+ *
+ * Author(s):
+ *	Bengt Thuree
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+using System;
+
+namespace FSpot {
+	public class RatingRange : IQueryCondition
+	{
+		public enum RatingType {
+			Unrated,
+			Rated
+		};
+
+		private RatingType ratetype;
+		public RatingType RateType {
+			get { return ratetype; }
+			set { ratetype = value; }
+		}
+
+		private uint minRating;		
+		public uint MinRating {
+			get { return minRating; }
+			set { minRating = value; }
+		}
+
+		private uint maxRating;		
+		public uint MaxRating {
+			get { return maxRating; }
+			set { maxRating = value; }
+		}
+
+		public RatingRange (RatingType ratetype) {
+			this.ratetype = ratetype;
+		}
+
+		public RatingRange (uint min_rating)
+		{
+			this.ratetype = RatingType.Rated;
+			this.minRating = min_rating;
+			this.maxRating = System.UInt32.MaxValue;
+		}
+
+		public RatingRange (uint min_rating, uint max_rating)
+		{
+			this.ratetype = RatingType.Rated;
+			this.minRating = min_rating;
+			this.maxRating = max_rating;
+		}
+
+		public string SqlClause ()
+		{
+			switch (this.ratetype) {
+			case (RatingType.Unrated) :
+				return String.Format (" photos.rating is NULL");
+			case (RatingType.Rated) :
+				return String.Format (" photos.rating >= {0} AND photos.rating <= {1} ", minRating, maxRating);
+			default :
+				return String.Empty;
+			}
+		}
+	}
+}

Modified: trunk/src/RollSet.cs
==============================================================================
--- trunk/src/RollSet.cs	(original)
+++ trunk/src/RollSet.cs	Wed Jan 16 13:06:25 2008
@@ -32,7 +32,6 @@
 					sb.Append (", ");
 			}
 			sb.Append (") ");
-	System.Console.WriteLine (sb.ToString ());
 			return sb.ToString ();	
 		}
 	}

Modified: trunk/src/SimpleCalendar.cs
==============================================================================
--- trunk/src/SimpleCalendar.cs	(original)
+++ trunk/src/SimpleCalendar.cs	Wed Jan 16 13:06:25 2008
@@ -50,7 +50,7 @@
 			if (current.Month != last.Month || current.Year != last.Year) {
 				System.Console.WriteLine ("Month thinks is changed {0} {1}", last.ToString (), current.ToString ());
 				last = current;
-				query.Range =  new PhotoStore.DateRange (current, current.AddMonths (1));
+				query.Range =  new DateRange (current, current.AddMonths (1));
 			}
 			base.OnMonthChanged ();
 		}

Modified: trunk/src/TimeAdaptor.cs
==============================================================================
--- trunk/src/TimeAdaptor.cs	(original)
+++ trunk/src/TimeAdaptor.cs	Wed Jan 16 13:06:25 2008
@@ -65,9 +65,9 @@
 		{
 			Console.WriteLine ("{0} {1}", start, end);
 			if (start > end)
-				query.Range = new PhotoStore.DateRange (end, start);
+				query.Range = new DateRange (end, start);
 			else 
-				query.Range = new PhotoStore.DateRange (start, end);
+				query.Range = new DateRange (start, end);
 		}
 
 		public override int Count ()

Added: trunk/src/Untagged.cs
==============================================================================
--- (empty file)
+++ trunk/src/Untagged.cs	Wed Jan 16 13:06:25 2008
@@ -0,0 +1,19 @@
+/*
+ * Untagged.cs
+ * 
+ * Author(s)
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+namespace FSpot
+{
+	public class Untagged : IQueryCondition
+	{
+		public string SqlClause ()
+		{
+			return " photos.id NOT IN (SELECT DISTINCT photo_id FROM photo_tags) ";
+		}
+	}
+}



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