f-spot r4061 - in trunk: . src



Author: sdelcroix
Date: Fri Jun 13 10:17:08 2008
New Revision: 4061
URL: http://svn.gnome.org/viewvc/f-spot?rev=4061&view=rev

Log:
2008-06-13  Stephane Delcroix  <sdelcroix novell com>

	* src/MainWindow.cs:
	* src/PhotoQuery.cs: Speed up tagging (and untagging).


Modified:
   trunk/ChangeLog
   trunk/src/MainWindow.cs
   trunk/src/PhotoQuery.cs

Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs	(original)
+++ trunk/src/MainWindow.cs	Fri Jun 13 10:17:08 2008
@@ -595,8 +595,7 @@
 	private void HandleTagsChanged (object sender, DbItemEventArgs args)
 	{
 		icon_view.QueueDraw ();
-		UpdateTagEntryFromSelection ();
-		
+		UpdateTagEntryFromSelection ();	
 	}
 
 	void HandleViewNotebookSwitchPage (object sender, SwitchPageArgs args)
@@ -835,22 +834,25 @@
 	//
 	// Tag Selection Drag Handlers
 	//
-
+	[Obsolete ("Use AddTagExtended (int [], Tag []) instead")]
 	public void AddTagExtended (int num, Tag [] tags)
 	{
-		Photo p = query.Photos [num];
+		AddTagExtended (new int [] {num}, tags);
+	}
 
-		p.AddTag (tags);
-		query.Commit (num);
+	public void AddTagExtended (int [] nums, Tag [] tags)
+	{
+		foreach (int num in nums)
+			query.Photos [num].AddTag (tags);
+		query.Commit (nums);
 
 		foreach (Tag t in tags) {
 			if (t.Icon != null)
 				continue;
-
 			// FIXME this needs a lot more work.
 			Pixbuf icon = null;
 			try {
-				Pixbuf tmp = FSpot.PhotoLoader.LoadAtMaxSize (query.Items [num], 128, 128);
+				Pixbuf tmp = FSpot.PhotoLoader.LoadAtMaxSize (query.Items [nums[0]], 128, 128);
 				icon = PixbufUtils.TagIconFromPixbuf (tmp);
 				tmp.Dispose ();
 			} catch {
@@ -862,6 +864,13 @@
 		}
 	}
 
+	public void RemoveTags (int [] nums, Tag [] tags)
+	{
+		foreach (int num in nums)
+			query.Photos [num].RemoveTag (tags);
+		query.Commit (nums);
+	}
+
 	void HandleTagSelectionRowActivated (object sender, RowActivatedArgs args)
 	{
 		ShowQueryWidget ();
@@ -978,9 +987,7 @@
 		switch (args.Info) {
 		case (uint)TargetType.PhotoList:
 			db.BeginTransaction ();
-			foreach (int num in SelectedIds ()) {
-				AddTagExtended (num, new Tag[] {tag});
-			}
+			AddTagExtended (SelectedIds (), new Tag[] {tag});
 			db.CommitTransaction ();
 			query_widget.PhotoTagsChanged (new Tag[] {tag});
 			break;
@@ -1476,7 +1483,6 @@
 		if (view_mode == ModeType.PhotoView)
 			this.photo_view.UpdateRating(r);
 
-		uint timer = Log.DebugTimerStart ();
 		Photo p;
 		db.BeginTransaction ();
 		foreach (int num in SelectedIds ()) {
@@ -1485,7 +1491,6 @@
 			query.Commit (num);
 		}
 		db.CommitTransaction ();
-		Log.DebugTimerPrint (timer, "HandleRating took {0}");
 	}
 
 	//
@@ -1505,9 +1510,7 @@
 	public void HandleAttachTagMenuSelected (Tag t) 
 	{
 		db.BeginTransaction ();
-		foreach (int num in SelectedIds ()) {
-			AddTagExtended (num, new Tag [] {t});
-		}
+		AddTagExtended (SelectedIds (), new Tag [] {t});
 		db.CommitTransaction ();
 		query_widget.PhotoTagsChanged (new Tag[] {t});
 	}
@@ -1526,10 +1529,7 @@
 	public void HandleRemoveTagMenuSelected (Tag t)
 	{
 		db.BeginTransaction ();
-		foreach (int num in SelectedIds ()) {
-			query.Photos [num].RemoveTag (t);
-			query.Commit (num);
-		}
+		RemoveTags (SelectedIds (), new Tag [] {t});
 		db.CommitTransaction ();
 		query_widget.PhotoTagsChanged (new Tag [] {t});
 	}
@@ -1910,9 +1910,7 @@
 	void AttachTags (Tag [] tags, int [] ids) 
 	{
 		db.BeginTransaction ();
-		foreach (int num in ids) {
-			AddTagExtended (num, tags);
-		}
+		AddTagExtended (ids, tags);
 		db.CommitTransaction ();
 		query_widget.PhotoTagsChanged (tags);
 	}
@@ -1922,13 +1920,7 @@
 		Tag [] tags = this.tag_selection_widget.TagHighlight;
 
 		db.BeginTransaction ();
-		foreach (int num in SelectedIds ()) {
-			Photo p = query.Photos [num];
-
-			p.RemoveTag (tags);
-
-			query.Commit (num);
-		}
+		RemoveTags (SelectedIds (), tags);
 		db.CommitTransaction ();
 		query_widget.PhotoTagsChanged (tags);
 	}
@@ -3079,7 +3071,8 @@
 			else
 				default_category = selection [0].Category;
 		}
-
+		Tag [] tags = new Tag [new_tags.Length];
+		int i = 0;
 		db.BeginTransaction ();
 		foreach (string tagname in new_tags) {
 			Tag t = db.Tags.GetTagByName (tagname);
@@ -3087,13 +3080,9 @@
 				t = db.Tags.CreateCategory (default_category, tagname) as Tag;
 				db.Tags.Commit (t);
 			}
-
-			Tag [] tags = new Tag [1];
-			tags [0] = t;
-
-			foreach (int num in selected_photos)
-				AddTagExtended (num, tags);
+			tags [i++] = t;
 		}
+		AddTagExtended (selected_photos, tags);
 		db.CommitTransaction ();
 	}
 
@@ -3103,12 +3092,9 @@
 		if (selected_photos == null || remove_tags == null || remove_tags.Length == 0)
 			return;
 
-		foreach (Tag t in remove_tags) {
-			foreach (int num in selected_photos) {
-				query.Photos [num].RemoveTag (t);
-				query.Commit (num);
-			}
-		}
+		db.BeginTransaction ();
+		RemoveTags (selected_photos, remove_tags);
+		db.CommitTransaction ();
 	}
 
 	private void HideTagbar ()

Modified: trunk/src/PhotoQuery.cs
==============================================================================
--- trunk/src/PhotoQuery.cs	(original)
+++ trunk/src/PhotoQuery.cs	Fri Jun 13 10:17:08 2008
@@ -184,15 +184,21 @@
 			return System.Array.IndexOf (photos, photo);
 		}
 		
-		public void Commit (int index) 
+		public void Commit (params int [] indexes)
 		{
-			store.Commit (photos[index]);
-			MarkChanged (index);
+			foreach (int index in indexes)
+				store.Commit (photos[index]);
+			MarkChanged (indexes);
 		}
-		
+
 		public void MarkChanged (int index)
 		{
-			ItemsChanged (this, new BrowsableEventArgs (index));
+			MarkChanged (new int [] {index});
+		}
+
+		public void MarkChanged (params int [] indexes)
+		{
+			ItemsChanged (this, new BrowsableEventArgs (indexes));
 		}
 	}
 }



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