From c5e72bbaf1744a6693e6a69cfe67c2aa914d3843 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 1 May 2013 16:39:52 -0700 Subject: fix for the datetime g_critical reported by desrt --- src/indicator-datetime.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 7d29914..0945cb2 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -268,26 +268,33 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) static void menu_visible_notify_cb(GtkWidget * menu, G_GNUC_UNUSED GParamSpec *pspec, gpointer user_data) { - GtkWidget * w; - GtkCalendar * calendar; - IndicatorDatetime * self = INDICATOR_DATETIME(user_data); - GDateTime *datetime; - gint cur_y, cur_m, cur_d; - guint cal_y, cal_m, cal_d; - - g_debug("notify visible signal received"); - - /* set the calendar to today's date */ - datetime = g_date_time_new_now_local (); - g_date_time_get_ymd (datetime, &cur_y, &cur_m, &cur_d); - g_date_time_unref (datetime); - w = ido_calendar_menu_item_get_calendar (self->priv->ido_calendar); - calendar = GTK_CALENDAR(w); - gtk_calendar_get_date (calendar, &cal_y, &cal_m, &cal_d); - if ((cur_y != cal_y) || (cur_m-1 != cal_m)) - gtk_calendar_select_month (calendar, cur_m-1, cur_y); /* (cur_m is 1-based) */ - if (cur_d != cal_d) - gtk_calendar_select_day (calendar, cur_d); + IndicatorDatetime * self; + g_debug ("notify visible signal received"); + + self = INDICATOR_DATETIME (user_data); + g_return_if_fail (self != NULL); + + /* if the calendar widget's been created, set it to today's date */ + if (IDO_IS_CALENDAR_MENU_ITEM(self->priv->ido_calendar)) { + GtkWidget * w; + GtkCalendar * calendar; + gint cur_y, cur_m, cur_d; + guint cal_y, cal_m, cal_d; + GDateTime * datetime = g_date_time_new_now_local (); + + g_date_time_get_ymd (datetime, &cur_y, &cur_m, &cur_d); + w = ido_calendar_menu_item_get_calendar (self->priv->ido_calendar); + calendar = GTK_CALENDAR(w); + g_return_if_fail (calendar != NULL); + + gtk_calendar_get_date (calendar, &cal_y, &cal_m, &cal_d); + if ((cur_y != cal_y) || (cur_m-1 != cal_m)) + gtk_calendar_select_month (calendar, cur_m-1, cur_y); /* (cur_m is 1-based) */ + if (cur_d != cal_d) + gtk_calendar_select_day (calendar, cur_d); + + g_date_time_unref (datetime); + } /* Update in case date was changed outside of indicator-datetime */ update_label(self, NULL); -- cgit v1.2.3