...
 
Commits (3)
......@@ -760,7 +760,7 @@ run_context_push_with_stmt (GdaReportEngine *engine, RunContext *context, GdaCon
GdaHolder *param;
GValue *value;
gchar *name;
param = gda_holder_new (G_TYPE_INT);
param = gda_holder_new (G_TYPE_INT, "id");
value = gda_value_new (G_TYPE_INT);
g_value_set_int (value, gda_data_model_get_n_rows (model));
if (! gda_holder_set_value (param, value, error)) {
......
......@@ -500,12 +500,10 @@ paramlist_param_attr_changed_cb (G_GNUC_UNUSED GdaSet *paramlist, GdaHolder *par
attrs |= toset ? 0 : GDA_VALUE_ATTR_CAN_BE_NULL;
mask |= GDA_VALUE_ATTR_CAN_BE_NULL;
defv = gda_holder_get_attribute (param, GDA_ATTRIBUTE_IS_DEFAULT);
if (defv && (G_VALUE_TYPE (defv) == G_TYPE_BOOLEAN) && g_value_get_boolean (defv)) {
if (gda_holder_value_is_default (param)) {
attrs |= GDA_VALUE_ATTR_IS_DEFAULT;
mask |= GDA_VALUE_ATTR_IS_DEFAULT;
}
g_signal_handlers_block_by_func (G_OBJECT (entry),
G_CALLBACK (entry_contents_modified), sentry);
gdaui_data_entry_set_attributes (GDAUI_DATA_ENTRY (entry), attrs, mask);
......@@ -912,14 +910,7 @@ create_entry_widget (SingleEntry *sentry)
value = default_val;
/* create entry */
plugin_val = gda_holder_get_attribute (param, GDAUI_ATTRIBUTE_PLUGIN);
if (plugin_val) {
if (G_VALUE_TYPE (plugin_val) == G_TYPE_STRING)
plugin = g_value_get_string (plugin_val);
else
g_warning (_("The '%s' attribute should be a G_TYPE_STRING value"),
GDAUI_ATTRIBUTE_PLUGIN);
}
g_object_get (param, "plugin", &plugin, NULL);
entry = GTK_WIDGET (gdaui_new_data_entry (type, plugin));
sentry->entry = GDAUI_DATA_ENTRY (entry);
......@@ -1300,8 +1291,7 @@ load_xml_layout_column (GdauiBasicForm *form, xmlNodePtr box_node)
if (plugin && sentry->single_param) {
GValue *value;
value = gda_value_new_from_string ((gchar*) plugin, G_TYPE_STRING);
gda_holder_set_attribute_static (sentry->single_param,
GDAUI_ATTRIBUTE_PLUGIN, value);
g_object_set (sentry->single_param, "plugin", value, NULL);
gda_value_free (value);
}
if (plugin)
......
......@@ -55,6 +55,7 @@ catch_css_parsing_errors (GtkCssProvider *provider,
g_warning (_("Error parsing CSS: %s"), error->message);
}
extern void _gdaui_register_resource (void);
/**
* gdaui_init:
*
......
......@@ -707,14 +707,7 @@ create_columns_data (GdauiRawGrid *grid)
if (!title)
title = g_strdup (_("No title"));
plugin_val = gda_holder_get_attribute (param, GDAUI_ATTRIBUTE_PLUGIN);
if (plugin_val) {
if (G_VALUE_TYPE (plugin_val) == G_TYPE_STRING)
plugin = g_value_get_string (plugin_val);
else
g_warning (_("The '%s' attribute should be a G_TYPE_STRING value"),
GDAUI_ATTRIBUTE_PLUGIN);
}
g_object_get (param, "plugin", &plugin, NULL);
renderer = _gdaui_new_cell_renderer (g_type, plugin);
cdata->data_cell = GTK_CELL_RENDERER (g_object_ref_sink ((GObject*) renderer));
g_hash_table_insert (priv->columns_hash, renderer, cdata);
......@@ -856,8 +849,7 @@ reset_columns_in_xml_layout (GdauiRawGrid *grid, xmlNodePtr grid_node)
if (plugin && cdata->single_param) {
GValue *value;
value = gda_value_new_from_string ((gchar*) plugin, G_TYPE_STRING);
gda_holder_set_attribute_static (cdata->single_param,
GDAUI_ATTRIBUTE_PLUGIN, value);
g_object_set (cdata->single_param, "plugin", value, NULL);
gda_value_free (value);
}
if (plugin)
......
......@@ -1954,8 +1954,8 @@ create_internal_provider (const gchar *path,
GValue *value;
#define GDAUI_ATTRIBUTE_PLUGIN "__gdaui_attr_plugin"
value = gda_value_new_from_string ("string:HIDDEN=true", G_TYPE_STRING);
gda_holder_set_attribute_static (h, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
g_object_set (h, "plugin", value, NULL);
gda_value_free (value);
}
info->icon_id = icon_id ? g_strdup (icon_id) : g_strdup (prov_name);
......
......@@ -40,7 +40,7 @@ extern GdaAttributesManager *gda_holder_attributes_manager;
/* private structure */
typedef struct
{
GdaDataModel *data_model; /* may be %NULL because there is only a weak ref on it */
GWeakRef data_model; /* may be %NULL because there is only a weak ref on it */
gulong model_changes_signals[3];
gboolean keep_param_changes;
gint row; /* -1 if row is unknown */
......@@ -180,7 +180,7 @@ static void
gda_data_model_iter_init (GdaDataModelIter *iter)
{
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
priv->data_model = NULL;
g_weak_ref_set (&priv->data_model, NULL);
priv->row = -1;
priv->model_changes_signals[0] = 0;
priv->model_changes_signals[1] = 0;
......@@ -191,9 +191,24 @@ gda_data_model_iter_init (GdaDataModelIter *iter)
static void
model_row_updated_cb (GdaDataModel *model, gint row, GdaDataModelIter *iter)
{
g_return_if_fail (model != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL (model));
g_return_if_fail (iter != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL_ITER (iter));
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
g_assert (model == priv->data_model);
GdaDataModel *obj = g_weak_ref_get (&priv->data_model);
if (obj == NULL) {
g_warning (_("Iter has an invalid/non-existent reference to a data model"));
return;
}
if (model != obj) {
g_warning (_("Referenced data model in iterator doesn't belong to given data model"));
g_object_unref (obj);
return;
}
g_object_unref (obj);
/* sync parameters with the new values in row */
if (priv->row == row) {
priv->keep_param_changes = TRUE;
......@@ -205,6 +220,11 @@ model_row_updated_cb (GdaDataModel *model, gint row, GdaDataModelIter *iter)
static void
model_row_removed_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaDataModelIter *iter)
{
g_return_if_fail (model != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL (model));
g_return_if_fail (iter != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL_ITER (iter));
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
if (priv->row < 0)
......@@ -227,6 +247,11 @@ model_row_removed_cb (G_GNUC_UNUSED GdaDataModel *model, gint row, GdaDataModelI
static void
define_holder_for_data_model_column (GdaDataModel *model, gint col, GdaDataModelIter *iter)
{
g_return_if_fail (model != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL (model));
g_return_if_fail (iter != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL_ITER (iter));
gchar *str;
GdaHolder *param;
GdaColumn *column;
......@@ -297,6 +322,11 @@ define_holder_for_data_model_column (GdaDataModel *model, gint col, GdaDataModel
static void
model_reset_cb (GdaDataModel *model, GdaDataModelIter *iter)
{
g_return_if_fail (model != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL (model));
g_return_if_fail (iter != NULL);
g_return_if_fail (GDA_IS_DATA_MODEL_ITER (iter));
gint row;
row = gda_data_model_iter_get_row (iter);
......@@ -368,10 +398,13 @@ validate_holder_change_cb (GdaSet *paramlist, GdaHolder *param, const GValue *ne
iter = GDA_DATA_MODEL_ITER (paramlist);
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
GdaDataModel *model = g_weak_ref_get (&priv->data_model);
g_return_val_if_fail (priv->data_model != NULL, NULL);
g_return_val_if_fail (GDA_IS_DATA_MODEL (priv->data_model), NULL);
if (model == NULL) {
g_set_error (&error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_INVALID,
_("Invalid data model. Can't validate holder"));
return error;
}
if (new_value)
nvalue = (GValue*) new_value;
......@@ -379,9 +412,9 @@ validate_holder_change_cb (GdaSet *paramlist, GdaHolder *param, const GValue *ne
nvalue = gda_value_new_null();
iter = (GdaDataModelIter *) paramlist;
if (!priv->keep_param_changes && (priv->row >= 0) && (GDA_IS_DATA_MODEL (priv->data_model))) {
g_signal_handler_block (priv->data_model, priv->model_changes_signals [0]);
g_signal_handler_block (priv->data_model, priv->model_changes_signals [1]);
if (!priv->keep_param_changes && (priv->row >= 0) && (GDA_IS_DATA_MODEL (model))) {
g_signal_handler_block (model, priv->model_changes_signals [0]);
g_signal_handler_block (model, priv->model_changes_signals [1]);
/* propagate the value update to the data model */
col = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (param), "model_col")) - 1;
......@@ -395,18 +428,22 @@ validate_holder_change_cb (GdaSet *paramlist, GdaHolder *param, const GValue *ne
}
else {
g_print ("using Data Model default set_value_at\n");
gda_data_model_set_value_at ((GdaDataModel *) priv->data_model, col, priv->row, nvalue, &error);
gda_data_model_set_value_at (model, col, priv->row, nvalue, &error);
}
g_signal_handler_unblock (priv->data_model, priv->model_changes_signals [0]);
g_signal_handler_unblock (priv->data_model, priv->model_changes_signals [1]);
g_signal_handler_unblock (model, priv->model_changes_signals [0]);
g_signal_handler_unblock (model, priv->model_changes_signals [1]);
}
if (!new_value)
gda_value_free (nvalue);
if (!error && GDA_SET_CLASS(gda_data_model_iter_parent_class)->validate_holder_change)
if (!error && GDA_SET_CLASS(gda_data_model_iter_parent_class)->validate_holder_change) {
g_object_unref (model);
/* for the parent class */
return (GDA_SET_CLASS(gda_data_model_iter_parent_class))->validate_holder_change (paramlist, param, new_value);
}
g_object_unref (model);
return error;
}
......@@ -430,13 +467,21 @@ holder_attr_changed_cb (GdaSet *paramlist, GdaHolder *param, const gchar *att_na
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
if (!GDA_IS_DATA_PROXY (priv->data_model))
GdaDataModel *model = g_weak_ref_get (&priv->data_model);
if (model == NULL) {
return;
}
if (!GDA_IS_DATA_PROXY (model)) {
g_object_unref (model);
return;
}
if (!strcmp (att_name, GDA_ATTRIBUTE_IS_DEFAULT) &&
!priv->keep_param_changes && (priv->row >= 0)) {
g_signal_handler_block (priv->data_model, priv->model_changes_signals [0]);
g_signal_handler_block (priv->data_model, priv->model_changes_signals [1]);
g_signal_handler_block (model, priv->model_changes_signals [0]);
g_signal_handler_block (model, priv->model_changes_signals [1]);
/* propagate the value update to the data model */
col = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (param), "model_col")) - 1;
......@@ -445,17 +490,19 @@ holder_attr_changed_cb (GdaSet *paramlist, GdaHolder *param, const gchar *att_na
if (att_value && g_value_get_boolean (att_value))
toset = TRUE;
if (toset && gda_holder_get_default_value (param))
gda_data_proxy_alter_value_attributes (GDA_DATA_PROXY (priv->data_model),
gda_data_proxy_alter_value_attributes (GDA_DATA_PROXY (model),
priv->row, col,
GDA_VALUE_ATTR_CAN_BE_DEFAULT | GDA_VALUE_ATTR_IS_DEFAULT);
g_signal_handler_unblock (priv->data_model, priv->model_changes_signals [0]);
g_signal_handler_unblock (priv->data_model, priv->model_changes_signals [1]);
g_signal_handler_unblock (model, priv->model_changes_signals [0]);
g_signal_handler_unblock (model, priv->model_changes_signals [1]);
}
/* for the parent class */
if ((GDA_SET_CLASS(gda_data_model_iter_parent_class))->holder_attr_changed)
(GDA_SET_CLASS(gda_data_model_iter_parent_class))->holder_attr_changed (paramlist, param, att_name, att_value);
g_object_unref (model);
}
static void
......@@ -468,13 +515,12 @@ gda_data_model_iter_finalize (GObject *object)
iter = GDA_DATA_MODEL_ITER (object);
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
if (priv->data_model) {
g_signal_handler_disconnect (priv->data_model, priv->model_changes_signals [0]);
g_signal_handler_disconnect (priv->data_model, priv->model_changes_signals [1]);
g_signal_handler_disconnect (priv->data_model, priv->model_changes_signals [2]);
g_object_remove_weak_pointer (G_OBJECT (priv->data_model),
(gpointer*) &(priv->data_model));
priv->data_model = NULL;
GdaDataModel *model = g_weak_ref_get (&priv->data_model);
if (model != NULL) {
g_signal_handler_disconnect (model, priv->model_changes_signals [0]);
g_signal_handler_disconnect (model, priv->model_changes_signals [1]);
g_signal_handler_disconnect (model, priv->model_changes_signals [2]);
g_object_unref (model);
}
/* parent class */
......@@ -496,25 +542,26 @@ gda_data_model_iter_set_property (GObject *object,
case PROP_DATA_MODEL: {
GdaDataModel *model;
GObject* ptr = g_value_get_object (value);
g_return_if_fail (ptr && GDA_IS_DATA_MODEL (ptr));
GObject* ptr = g_value_dup_object (value);
if (!GDA_IS_DATA_MODEL (ptr)) {
g_object_unref (ptr);
g_warning (_("Invalid data model object. Can't set property"));
return;
}
model = GDA_DATA_MODEL (ptr);
if (priv->data_model) {
if (priv->data_model == model)
GdaDataModel *current = g_weak_ref_get (&priv->data_model);
if (current != NULL) {
if (current == model)
return;
g_signal_handler_disconnect (priv->data_model,
g_signal_handler_disconnect (current,
priv->model_changes_signals [0]);
g_signal_handler_disconnect (priv->data_model,
g_signal_handler_disconnect (current,
priv->model_changes_signals [1]);
g_signal_handler_disconnect (priv->data_model,
g_signal_handler_disconnect (current,
priv->model_changes_signals [2]);
g_object_remove_weak_pointer (G_OBJECT (priv->data_model),
(gpointer*) &(priv->data_model));
}
priv->data_model = model;
g_object_add_weak_pointer (G_OBJECT (priv->data_model),
(gpointer*) &(priv->data_model));
g_weak_ref_set (&priv->data_model, model);
priv->model_changes_signals [0] = g_signal_connect (G_OBJECT (model), "row-updated",
G_CALLBACK (model_row_updated_cb),
......@@ -525,6 +572,7 @@ gda_data_model_iter_set_property (GObject *object,
priv->model_changes_signals [2] = g_signal_connect (G_OBJECT (model), "reset",
G_CALLBACK (model_reset_cb), iter);
model_reset_cb (GDA_DATA_MODEL (ptr), iter);
g_object_unref (ptr);
break;
}
case PROP_FORCED_MODEL: {
......@@ -561,11 +609,23 @@ gda_data_model_iter_get_property (GObject *object,
if (priv) {
switch (param_id) {
case PROP_DATA_MODEL:
g_value_set_object (value, G_OBJECT (priv->data_model));
{
GObject *obj = g_weak_ref_get (&priv->data_model);
g_value_set_object (value, obj);
if (obj != NULL) {
g_object_unref (obj);
}
}
break;
case PROP_FORCED_MODEL:
g_warning ("Deprecated property, not to be used");
g_value_set_object (value, G_OBJECT (priv->data_model));
{
g_warning ("Deprecated property, not to be used");
GObject *obj = g_weak_ref_get (&priv->data_model);
g_value_set_object (value, obj);
if (obj != NULL) {
g_object_unref (obj);
}
}
break;
case PROP_CURRENT_ROW:
g_value_set_int (value, priv->row);
......@@ -624,12 +684,14 @@ real_gda_data_model_iter_move_to_row (GdaDataModelIter *iter, gint row)
g_return_val_if_fail (GDA_IS_DATA_MODEL_ITER (iter), FALSE);
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
GdaDataModel *model;
model = priv->data_model;
g_return_val_if_fail (model, FALSE);
GdaDataModel *model = g_weak_ref_get (&priv->data_model);
gboolean ret = FALSE;
return gda_data_model_iter_move_to_row_default (model, iter, row);
ret = gda_data_model_iter_move_to_row_default (model, iter, row);
if (model != NULL) {
g_object_unref (model);
}
return ret;
}
static void
......@@ -744,12 +806,15 @@ real_gda_data_model_iter_move_next (GdaDataModelIter *iter)
g_return_val_if_fail (GDA_IS_DATA_MODEL_ITER (iter), FALSE);
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
gboolean ret = FALSE;
g_return_val_if_fail (priv, FALSE);
g_return_val_if_fail (priv->data_model, FALSE);
model = g_weak_ref_get (&priv->data_model);
model = priv->data_model;
return gda_data_model_iter_move_next_default (model, iter);
ret = gda_data_model_iter_move_next_default (model, iter);
if (model != NULL) {
g_object_unref (model);
}
return ret;
}
/**
......@@ -849,13 +914,15 @@ real_gda_data_model_iter_move_prev (GdaDataModelIter *iter)
g_return_val_if_fail (GDA_IS_DATA_MODEL_ITER (iter), FALSE);
GdaDataModelIterPrivate *priv = gda_data_model_iter_get_instance_private (iter);
gboolean ret = FALSE;
g_return_val_if_fail (priv, FALSE);
g_return_val_if_fail (priv->data_model, FALSE);
model = priv->data_model;
model = g_weak_ref_get (&priv->data_model);
/* default method */
return gda_data_model_iter_move_prev_default (model, iter);
ret = gda_data_model_iter_move_prev_default (model, iter);
if (model != NULL) {
g_object_unref (model);
}
return ret;
}
/**
......
......@@ -91,6 +91,7 @@ typedef enum {
GDA_DATA_MODEL_XML_FORMAT_ERROR,
GDA_DATA_MODEL_TRUNCATED_ERROR,
GDA_DATA_MODEL_INVALID,
GDA_DATA_MODEL_OTHER_ERROR
} GdaDataModelError;
......
......@@ -34,7 +34,6 @@
#include "gda-marshal.h"
#include "gda-util.h"
#include <libgda.h>
#include <libgda/gda-attributes-manager.h>
#include <libgda/gda-custom-marshal.h>
/*
......@@ -65,19 +64,16 @@ static void bound_holder_changed_cb (GdaHolder *alias_of, GdaHolder *holder);
static void full_bound_holder_changed_cb (GdaHolder *alias_of, GdaHolder *holder);
static void gda_holder_set_full_bind (GdaHolder *holder, GdaHolder *alias_of);
GdaAttributesManager *gda_holder_attributes_manager;
/* signals */
enum
{
CHANGED,
SOURCE_CHANGED,
SOURCE_CHANGED,
VALIDATE_CHANGE,
ATT_CHANGED,
LAST_SIGNAL
LAST_SIGNAL
};
static gint gda_holder_signals[LAST_SIGNAL] = { 0, 0, 0, 0 };
static gint gda_holder_signals[LAST_SIGNAL] = { 0, 0, 0 };
/* properties */
......@@ -93,7 +89,8 @@ enum
PROP_SOURCE_COLUMN,
PROP_GDA_TYPE,
PROP_NOT_NULL,
PROP_VALIDATE_CHANGES
PROP_VALIDATE_CHANGES,
PROP_PLUGIN
};
......@@ -121,6 +118,9 @@ typedef struct {
GRecMutex mutex;
gboolean validate_changes;
gchar *name;
gchar *desc;
gchar *plugin;
} GdaHolderPrivate;
G_DEFINE_TYPE_WITH_CODE (GdaHolder, gda_holder, G_TYPE_OBJECT,
G_ADD_PRIVATE (GdaHolder)
......@@ -154,13 +154,6 @@ m_validate_change (G_GNUC_UNUSED GdaHolder *holder, G_GNUC_UNUSED const GValue *
return NULL;
}
static void
holder_attribute_set_cb (GObject *obj, const gchar *att_name, const GValue *value,
G_GNUC_UNUSED gpointer data)
{
g_signal_emit (obj, gda_holder_signals[ATT_CHANGED], 0, att_name, value);
}
static void
gda_holder_class_init (GdaHolderClass *class)
{
......@@ -192,22 +185,6 @@ gda_holder_class_init (GdaHolderClass *class)
G_STRUCT_OFFSET (GdaHolderClass, changed),
NULL, NULL,
_gda_marshal_VOID__VOID, G_TYPE_NONE, 0);
/**
* GdaHolder::attribute-changed:
* @holder: the #GdaHolder
* @att_name: attribute's name
* @att_value: attribute's value
*
* Gets emitted when any @holder's attribute has changed
*/
gda_holder_signals[ATT_CHANGED] =
g_signal_new ("attribute-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GdaHolderClass, att_changed),
NULL, NULL,
_gda_marshal_VOID__STRING_VALUE, G_TYPE_NONE, 2,
G_TYPE_STRING, G_TYPE_VALUE);
/**
* GdaHolder::validate-change:
......@@ -276,6 +253,9 @@ gda_holder_class_init (GdaHolderClass *class)
"with the source-model property",
0, G_MAXINT, 0,
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
g_object_class_install_property (object_class, PROP_PLUGIN,
g_param_spec_string ("plugin", NULL, "Holder's plugin", NULL,
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
/**
* GdaHolder:validate-changes:
......@@ -288,9 +268,6 @@ gda_holder_class_init (GdaHolderClass *class)
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);
}
static void
......@@ -306,7 +283,7 @@ gda_holder_init (GdaHolder *holder)
{
GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
priv->id = NULL;
priv->id = g_strdup ("id");
priv->g_type = GDA_TYPE_NULL;
priv->full_bind = NULL;
......@@ -328,20 +305,25 @@ gda_holder_init (GdaHolder *holder)
g_rec_mutex_init (& (priv->mutex));
priv->validate_changes = TRUE;
priv->name = NULL;
priv->desc = NULL;
priv->plugin = NULL;
}
/**
* gda_holder_new:
* @type: the #GType requested
* @id: an identifiation
*
* Creates a new holder of type @type
*
* Returns: a new #GdaHolder object
*/
GdaHolder *
gda_holder_new (GType type)
gda_holder_new (GType type, const gchar *id)
{
return (GdaHolder*) g_object_new (GDA_TYPE_HOLDER, "g-type", type, NULL);
g_return_val_if_fail (id != NULL, NULL);
return (GdaHolder*) g_object_new (GDA_TYPE_HOLDER, "g-type", type, "id", id, NULL);
}
/**
......@@ -372,6 +354,12 @@ gda_holder_copy (GdaHolder *orig)
if (priv->id)
cpriv->id = g_strdup (priv->id);
if (priv->name)
cpriv->name = g_strdup (priv->name);
if (priv->desc)
cpriv->desc = g_strdup (priv->desc);
if (priv->plugin)
cpriv->plugin = g_strdup (priv->plugin);
if (priv->full_bind)
gda_holder_set_full_bind (holder, priv->full_bind);
......@@ -397,13 +385,6 @@ gda_holder_copy (GdaHolder *orig)
if (priv->default_value)
cpriv->default_value = gda_value_copy (priv->default_value);
cpriv->not_null = priv->not_null;
gda_attributes_manager_copy (gda_holder_attributes_manager, (gpointer) orig, gda_holder_attributes_manager, (gpointer) holder);
GValue *att_value;
g_value_set_boolean ((att_value = gda_value_new (G_TYPE_BOOLEAN)), cpriv->default_forced);
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_IS_DEFAULT, att_value);
gda_value_free (att_value);
gda_holder_unlock ((GdaLockable*) orig);
return holder;
......@@ -438,22 +419,23 @@ gda_holder_new_inline (GType type, const gchar *id, ...)
static GMutex serial_mutex;
static guint serial = 0;
const gchar *idm = NULL;
g_print ("Creating inline: %s", id);
holder = gda_holder_new (type);
if (id != NULL) {
idm = id;
} else {
idm = g_strdup_printf ("%d", serial++);
}
holder = gda_holder_new (type, idm);
GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
if (holder) {
GValue *value;
va_list ap;
GError *lerror = NULL;
if (id)
priv->id = g_strdup (id);
else {
g_mutex_lock (&serial_mutex);
priv->id = g_strdup_printf ("%d", serial++);
g_mutex_unlock (&serial_mutex);
}
va_start (ap, id);
value = gda_value_new (type);
if (type == G_TYPE_BOOLEAN)
......@@ -565,7 +547,22 @@ gda_holder_finalize (GObject * object)
holder = GDA_HOLDER (object);
GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
g_free (priv->id);
if (priv->id != NULL) {
g_free (priv->id);
priv->id = NULL;
}
if (priv->name != NULL) {
g_free (priv->name);
priv->name = NULL;
}
if (priv->desc != NULL) {
g_free (priv->desc);
priv->desc = NULL;
}
if (priv->plugin != NULL) {
g_free (priv->plugin);
priv->plugin = NULL;
}
g_rec_mutex_clear (& (priv->mutex));
/* parent class */
......@@ -586,14 +583,35 @@ gda_holder_set_property (GObject *object,
if (priv) {
switch (param_id) {
case PROP_ID:
g_free (priv->id);
if (priv->id != NULL) {
g_free (priv->id);
priv->id = NULL;
}
priv->id = g_value_dup_string (value);
break;
case PROP_NAME:
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_NAME, value);
if (priv->name != NULL) {
g_free (priv->name);
priv->name = NULL;
}
priv->name = g_value_dup_string (value);
g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
break;
case PROP_DESCR:
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_DESCRIPTION, value);
if (priv->desc != NULL) {
g_free (priv->desc);
priv->desc = NULL;
}
priv->desc = g_value_dup_string (value);
g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
break;
case PROP_PLUGIN:
if (priv->plugin != NULL) {
g_free (priv->plugin);
priv->plugin = NULL;
}
priv->plugin = g_value_dup_string (value);
g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
break;
case PROP_GDA_TYPE:
if (priv->g_type == GDA_TYPE_NULL) {
......@@ -664,16 +682,14 @@ gda_holder_get_property (GObject *object,
g_value_set_string (value, priv->id);
break;
case PROP_NAME:
cvalue = gda_holder_get_attribute (holder, GDA_ATTRIBUTE_NAME);
if (cvalue)
g_value_set_string (value, g_value_get_string (cvalue));
if (priv->name != NULL)
g_value_set_string (value, priv->name);
else
g_value_set_string (value, priv->id);
break;
case PROP_DESCR:
cvalue = gda_holder_get_attribute (holder, GDA_ATTRIBUTE_DESCRIPTION);
if (cvalue)
g_value_set_string (value, g_value_get_string (cvalue));
if (priv->desc != NULL)
g_value_set_string (value, priv->desc);
else
g_value_set_string (value, NULL);
break;
......@@ -1067,10 +1083,6 @@ real_gda_holder_set_value (GdaHolder *holder, GValue *value, gboolean do_copy, G
new_value && (G_VALUE_TYPE (new_value) == priv->g_type))
priv->default_forced = !gda_value_compare (priv->default_value, new_value);
}
GValue att_value = {0};
g_value_init (&att_value, G_TYPE_BOOLEAN);
g_value_set_boolean (&att_value, priv->default_forced);
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_IS_DEFAULT, &att_value);
/* real setting of the value */
if (priv->full_bind) {
......@@ -1213,10 +1225,6 @@ real_gda_holder_set_const_value (GdaHolder *holder, const GValue *value,
value && (G_VALUE_TYPE (value) == priv->g_type))
priv->default_forced = !gda_value_compare (priv->default_value, value);
}
GValue *att_value;
g_value_set_boolean ((att_value = gda_value_new (G_TYPE_BOOLEAN)), priv->default_forced);
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_IS_DEFAULT, att_value);
gda_value_free (att_value);
/* real setting of the value */
if (priv->full_bind) {
......@@ -1451,10 +1459,6 @@ gda_holder_set_value_to_default (GdaHolder *holder)
}
}
GValue *att_value;
g_value_set_boolean ((att_value = gda_value_new (G_TYPE_BOOLEAN)), TRUE);
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_IS_DEFAULT, att_value);
gda_value_free (att_value);
g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
gda_holder_unlock ((GdaLockable*) holder);
......@@ -1534,20 +1538,17 @@ gda_holder_set_default_value (GdaHolder *holder, const GValue *value)
/* check if default is equal to current value */
if (GDA_VALUE_HOLDS_NULL (value) &&
(!current || GDA_VALUE_HOLDS_NULL (current)))
(!current || GDA_VALUE_HOLDS_NULL (current))) {
priv->default_forced = TRUE;
else if ((G_VALUE_TYPE (value) == priv->g_type) &&
current && !gda_value_compare (value, current))
} else if ((G_VALUE_TYPE (value) == priv->g_type) &&
current && !gda_value_compare (value, current)) {
priv->default_forced = TRUE;
}
priv->default_value = gda_value_copy ((GValue *)value);
//g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
}
GValue *att_value;
g_value_set_boolean ((att_value = gda_value_new (G_TYPE_BOOLEAN)), priv->default_forced);
gda_holder_set_attribute_static (holder, GDA_ATTRIBUTE_IS_DEFAULT, att_value);
gda_value_free (att_value);
/* don't emit the "changed" signal */
gda_holder_unlock ((GdaLockable*) holder);
}
......@@ -1715,8 +1716,7 @@ bind_to_notify_cb (GdaHolder *bind_to, G_GNUC_UNUSED GParamSpec *pspec, GdaHolde
}
else if (priv->g_type != bpriv->g_type) {
/* break holder's binding because type differ */
g_warning (_("Cannot bind holders if their type is not the same, "
"breaking existing bind where '%s' was bound to '%s'"),
g_message (_("Cannot bind holders if their type is not the same, breaking existing bind where '%s' was bound to '%s'"),
gda_holder_get_id (holder), gda_holder_get_id (bind_to));
gda_holder_set_bind (holder, NULL, NULL);
}
......@@ -1980,67 +1980,6 @@ gda_holder_get_alphanum_id (GdaHolder *holder)
return gda_text_to_alphanum (priv->id);
}
/**
* gda_holder_get_attribute:
* @holder: a #GdaHolder
* @attribute: attribute name as a string
*
* Get the value associated to a named attribute.
*
* Attributes can have any name, but Libgda proposes some default names, see <link linkend="libgda-40-Attributes-manager.synopsis">this section</link>.
*
* Returns: a read-only #GValue, or %NULL if not attribute named @attribute has been set for @holder
*/
const GValue *
gda_holder_get_attribute (GdaHolder *holder, const gchar *attribute)
{
g_return_val_if_fail (GDA_IS_HOLDER (holder), NULL);
/*g_print ("GdaHolder %p ATTR '%s' get => '%s'\n", holder, attribute,
gda_value_stringify (gda_attributes_manager_get (gda_holder_attributes_manager, holder, attribute))); */
return gda_attributes_manager_get (gda_holder_attributes_manager, holder, attribute);
}
/**
* gda_holder_set_attribute:
* @holder: a #GdaHolder
* @attribute: attribute name
* @value: a #GValue, or %NULL
* @destroy: a function to be called when @attribute is not needed anymore, or %NULL
*
* Set the value associated to a named attribute. The @attribute string is 'stolen' by this method, and
* the memory it uses will be freed using the @destroy function when no longer needed (if @destroy is %NULL,
* then the string will not be freed at all).
*
* Attributes can have any name, but Libgda proposes some default names,
* see <link linkend="libgda-6.0-Attributes-manager.synopsis">this section</link>.
*
* For example one would use it as:
*
* <code>gda_holder_set_attribute (holder, g_strdup (my_attribute), my_value, g_free);</code>
* <code>gda_holder_set_attribute (holder, GDA_ATTRIBUTE_NAME, my_value, NULL);</code>
*
* If there is already an attribute named @attribute set, then its value is replaced with the new value (@value is
* copied), except if @value is %NULL, in which case the attribute is removed.
*/
void
gda_holder_set_attribute (GdaHolder *holder, const gchar *attribute, const GValue *value, GDestroyNotify destroy)
{
const GValue *cvalue;
g_return_if_fail (GDA_IS_HOLDER (holder));
gda_holder_lock ((GdaLockable*) holder);
cvalue = gda_attributes_manager_get (gda_holder_attributes_manager, holder, attribute);
if ((value && cvalue && !gda_value_differ (cvalue, value)) ||
(!value && !cvalue)) {
gda_holder_unlock ((GdaLockable*) holder);
return;
}
gda_attributes_manager_set_full (gda_holder_attributes_manager, holder, attribute, value, destroy);
//g_print ("GdaHolder %p ATTR '%s' set to '%s'\n", holder, attribute, gda_value_stringify (value));
gda_holder_unlock ((GdaLockable*) holder);
}
static void
gda_holder_lock (GdaLockable *lockable)
{
......
......@@ -75,7 +75,7 @@ struct _GdaHolderClass
* Each GdaHolder object is thread safe.
*/
GdaHolder *gda_holder_new (GType type);
GdaHolder *gda_holder_new (GType type, const gchar *id);
GdaHolder *gda_holder_new_inline (GType type, const gchar *id, ...);
GdaHolder *gda_holder_copy (GdaHolder *orig);
......@@ -148,20 +148,6 @@ GdaDataModel *gda_holder_get_source_model (GdaHolder *holder, gint
gboolean gda_holder_set_bind (GdaHolder *holder, GdaHolder *bind_to, GError **error);
GdaHolder *gda_holder_get_bind (GdaHolder *holder);
const GValue *gda_holder_get_attribute (GdaHolder *holder, const gchar *attribute);
void gda_holder_set_attribute (GdaHolder *holder, const gchar *attribute, const GValue *value,
GDestroyNotify destroy);
/**
* gda_holder_set_attribute_static:
* @holder: a #GdaHolder
* @attribute: attribute's name
* @value: (nullable): a #GValue, or %NULL
*
* This function is similar to gda_holder_set_attribute() but for static strings
*/
#define gda_holder_set_attribute_static(holder,attribute,value) gda_holder_set_attribute((holder),(attribute),(value),NULL)
G_END_DECLS
#endif
......@@ -651,7 +651,6 @@ static void set_remove_source (GdaSet *set, GdaSetSource *source);
static void changed_holder_cb (GdaHolder *holder, GdaSet *dataset);
static GError *validate_change_holder_cb (GdaHolder *holder, const GValue *value, GdaSet *dataset);
static void source_changed_holder_cb (GdaHolder *holder, GdaSet *dataset);
static void att_holder_changed_cb (GdaHolder *holder, const gchar *att_name, const GValue *att_value, GdaSet *dataset);
static void holder_notify_cb (GdaHolder *holder, GParamSpec *pspec, GdaSet *dataset);
......@@ -1098,7 +1097,7 @@ gda_set_new_inline (gint nb, ...)
id = va_arg (ap, char *);
type = va_arg (ap, GType);
holder = (GdaHolder *) g_object_new (GDA_TYPE_HOLDER, "g-type", type, "id", id, NULL);
holder = gda_holder_new (type, id);
value = gda_value_new (type);
if (g_type_is_a (type, G_TYPE_BOOLEAN))
......@@ -1596,8 +1595,6 @@ gda_set_remove_holder (GdaSet *set, GdaHolder *holder)
G_CALLBACK (changed_holder_cb), set);
g_signal_handlers_disconnect_by_func (G_OBJECT (holder),
G_CALLBACK (source_changed_holder_cb), set);
g_signal_handlers_disconnect_by_func (G_OBJECT (holder),
G_CALLBACK (att_holder_changed_cb), set);
}
g_signal_handlers_disconnect_by_func (holder,
G_CALLBACK (holder_notify_cb), set);
......@@ -1634,17 +1631,6 @@ source_changed_holder_cb (G_GNUC_UNUSED GdaHolder *holder, GdaSet *set)
compute_public_data (set);
}
static void
att_holder_changed_cb (GdaHolder *holder, const gchar *att_name, const GValue *att_value, GdaSet *set)
{
#ifdef GDA_DEBUG_signal
g_print (">> 'HOLDER_ATTR_CHANGED' from %s\n", __FUNCTION__);
#endif
g_signal_emit (G_OBJECT (set), gda_set_signals[HOLDER_ATTR_CHANGED], 0, holder, att_name, att_value);
#ifdef GDA_DEBUG_signal
g_print ("<< 'HOLDER_ATTR_CHANGED' from %s\n", __FUNCTION__);
#endif
}
static GError *
validate_change_holder_cb (GdaHolder *holder, const GValue *value, GdaSet *set)
......@@ -1710,8 +1696,6 @@ gda_set_dispose (GObject *object)
G_CALLBACK (changed_holder_cb), set);
g_signal_handlers_disconnect_by_func (G_OBJECT (list->data),
G_CALLBACK (source_changed_holder_cb), set);
g_signal_handlers_disconnect_by_func (G_OBJECT (list->data),
G_CALLBACK (att_holder_changed_cb), set);
}
g_object_unref (list->data);
}
......@@ -1889,24 +1873,22 @@ holder_notify_cb (GdaHolder *holder, GParamSpec *pspec, GdaSet *dataset)
g_signal_emit (dataset, gda_set_signals[HOLDER_TYPE_SET], 0, holder);
}
else if (!strcmp (pspec->name, "name")) {
#ifdef GDA_DEBUG_signal
g_print (">> 'HOLDER_ATTR_CHANGED' from %s\n", __FUNCTION__);
#endif
g_signal_emit (G_OBJECT (dataset), gda_set_signals[HOLDER_ATTR_CHANGED], 0, holder,
GDA_ATTRIBUTE_NAME, gda_holder_get_attribute (holder, GDA_ATTRIBUTE_NAME));
#ifdef GDA_DEBUG_signal
g_print ("<< 'HOLDER_ATTR_CHANGED' from %s\n", __FUNCTION__);
#endif
gchar *name = NULL;
g_object_get (dataset, "name", &name, NULL);
g_signal_emit (G_OBJECT (dataset), gda_set_signals[HOLDER_ATTR_CHANGED], 0, holder,
"name", name != NULL ? name : "NULL");
if (name != NULL) {
g_free (name);
}
}
else if (!strcmp (pspec->name, "description")) {
#ifdef GDA_DEBUG_signal
g_print (">> 'HOLDER_ATTR_CHANGED' from %s\n", __FUNCTION__);
#endif
g_signal_emit (G_OBJECT (dataset), gda_set_signals[HOLDER_ATTR_CHANGED], 0, holder,
GDA_ATTRIBUTE_DESCRIPTION, gda_holder_get_attribute (holder, GDA_ATTRIBUTE_DESCRIPTION));
#ifdef GDA_DEBUG_signal
g_print ("<< 'HOLDER_ATTR_CHANGED' from %s\n", __FUNCTION__);
#endif
gchar *desc = NULL;
g_object_get (dataset, "description", &desc, NULL);
g_signal_emit (G_OBJECT (dataset), gda_set_signals[HOLDER_ATTR_CHANGED], 0, holder,
"description", desc);
if (desc != NULL) {
g_free (desc);
}
}
}
......@@ -1924,7 +1906,7 @@ gda_set_real_add_holder (GdaSet *set, GdaHolder *holder)
* a holder B is similar to a holder A if it has the same ID
*/
hid = gda_holder_get_id (holder);
if (!hid) {
if (hid == NULL) {
g_warning (_("GdaHolder needs to have an ID"));
return FALSE;
}
......@@ -1947,8 +1929,6 @@ gda_set_real_add_holder (GdaSet *set, GdaHolder *holder)
G_CALLBACK (changed_holder_cb), set);
g_signal_connect (G_OBJECT (holder), "source-changed",
G_CALLBACK (source_changed_holder_cb), set);
g_signal_connect (G_OBJECT (holder), "attribute-changed",
G_CALLBACK (att_holder_changed_cb), set);
}
if (gda_holder_get_g_type (holder) == GDA_TYPE_NULL)
g_signal_connect (G_OBJECT (holder), "notify::g-type",
......
......@@ -453,8 +453,8 @@ get_params_foreach_func (GdaSqlAnyPart *node, GdaSet **params, GError **error)
}
if (!*params)
*params = gda_set_new (NULL);
h = gda_holder_new (pspec->g_type);
g_object_set (G_OBJECT (h), "id", pspec->name, "name", pspec->name,
h = gda_holder_new (pspec->g_type, pspec->name);
g_object_set (G_OBJECT (h), "name", pspec->name,
"description", pspec->descr, NULL);
gda_holder_set_not_null (h, ! pspec->nullok);
if (((GdaSqlExpr*) node)->value) {
......
......@@ -663,8 +663,8 @@ gda_utility_holder_load_attributes (GdaHolder *holder, xmlNodePtr node, GSList *
if (str) {
GValue *value;
#define GDAUI_ATTRIBUTE_PLUGIN "__gdaui_attr_plugin"
value = gda_value_new_from_string ((gchar*) str, G_TYPE_STRING);
gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
value = gda_value_new_from_string ((gchar*) str, G_TYPE_STRING);
g_object_set (holder, "plugin", value, NULL);
gda_value_free (value);
xmlFree (str);
}
......@@ -733,14 +733,7 @@ gda_utility_holder_load_attributes (GdaHolder *holder, xmlNodePtr node, GSList *
xmlChar *att_name;
att_name = xmlGetProp (vnode, (xmlChar*) "name");
if (att_name) {
GValue *value;
g_value_set_string ((value = gda_value_new (G_TYPE_STRING)),
(gchar*) xmlNodeGetContent (vnode));
gda_attributes_manager_set_full (gda_holder_attributes_manager,
(gpointer) holder,
(gchar*) att_name, value,
(GDestroyNotify) xmlFree);
gda_value_free (value);
g_object_set_data_full ((GObject*) holder, att_name, g_strdup ((gchar*) xmlNodeGetContent (vnode)), (GDestroyNotify) g_free);
}
vnode = vnode->next;
continue;
......
......@@ -62,7 +62,11 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
tmp = gda_connection_operation_get_sql_identifier_at (cnc, op, "/TABLE_DEF_P/TABLE_NAME", error);
if (!tmp) {
g_string_free (string, TRUE);
g_assert (*error != NULL);
if (error != NULL) {
if (*error == NULL) {
g_warning (_("Internal error, creating table in SQLite provider"));
}
}
return NULL;
}
g_string_append (string, tmp);
......
......@@ -3136,9 +3136,9 @@ make_last_inserted_set (GdaConnection *cnc, GdaStatement *stmt, sqlite3_int64 la
gchar *id;
const GValue *cvalue;
col = gda_data_model_describe_column (model, i);
h = gda_holder_new (gda_column_get_g_type (col));
id = g_strdup_printf ("+%d", i);
g_object_set (G_OBJECT (h), "id", id,
h = gda_holder_new (gda_column_get_g_type (col), id);
g_object_set (G_OBJECT (h),
"name", gda_column_get_name (col), NULL);
g_free (id);
cvalue = gda_data_model_get_value_at (model, i, 0, NULL);
......@@ -3922,8 +3922,7 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
GValue *value;
GSList *list;
holder = gda_holder_new (G_TYPE_INT);
g_object_set ((GObject*) holder, "id", "IMPACTED_ROWS", NULL);
holder = gda_holder_new (G_TYPE_INT, "IMPACTED_ROWS");
g_value_set_int ((value = gda_value_new (G_TYPE_INT)), changes);
gda_holder_take_value (holder, value, NULL);
list = g_slist_append (NULL, holder);
......
......@@ -623,9 +623,9 @@ vcontext_free (VContext *context)
void
_gda_vconnection_set_working_obj (GdaVconnectionDataModel *cnc, GObject *obj)
{
g_mutex_lock (& (cnc->priv->lock_context));
GSList *list;
if (obj) {
g_mutex_lock (& (cnc->priv->lock_context));
for (list = cnc->priv->table_data_list; list; list = list->next) {
GdaVConnectionTableData *td = (GdaVConnectionTableData*) list->data;
VContext *vc = NULL;
......@@ -660,8 +660,8 @@ _gda_vconnection_set_working_obj (GdaVconnectionDataModel *cnc, GObject *obj)
* an exception already occurred */
td->context.current_vcontext = NULL;
}
g_mutex_unlock (& (cnc->priv->lock_context));
}
g_mutex_unlock (& (cnc->priv->lock_context));
}
void
......
......@@ -2044,9 +2044,9 @@ make_last_inserted_set (GdaConnection *cnc, GdaStatement *stmt, my_ulonglong las
const GValue *cvalue;
col = gda_data_model_describe_column (model, i);
h = gda_holder_new (gda_column_get_g_type (col));
id = g_strdup_printf ("+%d", i);
g_object_set (G_OBJECT (h), "id", id, "not-null", FALSE,
h = gda_holder_new (gda_column_get_g_type (col), id);
g_object_set (G_OBJECT (h), "not-null", FALSE,
"name", gda_column_get_name (col), NULL);
g_free (id);
cvalue = gda_data_model_get_value_at (model, i, 0, NULL);
......
......@@ -1843,9 +1843,9 @@ make_last_inserted_set (GdaConnection *cnc, GdaStatement *stmt, Oid last_id)
const GValue *cvalue;
col = gda_data_model_describe_column (model, i);
h = gda_holder_new (gda_column_get_g_type (col));
id = g_strdup_printf ("+%d", i);
g_object_set (G_OBJECT (h), "id", id, "not-null", FALSE,
h = gda_holder_new (gda_column_get_g_type (col), id);
g_object_set (G_OBJECT (h), "not-null", FALSE,
"name", gda_column_get_name (col), NULL);
g_free (id);
cvalue = gda_data_model_get_value_at (model, i, 0, NULL);
......
......@@ -984,15 +984,12 @@ build_form_test_for_gtype (G_GNUC_UNUSED GdaDataHandler *dh, GType type, const g
if (model) {
GdaSet *plist;
GdaHolder *param;
GValue *value;
wid = gdaui_form_new (model);
plist = GDA_SET (gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (wid)));
param = gda_set_get_holders (plist)->data;
value = gda_value_new_from_string (plugin_name, G_TYPE_STRING);
gda_holder_set_attribute_static (param, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
g_object_set ((GObject*) param, "plugin", plugin_name, NULL);
}
else {
gchar *str;
......@@ -1016,15 +1013,12 @@ build_grid_test_for_gtype (G_GNUC_UNUSED GdaDataHandler *dh, GType type, const g
if (model) {
GdaSet *plist;
GdaHolder *param;
GValue *value;
wid = gdaui_grid_new (model);
plist = GDA_SET (gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (wid)));
param = gda_set_get_holders (plist)->data;
value = gda_value_new_from_string (plugin_name, G_TYPE_STRING);
gda_holder_set_attribute_static (param, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
g_object_set ((GObject*) param, "plugin", plugin_name, NULL);
}
else {
gchar *str;
......
......@@ -166,10 +166,9 @@ common_load_csv_file (const gchar *data_file, ...)
GdaHolder *holder;
GValue *v;
gchar *id;
holder = gda_holder_new (G_TYPE_GTYPE);
id = g_strdup_printf ("G_TYPE_%d", cnum);
g_object_set (G_OBJECT (holder), "id", id, NULL);
holder = gda_holder_new (G_TYPE_GTYPE, id);
g_free (id);
v = gda_value_new (G_TYPE_GTYPE);
......
......@@ -109,7 +109,7 @@ test1 (GError **error)
const GValue *cvalue;
GValue *value, *copy;
h = gda_holder_new (G_TYPE_STRING);
h = gda_holder_new (G_TYPE_STRING, "id");
emitted_signals_monitor_holder (h);
cvalue = gda_holder_get_value (h);
if (!gda_value_is_null (cvalue)) {
......@@ -296,17 +296,20 @@ test4 (GError **error)
}
/***/
if (gda_holder_set_value_to_default (h)) {
g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s",
"Should not set GdaHolder's value to default");
return FALSE;
}
printf ("Checking signals \"changed\" after try to set to default\n");
if (!emitted_signals_check_empty (NULL, "changed", error))
return FALSE;
/** Set a default value to NULL */
value = gda_value_new_null ();
gda_holder_set_default_value (h, value);
printf ("Checking signals \"changed\" after change default value\n");
if (!emitted_signals_check_empty (NULL, "changed", error))
return FALSE;
......@@ -331,8 +334,10 @@ test4 (GError **error)
"Could not set GdaHolder's value to default");
return FALSE;
}
printf ("Find \"changed\" signals after reset to default\n");
if (!emitted_signals_find (h, "changed", error))
return FALSE;
printf ("Checking empty signals \"changed\" after reset to default\n");
if (!emitted_signals_check_empty (NULL, "changed", error))
return FALSE;
......@@ -344,10 +349,12 @@ test4 (GError **error)
return FALSE;
}
printf ("Changing value to 'hey'\n");
/** set value to "hey" */
value = gda_value_new_from_string ("hey", G_TYPE_STRING);
if (!gda_holder_set_value (h, value, error))
return FALSE;
printf ("Checking signals \"changed\"");
if (!emitted_signals_find (h, "changed", error))
return FALSE;
if (!emitted_signals_check_empty (NULL, "changed", error))
......@@ -724,7 +731,7 @@ test8 (GError **error)
GdaHolder *h;
GValue *value;
h = gda_holder_new (G_TYPE_STRING);
h = gda_holder_new (G_TYPE_STRING, "id");
emitted_signals_monitor_holder (h);
emitted_signals_reset ();
......@@ -758,7 +765,7 @@ test9 (GError **error)
gchar *model_data="1,John\n2,Jack";
gint col;
h = gda_holder_new (G_TYPE_STRING);
h = gda_holder_new (G_TYPE_STRING, "id");
emitted_signals_monitor_holder (h);
emitted_signals_reset ();
......@@ -840,7 +847,7 @@ test10 (GError **error)
const GValue *cvalue;
GValue *value;
h = gda_holder_new (G_TYPE_STRING);
h = gda_holder_new (G_TYPE_STRING, "id");
emitted_signals_monitor_holder (h);
/***/
......@@ -912,7 +919,7 @@ test11 (GError **error)
const GValue *cvalue;
GValue *value;
h = gda_holder_new (GDA_TYPE_NULL);
h = gda_holder_new (GDA_TYPE_NULL, "id");
emitted_signals_monitor_holder (h);
/***/
......@@ -965,48 +972,13 @@ test12 (GError **error)
const GValue *cvalue;
GValue *value;
h = gda_holder_new (GDA_TYPE_NULL);
h = gda_holder_new (GDA_TYPE_NULL, "id");
/***/
value = gda_value_new_from_string ("my string", G_TYPE_STRING);
if (gda_holder_get_attribute (h, "attname1")) {
g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s",
"gda_holder_get_attribute() should have retunred NULL");
return FALSE;
}
gda_holder_set_attribute_static (h, "attname1", value);
gda_value_free (value);
cvalue = gda_holder_get_attribute (h, "attname1");
if (!cvalue) {
g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s",
"gda_holder_get_attribute() should have retunred a value");
return FALSE;
}
value = gda_value_new_from_string ("my string", G_TYPE_STRING);
if (gda_value_differ (cvalue, value)) {
g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s",
"gda_holder_get_attribute() retunred a wrong value");
return FALSE;
}
/***/
GdaHolder *copy;
gchar *name;
g_object_set (G_OBJECT (h), "name", "thename", NULL);
copy = gda_holder_copy (h);
cvalue = gda_holder_get_attribute (copy, "attname1");
if (!cvalue) {
g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s",
"gda_holder_get_attribute() should have retunred a value");
return FALSE;
}
if (gda_value_differ (cvalue, value)) {
g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s",
"gda_holder_get_attribute() retunred a wrong value");
return FALSE;
}
gda_value_free (value);
g_object_get (G_OBJECT (copy), "name", &name, NULL);
if (strcmp (name, "thename")) {
......@@ -1027,8 +999,8 @@ static gboolean
test13 (GError **error)
{
GdaHolder *h1, *h2;
h1 = gda_holder_new (GDA_TYPE_NULL);
h2 = gda_holder_new (GDA_TYPE_NULL);
h1 = gda_holder_new (GDA_TYPE_NULL, "id1");
h2 = gda_holder_new (GDA_TYPE_NULL, "id2");
if (! gda_holder_set_bind (h1, h2, error)) {
g_object_unref (h1);
g_object_unref (h2);
......@@ -1046,8 +1018,8 @@ test13 (GError **error)
g_object_unref (h2);
/* another test */
h1 = gda_holder_new (GDA_TYPE_NULL);
h2 = gda_holder_new (G_TYPE_INT);
h1 = gda_holder_new (GDA_TYPE_NULL, "1");
h2 = gda_holder_new (G_TYPE_INT, "2");
if (! gda_holder_set_bind (h1, h2, error)) {
g_object_unref (h1);
g_object_unref (h2);
......@@ -1064,8 +1036,8 @@ test13 (GError **error)
g_object_unref (h2);
/* another test */
h1 = gda_holder_new (G_TYPE_STRING);
h2 = gda_holder_new (GDA_TYPE_NULL);
h1 = gda_holder_new (G_TYPE_STRING, "1");
h2 = gda_holder_new (GDA_TYPE_NULL, "2");
if (! gda_holder_set_bind (h1, h2, error)) {
g_object_unref (h1);
g_object_unref (h2);
......@@ -1090,8 +1062,8 @@ test13 (GError **error)
g_object_unref (h2);
/* another test */
h1 = gda_holder_new (G_TYPE_STRING);
h2 = gda_holder_new (GDA_TYPE_NULL);
h1 = gda_holder_new (G_TYPE_STRING, "1");
h2 = gda_holder_new (GDA_TYPE_NULL, "2");
if (! gda_holder_set_bind (h1, h2, error)) {
g_object_unref (h1);
g_object_unref (h2);
......
......@@ -280,9 +280,8 @@ test4 (GError **error)
{
GdaSet *set;
GdaHolder *h;
GValue *value;
set = gda_set_new_inline (3,
set = gda_set_new_inline (3,
"H1", G_TYPE_STRING, "A string",
"H2", G_TYPE_STRING, "1234",
"H3", G_TYPE_CHAR, 'r');
......@@ -295,9 +294,7 @@ test4 (GError **error)
"Could not find GdaHolder H1");
return FALSE;
}
g_value_set_string ((value = gda_value_new (G_TYPE_STRING)), "Hello!");
gda_holder_set_attribute_static (h, "MyAttr", value);
gda_value_free (value);
g_object_set ((GObject*) h, "description", "Hello!", NULL);
if (!emitted_signals_find (set, "holder-attr-changed", error))
return FALSE;
......
......@@ -40,16 +40,15 @@ make_options_set_from_string (const gchar *context, GdaSet *options)
if (options) {
for (list = gda_set_get_holders (options); list; list = list->next) {
GdaHolder *param = GDA_HOLDER (list->data);
const GValue *cvalue;
cvalue = gda_holder_get_attribute (param, context);
if (!cvalue)
gchar *val;
val = g_object_get_data ((GObject*) param, context);
if (!val)
continue;
GdaHolder *nparam;
const GValue *cvalue2;
cvalue2 = gda_holder_get_value (param);
nparam = gda_holder_new (G_VALUE_TYPE (cvalue2));
g_object_set ((GObject*) nparam, "id", g_value_get_string (cvalue), NULL);
nparam = gda_holder_new (G_VALUE_TYPE (cvalue2), val);
g_assert (gda_holder_set_value (nparam, cvalue2, NULL));
nlist = g_slist_append (nlist, nparam);
}
......
......@@ -441,15 +441,12 @@ create_part_for_model (ConnectionBindingProperties *cprop, TVirtualConnectionPar
GdaSet *set;
GdaHolder *holder;
GtkWidget *form;
GValue *value;
set = gda_set_new_inline (1,
"NAME", G_TYPE_STRING, pm->table_name);
holder = gda_holder_new (GDA_TYPE_DATA_MODEL);
g_object_set (holder, "id", "DATASET", "name", "Data set", NULL);
value = gda_value_new_from_string ("data-model-import", G_TYPE_STRING);
gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
holder = gda_holder_new (GDA_TYPE_DATA_MODEL, "DATASET");
g_object_set (holder, "name", "Data set", NULL);
g_object_set ((GObject*) holder, "plugin", "data-model-import", NULL);
g_assert (gda_set_add_holder (set, holder));
g_object_unref (holder);
......@@ -555,8 +552,8 @@ create_part_for_cnc (ConnectionBindingProperties *cprop, TVirtualConnectionPart
set = gda_set_new_inline (1,
"SCHEMA", G_TYPE_STRING, cnc->table_schema);
holder = gda_holder_new (T_TYPE_CONNECTION);
g_object_set (holder, "id", "CNC", "name", "Connection", "not-null", TRUE, NULL);
holder = gda_holder_new (T_TYPE_CONNECTION, "CNC");
g_object_set (holder, "name", "Connection", "not-null", TRUE, NULL);
g_assert (gda_set_add_holder (set, holder));
g_value_set_object ((value = gda_value_new (T_TYPE_CONNECTION)), cnc->source_cnc);
......
......@@ -154,7 +154,6 @@ data_source_editor_init (DataSourceEditor *editor)
gtk_widget_show_all (ovl);
GdaHolder *holder;
GValue *value;
holder = gda_set_get_holder (editor->priv->attributes, "id");
g_object_set ((GObject*) holder, "name", _("Id"),
"description",
......@@ -175,17 +174,13 @@ data_source_editor_init (DataSourceEditor *editor)
g_object_set ((GObject*) holder, "name", _("SELECT\nSQL"),
"description", _("Actual SQL executed\nto select data\n"
"Can't be changed if a table name is set"), NULL);
value = gda_value_new_from_string ("text:PROG_LANG=gda-sql", G_TYPE_STRING);
gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
g_object_set ((GObject*) holder, "plugin", "text:PROG_LANG=gda-sql", NULL);
holder = gda_set_get_holder (editor->priv->attributes, "depend");
g_object_set ((GObject*) holder, "name", _("Dependencies"),
"description", _("Required and provided named parameters"), NULL);
gdaui_basic_form_entry_set_editable (GDAUI_BASIC_FORM (form), holder, FALSE);
value = gda_value_new_from_string ("rtext", G_TYPE_STRING);
gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
g_object_set ((GObject*) holder, "plugin", "rtext", NULL);
}
static void
......
......@@ -365,8 +365,7 @@ spec_changed_cb (GtkWidget *wid, GdauiDataImport *import)
for (sepno = SEP_COMMA; sepno < SEP_LAST; sepno++) {
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import->priv->sep_array [sepno]))) {
sep = g_object_get_data (G_OBJECT (import->priv->sep_array [sepno]), "_sep");
psep = gda_holder_new (G_TYPE_STRING);
g_object_set (G_OBJECT (psep), "id", "SEPARATOR", NULL);
psep = gda_holder_new (G_TYPE_STRING, "SEPARATOR");
if (sepno != SEP_OTHER)
gda_holder_set_value_str (psep, NULL, sep, NULL);
else
......
......@@ -789,10 +789,7 @@ action_insert_cb (G_GNUC_UNUSED GSimpleAction *action, G_GNUC_UNUSED GVariant *s
if (!plugin && !col->default_value && !autoinc)
continue;
if (plugin) {
GValue *value;
value = gda_value_new_from_string (plugin, G_TYPE_STRING);
gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
g_object_set ((GObject*) holder, "plugin", plugin, NULL);
}