r1414 - in trunk/src/target/OM-2007/applications/openmoko-today: . src

dodji at sita.openmoko.org dodji at sita.openmoko.org
Mon Mar 19 23:26:48 CET 2007


Author: dodji
Date: 2007-03-19 23:26:43 +0100 (Mon, 19 Mar 2007)
New Revision: 1414

Modified:
   trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.c
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.h
Log:
Use icalcomponent instead of EcalComponent

	* applications/openmoko-today/src/today-events-area.c:
	  Do not use ECalComponent anymore, but rather
	  the underlying icalcomponent.
	  ECalComponent was actually useless and was
	  just eating more memory.
	* applications/openmoko-today/src/today-utils.c,h:
	  ditto.
	  Added icalcomponent_has_alarm() to detect if an
	  icalcomponent has alarms.


Modified: trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog	2007-03-19 22:26:32 UTC (rev 1413)
+++ trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog	2007-03-19 22:26:43 UTC (rev 1414)
@@ -1,3 +1,15 @@
+Mon, 19 Mar 2007 23:15:46 +0100 Dodji Seketeli
+
+	* applications/openmoko-today/src/today-events-area.c:
+	  Do not use ECalComponent anymore, but rather
+	  the underlying icalcomponent.
+	  ECalComponent was actually useless and was
+	  just eating more memory.
+	* applications/openmoko-today/src/today-utils.c,h:
+	  ditto.
+	  Added icalcomponent_has_alarm() to detect if an
+	  icalcomponent has alarms.
+
 Mon, 19 Mar 2007 19:59:27 +0100 Dodji Seketeli
 
 	* applications/openmoko-today/src/today-events-area.c:

Modified: trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c	2007-03-19 22:26:32 UTC (rev 1413)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c	2007-03-19 22:26:43 UTC (rev 1414)
@@ -23,16 +23,19 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include <string.h>
-#include <libecal/e-cal-time-util.h>
-#include <libecal/e-cal-component.h>
+/*#include <libecal/e-cal-time-util.h>*/
+/*#include <libical/e-cal-component.h>*/
+#include <libical/icalcomponent.h>
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkhbox.h>
 #include <gtk/gtktable.h>
 #include <gtk/gtkimage.h>
 #include <gtk/gtkeventbox.h>
 #include <gtk/gtklabel.h>
+#include "today-utils.h"
 #include "today-events-area.h"
 
+
 struct _TodayEventsAreaPrivate {
   GList *events ;
   GtkWidget *left ;
@@ -84,8 +87,6 @@
 static void     render_events_page          (TodayEventsArea *a_this,
                                              GList *a_from) ;
 static void     render_events_page_auto     (TodayEventsArea *a_this) ;
-static void     e_cal_component_list_free   (GList * list) ;
-static gchar*   icaltime_to_pretty_string   (const icaltimetype *timetype) ;
 static void     event_selected_signal       (TodayEventsArea *a_this,
                                              guint a_index) ;
 static void     events_added_signal       (TodayEventsArea *a_this,
@@ -215,7 +216,7 @@
 
   if (self->priv->events)
   {
-    e_cal_component_list_free (self->priv->events) ;
+    e_cal_free_object_list (self->priv->events) ;
     self->priv->events = NULL ;
   }
   self->priv->cur_event = NULL ;
@@ -371,34 +372,7 @@
   }
 }
 
-/**
- * e_cal_component_list_free:
- * @list: the list ECalComooment to free
- *
- * Free a list of ECalComponent
- */
 static void
