[recipes/unit_convert_test: 6/10] Cleaned up a lot of the unnecessary debug garbage, got numbers to display as fractions



commit a72db7d186b9e17caa3caebb98faa2c56f9650ef
Author: Paxana Amanda Xander <VeganBikePunk Gmail com>
Date:   Tue Jul 4 14:46:19 2017 -0700

    Cleaned up a lot of the unnecessary debug garbage, got numbers to display as fractions

 data/org.gnome.Recipes.gschema.xml |   17 +++------
 src/gr-convert-units.c             |   69 ++++++++++++++++-------------------
 src/gr-ingredients-viewer-row.c    |   38 ++++++++++----------
 src/gr-ingredients-viewer.c        |   15 +++-----
 4 files changed, 61 insertions(+), 78 deletions(-)
---
diff --git a/data/org.gnome.Recipes.gschema.xml b/data/org.gnome.Recipes.gschema.xml
index 872e849..1fe5774 100644
--- a/data/org.gnome.Recipes.gschema.xml
+++ b/data/org.gnome.Recipes.gschema.xml
@@ -7,13 +7,7 @@
     <value nick="locale" value="2"/>
   </enum>
 
-    <enum id="org.gnome.recipes.VolumeUnit">
-    <value nick="metric" value="0"/>
-    <value nick="imperial" value="1"/>
-    <value nick="locale" value="2"/>
-  </enum>
-
-      <enum id="org.gnome.recipes.WeightUnit">
+    <enum id="org.gnome.recipes.MetricOrImperial">
     <value nick="metric" value="0"/>
     <value nick="imperial" value="1"/>
     <value nick="locale" value="2"/>
@@ -90,16 +84,16 @@
       </description>
     </key>
 
-    <key name="volume-unit" enum="org.gnome.recipes.VolumeUnit">
-      <default>'metric'</default>
+    <key name="volume-unit" enum="org.gnome.recipes.MetricOrImperial">
+      <default>'locale'</default>
       <summary>The setting for which unit temperatures should be displayed in. </summary>
       <description>
         The setting for which unit temperatures should be displayed in. Default is 'locale',
         which means to use the LC_MEASUREMENT category of the current locale to decide.
       </description>
     </key>
-    <key name="weight-unit" enum="org.gnome.recipes.WeightUnit">
-      <default>'metric'</default>
+    <key name="weight-unit" enum="org.gnome.recipes.MetricOrImperial">
+      <default>'locale'</default>
       <summary>The setting for which unit temperatures should be displayed in. </summary>
       <description>
         The setting for which unit temperatures should be displayed in. Default is 'locale',
@@ -107,7 +101,6 @@
       </description>
     </key>
 
-
   </schema>
 
 </schemalist>
diff --git a/src/gr-convert-units.c b/src/gr-convert-units.c
index b7b1a6b..b0dedd5 100644
--- a/src/gr-convert-units.c
+++ b/src/gr-convert-units.c
@@ -105,28 +105,20 @@ convert_temp (int *num, int *unit, int user_unit)
     int num1 = *num;
     int unit1 = *unit;
                 
-   /*     if (unit1 == user_unit) {
-            // no conversion needed
-            }
-        else */ if (unit1 == GR_TEMPERATURE_UNIT_CELSIUS &&
+        if (unit1 == GR_TEMPERATURE_UNIT_CELSIUS &&
                 user_unit == GR_TEMPERATURE_UNIT_FAHRENHEIT) {
                     num1 = (num1 * 1.8) + 32;
                     unit1 = user_unit;
-                    //g_message("temp should be: %i", num1);
-                                }
+                }
+
         else if (unit1 == GR_TEMPERATURE_UNIT_FAHRENHEIT &&
                 user_unit == GR_TEMPERATURE_UNIT_CELSIUS) {
                     num1 = (num1 - 32) / 1.8;
                     unit1 = user_unit;
-                    //g_message("temp should be: %i", num1);
-
                 }
                                 
                 *unit = unit1;
                 *num = num1;
-                g_message("temp is: %i", *num);
-
-
 }
 
 void 
