From d21e6e4dc143f1b077da4d9c9375947e63321d7a Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 18 Oct 2001 19:50:29 +0000 Subject: Adds session management for the alarm daemon. Also makes it store a list 2001-10-18 Federico Mena Quintero Adds session management for the alarm daemon. Also makes it store a list of calendars to be monitored. Those calendars will all be loaded when the alarm daemon starts up. * idl/evolution-calendar.idl (AlarmNotify): Removed the ::die() method. The alarm daemon now handles termination via the session manager's commands. * gui/alarm-notify/notify-main.c (set_session_parameters): New function, sets some parameters so that the session manager can restart the daemon via the evolution-alarm-client program. Also, sets up the "die" signal so that the daemon can terminate when the session ends. (load_calendars): New function to load the calendars on startup. (main): Set the session parameters. Load the calendars on startup. * gui/alarm-notify/alarm-notify.c (alarm_notify_add_calendar): New function, moved over from the impl_ function. Added a load_afterwards argument to indicate whether the calendar should just be loaded or if it should also be added to the list of calendars to load on startup. (AlarmNotify_addCalendar): Use alarm_notify_add_calendar(). (AlarmNotify_removeCalendar): Remove the calendar from the list of calendars to load on startup. * gui/alarm-notify/save.c (save_calendars_to_load): New function, saves a sequence of the URIs to load. (get_calendars_to_load): New function, loads a sequence of calendars to load. * gui/alarm-notify/alarm.h: Removed stale prototype for alarm_init(). * gui/component-factory.c (remove_folder): Ask the alarm daemon to stop monitoring alarms for the folder that is being deleted. svn path=/trunk/; revision=13763 --- calendar/gui/alarm-notify/save.c | 144 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 3 deletions(-) (limited to 'calendar/gui/alarm-notify/save.c') diff --git a/calendar/gui/alarm-notify/save.c b/calendar/gui/alarm-notify/save.c index 3fb8dde818..b4a788e71e 100644 --- a/calendar/gui/alarm-notify/save.c +++ b/calendar/gui/alarm-notify/save.c @@ -23,13 +23,22 @@ #include #endif +#include #include #include #include +#include "evolution-calendar.h" #include "save.h" +/* Key names for the configuration values */ + +#define KEY_LAST_NOTIFICATION_TIME "/Calendar/AlarmNotify/LastNotificationTime" +#define KEY_CALENDARS_TO_LOAD "/Calendar/AlarmNotify/CalendarsToLoad" + + + /* Tries to get the config database object; returns CORBA_OBJECT_NIL on failure. */ static Bonobo_ConfigDatabase get_config_db (void) @@ -94,7 +103,7 @@ save_notification_time (time_t t) CORBA_exception_init (&ev); - bonobo_config_set_long (db, "/Calendar/AlarmNotify/LastNotificationTime", (long) t, &ev); + bonobo_config_set_long (db, KEY_LAST_NOTIFICATION_TIME, (long) t, &ev); if (BONOBO_EX (&ev)) g_message ("save_notification_time(): Could not save the value"); @@ -120,10 +129,139 @@ get_saved_notification_time (void) if (db == CORBA_OBJECT_NIL) return -1; - t = bonobo_config_get_long_with_default (db, "/Calendar/AlarmNotify/LastNotificationTime", - -1, NULL); + t = bonobo_config_get_long_with_default (db, KEY_LAST_NOTIFICATION_TIME, -1, NULL); discard_config_db (db); return (time_t) t; } + +/** + * save_calendars_to_load: + * @uris: A list of URIs of calendars. + * + * Saves the list of calendars that should be loaded the next time the alarm + * daemon starts up. + **/ +void +save_calendars_to_load (GPtrArray *uris) +{ + Bonobo_ConfigDatabase db; + int len, i; + GNOME_Evolution_Calendar_StringSeq *seq; + CORBA_Environment ev; + CORBA_any *any; + + g_return_if_fail (uris != NULL); + + db = get_config_db (); + if (db == CORBA_OBJECT_NIL) + return; + + /* Build the sequence of URIs */ + + len = uris->len; + + seq = GNOME_Evolution_Calendar_StringSeq__alloc (); + seq->_length = len; + seq->_buffer = CORBA_sequence_CORBA_string_allocbuf (len); + CORBA_sequence_set_release (seq, TRUE); + + for (i = 0; i < len; i++) { + char *uri; + + uri = uris->pdata[i]; + seq->_buffer[i] = CORBA_string_dup (uri); + } + + /* Save it */ + + any = bonobo_arg_new (TC_GNOME_Evolution_Calendar_StringSeq); +#if 0 + *((GNOME_Evolution_Calendar_StringSeq **) any->_value) = seq; +#else + any->_value = seq; +#endif + CORBA_exception_init (&ev); + + bonobo_config_set_value (db, KEY_CALENDARS_TO_LOAD, any, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) + g_message ("save_calendars_to_load(): Could not save the list of calendars"); + + CORBA_exception_free (&ev); + + discard_config_db (db); + bonobo_arg_release (any); /* this releases the sequence */ +} + +/** + * get_calendars_to_load: + * + * Gets the list of calendars that should be loaded when the alarm daemon starts + * up. + * + * Return value: A list of URIs, or NULL if the value could not be retrieved. + **/ +GPtrArray * +get_calendars_to_load (void) +{ + Bonobo_ConfigDatabase db; + GNOME_Evolution_Calendar_StringSeq *seq; + CORBA_Environment ev; + CORBA_any *any; + int len, i; + GPtrArray *uris; + + db = get_config_db (); + if (db == CORBA_OBJECT_NIL) + return NULL; + + /* Get the value */ + + CORBA_exception_init (&ev); + + any = bonobo_config_get_value (db, KEY_CALENDARS_TO_LOAD, + TC_GNOME_Evolution_Calendar_StringSeq, + &ev); + discard_config_db (db); + + if (ev._major == CORBA_USER_EXCEPTION) { + char *ex_id; + + ex_id = CORBA_exception_id (&ev); + + if (strcmp (ex_id, ex_Bonobo_ConfigDatabase_NotFound) == 0) { + CORBA_exception_free (&ev); + uris = g_ptr_array_new (); + g_ptr_array_set_size (uris, 0); + return uris; + } + } + + if (ev._major != CORBA_NO_EXCEPTION) { + g_message ("get_calendars_to_load(): Could not get the list of calendars"); + CORBA_exception_free (&ev); + return NULL; + } + + CORBA_exception_free (&ev); + + /* Decode the value */ +#if 0 + seq = *((GNOME_Evolution_Calendar_StringSeq **) any->_value); +#else + seq = any->_value; +#endif + len = seq->_length; + + uris = g_ptr_array_new (); + g_ptr_array_set_size (uris, len); + + for (i = 0; i < len; i++) + uris->pdata[i] = g_strdup (seq->_buffer[i]); + + bonobo_arg_release (any); + + return uris; +} -- cgit v1.2.3