]> saetta.ns0.it Git - libgtkdateentry/commitdiff
Added function GtkDateEntry:is_time_visible.
authorAndrea Zagli <azagli@libero.it>
Sat, 30 Jul 2011 10:49:43 +0000 (12:49 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 30 Jul 2011 10:49:43 +0000 (12:49 +0200)
Fixed function GtkDateEntry::set_date_strf to manage time part.

src/gtkdateentry.c
src/gtkdateentry.h
tests/date_entry.c

index d963b79ee00f206d80cd01f93852ae2155f4cef5..38300d4bd8ef831f6e0ca8251ee1213f1957b4e8 100644 (file)
@@ -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)
index 23df8c2d4917e696219dbcdecefdabd66cc31253..8bf020dc3ec3cb9d9ccbbbe80c55fd5ccdd82d0b 100644 (file)
@@ -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
index e9a817581d9820823a5d4834332b297d59751f8a..4dbf972d5727e286cd098ed4184638456cf9352f 100644 (file)
@@ -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);