]> saetta.ns0.it Git - libgtkdateentry/commitdiff
Added functions GtkDateEntry::get_gdatetime and GtkDateEntry::set_date_gdatetime.
authorAndrea Zagli <azagli@libero.it>
Mon, 25 Jul 2011 08:42:38 +0000 (10:42 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 25 Jul 2011 08:42:38 +0000 (10:42 +0200)
Updated glade catalogue.

configure.ac
glade/gtkdateentry.xml
src/gtkdateentry.c
src/gtkdateentry.h

index b1a387bce6df8dc9bb2b3541d05df83db5c0334f..28e8eca453d328a592259bad76e606317a79ba66 100644 (file)
@@ -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])
index 4c3b22a41eaa31ccd89e5b1a74f8cb7a62e4dfb7..b45a2e1eb74021d633d7fd7c24f3734e8092fb49 100644 (file)
@@ -5,6 +5,7 @@
                <glade-widget-class name="GtkDateEntry" generic-name="gtkdateentry" title="Date Entry">
                        <properties>
                                <property name="Separator" id="separator" />
+                               <property name="Time separator" id="time-separator" />
                                <property name="Format" id="format" />
                                <property name="Editable only from calendar" id="editable-from-calendar" />
                                <property name="Calendar's button visible" id="calendar-button-visible" />
index 5e913f87bcb3fa6c231048c98d85d904d36a339a..ab78b94f7d5dddc3fde5b71f0a89e6a743656f34 100644 (file)
@@ -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);
                }
 }
 
index 511c304671225b94a3ea437e1676d63c6b9df419..97bab0bf578b0ef3cf3cca6d8eeee933e16e944c 100644 (file)
@@ -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);