From 7eff67693f6c26444743b9edb3f7e085a06645ae Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Thu, 4 Aug 2022 11:49:59 +0200 Subject: [PATCH] I#1982 - Calendar: The default reminder not always added Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1982 --- src/calendar/gui/comp-util.c | 97 +++++++++++-------- src/calendar/gui/comp-util.h | 3 + .../e-composer-to-meeting.c | 12 +++ src/plugins/mail-to-task/mail-to-task.c | 31 +++--- 4 files changed, 83 insertions(+), 60 deletions(-) diff --git a/src/calendar/gui/comp-util.c b/src/calendar/gui/comp-util.c index a67dd55efd..b6d75ca793 100644 --- a/src/calendar/gui/comp-util.c +++ b/src/calendar/gui/comp-util.c @@ -359,6 +359,59 @@ cal_comp_util_ref_default_object (ECalClient *client, return comp; } +void +cal_comp_util_add_reminder (ECalComponent *comp, + gint reminder_interval, + EDurationType reminder_units) +{ + ECalComponentAlarm *alarm; + ICalProperty *prop; + ICalDuration *duration; + ECalComponentAlarmTrigger *trigger; + + g_return_if_fail (E_IS_CAL_COMPONENT (comp)); + + alarm = e_cal_component_alarm_new (); + + /* We don't set the description of the alarm; we'll copy it from the + * summary when it gets committed to the server. For that, we add a + * X-EVOLUTION-NEEDS-DESCRIPTION property to the alarm's component. + */ + prop = i_cal_property_new_x ("1"); + i_cal_property_set_x_name (prop, "X-EVOLUTION-NEEDS-DESCRIPTION"); + e_cal_component_property_bag_take (e_cal_component_alarm_get_property_bag (alarm), prop); + + e_cal_component_alarm_set_action (alarm, E_CAL_COMPONENT_ALARM_DISPLAY); + + duration = i_cal_duration_new_null_duration (); + i_cal_duration_set_is_neg (duration, TRUE); + + switch (reminder_units) { + case E_DURATION_MINUTES: + i_cal_duration_set_minutes (duration, reminder_interval); + break; + + case E_DURATION_HOURS: + i_cal_duration_set_hours (duration, reminder_interval); + break; + + case E_DURATION_DAYS: + i_cal_duration_set_days (duration, reminder_interval); + break; + + default: + g_warning ("wrong units %d\n", reminder_units); + } + + trigger = e_cal_component_alarm_trigger_new_relative (E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, duration); + g_clear_object (&duration); + + e_cal_component_alarm_take_trigger (alarm, trigger); + + e_cal_component_add_alarm (comp, alarm); + e_cal_component_alarm_free (alarm); +} + /** * cal_comp_event_new_with_defaults_sync: * @@ -377,10 +430,6 @@ cal_comp_event_new_with_defaults_sync (ECalClient *client, GError **error) { ECalComponent *comp; - ECalComponentAlarm *alarm; - ICalProperty *prop; - ICalDuration *duration; - ECalComponentAlarmTrigger *trigger; comp = cal_comp_util_ref_default_object (client, I_CAL_VEVENT_COMPONENT, E_CAL_COMPONENT_EVENT, cancellable, error); @@ -390,45 +439,7 @@ cal_comp_event_new_with_defaults_sync (ECalClient *client, if (all_day || !use_default_reminder) return comp; - alarm = e_cal_component_alarm_new (); - - /* We don't set the description of the alarm; we'll copy it from the - * summary when it gets committed to the server. For that, we add a - * X-EVOLUTION-NEEDS-DESCRIPTION property to the alarm's component. - */ - prop = i_cal_property_new_x ("1"); - i_cal_property_set_x_name (prop, "X-EVOLUTION-NEEDS-DESCRIPTION"); - e_cal_component_property_bag_take (e_cal_component_alarm_get_property_bag (alarm), prop); - - e_cal_component_alarm_set_action (alarm, E_CAL_COMPONENT_ALARM_DISPLAY); - - duration = i_cal_duration_new_null_duration (); - i_cal_duration_set_is_neg (duration, TRUE); - - switch (default_reminder_units) { - case E_DURATION_MINUTES: - i_cal_duration_set_minutes (duration, default_reminder_interval); - break; - - case E_DURATION_HOURS: - i_cal_duration_set_hours (duration, default_reminder_interval); - break; - - case E_DURATION_DAYS: - i_cal_duration_set_days (duration, default_reminder_interval); - break; - - default: - g_warning ("wrong units %d\n", default_reminder_units); - } - - trigger = e_cal_component_alarm_trigger_new_relative (E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, duration); - g_clear_object (&duration); - - e_cal_component_alarm_take_trigger (alarm, trigger); - - e_cal_component_add_alarm (comp, alarm); - e_cal_component_alarm_free (alarm); + cal_comp_util_add_reminder (comp, default_reminder_interval, default_reminder_units); return comp; } diff --git a/src/calendar/gui/comp-util.h b/src/calendar/gui/comp-util.h index 3ec120a0a9..4a39ec3487 100644 --- a/src/calendar/gui/comp-util.h +++ b/src/calendar/gui/comp-util.h @@ -226,4 +226,7 @@ gboolean cal_comp_util_move_component_by_days ECalComponent *in_comp, gint days, gboolean is_move); +void cal_comp_util_add_reminder (ECalComponent *comp, + gint reminder_interval, + EDurationType reminder_units); #endif diff --git a/src/modules/composer-to-meeting/e-composer-to-meeting.c b/src/modules/composer-to-meeting/e-composer-to-meeting.c index 04a328ce61..ac566a493d 100644 --- a/src/modules/composer-to-meeting/e-composer-to-meeting.c +++ b/src/modules/composer-to-meeting/e-composer-to-meeting.c @@ -24,6 +24,7 @@ #include "e-util/e-util.h" #include "composer/e-msg-composer.h" #include "composer/e-composer-from-header.h" +#include "calendar/gui/comp-util.h" #include "calendar/gui/e-comp-editor.h" #include "calendar/gui/e-comp-editor-page-attachments.h" @@ -71,6 +72,7 @@ composer_to_meeting_component (EMsgComposer *composer, EComposerHeaderTable *header_table; EDestination **destinations_array[3]; ESource *source; + GSettings *settings; gchar *alias_name = NULL, *alias_address = NULL, *uid, *text; GSList *attendees = NULL; const gchar *subject; @@ -224,6 +226,16 @@ composer_to_meeting_component (EMsgComposer *composer, g_slist_free_full (descr_list, e_cal_component_text_free); } + settings = e_util_ref_settings ("org.gnome.evolution.calendar"); + + if (g_settings_get_boolean (settings, "use-default-reminder")) { + cal_comp_util_add_reminder (comp, + g_settings_get_int (settings, "default-reminder-interval"), + g_settings_get_enum (settings, "default-reminder-units")); + } + + g_clear_object (&settings); + return comp; } diff --git a/src/plugins/mail-to-task/mail-to-task.c b/src/plugins/mail-to-task/mail-to-task.c index 48f15e77ed..2c807e8890 100644 --- a/src/plugins/mail-to-task/mail-to-task.c +++ b/src/plugins/mail-to-task/mail-to-task.c @@ -38,6 +38,7 @@ #include #include +#include "calendar/gui/comp-util.h" #include #include @@ -485,7 +486,6 @@ set_attachments (ECalClient *client, if (cb_data.uris == NULL) { e_flag_free (cb_data.flag); - g_warning ("No attachment URIs retrieved."); return; } @@ -894,6 +894,7 @@ do_mail_to_event (AsyncData *data) break; } } else { + GSettings *settings; gint i; ECalComponentDateTime *dt, *dt2; ICalTime *tt, *tt2; @@ -913,6 +914,8 @@ do_mail_to_event (AsyncData *data) #undef cache_backend_prop + settings = e_util_ref_settings ("org.gnome.evolution.calendar"); + /* set start day of the event as today, without time - easier than looking for a calendar's time zone */ tt = i_cal_time_new_today (); tt2 = i_cal_time_clone (tt); @@ -937,20 +940,15 @@ do_mail_to_event (AsyncData *data) continue; } - comp = e_cal_component_new (); + comp = cal_comp_event_new_with_defaults_sync (E_CAL_CLIENT (client), FALSE, + data->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS && + g_settings_get_boolean (settings, "use-default-reminder"), + g_settings_get_int (settings, "default-reminder-interval"), + g_settings_get_enum (settings, "default-reminder-units"), + NULL, &error); - switch (data->source_type) { - case E_CAL_CLIENT_SOURCE_TYPE_EVENTS: - e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); - break; - case E_CAL_CLIENT_SOURCE_TYPE_TASKS: - e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO); - break; - case E_CAL_CLIENT_SOURCE_TYPE_MEMOS: - e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL); - break; - default: - g_warn_if_reached (); + if (!comp) { + report_error_idle (_("Cannot create component: %s"), error ? error->message : _("Unknown error")); break; } @@ -1058,11 +1056,10 @@ do_mail_to_event (AsyncData *data) e_cal_component_datetime_free (dt); e_cal_component_datetime_free (dt2); + g_clear_object (&settings); } - /* free memory */ - if (client != NULL) - g_object_unref (client); + g_clear_object (&client); g_ptr_array_unref (uids); g_object_unref (folder);