[evolution/gnome-42] I#1982 - Calendar: The default reminder not always added



commit 1e0d26b61621491d78d299bd13fbcdeaf0b10660
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 4 11:49:59 2022 +0200

    I#1982 - Calendar: The default reminder not always added
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1982

 src/calendar/gui/comp-util.c                       | 69 +++++++++++++---------
 src/calendar/gui/comp-util.h                       |  4 +-
 .../composer-to-meeting/e-composer-to-meeting.c    | 12 ++++
 3 files changed, 55 insertions(+), 30 deletions(-)
---
diff --git a/src/calendar/gui/comp-util.c b/src/calendar/gui/comp-util.c
index f307008c85..f1459a5c7d 100644
--- a/src/calendar/gui/comp-util.c
+++ b/src/calendar/gui/comp-util.c
@@ -327,36 +327,17 @@ cal_comp_util_ref_default_object (ECalClient *client,
        return comp;
 }
 
-/**
- * cal_comp_event_new_with_defaults_sync:
- *
- * Creates a new VEVENT component and adds any default alarms to it as set in
- * the program's configuration values, but only if not the all_day event.
- *
- * Return value: A newly-created calendar component.
- **/
-ECalComponent *
-cal_comp_event_new_with_defaults_sync (ECalClient *client,
-                                      gboolean all_day,
-                                      gboolean use_default_reminder,
-                                      gint default_reminder_interval,
-                                      EDurationType default_reminder_units,
-                                      GCancellable *cancellable,
-                                      GError **error)
+void
+cal_comp_util_add_reminder (ECalComponent *comp,
+                           gint reminder_interval,
+                           EDurationType reminder_units)
 {
-       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);
-
-       if (!comp)
-               return NULL;
-
-       if (all_day || !use_default_reminder)
-               return comp;
+       g_return_if_fail (E_IS_CAL_COMPONENT (comp));
 
        alarm = e_cal_component_alarm_new ();
 
@@ -373,21 +354,21 @@ cal_comp_event_new_with_defaults_sync (ECalClient *client,
        duration = i_cal_duration_new_null_duration ();
        i_cal_duration_set_is_neg (duration, TRUE);
 
-       switch (default_reminder_units) {
+       switch (reminder_units) {
        case E_DURATION_MINUTES:
-               i_cal_duration_set_minutes (duration, default_reminder_interval);
+               i_cal_duration_set_minutes (duration, reminder_interval);
                break;
 
        case E_DURATION_HOURS:
-               i_cal_duration_set_hours (duration, default_reminder_interval);
+               i_cal_duration_set_hours (duration, reminder_interval);
                break;
 
        case E_DURATION_DAYS:
-               i_cal_duration_set_days (duration, default_reminder_interval);
+               i_cal_duration_set_days (duration, reminder_interval);
                break;
 
        default:
-               g_warning ("wrong units %d\n", default_reminder_units);
+               g_warning ("wrong units %d\n", reminder_units);
        }
 
        trigger = e_cal_component_alarm_trigger_new_relative (E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, 
duration);
@@ -397,6 +378,36 @@ cal_comp_event_new_with_defaults_sync (ECalClient *client,
 
        e_cal_component_add_alarm (comp, alarm);
        e_cal_component_alarm_free (alarm);
+}
+
+/**
+ * cal_comp_event_new_with_defaults_sync:
+ *
+ * Creates a new VEVENT component and adds any default alarms to it as set in
+ * the program's configuration values, but only if not the all_day event.
+ *
+ * Return value: A newly-created calendar component.
+ **/
+ECalComponent *
+cal_comp_event_new_with_defaults_sync (ECalClient *client,
+                                      gboolean all_day,
+                                      gboolean use_default_reminder,
+                                      gint default_reminder_interval,
+                                      EDurationType default_reminder_units,
+                                      GCancellable *cancellable,
+                                      GError **error)
+{
+       ECalComponent *comp;
+
+       comp = cal_comp_util_ref_default_object (client, I_CAL_VEVENT_COMPONENT, E_CAL_COMPONENT_EVENT, 
cancellable, error);
+
+       if (!comp)
+               return NULL;
+
+       if (all_day || !use_default_reminder)
+               return comp;
+
+       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 97902e4d51..6c2c41a181 100644
--- a/src/calendar/gui/comp-util.h
+++ b/src/calendar/gui/comp-util.h
@@ -175,5 +175,7 @@ void                cal_comp_util_maybe_ensure_allday_timezone_properties
 void           cal_comp_util_format_itt        (ICalTime *itt,
                                                 gchar *buffer,
                                                 gint buffer_size);
-
+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;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]