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



commit 7eff67693f6c26444743b9edb3f7e085a06645ae
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                       |  3 +
 .../composer-to-meeting/e-composer-to-meeting.c    | 12 ++++
 src/plugins/mail-to-task/mail-to-task.c            | 31 +++++-----
 4 files changed, 69 insertions(+), 46 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,36 +359,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 ();
 
@@ -405,21 +386,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);
@@ -429,6 +410,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 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 <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);
 


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