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



Author: sdelcroix
Date: Mon Apr 28 06:36:02 2008
New Revision: 3850
URL: http://svn.gnome.org/viewvc/f-spot?rev=3850&view=rev

Log:
2008-04-28  Stephane Delcroix  <sdelcroix novell com>

	* src/Tag.cs: new Popularity property.
	* src/TagStore.cs: sort tags by popularity on the TagEntry. Fixes 
	bgo #378428.


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	Mon Apr 28 06:36:02 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;
+		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	Mon Apr 28 06:36:02 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
@@ -153,7 +156,7 @@
 
 		// Pass 1, get all the tags.
 
-		SqliteDataReader reader = Database.Query("SELECT id, name, is_category, sort_priority, icon FROM tags");
+		SqliteDataReader reader = Database.Query("SELECT id, name, is_category, sort_priority, icon, count(*) as popularity FROM tags LEFT OUTER JOIN photo_tags ON photo_tags.tag_id = tags.id group by id order by sort_priority, popularity desc");
 
 		while (reader.Read ()) {
 			uint id = Convert.ToUInt32 (reader [0]);
@@ -170,6 +173,7 @@
 				SetIconFromString (tag, reader [4].ToString ());
 
 			tag.SortPriority = Convert.ToInt32 (reader[3]);
+			tag.Popularity = Convert.ToInt32 (reader[5]);
 			AddToCache (tag);
 		}
 



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