[f-spot] Update hashtables to Dictionaries



commit 132c72be32151e37e3330ec6cb846fab0333bcab
Author: Stephen Shaw <sshaw decriptor com>
Date:   Thu Nov 24 20:19:55 2011 -0700

    Update hashtables to Dictionaries
    
    All but a few in Extensions has been replaced
      They are required by gnome-keyring bindings
    This also gets rid of the last ArrayList

 src/Clients/MainApp/FSpot.Widgets/Filmstrip.cs     |    8 +++--
 src/Clients/MainApp/FSpot.Widgets/TagEntry.cs      |    4 +-
 src/Clients/MainApp/FSpot/PixbufCache.cs           |   26 +++++++------
 src/Clients/MainApp/FSpot/Term.cs                  |    2 -
 src/Clients/MainApp/FSpot/ThumbnailCache.cs        |   14 ++++----
 src/Clients/MainApp/PhotoTagMenu.cs                |   38 ++++----------------
 .../FSpot.Exporters.Facebook/FacebookExport.cs     |   11 ++----
 .../FSpot.Exporters.Folder/FolderExport.cs         |   19 +++++-----
 8 files changed, 48 insertions(+), 74 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.Widgets/Filmstrip.cs b/src/Clients/MainApp/FSpot.Widgets/Filmstrip.cs
index f98d173..7b33096 100644
--- a/src/Clients/MainApp/FSpot.Widgets/Filmstrip.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/Filmstrip.cs
@@ -5,6 +5,7 @@
 //   Ruben Vermeersch <ruben savanne be>
 //   Lorenzo Milesi <maxxer yetopen it>
 //   Stephane Delcroix <stephane delcroix org>
+//   Stephen Shaw <sshaw decriptor com>
 //
 // Copyright (C) 2008-2010 Novell, Inc.
 // Copyright (C) 2008, 2010 Ruben Vermeersch
@@ -37,6 +38,7 @@
 
 using System;
 using System.Collections;
+using System.Collections.Generic;
 
 using Gtk;
 using Gdk;
@@ -304,7 +306,7 @@ namespace FSpot.Widgets
 			}
 		}
 
-		Hashtable start_indexes;
+		Dictionary<int,int> start_indexes;
 		int filmstrip_start_pos;
 		int filmstrip_end_pos;
 		protected override bool OnExposeEvent (EventExpose evnt)
@@ -335,7 +337,7 @@ namespace FSpot.Widgets
 					BackgroundPixbuf.Width, BackgroundPixbuf.Height, Gdk.RgbDither.None, 0, 0);
 
 			//drawing the icons...
-			start_indexes = new Hashtable ();
+			start_indexes = new Dictionary<int, int> ();
 
 			Pixbuf icon_pixbuf = null;
 			if (Orientation == Orientation.Horizontal)
@@ -523,7 +525,7 @@ namespace FSpot.Widgets
 			foreach (int key in start_indexes.Keys)
 				if (key <= (Orientation == Orientation.Horizontal ? evnt.X : evnt.Y) && key > pos)
 					pos = key;
-			ActiveItem = (int)start_indexes [pos];
+			ActiveItem = start_indexes [pos];
 			return true;
 		}
 
