From 931254c2a44bbf46a039ed4da2d0656ec0b4817f Mon Sep 17 00:00:00 2001 From: Titouan Real Date: Fri, 28 Feb 2025 10:11:44 +0100 Subject: [PATCH] common/date-chooser: Housekeeping Add some assertions and comments --- src/gui/common/gcal-date-chooser-day.c | 38 ++++++++++++++++++++++---- src/gui/common/gcal-date-chooser.c | 12 ++++++++ src/gui/common/gcal-date-chooser.h | 5 +--- src/gui/common/gcal-date-chooser.ui | 1 - 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/gui/common/gcal-date-chooser-day.c b/src/gui/common/gcal-date-chooser-day.c index ed4d933e..6af63128 100644 --- a/src/gui/common/gcal-date-chooser-day.c +++ b/src/gui/common/gcal-date-chooser-day.c @@ -48,6 +48,11 @@ static GParamSpec *properties[NUM_PROPS] = { NULL, }; G_DEFINE_TYPE (GcalDateChooserDay, gcal_date_chooser_day, GTK_TYPE_BUTTON) + +/* + * GObject overrides + */ + static void gcal_date_chooser_day_dispose (GObject *object) { @@ -158,6 +163,18 @@ gcal_date_chooser_day_init (GcalDateChooserDay *self) gtk_widget_init_template (GTK_WIDGET (self)); } + +/* + * Public API + */ + +/** + * gcal_date_chooser_day_new: + * + * Creates a new `DateChooserDay`. + * + * Returns: the newly created `DateChooserDay` + */ GtkWidget* gcal_date_chooser_day_new (void) { @@ -174,7 +191,8 @@ gcal_date_chooser_day_set_date (GcalDateChooserDay *self, gboolean today; gint weekday; - g_assert (date != NULL); + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); + g_assert (date); g_clear_pointer (&self->date, g_date_time_unref); self->date = g_date_time_ref (date); @@ -200,6 +218,8 @@ gcal_date_chooser_day_set_date (GcalDateChooserDay *self, GDateTime* gcal_date_chooser_day_get_date (GcalDateChooserDay *self) { + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); + return self->date; } @@ -207,6 +227,8 @@ void gcal_date_chooser_day_set_other_month (GcalDateChooserDay *self, gboolean other_month) { + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); + if (other_month) gtk_widget_add_css_class (GTK_WIDGET (self), "other-month"); else @@ -227,7 +249,7 @@ void gcal_date_chooser_day_set_has_dot (GcalDateChooserDay *self, gboolean has_dot) { - g_return_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self)); + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); has_dot = !!has_dot; @@ -248,7 +270,7 @@ gcal_date_chooser_day_set_has_dot (GcalDateChooserDay *self, gboolean gcal_date_chooser_day_get_has_dot (GcalDateChooserDay *self) { - g_return_val_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self), FALSE); + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); return gtk_widget_get_visible (self->dot_revealer); } @@ -267,7 +289,7 @@ void gcal_date_chooser_day_set_dot_visible (GcalDateChooserDay *self, gboolean dot_visible) { - g_return_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self)); + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); dot_visible = !!dot_visible; @@ -288,7 +310,7 @@ gcal_date_chooser_day_set_dot_visible (GcalDateChooserDay *self, gboolean gcal_date_chooser_day_get_dot_visible (GcalDateChooserDay *self) { - g_return_val_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self), FALSE); + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); return gtk_revealer_get_reveal_child (GTK_REVEALER (self->dot_revealer)); } @@ -297,7 +319,11 @@ void gcal_date_chooser_day_set_selected (GcalDateChooserDay *self, gboolean selected) { - GtkWidget *widget = GTK_WIDGET (self); + GtkWidget *widget; + + g_assert (GCAL_IS_DATE_CHOOSER_DAY (self)); + + widget = GTK_WIDGET (self); if (G_UNLIKELY (selected)) { diff --git a/src/gui/common/gcal-date-chooser.c b/src/gui/common/gcal-date-chooser.c index e9674fb2..732c7d9b 100644 --- a/src/gui/common/gcal-date-chooser.c +++ b/src/gui/common/gcal-date-chooser.c @@ -1090,6 +1090,18 @@ gcal_date_chooser_init (GcalDateChooser *self) gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drop_target)); } + +/* + * Public API + */ + +/** + * gcal_date_chooser_new: + * + * Creates a new `DateChooser`. + * + * Returns: the newly created `DateChooser` + */ GtkWidget* gcal_date_chooser_new (void) { diff --git a/src/gui/common/gcal-date-chooser.h b/src/gui/common/gcal-date-chooser.h index 493fa0ec..9e99360a 100644 --- a/src/gui/common/gcal-date-chooser.h +++ b/src/gui/common/gcal-date-chooser.h @@ -15,8 +15,7 @@ * License along with this library. If not, see . */ -#ifndef __GCAL_DATE_CHOOSER_H__ -#define __GCAL_DATE_CHOOSER_H__ +#pragma once #include @@ -59,5 +58,3 @@ void gcal_date_chooser_set_split_month_year (GcalDateChoose gboolean setting); G_END_DECLS - -#endif /* __GCAL_DATE_CHOOSER_H__ */ diff --git a/src/gui/common/gcal-date-chooser.ui b/src/gui/common/gcal-date-chooser.ui index 011f45db..02d3c9cc 100644 --- a/src/gui/common/gcal-date-chooser.ui +++ b/src/gui/common/gcal-date-chooser.ui @@ -1,6 +1,5 @@ -