aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/alarm-notify/notify-main.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/notify-main.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/notify-main.c')
-rw-r--r--calendar/gui/alarm-notify/notify-main.c110
1 files changed, 105 insertions, 5 deletions
diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c
index 5134aae0b7..f2e2444201 100644
--- a/calendar/gui/alarm-notify/notify-main.c
+++ b/calendar/gui/alarm-notify/notify-main.c
@@ -36,30 +36,121 @@
#include "alarm.h"
#include "alarm-queue.h"
#include "alarm-notify.h"
+#include "save.h"
+static GnomeClient *master_client = NULL;
+
static BonoboGenericFactory *factory;
static AlarmNotify *alarm_notify_service;
+/* Callback for the master client's "die" signal. We must terminate the daemon
+ * since the session is ending.
+ */
+static void
+client_die_cb (GnomeClient *client)
+{
+ gtk_main_quit ();
+}
+
+/* Sees if a session manager is present. If so, it tells the SM how to restart
+ * the daemon when the session starts. It also sets the die callback so that
+ * the daemon can terminate properly when the session ends.
+ */
+static void
+set_session_parameters (char **argv)
+{
+ int flags;
+ char *args[2];
+
+ master_client = gnome_master_client ();
+ flags = gnome_client_get_flags (master_client);
+
+ if (!(flags & GNOME_CLIENT_IS_CONNECTED))
+ return;
+
+ /* The daemon should always be started up by the session manager when
+ * the session starts. The daemon will take care of loading whatever
+ * calendars it was told to load.
+ */
+ gnome_client_set_restart_style (master_client, GNOME_RESTART_ANYWAY);
+
+ args[0] = argv[0];
+ args[1] = NULL;
+
+ gnome_client_set_restart_command (master_client, 1, args);
+
+ gtk_signal_connect (GTK_OBJECT (master_client), "die",
+ 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.
*/
static BonoboObject *
alarm_notify_factory_fn (BonoboGenericFactory *factory, void *data)
{
- if (!alarm_notify_service) {
- alarm_notify_service = alarm_notify_new ();
- if (!alarm_notify_service)
- return NULL;
- }
+ g_assert (alarm_notify_service != NULL);
bonobo_object_ref (BONOBO_OBJECT (alarm_notify_service));
return BONOBO_OBJECT (alarm_notify_service);
}
+/* Loads the calendars that the alarm daemon has been told to load in the past */
+static void
+load_calendars (void)
+{
+ GPtrArray *uris;
+ int i;
+
+ uris = get_calendars_to_load ();
+ g_assert (uris != NULL);
+
+ for (i = 0; i < uris->len; i++) {
+ char *uri;
+ CORBA_Environment ev;
+
+ uri = uris->pdata[i];
+
+ CORBA_exception_init (&ev);
+ alarm_notify_add_calendar (alarm_notify_service, uri, FALSE, &ev);
+
+ if (ev._major == CORBA_USER_EXCEPTION) {
+ char *ex_id;
+
+ ex_id = CORBA_exception_id (&ev);
+ if (strcmp (ex_id, ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI) == 0)
+ g_message ("load_calendars(): Invalid URI `%s'; will not load "
+ "that calendar.", uri);
+ else if (strcmp (ex_id,
+ ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError)
+ == 0)
+ g_message ("load_calendars(): Could not contact the backend "
+ "while trying to load `%s'", uri);
+ } else if (ev._major != CORBA_NO_EXCEPTION)
+ g_message ("load_calendars(): Exception while loading calendar `%s'", uri);
+
+ CORBA_exception_free (&ev);
+
+ g_free (uri);
+ }
+
+ g_ptr_array_free (uris, TRUE);
+}
+
int
main (int argc, char **argv)
{
@@ -84,16 +175,25 @@ main (int argc, char **argv)
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)
g_error (_("Could not create the alarm notify service factory"));
+ set_session_parameters (argv);
+
+ load_calendars ();
+
bonobo_main ();
bonobo_object_unref (BONOBO_OBJECT (factory));
factory = NULL;
+ /* FIXME: free the alarm_notify_service */
+
alarm_queue_done ();
alarm_done ();