diff options
Diffstat (limited to 'calendar/gui/alarm-notify')
-rw-r--r-- | calendar/gui/alarm-notify/.cvsignore | 12 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in | 28 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/Makefile.am | 68 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify-dialog.c | 410 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify-dialog.h | 44 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.c | 336 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.glade | 307 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.h | 64 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-queue.c | 1382 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-queue.h | 34 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm.c | 301 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm.h | 42 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/config-data.c | 251 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/config-data.h | 38 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/notify-main.c | 171 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/util.c | 49 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/util.h | 29 |
17 files changed, 0 insertions, 3566 deletions
diff --git a/calendar/gui/alarm-notify/.cvsignore b/calendar/gui/alarm-notify/.cvsignore deleted file mode 100644 index d940a07146..0000000000 --- a/calendar/gui/alarm-notify/.cvsignore +++ /dev/null @@ -1,12 +0,0 @@ -.deps -.libs -.pure -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*.server -GNOME_Evolution_Calendar_AlarmNotify*.server.in diff --git a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in b/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in deleted file mode 100644 index e528b15f75..0000000000 --- a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in +++ /dev/null @@ -1,28 +0,0 @@ -<oaf_info> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory:@VERSION@" - type="exe" - location="@LIBEXECDIR@/evolution-alarm-notify"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar alarm notification service"/> - -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_AlarmNotify:@VERSION@" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory:@VERSION@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:Bonobo/Unknown:1.0"/> - <item value="IDL:GNOME/Evolution/Calendar/AlarmNotify:@VERSION@"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" _value="Evolution Calendar 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 ffe95557ec..0000000000 --- a/calendar/gui/alarm-notify/Makefile.am +++ /dev/null @@ -1,68 +0,0 @@ -CORBA_GENERATED_H = \ - evolution-calendar.h -CORBA_GENERATED_C = \ - evolution-calendar-common.c \ - evolution-calendar-skels.c \ - evolution-calendar-stubs.c -CORBA_GENERATED = $(CORBA_GENERATED_C) $(CORBA_GENERATED_H) - -idls = $(top_srcdir)/calendar/idl/evolution-calendar.idl -idl_flags = $(IDL_INCLUDES) - -$(CORBA_GENERATED_H): $(idls) - $(ORBIT_IDL) $(idl_flags) $(top_srcdir)/calendar/idl/evolution-calendar.idl -$(CORBA_GENERATED_C): $(CORBA_GENERATED_H) - - -privlibexec_PROGRAMS = evolution-alarm-notify - - -INCLUDES = \ - -DG_LOG_DOMAIN=\"evolution-alarm-notify\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets \ - -I$(top_srcdir)/calendar \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \ - -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ - -DEVOLUTION_LIBEXECDIR=\""$(privlibexecdir)"\" \ - $(EVOLUTION_CALENDAR_CFLAGS) - -glade_DATA = \ - alarm-notify.glade - -evolution_alarm_notify_SOURCES = \ - $(CORBA_GENERATED) \ - alarm.c \ - alarm.h \ - alarm-notify.c \ - alarm-notify.h \ - alarm-notify-dialog.c \ - alarm-notify-dialog.h \ - alarm-queue.c \ - alarm-queue.h \ - config-data.c \ - config-data.h \ - notify-main.c \ - util.c \ - util.h - -evolution_alarm_notify_LDADD = \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/calendar/common/libevolution-calendarprivate.la \ - $(EVOLUTION_CALENDAR_LIBS) - -server_in_files = GNOME_Evolution_Calendar_AlarmNotify.server.in.in -server_DATA = $(server_in_files:.server.in.in=_$(BASE_VERSION).server) -@EVO_SERVER_RULE@ -@INTLTOOL_SERVER_RULE@ - -EXTRA_DIST = \ - $(server_in_files) \ - $(glade_DATA) - -BUILT_SOURCES = $(CORBA_GENERATED) $(server_DATA) -CLEANFILES = $(BUILT_SOURCES) - -dist-hook: - cd $(distdir); rm -f $(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 af31715ea9..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.c +++ /dev/null @@ -1,410 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2000 Ximian, Inc. - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <stdio.h> -#include <string.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkspinbutton.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkscrolledwindow.h> -#include <gtk/gtkwindow.h> -#include <libgnome/gnome-i18n.h> -#if 0 -# include <libgnomeui/gnome-winhints.h> -#endif -#include <glade/glade.h> -#include <e-util/e-time-utils.h> -#include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> -#include <libecal/e-cal-time-util.h> -#include "alarm-notify-dialog.h" -#include "config-data.h" -#include "util.h" -#include <e-util/e-icon-factory.h> - - -GtkWidget *make_html_display (gchar *widget_name, char *s1, char *s2, int scroll, int shadow); - -/* The useful contents of the alarm notify dialog */ -typedef struct { - GladeXML *xml; - - GtkWidget *dialog; - GtkWidget *close; - GtkWidget *snooze; - GtkWidget *edit; - GtkWidget *snooze_time; - GtkWidget *html; - - 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; - g_object_unref (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); -} - -static void -url_requested_cb (GtkHTML *html, const char *url, GtkHTMLStream *stream, gpointer data) -{ - - if (!strncmp ("file:///", url, strlen ("file:///"))) { - FILE *fp; - const char *filename = url + strlen ("file://"); - char buf[4096]; - size_t len; - - fp = fopen (filename, "r"); - - if (fp == NULL) { - g_warning ("Error opening image: %s\n", url); - gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); - return; - } - - while ((len = fread (buf, 1, sizeof(buf), fp)) > 0) - gtk_html_stream_write (stream, buf, len); - - if (feof (fp)) { - fclose (fp); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); - return; - } - - fclose (fp); - } - - g_warning ("Error loading image"); - gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); - return; -} - -GtkWidget * -make_html_display (gchar *widget_name, char *s1, char *s2, int scroll, int shadow) -{ - GtkWidget *html, *scrolled_window; - - gtk_widget_push_colormap (gdk_rgb_get_colormap ()); - - html = gtk_html_new(); - - gtk_html_set_default_content_type (GTK_HTML (html), - "charset=utf-8"); - gtk_html_load_empty (GTK_HTML (html)); - - g_signal_connect (html, "url_requested", - G_CALLBACK (url_requested_cb), - NULL); - - gtk_widget_pop_colormap(); - - scrolled_window = gtk_scrolled_window_new(NULL, NULL); - - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_SHADOW_IN); - - gtk_widget_set_size_request (scrolled_window, 300, 200); - - gtk_container_add(GTK_CONTAINER (scrolled_window), html); - - gtk_widget_show_all(scrolled_window); - - g_object_set_data (G_OBJECT (scrolled_window), "html", html); - return scrolled_window; -} - -static void -write_times (GtkHTMLStream *stream, char *start, char *end) -{ - if (start) - gtk_html_stream_printf (stream, "<b>%s</b> %s<br>", _("Starting:"), start); - if (end) - gtk_html_stream_printf (stream, "<b>%s</b> %s<br>", _("Ending:"), end); - -} - -/* Creates a heading for the alarm notification dialog */ -static void -write_html_heading (GtkHTMLStream *stream, const char *message, - ECalComponentVType vtype, time_t occur_start, time_t occur_end) -{ - char *buf; - char *start, *end; - char *bg_path = "file://" EVOLUTION_IMAGESDIR "/bcg.png"; - gchar *image_path; - gchar *icon_path; - icaltimezone *current_zone; - - icon_path = e_icon_factory_get_icon_filename ("stock_alarm", E_ICON_SIZE_DIALOG); - image_path = g_strdup_printf ("file://%s", icon_path); - g_free (icon_path); - - /* Stringize the times */ - - current_zone = config_data_get_timezone (); - - buf = timet_to_str_with_zone (occur_start, current_zone); - start = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - g_free (buf); - - buf = timet_to_str_with_zone (occur_end, current_zone); - end = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - g_free (buf); - - /* Write the header */ - - gtk_html_stream_printf (stream, - "<HTML><BODY background=\"%s\">" - "<TABLE WIDTH=\"100%%\">" - "<TR>" - "<TD><IMG SRC=\"%s\" ALIGN=\"top\" BORDER=\"0\"></TD>" - "<TD><H1>%s</H1></TD>" - "</TR>" - "</TABLE>", - bg_path, - image_path, - _("Evolution Alarm")); - - gtk_html_stream_printf (stream, "<br><br><font size=\"+2\">%s</font><br><br>", message); - - /* Write the times */ - - switch (vtype) { - case E_CAL_COMPONENT_EVENT: - write_times (stream, start, end); - break; - - case E_CAL_COMPONENT_TODO: - write_times (stream, start, end); - break; - - default: - /* Only VEVENTs and VTODOs can have alarms */ - g_assert_not_reached (); - break; - } - - g_free (start); - g_free (end); - g_free (image_path); -} - -/** - * 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: a pointer to the dialog structure if successful or NULL if an error occurs. - **/ -gpointer -alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, - ECalComponentVType vtype, const char *message, - AlarmNotifyFunc func, gpointer func_data) -{ - AlarmNotify *an; - GtkHTMLStream *stream; - icaltimezone *current_zone; - char *buf, *title; - GList *icon_list; - - g_return_val_if_fail (trigger != -1, NULL); - - /* Only VEVENTs or VTODOs can have alarms */ - g_return_val_if_fail (vtype == E_CAL_COMPONENT_EVENT || vtype == E_CAL_COMPONENT_TODO, NULL); - g_return_val_if_fail (message != NULL, NULL); - g_return_val_if_fail (func != NULL, NULL); - - an = g_new0 (AlarmNotify, 1); - - an->func = func; - an->func_data = func_data; - - an->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-notify.glade", NULL, NULL); - if (!an->xml) { - g_message ("alarm_notify_dialog(): Could not load the Glade XML file!"); - g_free (an); - return NULL; - } - - 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->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); - an->html = g_object_get_data (G_OBJECT (glade_xml_get_widget (an->xml, "frame")), "html"); - - if (!(an->dialog && an->close && an->snooze && an->edit - && an->snooze_time)) { - g_message ("alarm_notify_dialog(): Could not find all widgets in Glade file!"); - g_object_unref (an->xml); - g_free (an); - return NULL; - } - - gtk_widget_realize (an->dialog); - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (an->dialog)->vbox), 0); - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (an->dialog)->action_area), 12); - - g_signal_connect (G_OBJECT (an->dialog), "destroy", - G_CALLBACK (dialog_destroy_cb), - an); - - /* Title */ - - current_zone = config_data_get_timezone (); - - buf = timet_to_str_with_zone (trigger, current_zone); - title = g_strdup_printf (_("Alarm on %s"), buf); - g_free (buf); - - gtk_window_set_title (GTK_WINDOW (an->dialog), title); - g_free (title); - - /* html heading */ - stream = gtk_html_begin (GTK_HTML (an->html)); - write_html_heading (stream, message, vtype, occur_start, occur_end); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); - - /* Connect actions */ - - g_signal_connect (an->dialog, "delete_event", - G_CALLBACK (delete_event_cb), - an); - - g_signal_connect (an->close, "clicked", - G_CALLBACK (close_clicked_cb), - an); - - g_signal_connect (an->snooze, "clicked", - G_CALLBACK (snooze_clicked_cb), - an); - - g_signal_connect (an->edit, "clicked", - G_CALLBACK (edit_clicked_cb), - an); - - /* Run! */ - - if (!GTK_WIDGET_REALIZED (an->dialog)) - gtk_widget_realize (an->dialog); - - icon_list = e_icon_factory_get_icon_list ("stock_alarm"); - if (icon_list) { - gtk_window_set_icon_list (GTK_WINDOW (an->dialog), icon_list); - g_list_foreach (icon_list, (GFunc) g_object_unref, NULL); - g_list_free (icon_list); - } - - gtk_widget_show (an->dialog); - return an; -} - -void -alarm_notify_dialog_disable_buttons (gpointer dialog) -{ - AlarmNotify *an = dialog; - - gtk_widget_set_sensitive (an->snooze, FALSE); - gtk_widget_set_sensitive (an->edit, FALSE); -} 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 9bebce0a08..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.h +++ /dev/null @@ -1,44 +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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <libecal/e-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); - -gpointer alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, - ECalComponentVType vtype, const char *message, - AlarmNotifyFunc func, gpointer func_data); -void alarm_notify_dialog_disable_buttons (gpointer dialog); - - -#endif diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c deleted file mode 100644 index 19e5daf15f..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ /dev/null @@ -1,336 +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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <string.h> -#include <bonobo/bonobo-main.h> -#include <libecal/e-cal.h> -#include "alarm-notify.h" -#include "alarm-queue.h" -#include "config-data.h" -#include "common/authentication.h" -#include "e-util/e-url.h" - - - -/* Private part of the AlarmNotify structure */ -struct _AlarmNotifyPrivate { - /* Mapping from EUri's to LoadedClient structures */ - /* FIXME do we need per source type uri hashes? or perhaps we - just need to hash based on source */ - GHashTable *uri_client_hash; - - ESourceList *source_lists [E_CAL_SOURCE_TYPE_LAST]; -}; - - - -static void alarm_notify_class_init (AlarmNotifyClass *klass); -static void alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass); -static void alarm_notify_finalize (GObject *object); - - -static BonoboObjectClass *parent_class; - - - -BONOBO_TYPE_FUNC_FULL(AlarmNotify, GNOME_Evolution_Calendar_AlarmNotify, BONOBO_TYPE_OBJECT, alarm_notify) - -/* Class initialization function for the alarm notify service */ -static void -alarm_notify_class_init (AlarmNotifyClass *klass) -{ - GObjectClass *object_class; - - object_class = (GObjectClass *) klass; - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = alarm_notify_finalize; -} - -typedef struct { - AlarmNotify *an; - ESourceList *source_list; - GList *removals; -} ProcessRemovalsData; - -static void -process_removal_in_hash (gpointer key, gpointer value, gpointer data) -{ - char *uri = key; - ProcessRemovalsData *prd = data; - GSList *groups, *sources, *p, *q; - gboolean found = FALSE; - - /* search the list of selected calendars */ - groups = e_source_list_peek_groups (prd->source_list); - for (p = groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - - sources = e_source_group_peek_sources (group); - for (q = sources; q != NULL; q = q->next) { - ESource *source = E_SOURCE (q->data); - char *source_uri; - - source_uri = e_source_get_uri (source); - if (strcmp (source_uri, uri) == 0) - found = TRUE; - g_free (source_uri); - - if (found) - return; - } - } - - /* not found, so list it for removal */ - prd->removals = g_list_prepend (prd->removals, uri); -} - -static void -list_changed_cb (ESourceList *source_list, gpointer data) -{ - AlarmNotify *an = data; - AlarmNotifyPrivate *priv; - GSList *groups, *sources, *p, *q; - ECalSourceType source_type = E_CAL_SOURCE_TYPE_LAST; - ProcessRemovalsData prd; - GList *l; - int i; - - priv = an->priv; - - /* Figure out the source type */ - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) { - if (source_list == priv->source_lists[i]) { - source_type = i; - break; - } - } - if (source_type == E_CAL_SOURCE_TYPE_LAST) - return; - - /* process the additions */ - groups = e_source_list_peek_groups (source_list); - for (p = groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - - sources = e_source_group_peek_sources (group); - for (q = sources; q != NULL; q = q->next) { - ESource *source = E_SOURCE (q->data); - char *uri; - - uri = e_source_get_uri (source); - if (!g_hash_table_lookup (priv->uri_client_hash, uri)) { - g_message ("Adding %s", uri); - alarm_notify_add_calendar (an, source_type, uri, FALSE); - } - g_free (uri); - } - } - - /* process the removals */ - prd.an = an; - prd.source_list = priv->source_lists[source_type]; - prd.removals = NULL; - g_hash_table_foreach (priv->uri_client_hash, (GHFunc) process_removal_in_hash, &prd); - - for (l = prd.removals; l; l = l->next) { - g_message ("Removing %s", (char *)l->data); - alarm_notify_remove_calendar (an, l->data); - } - g_list_free (prd.removals); -} - -static void -load_calendars (AlarmNotify *an, ECalSourceType source_type) -{ - AlarmNotifyPrivate *priv; - ESourceList *source_list; - GSList *groups, *sources, *p, *q; - - priv = an->priv; - - if (!e_cal_get_sources (&source_list, source_type, NULL)) { - g_message (G_STRLOC ": Could not get the list of sources to load"); - priv->source_lists[source_type] = NULL; - - return; - } - - groups = e_source_list_peek_groups (source_list); - for (p = groups; p != NULL; p = p->next) { - ESourceGroup *group = E_SOURCE_GROUP (p->data); - - sources = e_source_group_peek_sources (group); - for (q = sources; q != NULL; q = q->next) { - ESource *source = E_SOURCE (q->data); - char *uri; - - uri = e_source_get_uri (source); - g_message ("Loading %s", uri); - alarm_notify_add_calendar (an, source_type, uri, FALSE); - g_free (uri); - - } - } - - g_signal_connect_object (source_list, "changed", G_CALLBACK (list_changed_cb), an, 0); - priv->source_lists[source_type] = source_list; -} - -/* Object initialization function for the alarm notify system */ -static void -alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass) -{ - AlarmNotifyPrivate *priv; - int i; - - priv = g_new0 (AlarmNotifyPrivate, 1); - an->priv = priv; - - priv->uri_client_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - - alarm_queue_init (); - - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) - load_calendars (an, i); -} - -static void -dequeue_client (gpointer key, gpointer value, gpointer user_data) -{ - ECal *client = value; - - alarm_queue_remove_client (client); -} - -/* Finalize handler for the alarm notify system */ -static void -alarm_notify_finalize (GObject *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, dequeue_client, NULL); - g_hash_table_destroy (priv->uri_client_hash); - - g_free (priv); - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/** - * 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 = g_object_new (TYPE_ALARM_NOTIFY, - "poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL), - NULL); - return an; -} - -static void -cal_opened_cb (ECal *client, ECalendarStatus status, gpointer user_data) -{ - AlarmNotifyPrivate *priv; - AlarmNotify *an = ALARM_NOTIFY (user_data); - - priv = an->priv; - - if (status == E_CALENDAR_STATUS_OK) - alarm_queue_add_client (client); - else { - g_hash_table_remove (priv->uri_client_hash, - e_cal_get_uri (client)); - } -} - -/** - * alarm_notify_add_calendar: - * @an: An alarm notification service. - * @uri: URI of the calendar to load. - * @load_afterwards: Whether this calendar should be loaded in the future - * when the alarm daemon starts up. - * - * Tells the alarm notification service to load a calendar and start monitoring - * its alarms. It can optionally be made to save the URI of this calendar so - * that it can be loaded in the future when the alarm daemon starts up. - **/ -void -alarm_notify_add_calendar (AlarmNotify *an, ECalSourceType source_type, const char *str_uri, gboolean load_afterwards) -{ - AlarmNotifyPrivate *priv; - ECal *client; - - g_return_if_fail (an != NULL); - g_return_if_fail (IS_ALARM_NOTIFY (an)); - g_return_if_fail (str_uri != NULL); - - priv = an->priv; - - /* See if we already know about this uri */ - if (g_hash_table_lookup (priv->uri_client_hash, str_uri)) - return; - - client = auth_new_cal_from_uri (str_uri, source_type); - - if (client) { - g_hash_table_insert (priv->uri_client_hash, g_strdup (str_uri), client); - g_signal_connect (G_OBJECT (client), "cal_opened", G_CALLBACK (cal_opened_cb), an); - e_cal_open_async (client, FALSE); - } -} - -void -alarm_notify_remove_calendar (AlarmNotify *an, const char *str_uri) -{ - AlarmNotifyPrivate *priv; - ECal *client; - - priv = an->priv; - - client = g_hash_table_lookup (priv->uri_client_hash, str_uri); - if (client) { - alarm_queue_remove_client (client); - g_hash_table_remove (priv->uri_client_hash, str_uri); - } -} diff --git a/calendar/gui/alarm-notify/alarm-notify.glade b/calendar/gui/alarm-notify/alarm-notify.glade deleted file mode 100644 index 1d53234c3e..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.glade +++ /dev/null @@ -1,307 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkDialog" id="alarm-notify"> - <property name="visible">True</property> - <property name="title" translatable="yes"></property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - <property name="decorated">True</property> - <property name="skip_taskbar_hint">False</property> - <property name="skip_pager_hint">False</property> - <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> - <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> - <property name="has_separator">False</property> - - <child internal-child="vbox"> - <widget class="GtkVBox" id="dialog-vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">0</property> - - <child internal-child="action_area"> - <widget class="GtkHButtonBox" id="dialog-action_area1"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> - - <child> - <widget class="GtkButton" id="edit"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="response_id">0</property> - - <child> - <widget class="GtkAlignment" id="alignment1"> - <property name="visible">True</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <property name="top_padding">0</property> - <property name="bottom_padding">0</property> - <property name="left_padding">0</property> - <property name="right_padding">0</property> - - <child> - <widget class="GtkHBox" id="hbox5"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">2</property> - - <child> - <widget class="GtkImage" id="image1"> - <property name="visible">True</property> - <property name="stock">gtk-properties</property> - <property name="icon_size">4</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Edit appointment</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - </widget> - </child> - </widget> - </child> - - <child> - <widget class="GtkButton" id="snooze"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="response_id">0</property> - - <child> - <widget class="GtkAlignment" id="alignment2"> - <property name="visible">True</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <property name="top_padding">0</property> - <property name="bottom_padding">0</property> - <property name="left_padding">0</property> - <property name="right_padding">0</property> - - <child> - <widget class="GtkHBox" id="hbox6"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">2</property> - - <child> - <widget class="GtkImage" id="image2"> - <property name="visible">True</property> - <property name="stock">gtk-refresh</property> - <property name="icon_size">4</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label6"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Snooze</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - </widget> - </child> - </widget> - </child> - - <child> - <widget class="GtkButton" id="close"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-close</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="response_id">-7</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox2"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">12</property> - - <child> - <widget class="GtkHBox" id="hbox3"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkVBox" id="vbox5"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="Custom" id="frame"> - <property name="visible">True</property> - <property name="creation_function">make_html_display</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Thu, 11 Oct 2001 08:19:04 GMT</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox4"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="label" translatable="yes">Snooze _time (minutes):</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">snooze-time</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="snooze-time"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">5 1 1440 1 5 5</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/alarm-notify/alarm-notify.h b/calendar/gui/alarm-notify/alarm-notify.h deleted file mode 100644 index f64452d450..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.h +++ /dev/null @@ -1,64 +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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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-object.h> -#include "evolution-calendar.h" - - - -#define TYPE_ALARM_NOTIFY (alarm_notify_get_type ()) -#define ALARM_NOTIFY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ALARM_NOTIFY, AlarmNotify)) -#define ALARM_NOTIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ALARM_NOTIFY, \ - AlarmNotifyClass)) -#define IS_ALARM_NOTIFY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ALARM_NOTIFY)) -#define IS_ALARM_NOTIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ALARM_NOTIFY)) - -typedef struct _AlarmNotify AlarmNotify; -typedef struct _AlarmNotifyClass AlarmNotifyClass; - -typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate; - -struct _AlarmNotify { - BonoboObject object; - - /* Private data */ - AlarmNotifyPrivate *priv; -}; - -struct _AlarmNotifyClass { - BonoboObjectClass parent_class; - POA_GNOME_Evolution_Calendar_AlarmNotify__epv epv; -}; - -GType alarm_notify_get_type (void); - -AlarmNotify *alarm_notify_new (void); - -void alarm_notify_add_calendar (AlarmNotify *an, ECalSourceType source_type, const char *str_uri, gboolean load_afterwards); -void alarm_notify_remove_calendar (AlarmNotify *an, const char *str_uri); - - - - -#endif diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c deleted file mode 100644 index 08d3033dcb..0000000000 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ /dev/null @@ -1,1382 +0,0 @@ -/* Evolution calendar - Alarm queueing engine - * - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <string.h> -#include <glib.h> -#include <bonobo-activation/bonobo-activation.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-exception.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkbox.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkeventbox.h> -#include <gtk/gtkimage.h> -#include <gtk/gtkimagemenuitem.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtkstock.h> -#include <gtk/gtktooltips.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-exec.h> -#include <libgnome/gnome-sound.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeui/gnome-uidefs.h> -#include <e-util/eggtrayicon.h> -#include <e-util/e-icon-factory.h> -#include <libecal/e-cal-time-util.h> -#include "evolution-calendar.h" -#include "alarm.h" -#include "alarm-notify-dialog.h" -#include "alarm-queue.h" -#include "config-data.h" -#include "util.h" - - - -/* Whether the queueing system has been initialized */ -static gboolean alarm_queue_inited; - -/* When the alarm queue system is inited, this gets set to the last time an - * alarm notification was issued. This lets us present any notifications that - * should have happened while the alarm daemon was not running. - */ -static time_t saved_notification_time; - -/* Clients we are monitoring for alarms */ -static GHashTable *client_alarms_hash = NULL; - -/* List of tray icons being displayed */ -static GList *tray_icons_list = NULL; - -/* Structure that stores a client we are monitoring */ -typedef struct { - /* Monitored client */ - ECal *client; - - /* The live query to the calendar */ - ECalView *query; - - /* 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 ECalComponentAlarms and the mapping from queued alarm IDs to the - * actual alarm instance structures. - */ -typedef struct { - /* The parent client alarms structure */ - ClientAlarms *parent_client; - - /* The component's UID */ - char *uid; - - /* The actual component and its alarm instances */ - ECalComponentAlarms *alarms; - - /* List of QueuedAlarm structures */ - GSList *queued_alarms; - - /* Flags */ - gboolean expecting_update; -} 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 */ - ECalComponentAlarmInstance *instance; - - /* Whether this is a snoozed queued alarm or a normal one */ - guint snooze : 1; -} QueuedAlarm; - -/* Alarm ID for the midnight refresh function */ -static gpointer midnight_refresh_id = NULL; - -static void display_notification (time_t trigger, CompQueuedAlarms *cqa, - gpointer alarm_id, gboolean use_description); -static void audio_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id); -static void mail_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id); -static void procedure_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id); - -static void query_objects_changed_cb (ECal *client, GList *objects, gpointer data); -static void query_objects_removed_cb (ECal *client, GList *objects, gpointer data); - - - -/* Alarm queue engine */ - -static void load_alarms_for_today (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; - icaltimezone *zone; - - g_assert (midnight_refresh_id == NULL); - - zone = config_data_get_timezone (); - - midnight = time_day_end_with_zone (time (NULL), zone); - - 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_for_today (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 (ECal *client) -{ - return g_hash_table_lookup (client_alarms_hash, client); -} - -/* Looks up a queued alarm based on its alarm ID */ -static QueuedAlarm * -lookup_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id) -{ - GSList *l; - QueuedAlarm *qa; - - qa = NULL; - - for (l = cqa->queued_alarms; l; l = l->next) { - qa = l->data; - if (qa->alarm_id == alarm_id) - return qa; - } - - /* not found, might have been updated/removed */ - return NULL; -} - -/* Removes an alarm from the list of alarms of a component. If the alarm was - * the last one listed for the component, it removes the component itself. - */ -static void -remove_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id, - gboolean free_object, gboolean remove_alarm) -{ - QueuedAlarm *qa; - GSList *l; - - qa = NULL; - - for (l = cqa->queued_alarms; l; l = l->next) { - qa = l->data; - if (qa->alarm_id == alarm_id) - break; - } - - if (!l) - return; - - cqa->queued_alarms = g_slist_remove_link (cqa->queued_alarms, l); - g_slist_free_1 (l); - - if (remove_alarm) { - cqa->expecting_update = TRUE; - e_cal_discard_alarm (cqa->parent_client->client, cqa->alarms->comp, - qa->instance->auid, NULL); - cqa->expecting_update = FALSE; - } - - g_free (qa); - - /* If this was the last queued alarm for this component, remove the - * component itself. - */ - - if (cqa->queued_alarms != NULL) - return; - - if (free_object) { - g_hash_table_remove (cqa->parent_client->uid_alarms_hash, cqa->uid); - g_free (cqa->uid); - cqa->uid = NULL; - cqa->parent_client = NULL; - e_cal_component_alarms_free (cqa->alarms); - g_free (cqa); - } else { - e_cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - } -} - -/* Callback used when an alarm triggers */ -static void -alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - CompQueuedAlarms *cqa; - ECalComponent *comp; - QueuedAlarm *qa; - ECalComponentAlarm *alarm; - ECalComponentAlarmAction action; - - cqa = data; - comp = cqa->alarms->comp; - - config_data_set_last_notification_time (trigger); - saved_notification_time = trigger; - - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - /* 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 = e_cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - e_cal_component_alarm_get_action (alarm, &action); - e_cal_component_alarm_free (alarm); - - switch (action) { - case E_CAL_COMPONENT_ALARM_AUDIO: - audio_notification (trigger, cqa, alarm_id); - break; - - case E_CAL_COMPONENT_ALARM_DISPLAY: - display_notification (trigger, cqa, alarm_id, TRUE); - break; - - case E_CAL_COMPONENT_ALARM_EMAIL: - mail_notification (trigger, cqa, alarm_id); - break; - - case E_CAL_COMPONENT_ALARM_PROCEDURE: - procedure_notification (trigger, cqa, alarm_id); - break; - - default: - g_assert_not_reached (); - break; - } -} - -/* Adds the alarms in a ECalComponentAlarms 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, ECalComponentAlarms *alarms) -{ - const char *uid; - CompQueuedAlarms *cqa; - GSList *l; - - /* No alarms? */ - if (alarms == NULL || alarms->alarms == NULL) { - g_message ("No alarms to add"); - if (alarms) - e_cal_component_alarms_free (alarms); - return; - } - - cqa = g_new (CompQueuedAlarms, 1); - cqa->parent_client = ca; - cqa->alarms = alarms; - cqa->expecting_update = FALSE; - - cqa->queued_alarms = NULL; - - for (l = alarms->alarms; l; l = l->next) { - ECalComponentAlarmInstance *instance; - gpointer alarm_id; - QueuedAlarm *qa; - - instance = l->data; - - g_message ("Adding alarm at %lu (%lu)", instance->trigger, time (NULL)); - alarm_id = alarm_add (instance->trigger, alarm_trigger_cb, cqa, NULL); - 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; - qa->snooze = FALSE; - - cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa); - } - - e_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); - - e_cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - - g_free (cqa); - return; - } - - cqa->queued_alarms = g_slist_reverse (cqa->queued_alarms); - cqa->uid = g_strdup (uid); - g_hash_table_insert (ca->uid_alarms_hash, cqa->uid, cqa); -} - -/* Loads the alarms of a client for a given range of time */ -static void -load_alarms (ClientAlarms *ca, time_t start, time_t end) -{ - /* create the live query */ - if (!ca->query) { - /* FIXME: handle errors */ - if (!e_cal_get_query (ca->client, "(has-alarms?)", &ca->query, NULL)) { - g_warning (G_STRLOC ": Could not get query for client"); - return; - } - - g_signal_connect (G_OBJECT (ca->query), "objects_added", - G_CALLBACK (query_objects_changed_cb), ca); - g_signal_connect (G_OBJECT (ca->query), "objects_modified", - G_CALLBACK (query_objects_changed_cb), ca); - g_signal_connect (G_OBJECT (ca->query), "objects_removed", - G_CALLBACK (query_objects_removed_cb), ca); - - e_cal_view_start (ca->query); - } -} - -/* Loads today's remaining alarms for a client */ -static void -load_alarms_for_today (ClientAlarms *ca) -{ - time_t now, day_end; - icaltimezone *zone; - - now = time (NULL); - - zone = config_data_get_timezone (); - - g_message ("Loading alarms for today"); - day_end = time_day_end_with_zone (now, zone); - load_alarms (ca, now, day_end); -} - -/* Adds any alarms that should have occurred while the alarm daemon was not - * running. - */ -static void -load_missed_alarms (ClientAlarms *ca) -{ - time_t now; - - now = time (NULL); - - g_assert (saved_notification_time != -1); - - /* We add 1 to the saved_notification_time to make the time ranges - * half-open; we do not want to display the "last" displayed alarm - * twice, once when it occurs and once when the alarm daemon restarts. - */ - load_alarms (ca, saved_notification_time + 1, now); -} - -/* Called when a calendar client finished loading; we load its alarms */ -static void -cal_opened_cb (ECal *client, ECalendarStatus status, gpointer data) -{ - ClientAlarms *ca; - - ca = data; - - if (status != E_CALENDAR_STATUS_OK) - return; - - load_alarms_for_today (ca); - load_missed_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); -} - -static void -remove_alarms (CompQueuedAlarms *cqa, gboolean free_object) -{ - GSList *l; - - for (l = cqa->queued_alarms; l;) { - QueuedAlarm *qa; - - qa = l->data; - - /* Get the next element here because the list element will go - * away in remove_queued_alarm(). The qa will be freed there as - * well. - */ - l = l->next; - - alarm_remove (qa->alarm_id); - remove_queued_alarm (cqa, qa->alarm_id, free_object, FALSE); - } - -} - -/* Removes a component an its alarms */ -static void -remove_comp (ClientAlarms *ca, const char *uid) -{ - CompQueuedAlarms *cqa; - - 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); - - remove_alarms (cqa, TRUE); - - /* 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 -query_objects_changed_cb (ECal *client, GList *objects, gpointer data) -{ - ClientAlarms *ca; - time_t from, day_end; - ECalComponentAlarms *alarms; - gboolean found; - icaltimezone *zone; - CompQueuedAlarms *cqa; - GList *l; - - ca = data; - - from = config_data_get_last_notification_time (); - if (from == -1) - from = time (NULL); - else - from += 1; /* we add 1 to make sure the alarm is not displayed twice */ - - zone = config_data_get_timezone (); - - day_end = time_day_end_with_zone (time (NULL), zone); - g_message ("Query response for alarms"); - for (l = objects; l != NULL; l = l->next) { - const char *uid; - GSList *sl; - - uid = icalcomponent_get_uid (l->data); - found = e_cal_get_alarms_for_object (ca->client, uid, from, day_end, &alarms); - - if (!found) { - g_message ("No alarms found on object"); - remove_comp (ca, uid); - continue; - } - - cqa = lookup_comp_queued_alarms (ca, uid); - if (!cqa) { - g_message ("No currently queue alarms"); - add_component_alarms (ca, alarms); - continue; - } - - g_message ("Already existing alarms"); - /* if the alarms or the alarms list is empty, just remove it */ - if (alarms == NULL || alarms->alarms == NULL) { - if (alarms) - e_cal_component_alarms_free (alarms); - continue; - } - - /* if already in the list, just update it */ - remove_alarms (cqa, FALSE); - cqa->alarms = alarms; - cqa->queued_alarms = NULL; - - /* add the new alarms */ - for (sl = cqa->alarms->alarms; sl; sl = sl->next) { - ECalComponentAlarmInstance *instance; - gpointer alarm_id; - QueuedAlarm *qa; - - instance = sl->data; - - alarm_id = alarm_add (instance->trigger, alarm_trigger_cb, cqa, NULL); - if (!alarm_id) { - g_message (G_STRLOC ": 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; - qa->snooze = FALSE; - - cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa); - } - - cqa->queued_alarms = g_slist_reverse (cqa->queued_alarms); - } -} - -/* Called when a calendar component is removed; we must delete its corresponding - * alarms. - */ -static void -query_objects_removed_cb (ECal *client, GList *objects, gpointer data) -{ - ClientAlarms *ca; - GList *l; - - ca = data; - - for (l = objects; l != NULL; l = l->next) - remove_comp (ca, l->data); -} - - - -/* Notification functions */ - -/* Creates a snooze alarm based on an existing one. The snooze offset is - * compued with respect to the current time. - */ -static void -create_snooze (CompQueuedAlarms *cqa, gpointer alarm_id, int snooze_mins) -{ - QueuedAlarm *orig_qa; - time_t t; - gpointer new_id; - - orig_qa = lookup_queued_alarm (cqa, alarm_id); - if (!orig_qa) - return; - - t = time (NULL); - t += snooze_mins * 60; - - new_id = alarm_add (t, alarm_trigger_cb, cqa, NULL); - if (!new_id) { - g_message ("create_snooze(): Could not schedule a trigger for " - "%ld, discarding...", (long) t); - return; - } - - orig_qa->instance->trigger = t; - orig_qa->alarm_id = new_id; - orig_qa->snooze = TRUE; -} - -/* Launches a component editor for a component */ -static void -edit_component (ECal *client, ECalComponent *comp) -{ - const char *uid; - const char *uri; - ECalSourceType source_type; - CORBA_Environment ev; - GNOME_Evolution_Calendar_CompEditorFactory factory; - GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode corba_type; - - e_cal_component_get_uid (comp, &uid); - - uri = e_cal_get_uri (client); - source_type = e_cal_get_source_type (client); - - /* Get the factory */ - CORBA_exception_init (&ev); - factory = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_CompEditorFactory:" BASE_VERSION, - 0, NULL, &ev); - - if (BONOBO_EX (&ev)) { - g_message (G_STRLOC ": Could not activate the component editor factory"); - CORBA_exception_free (&ev); - return; - } - - /* Edit the component */ - switch (source_type) { - case E_CAL_SOURCE_TYPE_TODO: - corba_type = GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO; - break; - default: - corba_type = GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT; - } - - GNOME_Evolution_Calendar_CompEditorFactory_editExisting (factory, uri, (char *) uid, corba_type, &ev); - - if (BONOBO_EX (&ev)) - g_message (G_STRLOC ": Exception while editing the component"); - - CORBA_exception_free (&ev); - - /* Get rid of the factory */ - bonobo_object_release_unref (factory, NULL); -} - -typedef struct { - char *message; - gboolean blink_state; - gint blink_id; - time_t trigger; - CompQueuedAlarms *cqa; - gpointer alarm_id; - ECalComponent *comp; - ECal *client; - ECalView *query; - GtkWidget *tray_icon; - GtkWidget *image; - GtkWidget *alarm_dialog; -} TrayIconData; - -static void -on_dialog_objs_removed_cb (ECal *client, GList *objects, gpointer data) -{ - const char *our_uid; - GList *l; - TrayIconData *tray_data = data; - - e_cal_component_get_uid (tray_data->comp, &our_uid); - g_return_if_fail (our_uid && *our_uid); - - for (l = objects; l != NULL; l = l->next) { - const char *uid = l->data; - - if (!uid) - continue; - - if (!strcmp (uid, our_uid)) { - if (tray_data->alarm_dialog) - alarm_notify_dialog_disable_buttons (tray_data->alarm_dialog); - tray_data->cqa = NULL; - tray_data->alarm_id = NULL; - - gtk_widget_destroy (tray_data->tray_icon); - } - } -} - -/* Callback used from the alarm notify dialog */ -static void -notify_dialog_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) -{ - TrayIconData *tray_data = data; - - g_signal_handlers_disconnect_matched (tray_data->query, G_SIGNAL_MATCH_FUNC, - 0, 0, NULL, on_dialog_objs_removed_cb, NULL); - - switch (result) { - case ALARM_NOTIFY_SNOOZE: - create_snooze (tray_data->cqa, tray_data->alarm_id, snooze_mins); - tray_data->cqa = NULL; - return; - - case ALARM_NOTIFY_EDIT: - edit_component (tray_data->client, tray_data->comp); - break; - - case ALARM_NOTIFY_CLOSE: - /* Do nothing */ - break; - - default: - g_assert_not_reached (); - } - - tray_data->alarm_dialog = NULL; - gtk_widget_destroy (tray_data->tray_icon); -} - -static gint -tray_icon_destroyed_cb (GtkWidget *tray, gpointer user_data) -{ - TrayIconData *tray_data = user_data; - - g_signal_handlers_disconnect_matched (tray_data->query, G_SIGNAL_MATCH_FUNC, - 0, 0, NULL, on_dialog_objs_removed_cb, NULL); - - if (tray_data->cqa != NULL) - remove_queued_alarm (tray_data->cqa, tray_data->alarm_id, TRUE, TRUE); - - if (tray_data->message != NULL) { - g_free (tray_data->message); - tray_data->message = NULL; - } - - if (tray_data->blink_id) - g_source_remove (tray_data->blink_id); - - g_object_unref (tray_data->comp); - g_object_unref (tray_data->client); - - tray_icons_list = g_list_remove (tray_icons_list, tray_data); - g_free (tray_data); - - return TRUE; -} - -/* Callbacks. */ -static void -add_popup_menu_item (GtkMenu *menu, const char *label, const char *pixmap, - GCallback callback, gpointer user_data) -{ - GtkWidget *item, *image; - - if (pixmap) { - item = gtk_image_menu_item_new_with_label (label); - - /* load the image */ - if (g_file_test (pixmap, G_FILE_TEST_EXISTS)) - image = gtk_image_new_from_file (pixmap); - else - image = gtk_image_new_from_stock (pixmap, GTK_ICON_SIZE_MENU); - - if (image) { - gtk_widget_show (image); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - } - } else { - item = gtk_menu_item_new_with_label (label); - } - - if (callback) - g_signal_connect (G_OBJECT (item), "activate", callback, user_data); - - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - gtk_widget_show (item); -} - -static gboolean -open_alarm_dialog (TrayIconData *tray_data) -{ - QueuedAlarm *qa; - - if (tray_data->alarm_dialog != NULL) - return FALSE; - - qa = lookup_queued_alarm (tray_data->cqa, tray_data->alarm_id); - if (qa) { - gtk_widget_hide (tray_data->tray_icon); - tray_data->alarm_dialog = alarm_notify_dialog ( - tray_data->trigger, - qa->instance->occur_start, - qa->instance->occur_end, - e_cal_component_get_vtype (tray_data->comp), - tray_data->message, - notify_dialog_cb, tray_data); - } - - return TRUE; -} - -static void -popup_dismiss_cb (GtkWidget *widget, TrayIconData *tray_data) -{ - gtk_widget_destroy (tray_data->tray_icon); -} - -static void -popup_dismiss_all_cb (GtkWidget *widget, TrayIconData *tray_data) -{ - while (tray_icons_list != NULL) { - TrayIconData *tray_data = tray_icons_list->data; - - gtk_widget_destroy (tray_data->tray_icon); - - tray_icons_list = g_list_remove (tray_icons_list, tray_icons_list); - } -} - -static void -popup_open_cb (GtkWidget *widget, TrayIconData *tray_data) -{ - open_alarm_dialog (tray_data); -} - -static gint -tray_icon_clicked_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data) -{ - TrayIconData *tray_data = user_data; - - if (event->type == GDK_BUTTON_PRESS) { - if (event->button == 1) { - return open_alarm_dialog (tray_data); - } else if (event->button == 3) { - GtkWidget *menu; - - /* display popup menu */ - menu = gtk_menu_new (); - add_popup_menu_item (GTK_MENU (menu), _("Open"), GTK_STOCK_OPEN, - G_CALLBACK (popup_open_cb), tray_data); - add_popup_menu_item (GTK_MENU (menu), _("Dismiss"), NULL, - G_CALLBACK (popup_dismiss_cb), tray_data); - add_popup_menu_item (GTK_MENU (menu), _("Dismiss All"), NULL, - G_CALLBACK (popup_dismiss_all_cb), tray_data); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); - - return TRUE; - } - } - - return FALSE; -} - -static gboolean -tray_icon_blink_cb (gpointer data) -{ - TrayIconData *tray_data = data; - GdkPixbuf *pixbuf; - - tray_data->blink_state = tray_data->blink_state == TRUE ? FALSE : TRUE; - pixbuf = e_icon_factory_get_icon (tray_data->blink_state == TRUE ? - "stock_appointment-reminder-excl" : - "stock_appointment-reminder", - E_ICON_SIZE_LARGE_TOOLBAR); - - gtk_image_set_from_pixbuf (GTK_IMAGE (tray_data->image), pixbuf); - g_object_unref (pixbuf); - - return TRUE; -} - -/* Performs notification of a display alarm */ -static void -display_notification (time_t trigger, CompQueuedAlarms *cqa, - gpointer alarm_id, gboolean use_description) -{ - QueuedAlarm *qa; - ECalComponent *comp; - const char *message; - ECalComponentAlarm *alarm; - GtkWidget *tray_icon, *image, *ebox; - GtkTooltips *tooltips; - TrayIconData *tray_data; - ECalComponentText text; - char *str, *start_str, *end_str, *alarm_str; - icaltimezone *current_zone; - GdkPixbuf *pixbuf; - - comp = cqa->alarms->comp; - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - /* get a sensible description for the event */ - alarm = e_cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - e_cal_component_alarm_get_description (alarm, &text); - e_cal_component_alarm_free (alarm); - - if (text.value) - message = text.value; - else { - e_cal_component_get_summary (comp, &text); - if (text.value) - message = text.value; - else - message = _("No description available."); - } - - /* create the tray icon */ - tooltips = gtk_tooltips_new (); - - /* FIXME: Use stock image equivalent when it becomes available */ - tray_icon = egg_tray_icon_new (qa->instance->auid); - pixbuf = e_icon_factory_get_icon ("stock_appointment-reminder", E_ICON_SIZE_LARGE_TOOLBAR); - image = gtk_image_new_from_pixbuf (pixbuf); - gdk_pixbuf_unref (pixbuf); - ebox = gtk_event_box_new (); - - gtk_widget_show (image); - gtk_widget_show (ebox); - - current_zone = config_data_get_timezone (); - alarm_str = timet_to_str_with_zone (trigger, current_zone); - start_str = timet_to_str_with_zone (qa->instance->occur_start, current_zone); - end_str = timet_to_str_with_zone (qa->instance->occur_end, current_zone); - str = g_strdup_printf (_("Alarm on %s\n%s\nStarting at %s\nEnding at %s"), - alarm_str, message, start_str, end_str); - gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), ebox, str, str); - g_free (start_str); - g_free (end_str); - g_free (alarm_str); - g_free (str); - - g_object_set_data (G_OBJECT (tray_icon), "image", image); - g_object_set_data (G_OBJECT (tray_icon), "available", GINT_TO_POINTER (1)); - - gtk_container_add (GTK_CONTAINER (ebox), image); - gtk_container_add (GTK_CONTAINER (tray_icon), ebox); - - /* create the private structure */ - tray_data = g_new0 (TrayIconData, 1); - tray_data->message = g_strdup (message); - tray_data->trigger = trigger; - tray_data->cqa = cqa; - tray_data->alarm_id = alarm_id; - tray_data->comp = e_cal_component_clone (comp); - tray_data->client = cqa->parent_client->client; - tray_data->query = cqa->parent_client->query; - tray_data->image = image; - tray_data->blink_state = FALSE; - g_object_ref (tray_data->client); - tray_data->tray_icon = tray_icon; - - tray_icons_list = g_list_prepend (tray_icons_list, tray_data); - - g_signal_connect (G_OBJECT (tray_icon), "destroy", - G_CALLBACK (tray_icon_destroyed_cb), tray_data); - g_signal_connect (G_OBJECT (ebox), "button_press_event", - G_CALLBACK (tray_icon_clicked_cb), tray_data); - g_signal_connect (G_OBJECT (tray_data->query), "objects_removed", - G_CALLBACK (on_dialog_objs_removed_cb), tray_data); - - if (!config_data_get_notify_with_tray ()) { - tray_data->blink_id = -1; - open_alarm_dialog (tray_data); - } else { - tray_data->blink_id = g_timeout_add (500, tray_icon_blink_cb, tray_data); - gtk_widget_show (tray_icon); - } -} - -/* Performs notification of an audio alarm */ -static void -audio_notification (time_t trigger, CompQueuedAlarms *cqa, - gpointer alarm_id) -{ - QueuedAlarm *qa; - ECalComponent *comp; - ECalComponentAlarm *alarm; - icalattach *attach; - int flag = 0; - - comp = cqa->alarms->comp; - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - alarm = e_cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - e_cal_component_alarm_get_attach (alarm, &attach); - e_cal_component_alarm_free (alarm); - - if (attach && icalattach_get_is_url (attach)) { - const char *url; - - url = icalattach_get_url (attach); - - if (url && *url && g_file_test (url, G_FILE_TEST_EXISTS)) { - flag = 1; - gnome_sound_play (url); /* this sucks */ - } - } - - if (!flag) - gdk_beep (); - - if (attach) - icalattach_unref (attach); - - /* We present a notification message in addition to playing the sound */ - display_notification (trigger, cqa, alarm_id, FALSE); -} - -/* Performs notification of a mail alarm */ -static void -mail_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id) -{ - GtkWidget *dialog; - GtkWidget *label; - - /* FIXME */ - - display_notification (trigger, cqa, alarm_id, FALSE); - - dialog = gtk_dialog_new_with_buttons (_("Warning"), - NULL, 0, - GTK_STOCK_OK, GTK_RESPONSE_CANCEL, - NULL); - label = gtk_label_new (_("Evolution does not support calendar reminders with\n" - "email notifications yet, but this reminder was\n" - "configured to send an email. Evolution will display\n" - "a normal reminder dialog box instead.")); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, TRUE, TRUE, 4); - - gtk_dialog_run (GTK_DIALOG (dialog)); -} - -/* Performs notification of a procedure alarm */ -static gboolean -procedure_notification_dialog (const char *cmd, const char *url) -{ - GtkWidget *dialog, *label, *checkbox; - char *str; - int btn; - - if (config_data_is_blessed_program (url)) - return TRUE; - - dialog = gtk_dialog_new_with_buttons (_("Warning"), - NULL, 0, - GTK_STOCK_NO, GTK_RESPONSE_CANCEL, - GTK_STOCK_YES, GTK_RESPONSE_OK, - NULL); - - str = g_strdup_printf (_("An Evolution Calendar reminder is about to trigger. " - "This reminder is configured to run the following program:\n\n" - " %s\n\n" - "Are you sure you want to run this program?"), - cmd); - label = gtk_label_new (str); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - label, TRUE, TRUE, 4); - g_free (str); - - checkbox = gtk_check_button_new_with_label - (_("Do not ask me about this program again.")); - gtk_widget_show (checkbox); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - checkbox, TRUE, TRUE, 4); - - /* Run the dialog */ - btn = gtk_dialog_run (GTK_DIALOG (dialog)); - if (btn == GTK_RESPONSE_OK && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox))) - config_data_save_blessed_program (url); - gtk_widget_destroy (dialog); - - return (btn == GTK_RESPONSE_OK); -} - -static void -procedure_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id) -{ - QueuedAlarm *qa; - ECalComponent *comp; - ECalComponentAlarm *alarm; - ECalComponentText description; - icalattach *attach; - const char *url; - char *cmd; - int result; - - comp = cqa->alarms->comp; - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - alarm = e_cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - e_cal_component_alarm_get_attach (alarm, &attach); - e_cal_component_alarm_get_description (alarm, &description); - e_cal_component_alarm_free (alarm); - - /* If the alarm has no attachment, simply display a notification dialog. */ - if (!attach) - goto fallback; - - if (!icalattach_get_is_url (attach)) { - icalattach_unref (attach); - goto fallback; - } - - url = icalattach_get_url (attach); - g_assert (url != NULL); - - /* Ask for confirmation before executing the stuff */ - if (description.value) - cmd = g_strconcat (url, " ", description.value, NULL); - else - cmd = (char *) url; - - result = 0; - if (procedure_notification_dialog (cmd, url)) - result = gnome_execute_shell (NULL, cmd); - - if (cmd != (char *) url) - g_free (cmd); - - icalattach_unref (attach); - - /* Fall back to display notification if we got an error */ - if (result < 0) - goto fallback; - - remove_queued_alarm (cqa, alarm_id, TRUE, TRUE); - return; - - fallback: - - display_notification (trigger, cqa, alarm_id, FALSE); -} - - - -/** - * alarm_queue_init: - * - * Initializes the alarm queueing system. This should be called near the - * beginning of the program. - **/ -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 (); - - saved_notification_time = config_data_get_last_notification_time (); - if (saved_notification_time == -1) { - saved_notification_time = time (NULL); - config_data_set_last_notification_time (saved_notification_time); - } - - alarm_queue_inited = TRUE; -} - -static void -free_client_alarms_cb (gpointer key, gpointer value, gpointer user_data) -{ - ClientAlarms *ca = value; - - if (ca) { - g_object_unref (ca->client); - g_free (ca); - } -} - -/** - * 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_foreach (client_alarms_hash, (GHFunc) free_client_alarms_cb, NULL); - 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 (ECal *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_queue_inited); - g_return_if_fail (client != NULL); - g_return_if_fail (E_IS_CAL (client)); - - ca = lookup_client (client); - if (ca) { - return; - } - - ca = g_new (ClientAlarms, 1); - - ca->client = client; - ca->query = NULL; - g_object_ref (ca->client); - - g_hash_table_insert (client_alarms_hash, client, ca); - - ca->uid_alarms_hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (e_cal_get_load_state (client) != E_CAL_LOAD_LOADED) - g_signal_connect (client, "cal_opened", - G_CALLBACK (cal_opened_cb), - ca); - - if (e_cal_get_load_state (client) == E_CAL_LOAD_LOADED) { - load_alarms_for_today (ca); - load_missed_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 (ECal *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_queue_inited); - g_return_if_fail (client != NULL); - g_return_if_fail (E_IS_CAL (client)); - - ca = lookup_client (client); - g_return_if_fail (ca != NULL); - - remove_client_alarms (ca); - - /* Clean up */ - - g_signal_handlers_disconnect_matched (ca->client, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, ca); - - g_object_unref (ca->query); - ca->query = NULL; - g_object_unref (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); -} diff --git a/calendar/gui/alarm-notify/alarm-queue.h b/calendar/gui/alarm-notify/alarm-queue.h deleted file mode 100644 index 12802750ec..0000000000 --- a/calendar/gui/alarm-notify/alarm-queue.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Evolution calendar - Alarm queueing engine - * - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <libecal/e-cal.h> - - -void alarm_queue_init (void); -void alarm_queue_done (void); - -void alarm_queue_add_client (ECal *client); -void alarm_queue_remove_client (ECal *client); - - -#endif diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c deleted file mode 100644 index 6c57311c12..0000000000 --- a/calendar/gui/alarm-notify/alarm.c +++ /dev/null @@ -1,301 +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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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" - - - -/* Our glib timeout */ -static guint timeout_id; - -/* The list of pending alarms */ -static GList *alarms = NULL; - -/* A queued alarm structure */ -typedef struct { - time_t trigger; - AlarmFunction alarm_fn; - gpointer data; - AlarmDestroyNotify destroy_notify_fn; -} AlarmRecord; - -static void setup_timeout (void); - - - -/* Removes the head alarm from the queue. Does not touch the timeout_id. */ -static void -pop_alarm (void) -{ - AlarmRecord *ar; - GList *l; - - g_assert (alarms != NULL); - - ar = alarms->data; - - l = alarms; - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - - g_free (ar); -} - -/* Callback from the alarm timeout */ -static gboolean -alarm_ready_cb (gpointer data) -{ - time_t now; - - g_assert (alarms != NULL); - timeout_id = 0; - - now = time (NULL); - - g_message ("Alarm callback!"); - while (alarms) { - AlarmRecord *notify_id, *ar; - AlarmRecord ar_copy; - - ar = alarms->data; - - if (ar->trigger > now) - break; - - g_message ("Process alarm with trigger %lu", ar->trigger); - notify_id = ar; - - ar_copy = *ar; - ar = &ar_copy; - - pop_alarm (); /* This will free the original AlarmRecord; that's why we copy it */ - - (* ar->alarm_fn) (notify_id, ar->trigger, ar->data); - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (notify_id, ar->data); - } - - /* We need this check because one of the alarm_fn above may have - * re-entered and added an alarm of its own, so the timer will - * already be set up. - */ - if (alarms) - setup_timeout (); - - return FALSE; -} - -/* Sets up a timeout for the next minute. We do not need to be concerned with - * timezones here, as this is just a periodic check on the alarm queue. - */ -static void -setup_timeout (void) -{ - const AlarmRecord *ar; - guint diff; - time_t now; - g_assert (alarms != NULL); - - ar = alarms->data; - - /* Remove the existing time out */ - if (timeout_id != 0) { - g_source_remove (timeout_id); - timeout_id = 0; - } - - /* Ensure that if the trigger managed to get behind the - * current time we timeout immediately */ - diff = MAX (0, ar->trigger - time (NULL)); - now = time (NULL); - - /* Add the time out */ - g_message ("Setting timeout for %d %lu %lu", diff, ar->trigger, now); - g_message (" %s", ctime (&ar->trigger)); - g_message (" %s", ctime (&now)); - timeout_id = g_timeout_add (diff * 1000, alarm_ready_cb, NULL); -} - -/* Used from g_list_insert_sorted(); compares the trigger times of two AlarmRecord structures. */ -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 void -queue_alarm (AlarmRecord *ar) -{ - GList *old_head; - - /* Track the current head of the list in case there are changes */ - old_head = alarms; - - /* Insert the new alarm in order */ - alarms = g_list_insert_sorted (alarms, ar, compare_alarm_by_time); - - /* If there first item on the list didn't change, the time out is fine */ - if (old_head == alarms) - return; - - /* Set the timer for removal upon activation */ - setup_timeout (); -} - - - -/** - * alarm_add: - * @trigger: Time at which alarm will trigger. - * @alarm_fn: Callback for trigger. - * @data: Closure data for callback. - * @destroy_notify_fn: destroy notification 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) -{ - AlarmRecord *ar; - - g_return_val_if_fail (trigger != -1, NULL); - g_return_val_if_fail (alarm_fn != NULL, NULL); - - ar = g_new (AlarmRecord, 1); - ar->trigger = trigger; - ar->alarm_fn = alarm_fn; - ar->data = data; - ar->destroy_notify_fn = destroy_notify_fn; - - queue_alarm (ar); - - return ar; -} - -/** - * alarm_remove: - * @alarm: A queued alarm identifier. - * - * Removes an alarm from the alarm queue. - **/ -void -alarm_remove (gpointer alarm) -{ - AlarmRecord *notify_id, *ar; - AlarmRecord ar_copy; - AlarmRecord *old_head; - GList *l; - - g_return_if_fail (alarm != NULL); - - ar = alarm; - - l = g_list_find (alarms, ar); - if (!l) { - g_message (G_STRLOC ": Requested removal of nonexistent alarm!"); - return; - } - - old_head = alarms->data; - - notify_id = ar; - - if (old_head == ar) { - ar_copy = *ar; - ar = &ar_copy; - pop_alarm (); /* This will free the original AlarmRecord; that's why we copy it */ - } else { - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - } - - /* Reset the timeout */ - - g_assert (timeout_id != 0); - - if (!alarms) { - g_source_remove (timeout_id); - timeout_id = 0; - } - - /* Notify about destructiono of the alarm */ - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (notify_id, ar->data); - -} - -/** - * alarm_done: - * - * Terminates the alarm timer mechanism. This should be called at the end of - * the program. - **/ -void -alarm_done (void) -{ - GList *l; - - if (timeout_id == 0) { - g_assert (alarms == NULL); - return; - } - - g_assert (alarms != NULL); - - g_source_remove (timeout_id); - timeout_id = 0; - - 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; -} diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h deleted file mode 100644 index 23fde886c9..0000000000 --- a/calendar/gui/alarm-notify/alarm.h +++ /dev/null @@ -1,42 +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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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_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/config-data.c b/calendar/gui/alarm-notify/config-data.c deleted file mode 100644 index cd3f7ed885..0000000000 --- a/calendar/gui/alarm-notify/config-data.c +++ /dev/null @@ -1,251 +0,0 @@ -/* Evolution calendar - Configuration values for the alarm notification daemon - * - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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_CONFIOH -#include <config.h> -#endif - -#include <string.h> -#include <libedataserver/e-source-list.h> -#include "config-data.h" - - - -#define KEY_LAST_NOTIFICATION_TIME "/apps/evolution/calendar/notify/last_notification_time" -#define KEY_PROGRAMS "/apps/evolution/calendar/notify/programs" - -/* Whether we have initied ourselves by reading the data from the configuration engine */ -static gboolean inited = FALSE; -static GConfClient *conf_client = NULL; -static ESourceList *calendar_source_list = NULL, *tasks_source_list = NULL; - - - -/* Copied from ../calendar-config.c; returns whether the locale has 'am' and - * 'pm' strings defined. - */ -static gboolean -locale_supports_12_hour_format (void) -{ - char s[16]; - time_t t = 0; - - strftime (s, sizeof s, "%p", gmtime (&t)); - return s[0] != '\0'; -} - -static void -do_cleanup (void) -{ - if (calendar_source_list) { - g_object_unref (calendar_source_list); - calendar_source_list = NULL; - } - - if (tasks_source_list) { - g_object_unref (tasks_source_list); - tasks_source_list = NULL; - } - - g_object_unref (conf_client); - conf_client = NULL; - - inited = FALSE; -} - -/* Ensures that the configuration values have been read */ -static void -ensure_inited (void) -{ - if (inited) - return; - - inited = TRUE; - - conf_client = gconf_client_get_default (); - if (!GCONF_IS_CLIENT (conf_client)) { - inited = FALSE; - return; - } - - g_atexit ((GVoidFunc) do_cleanup); - - /* load the sources for calendars and tasks */ - calendar_source_list = e_source_list_new_for_gconf (conf_client, - "/apps/evolution/calendar/sources"); - tasks_source_list = e_source_list_new_for_gconf (conf_client, - "/apps/evolution/tasks/sources"); - -} - -GConfClient * -config_data_get_conf_client (void) -{ - ensure_inited (); - return conf_client; -} - -icaltimezone * -config_data_get_timezone (void) -{ - char *location; - icaltimezone *local_timezone; - - ensure_inited (); - - location = gconf_client_get_string (conf_client, - "/apps/evolution/calendar/display/timezone", - NULL); - if (location && location[0]) { - local_timezone = icaltimezone_get_builtin_timezone (location); - } else { - local_timezone = icaltimezone_get_utc_timezone (); - } - - g_free (location); - - return local_timezone; -} - -gboolean -config_data_get_24_hour_format (void) -{ - ensure_inited (); - - if (locale_supports_12_hour_format ()) { - return gconf_client_get_bool (conf_client, - "/apps/evolution/calendar/display/use_24hour_format", - NULL); - } - - return TRUE; -} - -gboolean -config_data_get_notify_with_tray (void) -{ - ensure_inited (); - - return gconf_client_get_bool (conf_client, - "/apps/evolution/calendar/notify/notify_with_tray", - NULL); -} - -/** - * config_data_set_last_notification_time: - * @t: A time value. - * - * Saves the last notification time so that it can be fetched the next time the - * alarm daemon is run. This way the daemon can show alarms that should have - * triggered while it was not running. - **/ -void -config_data_set_last_notification_time (time_t t) -{ - GConfClient *conf_client; - time_t current_t; - - g_return_if_fail (t != -1); - - if (!(conf_client = config_data_get_conf_client ())) - return; - - /* we only store the new notification time if it is bigger - than the already stored one */ - current_t = gconf_client_get_int (conf_client, KEY_LAST_NOTIFICATION_TIME, NULL); - if (t > current_t) - gconf_client_set_int (conf_client, KEY_LAST_NOTIFICATION_TIME, t, NULL); -} - -/** - * config_data_get_last_notification_time: - * - * Queries the last saved value for alarm notification times. - * - * Return value: The last saved value, or -1 if no value had been saved before. - **/ -time_t -config_data_get_last_notification_time (void) -{ - GConfClient *conf_client; - GConfValue *value; - - if (!(conf_client = config_data_get_conf_client ())) - return -1; - - value = gconf_client_get_without_default (conf_client, KEY_LAST_NOTIFICATION_TIME, NULL); - if (value) - return (time_t) gconf_value_get_int (value); - - return time (NULL); -} - -/** - * config_data_save_blessed_program: - * @program: a program name - * - * Saves a program name as "blessed" - **/ -void -config_data_save_blessed_program (const char *program) -{ - GConfClient *conf_client; - GSList *l; - - if (!(conf_client = config_data_get_conf_client ())) - return; - - l = gconf_client_get_list (conf_client, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); - l = g_slist_append (l, g_strdup (program)); - gconf_client_set_list (conf_client, KEY_PROGRAMS, GCONF_VALUE_STRING, l, NULL); - g_slist_foreach (l, (GFunc) g_free, NULL); - g_slist_free (l); -} - -/** - * config_data_is_blessed_program: - * @program: a program name - * - * Checks to see if a program is blessed - * - * Return value: TRUE if program is blessed, FALSE otherwise - **/ -gboolean -config_data_is_blessed_program (const char *program) -{ - GConfClient *conf_client; - GSList *l, *n; - gboolean found = FALSE; - - if (!(conf_client = config_data_get_conf_client ())) - return FALSE; - - l = gconf_client_get_list (conf_client, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); - while (l) { - n = l->next; - if (!found) - found = strcmp ((char *) l->data, program) == 0; - g_free (l->data); - g_slist_free_1 (l); - l = n; - } - - return found; -} diff --git a/calendar/gui/alarm-notify/config-data.h b/calendar/gui/alarm-notify/config-data.h deleted file mode 100644 index e5b2c3d689..0000000000 --- a/calendar/gui/alarm-notify/config-data.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Evolution calendar - Configuration values for the alarm notification daemon - * - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CONFIG_DATA_H -#define CONFIG_DATA_H - -#include <glib.h> -#include <libical/ical.h> -#include <gconf/gconf-client.h> - -GConfClient *config_data_get_conf_client (void); - -icaltimezone *config_data_get_timezone (void); -gboolean config_data_get_24_hour_format (void); -gboolean config_data_get_notify_with_tray (void); -void config_data_set_last_notification_time (time_t t); -time_t config_data_get_last_notification_time (void); -void config_data_save_blessed_program (const char *program); -gboolean config_data_is_blessed_program (const char *program); - -#endif diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c deleted file mode 100644 index 91fc0c0bfe..0000000000 --- a/calendar/gui/alarm-notify/notify-main.c +++ /dev/null @@ -1,171 +0,0 @@ -/* Evolution calendar - Alarm notification service main file - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2003 Novell, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <string.h> -#include <glib.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-init.h> -#include <libgnome/gnome-sound.h> -#include <libgnomeui/gnome-client.h> -#include <libgnomeui/gnome-ui-init.h> -#include <libgnomevfs/gnome-vfs-init.h> -#include <glade/glade.h> -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo-activation/bonobo-activation.h> -#include <libedataserver/e-source.h> -#include "e-util/e-passwords.h" -#include "e-util/e-icon-factory.h" -#include "alarm.h" -#include "alarm-queue.h" -#include "alarm-notify.h" -#include "config-data.h" - - - -static BonoboGenericFactory *factory; - -static AlarmNotify *alarm_notify_service = NULL; - - -/* Callback for the master client's "die" signal. We must terminate the daemon - * since the session is ending. - */ -static void -client_die_cb (GnomeClient *client) -{ - bonobo_main_quit (); -} - -static gint -save_session_cb (GnomeClient *client, GnomeSaveStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, gpointer user_data) -{ - char *args[2]; - - args[0] = EVOLUTION_LIBEXECDIR "/evolution-alarm-notify"; - args[1] = NULL; - gnome_client_set_restart_command (client, 1, args); - - return TRUE; -} - -/* Sees if a session manager is present. If so, it tells the SM how to restart - * the daemon when the session starts. It also sets the die callback so that - * the daemon can terminate properly when the session ends. - */ -static void -init_session (void) -{ - GnomeClient *master_client; - - master_client = gnome_master_client (); - - g_signal_connect (G_OBJECT (master_client), "die", - G_CALLBACK (client_die_cb), NULL); - g_signal_connect (G_OBJECT (master_client), "save_yourself", - G_CALLBACK (save_session_cb), NULL); - - /* The daemon should always be started up by the session manager when - * the session starts. The daemon will take care of loading whatever - * calendars it was told to load. - */ - gnome_client_set_restart_style (master_client, GNOME_RESTART_IF_RUNNING); -} - -/* Factory function for the alarm notify service; just creates and references a - * singleton service object. - */ -static BonoboObject * -alarm_notify_factory_fn (BonoboGenericFactory *factory, const char *component_id, void *data) -{ - if (!alarm_notify_service) { - alarm_notify_service = alarm_notify_new (); - g_assert (alarm_notify_service != NULL); - } - - bonobo_object_ref (BONOBO_OBJECT (alarm_notify_service)); - - return BONOBO_OBJECT (alarm_notify_service); -} - -/* Creates the alarm notifier */ -static gboolean -init_alarm_service (gpointer user_data) -{ - if (!alarm_notify_service) { - alarm_notify_service = alarm_notify_new (); - g_assert (alarm_notify_service != NULL); - } - - return FALSE; -} - -int -main (int argc, char **argv) -{ - bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - gnome_program_init ("evolution-alarm-notify", VERSION, LIBGNOMEUI_MODULE, argc, argv, NULL); - - if (bonobo_init_full (&argc, argv, bonobo_activation_orb_get (), - CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) - g_error (_("Could not initialize Bonobo")); - - glade_init (); - - gnome_sound_init ("localhost"); - - e_icon_factory_init (); - - factory = bonobo_generic_factory_new ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory:" BASE_VERSION, - (BonoboFactoryCallback) alarm_notify_factory_fn, NULL); - if (!factory) - g_error (_("Could not create the alarm notify service factory")); - - init_session (); - - g_idle_add ((GSourceFunc) init_alarm_service, NULL); - - bonobo_main (); - - bonobo_object_unref (BONOBO_OBJECT (factory)); - factory = NULL; - - alarm_queue_done (); - alarm_done (); - - if (alarm_notify_service) - bonobo_object_unref (BONOBO_OBJECT (alarm_notify_service)); - - e_passwords_shutdown (); - gnome_sound_shutdown (); - - return 0; -} diff --git a/calendar/gui/alarm-notify/util.c b/calendar/gui/alarm-notify/util.c deleted file mode 100644 index 3749e5f300..0000000000 --- a/calendar/gui/alarm-notify/util.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Evolution calendar - utility functions - * - * Copyright (C) 2000 Ximian, Inc. - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <libgnome/gnome-i18n.h> -#include <e-util/e-time-utils.h> -#include <libecal/e-cal-time-util.h> -#include "config-data.h" -#include "util.h" - -/* Converts a time_t to a string, relative to the specified timezone */ -char * -timet_to_str_with_zone (time_t t, icaltimezone *zone) -{ - struct icaltimetype itt; - struct tm tm; - char buf[256]; - - if (t == -1) - return g_strdup (_("invalid time")); - - itt = icaltime_from_timet_with_zone (t, FALSE, zone); - tm = icaltimetype_to_tm (&itt); - - e_time_format_date_and_time (&tm, config_data_get_24_hour_format (), - FALSE, FALSE, buf, sizeof (buf)); - return g_strdup (buf); -} diff --git a/calendar/gui/alarm-notify/util.h b/calendar/gui/alarm-notify/util.h deleted file mode 100644 index 7dae3dd7fe..0000000000 --- a/calendar/gui/alarm-notify/util.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Evolution calendar - utility functions - * - * Copyright (C) 2000 Ximian, Inc. - * 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 version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 UTIL_H -#define UTIL_H - -#include <libecal/e-cal-component.h> - -char *timet_to_str_with_zone (time_t t, icaltimezone *zone); - -#endif |