[recipes] Added setting for preferred temperature unit.
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Added setting for preferred temperature unit.
- Date: Tue, 2 May 2017 23:47:28 +0000 (UTC)
commit c39338398e2629effeabdcc05c91e244836ae7ea
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date: Wed Apr 26 13:09:26 2017 +0530
Added setting for preferred temperature unit.
Added a enum setting in data/org.gnome/recipes.gchema.xml for
whether to display temperatures in celcius or fahrenheit, with the
default set to the more internationally recognized celcius.
gr-recipe-formatter.c now finds that setting and converts the temp
to the preferred unit.
https://bugzilla.gnome.org/show_bug.cgi?id=778695
data/org.gnome.Recipes.gschema.xml | 13 +++++++++++++
src/gr-recipe-formatter.c | 28 ++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.Recipes.gschema.xml b/data/org.gnome.Recipes.gschema.xml
index 4e8b660..c35f17c 100644
--- a/data/org.gnome.Recipes.gschema.xml
+++ b/data/org.gnome.Recipes.gschema.xml
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
+ <enum id="org.gnome.recipes.TemperatureUnit">
+ <value nick="celsius" value="0"/>
+ <value nick="fahrenheit" value="1"/>
+ </enum>
+
<schema path="/org/gnome/recipes/" id="org.gnome.Recipes" gettext-domain="gnome-recipes">
<key type="s" name="user">
@@ -63,6 +68,14 @@
</description>
</key>
+ <key name="temperature-unit" enum="org.gnome.recipes.TemperatureUnit">
+ <default>'celsius'</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 celsius.
+ </description>
+ </key>
+
</schema>
</schemalist>
diff --git a/src/gr-recipe-formatter.c b/src/gr-recipe-formatter.c
index 92880d7..32ade0e 100644
--- a/src/gr-recipe-formatter.c
+++ b/src/gr-recipe-formatter.c
@@ -19,7 +19,9 @@
*/
#include "config.h"
-
+#include <stdbool.h>
+#include <gtk/gtk.h>
+#include "gr-settings.h"
#include <stdlib.h>
#include <glib/gi18n.h>
@@ -30,6 +32,17 @@
#include "gr-recipe-store.h"
#include "gr-utils.h"
+typedef enum {
+ GR_TEMPERATURE_UNIT_CELSIUS = 0,
+ GR_TEMPERATURE_UNIT_FAHRENHEIT = 1
+} GrTemperatureUnit;
+
+static gint
+get_temperature_unit (void)
+{
+ GSettings *settings = gr_settings_get();
+ return g_settings_get_enum (settings, "temperature-unit"); }
+
char *
gr_recipe_format (GrRecipe *recipe)
{
@@ -129,6 +142,7 @@ gr_recipe_parse_instructions (const char *instructions,
GPtrArray *step_array;
g_auto(GStrv) steps = NULL;
int i;
+ gint user_unit = get_temperature_unit ();
step_array = g_ptr_array_new_with_free_func (recipe_step_free);
@@ -163,7 +177,17 @@ gr_recipe_parse_instructions (const char *instructions,
unit = "℃";
}
num = atoi (p + strlen ("[temperature:"));
-
+
+ if ((strcmp (unit, "℃") == 0 && (user_unit == GR_TEMPERATURE_UNIT_CELSIUS))
|| (strcmp (unit, "℉") == 0 && (user_unit == GR_TEMPERATURE_UNIT_FAHRENHEIT)))
+ {
+ ;}
+ else if (strcmp (unit, "℃") == 0 && (user_unit ==
GR_TEMPERATURE_UNIT_FAHRENHEIT)) {
+ num = (num * 1.8) + 32;
+ unit = "℉"; }
+ else if (strcmp (unit, "℉") == 0 && (user_unit ==
GR_TEMPERATURE_UNIT_CELSIUS)){
+ num = (num - 32) / 1.8;
+ unit = "℃"; }
+
tmp = g_strdup_printf ("%s%d%s%s", prefix, num, unit, q + 1);
g_free (step);
step = tmp;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]