[f-spot] change storage of drag data for photo- and tag-ids



commit 886e4150ee0484a0c0c42cc3cfb2a30db241776e
Author: Mike Gemuende <mike gemuende de>
Date:   Mon Jun 22 13:36:14 2009 +0200

    change storage of drag data for photo- and tag-ids

 src/DragDrop.cs           |   93 +++++++++++++++++++++++----------------------
 src/MainWindow.cs         |   16 +++++--
 src/TagCommands.cs        |    1 +
 src/TagSelectionWidget.cs |   11 ++++-
 4 files changed, 68 insertions(+), 53 deletions(-)
---
diff --git a/src/DragDrop.cs b/src/DragDrop.cs
index e79ecd7..242bca8 100644
--- a/src/DragDrop.cs
+++ b/src/DragDrop.cs
@@ -52,94 +52,97 @@ namespace FSpot.GuiUtils
 		public static readonly TargetEntry RootWindowEntry =
 			new TargetEntry ("application/x-root-window-drop", 0, (uint) TargetType.RootWindow);
 		
-		/* FIXME: we use a list of photo ids. Maybe this can be encoded more efficiently */
-		public static void SetPhotosData (Photo [] photos, SelectionData selection_data)
+
+		public static void SetPhotosData (Photo [] photos, SelectionData selection_data, Gdk.Atom target)
 		{
-			StringBuilder builder = new StringBuilder ();
+			byte [] data = new byte [photos.Length * sizeof (uint)];
+			
+			int i = 0;
 			foreach (Photo photo in photos) {
-
-				if (builder.Length == 0)
-					builder.Append (photo.Id);
-				else
-					builder.AppendFormat (" {0}", photo.Id);
+				byte [] bytes = System.BitConverter.GetBytes (photo.Id);
+				
+				foreach (byte b in bytes) {
+					data[i] = b;
+					i++;
+				}
 			}
 			
-			Byte [] data = Encoding.UTF8.GetBytes (builder.ToString ());
-			Gdk.Atom [] targets = args.Context.Targets;
-			
-			selection_data.Set (targets[0], 8, data, data.Length);
+			selection_data.Set (target, 8, data, data.Length);
 		}
 		
