[recipes/gsettings: 9/11] Clear removed ingredients when appropriate
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/gsettings: 9/11] Clear removed ingredients when appropriate
- Date: Wed, 8 Mar 2017 03:14:16 +0000 (UTC)
commit 16b1123cd02c086283418f6bb943c92a85a9436d
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Mar 7 22:07:28 2017 -0500
Clear removed ingredients when appropriate
When the shopping list is empty, clear out the removed
ingredients list too.
src/gr-recipe-store.c | 18 ++++++++++++++++++
src/gr-recipe-store.h | 1 +
src/gr-shopping-page.c | 22 ++++++----------------
3 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 02db34f..cef8764 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -1410,6 +1410,24 @@ gr_recipe_store_remove_from_shopping (GrRecipeStore *self,
g_signal_emit (self, changed_signal, 0, recipe);
}
+void
+gr_recipe_store_clear_shopping_list (GrRecipeStore *self)
+{
+ const char **empty[1] = { NULL };
+
+ g_variant_dict_unref (self->shopping_list);
+ self->shopping_list = g_variant_dict_new (NULL);
+
+ g_strfreev (self->shopping_removed);
+ self->shopping_removed = g_strdupv ((char **)empty);
+
+ if (self->shopping_change)
+ g_date_time_unref (self->shopping_change);
+ self->shopping_change = g_date_time_new_now_utc ();
+
+ save_shopping (self);
+}
+
gboolean
gr_recipe_store_is_in_shopping (GrRecipeStore *self,
GrRecipe *recipe)
diff --git a/src/gr-recipe-store.h b/src/gr-recipe-store.h
index e7a213f..572e0d4 100644
--- a/src/gr-recipe-store.h
+++ b/src/gr-recipe-store.h
@@ -80,6 +80,7 @@ void gr_recipe_store_add_to_shopping (GrRecipeStore *self,
int serves);
void gr_recipe_store_remove_from_shopping (GrRecipeStore *self,
GrRecipe *recipe);
+void gr_recipe_store_clear_shopping_list (GrRecipeStore *self);
gboolean gr_recipe_store_is_in_shopping (GrRecipeStore *self,
GrRecipe *recipe);
int gr_recipe_store_get_shopping_serves (GrRecipeStore *store,
diff --git a/src/gr-shopping-page.c b/src/gr-shopping-page.c
index 6c411f5..d5bef07 100644
--- a/src/gr-shopping-page.c
+++ b/src/gr-shopping-page.c
@@ -127,6 +127,11 @@ recount_recipes (GrShoppingPage *page)
count);
gtk_label_set_label (GTK_LABEL (page->recipe_count_label), tmp);
if (count == 0) {
+ GrRecipeStore *store;
+
+ store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
+ gr_recipe_store_clear_shopping_list (store);
+
window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
gr_window_go_back (GR_WINDOW (window));
}
@@ -589,31 +594,16 @@ search_finished (GrRecipeSearch *search,
static void
clear_list (GrShoppingPage *page)
{
- GList *children, *l;
GrRecipeStore *store;
GtkWidget *window;
- GList *recipes;
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- children = gtk_container_get_children (GTK_CONTAINER (page->recipe_list));
- recipes = NULL;
- for (l = children; l; l = l->next) {
- GtkWidget *tile = gtk_bin_get_child (GTK_BIN (l->data));
- GrRecipe *recipe = gr_recipe_small_tile_get_recipe (GR_RECIPE_SMALL_TILE (tile));
- recipes = g_list_prepend (recipes, g_object_ref (recipe));
- }
- g_list_free (children);
-
container_remove_all (GTK_CONTAINER (page->ingredients_list));
container_remove_all (GTK_CONTAINER (page->removed_list));
container_remove_all (GTK_CONTAINER (page->recipe_list));
- for (l = recipes; l; l = l->next) {
- GrRecipe *recipe = l->data;
- gr_recipe_store_remove_from_shopping (store, recipe);
- }
- g_list_free_full (recipes, g_object_unref);
+ gr_recipe_store_clear_shopping_list (store);
g_hash_table_remove_all (page->ingredients);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]