[recipes] store: Add APIs to maintain the export list



commit 13a51f890817f3c6bf479fe68ae54ba5f3b2b0e9
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 11 19:27:57 2017 -0500

    store: Add APIs to maintain the export list
    
    This is very similar to how we're handling the favorites.

 src/gr-recipe-store.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gr-recipe-store.h |   12 ++++++++
 2 files changed, 84 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 1738369..a7109e2 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -137,6 +137,7 @@ struct _GrRecipeStore
         char **todays;
         char **picks;
         char **favorites;
+        char **export_list;
         GVariantDict *shopping_list;
         char **shopping_removed;
         char **featured_chefs;
@@ -662,6 +663,22 @@ save_favorites (GrRecipeStore *self)
 }
 
 static void
+load_export_list (GrRecipeStore *self)
+{
+        g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+
+        self->export_list = g_settings_get_strv (settings, "export-list");
+}
+
+static void
+save_export_list (GrRecipeStore *self)
+{
+        g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+
+        g_settings_set_strv (settings, "export-list", (const char * const *)self->export_list);
+}
+
+static void
 load_shopping (GrRecipeStore *self)
 {
         g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
@@ -917,6 +934,7 @@ gr_recipe_store_init (GrRecipeStore *self)
         /* Now load saved data */
         load_recipes (self, user_dir, FALSE);
         load_favorites (self);
+        load_export_list (self);
         load_shopping (self);
         load_chefs (self, user_dir, FALSE);
 
@@ -1329,7 +1347,7 @@ strv_prepend (char       ***strv_in,
         strv = g_new (char *, length + 2);
         strv[0] = g_strdup (s);
         for (i = 0; i < length; i++)
-                strv[i + 1] = *strv_in[i];
+                strv[i + 1] = (*strv_in)[i];
         strv[length + 1] = NULL;
 
         g_free (*strv_in);
@@ -1431,6 +1449,59 @@ gr_recipe_store_last_favorite_change (GrRecipeStore *self)
 }
 
 void
+gr_recipe_store_add_export (GrRecipeStore *self,
+                            GrRecipe      *recipe)
+{
+        const char *id;
+
+        id = gr_recipe_get_id (recipe);
+
+        if (g_strv_contains ((const char * const*)self->export_list, id))
+                return;
+
+        strv_prepend (&self->export_list, id);
+
+        save_export_list (self);
+}
+
+void
+gr_recipe_store_remove_export (GrRecipeStore *self,
+                               GrRecipe      *recipe)
+{
+        int i, j;
+        const char *id;
+
+        id = gr_recipe_get_id (recipe);
+
+        for (i = 0; self->export_list[i]; i++) {
+                if (strcmp (self->export_list[i], id) == 0) {
+                        g_free (self->export_list[i]);
+                        for (j = i; self->export_list[j]; j++) {
+                                self->export_list[j] = self->export_list[j + 1];
+                        }
+                        break;
+                }
+        }
+
+        save_export_list (self);
+}
+
+const char **
+gr_recipe_store_get_export_list (GrRecipeStore *self)
+{
+        return (const char **)self->export_list;
+}
+
+void
+gr_recipe_store_clear_export_list (GrRecipeStore *self)
+{
+        g_strfreev (self->export_list);
+        self->export_list = g_new0 (char *, 1);
+
+        save_export_list (self);
+}
+
+void
 gr_recipe_store_add_to_shopping (GrRecipeStore *self,
                                  GrRecipe      *recipe,
                                  int            serves)
diff --git a/src/gr-recipe-store.h b/src/gr-recipe-store.h
index 003630c..9f9cea7 100644
--- a/src/gr-recipe-store.h
+++ b/src/gr-recipe-store.h
@@ -51,6 +51,7 @@ gboolean        gr_recipe_store_recipe_is_todays    (GrRecipeStore  *self,
                                                      GrRecipe       *recipe);
 gboolean        gr_recipe_store_recipe_is_pick      (GrRecipeStore  *self,
                                                      GrRecipe       *recipe);
+
 gboolean        gr_recipe_store_add_chef            (GrRecipeStore  *self,
                                                      GrChef         *chef,
                                                      GError        **error);
@@ -64,12 +65,15 @@ char          **gr_recipe_store_get_chef_keys       (GrRecipeStore  *self,
                                                      guint          *length);
 gboolean        gr_recipe_store_chef_is_featured    (GrRecipeStore  *self,
                                                      GrChef         *chef);
+
 const char     *gr_recipe_store_get_user_key        (GrRecipeStore  *self);
 gboolean        gr_recipe_store_update_user         (GrRecipeStore  *self,
                                                      GrChef         *chef,
                                                      GError        **error);
+
 char          **gr_recipe_store_get_all_ingredients (GrRecipeStore  *self,
                                                      guint          *length);
+
 void            gr_recipe_store_add_favorite        (GrRecipeStore  *self,
                                                      GrRecipe       *recipe);
 void            gr_recipe_store_remove_favorite     (GrRecipeStore  *self,
@@ -77,6 +81,14 @@ void            gr_recipe_store_remove_favorite     (GrRecipeStore  *self,
 gboolean        gr_recipe_store_is_favorite         (GrRecipeStore  *self,
                                                      GrRecipe       *recipe);
 GDateTime      *gr_recipe_store_last_favorite_change (GrRecipeStore *self);
+
+void            gr_recipe_store_add_export          (GrRecipeStore  *self,
+                                                     GrRecipe       *recipe);
+void            gr_recipe_store_remove_export       (GrRecipeStore  *self,
+                                                     GrRecipe       *recipe);
+void            gr_recipe_store_clear_export_list   (GrRecipeStore  *self);
+const char    **gr_recipe_store_get_export_list     (GrRecipeStore  *self);
+
 void            gr_recipe_store_add_to_shopping      (GrRecipeStore  *self,
                                                       GrRecipe       *recipe,
                                                       int             serves);


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