[libgda/gtk3] GdaTree managers: added a "meta-store" property



commit 58a2909298b71122ee0789f659a2a8312e7e9d4d
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Feb 9 18:01:00 2011 +0100

    GdaTree managers: added a "meta-store" property

 doc/C/tmpl/gda-tree-mgr-columns.sgml |    5 +++
 doc/C/tmpl/gda-tree-mgr-schemas.sgml |    5 +++
 doc/C/tmpl/gda-tree-mgr-tables.sgml  |    5 +++
 libgda/gda-tree-mgr-columns.c        |   58 +++++++++++++++++++++++++++------
 libgda/gda-tree-mgr-schemas.c        |   45 +++++++++++++++++++++++---
 libgda/gda-tree-mgr-tables.c         |   46 ++++++++++++++++++++++++---
 6 files changed, 143 insertions(+), 21 deletions(-)
---
diff --git a/doc/C/tmpl/gda-tree-mgr-columns.sgml b/doc/C/tmpl/gda-tree-mgr-columns.sgml
index e7c2cf7..ff4f0cb 100644
--- a/doc/C/tmpl/gda-tree-mgr-columns.sgml
+++ b/doc/C/tmpl/gda-tree-mgr-columns.sgml
@@ -43,6 +43,11 @@ a tree manager which creates a node for each column of a table
 
 </para>
 
+<!-- ##### ARG GdaTreeMgrColumns:meta-store ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG GdaTreeMgrColumns:schema ##### -->
 <para>
 
diff --git a/doc/C/tmpl/gda-tree-mgr-schemas.sgml b/doc/C/tmpl/gda-tree-mgr-schemas.sgml
index 0954662..21118c3 100644
--- a/doc/C/tmpl/gda-tree-mgr-schemas.sgml
+++ b/doc/C/tmpl/gda-tree-mgr-schemas.sgml
@@ -39,6 +39,11 @@ a tree manager which creates a node for each schema in a database
 
 </para>
 
+<!-- ##### ARG GdaTreeMgrSchemas:meta-store ##### -->
+<para>
+
+</para>
+
 <!-- ##### FUNCTION gda_tree_mgr_schemas_new ##### -->
 <para>
 
diff --git a/doc/C/tmpl/gda-tree-mgr-tables.sgml b/doc/C/tmpl/gda-tree-mgr-tables.sgml
index 4d5ace6..e0c6894 100644
--- a/doc/C/tmpl/gda-tree-mgr-tables.sgml
+++ b/doc/C/tmpl/gda-tree-mgr-tables.sgml
@@ -43,6 +43,11 @@ a tree manager which creates a node for each table in a schema
 
 </para>
 
+<!-- ##### ARG GdaTreeMgrTables:meta-store ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG GdaTreeMgrTables:schema ##### -->
 <para>
 
diff --git a/libgda/gda-tree-mgr-columns.c b/libgda/gda-tree-mgr-columns.c
index 59daa6a..6606546 100644
--- a/libgda/gda-tree-mgr-columns.c
+++ b/libgda/gda-tree-mgr-columns.c
@@ -1,5 +1,5 @@
 /* GDA library
- * Copyright (C) 2009 - 2010 The GNOME Foundation.
+ * Copyright (C) 2009 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -28,6 +28,7 @@
 
 struct _GdaTreeMgrColumnsPriv {
 	GdaConnection *cnc;
+	GdaMetaStore  *mstore;
 	gchar         *schema; /* imposed upon construction */
 	gchar         *table_name; /* imposed upon construction */
 
@@ -39,13 +40,13 @@ static void gda_tree_mgr_columns_class_init (GdaTreeMgrColumnsClass *klass);
 static void gda_tree_mgr_columns_init       (GdaTreeMgrColumns *tmgr1, GdaTreeMgrColumnsClass *klass);
 static void gda_tree_mgr_columns_dispose    (GObject *object);
 static void gda_tree_mgr_columns_set_property (GObject *object,
-					      guint param_id,
-					      const GValue *value,
-					      GParamSpec *pspec);
+					       guint param_id,
+					       const GValue *value,
+					       GParamSpec *pspec);
 static void gda_tree_mgr_columns_get_property (GObject *object,
-					      guint param_id,
-					      GValue *value,
-					      GParamSpec *pspec);
+					       guint param_id,
+					       GValue *value,
+					       GParamSpec *pspec);
 
 /* virtual methods */
 static GSList *gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node, 
