GcalScheduleValues: new struct to hold values from a GcalEvent for the schedule widges

We'll move GcalScheduleSection to operate without a backing GcalEvent,
so we can add tests.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/550>
This commit is contained in:
Federico Mena Quintero
2025-08-27 19:59:16 -03:00
committed by Georges Basile Stavracas Neto
parent 42b00ec052
commit f75785a34c
2 changed files with 62 additions and 0 deletions
@@ -771,3 +771,47 @@ gcal_schedule_section_day_changed (GcalScheduleSection *self)
GCAL_RETURN (gcal_date_time_compare_date (start_date, gcal_event_get_date_start (self->event)) < 0 ||
gcal_date_time_compare_date (end_date, gcal_event_get_date_end (self->event)) > 0);
}
/**
* Extracts the values from @event that are needed to populate #GcalScheduleSection.
*
* Returns: a #GcalscheduleValues ready for use. Free it with
* gcal_schedule_values_free().
*/
GcalScheduleValues *
gcal_schedule_values_from_event (GcalEvent *event)
{
GcalScheduleValues *values = g_new0 (GcalScheduleValues, 1);
if (event)
{
GcalRecurrence *recur = gcal_event_get_recurrence (event);
values->all_day = gcal_event_get_all_day (event);
values->date_start = g_date_time_ref (gcal_event_get_date_start (event));
values->date_end = g_date_time_ref (gcal_event_get_date_end (event));
if (recur)
{
values->recur = gcal_recurrence_ref (recur);
}
}
return values;
}
/**
* Frees the contents of @values. Does not free the @values pointer itself;
* this structure is meant to be allocated on the stack.
*/
void
gcal_schedule_values_free (GcalScheduleValues *values)
{
values->all_day = FALSE;
g_clear_pointer (&values->date_start, g_date_time_unref);
g_clear_pointer (&values->date_end, g_date_time_unref);
g_clear_pointer (&values->recur, gcal_recurrence_unref);
g_free (values);
}
@@ -28,8 +28,26 @@ 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)
/* Values from a GcalEvent that this widget can manipulate.
*
* We keep an immutable copy of the original event's values, and later generate
* a new GcalScheduleValues with the updated data from the widgetry.
*/
typedef struct
{
gboolean all_day;
GDateTime *date_start;
GDateTime *date_end;
GcalRecurrence *recur;
} GcalScheduleValues;
gboolean gcal_schedule_section_recurrence_changed (GcalScheduleSection *self);
gboolean gcal_schedule_section_day_changed (GcalScheduleSection *self);
GcalScheduleValues *gcal_schedule_values_from_event (GcalEvent *event);
void gcal_schedule_values_free (GcalScheduleValues *values);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalScheduleValues, gcal_schedule_values_free);
G_END_DECLS