[recipes/wip/yield: 4/8] Add yield information to GrRecipe
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/wip/yield: 4/8] Add yield information to GrRecipe
- Date: Sun, 25 Jun 2017 13:33:21 +0000 (UTC)
commit a2bb2273a787df8a220b6fe0032f078c1a47085d
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 18 18:28:05 2017 -0400
Add yield information to GrRecipe
Add two new properties to GrRecipe, yield-amount (a GrNumber)
and yield-unit (a string).
src/gr-recipe-store.c | 15 +++++++++++++++
src/gr-recipe.c | 25 +++++++++++++++++++++++++
src/gr-recipe.h | 2 ++
3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 13eb3f7..c5f679d 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -238,6 +238,7 @@ load_recipes (GrRecipeStore *self,
g_autofree char *ingredients = NULL;
g_autofree char *instructions = NULL;
g_autofree char *notes = NULL;
+ g_autofree char *yield = NULL;
g_auto(GStrv) paths = NULL;
int serves;
int spiciness;
@@ -368,6 +369,15 @@ load_recipes (GrRecipeStore *self,
}
g_clear_error (&error);
}
+ yield = g_key_file_get_string (keyfile, groups[i], "Yield", &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);
+ continue;
+ }
+ g_clear_error (&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)) {
@@ -459,6 +469,7 @@ load_recipes (GrRecipeStore *self,
"diets", diets,
"images", images,
"default-image", default_image,
+ "yield", yield,
"mtime", mtime,
NULL);
}
@@ -484,6 +495,7 @@ load_recipes (GrRecipeStore *self,
"diets", diets,
"images", images,
"default-image", default_image,
+ "yield", yield,
"ctime", ctime,
"mtime", mtime,
"contributed", contributed,
@@ -530,6 +542,7 @@ save_recipes (GrRecipeStore *self)
const char *ingredients;
const char *instructions;
const char *notes;
+ const char *yield;
GPtrArray *images;
int serves;
int spiciness;
@@ -548,6 +561,7 @@ save_recipes (GrRecipeStore *self)
author = gr_recipe_get_author (recipe);
description = gr_recipe_get_description (recipe);
serves = gr_recipe_get_serves (recipe);
+ yield = gr_recipe_get_yield (recipe);
spiciness = gr_recipe_get_spiciness (recipe);
cuisine = gr_recipe_get_cuisine (recipe);
season = gr_recipe_get_season (recipe);
@@ -589,6 +603,7 @@ save_recipes (GrRecipeStore *self)
g_key_file_set_string (keyfile, key, "Ingredients", ingredients ? ingredients : "");
g_key_file_set_string (keyfile, key, "Instructions", instructions ? instructions : "");
g_key_file_set_integer (keyfile, key, "Serves", serves);
+ g_key_file_set_string (keyfile, key, "Yield", yield ? yield : "");
g_key_file_set_integer (keyfile, key, "Spiciness", spiciness);
g_key_file_set_integer (keyfile, key, "Diets", diets);
g_key_file_set_integer (keyfile, key, "DefaultImage", default_image);
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index 58fc316..c93f7a7 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -79,6 +79,8 @@ struct _GrRecipe
char *translated_description;
char *translated_instructions;
char *translated_notes;
+
+ char *yield;
};
G_DEFINE_TYPE (GrRecipe, gr_recipe, G_TYPE_OBJECT)
@@ -97,6 +99,7 @@ enum {
PROP_PREP_TIME,
PROP_COOK_TIME,
PROP_SERVES,
+ PROP_YIELD,
PROP_INGREDIENTS,
PROP_INSTRUCTIONS,
PROP_SPICINESS,
@@ -141,6 +144,8 @@ gr_recipe_finalize (GObject *object)
g_free (self->translated_instructions);
g_free (self->translated_notes);
+ g_free (self->yield);
+
G_OBJECT_CLASS (gr_recipe_parent_class)->finalize (object);
}
@@ -237,6 +242,10 @@ gr_recipe_get_property (GObject *object,
g_value_set_boolean (value, self->contributed);
break;
+ case PROP_YIELD:
+ g_value_set_string (value, self->yield);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -403,6 +412,11 @@ gr_recipe_set_property (GObject *object,
self->contributed = g_value_get_boolean (value);
break;
+ case PROP_YIELD:
+ g_free (self->yield);
+ self->yield = g_value_dup_string (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -522,6 +536,11 @@ gr_recipe_class_init (GrRecipeClass *klass)
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONTRIBUTED, pspec);
+
+ pspec = g_param_spec_string ("yield", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_YIELD, pspec);
}
static void
@@ -707,6 +726,12 @@ gr_recipe_get_images (GrRecipe *recipe)
return recipe->images;
}
+const char *
+gr_recipe_get_yield (GrRecipe *recipe)
+{
+ return recipe->yield;
+}
+
/* terms are assumed to be g_utf8_casefold'ed where appropriate */
gboolean
gr_recipe_matches (GrRecipe *recipe,
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index 10408e0..4b578dd 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "gr-diet.h"
+#include "gr-number.h"
G_BEGIN_DECLS
@@ -56,6 +57,7 @@ GDateTime *gr_recipe_get_mtime (GrRecipe *recipe);
gboolean gr_recipe_is_readonly (GrRecipe *recipe);
gboolean gr_recipe_is_contributed (GrRecipe *recipe);
GPtrArray *gr_recipe_get_images (GrRecipe *recipe);
+const char *gr_recipe_get_yield (GrRecipe *recipe);
const char *gr_recipe_get_translated_name (GrRecipe *recipe);
const char *gr_recipe_get_translated_description (GrRecipe *recipe);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]