-e_cal_component_list_free (GList * a_list)
-{
-  GList *cur = NULL;
-
-  for (cur = a_list; cur; cur = cur->next)
-  {
-    /*if an element of the list is not of type ECalComponent, leak it */
-    if (cur->data && E_IS_CAL_COMPONENT (cur->data))
-    {
-      g_object_unref (G_OBJECT (cur->data));
-      cur->data = NULL;
-    }
-    else
-    {
-      g_warning ("cur->data is not of type ECalComponent !");
-    }
-  }
-  g_list_free (a_list);
-}
-
-static void
 clear_right_hand_side (TodayEventsArea *a_this)
 {
   g_return_if_fail (a_this
@@ -581,11 +555,10 @@
               GList *a_event)
 {
   GtkWidget *infoline, *label, *event_box, *icon ;
-  ECalComponentText text ;
-  ECalComponentDateTime date ;
-  ECalComponent *event=NULL ;
+  icaltimetype date ;
+  icalcomponent *event=NULL ;
   int event_index=0 ;
-  gchar *tmp_str=NULL, *tmp_str2=NULL ;
+  gchar *tmp_str=NULL, *tmp_str2=NULL, *summary=NULL ;
   gboolean has_alarm=FALSE, is_todo=FALSE, is_event=FALSE ;
 
   g_return_if_fail (a_this
@@ -597,78 +570,81 @@
   g_return_if_fail (a_event && a_event->data) ;
 
   event = a_event->data ;
-  g_return_if_fail (E_IS_CAL_COMPONENT (event)) ;
+  g_return_if_fail (icalcomponent_isa_component (event)) ;
+
   event_index = g_list_position (a_this->priv->events, a_event) ;
   g_return_if_fail (event_index >= 0) ;
 
   /*does the comp has an alarm ?*/
-  has_alarm = e_cal_component_has_alarms (event) ;
+  has_alarm = icalcomponent_has_alarm (event);
 
   /*is the comp a todo item ? */
-  is_todo = (e_cal_component_get_vtype (event) == E_CAL_COMPONENT_TODO);
+  is_todo = (icalcomponent_isa (event) == ICAL_VTODO_COMPONENT);
 
   /*is the comp a calendar event ?*/
-  is_event = (e_cal_component_get_vtype (event) == E_CAL_COMPONENT_EVENT);
+  is_event = (icalcomponent_isa (event) == ICAL_VEVENT_COMPONENT);
 
   /*a comp must be either a calendar event or a todo item*/
   g_return_if_fail (is_event != is_todo) ;
 
   /*get the event summary*/
-  e_cal_component_get_summary (event, &text) ;
+  summary = (gchar*) icalcomponent_get_summary (event) ;
 
   /*get the event starting date*/
   if (is_event)
-    e_cal_component_get_dtstart (event, &date) ;
-  else if (is_todo)
   {
-    e_cal_component_get_due (event, &date) ;
+    date = icalcomponent_get_dtstart (event) ;
+    tmp_str = icaltime_to_pretty_string (&date) ;
   }
-
-  if (date.value)
+  else if (is_todo)
   {
-    tmp_str = icaltime_to_pretty_string (date.value) ;
-    e_cal_component_free_datetime (&date) ;
+    date = icalcomponent_get_due (event) ;
+    tmp_str = icaltime_to_pretty_string (&date) ;
   }
 
+
   /*build event infoline*/
   if (tmp_str)
   {
-    tmp_str2 = g_strdup_printf ("%s %s", text.value, tmp_str) ;
+    tmp_str2 = g_strdup_printf ("%s %s", summary, tmp_str) ;
     g_free (tmp_str) ;
   }
   else
   {
-    tmp_str2 = g_strdup_printf ("%s", text.value) ;
+    tmp_str2 = g_strdup_printf ("%s", summary) ;
   }
   label = gtk_label_new (tmp_str2) ;
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0) ;
   gtk_widget_show (label) ;
   g_free (tmp_str2) ;
   infoline = gtk_hbox_new (TRUE, 0) ;
+  gtk_box_set_homogeneous (GTK_BOX (infoline), FALSE) ;
   gtk_widget_show (infoline) ;
-  gtk_box_pack_start_defaults (GTK_BOX (infoline), label) ;
+  gtk_box_pack_start (GTK_BOX (infoline), label, FALSE, FALSE, 0) ;
   icon = gtk_image_new () ;
-  if (is_event)
+
+  if (has_alarm)
   {
     gtk_image_set_from_stock (GTK_IMAGE (icon),
-                              "openmoko-today-event",
+                              "openmoko-today-bell",
                               GTK_ICON_SIZE_MENU);
   }
-  else if (is_todo)
+  else if (is_event)
   {
     gtk_image_set_from_stock (GTK_IMAGE (icon),
-                              "openmoko-today-todo",
+                              "openmoko-today-event",
                               GTK_ICON_SIZE_MENU);
   }
-  else if (has_alarm)
+  else if (is_todo)
   {
     gtk_image_set_from_stock (GTK_IMAGE (icon),
-                              "openmoko-today-bell",
+                              "openmoko-today-todo",
                               GTK_ICON_SIZE_MENU);
   }
+
   gtk_misc_set_alignment (GTK_MISC (icon), 0, 0);
   gtk_widget_show_all (icon) ;
-  gtk_box_pack_start_defaults (GTK_BOX (infoline), icon) ;
+  gtk_box_pack_start (GTK_BOX (infoline), icon, FALSE, FALSE, 6) ;
   event_box = gtk_event_box_new () ;
   gtk_widget_show (event_box) ;
   g_object_set_data (G_OBJECT (event_box),
@@ -816,7 +792,7 @@
   g_return_if_fail (a_this->priv) ;
 
   if (a_this->priv->events)
-    e_cal_component_list_free (a_this->priv->events) ;
+    e_cal_free_object_list (a_this->priv->events) ;
 
   a_this->priv->events = a_events ;
   a_this->priv->nb_events = get_nb_events_real (a_this) ;

Modified: trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.c	2007-03-19 22:26:32 UTC (rev 1413)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.c	2007-03-19 22:26:43 UTC (rev 1414)
@@ -28,7 +28,9 @@
  *
  * Free a list of ECalComponent
  */
+#include <string.h>
 #include "today-utils.h"
+#include <libical/icalcomponent.h>
 
 #define LOG_ERROR \
 g_warning ("Got error '%s', code '%d'", \
@@ -36,6 +38,9 @@
 
 #define FREE_ERROR g_error_free (error) ; error = NULL ;
 
+static ECal *calendar_db = NULL;
+static ECal *tasks_db = NULL;
+
 void
 e_cal_component_list_free (GList * list)
 {
@@ -142,24 +147,25 @@
 GList *
 today_get_today_events ()
 {
-  GList *result=NULL, *ical_comps=NULL,
-        *ecal_comps=NULL, *ecal_comps2=NULL;
-  ECal *ecal = NULL;
+  GList *result=NULL, *ical_comps=NULL, *ical_comps2=NULL;
   GError *error = NULL;
   gchar *query = NULL;
 
-  ecal = e_cal_new_system_calendar ();
-  g_return_val_if_fail (ecal, NULL);
+  if (!calendar_db)
+  {
+    calendar_db = e_cal_new_system_calendar ();
+    g_return_val_if_fail (calendar_db, NULL);
 
-  if (!e_cal_open (ecal, FALSE, &error))
-  {
-    g_warning ("failed to open the calendar");
+    if (!e_cal_open (calendar_db, TRUE, &error))
+    {
+      g_warning ("failed to open the calendar");
+    }
+    if (error)
+    {
+      LOG_ERROR;
+      goto out;
+    }
   }
-  if (error)
-  {
-    LOG_ERROR;
-    goto out;
-  }
 
   /*
   query = g_strdup_printf ("(occur-in-time-range? "
@@ -168,7 +174,7 @@
                            ")");
    */
   query = g_strdup_printf ("#t");
-  e_cal_get_object_list (ecal, query, &ical_comps, &error);
+  e_cal_get_object_list (calendar_db, query, &ical_comps, &error);
   g_free (query) ;
   query = NULL ;
   if (error)
@@ -177,32 +183,23 @@
     FREE_ERROR;
   }
 
-  /*
-   * build a list of ECalComponent, out of the list of icalcomponents
-   * when an icalcomponent is set to an ECalComponent, the later
-   * becomes responsible of freeing the former's memory
-   */
-  if (ical_comps)
+  if (!tasks_db)
   {
-    ecal_comps = icalcomps_to_ecalcomps (ical_comps) ;
-    g_list_free (ical_comps) ;
-    ical_comps = NULL ;
+    tasks_db = e_cal_new_system_tasks ();
+    g_return_val_if_fail (tasks_db, NULL);
+    if (!e_cal_open (tasks_db, TRUE, &error))
+    {
+      g_warning ("failed to open the tasks");
+    }
+    if (error)
+    {
+      LOG_ERROR;
+      goto out;
+    }
   }
 
-  ecal = e_cal_new_system_tasks ();
-  g_return_val_if_fail (ecal, NULL);
-  if (!e_cal_open (ecal, FALSE, &error))
-  {
-    g_warning ("failed to open the calendar");
-  }
-  if (error)
-  {
-    LOG_ERROR;
-    goto out;
-  }
-
   query = g_strdup_printf ("#t");
-  e_cal_get_object_list (ecal, query, &ical_comps, &error);
+  e_cal_get_object_list (tasks_db, query, &ical_comps2, &error);
   g_free (query) ;
   query = NULL ;
   if (error)
@@ -210,16 +207,10 @@
     LOG_ERROR;
     FREE_ERROR ;
   }
-  if (ical_comps)
-  {
-    ecal_comps2 = icalcomps_to_ecalcomps (ical_comps) ;
-    g_list_free (ical_comps) ;
-    ical_comps = NULL ;
-  }
-  ecal_comps = g_list_concat (ecal_comps, ecal_comps2) ;
+  ical_comps = g_list_concat (ical_comps, ical_comps2) ;
 
-  result = ecal_comps;
-  ecal_comps = ecal_comps2 = NULL;
+  result = ical_comps;
+  ical_comps = ical_comps2 = NULL;
 
 out:
   if (ical_comps)
@@ -227,14 +218,10 @@
     e_cal_free_object_list (ical_comps);
   }
 
-  if (ecal_comps)
+  if (ical_comps2)
   {
-    e_cal_component_list_free (ecal_comps);
+    e_cal_free_object_list (ical_comps);
   }
-  if (ecal_comps2)
-  {
-    e_cal_component_list_free (ecal_comps2);
-  }
 
   /*
    the calender must stay alive during the app's lifetime
@@ -248,12 +235,27 @@
   {
     g_error_free (error);
   }
-
   if (query)
   {
     g_free (query);
   }
-
   return result;
 }
 
+gboolean
+icalcomponent_has_alarm (icalcomponent *a_icalcomp)
+{
+  icalcompiter iter ;
+
+  g_return_val_if_fail (a_icalcomp, FALSE) ;
+  g_return_val_if_fail (icalcomponent_isa_component (a_icalcomp), FALSE) ;
+
+  for (iter = icalcomponent_begin_component (a_icalcomp,
+                                             ICAL_VALARM_COMPONENT);
+      icalcompiter_deref (&iter) != NULL ;
+      icalcompiter_next (&iter))
+  {
+    return TRUE ;
+  }
+  return FALSE ;
+}

Modified: trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.h	2007-03-19 22:26:32 UTC (rev 1413)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.h	2007-03-19 22:26:43 UTC (rev 1414)
@@ -25,12 +25,14 @@
 #define  __TODAY_UTILS_H__
 
 #include <glib.h>
+#include <libical/icalcomponent.h>
 #include <libecal/e-cal.h>
 #include <libecal/e-cal-time-util.h>
 
 GList* today_get_today_events () ;
 void e_cal_component_list_free (GList * list) ;
 gchar* icaltime_to_pretty_string (const icaltimetype *timetype) ;
+gboolean icalcomponent_has_alarm (icalcomponent *a_icalcomp) ;
 
 #endif /*__TODAY_UTILS_H__*/
 





More information about the commitlog mailing list