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.
This commit is contained in:
Georges Basile Stavracas Neto
2016-05-21 18:53:37 -03:00
parent 96de78d9af
commit f3da1b2cec
+41 -7
View File
@@ -250,14 +250,48 @@ gcal_subscriber_view_remove (GtkContainer *container,
} }
else else
{ {
guint cell_idx = gcal_subscriber_view_get_child_cell (GCAL_SUBSCRIBER_VIEW (container), GCAL_EVENT_WIDGET (widget)); GHashTableIter iter;
gpointer key, value;
aux = g_hash_table_lookup (priv->single_cell_children, GINT_TO_POINTER (cell_idx)); /*
aux = g_list_remove (g_list_copy (aux), widget); * When an event is changed, we can't rely on it's old date
if (aux == NULL) * to remove the corresponding widget. Because of that, we have
g_hash_table_remove (priv->single_cell_children, GINT_TO_POINTER (cell_idx)); * to iter through all the widgets to see which one matches
else */
g_hash_table_replace (priv->single_cell_children, GINT_TO_POINTER (cell_idx), aux); 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;
}
} }
} }