aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2002-08-26 23:56:05 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2002-08-26 23:56:05 +0800
commit4e8966108728859537ec045decb368251bf078dc (patch)
tree17066ea78b122d70ec7deb6594cd33d828c0d18b
parentf95a4634519d4e41c4d1f29ab4f6cf0503a37995 (diff)
downloadgsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.tar
gsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.tar.gz
gsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.tar.bz2
gsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.tar.lz
gsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.tar.xz
gsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.tar.zst
gsoc2013-evolution-4e8966108728859537ec045decb368251bf078dc.zip
Fixes #12326
2002-08-26 Rodrigo Moya <rodrigo@ximian.com> Fixes #12326 * gui/alarm-notify/config-data.c (ensure_inited): create a EConfigListener for configuration access. (do_cleanup): g_atexit installed function, to clean up configuration database resources. (config_data_get_timezone): retrieve the configuration for the EConfigListener object. (config_data_get_listener): new function. * gui/alarm-notify/save.c (get_config_db, discard_config_db): removed. Use EConfigListener instead. (save_notification_time, get_saved_notification_time, save_calendars_to_load, get_calendars_to_load, save_blessed_program, is_blessed_program): use EConfigListener. * gui/alarm-notify/notify-main.c (init_alarm_notify_service): removed. (alarm_notify_factory_fn): create here the alarm_notify_service if it hasn't been created yet. (load_calendars): likewise. (main): don't call init_alarm_notify_service. svn path=/trunk/; revision=17859
-rw-r--r--calendar/ChangeLog24
-rw-r--r--calendar/gui/alarm-notify/config-data.c80
-rw-r--r--calendar/gui/alarm-notify/config-data.h4
-rw-r--r--calendar/gui/alarm-notify/notify-main.c30
-rw-r--r--calendar/gui/alarm-notify/save.c126
5 files changed, 107 insertions, 157 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index ce949deca9..b0d45afc6d 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,27 @@
+2002-08-26 Rodrigo Moya <rodrigo@ximian.com>
+
+ Fixes #12326
+
+ * gui/alarm-notify/config-data.c (ensure_inited): create a
+ EConfigListener for configuration access.
+ (do_cleanup): g_atexit installed function, to clean up configuration
+ database resources.
+ (config_data_get_timezone): retrieve the configuration for the
+ EConfigListener object.
+ (config_data_get_listener): new function.
+
+ * gui/alarm-notify/save.c (get_config_db, discard_config_db): removed.
+ Use EConfigListener instead.
+ (save_notification_time, get_saved_notification_time,
+ save_calendars_to_load, get_calendars_to_load, save_blessed_program,
+ is_blessed_program): use EConfigListener.
+
+ * gui/alarm-notify/notify-main.c (init_alarm_notify_service): removed.
+ (alarm_notify_factory_fn): create here the alarm_notify_service if it
+ hasn't been created yet.
+ (load_calendars): likewise.
+ (main): don't call init_alarm_notify_service.
+
2002-08-22 JP Rosevear <jpr@ximian.com>
* gui/e-meeting-model.c (process_section): if its a
diff --git a/calendar/gui/alarm-notify/config-data.c b/calendar/gui/alarm-notify/config-data.c
index 71170a3ad6..0e2846308f 100644
--- a/calendar/gui/alarm-notify/config-data.c
+++ b/calendar/gui/alarm-notify/config-data.c
@@ -28,11 +28,8 @@
/* Whether we have initied ourselves by reading the data from the configuration engine */
-static gboolean inited;
-
-/* Configuration values */
-static icaltimezone *local_timezone;
-static gboolean use_24_hour_format;
+static gboolean inited = FALSE;
+static EConfigListener *config;
@@ -41,7 +38,7 @@ static gboolean use_24_hour_format;
*/
static gboolean
locale_supports_12_hour_format (void)
-{
+{
char s[16];
time_t t = 0;
@@ -49,57 +46,58 @@ locale_supports_12_hour_format (void)
return s[0] != '\0';
}
+static void
+do_cleanup (void)
+{
+ gtk_object_unref (GTK_OBJECT (config));
+ config = NULL;
+ inited = FALSE;
+}
+
/* Ensures that the configuration values have been read */
static void
ensure_inited (void)
{
- Bonobo_ConfigDatabase db;
- char *location;
-
if (inited)
return;
inited = TRUE;
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL) {
- /* This sucks */
- local_timezone = icaltimezone_get_utc_timezone ();
-
- /* This sucks as well */
- use_24_hour_format = TRUE;
-
+ config = e_config_listener_new ();
+ if (!E_IS_CONFIG_LISTENER (config)) {
+ inited = FALSE;
return;
}
- location = bonobo_config_get_string_with_default (db,
- "/Calendar/Display/Timezone", "UTC", NULL);
- if (location && location[0]) {
- local_timezone = icaltimezone_get_builtin_timezone (location);
- } else {
- local_timezone = icaltimezone_get_utc_timezone ();
- }
- g_free (location);
-
- if (locale_supports_12_hour_format ()) {
- /* Wasn't the whole point of a configuration engine *NOT* to
- * have apps specify their own stupid defaults everywhere, but
- * just in a schema file?
- */
- use_24_hour_format = bonobo_config_get_boolean_with_default (
- db,
- "/Calendar/Display/Use24HourFormat", FALSE, NULL);
- } else
- use_24_hour_format = TRUE;
+ g_atexit ((GVoidFunc) do_cleanup);
+}
- discard_config_db (db);
+EConfigListener *
+config_data_get_listener (void)
+{
+ ensure_inited ();
+ return config;
}
icaltimezone *
config_data_get_timezone (void)
{
+ char *location;
+ icaltimezone *local_timezone;
+
ensure_inited ();
+ location = e_config_listener_get_string_with_default (config,
+ "/Calendar/Display/Timezone",
+ "UTC", NULL);
+ if (location && location[0]) {
+ local_timezone = icaltimezone_get_builtin_timezone (location);
+ } else {
+ local_timezone = icaltimezone_get_utc_timezone ();
+ }
+
+ g_free (location);
+
return local_timezone;
}
@@ -108,5 +106,11 @@ config_data_get_24_hour_format (void)
{
ensure_inited ();
- return use_24_hour_format;
+ if (locale_supports_12_hour_format ()) {
+ return e_config_listener_get_boolean_with_default (
+ config,
+ "/Calendar/Display/Use24HourFormat", FALSE, NULL);
+ }
+
+ return TRUE;
}
diff --git a/calendar/gui/alarm-notify/config-data.h b/calendar/gui/alarm-notify/config-data.h
index 06a73ba562..c7041be111 100644
--- a/calendar/gui/alarm-notify/config-data.h
+++ b/calendar/gui/alarm-notify/config-data.h
@@ -23,9 +23,11 @@
#include <glib.h>
#include <ical.h>
+#include <e-util/e-config-listener.h>
-icaltimezone *config_data_get_timezone (void);
+EConfigListener *config_data_get_listener (void);
+icaltimezone *config_data_get_timezone (void);
gboolean config_data_get_24_hour_format (void);
#endif
diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c
index 06fe87b611..b7364475ca 100644
--- a/calendar/gui/alarm-notify/notify-main.c
+++ b/calendar/gui/alarm-notify/notify-main.c
@@ -43,7 +43,7 @@ static GnomeClient *master_client = NULL;
static BonoboGenericFactory *factory;
-static AlarmNotify *alarm_notify_service;
+static AlarmNotify *alarm_notify_service = NULL;
/* Callback for the master client's "die" signal. We must terminate the daemon
@@ -86,16 +86,6 @@ set_session_parameters (char **argv)
GTK_SIGNAL_FUNC (client_die_cb), NULL);
}
-/* Creates the singleton alarm notify service object */
-static gboolean
-init_alarm_notify_service (void)
-{
- g_assert (alarm_notify_service == NULL);
-
- alarm_notify_service = alarm_notify_new ();
- return (alarm_notify_service != NULL);
-}
-
/* Factory function for the alarm notify service; just creates and references a
* singleton service object.
*/
@@ -104,6 +94,11 @@ alarm_notify_factory_fn (BonoboGenericFactory *factory, void *data)
{
g_assert (alarm_notify_service != NULL);
+ if (!alarm_notify_service) {
+ alarm_notify_service = alarm_notify_new ();
+ g_assert (alarm_notify_service != NULL);
+ }
+
bonobo_object_ref (BONOBO_OBJECT (alarm_notify_service));
return BONOBO_OBJECT (alarm_notify_service);
}
@@ -115,6 +110,14 @@ load_calendars (gpointer user_data)
GPtrArray *uris;
int i;
+ alarm_queue_init ();
+
+ /* create the alarm notification service */
+ if (!alarm_notify_service) {
+ alarm_notify_service = alarm_notify_new ();
+ g_assert (alarm_notify_service != NULL);
+ }
+
uris = get_calendars_to_load ();
if (!uris) {
g_message ("load_calendars(): Could not get the list of calendars to load");
@@ -177,11 +180,6 @@ main (int argc, char **argv)
glade_gnome_init ();
- alarm_queue_init ();
-
- if (!init_alarm_notify_service ())
- g_error (_("Could not create the alarm notify service"));
-
factory = bonobo_generic_factory_new ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory",
alarm_notify_factory_fn, NULL);
if (!factory)
diff --git a/calendar/gui/alarm-notify/save.c b/calendar/gui/alarm-notify/save.c
index 92dc94b65a..455af7f883 100644
--- a/calendar/gui/alarm-notify/save.c
+++ b/calendar/gui/alarm-notify/save.c
@@ -26,6 +26,7 @@
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-moniker-util.h>
#include "evolution-calendar.h"
+#include "config-data.h"
#include "save.h"
@@ -40,48 +41,6 @@
-/* Tries to get the config database object; returns CORBA_OBJECT_NIL on failure. */
-Bonobo_ConfigDatabase
-get_config_db (void)
-{
- CORBA_Environment ev;
- Bonobo_ConfigDatabase db;
-
- CORBA_exception_init (&ev);
-
- db = bonobo_get_object ("wombat:", "Bonobo/ConfigDatabase", &ev);
- if (BONOBO_EX (&ev) || db == CORBA_OBJECT_NIL) {
- g_message ("get_config_db(): Could not get the config database object");
- db = CORBA_OBJECT_NIL;
- }
-
- CORBA_exception_free (&ev);
- return db;
-}
-
-/* Syncs a database and unrefs it */
-void
-discard_config_db (Bonobo_ConfigDatabase db)
-{
- CORBA_Environment ev;
-
- CORBA_exception_init (&ev);
-
- Bonobo_ConfigDatabase_sync (db, &ev);
- if (BONOBO_EX (&ev))
- g_message ("discard_config_db(): Got an exception during the sync command");
-
- CORBA_exception_free (&ev);
-
- CORBA_exception_init (&ev);
-
- bonobo_object_release_unref (db, &ev);
- if (BONOBO_EX (&ev))
- g_message ("discard_config_db(): Could not release/unref the database");
-
- CORBA_exception_free (&ev);
-}
-
/**
* save_notification_time:
* @t: A time value.
@@ -93,24 +52,14 @@ discard_config_db (Bonobo_ConfigDatabase db)
void
save_notification_time (time_t t)
{
- Bonobo_ConfigDatabase db;
- CORBA_Environment ev;
+ EConfigListener *cl;
g_return_if_fail (t != -1);
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL)
+ if (!(cl = config_data_get_listener ()))
return;
- CORBA_exception_init (&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");
-
- CORBA_exception_free (&ev);
-
- discard_config_db (db);
+ e_config_listener_set_long (cl, KEY_LAST_NOTIFICATION_TIME, (long) t);
}
/**
@@ -123,16 +72,13 @@ save_notification_time (time_t t)
time_t
get_saved_notification_time (void)
{
- Bonobo_ConfigDatabase db;
+ EConfigListener *cl;
long t;
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL)
+ if (!(cl = config_data_get_listener ()))
return -1;
- t = bonobo_config_get_long_with_default (db, KEY_LAST_NOTIFICATION_TIME, -1, NULL);
-
- discard_config_db (db);
+ t = e_config_listener_get_long_with_default (cl, KEY_LAST_NOTIFICATION_TIME, -1, NULL);
return (time_t) t;
}
@@ -147,23 +93,17 @@ get_saved_notification_time (void)
void
save_calendars_to_load (GPtrArray *uris)
{
- Bonobo_ConfigDatabase db;
- CORBA_Environment ev;
+ EConfigListener *cl;
int len, i;
g_return_if_fail (uris != NULL);
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL)
+ if (!(cl = config_data_get_listener ()))
return;
len = uris->len;
- CORBA_exception_init (&ev);
-
- bonobo_config_set_long (db, KEY_NUM_CALENDARS_TO_LOAD, len, &ev);
- if (BONOBO_EX (&ev))
- g_warning ("Cannot save config key %s -- %s", KEY_NUM_CALENDARS_TO_LOAD, BONOBO_EX_ID (&ev));
+ e_config_listener_set_long (cl, KEY_NUM_CALENDARS_TO_LOAD, len);
for (i = 0; i < len; i++) {
const char *uri;
@@ -172,15 +112,9 @@ save_calendars_to_load (GPtrArray *uris)
uri = uris->pdata[i];
key = g_strdup_printf ("%s%d", BASE_KEY_CALENDAR_TO_LOAD, i);
- bonobo_config_set_string (db, key, uri, &ev);
- if (BONOBO_EX (&ev))
- g_warning ("Cannot save config key %s -- %s", key, BONOBO_EX_ID (&ev));
+ e_config_listener_set_string (cl, key, uri);
g_free (key);
}
-
- CORBA_exception_free (&ev);
-
- discard_config_db (db);
}
/**
@@ -194,19 +128,18 @@ save_calendars_to_load (GPtrArray *uris)
GPtrArray *
get_calendars_to_load (void)
{
- Bonobo_ConfigDatabase db;
+ EConfigListener *cl;
GPtrArray *uris;
int len, i;
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL)
+ if (!(cl = config_data_get_listener ()))
return NULL;
/* Getting the default value below is not necessarily an error, as we
* may not have saved the list of calendar yet.
*/
- len = bonobo_config_get_long_with_default (db, KEY_NUM_CALENDARS_TO_LOAD, 0, NULL);
+ len = e_config_listener_get_long_with_default (cl, KEY_NUM_CALENDARS_TO_LOAD, 0, NULL);
uris = g_ptr_array_new ();
g_ptr_array_set_size (uris, len);
@@ -216,7 +149,7 @@ get_calendars_to_load (void)
gboolean used_default;
key = g_strdup_printf ("%s%d", BASE_KEY_CALENDAR_TO_LOAD, i);
- uris->pdata[i] = bonobo_config_get_string_with_default (db, key, "", &used_default);
+ uris->pdata[i] = e_config_listener_get_string_with_default (cl, key, "", &used_default);
if (used_default)
g_message ("get_calendars_to_load(): Could not read calendar name %d", i);
@@ -235,35 +168,25 @@ get_calendars_to_load (void)
void
save_blessed_program (const char *program)
{
- Bonobo_ConfigDatabase db;
- CORBA_Environment ev;
+ EConfigListener *cl;
char *key;
int len;
g_return_if_fail (program != NULL);
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL)
+ if (!(cl = config_data_get_listener ()))
return;
/* Up the number saved */
- len = bonobo_config_get_long_with_default (db, KEY_NUM_BLESSED_PROGRAMS, 0, NULL);
+ len = e_config_listener_get_long_with_default (cl, KEY_NUM_BLESSED_PROGRAMS, 0, NULL);
len++;
- bonobo_config_set_long (db, KEY_NUM_BLESSED_PROGRAMS, len, &ev);
- if (BONOBO_EX (&ev))
- g_warning ("Cannot save config key %s -- %s", KEY_NUM_BLESSED_PROGRAMS, BONOBO_EX_ID (&ev));
+ e_config_listener_set_long (cl, KEY_NUM_BLESSED_PROGRAMS, len);
/* Save the program name */
key = g_strdup_printf ("%s%d", BASE_KEY_BLESSED_PROGRAM, len - 1);
- bonobo_config_set_string (db, key, program, &ev);
- if (BONOBO_EX (&ev))
- g_warning ("Cannot save config key %s -- %s", key, BONOBO_EX_ID (&ev));
+ e_config_listener_set_string (cl, key, program);
g_free (key);
-
- CORBA_exception_free (&ev);
-
- discard_config_db (db);
}
/**
@@ -277,27 +200,26 @@ save_blessed_program (const char *program)
gboolean
is_blessed_program (const char *program)
{
- Bonobo_ConfigDatabase db;
+ EConfigListener *cl;
int len, i;
g_return_val_if_fail (program != NULL, FALSE);
- db = get_config_db ();
- if (db == CORBA_OBJECT_NIL)
+ if (!(cl = config_data_get_listener ()))
return FALSE;
/* Getting the default value below is not necessarily an error, as we
* may not have saved the list of calendar yet.
*/
- len = bonobo_config_get_long_with_default (db, KEY_NUM_BLESSED_PROGRAMS, 0, NULL);
+ len = e_config_listener_get_long_with_default (cl, KEY_NUM_BLESSED_PROGRAMS, 0, NULL);
for (i = 0; i < len; i++) {
char *key, *value;
gboolean used_default;
key = g_strdup_printf ("%s%d", BASE_KEY_BLESSED_PROGRAM, i);
- value = bonobo_config_get_string_with_default (db, key, "", &used_default);
+ value = e_config_listener_get_string_with_default (cl, key, "", &used_default);
if (used_default)
g_message ("get_calendars_to_load(): Could not read calendar name %d", i);