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

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


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

Added:
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.c
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.h
Modified:
   trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog
   trunk/src/target/OM-2007/applications/openmoko-today/src/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c
   trunk/src/target/OM-2007/applications/openmoko-today/src/today-main.c
   trunk/src/target/OM-2007/applications/openmoko-today/tests/Makefile.am
   trunk/src/target/OM-2007/applications/openmoko-today/tests/ecal-test.c
Log:
Show todo items and alarms. Use them icons for that.

	* applications/openmoko-today/src/today-events-area.c:
	  move utils functions into
	  applications/openmoko-today/src/today-utils.[c|h].
	  Get todo items as well.
	  Render todo items, events, and alarmed event using
	  the theme icons.
	* applications/openmoko-today/src/today-utils.c: move util functions in
	  here


Modified: trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog	2007-03-19 22:26:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog	2007-03-19 22:26:32 UTC (rev 1413)
@@ -1,3 +1,14 @@
+Mon, 19 Mar 2007 19:59:27 +0100 Dodji Seketeli
+
+	* applications/openmoko-today/src/today-events-area.c:
+	  move utils functions into
+	  applications/openmoko-today/src/today-utils.[c|h].
+	  Get todo items as well.
+	  Render todo items, events, and alarmed event using
+	  the theme icons.
+	* applications/openmoko-today/src/today-utils.c: move util functions in
+	  here
+
 Mon, 19 Mar 2007 15:29:03 +0000 Thomas Wood
 
 	* src/today-main.c: Use MokoPixmapButton for launchers

Modified: trunk/src/target/OM-2007/applications/openmoko-today/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/src/Makefile.am	2007-03-19 22:26:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/Makefile.am	2007-03-19 22:26:32 UTC (rev 1413)
@@ -8,7 +8,9 @@
 
 bin_PROGRAMS          = today
 
-today_SOURCES         = today-main.c today-events-area.h today-events-area.c
+today_SOURCES         = today-main.c \
+today-events-area.h today-events-area.c \
+today-utils.h today-utils.c
 
 today_LDADD          = @TODAY_LIBS@
 

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:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c	2007-03-19 22:26:32 UTC (rev 1413)
@@ -28,6 +28,7 @@
 #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-events-area.h"
@@ -575,59 +576,17 @@
 
 }
 
-/*
- * if the timetype is today, then only display it's hour part,
- * without the seconds
- * If it's not today, then only display it's date part, without the year
- */
-static gchar*
-icaltime_to_pretty_string (const icaltimetype *timetype)
-{
-#define TMP_STR_LEN 10
-    icaltimetype today ;
-    gboolean     hour_only              = FALSE ;
-    gboolean     date_only              = FALSE ;
-    gchar        *result                = NULL  ;
-    gchar        tmp_str[TMP_STR_LEN+1]         ;
-    struct tm    native_tm                      ;
-
-    g_return_val_if_fail (timetype, NULL) ;
-
-    today = icaltime_today () ;
-    if (!icaltime_compare_date_only (*timetype, today))
-    {
-        hour_only = TRUE ;
-    }
-    else
-    {
-        date_only = TRUE ;
-    }
-    if (hour_only)
-    {
-        result = g_strdup_printf ("%d:%d", timetype->hour, timetype->minute) ;
-    }
-    else if (date_only)
-    {
-        native_tm = icaltimetype_to_tm ((icaltimetype*)timetype) ;
-        memset (tmp_str, 0, TMP_STR_LEN+1) ;
-        strftime (tmp_str, TMP_STR_LEN, "%d/%b", &native_tm) ;
-        result = g_strdup (tmp_str) ;
-    }
-    return result ;
-}
-
 static void
 render_event (TodayEventsArea *a_this,
               GList *a_event)
 {
-  GtkWidget *infoline ;
-  GtkWidget *label ;
-  GtkWidget *event_box ;
+  GtkWidget *infoline, *label, *event_box, *icon ;
   ECalComponentText text ;
-  ECalComponentDateTime start_date ;
-  ECalComponent *event ;
-  int event_index ;
-  gchar *tmp_str, *tmp_str2 ;
+  ECalComponentDateTime date ;
+  ECalComponent *event=NULL ;
+  int event_index=0 ;
+  gchar *tmp_str=NULL, *tmp_str2=NULL ;
+  gboolean has_alarm=FALSE, is_todo=FALSE, is_event=FALSE ;
 
   g_return_if_fail (a_this
                     && TODAY_IS_EVENTS_AREA (a_this)
@@ -642,17 +601,45 @@
   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) ;
+
+  /*is the comp a todo item ? */
+  is_todo = (e_cal_component_get_vtype (event) == E_CAL_COMPONENT_TODO);
+
+  /*is the comp a calendar event ?*/
+  is_event = (e_cal_component_get_vtype (event) == E_CAL_COMPONENT_EVENT);
+
+  /*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) ;
 
   /*get the event starting date*/
-  e_cal_component_get_dtstart (event, &start_date) ;
-  tmp_str = icaltime_to_pretty_string (start_date.value) ;
-  e_cal_component_free_datetime (&start_date) ;
+  if (is_event)
+    e_cal_component_get_dtstart (event, &date) ;
+  else if (is_todo)
+  {
+    e_cal_component_get_due (event, &date) ;
+  }
 
+  if (date.value)
+  {
+    tmp_str = icaltime_to_pretty_string (date.value) ;
+    e_cal_component_free_datetime (&date) ;
+  }
+
   /*build event infoline*/
-  tmp_str2 = g_strdup_printf ("%s %s", text.value, tmp_str) ;
-  g_free (tmp_str) ;
+  if (tmp_str)
+  {
+    tmp_str2 = g_strdup_printf ("%s %s", text.value, tmp_str) ;
+    g_free (tmp_str) ;
+  }
+  else
+  {
+    tmp_str2 = g_strdup_printf ("%s", text.value) ;
+  }
   label = gtk_label_new (tmp_str2) ;
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0) ;
   gtk_widget_show (label) ;
