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/notify-main.c | 130 ++++++-------------------------- 1 file changed, 24 insertions(+), 106 deletions(-) (limited to 'calendar/gui/alarm-notify/notify-main.c') diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c index b3ff0db6a5..18e0a5eadf 100644 --- a/calendar/gui/alarm-notify/notify-main.c +++ b/calendar/gui/alarm-notify/notify-main.c @@ -30,144 +30,62 @@ #include #include #include -#include -#include -#include #include -#include -#include -#include +#include +#include #include #include + #include "e-util/e-icon-factory.h" #include "e-util/e-util-private.h" #include "alarm.h" #include "alarm-queue.h" #include "alarm-notify.h" #include "config-data.h" -#include - -static BonoboGenericFactory *factory; - -static AlarmNotify *alarm_notify_service = NULL; - -/* 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) -{ - bonobo_main_quit (); -} - -static gint -save_session_cb (GnomeClient *client, GnomeSaveStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, gpointer user_data) -{ - gchar *args[2]; - - args[0] = g_build_filename (EVOLUTION_LIBEXECDIR, - "evolution-alarm-notify" -#ifdef G_OS_WIN32 - ".exe" -#endif - , - NULL); - args[1] = NULL; - gnome_client_set_restart_command (client, 1, args); - g_free (args[0]); - - return TRUE; -} - -/* 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 -init_session (void) -{ - GnomeClient *master_client; - - master_client = gnome_master_client (); - - g_signal_connect (G_OBJECT (master_client), "die", - G_CALLBACK (client_die_cb), NULL); - g_signal_connect (G_OBJECT (master_client), "save_yourself", - G_CALLBACK (save_session_cb), NULL); - - /* 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_IF_RUNNING); -} - -/* Factory function for the alarm notify service; just creates and references a - * singleton service object. - */ -static BonoboObject * -alarm_notify_factory_fn (BonoboGenericFactory *factory, const gchar *component_id, gpointer data) -{ - g_return_val_if_fail (alarm_notify_service != NULL, NULL); - - bonobo_object_ref (BONOBO_OBJECT (alarm_notify_service)); - return BONOBO_OBJECT (alarm_notify_service); -} - -/* Creates the alarm notifier */ -static gboolean -init_alarm_service (gpointer user_data) -{ - alarm_notify_service = alarm_notify_new (); - g_return_val_if_fail (alarm_notify_service != NULL, FALSE); - return FALSE; -} gint main (gint argc, gchar **argv) { + AlarmNotify *alarm_notify_service; + UniqueApp *app; + bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); - gnome_program_init ("evolution-alarm-notify", VERSION, LIBGNOMEUI_MODULE, argc, argv, NULL); + g_thread_init (NULL); + + gtk_init (&argc, &argv); + + app = unique_app_new ("org.gnome.EvolutionAlarmNotify", NULL); - if (bonobo_init_full (&argc, argv, bonobo_activation_orb_get (), - CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error (_("Could not initialize Bonobo")); + if (unique_app_is_running (app)) + goto exit; glade_init (); e_icon_factory_init (); - init_alarm_service (NULL); - - factory = bonobo_generic_factory_new ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory:" BASE_VERSION, - (BonoboFactoryCallback) alarm_notify_factory_fn, NULL); - if (!factory) { - g_warning (_("Could not create the alarm notify service factory, maybe it's already running...")); - return 1; - } + alarm_notify_service = alarm_notify_new (); - init_session (); + /* FIXME Ideally we should not use camel libraries in calendar, + * though it is the case currently for attachments. Remove + * this once that is fixed. */ - /* FIXME Ideally we should not use camel libraries in calendar, though it is the case - currently for attachments. Remove this once that is fixed. - Initialise global camel_object_type */ + /* Initialize Camel's type system. */ camel_object_get_type(); - bonobo_main (); + gtk_main (); - bonobo_object_unref (BONOBO_OBJECT (factory)); - factory = NULL; - - if (alarm_notify_service) - bonobo_object_unref (BONOBO_OBJECT (alarm_notify_service)); + if (alarm_notify_service != NULL) + g_object_unref (alarm_notify_service); alarm_done (); e_passwords_shutdown (); +exit: + g_object_unref (app); + return 0; } -- cgit v1.2.3