More refinement.
This commit is contained in:
parent
a1a036eeed
commit
75bee77cb6
|
@ -4,5 +4,6 @@
|
||||||
#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_4
|
#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_4
|
||||||
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4
|
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
extern GtkWidget *newDTP(void);
|
extern GtkWidget *newDTP(void);
|
||||||
|
|
|
@ -37,10 +37,13 @@ struct dateTimePickerWidgetClass {
|
||||||
|
|
||||||
G_DEFINE_TYPE(dateTimePickerWidget, dateTimePickerWidget, GTK_TYPE_TOGGLE_BUTTON)
|
G_DEFINE_TYPE(dateTimePickerWidget, dateTimePickerWidget, GTK_TYPE_TOGGLE_BUTTON)
|
||||||
|
|
||||||
|
// TODO switch to GDateTime?
|
||||||
static void setLabel(dateTimePickerWidget *d)
|
static void setLabel(dateTimePickerWidget *d)
|
||||||
{
|
{
|
||||||
guint year, month, day;
|
guint year, month, day;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
time_t tt;
|
||||||
|
gchar *str;
|
||||||
|
|
||||||
gtk_calendar_get_date(GTK_CALENDAR(d->calendar), &year, &month, &day);
|
gtk_calendar_get_date(GTK_CALENDAR(d->calendar), &year, &month, &day);
|
||||||
tm.tm_hour = (int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(d->hours)) - 1;
|
tm.tm_hour = (int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(d->hours)) - 1;
|
||||||
|
@ -50,9 +53,14 @@ static void setLabel(dateTimePickerWidget *d)
|
||||||
tm.tm_mday = day;
|
tm.tm_mday = day;
|
||||||
tm.tm_year = year - 1900;
|
tm.tm_year = year - 1900;
|
||||||
tm.tm_isdst = -1; // not available
|
tm.tm_isdst = -1; // not available
|
||||||
// TODO strip \n
|
// fill in the missing fields
|
||||||
// TODO find the locale-preferred short date format
|
tt = mktime(&tm);
|
||||||
gtk_button_set_label(GTK_BUTTON(d), asctime(&tm));
|
tm = *localtime(&tt);
|
||||||
|
// and strip the newline
|
||||||
|
str = g_strdup(asctime(&tm));
|
||||||
|
str[strlen(str) - 1] = '\0';
|
||||||
|
gtk_button_set_label(GTK_BUTTON(d), str);
|
||||||
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we don't want ::toggled to be sent again
|
// we don't want ::toggled to be sent again
|
||||||
|
@ -285,7 +293,6 @@ static void dateTimePickerWidget_init(dateTimePickerWidget *d)
|
||||||
d->mouse = NULL;
|
d->mouse = NULL;
|
||||||
|
|
||||||
// TODO set current time to now
|
// TODO set current time to now
|
||||||
setLabel(d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dateTimePickerWidget_dispose(GObject *obj)
|
static void dateTimePickerWidget_dispose(GObject *obj)
|
||||||
|
@ -306,5 +313,9 @@ static void dateTimePickerWidget_class_init(dateTimePickerWidgetClass *class)
|
||||||
|
|
||||||
GtkWidget *newDTP(void)
|
GtkWidget *newDTP(void)
|
||||||
{
|
{
|
||||||
return GTK_WIDGET(g_object_new(dateTimePickerWidgetType, NULL));
|
GtkWidget *w;
|
||||||
|
|
||||||
|
w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL));
|
||||||
|
setLabel(dateTimePickerWidget(w));
|
||||||
|
return w;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue