]> saetta.ns0.it Git - libgtkform/commitdiff
Bugfixes and memory leaks.
authorAndrea Zagli <azagli@libero.it>
Sat, 2 Apr 2011 09:32:33 +0000 (11:32 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 2 Apr 2011 09:32:33 +0000 (11:32 +0200)
src/fielddatetime.c
src/fieldtext.c
src/widgetradio.c
test/database.db
test/from_xml_with_db.c
test/test_db.gui
test/test_db.xml

index 9b5278644acc7a8787e4af75071a70d6661314f2..d3040943af1591103e3b08b8ed93d3e4a52cce23 100644 (file)
@@ -350,10 +350,13 @@ gtk_form_field_datetime_is_changed (GtkFormField *field)
                {
                        ret = (value->tm_year != priv->original_value->tm_year
                                   || value->tm_mon != priv->original_value->tm_mon
-                                  || value->tm_mday != priv->original_value->tm_mday
-                                  || value->tm_hour != priv->original_value->tm_hour
-                                  || value->tm_min != priv->original_value->tm_min
-                                  || value->tm_sec != priv->original_value->tm_sec);
+                                  || value->tm_mday != priv->original_value->tm_mday);
+                       if (!ret && priv->type == GTK_FORM_FIELD_DATETIME_TYPE_DATETIME)
+                               {
+                                       ret = (value->tm_hour != priv->original_value->tm_hour
+                                              || value->tm_min != priv->original_value->tm_min
+                                              || value->tm_sec != priv->original_value->tm_sec);
+                               }
                }
        else if ((value == NULL || priv->original_value == NULL)
                 && !(value == NULL && priv->original_value == NULL))
@@ -361,6 +364,8 @@ gtk_form_field_datetime_is_changed (GtkFormField *field)
                        ret = TRUE;
                }
 
+       g_free (value);
+
        return ret;
 }
 
@@ -384,6 +389,15 @@ gtk_form_field_datetime_set_as_origin (GtkFormField *field)
                                                         priv->display_format);
 
        priv->original_value = g_memdup (value, sizeof (struct tm));
