f-spot r3919 - in trunk: . src src/Core



Author: sdelcroix
Date: Fri May 16 18:25:24 2008
New Revision: 3919
URL: http://svn.gnome.org/viewvc/f-spot?rev=3919&view=rev

Log:
2008-05-16  Stephane Delcroix  <stephane delcroix org>

	* src/TagStore.cs:
	* src/Core/Tag.cs: re-introducing an enhanced version of
	tag sorting by popularity on tag typing.


Modified:
   trunk/ChangeLog
   trunk/src/Core/Tag.cs
   trunk/src/TagStore.cs

Modified: trunk/src/Core/Tag.cs
==============================================================================
--- trunk/src/Core/Tag.cs	(original)
+++ trunk/src/Core/Tag.cs	Fri May 16 18:25:24 2008
@@ -42,14 +42,16 @@
 	
 		private int sort_priority;
 		public int SortPriority {
-			set {
-				sort_priority = value;
-			}
-			get {
-				return sort_priority;
-			}
+			set { sort_priority = value; }
+			get { return sort_priority; }
 		}
 	
+		private int popularity = 0;
+		public int Popularity {
+			get { return popularity; }
+			set { popularity = value; }
+		}
+
 		// Icon.  If theme_icon_name is not null, then we save the name of the icon instead
 		// of the actual icon data.
 	

Modified: trunk/src/TagStore.cs
==============================================================================
--- trunk/src/TagStore.cs	(original)
+++ trunk/src/TagStore.cs	Fri May 16 18:25:24 2008
@@ -3,6 +3,7 @@
 using Gtk;
 using Mono.Unix;
 using Mono.Data.SqliteClient;
+using System.Collections.Generic;
 using System.Collections;
 using System.IO;
 using System;
@@ -132,7 +133,7 @@
 
 	public Tag [] GetTagsByNameStart (string s)
 	{
-		ArrayList l = new ArrayList ();
+		List <Tag> l = new List<Tag> ();
 		foreach (Tag t in this.item_cache.Values) {
 			if (t.Name.ToLower ().StartsWith (s.ToLower ()))
 				l.Add (t);
@@ -140,8 +141,10 @@
 
 		if (l.Count == 0)
 			return null;
+		
+		l.Sort (delegate (Tag t1, Tag t2) {return t2.Popularity.CompareTo (t1.Popularity); });
 
-		return (Tag []) (l.ToArray (typeof (Tag)));
+		return l.ToArray ();
 	}
 
 	// In this store we keep all the items (i.e. the tags) in memory at all times.  This is
@@ -176,8 +179,7 @@
 		reader.Close ();
 
 		// Pass 2, set the parents.
-
-		reader = Database.Query("SELECT id, category_id FROM tags");
+		reader = Database.Query ("SELECT id, category_id FROM tags");
 
 		while (reader.Read ()) {
 			uint id = Convert.ToUInt32 (reader [0]);
@@ -197,6 +199,12 @@
 		}
 		reader.Close ();
 
+		//Pass 3, set popularity
+		reader = Database.Query ("SELECT tag_id, COUNT (*) as popularity FROM photo_tags GROUP BY tag_id");
+		while (reader.Read ())
+			(Get (Convert.ToUInt32 (reader [0])) as Tag).Popularity = Convert.ToInt32 (reader [1]);
+		reader.Close ();
+
 		if (FSpot.Core.Database.Meta.HiddenTagId.Value != null)
 			hidden = LookupInCache ((uint) FSpot.Core.Database.Meta.HiddenTagId.ValueAsInt) as Tag;
 	}



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