]> saetta.ns0.it Git - libgtkform/commitdiff
Added attribute long-name to GtkFormField.
authorAndrea Zagli <azagli@libero.it>
Sat, 11 Dec 2010 16:24:55 +0000 (17:24 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 11 Dec 2010 16:24:55 +0000 (17:24 +0100)
data/gtkform.dtd
src/field.c
src/field.h
src/form.c
test/test_db.xml

index 157e82e4895120f9d2ff986b37cd43726811f90f..93f10d95620e1b69070c95fe0d24b4fb9da68153 100644 (file)
 
 <!ELEMENT widget-name (#PCDATA)>
 
-<!ELEMENT field (to-load?, to-save?, obligatory?, default?, is-key?, auto-increment?, datetime-type?, display-format?, trim?)>
+<!ELEMENT field (long-name?, to-load?, to-save?, obligatory?, default?, is-key?, auto-increment?, datetime-type?, display-format?, trim?)>
 
 <!ATTLIST field
        type  (boolean | datetime | float | integer | text)  #REQUIRED
        name  CDATA  #REQUIRED
 >
 
+<!ELEMENT long-name (#PCDATA)>
 <!ELEMENT to-load (#PCDATA)>
 <!ELEMENT to-save (#PCDATA)>
 <!ELEMENT obligatory (#PCDATA)>
index 4500e24dd38798dca28e11f3b49975545ad58e40..ddc4ad5a0123d7f8f07252367dd811ba93f2df82 100644 (file)
@@ -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;
index 2b7bf991d0ec7419dd847c3d86f1496b57367251..680a174ba0b409ee19355d53129dc24efad5b488 100644 (file)
@@ -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);
index 1620f68b62c5a94ee6e3d409b8fe33c82a623d9e..d450b67a74384195e7233fed3504b0c10e9c4f0e 100644 (file)
@@ -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);
                }
index 3b0db423c0a852c30bb2527ee474e8b9f4bc672e..f9e6134bebbe305c9426a30ee88246e7368e6e6d 100644 (file)
@@ -10,8 +10,9 @@
                </field>
        </widget>
 
-       <widget type="entry" name="txt_name" label="label2">
+       <widget type="entry" name="txt_name">
                <field type="text" name="name">
+                       <long-name>The person's name</long-name>
                        <obligatory>TRUE</obligatory>
                </field>
        </widget>