--- src/cal-home-widget.h.orig	2010-10-08 19:01:02.000000000 -0400
+++ src/cal-home-widget.h	2010-12-02 22:12:07.000000000 -0500
@@ -84,6 +84,7 @@
   gboolean update_view;
   gboolean show_all_recurrences;
   gint cal_row_count;
+  gint past_undone_todos;
   gint today_events;
   time_t time_to_update;
   gint press_time;
--- src/cal-home-widget.c.orig	2010-10-08 19:10:56.000000000 -0400
+++ src/cal-home-widget.c	2010-12-02 22:12:07.000000000 -0500
@@ -514,10 +514,20 @@
     cairo_fill(cr);
     cairo_translate(cr, 0, -64);
   }
+  if(desktop_plugin->past_undone_todos > 0 &&
+     desktop_plugin->past_undone_todos < row_count)
+  {
+    int today_line_y = desktop_plugin->past_undone_todos*CAL_WIDGET_ENTRY_ROW_HEIGHT+CAL_WIDGET_TITLE_HEIGHT;
+    cairo_set_line_width(cr, 1.5);
+    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0);
+    cairo_move_to(cr, 8, today_line_y);
+    cairo_line_to(cr, CAL_WIDGET_WIDTH-8, today_line_y);
+    cairo_stroke(cr);
+  }
   if(desktop_plugin->today_events > 0 &&
-     desktop_plugin->today_events < row_count)
+     desktop_plugin->past_undone_todos+desktop_plugin->today_events < row_count)
   {
-    int today_line_y = desktop_plugin->today_events*CAL_WIDGET_ENTRY_ROW_HEIGHT+CAL_WIDGET_TITLE_HEIGHT;
+    int today_line_y = (desktop_plugin->past_undone_todos+desktop_plugin->today_events)*CAL_WIDGET_ENTRY_ROW_HEIGHT+CAL_WIDGET_TITLE_HEIGHT;
     cairo_set_line_width(cr, 1.5);
     cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
     cairo_move_to(cr, 8, today_line_y);
--- src/cal-home-calendar-util.h.orig	2010-06-16 10:04:47.000000000 -0400
+++ src/cal-home-calendar-util.h	2010-12-02 22:51:15.000000000 -0500
@@ -22,6 +22,7 @@
 
 #include <set>
 #include <CComponent.h>
+#include <Common.h>
 #include "cal-home-widget.h"
 
 
@@ -29,7 +30,39 @@
 {
   bool operator()(CComponent* c1, CComponent* c2)
   {
-    return c1->getDateStart() < c2->getDateStart();
+    int c1_type = c1->getType();
+    time_t c1_start_time = c1->getDateStart();
+    time_t c1_end_time = c1->getDateEnd();
+    int c2_type = c2->getType();
+    time_t c2_start_time = c2->getDateStart();
+    time_t c2_end_time = c2->getDateEnd();
+
+    if(c1_start_time == c2_start_time)
+    {
+      if(c1_end_time == c2_end_time)
+      {
+	/* TODO comes first */
+	if(c1_type == E_TODO && c2_type != E_TODO)
+	  return true;
+	else
+	if(c1_type != E_TODO && c2_type == E_TODO)
+	  return false;
+	else
+	/* birthday comes last */
+	if(c1_type == E_BDAY && c2_type != E_BDAY)
+	  return false;
+	else
+	if(c1_type != E_BDAY && c2_type == E_BDAY)
+	  return true;
+	else
+	/* alphabetical order */
+	  return c1->getSummary() < c2->getSummary();
+      }
+      else
+	return c1_end_time < c2_end_time;
+    }
+    else
+      return c1_start_time < c2_start_time;
   }
 };
 
--- src/cal-home-calendar-util.c.orig	2010-10-08 19:04:28.000000000 -0400
+++ src/cal-home-calendar-util.c	2010-12-03 00:56:27.000000000 -0500
@@ -278,9 +278,11 @@
   time_t end_time = cal_home_advance_date_by_time_period(&end_date,
 							 desktop_plugin->cal_time_period);
   time_t date_today_time = mktime(&desktop_plugin->date_today);
-  time_t system_time_offset = CMulticalendar::MCInstance()->getSystemTimeShift();
+  time_t today_midnight_time = end_time_today-24*60*60;
 
+  desktop_plugin->past_undone_todos = 0;
   desktop_plugin->today_events = 0;
+
   GtkTreeIter iter;
   for(SortedCComponentSet::const_iterator event_iter = ccomponent_set.begin();
       event_iter != ccomponent_set.end() && up_to>0;
@@ -288,30 +290,27 @@
   {
     gtk_list_store_append(list_store,
 			  &iter);
+
+    gchar* escaped_markedup;
     string summary = (*event_iter)->getSummary();
+
     if((*event_iter)->getType() == E_TODO &&
        (*event_iter)->getStatus() == 1)
     {
-      gchar* escaped_markedup = g_markup_printf_escaped("<s>%s</s>", summary.c_str());
-      summary = string(escaped_markedup);
-      g_free(escaped_markedup);
+      escaped_markedup = g_markup_printf_escaped("<s>%s</s>", summary.c_str());
     }
     else
     {
-      gchar* escaped_markedup = g_markup_printf_escaped("%s", summary.c_str());
-      summary = string(escaped_markedup);
-      g_free(escaped_markedup);
+      escaped_markedup = g_markup_printf_escaped("%s", summary.c_str());
     }
+
+    summary = string(escaped_markedup);
+    g_free(escaped_markedup);
+
     time_t event_start_time = (*event_iter)->getDateStart();
     time_t event_end_time = (*event_iter)->getDateEnd();
-    time_t event_time_offset = (*event_iter)->getTzOffset();
     struct tm* time = localtime(&event_start_time);
-    if(CMulticalendar::MCInstance()->getSystemTimeZone() != (*event_iter)->getTzid() &&
-       (*event_iter)->getAllDay())
-    {
-      event_end_time += event_time_offset - system_time_offset;
-      event_start_time += event_time_offset - system_time_offset;
-    }
+
     if(earliest_update_end_time>event_end_time)
       earliest_update_end_time = end_time+60;
     if(date_today_time < event_start_time &&
@@ -320,7 +319,7 @@
     char buf[255];
 
     if(cal_date_on_today(event_start_time, desktop_plugin) || 
-       (event_start_time <= date_today_time && (event_end_time == -1 || event_end_time >= date_today_time)))
+       ((*event_iter)->getType() == E_EVENT && event_start_time <= date_today_time && (event_end_time == -1 || event_end_time >= date_today_time)))
     {
       ++desktop_plugin->today_events;
 
@@ -341,6 +340,9 @@
     }
     else
     {
+      if((*event_iter)->getType() == E_TODO && event_start_time < today_midnight_time)
+	++desktop_plugin->past_undone_todos;
+
       if(desktop_plugin->show_week_day_name)
 	strftime(buf, 255,dgettext("hildon-libs","wdgt_va_date_day_name_short"), time);
       else
@@ -383,17 +385,56 @@
 }
 
 static void
+cal_read_past_undone_todos_for_calendar(CCalendar* calendar,
+				 time_t end_time,
+				 SortedCComponentSet& all_components,
+				 CalHomePlugin* desktop_plugin)
+{
+  int error = 0;
+  int offset = 0;
+  int size = 0;
+  int limit = 100;
+
+  do
+  {
+    vector<CComponent*> calendars_components = calendar->getComponents(E_TODO,
+								       -1,
+								       end_time,
+								       limit,
+								       offset,
+								       error);
+    size = calendars_components.size();
+    offset+=limit;
+    for(int k = 0;k<calendars_components.size();++k)
+    {
+      CComponent* component = calendars_components[k];
+
+      if(component->getDateStart() > end_time || component->getStatus() == 1)
+      {
+	delete component;
+      }
+      else
+      {
+	all_components.insert(component);
+      }
+    }
+  }while(size !=0 );
+}
+
+static void
 cal_read_ccompnents_for_calendar(CCalendar* calendar,
 				 time_t start_time,
 				 time_t end_time,
 				 SortedCComponentSet& all_components,
-				 gboolean birthday_only,
+				 gboolean allday_records,
 				 CalHomePlugin* desktop_plugin)
 {
   int error = 0;
   int offset = 0;
   int size = 0;
   int limit = 100;
+
+  FILE *fp=fopen("/tmp/lo.txt", "a");
   do
   {
     vector<CComponent*> calendars_components = calendar->getAllEventsTodos(start_time,
@@ -404,29 +445,29 @@
     size = calendars_components.size();
     offset+=limit;
     time_t last_start_date = start_time;
-    time_t system_time_offset = CMulticalendar::MCInstance()->getSystemTimeShift();
     for(int k = 0;k<calendars_components.size();++k)
     {
       CComponent* component = calendars_components[k];
+      time_t event_start_time = component->getDateStart();
+      time_t event_end_time = component->getDateEnd();
 
-      time_t event_time_offset = component->getTzOffset();
-
-      vector<time_t> instance_times =
-	component->getInstanceTimes(last_start_date, 
-				    end_time);
-      if((desktop_plugin->visible_entry_mode == VISIBLE_ENTRY_EVENT && calendars_components[k]->getType() == E_TODO) ||
-	 (FALSE==birthday_only && 
-	  ((calendars_components[k]->getType() == E_BDAY) ||
-	   (calendars_components[k]->getType() == E_TODO))) ||
-	 (birthday_only && (calendars_components[k]->getType() == E_EVENT)) ||
-	 (desktop_plugin->visible_entry_mode == VISIBLE_ENTRY_TASK && calendars_components[k]->getType() != E_TODO) ||
-	 (component->getType() == E_TODO && component->getDateStart() > end_time)
-	 )
+      if((desktop_plugin->visible_entry_mode == VISIBLE_ENTRY_EVENT && component->getType() == E_TODO) ||
+	 (desktop_plugin->visible_entry_mode == VISIBLE_ENTRY_TASK && component->getType() != E_TODO) ||
+	 /* allday_records: all day events, birthdays, todos */
+	 (allday_records && component->getType() == E_EVENT && !component->getAllDay()) ||
+	 /* !allday_records: time-sensitive events */
+	 (!allday_records && (component->getType() != E_EVENT || component->getAllDay())) ||
+	 (component->getType() == E_EVENT && event_end_time < start_time) ||
+	 (component->getType() == E_TODO && (event_start_time > end_time || component->getStatus() == 1)) ||
+	 (component->getType() == E_BDAY && event_start_time < start_time))
       {
-	delete calendars_components[k];
+	delete component;
       }
       else
       {
+        vector<time_t> instance_times =
+	  component->getInstanceTimes(last_start_date, end_time);
+
 	if(instance_times.empty())
 	{
 	  all_components.insert(component);
@@ -458,6 +499,7 @@
       }
     }
   }while(size !=0 );
+  fclose(fp);
 }
 
 static void
@@ -478,6 +520,11 @@
     CCalendar* cal = CMulticalendar::MCInstance()->getCalendarById(desktop_plugin->visible_cals[i], error);
     if(error == 500)
     {
+      if(desktop_plugin->visible_entry_mode != VISIBLE_ENTRY_EVENT)
+        cal_read_past_undone_todos_for_calendar(cal,
+						today_midnight_time-1,
+						all_components,
+						desktop_plugin);
       cal_read_ccompnents_for_calendar(cal,
 				       start_time+1,
 				       end_time,
