From 3c8ba7a13ff813aa4be767ca3db8813ce99566fc Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Fri, 25 Jun 2004 13:37:39 +0000 Subject: free old_summary (is_custom_alarm): take description into account when 004-06-25 JP Rosevear * gui/dialogs/event-page.c (event_page_finalize): free old_summary (is_custom_alarm): take description into account when checking for custom alarm (is_custom_alarm_uid_list): pass old_summary (is_custom_alarm_store): ditto (is_custom_alarm_store): ditto (sensitize_widgets): ditto (event_page_fill_component): ditto (event_page_fill_widgets): store the initial summary (alarm_changed_cb): make sure the needs description property gets set on the default alarm (alarm_custom_clicked_cb): copy the current store in case the user hits cancel, if all the alarms are erased uncheck the alarm toggle * gui/dialogs/alarm-dialog.glade: add toggles for custom messages and sound * gui/dialogs/alarm-dialog.c (aalarm_widgets_to_alarm): store custom sound only if the toggle is checked (dalarm_widgets_to_alarm): store custom message only if toggle is checked (get_widgets): load new widgets (aalarm_sound_toggled_cb): sensitize sound entry (dalarm_message_toggled_cb): sensitize message entry (init_widgets): listen for toggle signals svn path=/trunk/; revision=26511 --- calendar/ChangeLog | 28 +++++ calendar/gui/dialogs/alarm-dialog.c | 42 ++++++- calendar/gui/dialogs/alarm-dialog.glade | 194 +++++++++++++++++++++----------- calendar/gui/dialogs/event-page.c | 87 +++++++++++--- 4 files changed, 268 insertions(+), 83 deletions(-) (limited to 'calendar') diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 5267b41bdf..f64dea5182 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,31 @@ +2004-06-25 JP Rosevear + + * gui/dialogs/event-page.c (event_page_finalize): free old_summary + (is_custom_alarm): take description into account when checking for + custom alarm + (is_custom_alarm_uid_list): pass old_summary + (is_custom_alarm_store): ditto + (is_custom_alarm_store): ditto + (sensitize_widgets): ditto + (event_page_fill_component): ditto + (event_page_fill_widgets): store the initial summary + (alarm_changed_cb): make sure the needs description property gets + set on the default alarm + (alarm_custom_clicked_cb): copy the current store in case the user + hits cancel, if all the alarms are erased uncheck the alarm toggle + + * gui/dialogs/alarm-dialog.glade: add toggles for custom messages + and sound + + * gui/dialogs/alarm-dialog.c (aalarm_widgets_to_alarm): store + custom sound only if the toggle is checked + (dalarm_widgets_to_alarm): store custom message only if toggle is + checked + (get_widgets): load new widgets + (aalarm_sound_toggled_cb): sensitize sound entry + (dalarm_message_toggled_cb): sensitize message entry + (init_widgets): listen for toggle signals + 2004-06-24 JP Rosevear * gui/dialogs/alarm-list-dialog.c (selection_changed_cb): diff --git a/calendar/gui/dialogs/alarm-dialog.c b/calendar/gui/dialogs/alarm-dialog.c index e3d4b12be2..779ecf6b7b 100644 --- a/calendar/gui/dialogs/alarm-dialog.c +++ b/calendar/gui/dialogs/alarm-dialog.c @@ -89,10 +89,12 @@ typedef struct { /* Display alarm widgets */ GtkWidget *dalarm_group; + GtkWidget *dalarm_message; GtkWidget *dalarm_description; /* Audio alarm widgets */ GtkWidget *aalarm_group; + GtkWidget *aalarm_sound; GtkWidget *aalarm_attach; /* Mail alarm widgets */ @@ -186,6 +188,8 @@ clear_widgets (Dialog *dialog) e_dialog_option_menu_set (dialog->time, E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, time_map); gtk_widget_set_sensitive (dialog->repeat_group, FALSE); + gtk_widget_set_sensitive (dialog->dalarm_group, FALSE); + gtk_widget_set_sensitive (dialog->aalarm_group, FALSE); gtk_notebook_set_current_page (GTK_NOTEBOOK (dialog->option_notebook), 0); } @@ -210,7 +214,6 @@ alarm_to_dialog (Dialog *dialog) else gtk_widget_set_sensitive (l->data, TRUE); } - /* If we can repeat */ repeat = !e_cal_get_static_capability (dialog->ecal, CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT); gtk_widget_set_sensitive (dialog->repeat_toggle, repeat); @@ -259,6 +262,9 @@ aalarm_widgets_to_alarm (Dialog *dialog, ECalComponentAlarm *alarm) char *url; icalattach *attach; + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->aalarm_sound))) + return; + url = e_dialog_editable_get (dialog->aalarm_attach); attach = icalattach_new_from_url (url ? url : ""); g_free (url); @@ -278,6 +284,9 @@ dalarm_widgets_to_alarm (Dialog *dialog, ECalComponentAlarm *alarm) icalcomponent *icalcomp; icalproperty *icalprop; + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->dalarm_message))) + return; + text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description)); gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start); gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end); @@ -532,9 +541,11 @@ get_widgets (Dialog *dialog) dialog->option_notebook = GW ("option-notebook"); dialog->dalarm_group = GW ("dalarm-group"); + dialog->dalarm_message = GW ("dalarm-message"); dialog->dalarm_description = GW ("dalarm-description"); dialog->aalarm_group = GW ("aalarm-group"); + dialog->aalarm_sound = GW ("aalarm-sound"); dialog->aalarm_attach = GW ("aalarm-attach"); dialog->malarm_group = GW ("malarm-group"); @@ -560,8 +571,10 @@ get_widgets (Dialog *dialog) && dialog->repeat_unit && dialog->option_notebook && dialog->dalarm_group + && dialog->dalarm_message && dialog->dalarm_description && dialog->aalarm_group + && dialog->aalarm_sound && dialog->aalarm_attach && dialog->malarm_group && dialog->malarm_address_group @@ -674,6 +687,28 @@ repeat_toggle_toggled_cb (GtkToggleButton *toggle, gpointer data) gtk_widget_set_sensitive (dialog->repeat_group, active); } +static void +aalarm_sound_toggled_cb (GtkToggleButton *toggle, gpointer data) +{ + Dialog *dialog = data; + gboolean active; + + active = gtk_toggle_button_get_active (toggle); + + gtk_widget_set_sensitive (dialog->aalarm_group, active); +} + +static void +dalarm_message_toggled_cb (GtkToggleButton *toggle, gpointer data) +{ + Dialog *dialog = data; + gboolean active; + + active = gtk_toggle_button_get_active (toggle); + + gtk_widget_set_sensitive (dialog->dalarm_group, active); +} + /* Hooks the widget signals */ static void init_widgets (Dialog *dialog) @@ -687,6 +722,11 @@ init_widgets (Dialog *dialog) g_signal_connect (G_OBJECT (dialog->repeat_toggle), "toggled", G_CALLBACK (repeat_toggle_toggled_cb), dialog); + + g_signal_connect (G_OBJECT (dialog->aalarm_sound), "toggled", + G_CALLBACK (aalarm_sound_toggled_cb), dialog); + g_signal_connect (G_OBJECT (dialog->dalarm_message), "toggled", + G_CALLBACK (dalarm_message_toggled_cb), dialog); } gboolean diff --git a/calendar/gui/dialogs/alarm-dialog.glade b/calendar/gui/dialogs/alarm-dialog.glade index b5f869e82a..3c1c47ae38 100644 --- a/calendar/gui/dialogs/alarm-dialog.glade +++ b/calendar/gui/dialogs/alarm-dialog.glade @@ -368,7 +368,7 @@ True True True - Repeat the alarm + _Repeat the alarm True GTK_RELIEF_NORMAL False @@ -572,34 +572,34 @@ True False - 0 + 6 - + True - False - 6 + True + Custom _message + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + False + + - - - True - Message to Display: - False - False - GTK_JUSTIFY_CENTER - False - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - + + + True + 1 + 2 + False + 6 + 6 @@ -628,15 +628,41 @@ - 0 - True - True + 1 + 2 + 0 + 1 + fill + + + + + + True + Mes_sage: + True + False + GTK_JUSTIFY_CENTER + False + False + 0 + 0 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + fill 0 - False + True True @@ -670,7 +696,25 @@ True False - 0 + 6 + + + + True + True + Custom alarm sound + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + False + + @@ -681,8 +725,8 @@ True - Play sound: - False + _Sound: + True False GTK_JUSTIFY_CENTER False @@ -691,6 +735,7 @@ 0.5 0 0 + aalarm-attach 0 @@ -766,29 +811,61 @@ 0 - + True + 2 + 2 False - 6 + 6 + 6 True - Run program: - False + _Program: + True False GTK_JUSTIFY_CENTER False False - 0.5 + 0 0.5 0 0 + palarm-program - 0 - False - False + 0 + 1 + 0 + 1 + fill + + + + + + + True + _Arguments: + True + False + GTK_JUSTIFY_CENTER + False + False + 0 + 0.5 + 0 + 0 + palarm-args + + + 0 + 1 + 1 + 2 + fill + @@ -805,30 +882,11 @@ False - 0 - True - True - - - - - - True - With these arguments: - False - False - GTK_JUSTIFY_CENTER - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False + 1 + 2 + 0 + 1 + @@ -845,9 +903,11 @@ False - 0 - True - True + 1 + 2 + 1 + 2 + diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c index e723d62fd2..6a69daea0f 100644 --- a/calendar/gui/dialogs/event-page.c +++ b/calendar/gui/dialogs/event-page.c @@ -89,6 +89,8 @@ struct _EventPagePrivate { gboolean updating; + char *old_summary; + /* This is TRUE if both the start & end timezone are the same. If the start timezone is then changed, we updated the end timezone to the same value, since 99% of events start and end in one timezone. */ @@ -208,6 +210,8 @@ event_page_finalize (GObject *object) priv->alarm_list_store = NULL; } + g_free (priv->old_summary); + g_free (priv); epage->priv = NULL; @@ -433,12 +437,16 @@ clear_widgets (EventPage *epage) } static gboolean -is_custom_alarm (ECalComponentAlarm *ca, int *alarm_type) +is_custom_alarm (ECalComponentAlarm *ca, char *old_summary, int *alarm_type) { ECalComponentAlarmTrigger trigger; ECalComponentAlarmRepeat repeat; ECalComponentAlarmAction action; + ECalComponentText desc; + icalcomponent *icalcomp; + icalproperty *icalprop; icalattach *attach; + gboolean needs_desc = FALSE; e_cal_component_alarm_get_action (ca, &action); if (action != E_CAL_COMPONENT_ALARM_DISPLAY) @@ -448,11 +456,23 @@ is_custom_alarm (ECalComponentAlarm *ca, int *alarm_type) if (attach) return TRUE; -#if 0 - e_cal_component_alarm_get_description (ca, &desc); - if (attach) - return TRUE; -#endif + icalcomp = e_cal_component_alarm_get_icalcomponent (ca); + icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY); + while (icalprop) { + const char *x_name; + + x_name = icalproperty_get_x_name (icalprop); + if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) + needs_desc = TRUE; + + icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY); + } + + if (!needs_desc) { + e_cal_component_alarm_get_description (ca, &desc); + if (!desc.value || !old_summary || strcmp (desc.value, old_summary)) + return TRUE; + } e_cal_component_alarm_get_repeat (ca, &repeat); if (repeat.repetitions != 0) @@ -504,7 +524,7 @@ is_custom_alarm (ECalComponentAlarm *ca, int *alarm_type) } static gboolean -is_custom_alarm_uid_list (ECalComponent *comp, GList *alarms, int *alarm_type) +is_custom_alarm_uid_list (ECalComponent *comp, GList *alarms, char *old_summary, int *alarm_type) { ECalComponentAlarm *ca; gboolean result; @@ -513,14 +533,14 @@ is_custom_alarm_uid_list (ECalComponent *comp, GList *alarms, int *alarm_type) return TRUE; ca = e_cal_component_get_alarm (comp, alarms->data); - result = is_custom_alarm (ca, alarm_type); + result = is_custom_alarm (ca, old_summary, alarm_type); e_cal_component_alarm_free (ca); return result; } static gboolean -is_custom_alarm_store (EAlarmList *alarm_list_store, int *alarm_type) +is_custom_alarm_store (EAlarmList *alarm_list_store, char *old_summary, int *alarm_type) { const ECalComponentAlarm *alarm; GtkTreeModel *model; @@ -534,7 +554,7 @@ is_custom_alarm_store (EAlarmList *alarm_list_store, int *alarm_type) return FALSE; alarm = e_alarm_list_get_alarm (alarm_list_store, &iter); - if (is_custom_alarm (( ECalComponentAlarm *)alarm, alarm_type)) + if (is_custom_alarm ((ECalComponentAlarm *)alarm, old_summary, alarm_type)) return TRUE; valid_iter = gtk_tree_model_iter_next (model, &iter); @@ -555,7 +575,7 @@ sensitize_widgets (EventPage *epage) if (!e_cal_is_read_only (COMP_EDITOR_PAGE (epage)->client, &read_only, NULL)) read_only = TRUE; - custom = is_custom_alarm_store (priv->alarm_list_store, NULL); + custom = is_custom_alarm_store (priv->alarm_list_store, priv->old_summary, NULL); alarm = e_dialog_toggle_get (priv->alarm); gtk_widget_set_sensitive (priv->summary_label, !read_only); @@ -612,7 +632,8 @@ event_page_fill_widgets (CompEditorPage *page, ECalComponent *comp) e_cal_component_get_summary (comp, &text); e_dialog_editable_set (priv->summary, text.value); - + priv->old_summary = g_strdup (text.value); + e_cal_component_get_location (comp, &location); e_dialog_editable_set (priv->location, location); @@ -681,7 +702,7 @@ event_page_fill_widgets (CompEditorPage *page, ECalComponent *comp) e_dialog_toggle_set (priv->alarm, TRUE); alarms = e_cal_component_get_alarm_uids (comp); - if (!is_custom_alarm_uid_list (comp, alarms, &alarm_type)) + if (!is_custom_alarm_uid_list (comp, alarms, priv->old_summary, &alarm_type)) e_dialog_option_menu_set (priv->alarm_time, alarm_type, alarm_map); for (l = alarms; l != NULL; l = l->next) { @@ -872,7 +893,7 @@ event_page_fill_component (CompEditorPage *page, ECalComponent *comp) /* Alarm */ e_cal_component_remove_all_alarms (comp); if (e_dialog_toggle_get (priv->alarm)) { - if (is_custom_alarm_store (priv->alarm_list_store, NULL)) { + if (is_custom_alarm_store (priv->alarm_list_store, priv->old_summary, NULL)) { GtkTreeModel *model; GtkTreeIter iter; gboolean valid_iter; @@ -1552,6 +1573,8 @@ alarm_changed_cb (GtkWidget *widget, gpointer data) if (e_dialog_toggle_get (priv->alarm)) { ECalComponentAlarm *ca; ECalComponentAlarmTrigger trigger; + icalcomponent *icalcomp; + icalproperty *icalprop; int alarm_type; ca = e_cal_component_alarm_new (); @@ -1581,6 +1604,11 @@ alarm_changed_cb (GtkWidget *widget, gpointer data) } e_cal_component_alarm_set_trigger (ca, trigger); + icalcomp = e_cal_component_alarm_get_icalcomponent (ca); + icalprop = icalproperty_new_x ("1"); + icalproperty_set_x_name (icalprop, "X-EVOLUTION-NEEDS-DESCRIPTION"); + icalcomponent_add_property (icalcomp, icalprop); + e_alarm_list_append (priv->alarm_list_store, NULL, ca); } else { e_alarm_list_clear (priv->alarm_list_store); @@ -1594,14 +1622,43 @@ alarm_custom_clicked_cb (GtkWidget *widget, gpointer data) { EventPage *epage; EventPagePrivate *priv; + EAlarmList *temp_list_store; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean valid_iter; GtkWidget *toplevel; epage = EVENT_PAGE (data); priv = epage->priv; + /* Make a copy of the list store in case the user cancels */ + temp_list_store = e_alarm_list_new (); + model = GTK_TREE_MODEL (priv->alarm_list_store); + + for (valid_iter = gtk_tree_model_get_iter_first (model, &iter); valid_iter; + valid_iter = gtk_tree_model_iter_next (model, &iter)) { + ECalComponentAlarm *alarm; + + alarm = (ECalComponentAlarm *) e_alarm_list_get_alarm (priv->alarm_list_store, &iter); + g_assert (alarm != NULL); + + e_alarm_list_append (temp_list_store, NULL, alarm); + } + toplevel = gtk_widget_get_toplevel (priv->main); - if (alarm_list_dialog_run (toplevel, COMP_EDITOR_PAGE (epage)->client, priv->alarm_list_store)) + if (alarm_list_dialog_run (toplevel, COMP_EDITOR_PAGE (epage)->client, temp_list_store)) { + g_object_unref (priv->alarm_list_store); + priv->alarm_list_store = temp_list_store; + comp_editor_page_notify_changed (COMP_EDITOR_PAGE (epage)); + } else { + g_object_unref (temp_list_store); + } + + /* If the user erases everything, uncheck the alarm toggle */ + valid_iter = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->alarm_list_store), &iter); + if (!valid_iter) + e_dialog_toggle_set (priv->alarm, FALSE); sensitize_widgets (epage); } -- cgit