[evolution] Make sure evolution-alarm-notify is running on Evolution's start



commit 350f7118fec5b5d7bcf6a6c40d2fba6bedaf512e
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 30 15:37:11 2012 +0200

    Make sure evolution-alarm-notify is running on Evolution's start

 calendar/alarm-notify/alarm-notify.c   |   27 +++++++++++++++------------
 calendar/alarm-notify/notify-main.c    |   14 ++++++++++++++
 modules/calendar/Makefile.am           |    2 ++
 modules/calendar/e-cal-shell-backend.c |   32 ++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 12 deletions(-)
---
diff --git a/calendar/alarm-notify/alarm-notify.c b/calendar/alarm-notify/alarm-notify.c
index 3738a7c..dc588b7 100644
--- a/calendar/alarm-notify/alarm-notify.c
+++ b/calendar/alarm-notify/alarm-notify.c
@@ -135,19 +135,12 @@ alarm_notify_startup (GApplication *application)
 static void
 alarm_notify_activate (GApplication *application)
 {
-	/* Disregard.  This is just here to prevent the default
-	 * activate method from running, which issues a warning
-	 * if there are no handlers connected to this signal. */
-}
+	AlarmNotify *an = ALARM_NOTIFY (application);
 
-static gboolean
-alarm_notify_initable (GInitable *initable,
-                       GCancellable *cancellable,
-                       GError **error)
-{
-	AlarmNotify *an = ALARM_NOTIFY (initable);
-
-	an->priv->registry = e_source_registry_new_sync (cancellable, error);
+	if (g_application_get_is_remote (application)) {
+		g_application_quit (application);
+		return;
+	}
 
 	if (an->priv->registry != NULL) {
 		alarm_notify_load_calendars (an);
@@ -160,6 +153,16 @@ alarm_notify_initable (GInitable *initable,
 			an->priv->registry, "source-removed",
 			G_CALLBACK (alarm_notify_remove_calendar), an);
 	}
+}
+
+static gboolean
+alarm_notify_initable (GInitable *initable,
+                       GCancellable *cancellable,
+                       GError **error)
+{
+	AlarmNotify *an = ALARM_NOTIFY (initable);
+
+	an->priv->registry = e_source_registry_new_sync (cancellable, error);
 
 	return (an->priv->registry != NULL);
 }
diff --git a/calendar/alarm-notify/notify-main.c b/calendar/alarm-notify/notify-main.c
index 2b04104..c112331 100644
--- a/calendar/alarm-notify/notify-main.c
+++ b/calendar/alarm-notify/notify-main.c
@@ -99,6 +99,20 @@ main (gint argc,
 		exit (EXIT_FAILURE);
 	}
 
+	g_application_register (G_APPLICATION (alarm_notify_service), NULL, &error);
+
+	if (error != NULL) {
+		g_printerr ("%s\n", error->message);
+		g_error_free (error);
+		g_object_unref (alarm_notify_service);
+		exit (EXIT_FAILURE);
+	}
+
+	if (g_application_get_is_remote (G_APPLICATION (alarm_notify_service))) {
+		g_object_unref (alarm_notify_service);
+		return 0;
+	}
+
 	exit_status = g_application_run (
 		G_APPLICATION (alarm_notify_service), argc, argv);
 
diff --git a/modules/calendar/Makefile.am b/modules/calendar/Makefile.am
index 0bcc72c..c5e5475 100644
--- a/modules/calendar/Makefile.am
+++ b/modules/calendar/Makefile.am
@@ -3,6 +3,8 @@ module_LTLIBRARIES = module-calendar.la
 module_calendar_la_CPPFLAGS = \
 	$(AM_CPPFLAGS)					\
 	-DG_LOG_DOMAIN=\"calendar-modules\"		\
+	-DEVOLUTION_BINDIR=\""$(bindir)"\"		\
+	-DEVOLUTION_PRIVLIBEXECDIR=\""$(PRIVLIBEXECDIR)"\" \
 	-I$(top_srcdir)					\
 	-I$(top_srcdir)/widgets				\
 	-DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\"	\
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index 44179dc..cb5fb24 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -564,6 +564,36 @@ cal_shell_backend_window_added_cb (EShellBackend *shell_backend,
 }
 
 static void
+ensure_alarm_notify_is_running (void)
+{
+	const gchar *base_dir;
+	gchar *filename;
+
+	#ifdef G_OS_WIN32
+	base_dir = EVOLUTION_BINDIR;
+	#else
+	base_dir = EVOLUTION_PRIVLIBEXECDIR;
+	#endif
+
+	filename = g_build_filename (base_dir, "evolution-alarm-notify", NULL);
+
+	if (g_file_test (filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE)) {
+		gchar *argv[2];
+		GError *error = NULL;
+
+		argv[0] = filename;
+		argv[1] = NULL;
+
+		if (!g_spawn_async (base_dir, argv, NULL, 0, NULL, NULL, NULL, &error))
+			g_message ("Failed to start '%s': %s", filename, error ? error->message : "Unknown error");
+
+		g_clear_error (&error);
+	}
+
+	g_free (filename);
+}
+
+static void
 cal_shell_backend_constructed (GObject *object)
 {
 	EShell *shell;
@@ -607,6 +637,8 @@ cal_shell_backend_constructed (GObject *object)
 
 	/* Chain up to parent's constructed() method. */
 	G_OBJECT_CLASS (e_cal_shell_backend_parent_class)->constructed (object);
+
+	ensure_alarm_notify_is_running ();
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]