From d820abcb3ed0f800a4d77ca5d54b24cd55c44a93 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sun, 21 Dec 2014 12:48:09 -0200 Subject: [PATCH] date-selector: allow calendar to select the date For testing reasons, we don't fire MODIFIED signal yet. --- src/gcal-date-selector.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gcal-date-selector.c b/src/gcal-date-selector.c index 5a794742..01118b07 100644 --- a/src/gcal-date-selector.c +++ b/src/gcal-date-selector.c @@ -62,6 +62,9 @@ enum static guint signals[NUM_SIGNALS] = { 0, }; +static void calendar_day_selected (GtkCalendar *calendar, + gpointer user_data); + static void text_inserted (GtkEditable *editable, gchar *new_text, gint new_text_length, @@ -77,6 +80,30 @@ static void gcal_date_selector_constructed (GObject G_DEFINE_TYPE_WITH_PRIVATE (GcalDateSelector, gcal_date_selector, GTK_TYPE_TOGGLE_BUTTON); +static void +calendar_day_selected (GtkCalendar *calendar, + gpointer user_data) +{ + GcalDateSelectorPrivate *priv; + guint day, month, year; + + priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (user_data)); + gtk_calendar_get_date (calendar, &year, &month, &day); + + /** + * Block signal handler to avoid an infinite + * recursion, exploding the proccess stack. + */ + g_signal_handlers_block_by_func (priv->calendar, + calendar_day_selected, + user_data); + set_date (GCAL_DATE_SELECTOR (user_data), day, month + 1, year); + + g_signal_handlers_unblock_by_func (priv->calendar, + calendar_day_selected, + user_data); +} + static void text_inserted (GtkEditable *editable, gchar *new_text, @@ -359,6 +386,8 @@ gcal_date_selector_constructed (GObject *object) g_signal_connect (priv->entries[MONTH], "insert-text", G_CALLBACK (text_inserted), object); g_signal_connect (priv->entries[YEAR], "insert-text", G_CALLBACK (text_inserted), object); + g_signal_connect (priv->calendar, "day-selected", G_CALLBACK (calendar_day_selected), object); + g_object_unref (builder); }