2008-11-19 Alejandro Pinheiro <apinheiro@igalia.com>
authorAlejandro Piñeiro <apinheiro@igalia.com>
Thu, 20 Nov 2008 12:16:22 +0000 (12:16 +0000)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Thu, 20 Nov 2008 12:16:22 +0000 (12:16 +0000)
* src/hildon-touch-selector.c: updated the HildonTouchSelector::changed
documentation
* src/hildon-date-selector.c: (_update_day_model): Modified in order to
update the day model only if it is really required, and to avoid the
full-reconstruction aproach. Now it only add or remove the required days.

The purpose of this is avoid superfluous HildonTouchSelector::changed
signals

Fixes: NB#92744 (HildonDateSelector emits multiple "changed" singal
with strange parameters)

ChangeLog
src/hildon-date-selector.c
src/hildon-touch-selector.c

index 305e525..e682e09 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-11-19  Alejandro Pinheiro  <apinheiro@igalia.com>
+
+       * src/hildon-touch-selector.c: updated the HildonTouchSelector::changed
+       documentation
+       * src/hildon-date-selector.c: (_update_day_model): Modified in order to
+       update the day model only if it is really required, and to avoid the
+       full-reconstruction aproach. Now it only add or remove the required days.
+
+       The purpose of this is avoid superfluous HildonTouchSelector::changed
+       signals
+
+       Fixes: NB#92744 (HildonDateSelector emits multiple "changed" singal
+       with strange parameters)
+
 2008-11-19  Claudio Saavedra  <csaavedra@igalia.com>
 
        Patch contributed by Adam Endrodi (adam.endrodi@blumsoft.eu)
index dab0856..b9c5e36 100644 (file)
@@ -87,6 +87,8 @@ struct _HildonDateSelectorPrivate
   gint creation_day;
   gint creation_month;
   gint creation_year;           /* date at creation time */
+
+  gint current_num_days;
 };
 
 static void hildon_date_selector_finalize (GObject * object);
@@ -234,6 +236,7 @@ hildon_date_selector_init (HildonDateSelector * selector)
   selector->priv->year_model = _create_year_model (selector);
   selector->priv->month_model = _create_month_model (selector);
   selector->priv->day_model = _create_day_model (selector);
+  selector->priv->current_num_days = 31;
 
   /* We add the columns, checking the locale order */
   iter = selector->priv->column_order;
@@ -477,6 +480,7 @@ static GtkTreeModel *
 _update_day_model (HildonDateSelector * selector)
 {
   GtkListStore *store_days = NULL;
+  GtkTreePath *path = NULL;
   gint i = 0;
   GtkTreeIter iter;
   static gchar label[255];
@@ -486,32 +490,38 @@ _update_day_model (HildonDateSelector * selector)
   guint current_month = 0;
   guint num_days = 31;
 
-  hildon_date_selector_get_date (selector, NULL, NULL, &current_day);
-
-  hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector),
-                                      selector->priv->month_column, &iter);
-  gtk_tree_model_get (selector->priv->month_model,
-                      &iter, COLUMN_INT, &current_month, -1);
-
-  hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector),
-                                      selector->priv->year_column, &iter);
-  gtk_tree_model_get (selector->priv->year_model,
-                      &iter, COLUMN_INT, &current_year, -1);
+  hildon_date_selector_get_date (selector, &current_year, &current_month,
+                                 &current_day);
 
   num_days = _month_days (current_month, current_year);
-
   store_days = GTK_LIST_STORE (selector->priv->day_model);
-  gtk_list_store_clear (store_days);
 
-  for (i = 1; i <= num_days; i++) {
-    tm.tm_mday = i;
-    strftime (label, 255, _("wdgt_va_day_numeric"), &tm);
+  if (num_days == selector->priv->current_num_days) {
+    return GTK_TREE_MODEL (store_days);
+  }
 
-    gtk_list_store_append (store_days, &iter);
-    gtk_list_store_set (store_days, &iter,
-                        COLUMN_STRING, label, COLUMN_INT, i, -1);
+  if (num_days > selector->priv->current_num_days) {
+    for (i = selector->priv->current_num_days + 1; i <= num_days; i++) {
+      tm.tm_mday = i;
+      strftime (label, 255, _("wdgt_va_day_numeric"), &tm);
+
+      gtk_list_store_append (store_days, &iter);
+      gtk_list_store_set (store_days, &iter,
+                          COLUMN_STRING, label, COLUMN_INT, i, -1);
+    }
+  } else {
+    path = gtk_tree_path_new_from_indices (num_days,
+                                           -1);
+    gtk_tree_model_get_iter (GTK_TREE_MODEL (store_days), &iter, path);
+    do {
+    }while (gtk_list_store_remove (store_days, &iter));
+
+    gtk_tree_path_free (path);
   }
 
+
+  selector->priv->current_num_days = num_days;
+
   /* now we select a day */
   if (current_day >= num_days) {
     current_day = num_days;
@@ -558,6 +568,8 @@ _manage_selector_change_cb (HildonTouchSelector * touch_selector,
   if ((num_column == selector->priv->month_column) ||
       (num_column == selector->priv->year_column)) /* it is required to check that with
                                                     * the years too,remember: leap years
+                                                    * update_day_model will check if
+                                                    * the number of days is different
                                                     */
   {
     _update_day_model (selector);
@@ -595,7 +607,7 @@ hildon_date_selector_new ()
 
 
 /**
- * hildon_date_selector_select_date:
+ * hildon_date_selector_select_current_date:
  * @selector: the #HildonDateSelector
  * @year:  the current year
  * @month: the current month (0-11)
index b755492..24c0667 100644 (file)
@@ -164,6 +164,7 @@ static HildonTouchSelectorColumn *_create_new_column (HildonTouchSelector * sele
 static gboolean
 _hildon_touch_selector_center_on_selected_items (GtkWidget *widget,
                                                  gpointer data);
+
 static void
 _hildon_touch_selector_set_model                (HildonTouchSelector * selector,
                                                  gint num_column,
@@ -221,6 +222,7 @@ hildon_touch_selector_class_init (HildonTouchSelectorClass * class)
   container_class->remove = hildon_touch_selector_remove;
 
   /* HildonTouchSelector */
+  class->changed = NULL;
   class->set_model = _hildon_touch_selector_set_model;
 
   class->has_multiple_selection = _hildon_touch_selector_has_multiple_selection;
@@ -228,13 +230,12 @@ hildon_touch_selector_class_init (HildonTouchSelectorClass * class)
   /* signals */
   /**
    * HildonTouchSelector::changed:
+   * @column: the concrete column being modified
    * @widget: the object which received the signal
    *
-   * The changed signal is emitted when the active
-   * item is changed. This can be due to the user selecting
-   * a different item from the list, or due to a
-   * call to hildon_touch_selector_select_iter() on
-   * one of the columns.
+   * The changed signal is emitted when the active item on any column is changed.
+   * This can be due to the user selecting a different item from the list, or
+   * due to a call to hildon_touch_selector_select_iter() on one of the columns.
    *
    */
   hildon_touch_selector_signals[CHANGED] =