diff --git a/src/Clients/MainApp/FSpot.Widgets/TagEntry.cs b/src/Clients/MainApp/FSpot.Widgets/TagEntry.cs
index 6fa569d..ad18266 100644
--- a/src/Clients/MainApp/FSpot.Widgets/TagEntry.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/TagEntry.cs
@@ -70,13 +70,13 @@ namespace FSpot.Widgets
 		List<string> selected_photos_tagnames;
 		public void UpdateFromSelection (IPhoto [] sel)
 		{
-			Hashtable taghash = new Hashtable ();
+			Dictionary<Tag,int> taghash = new Dictionary<Tag,int> ();
 
 			for (int i = 0; i < sel.Length; i++) {
 				foreach (Tag tag in sel [i].Tags) {
 					int count = 1;
 
-					if (taghash.Contains (tag))
+					if (taghash.ContainsKey (tag))
 						count = ((int) taghash [tag]) + 1;
 
 					if (count <= i)
diff --git a/src/Clients/MainApp/FSpot/PixbufCache.cs b/src/Clients/MainApp/FSpot/PixbufCache.cs
index d73059b..cb4e605 100644
--- a/src/Clients/MainApp/FSpot/PixbufCache.cs
+++ b/src/Clients/MainApp/FSpot/PixbufCache.cs
@@ -38,9 +38,11 @@ using Hyena;
 using FSpot.Utils;
 using FSpot.Platform;
 
-namespace FSpot {
-	public class PixbufCache {
-		Hashtable items;
+namespace FSpot
+{
+	public class PixbufCache
+	{
+		Dictionary<SafeUri,CacheEntry> items;
 		List<CacheEntry> items_mru;
 		int total_size;
 		int max_size = 256 * 256 * 4 * 30;
@@ -52,7 +54,7 @@ namespace FSpot {
 
 		public PixbufCache ()
 		{
-			items = new Hashtable ();
+			items = new Dictionary<SafeUri, CacheEntry> ();
 			items_mru = new List<CacheEntry> ();
 
 			worker = new Thread (new ThreadStart (WorkerTask));
@@ -69,7 +71,7 @@ namespace FSpot {
 		public void Request (SafeUri uri, object closure, int width, int height)
 		{
 			lock (items) {
-				CacheEntry entry = items[uri] as CacheEntry;
+				CacheEntry entry = items[uri];
 
 				if (entry == null) {
 					entry = new CacheEntry (this, uri, closure, width, height);
@@ -86,7 +88,7 @@ namespace FSpot {
 //		public void Update (SafeUri uri, Gdk.Pixbuf pixbuf)
 //		{
 //			lock (items) {
-//				CacheEntry entry = (CacheEntry) items [uri];
+//				CacheEntry entry = items [uri];
 //				if (entry != null) {
 //					entry.SetPixbufExtended (pixbuf, true);
 //				}
@@ -118,7 +120,7 @@ namespace FSpot {
 			CacheEntry entry;
 
 			lock (items) {
-				entry = (CacheEntry) items [uri];
+				entry = items [uri];
 				if (entry != null) {
 					lock (entry) {
 						entry.Reload = true;
@@ -139,7 +141,7 @@ namespace FSpot {
 				return null;
 			}
 			while (i-- > 0) {
-				entry = (CacheEntry) items_mru [i];
+				entry = items_mru [i];
 				lock (entry) {
 					if (entry.Reload) {
 						entry.Reload = false;
@@ -165,7 +167,7 @@ namespace FSpot {
 		{
 			int num = 0;
 			while ((items_mru.Count - num) > 10 && total_size > max_size) {
-				CacheEntry entry = (CacheEntry) items_mru [num++];
+				CacheEntry entry = items_mru [num++];
 				items.Remove (entry.Uri);
 				entry.Dispose ();
 			}
@@ -231,7 +233,7 @@ namespace FSpot {
 			CacheEntry tmp1 = entry;
 			CacheEntry tmp2;
 			while (i-- > 0) {
-				tmp2 = (CacheEntry) items_mru [i];
+				tmp2 = items_mru [i];
 				items_mru [i] = tmp1;
 				tmp1 = tmp2;
 				if (tmp2 == entry)
@@ -247,7 +249,7 @@ namespace FSpot {
 
 		private CacheEntry ULookup (SafeUri uri)
 		{
-			CacheEntry entry = (CacheEntry) items [uri];
+			CacheEntry entry = items [uri];
 			if (entry != null) {
 				MoveForward (entry);
 			}
@@ -263,7 +265,7 @@ namespace FSpot {
 
 		private void URemove (SafeUri uri)
 		{
-			CacheEntry entry = (CacheEntry) items [uri];
+			CacheEntry entry = items [uri];
 			if (entry != null) {
 				items.Remove (uri);
 				items_mru.Remove (entry);
diff --git a/src/Clients/MainApp/FSpot/Term.cs b/src/Clients/MainApp/FSpot/Term.cs
index da2e89a..0ed83ce 100644
--- a/src/Clients/MainApp/FSpot/Term.cs
+++ b/src/Clients/MainApp/FSpot/Term.cs
@@ -307,8 +307,6 @@ else
 			return String.Empty;
 		}
 
-		protected static Hashtable op_term_lookup = new Hashtable ();
-
 		public static Term TermFromOperator (string op, Term parent, Literal after)
 		{
 			//Console.WriteLine ("finding type for operator {0}", op);
diff --git a/src/Clients/MainApp/FSpot/ThumbnailCache.cs b/src/Clients/MainApp/FSpot/ThumbnailCache.cs
index 5ee075e..c785c5e 100644
--- a/src/Clients/MainApp/FSpot/ThumbnailCache.cs
+++ b/src/Clients/MainApp/FSpot/ThumbnailCache.cs
@@ -5,6 +5,7 @@
 //   Ettore Perazzoli <ettore src gnome org>
 //   Larry Ewing <lewing novell com>
 //   Stephane Delcroix <sdelcroix novell com>
+//   Stephen Shaw <sshaw decriptor com>
 //
 // Copyright (C) 2003-2008 Novell, Inc.
 // Copyright (C) 2003 Ettore Perazzoli
@@ -43,8 +44,7 @@ namespace FSpot
 {
 	public class ThumbnailCache : IDisposable {
 	
-		// Types.
-	
+		#region Types
 		private class Thumbnail {
 			// Uri of the image source
 			public SafeUri uri;
@@ -52,13 +52,13 @@ namespace FSpot
 			// The uncompressed thumbnail.
 			public Pixbuf pixbuf;
 		}
-	
+		#endregion
 	
 		#region Private members and constants
 		private const int DEFAULT_CACHE_SIZE = 2;
 		private int max_count;
 		private List<Thumbnail> pixbuf_mru;
-		private Hashtable pixbuf_hash;
+		private Dictionary<SafeUri,Thumbnail> pixbuf_hash;
 		static private ThumbnailCache defaultcache = new ThumbnailCache (DEFAULT_CACHE_SIZE);
 		#endregion
 	
@@ -67,7 +67,7 @@ namespace FSpot
 		{
 			this.max_count = max_count;
 			pixbuf_mru = new List<Thumbnail> (max_count);
-			pixbuf_hash = new Hashtable();
+			pixbuf_hash = new Dictionary<SafeUri, Thumbnail> ();
 		}
 	
 		static public ThumbnailCache Default {
@@ -96,7 +96,7 @@ namespace FSpot
 			if (! pixbuf_hash.ContainsKey (uri))
 				return null;
 	
-			Thumbnail item = pixbuf_hash [uri] as Thumbnail;
+			Thumbnail item = pixbuf_hash [uri];
 	
 			pixbuf_mru.Remove (item);
 			pixbuf_mru.Insert (0, item);
@@ -111,7 +111,7 @@ namespace FSpot
 			if (! pixbuf_hash.ContainsKey (uri))
 				return;
 	
-			Thumbnail item = pixbuf_hash [uri] as Thumbnail;
+			Thumbnail item = pixbuf_hash [uri];
 	
 			pixbuf_hash.Remove (uri);
 			pixbuf_mru.Remove (item);
diff --git a/src/Clients/MainApp/PhotoTagMenu.cs b/src/Clients/MainApp/PhotoTagMenu.cs
index d24c196..bf183c6 100644
--- a/src/Clients/MainApp/PhotoTagMenu.cs
+++ b/src/Clients/MainApp/PhotoTagMenu.cs
@@ -3,6 +3,7 @@
 //
 // Author:
 //   Larry Ewing <lewing novell com>
+//   Stephen Shaw <sshaw decriptor com>
 //
 // Copyright (C) 2004-2006 Novell, Inc.
 // Copyright (C) 2004, 2006 Larry Ewing
@@ -27,34 +28,9 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-//
-// PhotoTagMenu.cs
-//
-// Copyright (C) 2004 Novell, Inc.
-//
-//
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-// DEALINGS IN THE SOFTWARE.
-//
-
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using Gtk;
 
 using FSpot;
@@ -71,12 +47,12 @@ public class PhotoTagMenu : Menu {
 	protected PhotoTagMenu (IntPtr raw) : base (raw) {}
 
 	public void Populate (IPhoto [] photos) {
-		Hashtable hash = new Hashtable ();
+		Dictionary<uint, Tag> dict = new Dictionary<uint, Tag> ();
 		if (photos != null) {
 			foreach (IPhoto p in photos) {
 				foreach (Tag t in p.Tags) {
-					if (!hash.Contains (t.Id)) {
-						hash.Add (t.Id, t);
+					if (!dict.ContainsKey (t.Id)) {
+						dict.Add (t.Id, t);
 					}
 				}
 			}
@@ -86,7 +62,7 @@ public class PhotoTagMenu : Menu {
 			w.Destroy ();
 		}
 
-		if (hash.Count == 0) {
+		if (dict.Count == 0) {
 			/* Fixme this should really set parent menu
 			   items insensitve */
 			MenuItem item = new MenuItem (Mono.Unix.Catalog.GetString ("(No Tags)"));
@@ -96,7 +72,7 @@ public class PhotoTagMenu : Menu {
 			return;
 		}
 
-		foreach (Tag t in hash.Values) {
+		foreach (Tag t in dict.Values) {
 			MenuItem item = new TagMenu.TagMenuItem (t);
 			this.Append (item);
 			item.ShowAll ();
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Facebook/FSpot.Exporters.Facebook/FacebookExport.cs b/src/Extensions/Exporters/FSpot.Exporters.Facebook/FSpot.Exporters.Facebook/FacebookExport.cs
index 61bdb6d..5ec17be 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.Facebook/FSpot.Exporters.Facebook/FacebookExport.cs
+++ b/src/Extensions/Exporters/FSpot.Exporters.Facebook/FSpot.Exporters.Facebook/FacebookExport.cs
@@ -4,6 +4,7 @@
 // Author:
 //   Stephane Delcroix <stephane delcroix org>
 //   Jim Ramsay <i am jimramsay com>
+//   Stephen Shaw <sshaw decriptor com>
 //
 // Copyright (C) 2007-2009 Novell, Inc.
 // Copyright (C) 2007-2009 Stephane Delcroix
@@ -30,27 +31,20 @@
 //
 
 using System;
-using System.Net;
 using System.IO;
-using System.Text;
 using System.Threading;
 using System.Collections;
 using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Web;
 using Mono.Unix;
 using Gtk;
 using Gnome.Keyring;
-using GtkBeans;
 
-using FSpot;
 using FSpot.Core;
 using Hyena;
 using Hyena.Widgets;
 using FSpot.UI.Dialog;
 using FSpot.Extensions;
 using FSpot.Filters;
-using FSpot.Platform;
 
 using Mono.Facebook;
 
@@ -149,6 +143,7 @@ namespace FSpot.Exporters.Facebook
 			}
 
 			Hashtable attribs = new Hashtable();
+			//Dictionary<string,string> attribs = new  Dictionary<string, string> ();
 			attribs["name"] = keyring_item_name;
 			attribs["uid"] = info.uid.ToString ();
 			attribs["session_key"] = info.session_key;
@@ -167,6 +162,7 @@ namespace FSpot.Exporters.Facebook
 			SessionInfo info = null;
 
 			Hashtable request_attributes = new Hashtable ();
+			//Dictionary<string, string> request_attributes = new Dictionary<string, string> ();
 			request_attributes["name"] = keyring_item_name;
 			try {
 				foreach (ItemData result in Ring.Find (ItemType.GenericSecret, request_attributes)) {
@@ -202,6 +198,7 @@ namespace FSpot.Exporters.Facebook
 			}
 
 			Hashtable request_attributes = new Hashtable ();
+			//Dictionary<string,string> request_attributes = new Dictionary<string, string> ();
 			request_attributes["name"] = keyring_item_name;
 			try {
 				foreach (ItemData result in Ring.Find (ItemType.GenericSecret, request_attributes)) {
diff --git a/src/Extensions/Exporters/FSpot.Exporters.Folder/FSpot.Exporters.Folder/FolderExport.cs b/src/Extensions/Exporters/FSpot.Exporters.Folder/FSpot.Exporters.Folder/FolderExport.cs
index 0d6e0c0..3e1ebfb 100644
--- a/src/Extensions/Exporters/FSpot.Exporters.Folder/FSpot.Exporters.Folder/FolderExport.cs
+++ b/src/Extensions/Exporters/FSpot.Exporters.Folder/FSpot.Exporters.Folder/FolderExport.cs
@@ -749,10 +749,9 @@ namespace FSpot.Exporters.Folder {
 		static string light = Catalog.GetString("Light");
 		static string dark = Catalog.GetString("Dark");
 
-		// FIXME: Need to clean up the ArrayList and Hashtable at the same time.
-		ArrayList allTagNames = new ArrayList ();
-		Hashtable allTags = new Hashtable ();
-		Hashtable tagSets = new Hashtable ();
+		List<string> allTagNames = new List<string> ();
+		Dictionary<string,Tag> allTags = new Dictionary<string, Tag> ();
+		Dictionary<string, List<int>> tagSets = new Dictionary<string, List<int>> ();
 
 		public HtmlGallery (IBrowsableCollection selection, string path, string name) : base (selection, path, name)
 		{
@@ -788,14 +787,14 @@ namespace FSpot.Exporters.Folder {
 				foreach (IPhoto photo in photos) {
 					foreach (var tag in photo.Tags) {
 						if (!tagSets.ContainsKey (tag.Name)) {
-							tagSets.Add (tag.Name, new ArrayList ());
+							tagSets.Add (tag.Name, new List<int> ());
 							allTags.Add (tag.Name, tag);
 						}
-						((ArrayList) tagSets [tag.Name]).Add (i);
+						tagSets [tag.Name].Add (i);
 					}
 					i++;
 				}
-				allTagNames = new ArrayList (tagSets.Keys);
+				allTagNames = new List<string> (tagSets.Keys);
 				allTagNames.Sort ();
 
 				// create tag pages
@@ -858,7 +857,7 @@ namespace FSpot.Exporters.Folder {
 
 		public int TagPageCount (string tag)
 		{
-			return (int) System.Math.Ceiling (((ArrayList) tagSets [tag]).Count / (double)perpage);
+			return (int) System.Math.Ceiling (tagSets [tag].Count / (double)perpage);
 		}
 
 		public string PhotoThumbPath (int item)
@@ -1088,7 +1087,7 @@ namespace FSpot.Exporters.Folder {
 
 		public void WriteTagsLinks (System.Web.UI.HtmlTextWriter writer, Tag[] tags)
 		{
-			ArrayList tagsList = new ArrayList (tags.Length);
+			List<Tag> tagsList = new List<Tag> (tags.Length);
 			foreach (var tag in tags) {
 				tagsList.Add (tag);
 			}
@@ -1270,7 +1269,7 @@ namespace FSpot.Exporters.Folder {
 			writer.RenderBeginTag ("div");
 
 			int start = page_num * perpage;
-			ArrayList tagSet = (ArrayList) tagSets [tag];
+			List<int> tagSet = tagSets [tag];
 			int end = Math.Min (start + perpage, tagSet.Count);
 			for (i = start; i < end; i++) {
 				writer.AddAttribute ("href", PhotoIndexPath ((int) tagSet [i]));



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