[recipes] Move diet functions to their own files



commit dcfefe3e1e487903b890e53887d4dcc8e356581c
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 12 09:39:22 2016 -0500

    Move diet functions to their own files

 src/Makefile.am        |   10 +++--
 src/gr-category-tile.c |   67 +-------------------------------------
 src/gr-category-tile.h |    3 --
 src/gr-diet-row.c      |    1 +
 src/gr-diet.c          |   83 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gr-diet.h          |   40 +++++++++++++++++++++++
 src/gr-recipe.h        |    9 +-----
 7 files changed, 133 insertions(+), 80 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a6b39c4..787296d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,8 @@ recipes_SOURCES = \
        gr-cuisines-page.c      \
        gr-details-page.h       \
        gr-details-page.c       \
+       gr-diet.h               \
+       gr-diet.c               \
        gr-diet-row.h           \
        gr-diet-row.c           \
        gr-edit-page.h          \
@@ -109,13 +111,13 @@ resources.c: recipes.gresource.xml $(resource_files)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/recipes.gresource.xml \
                 --target=$@ --sourcedir=$(srcdir) --generate-source
 
-types.h: types.h.template gr-recipe.h
-       $(AM_V_GEN) ($(GLIB_MKENUMS) --template types.h.template gr-recipe.h ) > xgen-eh && \
+types.h: types.h.template gr-diet.h
+       $(AM_V_GEN) ($(GLIB_MKENUMS) --template types.h.template gr-diet.h ) > xgen-eh && \
        cp xgen-eh $@ && \
        rm -f xgen-eh
 
-types.c: types.c.template gr-recipe.h
-       $(AM_V_GEN) ($(GLIB_MKENUMS) --template types.c.template gr-recipe.h ) > xgen-ec && \
+types.c: types.c.template gr-diet.h
+       $(AM_V_GEN) ($(GLIB_MKENUMS) --template types.c.template gr-diet.h ) > xgen-ec && \
        cp xgen-ec $@ && \
        rm -f xgen-ec
 
diff --git a/src/gr-category-tile.c b/src/gr-category-tile.c
index aac885c..e384555 100644
--- a/src/gr-category-tile.c
+++ b/src/gr-category-tile.c
@@ -26,6 +26,7 @@
 #include "gr-category-tile.h"
 #include "gr-window.h"
 #include "gr-utils.h"
+#include "gr-diet.h"
 
 
 struct _GrCategoryTile
@@ -41,70 +42,6 @@ struct _GrCategoryTile
 
 G_DEFINE_TYPE (GrCategoryTile, gr_category_tile, GTK_TYPE_BUTTON)
 
