From: Andrea Zagli Date: Sun, 8 May 2011 10:11:04 +0000 (+0200) Subject: Adjustments and bugfixes. X-Git-Tag: 0.0.3~2 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=7c033fbf497a3c64b2417923251ab64e2caf32b7;p=libgtkdateentry Adjustments and bugfixes. --- diff --git a/src/gtkdateentry.c b/src/gtkdateentry.c index 6dc7a56..f50c0b9 100644 --- a/src/gtkdateentry.c +++ b/src/gtkdateentry.c @@ -560,11 +560,9 @@ GDate gboolean gtk_date_entry_set_date_strf (GtkDateEntry *date, const gchar *str, - const gchar *format, - const gchar *separator) + const gchar *format) { gchar *fmt; - gchar *sep; GDateDay day; GDateMonth month; GDateYear year; @@ -581,33 +579,25 @@ gtk_date_entry_set_date_strf (GtkDateEntry *date, { fmt = g_strdup (format); } - if (separator == NULL) - { - sep = priv->separator; - } - else - { - sep = (gchar *)separator; - } for (i = 0; i < 3; i++) { switch (fmt[i]) { case 'd': - if (!g_date_valid_day ((GDateDay)atol (g_strndup (str + pos, 2)))) return FALSE; + if (!g_date_valid_day ((GDateDay)strtol (g_strndup (str + pos, 2), NULL, 10))) return FALSE; day = (GDateDay)strtol (g_strndup (str + pos, 2), NULL, 10); pos += 3; break; case 'm': - if (!g_date_valid_month ((GDateMonth)atol (g_strndup (str + pos, 2)))) return FALSE; + if (!g_date_valid_month ((GDateMonth)strtol (g_strndup (str + pos, 2), NULL, 10))) return FALSE; month = (GDateMonth)strtol (g_strndup (str + pos, 2), NULL, 10); pos += 3; break; case 'Y': - if (!g_date_valid_year ((GDateYear)atol (g_strndup (str + pos, 4)))) return FALSE; + if (!g_date_valid_year ((GDateYear)strtol (g_strndup (str + pos, 4), NULL, 10))) return FALSE; year = (GDateYear)strtol (g_strndup (str + pos, 4), NULL, 10); pos += 5; break; @@ -645,35 +635,37 @@ void gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate) { gint i; - gchar *txt = ""; + gchar *txt; if (gdate == NULL || !g_date_valid (gdate)) return; GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + txt = g_strdup (""); for (i = 0; i < 3; i++) { switch (priv->format[i]) { case 'd': - txt = g_strjoin (NULL, txt, g_strdup_printf ("%02d", g_date_get_day (gdate)), NULL); + txt = g_strconcat (txt, g_strdup_printf ("%02d", g_date_get_day (gdate)), NULL); break; case 'm': - txt = g_strjoin (NULL, txt, g_strdup_printf ("%02d", g_date_get_month (gdate)), NULL); + txt = g_strconcat (txt, g_strdup_printf ("%02d", g_date_get_month (gdate)), NULL); break; case 'Y': - txt = g_strjoin (NULL, txt, g_strdup_printf ("%04d", g_date_get_year (gdate)), NULL); + txt = g_strconcat (txt, g_strdup_printf ("%04d", g_date_get_year (gdate)), NULL); break; } if (i < 2) { - txt = g_strjoin (NULL, txt, g_strdup_printf ("%s", priv->separator), NULL); + txt = g_strconcat (txt, priv->separator, NULL); } } + gtk_editable_set_position (GTK_EDITABLE (priv->day), 0); gtk_entry_set_text (GTK_ENTRY (priv->day), txt); } diff --git a/src/gtkdateentry.h b/src/gtkdateentry.h index 81734d2..3832342 100644 --- a/src/gtkdateentry.h +++ b/src/gtkdateentry.h @@ -74,8 +74,7 @@ GDate *gtk_date_entry_get_gdate (GtkDateEntry *date); gboolean gtk_date_entry_set_date_strf (GtkDateEntry *date, const gchar *str, - const gchar *format, - const gchar *separator); + const gchar *format); void gtk_date_entry_set_date_tm (GtkDateEntry *date, const struct tm tmdate); diff --git a/src/gtkformwidgetdateentry.c b/src/gtkformwidgetdateentry.c index 7906486..702c5de 100644 --- a/src/gtkformwidgetdateentry.c +++ b/src/gtkformwidgetdateentry.c @@ -93,7 +93,7 @@ gchar GtkWidget *w = gtk_form_widget_get_widget (fwidget); - return g_strdup (gtk_date_entry_get_strf (GTK_DATE_ENTRY (w), "Ymd", '-')); + return g_strdup (gtk_date_entry_get_strf (GTK_DATE_ENTRY (w), "Ymd", "-")); } /** diff --git a/tests/date_entry.c b/tests/date_entry.c index f841c19..013bfcd 100644 --- a/tests/date_entry.c +++ b/tests/date_entry.c @@ -64,7 +64,7 @@ on_btnSetStrf_clicked (GtkButton *button, { gtk_date_entry_set_date_strf (GTK_DATE_ENTRY (date), (const gchar *)gtk_entry_get_text (GTK_ENTRY (txtSetStrf)), - NULL, 0); + NULL); } static void