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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -641,11 +641,68 @@ gcal_schedule_section_apply (GcalEventEditorSection *section)
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_schedule_section_changed (GcalEventEditorSection *section)
|
||||
{
|
||||
g_autoptr (GDateTime) start_date = NULL;
|
||||
g_autoptr (GDateTime) end_date = NULL;
|
||||
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 */
|
||||
GCAL_RETURN (gcal_schedule_section_recurrence_changed (self));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -749,3 +806,26 @@ gcal_schedule_section_init (GcalScheduleSection *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
gboolean
|
||||
gcal_schedule_section_recurrence_changed (GcalScheduleSection *self)
|
||||
{
|
||||
g_autoptr (GcalRecurrence) recurrence = NULL;
|
||||
GcalRecurrenceFrequency freq;
|
||||
|
||||
g_return_val_if_fail (GCAL_IS_SCHEDULE_SECTION (self), FALSE);
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
@@ -27,4 +27,6 @@ G_BEGIN_DECLS
|
||||
#define GCAL_TYPE_SCHEDULE_SECTION (gcal_schedule_section_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GcalScheduleSection, gcal_schedule_section, GCAL, SCHEDULE_SECTION, GtkBox)
|
||||
|
||||
gboolean gcal_schedule_section_recurrence_changed (GcalScheduleSection *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user