#include <string.h>
+#include <libxml/xpath.h>
+
#include "form.h"
#include "fieldboolean.h"
typedef struct _GtkFormPrivate GtkFormPrivate;
struct _GtkFormPrivate
{
+ GtkBuilder *gtkbuilder;
+
gchar *table;
- GList *fields;
+ GSList *fields;
GtkFormKey *key;
};
*gtk_form_new_from_xml (xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
{
GtkForm *form;
+ GtkFormPrivate *priv;
xmlNode *cur;
- GtkBuilder *new_gtkbuilder;
form = NULL;
- if (GTK_IS_BUILDER (gtkbuilder))
- {
- new_gtkbuilder = gtkbuilder;
- }
- else
- {
- new_gtkbuilder = NULL;
- }
-
cur = xmlDocGetRootElement (xmldoc);
if (cur != NULL)
{
form = gtk_form_new ();
- /* TO DO
- * search gtkguilder-file node
- */
+ priv = GTK_FORM_GET_PRIVATE (form);
+
+ if (GTK_IS_BUILDER (gtkbuilder))
+ {
+ priv->gtkbuilder = gtkbuilder;
+ }
+ else
+ {
+ priv->gtkbuilder = NULL;
+ }
+
+ /* search gtkguilder-file node */
+ if (!GTK_IS_BUILDER (priv->gtkbuilder))
+ {
+ xmlXPathContextPtr xpcontext;
+ xmlXPathObjectPtr xpresult;
+ xmlNodeSetPtr xnodeset;
+
+ xpcontext = xmlXPathNewContext (xmldoc);
+
+ xpcontext->node = cur;
+ xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::gtkbuilder-file", xpcontext);
+ if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+ {
+ xnodeset = xpresult->nodesetval;
+ if (xnodeset->nodeNr == 1)
+ {
+ GError *error;
+ gchar *filename;
+
+ filename = (gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]);
+
+ priv->gtkbuilder = gtk_builder_new ();
+
+ error = NULL;
+ if (gtk_builder_add_from_file (priv->gtkbuilder, filename, &error) <= 0)
+ {
+ priv->gtkbuilder = NULL;
+ g_warning ("Error on loading GtkBuilder file: %s\n",
+ error->message);
+ }
+ }
+ }
+ }
cur = cur->children;
while (cur)
{
name = xmlGetProp (cur, (const xmlChar *)"name");
- gtk_form_widget_set_from_gtkbuilder (widget, new_gtkbuilder, name);
+ if (GTK_IS_BUILDER (priv->gtkbuilder))
+ {
+ gtk_form_widget_set_from_gtkbuilder (widget, priv->gtkbuilder, name);
+ }
node_widget = cur->children;
while (node_widget != NULL)
return form;
}
+/**
+ * gtk_form_get_gtkbuilder:
+ * @form: a #GtkForm object.
+ *
+ */
+GtkBuilder
+*gtk_form_get_gtkbuilder (GtkForm *form)
+{
+ GtkFormPrivate *priv;
+
+ g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+ priv = GTK_FORM_GET_PRIVATE (form);
+
+ return priv->gtkbuilder;
+}
+
/**
* gtk_form_get_table:
* @form: a #GtkForm object.
priv = GTK_FORM_GET_PRIVATE (form);
- priv->fields = g_list_append (priv->fields, field);
+ priv->fields = g_slist_append (priv->fields, field);
ret = TRUE;
priv = GTK_FORM_GET_PRIVATE (form);
- priv->fields = g_list_remove (priv->fields, field);
+ priv->fields = g_slist_remove (priv->fields, field);
ret = TRUE;
priv = GTK_FORM_GET_PRIVATE (form);
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
name = gtk_form_field_get_field_name ((GtkFormField *)fields->data);
break;
}
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
return field;
priv = GTK_FORM_GET_PRIVATE (form);
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
widget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
break;
}
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
return widget_ret;
priv = GTK_FORM_GET_PRIVATE (form);
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
gtk_form_field_clear (field);
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
ret = TRUE;
GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
break;
}
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
- if (ret)
+ if (ret && IS_GTK_FORM_KEY (priv->key))
{
ret = gtk_form_key_check (priv->key);
}
g_return_if_fail (IS_GTK_FORM (form));
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
fwidget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
widget = gtk_form_widget_get_widget (fwidget);
gtk_widget_set_sensitive (widget, sensitive);
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
}
g_return_if_fail (IS_GTK_FORM (form));
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
fwidget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
gtk_form_widget_set_editable (fwidget, editable);
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
}
GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
break;
case GTK_FORM_SQL_UPDATE:
- if (!gtk_form_key_field_is_key (priv->key, field))
+ if (!IS_GTK_FORM_KEY (priv->key) ||
+ !gtk_form_key_field_is_key (priv->key, field))
{
value = gtk_form_field_get_value_sql (field);
if (value != NULL)
}
}
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
if (g_str_has_suffix (fields_names, ", "))
break;
}
- where = gtk_form_key_get_sql (priv->key);
- if ((type == GTK_FORM_SQL_SELECT || type == GTK_FORM_SQL_UPDATE || type == GTK_FORM_SQL_DELETE)
- && where != NULL && strcmp (where, "") != 0)
+ if (IS_GTK_FORM_KEY (priv->key))
{
- sql = g_strconcat (sql, where, NULL);
+ where = gtk_form_key_get_sql (priv->key);
+ if ((type == GTK_FORM_SQL_SELECT || type == GTK_FORM_SQL_UPDATE || type == GTK_FORM_SQL_DELETE)
+ && where != NULL && strcmp (where, "") != 0)
+ {
+ sql = g_strconcat (sql, where, NULL);
+ }
}
return sql;
GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
- GList *fields = g_list_first (priv->fields);
+ GSList *fields = priv->fields;
while (fields != NULL)
{
gtk_form_field_set_from_datamodel (field, dm, row);
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
return ret;