/*
 * _gdaui_provider_auth_editor_set_auths
 * @auth: a #GdauiProviderAuthEditor widget
 * @auth_string: 
 *
 * Sets the connection string to be displayed in the widget
 */
void
_gdaui_provider_auth_editor_set_auth (GdauiProviderAuthEditor *auth, const gchar *auth_string)
{
	g_return_if_fail (GDAUI_IS_PROVIDER_AUTH_EDITOR (auth));
	g_return_if_fail (auth->priv);

	if (!auth->priv->pinfo)
		return;

	if (!auth->priv->auth_needed) {
		if (auth_string && *auth_string)
			g_warning (_("Can't set authentification string: no authentication is needed"));
		return;
	}

	gdaui_basic_form_reset (GDAUI_BASIC_FORM (auth->priv->auth_widget));
	if (auth_string) {
		/* split array in a list of named parameters, and for each parameter value, set the correcponding
		   parameter in @dset */
		GdaSet *dset;
		GSList *params_set = NULL;
		g_assert (auth->priv->auth_widget);

		dset = gdaui_basic_form_get_data_set (GDAUI_BASIC_FORM (auth->priv->auth_widget));
		gchar **array = NULL;
		array = g_strsplit (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)
						if (gda_holder_set_value_str (param, NULL, value, NULL))
							params_set = g_slist_prepend (params_set, param);
				}
			}
			
			g_strfreev (array);
		}
	}

	g_signal_emit_by_name (auth, "changed");
}
static void
update_form_contents (GdauiProviderSpecEditor *spec)
{
	/*g_print ("DSN: %s\n", spec->priv->cnc_string);*/
	switch (spec->priv->type) {
	case PROVIDER_FORM: {
		/* update data set in form */
		GdaSet *dset;
		GSList *params_set = NULL;
		GSList *list;
		g_assert (spec->priv->form);

		dset = gdaui_basic_form_get_data_set (GDAUI_BASIC_FORM (spec->priv->form));

		/* split array in a list of named parameters, and for each parameter value, set the correcponding
		   parameter in @dset */
		if (spec->priv->cnc_string) {
			gchar **array = NULL;
			array = g_strsplit (spec->priv->cnc_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)
							if (gda_holder_set_value_str (param, NULL, value, NULL))
								params_set = g_slist_prepend (params_set, param);
					}
				}

				g_strfreev (array);
			}
		}

		list = dset->holders;
		while (0 && list) {
			if (!params_set || !g_slist_find (params_set, list->data)) {
				/* empty parameter */
				gda_holder_set_value (GDA_HOLDER (list->data), NULL, NULL);
			}
			list = g_slist_next (list);
		}
		g_slist_free (params_set);
		break;
	}
	default:
		/* no change here */
		break;
	}
}
Example #3
0
static void
selection_changed_cb (GtkTreeSelection *select, BrowserConnectionsList *clist)
{
	GtkTreeModel *model;
	GtkTreeIter iter;
	BrowserConnection *bcnc = NULL;
	const GdaDsnInfo *cncinfo = NULL;

	if (gtk_tree_selection_get_selected (select, &model, &iter)) {
		gtk_tree_model_get (model, &iter, COLUMN_BCNC, &bcnc, -1);
		cncinfo = browser_connection_get_information (bcnc);
		g_object_unref (bcnc);

		gtk_widget_set_sensitive (_clist->priv->close_cnc_button, TRUE);
	}
	else
		gtk_widget_set_sensitive (_clist->priv->close_cnc_button, FALSE);

	if (clist->priv->cnc_params_editor) {
		gtk_widget_destroy (clist->priv->cnc_params_editor);
		clist->priv->cnc_params_editor = NULL;
	}
	
	if (cncinfo && cncinfo->provider) {
		/* create GdaSet for parameters to display */
		GdaSet *dset;
		GdaHolder *holder;
		dset = gda_set_new_inline (1, "PROVIDER_NAME", G_TYPE_STRING, cncinfo->provider);
		holder = GDA_HOLDER (dset->holders->data);
		g_object_set (G_OBJECT (holder), "name", _("Database provider"), NULL);

		GdaProviderInfo *pinfo;
		pinfo = gda_config_get_provider_info (cncinfo->provider);
		if (pinfo && pinfo->dsn_params)
			gda_set_merge_with_set (dset, pinfo->dsn_params);

		holder = gda_holder_new_inline (G_TYPE_STRING, "GDA_BROWSER_DICT_FILE", _("In memory"));
		g_object_set (G_OBJECT (holder),
			      "name", _("Dictionary file"),
			      "description", _("File used to store any information associated\n"
					       "to this connection (favorites, descriptions, ...)"), NULL);
		gda_set_add_holder (dset, holder);
		g_object_unref (holder);
		if (bcnc) {
			const gchar *dict_file_name;
			dict_file_name = browser_connection_get_dictionary_file (bcnc);
			
			if (dict_file_name)
				gda_set_set_holder_value (dset, NULL, "GDA_BROWSER_DICT_FILE",
							  dict_file_name);
		}

		/* create form */
		GtkWidget *wid;
		wid = gdaui_basic_form_new (dset);
		g_object_set ((GObject*) wid, "show-actions", FALSE, NULL);
		gdaui_basic_form_entry_set_editable (GDAUI_BASIC_FORM (wid), NULL, FALSE);
		gtk_grid_attach (clist->priv->layout_grid, wid, 1, 2, 1, 1);
		gtk_widget_show (wid);
		clist->priv->cnc_params_editor = wid;

		/* fill GdaSet's parameters with values */
		if (cncinfo->cnc_string) {
                        gchar **array = NULL;

                        array = g_strsplit (cncinfo->cnc_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);
                        }
                }
		
		g_object_unref (dset);
	}
}
Example #4
0
/**
 * gda_quark_list_add_from_string:
 * @qlist: a #GdaQuarkList.
 * @string: a string.
 * @cleanup: whether to cleanup the previous content or not.
 *
 * @string must be a semi-colon separated list of "<key>=<value>" strings (for example
 * "DB_NAME=notes;USERNAME=alfred"). Each key and value must respect the RFC 1738 recommendations: the
 * <constant>&lt;&gt;&quot;#%{}|\^~[]&apos;`;/?:@=&amp;</constant> and space characters are replaced by 
 * <constant>&quot;%%ab&quot;</constant> where
 * <constant>ab</constant> is the hexadecimal number corresponding to the character (for example the
 * "DB_NAME=notes;USERNAME=al%%20fred" string will specify a username as "al fred"). If this formalism
 * is not respected, then some unexpected results may occur.
 *
 * Some corner cases for any string part (delimited by the semi-colon):
 * <itemizedlist>
 *    <listitem><para>If it does not respect the "&lt;key&gt;=&lt;value&gt;" format then it will be ignored.</para></listitem>
 *    <listitem><para>Only the 1st equal character is used to separate the key from the value part (which means
 *       any other equal sign will be part of the value)</para></listitem>
 * </itemizedlist>
 *
 *
 * Adds new key->value pairs from the given @string. If @cleanup is
 * set to %TRUE, the previous contents will be discarded before adding
 * the new pairs.
 */
