diff options
-rw-r--r-- | calendar/ChangeLog | 22 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/config-data.c | 78 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/config-data.h | 5 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/notify-main.c | 17 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/save.c | 97 |
5 files changed, 124 insertions, 95 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 9e55d9b757..47a953f469 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,25 @@ +2003-12-01 Rodrigo Moya <rodrigo@ximian.com> + + * gui/alarm-notify/save.c (save_calendars_to_load): removed this + function, since we now use the ESourceList to know what calendars + to load. + (get_calendars_to_load): moved to config-data.c. + (save_notification_time, get_saved_notification_time, + save_blessed_program, is_blessed_program): use the + shared GConfClient. + + * gui/alarm-notify/config-data.[ch]: use a GConfClient instead of a + EConfigListener. + (config_data_get_conf_client): renamed from _get_listener. + (config_data_get_timezone, config_data_get_24_hour_format): changed + to use the GConfClient. + (config_data_get_calendars_to_load): new function. + (ensure_inited): create the source lists for calendar and tasks here. + (do_cleanup): cleanup the source lists here. + + * gui/alarm-notify/notify-main.c (load_calendars): use + config_data_get_calendars_to_load(). + 2003-11-28 JP Rosevear <jpr@ximian.com> * gui/e-tasks.c (e_tasks_delete_completed): we want to skip if it diff --git a/calendar/gui/alarm-notify/config-data.c b/calendar/gui/alarm-notify/config-data.c index 8737d0549f..23ec04826a 100644 --- a/calendar/gui/alarm-notify/config-data.c +++ b/calendar/gui/alarm-notify/config-data.c @@ -22,6 +22,7 @@ #include <config.h> #endif +#include <libedataserver/e-source-list.h> #include "config-data.h" #include "save.h" @@ -29,7 +30,8 @@ /* Whether we have initied ourselves by reading the data from the configuration engine */ static gboolean inited = FALSE; -static EConfigListener *config; +static GConfClient *conf_client = NULL; +static ESourceList *calendar_source_list = NULL, *tasks_source_list = NULL; @@ -49,8 +51,19 @@ locale_supports_12_hour_format (void) static void do_cleanup (void) { - g_object_unref (config); - config = NULL; + if (calendar_source_list) { + g_object_unref (calendar_source_list); + calendar_source_list = NULL; + } + + if (tasks_source_list) { + g_object_unref (tasks_source_list); + tasks_source_list = NULL; + } + + g_object_unref (conf_client); + conf_client = NULL; + inited = FALSE; } @@ -63,20 +76,27 @@ ensure_inited (void) inited = TRUE; - config = e_config_listener_new (); - if (!E_IS_CONFIG_LISTENER (config)) { + conf_client = gconf_client_get_default (); + if (!GCONF_IS_CLIENT (conf_client)) { inited = FALSE; return; } g_atexit ((GVoidFunc) do_cleanup); + + /* load the sources for calendars and tasks */ + calendar_source_list = e_source_list_new_for_gconf (conf_client, + "/apps/evolution/calendar/sources"); + tasks_source_list = e_source_list_new_for_gconf (conf_client, + "/apps/evolution/tasks/sources"); + } -EConfigListener * +GConfClient * config_data_get_listener (void) { ensure_inited (); - return config; + return conf_client; } icaltimezone * @@ -87,9 +107,9 @@ config_data_get_timezone (void) ensure_inited (); - location = e_config_listener_get_string_with_default (config, - "/apps/evolution/calendar/display/timezone", - "UTC", NULL); + location = gconf_client_get_string (conf_client, + "/apps/evolution/calendar/display/timezone", + NULL); if (location && location[0]) { local_timezone = icaltimezone_get_builtin_timezone (location); } else { @@ -107,10 +127,42 @@ config_data_get_24_hour_format (void) ensure_inited (); if (locale_supports_12_hour_format ()) { - return e_config_listener_get_boolean_with_default ( - config, - "/apps/evolution/calendar/display/use_24hour_format", FALSE, NULL); + return gconf_client_get_bool (conf_client, + "/apps/evolution/calendar/display/use_24hour_format", + NULL); } return TRUE; } + +GPtrArray * +config_data_get_calendars_to_load (void) +{ + GPtrArray *cals; + GSList *groups, *gl, *sources, *sl; + + ensure_inited (); + + /* create the array to be returned */ + cals = g_ptr_array_new (); + + /* process calendar sources */ + groups = e_source_list_peek_groups (calendar_source_list); + for (gl = groups; gl != NULL; gl = gl->next) { + sources = e_source_group_peek_sources (E_SOURCE_GROUP (gl->data)); + for (sl = sources; sl != NULL; sl = sl->next) { + g_ptr_array_add (cals, sl->data); + } + } + + /* process tasks sources */ + groups = e_source_list_peek_groups (tasks_source_list); + for (gl = groups; gl != NULL; gl = gl->next) { + sources = e_source_group_peek_sources (E_SOURCE_GROUP (gl->data)); + for (sl = sources; sl != NULL; sl = sl->next) { + g_ptr_array_add (cals, sl->data); + } + } + + return cals; +} diff --git a/calendar/gui/alarm-notify/config-data.h b/calendar/gui/alarm-notify/config-data.h index 28f5e2d4b1..26b5dc111f 100644 --- a/calendar/gui/alarm-notify/config-data.h +++ b/calendar/gui/alarm-notify/config-data.h @@ -23,11 +23,12 @@ #include <glib.h> #include <libical/ical.h> -#include <e-util/e-config-listener.h> +#include <gconf/gconf-client.h> -EConfigListener *config_data_get_listener (void); +GConfClient *config_data_get_conf_client (void); icaltimezone *config_data_get_timezone (void); gboolean config_data_get_24_hour_format (void); +GPtrArray *config_data_get_calendars_to_load (void); #endif diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c index f50118ba47..e70f01b44b 100644 --- a/calendar/gui/alarm-notify/notify-main.c +++ b/calendar/gui/alarm-notify/notify-main.c @@ -36,9 +36,11 @@ #include <bonobo/bonobo-main.h> #include <bonobo/bonobo-generic-factory.h> #include <bonobo-activation/bonobo-activation.h> +#include <libedataserver/e-source.h> #include "alarm.h" #include "alarm-queue.h" #include "alarm-notify.h" +#include "config-data.h" #include "save.h" @@ -108,7 +110,7 @@ alarm_notify_factory_fn (BonoboGenericFactory *factory, const char *component_id static gboolean load_calendars (gpointer user_data) { - GPtrArray *uris; + GPtrArray *cals; int i; alarm_queue_init (); @@ -119,23 +121,24 @@ load_calendars (gpointer user_data) g_assert (alarm_notify_service != NULL); } - uris = get_calendars_to_load (); - if (!uris) { + cals = config_data_get_calendars_to_load (); + if (!cals) { g_message ("load_calendars(): Could not get the list of calendars to load"); return TRUE; /* should we continue retrying? */; } - for (i = 0; i < uris->len; i++) { + for (i = 0; i < cals->len; i++) { + ESource *source; char *uri; - uri = uris->pdata[i]; + source = cals->pdata[i]; + uri = e_source_get_uri (source); alarm_notify_add_calendar (alarm_notify_service, uri, FALSE); - g_free (uri); } - g_ptr_array_free (uris, TRUE); + g_ptr_array_free (cals, TRUE); return FALSE; } diff --git a/calendar/gui/alarm-notify/save.c b/calendar/gui/alarm-notify/save.c index e03183ed5d..d0b127fb99 100644 --- a/calendar/gui/alarm-notify/save.c +++ b/calendar/gui/alarm-notify/save.c @@ -52,20 +52,19 @@ void save_notification_time (time_t t) { - EConfigListener *cl; + GConfClient *conf_client; time_t current_t; g_return_if_fail (t != -1); - if (!(cl = config_data_get_listener ())) + if (!(conf_client = config_data_get_conf_client ())) return; /* we only store the new notification time if it is bigger than the already stored one */ - current_t = e_config_listener_get_long_with_default (cl, KEY_LAST_NOTIFICATION_TIME, - -1, NULL); + current_t = gconf_client_get_int (conf_client, KEY_LAST_NOTIFICATION_TIME, NULL); if (t > current_t) - e_config_listener_set_long (cl, KEY_LAST_NOTIFICATION_TIME, (long) t); + gconf_client_set_int (conf_client, KEY_LAST_NOTIFICATION_TIME, t, NULL); } /** @@ -78,72 +77,18 @@ save_notification_time (time_t t) time_t get_saved_notification_time (void) { - EConfigListener *cl; + GConfClient *conf_client; long t; - if (!(cl = config_data_get_listener ())) + if (!(conf_client = config_data_get_conf_client ())) return -1; - t = e_config_listener_get_long_with_default (cl, KEY_LAST_NOTIFICATION_TIME, -1, NULL); + t = gconf_client_get_int (conf_client, KEY_LAST_NOTIFICATION_TIME, NULL); 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) -{ - int i; - GConfClient *gconf = gconf_client_get_default(); - GSList *l = NULL; - - g_return_if_fail (uris != NULL); - - for (i=0;i<uris->len;i++) - l = g_slist_append(l, uris->pdata[i]); - - gconf_client_set_list(gconf, KEY_CALENDARS, GCONF_VALUE_STRING, l, NULL); - - g_slist_free(l); -} - -/** - * 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) -{ - GSList *l, *n; - GPtrArray *uris; - - /* Getting the default value below is not necessarily an error, as we - * may not have saved the list of calendar yet. - */ - - l = gconf_client_get_list (gconf_client_get_default (), KEY_CALENDARS, GCONF_VALUE_STRING, NULL); - uris = g_ptr_array_new (); - while (l) { - n = l->next; - g_ptr_array_add (uris, l->data); - g_slist_free_1(l); - l = n; - } - - return uris; -} - -/** * save_blessed_program: * @program: a program name * @@ -152,14 +97,17 @@ get_calendars_to_load (void) void save_blessed_program (const char *program) { - GConfClient *gconf = gconf_client_get_default(); + GConfClient *conf_client; GSList *l; - l = gconf_client_get_list(gconf, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); - l = g_slist_append(l, g_strdup(program)); - gconf_client_set_list(gconf, KEY_PROGRAMS, GCONF_VALUE_STRING, l, NULL); - g_slist_foreach(l, (GFunc)g_free, NULL); - g_slist_free(l); + if (!(conf_client = config_data_get_conf_client ())) + return; + + l = gconf_client_get_list (conf_client, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); + l = g_slist_append (l, g_strdup (program)); + gconf_client_set_list (conf_client, KEY_PROGRAMS, GCONF_VALUE_STRING, l, NULL); + g_slist_foreach (l, (GFunc) g_free, NULL); + g_slist_free (l); } /** @@ -173,17 +121,20 @@ save_blessed_program (const char *program) gboolean is_blessed_program (const char *program) { - GConfClient *gconf = gconf_client_get_default(); + GConfClient *conf_client; GSList *l, *n; gboolean found = FALSE; - l = gconf_client_get_list(gconf, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); + if (!(conf_client = config_data_get_conf_client ())) + return FALSE; + + l = gconf_client_get_list (conf_client, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); while (l) { n = l->next; if (!found) - found = strcmp((char *)l->data, program) == 0; - g_free(l->data); - g_slist_free_1(l); + found = strcmp ((char *) l->data, program) == 0; + g_free (l->data); + g_slist_free_1 (l); l = n; } |