-static const char *
-get_category_title (GrDiets diet)
-{
-        const char *label;
-
-       switch (diet) {
-       case GR_DIET_GLUTEN_FREE:
-               label = _("Gluten-free recipes");
-               break;
-       case GR_DIET_NUT_FREE:
-               label = _("Nut-free recipes");
-               break;
-       case GR_DIET_VEGAN:
-               label = _("Vegan recipes");
-               break;
-       case GR_DIET_VEGETARIAN:
-               label = _("Vegetarian recipes");
-               break;
-       case GR_DIET_MILK_FREE:
-               label = _("Milk-free recipes");
-               break;
-       default:
-               label = _("Other dietary restrictions");
-               break;
-       }
-
-        return label;
-}
-
-const char *
-gr_diet_get_label (GrDiets diet)
-{
-        return get_category_title (diet);
-}
-
-const char *
-gr_diet_get_description (GrDiets diet)
-{
-        const char *label;
-
-       switch (diet) {
-       case GR_DIET_GLUTEN_FREE:
-               label = _("A gluten-free diet is a diet that excludes gluten, a protein composite found in 
wheat, barley, rye, and all their species and hybrids (such as spelt, kamut, and triticale). The inclusion of 
oats in a gluten-free diet remains controversial. Avenin present in oats may also be toxic for coeliac 
people; its toxicity depends on the cultivar consumed. Furthermore, oats are frequently cross-contaminated 
with cereals containing gluten.\n<a href=\"https://en.wikibooks.org/wiki/Cookbook:Gluten-Free\";>Learn 
more…</a>");
-               break;
-       case GR_DIET_NUT_FREE:
-               label = _("A tree nut allergy is a hypersensitivity to dietary substances from tree nuts and 
edible tree seeds causing an overreaction of the immune system which may lead to severe physical symptoms. 
Tree nuts include, but are not limited to, almonds, Brazil nuts, cashews, chestnuts, filberts/hazelnuts, 
macadamia nuts, pecans, pistachios, pine nuts, shea nuts and walnuts.\n<a 
href=\"https://en.wikipedia.org/wiki/Tree_nut_allergy\";>Learn more…</a>");
-               break;
-       case GR_DIET_VEGAN:
-               label = _("Veganism is both the practice of abstaining from the use of animal products, 
particularly in diet, and an associated philosophy that rejects the commodity status of animals.\n<a 
href=\"https://en.wikipedia.org/wiki/Veganism\";>Learn more…</a>");
-               break;
-       case GR_DIET_VEGETARIAN:
-               label = _("Vegetarian cuisine is based on food that meets vegetarian standards by not 
including meat and animal tissue products (such as gelatin or animal-derived rennet). For lacto-ovo 
vegetarianism (the most common type of vegetarianism in the Western world), eggs and dairy products such as 
milk and cheese are permitted. For lacto vegetarianism, the earliest known type of vegetarianism (recorded in 
India), dairy products such as milk and cheese are permitted.\nThe strictest forms of vegetarianism are 
veganism and fruitarianism, which exclude all animal products, including dairy products as well as honey, and 
even some refined sugars if filtered and whitened with bone char.\n<a 
href=\"https://en.wikipedia.org/wiki/Vegetarianism\";>Learn more…</a>");
-               break;
-       case GR_DIET_MILK_FREE:
-               label = _("Lactose intolerance is a condition in which people have symptoms due to the 
decreased ability to digest lactose, a sugar found in milk products. Those affected vary in the amount of 
lactose they can tolerate before symptoms develop. Symptoms may include abdominal pain, bloating, diarrhea, 
gas, and nausea. These typically start between half and two hours after drinking milk. Severity depends on 
the amount a person eats or drinks. It does not cause damage to the gastrointestinal tract.\n<a 
href=\"https://en.wikipedia.org/wiki/Lactose_intolerance\";>Learn more…</a>");
-               break;
-       default:
-               label = _("Other dietary restrictions");
-               break;
-       }
-
-        return label;
-}
-
 static const char *colors[] = {
         "#215d9c",
         "#297bcc",
@@ -144,7 +81,7 @@ category_tile_set_category (GrCategoryTile *tile,
                             GrDiets         diet)
 {
        tile->diet = diet;
-        gtk_label_set_label (GTK_LABEL (tile->label), get_category_title (diet));
+        gtk_label_set_label (GTK_LABEL (tile->label), gr_diet_get_label (diet));
 }
 
 static void
diff --git a/src/gr-category-tile.h b/src/gr-category-tile.h
index 0205118..3f84535 100644
--- a/src/gr-category-tile.h
+++ b/src/gr-category-tile.h
@@ -36,7 +36,4 @@ GrDiets          gr_category_tile_get_diet       (GrCategoryTile *tile);
 const char      *gr_category_tile_get_category   (GrCategoryTile *tile);
 const char      *gr_category_tile_get_label      (GrCategoryTile *tile);
 
-const char      *gr_diet_get_label (GrDiets diet);
-const char      *gr_diet_get_description (GrDiets diet);
-
 G_END_DECLS
diff --git a/src/gr-diet-row.c b/src/gr-diet-row.c
index 528ceb7..c24b6c8 100644
--- a/src/gr-diet-row.c
+++ b/src/gr-diet-row.c
@@ -25,6 +25,7 @@
 
 #include "types.h"
 #include "gr-diet-row.h"
+#include "gr-diet.h"
 
 
 struct _GrDietRow
diff --git a/src/gr-diet.c b/src/gr-diet.c
new file mode 100644
index 0000000..6a49f84
--- /dev/null
+++ b/src/gr-diet.c
@@ -0,0 +1,83 @@
+/* gr-diet.c:
+ *
+ * Copyright (C) 2016 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gr-diet.h"
+
+const char *
+gr_diet_get_label (GrDiets diet)
+{
+        const char *label;
+
+        switch (diet) {
+        case GR_DIET_GLUTEN_FREE:
+                label = _("Gluten-free recipes");
+                break;
+        case GR_DIET_NUT_FREE:
+                label = _("Nut-free recipes");
+                break;
+        case GR_DIET_VEGAN:
+                label = _("Vegan recipes");
+                break;
+        case GR_DIET_VEGETARIAN:
+                label = _("Vegetarian recipes");
+                break;
+        case GR_DIET_MILK_FREE:
+                label = _("Milk-free recipes");
+                break;
+        default:
+                label = _("Other dietary restrictions");
+                break;
+        }
+
+        return label;
+}
+
+const char *
+gr_diet_get_description (GrDiets diet)
+{
+        const char *label;
+
+        switch (diet) {
+        case GR_DIET_GLUTEN_FREE:
+                label = _("A gluten-free diet is a diet that excludes gluten, a protein composite found in 
wheat, barley, rye, and all their species and hybrids (such as spelt, kamut, and triticale). The inclusion of 
oats in a gluten-free diet remains controversial. Avenin present in oats may also be toxic for coeliac 
people; its toxicity depends on the cultivar consumed. Furthermore, oats are frequently cross-contaminated 
with cereals containing gluten.\n<a href=\"https://en.wikibooks.org/wiki/Cookbook:Gluten-Free\";>Learn 
more…</a>");
+                break;
+        case GR_DIET_NUT_FREE:
+                label = _("A tree nut allergy is a hypersensitivity to dietary substances from tree nuts and 
edible tree seeds causing an overreaction of the immune system which may lead to severe physical symptoms. 
Tree nuts include, but are not limited to, almonds, Brazil nuts, cashews, chestnuts, filberts/hazelnuts, 
macadamia nuts, pecans, pistachios, pine nuts, shea nuts and walnuts.\n<a 
href=\"https://en.wikipedia.org/wiki/Tree_nut_allergy\";>Learn more…</a>");
+                break;
+        case GR_DIET_VEGAN:
+                label = _("Veganism is both the practice of abstaining from the use of animal products, 
particularly in diet, and an associated philosophy that rejects the commodity status of animals.\n<a 
href=\"https://en.wikipedia.org/wiki/Veganism\";>Learn more…</a>");
+                break;
+        case GR_DIET_VEGETARIAN:
+                label = _("Vegetarian cuisine is based on food that meets vegetarian standards by not 
including meat and animal tissue products (such as gelatin or animal-derived rennet). For lacto-ovo 
vegetarianism (the most common type of vegetarianism in the Western world), eggs and dairy products such as 
milk and cheese are permitted. For lacto vegetarianism, the earliest known type of vegetarianism (recorded in 
India), dairy products such as milk and cheese are permitted.\nThe strictest forms of vegetarianism are 
veganism and fruitarianism, which exclude all animal products, including dairy products as well as honey, and 
even some refined sugars if filtered and whitened with bone char.\n<a 
href=\"https://en.wikipedia.org/wiki/Vegetarianism\";>Learn more…</a>");
+                break;
+        case GR_DIET_MILK_FREE:
+                label = _("Lactose intolerance is a condition in which people have symptoms due to the 
decreased ability to digest lactose, a sugar found in milk products. Those affected vary in the amount of 
lactose they can tolerate before symptoms develop. Symptoms may include abdominal pain, bloating, diarrhea, 
gas, and nausea. These typically start between half and two hours after drinking milk. Severity depends on 
the amount a person eats or drinks. It does not cause damage to the gastrointestinal tract.\n<a 
href=\"https://en.wikipedia.org/wiki/Lactose_intolerance\";>Learn more…</a>");
+                break;
+        default:
+                label = _("Other dietary restrictions");
+                break;
+        }
+
+        return label;
+}
diff --git a/src/gr-diet.h b/src/gr-diet.h
new file mode 100644
index 0000000..3d339f6
--- /dev/null
+++ b/src/gr-diet.h
@@ -0,0 +1,40 @@
+/* gr-diet.h:
+ *
+ * Copyright (C) 2016 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+G_BEGIN_DECLS
+
+typedef enum { /*< flags >*/
+       GR_DIET_GLUTEN_FREE   =  1,
+       GR_DIET_NUT_FREE      =  2,
+       GR_DIET_VEGAN         =  4,
+       GR_DIET_VEGETARIAN    =  8,
+       GR_DIET_MILK_FREE     = 16
+} GrDiets;
+
+
+const char      *gr_diet_get_label       (GrDiets diet);
+const char      *gr_diet_get_description (GrDiets diet);
+
+G_END_DECLS
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index b0ce3ad..3ea509e 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -22,6 +22,7 @@
 
 #include <glib-object.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include "gr-diet.h"
 
 G_BEGIN_DECLS
 
@@ -34,14 +35,6 @@ struct _GrRecipeClass
        GObjectClass parent;
 };
 
-typedef enum { /*< flags >*/
-       GR_DIET_GLUTEN_FREE   =  1,
-       GR_DIET_NUT_FREE      =  2,
-       GR_DIET_VEGAN         =  4,
-       GR_DIET_VEGETARIAN    =  8,
-       GR_DIET_MILK_FREE     = 16
-} GrDiets;
-
 GrRecipe       *gr_recipe_new              (void);
 
 const char     *gr_recipe_get_name         (GrRecipe   *recipe);


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