From 833b7b77f3a3fee13f71b6becb96c13b18871f06 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 25 Jul 2011 10:42:38 +0200 Subject: [PATCH] Added functions GtkDateEntry::get_gdatetime and GtkDateEntry::set_date_gdatetime. Updated glade catalogue. --- configure.ac | 3 +- glade/gtkdateentry.xml | 1 + src/gtkdateentry.c | 120 +++++++++++++++++++++++++++++++++++++---- src/gtkdateentry.h | 3 ++ 4 files changed, 117 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index b1a387b..28e8eca 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,8 @@ AC_STRUCT_TM GTK_DOC_CHECK(1.0) -PKG_CHECK_MODULES(GTKDATEENTRY, [gtk+-2.0 >= 2.6.8 +PKG_CHECK_MODULES(GTKDATEENTRY, [glib-2.0 >= 2.26 + gtk+-2.0 >= 2.6.8 libgtkmaskedentry >= 0.0.3]) PKG_CHECK_EXISTS(gladeui-1.0 >= 3.2.0, [GLADEUI_FOUND=yes], [GLADEUI_FOUND=no]) PKG_CHECK_EXISTS(libgtkform >= 0.2.0, [LIBGTKFORM_FOUND=yes], [LIBGTKFORM_FOUND=no]) diff --git a/glade/gtkdateentry.xml b/glade/gtkdateentry.xml index 4c3b22a..b45a2e1 100644 --- a/glade/gtkdateentry.xml +++ b/glade/gtkdateentry.xml @@ -5,6 +5,7 @@ + diff --git a/src/gtkdateentry.c b/src/gtkdateentry.c index 5e913f8..ab78b94 100644 --- a/src/gtkdateentry.c +++ b/src/gtkdateentry.c @@ -113,6 +113,9 @@ struct _GtkDateEntryPrivate gchar *time_separator; gchar *format; gboolean editable_with_calendar; + + gboolean time_is_visible; + gboolean time_with_seconds; }; G_DEFINE_TYPE (GtkDateEntry, gtk_date_entry, GTK_TYPE_BIN) @@ -228,6 +231,9 @@ gtk_date_entry_init (GtkDateEntry *date) g_signal_connect (G_OBJECT (priv->calendar), "day-selected-double-click", G_CALLBACK (calendar_on_day_selected_double_click), (gpointer)date); + priv->time_is_visible = TRUE; + priv->time_with_seconds = TRUE; + priv->spnHours = gtk_spin_button_new_with_range (0, 23, 1); gtk_entry_set_width_chars (GTK_ENTRY (priv->spnHours), 2); priv->lblMinutes = gtk_label_new (":"); @@ -353,8 +359,6 @@ gtk_date_entry_set_time_separator (GtkDateEntry *date, const gchar *separator) g_return_val_if_fail (GTK_IS_DATE_ENTRY (date), FALSE); - GDate *gdate = gtk_date_entry_get_gdate (date); - GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); if (separator == NULL) @@ -716,6 +720,53 @@ GDate } } +/** + * gtk_date_entry_get_gdatetime: + * @date: a #GtkDateEntry object. + * + * Returns: the @date's content as a #GDateTime. + */ +GDateTime +*gtk_date_entry_get_gdatetime (GtkDateEntry *date) +{ + GDateTime *ret; + GDate *gdate; + + gint hour; + gint minute; + gdouble seconds; + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + gdate = gtk_date_entry_get_gdate (date); + if (gdate == NULL) + { + return NULL; + } + + hour = 0; + minute = 0; + seconds = 0.0; + if (priv->time_is_visible) + { + hour = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->spnHours)); + minute = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->spnMinutes)); + if (priv->time_with_seconds) + { + seconds = gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->spnSeconds)); + } + } + + ret = g_date_time_new_local (g_date_get_year (gdate), + g_date_get_month (gdate), + g_date_get_day (gdate), + hour, + minute, + seconds); + + return ret; +} + /** * gtk_date_entry_set_date_strf: * @date: a #GtkDateEntry. @@ -849,6 +900,40 @@ gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate) gtk_entry_set_text (GTK_ENTRY (priv->day), txt); } +/** + * gtk_date_entry_set_date_gdatetime: + * @date: a #GtkDateEntry. + * @gdatetime: a #GDateTime from which set @date's content. + * + * Sets @date's content from a @gdatetime. + **/ +void +gtk_date_entry_set_date_gdatetime (GtkDateEntry *date, const GDateTime *gdatetime) +{ + GDate *gdate; + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + gdate = g_date_new_dmy (g_date_time_get_year ((GDateTime *)gdatetime), + g_date_time_get_month ((GDateTime *)gdatetime), + g_date_time_get_day_of_month ((GDateTime *)gdatetime)); + + gtk_date_entry_set_date_gdate (date, gdate); + + if (priv->time_is_visible) + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnHours), + (gdouble)g_date_time_get_hour ((GDateTime *)gdatetime)); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnMinutes), + (gdouble)g_date_time_get_minute ((GDateTime *)gdatetime)); + if (priv->time_with_seconds) + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnHours), + g_date_time_get_seconds ((GDateTime *)gdatetime)); + } + } +} + /** * gtk_date_entry_is_valid: * @date: a #GtkDateEntry. @@ -860,10 +945,12 @@ gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate) gboolean gtk_date_entry_is_valid (GtkDateEntry *date) { - const GDate *gdate = gtk_date_entry_get_gdate (date); - if (gdate != NULL) + GDateTime *gdatetime; + + gdatetime = gtk_date_entry_get_gdatetime (date); + if (gdatetime != NULL) { - return g_date_valid (gdate); + return TRUE; } else { @@ -945,14 +1032,25 @@ gtk_date_entry_set_time_visible (GtkDateEntry *date, { GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); - if (is_visible) + priv->time_is_visible = is_visible; + if (priv->time_is_visible) { gtk_widget_show (priv->spnHours); gtk_widget_show (priv->lblMinutes); gtk_widget_show (priv->spnMinutes); - gtk_widget_show (priv->lblSeconds); - gtk_widget_show (priv->spnSeconds); - } + if (priv->time_with_seconds) + { + gtk_widget_show (priv->lblSeconds); + gtk_widget_show (priv->spnSeconds); + } + else + { + gtk_widget_hide (priv->lblSeconds); + gtk_widget_hide (priv->spnSeconds); + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnSeconds), 0.0); + } + } else { gtk_widget_hide (priv->spnHours); @@ -960,6 +1058,10 @@ gtk_date_entry_set_time_visible (GtkDateEntry *date, gtk_widget_hide (priv->spnMinutes); gtk_widget_hide (priv->lblSeconds); gtk_widget_hide (priv->spnSeconds); + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnHours), 0.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnMinutes), 0.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spnSeconds), 0.0); } } diff --git a/src/gtkdateentry.h b/src/gtkdateentry.h index 511c304..97bab0b 100644 --- a/src/gtkdateentry.h +++ b/src/gtkdateentry.h @@ -74,6 +74,7 @@ const gchar *gtk_date_entry_get_strf (GtkDateEntry *date, struct tm *gtk_date_entry_get_tm (GtkDateEntry *date); GDate *gtk_date_entry_get_gdate (GtkDateEntry *date); +GDateTime *gtk_date_entry_get_gdatetime (GtkDateEntry *date); gboolean gtk_date_entry_set_date_strf (GtkDateEntry *date, const gchar *str, @@ -83,6 +84,8 @@ void gtk_date_entry_set_date_tm (GtkDateEntry *date, const struct tm tmdate); void gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate); +void gtk_date_entry_set_date_gdatetime (GtkDateEntry *date, + const GDateTime *gdatetime); gboolean gtk_date_entry_is_valid (GtkDateEntry *date); -- 2.49.0