[recipes/unit_convert_test: 3/10] got convert-temp working, need to work on scaling the display



commit 598e8c42ffee02a8236d7dbd9eb90a64fadd3902
Author: Paxana Amanda Xander <VeganBikePunk Gmail com>
Date:   Mon Jun 26 15:02:00 2017 -0700

    got convert-temp working, need to work on scaling the display

 src/gr-convert-units.c      |  116 +++++++++++++++++++++++++++++++++++++++++++
 src/gr-convert-units.h      |   48 ++++++++++++++++++
 src/gr-ingredients-viewer.c |    4 ++
 src/gr-recipe-formatter.c   |   46 ++---------------
 src/meson.build             |    1 +
 5 files changed, 174 insertions(+), 41 deletions(-)
---
diff --git a/src/gr-convert-units.c b/src/gr-convert-units.c
new file mode 100644
index 0000000..da8e712
--- /dev/null
+++ b/src/gr-convert-units.c
@@ -0,0 +1,116 @@
+/* gr-convert-units.c:
+ *
+ * Copyright (C) 2016 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <string.h>
+#include "gr-settings.h"
+#include <stdlib.h>
+#include <glib/gi18n.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <gtk/gtk.h>
+#include "gr-unit.h"
+#include "gr-convert-units.h"
+
+int
+get_temperature_unit (void)
+{
+        int unit;
+        GSettings *settings = gr_settings_get ();
+
+        unit = g_settings_get_enum (settings, "temperature-unit");
+
+        if (unit == GR_TEMPERATURE_UNIT_LOCALE) {
+#ifdef LC_MEASUREMENT
+                const char *fmt;
+
+                fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
+                if (fmt && *fmt == 2)
+                        unit = GR_TEMPERATURE_UNIT_FAHRENHEIT;
+                else
+#endif
+                        unit = GR_TEMPERATURE_UNIT_CELSIUS;
+        }
+
+        return unit;
+}
+
+static int
+get_volume_unit (void)
+{
+        int unit;
+        GSettings *settings = gr_settings_get ();
+
+        unit = g_settings_get_enum (settings, "volume-unit");
+
+        if (unit == GR_VOLUME_UNIT_LOCALE) {
+#ifdef LC_MEASUREMENT
+                const char *fmt;
+
+                fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
+                if (fmt && *fmt == 2)
+                        unit = GR_VOLUME_UNIT_IMPERIAL;
+                else
+#endif
+                        unit = GR_VOLUME_UNIT_METRIC;
+        }
+
+        return unit;
+}
+
+
+void
+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 &&
+                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 
+convert_volume ()
+{
+
+}
+*/
\ No newline at end of file
diff --git a/src/gr-convert-units.h b/src/gr-convert-units.h
new file mode 100644
index 0000000..d6d61d5
--- /dev/null
+++ b/src/gr-convert-units.h
@@ -0,0 +1,48 @@
+/* gr-chef.h:
+ *
+ * Copyright (C) 2016 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <libgd/gd.h>
+#include "gr-recipe.h"
+
+G_BEGIN_DECLS
+
+typedef enum {
+        GR_TEMPERATURE_UNIT_CELSIUS    = 0,
+        GR_TEMPERATURE_UNIT_FAHRENHEIT = 1,
+        GR_TEMPERATURE_UNIT_LOCALE     = 2
+} GrTemperatureUnit;
+
+typedef enum {
+        GR_VOLUME_UNIT_METRIC    = 0,
+        GR_VOLUME_UNIT_IMPERIAL = 1,
+        GR_VOLUME_UNIT_LOCALE     = 2
+} GrVolumeUnit;
+
+int             get_temperature_unit        (void);
+void            convert_temp                (int *num, int *unit, int user_unit);
+
+
+
+G_END_DECLS
\ No newline at end of file
diff --git a/src/gr-ingredients-viewer.c b/src/gr-ingredients-viewer.c
index 1c36df6..fdb4a3c 100644
--- a/src/gr-ingredients-viewer.c
+++ b/src/gr-ingredients-viewer.c
@@ -323,10 +323,14 @@ gr_ingredients_viewer_set_ingredients (GrIngredientsViewer *viewer,
                 const char *unit;
                 GtkWidget *row;
 
+<<<<<<< 5304691ced802de6f16064e89f48e6c38b5de0df
                 s = gr_ingredients_list_scale_unit (ingredients, viewer->title, ings[i], viewer->scale);
                 //strv = g_strsplit (s, " ", 2);
                 //amount = strv[0];
                 unit = strv[1] ? strv[1] : "";
+=======
+                s = gr_ingredients_list_scale_unit (ingredients, viewer->title, ings[i], viewer->scale_num, 
viewer->scale_denom);
+>>>>>>> got convert-temp working, need to work on scaling the display
                 unit = gr_ingredients_list_get_unit(ingredients, viewer->title, ings[i]);
                 amount = gr_ingredients_list_get_amount(ingredients, viewer->title, ings[i]);
                 
diff --git a/src/gr-recipe-formatter.c b/src/gr-recipe-formatter.c
index 0e7ceaf..6265ae4 100644
--- a/src/gr-recipe-formatter.c
+++ b/src/gr-recipe-formatter.c
@@ -33,35 +33,7 @@
 #include "gr-chef.h"
 #include "gr-recipe-store.h"
 #include "gr-utils.h"
-
-typedef enum {
-        GR_TEMPERATURE_UNIT_CELSIUS    = 0,
-        GR_TEMPERATURE_UNIT_FAHRENHEIT = 1,
-        GR_TEMPERATURE_UNIT_LOCALE     = 2
-} GrTemperatureUnit;
-
-static int
-get_temperature_unit (void)
-{
-        int unit;
-        GSettings *settings = gr_settings_get ();
-
-        unit = g_settings_get_enum (settings, "temperature-unit");
-
-        if (unit == GR_TEMPERATURE_UNIT_LOCALE) {
-#ifdef LC_MEASUREMENT
-                const char *fmt;
-
-                fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
-                if (fmt && *fmt == 2)
-                        unit = GR_TEMPERATURE_UNIT_FAHRENHEIT;
-                else
-#endif
-                        unit = GR_TEMPERATURE_UNIT_CELSIUS;
-        }
-
-        return unit;
-}
+#include "gr-convert-units.h"
 
 char *
 gr_recipe_format (GrRecipe *recipe)
@@ -204,19 +176,11 @@ gr_recipe_parse_instructions (const char *instructions,
                                         unit = GR_TEMPERATURE_UNIT_CELSIUS;
                                 }
                                 num = atoi (p + strlen ("[temperature:"));
+                                g_message("num before convert: %i \n unit before convert: %s", num, unit);
 
-                                if (unit == user_unit) {
-                                        // no conversion needed
-                                }
-                                else if (unit == GR_TEMPERATURE_UNIT_CELSIUS &&
-                                         user_unit == GR_TEMPERATURE_UNIT_FAHRENHEIT) {
-                                        num = (num * 1.8) + 32;
-                                }
-                                else if (unit == GR_TEMPERATURE_UNIT_FAHRENHEIT &&
-                                         user_unit == GR_TEMPERATURE_UNIT_CELSIUS) {
-                                        num = (num - 32) / 1.8;
-                                }
-
+                                convert_temp(&num, &unit, user_unit);
+                                g_message("num after convert: %i \n unit after convert: %i", num, unit);
+                                
                                 tmp = g_strdup_printf ("%s%d%s%s", prefix, num, unit_str[user_unit], q + 1);
                                 g_free (step);
                                 step = tmp;
diff --git a/src/meson.build b/src/meson.build
index dedea30..f8d3bcd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -48,6 +48,7 @@ src += ['main.c',
        'gr-chef.c',
        'gr-chef-dialog.c',
        'gr-chef-tile.c',
+       'gr-convert-units.c',
        'gr-cooking-page.c',
        'gr-cooking-view.c',
        'gr-cuisine.c',


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