I#1982 - Calendar: The default reminder not always added

Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1982
This commit is contained in:
Milan Crha
2022-08-04 11:49:59 +02:00
parent c928c5c0b5
commit 7eff67693f
4 changed files with 83 additions and 60 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -38,6 +38,7 @@
#include <mail/em-utils.h>
#include <mail/message-list.h>
#include "calendar/gui/comp-util.h"
#include <calendar/gui/e-comp-editor.h>
#include <calendar/gui/itip-utils.h>
@ -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);