[recipes] plurals api causing crash, working on converting between metric and imperial



commit f15e3de318c0d147f27156a923944e8940b572f6
Author: Paxana Amanda Xander <VeganBikePunk Gmail com>
Date:   Sat Jun 10 17:47:46 2017 -0700

    plurals api causing crash, working on converting between metric and imperial

 src/gr-ingredients-viewer-row.c |   14 ++++++++++++++
 src/gr-unit.c                   |   22 +++++++++++++++++++---
 src/gr-unit.h                   |    1 +
 3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/src/gr-ingredients-viewer-row.c b/src/gr-ingredients-viewer-row.c
index 854a163..f142427 100644
--- a/src/gr-ingredients-viewer-row.c
+++ b/src/gr-ingredients-viewer-row.c
@@ -173,6 +173,7 @@ static void
 gr_ingredients_viewer_row_set_amount (GrIngredientsViewerRow *row,
                                       const char             *amount)
 {
+        //amount here is number before unit in ingredient box
         g_free (row->amount);
         row->amount = g_strdup (amount);
         update_unit (row);
@@ -183,7 +184,9 @@ gr_ingredients_viewer_row_set_unit (GrIngredientsViewerRow *row,
                                     const char             *unit)
 {
         g_free (row->unit);
+        //unit here is the unit
         row->unit = g_strdup (unit);
+        g_message(unit);
         update_unit (row);
 }
 
@@ -707,10 +710,18 @@ get_units_model (GrIngredientsViewerRow *row)
                 for (i = 0; names[i]; i++) {
                         const char *abbrev;
                         const char *name;
+                        const char *plural;
+
                         g_autofree char *tmp = NULL;
 
                         abbrev = gr_unit_get_abbreviation (names[i]);
                         name = gr_unit_get_display_name (names[i]);
+                        plural = gr_unit_get_plural (names[i]);
+
+                        if (plural != NULL) {
+                                g_message(plural);
+                        } 
+
                         if (strcmp (abbrev, name) == 0)
                                 tmp = g_strdup (name);
                         else
@@ -719,6 +730,7 @@ get_units_model (GrIngredientsViewerRow *row)
                                                            0, abbrev,
                                                            1, name,
                                                            2, tmp,
+                                                           3, plural,
                                                            -1);
                 }
         }
@@ -760,6 +772,7 @@ match_func (GtkEntryCompletion *completion,
         g_autofree char *name = NULL;
         g_autofree char *amount = NULL;
         g_autofree char *unit = NULL;
+        g_autofree char *plural = NULL;
 
         model = gtk_entry_completion_get_model (completion);
         gtk_tree_model_get (model, iter, 0, &abbrev, 1, &name, -1);
@@ -786,6 +799,7 @@ match_selected (GtkEntryCompletion *completion,
         g_autofree char *amount = NULL;
         g_autofree char *unit = NULL;
         g_autofree char *tmp = NULL;
+        g_autofree char *plural = NULL;
 
         gtk_tree_model_get (model, iter, 0, &abbrev, -1);
 
diff --git a/src/gr-unit.c b/src/gr-unit.c
index 7adf0a0..1d1cc4c 100644
--- a/src/gr-unit.c
+++ b/src/gr-unit.c
@@ -26,7 +26,7 @@
 
 static const char * const unit_names[] = {
         "g", "kg", "lb", "oz", "l", "dl", "ml", "fl oz", "pt", "qt", "gal", "cup",
-        "tbsp", "tsp", "box", "pkg", "glass",
+        "tbsp", "tsp", "box", "pkg", "glass", "st", "pinch",  
         NULL
 };
 
@@ -34,17 +34,19 @@ typedef struct {
         const char *unit;
         const char *abbreviation;
         const char *display_name;
+        const char *plural;
 } GrUnit;
 
 static GrUnit units[] = {
-        { "g",     NC_("unit abbreviation", "g"),     NC_("unit name", "gram") },
-        { "kg",    NC_("unit abbreviation", "kg"),    NC_("unit name", "kilogram") },
+        { "g",     NC_("unit abbreviation", "g"),     NC_("unit name", "gram"), NC_("unit plural", "grams") 
},
+        { "kg",    NC_("unit abbreviation", "kg"),    NC_("unit name", "kilogram"), NC_("unit plural", 
"kilograms") },
         { "lb",    NC_("unit abbreviation", "lb"),    NC_("unit name", "pound") },
         { "oz",    NC_("unit abbreviation", "oz"),    NC_("unit name", "ounce") },
         { "l",     NC_("unit abbreviation", "l"),     NC_("unit name", "liter") },
         { "dl",    NC_("unit abbreviation", "dl"),    NC_("unit name", "deciliter") },
         { "ml",    NC_("unit abbreviation", "ml"),    NC_("unit name", "milliliter") },
         { "fl oz", NC_("unit abbreviation", "fl oz"), NC_("unit name", "fluid ounce") },
+        { "fl. oz.", NC_("unit abbreviation", "fl oz"), NC_("unit name", "fluid ounce") },        
         { "pt",    NC_("unit abbreviation", "pt"),    NC_("unit name", "pint") },
         { "qt",    NC_("unit abbreviation", "qt"),    NC_("unit name", "quart") },
         { "gal",   NC_("unit abbreviation", "gal"),   NC_("unit name", "gallon") },
@@ -57,6 +59,10 @@ static GrUnit units[] = {
         { "mm",    NC_("unit abbreviation", "mm"),    NC_("unit name", "millimeter") },
         { "cm",    NC_("unit abbreviation", "cm"),    NC_("unit name", "centimeter") },
         { "m",     NC_("unit abbreviation", "m"),     NC_("unit name", "meter") },
+        { "st",    NC_("unit abbreviation", "st"),     NC_("unit name", "stone") },
+        { "pinch", NC_("unit abbreviation", "pinch"),     NC_("unit name", "pinch") },
+        { "bunch", NC_("unit abbreviation", "bunch"), NC_("unit name", "bunch"), NC_("unit plural", 
"bunches") },
+
 };
 
 const char **
@@ -86,6 +92,16 @@ gr_unit_get_display_name (const char *name)
 }
 
 const char *
+gr_unit_get_plural (const char *name)
+{
+        GrUnit *unit = find_unit (name);
+        if (unit)
+                return g_dpgettext2 (NULL, "unit plural", unit->plural);
+        return NULL; 
+
+}
+
+const char *
 gr_unit_get_abbreviation (const char *name)
 {
         GrUnit *unit = find_unit (name);
diff --git a/src/gr-unit.h b/src/gr-unit.h
index bc143eb..46d8278 100644
--- a/src/gr-unit.h
+++ b/src/gr-unit.h
@@ -28,5 +28,6 @@ const char *gr_unit_parse (char   **string,
 const char **gr_unit_get_names (void);
 const char  *gr_unit_get_abbreviation (const char *name);
 const char  *gr_unit_get_display_name (const char *name);
+const char  *gr_unit_get_plural (const char *name);
 
 G_END_DECLS


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