From: Andrea Zagli Date: Sat, 2 Apr 2011 09:32:33 +0000 (+0200) Subject: Bugfixes and memory leaks. X-Git-Tag: 0.1.6~7 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=7bb75eb413b4e6aeae5013fb41a6bed66b47d788;p=libgtkform Bugfixes and memory leaks. --- diff --git a/src/fielddatetime.c b/src/fielddatetime.c index 9b52786..d304094 100644 --- a/src/fielddatetime.c +++ b/src/fielddatetime.c @@ -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; } diff --git a/src/fieldtext.c b/src/fieldtext.c index 5b8b5e2..ae168da 100644 --- a/src/fieldtext.c +++ b/src/fieldtext.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Andrea Zagli + * Copyright (C) 2005-2011 Andrea Zagli * * 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; } diff --git a/src/widgetradio.c b/src/widgetradio.c index b9aab81..552ac6f 100644 --- a/src/widgetradio.c +++ b/src/widgetradio.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Andrea Zagli + * Copyright (C) 2005-2011 Andrea Zagli * * 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; diff --git a/test/database.db b/test/database.db index 0660349..128b578 100644 Binary files a/test/database.db and b/test/database.db differ diff --git a/test/from_xml_with_db.c b/test/from_xml_with_db.c index f4ec536..34d9996 100644 --- a/test/from_xml_with_db.c +++ b/test/from_xml_with_db.c @@ -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; diff --git a/test/test_db.gui b/test/test_db.gui index dc974ef..194dd96 100644 --- a/test/test_db.gui +++ b/test/test_db.gui @@ -17,7 +17,7 @@ True 3 - 7 + 8 2 3 3 @@ -222,6 +222,69 @@ 7 + + + True + 0 + Sex + + + 7 + 8 + GTK_FILL + GTK_FILL + + + + + True + + + None + True + True + False + True + True + + + 0 + + + + + Male + True + True + False + True + rbtnNone + + + 1 + + + + + Female + True + True + False + True + rbtnNone + + + 2 + + + + + 1 + 2 + 7 + 8 + + False diff --git a/test/test_db.xml b/test/test_db.xml index f9e6134..0889f42 100644 --- a/test/test_db.xml +++ b/test/test_db.xml @@ -46,4 +46,22 @@ + + + + + + + + M + + + + + + F + + + +