-		public static Photo [] GetPhotosData (SelectionData data)
+		public static Photo [] GetPhotosData (SelectionData selection_data)
 		{
-			string [] values = GetStringData (data).Split (' ');
+			int size = sizeof (uint);
+			int length = selection_data.Length / size;
 			
-			Photo [] photos = new Photo [values.Length];
+			PhotoStore photo_store = MainWindow.Toplevel.Database.Photos;
+
+			Photo [] photos = new Photo [length];
 			
-			for (int i = 0; i < values.Length; i++) {
-				uint id = Convert.ToUInt32 (values[i]);
-				
-				photos[i] = MainWindow.Toplevel.Database.Photos.Get (id);
+			for (int i = 0; i < length; i ++) {
+				uint id = System.BitConverter.ToUInt32 (selection_data.Data, i * size);
+				photos[i] = photo_store.Get (id);
 			}
 
 			return photos;
 		}
 		
-		public static void SetTagsData (Tag [] tags, SelectionData selection_data)
+		public static void SetTagsData (Tag [] tags, SelectionData selection_data, Gdk.Atom target)
 		{
-			StringBuilder builder = new StringBuilder ();
+			byte [] data = new byte [tags.Length * sizeof (uint)];
+			
+			int i = 0;
 			foreach (Tag tag in tags) {
-
-				if (builder.Length == 0)
-					builder.Append (tag.Id);
-				else
-					builder.AppendFormat (" {0}", tag.Id);
+				byte [] bytes = System.BitConverter.GetBytes (tag.Id);
+				
+				foreach (byte b in bytes) {
+					data[i] = b;
+					i++;
+				}
 			}
 			
-			Byte [] data = Encoding.UTF8.GetBytes (builder.ToString ());
-			Gdk.Atom [] targets = args.Context.Targets;
-			
-			selection_data.Set (targets[0], 8, data, data.Length);
+			selection_data.Set (target, 8, data, data.Length);
 		}
 		
-		public static Tag [] GetTagsData (SelectionData data)
+		public static Tag [] GetTagsData (SelectionData selection_data)
 		{
-			string [] values = GetStringData (data).Split (' ');
+			int size = sizeof (uint);
+			int length = selection_data.Length / size;
 			
-			Tag [] tags = new Tag [values.Length];
+			TagStore tag_store = MainWindow.Toplevel.Database.Tags;
+
+			Tag [] tags = new Tag [length];
 			
-			for (int i = 0; i < values.Length; i++) {
-				uint id = Convert.ToUInt32 (values[i]);
-				
-				tags[i] = MainWindow.Toplevel.Database.Tags.Get (id);
+			for (int i = 0; i < length; i ++) {
+				uint id = System.BitConverter.ToUInt32 (selection_data.Data, i * size);
+				tags[i] = tag_store.Get (id);
 			}
 
 			return tags;
 		}
 		
-		public static string GetStringData (SelectionData data)
+		public static string GetStringData (SelectionData selection_data)
 		{
-			if (data.Length <= 0)
+			if (selection_data.Length <= 0)
 				return String.Empty;
 			
 			try {
-				return Encoding.UTF8.GetString (data.Data);
+				return Encoding.UTF8.GetString (selection_data.Data);
 			} catch (Exception) {
 				return String.Empty;
 			}
 		}
 		
-		public static void SetUriListData (UriList uri_list, DragDataGetArgs args)
+		public static void SetUriListData (UriList uri_list, SelectionData selection_data, Gdk.Atom target)
 		{
 			Byte [] data = Encoding.UTF8.GetBytes (uri_list.ToString ());
-			Gdk.Atom [] targets = args.Context.Targets;
 			
-			args.SelectionData.Set (targets[0], 8, data, data.Length);
+			selection_data.Set (target, 8, data, data.Length);
 		}
 		
-		public static UriList GetUriListData (SelectionData data)
+		public static UriList GetUriListData (SelectionData selection_data)
 		{
-			string [] uris = GetStringData (data).Split ('\n');
+			string [] uris = GetStringData (selection_data).Split ('\n');
 			
 			return new UriList (uris);
 		}
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index c79ef76..e222916 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -378,7 +378,7 @@ public class MainWindow {
 
 		tag_selection_widget.ButtonPressEvent += HandleTagSelectionButtonPressEvent;
 		tag_selection_widget.PopupMenu += HandleTagSelectionPopupMenu;
-		tag_selection_widget.RowActivated += HandleTagSelectionRowActivated;
+//		tag_selection_widget.RowActivated += HandleTagSelectionRowActivated;
 		
 		LoadPreference (Preferences.TAG_ICON_SIZE);
 		
@@ -953,6 +953,12 @@ public class MainWindow {
 			db.Tags.Commit (t);
 		}
 	}
+	
+	public void AddTagsQuery (Tag [] tags)
+	{
+		ShowQueryWidget ();
+		query_widget.Include (tags);
+	}
 
 	public void RemoveTags (int [] nums, Tag [] tags)
 	{
@@ -961,11 +967,11 @@ public class MainWindow {
 		query.Commit (nums);
 	}
 
-	void HandleTagSelectionRowActivated (object sender, RowActivatedArgs args)
+/*	void HandleTagSelectionRowActivated (object sender, RowActivatedArgs args)
 	{
 		ShowQueryWidget ();
 		query_widget.Include (new Tag [] {tag_selection_widget.TagByPath (args.Path)});
-	}
+	}*/
 
 	void HandleTagSelectionButtonPressEvent (object sender, ButtonPressEventArgs args)
 	{
@@ -1295,12 +1301,12 @@ public class MainWindow {
 		  */
 		
 		if (args.Info == DragDrop.UriListEntry.Info) {
-			DragDrop.SetUriListData (new UriList (SelectedPhotos ()), args);
+			DragDrop.SetUriListData (new UriList (SelectedPhotos ()), args.SelectionData, args.Context.Targets[0]);
 			return;
 		}
 		
 		if (args.Info == DragDrop.PhotoListEntry.Info) {
-			DragDrop.SetPhotosData (SelectedPhotos (), args.SelectionData);
+			DragDrop.SetPhotosData (SelectedPhotos (), args.SelectionData, args.Context.Targets[0]);
 			return;
 		}
 		
diff --git a/src/TagCommands.cs b/src/TagCommands.cs
index f22bc8e..0a3637a 100644
--- a/src/TagCommands.cs
+++ b/src/TagCommands.cs
@@ -123,6 +123,7 @@ public class TagCommands {
 				}
 			}
 		}
+		
 		public Tag Execute (TagType type, Tag [] selection)
 		{
 			this.CreateDialog ("create_tag_dialog");
diff --git a/src/TagSelectionWidget.cs b/src/TagSelectionWidget.cs
index e85aa19..3bca162 100644
--- a/src/TagSelectionWidget.cs
+++ b/src/TagSelectionWidget.cs
@@ -654,7 +654,7 @@ namespace FSpot {
 		void HandleDragDataGet (object sender, DragDataGetArgs args)
 		{
 			if (args.Info == FSpot.GuiUtils.DragDrop.TagListEntry.Info) {
-				FSpot.GuiUtils.DragDrop.SetTagsData (TagHighlight, args.SelectionData);
+				FSpot.GuiUtils.DragDrop.SetTagsData (TagHighlight, args.SelectionData, args.Context.Targets[0]);
 				return;
 			}
 		}
@@ -707,9 +707,9 @@ namespace FSpot {
 	
 			if (args.Info == GuiUtils.DragDrop.PhotoListEntry.Info) {
 				database.BeginTransaction ();
-
-				Photo[] photos = FSpot.GuiUtils.DragDrop.GetPhotosData (args.SelectionData);
 				
+				Photo[] photos = FSpot.GuiUtils.DragDrop.GetPhotosData (args.SelectionData);
+
 				foreach (Photo photo in photos) {
 
 					if (photo == null)
@@ -785,6 +785,11 @@ namespace FSpot {
 				return;
 			}
 		}
+		
+		protected override void OnRowActivated (Gtk.TreePath path, Gtk.TreeViewColumn column)
+		{
+			MainWindow.Toplevel.AddTagsQuery (new Tag [] {TagByPath (path)});			
+		}
 	
 	
 	#if TEST_TAG_SELECTION_WIDGET



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