aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/alarm-notify/alarm-notify.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2001-10-19 03:50:29 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2001-10-19 03:50:29 +0800
commitd21e6e4dc143f1b077da4d9c9375947e63321d7a (patch)
treecb01ffe152063455c05e2d802ae5309d0d96685a /calendar/gui/alarm-notify/alarm-notify.c
parentf7d9f635db0b3375f31bfa8d7984032dad87c5d1 (diff)
downloadgsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.tar
gsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.tar.gz
gsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.tar.bz2
gsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.tar.lz
gsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.tar.xz
gsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.tar.zst
gsoc2013-evolution-d21e6e4dc143f1b077da4d9c9375947e63321d7a.zip
Adds session management for the alarm daemon. Also makes it store a list
2001-10-18 Federico Mena Quintero <federico@ximian.com> 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
Diffstat (limited to 'calendar/gui/alarm-notify/alarm-notify.c')
-rw-r--r--calendar/gui/alarm-notify/alarm-notify.c237
1 files changed, 180 insertions, 57 deletions
diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c
index 88d25dafbc..61b8e8ecc5 100644
--- a/calendar/gui/alarm-notify/alarm-notify.c
+++ b/calendar/gui/alarm-notify/alarm-notify.c
@@ -27,6 +27,7 @@
#include <cal-client/cal-client.h>
#include "alarm-notify.h"
#include "alarm-queue.h"
+#include "save.h"
@@ -64,8 +65,6 @@ static void AlarmNotify_addCalendar (PortableServer_Servant servant,
static void AlarmNotify_removeCalendar (PortableServer_Servant servant,
const CORBA_char *str_uri,
CORBA_Environment *ev);
-static void AlarmNotify_die (PortableServer_Servant servant,
- CORBA_Environment *ev);
static BonoboXObjectClass *parent_class;
@@ -89,7 +88,6 @@ alarm_notify_class_init (AlarmNotifyClass *class)
class->epv.addCalendar = AlarmNotify_addCalendar;
class->epv.removeCalendar = AlarmNotify_removeCalendar;
- class->epv.die = AlarmNotify_die;
object_class->destroy = alarm_notify_destroy;
}
@@ -148,63 +146,124 @@ alarm_notify_destroy (GtkObject *object)
/* CORBA servant implementation */
-/* AlarmNotify::addCalendar method */
+/* Looks for a canonicalized URI inside an array of URIs; returns the index
+ * within the array or -1 if not found.
+ */
+static int
+find_uri_index (GPtrArray *uris, const char *str_uri)
+{
+ int i;
+
+ for (i = 0; i < uris->len; i++) {
+ char *uri;
+
+ uri = uris->pdata[i];
+ if (strcmp (uri, str_uri) == 0)
+ break;
+ }
+
+ if (i == uris->len)
+ return -1;
+ else
+ return i;
+}
+
+/* Frees an array of URIs and the URIs within it. */
static void
-AlarmNotify_addCalendar (PortableServer_Servant servant,
- const CORBA_char *str_uri,
- CORBA_Environment *ev)
+free_uris (GPtrArray *uris)
{
- AlarmNotify *an;
- AlarmNotifyPrivate *priv;
- GnomeVFSURI *uri;
- CalClient *client;
- LoadedClient *lc;
+ int i;
- an = ALARM_NOTIFY (bonobo_object_from_servant (servant));
- priv = an->priv;
+ for (i = 0; i < uris->len; i++) {
+ char *uri;
- uri = gnome_vfs_uri_new (str_uri);
- if (!uri) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI,
- NULL);
- return;
+ uri = uris->pdata[i];
+ g_free (uri);
}
- lc = g_hash_table_lookup (priv->uri_client_hash, uri);
+ g_ptr_array_free (uris, TRUE);
+}
- if (lc) {
- gnome_vfs_uri_unref (uri);
- g_assert (lc->refcount > 0);
- lc->refcount++;
+/* Adds an URI to the list of calendars to load on startup */
+static void
+add_uri_to_load (GnomeVFSURI *uri)
+{
+ char *str_uri;
+ GPtrArray *loaded_uris;
+ int i;
+
+ /* Canonicalize the URI */
+ str_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
+ g_assert (str_uri != NULL);
+
+ loaded_uris = get_calendars_to_load ();
+ g_assert (loaded_uris != NULL);
+
+ /* Look for the URI in the list of calendars to load */
+
+ i = find_uri_index (loaded_uris, str_uri);
+
+ /* We only need to add the URI if we didn't find it among the list of
+ * calendars.
+ */
+ if (i != -1) {
+ g_free (str_uri);
+ free_uris (loaded_uris);
return;
}
- client = cal_client_new ();
+ g_ptr_array_add (loaded_uris, str_uri);
+ save_calendars_to_load (loaded_uris);
- if (client) {
- if (cal_client_open_calendar (client, str_uri, FALSE)) {
- lc = g_new (LoadedClient, 1);
- lc->client = client;
- lc->uri = uri;
- lc->refcount = 1;
- g_hash_table_insert (priv->uri_client_hash, uri, lc);
+ free_uris (loaded_uris);
+}
- alarm_queue_add_client (client);
- } else {
- gtk_object_unref (GTK_OBJECT (client));
- client = NULL;
- }
- }
+/* Removes an URI from the list of calendars to load on startup */
+static void
+remove_uri_to_load (GnomeVFSURI *uri)
+{
+ char *str_uri;
+ GPtrArray *loaded_uris;
+ char *loaded_uri;
+ int i;
- if (!client) {
- gnome_vfs_uri_unref (uri);
+ /* Canonicalize the URI */
+ str_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
+ g_assert (str_uri != NULL);
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError,
- NULL);
+ loaded_uris = get_calendars_to_load ();
+ g_assert (loaded_uris != NULL);
+
+ /* 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) {
+ free_uris (loaded_uris);
return;
}
+
+ loaded_uri = loaded_uris->pdata[i];
+ g_free (loaded_uri);
+
+ g_ptr_array_remove_index (loaded_uris, i);
+ save_calendars_to_load (loaded_uris);
+
+ free_uris (loaded_uris);
+}
+
+/* AlarmNotify::addCalendar method */
+static void
+AlarmNotify_addCalendar (PortableServer_Servant servant,
+ const CORBA_char *str_uri,
+ CORBA_Environment *ev)
+{
+ AlarmNotify *an;
+
+ an = ALARM_NOTIFY (bonobo_object_from_servant (servant));
+ alarm_notify_add_calendar (an, str_uri, TRUE, ev);
}
/* AlarmNotify::removeCalendar method */
@@ -229,6 +288,8 @@ AlarmNotify_removeCalendar (PortableServer_Servant servant,
return;
}
+ remove_uri_to_load (uri);
+
lc = g_hash_table_lookup (priv->uri_client_hash, uri);
gnome_vfs_uri_unref (uri);
@@ -252,19 +313,6 @@ AlarmNotify_removeCalendar (PortableServer_Servant servant,
g_free (lc);
}
-static void
-AlarmNotify_die (PortableServer_Servant servant,
- CORBA_Environment *ev)
-{
- AlarmNotify *an;
- AlarmNotifyPrivate *priv;
-
- an = ALARM_NOTIFY (bonobo_object_from_servant (servant));
- priv = an->priv;
-
- /* FIXME */
-}
-
/**
@@ -283,3 +331,78 @@ alarm_notify_new (void)
an = gtk_type_new (TYPE_ALARM_NOTIFY);
return an;
}
+
+/**
+ * alarm_notify_add_calendar:
+ * @an: An alarm notification service.
+ * @uri: URI of the calendar to load.
+ * @load_afterwards: Whether this calendar should be loaded in the future
+ * when the alarm daemon starts up.
+ * @ev: CORBA environment for exceptions.
+ *
+ * Tells the alarm notification service to load a calendar and start monitoring
+ * its alarms. It can optionally be made to save the URI of this calendar so
+ * that it can be loaded in the future when the alarm daemon starts up.
+ **/
+void
+alarm_notify_add_calendar (AlarmNotify *an, const char *str_uri, gboolean load_afterwards,
+ CORBA_Environment *ev)
+{
+ AlarmNotifyPrivate *priv;
+ GnomeVFSURI *uri;
+ CalClient *client;
+ LoadedClient *lc;
+
+ g_return_if_fail (an != NULL);
+ g_return_if_fail (IS_ALARM_NOTIFY (an));
+ g_return_if_fail (str_uri != NULL);
+ g_return_if_fail (ev != NULL);
+
+ priv = an->priv;
+
+ uri = gnome_vfs_uri_new (str_uri);
+ if (!uri) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI,
+ NULL);
+ return;
+ }
+
+ if (load_afterwards)
+ add_uri_to_load (uri);
+
+ lc = g_hash_table_lookup (priv->uri_client_hash, uri);
+
+ if (lc) {
+ gnome_vfs_uri_unref (uri);
+ g_assert (lc->refcount > 0);
+ lc->refcount++;
+ return;
+ }
+
+ client = cal_client_new ();
+
+ if (client) {
+ if (cal_client_open_calendar (client, str_uri, FALSE)) {
+ lc = g_new (LoadedClient, 1);
+ lc->client = client;
+ lc->uri = uri;
+ lc->refcount = 1;
+ g_hash_table_insert (priv->uri_client_hash, uri, lc);
+
+ alarm_queue_add_client (client);
+ } else {
+ gtk_object_unref (GTK_OBJECT (client));
+ client = NULL;
+ }
+ }
+
+ if (!client) {
+ gnome_vfs_uri_unref (uri);
+
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError,
+ NULL);
+ return;
+ }
+}