/* * Copyright (C) 2012 - Juan Ferrer Toribio * * 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 . */ #include "vn-model.h" static void vn_model_buildable_init (GtkBuildableIface * iface); G_DEFINE_TYPE_WITH_CODE (VnModel, vn_model, DB_TYPE_MODEL, G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, vn_model_buildable_init) ); /* GtkBuildable custom tag implementation * * * * ... * */ typedef struct { GtkBuilder * builder; DbModel * model; GSList * fields; GSList * params; } VnModelData; //+++++++++++++++++++++++++++++++++++++++++++++++++++ GtkBuildable static void vn_model_start_element (GMarkupParseContext * context, const gchar * element, const gchar ** names, const gchar ** values, gpointer data, GError ** err) { guint i; VnModelData * d = data; for (i = 0; names[i]; i++) if (!g_strcmp0 (names[i], "field")) d->fields = g_slist_prepend (d->fields, g_strdup (values[i])); else if (!g_strcmp0 (names[i], "param")) d->params = g_slist_prepend (d->params, g_strdup (values[i])); } static void vn_model_end_element (GMarkupParseContext * context, const gchar * element, gpointer data, GError ** error) { GSList * f, * p; VnModelData * d = data; g_return_if_fail (d->builder); if (g_strcmp0 (element, "links")) return; d->fields = g_slist_reverse (d->fields); d->params = g_slist_reverse (d->params); for (f = d->fields, p = d->params; f && p; f = f->next, p = p->next) { gchar * field = f->data; GvnParam * param = GVN_PARAM (gtk_builder_get_object (d->builder, p->data)); db_model_set_default_value_from_param (d->model, field, param); g_free (f->data); g_free (p->data); } g_slist_free (d->fields); g_slist_free (d->params); g_slice_free (VnModelData, d); } static const GMarkupParser vn_model_parser = { vn_model_start_element ,vn_model_end_element }; //FIXME: se pone la propiedad "sql" dos veces en el modelo (entre custom_tag_end y custom_finished) static gboolean vn_model_buildable_custom_tag_start (GtkBuildable * buildable, GtkBuilder * builder, GObject * child, const gchar * tag, GMarkupParser * parser, gpointer * data) { if (child) return FALSE; if (!g_strcmp0 (tag, "links")) { VnModelData * data_ptr = g_slice_new (VnModelData); data_ptr->builder = builder; data_ptr->model = DB_MODEL (buildable); data_ptr->fields = NULL; data_ptr->params = NULL; *data = data_ptr; *parser = vn_model_parser; return TRUE; } else g_warning ("Unknown custom model tag: %s", tag); return FALSE; } /*XXX TEST static void vn_model_buildable_set_buildable_property (GtkBuildable *buildable, GtkBuilder * builder, const gchar * name, const GValue * value) { g_message ("set buildable property"); }*/ //+++++++++++++++++++++++++++++++++++++++++++++++++++ Class static void vn_model_finalize (VnModel * obj) { G_OBJECT_CLASS (vn_model_parent_class)->finalize (G_OBJECT (obj)); } static void vn_model_class_init (VnModelClass * klass) { GObjectClass * k = G_OBJECT_CLASS (klass); k->finalize = (GObjectFinalizeFunc) vn_model_finalize; } static void vn_model_buildable_init (GtkBuildableIface * iface) { iface->custom_tag_start = vn_model_buildable_custom_tag_start; // iface->set_buildable_property = vn_model_buildable_set_buildable_property; } static void vn_model_init (VnModel * obj) {}