[libgda/gtk3] GdaConfig related corrections



commit dec90147a11ea4e5af0649218756db16e523e1b2
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Feb 9 21:07:35 2011 +0100

    GdaConfig related corrections

 doc/C/tmpl/gda-config.sgml       |    5 +-
 libgda-ui/gdaui-login.c          |    8 ++-
 libgda/gda-config.c              |  105 ++++++++++++++++++++++++++------------
 libgda/gda-config.h              |   34 ++++++++++---
 libgda/gda-data-model-dsn-list.c |    5 +-
 tools/browser/auth-dialog.c      |   10 +++-
 6 files changed, 117 insertions(+), 50 deletions(-)
---
diff --git a/doc/C/tmpl/gda-config.sgml b/doc/C/tmpl/gda-config.sgml
index 4e0c60b..78c9004 100644
--- a/doc/C/tmpl/gda-config.sgml
+++ b/doc/C/tmpl/gda-config.sgml
@@ -6,9 +6,8 @@ Access/Management of libgda configuration
 
 <!-- ##### SECTION Long_Description ##### -->
 <para>
-  The functions in this section allow applications an easy access to the libgda
-  configuration, thus making them able to access the list of data sources
-  configured in the system, for instance.
+  The functions in this section allow applications an easy access to libgda's
+  configuration (the list of data sources and database providers).
 </para>
 <para>
   As soon as a <link linkend="GdaConfig">GdaConfig</link> is needed (for example when requesting information
diff --git a/libgda-ui/gdaui-login.c b/libgda-ui/gdaui-login.c
index 113235b..cb790e4 100644
--- a/libgda-ui/gdaui-login.c
+++ b/libgda-ui/gdaui-login.c
@@ -155,8 +155,10 @@ gdaui_login_init (GdauiLogin *login, G_GNUC_UNUSED GdauiLoginClass *klass)
 	memset (&(login->priv->dsn_info), 0, sizeof (GdaDsnInfo));
 	
 	/* catch DSN definition changes */
-	g_signal_connect (gda_config_get (), "dsn-changed",
+	GdaConfig *conf = gda_config_get ();
+	g_signal_connect (conf, "dsn-changed",
 			  G_CALLBACK (config_dsn_changed_cb), login);
+	g_object_unref (conf);
 
 	/* table layout */
 	table = gtk_table_new (3, 3, FALSE);
@@ -298,8 +300,10 @@ gdaui_login_finalize (GObject *object)
 
 	g_return_if_fail (GDAUI_IS_LOGIN (login));
 
-	g_signal_handlers_disconnect_by_func (gda_config_get (),
+	GdaConfig *conf = gda_config_get ();
+	g_signal_handlers_disconnect_by_func (conf,
 					      G_CALLBACK (config_dsn_changed_cb), login);
+	g_object_unref (conf);
 
 	/* free memory */
 	clear_dsn_info (login);
diff --git a/libgda/gda-config.c b/libgda/gda-config.c
index 86c629c..83382d2 100644
--- a/libgda/gda-config.c
+++ b/libgda/gda-config.c
@@ -1,5 +1,5 @@
 /* GDA library
- * Copyright (C) 2007 - 2010 The GNOME Foundation.
+ * Copyright (C) 2007 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -90,6 +90,8 @@ static void internal_provider_free (InternalProvider *ip);
 static void load_config_file (const gchar *file, gboolean is_system);
 static void save_config_file (gboolean is_system);
 static void load_all_providers (void);
+static void reload_dsn_configuration (void);
+
 
 enum {
 	DSN_ADDED,
@@ -146,7 +148,7 @@ gda_config_class_init (GdaConfigClass *klass)
 	parent_class = g_type_class_peek_parent (klass);
 
 	/**
-	 * GdaConfig::dsn-added
+	 * GdaConfig::dsn-added:
 	 * @conf: the #GdaConfig object
 	 * @new_dsn: a #GdaDsnInfo
 	 *
@@ -161,7 +163,7 @@ gda_config_class_init (GdaConfigClass *klass)
                               _gda_marshal_VOID__POINTER,
                               G_TYPE_NONE, 1, G_TYPE_POINTER);
 	/**
-	 * GdaConfig::dsn-to-be-removed
+	 * GdaConfig::dsn-to-be-removed:
 	 * @conf: the #GdaConfig object
 	 * @old_dsn: a #GdaDsnInfo
 	 *
@@ -176,7 +178,7 @@ gda_config_class_init (GdaConfigClass *klass)
                               _gda_marshal_VOID__POINTER,
                               G_TYPE_NONE, 1, G_TYPE_POINTER);
 	/**
-	 * GdaConfig::dsn-removed
+	 * GdaConfig::dsn-removed:
 	 * @conf: the #GdaConfig object
 	 * @old_dsn: a #GdaDsnInfo
 	 *
@@ -191,7 +193,7 @@ gda_config_class_init (GdaConfigClass *klass)
                               _gda_marshal_VOID__POINTER,
                               G_TYPE_NONE, 1, G_TYPE_POINTER);
 	/**
-	 * GdaConfig::dsn-changed
+	 * GdaConfig::dsn-changed:
 	 * @conf: the #GdaConfig object
 	 * @dsn: a #GdaDsnInfo
 	 *
@@ -210,12 +212,22 @@ gda_config_class_init (GdaConfigClass *klass)
         object_class->set_property = gda_config_set_property;
         object_class->get_property = gda_config_get_property;
 
+	/**
+	 * GdaConfig:user-filename:
+	 *
+	 * File to use for per-user DSN list. When changed, the whole list of DSN will be reloaded.
+	 */
 	/* To translators: DSN stands for Data Source Name, it's a named connection string defined in $XDG_DATA_HOME/libgda/config */
 	g_object_class_install_property (object_class, PROP_USER_FILE,
                                          g_param_spec_string ("user-filename", NULL, 
 							      "File to use for per-user DSN list", 
 							      NULL, 
 							      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+	/**
+	 * GdaConfig:system-filename:
+	 *
+	 * File to use for system-wide DSN list. When changed, the whole list of DSN will be reloaded.
+	 */
 	/* To translators: DSN stands for Data Source Name, it's a named connection string defined in $PREFIX/etc/libgda-5.0/config */
 	g_object_class_install_property (object_class, PROP_USER_FILE,
                                          g_param_spec_string ("system-filename", NULL,
@@ -734,21 +746,38 @@ gda_config_set_property (GObject *object,
 			 GParamSpec *pspec)
 {
 	GdaConfig *conf;
+	const gchar *cstr;
 
         conf = GDA_CONFIG (object);
         if (conf->priv) {
                 switch (param_id) {
 		case PROP_USER_FILE:
+			cstr = g_value_get_string (value);
+			if ((cstr && conf->priv->user_file &&
+			     !strcmp (cstr, conf->priv->user_file)) ||
+			    (! cstr && !conf->priv->user_file)) {
+				/* nothing to do */
+				break;
+			}
 			g_free (conf->priv->user_file);
 			conf->priv->user_file = NULL;
 			if (g_value_get_string (value))
-				conf->priv->user_file = g_strdup (g_value_get_string (value));
+				conf->priv->user_file = g_strdup (cstr);
+			reload_dsn_configuration ();
 			break;
                 case PROP_SYSTEM_FILE:
+			cstr = g_value_get_string (value);
+			if ((cstr && conf->priv->system_file &&
+			     !strcmp (cstr, conf->priv->system_file)) ||
+			    (! cstr && !conf->priv->system_file)) {
+				/* nothing to do */
+				break;
+			}
 			g_free (conf->priv->system_file);
 			conf->priv->system_file = NULL;
 			if (g_value_get_string (value))
-				conf->priv->system_file = g_strdup (g_value_get_string (value));
+				conf->priv->system_file = g_strdup (cstr);
+			reload_dsn_configuration ();
                         break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -784,9 +813,10 @@ gda_config_get_property (GObject *object,
 /**
  * gda_config_get:
  * 
- * Get a pointer to the global GdaConfig object
+ * Get a pointer to the global (unique) #GdaConfig object. This functions increments
+ * the reference count of the object, so you need to call g_object_unref() on it once finished.
  *
- * Returns: (transfer full): a non %NULL pointer to a #GdaConfig
+ * Returns: (transfer full): a non %NULL pointer to the unique #GdaConfig
  */
 GdaConfig*
 gda_config_get (void)
@@ -1706,34 +1736,14 @@ internal_provider_free (InternalProvider *ip)
 	g_free (ip);
 }
 
-/*
- * File monitoring actions
- */
-#ifdef HAVE_GIO
-
-static gboolean
-str_equal (const gchar *str1, const gchar *str2)
-{
-	if (str1 && str2) {
-		if (!strcmp (str1, str2))
-			return TRUE;
-		else
-			return FALSE;
-	}
-	else if (!str1 && !str2)
-		return TRUE;
-	return FALSE;
-}
-
 static void
-conf_file_changed (G_GNUC_UNUSED GFileMonitor *mon, G_GNUC_UNUSED GFile *file,
-		   G_GNUC_UNUSED GFile *other_file, GFileMonitorEvent event_type, G_GNUC_UNUSED gpointer data)
+reload_dsn_configuration (void)
 {
 	GSList *list, *current_dsn_list, *new_dsn_list;
-	g_assert (unique_instance);
-
-	if (event_type != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
+	if (!unique_instance) {
+		/* object not yet created */
 		return;
+	}
 
         GDA_CONFIG_LOCK ();
 #ifdef GDA_DEBUG_NO
@@ -1820,6 +1830,35 @@ conf_file_changed (G_GNUC_UNUSED GFileMonitor *mon, G_GNUC_UNUSED GFile *file,
         GDA_CONFIG_UNLOCK ();
 }
 
+/*
+ * File monitoring actions
+ */
+#ifdef HAVE_GIO
+
+static gboolean
+str_equal (const gchar *str1, const gchar *str2)
+{
+	if (str1 && str2) {
+		if (!strcmp (str1, str2))
+			return TRUE;
+		else
+			return FALSE;
+	}
+	else if (!str1 && !str2)
+		return TRUE;
+	return FALSE;
+}
+
+static void
+conf_file_changed (G_GNUC_UNUSED GFileMonitor *mon, G_GNUC_UNUSED GFile *file,
+		   G_GNUC_UNUSED GFile *other_file, GFileMonitorEvent event_type,
+		   G_GNUC_UNUSED gpointer data)
+{
+	if (event_type != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
+		return;
+	reload_dsn_configuration ();
+}
+
 static void
 lock_notify_changes (void)
 {
diff --git a/libgda/gda-config.h b/libgda/gda-config.h
index 94baca7..00a9eb8 100644
--- a/libgda/gda-config.h
+++ b/libgda/gda-config.h
@@ -1,5 +1,5 @@
-/* GDA library
- * Copyright (C) 2007 - 2010 The GNOME Foundation.
+/*
+ * Copyright (C) 2007 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -49,12 +49,23 @@ typedef enum {
 	GDA_CONFIG_PROVIDER_CREATION_ERROR
 } GdaConfigError;
 
+/**
+ * GdaDsnInfo:
+ * @name: the (unique) name of the DSN (plain text, not RFC 1738 encoded)
+ * @provider: the ID of the database provider to be used (plain text, not RFC 1738 encoded)
+ * @description: a descriptive string (plain text, not RFC 1738 encoded), can be %NULL.
+ * @cnc_string: the connection string, a semi-colon separated &lt;key>=&lt;value&gt; list where &lt;key&gt; and &lt;value&gt; are RFC 1738 encoded 
+ * @auth_string: the authentication string, a semi-colon separated &lt;key>=&lt;value&gt; list where &lt;key&gt; and &lt;value&gt; are RFC 1738 encoded. Can be %NULL.
+ * @is_system: %TRUE if the DSN is a system wide defined data source
+ *
+ * This structure defines the properties of a named data source (DSN).
+ */
 struct _GdaDsnInfo {
-        gchar    *name;        /* plain text, not RFC 1738 encoded */
-        gchar    *provider;    /* plain text, not RFC 1738 encoded */
-        gchar    *description; /* plain text, not RFC 1738 encoded */
-        gchar    *cnc_string;  /* semi-colon separated <key>=<value> list where <key> and <value> are RFC 1738 encoded */
-        gchar    *auth_string; /* semi-colon separated <key>=<value> list where <key> and <value> are RFC 1738 encoded */
+        gchar    *name;
+        gchar    *provider;
+        gchar    *description;
+        gchar    *cnc_string;
+        gchar    *auth_string;
         gboolean  is_system;
 
 	/*< private >*/
@@ -65,6 +76,15 @@ struct _GdaDsnInfo {
 	gpointer _gda_reserved4;
 };
 
+/**
+ * GdaProviderInfo:
+ * @id: the unique identifier of the database provider
+ * @location: the complete path to the shared library implementing the database provider
+ * @dsn_params: a #GdaSet containing all the parameters which can/must be specified when opening a connection or defining a named data source (DSN)
+ * @auth_params: a #GdaSet containing all the authentication parameters
+ *
+ * This structure holds the information associated to a database provider as discovered by Libgda.
+ */
 struct _GdaProviderInfo {
         gchar             *id;
         gchar             *location;
diff --git a/libgda/gda-data-model-dsn-list.c b/libgda/gda-data-model-dsn-list.c
index af65103..382eac0 100644
--- a/libgda/gda-data-model-dsn-list.c
+++ b/libgda/gda-data-model-dsn-list.c
@@ -1,5 +1,5 @@
 /* GDA library
- * Copyright (C) 2007 - 2009 The GNOME Foundation.
+ * Copyright (C) 2007 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *         Vivien Malerba <malerba gnome-db org>
@@ -150,6 +150,7 @@ gda_data_model_dsn_list_init (GdaDataModelDsnList *model,
 			  G_CALLBACK (dsn_removed_cb), model);
 	g_signal_connect (G_OBJECT (config), "dsn-changed",
 			  G_CALLBACK (dsn_changed_cb), model);
+	g_object_unref (config);
 
 	model->priv->tmp_value = NULL;
 }
@@ -181,7 +182,7 @@ gda_data_model_dsn_list_dispose (GObject *object)
 						      G_CALLBACK (dsn_to_be_removed_cb), model);
 		g_signal_handlers_disconnect_by_func (G_OBJECT (config),
 						      G_CALLBACK (dsn_changed_cb), model);
-
+		g_object_unref (config);
 		if (model->priv->tmp_value) {
 			gda_value_free (model->priv->tmp_value);
 			model->priv->tmp_value = NULL;
diff --git a/tools/browser/auth-dialog.c b/tools/browser/auth-dialog.c
index b3f536e..bf99229 100644
--- a/tools/browser/auth-dialog.c
+++ b/tools/browser/auth-dialog.c
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2009 - 2010 Vivien Malerba
+ * Copyright (C) 2009 - 2011 Vivien Malerba
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -237,8 +237,10 @@ auth_dialog_init (AuthDialog *dialog)
 	dialog->priv->spinner = browser_spinner_new ();
 	gtk_container_add (GTK_CONTAINER (hbox), dialog->priv->spinner);
 
-	g_signal_connect (gda_config_get (), "dsn-changed",
+	GdaConfig *conf = gda_config_get ();
+	g_signal_connect (conf, "dsn-changed",
 			  G_CALLBACK (dsn_changed_cb), dialog);
+	g_object_unref (conf);
 }
 
 static void
@@ -247,8 +249,10 @@ auth_dialog_dispose (GObject *object)
 	AuthDialog *dialog;
 	dialog = AUTH_DIALOG (object);
 	if (dialog->priv) {
-		g_signal_handlers_disconnect_by_func (gda_config_get (),
+		GdaConfig *conf = gda_config_get ();
+		g_signal_handlers_disconnect_by_func (conf,
 						      G_CALLBACK (dsn_changed_cb), dialog);
+		g_object_unref (conf);
 		if (dialog->priv->auth_list) {
 			g_slist_foreach (dialog->priv->auth_list, (GFunc) auth_data_free, NULL);
 			g_slist_free (dialog->priv->auth_list);



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