[evolution] I#1958 - Calendar: Sort reminder times in the component editor



commit bed1556e0f22d061e3bd164a67dad98b801a2540
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 13 15:07:57 2022 +0200

    I#1958 - Calendar: Sort reminder times in the component editor
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1958

 src/calendar/gui/e-comp-editor-page-reminders.c | 35 +++++++++----------------
 1 file changed, 13 insertions(+), 22 deletions(-)
---
diff --git a/src/calendar/gui/e-comp-editor-page-reminders.c b/src/calendar/gui/e-comp-editor-page-reminders.c
index 0241c20c97..d5dbed27d1 100644
--- a/src/calendar/gui/e-comp-editor-page-reminders.c
+++ b/src/calendar/gui/e-comp-editor-page-reminders.c
@@ -1787,12 +1787,8 @@ ecep_reminders_sort_predefined_alarms (ECompEditorPageReminders *page_reminders)
                /* Just count those filled */
        }
 
-       nelems -= N_PREDEFINED_ALARMS;
-
-       if (nelems > 1) {
-               g_qsort_with_data (&(page_reminders->priv->predefined_alarms[N_PREDEFINED_ALARMS]), nelems,
-                       sizeof (gint), ecep_reminders_compare_predefined_alarm, NULL);
-       }
+       g_qsort_with_data (page_reminders->priv->predefined_alarms, nelems,
+               sizeof (gint), ecep_reminders_compare_predefined_alarm, NULL);
 }
 
 static gboolean
@@ -1806,6 +1802,8 @@ ecep_reminders_fill_alarms_combo (ECompEditorPageReminders *page_reminders,
        g_return_val_if_fail (E_IS_COMP_EDITOR_PAGE_REMINDERS (page_reminders), FALSE);
        g_return_val_if_fail (GTK_IS_COMBO_BOX_TEXT (page_reminders->priv->alarms_combo), FALSE);
 
+       ecep_reminders_sort_predefined_alarms (page_reminders);
+
        text_combo = GTK_COMBO_BOX_TEXT (page_reminders->priv->alarms_combo);
 
        g_signal_handlers_block_by_func (text_combo, ecep_reminders_alarms_combo_changed_cb, page_reminders);
@@ -1859,13 +1857,18 @@ ecep_reminders_fill_alarms_combo (ECompEditorPageReminders *page_reminders,
 }
 
 static void
-ecep_reminders_add_default_alarm_time (ECompEditorPageReminders *page_reminders)
+ecep_reminders_init_predefined_alarms (ECompEditorPageReminders *page_reminders)
 {
        EDurationType alarm_units;
        gint alarm_interval, minutes;
 
        g_return_if_fail (E_IS_COMP_EDITOR_PAGE_REMINDERS (page_reminders));
 
+       page_reminders->priv->predefined_alarms[0] = ecep_reminders_interval_to_int (0, 0, 15);
+       page_reminders->priv->predefined_alarms[1] = ecep_reminders_interval_to_int (0, 1, 0);
+       page_reminders->priv->predefined_alarms[2] = ecep_reminders_interval_to_int (1, 0, 0);
+       page_reminders->priv->predefined_alarms[3] = -1;
+
        alarm_interval = calendar_config_get_default_reminder_interval ();
        alarm_units = calendar_config_get_default_reminder_units ();
 
@@ -1936,17 +1939,13 @@ ecep_reminders_add_custom_time_add_button_clicked_cb (GtkButton *button,
 
                g_object_unref (settings);
 
-               page_reminders->priv->predefined_alarms[N_PREDEFINED_ALARMS] = -1;
-
-               ecep_reminders_add_default_alarm_time (page_reminders);
+               ecep_reminders_init_predefined_alarms (page_reminders);
 
                for (ii = 0; ii < narray; ii++) {
                        if (ecep_reminders_add_predefined_alarm (page_reminders, array[ii]))
                                any_user_alarm_added = TRUE;
                }
 
-               ecep_reminders_sort_predefined_alarms (page_reminders);
-
                page_reminders->priv->any_custom_reminder_set = any_user_alarm_added;
 
                if (!ecep_reminders_fill_alarms_combo (page_reminders, new_minutes))
@@ -2077,9 +2076,7 @@ ecep_reminders_remove_custom_times_clicked (ECompEditorPageReminders *page_remin
        g_settings_reset (settings, "custom-reminders-minutes");
        g_object_unref (settings);
 
-       page_reminders->priv->predefined_alarms[N_PREDEFINED_ALARMS] = -1;
-
-       ecep_reminders_add_default_alarm_time (page_reminders);
+       ecep_reminders_init_predefined_alarms (page_reminders);
 
        page_reminders->priv->any_custom_reminder_set = FALSE;
 
@@ -2188,12 +2185,7 @@ ecep_reminders_constructed (GObject *object)
 
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), page_reminders->priv->alarms_combo);
 
-       page_reminders->priv->predefined_alarms[0] = ecep_reminders_interval_to_int (0, 0, 15);
-       page_reminders->priv->predefined_alarms[1] = ecep_reminders_interval_to_int (0, 1, 0);
-       page_reminders->priv->predefined_alarms[2] = ecep_reminders_interval_to_int (1, 0, 0);
-       page_reminders->priv->predefined_alarms[3] = -1;
-
-       ecep_reminders_add_default_alarm_time (page_reminders);
+       ecep_reminders_init_predefined_alarms (page_reminders);
 
        settings = e_util_ref_settings ("org.gnome.evolution.calendar");
        variant = g_settings_get_value (settings, "custom-reminders-minutes");
@@ -2220,7 +2212,6 @@ ecep_reminders_constructed (GObject *object)
 
        g_object_unref (settings);
 
-       ecep_reminders_sort_predefined_alarms (page_reminders);
        ecep_reminders_fill_alarms_combo (page_reminders, -1);
 
        gtk_combo_box_set_active (GTK_COMBO_BOX (page_reminders->priv->alarms_combo), 0);


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