nemo r134 - in trunk: broker common gtk metadata uicommon



Author: arj
Date: Tue Sep 16 18:19:55 2008
New Revision: 134
URL: http://svn.gnome.org/viewvc/nemo?rev=134&view=rev

Log:
Minor fixes and refactorings

Found with gendarme:
- Split a mega function into several helper functions
- Converted a lot of "" to string.Empty
- added static to classes that have only static methods
- fixed a locking problem with the singleton pattern



Modified:
   trunk/broker/Tracker.cs
   trunk/broker/Xesam.cs
   trunk/common/Common.cs
   trunk/gtk/Cairo.cs
   trunk/gtk/CalendarDrawer.cs
   trunk/gtk/Common.cs
   trunk/gtk/DisplayItem.cs
   trunk/gtk/MainWindow.cs
   trunk/gtk/OSSpecific.cs
   trunk/gtk/SearchPopup.cs
   trunk/metadata/MetadataStore.cs
   trunk/uicommon/DocumentItem.cs
   trunk/uicommon/Item.cs

Modified: trunk/broker/Tracker.cs
==============================================================================
--- trunk/broker/Tracker.cs	(original)
+++ trunk/broker/Tracker.cs	Tue Sep 16 18:19:55 2008
@@ -159,7 +159,7 @@
 	    public override void search_snippet(string uri, string search_string, VoidFunction<string> callback)
 	    {
 			ThreadPool.QueueUserWorkItem(delegate {
-				string result = "";
+				string result = string.Empty;
 				if (search_string.Length != 0)
 					result = bus_search.GetSnippet("Files", uri, search_string);
 				callback(result);

Modified: trunk/broker/Xesam.cs
==============================================================================
--- trunk/broker/Xesam.cs	(original)
+++ trunk/broker/Xesam.cs	Tue Sep 16 18:19:55 2008
@@ -40,7 +40,7 @@
 			finished = false;
 			iterating = false;
 			
-			session_id = "";
+			session_id = string.Empty;
 			
 			try {
 			    BusG.Init ();

Modified: trunk/common/Common.cs
==============================================================================
--- trunk/common/Common.cs	(original)
+++ trunk/common/Common.cs	Tue Sep 16 18:19:55 2008
@@ -33,7 +33,7 @@
 	    }
     }
 
-	class Helpers 
+	static class Helpers 
     {
 		public static VoidFunction<A> RunInMainThread<A>(VoidFunction<A> b)
 		{
@@ -231,7 +231,7 @@
         	return zip<int, T>(ints(), ie);
         }
 
-        public static bool sorted_lists_equal<T>(List<T> l1, List<T> l2) where T:IEquatable<T>
+        public static bool sorted_lists_equal<T>(T l1, T l2) where T:System.Collections.Generic.ICollection<T>
         {
             if (l1.Count != l2.Count)
                 return false;
@@ -283,7 +283,7 @@
 		public T wrapped;
 	}
 
-	public class Singleton<T>
+	static public class Singleton<T>
 	{
 	    private static T _instance;
 	    private static readonly object LOCK = new object();
@@ -292,8 +292,7 @@
 	    {
 	        get
 	        {
-	      		if (_instance == null)
-			      lock (LOCK)
+		        lock (LOCK)
 	                if (_instance == null)
 	                    _instance = (T)System.Activator.CreateInstance(typeof(T), true);
 	            return _instance;

Modified: trunk/gtk/Cairo.cs
==============================================================================
--- trunk/gtk/Cairo.cs	(original)
+++ trunk/gtk/Cairo.cs	Tue Sep 16 18:19:55 2008
@@ -7,8 +7,10 @@
 
 namespace Nemo
 {	
-	public class CairoDrawing
+	static public class CairoDrawing
 	{
+		private static string tmp_image_path = "/tmp/nemo_cairo.png";
+
 		public static Gtk.Image create_small_starred_image(string pic_path)
 		{
 			// evil hack because the interface to cairo is pretty bad
@@ -16,35 +18,35 @@
 
 			Stream img_s = asm.GetManifestResourceStream(pic_path);
 
-			FileStream img_fs = new System.IO.FileStream("/tmp/nemo_cairo.png", FileMode.Create);
+			FileStream img_fs = new System.IO.FileStream(tmp_image_path, FileMode.Create);
 			
 			for (int i = 0; i < img_s.Length; ++i)
 				img_fs.WriteByte((byte)img_s.ReadByte());
 				
 			img_fs.Close();
 			
-			using (Cairo.ImageSurface img_surface = new ImageSurface("/tmp/nemo_cairo.png")) {
-				System.IO.File.Delete("/tmp/nemo_cairo.png");
+			using (Cairo.ImageSurface img_surface = new ImageSurface(tmp_image_path)) {
+				System.IO.File.Delete(tmp_image_path);
 
 				using (Cairo.Context context = new Context(img_surface)) {
 					Stream s = asm.GetManifestResourceStream("starred_right.png");
 
-					FileStream fs = new System.IO.FileStream("/tmp/nemo_cairo.png", FileMode.Create);
+					FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create);
 					
 					for (int i = 0; i < s.Length; ++i)
 						fs.WriteByte((byte)s.ReadByte());
 						
 					fs.Close();
 					
-					using (Cairo.ImageSurface star_surface = new ImageSurface("/tmp/nemo_cairo.png")) {
-						System.IO.File.Delete("/tmp/nemo_cairo.png");
+					using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) {
+						System.IO.File.Delete(tmp_image_path);
 						
 						context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height);
 						context.Paint();
 
-						img_surface.WriteToPng("/tmp/nemo_cairo.png");
-						Gtk.Image img = new Gtk.Image("/tmp/nemo_cairo.png");
-						System.IO.File.Delete("/tmp/nemo_cairo.png");
+						img_surface.WriteToPng(tmp_image_path);
+						Gtk.Image img = new Gtk.Image(tmp_image_path);
+						System.IO.File.Delete(tmp_image_path);
 
 						return img;
 					}
@@ -73,22 +75,22 @@
 
 						Stream s = asm.GetManifestResourceStream("big_star.png");
 
-						FileStream fs = new System.IO.FileStream("/tmp/nemo_cairo.png", FileMode.Create);
+						FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create);
 						
 						for (int i = 0; i < s.Length; ++i)
 							fs.WriteByte((byte)s.ReadByte());
 							
 						fs.Close();
 						
-						using (Cairo.ImageSurface star_surface = new ImageSurface("/tmp/nemo_cairo.png")) {
-							System.IO.File.Delete("/tmp/nemo_cairo.png");
+						using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) {
+							System.IO.File.Delete(tmp_image_path);
 							
 							context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height);
 							context.Paint();
 
-							surface.WriteToPng("/tmp/nemo_cairo.png");
-							Gtk.Image img = new Gtk.Image("/tmp/nemo_cairo.png");
-							System.IO.File.Delete("/tmp/nemo_cairo.png");
+							surface.WriteToPng(tmp_image_path);
+							Gtk.Image img = new Gtk.Image(tmp_image_path);
+							System.IO.File.Delete(tmp_image_path);
 							return img;
 						}
 					}
@@ -111,9 +113,9 @@
 						context.SetSource(img_surface, 1, 1);
 						context.Paint();
 
-						surface.WriteToPng("/tmp/nemo_cairo.png");
-						Gtk.Image img = new Gtk.Image("/tmp/nemo_cairo.png");
-						System.IO.File.Delete("/tmp/nemo_cairo.png");
+						surface.WriteToPng(tmp_image_path);
+						Gtk.Image img = new Gtk.Image(tmp_image_path);
+						System.IO.File.Delete(tmp_image_path);
 						return img;
 					}
 				}
@@ -125,9 +127,9 @@
 			using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height)) {
 				using (Cairo.Context context = new Context(surface)) {
 					draw(context, width, height, new Cairo.Color(((double)r)/255, ((double)g)/255, ((double)b)/255, ((double)a)/255));
-					surface.WriteToPng("/tmp/nemo_cairo.png");
-					Gtk.Image img = new Gtk.Image("/tmp/nemo_cairo.png");
-					System.IO.File.Delete("/tmp/nemo_cairo.png");
+					surface.WriteToPng(tmp_image_path);
+					Gtk.Image img = new Gtk.Image(tmp_image_path);
+					System.IO.File.Delete(tmp_image_path);
 					return img;
 				}
 			}
@@ -136,9 +138,9 @@
 		public static Gtk.Image create_empty_image(int width, int height)
 		{
 			using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height)) {
-				surface.WriteToPng("/tmp/nemo_cairo.png");
-				Gtk.Image img = new Gtk.Image("/tmp/nemo_cairo.png");
-				System.IO.File.Delete("/tmp/nemo_cairo.png");
+				surface.WriteToPng(tmp_image_path);
+				Gtk.Image img = new Gtk.Image(tmp_image_path);
+				System.IO.File.Delete(tmp_image_path);
 				return img;
 			}
 		}

Modified: trunk/gtk/CalendarDrawer.cs
==============================================================================
--- trunk/gtk/CalendarDrawer.cs	(original)
+++ trunk/gtk/CalendarDrawer.cs	Tue Sep 16 18:19:55 2008
@@ -381,347 +381,296 @@
 		
 		List<ItemWrapper> last_elements;
 		
-		public void draw(CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
+		private void draw_day(Gtk.VBox calendar, CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
 		{
-			if (last_elements != null) {
-				if (last_elements != elements) {
-					last_elements = elements;
-					day_offset = 0;
-				}
-			} else
-				last_elements = elements;
-			
-			if (elements.Count > 0)
-				System.Console.WriteLine("hurray! elements");
+			Gtk.Viewport viewport = new Gtk.Viewport();
 
-			if (calendar_body != null) {
-				System.Console.WriteLine("cleaning up body of size:{0}", calendar_body.Children.Length);
-				foreach (Widget w in calendar_body.Children)
-					w.Destroy();
-				calendar_body.Dispose();
-			}
+			Gtk.VBox viewbox = new VBox();
+			viewbox.Add(calendar_body);
 			
-			foreach (CalendarFixedElement element in calendar_elements)
-				element.reset(); // workaround GTK-sharp signal bug
-				
-			calendar_elements.Clear();
-
-            // cleanup
-            foreach (Widget w in calendar_event_box.Children)
-				w.Destroy();
+			viewport.Add(viewbox);
 			
-			Gtk.VBox calendar = new Gtk.VBox();
-			Gtk.HBox calendar_middle = new Gtk.HBox(); 
-			Gtk.HBox calendar_top = new Gtk.HBox();
-		
-			calendar_event_box.Add(calendar);
-			GtkCommon.set_background_color(calendar_event_box, "gray");
-
-			Gtk.Table calendar_side_header = new Gtk.Table(1, 1, true);
-			calendar_side_header.RowSpacing = 2;
-			calendar_side_header.ColumnSpacing = 2;
+			Gtk.ScrolledWindow scrolled = new Gtk.ScrolledWindow();
+			scrolled.Add(viewport);
+			
+			calendar.PackStart(scrolled, true, true, 0);
 
-			Gtk.Table calendar_header = new Gtk.Table(1, 1, true);
-			calendar_header.RowSpacing = 2;
-			calendar_header.ColumnSpacing = 2;
+			today_button.Label = "Today";
+			current_date.Markup = "<b>" + String.Format("{0:dddd} {0:dd/MM/yy}", centered_date) + "</b>";
 
-			calendar_body = new Gtk.Table(1, 1, true);
-			calendar_body.RowSpacing = 2;
-			calendar_body.ColumnSpacing = 2;
+			Gdk.Rectangle last_allocation = new Gdk.Rectangle();
+			
+			foreach (Widget w in calendar_body.Children)
+				w.Destroy();
 
-			int days_in_week = 6; // lumb weekends together
+			uint cols = 3;
 
-			Singleton<OverlayTracker>.Instance.hide_and_die("time_overlay1");
-			Singleton<OverlayTracker>.Instance.hide_and_die("time_overlay2");
+			if (calendar_event_box.Allocation.Width >= 350)
+				cols = (uint)calendar_event_box.Allocation.Width/350;
+			
+			uint rows;
+			
+			if (elements.Count >= days_per_page) {
+				int elements_in_view = days_per_page;
+				if ((day_offset+1)*days_per_page > elements.Count) // last page
+					elements_in_view = elements.Count - day_offset*days_per_page;
+				rows = (uint)Math.Ceiling((elements_in_view*1.0)/cols);
+			} else
+				rows = (uint)Math.Ceiling((elements.Count*1.0)/cols);
 
-			if (state.view == CalendarDriver.View.Day)
-			{
-				Gtk.Viewport viewport = new Gtk.Viewport();
+			System.Console.WriteLine("elements: {0}, day_offset {1}", elements.Count, day_offset);
+			System.Console.WriteLine("cols {0} - rows {1}", cols, rows);
+			System.Console.WriteLine("width {0}, height {1}", calendar_event_box.Allocation.Width, calendar_event_box.Allocation.Height);
 
-				Gtk.VBox viewbox = new VBox();
-				viewbox.Add(calendar_body);
-				
-				viewport.Add(viewbox);
-				
-				Gtk.ScrolledWindow scrolled = new Gtk.ScrolledWindow();
-				scrolled.Add(viewport);
-				
-				calendar.PackStart(scrolled, true, true, 0);
+			calendar_body.Resize(rows, cols);
+		
+			uint col = 0, row = 0; 
 
-				today_button.Label = "Today";
-				current_date.Markup = "<b>" + String.Format("{0:dddd} {0:dd/MM/yy}", centered_date) + "</b>";
+			int element = 0;
+			
+			// fill in elements
+			foreach (ItemWrapper wrapper in elements)
+			{
+				if (!(element >= day_offset*days_per_page && element < (day_offset+1)*days_per_page)) {
+					++element;
+					continue;
+				}
 
-				Gdk.Rectangle last_allocation = new Gdk.Rectangle();
+				uint tmp_col = col;
+				uint tmp_row = row;
+				ItemWrapper tmp_wrapper = wrapper; // oh lambda bug, we love ye
+		
+				wrapper.item.on_data_callback = delegate {
+					calendar_body.Attach(tmp_wrapper.item.Display().get_representation(), tmp_col, tmp_col+1, tmp_row, tmp_row+1, 
+							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+										 AttachOptions.Shrink | AttachOptions.Fill,
+										 0,0);
+				};
 				
-				foreach (Widget w in calendar_body.Children)
-					w.Destroy();
-
-				uint cols = 3;
+				wrapper.item.on_data_callback();
 
-				if (calendar_event_box.Allocation.Width >= 350)
-					cols = (uint)calendar_event_box.Allocation.Width/350;
+	            col = ++col % cols;
+	            if (col == 0)
+	                ++row;
 				
-				uint rows;
-				
-				if (elements.Count >= days_per_page) {
-					int elements_in_view = days_per_page;
-					if ((day_offset+1)*days_per_page > elements.Count) // last page
-						elements_in_view = elements.Count - day_offset*days_per_page;
-					rows = (uint)Math.Ceiling((elements_in_view*1.0)/cols);
-				} else
-					rows = (uint)Math.Ceiling((elements.Count*1.0)/cols);
-
-				System.Console.WriteLine("elements: {0}, day_offset {1}", elements.Count, day_offset);
-				System.Console.WriteLine("cols {0} - rows {1}", cols, rows);
-				System.Console.WriteLine("width {0}, height {1}", calendar_event_box.Allocation.Width, calendar_event_box.Allocation.Height);
-
-				calendar_body.Resize(rows, cols);
-			
-				uint col = 0, row = 0; 
+				++element;
+			}
 
-				int element = 0;
+			if (elements.Count > days_per_page)
+			{
+				Gtk.HBox page_navigation = new Gtk.HBox();
+				page_navigation.Homogeneous = true;
 				
-				// fill in elements
-				foreach (ItemWrapper wrapper in elements)
-				{
-					if (!(element >= day_offset*days_per_page && element < (day_offset+1)*days_per_page)) {
-						++element;
-						continue;
-					}
-
-					uint tmp_col = col;
-					uint tmp_row = row;
-					ItemWrapper tmp_wrapper = wrapper; // oh lambda bug, we love ye
-			
-					wrapper.item.on_data_callback = delegate {
-						calendar_body.Attach(tmp_wrapper.item.Display().get_representation(), tmp_col, tmp_col+1, tmp_row, tmp_row+1, 
-								     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-											 AttachOptions.Shrink | AttachOptions.Fill,
-											 0,0);
+				if (day_offset > 0) {
+					// prev button
+					Gtk.EventBox link_wrapper = new Gtk.EventBox();
+					Gtk.Alignment alignment = new Alignment(1,1,1,1);
+					alignment.BorderWidth = 15;
+					Gtk.Label link = new Gtk.Label();
+					string text = Mono.Posix.Catalog.GetString("Previous page");
+					link.Markup = "<u>" + text + String.Format(" ({0}/{1})", day_offset, Math.Ceiling(elements.Count*1.0/days_per_page)) + "</u>";
+	
+					GtkCommon.show_hand_and_tooltip(link_wrapper, text);
+	
+					link_wrapper.Add(alignment);
+					alignment.Add(link);
+					link_wrapper.ButtonPressEvent += delegate {
+						day_offset -= 1;
+						draw(state, centered_date, elements);
 					};
 					
-					wrapper.item.on_data_callback();
-
-		            col = ++col % cols;
-		            if (col == 0)
-		                ++row;
-					
-					++element;
+					GtkCommon.set_background_color(link_wrapper, "white");
+					page_navigation.PackStart(link_wrapper, false, true, 0);
 				}
-
-				if (elements.Count > days_per_page)
+				
+				if ((day_offset+1)*days_per_page <= elements.Count)
 				{
-					Gtk.HBox page_navigation = new Gtk.HBox();
-					page_navigation.Homogeneous = true;
-					
-					if (day_offset > 0) {
-						// prev button
-						Gtk.EventBox link_wrapper = new Gtk.EventBox();
-						Gtk.Alignment alignment = new Alignment(1,1,1,1);
-						alignment.BorderWidth = 15;
-						Gtk.Label link = new Gtk.Label();
-						string text = Mono.Posix.Catalog.GetString("Previous page");
-						link.Markup = "<u>" + text + String.Format(" ({0}/{1})", day_offset, Math.Ceiling(elements.Count*1.0/days_per_page)) + "</u>";
-		
-						GtkCommon.show_hand_and_tooltip(link_wrapper, text);
-		
-						link_wrapper.Add(alignment);
-						alignment.Add(link);
-						link_wrapper.ButtonPressEvent += delegate {
-							day_offset -= 1;
-							draw(state, centered_date, elements);
-						};
-						
-						GtkCommon.set_background_color(link_wrapper, "white");
-						page_navigation.PackStart(link_wrapper, false, true, 0);
-					}
+					// next button
+					Gtk.EventBox link_wrapper = new Gtk.EventBox();
+					Gtk.Alignment alignment = new Alignment(1,1,1,1);
+					alignment.BorderWidth = 15;
+					Gtk.Label link = new Gtk.Label();
+					string text = Mono.Posix.Catalog.GetString("Next page");
+					link.Markup = "<u>" + text + String.Format(" ({0}/{1})", day_offset+2, Math.Ceiling(elements.Count*1.0/days_per_page))  + "</u>";
+	
+					GtkCommon.show_hand_and_tooltip(link_wrapper, text);
+	
+					link_wrapper.Add(alignment);
+					alignment.Add(link);
+					link_wrapper.ButtonPressEvent += delegate {
+						day_offset += 1;
+						draw(state, centered_date, elements);
+					};
 					
-					if ((day_offset+1)*days_per_page <= elements.Count)
-					{
-						// next button
-						Gtk.EventBox link_wrapper = new Gtk.EventBox();
-						Gtk.Alignment alignment = new Alignment(1,1,1,1);
-						alignment.BorderWidth = 15;
-						Gtk.Label link = new Gtk.Label();
-						string text = Mono.Posix.Catalog.GetString("Next page");
-						link.Markup = "<u>" + text + String.Format(" ({0}/{1})", day_offset+2, Math.Ceiling(elements.Count*1.0/days_per_page))  + "</u>";
-		
-						GtkCommon.show_hand_and_tooltip(link_wrapper, text);
-		
-						link_wrapper.Add(alignment);
-						alignment.Add(link);
-						link_wrapper.ButtonPressEvent += delegate {
-							day_offset += 1;
-							draw(state, centered_date, elements);
-						};
-						
-						GtkCommon.set_background_color(link_wrapper, "white");
-						page_navigation.PackStart(link_wrapper, false, true, 0);
-					}
-
-					viewbox.Add(page_navigation);					
+					GtkCommon.set_background_color(link_wrapper, "white");
+					page_navigation.PackStart(link_wrapper, false, true, 0);
 				}
-					
-				if (elements.Count == 0)
-				{
-					Gtk.EventBox eventbox = new Gtk.EventBox();
-					Gtk.Alignment alignment = new Alignment(0.5f, 0.5f, 0f, 0f);
+
+				viewbox.Add(page_navigation);					
+			}
 				
-					Gtk.VBox box = new Gtk.VBox();
+			if (elements.Count == 0)
+			{
+				Gtk.EventBox eventbox = new Gtk.EventBox();
+				Gtk.Alignment alignment = new Alignment(0.5f, 0.5f, 0f, 0f);
+			
+				Gtk.VBox box = new Gtk.VBox();
+			
+				Gtk.Image img = new Gtk.Image(null, "blue_guy_med.png");
+				box.PackStart(img, true, true, 10);
 				
-					Gtk.Image img = new Gtk.Image(null, "blue_guy_med.png");
-					box.PackStart(img, true, true, 10);
-					
-					Gtk.Label label = new Gtk.Label(Mono.Unix.Catalog.GetString("Sorry, no files for this day"));
-					box.PackStart(label, true, true, 10);
-					
-					alignment.Add(box);
-					eventbox.Add(alignment);
-					
-					GtkCommon.set_background_color(eventbox, "white");
-
-					calendar_body.Resize(1, 1);
+				Gtk.Label label = new Gtk.Label(Mono.Unix.Catalog.GetString("Sorry, no files for this day"));
+				box.PackStart(label, true, true, 10);
 				
-					calendar_body.Attach(eventbox, 0, 1, 0, 1, 
-								     	 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-										 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0,0);
-				}
+				alignment.Add(box);
+				eventbox.Add(alignment);
 				
-				week_button.Active = false;
-				month_button.Active = false;				
-				year_button.Active = false;				
+				GtkCommon.set_background_color(eventbox, "white");
+
+				calendar_body.Resize(1, 1);
+			
+				calendar_body.Attach(eventbox, 0, 1, 0, 1, 
+							     	 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+									 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0,0);
 			}
-			else if (state.view == CalendarDriver.View.Week)
+			
+			week_button.Active = false;
+			month_button.Active = false;				
+			year_button.Active = false;				
+		}
+
+		private void draw_week(Gtk.VBox calendar, Gtk.Table calendar_header, int days_in_week, 
+							   CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
+		{
+			calendar.PackStart(calendar_header, false, false, 0);
+			calendar.PackStart(calendar_body, true, true, 0);
+
+			int week = cal.GetWeekOfYear(centered_date, culture.DateTimeFormat.CalendarWeekRule,
+				                         culture.DateTimeFormat.FirstDayOfWeek);
+
+			today_button.Label = Mono.Unix.Catalog.GetString("This week");
+			current_date.Markup = "<b>" + String.Format(Mono.Unix.Catalog.GetString("Week {0} - {1}"), System.Convert.ToString(week), 
+													    System.Convert.ToString(centered_date.Year)) + "</b>";
+
+			calendar_header.Resize(1, 6);
+			calendar_body.Resize(3, 6);
+			
+			uint col = 0, row = 0; 
+
+			System.DateTime header_date = state.start_time;
+
+			// fill in headers
+			for (int i = 0; i < days_in_week; ++i)
 			{
-				calendar.PackStart(calendar_header, false, false, 0);
-				calendar.PackStart(calendar_body, true, true, 0);
+				bool full_weekend = (days_in_week == 6 && col == 5); 
 
-				int week = cal.GetWeekOfYear(centered_date, culture.DateTimeFormat.CalendarWeekRule,
-					                         culture.DateTimeFormat.FirstDayOfWeek);
+				WeekCalendarHeader header;
+				
+				if (full_weekend)
+					header = new WeekCalendarHeader(header_date, header_date.AddDays(1), update_view);
+				else
+					header = new WeekCalendarHeader(header_date, update_view);
+
+				calendar_header.Attach(header.representation(), col, col+1, row, row+1, 
+					       		 	   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+						       		   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+				
+	            col = ++col;
+	            if (col == 0)
+	                ++row;
+	                
+	           header_date = header_date.AddDays(full_weekend ? 2 : 1);
+			}
 
-				today_button.Label = Mono.Unix.Catalog.GetString("This week");
-				current_date.Markup = "<b>" + String.Format(Mono.Unix.Catalog.GetString("Week {0} - {1}"), System.Convert.ToString(week), 
-														    System.Convert.ToString(centered_date.Year)) + "</b>";
+			col = 0; row = 0;
 
-				calendar_header.Resize(1, 6);
-				calendar_body.Resize(3, 6);
+			// fill in periods
+			for (int i = 0; i < 3*days_in_week; ++i)
+			{
+				CalendarFixedElement element = new CalendarFixedElement(false, false, 0.5, size, true, false, 
+					System.DateTime.Now.ToShortDateString() == state.start_time.AddDays(col).ToShortDateString());
+				calendar_elements.Add(element);
 				
-				uint col = 0, row = 0; 
+				element.set_update_view(update_view, update_view_set_next);
+			
+				List<ItemWrapper> filenames = new List<ItemWrapper>();
 
-				System.DateTime header_date = state.start_time;
+				// fixme: logic in UI
 
-				// fill in headers
-				for (int i = 0; i < days_in_week; ++i)
-				{
-					bool full_weekend = (days_in_week == 6 && col == 5); 
+				if (days_in_week == 6 && i != 0 && (i + 1) % days_in_week == 0) {
 
-					WeekCalendarHeader header;
-					
-					if (full_weekend)
-						header = new WeekCalendarHeader(header_date, header_date.AddDays(1), update_view);
-					else
-						header = new WeekCalendarHeader(header_date, update_view);
-
-					calendar_header.Attach(header.representation(), col, col+1, row, row+1, 
-						       		 	   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-							       		   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
-					
-		            col = ++col;
-		            if (col == 0)
-		                ++row;
-		                
-		           header_date = header_date.AddDays(full_weekend ? 2 : 1);
-				}
+					System.DateTime date_start = state.start_time.AddDays(col);
+					if (row == 1)
+						date_start = date_start.AddHours(12);
+					else if (row == 2)
+						date_start = date_start.AddHours(18);
+
+					System.DateTime date_end = state.start_time.AddDays(col);
+					if (row == 0)
+						date_end = date_end.AddHours(12);
+					else if (row == 1)
+						date_end = date_end.AddHours(18);
+					else if (row == 2)
+						date_end = date_end.AddHours(24);
 
-				col = 0; row = 0;
+					DateTime saturday_start = date_start;
+					DateTime sunday_end = date_end.AddDays(1);
 
-				// fill in periods
-				for (int i = 0; i < 3*days_in_week; ++i)
-				{
-					CalendarFixedElement element = new CalendarFixedElement(false, false, 0.5, size, true, false, 
-						System.DateTime.Now.ToShortDateString() == state.start_time.AddDays(col).ToShortDateString());
-					calendar_elements.Add(element);
+					foreach (ItemWrapper wrapper in elements) 
+						if (wrapper.item.last_modify > saturday_start && wrapper.item.last_modify < sunday_end)
+							filenames.Add(wrapper);
+
+					if (filenames.Count > 0) {
+						element.set_dates(saturday_start, sunday_end, date_start, CalendarDriver.View.Day);
+						element.set_files(filenames);
+					}
 					
-					element.set_update_view(update_view, update_view_set_next);
-				
-					List<ItemWrapper> filenames = new List<ItemWrapper>();
+				} else {
 
-					// fixme: logic in UI
+					System.DateTime date_start = state.start_time.AddDays(col);
+					if (row == 1)
+						date_start = date_start.AddHours(12);
+					else if (row == 2)
+						date_start = date_start.AddHours(18);
+
+					System.DateTime date_end = state.start_time.AddDays(col);
+					if (row == 0)
+						date_end = date_end.AddHours(12);
+					else if (row == 1)
+						date_end = date_end.AddHours(18);
+					else if (row == 2)
+						date_end = date_end.AddHours(24);
 
-					if (days_in_week == 6 && i != 0 && (i + 1) % days_in_week == 0) {
+					foreach (ItemWrapper wrapper in elements)
+						if (wrapper.item.last_modify > date_start && wrapper.item.last_modify < date_end)
+							filenames.Add(wrapper);
 
-						System.DateTime date_start = state.start_time.AddDays(col);
-						if (row == 1)
-							date_start = date_start.AddHours(12);
-						else if (row == 2)
-							date_start = date_start.AddHours(18);
-
-						System.DateTime date_end = state.start_time.AddDays(col);
-						if (row == 0)
-							date_end = date_end.AddHours(12);
-						else if (row == 1)
-							date_end = date_end.AddHours(18);
-						else if (row == 2)
-							date_end = date_end.AddHours(24);
-
-						DateTime saturday_start = date_start;
-						DateTime sunday_end = date_end.AddDays(1);
-
-						foreach (ItemWrapper wrapper in elements) 
-							if (wrapper.item.last_modify > saturday_start && wrapper.item.last_modify < sunday_end)
-								filenames.Add(wrapper);
-
-						if (filenames.Count > 0) {
-							element.set_dates(saturday_start, sunday_end, date_start, CalendarDriver.View.Day);
-							element.set_files(filenames);
-						}
-						
-					} else {
-
-						System.DateTime date_start = state.start_time.AddDays(col);
-						if (row == 1)
-							date_start = date_start.AddHours(12);
-						else if (row == 2)
-							date_start = date_start.AddHours(18);
-
-						System.DateTime date_end = state.start_time.AddDays(col);
-						if (row == 0)
-							date_end = date_end.AddHours(12);
-						else if (row == 1)
-							date_end = date_end.AddHours(18);
-						else if (row == 2)
-							date_end = date_end.AddHours(24);
-
-						foreach (ItemWrapper wrapper in elements)
-							if (wrapper.item.last_modify > date_start && wrapper.item.last_modify < date_end)
-								filenames.Add(wrapper);
-
-						if (filenames.Count > 0) {
-							element.set_dates(date_start, date_end, date_start, CalendarDriver.View.Day);
-							element.set_files(filenames);
-						}
+					if (filenames.Count > 0) {
+						element.set_dates(date_start, date_end, date_start, CalendarDriver.View.Day);
+						element.set_files(filenames);
 					}
-
-					calendar_body.Attach(element.representation(), col, col+1, row, row+1, 
-							       	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
-
-		            col = ++col % (uint)days_in_week;
-		            if (col == 0)
-		                ++row;
 				}
 
-				Gtk.EventBox label_wrapper = new Gtk.EventBox();
-				Gtk.Label label = new Gtk.Label();
-				label.Markup = "<span foreground=\"darkgray\" size=\"small\">12:00</span>";
-				label_wrapper.Add(label);
-				GtkCommon.set_background_color(label_wrapper, "white");
-	
-				Gtk.EventBox label2_wrapper = new Gtk.EventBox();
-				Gtk.Label label2 = new Gtk.Label();
-				label2.Markup = "<span foreground=\"darkgray\" size=\"small\">18:00</span>";
-				label2_wrapper.Add(label2);
-				GtkCommon.set_background_color(label2_wrapper, "white");
+				calendar_body.Attach(element.representation(), col, col+1, row, row+1, 
+						       	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+						     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+
+	            col = ++col % (uint)days_in_week;
+	            if (col == 0)
+	                ++row;
+			}
+
+			Gtk.EventBox label_wrapper = new Gtk.EventBox();
+			Gtk.Label label = new Gtk.Label();
+			label.Markup = "<span foreground=\"darkgray\" size=\"small\">12:00</span>";
+			label_wrapper.Add(label);
+			GtkCommon.set_background_color(label_wrapper, "white");
+
+			Gtk.EventBox label2_wrapper = new Gtk.EventBox();
+			Gtk.Label label2 = new Gtk.Label();
+			label2.Markup = "<span foreground=\"darkgray\" size=\"small\">18:00</span>";
+			label2_wrapper.Add(label2);
+			GtkCommon.set_background_color(label2_wrapper, "white");
 
 //				int[] cal_size = size();
 //
@@ -731,243 +680,318 @@
 //
 //				System.Console.WriteLine("{0}  {1} {2}", x_pos, cal_size[1] + cal_size[3]/3, cal_size[1] + 2*cal_size[3]/3);
 
-				// above line
+			// above line
 //					TransparentWindow overlay1 = new TransparentWindow(label_wrapper, x_pos - 33, cal_size[1] + cal_size[3]/3 + 5);
 //					TransparentWindow overlay2 = new TransparentWindow(label2_wrapper, x_pos - 33, cal_size[1] + 2*cal_size[3]/3 - 5);
 
-				Function<int> x_pos_func = delegate { 
-					int[] cal_size = size(); 
-					return cal_size[0] + cal_size[2] - 33; 
-				};
+			Function<int> x_pos_func = delegate { 
+				int[] cal_size = size(); 
+				return cal_size[0] + cal_size[2] - 33; 
+			};
+
+			Function<int> time_1_y_pos_func = delegate { 
+				int[] cal_size = size(); 
+				return cal_size[1] + cal_size[3]/3 + 13; 
+			};
+
+			Function<int> time_2_y_pos_func = delegate { 
+				int[] cal_size = size(); 
+				return cal_size[1] + 2*cal_size[3]/3 + 4; 
+			};
+
+			// -33?
+
+			// on line :-)
+			Singleton<OverlayTracker>.Instance.add_overlay_and_show(new TransparentWindow(label_wrapper, x_pos_func, time_1_y_pos_func, "time_overlay1"));
+			Singleton<OverlayTracker>.Instance.add_overlay_and_show(new TransparentWindow(label2_wrapper, x_pos_func, time_2_y_pos_func, "time_overlay2"));
+			
+			day_button.Active = false;
+			month_button.Active = false;
+			year_button.Active = false;
+		}
 
-				Function<int> time_1_y_pos_func = delegate { 
-					int[] cal_size = size(); 
-					return cal_size[1] + cal_size[3]/3 + 13; 
-				};
+		private void draw_month(Gtk.VBox calendar, Gtk.Table calendar_header, int days_in_week, 
+							    CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
+		{
+			System.Console.WriteLine("month view");
+		
+			Gtk.Table calendar_side_header = new Gtk.Table(1, 1, true);
+			calendar_side_header.RowSpacing = 2;
+			calendar_side_header.ColumnSpacing = 2;
 
-				Function<int> time_2_y_pos_func = delegate { 
-					int[] cal_size = size(); 
-					return cal_size[1] + 2*cal_size[3]/3 + 4; 
-				};
+			Gtk.HBox calendar_middle = new Gtk.HBox(); 
+			Gtk.HBox calendar_top = new Gtk.HBox();
 
-				// -33?
+			int days = (state.end_time - state.start_time).Days;
+			int weeks = days/7;
 
-				// on line :-)
-				Singleton<OverlayTracker>.Instance.add_overlay_and_show(new TransparentWindow(label_wrapper, x_pos_func, time_1_y_pos_func, "time_overlay1"));
-				Singleton<OverlayTracker>.Instance.add_overlay_and_show(new TransparentWindow(label2_wrapper, x_pos_func, time_2_y_pos_func, "time_overlay2"));
-				
-				day_button.Active = false;
-				month_button.Active = false;
-				year_button.Active = false;
-			}
-			else if (state.view == CalendarDriver.View.Month)
-			{
-				System.Console.WriteLine("month view");
-			
-				int days = (state.end_time - state.start_time).Days;
-				int weeks = days/7;
+			Gtk.Alignment side_header_alignment = new Gtk.Alignment(1, 1, 1, 1);
+			side_header_alignment.RightPadding = 2;
+			side_header_alignment.Add(calendar_side_header);
 
-				Gtk.Alignment side_header_alignment = new Gtk.Alignment(1, 1, 1, 1);
-				side_header_alignment.RightPadding = 2;
-				side_header_alignment.Add(calendar_side_header);
+			calendar_middle.PackStart(side_header_alignment, false, false, 0);
+			calendar_middle.PackStart(calendar_body, true, true, 0);
 
-				calendar_middle.PackStart(side_header_alignment, false, false, 0);
-				calendar_middle.PackStart(calendar_body, true, true, 0);
+			Gtk.Alignment top_alignment = new Gtk.Alignment(1, 1, 1, 1);
+			top_alignment.BottomPadding = 2;
+			top_alignment.Add(calendar_top);
 
-				Gtk.Alignment top_alignment = new Gtk.Alignment(1, 1, 1, 1);
-				top_alignment.BottomPadding = 2;
-				top_alignment.Add(calendar_top);
+			calendar.PackStart(top_alignment, false, false, 0);
+			calendar.PackStart(calendar_middle, true, true, 0);
 
-				calendar.PackStart(top_alignment, false, false, 0);
-				calendar.PackStart(calendar_middle, true, true, 0);
+			today_button.Label = Mono.Unix.Catalog.GetString("This month");
+			current_date.Markup = "<b>" + GtkCommon.month_name(centered_date.Month) + " " + System.Convert.ToString(centered_date.Year) + "</b>";
 
-				today_button.Label = Mono.Unix.Catalog.GetString("This month");
-				current_date.Markup = "<b>" + GtkCommon.month_name(centered_date.Month) + " " + System.Convert.ToString(centered_date.Year) + "</b>";
+			calendar_side_header.Resize((uint)weeks, 1);
 
-				calendar_side_header.Resize((uint)weeks, 1);
+			calendar_header.Resize(1, (uint)days_in_week);
+			calendar_body.Resize((uint)weeks, (uint)days_in_week);
+			
+			uint col = 0, row = 0; 
 
-				calendar_header.Resize(1, (uint)days_in_week);
-				calendar_body.Resize((uint)weeks, (uint)days_in_week);
-				
-				uint col = 0, row = 0; 
+			System.DateTime header_date = state.start_time;
 
-				System.DateTime header_date = state.start_time;
+			// fill in side headers
+			for (int i = 0; i < weeks; ++i)
+			{
+				calendar_side_header.Attach(new SideWeekCalendarHeader(header_date, update_view).representation(), col, col+1, row, row+1, 
+						       		 	    AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+						       		 	    AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+				
+	            ++row;
+	                
+	            header_date = header_date.AddDays(7);
+			}
 
-				// fill in side headers
-				for (int i = 0; i < weeks; ++i)
-				{
-					calendar_side_header.Attach(new SideWeekCalendarHeader(header_date, update_view).representation(), col, col+1, row, row+1, 
-							       		 	    AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-							       		 	    AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
-					
-		            ++row;
-		                
-		            header_date = header_date.AddDays(7);
-				}
+			header_date = state.start_time;
 
-				header_date = state.start_time;
+			col = 0; row = 0;
 
-				col = 0; row = 0;
+			// fill in headers
+			for (int i = 0; i < days_in_week; ++i)
+			{
+				bool full_weekend = (days_in_week == 6 && col == 5); 
+			
+				MonthCalendarHeader header;
+			
+				if (full_weekend)
+					header = new MonthCalendarHeader(header_date, header_date.AddDays(1));
+				else
+					header = new MonthCalendarHeader(header_date);
+					
+				calendar_header.Attach(header.representation(), col, col+1, row, row+1, 
+						       		   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+						       		   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+	                
+	            header_date = header_date.AddDays(full_weekend ? 2 : 1);
 
-				// fill in headers
-				for (int i = 0; i < days_in_week; ++i)
-				{
-					bool full_weekend = (days_in_week == 6 && col == 5); 
-				
-					MonthCalendarHeader header;
-				
-					if (full_weekend)
-						header = new MonthCalendarHeader(header_date, header_date.AddDays(1));
-					else
-						header = new MonthCalendarHeader(header_date);
-						
-					calendar_header.Attach(header.representation(), col, col+1, row, row+1, 
-							       		   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-							       		   AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
-		                
-		            header_date = header_date.AddDays(full_weekend ? 2 : 1);
+				++col;
+			}
 
-					++col;
-				}
+			Gtk.EventBox tmp_wrapper = new EventBox();
+			Gtk.Label tmp = new Gtk.Label();
+			tmp.Markup = "<span foreground=\"white\">Week</span>";
+			tmp.Angle = 90;
 
-				Gtk.EventBox tmp_wrapper = new EventBox();
-				Gtk.Label tmp = new Gtk.Label();
-				tmp.Markup = "<span foreground=\"white\">Week</span>";
-				tmp.Angle = 90;
+			Gtk.Alignment tmp_tmp_alignment = new Gtk.Alignment(1, 1, 1, 1);
+			tmp_tmp_alignment.RightPadding = 4;
+			tmp_tmp_alignment.Add(tmp);
 
-				Gtk.Alignment tmp_tmp_alignment = new Gtk.Alignment(1, 1, 1, 1);
-				tmp_tmp_alignment.RightPadding = 4;
-				tmp_tmp_alignment.Add(tmp);
+			tmp_wrapper.Add(tmp_tmp_alignment);
+			GtkCommon.set_background_color(tmp_wrapper, "white");
 
-				tmp_wrapper.Add(tmp_tmp_alignment);
-				GtkCommon.set_background_color(tmp_wrapper, "white");
+			Gtk.Alignment tmp_alignment = new Gtk.Alignment(1, 1, 1, 1);
+			tmp_alignment.RightPadding = 2;
+			tmp_alignment.Add(tmp_wrapper);
 
-				Gtk.Alignment tmp_alignment = new Gtk.Alignment(1, 1, 1, 1);
-				tmp_alignment.RightPadding = 2;
-				tmp_alignment.Add(tmp_wrapper);
+			calendar_top.PackStart(tmp_alignment, false, false, 0);
+			calendar_top.PackStart(calendar_header, true, true, 0);
 
-				calendar_top.PackStart(tmp_alignment, false, false, 0);
-				calendar_top.PackStart(calendar_header, true, true, 0);
+			header_date = state.start_time;
 
-				header_date = state.start_time;
+			col = 0; row = 0;
 
-				col = 0; row = 0;
+			int days_to_show = days;
+			if (days_in_week == 6)
+				days_to_show = days-weeks;
 
-				int days_to_show = days;
-				if (days_in_week == 6)
-					days_to_show = days-weeks;
+			// fill in days
+			for (int i = 0; i < days_to_show; ++i)
+			{
+				bool end_of_week = (days_in_week == 6 && i != 0 && (i + 1) % days_in_week == 0);
 
-				// fill in days
-				for (int i = 0; i < days_to_show; ++i)
-				{
-					bool end_of_week = (days_in_week == 6 && i != 0 && (i + 1) % days_in_week == 0);
+				CalendarFixedElement element = new CalendarFixedElement(true, true, 0.5, size, true, header_date.Month != centered_date.Month, 
+																		System.DateTime.Now.ToShortDateString() == header_date.ToShortDateString());
+		
+				calendar_elements.Add(element);
 
-					CalendarFixedElement element = new CalendarFixedElement(true, true, 0.5, size, true, header_date.Month != centered_date.Month, 
-																			System.DateTime.Now.ToShortDateString() == header_date.ToShortDateString());
-			
-					calendar_elements.Add(element);
+				string header_string = string.Empty;
+				
+				if (end_of_week)
+					header_string = System.Convert.ToString(header_date.Day) + " - " + System.Convert.ToString(header_date.AddDays(1).Day);
+				else
+					header_string = System.Convert.ToString(header_date.Day);
+				
+				List<ItemWrapper> filenames = new List<ItemWrapper>();
 
-					string header_string = "";
-					
-					if (end_of_week)
-						header_string = System.Convert.ToString(header_date.Day) + " - " + System.Convert.ToString(header_date.AddDays(1).Day);
-					else
-						header_string = System.Convert.ToString(header_date.Day);
-					
-					List<ItemWrapper> filenames = new List<ItemWrapper>();
+				DateTime date_start = header_date, date_end;
 
-					DateTime date_start = header_date, date_end;
+				// fixme: logic in UI
+				if (days_in_week == 6 && i != 0 && (i + 1) % days_in_week == 0)
+					date_end = header_date.AddDays(2);
+				else
+					date_end = header_date.AddDays(1);
 
-					// fixme: logic in UI
-					if (days_in_week == 6 && i != 0 && (i + 1) % days_in_week == 0)
-						date_end = header_date.AddDays(2);
-					else
-						date_end = header_date.AddDays(1);
+				foreach (ItemWrapper wrapper in elements)
+					if (wrapper.item.last_modify > date_start && wrapper.item.last_modify < date_end)
+						filenames.Add(wrapper);
 
-					foreach (ItemWrapper wrapper in elements)
-						if (wrapper.item.last_modify > date_start && wrapper.item.last_modify < date_end)
-							filenames.Add(wrapper);
+				string tooltip_string = String.Format(Mono.Unix.Catalog.GetString("Zoom to {0} {1}, {2}"), GtkCommon.month_name(header_date.Month), 
+													  header_date.Day, header_date.Year);
 
-					string tooltip_string = String.Format(Mono.Unix.Catalog.GetString("Zoom to {0} {1}, {2}"), GtkCommon.month_name(header_date.Month), 
-														  header_date.Day, header_date.Year);
+				element.set_header(header_string, filenames.Count > 0, tooltip_string);
+				element.set_update_view(update_view, update_view_set_next);
 
-					element.set_header(header_string, filenames.Count > 0, tooltip_string);
-					element.set_update_view(update_view, update_view_set_next);
+				if (filenames.Count > 0) {
+					element.set_dates(date_start, date_end, header_date, CalendarDriver.View.Day);
+					element.set_files(filenames);
+				}
 
-					if (filenames.Count > 0) {
-						element.set_dates(date_start, date_end, header_date, CalendarDriver.View.Day);
-						element.set_files(filenames);
-					}
+				calendar_body.Attach(element.representation(), col, col+1, row, row+1, 
+						     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+						     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+
+				col = ++col % (uint)days_in_week;
+	            if (col == 0)
+	                ++row;
 
-					calendar_body.Attach(element.representation(), col, col+1, row, row+1, 
-							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+	            header_date = header_date.AddDays((days_in_week == 6 && col == 0) ? 2 : 1);
+			}
+			
+			day_button.Active = false;
+			week_button.Active = false;
+			year_button.Active = false;
+		}
 
-					col = ++col % (uint)days_in_week;
-		            if (col == 0)
-		                ++row;
+		private void draw_year(Gtk.VBox calendar, CalendarDriver.State state, System.DateTime centered_date,
+							   List<ItemWrapper> elements)
+		{
+			calendar.PackStart(calendar_body, true, true, 0);
 
-		            header_date = header_date.AddDays((days_in_week == 6 && col == 0) ? 2 : 1);
-				}
-				
-				day_button.Active = false;
-				week_button.Active = false;
-				year_button.Active = false;
-			}
-			else if (state.view == CalendarDriver.View.Year)
-			{
-				calendar.PackStart(calendar_body, true, true, 0);
+			today_button.Label = Mono.Unix.Catalog.GetString("This year");
+			current_date.Markup = "<b>" + System.Convert.ToString(centered_date.Year) + "</b>";
 
-				today_button.Label = Mono.Unix.Catalog.GetString("This year");
-				current_date.Markup = "<b>" + System.Convert.ToString(centered_date.Year) + "</b>";
+			calendar_body.Resize(2, 6);
+			
+			uint col = 0, row = 0; 
 
-				calendar_body.Resize(2, 6);
-				
-				uint col = 0, row = 0; 
+			System.DateTime header_date = state.start_time;
 
-				System.DateTime header_date = state.start_time;
+			// fill in months
+			for (int i = 0; i < 12; ++i)
+			{
+				CalendarFixedElement element = new CalendarFixedElement(true, false, 0.5, size, true, false, 
+																		String.Format("{0:MM/yy}", System.DateTime.Now) == String.Format("{0:MM/yy}", 
+																		header_date));
+				calendar_elements.Add(element);
+
+				element.set_large_header(GtkCommon.month_name(header_date.Month), 
+										 String.Format(Mono.Unix.Catalog.GetString("Zoom to {0}, {1}"), GtkCommon.month_name(header_date.Month), 
+										 header_date.Year));
+				element.set_update_view(update_view, update_view_set_next);
+
+				List<ItemWrapper> filenames = new List<ItemWrapper>();
+
+				DateTime date_start = header_date;
+				DateTime date_end = header_date.AddMonths(1);
+
+				foreach (ItemWrapper wrapper in elements) 
+					if (wrapper.item.last_modify > date_start && wrapper.item.last_modify < date_end)
+						filenames.Add(wrapper);
+
+				if (filenames.Count > 0) {
+					element.set_dates(date_start, date_end, header_date, CalendarDriver.View.Month);
+					element.set_files(filenames);
+				}
 
-				// fill in months
-				for (int i = 0; i < 12; ++i)
-				{
-					CalendarFixedElement element = new CalendarFixedElement(true, false, 0.5, size, true, false, 
-																			String.Format("{0:MM/yy}", System.DateTime.Now) == String.Format("{0:MM/yy}", 
-																			header_date));
-					calendar_elements.Add(element);
-
-					element.set_large_header(GtkCommon.month_name(header_date.Month), 
-											 String.Format(Mono.Unix.Catalog.GetString("Zoom to {0}, {1}"), GtkCommon.month_name(header_date.Month), 
-											 header_date.Year));
-					element.set_update_view(update_view, update_view_set_next);
+				calendar_body.Attach(element.representation(), col, col+1, row, row+1, 
+						     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+						     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+
+	            col = ++col % 6;
+	            if (col == 0)
+	                ++row;
 
-					List<ItemWrapper> filenames = new List<ItemWrapper>();
+				header_date = header_date.AddMonths(1);
+			}
+			
+			day_button.Active = false;
+			week_button.Active = false;
+			month_button.Active = false;
+		}
 
-					DateTime date_start = header_date;
-					DateTime date_end = header_date.AddMonths(1);
+		public void draw(CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
+		{
+			if (last_elements != null) {
+				if (last_elements != elements) {
+					last_elements = elements;
+					day_offset = 0;
+				}
+			} else
+				last_elements = elements;
+			
+			if (elements.Count > 0)
+				System.Console.WriteLine("hurray! elements");
 
-					foreach (ItemWrapper wrapper in elements) 
-						if (wrapper.item.last_modify > date_start && wrapper.item.last_modify < date_end)
-							filenames.Add(wrapper);
+			if (calendar_body != null) {
+				System.Console.WriteLine("cleaning up body of size:{0}", calendar_body.Children.Length);
+				foreach (Widget w in calendar_body.Children)
+					w.Destroy();
+				calendar_body.Dispose();
+			}
+			
+			foreach (CalendarFixedElement element in calendar_elements)
+				element.reset(); // workaround GTK-sharp signal bug
+				
+			calendar_elements.Clear();
 
-					if (filenames.Count > 0) {
-						element.set_dates(date_start, date_end, header_date, CalendarDriver.View.Month);
-						element.set_files(filenames);
-					}
+            // cleanup
+            foreach (Widget w in calendar_event_box.Children)
+				w.Destroy();
+			
+			Gtk.VBox calendar = new Gtk.VBox();
+		
+			calendar_event_box.Add(calendar);
+			GtkCommon.set_background_color(calendar_event_box, "gray");
 
-					calendar_body.Attach(element.representation(), col, col+1, row, row+1, 
-							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
+			Gtk.Table calendar_header = new Gtk.Table(1, 1, true);
+			calendar_header.RowSpacing = 2;
+			calendar_header.ColumnSpacing = 2;
 
-		            col = ++col % 6;
-		            if (col == 0)
-		                ++row;
+			calendar_body = new Gtk.Table(1, 1, true);
+			calendar_body.RowSpacing = 2;
+			calendar_body.ColumnSpacing = 2;
 
-					header_date = header_date.AddMonths(1);
-				}
-				
-				day_button.Active = false;
-				week_button.Active = false;
-				month_button.Active = false;
+			int days_in_week = 6; // lumb weekends together
+
+			Singleton<OverlayTracker>.Instance.hide_and_die("time_overlay1");
+			Singleton<OverlayTracker>.Instance.hide_and_die("time_overlay2");
+
+			if (state.view == CalendarDriver.View.Day)
+			{
+				draw_day(calendar, state, centered_date, elements);
+			}
+			else if (state.view == CalendarDriver.View.Week)
+			{
+				draw_week(calendar, calendar_header, days_in_week, state, centered_date, elements);
+			}
+			else if (state.view == CalendarDriver.View.Month)
+			{
+				draw_month(calendar, calendar_header, days_in_week, state, centered_date, elements);
+			}
+			else if (state.view == CalendarDriver.View.Year)
+			{
+				draw_year(calendar, state, centered_date, elements);
 			}
 
 			System.Console.WriteLine("calendar show all");

Modified: trunk/gtk/Common.cs
==============================================================================
--- trunk/gtk/Common.cs	(original)
+++ trunk/gtk/Common.cs	Tue Sep 16 18:19:55 2008
@@ -8,7 +8,7 @@
 
 namespace Nemo
 {
-	class GtkCommon
+	static class GtkCommon
 	{
 		public static void show_hand_and_tooltip(Gtk.Widget widget, string tooltip_text)
 		{
@@ -236,7 +236,7 @@
 				case 12:
 					return Catalog.GetString("December");
 				default:
-					return "";
+					return string.Empty;
 			}
 		}
 
@@ -256,7 +256,7 @@
 				return Mono.Unix.Catalog.GetString("Saturday");
 			else if (date.DayOfWeek == System.DayOfWeek.Sunday)
 				return Mono.Unix.Catalog.GetString("Sunday");
-			return ""; // make compiler happy
+			return string.Empty; // make compiler happy
 		}
 	}
 }

Modified: trunk/gtk/DisplayItem.cs
==============================================================================
--- trunk/gtk/DisplayItem.cs	(original)
+++ trunk/gtk/DisplayItem.cs	Tue Sep 16 18:19:55 2008
@@ -19,7 +19,7 @@
 		protected Gtk.Image picture;
 		protected string pic_path;
 
-		protected Gtk.Label filename;
+//		protected Gtk.Label filename;
 		protected Gtk.HBox labels;
 		
 		protected Gtk.Label size;

Modified: trunk/gtk/MainWindow.cs
==============================================================================
--- trunk/gtk/MainWindow.cs	(original)
+++ trunk/gtk/MainWindow.cs	Tue Sep 16 18:19:55 2008
@@ -430,7 +430,7 @@
 
 	protected virtual void OnAllFilesPressed (object sender, System.EventArgs e)
 	{
-		search_input.Text = "";
+		search_input.Text = String.Empty;
 
 		Singleton<TypeLabels>.Instance.clear_restrictions();
 		Singleton<Categories>.Instance.clear_restrictions(); 

Modified: trunk/gtk/OSSpecific.cs
==============================================================================
--- trunk/gtk/OSSpecific.cs	(original)
+++ trunk/gtk/OSSpecific.cs	Tue Sep 16 18:19:55 2008
@@ -4,7 +4,7 @@
 
 namespace Nemo
 {
-	class OSSpecific
+	static class OSSpecific
 	{
 		[DllImport ("libc")] // Linux
 		private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);

Modified: trunk/gtk/SearchPopup.cs
==============================================================================
--- trunk/gtk/SearchPopup.cs	(original)
+++ trunk/gtk/SearchPopup.cs	Tue Sep 16 18:19:55 2008
@@ -324,7 +324,7 @@
 			
 			lines.PackStart(label_links, true, true, 2);
 
-			string image = "";
+			string image = String.Empty;
 			
 			if (item.file != null)
 				image = Singleton<Types>.Instance.get_type((int)item.file.type.category).icon;

Modified: trunk/metadata/MetadataStore.cs
==============================================================================
--- trunk/metadata/MetadataStore.cs	(original)
+++ trunk/metadata/MetadataStore.cs	Tue Sep 16 18:19:55 2008
@@ -1712,11 +1712,11 @@
             clauses.Add("files.last_modified <= @date_end");
             add_par(cmd, "@date_end", DbType.Int64, query.date_end.ToFileTime());
                 
-            string extra_tables = "";
+            string extra_tables = String.Empty;
             if (froms.Count > 0)
                 extra_tables = ", " + String.Join(", ", froms.ToArray()) + " ";
 
-            string where = "";
+            string where = String.Empty;
             if (clauses.Count > 0)
                 where = "where " + String.Join(" and ", clauses.ToArray()) + " ";
 

Modified: trunk/uicommon/DocumentItem.cs
==============================================================================
--- trunk/uicommon/DocumentItem.cs	(original)
+++ trunk/uicommon/DocumentItem.cs	Tue Sep 16 18:19:55 2008
@@ -107,7 +107,7 @@
 					title += "...";
 				}
 			} else
-				title = "";
+				title = String.Empty;
 		}
 		
 		protected void on_snippet_result(string text_snippet)

Modified: trunk/uicommon/Item.cs
==============================================================================
--- trunk/uicommon/Item.cs	(original)
+++ trunk/uicommon/Item.cs	Tue Sep 16 18:19:55 2008
@@ -119,8 +119,8 @@
             Process.Start("'" + path + "'");
 		}
 
-	        public VoidFunction<bool> small_starred_update_function;
-   	        VoidFunction<bool> big_starred_update_function;
+	    public VoidFunction<bool> small_starred_update_function;
+   	    VoidFunction<bool> big_starred_update_function;
 
 		public void register_small_starred_change(VoidFunction<bool> update_function)
 		{
@@ -202,4 +202,4 @@
 			return String.Format("{0:HH:mm:ss} {0:dd/MM/yy}", date); // {0:HH:mm:ss} 
         }
 	}
-}
+}
\ No newline at end of file



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