Changeset 1413


Ignore:
Timestamp:
03/19/07 23:26:32 (6 years ago)
Author:
dodji
Message:

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
Location:
trunk/src/target/OM-2007/applications/openmoko-today
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog

    r1412 r1413  
     1Mon, 19 Mar 2007 19:59:27 +0100 Dodji Seketeli 
     2 
     3        * applications/openmoko-today/src/today-events-area.c: 
     4          move utils functions into 
     5          applications/openmoko-today/src/today-utils.[c|h]. 
     6          Get todo items as well. 
     7          Render todo items, events, and alarmed event using 
     8          the theme icons. 
     9        * applications/openmoko-today/src/today-utils.c: move util functions in 
     10          here 
     11 
    112Mon, 19 Mar 2007 15:29:03 +0000 Thomas Wood 
    213 
  • trunk/src/target/OM-2007/applications/openmoko-today/src/Makefile.am

    r1346 r1413  
    99bin_PROGRAMS          = today 
    1010 
    11 today_SOURCES         = today-main.c today-events-area.h today-events-area.c 
     11today_SOURCES         = today-main.c \ 
     12today-events-area.h today-events-area.c \ 
     13today-utils.h today-utils.c 
    1214 
    1315today_LDADD          = @TODAY_LIBS@ 
  • trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c

    r1380 r1413  
    2929#include <gtk/gtkhbox.h> 
    3030#include <gtk/gtktable.h> 
     31#include <gtk/gtkimage.h> 
    3132#include <gtk/gtkeventbox.h> 
    3233#include <gtk/gtklabel.h> 
     
    576577} 
    577578 
    578 /* 
    579  * if the timetype is today, then only display it's hour part, 
    580  * without the seconds 
    581  * If it's not today, then only display it's date part, without the year 
    582  */ 
    583 static gchar* 
    584 icaltime_to_pretty_string (const icaltimetype *timetype) 
    585 { 
    586 #define TMP_STR_LEN 10 
    587     icaltimetype today ; 
    588     gboolean     hour_only              = FALSE ; 
    589     gboolean     date_only              = FALSE ; 
    590     gchar        *result                = NULL  ; 
    591     gchar        tmp_str[TMP_STR_LEN+1]         ; 
    592     struct tm    native_tm                      ; 
    593  
    594     g_return_val_if_fail (timetype, NULL) ; 
    595  
    596     today = icaltime_today () ; 
    597     if (!icaltime_compare_date_only (*timetype, today)) 
    598     { 
    599         hour_only = TRUE ; 
    600     } 
    601     else 
    602     { 
    603         date_only = TRUE ; 
    604     } 
    605     if (hour_only) 
    606     { 
    607         result = g_strdup_printf ("%d:%d", timetype->hour, timetype->minute) ; 
    608     } 
    609     else if (date_only) 
    610     { 
    611         native_tm = icaltimetype_to_tm ((icaltimetype*)timetype) ; 
    612         memset (tmp_str, 0, TMP_STR_LEN+1) ; 
    613         strftime (tmp_str, TMP_STR_LEN, "%d/%b", &native_tm) ; 
    614         result = g_strdup (tmp_str) ; 
    615     } 
    616     return result ; 
    617 } 
    618  
    619579static void 
    620580render_event (TodayEventsArea *a_this, 
    621581              GList *a_event) 
    622582{ 
    623   GtkWidget *infoline ; 
    624   GtkWidget *label ; 
    625   GtkWidget *event_box ; 
     583  GtkWidget *infoline, *label, *event_box, *icon ; 
    626584  ECalComponentText text ; 
    627   ECalComponentDateTime start_date ; 
    628   ECalComponent *event ; 
    629   int event_index ; 
    630   gchar *tmp_str, *tmp_str2 ; 
     585  ECalComponentDateTime date ; 
     586  ECalComponent *event=NULL ; 
     587  int event_index=0 ; 
     588  gchar *tmp_str=NULL, *tmp_str2=NULL ; 
     589  gboolean has_alarm=FALSE, is_todo=FALSE, is_event=FALSE ; 
    631590 
    632591  g_return_if_fail (a_this 
     
    643602  g_return_if_fail (event_index >= 0) ; 
    644603 
     604  /*does the comp has an alarm ?*/ 
     605  has_alarm = e_cal_component_has_alarms (event) ; 
     606 
     607  /*is the comp a todo item ? */ 
     608  is_todo = (e_cal_component_get_vtype (event) == E_CAL_COMPONENT_TODO); 
     609 
     610  /*is the comp a calendar event ?*/ 
     611  is_event = (e_cal_component_get_vtype (event) == E_CAL_COMPONENT_EVENT); 
     612 
     613  /*a comp must be either a calendar event or a todo item*/ 
     614  g_return_if_fail (is_event != is_todo) ; 
     615 
    645616  /*get the event summary*/ 
    646617  e_cal_component_get_summary (event, &text) ; 
    647618 
    648619  /*get the event starting date*/ 
    649   e_cal_component_get_dtstart (event, &start_date) ; 
    650   tmp_str = icaltime_to_pretty_string (start_date.value) ; 
    651   e_cal_component_free_datetime (&start_date) ; 
     620  if (is_event) 
     621    e_cal_component_get_dtstart (event, &date) ; 
     622  else if (is_todo) 
     623  { 
     624    e_cal_component_get_due (event, &date) ; 
     625  } 
     626 
     627  if (date.value) 
     628  { 
     629    tmp_str = icaltime_to_pretty_string (date.value) ; 
     630    e_cal_component_free_datetime (&date) ; 
     631  } 
    652632 
    653633  /*build event infoline*/ 
    654   tmp_str2 = g_strdup_printf ("%s %s", text.value, tmp_str) ; 
    655   g_free (tmp_str) ; 
     634  if (tmp_str) 
     635  { 
     636    tmp_str2 = g_strdup_printf ("%s %s", text.value, tmp_str) ; 
     637    g_free (tmp_str) ; 
     638  } 
     639  else 
     640  { 
     641    tmp_str2 = g_strdup_printf ("%s", text.value) ; 
     642  } 
    656643  label = gtk_label_new (tmp_str2) ; 
    657644  gtk_misc_set_alignment (GTK_MISC (label), 0, 0) ; 
     
    661648  gtk_widget_show (infoline) ; 
    662649  gtk_box_pack_start_defaults (GTK_BOX (infoline), label) ; 
     650  icon = gtk_image_new () ; 
     651  if (is_event) 
     652  { 
     653    gtk_image_set_from_stock (GTK_IMAGE (icon), 
     654                              "openmoko-today-event", 
     655                              GTK_ICON_SIZE_MENU); 
     656  } 
     657  else if (is_todo) 
     658  { 
     659    gtk_image_set_from_stock (GTK_IMAGE (icon), 
     660                              "openmoko-today-todo", 
     661                              GTK_ICON_SIZE_MENU); 
     662  } 
     663  else if (has_alarm) 
     664  { 
     665    gtk_image_set_from_stock (GTK_IMAGE (icon), 
     666                              "openmoko-today-bell", 
     667                              GTK_ICON_SIZE_MENU); 
     668  } 
     669  gtk_misc_set_alignment (GTK_MISC (icon), 0, 0); 
     670  gtk_widget_show_all (icon) ; 
     671  gtk_box_pack_start_defaults (GTK_BOX (infoline), icon) ; 
    663672  event_box = gtk_event_box_new () ; 
    664673  gtk_widget_show (event_box) ; 
  • trunk/src/target/OM-2007/applications/openmoko-today/src/today-main.c

    r1412 r1413  
    2626#include <glib.h> 
    2727#include <glib/gprintf.h> 
    28 #include <libecal/e-cal.h> 
    29 #include <libecal/e-cal-time-util.h> 
    3028#include <gtk/gtk.h> 
    3129#include <libmokoui/moko-window.h> 
    3230#include <libmokoui/moko-pixmap-button.h> 
    3331#include "today-events-area.h" 
     32#include "today-utils.h" 
    3433 
    3534#define LOG_ERROR \ 
     
    8281} 
    8382 
    84 /** 
    85  * e_cal_component_list_free: 
    86  * @list: the list ECalComooment to free 
    87  * 
    88  * Free a list of ECalComponent 
    89  */ 
    90 static void 
    91 e_cal_component_list_free (GList * list) 
    92 { 
    93   GList *cur = NULL; 
    94  
    95   for (cur = list; cur; cur = cur->next) 
    96   { 
    97     /*if an element of the list is not of type ECalComponent, leak it */ 
    98     if (cur->data && E_IS_CAL_COMPONENT (cur->data)) 
    99     { 
    100       g_object_unref (G_OBJECT (cur->data)); 
    101       cur->data = NULL; 
    102     } 
    103     else 
    104     { 
    105       g_warning ("cur->data is not of type ECalComponent !"); 
    106     } 
    107   } 
    108   g_list_free (list); 
    109 } 
    110  
    111 /** 
    112  * today_get_today_events: 
    113  * 
    114  * Return value:  a list of ECalComponents, of type VEVENT 
    115  * must be freed with e_cal_component_list_free() 
    116  */ 
    117 static GList * 
    118 today_get_today_events () 
    119 { 
    120   GList *result = NULL; 
    121   GList *ical_comps = NULL; 
    122   GList *ecal_comps = NULL; 
    123   GList *cur = NULL; 
    124   ECal *ecal = NULL; 
    125   GError *error = NULL; 
    126   gchar *query = NULL; 
    127  
    128   ecal = e_cal_new_system_calendar (); 
    129   g_return_val_if_fail (ecal, NULL); 
    130  
    131   if (!e_cal_open (ecal, FALSE, &error)) 
    132   { 
    133     g_warning ("failed to open the calendar"); 
    134   } 
    135  
    136   if (error) 
    137   { 
    138     LOG_ERROR; 
    139     goto out; 
    140   } 
    141  
    142   /* 
    143   query = g_strdup_printf ("(occur-in-time-range? " 
    144                                "(time-day-begin (time-now)) " 
    145                                "(time-day-end   (time-now)) " 
    146                            ")"); 
    147    */ 
    148   query = g_strdup_printf ("#t"); 
    149   e_cal_get_object_list (ecal, query, &ical_comps, &error); 
    150   if (error) 
    151   { 
    152     LOG_ERROR; 
    153     goto out; 
    154   } 
    155  
    156   /* 
    157    * build a list of ECalComponent, out of the list of icalcomponents 
    158    * when an icalcomponent is set to an ECalComponent, the later 
    159    * becomes responsible of freeing the former's memory 
    160    */ 
    161   for (cur = ical_comps; cur; cur = cur->next) 
    162   { 
    163     ECalComponent *c = NULL; 
    164     if (!cur->data) 
    165       continue; 
    166  
    167     c = e_cal_component_new (); 
    168     if (!e_cal_component_set_icalcomponent (c, cur->data)) 
    169     { 
    170       icalcomponent_free (cur->data); 
    171       cur->data = NULL; 
    172       continue; 
    173     } 
    174  
    175     ecal_comps = g_list_prepend (ecal_comps, c); 
    176     cur->data = NULL; 
    177   } 
    178   result = ecal_comps; 
    179   ecal_comps = NULL; 
    180  
    181 out: 
    182   if (ical_comps) 
    183   { 
    184     e_cal_free_object_list (ical_comps); 
    185   } 
    186  
    187   if (ecal_comps) 
    188   { 
    189     e_cal_component_list_free (ecal_comps); 
    190   } 
    191   ecal_comps = NULL; 
    192  
    193   /* 
    194    the calender must stay alive during the app's lifetime 
    195   if (ecal) 
    196   { 
    197     g_object_unref (G_OBJECT (ecal)); 
    198   } 
    199   */ 
    200  
    201   if (error) 
    202   { 
    203     g_error_free (error); 
    204   } 
    205  
    206   g_free (query); 
    207  
    208   return result; 
    209 } 
    210  
    211  
    21283/* information lines */ 
    21384 
     
    236107  gtk_image_set_from_stock (GTK_IMAGE (icon), stock_id, GTK_ICON_SIZE_MENU); 
    237108  gtk_misc_set_alignment (GTK_MISC (icon), 0, 0); 
     109  gtk_widget_show (icon) ; 
    238110  gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0); 
    239111 
     
    248120} 
    249121 
    250  
    251122/* launcher buttons */ 
    252123 
     
    254125 * callback for luncher buttons 
    255126 */ 
    256 static void 
     127void 
    257128today_launcher_clicked_cb (GtkWidget *button, gchar *command) 
    258129{ 
  • trunk/src/target/OM-2007/applications/openmoko-today/tests/Makefile.am

    r1346 r1413  
    55 
    66eventsareatest_SOURCES     = events-area-test.c \ 
    7 $(top_srcdir)/src/today-events-area.c 
     7$(top_srcdir)/src/today-events-area.c \ 
     8$(top_srcdir)/src/today-utils.c 
    89 
    910eventsareatest_LDADD       = @TODAY_LIBS@ 
  • trunk/src/target/OM-2007/applications/openmoko-today/tests/ecal-test.c

    r1341 r1413  
     1/* vi:set sw=2: */ 
    12/* 
    23 *  Today - At a glance view of date, time, calender events, todo items and 
     
    4647display_events (GList *a_events/*list of icalcomponents*/) 
    4748{ 
    48     GList          *cur         = NULL ; 
    49     ECalComponent  *cal_comp    = NULL ; 
    50     char           *event_str   = NULL ; 
     49  GList          *cur         = NULL ; 
     50  ECalComponent  *cal_comp    = NULL ; 
     51  char           *event_str   = NULL ; 
     52  char           *categories  = NULL ; 
    5153 
    52     if (!a_events) { 
    53         g_message ("No events") ; 
    54         return ; 
     54  if (!a_events) 
     55  { 
     56    g_message ("No events") ; 
     57    return ; 
     58  } 
     59  cal_comp = e_cal_component_new () ; 
     60  g_return_if_fail (cal_comp) ; 
     61 
     62  for (cur = a_events ; cur ; cur = cur->next) 
     63  { 
     64    if (!cur->data) {continue;} 
     65    e_cal_component_set_icalcomponent (cal_comp, cur->data) ; 
     66    if (e_cal_component_get_vtype (cal_comp) != E_CAL_COMPONENT_EVENT) 
     67    { 
     68      g_warning ("component is not an event, rather of type %d", 
     69          e_cal_component_get_vtype (cal_comp)); 
     70      continue ; 
    5571    } 
    56     cal_comp = e_cal_component_new () ; 
    57     g_return_if_fail (cal_comp) ; 
    58  
    59     for (cur = a_events ; cur ; cur = cur->next) { 
    60         if (!cur->data) {continue;} 
    61         e_cal_component_set_icalcomponent (cal_comp, cur->data) ; 
    62         if (e_cal_component_get_vtype (cal_comp) != E_CAL_COMPONENT_EVENT) { 
    63             g_warning ("component is not an event, rather of type %d", 
    64                        e_cal_component_get_vtype (cal_comp)); 
    65             continue ; 
    66         } 
    67         event_str = e_cal_component_get_as_string (cal_comp) ; 
    68         if (event_str) { 
    69             g_message ("Got event '%s'", event_str) ; 
    70             g_free (event_str) ; 
    71         } 
     72    event_str = e_cal_component_get_as_string (cal_comp) ; 
     73    if (event_str) 
     74    { 
     75      g_message ("Got event '%s'", event_str) ; 
     76      g_free (event_str) ; 
    7277    } 
     78    e_cal_component_get_categories (cal_comp, &categories) ; 
     79    if (categories) 
     80    { 
     81      g_message ("event's categs: '%s'\n", categories) ; 
     82      //g_free (categories) ; 
     83      categories = NULL ; 
     84    } 
     85    else 
     86    { 
     87      g_message ("no associated category") ; 
     88    } 
     89  } 
    7390} 
    7491 
     
    102119    if (ret) {goto out ;} 
    103120 
     121    /* 
    104122    query = g_strdup_printf ("(occur-in-time-range? " 
    105123                                 "(time-day-begin (time-now)) " 
    106124                                 "(time-day-end   (time-now))" 
    107125                             ")"); 
     126 
     127    */ 
     128    query = g_strdup_printf ("#t") ; 
    108129 
    109130    printf ("Issuing query: '%s'\n", query) ; 
     
    124145 
    125146out: 
     147    /* 
    126148    if (cal) { 
    127149        g_object_unref (G_OBJECT (cal)) ; 
    128150    } 
     151    */ 
    129152    if (objects) { 
    130         e_cal_free_object_list (objects) ; 
     153        g_list_free (objects) ; 
    131154    } 
    132155    if (query) { 
Note: See TracChangeset for help on using the changeset viewer.