[gnome-calendar] date-selector: update date on GtkEntry::activate signal
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] date-selector: update date on GtkEntry::activate signal
- Date: Tue, 23 Dec 2014 17:06:32 +0000 (UTC)
commit f0e0a6c015d939bbf034d27cc7c7c8298932b8e1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Dec 21 13:50:00 2014 -0200
date-selector: update date on GtkEntry::activate signal
src/gcal-date-selector.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-date-selector.c b/src/gcal-date-selector.c
index 8090e90..b74921b 100644
--- a/src/gcal-date-selector.c
+++ b/src/gcal-date-selector.c
@@ -70,6 +70,9 @@ static void date_entry_focus_out (GtkWidget
GdkEvent *event,
gpointer user_data);
+static void entry_activated (GtkEntry *entry,
+ gpointer user_data);
+
static void text_inserted (GtkEditable *editable,
gchar *new_text,
gint new_text_length,
@@ -150,6 +153,50 @@ date_entry_focus_out (GtkWidget *widget,
}
static void
+entry_activated (GtkEntry *entry,
+ 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,
@@ -372,6 +419,9 @@ gcal_date_selector_constructed (GObject *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_signal_connect (priv->entries[DAY], "activate", G_CALLBACK (entry_activated), object);
+ g_signal_connect (priv->entries[MONTH], "activate", G_CALLBACK (entry_activated), object);
+ g_signal_connect (priv->entries[YEAR], "activate", G_CALLBACK (entry_activated), object);
g_object_unref (builder);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]