From: Andrea Zagli Date: Sat, 30 Jul 2011 10:49:43 +0000 (+0200) Subject: Added function GtkDateEntry:is_time_visible. X-Git-Tag: v.gtk2~7 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=65f8566f62da399d7e3b411ca7332a25aaacc20c;p=libgtkdateentry Added function GtkDateEntry:is_time_visible. Fixed function GtkDateEntry::set_date_strf to manage time part. --- diff --git a/src/gtkdateentry.c b/src/gtkdateentry.c index d963b79..38300d4 100644 --- a/src/gtkdateentry.c +++ b/src/gtkdateentry.c @@ -861,11 +861,19 @@ gtk_date_entry_set_date_strf (GtkDateEntry *date, const gchar *format) { gchar *fmt; - GDateDay day; - GDateMonth month; - GDateYear year; + + gint year; + gint month; + gint day; + gint hours; + gint minutes; + gdouble seconds; + gint i; - gint pos = 0; + gint l; + gint pos; + + GDateTime *gdatetime; g_return_val_if_fail (GTK_IS_DATE_ENTRY (date), FALSE); @@ -880,31 +888,64 @@ gtk_date_entry_set_date_strf (GtkDateEntry *date, fmt = g_strdup (format); } - for (i = 0; i < 3; i++) + year = 1; + month = 1; + day = 1; + hours = 0; + minutes = 0; + seconds = 0.0; + + pos = 0; + l = strlen (fmt); + for (i = 0; i < l; i++) { switch (fmt[i]) { case 'd': - 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); + day = strtol (g_strndup (str + pos, 2), NULL, 10); + if (day == 0) day = 1; pos += 3; break; case 'm': - 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); + month = strtol (g_strndup (str + pos, 2), NULL, 10); + if (month == 0) month = 1; pos += 3; break; case 'Y': - 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); + year = strtol (g_strndup (str + pos, 4), NULL, 10); + if (year == 0) year = 1; pos += 5; break; + + case 'H': + hours = strtol (g_strndup (str + pos, 2), NULL, 10); + pos += 3; + break; + + case 'M': + minutes = strtol (g_strndup (str + pos, 2), NULL, 10); + pos += 3; + break; + + case 'S': + seconds = g_strtod (g_strndup (str + pos, 2), NULL); + pos += 3; + break; + } + + if (pos >= strlen (str)) + { + i = l; + continue; } } - gtk_date_entry_set_date_gdate (date, g_date_new_dmy (day, month, year)); + gdatetime = g_date_time_new_local (year, month, day, hours, minutes, seconds); + gtk_date_entry_set_date_gdatetime (date, gdatetime); + g_date_time_unref (gdatetime); + return TRUE; } @@ -1171,6 +1212,22 @@ gtk_date_entry_set_time_visible (GtkDateEntry *date, } } +/** + * gtk_date_entry_is_time_visible: + * @date: a #GtkDateEntry. + * + * Returns: #TRUE or #FALSE if time part is visible or not. + */ +gboolean +gtk_date_entry_is_time_visible (GtkDateEntry *date) +{ + g_return_if_fail (GTK_IS_DATE_ENTRY (date)); + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + return priv->time_is_visible; +} + /* PRIVATE */ static void gtk_date_entry_change_mask (GtkDateEntry *date) diff --git a/src/gtkdateentry.h b/src/gtkdateentry.h index 23df8c2..8bf020d 100644 --- a/src/gtkdateentry.h +++ b/src/gtkdateentry.h @@ -100,6 +100,7 @@ void gtk_date_entry_set_calendar_button_visible (GtkDateEntry *date, void gtk_date_entry_set_time_visible (GtkDateEntry *date, gboolean is_visible); +gboolean gtk_date_entry_is_time_visible (GtkDateEntry *date); G_END_DECLS diff --git a/tests/date_entry.c b/tests/date_entry.c index e9a8175..4dbf972 100644 --- a/tests/date_entry.c +++ b/tests/date_entry.c @@ -36,7 +36,6 @@ GtkWidget *format; GtkWidget *btnFormat; GtkWidget *txtSetStrf; GtkWidget *txtSetStrfFormat; -GtkWidget *txtSetStrfSep; GtkWidget *btnSetStrf; GtkWidget *txtGetStrfFormat; GtkWidget *txtGetStrf; @@ -84,7 +83,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); + (const gchar *)gtk_entry_get_text (GTK_ENTRY (txtSetStrfFormat))); } static void @@ -266,6 +265,11 @@ main (int argc, char **argv) gtk_table_attach (GTK_TABLE (table), txtSetStrf, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); gtk_widget_show (txtSetStrf); + x++; + txtSetStrfFormat = gtk_entry_new (); + gtk_table_attach (GTK_TABLE (table), txtSetStrfFormat, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (txtSetStrfFormat); + x++; btnSetStrf = gtk_button_new_with_label ("set_date_strf"); gtk_table_attach (GTK_TABLE (table), btnSetStrf, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);