[recipes/pksadiq-wip/sadiq: 1/2] ingredient-item: new class
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/pksadiq-wip/sadiq: 1/2] ingredient-item: new class
- Date: Sun, 7 May 2017 19:25:05 +0000 (UTC)
commit 15c03cdbf5bd9f3e8c2da48cc3323099a2cf37bb
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Fri Jan 20 15:51:54 2017 +0530
ingredient-item: new class
src/Makefile.am | 2 +
src/gr-details-page.c | 25 +-------
src/gr-ingredient-item.c | 144 ++++++++++++++++++++++++++++++++++++++++++
src/gr-ingredient-item.h | 32 +++++++++
src/gr-ingredient-item.ui | 25 +++++++
src/recipes-ui.gresource.xml | 1 +
6 files changed, 206 insertions(+), 23 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2867298..3cfa741 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,6 +62,8 @@ recipes_SOURCES = \
gr-ingredient.c \
gr-ingredient-row.h \
gr-ingredient-row.c \
+ gr-ingredient-item.h \
+ gr-ingredient-item.c \
gr-ingredients-list.h \
gr-ingredients-list.c \
gr-list-page.h \
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 12e39ae..c9c8216 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -37,6 +37,7 @@
#include "gr-images.h"
#include "gr-image-viewer.h"
#include "gr-ingredients-list.h"
+#include "gr-ingredient-item.h"
#include "gr-timer.h"
#include "gr-recipe-printer.h"
#include "gr-recipe-exporter.h"
@@ -816,35 +817,13 @@ populate_ingredients (GrDetailsPage *page,
ings = gr_ingredients_list_get_ingredients (page->ingredients, segments[j]);
for (i = 0; ings[i]; i++) {
- GtkWidget *row;
GtkWidget *box;
g_autofree char *s = NULL;
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (box);
-
s = gr_ingredients_list_scale_unit (page->ingredients, segments[j], ings[i], num,
denom);
- label = gtk_label_new (s);
- g_object_set (label,
- "visible", TRUE,
- "xalign", 0.0,
- "margin", 10,
- NULL);
- gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
- gtk_container_add (GTK_CONTAINER (box), label);
- gtk_size_group_add_widget (group, label);
-
- label = gtk_label_new (ings[i]);
- g_object_set (label,
- "visible", TRUE,
- "xalign", 0.0,
- "margin", 10,
- NULL);
- gtk_container_add (GTK_CONTAINER (box), label);
+ box = gr_ingredient_item_new (ings[i], s);
gtk_container_add (GTK_CONTAINER (list), box);
- row = gtk_widget_get_parent (box);
- gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
}
}
diff --git a/src/gr-ingredient-item.c b/src/gr-ingredient-item.c
new file mode 100644
index 0000000..591ceab
--- /dev/null
+++ b/src/gr-ingredient-item.c
@@ -0,0 +1,144 @@
+/* gr-ingredient-item.c:
+ *
+ * Copyright (C) 2017 Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * 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 "gr-ingredient-item.h"
+
+
+struct _GrIngredientItem
+{
+ GtkBox parent_instance;
+
+ GtkWidget *unit_label;
+ GtkWidget *ingredient_label;
+
+ gchar *ingredient;
+ gchar *unit;
+};
+
+
+G_DEFINE_TYPE (GrIngredientItem, gr_ingredient_item, GTK_TYPE_BOX)
+
+enum {
+ PROP_0,
+ PROP_INGREDIENT,
+ PROP_UNIT,
+};
+
+static void
+gr_ingredient_item_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gr_ingredient_item_parent_class)->finalize (object);
+}
+
+static void
+gr_ingredient_item_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GrIngredientItem *self = GR_INGREDIENT_ITEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_INGREDIENT:
+ g_value_set_string (value, self->ingredient);
+ break;
+ case PROP_UNIT:
+ g_value_set_string (value, self->unit);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gr_ingredient_item_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GrIngredientItem *self = GR_INGREDIENT_ITEM (object);
+
+ switch (prop_id)
+ {
+ case PROP_INGREDIENT:
+ {
+ g_free (self->ingredient);
+ self->ingredient = g_value_dup_string (value);
+ gtk_label_set_text (GTK_LABEL (self->ingredient_label), self->ingredient);
+ }
+ break;
+ case PROP_UNIT:
+ {
+ g_free (self->unit);
+ self->unit = g_value_dup_string (value);
+ gtk_label_set_text (GTK_LABEL (self->unit_label), self->unit);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+
+static void
+gr_ingredient_item_class_init (GrIngredientItemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GParamSpec *pspec;
+
+ object_class->finalize = gr_ingredient_item_finalize;
+ object_class->get_property = gr_ingredient_item_get_property;
+ object_class->set_property = gr_ingredient_item_set_property;
+
+ pspec = g_param_spec_string ("ingredient", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_INGREDIENT, pspec);
+
+ pspec = g_param_spec_string ("unit", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_UNIT, pspec);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Recipes/gr-ingredient-item.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, GrIngredientItem, unit_label);
+ gtk_widget_class_bind_template_child (widget_class, GrIngredientItem, ingredient_label);
+}
+
+static void
+gr_ingredient_item_init (GrIngredientItem *self)
+{
+ gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+}
+
+GtkWidget *
+gr_ingredient_item_new (gchar *ingredient, gchar *unit)
+{
+ return g_object_new (GR_TYPE_INGREDIENT_ITEM,
+ "ingredient", ingredient,
+ "unit", unit,
+ NULL);
+}
diff --git a/src/gr-ingredient-item.h b/src/gr-ingredient-item.h
new file mode 100644
index 0000000..9bc6ee1
--- /dev/null
+++ b/src/gr-ingredient-item.h
@@ -0,0 +1,32 @@
+/* gr-ingredient-item.h:
+ *
+ * Copyright (C) 2017 Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * 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 <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GR_TYPE_INGREDIENT_ITEM (gr_ingredient_item_get_type ())
+
+G_DECLARE_FINAL_TYPE (GrIngredientItem, gr_ingredient_item, GR, INGREDIENT_ITEM, GtkBox)
+
+GtkWidget *gr_ingredient_item_new (gchar *ingredient, gchar *unit);
+
+G_END_DECLS
diff --git a/src/gr-ingredient-item.ui b/src/gr-ingredient-item.ui
new file mode 100644
index 0000000..540f558
--- /dev/null
+++ b/src/gr-ingredient-item.ui
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="recipes">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GrIngredientItem" parent="GtkBox">
+ <property name="visible">1</property>
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkLabel" id="unit_label">
+ <property name="visible">true</property>
+ <property name="xalign">0.0</property>
+ <property name="margin">10</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="ingredient_label">
+ <property name="visible">true</property>
+ <property name="xalign">0.0</property>
+ <property name="margin">10</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/recipes-ui.gresource.xml b/src/recipes-ui.gresource.xml
index 56eb1d8..f9d615b 100644
--- a/src/recipes-ui.gresource.xml
+++ b/src/recipes-ui.gresource.xml
@@ -12,6 +12,7 @@
<file preprocess="xml-stripblanks">gr-image-editor.ui</file>
<file preprocess="xml-stripblanks">gr-image-viewer.ui</file>
<file preprocess="xml-stripblanks">gr-ingredient-row.ui</file>
+ <file preprocess="xml-stripblanks">gr-ingredient-item.ui</file>
<file preprocess="xml-stripblanks">gr-list-page.ui</file>
<file preprocess="xml-stripblanks">gr-meal-row.ui</file>
<file preprocess="xml-stripblanks">gr-preferences.ui</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]