[gnome-calendar] Added modified signals to both widgets.



commit ba68b831cc4f03c70f5ee58c94c2da8d4e72b535
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Sun Nov 18 16:39:18 2012 -0500

    Added modified signals to both widgets.
    
    GcalDateEntry and GcalTimeEntry now have a ::modified signal.

 src/gcal-date-entry.c |   42 +++++++++++++++++++++++++++++++++++----
 src/gcal-date-entry.h |    3 ++
 src/gcal-time-entry.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcal-time-entry.h |    3 ++
 4 files changed, 94 insertions(+), 5 deletions(-)
---
diff --git a/src/gcal-date-entry.c b/src/gcal-date-entry.c
index 36d59f6..7749e13 100644
--- a/src/gcal-date-entry.c
+++ b/src/gcal-date-entry.c
@@ -38,6 +38,14 @@ struct _GcalDateEntryPrivate
   gboolean  have_long_year;
 };
 
+enum
+{
+  MODIFIED,
+  NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
 static void     gtk_editable_iface_init                        (GtkEditableInterface *iface);
 
 static void     gcal_date_entry_constructed                    (GObject              *object);
@@ -70,9 +78,18 @@ gcal_date_entry_class_init (GcalDateEntryClass *klass)
   GObjectClass *object_class;
 
   object_class = G_OBJECT_CLASS (klass);
-
   object_class->constructed = gcal_date_entry_constructed;
 
+  signals[MODIFIED] = g_signal_new ("modified",
+                                    GCAL_TYPE_DATE_ENTRY,
+                                    G_SIGNAL_RUN_LAST,
+                                    G_STRUCT_OFFSET (GcalDateEntryClass,
+                                                     modified),
+                                    NULL, NULL,
+                                    g_cclosure_marshal_VOID__VOID,
+                                    G_TYPE_NONE,
+                                    0);
+
   g_type_class_add_private ((gpointer)klass, sizeof(GcalDateEntryPrivate));
 }
 
@@ -255,6 +272,10 @@ gcal_date_entry_insert_text (GtkEditable *editable,
       gchar* unit_string;
       const gchar* text;
 
+      gint new_day;
+      gint new_month;
+      gint new_year;
+
       /* making space for new_string */
       priv->internal_skip = TRUE;
       gtk_editable_delete_text (editable,
@@ -270,18 +291,27 @@ gcal_date_entry_insert_text (GtkEditable *editable,
       /* Updating internal data and validating */
       text = gtk_entry_get_text (GTK_ENTRY (editable));
       unit_string = g_strndup (text + priv->day_pos, 2);
-      priv->day = (guint) g_ascii_strtoull (unit_string, NULL, 10);
+      new_day = (gint) g_ascii_strtoull (unit_string, NULL, 10);
       g_free (unit_string);
 
       unit_string = g_strndup (text + priv->month_pos, 2);
-      priv->month = (guint) g_ascii_strtoull (unit_string, NULL, 10);
+      new_month = (gint) g_ascii_strtoull (unit_string, NULL, 10);
       g_free (unit_string);
 
       unit_string = g_strndup (text + priv->year_pos, (priv->have_long_year ? 4 : 2));
-      priv->year = (guint) g_ascii_strtoull (unit_string, NULL, 10);
+      new_year = (gint) g_ascii_strtoull (unit_string, NULL, 10);
       g_free (unit_string);
 
-      gcal_date_entry_validate_and_insert (GCAL_DATE_ENTRY (editable));
+      if (priv->day != new_day ||
+          priv->month != new_month ||
+          priv->year != new_year)
+        {
+          priv->day = new_day;
+          priv->month = new_month;
+          priv->year = new_year;
+
+          gcal_date_entry_validate_and_insert (GCAL_DATE_ENTRY (editable));
+        }
     }
 }
 
@@ -355,6 +385,8 @@ gcal_date_entry_validate_and_insert (GcalDateEntry *entry)
   gtk_entry_set_text (GTK_ENTRY (entry), tmp);
   priv->internal_skip = FALSE;
 
+  g_signal_emit (entry, signals[MODIFIED], 0);
+
   g_free (tmp);
   g_free (tmp1);
 }
