[recipes/shopping-list: 14/15] Add api to get unformatted units for ingredients



commit 3eed5de7567fdf246b92dd396810648b7ba2301c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jan 14 12:44:40 2017 -0500

    Add api to get unformatted units for ingredients
    
    This will help with some minimal merging support on the shopping
    list.

 src/gr-ingredients-list.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/gr-ingredients-list.h |    9 ++++++++-
 2 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-ingredients-list.c b/src/gr-ingredients-list.c
index 4b19920..658aae2 100644
--- a/src/gr-ingredients-list.c
+++ b/src/gr-ingredients-list.c
@@ -100,6 +100,9 @@ gr_ingredients_list_add_one (GrIngredientsList  *ingredients,
         return TRUE;
 }
 
+/* this code should go away when we get rid of all the test data which uses
+ * that format
+ */
 static gboolean
 gr_ingredients_list_populate (GrIngredientsList  *ingredients,
                               const char         *text,
@@ -364,3 +367,43 @@ gr_ingredients_list_scale_unit (GrIngredientsList *ingredients,
 
         return NULL;
 }
+
+const char *
+gr_ingredients_list_get_unit (GrIngredientsList *ingredients,
+                              const char        *segment,
+                              const char        *name)
+{
+        GList *l;
+
+        for (l = ingredients->ingredients; l; l = l->next) {
+                Ingredient *ing = (Ingredient *)l->data;
+
+                if (g_strcmp0 (segment, ing->segment) == 0 &&
+                    g_strcmp0 (name, ing->name) == 0) {
+                        return ing->unit;
+                }
+        }
+
+        return NULL;
+}
+
+GrNumber *
+gr_ingredients_list_get_amount (GrIngredientsList *ingredients,
+                                const char        *segment,
+                                const char        *name)
+{
+        GList *l;
+
+        for (l = ingredients->ingredients; l; l = l->next) {
+                Ingredient *ing = (Ingredient *)l->data;
+
+                if (g_strcmp0 (segment, ing->segment) == 0 &&
+                    g_strcmp0 (name, ing->name) == 0) {
+                        return &ing->amount;
+                }
+        }
+
+        return NULL;
+}
+
+
diff --git a/src/gr-ingredients-list.h b/src/gr-ingredients-list.h
index b5c83ab..0df6fe1 100644
--- a/src/gr-ingredients-list.h
+++ b/src/gr-ingredients-list.h
@@ -22,6 +22,8 @@
 
 #include <gtk/gtk.h>
 
+#include "gr-number.h"
+
 G_BEGIN_DECLS
 
 #define GR_TYPE_INGREDIENTS_LIST (gr_ingredients_list_get_type ())
@@ -43,6 +45,11 @@ char              *gr_ingredients_list_scale_unit      (GrIngredientsList  *ingr
 char             **gr_ingredients_list_get_segments    (GrIngredientsList  *ingredients);
 char             **gr_ingredients_list_get_ingredients (GrIngredientsList  *ingredients,
                                                         const char         *segment);
-
+const char        *gr_ingredients_list_get_unit        (GrIngredientsList  *list,
+                                                        const char         *segment,
+                                                        const char         *ingredient);
+GrNumber          *gr_ingredients_list_get_amount      (GrIngredientsList  *list,
+                                                        const char         *segment,
+                                                        const char         *ingredient);
 
 G_END_DECLS


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