Rename GcalScheduleSectionValues -> GcalEventSchedule

And correspondingly, gcal_schedule_section_values_*() -> gcal_event_schedule_*()

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/550>
This commit is contained in:
Federico Mena Quintero
2025-08-27 20:18:52 -03:00
committed by Georges Basile Stavracas Neto
parent e9a626ed40
commit 8a653ec99d
2 changed files with 130 additions and 130 deletions
+125 -125
View File
@@ -37,7 +37,7 @@ struct _GcalScheduleSection
{ {
GtkBox parent; GtkBox parent;
GcalScheduleSectionValues *values; GcalEventSchedule *values;
AdwToggleGroup *schedule_type_toggle_group; AdwToggleGroup *schedule_type_toggle_group;
AdwPreferencesGroup *start_date_group; AdwPreferencesGroup *start_date_group;
@@ -57,10 +57,10 @@ struct _GcalScheduleSection
GcalEventEditorFlags flags; GcalEventEditorFlags flags;
}; };
/* Desired state of the widgets, computed from GcalScheduleValues. /* Desired state of the widgets, computed from GcalEventSchedule.
* *
* There is some subtle logic to decide how to update the widgets based on how * There is some subtle logic to decide how to update the widgets based on how
* each of them causes the GcalScheduleValues to be modified. We encapsulate * each of them causes the GcalEventSchedule to be modified. We encapsulate
* the desired state in this struct, so we can have tests for it. * the desired state in this struct, so we can have tests for it.
*/ */
typedef struct typedef struct
@@ -72,7 +72,7 @@ typedef struct
GcalTimeFormat time_format; GcalTimeFormat time_format;
/* Note that the displayed date/time may not correspond to the real data in the /* Note that the displayed date/time may not correspond to the real data in the
* GcalScheduleValues. See the comment in widget_state_from_values(). * GcalEventSchedule. See the comment in widget_state_from_values().
*/ */
GDateTime *date_time_start; GDateTime *date_time_start;
GDateTime *date_time_end; GDateTime *date_time_end;
@@ -140,10 +140,10 @@ gcal_schedule_values_copy (const GcalScheduleValues *values)
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_copy (const GcalScheduleSectionValues *values) gcal_event_schedule_copy (const GcalEventSchedule *values)
{ {
GcalScheduleSectionValues *copy = g_new0 (GcalScheduleSectionValues, 1); GcalEventSchedule *copy = g_new0 (GcalEventSchedule, 1);
copy->orig = gcal_schedule_values_copy (&values->orig); copy->orig = gcal_schedule_values_copy (&values->orig);
copy->curr = gcal_schedule_values_copy (&values->curr); copy->curr = gcal_schedule_values_copy (&values->curr);
@@ -163,22 +163,22 @@ gcal_schedule_values_free (GcalScheduleValues *values)
} }
/** /**
* gcal_schedule_section_values_free(): * gcal_event_schedule_free():
* *
* Frees the contents of @values. * Frees the contents of @values.
*/ */
void void
gcal_schedule_section_values_free (GcalScheduleSectionValues *values) gcal_event_schedule_free (GcalEventSchedule *values)
{ {
gcal_schedule_values_free (&values->orig); gcal_schedule_values_free (&values->orig);
gcal_schedule_values_free (&values->curr); gcal_schedule_values_free (&values->curr);
g_free (values); g_free (values);
} }
static GcalScheduleSectionValues* static GcalEventSchedule*
gcal_schedule_section_values_set_all_day (const GcalScheduleSectionValues *values, gboolean all_day) gcal_event_schedule_set_all_day (const GcalEventSchedule *values, gboolean all_day)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
if (all_day == values->curr.all_day) if (all_day == values->curr.all_day)
{ {
@@ -257,10 +257,10 @@ gcal_schedule_section_values_set_all_day (const GcalScheduleSectionValues *value
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_time_format (const GcalScheduleSectionValues *values, GcalTimeFormat time_format) gcal_event_schedule_set_time_format (const GcalEventSchedule *values, GcalTimeFormat time_format)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
copy->time_format = time_format; copy->time_format = time_format;
return copy; return copy;
@@ -269,10 +269,10 @@ gcal_schedule_section_values_set_time_format (const GcalScheduleSectionValues *v
/* The start_date_row widget has changed. We need to sync it to the values and /* The start_date_row widget has changed. We need to sync it to the values and
* adjust the other values based on it. * adjust the other values based on it.
*/ */
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_start_date (const GcalScheduleSectionValues *values, GDateTime *start) gcal_event_schedule_set_start_date (const GcalEventSchedule *values, GDateTime *start)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
gcal_set_date_time (&copy->curr.date_start, start); gcal_set_date_time (&copy->curr.date_start, start);
@@ -287,10 +287,10 @@ gcal_schedule_section_values_set_start_date (const GcalScheduleSectionValues *va
/* The end_date_row widget has changed. We need to sync it to the values and /* The end_date_row widget has changed. We need to sync it to the values and
* adjust the other values based on it. * adjust the other values based on it.
*/ */
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_end_date (const GcalScheduleSectionValues *values, GDateTime *end) gcal_event_schedule_set_end_date (const GcalEventSchedule *values, GDateTime *end)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
if (copy->curr.all_day) if (copy->curr.all_day)
{ {
@@ -314,10 +314,10 @@ gcal_schedule_section_values_set_end_date (const GcalScheduleSectionValues *valu
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_start_date_time (const GcalScheduleSectionValues *values, GDateTime *start) gcal_event_schedule_set_start_date_time (const GcalEventSchedule *values, GDateTime *start)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
gcal_set_date_time (&copy->curr.date_start, start); gcal_set_date_time (&copy->curr.date_start, start);
@@ -333,10 +333,10 @@ gcal_schedule_section_values_set_start_date_time (const GcalScheduleSectionValue
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_end_date_time (const GcalScheduleSectionValues *values, GDateTime *end) gcal_event_schedule_set_end_date_time (const GcalEventSchedule *values, GDateTime *end)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
gcal_set_date_time (&copy->curr.date_end, end); gcal_set_date_time (&copy->curr.date_end, end);
@@ -420,11 +420,11 @@ recur_change_limit_type (GcalRecurrence *old_recur, GcalRecurrenceLimitType limi
return new_recur; return new_recur;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_recur_frequency (const GcalScheduleSectionValues *values, gcal_event_schedule_set_recur_frequency (const GcalEventSchedule *values,
GcalRecurrenceFrequency frequency) GcalRecurrenceFrequency frequency)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
GcalRecurrence *new_recur = recur_change_frequency (copy->curr.recur, frequency); GcalRecurrence *new_recur = recur_change_frequency (copy->curr.recur, frequency);
g_clear_pointer (&copy->curr.recur, gcal_recurrence_unref); g_clear_pointer (&copy->curr.recur, gcal_recurrence_unref);
copy->curr.recur = new_recur; copy->curr.recur = new_recur;
@@ -432,11 +432,11 @@ gcal_schedule_section_values_set_recur_frequency (const GcalScheduleSectionValue
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_recur_limit_type (const GcalScheduleSectionValues *values, gcal_event_schedule_set_recur_limit_type (const GcalEventSchedule *values,
GcalRecurrenceLimitType limit_type) GcalRecurrenceLimitType limit_type)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
GcalRecurrence *new_recur = recur_change_limit_type (copy->curr.recur, limit_type, values->curr.date_start); GcalRecurrence *new_recur = recur_change_limit_type (copy->curr.recur, limit_type, values->curr.date_start);
g_clear_pointer (&copy->curr.recur, gcal_recurrence_unref); g_clear_pointer (&copy->curr.recur, gcal_recurrence_unref);
copy->curr.recur = new_recur; copy->curr.recur = new_recur;
@@ -444,11 +444,11 @@ gcal_schedule_section_values_set_recur_limit_type (const GcalScheduleSectionValu
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_recurrence_count (const GcalScheduleSectionValues *values, gcal_event_schedule_set_recurrence_count (const GcalEventSchedule *values,
guint count) guint count)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
/* An old recurrence would already be present */ /* An old recurrence would already be present */
g_assert (copy->curr.recur != NULL); g_assert (copy->curr.recur != NULL);
@@ -460,11 +460,11 @@ gcal_schedule_section_values_set_recurrence_count (const GcalScheduleSectionValu
return copy; return copy;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
gcal_schedule_section_values_set_recurrence_until (const GcalScheduleSectionValues *values, gcal_event_schedule_set_recurrence_until (const GcalEventSchedule *values,
GDateTime *until) GDateTime *until)
{ {
GcalScheduleSectionValues *copy = gcal_schedule_section_values_copy (values); GcalEventSchedule *copy = gcal_event_schedule_copy (values);
/* An old recurrence would already be present */ /* An old recurrence would already be present */
g_assert (copy->curr.recur != NULL); g_assert (copy->curr.recur != NULL);
@@ -477,7 +477,7 @@ gcal_schedule_section_values_set_recurrence_until (const GcalScheduleSectionValu
} }
static WidgetState * static WidgetState *
widget_state_from_values (const GcalScheduleSectionValues *values) widget_state_from_values (const GcalEventSchedule *values)
{ {
WidgetState *state = g_new0 (WidgetState, 1); WidgetState *state = g_new0 (WidgetState, 1);
@@ -496,7 +496,7 @@ widget_state_from_values (const GcalScheduleSectionValues *values)
* want to show the user a single-day all-day event as starting on Feb 1 and ending * want to show the user a single-day all-day event as starting on Feb 1 and ending
* on Feb 2, for example. * on Feb 2, for example.
* *
* So, we maintain the "real" data in GcalScheduleValues with the $day+1 as iCalendar wants, * So, we maintain the "real" data in GcalEventSchedule with the $day+1 as iCalendar wants,
* but for display purposes, we subtract a day from the end date to show the expected thing to the * but for display purposes, we subtract a day from the end date to show the expected thing to the
* user. When the widget changes, we add the day back - see gcal_schedule_values_set_end_date(). * user. When the widget changes, we add the day back - see gcal_schedule_values_set_end_date().
* *
@@ -692,10 +692,10 @@ refresh (GcalScheduleSection *self)
* This will free the current values and replace them with new ones. * This will free the current values and replace them with new ones.
*/ */
static void static void
update_from_section_values (GcalScheduleSection *self, update_from_event_schedule (GcalScheduleSection *self,
GcalScheduleSectionValues *values) GcalEventSchedule *values)
{ {
gcal_schedule_section_values_free (self->values); gcal_event_schedule_free (self->values);
self->values = values; self->values = values;
refresh (self); refresh (self);
@@ -711,8 +711,8 @@ on_schedule_type_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
gboolean all_day = all_day_selected (self); gboolean all_day = all_day_selected (self);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_all_day (self->values, all_day); GcalEventSchedule *updated = gcal_event_schedule_set_all_day (self->values, all_day);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
@@ -721,8 +721,8 @@ on_start_date_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
GDateTime *start = gcal_date_chooser_row_get_date (self->start_date_row); GDateTime *start = gcal_date_chooser_row_get_date (self->start_date_row);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_start_date (self->values, start); GcalEventSchedule *updated = gcal_event_schedule_set_start_date (self->values, start);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
@@ -731,8 +731,8 @@ on_end_date_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
GDateTime *end = gcal_date_chooser_row_get_date (self->end_date_row); GDateTime *end = gcal_date_chooser_row_get_date (self->end_date_row);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_end_date (self->values, end); GcalEventSchedule *updated = gcal_event_schedule_set_end_date (self->values, end);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
@@ -741,8 +741,8 @@ on_start_date_time_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
GDateTime *start = gcal_date_time_chooser_get_date_time (self->start_date_time_chooser); GDateTime *start = gcal_date_time_chooser_get_date_time (self->start_date_time_chooser);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_start_date_time (self->values, start); GcalEventSchedule *updated = gcal_event_schedule_set_start_date_time (self->values, start);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
@@ -751,24 +751,24 @@ on_end_date_time_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
GDateTime *end = gcal_date_time_chooser_get_date_time (self->end_date_time_chooser); GDateTime *end = gcal_date_time_chooser_get_date_time (self->end_date_time_chooser);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_end_date_time (self->values, end); GcalEventSchedule *updated = gcal_event_schedule_set_end_date_time (self->values, end);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
on_number_of_occurrences_changed_cb (GcalScheduleSection *self) on_number_of_occurrences_changed_cb (GcalScheduleSection *self)
{ {
guint count = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (self->number_of_occurrences_spin)); guint count = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (self->number_of_occurrences_spin));
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_recurrence_count (self->values, count); GcalEventSchedule *updated = gcal_event_schedule_set_recurrence_count (self->values, count);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
on_until_date_changed_cb (GcalScheduleSection *self) on_until_date_changed_cb (GcalScheduleSection *self)
{ {
GDateTime *until = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (self->until_date_selector)); GDateTime *until = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (self->until_date_selector));
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_recurrence_until (self->values, until); GcalEventSchedule *updated = gcal_event_schedule_set_recurrence_until (self->values, until);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static GcalRecurrenceLimitType static GcalRecurrenceLimitType
@@ -787,8 +787,8 @@ on_repeat_duration_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
GcalRecurrenceLimitType limit_type = get_recurence_limit_type (self); GcalRecurrenceLimitType limit_type = get_recurence_limit_type (self);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_recur_limit_type (self->values, limit_type); GcalEventSchedule *updated = gcal_event_schedule_set_recur_limit_type (self->values, limit_type);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static GcalRecurrenceFrequency static GcalRecurrenceFrequency
@@ -807,8 +807,8 @@ on_repeat_type_changed_cb (GtkWidget *widget,
GcalScheduleSection *self) GcalScheduleSection *self)
{ {
GcalRecurrenceFrequency frequency = get_recurrence_frequency (self); GcalRecurrenceFrequency frequency = get_recurrence_frequency (self);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_recur_frequency (self->values, frequency); GcalEventSchedule *updated = gcal_event_schedule_set_recur_frequency (self->values, frequency);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
static void static void
@@ -821,9 +821,9 @@ on_time_format_changed_cb (GcalScheduleSection *self)
*/ */
GcalTimeFormat time_format = gcal_context_get_time_format (self->context); GcalTimeFormat time_format = gcal_context_get_time_format (self->context);
GcalScheduleSectionValues *updated = gcal_schedule_section_values_set_time_format (self->values, time_format); GcalEventSchedule *updated = gcal_event_schedule_set_time_format (self->values, time_format);
update_from_section_values (self, updated); update_from_event_schedule (self, updated);
} }
} }
@@ -859,7 +859,7 @@ gcal_schedule_section_set_event (GcalEventEditorSection *section,
self->flags = flags; self->flags = flags;
time_format = gcal_context_get_time_format (self->context); time_format = gcal_context_get_time_format (self->context);
self->values = gcal_schedule_section_values_from_event (event, time_format); self->values = gcal_event_schedule_from_event (event, time_format);
if (!event) if (!event)
GCAL_RETURN (); GCAL_RETURN ();
@@ -909,29 +909,29 @@ gcal_schedule_section_apply (GcalEventEditorSection *section)
gcal_schedule_section_apply_to_event (self, self->event); gcal_schedule_section_apply_to_event (self, self->event);
gcal_schedule_section_values_free (self->values); gcal_event_schedule_free (self->values);
GcalTimeFormat time_format = gcal_context_get_time_format (self->context); GcalTimeFormat time_format = gcal_context_get_time_format (self->context);
self->values = gcal_schedule_section_values_from_event (self->event, time_format); self->values = gcal_event_schedule_from_event (self->event, time_format);
GCAL_EXIT; GCAL_EXIT;
} }
static gboolean static gboolean
recurrence_changed (const GcalScheduleSectionValues *values) recurrence_changed (const GcalEventSchedule *values)
{ {
return !gcal_recurrence_is_equal (values->orig.recur, values->curr.recur); return !gcal_recurrence_is_equal (values->orig.recur, values->curr.recur);
} }
static gboolean static gboolean
day_changed (const GcalScheduleSectionValues *values) day_changed (const GcalEventSchedule *values)
{ {
return (gcal_date_time_compare_date (values->curr.date_start, values->orig.date_start) < 0 || return (gcal_date_time_compare_date (values->curr.date_start, values->orig.date_start) < 0 ||
gcal_date_time_compare_date (values->curr.date_end, values->orig.date_end) > 0); gcal_date_time_compare_date (values->curr.date_end, values->orig.date_end) > 0);
} }
static gboolean static gboolean
values_changed (const GcalScheduleSectionValues *values) values_changed (const GcalEventSchedule *values)
{ {
const GcalScheduleValues *orig = &values->orig; const GcalScheduleValues *orig = &values->orig;
const GcalScheduleValues *curr = &values->curr; const GcalScheduleValues *curr = &values->curr;
@@ -988,7 +988,7 @@ gcal_schedule_section_finalize (GObject *object)
{ {
GcalScheduleSection *self = (GcalScheduleSection *)object; GcalScheduleSection *self = (GcalScheduleSection *)object;
g_clear_pointer (&self->values, gcal_schedule_section_values_free); g_clear_pointer (&self->values, gcal_event_schedule_free);
g_clear_object (&self->context); g_clear_object (&self->context);
g_clear_object (&self->event); g_clear_object (&self->event);
@@ -1107,12 +1107,12 @@ gcal_schedule_section_day_changed (GcalScheduleSection *self)
/** /**
* Extracts the values from @event that are needed to populate #GcalScheduleSection. * Extracts the values from @event that are needed to populate #GcalScheduleSection.
* *
* Returns: a #GcalScheduleSectionValues ready for use. Free it with * Returns: a #GcalEventSchedule ready for use. Free it with
* gcal_schedule_section_values_free(). * gcal_event_schedule_free().
*/ */
GcalScheduleSectionValues * GcalEventSchedule *
gcal_schedule_section_values_from_event (GcalEvent *event, gcal_event_schedule_from_event (GcalEvent *event,
GcalTimeFormat time_format) GcalTimeFormat time_format)
{ {
GcalScheduleValues values; GcalScheduleValues values;
memset (&values, 0, sizeof (values)); memset (&values, 0, sizeof (values));
@@ -1135,9 +1135,9 @@ gcal_schedule_section_values_from_event (GcalEvent *event,
} }
} }
GcalScheduleSectionValues *section_values = g_new0 (GcalScheduleSectionValues, 1); GcalEventSchedule *section_values = g_new0 (GcalEventSchedule, 1);
*section_values = (GcalScheduleSectionValues) { *section_values = (GcalEventSchedule) {
.orig = gcal_schedule_values_copy (&values), .orig = gcal_schedule_values_copy (&values),
.curr = values, .curr = values,
.time_format = time_format, .time_format = time_format,
@@ -1170,14 +1170,14 @@ values_with_date_times (const char *start, const char *end, gboolean all_day)
return values; return values;
} }
static GcalScheduleSectionValues * static GcalEventSchedule *
section_values_with_date_times (const char *start, const char *end, gboolean all_day) event_schedule_with_date_times (const char *start, const char *end, gboolean all_day)
{ {
GcalScheduleValues values = values_with_date_times (start, end, all_day); GcalScheduleValues values = values_with_date_times (start, end, all_day);
GcalScheduleSectionValues *section_values = g_new0 (GcalScheduleSectionValues, 1); GcalEventSchedule *section_values = g_new0 (GcalEventSchedule, 1);
*section_values = (GcalScheduleSectionValues) { *section_values = (GcalEventSchedule) {
.orig = gcal_schedule_values_copy (&values), .orig = gcal_schedule_values_copy (&values),
.curr = values, .curr = values,
.time_format = GCAL_TIME_FORMAT_24H, .time_format = GCAL_TIME_FORMAT_24H,
@@ -1197,13 +1197,13 @@ test_setting_start_date_after_end_date_resets_end_date (void)
* *
* We want to test that end becomes 12:00 as well. * We want to test that end becomes 12:00 as well.
*/ */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times("20250303T10:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times("20250303T10:00:00-06:00",
"20250303T11:00:00-06:00", "20250303T11:00:00-06:00",
FALSE); FALSE);
g_autoptr (GDateTime) two_hours_later = g_date_time_new_from_iso8601 ("20250303T12:00:00-06:00", NULL); g_autoptr (GDateTime) two_hours_later = g_date_time_new_from_iso8601 ("20250303T12:00:00-06:00", NULL);
g_autoptr (GcalScheduleSectionValues) new_values = gcal_schedule_section_values_set_start_date (values, two_hours_later); g_autoptr (GcalEventSchedule) new_values = gcal_event_schedule_set_start_date (values, two_hours_later);
g_assert (g_date_time_equal (new_values->curr.date_start, two_hours_later)); g_assert (g_date_time_equal (new_values->curr.date_start, two_hours_later));
g_assert (g_date_time_equal (new_values->curr.date_end, two_hours_later)); g_assert (g_date_time_equal (new_values->curr.date_end, two_hours_later));
} }
@@ -1219,13 +1219,13 @@ test_setting_end_date_before_start_date_resets_start_date (void)
* *
* We want to test that start becomes 09:00 as well. * We want to test that start becomes 09:00 as well.
*/ */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times("20250303T10:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times("20250303T10:00:00-06:00",
"20250303T11:00:00-06:00", "20250303T11:00:00-06:00",
FALSE); FALSE);
g_autoptr (GDateTime) two_hours_earlier = g_date_time_new_from_iso8601 ("20250303T09:00:00-06:00", NULL); g_autoptr (GDateTime) two_hours_earlier = g_date_time_new_from_iso8601 ("20250303T09:00:00-06:00", NULL);
g_autoptr (GcalScheduleSectionValues) new_values = gcal_schedule_section_values_set_end_date (values, two_hours_earlier); g_autoptr (GcalEventSchedule) new_values = gcal_event_schedule_set_end_date (values, two_hours_earlier);
g_assert (g_date_time_equal (new_values->curr.date_start, two_hours_earlier)); g_assert (g_date_time_equal (new_values->curr.date_start, two_hours_earlier));
g_assert (g_date_time_equal (new_values->curr.date_end, two_hours_earlier)); g_assert (g_date_time_equal (new_values->curr.date_end, two_hours_earlier));
} }
@@ -1243,15 +1243,15 @@ test_setting_start_datetime_preserves_end_timezone (void)
* *
* (imagine driving for one hour while crossing timezones) * (imagine driving for one hour while crossing timezones)
*/ */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times("20250303T10:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times("20250303T10:00:00-06:00",
"20250303T11:30:00-05:00", "20250303T11:30:00-05:00",
FALSE); FALSE);
g_assert (g_date_time_compare (values->curr.date_start, values->curr.date_end) == -1); g_assert (g_date_time_compare (values->curr.date_start, values->curr.date_end) == -1);
g_autoptr (GDateTime) new_start = g_date_time_new_from_iso8601 ("20250303T11:30:00-06:00", NULL); g_autoptr (GDateTime) new_start = g_date_time_new_from_iso8601 ("20250303T11:30:00-06:00", NULL);
g_autoptr (GDateTime) expected_end = g_date_time_new_from_iso8601 ("20250303T13:30:00-05:00", NULL); g_autoptr (GDateTime) expected_end = g_date_time_new_from_iso8601 ("20250303T13:30:00-05:00", NULL);
g_autoptr (GcalScheduleSectionValues) new_values = gcal_schedule_section_values_set_start_date_time (values, new_start); g_autoptr (GcalEventSchedule) new_values = gcal_event_schedule_set_start_date_time (values, new_start);
g_assert (g_date_time_equal (new_values->curr.date_start, new_start)); g_assert (g_date_time_equal (new_values->curr.date_start, new_start));
g_assert (g_date_time_equal (new_values->curr.date_end, expected_end)); g_assert (g_date_time_equal (new_values->curr.date_end, expected_end));
@@ -1270,15 +1270,15 @@ test_setting_end_datetime_preserves_start_timezone (void)
* *
* (imagine driving for one hour while crossing timezones) * (imagine driving for one hour while crossing timezones)
*/ */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times("20250303T10:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times("20250303T10:00:00-06:00",
"20250303T11:30:00-05:00", "20250303T11:30:00-05:00",
FALSE); FALSE);
g_assert (g_date_time_compare (values->curr.date_start, values->curr.date_end) == -1); g_assert (g_date_time_compare (values->curr.date_start, values->curr.date_end) == -1);
g_autoptr (GDateTime) new_end = g_date_time_new_from_iso8601 ("20250303T09:30:00-05:00", NULL); g_autoptr (GDateTime) new_end = g_date_time_new_from_iso8601 ("20250303T09:30:00-05:00", NULL);
g_autoptr (GDateTime) expected_start = g_date_time_new_from_iso8601 ("20250303T07:30:00-06:00", NULL); g_autoptr (GDateTime) expected_start = g_date_time_new_from_iso8601 ("20250303T07:30:00-06:00", NULL);
g_autoptr (GcalScheduleSectionValues) new_values = gcal_schedule_section_values_set_end_date_time (values, new_end); g_autoptr (GcalEventSchedule) new_values = gcal_event_schedule_set_end_date_time (values, new_end);
g_assert (g_date_time_equal (new_values->curr.date_end, new_end)); g_assert (g_date_time_equal (new_values->curr.date_end, new_end));
g_assert (g_date_time_equal (new_values->curr.date_start, expected_start)); g_assert (g_date_time_equal (new_values->curr.date_start, expected_start));
@@ -1301,9 +1301,9 @@ test_all_day_displays_sensible_dates_and_roundtrips (void)
* Check that the values gets back end = (start + 2 days) * Check that the values gets back end = (start + 2 days)
*/ */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times ("20250303T00:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times ("20250303T00:00:00-06:00",
"20250304T00:00:00-06:00", "20250304T00:00:00-06:00",
TRUE); TRUE);
/* Compute the widget state from the values; check the displayed dates (should be the same) */ /* Compute the widget state from the values; check the displayed dates (should be the same) */
@@ -1325,7 +1325,7 @@ test_all_day_displays_sensible_dates_and_roundtrips (void)
g_autoptr (GDateTime) displayed_end_date_plus_one_day = g_date_time_new_from_iso8601 ("20250304T00:00:00-06:00", NULL); g_autoptr (GDateTime) displayed_end_date_plus_one_day = g_date_time_new_from_iso8601 ("20250304T00:00:00-06:00", NULL);
g_assert (displayed_end_date_plus_one_day != NULL); g_assert (displayed_end_date_plus_one_day != NULL);
g_autoptr (GcalScheduleSectionValues) new_values = gcal_schedule_section_values_set_end_date (values, displayed_end_date_plus_one_day); g_autoptr (GcalEventSchedule) new_values = gcal_event_schedule_set_end_date (values, displayed_end_date_plus_one_day);
/* Check the real iCalendar value for the new date, should be different from the displayed value */ /* Check the real iCalendar value for the new date, should be different from the displayed value */
@@ -1353,13 +1353,13 @@ test_43_switching_to_all_day_preserves_timezones (void)
* original times. * original times.
*/ */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times ("20250303T12:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times ("20250303T12:00:00-06:00",
"20250304T13:00:00-06:00", "20250304T13:00:00-06:00",
FALSE); FALSE);
/* set all-day and check that this modified the times to midnight */ /* set all-day and check that this modified the times to midnight */
g_autoptr (GcalScheduleSectionValues) all_day_values = gcal_schedule_section_values_set_all_day (values, TRUE); g_autoptr (GcalEventSchedule) all_day_values = gcal_event_schedule_set_all_day (values, TRUE);
g_autoptr (GDateTime) expected_start_date = g_date_time_new_from_iso8601 ("20250303T00:00:00-06:00", NULL); g_autoptr (GDateTime) expected_start_date = g_date_time_new_from_iso8601 ("20250303T00:00:00-06:00", NULL);
g_autoptr (GDateTime) expected_end_date = g_date_time_new_from_iso8601 ("20250305T00:00:00-06:00", NULL); g_autoptr (GDateTime) expected_end_date = g_date_time_new_from_iso8601 ("20250305T00:00:00-06:00", NULL);
@@ -1369,7 +1369,7 @@ test_43_switching_to_all_day_preserves_timezones (void)
/* turn off all-day; check that times were restored */ /* turn off all-day; check that times were restored */
g_autoptr (GcalScheduleSectionValues) not_all_day_values = gcal_schedule_section_values_set_all_day (all_day_values, FALSE); g_autoptr (GcalEventSchedule) not_all_day_values = gcal_event_schedule_set_all_day (all_day_values, FALSE);
g_autoptr (GDateTime) expected_start_date2 = g_date_time_new_from_iso8601 ("20250303T12:00:00-06:00", NULL); g_autoptr (GDateTime) expected_start_date2 = g_date_time_new_from_iso8601 ("20250303T12:00:00-06:00", NULL);
g_autoptr (GDateTime) expected_end_date2 = g_date_time_new_from_iso8601 ("20250304T13:00:00-06:00", NULL); g_autoptr (GDateTime) expected_end_date2 = g_date_time_new_from_iso8601 ("20250304T13:00:00-06:00", NULL);
@@ -1416,17 +1416,17 @@ static void
test_turning_on_recurrence_count_turns_on_its_widget (void) test_turning_on_recurrence_count_turns_on_its_widget (void)
{ {
/* Start with some configuration */ /* Start with some configuration */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times("20250411T10:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times("20250411T10:00:00-06:00",
"20250411T11:30:00-06:00", "20250411T11:30:00-06:00",
FALSE); FALSE);
/* Turn on recurrence */ /* Turn on recurrence */
g_autoptr (GcalScheduleSectionValues) with_recur = g_autoptr (GcalEventSchedule) with_recur =
gcal_schedule_section_values_set_recur_frequency (values, GCAL_RECURRENCE_DAILY); gcal_event_schedule_set_recur_frequency (values, GCAL_RECURRENCE_DAILY);
/* Set it to "count" */ /* Set it to "count" */
g_autoptr (GcalScheduleSectionValues) with_count = g_autoptr (GcalEventSchedule) with_count =
gcal_schedule_section_values_set_recur_limit_type (with_recur, GCAL_RECURRENCE_COUNT); gcal_event_schedule_set_recur_limit_type (with_recur, GCAL_RECURRENCE_COUNT);
g_autoptr (WidgetState) state = widget_state_from_values (with_count); g_autoptr (WidgetState) state = widget_state_from_values (with_count);
g_assert_true (state->recurrence.duration_combo_visible); g_assert_true (state->recurrence.duration_combo_visible);
@@ -1438,17 +1438,17 @@ static void
test_turning_on_recurrence_until_turns_on_its_widget (void) test_turning_on_recurrence_until_turns_on_its_widget (void)
{ {
/* Start with some configuration */ /* Start with some configuration */
g_autoptr (GcalScheduleSectionValues) values = section_values_with_date_times("20250411T10:00:00-06:00", g_autoptr (GcalEventSchedule) values = event_schedule_with_date_times("20250411T10:00:00-06:00",
"20250411T11:30:00-06:00", "20250411T11:30:00-06:00",
FALSE); FALSE);
/* Turn on recurrence */ /* Turn on recurrence */
g_autoptr (GcalScheduleSectionValues) with_recur = g_autoptr (GcalEventSchedule) with_recur =
gcal_schedule_section_values_set_recur_frequency (values, GCAL_RECURRENCE_DAILY); gcal_event_schedule_set_recur_frequency (values, GCAL_RECURRENCE_DAILY);
/* Set it to "count" */ /* Set it to "count" */
g_autoptr (GcalScheduleSectionValues) with_until = g_autoptr (GcalEventSchedule) with_until =
gcal_schedule_section_values_set_recur_limit_type (with_recur, GCAL_RECURRENCE_UNTIL); gcal_event_schedule_set_recur_limit_type (with_recur, GCAL_RECURRENCE_UNTIL);
g_autoptr (WidgetState) state = widget_state_from_values (with_until); g_autoptr (WidgetState) state = widget_state_from_values (with_until);
g_assert_true (state->recurrence.duration_combo_visible); g_assert_true (state->recurrence.duration_combo_visible);
+5 -5
View File
@@ -57,17 +57,17 @@ typedef struct
/* copied from GcalContext to avoid a dependency on it */ /* copied from GcalContext to avoid a dependency on it */
GcalTimeFormat time_format; GcalTimeFormat time_format;
} GcalScheduleSectionValues; } GcalEventSchedule;
gboolean gcal_schedule_section_recurrence_changed (GcalScheduleSection *self); gboolean gcal_schedule_section_recurrence_changed (GcalScheduleSection *self);
gboolean gcal_schedule_section_day_changed (GcalScheduleSection *self); gboolean gcal_schedule_section_day_changed (GcalScheduleSection *self);
GcalScheduleSectionValues *gcal_schedule_section_values_from_event (GcalEvent *event, GcalEventSchedule *gcal_event_schedule_from_event (GcalEvent *event,
GcalTimeFormat time_format); GcalTimeFormat time_format);
void gcal_schedule_section_values_free (GcalScheduleSectionValues *values); void gcal_event_schedule_free (GcalEventSchedule *values);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalScheduleSectionValues, gcal_schedule_section_values_free); G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalEventSchedule, gcal_event_schedule_free);
/* Tests */ /* Tests */