]> saetta.ns0.it Git - libgtkdateentry/commitdiff
Adjustments and bugfixes.
authorAndrea Zagli <azagli@libero.it>
Sun, 8 May 2011 10:11:04 +0000 (12:11 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 8 May 2011 10:11:04 +0000 (12:11 +0200)
src/gtkdateentry.c
src/gtkdateentry.h
src/gtkformwidgetdateentry.c
tests/date_entry.c

index 6dc7a561f5d0f36c1e600326ef83ba508abfa921..f50c0b986af5dbb4422b70ad4cdf1909e3094752 100644 (file)
@@ -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);
 }
 
index 81734d2c3ab67e13ce6d748a6b402b75ad467817..38323427fcc96330b298e8c3d1d0575cbb67727c 100644 (file)
@@ -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);
index 79064864fb17458f506fd2f5e2fe693d12c36790..702c5de1d9572570c637f116b33fbbe653161fb8 100644 (file)
@@ -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", "-"));
 }
 
 /**
index f841c198ac15693fe2d0f718bb07c9d480bef18d..013bfcd3a621254fb737f7f6dfac031af93d2af3 100644 (file)
@@ -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