From 2c1887f5fed391efb16a1f5084a5a9016bd73f32 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Sun, 24 Jun 2001 22:53:14 +0000 Subject: Converted to use BonoboXObject. 2001-06-24 Federico Mena Quintero * gui/alarm-notify/alarm-notify.c: Converted to use BonoboXObject. * gui/gnome-cal.c (gnome_calendar_open): Ask the alarm notification service to add the calendar and tasks URIs. (add_alarms): New function. * gui/alarm-notify/notify-main.c (main): Doh, fixed typo in the OAFIID. (main): Initialize and shut down gnome-vfs. * gui/Makefile.am (IDLS): Added evolution-calendar.idl, sigh. (evolution_calendar_SOURCES): Added the files generated from the IDL. * gui/alarm-notify/alarm-queue.c (alarm_trigger_cb): New function used when an alarm is triggered. * gui/dialogs/Makefile.am: Removed the alarm-notify-dialog files; they are now in gui/alarm-notify. * gui/alarm-notify/Makefile.am: Added the alarm-notify-dialog files. * pcs/cal.c (cal_forget_password): This was incorrectly named cal_client_forget_password(); renamed it. * gui/main.c (main): Initialize and shut down gnome-vfs. svn path=/trunk/; revision=10453 --- calendar/gui/Makefile.am | 17 +- calendar/gui/alarm-notify.c | 963 ------------------------ calendar/gui/alarm-notify.h | 35 - calendar/gui/alarm-notify/Makefile.am | 8 +- calendar/gui/alarm-notify/alarm-notify-dialog.h | 3 +- calendar/gui/alarm-notify/alarm-notify.c | 161 +--- calendar/gui/alarm-notify/alarm-notify.h | 14 +- calendar/gui/alarm-notify/alarm-queue.c | 49 +- calendar/gui/alarm-notify/notify-main.c | 10 +- calendar/gui/calendar-model.c | 10 +- calendar/gui/dialogs/Makefile.am | 3 - calendar/gui/dialogs/alarm-notify-dialog.c | 231 ------ calendar/gui/dialogs/alarm-notify-dialog.h | 45 -- calendar/gui/dialogs/alarm-notify.glade | 228 ------ calendar/gui/e-tasks.c | 7 - calendar/gui/gnome-cal.c | 72 +- calendar/gui/main.c | 7 + calendar/gui/tasks-control.c | 1 + 18 files changed, 172 insertions(+), 1692 deletions(-) delete mode 100644 calendar/gui/alarm-notify.c delete mode 100644 calendar/gui/alarm-notify.h delete mode 100644 calendar/gui/dialogs/alarm-notify-dialog.c delete mode 100644 calendar/gui/dialogs/alarm-notify-dialog.h delete mode 100644 calendar/gui/dialogs/alarm-notify.glade (limited to 'calendar/gui') diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index b801ca42a3..e3ec865d98 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -1,8 +1,9 @@ ## CORBA stuff -IDLS = \ - $(top_srcdir)/composer/Evolution-Composer.idl \ - $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl +IDLS = \ + $(top_srcdir)/composer/Evolution-Composer.idl \ + $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl \ + $(top_srcdir)/calendar/idl/evolution-calendar.idl IDL_GENERATED = \ Evolution-Composer.h \ @@ -12,13 +13,19 @@ IDL_GENERATED = \ Evolution-Addressbook-SelectNames.h \ Evolution-Addressbook-SelectNames-common.c \ Evolution-Addressbook-SelectNames-skels.c \ - Evolution-Addressbook-SelectNames-stubs.c + Evolution-Addressbook-SelectNames-stubs.c \ + evolution-calendar.h \ + evolution-calendar-common.c \ + evolution-calendar-skels.c \ + evolution-calendar-stubs.c -$(IDL_GENERATED): $(IDLS) +$(IDL_GENERATED): $(IDLS) $(ORBIT_IDL) -I $(srcdir) -I $(datadir)/idl `$(GNOME_CONFIG) --cflags idl` \ $(srcdir)/../../composer/Evolution-Composer.idl $(ORBIT_IDL) -I $(srcdir) -I $(datadir)/idl `$(GNOME_CONFIG) --cflags idl` \ $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl + $(ORBIT_IDL) -I $(srcdir) -I $(datadir)/idl `$(GNOME_CONFIG) --cflags idl` \ + $(top_srcdir)/calendar/idl/evolution-calendar.idl SUBDIRS = alarm-notify dialogs diff --git a/calendar/gui/alarm-notify.c b/calendar/gui/alarm-notify.c deleted file mode 100644 index ceb8cc0c81..0000000000 --- a/calendar/gui/alarm-notify.c +++ /dev/null @@ -1,963 +0,0 @@ -/* Evolution calendar - Alarm notification engine - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Federico Mena-Quintero - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include "alarm.h" -#include "alarm-notify.h" - - - -/* Whether the notification system has been initialized */ -static gboolean alarm_notify_inited; - -/* Clients we are monitoring for alarms */ -static GHashTable *client_alarms_hash = NULL; - -/* Structure that stores a client we are monitoring */ -typedef struct { - /* Monitored client */ - CalClient *client; - - /* Number of times this client has been registered */ - int refcount; - - /* Hash table of component UID -> CompQueuedAlarms. If an element is - * present here, then it means its cqa->queued_alarms contains at least - * one queued alarm. When all the alarms for a component have been - * dequeued, the CompQueuedAlarms structure is removed from the hash - * table. Thus a CQA exists <=> it has queued alarms. - */ - GHashTable *uid_alarms_hash; -} ClientAlarms; - -/* Pair of a CalComponentAlarms and the mapping from queued alarm IDs to the - * actual alarm instance structures. - */ -typedef struct { - /* The parent client alarms structure */ - ClientAlarms *parent_client; - - /* The actual component and its alarm instances */ - CalComponentAlarms *alarms; - - /* List of QueuedAlarm structures */ - GSList *queued_alarms; -} CompQueuedAlarms; - -/* Pair of a queued alarm ID and the alarm trigger instance it refers to */ -typedef struct { - /* Alarm ID from alarm.h */ - gpointer alarm_id; - - /* Instance from our parent CompAlarms->alarms list */ - CalAlarmInstance *instance; -} QueuedAlarm; - -/* Alarm ID for the midnight refresh function */ -static gpointer midnight_refresh_id = NULL; - - - -static void load_alarms (ClientAlarms *ca); -static void midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data); - -/* Queues an alarm trigger for midnight so that we can load the next day's worth - * of alarms. - */ -static void -queue_midnight_refresh (void) -{ - time_t midnight; - - g_assert (midnight_refresh_id == NULL); - - midnight = time_day_end (time (NULL)); - - midnight_refresh_id = alarm_add (midnight, midnight_refresh_cb, NULL, NULL); - if (!midnight_refresh_id) { - g_message ("alarm_notify_init(): Could not set up the midnight refresh alarm!"); - /* FIXME: what to do? */ - } -} - -/* Loads a client's alarms; called from g_hash_table_foreach() */ -static void -add_client_alarms_cb (gpointer key, gpointer value, gpointer data) -{ - ClientAlarms *ca; - - ca = value; - load_alarms (ca); -} - -/* Loads the alarms for the new day every midnight */ -static void -midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - /* Re-load the alarms for all clients */ - - g_hash_table_foreach (client_alarms_hash, add_client_alarms_cb, NULL); - - /* Re-schedule the midnight update */ - - midnight_refresh_id = NULL; - queue_midnight_refresh (); -} - -/* Looks up a client in the client alarms hash table */ -static ClientAlarms * -lookup_client (CalClient *client) -{ - return g_hash_table_lookup (client_alarms_hash, client); -} - -/* Callback used when an alarm triggers */ -static void -alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - CompQueuedAlarms *cqa; - - cqa = data; - - /* FIXME */ - - g_message ("alarm_trigger_cb(): Triggered!"); -} - -/* Callback used when an alarm must be destroyed */ -static void -alarm_destroy_cb (gpointer alarm_id, gpointer data) -{ - CompQueuedAlarms *cqa; - GSList *l; - QueuedAlarm *qa; - const char *uid; - - cqa = data; - - qa = NULL; /* Keep GCC happy */ - - /* Find the alarm in the queued alarms */ - - for (l = cqa->queued_alarms; l; l = l->next) { - qa = l->data; - if (qa->alarm_id == alarm_id) - break; - } - - g_assert (l != NULL); - - /* Remove it and free it */ - - cqa->queued_alarms = g_slist_remove_link (cqa->queued_alarms, l); - g_slist_free_1 (l); - - g_free (qa); - - /* If this was the last queued alarm for this component, remove the - * component itself. - */ - - if (cqa->queued_alarms != NULL) - return; - - cal_component_get_uid (cqa->alarms->comp, &uid); - g_hash_table_remove (cqa->parent_client->uid_alarms_hash, uid); - cqa->parent_client = NULL; - - cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - - g_free (cqa); -} - -/* Adds the alarms in a CalComponentAlarms structure to the alarms queued for a - * particular client. Also puts the triggers in the alarm timer queue. - */ -static void -add_component_alarms (ClientAlarms *ca, CalComponentAlarms *alarms) -{ - const char *uid; - CompQueuedAlarms *cqa; - GSList *l; - - /* No alarms? */ - if (alarms->alarms == NULL) { - cal_component_alarms_free (alarms); - return; - } - - cqa = g_new (CompQueuedAlarms, 1); - cqa->parent_client = ca; - cqa->alarms = alarms; - - cqa->queued_alarms = NULL; - - for (l = alarms->alarms; l; l = l->next) { - CalAlarmInstance *instance; - gpointer alarm_id; - QueuedAlarm *qa; - - instance = l->data; - - alarm_id = alarm_add (instance->trigger, alarm_trigger_cb, cqa, alarm_destroy_cb); - if (!alarm_id) { - g_message ("add_component_alarms(): Could not schedule a trigger for " - "%ld, discarding...", (long) instance->trigger); - continue; - } - - qa = g_new (QueuedAlarm, 1); - qa->alarm_id = alarm_id; - qa->instance = instance; - - cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa); - } - - cal_component_get_uid (alarms->comp, &uid); - - /* If we failed to add all the alarms, then we should get rid of the cqa */ - if (cqa->queued_alarms == NULL) { - g_message ("add_component_alarms(): Could not add any of the alarms " - "for the component `%s'; discarding it...", uid); - - cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - - g_free (cqa); - return; - } - - cqa->queued_alarms = g_slist_reverse (cqa->queued_alarms); - g_hash_table_insert (ca->uid_alarms_hash, (char *) uid, cqa); -} - -/* Loads today's remaining alarms for a client */ -static void -load_alarms (ClientAlarms *ca) -{ - time_t now, day_end; - GSList *comp_alarms; - GSList *l; - - now = time (NULL); - day_end = time_day_end (now); - - comp_alarms = cal_client_get_alarms_in_range (ca->client, now, day_end); - - /* All of the last day's alarms should have already triggered and should - * have been removed, so we should have no pending components. - */ - g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0); - - for (l = comp_alarms; l; l = l->next) { - CalComponentAlarms *alarms; - - alarms = l->data; - add_component_alarms (ca, alarms); - } - - g_slist_free (comp_alarms); -} - -/* Called when a calendar client finished loading; we load its alarms */ -static void -cal_loaded_cb (CalClient *client, CalClientLoadStatus status, gpointer data) -{ - ClientAlarms *ca; - - ca = data; - - if (status != CAL_CLIENT_LOAD_SUCCESS) - return; - - load_alarms (ca); -} - -/* Looks up a component's queued alarm structure in a client alarms structure */ -static CompQueuedAlarms * -lookup_comp_queued_alarms (ClientAlarms *ca, const char *uid) -{ - return g_hash_table_lookup (ca->uid_alarms_hash, uid); -} - -/* Removes a component an its alarms */ -static void -remove_comp (ClientAlarms *ca, const char *uid) -{ - CompQueuedAlarms *cqa; - GSList *l; - - cqa = lookup_comp_queued_alarms (ca, uid); - if (!cqa) - return; - - /* If a component is present, then it means we must have alarms queued - * for it. - */ - g_assert (cqa->queued_alarms != NULL); - - for (l = cqa->queued_alarms; l;) { - QueuedAlarm *qa; - - qa = l->data; - - /* Get the next element here because the list element will go - * away. Also, we do not free the qa here because it will be - * freed by the destroy notification function. - */ - l = l->next; - - alarm_remove (qa->alarm_id); - } - - /* The list should be empty now, and thus the queued component alarms - * structure should have been freed and removed from the hash table. - */ - g_assert (lookup_comp_queued_alarms (ca, uid) == NULL); -} - -/* Called when a calendar component changes; we must reload its corresponding - * alarms. - */ -static void -obj_updated_cb (CalClient *client, const char *uid, gpointer data) -{ - ClientAlarms *ca; - time_t now, day_end; - CalComponentAlarms *alarms; - gboolean found; - - ca = data; - - remove_comp (ca, uid); - - now = time (NULL); - day_end = time_day_end (now); - - found = cal_client_get_alarms_for_object (ca->client, uid, now, day_end, &alarms); - - if (!found) - return; - - add_component_alarms (ca, alarms); -} - -/* Called when a calendar component is removed; we must delete its corresponding - * alarms. - */ -static void -obj_removed_cb (CalClient *client, const char *uid, gpointer data) -{ - ClientAlarms *ca; - - ca = data; - - remove_comp (ca, uid); -} - - - -/** - * alarm_notify_init: - * - * Initializes the alarm notification system. This should be called near the - * beginning of the program, after calling alarm_init(). - **/ -void -alarm_notify_init (void) -{ - g_return_if_fail (alarm_notify_inited == FALSE); - - client_alarms_hash = g_hash_table_new (g_direct_hash, g_direct_equal); - queue_midnight_refresh (); - - alarm_notify_inited = TRUE; -} - -/** - * alarm_notify_done: - * - * Shuts down the alarm notification system. This should be called near the end - * of the program. All the monitored calendar clients should already have been - * unregistered with alarm_notify_remove_client(). - **/ -void -alarm_notify_done (void) -{ - g_return_if_fail (alarm_notify_inited); - - /* All clients must be unregistered by now */ - g_return_if_fail (g_hash_table_size (client_alarms_hash) == 0); - - g_hash_table_destroy (client_alarms_hash); - client_alarms_hash = NULL; - - g_assert (midnight_refresh_id != NULL); - alarm_remove (midnight_refresh_id); - midnight_refresh_id = NULL; - - alarm_notify_inited = FALSE; -} - -/** - * alarm_notify_add_client: - * @client: A calendar client. - * - * Adds a calendar client to the alarm notification system. Alarm trigger - * notifications will be presented at the appropriate times. The client should - * be removed with alarm_notify_remove_client() when receiving notifications - * from it is no longer desired. - * - * A client can be added any number of times to the alarm notification system, - * but any single alarm trigger will only be presented once for a particular - * client. The client must still be removed the same number of times from the - * notification system when it is no longer wanted. - **/ -void -alarm_notify_add_client (CalClient *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_notify_inited); - g_return_if_fail (client != NULL); - g_return_if_fail (IS_CAL_CLIENT (client)); - - ca = lookup_client (client); - if (ca) { - ca->refcount++; - return; - } - - ca = g_new (ClientAlarms, 1); - - ca->client = client; - gtk_object_ref (GTK_OBJECT (ca->client)); - - ca->refcount = 1; - g_hash_table_insert (client_alarms_hash, client, ca); - - ca->uid_alarms_hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (!cal_client_is_loaded (client)) - gtk_signal_connect (GTK_OBJECT (client), "cal_loaded", - GTK_SIGNAL_FUNC (cal_loaded_cb), ca); - - gtk_signal_connect (GTK_OBJECT (client), "obj_updated", - GTK_SIGNAL_FUNC (obj_updated_cb), ca); - gtk_signal_connect (GTK_OBJECT (client), "obj_removed", - GTK_SIGNAL_FUNC (obj_removed_cb), ca); - - if (cal_client_is_loaded (client)) - load_alarms (ca); -} - -/* Called from g_hash_table_foreach(); adds a component UID to a list */ -static void -add_uid_cb (gpointer key, gpointer value, gpointer data) -{ - GSList **uids; - const char *uid; - - uids = data; - uid = key; - - *uids = g_slist_prepend (*uids, (char *) uid); -} - -/* Removes all the alarms queued for a particular calendar client */ -static void -remove_client_alarms (ClientAlarms *ca) -{ - GSList *uids; - GSList *l; - - /* First we build a list of UIDs so that we can remove them one by one */ - - uids = NULL; - g_hash_table_foreach (ca->uid_alarms_hash, add_uid_cb, &uids); - - for (l = uids; l; l = l->next) { - const char *uid; - - uid = l->data; - - remove_comp (ca, uid); - } - - g_slist_free (uids); - - /* The hash table should be empty now */ - - g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0); -} - -/** - * alarm_notify_remove_client: - * @client: A calendar client. - * - * Removes a calendar client from the alarm notification system. - **/ -void -alarm_notify_remove_client (CalClient *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_notify_inited); - g_return_if_fail (client != NULL); - g_return_if_fail (IS_CAL_CLIENT (client)); - - ca = lookup_client (client); - g_return_if_fail (ca != NULL); - - g_assert (ca->refcount > 0); - ca->refcount--; - - if (ca->refcount > 0) - return; - - remove_client_alarms (ca); - - /* Clean up */ - - gtk_signal_disconnect_by_data (GTK_OBJECT (ca->client), ca); - - gtk_object_unref (GTK_OBJECT (ca->client)); - ca->client = NULL; - - g_hash_table_destroy (ca->uid_alarms_hash); - ca->uid_alarms_hash = NULL; - - g_free (ca); - - g_hash_table_remove (client_alarms_hash, client); -} - - - -#if 0 - -/* Sends a mail notification of an alarm trigger */ -static void -mail_notification (char *mail_address, char *text, time_t app_time) -{ - pid_t pid; - int p [2]; - char *command; - - pipe (p); - pid = fork (); - if (pid == 0){ - int dev_null; - - dev_null = open ("/dev/null", O_RDWR); - dup2 (p [0], 0); - dup2 (dev_null, 1); - dup2 (dev_null, 2); - execl ("/usr/lib/sendmail", "/usr/lib/sendmail", - mail_address, NULL); - _exit (127); - } - command = g_strconcat ("To: ", mail_address, "\n", - "Subject: ", _("Reminder of your appointment at "), - ctime (&app_time), "\n\n", text, "\n", NULL); - write (p [1], command, strlen (command)); - close (p [1]); - close (p [0]); - g_free (command); -} - -static int -max_open_files (void) -{ - static int files; - - if (files) - return files; - - files = sysconf (_SC_OPEN_MAX); - if (files != -1) - return files; -#ifdef OPEN_MAX - return files = OPEN_MAX; -#else - return files = 256; -#endif -} - -/* Executes a program as a notification of an alarm trigger */ -static void -program_notification (char *command, int close_standard) -{ - struct sigaction ignore, save_intr, save_quit; - int status = 0, i; - pid_t pid; - - ignore.sa_handler = SIG_IGN; - sigemptyset (&ignore.sa_mask); - ignore.sa_flags = 0; - - sigaction (SIGINT, &ignore, &save_intr); - sigaction (SIGQUIT, &ignore, &save_quit); - - if ((pid = fork ()) < 0){ - fprintf (stderr, "\n\nfork () = -1\n"); - return; - } - if (pid == 0){ - pid = fork (); - if (pid == 0){ - const int top = max_open_files (); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); - - for (i = (close_standard ? 0 : 3); i < top; i++) - close (i); - - /* FIXME: As an excercise to the reader, copy the - * code from mc to setup shell properly instead of - * /bin/sh. Yes, this comment is larger than a cut and paste. - */ - execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0); - - _exit (127); - } else { - _exit (127); - } - } - wait (&status); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); -} - -/* Queues a snooze alarm */ -static void -snooze (GnomeCalendar *gcal, CalComponent *comp, time_t occur, int snooze_mins, gboolean audio) -{ - time_t now, trigger; - struct tm tm; - CalAlarmInstance ai; - - now = time (NULL); - tm = *localtime (&now); - tm.tm_min += snooze_mins; - - trigger = mktime (&tm); - if (trigger == -1) { - g_message ("snooze(): produced invalid time_t; not queueing alarm!"); - return; - } - -#if 0 - cal_component_get_uid (comp, &ai.uid); - ai.type = audio ? ALARM_AUDIO : ALARM_DISPLAY; -#endif - ai.trigger = trigger; - ai.occur = occur; - - setup_alarm (gcal, &ai); -} - -struct alarm_notify_closure { - GnomeCalendar *gcal; - CalComponent *comp; - time_t occur; -}; - -/* Callback used for the result of the alarm notification dialog */ -static void -display_notification_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) -{ - struct alarm_notify_closure *c; - - c = data; - - switch (result) { - case ALARM_NOTIFY_CLOSE: - break; - - case ALARM_NOTIFY_SNOOZE: - snooze (c->gcal, c->comp, c->occur, snooze_mins, FALSE); - break; - - case ALARM_NOTIFY_EDIT: - gnome_calendar_edit_object (c->gcal, c->comp); - break; - - default: - g_assert_not_reached (); - } - - gtk_object_unref (GTK_OBJECT (c->comp)); - g_free (c); -} - -/* Present a display notification of an alarm trigger */ -static void -display_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) -{ - gboolean result; - struct alarm_notify_closure *c; - - gtk_object_ref (GTK_OBJECT (comp)); - - c = g_new (struct alarm_notify_closure, 1); - c->gcal = gcal; - c->comp = comp; - c->occur = occur; - - result = alarm_notify_dialog (trigger, occur, comp, display_notification_cb, c); - if (!result) { - g_message ("display_notification(): could not display the alarm notification dialog"); - g_free (c); - gtk_object_unref (GTK_OBJECT (comp)); - } -} - -/* Present an audible notification of an alarm trigger */ -static void -audio_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) -{ - g_message ("AUDIO NOTIFICATION!"); - /* FIXME */ -} - -/* Callback function used when an alarm is triggered */ -static void -trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - struct trigger_alarm_closure *c; - GnomeCalendarPrivate *priv; - CalComponent *comp; - CalClientGetStatus status; - const char *uid; - ObjectAlarms *oa; - GList *l; - - c = data; - priv = c->gcal->priv; - - /* Fetch the object */ - - status = cal_client_get_object (priv->client, c->uid, &comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* Go on */ - break; - case CAL_CLIENT_GET_SYNTAX_ERROR: - case CAL_CLIENT_GET_NOT_FOUND: - g_message ("trigger_alarm_cb(): syntax error in fetched object"); - return; - } - - g_assert (comp != NULL); - - /* Present notification */ - - switch (c->type) { - case CAL_COMPONENT_ALARM_EMAIL: -#if 0 - g_assert (ico->malarm.enabled); - mail_notification (ico->malarm.data, ico->summary, c->occur); -#endif - break; - - case CAL_COMPONENT_ALARM_PROCEDURE: -#if 0 - g_assert (ico->palarm.enabled); - program_notification (ico->palarm.data, FALSE); -#endif - break; - - case CAL_COMPONENT_ALARM_DISPLAY: -#if 0 - g_assert (ico->dalarm.enabled); -#endif - display_notification (trigger, c->occur, comp, c->gcal); - break; - - case CAL_COMPONENT_ALARM_AUDIO: -#if 0 - g_assert (ico->aalarm.enabled); -#endif - audio_notification (trigger, c->occur, comp, c->gcal); - break; - - default: - break; - } - - /* Remove the alarm from the hash table */ - cal_component_get_uid (comp, &uid); - oa = g_hash_table_lookup (priv->alarms, uid); - g_assert (oa != NULL); - - l = g_list_find (oa->alarm_ids, alarm_id); - g_assert (l != NULL); - - oa->alarm_ids = g_list_remove_link (oa->alarm_ids, l); - g_list_free_1 (l); - - if (!oa->alarm_ids) { - g_hash_table_remove (priv->alarms, uid); - g_free (oa->uid); - g_free (oa); - } - - gtk_object_unref (GTK_OBJECT (comp)); -} - -#endif - -#if 0 - -static void -stop_beeping (GtkObject* object, gpointer data) -{ - guint timer_tag, beep_tag; - timer_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "timer_tag")); - beep_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "beep_tag")); - - if (beep_tag > 0) { - gtk_timeout_remove (beep_tag); - gtk_object_set_data (object, "beep_tag", GINT_TO_POINTER (0)); - } - if (timer_tag > 0) { - gtk_timeout_remove (timer_tag); - gtk_object_set_data (object, "timer_tag", GINT_TO_POINTER (0)); - } -} - -static gint -start_beeping (gpointer data) -{ - gdk_beep (); - - return TRUE; -} - -static gint -timeout_beep (gpointer data) -{ - stop_beeping (data, NULL); - return FALSE; -} - -void -calendar_notify (time_t activation_time, CalendarAlarm *which, void *data) -{ - iCalObject *ico = data; - guint beep_tag, timer_tag; - int ret; - gchar* snooze_button = (enable_snooze ? _("Snooze") : NULL); - time_t now, diff; - - if (&ico->aalarm == which){ - time_t app = ico->aalarm.trigger + ico->aalarm.offset; - GtkWidget *w; - char *msg; - - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - - /* Idea: we need Snooze option :-) */ - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, _("Ok"), snooze_button, NULL); - beep_tag = gtk_timeout_add (1000, start_beeping, NULL); - if (enable_aalarm_timeout) - timer_tag = gtk_timeout_add (audio_alarm_timeout*1000, - timeout_beep, w); - else - timer_tag = 0; - gtk_object_set_data (GTK_OBJECT (w), "timer_tag", - GINT_TO_POINTER (timer_tag)); - gtk_object_set_data (GTK_OBJECT (w), "beep_tag", - GINT_TO_POINTER (beep_tag)); - gtk_widget_ref (w); - gtk_window_set_modal (GTK_WINDOW (w), FALSE); - ret = gnome_dialog_run (GNOME_DIALOG (w)); - switch (ret) { - case 1: - stop_beeping (GTK_OBJECT (w), NULL); - now = time (NULL); - diff = now - which->trigger; - which->trigger = which->trigger + diff + snooze_secs; - which->offset = which->offset - diff - snooze_secs; - alarm_add (which, &calendar_notify, data); - break; - default: - stop_beeping (GTK_OBJECT (w), NULL); - break; - } - - gtk_widget_unref (w); - return; - } - - if (&ico->palarm == which){ - execute (ico->palarm.data, 0); - return; - } - - if (&ico->malarm == which){ - time_t app = ico->malarm.trigger + ico->malarm.offset; - - mail_notify (ico->malarm.data, ico->summary, app); - return; - } - - if (&ico->dalarm == which){ - time_t app = ico->dalarm.trigger + ico->dalarm.offset; - GtkWidget *w; - char *msg; - - if (beep_on_display) - gdk_beep (); - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, - _("Ok"), snooze_button, NULL); - gtk_window_set_modal (GTK_WINDOW (w), FALSE); - ret = gnome_dialog_run (GNOME_DIALOG (w)); - switch (ret) { - case 1: - now = time (NULL); - diff = now - which->trigger; - which->trigger = which->trigger + diff + snooze_secs; - which->offset = which->offset - diff - snooze_secs; - alarm_add (which, &calendar_notify, data); - break; - default: - break; - } - - return; - } -} - -#endif diff --git a/calendar/gui/alarm-notify.h b/calendar/gui/alarm-notify.h deleted file mode 100644 index f33c2a130c..0000000000 --- a/calendar/gui/alarm-notify.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Evolution calendar - Alarm notification engine - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Federico Mena-Quintero - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef ALARM_NOTIFY_H -#define ALARM_NOTIFY_H - -#include - - -void alarm_notify_init (void); -void alarm_notify_done (void); - -void alarm_notify_add_client (CalClient *client); -void alarm_notify_remove_client (CalClient *client); - - -#endif diff --git a/calendar/gui/alarm-notify/Makefile.am b/calendar/gui/alarm-notify/Makefile.am index de0f4fb847..4176a71685 100644 --- a/calendar/gui/alarm-notify/Makefile.am +++ b/calendar/gui/alarm-notify/Makefile.am @@ -36,10 +36,15 @@ INCLUDES = \ gladedir = $(datadir)/evolution/glade +glade_DATA = \ + alarm-notify.glade + evolution_alarm_notify_SOURCES = \ $(CORBA_GENERATED) \ alarm-notify.c \ alarm-notify.h \ + alarm-notify-dialog.c \ + alarm-notify-dialog.h \ alarm-queue.c \ alarm-queue.h \ notify-main.c @@ -73,7 +78,8 @@ oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) EXTRA_DIST = \ $(oaf_DATA) \ - $(oaf_in_files) + $(oaf_in_files) \ + $(glade_DATA) BUILT_SOURCES = $(CORBA_GENERATED) CLEANFILES += $(BUILT_SOURCES) diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.h b/calendar/gui/alarm-notify/alarm-notify-dialog.h index a6715a7325..1b37a097aa 100644 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.h +++ b/calendar/gui/alarm-notify/alarm-notify-dialog.h @@ -1,7 +1,6 @@ /* Evolution calendar - alarm notification dialog * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. + * Copyright (C) 2001 Ximian, Inc. * * Author: Federico Mena-Quintero * diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c index f0824bd8f4..88d25dafbc 100644 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ b/calendar/gui/alarm-notify/alarm-notify.c @@ -1,7 +1,6 @@ /* Evolution calendar - Alarm notification service object * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. + * Copyright (C) 2001 Ximian, Inc. * * Author: Federico Mena-Quintero * @@ -59,50 +58,24 @@ static void alarm_notify_class_init (AlarmNotifyClass *class); static void alarm_notify_init (AlarmNotify *an); static void alarm_notify_destroy (GtkObject *object); -static POA_GNOME_Evolution_Calendar_AlarmNotify__vepv alarm_notify_vepv; +static void AlarmNotify_addCalendar (PortableServer_Servant servant, + const CORBA_char *str_uri, + CORBA_Environment *ev); +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 BonoboObjectClass *parent_class; - +static BonoboXObjectClass *parent_class; -/** - * alarm_notify_get_type: - * - * Registers the #AlarmNotify class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #AlarmNotify class. - **/ -GtkType -alarm_notify_get_type (void) -{ - static GtkType alarm_notify_type = 0; - - if (!alarm_notify_type) { - static const GtkTypeInfo alarm_notify_info = { - "AlarmNotify", - sizeof (AlarmNotify), - sizeof (AlarmNotifyClass), - (GtkClassInitFunc) alarm_notify_class_init, - (GtkObjectInitFunc) alarm_notify_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - alarm_notify_type = gtk_type_unique (BONOBO_OBJECT_TYPE, &alarm_notify_info); - } - - return alarm_notify_type; -} + -/* CORBA class initialization function for the alarm notify service */ -static void -init_alarm_notify_corba_class (void) -{ - alarm_notify_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - alarm_notify_vepv.GNOME_Evolution_Calendar_AlarmNotify_epv = alarm_notify_get_epv (); -} +BONOBO_X_TYPE_FUNC_FULL (AlarmNotify, + GNOME_Evolution_Calendar_AlarmNotify, + BONOBO_X_OBJECT_TYPE, + alarm_notify); /* Class initialization function for the alarm notify service */ static void @@ -112,11 +85,13 @@ alarm_notify_class_init (AlarmNotifyClass *class) object_class = (GtkObjectClass *) class; - parent_class = gtk_type_class (BONOBO_OBJECT_TYPE); + parent_class = gtk_type_class (BONOBO_X_OBJECT_TYPE); - object_class->destroy = alarm_notify_destroy; + class->epv.addCalendar = AlarmNotify_addCalendar; + class->epv.removeCalendar = AlarmNotify_removeCalendar; + class->epv.die = AlarmNotify_die; - init_alarm_notify_corba_class (); + object_class->destroy = alarm_notify_destroy; } /* Object initialization function for the alarm notify system */ @@ -290,85 +265,8 @@ AlarmNotify_die (PortableServer_Servant servant, /* FIXME */ } -/** - * alarm_notify_get_epv: - * - * Creates an EPV for the AlarmNotify CORBA class. - * - * Return value: A newly-allocated EPV. - **/ -POA_GNOME_Evolution_Calendar_AlarmNotify__epv * -alarm_notify_get_epv (void) -{ - POA_GNOME_Evolution_Calendar_AlarmNotify__epv *epv; - - epv = g_new0 (POA_GNOME_Evolution_Calendar_AlarmNotify__epv, 1); - epv->addCalendar = AlarmNotify_addCalendar; - epv->removeCalendar = AlarmNotify_removeCalendar; - epv->die = AlarmNotify_die; - return epv; -} - -/** - * alarm_notify_construct: - * @an: An alarm notification service object. - * @corba_an: CORBA object for the alarm notification service. - * - * Constructs an alarm notification service object by binding the corresponding - * CORBA object to it. - * - * Return value: the same object as the @an argument. - **/ -AlarmNotify * -alarm_notify_construct (AlarmNotify *an, - GNOME_Evolution_Calendar_AlarmNotify corba_an) -{ - g_return_val_if_fail (an != NULL, NULL); - g_return_val_if_fail (IS_ALARM_NOTIFY (an), NULL); - - /* FIXME: add_interface the property bag here */ - - bonobo_object_construct (BONOBO_OBJECT (an), corba_an); - return an; -} - -/** - * alarm_notify_corba_object_create: - * @object: #BonoboObject that will wrap the CORBA object. - * - * Creates and activates the CORBA object that is wrapped by the specified alarm - * notification service @object. - * - * Return value: An activated object reference or #CORBA_OBJECT_NIL in case of - * failure. - **/ -GNOME_Evolution_Calendar_AlarmNotify -alarm_notify_corba_object_create (BonoboObject *object) -{ - POA_GNOME_Evolution_Calendar_AlarmNotify *servant; - CORBA_Environment ev; - - g_return_val_if_fail (object != NULL, CORBA_OBJECT_NIL); - g_return_val_if_fail (IS_ALARM_NOTIFY (object), CORBA_OBJECT_NIL); - - servant = (POA_GNOME_Evolution_Calendar_AlarmNotify *) g_new (BonoboObjectServant, 1); - servant->vepv = &alarm_notify_vepv; - - CORBA_exception_init (&ev); - POA_GNOME_Evolution_Calendar_AlarmNotify__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - return CORBA_OBJECT_NIL; - } - - CORBA_exception_free (&ev); - return (GNOME_Evolution_Calendar_AlarmNotify) bonobo_object_activate_servant ( - object, servant); -} - /** * alarm_notify_new: * @@ -381,24 +279,7 @@ AlarmNotify * alarm_notify_new (void) { AlarmNotify *an; - GNOME_Evolution_Calendar_AlarmNotify corba_an; - CORBA_Environment ev; - gboolean result; an = gtk_type_new (TYPE_ALARM_NOTIFY); - - corba_an = alarm_notify_corba_object_create (BONOBO_OBJECT (an)); - - CORBA_exception_init (&ev); - result = CORBA_Object_is_nil (corba_an, &ev); - - if (ev._major != CORBA_NO_EXCEPTION || result) { - g_message ("alarm_notify_new(): could not create the CORBA alarm notify service"); - bonobo_object_unref (BONOBO_OBJECT (an)); - CORBA_exception_free (&ev); - return NULL; - } - CORBA_exception_free (&ev); - - return alarm_notify_construct (an, corba_an); + return an; } diff --git a/calendar/gui/alarm-notify/alarm-notify.h b/calendar/gui/alarm-notify/alarm-notify.h index 0fb73551d7..4122b269fa 100644 --- a/calendar/gui/alarm-notify/alarm-notify.h +++ b/calendar/gui/alarm-notify/alarm-notify.h @@ -23,7 +23,7 @@ #ifndef ALARM_NOTIFY_H #define ALARM_NOTIFY_H -#include +#include #include "evolution-calendar.h" @@ -41,24 +41,20 @@ typedef struct _AlarmNotifyClass AlarmNotifyClass; typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate; struct _AlarmNotify { - BonoboObject object; + BonoboXObject xobject; /* Private data */ AlarmNotifyPrivate *priv; }; struct _AlarmNotifyClass { - BonoboObjectClass parent_class; + BonoboXObjectClass parent_class; + + POA_GNOME_Evolution_Calendar_AlarmNotify__epv epv; }; GtkType alarm_notify_get_type (void); -AlarmNotify *alarm_notify_construct (AlarmNotify *an, - GNOME_Evolution_Calendar_AlarmNotify corba_an); - -GNOME_Evolution_Calendar_AlarmNotify alarm_notify_corba_object_create (BonoboObject *object); -POA_GNOME_Evolution_Calendar_AlarmNotify__epv *alarm_notify_get_epv (void); - AlarmNotify *alarm_notify_new (void); diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index f56905392a..2072e03c84 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -27,6 +27,7 @@ #include #include #include "alarm.h" +#include "alarm-notify-dialog.h" #include "alarm-queue.h" @@ -135,17 +136,61 @@ lookup_client (CalClient *client) return g_hash_table_lookup (client_alarms_hash, client); } +/* Callback used from the alarm notify dialog */ +static void +notify_dialog_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) +{ + switch (result) { + case ALARM_NOTIFY_SNOOZE: + /* FIXME */ + break; + + case ALARM_NOTIFY_EDIT: + /* FIXME */ + break; + + case ALARM_NOTIFY_CLOSE: + default: + break; + } +} + /* Callback used when an alarm triggers */ static void alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) { CompQueuedAlarms *cqa; + CalComponent *comp; + GSList *l; + QueuedAlarm *qa; + const char *auid; + time_t occur; cqa = data; + comp = cqa->alarms->comp; - /* FIXME */ + /* Look for the queued alarm so that we can identify its occurrence */ + + qa = NULL; + + for (l = cqa->queued_alarms; l; l = l->next) { + qa = l->data; + if (qa->alarm_id == alarm_id) + break; + } + + g_assert (qa != NULL); + + /* Fetch the alarm information. We use the trigger time passed to us + * instead of the one in the instance structure because this may not be + * the actual computed trigger but a snoozed one instead. + */ + + auid = qa->instance->auid; + occur = qa->instance->occur; - g_message ("alarm_trigger_cb(): Triggered!"); + if (!alarm_notify_dialog (trigger, occur, comp, notify_dialog_cb, comp)) + g_message ("alarm_trigger_cb(): Could not create the alarm notify dialog"); } /* Callback used when an alarm must be destroyed */ diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c index c26ecd8975..d608579933 100644 --- a/calendar/gui/alarm-notify/notify-main.c +++ b/calendar/gui/alarm-notify/notify-main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,7 @@ funny_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) struct tm *tm; tm = localtime (&trigger); - strftime (str, sizeof (str), "%x %X", tm); + strftime (str, sizeof (str), "%Y/%m/%d %H:%M:%S", tm); msg = g_strdup_printf (_("It is %s. The Unix time is %ld right now. We just thought " "you may like to know."), str, (long) trigger); @@ -97,12 +98,15 @@ main (int argc, char **argv) if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) g_error (_("Could not initialize Bonobo")); + if (!gnome_vfs_init ()) + g_error (_("Could not initialize gnome-vfs")); + alarm_init (); alarm_queue_init (); funny_times_init (); - factory = bonobo_generic_factory_new ("OAFID:GNOME_Evolution_Calendar_AlarmNotify_Factory", + 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")); @@ -115,5 +119,7 @@ main (int argc, char **argv) alarm_queue_done (); alarm_done (); + gnome_vfs_shutdown (); + return 0; } diff --git a/calendar/gui/calendar-model.c b/calendar/gui/calendar-model.c index 8a90b507f9..1e64b940c4 100644 --- a/calendar/gui/calendar-model.c +++ b/calendar/gui/calendar-model.c @@ -1415,9 +1415,13 @@ calendar_model_duplicate_value (ETableModel *etm, int col, const void *value) case CAL_COMPONENT_FIELD_COLOR: return (void *) value; - case CAL_COMPONENT_FIELD_COMPONENT: - gtk_object_ref (GTK_OBJECT (value)); - return; + case CAL_COMPONENT_FIELD_COMPONENT: { + CalComponent *comp; + + comp = CAL_COMPONENT (value); + gtk_object_ref (GTK_OBJECT (comp)); + return comp; + } default: g_message ("calendar_model_duplicate_value(): Requested invalid column %d", col); diff --git a/calendar/gui/dialogs/Makefile.am b/calendar/gui/dialogs/Makefile.am index 90815ec7ec..3069c97a46 100644 --- a/calendar/gui/dialogs/Makefile.am +++ b/calendar/gui/dialogs/Makefile.am @@ -20,8 +20,6 @@ INCLUDES = \ noinst_LIBRARIES = libcal-dialogs.a libcal_dialogs_a_SOURCES = \ - alarm-notify-dialog.c \ - alarm-notify-dialog.h \ alarm-page.c \ alarm-page.h \ cal-prefs-dialog.c \ @@ -60,7 +58,6 @@ libcal_dialogs_a_SOURCES = \ task-page.h glade_DATA = \ - alarm-notify.glade \ alarm-page.glade \ cal-prefs-dialog.glade \ e-timezone-dialog.glade \ diff --git a/calendar/gui/dialogs/alarm-notify-dialog.c b/calendar/gui/dialogs/alarm-notify-dialog.c deleted file mode 100644 index 99b244613a..0000000000 --- a/calendar/gui/dialogs/alarm-notify-dialog.c +++ /dev/null @@ -1,231 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "alarm-notify-dialog.h" - - - -/* The useful contents of the alarm notify dialog */ -typedef struct { - GladeXML *xml; - - GtkWidget *dialog; - GtkWidget *close; - GtkWidget *snooze; - GtkWidget *edit; - GtkWidget *heading; - GtkWidget *summary; - GtkWidget *snooze_time; - - AlarmNotifyFunc func; - gpointer func_data; -} AlarmNotify; - - - -/* Callback used when the notify dialog is destroyed */ -static void -dialog_destroy_cb (GtkObject *object, gpointer data) -{ - AlarmNotify *an; - - an = data; - gtk_object_unref (GTK_OBJECT (an->xml)); - g_free (an); -} - -/* Delete_event handler for the alarm notify dialog */ -static gint -delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_assert (an->func != NULL); - - (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); - - gtk_widget_destroy (widget); - return TRUE; -} - -/* Callback for the close button */ -static void -close_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_assert (an->func != NULL); - - (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); - - gtk_widget_destroy (an->dialog); -} - -/* Callback for the snooze button */ -static void -snooze_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmNotify *an; - int snooze_time; - - an = data; - g_assert (an->func != NULL); - - snooze_time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (an->snooze_time)); - (* an->func) (ALARM_NOTIFY_SNOOZE, snooze_time, an->func_data); - - gtk_widget_destroy (an->dialog); -} - -/* Callback for the edit button */ -static void -edit_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_assert (an->func != NULL); - - (* an->func) (ALARM_NOTIFY_EDIT, -1, an->func_data); - - gtk_widget_destroy (an->dialog); -} - -/** - * alarm_notify_dialog: - * @trigger: Trigger time for the alarm. - * @occur: Occurrence time for the event. - * @comp: Calendar component object which corresponds to the alarm. - * @func: Function to be called when a dialog action is invoked. - * @func_data: Closure data for @func. - * - * Runs the alarm notification dialog. The specified @func will be used to - * notify the client about result of the actions in the dialog. - * - * Return value: TRUE on success, FALSE if the dialog could not be created. - **/ -gboolean -alarm_notify_dialog (time_t trigger, time_t occur, CalComponent *comp, - AlarmNotifyFunc func, gpointer func_data) -{ - AlarmNotify *an; - char buf[256]; - struct tm tm_trigger; - struct tm tm_occur; - CalComponentText summary; - - g_return_val_if_fail (trigger != -1, FALSE); - g_return_val_if_fail (occur != -1, FALSE); - g_return_val_if_fail (comp != NULL, FALSE); - g_return_val_if_fail (IS_CAL_COMPONENT (comp), FALSE); - g_return_val_if_fail (func != NULL, FALSE); - - an = g_new0 (AlarmNotify, 1); - - an->func = func; - an->func_data = func_data; - - an->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-notify.glade", NULL); - if (!an->xml) { - g_message ("alarm_notify_dialog(): Could not load the Glade XML file!"); - g_free (an); - return FALSE; - } - - an->dialog = glade_xml_get_widget (an->xml, "alarm-notify"); - an->close = glade_xml_get_widget (an->xml, "close"); - an->snooze = glade_xml_get_widget (an->xml, "snooze"); - an->edit = glade_xml_get_widget (an->xml, "edit"); - an->heading = glade_xml_get_widget (an->xml, "heading"); - an->summary = glade_xml_get_widget (an->xml, "summary"); - an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); - - if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->summary - && an->snooze_time)) { - g_message ("alarm_notify_dialog(): Could not find all widgets in Glade file!"); - gtk_object_unref (GTK_OBJECT (an->xml)); - g_free (an); - return FALSE; - } - - gtk_object_set_data (GTK_OBJECT (an->dialog), "alarm-notify", an); - gtk_signal_connect (GTK_OBJECT (an->dialog), "destroy", - GTK_SIGNAL_FUNC (dialog_destroy_cb), an); - - /* Title */ - - /* FIXME: use am_pm_flag or 24-hour time */ - - tm_trigger = *localtime (&trigger); - strftime (buf, sizeof (buf), _("Alarm on %A %b %d %Y %H:%M"), &tm_trigger); - gtk_window_set_title (GTK_WINDOW (an->dialog), buf); - - /* Heading */ - - tm_occur = *localtime (&occur); - strftime (buf, sizeof (buf), - _("Notification about your appointment on %A %b %d %Y %H:%M"), - &tm_occur); - gtk_label_set_text (GTK_LABEL (an->heading), buf); - - /* Summary */ - - cal_component_get_summary (comp, &summary); - - if (summary.value) - gtk_label_set_text (GTK_LABEL (an->summary), summary.value); - else - gtk_label_set_text (GTK_LABEL (an->summary), _("No summary available.")); - - /* Connect actions */ - - gtk_signal_connect (GTK_OBJECT (an->dialog), "delete_event", - GTK_SIGNAL_FUNC (delete_event_cb), - an); - - gtk_signal_connect (GTK_OBJECT (an->close), "clicked", - GTK_SIGNAL_FUNC (close_clicked_cb), - an); - - gtk_signal_connect (GTK_OBJECT (an->snooze), "clicked", - GTK_SIGNAL_FUNC (snooze_clicked_cb), - an); - - gtk_signal_connect (GTK_OBJECT (an->edit), "clicked", - GTK_SIGNAL_FUNC (edit_clicked_cb), - an); - - /* Run! */ - - gtk_widget_show (an->dialog); - return TRUE; -} diff --git a/calendar/gui/dialogs/alarm-notify-dialog.h b/calendar/gui/dialogs/alarm-notify-dialog.h deleted file mode 100644 index a6715a7325..0000000000 --- a/calendar/gui/dialogs/alarm-notify-dialog.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef ALARM_NOTIFY_DIALOG_H -#define ALARM_NOTIFY_DIALOG_H - -#include -#include -#include - - - -typedef enum { - ALARM_NOTIFY_CLOSE, - ALARM_NOTIFY_SNOOZE, - ALARM_NOTIFY_EDIT -} AlarmNotifyResult; - -typedef void (* AlarmNotifyFunc) (AlarmNotifyResult result, int snooze_mins, gpointer data); - -gboolean alarm_notify_dialog (time_t trigger, time_t occur, CalComponent *comp, - AlarmNotifyFunc func, gpointer func_data); - - - -#endif diff --git a/calendar/gui/dialogs/alarm-notify.glade b/calendar/gui/dialogs/alarm-notify.glade deleted file mode 100644 index 41718d0572..0000000000 --- a/calendar/gui/dialogs/alarm-notify.glade +++ /dev/null @@ -1,228 +0,0 @@ - - - - - Evolution Calendar - evolution-calendar - - src - pixmaps - C - True - True - False - True - True - True - True - interface.c - interface.h - callbacks.c - callbacks.h - support.c - support.h - - - - GtkWindow - alarm-notify - True - - GTK_WINDOW_DIALOG - GTK_WIN_POS_CENTER - False - False - False - False - - - GtkVBox - vbox2 - 4 - True - False - 4 - - - GtkHBox - hbox3 - True - False - 8 - - 0 - True - True - - - - GtkVBox - vbox5 - True - False - 4 - - 0 - True - True - - - - GtkLabel - heading - True - - GTK_JUSTIFY_LEFT - True - 0 - 0.5 - 0 - 0 - - 0 - False - False - - - - - GtkLabel - summary - True - - GTK_JUSTIFY_LEFT - True - 0 - 0.5 - 0 - 0 - - 0 - False - False - - - - - - GtkVBox - vbox4 - True - False - 4 - - 0 - True - True - - - - GtkButton - close - True - True - - - 0 - False - False - - - - - GtkButton - snooze - True - True - - - 0 - False - False - - - - - GtkButton - edit - True - True - - - 0 - False - False - - - - - - - GtkHSeparator - hseparator1 - True - - 0 - True - True - - - - - GtkHBox - hbox4 - True - False - 4 - - 0 - True - True - - - - GtkLabel - label4 - True - - GTK_JUSTIFY_CENTER - False - 0 - 0.5 - 0 - 0 - - 0 - False - False - - - - - GtkSpinButton - snooze-time - True - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 5 - 1 - 1440 - 1 - 5 - 5 - - 0 - False - False - - - - - - - diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c index f073039aa3..92113f2702 100644 --- a/calendar/gui/e-tasks.c +++ b/calendar/gui/e-tasks.c @@ -233,10 +233,6 @@ e_tasks_construct (ETasks *tasks) gtk_signal_connect (GTK_OBJECT (priv->client), "obj_removed", GTK_SIGNAL_FUNC (obj_removed_cb), tasks); -#if 0 - alarm_notify_add_client (priv->client); -#endif - e_calendar_table_set_cal_client (E_CALENDAR_TABLE (priv->tasks_view), priv->client); @@ -283,9 +279,6 @@ e_tasks_destroy (GtkObject *object) g_free (config_filename); if (priv->client) { -#if 0 - alarm_notify_remove_client (priv->client); -#endif gtk_object_unref (GTK_OBJECT (priv->client)); priv->client = NULL; } diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index cac469808f..16afc47bd1 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -35,17 +35,18 @@ #include #include #include +#include #include #include #include #include "widgets/menus/gal-view-menus.h" #include "widgets/misc/e-search-bar.h" #include "widgets/misc/e-filter-bar.h" -#include "dialogs/alarm-notify-dialog.h" #include "dialogs/event-editor.h" #include "e-calendar-table.h" #include "e-day-view.h" #include "e-week-view.h" +#include "evolution-calendar.h" #include "gnome-cal.h" #include "component-factory.h" #include "calendar-commands.h" @@ -503,17 +504,11 @@ gnome_calendar_destroy (GtkObject *object) g_free (filename); if (priv->client) { -#if 0 - alarm_notify_remove_client (priv->client); -#endif gtk_object_unref (GTK_OBJECT (priv->client)); priv->client = NULL; } if (priv->task_pad_client) { -#if 0 - alarm_notify_remove_client (priv->task_pad_client); -#endif gtk_object_unref (GTK_OBJECT (priv->task_pad_client)); priv->task_pad_client = NULL; } @@ -1120,10 +1115,6 @@ gnome_calendar_construct (GnomeCalendar *gcal) gtk_signal_connect (GTK_OBJECT (priv->client), "obj_removed", GTK_SIGNAL_FUNC (obj_removed_cb), gcal); -#if 0 - alarm_notify_add_client (priv->client); -#endif - e_day_view_set_cal_client (E_DAY_VIEW (priv->day_view), priv->client); e_day_view_set_cal_client (E_DAY_VIEW (priv->work_week_view), @@ -1143,14 +1134,9 @@ gnome_calendar_construct (GnomeCalendar *gcal) gtk_signal_connect (GTK_OBJECT (priv->task_pad_client), "cal_opened", GTK_SIGNAL_FUNC (cal_opened_cb), gcal); -#if 0 - alarm_notify_add_client (priv->task_pad_client); -#endif - e_calendar_table_set_cal_client (E_CALENDAR_TABLE (priv->todo), priv->task_pad_client); - /* Get the default view to show. */ view_type = calendar_config_get_default_view (); if (view_type < GNOME_CAL_DAY_VIEW || view_type > GNOME_CAL_MONTH_VIEW) @@ -1220,6 +1206,56 @@ gnome_calendar_get_task_pad_cal_client (GnomeCalendar *gcal) return priv->task_pad_client; } +/* Adds the specified URI to the alarm notification service */ +static void +add_alarms (const char *uri) +{ + CORBA_Environment ev; + GNOME_Evolution_Calendar_AlarmNotify an; + + /* Activate the alarm notification service */ + + CORBA_exception_init (&ev); + an = oaf_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify", 0, NULL, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_message ("add_alarms(): Could not activate the alarm notification service"); + CORBA_exception_free (&ev); + return; + } + CORBA_exception_free (&ev); + + /* Ask the service to load the URI */ + + CORBA_exception_init (&ev); + GNOME_Evolution_Calendar_AlarmNotify_addCalendar (an, uri, &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 ("add_calendar(): Invalid URI reported from the " + "alarm notification service"); + else if (strcmp (ex_id, + ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError) == 0) + g_message ("add_calendar(): The alarm notification service could " + "not contact the backend"); + } else if (ev._major != CORBA_NO_EXCEPTION) + g_message ("add_calendar(): Could not issue the addCalendar request"); + + CORBA_exception_free (&ev); + + /* Get rid of the service */ + + CORBA_exception_init (&ev); + bonobo_object_release_unref (an, &ev); + if (ev._major != CORBA_NO_EXCEPTION) + g_message ("add_alarms(): Could not unref the alarm notification service"); + + CORBA_exception_free (&ev); +} + gboolean gnome_calendar_open (GnomeCalendar *gcal, const char *str_uri) { @@ -1246,12 +1282,16 @@ gnome_calendar_open (GnomeCalendar *gcal, const char *str_uri) return FALSE; } + add_alarms (str_uri); + /* Open the appropriate Tasks folder to show in the TaskPad. Currently we just show the folder named "Tasks", but it will be a per-calendar option in future. */ tasks_uri = g_strdup_printf ("%s/local/Tasks/tasks.ics", evolution_dir); success = cal_client_open_calendar (priv->task_pad_client, tasks_uri, FALSE); + + add_alarms (tasks_uri); g_free (tasks_uri); if (!success) { diff --git a/calendar/gui/main.c b/calendar/gui/main.c index d13a16383f..8054bbb752 100644 --- a/calendar/gui/main.c +++ b/calendar/gui/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -64,6 +65,10 @@ main (int argc, char **argv) textdomain(PACKAGE); init_bonobo (argc, argv); + + if (!gnome_vfs_init ()) + g_error (_("Could not initialize gnome-vfs")); + glade_gnome_init (); alarm_init (); e_cursors_init (); @@ -85,5 +90,7 @@ main (int argc, char **argv) alarm_done (); calendar_config_write_on_exit (); + gnome_vfs_shutdown (); + return 0; } diff --git a/calendar/gui/tasks-control.c b/calendar/gui/tasks-control.c index 53103aec60..8d61121380 100644 --- a/calendar/gui/tasks-control.c +++ b/calendar/gui/tasks-control.c @@ -29,6 +29,7 @@ #include #include #include +#include "calendar-config.h" #include "e-tasks.h" #include "tasks-control.h" #include "evolution-shell-component-utils.h" -- cgit v1.2.3