f-spot r3609 - in trunk: . src src/Query
- From: sdelcroix svn gnome org
- To: svn-commits-list gnome org
- Subject: f-spot r3609 - in trunk: . src src/Query
- Date: Wed, 30 Jan 2008 09:19:09 +0000 (GMT)
Author: sdelcroix
Date: Wed Jan 30 09:19:09 2008
New Revision: 3609
URL: http://svn.gnome.org/viewvc/f-spot?rev=3609&view=rev
Log:
2008-01-30 Stephane Delcroix <sdelcroix novell com>
* Query/RatingRange.cs: Unrated as a static field.
* PhotoQuery.cs: Start abstracting the conditions.
Modified:
trunk/ChangeLog
trunk/src/PhotoQuery.cs
trunk/src/Query/RatingRange.cs
Modified: trunk/src/PhotoQuery.cs
==============================================================================
--- trunk/src/PhotoQuery.cs (original)
+++ trunk/src/PhotoQuery.cs Wed Jan 30 09:19:09 2008
@@ -1,6 +1,16 @@
-using Gnome;
+/*
+ * FSpot.PhotoQuery.cs
+ *
+ * Author(s):
+ * Larry Ewing <lewing novell com>
+ * Stephane Delcroix <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
using System;
using System.Collections;
+using System.Collections.Generic;
using FSpot.Query;
namespace FSpot {
@@ -10,9 +20,6 @@
private Term terms;
private Tag [] tags;
private string extra_condition;
- private DateRange range = null;
- private RollSet roll_set = null;
- private RatingRange ratingrange = null;
// Constructor
public PhotoQuery (PhotoStore store)
@@ -23,13 +30,11 @@
this.store.ItemsAddedOverDBus += delegate { RequestReload(); };
this.store.ItemsRemovedOverDBus += delegate { RequestReload(); };
- photos = store.Query ((Tag [])null, null, range, roll_set, ratingrange);
+ photos = store.Query ((Tag [])null, null, Range, RollSet, RatingRange);
}
public int Count {
- get {
- return photos.Length;
- }
+ get { return photos.Length;}
}
public bool Contains (IBrowsableItem item) {
@@ -42,29 +47,57 @@
public event FSpot.IBrowsableCollectionItemsChangedHandler ItemsChanged;
public IBrowsableItem this [int index] {
- get {
- return photos [index];
- }
+ get { return photos [index]; }
}
public Photo [] Photos {
- get {
- return photos;
- }
+ get { return photos; }
}
public IBrowsableItem [] Items {
- get {
- return (IBrowsableItem [])photos;
- }
+ get { return (IBrowsableItem [])photos; }
}
public PhotoStore Store {
+ get { return store; }
+ }
+
+
+ //Query Conditions
+ private Dictionary<Type, IQueryCondition> conditions;
+ private Dictionary<Type, IQueryCondition> Conditions {
get {
- return store;
+ if (conditions == null)
+ conditions = new Dictionary<Type, IQueryCondition> ();
+ return conditions;
}
}
-
+
+ internal bool SetCondition (IQueryCondition condition)
+ {
+ if (condition == null)
+ throw new ArgumentNullException ("condition");
+ if (Conditions.ContainsKey (condition.GetType ()) && Conditions [condition.GetType ()] == condition)
+ return false;
+ Conditions [condition.GetType ()] = condition;
+ return true;
+ }
+
+ internal IQueryCondition GetCondition<T> ()
+ {
+ if (Conditions.ContainsKey (typeof (T)))
+ return Conditions [typeof (T)];
+ return null;
+ }
+
+ internal bool UnSetCondition<T> ()
+ {
+ if (!Conditions.ContainsKey (typeof(T)))
+ return false;
+ Conditions.Remove (typeof(T));
+ return true;
+ }
+
public Term Terms {
get {
return terms;
@@ -92,79 +125,61 @@
}
public DateRange Range {
- get { return range; }
+ get { return GetCondition<DateRange> () as DateRange; }
set {
- if (value == range)
- return;
-
- range = value;
- RequestReload ();
+ if (value == null && UnSetCondition<DateRange> () || value != null && SetCondition (value))
+ RequestReload ();
}
}
private bool untagged = false;
public bool Untagged {
- get {
- return untagged;
- }
+ get { return untagged; }
set {
if (untagged != value) {
untagged = value;
-
- if (untagged) {
- tags = null;
+ if (untagged)
extra_condition = null;
- }
-
RequestReload ();
}
}
}
public RollSet RollSet {
- get { return roll_set; }
+ get { return GetCondition<RollSet> () as RollSet; }
set {
- if (value == roll_set)
- return;
-
- roll_set = value;
- RequestReload ();
- }
+ if (value == null && UnSetCondition<RollSet> () || value != null && SetCondition (value))
+ RequestReload ();
+ }
}
public RatingRange RatingRange {
- get { return ratingrange; }
+ get { return GetCondition<RatingRange> () as RatingRange; }
set {
- if (value == ratingrange)
- return;
-
- ratingrange = value;
- RequestReload ();
+ if (value == null && UnSetCondition<RatingRange>() || value != null && SetCondition (value))
+ RequestReload ();
}
}
- private bool unrated = false;
public bool Unrated {
- get { return unrated; }
+ get {
+ return (GetCondition<RatingRange> () != null && GetCondition<RatingRange> () == RatingRange.Unrated);
+ }
set {
- if (value == unrated)
- return;
-
- unrated = value;
- if (unrated)
- ratingrange = new RatingRange (RatingRange.RatingType.Unrated);
+ if (value)
+ RatingRange = RatingRange.Unrated;
else
- ratingrange = null;
- RequestReload ();
+ if (UnSetCondition<RatingRange> ())
+ RequestReload ();
}
}
public void RequestReload ()
{
if (untagged)
- photos = store.Query (new UntaggedCondition (), range, roll_set, ratingrange);
+ photos = store.Query (new UntaggedCondition (), Range, RollSet, RatingRange);
else
- photos = store.Query (terms, extra_condition, range, roll_set, ratingrange);
+ photos = store.Query (terms, extra_condition, Range, RollSet, RatingRange);
//this event will allow resorting the query content
if (PreChanged != null)
Modified: trunk/src/Query/RatingRange.cs
==============================================================================
--- trunk/src/Query/RatingRange.cs (original)
+++ trunk/src/Query/RatingRange.cs Wed Jan 30 09:19:09 2008
@@ -37,10 +37,12 @@
set { maxRating = value; }
}
- public RatingRange (RatingType ratetype) {
+ RatingRange (RatingType ratetype) {
this.ratetype = ratetype;
}
+ public static RatingRange Unrated = new RatingRange (RatingType.Unrated);
+
public RatingRange (uint min_rating)
{
this.ratetype = RatingType.Rated;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]