[recipes/inline-editing] Bring back collecting ingredients
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/inline-editing] Bring back collecting ingredients
- Date: Thu, 20 Apr 2017 02:55:22 +0000 (UTC)
commit 815fadded66ba02f11cfadb608559fcb2e651070
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Apr 19 22:54:21 2017 -0400
Bring back collecting ingredients
This brings back the code to collect ingredients from
the lists when we want to save them.
src/gr-edit-page.c | 43 ++++++++++++-------------------------------
src/gr-ingredients-viewer.c | 43 ++++++++++++++++++++++++++++++++++++-------
2 files changed, 48 insertions(+), 38 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 551126e..1e601fe 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -421,40 +421,21 @@ static char *
collect_ingredients (GrEditPage *page)
{
GString *s;
- GtkWidget *segment;
- GtkWidget *list;
- GtkWidget *entry;
- GList *children, *l, *k;
+ GList *children, *l;
s = g_string_new ("");
- for (k = page->segments; k; k = k->next) {
- segment = k->data;
- list = GTK_WIDGET (g_object_get_data (G_OBJECT (segment), "list"));
- entry = GTK_WIDGET (g_object_get_data (G_OBJECT (segment), "entry"));
- children = gtk_container_get_children (GTK_CONTAINER (list));
- for (l = children; l; l = l->next) {
- GtkWidget *row = l->data;
- const char *amount;
- const char *unit;
- const char *ingredient;
- const char *id;
-
- amount = (const char *)g_object_get_data (G_OBJECT (row), "amount");
- unit = (const char *)g_object_get_data (G_OBJECT (row), "unit");
- ingredient = (const char *)g_object_get_data (G_OBJECT (row), "ingredient");
- id = gr_ingredient_get_id (ingredient);
- if (s->len > 0)
- g_string_append (s, "\n");
- g_string_append (s, amount);
- g_string_append (s, "\t");
- g_string_append (s, unit);
- g_string_append (s, "\t");
- g_string_append (s, id ? id : ingredient);
- g_string_append (s, "\t");
- g_string_append (s, gtk_entry_get_text (GTK_ENTRY (entry)));
- }
- g_list_free (children);
+
+ children = gtk_container_get_children (GTK_CONTAINER (page->ingredients_box));
+ for (l = children; l; l = l->next) {
+ GtkWidget *list = l->data;
+ g_autofree char *segment = NULL;
+
+ g_object_get (list, "ingredients", &segment, NULL);
+ if (s->len > 0)
+ g_string_append (s, "\n");
+ g_string_append (s, segment);
}
+ g_list_free (children);
return g_string_free (s, FALSE);
}
diff --git a/src/gr-ingredients-viewer.c b/src/gr-ingredients-viewer.c
index 3419442..a90eeec 100644
--- a/src/gr-ingredients-viewer.c
+++ b/src/gr-ingredients-viewer.c
@@ -43,7 +43,6 @@ struct _GrIngredientsViewer
GtkWidget *add_button;
char *title;
- char *ingredients;
gboolean editable;
GtkSizeGroup *group;
@@ -76,7 +75,6 @@ gr_ingredients_viewer_finalize (GObject *object)
GrIngredientsViewer *viewer = GR_INGREDIENTS_VIEWER (object);
g_free (viewer->title);
- g_free (viewer->ingredients);
g_clear_object (&viewer->group);
@@ -124,6 +122,37 @@ title_changed (GtkEntry *entry,
g_object_notify (G_OBJECT (viewer), "title");
}
+static char *
+collect_ingredients (GrIngredientsViewer *viewer)
+{
+ GString *s;
+ GList *children, *l;
+
+ s = g_string_new ("");
+
+ children = gtk_container_get_children (GTK_CONTAINER (viewer->list));
+ for (l = children; l; l = l->next) {
+ GrIngredientsViewerRow *row = l->data;
+ g_autofree char *amount = NULL;
+ g_autofree char *unit = NULL;
+ g_autofree char *ingredient = NULL;
+
+ g_object_get (row,
+ "amount", &amount,
+ "unit", &unit,
+ "ingredient", &ingredient,
+ NULL);
+
+ if (s->len > 0)
+ g_string_append (s, "\n");
+ g_string_append_printf (s, "%s\t%s\t%s\t%s",
+ amount, unit, ingredient, viewer->title);
+ }
+ g_list_free (children);
+
+ return g_string_free (s, FALSE);
+}
+
static void
gr_ingredients_viewer_get_property (GObject *object,
guint prop_id,
@@ -148,8 +177,11 @@ gr_ingredients_viewer_get_property (GObject *object,
g_value_set_boolean (value, self->editable);
break;
- case PROP_INGREDIENTS:
- g_value_set_string (value, self->ingredients);
+ case PROP_INGREDIENTS: {
+ g_autofree char *ingredients = NULL;
+ ingredients = collect_ingredients (self);
+ g_value_set_string (value, ingredients);
+ }
break;
case PROP_ACTIVE:
@@ -225,9 +257,6 @@ gr_ingredients_viewer_set_ingredients (GrIngredientsViewer *viewer,
g_auto(GStrv) ings = NULL;
int i;
- g_free (viewer->ingredients);
- viewer->ingredients = g_strdup (text);
-
container_remove_all (GTK_CONTAINER (viewer->list));
ingredients = gr_ingredients_list_new (text);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]