[libgda/LIBGDA_4.2] Added GdaSet:validate-changes and GdaHolder:validate-changes properties
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] Added GdaSet:validate-changes and GdaHolder:validate-changes properties
- Date: Sat, 10 Mar 2012 13:50:47 +0000 (UTC)
commit 67d345e54a470ae4f9c876bf66a17f4aba9b9f29
Author: Vivien Malerba <malerba gnome-db org>
Date: Thu Mar 1 19:26:40 2012 +0100
Added GdaSet:validate-changes and GdaHolder:validate-changes properties
libgda/gda-holder.c | 65 ++++++++++++++++++++++++++++++++++++---------------
libgda/gda-set.c | 56 ++++++++++++++++++++++++++++++++++++-------
2 files changed, 93 insertions(+), 28 deletions(-)
---
diff --git a/libgda/gda-holder.c b/libgda/gda-holder.c
index c226a02..a10ffd8 100644
--- a/libgda/gda-holder.c
+++ b/libgda/gda-holder.c
@@ -95,7 +95,8 @@ enum
PROP_SOURCE_MODEL,
PROP_SOURCE_COLUMN,
PROP_GDA_TYPE,
- PROP_NOT_NULL
+ PROP_NOT_NULL,
+ PROP_VALIDATE_CHANGES
};
@@ -122,6 +123,8 @@ struct _GdaHolderPrivate
gint source_col;
GdaMutex *mutex;
+
+ gboolean validate_changes;
};
/* module error */
@@ -314,6 +317,18 @@ gda_holder_class_init (GdaHolderClass *class)
"with the source-model property",
0, G_MAXINT, 0,
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
+ /**
+ * GdaHolder:validate-changes:
+ *
+ * Defines if the "validate-change" signal gets emitted when
+ * the holder's value changes.
+ *
+ * Since: 5.2.0
+ */
+ g_object_class_install_property (object_class, PROP_VALIDATE_CHANGES,
+ g_param_spec_boolean ("validate-changes", NULL, "Defines if the validate-change signal is emitted on value change", TRUE,
+ (G_PARAM_READABLE | G_PARAM_WRITABLE)));
/* extra */
gda_holder_attributes_manager = gda_attributes_manager_new (TRUE, holder_attribute_set_cb, NULL);
@@ -352,6 +367,8 @@ gda_holder_init (GdaHolder *holder)
holder->priv->source_col = 0;
holder->priv->mutex = gda_mutex_new ();
+
+ holder->priv->validate_changes = TRUE;
}
/**
@@ -662,6 +679,9 @@ gda_holder_set_property (GObject *object,
case PROP_SOURCE_COLUMN:
holder->priv->source_col = g_value_get_int (value);
break;
+ case PROP_VALIDATE_CHANGES:
+ holder->priv->validate_changes = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -715,7 +735,10 @@ gda_holder_get_property (GObject *object,
break;
case PROP_SOURCE_COLUMN:
g_value_set_int (value, holder->priv->source_col);
- break;
+ break;
+ case PROP_VALIDATE_CHANGES:
+ g_value_set_boolean (value, holder->priv->validate_changes);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -1036,19 +1059,21 @@ real_gda_holder_set_value (GdaHolder *holder, GValue *value, gboolean do_copy, G
}
/* check if we are allowed to change value */
- GError *lerror = NULL;
- g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, value, &lerror);
- if (lerror) {
- /* change refused by signal callback */
+ if (holder->priv->validate_changes) {
+ GError *lerror = NULL;
+ g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, value, &lerror);
+ if (lerror) {
+ /* change refused by signal callback */
#ifdef DEBUG_HOLDER
- g_print ("Holder change refused %p (ERROR %s)\n", holder,
- lerror->message);
+ g_print ("Holder change refused %p (ERROR %s)\n", holder,
+ lerror->message);
#endif
- g_propagate_error (error, lerror);
- if (!do_copy)
- gda_value_free (value);
- gda_holder_unlock ((GdaLockable*) holder);
- return FALSE;
+ g_propagate_error (error, lerror);
+ if (!do_copy)
+ gda_value_free (value);
+ gda_holder_unlock ((GdaLockable*) holder);
+ return FALSE;
+ }
}
/* new valid status */
@@ -1184,12 +1209,14 @@ real_gda_holder_set_const_value (GdaHolder *holder, const GValue *value,
}
/* check if we are allowed to change value */
- GError *lerror = NULL;
- g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, value, &lerror);
- if (lerror) {
- /* change refused by signal callback */
- g_propagate_error (error, lerror);
- return NULL;
+ if (holder->priv->validate_changes) {
+ GError *lerror = NULL;
+ g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, value, &lerror);
+ if (lerror) {
+ /* change refused by signal callback */
+ g_propagate_error (error, lerror);
+ return NULL;
+ }
}
/* new valid status */
diff --git a/libgda/gda-set.c b/libgda/gda-set.c
index a9e1ba0..d7b3b28 100644
--- a/libgda/gda-set.c
+++ b/libgda/gda-set.c
@@ -75,7 +75,8 @@ enum
PROP_ID,
PROP_NAME,
PROP_DESCR,
- PROP_HOLDERS
+ PROP_HOLDERS,
+ PROP_VALIDATE_CHANGES
};
/* signals */
@@ -103,6 +104,7 @@ struct _GdaSetPrivate
GHashTable *holders_hash; /* key = GdaHoler ID, value = GdaHolder */
GArray *holders_array;
gboolean read_only;
+ gboolean validate_changes;
};
static void
@@ -130,11 +132,29 @@ gda_set_set_property (GObject *object,
case PROP_HOLDERS: {
/* add the holders */
GSList* holders;
- for (holders = (GSList*) g_value_get_pointer(value); holders; holders = holders->next)
+ for (holders = (GSList*) g_value_get_pointer (value); holders; holders = holders->next)
gda_set_real_add_holder (set, GDA_HOLDER (holders->data));
compute_public_data (set);
break;
}
+ case PROP_VALIDATE_CHANGES:
+ if (set->priv->validate_changes != g_value_get_boolean (value)) {
+ GSList *list;
+ set->priv->validate_changes = g_value_get_boolean (value);
+ for (list = set->holders; list; list = list->next) {
+ GdaHolder *holder = (GdaHolder*) list->data;
+ g_object_set ((GObject*) holder, "validate-changes",
+ set->priv->validate_changes, NULL);
+ if (set->priv->validate_changes)
+ g_signal_connect ((GObject*) holder, "validate-change",
+ G_CALLBACK (validate_change_holder_cb), set);
+ else
+ g_signal_handlers_disconnect_by_func ((GObject*) holder,
+ G_CALLBACK (validate_change_holder_cb),
+ set);
+ }
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -163,6 +183,9 @@ gda_set_get_property (GObject *object,
case PROP_DESCR:
g_value_set_string (value, set->priv->descr);
break;
+ case PROP_VALIDATE_CHANGES:
+ g_value_set_boolean (value, set->priv->validate_changes);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -381,7 +404,18 @@ gda_set_class_init (GdaSetClass *class)
g_param_spec_pointer ("holders", "GSList of GdaHolders",
"GdaHolder objects the set should contain", (
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)));
-
+ /**
+ * GdaSet:validate-changes:
+ *
+ * Defines if the "validate-set" signal gets emitted when
+ * any holder in the data set changes. This property also affects the
+ * GdaHolder:validate-changes property.
+ *
+ * Since: 5.2.0
+ */
+ g_object_class_install_property (object_class, PROP_VALIDATE_CHANGES,
+ g_param_spec_boolean ("validate-changes", NULL, "Defines if the validate-set signal is emitted", TRUE,
+ (G_PARAM_READABLE | G_PARAM_WRITABLE)));
object_class->dispose = gda_set_dispose;
object_class->finalize = gda_set_finalize;
}
@@ -397,6 +431,7 @@ gda_set_init (GdaSet *set)
set->priv->holders_hash = g_hash_table_new (g_str_hash, g_str_equal);
set->priv->holders_array = NULL;
set->priv->read_only = FALSE;
+ set->priv->validate_changes = TRUE;
}
@@ -982,8 +1017,9 @@ gda_set_remove_holder (GdaSet *set, GdaHolder *holder)
g_return_if_fail (set->priv);
g_return_if_fail (g_slist_find (set->holders, holder));
- g_signal_handlers_disconnect_by_func (G_OBJECT (holder),
- G_CALLBACK (validate_change_holder_cb), set);
+ if (set->priv->validate_changes)
+ g_signal_handlers_disconnect_by_func (G_OBJECT (holder),
+ G_CALLBACK (validate_change_holder_cb), set);
if (! set->priv->read_only) {
g_signal_handlers_disconnect_by_func (G_OBJECT (holder),
G_CALLBACK (changed_holder_cb), set);
@@ -1088,8 +1124,9 @@ gda_set_dispose (GObject *object)
/* free the holders list */
if (set->holders) {
for (list = set->holders; list; list = list->next) {
- g_signal_handlers_disconnect_by_func (G_OBJECT (list->data),
- G_CALLBACK (validate_change_holder_cb), set);
+ if (set->priv->validate_changes)
+ g_signal_handlers_disconnect_by_func (G_OBJECT (list->data),
+ G_CALLBACK (validate_change_holder_cb), set);
if (! set->priv->read_only) {
g_signal_handlers_disconnect_by_func (G_OBJECT (list->data),
G_CALLBACK (changed_holder_cb), set);
@@ -1321,8 +1358,9 @@ gda_set_real_add_holder (GdaSet *set, GdaHolder *holder)
set->priv->holders_array = NULL;
}
g_object_ref (holder);
- g_signal_connect (G_OBJECT (holder), "validate-change",
- G_CALLBACK (validate_change_holder_cb), set);
+ if (set->priv->validate_changes)
+ g_signal_connect (G_OBJECT (holder), "validate-change",
+ G_CALLBACK (validate_change_holder_cb), set);
if (! set->priv->read_only) {
g_signal_connect (G_OBJECT (holder), "changed",
G_CALLBACK (changed_holder_cb), set);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]