[gnome-calendar/gbsneto/recurring-event-editing-fixes: 13/18] event-editor/sections: Add vfunc to check for changes
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gbsneto/recurring-event-editing-fixes: 13/18] event-editor/sections: Add vfunc to check for changes
- Date: Fri, 14 Oct 2022 17:53:54 +0000 (UTC)
commit fbfb9ceebf5d1967785b39291b87aeeffbb7bb0f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Oct 14 13:59:45 2022 -0300
event-editor/sections: Add vfunc to check for changes
This will be useful for next commits where we will need to check
if the schedule section actually changed something.
src/gui/event-editor/gcal-event-editor-section.c | 19 +++++++
src/gui/event-editor/gcal-event-editor-section.h | 4 ++
src/gui/event-editor/gcal-notes-section.c | 19 +++++++
src/gui/event-editor/gcal-reminders-section.c | 43 ++++++++++++++
src/gui/event-editor/gcal-schedule-section.c | 71 ++++++++++++++++++++++++
src/gui/event-editor/gcal-summary-section.c | 18 ++++++
6 files changed, 174 insertions(+)
---
diff --git a/src/gui/event-editor/gcal-event-editor-section.c
b/src/gui/event-editor/gcal-event-editor-section.c
index 1ac13125..3bdcba26 100644
--- a/src/gui/event-editor/gcal-event-editor-section.c
+++ b/src/gui/event-editor/gcal-event-editor-section.c
@@ -66,3 +66,22 @@ gcal_event_editor_section_apply (GcalEventEditorSection *self)
if (GCAL_EVENT_EDITOR_SECTION_GET_IFACE (self)->apply)
GCAL_EVENT_EDITOR_SECTION_GET_IFACE (self)->apply (self);
}
+
+/**
+ * gcal_event_editor_section_changed:
+ * @self: a #GcalEventEditorSection
+ *
+ * Checks whether this section has any pending changes to the event.
+ *
+ * Returns: %TRUE if this section has pending changes
+ */
+gboolean
+gcal_event_editor_section_changed (GcalEventEditorSection *self)
+{
+ g_return_val_if_fail (GCAL_IS_EVENT_EDITOR_SECTION (self), FALSE);
+
+ if (GCAL_EVENT_EDITOR_SECTION_GET_IFACE (self)->changed)
+ return GCAL_EVENT_EDITOR_SECTION_GET_IFACE (self)->changed (self);
+ else
+ return TRUE;
+}
diff --git a/src/gui/event-editor/gcal-event-editor-section.h
b/src/gui/event-editor/gcal-event-editor-section.h
index bf34aafa..85e2a386 100644
--- a/src/gui/event-editor/gcal-event-editor-section.h
+++ b/src/gui/event-editor/gcal-event-editor-section.h
@@ -45,6 +45,8 @@ struct _GcalEventEditorSectionInterface
GcalEventEditorFlags flags);
void (*apply) (GcalEventEditorSection *self);
+
+ gboolean (*changed) (GcalEventEditorSection *self);
};
void gcal_event_editor_section_set_event (GcalEventEditorSection *self,
@@ -53,4 +55,6 @@ void gcal_event_editor_section_set_event (GcalEventEdito
void gcal_event_editor_section_apply (GcalEventEditorSection *self);
+gboolean gcal_event_editor_section_changed (GcalEventEditorSection *self);
+
G_END_DECLS
diff --git a/src/gui/event-editor/gcal-notes-section.c b/src/gui/event-editor/gcal-notes-section.c
index eeb105ed..5256b3da 100644
--- a/src/gui/event-editor/gcal-notes-section.c
+++ b/src/gui/event-editor/gcal-notes-section.c
@@ -94,11 +94,30 @@ gcal_notes_section_apply (GcalEventEditorSection *section)
GCAL_EXIT;
}
+static gboolean
+gcal_notes_section_changed (GcalEventEditorSection *section)
+{
+ g_autofree gchar *note_text = NULL;
+ GcalNotesSection *self;
+ GtkTextBuffer *buffer;
+
+ GCAL_ENTRY;
+
+ self = GCAL_NOTES_SECTION (section);
+
+ /* Update description */
+ buffer = gtk_text_view_get_buffer (self->notes_text);
+ g_object_get (G_OBJECT (buffer), "text", ¬e_text, NULL);
+
+ GCAL_RETURN (g_strcmp0 (gcal_event_get_description (self->event), note_text) != 0);
+}
+
static void
gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface)
{
iface->set_event = gcal_notes_section_set_event;
iface->apply = gcal_notes_section_apply;
+ iface->changed = gcal_notes_section_changed;
}
diff --git a/src/gui/event-editor/gcal-reminders-section.c b/src/gui/event-editor/gcal-reminders-section.c
index 69b56f5e..eb7995e7 100644
--- a/src/gui/event-editor/gcal-reminders-section.c
+++ b/src/gui/event-editor/gcal-reminders-section.c
@@ -361,11 +361,54 @@ gcal_reminders_section_apply (GcalEventEditorSection *section)
GCAL_EXIT;
}
+static gboolean
+gcal_reminders_section_changed (GcalEventEditorSection *section)
+{
+ GcalRemindersSection *self;
+ g_autoptr (GList) alarms = NULL;
+
+ GCAL_ENTRY;
+
+ self = GCAL_REMINDERS_SECTION (section);
+
+ alarms = gcal_event_get_alarms (self->event);
+ if (g_list_length (alarms) != self->alarms->len)
+ GCAL_RETURN (FALSE);
+
+ for (GList *l = alarms; l != NULL; l = l->next)
+ {
+ ECalComponentAlarm *other_alarm;
+ ECalComponentAlarm *alarm;
+
+ alarm = l->data;
+ other_alarm = NULL;
+
+ for (guint i = 0; i < self->alarms->len; i++)
+ {
+ ECalComponentAlarm *aux = g_ptr_array_index (self->alarms, i);
+
+ if (get_alarm_trigger_minutes (self->event, alarm) == get_alarm_trigger_minutes (self->event, aux))
+ {
+ other_alarm = aux;
+ break;
+ }
+ }
+
+ if (!other_alarm)
+ GCAL_RETURN (TRUE);
+
+ /* TODO: this certainly needs deeper comparisons! */
+ }
+
+ GCAL_RETURN (FALSE);
+}
+
static void
gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface)
{
iface->set_event = gcal_reminders_section_set_event;
iface->apply = gcal_reminders_section_apply;
+ iface->changed = gcal_reminders_section_changed;
}
diff --git a/src/gui/event-editor/gcal-schedule-section.c b/src/gui/event-editor/gcal-schedule-section.c
index 7f13d9a7..fb762643 100644
--- a/src/gui/event-editor/gcal-schedule-section.c
+++ b/src/gui/event-editor/gcal-schedule-section.c
@@ -641,11 +641,82 @@ gcal_schedule_section_apply (GcalEventEditorSection *section)
GCAL_EXIT;
}
+static gboolean
+gcal_schedule_section_changed (GcalEventEditorSection *section)
+{
+ g_autoptr (GcalRecurrence) recurrence = NULL;
+ g_autoptr (GDateTime) start_date = NULL;
+ g_autoptr (GDateTime) end_date = NULL;
+ GcalRecurrenceFrequency freq;
+ GcalScheduleSection *self;
+ gboolean was_all_day;
+ gboolean all_day;
+
+ GCAL_ENTRY;
+
+ self = GCAL_SCHEDULE_SECTION (section);
+ all_day = gtk_switch_get_active (self->all_day_switch);
+ was_all_day = gcal_event_get_all_day (self->event);
+
+ /* All day */
+ if (all_day != was_all_day)
+ GCAL_RETURN (TRUE);
+
+ /* Start date */
+ start_date = get_date_start (self);
+ if (!g_date_time_equal (start_date, gcal_event_get_date_start (self->event)))
+ GCAL_RETURN (TRUE);
+
+ /* End date */
+ end_date = get_date_end (self);
+ if (gtk_switch_get_active (self->all_day_switch))
+ {
+ g_autoptr (GDateTime) fake_end_date = g_date_time_add_days (end_date, 1);
+ gcal_set_date_time (&end_date, fake_end_date);
+ }
+ else if (!all_day && was_all_day)
+ {
+ /* When an all day event is changed to be not an all day event, we
+ * need to correct for the fact that the event's timezone was until
+ * now set to UTC. That means we need to change the timezone to
+ * localtime now, or else it will be saved incorrectly.
+ */
+ GDateTime *localtime_date;
+
+ localtime_date = g_date_time_to_local (start_date);
+ g_clear_pointer (&start_date, g_date_time_unref);
+ start_date = localtime_date;
+
+ localtime_date = g_date_time_to_local (end_date);
+ g_clear_pointer (&end_date, g_date_time_unref);
+ end_date = localtime_date;
+ }
+
+ if (!g_date_time_equal (end_date, gcal_event_get_date_end (self->event)))
+ GCAL_RETURN (TRUE);
+
+ /* Recurrency */
+ freq = gtk_combo_box_get_active (GTK_COMBO_BOX (self->repeat_combo));
+ if (freq == GCAL_RECURRENCE_NO_REPEAT && !gcal_event_get_recurrence (self->event))
+ GCAL_RETURN (FALSE);
+
+ recurrence = gcal_recurrence_new ();
+ recurrence->frequency = gtk_combo_box_get_active (GTK_COMBO_BOX (self->repeat_combo));
+ recurrence->limit_type = gtk_combo_box_get_active (GTK_COMBO_BOX (self->repeat_duration_combo));
+ if (recurrence->limit_type == GCAL_RECURRENCE_UNTIL)
+ recurrence->limit.until = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (self->until_date_selector));
+ else if (recurrence->limit_type == GCAL_RECURRENCE_COUNT)
+ recurrence->limit.count = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
(self->number_of_occurrences_spin));
+
+ GCAL_RETURN (!gcal_recurrence_is_equal (recurrence, gcal_event_get_recurrence (self->event)));
+}
+
static void
gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface)
{
iface->set_event = gcal_schedule_section_set_event;
iface->apply = gcal_schedule_section_apply;
+ iface->changed = gcal_schedule_section_changed;
}
diff --git a/src/gui/event-editor/gcal-summary-section.c b/src/gui/event-editor/gcal-summary-section.c
index 401a8c9b..d1cf3b84 100644
--- a/src/gui/event-editor/gcal-summary-section.c
+++ b/src/gui/event-editor/gcal-summary-section.c
@@ -99,11 +99,29 @@ gcal_reminders_section_apply (GcalEventEditorSection *section)
GCAL_EXIT;
}
+static gboolean
+gcal_reminders_section_changed (GcalEventEditorSection *section)
+{
+ GcalSummarySection *self;
+ const gchar *event_location;
+ const gchar *event_summary;
+
+ GCAL_ENTRY;
+
+ self = GCAL_SUMMARY_SECTION (section);
+ event_summary = gcal_event_get_summary (self->event);
+ event_location = gcal_event_get_location (self->event);
+
+ GCAL_RETURN (g_strcmp0 (event_summary, gtk_editable_get_text (self->summary_entry)) != 0 ||
+ g_strcmp0 (event_location, gtk_editable_get_text (self->location_entry)) != 0);
+}
+
static void
gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface)
{
iface->set_event = gcal_reminders_section_set_event;
iface->apply = gcal_reminders_section_apply;
+ iface->changed = gcal_reminders_section_changed;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]