@@ -58,7 +59,8 @@ enum {
         PROP_0,
 	PROP_CNC,
 	PROP_SCHEMA,
-	PROP_TABLE
+	PROP_TABLE,
+	PROP_META_STORE
 };
 
 /*
@@ -79,10 +81,31 @@ gda_tree_mgr_columns_class_init (GdaTreeMgrColumnsClass *klass)
         object_class->set_property = gda_tree_mgr_columns_set_property;
         object_class->get_property = gda_tree_mgr_columns_get_property;
 
+	/**
+	 * GdaTreeMgrColumns:connection:
+	 *
+	 * Defines the #GdaConnection to display information for. Necessary upon construction unless
+	 * the #GdaTreeMgrColumns:meta-store property is specified instead.
+	 */
 	g_object_class_install_property (object_class, PROP_CNC,
                                          g_param_spec_object ("connection", NULL, "Connection to use",
                                                               GDA_TYPE_CONNECTION,
                                                               G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+	/**
+	 * GdaTreeMgrColumns:meta-store:
+	 *
+	 * Defines the #GdaMetaStore to extract information from. Necessary upon construction unless
+	 * the #GdaTreeMgrColumns:connection property is specified instead. This property has
+	 * priority over the GdaTreeMgrColumns:connection property.
+	 *
+	 * Since: 4.2.4
+	 */
+	g_object_class_install_property (object_class, PROP_META_STORE,
+                                         g_param_spec_object ("meta-store", NULL, "GdaMetaStore to use",
+                                                              GDA_TYPE_META_STORE,
+                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
 	/**
 	 * GdaTreeMgrColumns:schema:
 	 *
@@ -123,6 +146,8 @@ gda_tree_mgr_columns_dispose (GObject *object)
 	if (mgr->priv) {
 		if (mgr->priv->cnc)
 			g_object_unref (mgr->priv->cnc);
+		if (mgr->priv->mstore)
+			g_object_unref (mgr->priv->mstore);
 		g_free (mgr->priv->schema);
 		g_free (mgr->priv->table_name);
 
@@ -190,6 +215,11 @@ gda_tree_mgr_columns_set_property (GObject *object,
 			if (mgr->priv->cnc)
 				g_object_ref (mgr->priv->cnc);
 			break;
+		case PROP_META_STORE:
+			mgr->priv->mstore = (GdaMetaStore*) g_value_get_object (value);
+			if (mgr->priv->mstore)
+				g_object_ref (mgr->priv->mstore);
+			break;
 		case PROP_SCHEMA:
 			mgr->priv->schema = g_value_dup_string (value);
 			break;
@@ -217,6 +247,9 @@ gda_tree_mgr_columns_get_property (GObject *object,
 		case PROP_CNC:
 			g_value_set_object (value, mgr->priv->cnc);
 			break;
+		case PROP_META_STORE:
+			g_value_set_object (value, mgr->priv->mstore);
+			break;
 		case PROP_SCHEMA:
 			g_value_set_string (value, mgr->priv->schema);
 			break;
@@ -266,15 +299,18 @@ gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node
 	GSList *list = NULL;
 	GdaConnection *scnc;
 
-	if (!mgr->priv->cnc) {
+	if (!mgr->priv->cnc && !mgr->priv->mstore) {
 		g_set_error (error, GDA_TREE_MANAGER_ERROR, GDA_TREE_MANAGER_UNKNOWN_ERROR,
-			     _("No connection specified"));
+			     _("No connection and no GdaMetaStore specified"));
 		if (out_error)
 			*out_error = TRUE;
 		return NULL;
 	}
+	else if (mgr->priv->mstore)
+		store = mgr->priv->mstore;
+	else
+		store = gda_connection_get_meta_store (mgr->priv->cnc);
 
-	store = gda_connection_get_meta_store (mgr->priv->cnc);
 	scnc = gda_meta_store_get_internal_connection (store);
 
 	/* create statements if necessary */
diff --git a/libgda/gda-tree-mgr-schemas.c b/libgda/gda-tree-mgr-schemas.c
index 26b891c..9c0f096 100644
--- a/libgda/gda-tree-mgr-schemas.c
+++ b/libgda/gda-tree-mgr-schemas.c
@@ -1,5 +1,5 @@
 /* GDA library
- * Copyright (C) 2009 - 2010 The GNOME Foundation.
+ * Copyright (C) 2009 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -28,6 +28,7 @@
 
 struct _GdaTreeMgrSchemasPriv {
 	GdaConnection *cnc;
+	GdaMetaStore  *mstore;
 	GdaStatement  *stmt;
 };
 
@@ -52,7 +53,8 @@ static GObjectClass *parent_class = NULL;
 /* properties */
 enum {
         PROP_0,
-	PROP_CNC
+	PROP_CNC,
+	PROP_META_STORE
 };
 
 /*
@@ -73,10 +75,30 @@ gda_tree_mgr_schemas_class_init (GdaTreeMgrSchemasClass *klass)
         object_class->set_property = gda_tree_mgr_schemas_set_property;
         object_class->get_property = gda_tree_mgr_schemas_get_property;
 
+	/**
+	 * GdaTreeMgrSchemas:connection:
+	 *
+	 * Defines the #GdaConnection to display information for. Necessary upon construction unless
+	 * the #GdaTreeMgrSchema:meta-store property is specified instead.
+	 */
 	g_object_class_install_property (object_class, PROP_CNC,
                                          g_param_spec_object ("connection", NULL, "Connection to use",
                                                               GDA_TYPE_CONNECTION,
                                                               G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+	/**
+	 * GdaTreeMgrSchemas:meta-store:
+	 *
+	 * Defines the #GdaMetaStore to extract information from. Necessary upon construction unless
+	 * the #GdaTreeMgrSchema:connection property is specified instead. This property has
+	 * priority over the GdaTreeMgrSchema:connection property.
+	 *
+	 * Since: 4.2.4
+	 */
+	g_object_class_install_property (object_class, PROP_META_STORE,
+					 g_param_spec_object ("meta-store", NULL, "GdaMetaStore to use",
+                                                              GDA_TYPE_META_STORE,
+                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+					 
 	object_class->dispose = gda_tree_mgr_schemas_dispose;
 }
 
@@ -97,6 +119,8 @@ gda_tree_mgr_schemas_dispose (GObject *object)
 	if (mgr->priv) {
 		if (mgr->priv->cnc)
 			g_object_unref (mgr->priv->cnc);
+		if (mgr->priv->mstore)
+			g_object_unref (mgr->priv->mstore);
 		if (mgr->priv->stmt)
 			g_object_unref (mgr->priv->stmt);
 
@@ -159,6 +183,11 @@ gda_tree_mgr_schemas_set_property (GObject *object,
 			if (mgr->priv->cnc)
 				g_object_ref (mgr->priv->cnc);
 			break;
+		case PROP_META_STORE:
+			mgr->priv->mstore = (GdaMetaStore*) g_value_get_object (value);
+			if (mgr->priv->mstore)
+				g_object_ref (mgr->priv->mstore);
+			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 			break;
@@ -180,6 +209,9 @@ gda_tree_mgr_schemas_get_property (GObject *object,
 		case PROP_CNC:
 			g_value_set_object (value, mgr->priv->cnc);
 			break;
+		case PROP_META_STORE:
+			g_value_set_object (value, mgr->priv->mstore);
+			break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 			break;
@@ -220,15 +252,18 @@ gda_tree_mgr_schemas_update_children (GdaTreeManager *manager, GdaTreeNode *node
 	GSList *list = NULL;
 	GdaConnection *scnc;
 
-	if (!mgr->priv->cnc) {
+	if (!mgr->priv->cnc && !mgr->priv->mstore) {
 		g_set_error (error, GDA_TREE_MANAGER_ERROR, GDA_TREE_MANAGER_UNKNOWN_ERROR,
-			     _("No connection specified"));
+			     _("No connection and no GdaMetaStore specified"));
 		if (out_error)
 			*out_error = TRUE;
 		return NULL;
 	}
+	else if (mgr->priv->mstore)
+		store = mgr->priv->mstore;
+	else
+		store = gda_connection_get_meta_store (mgr->priv->cnc);
 
-	store = gda_connection_get_meta_store (mgr->priv->cnc);
 	scnc = gda_meta_store_get_internal_connection (store);
 
 	if (!mgr->priv->stmt) {
diff --git a/libgda/gda-tree-mgr-tables.c b/libgda/gda-tree-mgr-tables.c
index 6ecb4f0..4e77495 100644
--- a/libgda/gda-tree-mgr-tables.c
+++ b/libgda/gda-tree-mgr-tables.c
@@ -1,5 +1,5 @@
 /* GDA library
- * Copyright (C) 2009 - 2010 The GNOME Foundation.
+ * Copyright (C) 2009 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -28,6 +28,7 @@
 
 struct _GdaTreeMgrTablesPriv {
 	GdaConnection *cnc;
+	GdaMetaStore  *mstore;
 	gchar         *schema; /* imposed upon construction */
 
 	GdaStatement  *stmt_with_schema;
@@ -57,7 +58,8 @@ static GObjectClass *parent_class = NULL;
 enum {
         PROP_0,
 	PROP_CNC,
-	PROP_SCHEMA
+	PROP_SCHEMA,
+	PROP_META_STORE
 };
 
 /*
@@ -78,10 +80,31 @@ gda_tree_mgr_tables_class_init (GdaTreeMgrTablesClass *klass)
         object_class->set_property = gda_tree_mgr_tables_set_property;
         object_class->get_property = gda_tree_mgr_tables_get_property;
 
+	/**
+	 * GdaTreeMgrTables:connection:
+	 *
+	 * Defines the #GdaConnection to display information for. Necessary upon construction unless
+	 * the #GdaTreeMgrTables:meta-store property is specified instead.
+	 */
 	g_object_class_install_property (object_class, PROP_CNC,
                                          g_param_spec_object ("connection", NULL, "Connection to use",
                                                               GDA_TYPE_CONNECTION,
                                                               G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
+	/**
+	 * GdaTreeMgrTables:meta-store:
+	 *
+	 * Defines the #GdaMetaStore to extract information from. Necessary upon construction unless
+	 * the #GdaTreeMgrTables:connection property is specified instead. This property has
+	 * priority over the GdaTreeMgrTables:connection property.
+	 *
+	 * Since: 4.2.4
+	 */
+	g_object_class_install_property (object_class, PROP_META_STORE,
+                                         g_param_spec_object ("meta-store", NULL, "GdaMetaStore to use",
+                                                              GDA_TYPE_META_STORE,
+                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+
 	/**
 	 * GdaTreeMgrTables:schema:
 	 *
@@ -114,6 +137,8 @@ gda_tree_mgr_tables_dispose (GObject *object)
 	if (mgr->priv) {
 		if (mgr->priv->cnc)
 			g_object_unref (mgr->priv->cnc);
+		if (mgr->priv->mstore)
+			g_object_unref (mgr->priv->mstore);
 		g_free (mgr->priv->schema);
 
 		if (mgr->priv->stmt_with_schema)
@@ -182,6 +207,11 @@ gda_tree_mgr_tables_set_property (GObject *object,
 			if (mgr->priv->cnc)
 				g_object_ref (mgr->priv->cnc);
 			break;
+		case PROP_META_STORE:
+			mgr->priv->mstore = (GdaMetaStore*) g_value_get_object (value);
+			if (mgr->priv->mstore)
+				g_object_ref (mgr->priv->mstore);
+			break;
 		case PROP_SCHEMA:
 			mgr->priv->schema = g_value_dup_string (value);
 			break;
@@ -206,6 +236,9 @@ gda_tree_mgr_tables_get_property (GObject *object,
 		case PROP_CNC:
 			g_value_set_object (value, mgr->priv->cnc);
 			break;
+		case PROP_META_STORE:
+			g_value_set_object (value, mgr->priv->mstore);
+			break;
 		case PROP_SCHEMA:
 			g_value_set_string (value, mgr->priv->schema);
 			break;
@@ -251,15 +284,18 @@ gda_tree_mgr_tables_update_children (GdaTreeManager *manager, GdaTreeNode *node,
 	GSList *list = NULL;
 	GdaConnection *scnc;
 
-	if (!mgr->priv->cnc) {
+	if (!mgr->priv->cnc && !mgr->priv->mstore) {
 		g_set_error (error, GDA_TREE_MANAGER_ERROR, GDA_TREE_MANAGER_UNKNOWN_ERROR,
-			     _("No connection specified"));
+			     _("No connection and no GdaMetaStore specified"));
 		if (out_error)
 			*out_error = TRUE;
 		return NULL;
 	}
+	else if (mgr->priv->mstore)
+		store = mgr->priv->mstore;
+	else
+		store = gda_connection_get_meta_store (mgr->priv->cnc);
 
-	store = gda_connection_get_meta_store (mgr->priv->cnc);
 	scnc = gda_meta_store_get_internal_connection (store);
 
 	/* create statements if necessary */



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