+
+       if (priv->type == GTK_FORM_FIELD_DATETIME_TYPE_DATE)
+               {
+                       priv->original_value->tm_hour = 0;
+                       priv->original_value->tm_min = 0;
+                       priv->original_value->tm_sec = 0;
+               }
+
+       g_free (value);
 }
 
 /**
@@ -421,6 +435,7 @@ gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *d
 
                        priv->original_value = g_memdup (datetime, sizeof (struct tm));
 
+                       g_free (datetime);
                        g_free (value);
                }
        else
@@ -475,6 +490,7 @@ gtk_form_field_datetime_set_from_hashtable (GtkFormField *field, GHashTable *has
 
                                        priv->original_value = g_memdup (datetime, sizeof (struct tm));
 
+                                       g_free (datetime);
                                        g_free (value);
                                }
                }
@@ -514,6 +530,9 @@ gtk_form_field_datetime_set_value (GtkFormField *field, GValue *gvalue)
        ret = gtk_form_field_datetime_set_value_stringify (field, value);
        priv->original_value = g_memdup (datetime, sizeof (struct tm));
 
+       g_free (datetime);
+       g_free (value);
+
        return ret;
 }
 
@@ -890,5 +909,10 @@ gtk_form_field_datetime_is_valid (GtkFormFieldDateTime *field)
        str_date = gtk_form_field_datetime_get_value_stringify (GTK_FORM_FIELD (field));
        tm_date = gtk_form_field_datetime_get_tm_from_str (str_date, priv->display_format);
 
-       return (tm_date != NULL);
+       ret = (tm_date != NULL);
+
+       g_free (str_date);
+       g_free (tm_date);
+
+       return ret;
 }
index 5b8b5e23228c3860d15a469fd5aff2bd61a4952f..ae168daba101d709975914899344c292e60843f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -301,7 +301,8 @@ gtk_form_field_text_set_as_origin (GtkFormField *field)
 
        priv = GTK_FORM_FIELD_TEXT_GET_PRIVATE (GTK_FORM_FIELD_TEXT (field));
 
-       priv->original_value = (gchar *)gtk_form_field_text_get_value_stringify (field);
+       g_free (priv->original_value);
+       priv->original_value = g_strdup (gtk_form_field_text_get_value_stringify (field));
 }
 
 /**
@@ -333,7 +334,8 @@ gtk_form_field_text_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, g
                }
        ret = gtk_form_field_text_set_value_stringify (field, strret);
 
-       priv->original_value = gtk_form_field_text_get_value_stringify (field);
+       g_free (priv->original_value);
+       priv->original_value = g_strdup (gtk_form_field_text_get_value_stringify (field));
 
        g_free (field_name);
        g_free (strret);
@@ -363,6 +365,7 @@ gtk_form_field_text_set_from_hashtable (GtkFormField *field, GHashTable *hashtab
        field_name = gtk_form_field_get_field_name (field);
        if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
                {
+                       g_free (priv->original_value);
                        gval = (GValue *)g_hash_table_lookup (hashtable, field_name);
                        if (gval == NULL)
                                {
@@ -372,7 +375,7 @@ gtk_form_field_text_set_from_hashtable (GtkFormField *field, GHashTable *hashtab
                        else
                                {
                                        ret = gtk_form_field_text_set_value_stringify (field, g_value_get_string (gval));
-                                       priv->original_value = gtk_form_field_text_get_value_stringify (field);
+                                       priv->original_value = g_strdup (gtk_form_field_text_get_value_stringify (field));
                                }
                        g_free (field_name);
                }
@@ -398,7 +401,9 @@ gtk_form_field_text_set_value (GtkFormField *field, GValue *gvalue)
        priv = GTK_FORM_FIELD_TEXT_GET_PRIVATE (GTK_FORM_FIELD_TEXT (field));
 
        ret = gtk_form_field_text_set_value_stringify (field, g_value_get_string (gvalue));
-       priv->original_value = gtk_form_field_text_get_value_stringify (field);
+
+       g_free (priv->original_value);
+       priv->original_value = g_strdup (gtk_form_field_text_get_value_stringify (field));
 
        return ret;
 }
@@ -445,7 +450,7 @@ gtk_form_field_text_get_property (GObject *object,
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
-         }
+               }
 }
 
 static gboolean
@@ -469,6 +474,7 @@ gtk_form_field_text_set_value_stringify (GtkFormField *field, const gchar *value
                }
 
        ret = gtk_form_widget_set_value_stringify (fw, newval);
+       g_free (newval);
 
        return ret;
 }
index b9aab81b283fe07d3b4a33ee1fc2973f25caa22f..552ac6fae5754c9f84351d1a3f1946165203f81a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -117,7 +117,7 @@ gchar
                {
                        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (group->data)))
                                {
-                                       ret = g_strdup ((const gchar*)g_object_get_data (G_OBJECT (group->data), "return-value"));
+                                       ret = (gchar *)g_object_get_data (G_OBJECT (group->data), "return-value");
                                        if (ret == NULL)
                                                {
                                                        ret = g_strdup ("");
@@ -128,7 +128,7 @@ gchar
                        group = g_slist_next (group);
                }
 
-       return ret;
+       return g_strdup (ret);
 }
 
 /**
@@ -142,7 +142,9 @@ gtk_form_widget_radio_set_value_stringify (GtkFormWidget *fwidget, const gchar *
 {
        gboolean ret;
        GtkWidget *w;
-       gboolean active;
+
+       GSList *group;
+
        GtkFormWidgetRadioPrivate *priv;
 
        g_return_val_if_fail (IS_GTK_FORM_WIDGET_RADIO (fwidget), FALSE);
@@ -150,15 +152,21 @@ gtk_form_widget_radio_set_value_stringify (GtkFormWidget *fwidget, const gchar *
        priv = GTK_FORM_WIDGET_RADIO_GET_PRIVATE (GTK_FORM_WIDGET_RADIO (fwidget));
 
        ret = FALSE;
-       active = FALSE;
 
-       g_object_get (G_OBJECT (fwidget),
-                     "widget", &w,
-                     NULL);
+       w = gtk_form_widget_get_widget (fwidget);
 
-       active = (g_strcmp0 (priv->value, value) == 0);
+       /* always set only the right group's radio button */
+       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
+       while (group != NULL)
+               {
+                       if (g_strcmp0 ((gchar *)g_object_get_data (G_OBJECT (group->data), "return-value"), value) == 0)
+                               {
+                                       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (group->data), TRUE);
+                                       break;
+                               }
 
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), active);
+                       group = g_slist_next (group);
+               }
 
        ret = TRUE;
 
