]> saetta.ns0.it Git - libgtkdateentry/commitdiff
Bugfixes and adjustments.
authorAndrea Zagli <azagli@libero.it>
Tue, 31 May 2011 18:19:01 +0000 (20:19 +0200)
committerAndrea Zagli <azagli@libero.it>
Tue, 31 May 2011 18:19:01 +0000 (20:19 +0200)
configure.ac
src/gtkdateentry.c
src/gtkdateentry.h
src/gtkformwidgetdateentry.c
tests/date_entry.c

index 6a27c746f7ed43c9bf9fa6822ab0ae8f03a3f91d..5d507b5731c9993f7124d44965f227ebbfa8ef23 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ(2.59)
-AC_INIT([GtkDateEntry], [0.0.3], [azagli@libero.it])
+AC_INIT([GtkDateEntry], [0.0.4], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/gtkdateentry.c])
 AC_CONFIG_HEADER([config.h])
 
index 7f445c9b1091697574c1002944c2429187909aab..b347904855497ad14ff48defe4402724986e7169 100644 (file)
@@ -461,9 +461,11 @@ const gchar
        if (gtk_widget_get_visible (priv->spnHours))
                {
                        ret = g_strconcat (ret,
-                                          g_strdup_printf (" %02d:%02d:%02d",
+                                          g_strdup_printf (" %02d%s%02d%s%02d",
                                                            gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->spnHours)),
+                                                           priv->time_separator,
                                                            gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->spnMinutes)),
+                                                           priv->time_separator,
                                                            gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->spnSeconds))),
                                           NULL);
                }
@@ -483,19 +485,33 @@ const gchar
 const gchar
 *gtk_date_entry_get_strf (GtkDateEntry *date,
                           const gchar *format,
-                          const gchar *separator)
+                          const gchar *separator,
+                          const gchar *time_separator)
 {
-       gchar *fmt, *sep, *ret = "";
-       gint i;
-       GDate *gdate = (GDate *)gtk_date_entry_get_gdate (date);
+       gchar *fmt;
+       gchar *sep;
+       gchar *tsep;
+
+       gchar *str_date;
+       gchar *str_time;
+
+       guint l;
+       guint i;
+
+       g_return_val_if_fail (GTK_IS_DATE_ENTRY (date), "");
+
+       struct tm *tm_date = gtk_date_entry_get_tm (date);
 
        GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date);
 
-       if (gdate == NULL)
+       if (tm_date == NULL)
                {
                        return "";
                }
 
