[recipes] Add locale setting for temperature conversion
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add locale setting for temperature conversion
- Date: Thu, 11 May 2017 02:54:33 +0000 (UTC)
commit 3bb40fa27b1c1f0425ca1f72c5339cfb887e860c
Author: Paxana Amanda Xander <VeganBikePunk Gmail com>
Date: Wed May 10 19:26:03 2017 -0700
Add locale setting for temperature conversion
In addition to Fahrenheit and Celsius, added locale to the possible
options for preferred temperature. If locale is selected, it looks
for a locale and chooses the preferred temperature unit for that
area (generally Fahrenheit in the US and Celsius elsewhere).
https://bugzilla.gnome.org/show_bug.cgi?id=778695
data/org.gnome.Recipes.gschema.xml | 3 ++-
src/gr-recipe-formatter.c | 24 ++++++++++++++++++++++--
2 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/data/org.gnome.Recipes.gschema.xml b/data/org.gnome.Recipes.gschema.xml
index c35f17c..ad32a99 100644
--- a/data/org.gnome.Recipes.gschema.xml
+++ b/data/org.gnome.Recipes.gschema.xml
@@ -4,6 +4,7 @@
<enum id="org.gnome.recipes.TemperatureUnit">
<value nick="celsius" value="0"/>
<value nick="fahrenheit" value="1"/>
+ <value nick="locale" value="2"/>
</enum>
<schema path="/org/gnome/recipes/" id="org.gnome.Recipes" gettext-domain="gnome-recipes">
@@ -69,7 +70,7 @@
</key>
<key name="temperature-unit" enum="org.gnome.recipes.TemperatureUnit">
- <default>'celsius'</default>
+ <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 celsius.
diff --git a/src/gr-recipe-formatter.c b/src/gr-recipe-formatter.c
index 77de0be..0de372c 100644
--- a/src/gr-recipe-formatter.c
+++ b/src/gr-recipe-formatter.c
@@ -24,6 +24,8 @@
#include "gr-settings.h"
#include <stdlib.h>
#include <glib/gi18n.h>
+#include <locale.h>
+#include <langinfo.h>
#include "gr-recipe-formatter.h"
#include "gr-ingredients-list.h"
@@ -34,14 +36,32 @@
typedef enum {
GR_TEMPERATURE_UNIT_CELSIUS = 0,
- GR_TEMPERATURE_UNIT_FAHRENHEIT = 1
+ GR_TEMPERATURE_UNIT_FAHRENHEIT = 1,
+ GR_TEMPERATURE_UNIT_LOCALE = 2
} GrTemperatureUnit;
static gint
get_temperature_unit (void)
{
+ gint unit;
+ const gchar *fmt;
+
GSettings *settings = gr_settings_get();
- return g_settings_get_enum (settings, "temperature-unit"); }
+ unit = g_settings_get_enum (settings, "temperature-unit");
+ if (unit == GR_TEMPERATURE_UNIT_CELSIUS || unit == GR_TEMPERATURE_UNIT_FAHRENHEIT) {
+ ;}
+ else if (unit == GR_TEMPERATURE_UNIT_LOCALE) {
+
+
+
+ fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
+ if (fmt && *fmt == 2)
+ unit = GR_TEMPERATURE_UNIT_FAHRENHEIT;
+ else
+ unit = GR_TEMPERATURE_UNIT_CELSIUS;
+ }
+ return unit;
+ }
char *
gr_recipe_format (GrRecipe *recipe)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]