From cef5a8ef5751c157817f3e132e3f0b18ce48d919 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 31 Jan 2011 12:58:24 -0500 Subject: Port AlarmNotify to GtkApplication. --- calendar/gui/alarm-notify/alarm-notify.c | 73 ++++++++++++++++++-------------- calendar/gui/alarm-notify/alarm-notify.h | 5 ++- calendar/gui/alarm-notify/notify-main.c | 53 +++-------------------- 3 files changed, 52 insertions(+), 79 deletions(-) (limited to 'calendar') diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c index 2a75d7943c..26c84bb056 100644 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ b/calendar/gui/alarm-notify/alarm-notify.c @@ -25,15 +25,20 @@ #endif #include +#include #include #include #include #include + +#include "alarm.h" #include "alarm-notify.h" #include "alarm-queue.h" #include "config-data.h" #include "common/authentication.h" +#define APPLICATION_ID "org.gnome.EvolutionAlarmNotify" + struct _AlarmNotifyPrivate { /* Mapping from EUri's to LoadedClient structures */ /* FIXME do we need per source type uri hashes? or perhaps we @@ -50,7 +55,7 @@ typedef struct { GList *removals; } ProcessRemovalsData; -static gpointer parent_class; +G_DEFINE_TYPE (AlarmNotify, alarm_notify, GTK_TYPE_APPLICATION) static void process_removal_in_hash (const gchar *uri, @@ -214,23 +219,53 @@ alarm_notify_finalize (GObject *object) } alarm_queue_done (); + alarm_done (); + + e_passwords_shutdown (); g_mutex_free (priv->mutex); /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (alarm_notify_parent_class)->finalize (object); +} + +static void +alarm_notify_startup (GApplication *application) +{ + GtkIconTheme *icon_theme; + + /* Chain up to parent's startup() method. */ + G_APPLICATION_CLASS (alarm_notify_parent_class)->startup (application); + + /* Keep the application running. */ + g_application_hold (application); + + config_data_init_debugging (); + + /* FIXME Ideally we should not use Camel libraries in calendar, + * though it is the case currently for attachments. Remove + * this once that is fixed. */ + + /* Initialize Camel's type system. */ + camel_object_get_type (); + + icon_theme = gtk_icon_theme_get_default (); + gtk_icon_theme_append_search_path (icon_theme, EVOLUTION_ICONDIR); } static void alarm_notify_class_init (AlarmNotifyClass *class) { GObjectClass *object_class; + GApplicationClass *application_class; - parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (AlarmNotifyPrivate)); - object_class = (GObjectClass *) class; + object_class = G_OBJECT_CLASS (class); object_class->finalize = alarm_notify_finalize; + + application_class = G_APPLICATION_CLASS (class); + application_class->startup = alarm_notify_startup; } static void @@ -262,32 +297,6 @@ alarm_notify_get_selected_calendars (AlarmNotify *an) return an->priv->selected_calendars; } -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); - } - - return type; -} - /** * alarm_notify_new: * @@ -298,7 +307,9 @@ alarm_notify_get_type (void) AlarmNotify * alarm_notify_new (void) { - return g_object_new (TYPE_ALARM_NOTIFY, NULL); + return g_object_new ( + TYPE_ALARM_NOTIFY, + "application-id", APPLICATION_ID, NULL); } static void diff --git a/calendar/gui/alarm-notify/alarm-notify.h b/calendar/gui/alarm-notify/alarm-notify.h index b3fb47990a..de7e0398a6 100644 --- a/calendar/gui/alarm-notify/alarm-notify.h +++ b/calendar/gui/alarm-notify/alarm-notify.h @@ -26,6 +26,7 @@ #ifndef ALARM_NOTIFY_H #define ALARM_NOTIFY_H +#include #include /* Standard GObject macros */ @@ -54,12 +55,12 @@ typedef struct _AlarmNotifyClass AlarmNotifyClass; typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate; struct _AlarmNotify { - GObject parent; + GtkApplication parent; AlarmNotifyPrivate *priv; }; struct _AlarmNotifyClass { - GObjectClass parent_class; + GtkApplicationClass parent_class; }; GType alarm_notify_get_type (void); diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c index 848323b7a5..db74af8e9a 100644 --- a/calendar/gui/alarm-notify/notify-main.c +++ b/calendar/gui/alarm-notify/notify-main.c @@ -23,22 +23,10 @@ * */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include +#include #include -#include -#include -#include -#include -#include "alarm.h" -#include "alarm-queue.h" #include "alarm-notify.h" -#include "config-data.h" #ifdef G_OS_WIN32 #include @@ -56,9 +44,8 @@ gint main (gint argc, gchar **argv) { - GtkIconTheme *icon_theme; AlarmNotify *alarm_notify_service; - UniqueApp *app; + gint exit_status; #ifdef G_OS_WIN32 gchar *path; @@ -87,7 +74,7 @@ main (gint argc, gchar **argv) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); - g_thread_init (NULL); + gtk_init (&argc, &argv); #ifdef G_OS_WIN32 path = g_build_path (";", _e_get_bindir (), g_getenv ("PATH"), NULL); @@ -96,38 +83,12 @@ main (gint argc, gchar **argv) g_warning ("Could not set PATH for Evolution Alarm Notifier"); #endif - gtk_init (&argc, &argv); - - app = unique_app_new ("org.gnome.EvolutionAlarmNotify", NULL); - - if (unique_app_is_running (app)) - goto exit; - - config_data_init_debugging (); - alarm_notify_service = alarm_notify_new (); - /* FIXME Ideally we should not use camel libraries in calendar, - * though it is the case currently for attachments. Remove - * this once that is fixed. */ - - /* Initialize Camel's type system. */ - camel_object_get_type (); - - icon_theme = gtk_icon_theme_get_default (); - gtk_icon_theme_append_search_path (icon_theme, EVOLUTION_ICONDIR); - - gtk_main (); - - if (alarm_notify_service != NULL) - g_object_unref (alarm_notify_service); - - alarm_done (); - - e_passwords_shutdown (); + exit_status = g_application_run ( + G_APPLICATION (alarm_notify_service), argc, argv); -exit: - g_object_unref (app); + g_object_unref (alarm_notify_service); - return 0; + return exit_status; } -- cgit v1.2.3