[f-spot] DragDropUtils.cs added



commit c0f6a8aec8507f0536c7fa8bcddc00f8434c1465
Author: Mike Gemuende <mike gemuende de>
Date:   Mon Jun 22 16:35:11 2009 +0200

    DragDropUtils.cs added

 src/DragDropUtils.cs |  125 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)
---
diff --git a/src/DragDropUtils.cs b/src/DragDropUtils.cs
new file mode 100644
index 0000000..0bf2174
--- /dev/null
+++ b/src/DragDropUtils.cs
@@ -0,0 +1,125 @@
+/*
+ * DragDropUtils.cs
+ *
+ * Author(s)
+ * 	Mike Gemuende <mike gemuende de>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+
+
+using System;
+using System.Text;
+
+using Gtk;
+
+using Gdk;
+
+using FSpot;
+using FSpot.Utils;
+
+
+
+
+namespace FSpot.Gui
+{
+	
+	public static class DragDropUtils
+	{
+		
+		public static void SetPhotosData (Photo [] photos, SelectionData selection_data, Atom target)
+		{
+			byte [] data = new byte [photos.Length * sizeof (uint)];
+			
+			int i = 0;
+			foreach (Photo photo in photos) {
+				byte [] bytes = System.BitConverter.GetBytes (photo.Id);
+				
+				foreach (byte b in bytes) {
+					data[i] = b;
+					i++;
+				}
+			}
+			
+			selection_data.Set (target, 8, data, data.Length);
+		}
+		
+		public static Photo [] GetPhotosData (SelectionData selection_data)
+		{
+			int size = sizeof (uint);
+			int length = selection_data.Length / size;
+			
+			PhotoStore photo_store = MainWindow.Toplevel.Database.Photos;
+
+			Photo [] photos = new Photo [length];
+			
+			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, Atom target)
+		{
+			byte [] data = new byte [tags.Length * sizeof (uint)];
+			
+			int i = 0;
+			foreach (Tag tag in tags) {
+				byte [] bytes = System.BitConverter.GetBytes (tag.Id);
+				
+				foreach (byte b in bytes) {
+					data[i] = b;
+					i++;
+				}
+			}
+			
+			selection_data.Set (target, 8, data, data.Length);
+		}
+		
+		public static Tag [] GetTagsData (SelectionData selection_data)
+		{
+			int size = sizeof (uint);
+			int length = selection_data.Length / size;
+			
+			TagStore tag_store = MainWindow.Toplevel.Database.Tags;
+
+			Tag [] tags = new Tag [length];
+			
+			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 selection_data)
+		{
+			if (selection_data.Length <= 0)
+				return String.Empty;
+			
+			try {
+				return Encoding.UTF8.GetString (selection_data.Data);
+			} catch (Exception) {
+				return String.Empty;
+			}
+		}
+		
+		public static void SetUriListData (UriList uri_list, SelectionData selection_data, Atom target)
+		{
+			Byte [] data = Encoding.UTF8.GetBytes (uri_list.ToString ());
+			
+			selection_data.Set (target, 8, data, data.Length);
+		}
+		
+		public static UriList GetUriListData (SelectionData selection_data)
+		{
+			string [] uris = GetStringData (selection_data).Split ('\n');
+			
+			return new UriList (uris);
+		}
+	}
+}



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