void
gda_quark_list_add_from_string (GdaQuarkList *qlist, const gchar *string, gboolean cleanup)
{
	gchar **arr;

	g_return_if_fail (qlist != NULL);
	if (!string || !*string)
		return;

	if (cleanup)
		gda_quark_list_clear (qlist);

	arr = (gchar **) g_strsplit (string, ";", 0);
	if (arr) {
		guint n;
		for (n = 0; arr[n] && (* (arr[n])); n++) {
			gchar **pair;
			gchar *tmp;
			for (tmp = arr[n]; *tmp; tmp++) {
				if (*tmp == '=')
					break;
			}
			if (!*tmp) {
				/* ignore this string since it does not contain the '=' char */
				continue;
			}

			pair = (gchar **) g_strsplit (arr[n], "=", 2);
			if (pair && pair[0]) {
				gchar *name = pair[0];
				gchar *value = pair[1];
				g_strstrip (name);
				gda_rfc1738_decode (name);
				if (value) {
					g_strstrip (value);
					gda_rfc1738_decode (value);
				}

				if (! name_is_protected (name)) {
					if (!qlist->hash_table)
						qlist->hash_table = g_hash_table_new_full (g_str_hash,
											   g_str_equal,
											   g_free, g_free);
					g_hash_table_insert (qlist->hash_table, 
							     (gpointer) name, (gpointer) value);
				}
				else {
					ProtectedValue *pvalue;
					pvalue = protected_value_new (value);
					if (pvalue) {
						if (!qlist->hash_protected)
							qlist->hash_protected = g_hash_table_new_full (g_str_hash,
												       g_str_equal,
												       g_free,
												       (GDestroyNotify) protected_value_free);
						g_hash_table_insert (qlist->hash_protected, 
								     (gpointer) name, (gpointer) pvalue);
						g_free (value); /* has been mangled */
					}
					else {
						if (!qlist->hash_table)
							qlist->hash_table = g_hash_table_new_full (g_str_hash,
												   g_str_equal,
												   g_free, g_free);
						g_hash_table_insert (qlist->hash_table, 
								     (gpointer) name, (gpointer) value);
					}
				}
				g_free (pair);
			}
			else
				g_strfreev (pair);
		}
		g_strfreev (arr);
	}
}