From 795956eec8940a25967b9f6bb5e3fa2f76953864 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 16 May 2000 07:33:43 +0000 Subject: Alarm stuff I had not cvs added, sigh - Federico 2000-05-14 Federico Mena Quintero * gui/gnome-cal.c (display_notification): Use the alarm notification dialog. (display_notification_cb): New callback for the result of the alarm notification dialog. * gui/dialogs/alarm-notify.glade: New file with the alarm notification dialog. * gui/dialogs/alarm-notify-dialog.[ch]: New file. * gui/dialogs/Makefile.am: New file. * gui/Makefile.am (SUBDIRS): Added the dialogs directory. 2000-05-13 Federico Mena Quintero * gui/gnome-cal.c (trigger_alarm_cb): Better error checking, and plug leaks of str_ico and ico. * gui/evolution-calendar-control.c (main): Initialize libglade. svn path=/trunk/; revision=3072 --- calendar/ChangeLog | 23 +++ calendar/gui/Makefile.am | 3 + calendar/gui/alarm-notify/alarm-notify-dialog.c | 218 ++++++++++++++++++++++ calendar/gui/alarm-notify/alarm-notify-dialog.h | 44 +++++ calendar/gui/alarm-notify/alarm-notify.glade | 230 ++++++++++++++++++++++++ calendar/gui/dialogs/Makefile.am | 27 +++ calendar/gui/dialogs/alarm-notify-dialog.c | 218 ++++++++++++++++++++++ calendar/gui/dialogs/alarm-notify-dialog.h | 44 +++++ calendar/gui/dialogs/alarm-notify.glade | 230 ++++++++++++++++++++++++ calendar/gui/dialogs/alarm-notify.glade.h | 10 ++ calendar/gui/e-day-view.c | 5 +- calendar/gui/evolution-calendar-control.c | 2 + calendar/gui/gnome-cal.c | 105 ++++++++++- 13 files changed, 1155 insertions(+), 4 deletions(-) create mode 100644 calendar/gui/alarm-notify/alarm-notify-dialog.c create mode 100644 calendar/gui/alarm-notify/alarm-notify-dialog.h create mode 100644 calendar/gui/alarm-notify/alarm-notify.glade create mode 100644 calendar/gui/dialogs/Makefile.am create mode 100644 calendar/gui/dialogs/alarm-notify-dialog.c create mode 100644 calendar/gui/dialogs/alarm-notify-dialog.h create mode 100644 calendar/gui/dialogs/alarm-notify.glade create mode 100644 calendar/gui/dialogs/alarm-notify.glade.h (limited to 'calendar') diff --git a/calendar/ChangeLog b/calendar/ChangeLog index db38ac5e7e..4810a7bbc0 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,26 @@ +2000-05-14 Federico Mena Quintero + + * gui/gnome-cal.c (display_notification): Use the alarm + notification dialog. + (display_notification_cb): New callback for the result of the + alarm notification dialog. + + * gui/dialogs/alarm-notify.glade: New file with the alarm + notification dialog. + + * gui/dialogs/alarm-notify-dialog.[ch]: New file. + + * gui/dialogs/Makefile.am: New file. + + * gui/Makefile.am (SUBDIRS): Added the dialogs directory. + +2000-05-13 Federico Mena Quintero + + * gui/gnome-cal.c (trigger_alarm_cb): Better error checking, and + plug leaks of str_ico and ico. + + * gui/evolution-calendar-control.c (main): Initialize libglade. + 2000-05-13 Ettore Perazzoli * pcs/Makefile.am (INCLUDES): Add diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 3d13df9148..41d3ed03fe 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = dialogs + help_base = $(datadir)/gnome/help/cal #if HAVE_GNOME_PILOT @@ -25,6 +27,7 @@ INCLUDES = \ LINK_FLAGS = \ $(BONOBO_VFS_GNOME_LIBS) \ $(INTLLIBS) \ + dialogs/libcal-dialogs.a \ $(top_builddir)/calendar/cal-client/libcal-client.la \ $(top_builddir)/calendar/cal-util/libcal-util.la \ $(top_builddir)/e-util/libeutil.la \ diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.c b/calendar/gui/alarm-notify/alarm-notify-dialog.c new file mode 100644 index 0000000000..931ab0bfac --- /dev/null +++ b/calendar/gui/alarm-notify/alarm-notify-dialog.c @@ -0,0 +1,218 @@ +/* Evolution calendar - alarm notification dialog + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Author: Federico Mena-Quintero + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include +#include "alarm-notify-dialog.h" + + + +/* The useful contents of the alarm notify dialog */ +typedef struct { + GladeXML *xml; + + GtkWidget *dialog; + GtkWidget *close; + GtkWidget *snooze; + GtkWidget *edit; + GtkWidget *heading; + GtkWidget *summary; + GtkWidget *snooze_time; + + AlarmNotifyFunc func; + gpointer func_data; +} AlarmNotify; + + + +/* Callback used when the notify dialog is destroyed */ +static void +dialog_destroy_cb (GtkObject *object, gpointer data) +{ + AlarmNotify *an; + + an = data; + gtk_object_unref (GTK_OBJECT (an->xml)); + g_free (an); +} + +/* Delete_event handler for the alarm notify dialog */ +static gint +delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) +{ + AlarmNotify *an; + + an = data; + g_assert (an->func != NULL); + + (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); + + gtk_widget_destroy (widget); + return TRUE; +} + +/* Callback for the close button */ +static void +close_clicked_cb (GtkWidget *widget, gpointer data) +{ + AlarmNotify *an; + + an = data; + g_assert (an->func != NULL); + + (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); + + gtk_widget_destroy (an->dialog); +} + +/* Callback for the snooze button */ +static void +snooze_clicked_cb (GtkWidget *widget, gpointer data) +{ + AlarmNotify *an; + int snooze_time; + + an = data; + g_assert (an->func != NULL); + + snooze_time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (an->snooze_time)); + (* an->func) (ALARM_NOTIFY_SNOOZE, snooze_time, an->func_data); + + gtk_widget_destroy (an->dialog); +} + +/* Callback for the edit button */ +static void +edit_clicked_cb (GtkWidget *widget, gpointer data) +{ + AlarmNotify *an; + + an = data; + g_assert (an->func != NULL); + + (* an->func) (ALARM_NOTIFY_EDIT, -1, an->func_data); + + gtk_widget_destroy (an->dialog); +} + +/** + * alarm_notify_dialog: + * @func: Function to be called when a dialog action is invoked. + * @data: Closure data for @func. + * + * Runs the alarm notification dialog. The specified @func will be used to + * notify the client about result of the actions in the dialog. + * + * Return value: TRUE on success, FALSE if the dialog could not be created. + **/ +gboolean +alarm_notify_dialog (time_t trigger, time_t occur, iCalObject *ico, + AlarmNotifyFunc func, gpointer func_data) +{ + AlarmNotify *an; + char buf[256]; + struct tm tm_trigger; + struct tm tm_occur; + + g_return_val_if_fail (trigger != -1, FALSE); + g_return_val_if_fail (occur != -1, FALSE); + g_return_val_if_fail (ico != NULL, FALSE); + g_return_val_if_fail (func != NULL, FALSE); + + an = g_new0 (AlarmNotify, 1); + + an->func = func; + an->func_data = func_data; + + an->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-notify.glade", NULL); + if (!an->xml) { + g_message ("alarm_notify_dialog(): Could not load the Glade XML file!"); + g_free (an); + return FALSE; + } + + an->dialog = glade_xml_get_widget (an->xml, "alarm-notify"); + an->close = glade_xml_get_widget (an->xml, "close"); + an->snooze = glade_xml_get_widget (an->xml, "snooze"); + an->edit = glade_xml_get_widget (an->xml, "edit"); + an->heading = glade_xml_get_widget (an->xml, "heading"); + an->summary = glade_xml_get_widget (an->xml, "summary"); + an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); + + if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->summary + && an->snooze_time)) { + g_message ("alarm_notify_dialog(): Could not find all widgets in Glade file!"); + gtk_object_unref (GTK_OBJECT (an->xml)); + g_free (an); + return FALSE; + } + + gtk_object_set_data (GTK_OBJECT (an->dialog), "alarm-notify", an); + gtk_signal_connect (GTK_OBJECT (an->dialog), "destroy", + GTK_SIGNAL_FUNC (dialog_destroy_cb), an); + + /* Title */ + + /* FIXME: use am_pm_flag or 24-hour time */ + + tm_trigger = *localtime (&trigger); + strftime (buf, sizeof (buf), _("Alarm on %A %b %d %Y %H:%M"), &tm_trigger); + gtk_window_set_title (GTK_WINDOW (an->dialog), buf); + + /* Heading */ + + tm_occur = *localtime (&occur); + strftime (buf, sizeof (buf), + _("Notification about your appointment on %A %b %d %Y %H:%M"), + &tm_occur); + gtk_label_set_text (GTK_LABEL (an->heading), buf); + + /* Summary */ + + gtk_label_set_text (GTK_LABEL (an->summary), ico->summary); + + /* Connect actions */ + + gtk_signal_connect (GTK_OBJECT (an->dialog), "delete_event", + GTK_SIGNAL_FUNC (delete_event_cb), + an); + + gtk_signal_connect (GTK_OBJECT (an->close), "clicked", + GTK_SIGNAL_FUNC (close_clicked_cb), + an); + + gtk_signal_connect (GTK_OBJECT (an->snooze), "clicked", + GTK_SIGNAL_FUNC (snooze_clicked_cb), + an); + + gtk_signal_connect (GTK_OBJECT (an->edit), "clicked", + GTK_SIGNAL_FUNC (edit_clicked_cb), + an); + + /* Run! */ + + gtk_widget_show (an->dialog); + return TRUE; +} diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.h b/calendar/gui/alarm-notify/alarm-notify-dialog.h new file mode 100644 index 0000000000..770768f59c --- /dev/null +++ b/calendar/gui/alarm-notify/alarm-notify-dialog.h @@ -0,0 +1,44 @@ +/* Evolution calendar - alarm notification dialog + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Author: Federico Mena-Quintero + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef ALARM_NOTIFY_DIALOG_H +#define ALARM_NOTIFY_DIALOG_H + +#include +#include +#include + + + +typedef enum { + ALARM_NOTIFY_CLOSE, + ALARM_NOTIFY_SNOOZE, + ALARM_NOTIFY_EDIT +} AlarmNotifyResult; + +typedef void (* AlarmNotifyFunc) (AlarmNotifyResult result, int snooze_mins, gpointer data); + +gboolean alarm_notify_dialog (time_t trigger, time_t occur, iCalObject *ico, + AlarmNotifyFunc func, gpointer func_data); + + + +#endif diff --git a/calendar/gui/alarm-notify/alarm-notify.glade b/calendar/gui/alarm-notify/alarm-notify.glade new file mode 100644 index 0000000000..32d7e03f8b --- /dev/null +++ b/calendar/gui/alarm-notify/alarm-notify.glade @@ -0,0 +1,230 @@ + + + + + Evolution Calendar + evolution-calendar + + src + pixmaps + C + True + True + False + True + True + True + True + interface.c + interface.h + callbacks.c + callbacks.h + support.c + support.h + True + alarm-notify.glade.h + + + + GtkWindow + alarm-notify + True + + GTK_WINDOW_DIALOG + GTK_WIN_POS_CENTER + False + False + False + False + + + GtkVBox + vbox2 + 4 + True + False + 4 + + + GtkHBox + hbox3 + True + False + 8 + + 0 + True + True + + + + GtkVBox + vbox5 + True + False + 4 + + 0 + True + True + + + + GtkLabel + heading + True + + GTK_JUSTIFY_LEFT + True + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + summary + True + + GTK_JUSTIFY_LEFT + True + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + GtkVBox + vbox4 + True + False + 4 + + 0 + True + True + + + + GtkButton + close + True + True + + + 0 + False + False + + + + + GtkButton + snooze + True + True + + + 0 + False + False + + + + + GtkButton + edit + True + True + + + 0 + False + False + + + + + + + GtkHSeparator + hseparator1 + True + + 0 + True + True + + + + + GtkHBox + hbox4 + True + False + 4 + + 0 + True + True + + + + GtkLabel + label4 + True + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkSpinButton + snooze-time + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 5 + 1 + 1440 + 1 + 5 + 5 + + 0 + False + False + + + + + + + diff --git a/calendar/gui/dialogs/Makefile.am b/calendar/gui/dialogs/Makefile.am new file mode 100644 index 0000000000..8dfccc5650 --- /dev/null +++ b/calendar/gui/dialogs/Makefile.am @@ -0,0 +1,27 @@ +INCLUDES = \ + -DG_LOG_DOMAIN=\"calendar-gui\" \ + -I$(top_srcdir) \ + -I$(top_srcdir)/calendar \ + -I$(top_srcdir)/libical/src/libical \ + -I$(includedir) \ + -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ + $(BONOBO_VFS_GNOME_CFLAGS) \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" + +noinst_LIBRARIES = libcal-dialogs.a + +libcal_dialogs_a_SOURCES = \ + alarm-notify-dialog.c \ + alarm-notify-dialog.h + +gladedir = $(datadir)/evolution/glade + +glade_DATA = \ + alarm-notify.glade + +glade_messages = \ + alarm-notify.glade.h + +EXTRA_DIST = \ + $(glade_DATA) \ + $(glade_messages) diff --git a/calendar/gui/dialogs/alarm-notify-dialog.c b/calendar/gui/dialogs/alarm-notify-dialog.c new file mode 100644 index 0000000000..931ab0bfac --- /dev/null +++ b/calendar/gui/dialogs/alarm-notify-dialog.c @@ -0,0 +1,218 @@ +/* Evolution calendar - alarm notification dialog + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Author: Federico Mena-Quintero + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include +#include "alarm-notify-dialog.h" + + + +/* The useful contents of the alarm notify dialog */ +typedef struct { + GladeXML *xml; + + GtkWidget *dialog; + GtkWidget *close; + GtkWidget *snooze; + GtkWidget *edit; + GtkWidget *heading; + GtkWidget *summary; + GtkWidget *snooze_time; + + AlarmNotifyFunc func; + gpointer func_data; +} AlarmNotify; + + + +/* Callback used when the notify dialog is destroyed */ +static void +dialog_destroy_cb (GtkObject *object, gpointer data) +{ + AlarmNotify *an; + + an = data; + gtk_object_unref (GTK_OBJECT (an->xml)); + g_free (an); +} + +/* Delete_event handler for the alarm notify dialog */ +static gint +delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) +{ + AlarmNotify *an; + + an = data; + g_assert (an->func != NULL); + + (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); + + gtk_widget_destroy (widget); + return TRUE; +} + +/* Callback for the close button */ +static void +close_clicked_cb (GtkWidget *widget, gpointer data) +{ + AlarmNotify *an; + + an = data; + g_assert (an->func != NULL); + + (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); + + gtk_widget_destroy (an->dialog); +} + +/* Callback for the snooze button */ +static void +snooze_clicked_cb (GtkWidget *widget, gpointer data) +{ + AlarmNotify *an; + int snooze_time; + + an = data; + g_assert (an->func != NULL); + + snooze_time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (an->snooze_time)); + (* an->func) (ALARM_NOTIFY_SNOOZE, snooze_time, an->func_data); + + gtk_widget_destroy (an->dialog); +} + +/* Callback for the edit button */ +static void +edit_clicked_cb (GtkWidget *widget, gpointer data) +{ + AlarmNotify *an; + + an = data; + g_assert (an->func != NULL); + + (* an->func) (ALARM_NOTIFY_EDIT, -1, an->func_data); + + gtk_widget_destroy (an->dialog); +} + +/** + * alarm_notify_dialog: + * @func: Function to be called when a dialog action is invoked. + * @data: Closure data for @func. + * + * Runs the alarm notification dialog. The specified @func will be used to + * notify the client about result of the actions in the dialog. + * + * Return value: TRUE on success, FALSE if the dialog could not be created. + **/ +gboolean +alarm_notify_dialog (time_t trigger, time_t occur, iCalObject *ico, + AlarmNotifyFunc func, gpointer func_data) +{ + AlarmNotify *an; + char buf[256]; + struct tm tm_trigger; + struct tm tm_occur; + + g_return_val_if_fail (trigger != -1, FALSE); + g_return_val_if_fail (occur != -1, FALSE); + g_return_val_if_fail (ico != NULL, FALSE); + g_return_val_if_fail (func != NULL, FALSE); + + an = g_new0 (AlarmNotify, 1); + + an->func = func; + an->func_data = func_data; + + an->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-notify.glade", NULL); + if (!an->xml) { + g_message ("alarm_notify_dialog(): Could not load the Glade XML file!"); + g_free (an); + return FALSE; + } + + an->dialog = glade_xml_get_widget (an->xml, "alarm-notify"); + an->close = glade_xml_get_widget (an->xml, "close"); + an->snooze = glade_xml_get_widget (an->xml, "snooze"); + an->edit = glade_xml_get_widget (an->xml, "edit"); + an->heading = glade_xml_get_widget (an->xml, "heading"); + an->summary = glade_xml_get_widget (an->xml, "summary"); + an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); + + if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->summary + && an->snooze_time)) { + g_message ("alarm_notify_dialog(): Could not find all widgets in Glade file!"); + gtk_object_unref (GTK_OBJECT (an->xml)); + g_free (an); + return FALSE; + } + + gtk_object_set_data (GTK_OBJECT (an->dialog), "alarm-notify", an); + gtk_signal_connect (GTK_OBJECT (an->dialog), "destroy", + GTK_SIGNAL_FUNC (dialog_destroy_cb), an); + + /* Title */ + + /* FIXME: use am_pm_flag or 24-hour time */ + + tm_trigger = *localtime (&trigger); + strftime (buf, sizeof (buf), _("Alarm on %A %b %d %Y %H:%M"), &tm_trigger); + gtk_window_set_title (GTK_WINDOW (an->dialog), buf); + + /* Heading */ + + tm_occur = *localtime (&occur); + strftime (buf, sizeof (buf), + _("Notification about your appointment on %A %b %d %Y %H:%M"), + &tm_occur); + gtk_label_set_text (GTK_LABEL (an->heading), buf); + + /* Summary */ + + gtk_label_set_text (GTK_LABEL (an->summary), ico->summary); + + /* Connect actions */ + + gtk_signal_connect (GTK_OBJECT (an->dialog), "delete_event", + GTK_SIGNAL_FUNC (delete_event_cb), + an); + + gtk_signal_connect (GTK_OBJECT (an->close), "clicked", + GTK_SIGNAL_FUNC (close_clicked_cb), + an); + + gtk_signal_connect (GTK_OBJECT (an->snooze), "clicked", + GTK_SIGNAL_FUNC (snooze_clicked_cb), + an); + + gtk_signal_connect (GTK_OBJECT (an->edit), "clicked", + GTK_SIGNAL_FUNC (edit_clicked_cb), + an); + + /* Run! */ + + gtk_widget_show (an->dialog); + return TRUE; +} diff --git a/calendar/gui/dialogs/alarm-notify-dialog.h b/calendar/gui/dialogs/alarm-notify-dialog.h new file mode 100644 index 0000000000..770768f59c --- /dev/null +++ b/calendar/gui/dialogs/alarm-notify-dialog.h @@ -0,0 +1,44 @@ +/* Evolution calendar - alarm notification dialog + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Author: Federico Mena-Quintero + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef ALARM_NOTIFY_DIALOG_H +#define ALARM_NOTIFY_DIALOG_H + +#include +#include +#include + + + +typedef enum { + ALARM_NOTIFY_CLOSE, + ALARM_NOTIFY_SNOOZE, + ALARM_NOTIFY_EDIT +} AlarmNotifyResult; + +typedef void (* AlarmNotifyFunc) (AlarmNotifyResult result, int snooze_mins, gpointer data); + +gboolean alarm_notify_dialog (time_t trigger, time_t occur, iCalObject *ico, + AlarmNotifyFunc func, gpointer func_data); + + + +#endif diff --git a/calendar/gui/dialogs/alarm-notify.glade b/calendar/gui/dialogs/alarm-notify.glade new file mode 100644 index 0000000000..32d7e03f8b --- /dev/null +++ b/calendar/gui/dialogs/alarm-notify.glade @@ -0,0 +1,230 @@ + + + + + Evolution Calendar + evolution-calendar + + src + pixmaps + C + True + True + False + True + True + True + True + interface.c + interface.h + callbacks.c + callbacks.h + support.c + support.h + True + alarm-notify.glade.h + + + + GtkWindow + alarm-notify + True + + GTK_WINDOW_DIALOG + GTK_WIN_POS_CENTER + False + False + False + False + + + GtkVBox + vbox2 + 4 + True + False + 4 + + + GtkHBox + hbox3 + True + False + 8 + + 0 + True + True + + + + GtkVBox + vbox5 + True + False + 4 + + 0 + True + True + + + + GtkLabel + heading + True + + GTK_JUSTIFY_LEFT + True + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + summary + True + + GTK_JUSTIFY_LEFT + True + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + GtkVBox + vbox4 + True + False + 4 + + 0 + True + True + + + + GtkButton + close + True + True + + + 0 + False + False + + + + + GtkButton + snooze + True + True + + + 0 + False + False + + + + + GtkButton + edit + True + True + + + 0 + False + False + + + + + + + GtkHSeparator + hseparator1 + True + + 0 + True + True + + + + + GtkHBox + hbox4 + True + False + 4 + + 0 + True + True + + + + GtkLabel + label4 + True + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkSpinButton + snooze-time + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 5 + 1 + 1440 + 1 + 5 + 5 + + 0 + False + False + + + + + + + diff --git a/calendar/gui/dialogs/alarm-notify.glade.h b/calendar/gui/dialogs/alarm-notify.glade.h new file mode 100644 index 0000000000..c7b8918e06 --- /dev/null +++ b/calendar/gui/dialogs/alarm-notify.glade.h @@ -0,0 +1,10 @@ +/* + * Translatable strings file generated by Glade. + * Add this file to your project's POTFILES.in. + * DO NOT compile it as part of your application. + */ + +gchar *s = N_("Close"); +gchar *s = N_("Snooze"); +gchar *s = N_("Edit appointment"); +gchar *s = N_("Snooze time (minutes)"); diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index e21a492c71..84cd31464a 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -2336,8 +2336,9 @@ e_day_view_on_edit_appointment (GtkWidget *widget, gpointer data) if (event == NULL) return; - /* We must duplicate the iCalObject, since the event editor will - change the fields. */ + /* We must duplicate the iCalObject, since the event editor will change + * the fields. + */ ico = ical_object_duplicate (event->ico); event_editor = event_editor_new (day_view->calendar, ico); diff --git a/calendar/gui/evolution-calendar-control.c b/calendar/gui/evolution-calendar-control.c index 904e146c7c..9f8760fd3f 100644 --- a/calendar/gui/evolution-calendar-control.c +++ b/calendar/gui/evolution-calendar-control.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -182,6 +183,7 @@ int main (int argc, char **argv) { init_bonobo (&argc, argv); + glade_gnome_init (); alarm_init (); init_calendar (); diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index e3b79e51b3..38a0c33118 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -20,6 +20,7 @@ #include #include #include +#include "dialogs/alarm-notify-dialog.h" #include "alarm.h" #include "e-day-view.h" #include "e-week-view.h" @@ -54,6 +55,8 @@ static void gnome_calendar_on_month_changed (GtkCalendar *calendar, static GtkVBoxClass *parent_class; +static void setup_alarm (GnomeCalendar *cal, CalAlarmInstance *ai); + guint @@ -519,12 +522,102 @@ program_notification (char *command, int close_standard) sigaction (SIGQUIT, &save_quit, NULL); } +/* Queues a snooze alarm */ +static void +snooze (GnomeCalendar *gcal, iCalObject *ico, time_t occur, int snooze_mins, gboolean audio) +{ + time_t now, trigger; + struct tm tm; + CalAlarmInstance ai; + + now = time (NULL); + tm = *localtime (&now); + tm.tm_min += snooze_mins; + + trigger = mktime (&tm); + if (trigger == -1) { + g_message ("snooze(): produced invalid time_t; not queueing alarm!"); + return; + } + + ai.uid = ico->uid; + ai.type = audio ? ALARM_AUDIO : ALARM_DISPLAY; + ai.trigger = trigger; + ai.occur = occur; + + setup_alarm (gcal, &ai); +} + +/* Edits an appointment from the alarm notification dialog */ +static void +edit (GnomeCalendar *gcal, iCalObject *ico) +{ + iCalObject *new_ico; + GtkWidget *event_editor; + + /* We must duplicate the iCalObject, since the event editor will change + * the fields. + */ + new_ico = ical_object_duplicate (ico); + + event_editor = event_editor_new (gcal, new_ico); + gtk_widget_show (event_editor); +} + +struct alarm_notify_closure { + GnomeCalendar *gcal; + iCalObject *ico; + time_t occur; +}; + +/* Callback used for the result of the alarm notification dialog */ +static void +display_notification_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) +{ + struct alarm_notify_closure *c; + + c = data; + + switch (result) { + case ALARM_NOTIFY_CLOSE: + break; + + case ALARM_NOTIFY_SNOOZE: + snooze (c->gcal, c->ico, c->occur, snooze_mins, FALSE); + break; + + case ALARM_NOTIFY_EDIT: + edit (c->gcal, c->ico); + break; + + default: + g_assert_not_reached (); + } + + ical_object_unref (c->ico); + g_free (c); +} + /* Present a display notification of an alarm trigger */ static void display_notification (time_t trigger, time_t occur, iCalObject *ico, GnomeCalendar *gcal) { - g_message ("DISPLAY NOTIFICATION!"); - /* FIXME */ + gboolean result; + struct alarm_notify_closure *c; + + ical_object_ref (ico); + + c = g_new (struct alarm_notify_closure, 1); + c->gcal = gcal; + c->ico = ico; + c->occur = occur; + + result = alarm_notify_dialog (trigger, occur, ico, display_notification_cb, c); + if (!result) { + g_message ("display_notification(): could not display the alarm notification dialog"); + g_free (c); + ical_object_unref (ico); + } } /* Present an audible notification of an alarm trigger */ @@ -558,7 +651,13 @@ trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data) /* Fetch the object */ str_ico = cal_client_get_object (c->gcal->client, c->uid); + if (!str_ico) { + g_message ("trigger_alarm_cb(): could not fetch object `%s'", c->uid); + return; + } + status = ical_object_find_in_string (c->uid, str_ico, &ico); + g_free (str_ico); switch (status) { case CAL_OBJ_FIND_SUCCESS: @@ -616,6 +715,8 @@ trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data) g_free (oa->uid); g_free (oa); } + + ical_object_unref (ico); } /* Frees a struct trigger_alarm_closure */ -- cgit v1.2.3