@@ -660,6 +647,28 @@
   infoline = gtk_hbox_new (TRUE, 0) ;
   gtk_widget_show (infoline) ;
   gtk_box_pack_start_defaults (GTK_BOX (infoline), label) ;
+  icon = gtk_image_new () ;
+  if (is_event)
+  {
+    gtk_image_set_from_stock (GTK_IMAGE (icon),
+                              "openmoko-today-event",
+                              GTK_ICON_SIZE_MENU);
+  }
+  else if (is_todo)
+  {
+    gtk_image_set_from_stock (GTK_IMAGE (icon),
+                              "openmoko-today-todo",
+                              GTK_ICON_SIZE_MENU);
+  }
+  else if (has_alarm)
+  {
+    gtk_image_set_from_stock (GTK_IMAGE (icon),
+                              "openmoko-today-bell",
+                              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) ;
   event_box = gtk_event_box_new () ;
   gtk_widget_show (event_box) ;
   g_object_set_data (G_OBJECT (event_box),

Modified: trunk/src/target/OM-2007/applications/openmoko-today/src/today-main.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/src/today-main.c	2007-03-19 22:26:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-main.c	2007-03-19 22:26:32 UTC (rev 1413)
@@ -25,12 +25,11 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gprintf.h>
-#include <libecal/e-cal.h>
-#include <libecal/e-cal-time-util.h>
 #include <gtk/gtk.h>
 #include <libmokoui/moko-window.h>
 #include <libmokoui/moko-pixmap-button.h>
 #include "today-events-area.h"
+#include "today-utils.h"
 
 #define LOG_ERROR \
 g_warning ("Got error '%s', code '%d'", \
@@ -81,134 +80,6 @@
   gtk_label_set_markup (label, time_str);
 }
 
-/**
- * e_cal_component_list_free:
- * @list: the list ECalComooment to free
- *
- * Free a list of ECalComponent
- */
-static void
-e_cal_component_list_free (GList * list)
-{
-  GList *cur = NULL;
-
-  for (cur = 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 (list);
-}
-
-/**
- * today_get_today_events:
- *
- * Return value:  a list of ECalComponents, of type VEVENT
- * must be freed with e_cal_component_list_free()
- */
-static GList *
-today_get_today_events ()
-{
-  GList *result = NULL;
-  GList *ical_comps = NULL;
-  GList *ecal_comps = NULL;
-  GList *cur = NULL;
-  ECal *ecal = NULL;
-  GError *error = NULL;
-  gchar *query = NULL;
-
-  ecal = e_cal_new_system_calendar ();
-  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 ("(occur-in-time-range? "
-                               "(time-day-begin (time-now)) "
-                               "(time-day-end   (time-now)) "
-                           ")");
-   */
-  query = g_strdup_printf ("#t");
-  e_cal_get_object_list (ecal, query, &ical_comps, &error);
-  if (error)
-  {
-    LOG_ERROR;
-    goto out;
-  }
-
-  /*
-   * 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
-   */
-  for (cur = ical_comps; cur; cur = cur->next)
-  {
-    ECalComponent *c = NULL;
-    if (!cur->data)
-      continue;
-
-    c = e_cal_component_new ();
-    if (!e_cal_component_set_icalcomponent (c, cur->data))
-    {
-      icalcomponent_free (cur->data);
-      cur->data = NULL;
-      continue;
-    }
-
-    ecal_comps = g_list_prepend (ecal_comps, c);
-    cur->data = NULL;
-  }
-  result = ecal_comps;
-  ecal_comps = NULL;
-
-out:
-  if (ical_comps)
-  {
-    e_cal_free_object_list (ical_comps);
-  }
-
-  if (ecal_comps)
-  {
-    e_cal_component_list_free (ecal_comps);
-  }
-  ecal_comps = NULL;
-
-  /*
-   the calender must stay alive during the app's lifetime
-  if (ecal)
-  {
-    g_object_unref (G_OBJECT (ecal));
-  }
-  */
-
-  if (error)
-  {
-    g_error_free (error);
-  }
-
-  g_free (query);
-
-  return result;
-}
-
-
 /* information lines */
 
 /**
@@ -235,6 +106,7 @@
   icon = gtk_image_new ();
   gtk_image_set_from_stock (GTK_IMAGE (icon), stock_id, GTK_ICON_SIZE_MENU);
   gtk_misc_set_alignment (GTK_MISC (icon), 0, 0);
+  gtk_widget_show (icon) ;
   gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
 
   // FIXME: get this from the style... somehow
@@ -247,13 +119,12 @@
   return eventbox;
 }
 
-
 /* launcher buttons */
 
 /**
  * callback for luncher buttons
  */
-static void
+void
 today_launcher_clicked_cb (GtkWidget *button, gchar *command)
 {
   GError *error;

Added: 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:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.c	2007-03-19 22:26:32 UTC (rev 1413)
@@ -0,0 +1,259 @@
+/* vi: set sw=2: */
+/*
+ *  Today - At a glance view of date, time, calender events, todo items and
+ *  other images.
+ *
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info at openedhand.com>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * e_cal_component_list_free:
+ * @list: the list ECalComooment to free
+ *
+ * Free a list of ECalComponent
+ */
+#include "today-utils.h"
+
+#define LOG_ERROR \
+g_warning ("Got error '%s', code '%d'", \
+           error->message, error->code);
+
+#define FREE_ERROR g_error_free (error) ; error = NULL ;
+
+void
+e_cal_component_list_free (GList * list)
+{
+  GList *cur = NULL;
+
+  for (cur = 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 (list);
+}
+
+/*
+ * if the timetype is today, then only display it's hour part,
+ * without the seconds
+ * If it's not today, then only display it's date part, without the year
+ */
+gchar*
+icaltime_to_pretty_string (const icaltimetype *timetype)
+{
+#define TMP_STR_LEN 10
+    icaltimetype today ;
+    gboolean     hour_only              = FALSE ;
+    gboolean     date_only              = FALSE ;
+    gchar        *result                = NULL  ;
+    gchar        tmp_str[TMP_STR_LEN+1]         ;
+    struct tm    native_tm                      ;
+
+    g_return_val_if_fail (timetype, NULL) ;
+
+    today = icaltime_today () ;
+    if (!icaltime_compare_date_only (*timetype, today))
+    {
+        hour_only = TRUE ;
+    }
+    else
+    {
+        date_only = TRUE ;
+    }
+    if (hour_only)
+    {
+        result = g_strdup_printf ("%d:%d", timetype->hour, timetype->minute) ;
+    }
+    else if (date_only)
+    {
+        native_tm = icaltimetype_to_tm ((icaltimetype*)timetype) ;
+        memset (tmp_str, 0, TMP_STR_LEN+1) ;
+        strftime (tmp_str, TMP_STR_LEN, "%d/%b", &native_tm) ;
+        result = g_strdup (tmp_str) ;
+    }
+    return result ;
+}
+
+
+static GList*
+icalcomps_to_ecalcomps (GList *a_icalcomps)
+{
+  GList *cur=NULL, *ecalcomps=NULL  ;
+
+  g_return_val_if_fail (a_icalcomps, NULL) ;
+  /*
+   * 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
+   */
+  for (cur = a_icalcomps; cur; cur = cur->next)
+  {
+    ECalComponent *c = NULL;
+    if (!cur->data)
+      continue;
+
+    c = e_cal_component_new ();
+    if (!e_cal_component_set_icalcomponent (c, cur->data))
+    {
+      g_warning ("setting icalcomp into ecalcomp failed") ;
+      icalcomponent_free (cur->data);
+      cur->data = NULL;
+      continue;
+    }
+    ecalcomps = g_list_prepend (ecalcomps, c);
+    cur->data = NULL;
+  }
+  return ecalcomps ;
+
+}
+
+
+/**
+ * today_get_today_events:
+ *
+ * Return value:  a list of ECalComponents, of type VEVENT
+ * or VTODO
+ * must be freed with e_cal_component_list_free()
+ */
+GList *
+today_get_today_events ()
+{
+  GList *result=NULL, *ical_comps=NULL,
+        *ecal_comps=NULL, *ecal_comps2=NULL;
+  ECal *ecal = NULL;
+  GError *error = NULL;
+  gchar *query = NULL;
+
+  ecal = e_cal_new_system_calendar ();
+  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 ("(occur-in-time-range? "
+                               "(time-day-begin (time-now)) "
+                               "(time-day-end   (time-now)) "
+                           ")");
+   */
+  query = g_strdup_printf ("#t");
+  e_cal_get_object_list (ecal, query, &ical_comps, &error);
+  g_free (query) ;
+  query = NULL ;
+  if (error)
+  {
+    LOG_ERROR;
+    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)
+  {
+    ecal_comps = icalcomps_to_ecalcomps (ical_comps) ;
+    g_list_free (ical_comps) ;
+    ical_comps = NULL ;
+  }
+
+  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);
+  g_free (query) ;
+  query = NULL ;
+  if (error)
+  {
+    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) ;
+
+  result = ecal_comps;
+  ecal_comps = ecal_comps2 = NULL;
+
+out:
+  if (ical_comps)
+  {
+    e_cal_free_object_list (ical_comps);
+  }
+
+  if (ecal_comps)
+  {
+    e_cal_component_list_free (ecal_comps);
+  }
+  if (ecal_comps2)
+  {
+    e_cal_component_list_free (ecal_comps2);
+  }
+
+  /*
+   the calender must stay alive during the app's lifetime
+  if (ecal)
+  {
+    g_object_unref (G_OBJECT (ecal));
+  }
+  */
+
+  if (error)
+  {
+    g_error_free (error);
+  }
+
+  if (query)
+  {
+    g_free (query);
+  }
+
+  return result;
+}
+

Added: 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:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/src/today-utils.h	2007-03-19 22:26:32 UTC (rev 1413)
@@ -0,0 +1,36 @@
+/* vi: set sw=2: */
+/*
+ *  Today - At a glance view of date, time, calender events, todo items and
+ *  other images.
+ *
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info at openedhand.com>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef __TODAY_UTILS_H__
+#define  __TODAY_UTILS_H__
+
+#include <glib.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) ;
+
+#endif /*__TODAY_UTILS_H__*/
+

Modified: trunk/src/target/OM-2007/applications/openmoko-today/tests/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/tests/Makefile.am	2007-03-19 22:26:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/tests/Makefile.am	2007-03-19 22:26:32 UTC (rev 1413)
@@ -4,7 +4,8 @@
 ecaltest_LDADD		   = @TODAY_LIBS@
 
 eventsareatest_SOURCES     = events-area-test.c \
-$(top_srcdir)/src/today-events-area.c
+$(top_srcdir)/src/today-events-area.c \
+$(top_srcdir)/src/today-utils.c
 
 eventsareatest_LDADD       = @TODAY_LIBS@
 

Modified: trunk/src/target/OM-2007/applications/openmoko-today/tests/ecal-test.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-today/tests/ecal-test.c	2007-03-19 22:26:24 UTC (rev 1412)
+++ trunk/src/target/OM-2007/applications/openmoko-today/tests/ecal-test.c	2007-03-19 22:26:32 UTC (rev 1413)
@@ -1,3 +1,4 @@
+/* vi:set sw=2: */
 /*
  *  Today - At a glance view of date, time, calender events, todo items and
  *  other images.
@@ -45,31 +46,47 @@
 void
 display_events (GList *a_events/*list of icalcomponents*/)
 {
-    GList          *cur         = NULL ;
-    ECalComponent  *cal_comp    = NULL ;
-    char           *event_str   = NULL ;
+  GList          *cur         = NULL ;
+  ECalComponent  *cal_comp    = NULL ;
+  char           *event_str   = NULL ;
+  char           *categories  = NULL ;
 
-    if (!a_events) {
-        g_message ("No events") ;
-        return ;
-    }
-    cal_comp = e_cal_component_new () ;
-    g_return_if_fail (cal_comp) ;
+  if (!a_events)
+  {
+    g_message ("No events") ;
+    return ;
+  }
+  cal_comp = e_cal_component_new () ;
+  g_return_if_fail (cal_comp) ;
 
-    for (cur = a_events ; cur ; cur = cur->next) {
-        if (!cur->data) {continue;}
-        e_cal_component_set_icalcomponent (cal_comp, cur->data) ;
-        if (e_cal_component_get_vtype (cal_comp) != E_CAL_COMPONENT_EVENT) {
-            g_warning ("component is not an event, rather of type %d",
-                       e_cal_component_get_vtype (cal_comp));
-            continue ;
-        }
-        event_str = e_cal_component_get_as_string (cal_comp) ;
-        if (event_str) {
-            g_message ("Got event '%s'", event_str) ;
-            g_free (event_str) ;
-        }
+  for (cur = a_events ; cur ; cur = cur->next)
+  {
+    if (!cur->data) {continue;}
+    e_cal_component_set_icalcomponent (cal_comp, cur->data) ;
+    if (e_cal_component_get_vtype (cal_comp) != E_CAL_COMPONENT_EVENT)
+    {
+      g_warning ("component is not an event, rather of type %d",
+          e_cal_component_get_vtype (cal_comp));
+      continue ;
     }
+    event_str = e_cal_component_get_as_string (cal_comp) ;
+    if (event_str)
+    {
+      g_message ("Got event '%s'", event_str) ;
+      g_free (event_str) ;
+    }
+    e_cal_component_get_categories (cal_comp, &categories) ;
+    if (categories)
+    {
+      g_message ("event's categs: '%s'\n", categories) ;
+      //g_free (categories) ;
+      categories = NULL ;
+    }
+    else
+    {
+      g_message ("no associated category") ;
+    }
+  }
 }
 
 int
@@ -101,11 +118,15 @@
     }
     if (ret) {goto out ;}
 
+    /*
     query = g_strdup_printf ("(occur-in-time-range? "
                                  "(time-day-begin (time-now)) "
                                  "(time-day-end   (time-now))"
                              ")");
 
+    */
+    query = g_strdup_printf ("#t") ;
+
     printf ("Issuing query: '%s'\n", query) ;
     if (!e_cal_get_object_list (cal, query, &objects, &error)) {
         g_message ("Querying system calendar failed\n") ;
@@ -123,11 +144,13 @@
     }
 
 out:
+    /*
     if (cal) {
         g_object_unref (G_OBJECT (cal)) ;
     }
+    */
     if (objects) {
-        e_cal_free_object_list (objects) ;
+        g_list_free (objects) ;
     }
     if (query) {
         g_free (query) ;





More information about the commitlog mailing list