[recipes/wip/clone: 1/2] Add gr_recipe_clone



commit ff3ceafcc42b8efbf048e5bc3839789803e08c48
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue May 23 22:43:08 2017 -0400

    Add gr_recipe_clone
    
    This will be used to make copies of existing recipes.
    Still to be determined: Do we want to keep a reference
    to the original?

 src/gr-recipe.c |   33 +++++++++++++++++++++++++++++++++
 src/gr-recipe.h |    3 +++
 2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index 58fc316..f50220c 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -814,3 +814,36 @@ gr_recipe_matches (GrRecipe    *recipe,
 
         return TRUE;
 }
+
+GrRecipe *
+gr_recipe_clone (GrRecipe   *recipe,
+                 const char *author)
+{
+        g_autofree char *name = NULL;
+        g_autofree char *id = NULL;
+        g_autoptr(GDateTime) now = NULL;
+
+        name = g_strdup_printf (_("%s (copy)"), recipe->name);
+        id = generate_id ("R_", name, "_by_", author, NULL);
+        now = g_date_time_new_now_utc ();
+
+        return g_object_new (GR_TYPE_RECIPE,
+                             "id", id,
+                             "author", author,
+                             "name", name,
+                             "cuisine", recipe->cuisine,
+                             "category", recipe->category,
+                             "season", recipe->season,
+                             "prep-time", recipe->prep_time,
+                             "cook-time", recipe->cook_time,
+                             "serves", recipe->serves,
+                             "spiciness", recipe->spiciness,
+                             "description", recipe->description,
+                             "ingredients", recipe->ingredients,
+                             "instructions", recipe->instructions,
+                             "diets", recipe->diets,
+                             "images", recipe->images,
+                             "mtime", now,
+                             "ctime", now,
+                             NULL);
+}
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index 10408e0..1b7e5e1 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -32,6 +32,9 @@ G_DECLARE_FINAL_TYPE (GrRecipe, gr_recipe, GR, RECIPE, GObject)
 
 GrRecipe       *gr_recipe_new              (void);
 
+GrRecipe       *gr_recipe_clone            (GrRecipe   *recipe,
+                                            const char *author);
+
 const char     *gr_recipe_get_id           (GrRecipe   *recipe);
 const char     *gr_recipe_get_name         (GrRecipe   *recipe);
 const char     *gr_recipe_get_author       (GrRecipe   *recipe);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]