+       str_date = g_strdup ("");
+       str_time = g_strdup ("");
+
        if (format == NULL)
                {
                        fmt = priv->format;
@@ -504,6 +520,7 @@ const gchar
                {
                        fmt = g_strdup (format);
                }
+
        if (separator == NULL)
                {
                        sep = priv->separator;
@@ -513,30 +530,71 @@ const gchar
                        sep = (gchar *)separator;
                }
 
-       for (i = 0; i < 3; i++)
+       if (time_separator == NULL)
+               {
+                       tsep = priv->time_separator;
+               }
+       else
+               {
+                       tsep = (gchar *)time_separator;
+               }
+
+       l = strlen (fmt);
+       for (i = 0; i < l; i++)
                {
                        switch (fmt[i])
                                {
                                        case 'd':
-                                               ret = g_strjoin (NULL, ret, g_strdup_printf ("%02d", (int)g_date_get_day (gdate)), NULL);
+                                               if (strlen (str_date) > 0)
+                                                       {
+                                                               str_date = g_strconcat (str_date, sep, NULL);
+                                                       }
+                                               str_date = g_strconcat (str_date, g_strdup_printf ("%02d", tm_date->tm_mday, NULL));
                                                break;
 
                                        case 'm':
-                                               ret = g_strjoin (NULL, ret, g_strdup_printf ("%02d", (int)g_date_get_month (gdate)), NULL);
+                                               if (strlen (str_date) > 0)
+                                                       {
+                                                               str_date = g_strconcat (str_date, sep, NULL);
+                                                       }
+                                               str_date = g_strconcat (str_date, g_strdup_printf ("%02d", tm_date->tm_mon + 1, NULL));
                                                break;
 
                                        case 'Y':
-                                               ret = g_strjoin (NULL, ret, g_strdup_printf ("%04d", (int)g_date_get_year (gdate)), NULL);
+                                               if (strlen (str_date) > 0)
+                                                       {
+                                                               str_date = g_strconcat (str_date, sep, NULL);
+                                                       }
+                                               str_date = g_strconcat (str_date, g_strdup_printf ("%04d", tm_date->tm_year + 1900, NULL));
                                                break;
-                               }
 
-                       if (i < 2)
-                               {
-                                       ret = g_strjoin (NULL, ret, g_strdup_printf ("%s", sep), NULL);
+                                       case 'H':
+                                               if (strlen (str_time) > 0)
+                                                       {
+                                                               str_time = g_strconcat (str_time, tsep, NULL);
+                                                       }
+                                               str_time = g_strconcat (str_time, g_strdup_printf ("%02d", tm_date->tm_hour, NULL));
+                                               break;
+
+                                       case 'M':
+                                               if (strlen (str_time) > 0)
+                                                       {
+                                                               str_time = g_strconcat (str_time, tsep, NULL);
+                                                       }
+                                               str_time = g_strconcat (str_time, g_strdup_printf ("%02d", tm_date->tm_min, NULL));
+                                               break;
+
+                                       case 'S':
+                                               if (strlen (str_time) > 0)
+                                                       {
+                                                               str_time = g_strconcat (str_time, tsep, NULL);
+                                                       }
+                                               str_time = g_strconcat (str_time, g_strdup_printf ("%02d", tm_date->tm_sec, NULL));
+                                               break;
                                }
                }
 
-       return (const gchar *)ret;
+       return (const gchar *)g_strstrip (g_strdup_printf ("%s %s", str_date, str_time));
 }
 
 /**
index db3910a4a2475ec1477bc78f6f4566311ea39338..511c304671225b94a3ea437e1676d63c6b9df419 100644 (file)
@@ -69,7 +69,8 @@ gboolean gtk_date_entry_set_format (GtkDateEntry *date,
 const gchar *gtk_date_entry_get_text (GtkDateEntry *date);
 const gchar *gtk_date_entry_get_strf (GtkDateEntry *date,
                                       const gchar *format,
-                                      const gchar *separator);
+                                      const gchar *separator,
+                                      const gchar *time_separator);
 
 struct tm *gtk_date_entry_get_tm (GtkDateEntry *date);
 GDate *gtk_date_entry_get_gdate (GtkDateEntry *date);
index 702c5de1d9572570c637f116b33fbbe653161fb8..17914566235a789404dc5c569c60736e15526bdf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -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 HMS", "-", ":"));
 }
 
 /**
@@ -153,7 +153,7 @@ gtk_form_widget_date_entry_set_property (GObject *object,
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
-         }
+               }
 }
 
 static void
@@ -171,5 +171,5 @@ gtk_form_widget_date_entry_get_property (GObject *object,
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
-         }
+               }
 }
index b4b6aa6a8b7d5af5f550674dc3625087a13282cc..bbea89d5c455234649230b93da02453216d36330 100644 (file)
@@ -38,6 +38,9 @@ GtkWidget *txtSetStrf;
 GtkWidget *txtSetStrfFormat;
 GtkWidget *txtSetStrfSep;
 GtkWidget *btnSetStrf;
+GtkWidget *txtGetStrfFormat;
+GtkWidget *txtGetStrf;
+GtkWidget *btnGetStrf;
 GtkWidget *txtGetText;
 GtkWidget *btnGetText;
 
@@ -82,6 +85,17 @@ on_btnSetStrf_clicked (GtkButton *button,
                                      NULL);
 }
 
+static void
+on_btnGetStrf_clicked (GtkButton *button,
+                       gpointer user_data)
+{
+       gtk_entry_set_text (GTK_ENTRY (txtGetStrf),
+                           gtk_date_entry_get_strf (GTK_DATE_ENTRY (date),
+                                     (const gchar *)gtk_entry_get_text (GTK_ENTRY (txtGetStrfFormat)),
+                                     NULL,
+                                     NULL));
+}
+
 static void
 on_btnGetText_clicked (GtkButton *button,
                        gpointer user_data)
@@ -152,7 +166,7 @@ main (int argc, char **argv)
        gtk_window_set_title (GTK_WINDOW (window), "GtkDateEntry Test");
 
        g_signal_connect (G_OBJECT (window), "destroy",
-                       G_CALLBACK (gtk_main_quit), NULL);
+                         G_CALLBACK (gtk_main_quit), NULL);
 
        table = gtk_table_new (5, 3, FALSE);
        gtk_container_add (GTK_CONTAINER (window), table);
@@ -251,6 +265,30 @@ main (int argc, char **argv)
        g_signal_connect (G_OBJECT (btnSetStrf), "clicked",
                          G_CALLBACK (on_btnSetStrf_clicked), NULL);
 
+       x = 0;
+       y++;
+       label = gtk_label_new ("Get strf");
+       gtk_table_attach (GTK_TABLE (table), label, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+       gtk_widget_show (label);
+
+       x++;
+       txtGetStrfFormat = gtk_entry_new ();
+       gtk_table_attach (GTK_TABLE (table), txtGetStrfFormat, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+       gtk_widget_show (txtGetStrfFormat);
+
+       x++;
+       txtGetStrf = gtk_entry_new ();
+       gtk_table_attach (GTK_TABLE (table), txtGetStrf, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+       gtk_widget_show (txtGetStrf);
+
+       x++;
+       btnGetStrf = gtk_button_new_with_label ("get_strf");
+       gtk_table_attach (GTK_TABLE (table), btnGetStrf, x, x + 1, y, y + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+       gtk_widget_show (btnGetStrf);
+
+       g_signal_connect (G_OBJECT (btnGetStrf), "clicked",
+                         G_CALLBACK (on_btnGetStrf_clicked), NULL);
+
        x = 0;
        y++;
        label = gtk_label_new ("Text");