[recipes] Store spiciness as an integer
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Store spiciness as an integer
- Date: Wed, 14 Dec 2016 19:27:34 +0000 (UTC)
commit 8778d08cb146d66744fe7e907b90bd5b9df21cc9
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 14 14:12:48 2016 -0500
Store spiciness as an integer
We are going to need levels here, so best to switch this right away.
src/gr-details-page.c | 4 +++-
src/gr-recipe-store.c | 13 +++++++------
src/gr-recipe.c | 26 +++++++++++++-------------
src/gr-recipe.h | 2 +-
4 files changed, 24 insertions(+), 21 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 638c97c..5e7bb2c 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -635,13 +635,15 @@ populate_ingredients (GrDetailsPage *page,
}
gtk_widget_hide (page->warning_box);
+ gtk_widget_hide (page->garlic_warning);
+ gtk_widget_hide (page->spicy_warning);
if (gr_recipe_contains_garlic (page->recipe)) {
gtk_widget_show (page->warning_box);
gtk_widget_show (page->garlic_warning);
}
- if (gr_recipe_is_spicy (page->recipe)) {
+ if (gr_recipe_get_spiciness (page->recipe) > 50) {
gtk_widget_show (page->warning_box);
gtk_widget_show (page->spicy_warning);
}
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 9207268..14aa563 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -112,7 +112,7 @@ load_recipes (GrRecipeStore *self,
g_autofree int *angles = NULL;
g_autofree gboolean *dark = NULL;
int serves;
- gboolean spicy;
+ int spiciness;
GrDiets diets;
g_autoptr(GArray) images = NULL;
GrRotatedImage ri;
@@ -255,7 +255,7 @@ load_recipes (GrRecipeStore *self,
}
g_clear_error (&error);
}
- spicy = g_key_file_get_boolean (keyfile, groups[i], "Spicy", &error);
+ spiciness = g_key_file_get_integer (keyfile, groups[i], "Spiciness", &error);
if (error) {
if (!g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
g_warning ("Failed to load recipe %s: %s", groups[i], error->message);
@@ -358,7 +358,7 @@ load_recipes (GrRecipeStore *self,
"instructions", instructions,
"notes", notes,
"serves", serves,
- "spicy", spicy,
+ "spiciness", spiciness,
"diets", diets,
"images", images,
NULL);
@@ -377,6 +377,7 @@ load_recipes (GrRecipeStore *self,
"instructions", instructions,
"notes", notes,
"serves", serves,
+ "spiciness", spiciness,
"diets", diets,
"images", images,
"ctime", ctime,
@@ -421,7 +422,7 @@ save_recipes (GrRecipeStore *self)
const char *notes;
g_autoptr(GArray) images = NULL;
int serves;
- gboolean spicy;
+ int spiciness;
GrDiets diets;
g_auto(GStrv) paths = NULL;
g_autofree int *angles = NULL;
@@ -434,7 +435,7 @@ save_recipes (GrRecipeStore *self)
author = gr_recipe_get_author (recipe);
description = gr_recipe_get_description (recipe);
serves = gr_recipe_get_serves (recipe);
- spicy = gr_recipe_is_spicy (recipe);
+ spiciness = gr_recipe_get_spiciness (recipe);
cuisine = gr_recipe_get_cuisine (recipe);
season = gr_recipe_get_season (recipe);
category = gr_recipe_get_category (recipe);
@@ -475,7 +476,7 @@ save_recipes (GrRecipeStore *self)
g_key_file_set_string (keyfile, key, "Instructions", instructions ? instructions : "");
g_key_file_set_string (keyfile, key, "Notes", notes ? notes : "");
g_key_file_set_integer (keyfile, key, "Serves", serves);
- g_key_file_set_boolean (keyfile, key, "Spicy", spicy);
+ g_key_file_set_integer (keyfile, key, "Spiciness", spiciness);
g_key_file_set_integer (keyfile, key, "Diets", diets);
g_key_file_set_string_list (keyfile, key, "Images", (const char * const *)paths,
images->len);
g_key_file_set_integer_list (keyfile, key, "Angles", angles, images->len);
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index dcccb0a..1550405 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -53,7 +53,7 @@ typedef struct
char *cf_ingredients;
gboolean garlic;
- gboolean spicy;
+ int spiciness;
} GrRecipePrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GrRecipe, gr_recipe, G_TYPE_OBJECT)
@@ -72,7 +72,7 @@ enum {
PROP_SERVES,
PROP_INGREDIENTS,
PROP_INSTRUCTIONS,
- PROP_SPICY,
+ PROP_SPICINESS,
PROP_NOTES,
PROP_DIETS,
PROP_CTIME,
@@ -158,8 +158,8 @@ gr_recipe_get_property (GObject *object,
g_value_set_int (value, priv->serves);
break;
- case PROP_SPICY:
- g_value_set_boolean (value, priv->spicy);
+ case PROP_SPICINESS:
+ g_value_set_int (value, priv->spiciness);
break;
case PROP_INGREDIENTS:
@@ -290,8 +290,8 @@ gr_recipe_set_property (GObject *object,
update_mtime (self);
break;
- case PROP_SPICY:
- priv->spicy = g_value_get_boolean (value);
+ case PROP_SPICINESS:
+ priv->spiciness = g_value_get_int (value);
update_mtime (self);
break;
@@ -389,10 +389,10 @@ gr_recipe_class_init (GrRecipeClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_SEASON, pspec);
- pspec = g_param_spec_boolean ("spicy", NULL, NULL,
- FALSE,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_SPICY, pspec);
+ pspec = g_param_spec_int ("spiciness", NULL, NULL,
+ 0, 100, 0,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_SPICINESS, pspec);
pspec = g_param_spec_string ("prep-time", NULL, NULL,
NULL,
@@ -568,12 +568,12 @@ gr_recipe_contains_garlic (GrRecipe *recipe)
return priv->garlic;
}
-gboolean
-gr_recipe_is_spicy (GrRecipe *recipe)
+int
+gr_recipe_get_spiciness (GrRecipe *recipe)
{
GrRecipePrivate *priv = gr_recipe_get_instance_private (recipe);
- return priv->spicy;
+ return priv->spiciness;
}
GDateTime *
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index 2a82fdc..a6df230 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -51,7 +51,7 @@ const char *gr_recipe_get_ingredients (GrRecipe *recipe);
const char *gr_recipe_get_instructions (GrRecipe *recipe);
const char *gr_recipe_get_notes (GrRecipe *recipe);
gboolean gr_recipe_contains_garlic (GrRecipe *recipe);
-gboolean gr_recipe_is_spicy (GrRecipe *recipe);
+int gr_recipe_get_spiciness (GrRecipe *recipe);
GDateTime *gr_recipe_get_ctime (GrRecipe *recipe);
GDateTime *gr_recipe_get_mtime (GrRecipe *recipe);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]