[recipes] store: Use yield in shopping api



commit 3267d101924290c50b81753c4d1de16d4e258637
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 25 20:13:03 2017 -0400

    store: Use yield in shopping api
    
    change the shopping list api to take the yield as
    a double instead of serves. Update all callers.

 src/gr-recipe-store.c |   18 +++++++++---------
 src/gr-recipe-store.h |    4 ++--
 src/gr-window.c       |    6 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 3f88f05..b48c6ac 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -1812,12 +1812,12 @@ gr_recipe_store_clear_export_list (GrRecipeStore *self)
 void
 gr_recipe_store_add_to_shopping (GrRecipeStore *self,
                                  GrRecipe      *recipe,
-                                 int            serves)
+                                 double         yield)
 {
         const char *id;
 
         id = gr_recipe_get_id (recipe);
-        g_variant_dict_insert (self->shopping_list, id, "u", (guint)serves);
+        g_variant_dict_insert (self->shopping_list, id, "d", yield);
 
         if (self->shopping_change)
                 g_date_time_unref (self->shopping_change);
@@ -1903,18 +1903,18 @@ gr_recipe_store_get_shopping_list (GrRecipeStore *self)
         return list;
 }
 
-int
-gr_recipe_store_get_shopping_serves (GrRecipeStore *self,
-                                     GrRecipe      *recipe)
+double
+gr_recipe_store_get_shopping_yield (GrRecipeStore *self,
+                                    GrRecipe      *recipe)
 {
         const char *id;
-        guint serves;
+        double yield;
 
         id = gr_recipe_get_id (recipe);
-        if (g_variant_dict_lookup (self->shopping_list, id, "u", &serves))
-                return (int)serves;
+        if (g_variant_dict_lookup (self->shopping_list, id, "d", &yield))
+                return yield;
 
-        return 0;
+        return 0.0;
 }
 
 gboolean
diff --git a/src/gr-recipe-store.h b/src/gr-recipe-store.h
index a45414c..f766895 100644
--- a/src/gr-recipe-store.h
+++ b/src/gr-recipe-store.h
@@ -91,14 +91,14 @@ const char    **gr_recipe_store_get_export_list     (GrRecipeStore  *self);
 
 void            gr_recipe_store_add_to_shopping      (GrRecipeStore  *self,
                                                       GrRecipe       *recipe,
-                                                      int             serves);
+                                                      double          yield);
 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);
 GList          *gr_recipe_store_get_shopping_list    (GrRecipeStore  *self);
-int             gr_recipe_store_get_shopping_serves  (GrRecipeStore  *self,
+double          gr_recipe_store_get_shopping_yield   (GrRecipeStore  *self,
                                                       GrRecipe       *recipe);
 gboolean        gr_recipe_store_not_shopping_ingredient    (GrRecipeStore *self,
                                                             const char    *ingredient);
diff --git a/src/gr-window.c b/src/gr-window.c
index d4dfd2d..6038dc6 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -560,7 +560,7 @@ gr_window_new (GrApp *app)
 
 typedef struct {
         GrRecipe *recipe;
-        int serves;
+        double yield;
 } ShoppingListEntry;
 
 static void
@@ -800,7 +800,7 @@ back_to_shopping (GrWindow *window)
 
         for (l = window->shopping_done_list; l; l = l->next) {
                 ShoppingListEntry *entry = l->data;
-                gr_recipe_store_add_to_shopping (store, entry->recipe, entry->serves);
+                gr_recipe_store_add_to_shopping (store, entry->recipe, entry->yield);
         }
         for (i = 0; window->removed_ingredients && window->removed_ingredients[i]; i++) {
                 gr_recipe_store_remove_shopping_ingredient (store, window->removed_ingredients[i]);
@@ -849,7 +849,7 @@ done_shopping (GrWindow *window)
 
                 entry = g_new (ShoppingListEntry, 1);
                 entry->recipe = g_object_ref (recipe);
-                entry->serves = gr_recipe_store_get_shopping_serves (store, recipe);
+                entry->yield = gr_recipe_store_get_shopping_yield (store, recipe);
                 window->shopping_done_list = g_list_append (window->shopping_done_list, entry);
         }
         g_list_free_full (recipes, g_object_unref);


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