@@ -138,6 +130,7 @@ convert_volume (double *amount, char **unit)
         int user_volume_unit = get_volume_unit();
 
                 if (user_volume_unit == GR_VOLUME_UNIT_IMPERIAL) {
+                        
                        if (strcmp(unit1, "ml") == 0)
                                 {
                                         amount1 = (amount1 / 4.92892);
@@ -172,8 +165,8 @@ convert_volume (double *amount, char **unit)
                         }
                         else if (strcmp(unit1, "pt") == 0)
                                 {
-                                        amount1 = (amount1 * 473.176);
-                                        unit1 = "ml";
+                                amount1 = (amount1 * 473.176);
+                                unit1 = "ml";
                                 }
                         else if (strcmp(unit1, "qt") == 0)
                         {
@@ -211,38 +204,39 @@ convert_weight (double *amount, char **unit)
 
         if (user_weight_unit == GR_VOLUME_UNIT_IMPERIAL) {
 
-                       if (strcmp(unit1, "g") == 0)
-                                {
-                                        amount1 = (amount1 * 0.035274);
-                                        unit1 = "oz";
-                                }
+                        if (strcmp(unit1, "g") == 0)
+                        {
+                                amount1 = (amount1 * 0.035274);
+                                unit1 = "oz";
+                        }
                         else if (strcmp(unit1, "kg") == 0)
-                                {
-                                        amount1 = (amount1 * 35.274);
-                                        unit1 = "oz";
-                                }
+                        {
+                                amount1 = (amount1 * 35.274);
+                                unit1 = "oz";
+                        }
                 
         }
-                if (user_weight_unit == GR_VOLUME_UNIT_METRIC) {
+        
+        if (user_weight_unit == GR_VOLUME_UNIT_METRIC) {
 
                        if (strcmp(unit1, "oz") == 0)
-                                {
-                                        amount1 = (amount1 * 28.3495);
-                                        unit1 = "g";
-                                }
+                        {
+                                amount1 = (amount1 * 28.3495);
+                                unit1 = "g";
+                        }
                         else if (strcmp(unit1, "lb") == 0)
-                                {
-                                        amount1 = (amount1 * 453.592);
-                                        unit1 = "g";
-                                }
+                        {
+                                amount1 = (amount1 * 453.592);
+                                unit1 = "g";
+                        }
                         else if (strcmp(unit1, "st") == 0)
                         {
-                                        amount1 = (amount1 * 6350.29);
-                                        unit1 = "g";
+                                amount1 = (amount1 * 6350.29);
+                                unit1 = "g";
                         } 
         }
-                                *amount = amount1;
-                                *unit = unit1;
+                *amount = amount1;
+                *unit = unit1;
 }
 
 void 
@@ -261,6 +255,7 @@ human_readable (double *amount, char **unit)
                 amount1 = (amount1 / 16);
                 unit1 = "lb";
         } 
-                        *amount = amount1;
-                        *unit = unit1;
+
+        *amount = amount1;
+        *unit = unit1;
 }
diff --git a/src/gr-ingredients-viewer-row.c b/src/gr-ingredients-viewer-row.c
index 5151650..821afa0 100644
--- a/src/gr-ingredients-viewer-row.c
+++ b/src/gr-ingredients-viewer-row.c
@@ -50,7 +50,7 @@ struct _GrIngredientsViewerRow
         GtkEntryCompletion *unit_completion;
         GtkCellRenderer *unit_cell;
 
-        double amount;
+        char *amount;
         char *unit;
         char *ingredient;
 
