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])
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);
}
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;
{
fmt = g_strdup (format);
}
+
if (separator == NULL)
{
sep = priv->separator;
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));
}
/**
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);
/*
- * 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
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", "-", ":"));
}
/**
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
- }
+ }
}
static void
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
- }
+ }
}
GtkWidget *txtSetStrfFormat;
GtkWidget *txtSetStrfSep;
GtkWidget *btnSetStrf;
+GtkWidget *txtGetStrfFormat;
+GtkWidget *txtGetStrf;
+GtkWidget *btnGetStrf;
GtkWidget *txtGetText;
GtkWidget *btnGetText;
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)
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);
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");