[recipes] Add content warning APIs to GrRecipe
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add content warning APIs to GrRecipe
- Date: Wed, 14 Dec 2016 16:04:46 +0000 (UTC)
commit da1fe390da0cde7079f2284abb7f9ee148bce2e4
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 14 11:02:20 2016 -0500
Add content warning APIs to GrRecipe
We can now ask if a recipe contains garlic, or is spicy.
For the garlic, we can just derive this information from
the ingredients list. For spicy, it is not so easy, so
we store it separately.
src/gr-recipe.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/gr-recipe.h | 2 ++
2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index 808230b..dcccb0a 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -51,6 +51,9 @@ typedef struct
char *cf_name;
char *cf_description;
char *cf_ingredients;
+
+ gboolean garlic;
+ gboolean spicy;
} GrRecipePrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GrRecipe, gr_recipe, G_TYPE_OBJECT)
@@ -69,6 +72,7 @@ enum {
PROP_SERVES,
PROP_INGREDIENTS,
PROP_INSTRUCTIONS,
+ PROP_SPICY,
PROP_NOTES,
PROP_DIETS,
PROP_CTIME,
@@ -154,6 +158,10 @@ gr_recipe_get_property (GObject *object,
g_value_set_int (value, priv->serves);
break;
+ case PROP_SPICY:
+ g_value_set_boolean (value, priv->spicy);
+ break;
+
case PROP_INGREDIENTS:
g_value_set_string (value, priv->ingredients);
break;
@@ -282,12 +290,24 @@ gr_recipe_set_property (GObject *object,
update_mtime (self);
break;
+ case PROP_SPICY:
+ priv->spicy = g_value_get_boolean (value);
+ update_mtime (self);
+ break;
+
case PROP_INGREDIENTS:
+ {
+ g_autofree char *cf_garlic = NULL;
+
g_free (priv->ingredients);
g_free (priv->cf_ingredients);
priv->ingredients = g_value_dup_string (value);
priv->cf_ingredients = g_utf8_casefold (priv->ingredients, -1);
+
+ cf_garlic = g_utf8_casefold ("Garlic", -1);
+ priv->garlic = (strstr (priv->cf_ingredients, cf_garlic) != NULL);
update_mtime (self);
+ }
break;
case PROP_INSTRUCTIONS:
@@ -369,6 +389,11 @@ 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_string ("prep-time", NULL, NULL,
NULL,
G_PARAM_READWRITE);
@@ -535,6 +560,22 @@ gr_recipe_get_notes (GrRecipe *recipe)
return priv->notes;
}
+gboolean
+gr_recipe_contains_garlic (GrRecipe *recipe)
+{
+ GrRecipePrivate *priv = gr_recipe_get_instance_private (recipe);
+
+ return priv->garlic;
+}
+
+gboolean
+gr_recipe_is_spicy (GrRecipe *recipe)
+{
+ GrRecipePrivate *priv = gr_recipe_get_instance_private (recipe);
+
+ return priv->spicy;
+}
+
GDateTime *
gr_recipe_get_ctime (GrRecipe *recipe)
{
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index 3ea509e..2a82fdc 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -50,6 +50,8 @@ GrDiets gr_recipe_get_diets (GrRecipe *recipe);
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);
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]