Changeset 1413
- Timestamp:
- 03/19/07 23:26:32 (6 years ago)
- Location:
- trunk/src/target/OM-2007/applications/openmoko-today
- Files:
-
- 2 added
- 6 edited
-
ChangeLog (modified) (1 diff)
-
src/Makefile.am (modified) (1 diff)
-
src/today-events-area.c (modified) (4 diffs)
-
src/today-main.c (modified) (5 diffs)
-
src/today-utils.c (added)
-
src/today-utils.h (added)
-
tests/Makefile.am (modified) (1 diff)
-
tests/ecal-test.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/OM-2007/applications/openmoko-today/ChangeLog
r1412 r1413 1 Mon, 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 1 12 Mon, 19 Mar 2007 15:29:03 +0000 Thomas Wood 2 13 -
trunk/src/target/OM-2007/applications/openmoko-today/src/Makefile.am
r1346 r1413 9 9 bin_PROGRAMS = today 10 10 11 today_SOURCES = today-main.c today-events-area.h today-events-area.c 11 today_SOURCES = today-main.c \ 12 today-events-area.h today-events-area.c \ 13 today-utils.h today-utils.c 12 14 13 15 today_LDADD = @TODAY_LIBS@ -
trunk/src/target/OM-2007/applications/openmoko-today/src/today-events-area.c
r1380 r1413 29 29 #include <gtk/gtkhbox.h> 30 30 #include <gtk/gtktable.h> 31 #include <gtk/gtkimage.h> 31 32 #include <gtk/gtkeventbox.h> 32 33 #include <gtk/gtklabel.h> … … 576 577 } 577 578 578 /*579 * if the timetype is today, then only display it's hour part,580 * without the seconds581 * If it's not today, then only display it's date part, without the year582 */583 static gchar*584 icaltime_to_pretty_string (const icaltimetype *timetype)585 {586 #define TMP_STR_LEN 10587 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 else602 {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 619 579 static void 620 580 render_event (TodayEventsArea *a_this, 621 581 GList *a_event) 622 582 { 623 GtkWidget *infoline ; 624 GtkWidget *label ; 625 GtkWidget *event_box ; 583 GtkWidget *infoline, *label, *event_box, *icon ; 626 584 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 ; 631 590 632 591 g_return_if_fail (a_this … … 643 602 g_return_if_fail (event_index >= 0) ; 644 603 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 645 616 /*get the event summary*/ 646 617 e_cal_component_get_summary (event, &text) ; 647 618 648 619 /*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 } 652 632 653 633 /*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 } 656 643 label = gtk_label_new (tmp_str2) ; 657 644 gtk_misc_set_alignment (GTK_MISC (label), 0, 0) ; … … 661 648 gtk_widget_show (infoline) ; 662 649 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) ; 663 672 event_box = gtk_event_box_new () ; 664 673 gtk_widget_show (event_box) ; -
trunk/src/target/OM-2007/applications/openmoko-today/src/today-main.c
r1412 r1413 26 26 #include <glib.h> 27 27 #include <glib/gprintf.h> 28 #include <libecal/e-cal.h>29 #include <libecal/e-cal-time-util.h>30 28 #include <gtk/gtk.h> 31 29 #include <libmokoui/moko-window.h> 32 30 #include <libmokoui/moko-pixmap-button.h> 33 31 #include "today-events-area.h" 32 #include "today-utils.h" 34 33 35 34 #define LOG_ERROR \ … … 82 81 } 83 82 84 /**85 * e_cal_component_list_free:86 * @list: the list ECalComooment to free87 *88 * Free a list of ECalComponent89 */90 static void91 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 else104 {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 VEVENT115 * 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 icalcomponents158 * when an icalcomponent is set to an ECalComponent, the later159 * becomes responsible of freeing the former's memory160 */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 lifetime195 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 212 83 /* information lines */ 213 84 … … 236 107 gtk_image_set_from_stock (GTK_IMAGE (icon), stock_id, GTK_ICON_SIZE_MENU); 237 108 gtk_misc_set_alignment (GTK_MISC (icon), 0, 0); 109 gtk_widget_show (icon) ; 238 110 gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0); 239 111 … … 248 120 } 249 121 250 251 122 /* launcher buttons */ 252 123 … … 254 125 * callback for luncher buttons 255 126 */ 256 staticvoid127 void 257 128 today_launcher_clicked_cb (GtkWidget *button, gchar *command) 258 129 { -
trunk/src/target/OM-2007/applications/openmoko-today/tests/Makefile.am
r1346 r1413 5 5 6 6 eventsareatest_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 8 9 9 10 eventsareatest_LDADD = @TODAY_LIBS@ -
trunk/src/target/OM-2007/applications/openmoko-today/tests/ecal-test.c
r1341 r1413 1 /* vi:set sw=2: */ 1 2 /* 2 3 * Today - At a glance view of date, time, calender events, todo items and … … 46 47 display_events (GList *a_events/*list of icalcomponents*/) 47 48 { 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 ; 51 53 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 ; 55 71 } 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) ; 72 77 } 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 } 73 90 } 74 91 … … 102 119 if (ret) {goto out ;} 103 120 121 /* 104 122 query = g_strdup_printf ("(occur-in-time-range? " 105 123 "(time-day-begin (time-now)) " 106 124 "(time-day-end (time-now))" 107 125 ")"); 126 127 */ 128 query = g_strdup_printf ("#t") ; 108 129 109 130 printf ("Issuing query: '%s'\n", query) ; … … 124 145 125 146 out: 147 /* 126 148 if (cal) { 127 149 g_object_unref (G_OBJECT (cal)) ; 128 150 } 151 */ 129 152 if (objects) { 130 e_cal_free_object_list(objects) ;153 g_list_free (objects) ; 131 154 } 132 155 if (query) {
Note: See TracChangeset
for help on using the changeset viewer.
