[recipes] Add a readonly flag to recipes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add a readonly flag to recipes
- Date: Tue, 20 Dec 2016 10:02:23 +0000 (UTC)
commit 082b4b105bfd6d095de1770d9768f5b6cc185256
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 19 20:16:06 2016 -0500
Add a readonly flag to recipes
This will be used to mark preinstalled recipes as readonly.
src/gr-recipe.c | 28 ++++++++++++++++++++++++++++
src/gr-recipe.h | 1 +
2 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index 33dcd65..bc3fab1 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -57,6 +57,8 @@ struct _GrRecipe
gboolean garlic;
int spiciness;
+
+ gboolean readonly;
};
G_DEFINE_TYPE (GrRecipe, gr_recipe, G_TYPE_OBJECT)
@@ -81,6 +83,7 @@ enum {
PROP_DIETS,
PROP_CTIME,
PROP_MTIME,
+ PROP_READONLY,
N_PROPS
};
@@ -193,6 +196,10 @@ gr_recipe_get_property (GObject *object,
g_value_set_boxed (value, self->mtime);
break;
+ case PROP_READONLY:
+ g_value_set_boolean (value, self->readonly);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -230,6 +237,11 @@ gr_recipe_set_property (GObject *object,
{
GrRecipe *self = GR_RECIPE (object);
+ if (self->readonly && prop_id != PROP_NOTES) {
+ g_error ("trying to modify a readonly recipe");
+ return;
+ }
+
switch (prop_id) {
case PROP_ID:
g_free (self->id);
@@ -348,6 +360,11 @@ gr_recipe_set_property (GObject *object,
g_date_time_ref (self->mtime);
break;
+ case PROP_READONLY:
+ self->readonly = g_value_get_boolean (value);
+ update_mtime (self);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -452,6 +469,11 @@ gr_recipe_class_init (GrRecipeClass *klass)
G_TYPE_DATE_TIME,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_MTIME, pspec);
+
+ pspec = g_param_spec_boolean ("readonly", NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_READONLY, pspec);
}
static void
@@ -576,6 +598,12 @@ gr_recipe_get_mtime (GrRecipe *recipe)
return recipe->mtime;
}
+gboolean
+gr_recipe_is_readonly (GrRecipe *recipe)
+{
+ return recipe->readonly;
+}
+
/* term is assumed to be g_utf8_casefold'ed */
gboolean
gr_recipe_matches (GrRecipe *recipe,
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index c5bfc66..debfd06 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -50,6 +50,7 @@ gboolean gr_recipe_contains_garlic (GrRecipe *recipe);
int gr_recipe_get_spiciness (GrRecipe *recipe);
GDateTime *gr_recipe_get_ctime (GrRecipe *recipe);
GDateTime *gr_recipe_get_mtime (GrRecipe *recipe);
+gboolean gr_recipe_is_readonly (GrRecipe *recipe);
gboolean gr_recipe_matches (GrRecipe *recipe,
const char *term);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]