[recipes] Add api to update chefs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add api to update chefs
- Date: Tue, 31 Jan 2017 12:18:16 +0000 (UTC)
commit 5d1de5eca449f19f1035a362feda3f4e30df50b0
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jan 31 08:00:41 2017 +0100
Add api to update chefs
This is similar to the corresponding API for recipes.
It ensures that we get the proper store signals emitted
when a chef changes.
src/gr-recipe-store.c | 39 +++++++++++++++++++++++++++++++++++++++
src/gr-recipe-store.h | 4 ++++
2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index cb41d42..c7d246e 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -1297,6 +1297,45 @@ gr_recipe_store_add_chef (GrRecipeStore *self,
}
gboolean
+gr_recipe_store_update_chef (GrRecipeStore *self,
+ GrChef *chef,
+ const char *old_id,
+ GError **error)
+{
+ const char *id;
+ GrChef *old;
+
+ g_object_ref (chef);
+
+ id = gr_chef_get_id (chef);
+
+ if (id == NULL || id[0] == '\0') {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("You need to provide an ID for the chef"));
+ return FALSE;
+ }
+ if (strcmp (id, old_id) != 0 &&
+ g_hash_table_contains (self->chefs, id)) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("A chef with this ID already exists"));
+ return FALSE;
+ }
+
+ old = g_hash_table_lookup (self->chefs, old_id);
+ g_assert (chef == old);
+
+ g_hash_table_remove (self->chefs, old_id);
+ g_hash_table_insert (self->chefs, g_strdup (id), g_object_ref (chef));
+
+ g_signal_emit (self, chefs_changed_signal, 0);
+ save_chefs (self);
+
+ g_object_unref (chef);
+
+ return TRUE;
+}
+
+gboolean
gr_recipe_store_update_user (GrRecipeStore *self,
GrChef *chef,
GError **error)
diff --git a/src/gr-recipe-store.h b/src/gr-recipe-store.h
index 3c03efc..f1da9c3 100644
--- a/src/gr-recipe-store.h
+++ b/src/gr-recipe-store.h
@@ -52,6 +52,10 @@ gboolean gr_recipe_store_recipe_is_pick (GrRecipeStore *self,
gboolean gr_recipe_store_add_chef (GrRecipeStore *self,
GrChef *chef,
GError **error);
+gboolean gr_recipe_store_update_chef (GrRecipeStore *self,
+ GrChef *chef,
+ const char *old_id,
+ GError **error);
GrChef *gr_recipe_store_get_chef (GrRecipeStore *self,
const char *id);
char **gr_recipe_store_get_chef_keys (GrRecipeStore *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]