[gnome-calendar] date-selector: set date on GtkEntry::focus-out-event
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] date-selector: set date on GtkEntry::focus-out-event
- Date: Tue, 23 Dec 2014 17:06:27 +0000 (UTC)
commit 55b4002e6bda403fd78b07249059f7491e5d5bba
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Dec 21 13:42:06 2014 -0200
date-selector: set date on GtkEntry::focus-out-event
src/gcal-date-selector.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-date-selector.c b/src/gcal-date-selector.c
index 25d8a32..8090e90 100644
--- a/src/gcal-date-selector.c
+++ b/src/gcal-date-selector.c
@@ -21,6 +21,7 @@
#include <locale.h>
#include <langinfo.h>
+#include <stdlib.h>
#include <glib/gi18n.h>
enum
@@ -65,6 +66,10 @@ static guint signals[NUM_SIGNALS] = { 0, };
static void calendar_day_selected (GtkCalendar *calendar,
gpointer user_data);
+static void date_entry_focus_out (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data);
+
static void text_inserted (GtkEditable *editable,
gchar *new_text,
gint new_text_length,
@@ -100,6 +105,51 @@ calendar_day_selected (GtkCalendar *calendar,
}
static void
+date_entry_focus_out (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ GcalDateSelectorPrivate *priv;
+ gint day, month, year;
+
+ priv = gcal_date_selector_get_instance_private (GCAL_DATE_SELECTOR (user_data));
+
+ day = strtol (gtk_entry_get_text (GTK_ENTRY (priv->entries[DAY])), NULL, 0);
+ month = strtol (gtk_entry_get_text (GTK_ENTRY (priv->entries[MONTH])), NULL, 0);
+ year = strtol (gtk_entry_get_text (GTK_ENTRY (priv->entries[YEAR])), NULL, 0);
+
+ /* Fix year if neccessary */
+ if (!priv->have_long_year)
+ {
+ GDateTime *dt;
+ gint suffix;
+
+ dt = g_date_time_new_now_local ();
+ suffix = g_date_time_get_year (dt) % 100;
+
+ /* last century */
+ if (year > suffix)
+ year += g_date_time_get_year (dt) - suffix - 100;
+
+ /* this century */
+ else
+ year += g_date_time_get_year (dt) - suffix;
+
+ g_date_time_unref (dt);
+ }
+
+ /* select the date */
+ g_signal_handlers_block_by_func (priv->calendar,
+ calendar_day_selected,
+ user_data);
+ gcal_date_selector_set_date (GCAL_DATE_SELECTOR (user_data), day, month, year);
+
+ g_signal_handlers_unblock_by_func (priv->calendar,
+ calendar_day_selected,
+ user_data);
+}
+
+static void
text_inserted (GtkEditable *editable,
gchar *new_text,
gint new_text_length,
@@ -319,6 +369,9 @@ gcal_date_selector_constructed (GObject *object)
g_signal_connect (priv->entries[YEAR], "insert-text", G_CALLBACK (text_inserted), object);
g_signal_connect (priv->calendar, "day-selected", G_CALLBACK (calendar_day_selected), object);
+ g_signal_connect (priv->entries[DAY], "focus-out-event", G_CALLBACK (date_entry_focus_out), object);
+ g_signal_connect (priv->entries[MONTH], "focus-out-event", G_CALLBACK (date_entry_focus_out), object);
+ g_signal_connect (priv->entries[YEAR], "focus-out-event", G_CALLBACK (date_entry_focus_out), object);
g_object_unref (builder);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]