diff options
Diffstat (limited to 'calendar/gui')
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify-dialog.c | 69 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify-dialog.h | 2 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-notify.glade | 30 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-queue.c | 125 |
4 files changed, 131 insertions, 95 deletions
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 <libgnome/gnome-defs.h> #include <libgnome/gnome-i18n.h> #include <glade/glade.h> +#include <gal/widgets/e-unicode.h> #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 @@ <language>C</language> <gnome_support>True</gnome_support> <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>True</output_main_file> - <output_support_files>True</output_support_files> - <output_build_files>True</output_build_files> - <backup_source_files>True</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> </project> <widget> <class>GtkWindow</class> <name>alarm-notify</name> - <cxx_use_heap>True</cxx_use_heap> <title></title> <type>GTK_WINDOW_DIALOG</type> <position>GTK_WIN_POS_CENTER</position> @@ -39,14 +27,12 @@ <class>GtkVBox</class> <name>vbox2</name> <border_width>4</border_width> - <cxx_use_heap>True</cxx_use_heap> <homogeneous>False</homogeneous> <spacing>4</spacing> <widget> <class>GtkHBox</class> <name>hbox3</name> - <cxx_use_heap>True</cxx_use_heap> <homogeneous>False</homogeneous> <spacing>8</spacing> <child> @@ -58,7 +44,6 @@ <widget> <class>GtkVBox</class> <name>vbox5</name> - <cxx_use_heap>True</cxx_use_heap> <homogeneous>False</homogeneous> <spacing>4</spacing> <child> @@ -70,7 +55,6 @@ <widget> <class>GtkLabel</class> <name>heading</name> - <cxx_use_heap>True</cxx_use_heap> <label></label> <justify>GTK_JUSTIFY_LEFT</justify> <wrap>True</wrap> @@ -87,8 +71,7 @@ <widget> <class>GtkLabel</class> - <name>summary</name> - <cxx_use_heap>True</cxx_use_heap> + <name>message</name> <label></label> <justify>GTK_JUSTIFY_LEFT</justify> <wrap>True</wrap> @@ -107,7 +90,6 @@ <widget> <class>GtkVBox</class> <name>vbox4</name> - <cxx_use_heap>True</cxx_use_heap> <homogeneous>False</homogeneous> <spacing>4</spacing> <child> @@ -119,9 +101,9 @@ <widget> <class>GtkButton</class> <name>close</name> - <cxx_use_heap>True</cxx_use_heap> <can_focus>True</can_focus> <label>Close</label> + <relief>GTK_RELIEF_NORMAL</relief> <child> <padding>0</padding> <expand>False</expand> @@ -132,9 +114,9 @@ <widget> <class>GtkButton</class> <name>snooze</name> - <cxx_use_heap>True</cxx_use_heap> <can_focus>True</can_focus> <label>Snooze</label> + <relief>GTK_RELIEF_NORMAL</relief> <child> <padding>0</padding> <expand>False</expand> @@ -145,9 +127,9 @@ <widget> <class>GtkButton</class> <name>edit</name> - <cxx_use_heap>True</cxx_use_heap> <can_focus>True</can_focus> <label>Edit appointment</label> + <relief>GTK_RELIEF_NORMAL</relief> <child> <padding>0</padding> <expand>False</expand> @@ -160,7 +142,6 @@ <widget> <class>GtkHSeparator</class> <name>hseparator1</name> - <cxx_use_heap>True</cxx_use_heap> <child> <padding>0</padding> <expand>True</expand> @@ -171,7 +152,6 @@ <widget> <class>GtkHBox</class> <name>hbox4</name> - <cxx_use_heap>True</cxx_use_heap> <homogeneous>False</homogeneous> <spacing>4</spacing> <child> @@ -183,7 +163,6 @@ <widget> <class>GtkLabel</class> <name>label4</name> - <cxx_use_heap>True</cxx_use_heap> <label>Snooze time (minutes)</label> <justify>GTK_JUSTIFY_CENTER</justify> <wrap>False</wrap> @@ -201,7 +180,6 @@ <widget> <class>GtkSpinButton</class> <name>snooze-time</name> - <cxx_use_heap>True</cxx_use_heap> <can_focus>True</can_focus> <climb_rate>1</climb_rate> <digits>0</digits> 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 <config.h> #endif +#include <glib.h> +#include <libgnome/gnome-defs.h> +#include <libgnome/gnome-i18n.h> #include <gtk/gtksignal.h> #include <cal-util/timeutil.h> #include "alarm.h" @@ -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: * |