aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/alarm-notify
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui/alarm-notify')
-rw-r--r--calendar/gui/alarm-notify/alarm-notify.c209
-rw-r--r--calendar/gui/alarm-notify/alarm-queue.c2
2 files changed, 26 insertions, 185 deletions
diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c
index 133448e7cd..006533c6bf 100644
--- a/calendar/gui/alarm-notify/alarm-notify.c
+++ b/calendar/gui/alarm-notify/alarm-notify.c
@@ -31,26 +31,6 @@
-/* A loaded client */
-typedef struct {
- /* The actual client */
- CalClient *client;
-
- /* The URI of the client in gnome-vfs's format. This *is* the key that
- * is stored in the uri_client_hash hash table below.
- */
- EUri *uri;
-
- /* Number of times clients have requested this URI to be added to the
- * alarm notification system.
- */
- int refcount;
-
- /* the ID of the retry timeout function
- */
- int timeout_id;
-} LoadedClient;
-
/* Private part of the AlarmNotify structure */
struct _AlarmNotifyPrivate {
/* Mapping from EUri's to LoadedClient structures */
@@ -105,23 +85,7 @@ alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass)
priv = g_new0 (AlarmNotifyPrivate, 1);
an->priv = priv;
- priv->uri_client_hash = g_hash_table_new (g_str_hash, g_str_equal);
-}
-
-/* Callback used from g_hash-table_forach(), used to destroy a loade client */
-static void
-destroy_loaded_client_cb (gpointer key, gpointer value, gpointer data)
-{
- LoadedClient *lc;
- char *str_uri;
-
- str_uri = key;
- lc = value;
-
- g_free (str_uri);
- g_object_unref (G_OBJECT (lc->client));
- e_uri_free (lc->uri);
- g_free (lc);
+ priv->uri_client_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
}
/* Finalize handler for the alarm notify system */
@@ -137,13 +101,9 @@ alarm_notify_finalize (GObject *object)
an = ALARM_NOTIFY (object);
priv = an->priv;
- g_hash_table_foreach (priv->uri_client_hash, destroy_loaded_client_cb, NULL);
-
g_hash_table_destroy (priv->uri_client_hash);
- priv->uri_client_hash = NULL;
g_free (priv);
- an->priv = NULL;
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
@@ -193,21 +153,15 @@ free_uris (GPtrArray *uris)
/* Adds an URI to the list of calendars to load on startup */
static void
-add_uri_to_load (EUri *uri)
+add_uri_to_load (const char *str_uri)
{
- char *str_uri;
GPtrArray *loaded_uris;
int i;
- /* Canonicalize the URI */
- str_uri = e_uri_to_string (uri, FALSE);
- g_assert (str_uri != NULL);
-
loaded_uris = get_calendars_to_load ();
if (!loaded_uris) {
g_message ("add_uri_to_load(): Could not get the list of calendars to load; "
"will not add `%s'", str_uri);
- g_free (str_uri);
return;
}
@@ -219,12 +173,11 @@ add_uri_to_load (EUri *uri)
* calendars.
*/
if (i != -1) {
- g_free (str_uri);
free_uris (loaded_uris);
return;
}
- g_ptr_array_add (loaded_uris, str_uri);
+ g_ptr_array_add (loaded_uris, g_strdup (str_uri));
save_calendars_to_load (loaded_uris);
free_uris (loaded_uris);
@@ -232,29 +185,22 @@ add_uri_to_load (EUri *uri)
/* Removes an URI from the list of calendars to load on startup */
static void
-remove_uri_to_load (EUri *uri)
+remove_uri_to_load (const char *str_uri)
{
- char *str_uri;
GPtrArray *loaded_uris;
char *loaded_uri;
int i;
- /* Canonicalize the URI */
- str_uri = e_uri_to_string (uri, FALSE);
- g_assert (str_uri != NULL);
-
loaded_uris = get_calendars_to_load ();
if (!loaded_uris) {
g_message ("remove_uri_to_load(): Could not get the list of calendars to load; "
"will not add `%s'", str_uri);
- g_free (str_uri);
return;
}
/* Look for the URI in the list of calendars to load */
i = find_uri_index (loaded_uris, str_uri);
- g_free (str_uri);
/* If we didn't find it, there is no need to remove it */
if (i == -1) {
@@ -291,61 +237,19 @@ AlarmNotify_removeCalendar (PortableServer_Servant servant,
{
AlarmNotify *an;
AlarmNotifyPrivate *priv;
- LoadedClient *lc;
- EUri *uri;
- char *orig_str;
- gpointer lc_ptr, orig_str_ptr;
- gboolean found;
-
- lc_ptr = NULL;
- orig_str_ptr = NULL;
+ CalClient *client;
an = ALARM_NOTIFY (bonobo_object_from_servant (servant));
priv = an->priv;
- uri = e_uri_new (str_uri);
- if (!uri) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI,
- NULL);
- return;
- }
+ client = g_hash_table_lookup (priv->uri_client_hash, str_uri);
+ if (client) {
+ alarm_queue_remove_client (client);
- remove_uri_to_load (uri);
-
- found = g_hash_table_lookup_extended (priv->uri_client_hash, str_uri,
- &orig_str_ptr,
- &lc_ptr);
- orig_str = orig_str_ptr;
- lc = lc_ptr;
-
- e_uri_free (uri);
-
- if (!lc) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_AlarmNotify_NotFound,
- NULL);
- return;
+ g_hash_table_remove (priv->uri_client_hash, str_uri);
}
- g_assert (lc->refcount > 0);
-
- lc->refcount--;
- if (lc->refcount > 0)
- return;
-
- g_hash_table_remove (priv->uri_client_hash, str_uri);
-
- g_free (orig_str);
- g_signal_handlers_disconnect_matched (lc->client,
- G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL, lc);
- if (lc->timeout_id != -1)
- g_source_remove (lc->timeout_id);
- alarm_queue_remove_client (lc->client);
- g_object_unref (G_OBJECT (lc->client));
- e_uri_free (lc->uri);
- g_free (lc);
+ remove_uri_to_load (str_uri);
}
@@ -367,40 +271,6 @@ alarm_notify_new (void)
return an;
}
-static gboolean
-retry_timeout_cb (gpointer data)
-{
- LoadedClient *lc = data;
- char *str_uri;
-
- if (cal_client_get_load_state (lc->client) != CAL_CLIENT_LOAD_LOADED) {
- str_uri = e_uri_to_string (lc->uri, FALSE);
- cal_client_open_calendar (lc->client, str_uri, FALSE);
-
- g_free (str_uri);
- }
-
- return FALSE;
-}
-
-static void
-cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
-{
- LoadedClient *lc = (LoadedClient *) data;
-
- if (status == CAL_CLIENT_OPEN_SUCCESS) {
- add_uri_to_load (lc->uri);
- alarm_queue_add_client (client);
- lc->timeout_id = -1;
- }
- else {
- remove_uri_to_load (lc->uri);
-
- /* we set a timeout of 5 mins before retrying */
- lc->timeout_id = g_timeout_add (300000, (GSourceFunc) retry_timeout_cb, lc);
- }
-}
-
/**
* alarm_notify_add_calendar:
* @an: An alarm notification service.
@@ -418,10 +288,7 @@ alarm_notify_add_calendar (AlarmNotify *an, const char *str_uri, gboolean load_a
CORBA_Environment *ev)
{
AlarmNotifyPrivate *priv;
- EUri *uri;
CalClient *client;
- LoadedClient *lc;
- gpointer lc_ptr, s_ptr;
g_return_if_fail (an != NULL);
g_return_if_fail (IS_ALARM_NOTIFY (an));
@@ -430,49 +297,23 @@ alarm_notify_add_calendar (AlarmNotify *an, const char *str_uri, gboolean load_a
priv = an->priv;
- uri = e_uri_new (str_uri);
- if (!uri) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI,
- NULL);
+ /* See if we already know about this uri */
+ if (g_hash_table_lookup (priv->uri_client_hash, str_uri))
return;
- }
- if (g_hash_table_lookup_extended (priv->uri_client_hash, str_uri, &s_ptr, &lc_ptr)) {
- lc = lc_ptr;
- lc->refcount++;
- } else {
- client = cal_client_new ();
-
- if (client) {
- /* we only add the URI to load_afterwards if we open it
- correctly */
- lc = g_new (LoadedClient, 1);
- lc->client = client;
- lc->uri = uri;
- lc->refcount = 1;
- lc->timeout_id = -1;
-
-
- g_signal_connect (G_OBJECT (client), "cal_opened",
- G_CALLBACK (cal_opened_cb),
- lc);
-
- if (cal_client_open_calendar (client, str_uri, FALSE)) {
- g_hash_table_insert (priv->uri_client_hash,
- g_strdup (str_uri), lc);
- } else {
- g_free (lc);
- g_object_unref (G_OBJECT (client));
- client = NULL;
- }
- } else {
- e_uri_free (uri);
-
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError,
- NULL);
- return;
+ client = cal_client_new (str_uri, CALOBJ_TYPE_EVENT);
+
+ if (client) {
+ if (cal_client_open (client, FALSE, NULL)) {
+ add_uri_to_load (str_uri);
+
+ g_hash_table_insert (priv->uri_client_hash,
+ g_strdup (str_uri), client);
}
+ } else {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError,
+ NULL);
+ return;
}
}
diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c
index cb792e466f..cee17bd97e 100644
--- a/calendar/gui/alarm-notify/alarm-queue.c
+++ b/calendar/gui/alarm-notify/alarm-queue.c
@@ -227,7 +227,7 @@ remove_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id,
if (remove_alarm) {
cqa->expecting_update = TRUE;
cal_client_discard_alarm (cqa->parent_client->client, cqa->alarms->comp,
- qa->instance->auid);
+ qa->instance->auid, NULL);
cqa->expecting_update = FALSE;
}