[libgda] Correctly handle DSN changes in authentification dialogs



commit 48bff6e41dd7f3bd455ff4a7743fba412c7a0219
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Jul 14 16:39:00 2010 +0200

    Correctly handle DSN changes in authentification dialogs

 libgda-ui/gdaui-login.c     |   20 +++++++++
 tools/browser/auth-dialog.c |  100 ++++++++++++++++++++++++++++---------------
 2 files changed, 85 insertions(+), 35 deletions(-)
---
diff --git a/libgda-ui/gdaui-login.c b/libgda-ui/gdaui-login.c
index def52e4..78ab87a 100644
--- a/libgda-ui/gdaui-login.c
+++ b/libgda-ui/gdaui-login.c
@@ -129,6 +129,19 @@ gdaui_login_class_init (GdauiLoginClass *klass)
 }
 
 static void
+config_dsn_changed_cb (GdaConfig *config, GdaDsnInfo *dsn, GdauiLogin *login)
+{
+	if (!login->priv->prov_selector)
+		return;
+	gchar *sdsn;
+	sdsn = _gdaui_dsn_selector_get_dsn (GDAUI_DSN_SELECTOR (login->priv->dsn_selector));
+	if (dsn && dsn->name && sdsn && !strcmp (dsn->name, sdsn)) {
+		dsn_entry_changed_cb (GDAUI_DSN_SELECTOR (login->priv->dsn_selector), login);
+		g_print ("Update...\n");
+	}
+}
+
+static void
 gdaui_login_init (GdauiLogin *login, GdauiLoginClass *klass)
 {
 	GtkWidget *table;
@@ -141,6 +154,10 @@ gdaui_login_init (GdauiLogin *login, GdauiLoginClass *klass)
 	login->priv->mode = GDA_UI_LOGIN_ENABLE_CONTROL_CENTRE_MODE;
 	memset (&(login->priv->dsn_info), 0, sizeof (GdaDsnInfo));
 	
+	/* catch DSN definition changes */
+	g_signal_connect (gda_config_get (), "dsn-changed",
+			  G_CALLBACK (config_dsn_changed_cb), login);
+
 	/* table layout */
 	table = gtk_table_new (3, 3, FALSE);
 	gtk_widget_show (table);
@@ -281,6 +298,9 @@ gdaui_login_finalize (GObject *object)
 
 	g_return_if_fail (GDAUI_IS_LOGIN (login));
 
+	g_signal_handlers_disconnect_by_func (gda_config_get (),
+					      G_CALLBACK (config_dsn_changed_cb), login);
+
 	/* free memory */
 	clear_dsn_info (login);
 	g_free (login->priv);
diff --git a/tools/browser/auth-dialog.c b/tools/browser/auth-dialog.c
index 340d71f..fc50748 100644
--- a/tools/browser/auth-dialog.c
+++ b/tools/browser/auth-dialog.c
@@ -133,6 +133,65 @@ auth_contents_changed_cb (GdauiAuth *auth, gboolean is_valid, AuthDialog *dialog
 */
 
 static void
+update_ad_auth (AuthData *ad)
+{
+	if (ad->cncinfo.auth_string) {
+		/* split array in a list of named parameters, and for each parameter value, 
+		 * set the correcponding parameter in @dset */
+		GdaSet *dset;
+		dset = gdaui_basic_form_get_data_set (GDAUI_BASIC_FORM (ad->auth_widget));
+		gchar **array = NULL;
+		array = g_strsplit (ad->cncinfo.auth_string, ";", 0);
+		if (array) {
+			gint index = 0;
+			gchar *tok;
+			gchar *value;
+			gchar *name;
+			
+			for (index = 0; array[index]; index++) {
+				name = strtok_r (array [index], "=", &tok);
+				if (name)
+					value = strtok_r (NULL, "=", &tok);
+				else
+					value = NULL;
+				if (name && value) {
+					GdaHolder *param;
+					gda_rfc1738_decode (name);
+					gda_rfc1738_decode (value);
+					
+					param = gda_set_get_holder (dset, name);
+					if (param)
+						g_assert (gda_holder_set_value_str (param, NULL, value, NULL));
+				}
+			}
+			
+			g_strfreev (array);
+		}
+	}
+}
+
+ /*
+  * Update the auth part
+  */
+static void
+dsn_changed_cb (GdaConfig *config, GdaDsnInfo *info, AuthDialog *dialog)
+{
+	GSList *list;
+	if (!info || !info->name) /* should not happen */
+		return;
+	for (list = dialog->priv->auth_list; list; list = list->next) {
+		AuthData *ad = (AuthData*) list->data;
+		if (! ad->cncinfo.name || strcmp (info->name, ad->cncinfo.name))
+			continue;
+		g_free (ad->cncinfo.auth_string);
+		ad->cncinfo.auth_string = NULL;
+		if (info->auth_string)
+			ad->cncinfo.auth_string = g_strdup (info->auth_string);
+		update_ad_auth (ad);
+	}
+}
+
+static void
 auth_dialog_init (AuthDialog *dialog)
 {
 	GtkWidget *label, *hbox, *wid;
@@ -181,6 +240,8 @@ 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",
+			  G_CALLBACK (dsn_changed_cb), dialog);
 }
 
 static void
@@ -189,6 +250,8 @@ auth_dialog_dispose (GObject *object)
 	AuthDialog *dialog;
 	dialog = AUTH_DIALOG (object);
 	if (dialog->priv) {
+		g_signal_handlers_disconnect_by_func (gda_config_get (),
+						      G_CALLBACK (dsn_changed_cb), dialog);
 		if (dialog->priv->auth_list) {
 			g_slist_foreach (dialog->priv->auth_list, (GFunc) auth_data_free, NULL);
 			g_slist_free (dialog->priv->auth_list);
@@ -387,7 +450,6 @@ auth_dialog_add_cnc_string (AuthDialog *dialog, const gchar *cnc_string, GError
 		ad->cncinfo.auth_string = real_auth_string;
 		real_auth_string = NULL;
 	}
-	
 
 	dialog->priv->auth_list = g_slist_append (dialog->priv->auth_list, ad);
 
@@ -449,40 +511,8 @@ auth_dialog_add_cnc_string (AuthDialog *dialog, const gchar *cnc_string, GError
 		gtk_widget_show_all (hbox);
 
 		/* set values */
-		if (ad->cncinfo.auth_string) {
-			/* split array in a list of named parameters, and for each parameter value, 
-			 * set the correcponding parameter in @dset */
-			GdaSet *dset;
-			
-			dset = gdaui_basic_form_get_data_set (GDAUI_BASIC_FORM (ad->auth_widget));
-			gchar **array = NULL;
-			array = g_strsplit (ad->cncinfo.auth_string, ";", 0);
-			if (array) {
-				gint index = 0;
-				gchar *tok;
-				gchar *value;
-				gchar *name;
-				
-				for (index = 0; array[index]; index++) {
-					name = strtok_r (array [index], "=", &tok);
-					if (name)
-						value = strtok_r (NULL, "=", &tok);
-					else
-						value = NULL;
-					if (name && value) {
-						GdaHolder *param;
-						gda_rfc1738_decode (name);
-						gda_rfc1738_decode (value);
-						
-						param = gda_set_get_holder (dset, name);
-						if (param)
-							g_assert (gda_holder_set_value_str (param, NULL, value, NULL));
-					}
-				}
-				
-				g_strfreev (array);
-			}
-		}
+		if (ad->cncinfo.auth_string)
+			update_ad_auth (ad);
 	}
 	else {
 		/* open connection right away */



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