[recipes/wip/yield: 7/8] wip: add a yield and yield-unit
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/wip/yield: 7/8] wip: add a yield and yield-unit
- Date: Sun, 25 Jun 2017 13:33:36 +0000 (UTC)
commit 6e5fe984ddf8e37ae5c4d01b82993cd69c8ac755
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 24 23:53:05 2017 -0400
wip: add a yield and yield-unit
src/gr-details-page.c | 2 +-
src/gr-edit-page.c | 6 +++---
src/gr-recipe-small-tile.c | 2 +-
src/gr-recipe-store.c | 6 +++---
src/gr-recipe.c | 38 ++++++++++++++++++++++++++++++--------
src/gr-recipe.h | 3 ++-
6 files changed, 40 insertions(+), 17 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 6fdab53..b4354d8 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -187,7 +187,7 @@ update_yield_label (GrDetailsPage *page,
{
const char *yield;
- yield = gr_recipe_get_yield (page->recipe);
+ yield = gr_recipe_get_yield_unit (page->recipe);
if (yield && yield[0])
gtk_label_set_label (GTK_LABEL (page->yield_label), yield);
else
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 14f27d5..e29f0f6 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -1466,7 +1466,7 @@ gr_edit_page_edit (GrEditPage *page,
author = gr_recipe_get_author (recipe);
index = gr_recipe_get_default_image (recipe);
images = gr_recipe_get_images (recipe);
- yield = gr_recipe_get_yield (recipe);
+ yield = gr_recipe_get_yield_unit (recipe);
g_free (page->author);
page->author = g_strdup (author);
@@ -1591,7 +1591,7 @@ gr_edit_page_save (GrEditPage *page)
"prep-time", prep_time,
"cook-time", cook_time,
"serves", serves,
- "yield", yield && yield[0] ? yield : NULL,
+ "yield-unit", yield && yield[0] ? yield : NULL,
"spiciness", spiciness,
"description", description,
"ingredients", ingredients,
@@ -1625,7 +1625,7 @@ gr_edit_page_save (GrEditPage *page)
"prep-time", prep_time,
"cook-time", cook_time,
"serves", serves,
- "yield", yield && yield[0] ? yield : NULL,
+ "yield-unit", yield && yield[0] ? yield : NULL,
"spiciness", spiciness,
"description", description,
"ingredients", ingredients,
diff --git a/src/gr-recipe-small-tile.c b/src/gr-recipe-small-tile.c
index 9d76600..bc605ec 100644
--- a/src/gr-recipe-small-tile.c
+++ b/src/gr-recipe-small-tile.c
@@ -101,7 +101,7 @@ recipe_small_tile_set_recipe (GrRecipeSmallTile *tile,
name = gr_recipe_get_translated_name (recipe);
author = gr_recipe_get_author (recipe);
- yield = gr_recipe_get_yield (recipe);
+ yield = gr_recipe_get_yield_unit (recipe);
chef = gr_recipe_store_get_chef (store, author);
gtk_label_set_label (GTK_LABEL (tile->label), name);
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index c5f679d..ab3b62d 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -469,7 +469,7 @@ load_recipes (GrRecipeStore *self,
"diets", diets,
"images", images,
"default-image", default_image,
- "yield", yield,
+ "yield-unit", yield,
"mtime", mtime,
NULL);
}
@@ -495,7 +495,7 @@ load_recipes (GrRecipeStore *self,
"diets", diets,
"images", images,
"default-image", default_image,
- "yield", yield,
+ "yield-unit", yield,
"ctime", ctime,
"mtime", mtime,
"contributed", contributed,
@@ -561,7 +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);
+ yield = gr_recipe_get_yield_unit (recipe);
spiciness = gr_recipe_get_spiciness (recipe);
cuisine = gr_recipe_get_cuisine (recipe);
season = gr_recipe_get_season (recipe);
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index c93f7a7..1050ba2 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -80,7 +80,8 @@ struct _GrRecipe
char *translated_instructions;
char *translated_notes;
- char *yield;
+ double yield;
+ char *yield_unit;
};
G_DEFINE_TYPE (GrRecipe, gr_recipe, G_TYPE_OBJECT)
@@ -100,6 +101,7 @@ enum {
PROP_COOK_TIME,
PROP_SERVES,
PROP_YIELD,
+ PROP_YIELD_UNIT,
PROP_INGREDIENTS,
PROP_INSTRUCTIONS,
PROP_SPICINESS,
@@ -144,7 +146,7 @@ gr_recipe_finalize (GObject *object)
g_free (self->translated_instructions);
g_free (self->translated_notes);
- g_free (self->yield);
+ g_free (self->yield_unit);
G_OBJECT_CLASS (gr_recipe_parent_class)->finalize (object);
}
@@ -243,7 +245,11 @@ gr_recipe_get_property (GObject *object,
break;
case PROP_YIELD:
- g_value_set_string (value, self->yield);
+ g_value_set_double (value, self->yield);
+ break;
+
+ case PROP_YIELD_UNIT:
+ g_value_set_string (value, self->yield_unit);
break;
default:
@@ -413,8 +419,12 @@ gr_recipe_set_property (GObject *object,
break;
case PROP_YIELD:
- g_free (self->yield);
- self->yield = g_value_dup_string (value);
+ self->yield = g_value_get_double (value);
+ break;
+
+ case PROP_YIELD_UNIT:
+ g_free (self->yield_unit);
+ self->yield_unit = g_value_dup_string (value);
break;
default:
@@ -537,10 +547,15 @@ gr_recipe_class_init (GrRecipeClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CONTRIBUTED, pspec);
- pspec = g_param_spec_string ("yield", NULL, NULL,
- NULL,
+ pspec = g_param_spec_double ("yield", NULL, NULL,
+ 0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_YIELD, pspec);
+
+ pspec = g_param_spec_string ("yield-unit", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_YIELD_UNIT, pspec);
}
static void
@@ -549,6 +564,7 @@ gr_recipe_init (GrRecipe *self)
self->ctime = g_date_time_new_now_utc ();
self->mtime = g_date_time_new_now_utc ();
self->images = gr_image_array_new ();
+ self->yield = 0.0;
}
GrRecipe *
@@ -726,12 +742,18 @@ gr_recipe_get_images (GrRecipe *recipe)
return recipe->images;
}
-const char *
+double
gr_recipe_get_yield (GrRecipe *recipe)
{
return recipe->yield;
}
+const char *
+gr_recipe_get_yield_unit (GrRecipe *recipe)
+{
+ return recipe->yield_unit;
+}
+
/* 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 4b578dd..03ac876 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -57,7 +57,8 @@ 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_yield_unit (GrRecipe *recipe);
+double 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]