From 39e7268930b5d5cbc6f9128ebf1a8055ed007cc6 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 10 Jul 2001 23:57:55 +0000 Subject: Handle the different alarm actions. (display_notification): Do the alarm 2001-07-10 Federico Mena Quintero * gui/alarm-notify/alarm-queue.c (alarm_trigger_cb): Handle the different alarm actions. (display_notification): Do the alarm notification dialog here. * gui/alarm-notify/alarm-notify-dialog.c (make_heading): Take in a CalComponentVType, not a whole component. (alarm_notify_dialog): Take in a CalComponentVType and the final message instead of generating it ourselves. svn path=/trunk/; revision=10978 --- calendar/ChangeLog | 11 +++ calendar/gui/alarm-notify/alarm-notify-dialog.c | 69 +++++-------- calendar/gui/alarm-notify/alarm-notify-dialog.h | 2 +- calendar/gui/alarm-notify/alarm-notify.glade | 30 +----- calendar/gui/alarm-notify/alarm-queue.c | 125 +++++++++++++++++++----- 5 files changed, 142 insertions(+), 95 deletions(-) (limited to 'calendar') diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 685dad73bd..b0a55ad641 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,14 @@ +2001-07-10 Federico Mena Quintero + + * gui/alarm-notify/alarm-queue.c (alarm_trigger_cb): Handle the + different alarm actions. + (display_notification): Do the alarm notification dialog here. + + * gui/alarm-notify/alarm-notify-dialog.c (make_heading): Take in a + CalComponentVType, not a whole component. + (alarm_notify_dialog): Take in a CalComponentVType and the final + message instead of generating it ourselves. + 2001-07-09 Federico Mena Quintero * pcs/cal-backend-file.c (generate_alarms_for_comp): Pass the diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.c b/calendar/gui/alarm-notify/alarm-notify-dialog.c index 219bf7b102..2a11026f23 100644 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.c +++ b/calendar/gui/alarm-notify/alarm-notify-dialog.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "alarm-notify-dialog.h" @@ -41,7 +42,7 @@ typedef struct { GtkWidget *snooze; GtkWidget *edit; GtkWidget *heading; - GtkWidget *summary; + GtkWidget *message; GtkWidget *snooze_time; AlarmNotifyFunc func; @@ -122,14 +123,11 @@ edit_clicked_cb (GtkWidget *widget, gpointer data) /* Creates a heading for the alarm notification dialog */ static char * -make_heading (CalComponent *comp, time_t occur_start, time_t occur_end) +make_heading (CalComponentVType vtype, time_t occur_start, time_t occur_end) { - CalComponentVType vtype; char *buf; char s[128], e[128]; - vtype = cal_component_get_vtype (comp); - if (occur_start != -1) { struct tm tm; @@ -187,29 +185,11 @@ make_heading (CalComponent *comp, time_t occur_start, time_t occur_end) } break; - case CAL_COMPONENT_JOURNAL: - if (occur_start != -1) { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your journal entry " - "starting on %s and ending on %s"), - s, e); - else - buf = g_strdup_printf (_("Notification about your journal entry " - "starting on %s"), - s); - } else { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your journal entry " - "ending on %s"), - e); - else - buf = g_strdup_printf (_("Notification about your journal entry")); - } - break; - default: - g_assert_not_reached(); - return NULL; + /* Only VEVENTs and VTODOs can have alarms */ + g_assert_not_reached (); + buf = NULL; + break; } return buf; @@ -220,7 +200,8 @@ make_heading (CalComponent *comp, time_t occur_start, time_t occur_end) * @trigger: Trigger time for the alarm. * @occur_start: Start of occurrence time for the event. * @occur_end: End of occurrence time for the event. - * @comp: Calendar component object which corresponds to the alarm. + * @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. * @@ -231,18 +212,20 @@ make_heading (CalComponent *comp, time_t occur_start, time_t occur_end) **/ gboolean alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, - CalComponent *comp, + CalComponentVType vtype, const char *message, AlarmNotifyFunc func, gpointer func_data) { AlarmNotify *an; char buf[256]; char *heading; + char *msg; struct tm tm_trigger; - CalComponentText summary; g_return_val_if_fail (trigger != -1, FALSE); - g_return_val_if_fail (comp != NULL, FALSE); - g_return_val_if_fail (IS_CAL_COMPONENT (comp), FALSE); + + /* Only VEVENTs or VTODOs can have alarms */ + g_return_val_if_fail (vtype == CAL_COMPONENT_EVENT || vtype == CAL_COMPONENT_TODO, FALSE); + g_return_val_if_fail (message != NULL, FALSE); g_return_val_if_fail (func != NULL, FALSE); an = g_new0 (AlarmNotify, 1); @@ -262,10 +245,10 @@ alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, 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->message = glade_xml_get_widget (an->xml, "message"); an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); - if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->summary + if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->message && an->snooze_time)) { g_message ("alarm_notify_dialog(): Could not find all widgets in Glade file!"); gtk_object_unref (GTK_OBJECT (an->xml)); @@ -279,26 +262,24 @@ alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, /* 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 */ - heading = make_heading (comp, occur_start, occur_end); + heading = make_heading (vtype, occur_start, occur_end); gtk_label_set_text (GTK_LABEL (an->heading), heading); g_free (heading); - /* Summary */ - - cal_component_get_summary (comp, &summary); + /* Message */ - if (summary.value) - gtk_label_set_text (GTK_LABEL (an->summary), summary.value); - else - gtk_label_set_text (GTK_LABEL (an->summary), _("No summary available.")); + msg = e_utf8_to_gtk_string (an->message, message); + if (msg) { + gtk_label_set_text (GTK_LABEL (an->message), msg); + g_free (msg); + } else + g_message ("Could not convert the alarm message from UTF8"); /* Connect actions */ diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.h b/calendar/gui/alarm-notify/alarm-notify-dialog.h index 6399261819..2eebbf1796 100644 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.h +++ b/calendar/gui/alarm-notify/alarm-notify-dialog.h @@ -37,7 +37,7 @@ typedef enum { typedef void (* AlarmNotifyFunc) (AlarmNotifyResult result, int snooze_mins, gpointer data); gboolean alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, - CalComponent *comp, + CalComponentVType vtype, const char *message, AlarmNotifyFunc func, gpointer func_data); diff --git a/calendar/gui/alarm-notify/alarm-notify.glade b/calendar/gui/alarm-notify/alarm-notify.glade index 41718d0572..91d499fa65 100644 --- a/calendar/gui/alarm-notify/alarm-notify.glade +++ b/calendar/gui/alarm-notify/alarm-notify.glade @@ -10,23 +10,11 @@ C True True - False - True - True - True - True - interface.c - interface.h - callbacks.c - callbacks.h - support.c - support.h GtkWindow alarm-notify - True GTK_WINDOW_DIALOG GTK_WIN_POS_CENTER @@ -39,14 +27,12 @@ GtkVBox vbox2 4 - True False 4 GtkHBox hbox3 - True False 8 @@ -58,7 +44,6 @@ GtkVBox vbox5 - True False 4 @@ -70,7 +55,6 @@ GtkLabel heading - True GTK_JUSTIFY_LEFT True @@ -87,8 +71,7 @@ GtkLabel - summary - True + message GTK_JUSTIFY_LEFT True @@ -107,7 +90,6 @@ GtkVBox vbox4 - True False 4 @@ -119,9 +101,9 @@ GtkButton close - True True + GTK_RELIEF_NORMAL 0 False @@ -132,9 +114,9 @@ GtkButton snooze - True True + GTK_RELIEF_NORMAL 0 False @@ -145,9 +127,9 @@ GtkButton edit - True True + GTK_RELIEF_NORMAL 0 False @@ -160,7 +142,6 @@ GtkHSeparator hseparator1 - True 0 True @@ -171,7 +152,6 @@ GtkHBox hbox4 - True False 4 @@ -183,7 +163,6 @@ GtkLabel label4 - True GTK_JUSTIFY_CENTER False @@ -201,7 +180,6 @@ GtkSpinButton snooze-time - True True 1 0 diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index c0e66ff484..7f829e1bf5 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -24,6 +24,9 @@ #include #endif +#include +#include +#include #include #include #include "alarm.h" @@ -74,15 +77,20 @@ typedef struct { /* Alarm ID from alarm.h */ gpointer alarm_id; - /* Instance from our parent CompAlarms->alarms list */ + /* Instance from our parent CompQueuedAlarms->alarms->alarms list */ CalAlarmInstance *instance; } QueuedAlarm; /* Alarm ID for the midnight refresh function */ static gpointer midnight_refresh_id = NULL; +static void display_notification (time_t trigger, CalAlarmInstance *instance, + CalComponent *comp, CalComponentAlarm *alarm); + +/* Alarm queue engine */ + static void load_alarms (ClientAlarms *ca); static void midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data); @@ -136,25 +144,6 @@ lookup_client (CalClient *client) return g_hash_table_lookup (client_alarms_hash, client); } -/* Callback used from the alarm notify dialog */ -static void -notify_dialog_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) -{ - switch (result) { - case ALARM_NOTIFY_SNOOZE: - /* FIXME */ - break; - - case ALARM_NOTIFY_EDIT: - /* FIXME */ - break; - - case ALARM_NOTIFY_CLOSE: - default: - break; - } -} - /* Callback used when an alarm triggers */ static void alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) @@ -163,6 +152,8 @@ alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) CalComponent *comp; GSList *l; QueuedAlarm *qa; + CalComponentAlarm *alarm; + CalAlarmAction action; cqa = data; comp = cqa->alarms->comp; @@ -179,10 +170,40 @@ alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) g_assert (qa != NULL); - if (!alarm_notify_dialog (trigger, - qa->instance->occur_start, qa->instance->occur_end, - comp, notify_dialog_cb, comp)) - g_message ("alarm_trigger_cb(): Could not create the alarm notify dialog"); + /* Decide what to do based on the alarm action. We use the trigger that + * is passed to us instead of the one from the instance structure + * because this may be a snoozed alarm instead of an original + * occurrence. + */ + + alarm = cal_component_get_alarm (comp, qa->instance->auid); + g_assert (alarm != NULL); + + cal_component_alarm_get_action (alarm, &action); + + switch (action) { + case CAL_ALARM_AUDIO: + /* FIXME: audio_notification (); */ + break; + + case CAL_ALARM_DISPLAY: + display_notification (trigger, qa->instance, comp, alarm); + break; + + case CAL_ALARM_EMAIL: + /* FIXME: mail_notification (); */ + break; + + case CAL_ALARM_PROCEDURE: + /* FIXME: procedure_notification (); */ + break; + + default: + g_assert_not_reached (); + break; + } + + cal_component_alarm_free (alarm); } /* Callback used when an alarm must be destroyed */ @@ -419,6 +440,62 @@ obj_removed_cb (CalClient *client, const char *uid, gpointer data) +/* Notification functions */ + +/* Callback used from the alarm notify dialog */ +static void +notify_dialog_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) +{ + switch (result) { + case ALARM_NOTIFY_SNOOZE: + /* FIXME */ + break; + + case ALARM_NOTIFY_EDIT: + /* FIXME */ + break; + + case ALARM_NOTIFY_CLOSE: + default: + break; + } +} + +/* Performs notification of a display alarm */ +static void +display_notification (time_t trigger, CalAlarmInstance *instance, + CalComponent *comp, CalComponentAlarm *alarm) +{ + CalComponentVType vtype; + CalComponentText text; + const char *message; + + vtype = cal_component_get_vtype (comp); + + /* Pick a sensible notification message. First we try the DESCRIPTION + * from the alarm, then the SUMMARY of the component. + */ + + cal_component_alarm_get_description (alarm, &text); + if (text.value) + message = text.value; + else { + cal_component_get_summary (comp, &text); + if (text.value) + message = text.value; + else + message = _("No description available."); + } + + if (!alarm_notify_dialog (trigger, + instance->occur_start, instance->occur_end, + vtype, message, + notify_dialog_cb, comp)) + g_message ("display_notification(): Could not create the alarm notify dialog"); +} + + + /** * alarm_queue_init: * -- cgit v1.2.3