From 3f4616172afe2cbaa6907f9bbaaf764fd96398ac Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 11 Dec 2010 17:24:55 +0100 Subject: [PATCH] Added attribute long-name to GtkFormField. --- data/gtkform.dtd | 3 ++- src/field.c | 33 ++++++++++++++++++++++++++++++++- src/field.h | 2 ++ src/form.c | 37 +++++++++++++++++++++++++++++++------ test/test_db.xml | 3 ++- 5 files changed, 69 insertions(+), 9 deletions(-) diff --git a/data/gtkform.dtd b/data/gtkform.dtd index 157e82e..93f10d9 100644 --- a/data/gtkform.dtd +++ b/data/gtkform.dtd @@ -31,13 +31,14 @@ - + + diff --git a/src/field.c b/src/field.c index 4500e24..ddc4ad5 100644 --- a/src/field.c +++ b/src/field.c @@ -23,6 +23,7 @@ enum { PROP_0, PROP_FIELD, + PROP_LONG_NAME, PROP_TO_LOAD, PROP_TO_SAVE, PROP_OBLIGATORY, @@ -50,6 +51,7 @@ typedef struct _GtkFormFieldPrivate GtkFormFieldPrivate; struct _GtkFormFieldPrivate { gchar *field; + gchar *long_name; gboolean is_key; gboolean to_load; gboolean to_save; @@ -79,11 +81,18 @@ gtk_form_field_class_init (GtkFormFieldClass *klass) g_object_class_install_property (object_class, PROP_FIELD, g_param_spec_string ("field", - "Field", + "Field's name", "Field's name", "", G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_LONG_NAME, + g_param_spec_string ("long-name", + "Field's long name", + "Field's long name", + "", + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_TO_LOAD, g_param_spec_boolean ("to-load", "Whether load the field or not", @@ -177,6 +186,20 @@ gchar return g_strdup (priv->field); } +/** + * gtk_form_field_get_field_long_name: + * @field: a #GtkFormField object. + * + * Returns: the field's long name. + */ +gchar +*gtk_form_field_get_field_long_name (GtkFormField *field) +{ + GtkFormFieldPrivate *priv = GTK_FORM_FIELD_GET_PRIVATE (field); + + return g_strdup (priv->long_name); +} + /** * gtk_form_field_get_form_widget: * @field: a #GtkFormField object. @@ -496,6 +519,10 @@ gtk_form_field_set_property (GObject *object, priv->field = g_strstrip (g_value_dup_string (value)); break; + case PROP_LONG_NAME: + priv->long_name = g_strstrip (g_value_dup_string (value)); + break; + case PROP_TO_LOAD: priv->to_load = g_value_get_boolean (value); break; @@ -547,6 +574,10 @@ gtk_form_field_get_property (GObject *object, g_value_set_string (value, gtk_form_field_get_field_name (field)); break; + case PROP_LONG_NAME: + g_value_set_string (value, gtk_form_field_get_field_long_name (field)); + break; + case PROP_TO_LOAD: g_value_set_boolean (value, priv->to_load); break; diff --git a/src/field.h b/src/field.h index 2b7bf99..680a174 100644 --- a/src/field.h +++ b/src/field.h @@ -69,6 +69,8 @@ GtkFormField *gtk_form_field_new (void); GtkFormField *gtk_form_field_new_from_gtk_form_widget (GtkFormWidget *fwidget); gchar *gtk_form_field_get_field_name (GtkFormField *field); +gchar *gtk_form_field_get_field_long_name (GtkFormField *field); + GtkFormWidget *gtk_form_field_get_form_widget (GtkFormField *field); gchar *gtk_form_field_get_value_stringify (GtkFormField *field); diff --git a/src/form.c b/src/form.c index 1620f68..d450b67 100644 --- a/src/form.c +++ b/src/form.c @@ -545,7 +545,13 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder) while (node_field != NULL) { prop = (gchar *)xmlNodeGetContent (node_field); - if (xmlStrcmp (node_field->name, (const xmlChar *)"to-load") == 0) + if (xmlStrcmp (node_field->name, (const xmlChar *)"long-name") == 0) + { + g_object_set (G_OBJECT (field), + "long-name", prop, + NULL); + } + else if (xmlStrcmp (node_field->name, (const xmlChar *)"to-load") == 0) { g_object_set (G_OBJECT (field), "to-load", gtk_form_field_boolean_str_to_boolean (prop), @@ -2233,21 +2239,40 @@ gtk_form_show_check_error_dialog (GtkFormWidget *fwidget, GtkWidget *parent_wind { GtkWidget *dialog; GtkWidget *label; - const gchar *label_text; + GtkFormField *field; + + gchar *label_text; g_return_if_fail (IS_GTK_FORM_WIDGET (fwidget)); g_return_if_fail (GTK_IS_WINDOW (parent_window)); + label_text = NULL; + label = gtk_form_widget_get_label (fwidget); if (GTK_IS_LABEL (label)) { - label_text = gtk_label_get_text (GTK_LABEL (label)); + label_text = (gchar *)gtk_label_get_text (GTK_LABEL (label)); } - else if (GTK_IS_CHECK_BUTTON (label)) + else { - label_text = gtk_button_get_label (GTK_BUTTON (label)); + g_object_get (G_OBJECT (fwidget), "field", &field, NULL); + if (IS_GTK_FORM_FIELD (field)) + { + label_text = gtk_form_field_get_field_long_name (field); + if (label_text == NULL || g_strcmp0 (g_strstrip (label_text), "") == 0) + { + label_text = gtk_form_field_get_field_name (field); + } + } + + if ((label_text == NULL || g_strcmp0 (g_strstrip (label_text), "") == 0) + && GTK_IS_CHECK_BUTTON (label)) + { + label_text = (gchar *)gtk_button_get_label (GTK_BUTTON (label)); + } } - else + + if (label_text == NULL || g_strcmp0 (g_strstrip (label_text), "") == 0) { label_text = gtk_form_widget_get_widget_name (fwidget); } diff --git a/test/test_db.xml b/test/test_db.xml index 3b0db42..f9e6134 100644 --- a/test/test_db.xml +++ b/test/test_db.xml @@ -10,8 +10,9 @@ - + + The person's name TRUE -- 2.49.0