index 0660349eff5feb8860ee97696849d20830a37c28..128b578fc52b4c12fe934caa5bbd64043cbcec39 100644 (file)
Binary files a/test/database.db and b/test/database.db differ
index f4ec5363673e40f79eb28d36e4ef6aa3f9908cb4..34d99966f814057de78cfa226b78ee1d16086128 100644 (file)
@@ -162,6 +162,23 @@ G_MODULE_EXPORT void
 on_btn_cancel_clicked (GtkButton *button,
                          gpointer user_data)
 {
+       GtkWidget *dialog;
+
+       if (gtk_form_is_changed (form))
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (w),
+                                                                GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                GTK_MESSAGE_QUESTION,
+                                                                GTK_BUTTONS_YES_NO,
+                                                                "Are you sure to undo without saving changes?");
+                       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_NO)
+                               {
+                                       gtk_widget_destroy (dialog);
+                                       return;
+                               }
+                       gtk_widget_destroy (dialog);
+               }
+
        gtk_form_reset (form);
 }
 
@@ -200,7 +217,7 @@ main (int argc, char **argv)
 
        gtk_init (&argc, &argv);
 
-       gdaex = gdaex_new_from_string ("SQLite://DB_DIR=test;DB_NAME=database.db");
+       gdaex = gdaex_new_from_string ("SQLite://DB_DIR=" GUIDIR ";DB_NAME=database.db");
        if (gdaex == NULL)
                {
                        return 0;
index dc974ef3ae44617bde1b2fea61b59c674e417836..194dd96ded9970a9d2dcefdadbfa28bb115b4641 100644 (file)
@@ -17,7 +17,7 @@
           <object class="GtkTable" id="table1">
             <property name="visible">True</property>
             <property name="border_width">3</property>
-            <property name="n_rows">7</property>
+            <property name="n_rows">8</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">3</property>
             <property name="row_spacing">3</property>
                 <property name="bottom_attach">7</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Sex</property>
+              </object>
+              <packing>
+                <property name="top_attach">7</property>
+                <property name="bottom_attach">8</property>
+                <property name="x_options">GTK_FILL</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkRadioButton" id="rbtnNone">
+                    <property name="label" translatable="yes">None</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="rbtnMale">
+                    <property name="label" translatable="yes">Male</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">rbtnNone</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="rbtnFemale">
+                    <property name="label" translatable="yes">Female</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">rbtnNone</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">7</property>
+                <property name="bottom_attach">8</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
index f9e6134bebbe305c9426a30ee88246e7368e6e6d..0889f42a9f6245cb38256a25b52e1f1ca7e8fb0b 100644 (file)
                </field>
        </widget>
 
+       <widget type="radio" name="rbtnNone">
+               <return-value />
+               <field type="text" name="sex">
+               </field>
+       </widget>
+
+       <widget type="radio" name="rbtnMale">
+               <return-value>M</return-value>
+               <field type="text" name="sex">
+               </field>
+       </widget>
+
+       <widget type="radio" name="rbtnFemale">
+               <return-value>F</return-value>
+               <field type="text" name="sex">
+               </field>
+       </widget>
+
 </gtkform>