reminders-section: make alarm sound changes persistent

When the alarm sound changes, the change is not updated because
gcal-manager does not see the changes.

We now update the components and make more comparisons so that
it can be seen by gcal-manager
This commit is contained in:
Abdullahi Usman
2024-07-09 19:47:13 +00:00
committed by Georges Basile Stavracas Neto
parent 420a126ddb
commit d8e2fd6d81
3 changed files with 60 additions and 1 deletions
+10
View File
@@ -46,6 +46,7 @@ enum
enum
{
UPDATE_ALARM,
REMOVE_ALARM,
N_SIGNALS,
};
@@ -250,6 +251,7 @@ on_sound_toggle_changed_cb (GtkToggleButton *button,
gtk_button_set_icon_name (GTK_BUTTON (self->volume_button),
has_sound ? "audio-volume-high-symbolic" : "audio-volume-muted-symbolic");
g_signal_emit (self, signals[UPDATE_ALARM], 0);
}
@@ -332,6 +334,14 @@ gcal_alarm_row_class_init (GcalAlarmRowClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals[UPDATE_ALARM] = g_signal_new ("update-alarm",
GCAL_TYPE_ALARM_ROW,
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-alarm-row.ui");
@@ -137,6 +137,7 @@ apply_event_properties_to_template_event (GcalEvent *template_event,
{
g_autoptr (GDateTime) start_date = NULL;
g_autoptr (GDateTime) end_date = NULL;
g_autoptr (GList) alarms = gcal_event_get_alarms (event);
GDateTime *template_start_date;
GDateTime *event_start_date;
GDateTime *template_end_date;
@@ -187,6 +188,15 @@ apply_event_properties_to_template_event (GcalEvent *template_event,
gcal_event_set_all_day (template_event, gcal_event_get_all_day (event));
gcal_event_set_date_start (template_event, start_date);
gcal_event_set_date_end (template_event, end_date);
gcal_event_remove_all_alarms (template_event);
for (GList *l = alarms; l != NULL; l = l->next)
{
ECalComponentAlarm *alarm = l->data;
if (alarm)
gcal_event_add_alarm (template_event, alarm);
}
}
static gboolean
+40 -1
View File
@@ -57,6 +57,8 @@ static void gcal_event_editor_section_iface_init (GcalEventEdito
static void on_remove_alarm_cb (GcalAlarmRow *alarm_row,
GcalRemindersSection *self);
static void on_update_alarm_cb (GcalAlarmRow *alarm_row,
GcalRemindersSection *self);
G_DEFINE_TYPE_WITH_CODE (GcalRemindersSection, gcal_reminders_section, GTK_TYPE_BOX,
G_IMPLEMENT_INTERFACE (GCAL_TYPE_EVENT_EDITOR_SECTION, gcal_event_editor_section_iface_init))
@@ -169,6 +171,7 @@ create_alarm_row (GcalRemindersSection *self,
row = gcal_alarm_row_new (alarm);
g_signal_connect_object (row, "remove-alarm", G_CALLBACK (on_remove_alarm_cb), self, 0);
g_signal_connect_object (row, "update-alarm", G_CALLBACK (on_update_alarm_cb), self, 0);
return row;
}
@@ -257,6 +260,38 @@ sort_alarms_func (GtkListBoxRow *a,
return minutes_a - minutes_b;
}
static void
on_update_alarm_cb (GcalAlarmRow *alarm_row,
GcalRemindersSection *self)
{
ECalComponentAlarm *alarm;
gint trigger_minutes;
gsize i;
GCAL_ENTRY;
alarm = gcal_alarm_row_get_alarm (alarm_row);
trigger_minutes = get_alarm_trigger_minutes (self->event, alarm);
/* Remove from the array */
for (i = 0; i < self->alarms->len; i++)
{
ECalComponentAlarm *a = g_ptr_array_index (self->alarms, i);
if (trigger_minutes == get_alarm_trigger_minutes (self->event, a))
{
GCAL_TRACE_MSG ("Updated alarm for %d minutes", trigger_minutes);
g_ptr_array_remove_index (self->alarms, i);
g_ptr_array_insert (self->alarms, i, e_cal_component_alarm_copy (alarm));
break;
}
}
GCAL_EXIT;
}
static void
on_remove_alarm_cb (GcalAlarmRow *alarm_row,
GcalRemindersSection *self)
@@ -392,7 +427,7 @@ gcal_reminders_section_changed (GcalEventEditorSection *section)
alarms = gcal_event_get_alarms (self->event);
if (g_list_length (alarms) != self->alarms->len)
GCAL_RETURN (FALSE);
GCAL_RETURN (TRUE);
for (GList *l = alarms; l != NULL; l = l->next)
{
@@ -409,6 +444,10 @@ gcal_reminders_section_changed (GcalEventEditorSection *section)
if (get_alarm_trigger_minutes (self->event, alarm) == get_alarm_trigger_minutes (self->event, aux))
{
other_alarm = aux;
if (e_cal_component_alarm_get_action (alarm) != e_cal_component_alarm_get_action (aux))
GCAL_RETURN (TRUE);
break;
}
}