From 46c9ba67664e8d8e52d7b6d0841d17d8d779ea64 Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Fri, 22 Dec 2000 00:10:58 +0000 Subject: Working Calendar summary. Smile. svn path=/trunk/; revision=7123 --- calendar/ChangeLog | 8 + calendar/gui/GNOME_Evolution_Calendar.oaf.in | 8 +- calendar/gui/GNOME_Evolution_Calendar.oafinfo | 8 +- calendar/gui/Makefile.am | 4 + calendar/gui/calendar-component.c | 30 +-- calendar/gui/calendar-summary.c | 299 +++++++++++++++++++++----- calendar/gui/calendar-summary.h | 8 +- calendar/gui/component-factory.c | 30 +-- calendar/gui/event-editor-dialog.glade.h | 66 +++--- 9 files changed, 315 insertions(+), 146 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 2cf614c5c0..994d22fa2d 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,11 @@ +2000-12-21 Iain Holmes + + * gui/calendar-summary.c: Updated for new executive summary. + + * gui/component-factory.c: Reenabled the summary. + + * gui/GNOME_Evolution_Calendar.oafinfo: Added the summary. + 2000-12-20 JP Rosevear * conduits/todo/todo-conduit.h: Fix erroneous documentation diff --git a/calendar/gui/GNOME_Evolution_Calendar.oaf.in b/calendar/gui/GNOME_Evolution_Calendar.oaf.in index c587055282..75aa4a6b0f 100644 --- a/calendar/gui/GNOME_Evolution_Calendar.oaf.in +++ b/calendar/gui/GNOME_Evolution_Calendar.oaf.in @@ -62,7 +62,7 @@ value="evolution-calendar.png"/> - @@ -74,12 +74,12 @@ value="Factory for the Calendar Summary component."/> - + location="OAFIID:GNOME_Evolution_Calendar_Summary_ComponentFactory"> - + - @@ -74,12 +74,12 @@ value="Factory for the Calendar Summary component."/> - + location="OAFIID:GNOME_Evolution_Calendar_Summary_ComponentFactory"> - + #include #include "evolution-shell-component.h" -#ifdef WANT_THE_EXECUTIVE_SUMMARY #include -#endif #include "component-factory.h" #include "control-factory.h" #include "calendar-config.h" -#if WANT_THE_EXECUTIVE_SUMMARY #include "calendar-summary.h" -#endif #define COMPONENT_FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_ShellComponentFactory" -#define SUMMARY_FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_ExecutiveSummaryComponentFactory" static BonoboGenericFactory *factory = NULL; -#ifdef WANT_THE_EXECUTIVE_SUMMARY static BonoboGenericFactory *summary_factory = NULL; -#endif char *evolution_dir; static const EvolutionShellComponentFolderType folder_types[] = { @@ -81,6 +74,7 @@ owner_set_cb (EvolutionShellComponent *shell_component, gpointer user_data) { evolution_dir = g_strdup (evolution_homedir); + g_print ("evolution_dir: %s\n", evolution_dir); calendar_config_init (); owner_count ++; } @@ -113,21 +107,6 @@ factory_fn (BonoboGenericFactory *factory, return BONOBO_OBJECT (shell_component); } -#ifdef WANT_THE_EXECUTIVE_SUMMARY -static BonoboObject * -summary_fn (BonoboGenericFactory *factory, - void *closure) -{ - ExecutiveSummaryComponent *summary_component; - - summary_component = executive_summary_component_new (NULL, - create_summary_view, - NULL, - evolution_dir); - return BONOBO_OBJECT (summary_component); -} -#endif - void component_factory_init (void) @@ -137,14 +116,11 @@ component_factory_init (void) factory = bonobo_generic_factory_new (COMPONENT_FACTORY_ID, factory_fn, NULL); -#ifdef WANT_THE_EXECUTIVE_SUMMARY - summary_factory = bonobo_generic_factory_new (SUMMARY_FACTORY_ID, summary_fn, NULL); -#endif + summary_factory = calendar_summary_factory_init (); + if (factory == NULL) g_error ("Cannot initialize Evolution's calendar component."); -#ifdef WANT_THE_EXECUTIVE_SUMMARY if (summary_factory == NULL) g_error ("Cannot initialize Evolution's calendar summary component."); -#endif } diff --git a/calendar/gui/calendar-summary.c b/calendar/gui/calendar-summary.c index 0c05ace30a..3544fbbc38 100644 --- a/calendar/gui/calendar-summary.c +++ b/calendar/gui/calendar-summary.c @@ -25,34 +25,73 @@ #include #endif +#include + #include #include +#include + +#include +#include -#include #include "cal-util/cal-component.h" +#include "cal-util/timeutil.h" #include "calendar-model.h" #include "calendar-summary.h" typedef struct { ExecutiveSummaryComponent *component; + ExecutiveSummaryHtmlView *view; CalClient *client; + gboolean cal_loaded; + + char *title; + char *icon; + + guint32 idle; } CalSummary; -static char * +enum { + PROPERTY_TITLE, + PROPERTY_ICON +}; + +extern gchar *evolution_dir; + +static int running_views = 0; +static BonoboGenericFactory *factory; +#define CALENDAR_SUMMARY_ID "OAFIID:GNOME_Evolution_Calendar_Summary_ComponentFactory" + +static gboolean generate_html_summary (CalSummary *summary) { + time_t t, day_begin, day_end; + struct tm *timeptr; GList *uids, *l; - char *ret_html, *tmp; - - ret_html = g_strdup ("
    "); + char *ret_html, *tmp, *datestr; - uids = cal_client_get_uids (summary->client, CALOBJ_TYPE_ANY); + t = time (NULL); + day_begin = time_day_begin (t); + day_end = time_day_end (t); + + datestr = g_new (char, 256); + timeptr = localtime (&t); + strftime (datestr, 255, _("%A, %e %B %Y"), timeptr); + ret_html = g_strdup_printf ("%s
      ", datestr); + g_free (datestr); + + uids = cal_client_get_objects_in_range (summary->client, + CALOBJ_TYPE_EVENT, day_begin, + day_end); for (l = uids; l; l = l->next){ CalComponent *comp; CalComponentText text; CalClientGetStatus status; + CalComponentDateTime start, end; + struct icaltimetype *start_time, *end_time; + char *start_str, *end_str; char *uid; char *tmp2; @@ -62,9 +101,24 @@ generate_html_summary (CalSummary *summary) continue; cal_component_get_summary (comp, &text); - - tmp2 = g_strdup_printf ("
    • %s
    • ", text.value); - + cal_component_get_dtstart (comp, &start); + cal_component_get_dtend (comp, &end); + + g_print ("text.value: %s\n", text.value); + start_time = start.value; + end_time = end.value; + + start_str = g_strdup_printf ("%d.%d", start_time->hour, start_time->minute); + if (end_time) { + end_str = g_strdup_printf ("%d.%d", end_time->hour, end_time->minute); + } else { + end_str = g_strdup (" "); + } + + tmp2 = g_strdup_printf ("
    • %s:%s -> %s
    • ", text.value, start_str, end_str); + g_free (start_str); + g_free (end_str); + tmp = ret_html; ret_html = g_strconcat (ret_html, tmp2, NULL); g_free (tmp); @@ -77,59 +131,204 @@ generate_html_summary (CalSummary *summary) ret_html = g_strconcat (ret_html, "
    ", NULL); g_free (tmp); - return ret_html; + executive_summary_html_view_set_html (summary->view, ret_html); + g_free (ret_html); + + summary->idle = 0; + return FALSE; } static void -cal_loaded (CalClient *client, - CalClientLoadStatus status, - CalSummary *summary) +get_property (BonoboPropertyBag *bag, + BonoboArg *arg, + guint arg_id, + gpointer data) { - char *html; - - if (status == CAL_CLIENT_LOAD_SUCCESS) { - html = generate_html_summary (summary); - executive_summary_component_update (summary->component, html); - g_free (html); - } else { - g_print ("Error loading %d\n", status); - executive_summary_component_update (summary->component, " "); + CalSummary *summary = (CalSummary *) data; + + switch (arg_id) { + case PROPERTY_TITLE: + BONOBO_ARG_SET_STRING (arg, summary->title); + break; + + case PROPERTY_ICON: + BONOBO_ARG_SET_STRING (arg, summary->icon); + break; + + default: + break; + } +} + +static void +component_destroyed (GtkObject *object, + gpointer data) +{ + CalSummary *summary = (CalSummary *) data; + + g_free (summary->title); + g_free (summary->icon); + gtk_object_destroy (GTK_OBJECT (summary->client)); + + g_free (summary); + + running_views--; + + if (running_views <= 0) { + bonobo_object_unref (BONOBO_OBJECT (factory)); + } +} + +static void +obj_updated_cb (CalClient *client, + const char *uid, + CalSummary *summary) +{ + /* FIXME: Maybe cache the uid's in the summary and only call this if + uid is in this cache??? */ + + if (summary->idle != 0) + return; + + summary->idle = g_idle_add (generate_html_summary, summary); +} + +static void +obj_removed_cb (CalClient *client, + const char *uid, + CalSummary *summary) +{ + /* See FIXME: above */ + if (summary->idle != 0) + return; + + summary->idle = g_idle_add (generate_html_summary, summary); +} +static void +cal_loaded_cb (CalClient *client, + CalClientLoadStatus status, + CalSummary *summary) +{ + switch (status) { + case CAL_CLIENT_LOAD_SUCCESS: + summary->cal_loaded = TRUE; + + if (summary->idle != 0) + return; + + summary->idle = g_idle_add (generate_html_summary, summary); + break; + + case CAL_CLIENT_LOAD_ERROR: + executive_summary_html_view_set_html (summary->view, + _("Error loading calendar")); + break; + + case CAL_CLIENT_LOAD_IN_USE: + executive_summary_html_view_set_html (summary->view, + _("Error loading calendar:
    Calendar in use.")); + + break; + + case CAL_CLIENT_LOAD_METHOD_NOT_SUPPORTED: + executive_summary_html_view_set_html (summary->view, + _("Error loading calendar:
    Method not supported")); + break; + + default: + break; } } -char * -create_summary_view (ExecutiveSummaryComponent *component, - char **title, - char **icon, +BonoboObject * +create_summary_view (ExecutiveSummaryComponentFactory *_factory, void *closure) { - char *ret_html; - char *evoldir; - char *calfile; + BonoboObject *component, *view; + BonoboPersistStream *stream; + BonoboPropertyBag *bag; CalSummary *summary; - gboolean result; - - evoldir = (char *) closure; - - /* strdup the title and icon */ - *title = g_strdup ("Things to do"); - *icon = g_strdup ("evolution-tasks.png"); - + char *html, *file; + + file = g_concat_dir_and_file (evolution_dir, "local/Calendar/calendar.ics"); + + /* Create the component object */ + component = executive_summary_component_new (); + summary = g_new (CalSummary, 1); summary->component = component; - - calfile = g_strdup_printf ("%s/local/Calendar/calendar.ics", evoldir); - g_print ("calfile: %s\n", calfile); + summary->icon = g_strdup ("evolution-calendar.png"); + summary->title = g_strdup ("Things to do"); summary->client = cal_client_new (); - - result = cal_client_load_calendar (summary->client, calfile); - if (!result) { - g_warning ("%s: Could not load %s", __FUNCTION__, calfile); - return ""; + summary->cal_loaded = FALSE; + summary->idle = 0; + + /* Check for calendar files */ + if (!g_file_exists (file)) { + cal_client_create_calendar (summary->client, file); } - - gtk_signal_connect (GTK_OBJECT (summary->client), "cal_loaded", - GTK_SIGNAL_FUNC (cal_loaded), summary); - - return g_strdup (" "); + + /* Load calendar */ + cal_client_load_calendar (summary->client, file); + g_free (file); + + gtk_signal_connect (GTK_OBJECT (summary->client), "cal-loaded", + GTK_SIGNAL_FUNC (cal_loaded_cb), summary); + gtk_signal_connect (GTK_OBJECT (summary->client), "obj-updated", + GTK_SIGNAL_FUNC (obj_updated_cb), summary); + gtk_signal_connect (GTK_OBJECT (summary->client), "obj-removed", + GTK_SIGNAL_FUNC (obj_removed_cb), summary); + + gtk_signal_connect (GTK_OBJECT (component), "destroy", + GTK_SIGNAL_FUNC (component_destroyed), summary); + + /* HTML view */ + view = executive_summary_html_view_new (); + summary->view = view; + + executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (view), + _("Loading Calendar")); + bonobo_object_add_interface (component, view); + + /* BonoboPropertyBag */ + bag = bonobo_property_bag_new (get_property, NULL, summary); + bonobo_property_bag_add (bag, "window_title", PROPERTY_TITLE, + BONOBO_ARG_STRING, NULL, + "The title of this component's window", 0); + bonobo_property_bag_add (bag, "window_icon", PROPERTY_ICON, + BONOBO_ARG_STRING, NULL, + "The icon for this component's window", 0); + bonobo_object_add_interface (component, BONOBO_OBJECT (bag)); + + running_views++; + + return component; +} + +static BonoboObject * +factory_fn (BonoboGenericFactory *generic_factory, + void *closure) +{ + BonoboObject *_factory; + + _factory = executive_summary_component_factory_new (create_summary_view, + NULL); + return _factory; +} + +BonoboGenericFactory * +calendar_summary_factory_init (void) +{ + if (factory != NULL) + return factory; + + factory = bonobo_generic_factory_new (CALENDAR_SUMMARY_ID, factory_fn, + NULL); + + if (factory == NULL) { + g_warning ("Cannot initialise calendar summary factory"); + return NULL; + } + + return factory; } diff --git a/calendar/gui/calendar-summary.h b/calendar/gui/calendar-summary.h index 8e21262db3..259fe355de 100644 --- a/calendar/gui/calendar-summary.h +++ b/calendar/gui/calendar-summary.h @@ -24,9 +24,9 @@ #ifndef CALENDAR_SUMMARY_H #define CALENDAR_SUMMARY_H -char * create_summary_view (ExecutiveSummaryComponent *component, - char **title, - char **icon, - void *closure); +#include + +BonoboObject *create_summary_view (ExecutiveSummaryComponentFactory *_factory, + void *closure); #endif diff --git a/calendar/gui/component-factory.c b/calendar/gui/component-factory.c index f0de87fddc..dd1b6edb3a 100644 --- a/calendar/gui/component-factory.c +++ b/calendar/gui/component-factory.c @@ -24,24 +24,17 @@ #include #include #include "evolution-shell-component.h" -#ifdef WANT_THE_EXECUTIVE_SUMMARY #include -#endif #include "component-factory.h" #include "control-factory.h" #include "calendar-config.h" -#if WANT_THE_EXECUTIVE_SUMMARY #include "calendar-summary.h" -#endif #define COMPONENT_FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_ShellComponentFactory" -#define SUMMARY_FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_ExecutiveSummaryComponentFactory" static BonoboGenericFactory *factory = NULL; -#ifdef WANT_THE_EXECUTIVE_SUMMARY static BonoboGenericFactory *summary_factory = NULL; -#endif char *evolution_dir; static const EvolutionShellComponentFolderType folder_types[] = { @@ -81,6 +74,7 @@ owner_set_cb (EvolutionShellComponent *shell_component, gpointer user_data) { evolution_dir = g_strdup (evolution_homedir); + g_print ("evolution_dir: %s\n", evolution_dir); calendar_config_init (); owner_count ++; } @@ -113,21 +107,6 @@ factory_fn (BonoboGenericFactory *factory, return BONOBO_OBJECT (shell_component); } -#ifdef WANT_THE_EXECUTIVE_SUMMARY -static BonoboObject * -summary_fn (BonoboGenericFactory *factory, - void *closure) -{ - ExecutiveSummaryComponent *summary_component; - - summary_component = executive_summary_component_new (NULL, - create_summary_view, - NULL, - evolution_dir); - return BONOBO_OBJECT (summary_component); -} -#endif - void component_factory_init (void) @@ -137,14 +116,11 @@ component_factory_init (void) factory = bonobo_generic_factory_new (COMPONENT_FACTORY_ID, factory_fn, NULL); -#ifdef WANT_THE_EXECUTIVE_SUMMARY - summary_factory = bonobo_generic_factory_new (SUMMARY_FACTORY_ID, summary_fn, NULL); -#endif + summary_factory = calendar_summary_factory_init (); + if (factory == NULL) g_error ("Cannot initialize Evolution's calendar component."); -#ifdef WANT_THE_EXECUTIVE_SUMMARY if (summary_factory == NULL) g_error ("Cannot initialize Evolution's calendar summary component."); -#endif } diff --git a/calendar/gui/event-editor-dialog.glade.h b/calendar/gui/event-editor-dialog.glade.h index fc0accb4a4..015c62c534 100644 --- a/calendar/gui/event-editor-dialog.glade.h +++ b/calendar/gui/event-editor-dialog.glade.h @@ -1,50 +1,55 @@ /* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. + * Translatable strings file generated by extract-ui. + * Add this file to your project's POTFILES.in * DO NOT compile it as part of your application. */ -gchar *s = N_("event-editor-dialog"); -gchar *s = N_("Su_mmary:"); -gchar *s = N_("Time"); -gchar *s = N_("_Start time:"); -gchar *s = N_("_End time:"); gchar *s = N_("A_ll day event"); +gchar *s = N_("Add"); +gchar *s = N_("Appointment Basics"); gchar *s = N_("Classification"); -gchar *s = N_("Pu_blic"); +gchar *s = N_("Custom recurrence"); +gchar *s = N_("Delete"); +gchar *s = N_("Every"); +gchar *s = N_("Exceptions"); +gchar *s = N_("General"); +gchar *s = N_("Mail _to:"); +gchar *s = N_("Modify"); +gchar *s = N_("No recurrence"); gchar *s = N_("Pri_vate"); +gchar *s = N_("Pu_blic"); +gchar *s = N_("Recur on the"); +gchar *s = N_("Recurrence"); +gchar *s = N_("Recurrence Rule"); +gchar *s = N_("Reminder"); +gchar *s = N_("Simple recurrence"); +gchar *s = N_("Su_mmary:"); +gchar *s = N_("This appointment has custom recurrence rules that cannot be edited by Evolution."); + ""); + "However, the appointment will recur at the appropriate time and will be displayed properly in the calendar views."); +gchar *s = N_("Time"); +gchar *s = N_("_Audio"); gchar *s = N_("_Confidential"); -gchar *s = N_("General"); -gchar *s = N_("Minutes"); -gchar *s = N_("Hours"); -gchar *s = N_("Days"); -gchar *s = N_("Minutes"); -gchar *s = N_("Hours"); -gchar *s = N_("Days"); -gchar *s = N_("Minutes"); -gchar *s = N_("Hours"); -gchar *s = N_("Days"); -gchar *s = N_("Minutes"); -gchar *s = N_("Hours"); -gchar *s = N_("Days"); gchar *s = N_("_Display"); -gchar *s = N_("_Program"); +gchar *s = N_("_End time:"); gchar *s = N_("_Mail"); -gchar *s = N_("Mail _to:"); +gchar *s = N_("_Program"); gchar *s = N_("_Run program:"); +<<<<<<< event-editor-dialog.glade.h +gchar *s = N_("_Start time:"); +======= gchar *s = N_("_Audio"); gchar *s = N_("Reminder"); gchar *s = N_("Appointment Basics"); gchar *s = N_("Su_mmary:"); +>>>>>>> 1.9 gchar *s = N_("_Starting date:"); -gchar *s = N_("Recurrence Rule"); -gchar *s = N_("No recurrence"); -gchar *s = N_("Simple recurrence"); -gchar *s = N_("Custom recurrence"); -gchar *s = N_("Every"); -gchar *s = N_("day(s)"); -gchar *s = N_("week(s)"); +gchar *s = N_("event-editor-dialog"); +gchar *s = N_("label21"); gchar *s = N_("month(s)"); +<<<<<<< event-editor-dialog.glade.h +gchar *s = N_("th day of the month"); +======= gchar *s = N_("year(s)"); gchar *s = N_("for"); gchar *s = N_("until"); @@ -56,3 +61,4 @@ gchar *s = N_("Delete"); gchar *s = N_("label21"); gchar *s = N_("Preview"); gchar *s = N_("Recurrence"); +>>>>>>> 1.11 -- cgit