[gnome-db] GdaXmlDatabase Patch and two new functions (libgda HEAD)



Hi,

   I have found a bug in the GdaXmlDatabase, when a table changed his
name the xmldb don't know this change and don't apply.

   In other way, I have make two new functions, gda_table_find_field and
gda_table_get_fields.

Regards.

note: I don't add a changelog entry, I will make it if you think the
patch is ok.
? libgda/gda-enum-types.c
? libgda/gda-enum-types.h
? libgda/s-enum-types-c
? libgda/s-enum-types-h
Index: libgda/gda-table.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-table.c,v
retrieving revision 1.13
diff -u -r1.13 gda-table.c
--- libgda/gda-table.c	9 Jan 2005 21:00:55 -0000	1.13
+++ libgda/gda-table.c	9 Feb 2005 16:01:36 -0000
@@ -33,10 +33,16 @@
 	GHashTable *fields;
 };
 
+enum {
+	NAME_CHANGED,
+	LAST_SIGNAL
+};
+
 static void gda_table_class_init (GdaTableClass *klass);
 static void gda_table_init       (GdaTable *table, GdaTableClass *klass);
 static void gda_table_finalize   (GObject *object);
 
+static guint gda_table_signals[LAST_SIGNAL];
 static GObjectClass *parent_class = NULL;
 
 /*
@@ -92,6 +98,15 @@
 
 	parent_class = g_type_class_peek_parent (klass);
 
+	gda_table_signals[NAME_CHANGED] =
+		g_signal_new ("name_changed",
+			      G_TYPE_FROM_CLASS (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (GdaTableClass, name_changed),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__STRING,
+			      G_TYPE_NONE, 1, G_TYPE_STRING);
+
 	object_class->finalize = gda_table_finalize;
 	model_class->describe_column = gda_table_describe_column;
 }
@@ -252,13 +267,20 @@
 void
 gda_table_set_name (GdaTable *table, const gchar *name)
 {
+	gchar *old_name;
+	
 	g_return_if_fail (GDA_IS_TABLE (table));
 	g_return_if_fail (name != NULL);
 
+	old_name = g_strdup (table->priv->name);
 	if (table->priv->name)
 		g_free (table->priv->name);
 
 	table->priv->name = g_strdup (name);
+	g_signal_emit (G_OBJECT (table),
+		       gda_table_signals[NAME_CHANGED],
+		       0, old_name);
+	gda_data_model_changed (GDA_DATA_MODEL (table));
 }
 
 /**
@@ -316,4 +338,33 @@
 	g_return_if_fail (GDA_IS_DATA_MODEL (model));
 
     /* FIXME: implement me */
+}
+
+static void
+add_field_to_list (gpointer key, gpointer value, gpointer user_data)
+{
+	gchar *name = (gchar *) key;
+	GList **list = (GList **) user_data;
+
+	*list = g_list_append (*list, g_strdup (name));
+}
+
+GList *
+gda_table_get_fields (GdaTable *table)
+{
+	GList *list = NULL;
+	
+	g_return_val_if_fail (GDA_IS_TABLE (table), NULL);
+	
+	g_hash_table_foreach (table->priv->fields, (GHFunc) add_field_to_list, &list);
+	return list;
+}
+
+GdaDataModelColumnAttributes *
+gda_table_find_field (GdaTable *table, const gchar *name)
+{
+	g_return_val_if_fail (GDA_IS_TABLE (table), NULL);
+	g_return_val_if_fail (name != NULL, NULL);
+	
+	return g_hash_table_lookup (table->priv->fields, name);
 }
Index: libgda/gda-table.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-table.h,v
retrieving revision 1.6
diff -u -r1.6 gda-table.h
--- libgda/gda-table.h	9 Jan 2005 21:00:55 -0000	1.6
+++ libgda/gda-table.h	9 Feb 2005 16:01:36 -0000
@@ -45,6 +45,9 @@
 
 struct _GdaTableClass {
 	GdaDataModelArrayClass parent_class;
+
+	/* signals */
+	void (* name_changed) (GdaTable *table, const gchar *old_name);
 };
 
 GType        gda_table_get_type (void);
@@ -58,6 +61,10 @@
 
 void         gda_table_add_field (GdaTable *table, const GdaDataModelColumnAttributes *fa);
 void         gda_table_add_data_from_model (GdaTable *table, const GdaDataModel *model);
+
+GList       *gda_table_get_fields (GdaTable *table);
+
+GdaDataModelColumnAttributes *gda_table_find_field (GdaTable *table, const gchar *name);
 
 G_END_DECLS
 
Index: libgda/gda-xml-database.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-xml-database.c,v
retrieving revision 1.31
diff -u -r1.31 gda-xml-database.c
--- libgda/gda-xml-database.c	9 Jan 2005 21:00:55 -0000	1.31
+++ libgda/gda-xml-database.c	9 Feb 2005 16:01:36 -0000
@@ -117,6 +117,17 @@
 	gda_xml_database_changed (xmldb);
 }
 
+static void
+table_name_changed_cb (GdaDataModel *model, gchar *old_name, gpointer user_data)
+{
+	GdaXmlDatabase *xmldb = (GdaXmlDatabase *) user_data;
+
+	g_return_if_fail (GDA_IS_XML_DATABASE (xmldb));
+
+	g_hash_table_remove (xmldb->priv->tables, old_name);
+	g_hash_table_insert (xmldb->priv->tables, gda_table_get_name (GDA_TABLE (model)), GDA_TABLE (model));
+}
+
 /*
  * GdaXmlDatabase class interface
  */
@@ -653,6 +664,7 @@
 
 	table = gda_table_new (name);
 	g_signal_connect (G_OBJECT (table), "changed", G_CALLBACK (table_changed_cb), xmldb);
+	g_signal_connect (G_OBJECT (table), "name_changed", G_CALLBACK (table_name_changed_cb), xmldb);
 	g_hash_table_insert (xmldb->priv->tables, g_strdup (name), table);
 	gda_xml_database_changed (xmldb);
 
@@ -690,6 +702,7 @@
 
 	table = gda_table_new_from_model (name, model, add_data);
 	g_signal_connect (G_OBJECT (table), "changed", G_CALLBACK (table_changed_cb), xmldb);
+	g_signal_connect (G_OBJECT (table), "name_changed", G_CALLBACK (table_name_changed_cb), xmldb);
 	if (GDA_IS_TABLE (table)) {
 		g_hash_table_insert (xmldb->priv->tables, g_strdup (name), table);
 		gda_xml_database_changed (xmldb);
@@ -785,6 +798,7 @@
 	/* add the table to the XML database object */
 	g_hash_table_insert (xmldb->priv->tables, g_strdup (name), table);
 	g_signal_connect (G_OBJECT (table), "changed", G_CALLBACK (table_changed_cb), xmldb);
+	g_signal_connect (G_OBJECT (table), "name_changed", G_CALLBACK (table_name_changed_cb), xmldb);
 	gda_xml_database_changed (xmldb);
 
 	return table;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]