From 3f1448b0119585493e1d213af9afde5faf50cb2c Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 18 Sep 2009 10:28:13 -0400 Subject: Restore the alarm notify daemon. Convert evolution-alarm-notify to an autostart program, add a .desktop file for it, and use libunique to ensure only one instance is running. --- calendar/gui/alarm-notify/alarm-notify.c | 206 ++++++++++++++++--------------- 1 file changed, 104 insertions(+), 102 deletions(-) (limited to 'calendar/gui/alarm-notify/alarm-notify.c') diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c index 62679bb2b6..5651a61182 100644 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ b/calendar/gui/alarm-notify/alarm-notify.c @@ -25,7 +25,6 @@ #endif #include -#include #include #include #include @@ -34,54 +33,36 @@ #include "alarm-queue.h" #include "config-data.h" #include "common/authentication.h" - -/* Private part of the AlarmNotify structure */ + +#define d(x) + +#define ALARM_NOTIFY_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), TYPE_ALARM_NOTIFY, AlarmNotifyPrivate)) + struct _AlarmNotifyPrivate { /* Mapping from EUri's to LoadedClient structures */ /* FIXME do we need per source type uri hashes? or perhaps we just need to hash based on source */ - GHashTable *uri_client_hash [E_CAL_SOURCE_TYPE_LAST]; - ESourceList *source_lists [E_CAL_SOURCE_TYPE_LAST]; + GHashTable *uri_client_hash[E_CAL_SOURCE_TYPE_LAST]; + ESourceList *source_lists[E_CAL_SOURCE_TYPE_LAST]; ESourceList *selected_calendars; GMutex *mutex; }; -#define d(x) - - -static void alarm_notify_class_init (AlarmNotifyClass *klass); -static void alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass); -static void alarm_notify_finalize (GObject *object); - -static BonoboObjectClass *parent_class; - - -BONOBO_TYPE_FUNC_FULL(AlarmNotify, GNOME_Evolution_Calendar_AlarmNotify, BONOBO_TYPE_OBJECT, alarm_notify) - -/* Class initialization function for the alarm notify service */ -static void -alarm_notify_class_init (AlarmNotifyClass *klass) -{ - GObjectClass *object_class; - - object_class = (GObjectClass *) klass; - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = alarm_notify_finalize; -} - typedef struct { AlarmNotify *an; ESourceList *source_list; GList *removals; } ProcessRemovalsData; +static gpointer parent_class; + static void -process_removal_in_hash (gpointer key, gpointer value, gpointer data) +process_removal_in_hash (const gchar *uri, + gpointer value, + ProcessRemovalsData *prd) { - gchar *uri = key; - ProcessRemovalsData *prd = data; GSList *groups, *sources, *p, *q; gboolean found = FALSE; @@ -109,27 +90,25 @@ process_removal_in_hash (gpointer key, gpointer value, gpointer data) } /* not found, so list it for removal */ - prd->removals = g_list_prepend (prd->removals, uri); + prd->removals = g_list_prepend (prd->removals, (gpointer) uri); } static void -list_changed_cb (ESourceList *source_list, gpointer data) +alarm_notify_list_changed_cb (ESourceList *source_list, + AlarmNotify *an) { - AlarmNotify *an = data; - AlarmNotifyPrivate *priv; GSList *groups, *sources, *p, *q; ECalSourceType source_type = E_CAL_SOURCE_TYPE_LAST; ProcessRemovalsData prd; GList *l; gint i; - g_signal_handlers_block_by_func(source_list, list_changed_cb, data); - - priv = an->priv; + g_signal_handlers_block_by_func ( + source_list, alarm_notify_list_changed_cb, an); /* Figure out the source type */ for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) { - if (source_list == priv->source_lists[i]) { + if (source_list == an->priv->source_lists[i]) { source_type = i; break; } @@ -153,7 +132,7 @@ list_changed_cb (ESourceList *source_list, gpointer data) continue; uri = e_source_get_uri (source); - if (!g_hash_table_lookup (priv->uri_client_hash[source_type], uri)) { + if (!g_hash_table_lookup (an->priv->uri_client_hash[source_type], uri)) { d (printf("%s:%d (list_changed_cb) - Adding Calendar %s\n", __FILE__, __LINE__, uri)); alarm_notify_add_calendar (an, source_type, source, FALSE); } @@ -163,37 +142,30 @@ list_changed_cb (ESourceList *source_list, gpointer data) /* process the removals */ prd.an = an; - prd.source_list = priv->source_lists[source_type]; + prd.source_list = an->priv->source_lists[source_type]; prd.removals = NULL; - g_hash_table_foreach (priv->uri_client_hash[source_type], (GHFunc) process_removal_in_hash, &prd); + g_hash_table_foreach (an->priv->uri_client_hash[source_type], (GHFunc) process_removal_in_hash, &prd); for (l = prd.removals; l; l = l->next) { d (printf("%s:%d (list_changed_cb) - Removing Calendar %s\n", __FILE__, __LINE__, (gchar *)l->data)); alarm_notify_remove_calendar (an, source_type, l->data); } g_list_free (prd.removals); - g_signal_handlers_unblock_by_func(source_list, list_changed_cb, data); - -} + g_signal_handlers_unblock_by_func ( + source_list, alarm_notify_list_changed_cb, an); -ESourceList * -alarm_notify_get_selected_calendars (AlarmNotify *an) -{ - return an->priv->selected_calendars; } static void -load_calendars (AlarmNotify *an, ECalSourceType source_type) +alarm_notify_load_calendars (AlarmNotify *an, + ECalSourceType source_type) { - AlarmNotifyPrivate *priv; ESourceList *source_list; GSList *groups, *sources, *p, *q; - priv = an->priv; - if (!e_cal_get_sources (&source_list, source_type, NULL)) { d (printf("%s:%d (load_calendars) - Cannont get sources\n ", __FILE__, __LINE__)); - priv->source_lists[source_type] = NULL; + an->priv->source_lists[source_type] = NULL; return; } @@ -220,89 +192,119 @@ load_calendars (AlarmNotify *an, ECalSourceType source_type) } } - g_signal_connect_object (source_list, "changed", G_CALLBACK (list_changed_cb), an, 0); - priv->source_lists[source_type] = source_list; + g_signal_connect_object ( + source_list, "changed", + G_CALLBACK (alarm_notify_list_changed_cb), an, 0); + an->priv->source_lists[source_type] = source_list; } -/* Object initialization function for the alarm notify system */ static void -alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass) +alarm_notify_dequeue_client (gpointer key, + ECal *client) +{ + alarm_queue_remove_client (client, TRUE); +} + +static void +alarm_notify_finalize (GObject *object) { AlarmNotifyPrivate *priv; - gint i; + gint ii; - priv = g_new0 (AlarmNotifyPrivate, 1); - an->priv = priv; - priv->mutex = g_mutex_new (); - priv->selected_calendars = config_data_get_calendars ("/apps/evolution/calendar/sources"); + priv = ALARM_NOTIFY_GET_PRIVATE (object); - d (printf("%s:%d (alarm_notify_init) - Initing Alarm Notify\n", __FILE__, __LINE__)); + for (ii = 0; ii < E_CAL_SOURCE_TYPE_LAST; ii++) { + g_hash_table_foreach ( + priv->uri_client_hash[ii], + (GHFunc) alarm_notify_dequeue_client, NULL); + g_hash_table_destroy (priv->uri_client_hash[ii]); + } - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) - priv->uri_client_hash[i] = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + alarm_queue_done (); - alarm_queue_init (an); + g_mutex_free (priv->mutex); - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) - load_calendars (an, i); + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -dequeue_client (gpointer key, gpointer value, gpointer user_data) +alarm_notify_class_init (AlarmNotifyClass *class) { - ECal *client = value; + GObjectClass *object_class; - d (printf("%s:%d (dequeue_client) - Removing client %p\n ", __FILE__, __LINE__, client)); - alarm_queue_remove_client (client, TRUE); + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (AlarmNotifyPrivate)); + + object_class = (GObjectClass *) class; + object_class->finalize = alarm_notify_finalize; } -/* Finalize handler for the alarm notify system */ static void -alarm_notify_finalize (GObject *object) +alarm_notify_init (AlarmNotify *an) { - AlarmNotify *an; - AlarmNotifyPrivate *priv; - gint i; + gint ii; - g_return_if_fail (object != NULL); - g_return_if_fail (IS_ALARM_NOTIFY (object)); + an->priv = ALARM_NOTIFY_GET_PRIVATE (an); + an->priv->mutex = g_mutex_new (); + an->priv->selected_calendars = config_data_get_calendars ( + "/apps/evolution/calendar/sources"); - d (printf("%s:%d (alarm_notify_finalize) - Finalize \n ", __FILE__, __LINE__)); + for (ii = 0; ii < E_CAL_SOURCE_TYPE_LAST; ii++) + an->priv->uri_client_hash[ii] = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_object_unref); - an = ALARM_NOTIFY (object); - priv = an->priv; + alarm_queue_init (an); - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) { - g_hash_table_foreach (priv->uri_client_hash[i], dequeue_client, NULL); - g_hash_table_destroy (priv->uri_client_hash[i]); - } + for (ii = 0; ii < E_CAL_SOURCE_TYPE_LAST; ii++) + alarm_notify_load_calendars (an, ii); +} - alarm_queue_done (); +ESourceList * +alarm_notify_get_selected_calendars (AlarmNotify *an) +{ + return an->priv->selected_calendars; +} - g_mutex_free (priv->mutex); - g_free (priv); +GType +alarm_notify_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (AlarmNotifyClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) alarm_notify_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (AlarmNotify), + 0, /* n_preallocs */ + (GInstanceInitFunc) alarm_notify_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + G_TYPE_OBJECT, "AlarmNotify", &type_info, 0); + } - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); + return type; } - - /** * alarm_notify_new: * * Creates a new #AlarmNotify object. * - * Return value: A newly-created #AlarmNotify, or NULL if its corresponding - * CORBA object could not be created. + * Returns: a newly-created #AlarmNotify **/ AlarmNotify * alarm_notify_new (void) { - return g_object_new (TYPE_ALARM_NOTIFY, - "poa", bonobo_poa_get_threaded ( - ORBIT_THREAD_HINT_PER_REQUEST, NULL), - NULL); + return g_object_new (TYPE_ALARM_NOTIFY, NULL); } static void -- cgit v1.2.3