diff --git a/src/gcal-date-entry.h b/src/gcal-date-entry.h
index a59e17b..8013778 100644
--- a/src/gcal-date-entry.h
+++ b/src/gcal-date-entry.h
@@ -48,6 +48,9 @@ struct _GcalDateEntry
 struct _GcalDateEntryClass
 {
   GtkEntryClass parent_class;
+
+  /* signals */
+  void (*modified)  (GcalDateEntry *entry);
 };
 
 GType            gcal_date_entry_get_type        (void);
diff --git a/src/gcal-time-entry.c b/src/gcal-time-entry.c
index de1aed2..2d0e97b 100644
--- a/src/gcal-time-entry.c
+++ b/src/gcal-time-entry.c
@@ -29,6 +29,15 @@ struct _GcalTimeEntryPrivate
   gint    minutes;
 };
 
+enum
+{
+  MODIFIED,
+  NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
+
 static void     gtk_editable_iface_init                        (GtkEditableInterface *iface);
 
 static void     gcal_time_entry_constructed                    (GObject              *object);
@@ -41,6 +50,10 @@ static void     gcal_time_entry_insert_text                    (GtkEditable
                                                                 gint                  new_text_length,
                                                                 gint                 *position);
 
+static void     gcal_time_entry_delete_text                    (GtkEditable          *editable,
+                                                                gint                  start_pos,
+                                                                gint                  end_pos);
+
 G_DEFINE_TYPE_WITH_CODE (GcalTimeEntry,
                          gcal_time_entry,
                          GTK_TYPE_ENTRY,
@@ -59,6 +72,17 @@ gcal_time_entry_class_init (GcalTimeEntryClass *klass)
   object_class = G_OBJECT_CLASS (klass);
   object_class->constructed = gcal_time_entry_constructed;
 
+  signals[MODIFIED] = g_signal_new ("modified",
+                                    GCAL_TYPE_TIME_ENTRY,
+                                    G_SIGNAL_RUN_LAST,
+                                    G_STRUCT_OFFSET (GcalTimeEntryClass,
+                                                     modified),
+                                    NULL, NULL,
+                                    g_cclosure_marshal_VOID__VOID,
+                                    G_TYPE_NONE,
+                                    0);
+
+
   g_type_class_add_private ((gpointer)klass, sizeof(GcalTimeEntryPrivate));
 }
 
@@ -82,6 +106,7 @@ static void
 gtk_editable_iface_init (GtkEditableInterface *iface)
 {
   iface->insert_text = gcal_time_entry_insert_text;
+  iface->delete_text = gcal_time_entry_delete_text;
 }
 
 static void
@@ -311,6 +336,32 @@ gcal_time_entry_insert_text (GtkEditable *editable,
   *position = next_pos;
   g_free (old_text);
   g_free (text_to_insert);
+
+  /* sending modified signal */
+  g_signal_emit (editable, signals[MODIFIED], 0);
+}
+
+static void
+gcal_time_entry_delete_text (GtkEditable *editable,
+                             gint         start_pos,
+                             gint         end_pos)
+{
+  GcalTimeEntryPrivate *priv;
+  GtkEditableInterface *parent_editable_iface;
+
+  priv = GCAL_TIME_ENTRY (editable)->priv;
+  parent_editable_iface = g_type_interface_peek (gcal_time_entry_parent_class,
+                                                 GTK_TYPE_EDITABLE);
+  if (! priv->internal_delete)
+    {
+      /* FIXME: Handle delete_text */
+      /* handle delete */
+    }
+
+  parent_editable_iface->delete_text (editable,
+                                      start_pos,
+                                      end_pos);
+
 }
 
 /* Public API */
diff --git a/src/gcal-time-entry.h b/src/gcal-time-entry.h
index 40c382c..a895a79 100644
--- a/src/gcal-time-entry.h
+++ b/src/gcal-time-entry.h
@@ -46,6 +46,9 @@ struct _GcalTimeEntry
 struct _GcalTimeEntryClass
 {
   GtkEntryClass parent_class;
+
+  /* signals */
+  void (*modified)  (GcalTimeEntry *entry);
 };
 
 GType            gcal_time_entry_get_type        (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]