From ada5ab5504a60bbac631119db5bb74b71a4827b4 Mon Sep 17 00:00:00 2001 From: jrl Date: Mon, 4 Dec 2006 12:11:26 +0000 Subject: [PATCH] 2006-12-04 James Livingston patch by: Alex Lancaster * rhythmdb/rhythmdb-query.c: (rhythmdb_query_preprocess): * widgets/rb-query-creator-properties.c: (yearCriteriaSetWidgetData), (yearCriteriaGetWidgetData): stop some critical warnings emitted if a YEAR=0 query was done. Fixes #381839 --- ChangeLog | 9 +++++++++ rhythmdb/rhythmdb-query.c | 31 +++++++++++++++++++------------ widgets/rb-query-creator-properties.c | 33 ++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 664f3d0c..d31282a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-12-04 James Livingston + + patch by: Alex Lancaster + + * rhythmdb/rhythmdb-query.c: (rhythmdb_query_preprocess): + * widgets/rb-query-creator-properties.c: + (yearCriteriaSetWidgetData), (yearCriteriaGetWidgetData): stop some + critical warnings emitted if a YEAR=0 query was done. Fixes #381839 + 2006-12-03 James Livingston * lib/rb-file-helpers.c: (_rb_uri_recurse_data_free), diff --git a/rhythmdb/rhythmdb-query.c b/rhythmdb/rhythmdb-query.c index e25d4644..b058cb06 100644 --- a/rhythmdb/rhythmdb-query.c +++ b/rhythmdb/rhythmdb-query.c @@ -634,18 +634,25 @@ rhythmdb_query_preprocess (RhythmDB *db, GPtrArray *query) gulong year; search_date = g_value_get_ulong (data->val); - g_date_set_julian (&date, search_date); - year = g_date_get_year (&date); - g_date_clear (&date, 1); - - /* get Julian dates for beginning and end of year */ - g_date_set_dmy (&date, 1, G_DATE_JANUARY, year); - begin = g_date_get_julian (&date); - g_date_clear (&date, 1); - - /* and the day before the beginning of the next year */ - g_date_set_dmy (&date, 1, G_DATE_JANUARY, year + 1); - end = g_date_get_julian (&date) - 1; + + /* GDate functions don't handle Year="0", so we need to special case this */ + if (search_date != 0) { + g_date_set_julian (&date, search_date); + year = g_date_get_year (&date); + g_date_clear (&date, 1); + + /* get Julian dates for beginning and end of year */ + g_date_set_dmy (&date, 1, G_DATE_JANUARY, year); + begin = g_date_get_julian (&date); + g_date_clear (&date, 1); + + /* and the day before the beginning of the next year */ + g_date_set_dmy (&date, 1, G_DATE_JANUARY, year + 1); + end = g_date_get_julian (&date) - 1; + } else { + begin = 0; + end = 0; + } switch (data->type) { diff --git a/widgets/rb-query-creator-properties.c b/widgets/rb-query-creator-properties.c index 01e3f9f7..5a06c23c 100644 --- a/widgets/rb-query-creator-properties.c +++ b/widgets/rb-query-creator-properties.c @@ -365,14 +365,19 @@ yearCriteriaSetWidgetData (GtkWidget *widget, GValue *val) { GDate *date = NULL; gulong num = g_value_get_ulong (val); + gint display_year; g_assert (num <= G_MAXINT); - /* Create a date structure to get year from */ - date = g_date_new(); - g_date_set_julian (date, num); - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gint)g_date_get_year(date)); - g_date_free(date); + if (num != 0) { + /* Create a date structure to get year from */ + date = g_date_new(); + g_date_set_julian (date, num); + display_year = (gint)g_date_get_year(date); + g_date_free(date); + } else { + display_year = 0; + } + gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), display_year); } static void @@ -380,14 +385,20 @@ yearCriteriaGetWidgetData (GtkWidget *widget, GValue *val) { GDate *date = NULL; gint num = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); + guint32 display_date; g_assert (num >= 0); - /* New date structure, use year set in widget */ - date = g_date_new_dmy (1, G_DATE_JANUARY, num); - g_value_init (val, G_TYPE_ULONG); - g_value_set_ulong (val, (gulong) g_date_get_julian (date) ); - g_date_free(date); + + if (num != 0) { + /* New date structure, use year set in widget */ + date = g_date_new_dmy (1, G_DATE_JANUARY, num); + display_date = g_date_get_julian (date); + g_date_free(date); + } else { + display_date = 0; + } + g_value_set_ulong (val, (gulong)display_date); } /* -- 2.11.4.GIT