diff options
author | nobody <nobody@localhost> | 2001-08-02 23:43:54 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2001-08-02 23:43:54 +0800 |
commit | db171b24325a1ce9b39e3606dd1e72c27cb27e0a (patch) | |
tree | 94acb43d14c571e8ec432fa3650277178741f531 /calendar/gui/alarm-notify | |
parent | ea4315435238149d387701ed2940bf8c97d4d319 (diff) | |
download | gsoc2013-evolution-gnomoku-1_2.tar.gz gsoc2013-evolution-gnomoku-1_2.tar.zst gsoc2013-evolution-gnomoku-1_2.zip |
This commit was manufactured by cvs2svn to create tag 'gnomoku-1_2'.gnomoku-1_2
svn path=/tags/gnomoku-1_2/; revision=11577
Diffstat (limited to 'calendar/gui/alarm-notify')
-rw-r--r-- | calendar/gui/alarm-notify/.cvsignore | 10 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in | 24 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/Makefile.am | 85 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify-dialog.c | 306 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify-dialog.h | 45 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.c | 285 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.glade | 206 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.h | 63 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-queue.c | 1078 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-queue.h | 36 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm.c | 357 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm.h | 44 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/client-main.c | 178 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/notify-main.c | 128 |
14 files changed, 0 insertions, 2845 deletions
diff --git a/calendar/gui/alarm-notify/.cvsignore b/calendar/gui/alarm-notify/.cvsignore deleted file mode 100644 index 1f2b546c7c..0000000000 --- a/calendar/gui/alarm-notify/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -evolution-calendar-stubs.c -evolution-calendar-skels.c -evolution-calendar-common.c -evolution-calendar.h -evolution-alarm-notify -GNOME_Evolution_Calendar_AlarmNotify.oaf diff --git a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in b/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in deleted file mode 100644 index 86f5c71493..0000000000 --- a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.oaf.in +++ /dev/null @@ -1,24 +0,0 @@ -<oaf_info> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory" - type="exe" - location="evolution-alarm-notify"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="description" type="string" - _value="Factory for the alarm notification service"/> - -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_AlarmNotify" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory"> - - <oaf_attribute name="description" type="string" - _value="Alarm notification service"/> -</oaf_server> - -</oaf_info> diff --git a/calendar/gui/alarm-notify/Makefile.am b/calendar/gui/alarm-notify/Makefile.am deleted file mode 100644 index 4176a71685..0000000000 --- a/calendar/gui/alarm-notify/Makefile.am +++ /dev/null @@ -1,85 +0,0 @@ -CORBA_GENERATED = \ - evolution-calendar.h \ - evolution-calendar-common.c \ - evolution-calendar-skels.c \ - evolution-calendar-stubs.c - -idls = $(top_srcdir)/calendar/idl/evolution-calendar.idl - -idl_flags = `$(GNOME_CONFIG) --cflags idl` -I $(datadir)/idl - -$(CORBA_GENERATED): $(idls) - $(ORBIT_IDL) $(idl_flags) $(top_srcdir)/calendar/idl/evolution-calendar.idl - -bin_PROGRAMS = evolution-alarm-notify # evolution-alarm-client - -noinst_LIBRARIES = libalarm.a - -libalarm_a_SOURCES = \ - alarm.c \ - alarm.h - -INCLUDES = \ - -DG_LOG_DOMAIN=\"evolution-alarm-notify\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/calendar \ - -I$(top_builddir)/calendar \ - -I$(top_srcdir)/libical/src/libical \ - -I$(top_builddir)/libical/src/libical \ - -I$(top_srcdir)/widgets \ - -I$(includedir) \ - $(BONOBO_VFS_GNOME_CFLAGS) \ - $(EXTRA_GNOME_CFLAGS) \ - -DEVOLUTION_DATADIR=\""$(datadir)"\" \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" - -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 - -evolution_alarm_notify_LDADD = \ - libalarm.a \ - $(top_builddir)/calendar/cal-client/libcal-client.la \ - $(top_builddir)/calendar/cal-util/libcal-util.la \ - $(top_builddir)/libical/src/libical/libical.la \ - $(top_builddir)/libwombat/libwombat.la \ - $(BONOBO_VFS_GNOME_LIBS) \ - $(EXTRA_GNOME_LIBS) \ - $(INTLLIBS) - -# evolution_alarm_client_SOURCES = \ -# client-main.c \ -# $(CORBA_GENERATED) -# -# evolution_alarm_client_LDADD = \ -# $(BONOBO_VFS_GNOME_LIBS) \ -# $(EXTRA_GNOME_LIBS) \ -# $(INTLLIBS) - -oafdir = $(datadir)/oaf -oaf_in_files = \ - GNOME_Evolution_Calendar_AlarmNotify.oaf.in - -oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) - -@XML_I18N_MERGE_OAF_RULE@ - -EXTRA_DIST = \ - $(oaf_DATA) \ - $(oaf_in_files) \ - $(glade_DATA) - -BUILT_SOURCES = $(CORBA_GENERATED) -CLEANFILES += $(BUILT_SOURCES) diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.c b/calendar/gui/alarm-notify/alarm-notify-dialog.c deleted file mode 100644 index 2a11026f23..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.c +++ /dev/null @@ -1,306 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * 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 <config.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkspinbutton.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkwindow.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#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 *message; - 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); -} - -/* Creates a heading for the alarm notification dialog */ -static char * -make_heading (CalComponentVType vtype, time_t occur_start, time_t occur_end) -{ - char *buf; - char s[128], e[128]; - - if (occur_start != -1) { - struct tm tm; - - tm = *localtime (&occur_start); - strftime (s, sizeof (s), "%A %b %d %Y %H:%M", &tm); - } - - if (occur_end != -1) { - struct tm tm; - - tm = *localtime (&occur_end); - strftime (e, sizeof (e), "%A %b %d %Y %H:%M", &tm); - } - - /* I love combinatorial explosion */ - - switch (vtype) { - case CAL_COMPONENT_EVENT: - if (occur_start != -1) { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your appointment " - "starting on %s and ending on %s"), - s, e); - else - buf = g_strdup_printf (_("Notification about your appointment " - "starting on %s"), - s); - } else { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your appointment " - "ending on %s"), - e); - else - buf = g_strdup_printf (_("Notification about your appointment")); - } - break; - - case CAL_COMPONENT_TODO: - if (occur_start != -1) { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your task " - "starting on %s and ending on %s"), - s, e); - else - buf = g_strdup_printf (_("Notification about your task " - "starting on %s"), - s); - } else { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your task " - "ending on %s"), - e); - else - buf = g_strdup_printf (_("Notification about your task")); - } - break; - - default: - /* Only VEVENTs and VTODOs can have alarms */ - g_assert_not_reached (); - buf = NULL; - break; - } - - return buf; -} - -/** - * alarm_notify_dialog: - * @trigger: Trigger time for the alarm. - * @occur_start: Start of occurrence time for the event. - * @occur_end: End of occurrence time for the event. - * @vtype: Type of the component which corresponds to the alarm. - * @message; Message to display in the dialog; usually comes from the component. - * @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_start, time_t occur_end, - CalComponentVType vtype, const char *message, - AlarmNotifyFunc func, gpointer func_data) -{ - AlarmNotify *an; - char buf[256]; - char *heading; - char *msg; - struct tm tm_trigger; - - g_return_val_if_fail (trigger != -1, FALSE); - - /* Only VEVENTs or VTODOs can have alarms */ - g_return_val_if_fail (vtype == CAL_COMPONENT_EVENT || vtype == CAL_COMPONENT_TODO, FALSE); - g_return_val_if_fail (message != NULL, 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->message = glade_xml_get_widget (an->xml, "message"); - an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); - - if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->message - && 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 */ - - 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 */ - - heading = make_heading (vtype, occur_start, occur_end); - gtk_label_set_text (GTK_LABEL (an->heading), heading); - g_free (heading); - - /* Message */ - - msg = e_utf8_to_gtk_string (an->message, message); - if (msg) { - gtk_label_set_text (GTK_LABEL (an->message), msg); - g_free (msg); - } else - g_message ("Could not convert the alarm message from UTF8"); - - /* 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/alarm-notify/alarm-notify-dialog.h b/calendar/gui/alarm-notify/alarm-notify-dialog.h deleted file mode 100644 index 2eebbf1796..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * 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 <time.h> -#include <glib.h> -#include <cal-util/cal-component.h> - - - -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_start, time_t occur_end, - CalComponentVType vtype, const char *message, - AlarmNotifyFunc func, gpointer func_data); - - - -#endif diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c deleted file mode 100644 index 88d25dafbc..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ /dev/null @@ -1,285 +0,0 @@ -/* Evolution calendar - Alarm notification service object - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * 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 "config.h" -#endif - -#include <libgnomevfs/gnome-vfs.h> -#include <cal-client/cal-client.h> -#include "alarm-notify.h" -#include "alarm-queue.h" - - - -/* A loaded client */ -typedef struct { - /* The actual client */ - CalClient *client; - - /* The URI of the client in gnome-vfs's format. This *is* the key that - * is stored in the uri_client_hash hash table below. - */ - GnomeVFSURI *uri; - - /* Number of times clients have requested this URI to be added to the - * alarm notification system. - */ - int refcount; -} LoadedClient; - -/* Private part of the AlarmNotify structure */ -struct _AlarmNotifyPrivate { - /* Mapping from GnomeVFSURIs to LoadedClient structures */ - GHashTable *uri_client_hash; -}; - - - -static void alarm_notify_class_init (AlarmNotifyClass *class); -static void alarm_notify_init (AlarmNotify *an); -static void alarm_notify_destroy (GtkObject *object); - -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 BonoboXObjectClass *parent_class; - - - -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 -alarm_notify_class_init (AlarmNotifyClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - - parent_class = gtk_type_class (BONOBO_X_OBJECT_TYPE); - - class->epv.addCalendar = AlarmNotify_addCalendar; - class->epv.removeCalendar = AlarmNotify_removeCalendar; - class->epv.die = AlarmNotify_die; - - object_class->destroy = alarm_notify_destroy; -} - -/* Object initialization function for the alarm notify system */ -static void -alarm_notify_init (AlarmNotify *an) -{ - AlarmNotifyPrivate *priv; - - priv = g_new0 (AlarmNotifyPrivate, 1); - an->priv = priv; - - priv->uri_client_hash = g_hash_table_new (gnome_vfs_uri_hash, gnome_vfs_uri_hequal); -} - -/* Callback used from g_hash-table_forach(), used to destroy a loade client */ -static void -destroy_loaded_client_cb (gpointer key, gpointer value, gpointer data) -{ - LoadedClient *lc; - - lc = value; - - gtk_object_unref (GTK_OBJECT (lc->client)); - gnome_vfs_uri_unref (lc->uri); - g_free (lc); -} - -/* Destroy handler for the alarm notify system */ -static void -alarm_notify_destroy (GtkObject *object) -{ - AlarmNotify *an; - AlarmNotifyPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_ALARM_NOTIFY (object)); - - an = ALARM_NOTIFY (object); - priv = an->priv; - - g_hash_table_foreach (priv->uri_client_hash, destroy_loaded_client_cb, NULL); - - g_hash_table_destroy (priv->uri_client_hash); - priv->uri_client_hash = NULL; - - g_free (priv); - an->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - - -/* CORBA servant implementation */ - -/* AlarmNotify::addCalendar method */ -static void -AlarmNotify_addCalendar (PortableServer_Servant servant, - const CORBA_char *str_uri, - CORBA_Environment *ev) -{ - AlarmNotify *an; - AlarmNotifyPrivate *priv; - GnomeVFSURI *uri; - CalClient *client; - LoadedClient *lc; - - an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); - priv = an->priv; - - uri = gnome_vfs_uri_new (str_uri); - if (!uri) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI, - NULL); - return; - } - - lc = g_hash_table_lookup (priv->uri_client_hash, uri); - - if (lc) { - gnome_vfs_uri_unref (uri); - g_assert (lc->refcount > 0); - lc->refcount++; - return; - } - - client = cal_client_new (); - - if (client) { - if (cal_client_open_calendar (client, str_uri, FALSE)) { - lc = g_new (LoadedClient, 1); - lc->client = client; - lc->uri = uri; - lc->refcount = 1; - g_hash_table_insert (priv->uri_client_hash, uri, lc); - - alarm_queue_add_client (client); - } else { - gtk_object_unref (GTK_OBJECT (client)); - client = NULL; - } - } - - if (!client) { - gnome_vfs_uri_unref (uri); - - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError, - NULL); - return; - } -} - -/* AlarmNotify::removeCalendar method */ -static void -AlarmNotify_removeCalendar (PortableServer_Servant servant, - const CORBA_char *str_uri, - CORBA_Environment *ev) -{ - AlarmNotify *an; - AlarmNotifyPrivate *priv; - LoadedClient *lc; - GnomeVFSURI *uri; - - an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); - priv = an->priv; - - uri = gnome_vfs_uri_new (str_uri); - if (!uri) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI, - NULL); - return; - } - - lc = g_hash_table_lookup (priv->uri_client_hash, uri); - gnome_vfs_uri_unref (uri); - - if (!lc) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_NotFound, - NULL); - return; - } - - g_assert (lc->refcount > 0); - - lc->refcount--; - if (lc->refcount > 0) - return; - - g_hash_table_remove (priv->uri_client_hash, lc->uri); - - gtk_object_unref (GTK_OBJECT (lc->client)); - gnome_vfs_uri_unref (lc->uri); - g_free (lc); -} - -static void -AlarmNotify_die (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - AlarmNotify *an; - AlarmNotifyPrivate *priv; - - an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); - priv = an->priv; - - /* FIXME */ -} - - - -/** - * alarm_notify_new: - * - * Creates a new #AlarmNotify object. - * - * Return value: A newly-created #AlarmNotify, or NULL if its corresponding - * CORBA object could not be created. - **/ -AlarmNotify * -alarm_notify_new (void) -{ - AlarmNotify *an; - - an = gtk_type_new (TYPE_ALARM_NOTIFY); - return an; -} diff --git a/calendar/gui/alarm-notify/alarm-notify.glade b/calendar/gui/alarm-notify/alarm-notify.glade deleted file mode 100644 index 19af18f010..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.glade +++ /dev/null @@ -1,206 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>Evolution Calendar</name> - <program_name>evolution-calendar</program_name> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> -</project> - -<widget> - <class>GtkWindow</class> - <name>alarm-notify</name> - <title></title> - <type>GTK_WINDOW_DIALOG</type> - <position>GTK_WIN_POS_CENTER</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>False</allow_grow> - <auto_shrink>False</auto_shrink> - - <widget> - <class>GtkVBox</class> - <name>vbox2</name> - <border_width>4</border_width> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - - <widget> - <class>GtkHBox</class> - <name>hbox3</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkVBox</class> - <name>vbox5</name> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>heading</name> - <label></label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>True</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>message</name> - <label></label> - <justify>GTK_JUSTIFY_LEFT</justify> - <wrap>True</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox4</name> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkButton</class> - <name>close</name> - <can_focus>True</can_focus> - <label>C_lose</label> - <relief>GTK_RELIEF_NORMAL</relief> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>snooze</name> - <can_focus>True</can_focus> - <label>Snoo_ze</label> - <relief>GTK_RELIEF_NORMAL</relief> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>edit</name> - <can_focus>True</can_focus> - <label>_Edit appointment</label> - <relief>GTK_RELIEF_NORMAL</relief> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHSeparator</class> - <name>hseparator1</name> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - </widget> - - <widget> - <class>GtkHBox</class> - <name>hbox4</name> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label4</name> - <label>Snooze time (minutes)</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkSpinButton</class> - <name>snooze-time</name> - <can_focus>True</can_focus> - <climb_rate>1</climb_rate> - <digits>0</digits> - <numeric>False</numeric> - <update_policy>GTK_UPDATE_ALWAYS</update_policy> - <snap>False</snap> - <wrap>False</wrap> - <value>5</value> - <lower>1</lower> - <upper>1440</upper> - <step>1</step> - <page>5</page> - <page_size>5</page_size> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/calendar/gui/alarm-notify/alarm-notify.h b/calendar/gui/alarm-notify/alarm-notify.h deleted file mode 100644 index 4122b269fa..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Evolution calendar - Alarm notification service object - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * 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 <bonobo/bonobo-xobject.h> -#include "evolution-calendar.h" - - - -#define TYPE_ALARM_NOTIFY (alarm_notify_get_type ()) -#define ALARM_NOTIFY(obj) (GTK_CHECK_CAST ((obj), TYPE_ALARM_NOTIFY, AlarmNotify)) -#define ALARM_NOTIFY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_ALARM_NOTIFY, \ - AlarmNotifyClass)) -#define IS_ALARM_NOTIFY(obj) (GTK_CHECK_TYPE ((obj), TYPE_ALARM_NOTIFY)) -#define IS_ALARM_NOTIFY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_ALARM_NOTIFY)) - -typedef struct _AlarmNotify AlarmNotify; -typedef struct _AlarmNotifyClass AlarmNotifyClass; - -typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate; - -struct _AlarmNotify { - BonoboXObject xobject; - - /* Private data */ - AlarmNotifyPrivate *priv; -}; - -struct _AlarmNotifyClass { - BonoboXObjectClass parent_class; - - POA_GNOME_Evolution_Calendar_AlarmNotify__epv epv; -}; - -GtkType alarm_notify_get_type (void); - -AlarmNotify *alarm_notify_new (void); - - - - -#endif diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c deleted file mode 100644 index 7f829e1bf5..0000000000 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ /dev/null @@ -1,1078 +0,0 @@ -/* Evolution calendar - Alarm queueing engine - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * 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 <config.h> -#endif - -#include <glib.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <gtk/gtksignal.h> -#include <cal-util/timeutil.h> -#include "alarm.h" -#include "alarm-notify-dialog.h" -#include "alarm-queue.h" - - - -/* Whether the queueing system has been initialized */ -static gboolean alarm_queue_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 CompQueuedAlarms->alarms->alarms list */ - CalAlarmInstance *instance; -} QueuedAlarm; - -/* Alarm ID for the midnight refresh function */ -static gpointer midnight_refresh_id = NULL; - -static void display_notification (time_t trigger, CalAlarmInstance *instance, - CalComponent *comp, CalComponentAlarm *alarm); - - - -/* Alarm queue engine */ - -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 ("queue_midnight_refresh(): 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; - CalComponent *comp; - GSList *l; - QueuedAlarm *qa; - CalComponentAlarm *alarm; - CalAlarmAction action; - - cqa = data; - comp = cqa->alarms->comp; - - /* 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); - - /* Decide what to do based on the alarm action. We use the trigger that - * is passed to us instead of the one from the instance structure - * because this may be a snoozed alarm instead of an original - * occurrence. - */ - - alarm = cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - cal_component_alarm_get_action (alarm, &action); - - switch (action) { - case CAL_ALARM_AUDIO: - /* FIXME: audio_notification (); */ - break; - - case CAL_ALARM_DISPLAY: - display_notification (trigger, qa->instance, comp, alarm); - break; - - case CAL_ALARM_EMAIL: - /* FIXME: mail_notification (); */ - break; - - case CAL_ALARM_PROCEDURE: - /* FIXME: procedure_notification (); */ - break; - - default: - g_assert_not_reached (); - break; - } - - cal_component_alarm_free (alarm); -} - -/* 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_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - ClientAlarms *ca; - - ca = data; - - if (status != CAL_CLIENT_OPEN_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); -} - - - -/* Notification functions */ - -/* 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; - } -} - -/* Performs notification of a display alarm */ -static void -display_notification (time_t trigger, CalAlarmInstance *instance, - CalComponent *comp, CalComponentAlarm *alarm) -{ - CalComponentVType vtype; - CalComponentText text; - const char *message; - - vtype = cal_component_get_vtype (comp); - - /* Pick a sensible notification message. First we try the DESCRIPTION - * from the alarm, then the SUMMARY of the component. - */ - - cal_component_alarm_get_description (alarm, &text); - if (text.value) - message = text.value; - else { - cal_component_get_summary (comp, &text); - if (text.value) - message = text.value; - else - message = _("No description available."); - } - - if (!alarm_notify_dialog (trigger, - instance->occur_start, instance->occur_end, - vtype, message, - notify_dialog_cb, comp)) - g_message ("display_notification(): Could not create the alarm notify dialog"); -} - - - -/** - * alarm_queue_init: - * - * Initializes the alarm queueing system. This should be called near the - * beginning of the program, after calling alarm_init(). - **/ -void -alarm_queue_init (void) -{ - g_return_if_fail (alarm_queue_inited == FALSE); - - client_alarms_hash = g_hash_table_new (g_direct_hash, g_direct_equal); - queue_midnight_refresh (); - - alarm_queue_inited = TRUE; -} - -/** - * alarm_queue_done: - * - * Shuts down the alarm queueing system. This should be called near the end - * of the program. All the monitored calendar clients should already have been - * unregistered with alarm_queue_remove_client(). - **/ -void -alarm_queue_done (void) -{ - g_return_if_fail (alarm_queue_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_queue_inited = FALSE; -} - -/** - * alarm_queue_add_client: - * @client: A calendar client. - * - * Adds a calendar client to the alarm queueing system. Alarm trigger - * notifications will be presented at the appropriate times. The client should - * be removed with alarm_queue_remove_client() when receiving notifications - * from it is no longer desired. - * - * A client can be added any number of times to the alarm queueing 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 - * queueing system when it is no longer wanted. - **/ -void -alarm_queue_add_client (CalClient *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_queue_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_get_load_state (client) != CAL_CLIENT_LOAD_LOADED) - gtk_signal_connect (GTK_OBJECT (client), "cal_opened", - GTK_SIGNAL_FUNC (cal_opened_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_get_load_state (client) == CAL_CLIENT_LOAD_LOADED) - 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_queue_remove_client: - * @client: A calendar client. - * - * Removes a calendar client from the alarm queueing system. - **/ -void -alarm_queue_remove_client (CalClient *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_queue_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/alarm-queue.h b/calendar/gui/alarm-notify/alarm-queue.h deleted file mode 100644 index cd2e9444b1..0000000000 --- a/calendar/gui/alarm-notify/alarm-queue.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Evolution calendar - Alarm queueing engine - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * 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_QUEUE_H -#define ALARM_QUEUE_H - -#include <cal-client/cal-client.h> - - -void alarm_queue_init (void); -void alarm_queue_done (void); - -void alarm_queue_add_client (CalClient *client); -void alarm_queue_remove_client (CalClient *client); - - -#endif diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c deleted file mode 100644 index 8f6ba013a4..0000000000 --- a/calendar/gui/alarm-notify/alarm.c +++ /dev/null @@ -1,357 +0,0 @@ -/* Evolution calendar - Low-level alarm timer mechanism - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * 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 <config.h> -#include <unistd.h> -#include <time.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/time.h> -#include <gdk/gdk.h> -#include "alarm.h" - - - -/* Whether the timer system has been initialized */ -static gboolean alarm_inited; - -/* The pipes used to notify about an alarm */ -static int alarm_pipes [2]; - -/* The list of pending alarms */ -static GList *alarms; - -/* A queued alarm structure */ -typedef struct { - time_t trigger; - AlarmFunction alarm_fn; - gpointer data; - AlarmDestroyNotify destroy_notify_fn; -} AlarmRecord; - - - -/* SIGALRM handler. Notifies the callback about the alarm. */ -static void -alarm_signal (int arg) -{ - char c = 0; - - write (alarm_pipes [1], &c, 1); -} - -/* Sets up an itimer and returns a success code */ -static gboolean -setup_itimer (time_t diff) -{ - struct itimerval itimer; - int v; - - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = diff; - itimer.it_value.tv_usec = 0; - - v = setitimer (ITIMER_REAL, &itimer, NULL); - - return (v == 0) ? TRUE : FALSE; -} - -/* Clears the itimer we have pending */ -static gboolean -clear_itimer (void) -{ - return setup_itimer (0); -} - -/* Removes the head alarm, returns it, and schedules the next alarm in the - * queue. - */ -static AlarmRecord * -pop_alarm (void) -{ - AlarmRecord *ar; - GList *l; - - if (!alarms) - return NULL; - - ar = alarms->data; - - l = alarms; - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - - if (alarms) { - time_t now; - AlarmRecord *new_ar; - - now = time (NULL); - new_ar = alarms->data; - - if (!setup_itimer (new_ar->trigger - now)) { - g_message ("pop_alarm(): Could not reset the timer! " - "Weird things will happen."); - - /* FIXME: should we free the alarm list? What - * about further alarm removal requests that - * will fail? - */ - } - } else - if (!clear_itimer ()) - g_message ("pop_alarm(): Could not clear the timer! " - "Weird things may happen."); - - return ar; -} - -/* Input handler for our own alarm notification pipe */ -static void -alarm_ready (gpointer data, gint fd, GdkInputCondition cond) -{ - AlarmRecord *ar; - char c; - - if (read (alarm_pipes [0], &c, 1) != 1) { - g_message ("alarm_ready(): Uh? Could not read from notification pipe."); - return; - } - - g_assert (alarms != NULL); - ar = pop_alarm (); - - g_print ("alarm_ready(): Notifying about alarm on %s\n", ctime (&ar->trigger)); - - (* ar->alarm_fn) (ar, ar->trigger, ar->data); - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (ar, ar->data); - - g_free (ar); -} - -static int -compare_alarm_by_time (gconstpointer a, gconstpointer b) -{ - const AlarmRecord *ara = a; - const AlarmRecord *arb = b; - time_t diff; - - diff = ara->trigger - arb->trigger; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/* Adds an alarm to the queue and sets up the timer */ -static gboolean -queue_alarm (time_t now, AlarmRecord *ar) -{ - time_t diff; - AlarmRecord *old_head; - - if (alarms) - old_head = alarms->data; - else - old_head = NULL; - - alarms = g_list_insert_sorted (alarms, ar, compare_alarm_by_time); - - if (old_head == alarms->data) - return TRUE; - - /* Set the timer for removal upon activation */ - - diff = ar->trigger - now; - if (!setup_itimer (diff)) { - GList *l; - - g_message ("queue_alarm(): Could not set up timer! Not queueing alarm."); - - l = g_list_find (alarms, ar); - g_assert (l != NULL); - - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - return FALSE; - } - - return TRUE; -} - -/** - * alarm_add: - * @trigger: Time at which alarm will trigger. - * @alarm_fn: Callback for trigger. - * @data: Closure data for callback. - * - * Adds an alarm to trigger at the specified time. The @alarm_fn will be called - * with the provided data and the alarm will be removed from the trigger list. - * - * Return value: An identifier for this alarm; it can be used to remove the - * alarm later with alarm_remove(). If the trigger time occurs in the past, then - * the alarm will not be queued and the function will return NULL. - **/ -gpointer -alarm_add (time_t trigger, AlarmFunction alarm_fn, gpointer data, - AlarmDestroyNotify destroy_notify_fn) -{ - time_t now; - AlarmRecord *ar; - - g_return_val_if_fail (alarm_inited, NULL); - g_return_val_if_fail (trigger != -1, NULL); - g_return_val_if_fail (alarm_fn != NULL, NULL); - - now = time (NULL); - if (trigger < now) - return NULL; - - ar = g_new (AlarmRecord, 1); - ar->trigger = trigger; - ar->alarm_fn = alarm_fn; - ar->data = data; - ar->destroy_notify_fn = destroy_notify_fn; - - g_print ("alarm_add(): Adding alarm for %s\n", ctime (&trigger)); - - if (!queue_alarm (now, ar)) { - g_free (ar); - ar = NULL; - } - - return ar; -} - -/** - * alarm_remove: - * @alarm: A queued alarm identifier. - * - * Removes an alarm from the alarm queue. - **/ -void -alarm_remove (gpointer alarm) -{ - AlarmRecord *ar; - AlarmRecord *old_head; - GList *l; - - g_return_if_fail (alarm_inited); - g_return_if_fail (alarm != NULL); - - ar = alarm; - - l = g_list_find (alarms, ar); - if (!l) { - g_message ("alarm_remove(): Requested removal of nonexistent alarm!"); - return; - } - - old_head = alarms->data; - - if (old_head == ar) - pop_alarm (); - else { - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - } - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (ar, ar->data); - - g_free (ar); -} - -/** - * alarm_init: - * - * Initializes the alarm timer mechanism. This must be called near the - * beginning of the program. - **/ -void -alarm_init (void) -{ - struct sigaction sa; - int flags; - - g_return_if_fail (alarm_inited == FALSE); - - pipe (alarm_pipes); - - /* set non blocking mode */ - flags = 0; - fcntl (alarm_pipes [0], F_GETFL, &flags); - fcntl (alarm_pipes [0], F_SETFL, flags | O_NONBLOCK); - gdk_input_add (alarm_pipes [0], GDK_INPUT_READ, alarm_ready, NULL); - - /* Setup the signal handler */ - sa.sa_handler = alarm_signal; - sigemptyset (&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction (SIGALRM, &sa, NULL); - - alarm_inited = TRUE; -} - -/** - * alarm_done: - * - * Terminates the alarm timer mechanism. This should be called at the end of - * the program. - **/ -void -alarm_done (void) -{ - GList *l; - - g_return_if_fail (alarm_inited); - - if (!clear_itimer ()) - g_message ("alarm_done(): Could not clear the timer! " - "Weird things may happen."); - - for (l = alarms; l; l = l->next) { - AlarmRecord *ar; - - ar = l->data; - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (ar, ar->data); - - g_free (ar); - } - - g_list_free (alarms); - alarms = NULL; - - if (close (alarm_pipes[0]) != 0) - g_message ("alarm_done(): Could not close the input pipe for notification"); - - alarm_pipes[0] = -1; - - if (close (alarm_pipes[1]) != 0) - g_message ("alarm_done(): Could not close the output pipe for notification"); - - alarm_pipes[1] = -1; - - alarm_inited = FALSE; -} diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h deleted file mode 100644 index b5d57cbe49..0000000000 --- a/calendar/gui/alarm-notify/alarm.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Evolution calendar - Low-level alarm timer mechanism - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * 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_H -#define ALARM_H - -#include <time.h> -#include <glib.h> - - - -typedef void (* AlarmFunction) (gpointer alarm_id, time_t trigger, gpointer data); -typedef void (* AlarmDestroyNotify) (gpointer alarm_id, gpointer data); - -void alarm_init (void); -void alarm_done (void); - -gpointer alarm_add (time_t trigger, AlarmFunction alarm_fn, gpointer data, - AlarmDestroyNotify destroy_notify_fn); -void alarm_remove (gpointer alarm); - - - -#endif diff --git a/calendar/gui/alarm-notify/client-main.c b/calendar/gui/alarm-notify/client-main.c deleted file mode 100644 index 5b0fb669d2..0000000000 --- a/calendar/gui/alarm-notify/client-main.c +++ /dev/null @@ -1,178 +0,0 @@ -/* Evolution calendar - Command-line client for the alarm notification service - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * 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 "config.h" -#endif - -#include <liboaf/liboaf.h> -#include "evolution-calendar.h" - - - -/* Requests that a calendar be added to the alarm notification service */ -static void -add_calendar (GNOME_Evolution_Calendar_AlarmNotify an, const char *uri) -{ - CORBA_Environment ev; - - 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"); - goto out; - } 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"); - goto out; - } - } - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("add_calendar(): Could not issue the addCalendar request"); - - out: - CORBA_exception_free (&ev); -} - -/* Loads the calendars that the user has configured to be loaded */ -static void -load_calendars (void) -{ - CORBA_Environment ev; - GNOME_Evolution_Calendar_AlarmNotify an; - char *base_uri; - char *uri; - - CORBA_exception_init (&ev); - an = oaf_activate_from_id ("OAFID:GNOME_Evolution_Calendar_AlarmNotify", 0, NULL, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_message ("load_calendars(): Could not activate the alarm notification service"); - CORBA_exception_free (&ev); - exit (EXIT_FAILURE); - } - CORBA_exception_free (&ev); - - /* FIXME: this should be obtained from the configuration in the Wombat */ - - base_uri = g_concat_dir_and_file (g_get_home_dir (), "evolution"); - - uri = g_concat_dir_and_file (base_uri, "local/Calendar/calendar.ics"); - add_calendar (an, uri); - g_free (uri); - - uri = g_concat_dir_and_file (base_uri, "local/Tasks/tasks.ics"); - add_calendar (an, uri); - g_free (uri); - - g_free (base_uri); - - CORBA_exception_init (&ev); - Bonobo_Unknown_unref (an, &ev); - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("load_calendars(): Could not unref the alarm notification service"); - - CORBA_exception_free (&ev); - - CORBA_exception_init (&ev); - CORBA_Object_release (an, &ev); - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("load_calendars(): Could not release the alarm notification service"); - - CORBA_exception_free (&ev); -} - -/* FIXME: handle the --die option */ - -int -main (int argc, char **argv) -{ - GnomeClient *client; - int flags; - gboolean launch_service; - - bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR); - textdomain (PACKAGE); - - if (gnome_init_with_popt_table ("evolution-alarm-client", VERSION, - argc, argv, oaf_popt_options, 0, NULL) != 0) { - g_message ("main(): Could not initialize GNOME"); - exit (EXIT_FAILURE); - } - - oaf_init (argc, argv); - - if (!bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) { - g_message ("main(): Could not initialize Bonobo"); - exit (EXIT_FAILURE); - } - - /* Ask the session manager to restart us */ - - client = gnome_master_client (); - flags = gnome_client_get_flags (client); - - if (flags & GNOME_CLIENT_IS_CONNECTED) { - char *client_id; - - client_id = gnome_client_get_id (client); - g_assert (client_id != NULL); - - launch_service = gnome_startup_acquire_token ("EVOLUTION_ALARM_NOTIFY", - client_id); - - if (launch_service) { - char *args[3]; - - args[0] = argv[0]; - args[2] = NULL; - - gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY); - gnome_client_set_restart_command (client, 2, args); - - args[0] = argv[0]; - args[1] = "--die"; - args[2] = NULL; - - gnome_client_set_shutdown_command (client, 2, args); - } else - gnome_client_set_restart_style (client, GNOME_RESTART_NEVER); - - gnome_client_flush (client); - } else - launch_service = TRUE; - - if (!launch_service) - return EXIT_SUCCESS; - - load_calendars (); - - return EXIT_SUCCESS; -} diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c deleted file mode 100644 index b8b409632d..0000000000 --- a/calendar/gui/alarm-notify/notify-main.c +++ /dev/null @@ -1,128 +0,0 @@ -/* Evolution calendar - Alarm notification service main file - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * 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 "config.h" -#endif - -#include <glib.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-init.h> -#include <libgnomevfs/gnome-vfs-init.h> -#include <glade/glade.h> -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-generic-factory.h> -#include <liboaf/liboaf.h> -#include "alarm.h" -#include "alarm-queue.h" -#include "alarm-notify.h" - - - -static BonoboGenericFactory *factory; - -static AlarmNotify *alarm_notify_service; - - -/* La de da */ -static void -funny_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - char *msg; - char str[256]; - struct tm *tm; - - tm = localtime (&trigger); - 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); - gnome_ok_dialog (msg); - g_free (msg); -} - -/* Dum de dum */ -static void -funny_times_init (void) -{ - alarm_add ((time_t) 999999999L, funny_trigger_cb, NULL, NULL); /* Sep 9 01:46:39 2001 UTC */ -} - -/* 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; - } - - bonobo_object_ref (BONOBO_OBJECT (alarm_notify_service)); - return BONOBO_OBJECT (alarm_notify_service); -} - -int -main (int argc, char **argv) -{ - bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR); - textdomain (PACKAGE); - - if (gnome_init_with_popt_table ("evolution-alarm-notify", VERSION, argc, argv, - oaf_popt_options, 0, NULL) != 0) - g_error (_("Could not initialize GNOME")); - - oaf_init (argc, 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")); - - glade_gnome_init (); - - alarm_init (); - alarm_queue_init (); - - funny_times_init (); - - 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")); - - bonobo_main (); - - bonobo_object_unref (BONOBO_OBJECT (factory)); - factory = NULL; - - alarm_queue_done (); - alarm_done (); - - gnome_vfs_shutdown (); - - return 0; -} |