@@ -88,7 +88,7 @@ gr_ingredients_viewer_row_finalize (GObject *object)
 {
         GrIngredientsViewerRow *self = GR_INGREDIENTS_VIEWER_ROW (object);
 
-        //g_free (self->amount);
+        g_free (self->amount);
         g_free (self->unit);
         g_free (self->ingredient);
 
@@ -108,7 +108,7 @@ gr_ingredients_viewer_row_get_property (GObject    *object,
         switch (prop_id)
           {
           case PROP_AMOUNT:
-                g_value_set_double (value, self->amount);
+                g_value_set_string (value, self->amount);
                 break;
 
           case PROP_UNIT:
@@ -140,14 +140,14 @@ static void
 update_unit (GrIngredientsViewerRow *row)
 {
         g_autofree char *tmp = NULL;
-        double amount;
+        const char *amount;
         const char *space;
         const char *unit;
 
-        amount = row->amount ? row->amount : 0;
-        //space = amount[0] ? " " : "";
+        amount = row->amount ? row->amount : "";
+        space = amount[0] ? " " : "";
         unit = row->unit ? row->unit : "";
-        tmp = g_strdup_printf ("%f %s", amount, unit);
+        tmp = g_strdup_printf ("%s%s%s", amount, space, unit);
         if (tmp[0] == '\0' && row->editable) {
                 gtk_style_context_add_class (gtk_widget_get_style_context (row->unit_label), "dim-label");
                 gtk_label_set_label (GTK_LABEL (row->unit_label), _("Amount…"));
@@ -173,10 +173,10 @@ update_ingredient (GrIngredientsViewerRow *row)
 
 static void
 gr_ingredients_viewer_row_set_amount (GrIngredientsViewerRow *row,
-                                      double             amount)
+                                      const char             *amount)
 {
-        //g_free (row->amount);
-        row->amount = amount;
+        g_free (row->amount);
+        row->amount = g_strdup (amount);
         update_unit (row);
 }
 
@@ -245,7 +245,7 @@ gr_ingredients_viewer_row_set_property (GObject      *object,
         switch (prop_id)
           {
           case PROP_AMOUNT:
-                gr_ingredients_viewer_row_set_amount (self, g_value_get_double (value));
+                gr_ingredients_viewer_row_set_amount (self, g_value_get_string (value));
                 break;
 
           case PROP_UNIT:
@@ -306,14 +306,14 @@ static void
 edit_unit (GrIngredientsViewerRow *row)
 {
         g_autofree char *tmp = NULL;
-        double amount;
+        const char *amount;
         const char *space;
         const char *unit;
 
-        amount = row->amount ? row->amount : 0;
-        //space = amount[0] ? " " : "";
+        amount = row->amount ? row->amount : "";
+        space = amount[0] ? " " : "";
         unit = row->unit ? row->unit : "";
-        tmp = g_strdup_printf ("%f%s%s", amount, space, unit);
+        tmp = g_strdup_printf ("%s%s%s", amount, space, unit);
 
         save_ingredient (row);
 
@@ -356,7 +356,7 @@ parse_unit (const char  *text,
                 return FALSE;
         }
 
-        amount = gr_number_format (number);
+        *amount = gr_number_format (number);
         skip_whitespace (&tmp);
         if (tmp)
                 *unit = g_strdup (tmp);
@@ -481,8 +481,8 @@ gr_ingredients_viewer_row_class_init (GrIngredientsViewerRowClass *klass)
         object_class->get_property = gr_ingredients_viewer_row_get_property;
         object_class->set_property = gr_ingredients_viewer_row_set_property;
 
-        pspec = g_param_spec_double ("amount", NULL, NULL,
-                                     0.0, G_MAXDOUBLE, 1.0,
+        pspec = g_param_spec_string ("amount", NULL, NULL,
+                                     NULL,
                                      G_PARAM_READWRITE);
         g_object_class_install_property (object_class, PROP_AMOUNT, pspec);
 
@@ -812,7 +812,7 @@ match_selected (GtkEntryCompletion *completion,
 
         parse_unit (gtk_entry_get_text (GTK_ENTRY (row->unit_entry)), &amount, &unit);
 
-        tmp = g_strdup_printf ("%f %s", amount, abbrev);
+        tmp = g_strdup_printf ("%s %s", amount, abbrev);
 
         gtk_entry_set_text (GTK_ENTRY (row->unit_entry), tmp);
 
diff --git a/src/gr-ingredients-viewer.c b/src/gr-ingredients-viewer.c
index fb25a49..7344c07 100644
--- a/src/gr-ingredients-viewer.c
+++ b/src/gr-ingredients-viewer.c
@@ -325,34 +325,29 @@ gr_ingredients_viewer_set_ingredients (GrIngredientsViewer *viewer,
                 char *unit;
                 GtkWidget *row;
                 const char *measure;
+                const char *endAmount;
 
                 double scale = viewer->scale;
 
                 unit = gr_ingredients_list_get_unit(ingredients, viewer->title, ings[i]);
                 amount = (gr_ingredients_list_get_amount(ingredients, viewer->title, ings[i]) * scale);
                 measure = gr_unit_get_measure(unit);
-                //gr_ingredients_list_scale_unit (&amount, viewer->scale);
-                g_message("%f is the amount in the viewer", amount);
-
                
                if (measure) {
                 if (strcmp(measure, "volume") == 0) {
-                        g_message ("measure is %s", measure);
                         convert_volume(&amount, &unit);
                         }
                 if (strcmp(measure, "weight") == 0) {
-                        g_message ("measure is %s", measure);
                         convert_weight(&amount, &unit);
                         }
                }
-               human_readable(&amount, &unit);
-                g_message("segment is %s", viewer->title);
+                
+                human_readable(&amount, &unit);
 
-                g_message("unit is %s", unit);
-                        //g_message ("measure is %s", measure);
+                endAmount = gr_number_format(amount);                
 
                 row = g_object_new (GR_TYPE_INGREDIENTS_VIEWER_ROW,
-                                    "amount", amount,
+                                    "amount", endAmount,
                                     "unit", unit,
                                     "ingredient", ings[i],
                                     "size-group", viewer->group,


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