[gnome-calendar/gnome-3-20] subscriber-view: iter the single day table



commit e2fd6e4242ecef381c64798d2d4295755214c1c3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat May 21 17:34:26 2016 -0300

    subscriber-view: iter the single day table
    
    When we modify an event, the start date may change
    and there is no way to retrieve it back. Since we're
    relying on the start date to get the cell number and,
    remove the widget, it leads to a crash because the
    widget is not removed.
    
    Fix that by brute-forcely search the widget in the
    correct table.

 src/gcal-subscriber-view.c |   50 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/src/gcal-subscriber-view.c b/src/gcal-subscriber-view.c
index 63109d2..e020add 100644
--- a/src/gcal-subscriber-view.c
+++ b/src/gcal-subscriber-view.c
@@ -250,14 +250,48 @@ gcal_subscriber_view_remove (GtkContainer *container,
             }
           else
             {
-              guint cell_idx = gcal_subscriber_view_get_child_cell (GCAL_SUBSCRIBER_VIEW (container), 
GCAL_EVENT_WIDGET (widget));
-
-              aux = g_hash_table_lookup (priv->single_cell_children, GINT_TO_POINTER (cell_idx));
-              aux = g_list_remove (g_list_copy (aux), widget);
-              if (aux == NULL)
-                g_hash_table_remove (priv->single_cell_children, GINT_TO_POINTER (cell_idx));
-              else
-                g_hash_table_replace (priv->single_cell_children, GINT_TO_POINTER (cell_idx), aux);
+              GHashTableIter iter;
+              gpointer key, value;
+
+              /*
+               * When an event is changed, we can't rely on it's old date
+               * to remove the corresponding widget. Because of that, we have
+               * to iter through all the widgets to see which one matches
+               */
+              g_hash_table_iter_init (&iter, priv->single_cell_children);
+
+              while (g_hash_table_iter_next (&iter, &key, &value))
+                {
+                  GList *aux;
+                  gboolean should_break;
+
+                  should_break = FALSE;
+
+                  for (aux = value; aux != NULL; aux = aux->next)
+                    {
+                      if (aux->data == widget)
+                        {
+                          aux = g_list_remove (g_list_copy (value), widget);
+
+                          /*
+                           * If we removed the event and there's no event left for
+                           * the day, remove the key from the table. If there are
+                           * events for that day, replace the list.
+                           */
+                          if (aux == NULL)
+                            g_hash_table_remove (priv->single_cell_children, key);
+                          else
+                            g_hash_table_replace (priv->single_cell_children, key, aux);
+
+                          should_break = TRUE;
+
+                          break;
+                        }
+                    }
+
+                  if (should_break)
+                    break;
+                }
             }
         }
 


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