Exemplo n.º 1
0
static void
sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole)
{
	TFavorites *tfav;
	TFavoritesAttributes fav;
	GError *error = NULL;

	GdaSet *set;
	GtkWidget *dlg, *form;
	gint response;
	const GValue *cvalue;
	set = gda_set_new_inline (1, _("Favorite's name"),
				  G_TYPE_STRING, _("Unnamed query"));
	dlg = gdaui_basic_form_new_in_dialog (set,
					      (GtkWindow*) gtk_widget_get_toplevel (GTK_WIDGET (tconsole)),
					      _("Name of the favorite to create"),
					      _("Enter the name of the favorite to create"));
	form = g_object_get_data (G_OBJECT (dlg), "form");
	g_signal_connect (form, "activated",
			  G_CALLBACK (fav_form_name_activated_cb), dlg);
	response = gtk_dialog_run (GTK_DIALOG (dlg));
	if (response == GTK_RESPONSE_REJECT) {
		g_object_unref (set);
		gtk_widget_destroy (dlg);
		return;
	}

	memset (&fav, 0, sizeof (fav));
	fav.id = -1;
	fav.type = T_FAVORITES_QUERIES;
	fav.contents = query_editor_get_all_text (tconsole->priv->editor);
	cvalue = gda_set_get_holder_value (set, _("Favorite's name"));
	fav.name = (gchar*) g_value_get_string (cvalue);

	tfav = t_connection_get_favorites (tconsole->priv->tcnc);

	if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
		ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
			       _("Could not add favorite: %s"),
			       error && error->message ? error->message : _("No detail"));
                if (error)
                        g_error_free (error);
	}
	else
		tconsole->priv->fav_id = fav.id;
	g_free (fav.contents);

	g_object_unref (set);
	gtk_widget_destroy (dlg);
}
Exemplo n.º 2
0
/*
 * COMMAND: <gda_report_param_value>
 *
 * Creates a new text node containing the value of the parameter named from "param_name"
 *
 * uses node's contents: no
 * requested attributes: param_name
 * optional attributes: converter => use "richtext::docbook"
 */
static gboolean
command_gda_report_param_value (GdaReportEngine *engine, xmlNodePtr node, GSList **created_nodes,
				RunContext *context, GError **error)
{
	xmlChar *prop;
	prop = xmlGetProp (node, BAD_CAST "param_name");
	if (prop) {
		GdaHolder *param;
		
		param = run_context_find_param (engine, context, prop);
		if (!param) {
			g_set_error (error, 0, 0,
				     _("Unknown parameter '%s'"), prop);
			return FALSE;
		}
		else {
			/* Add a text node */
			const GValue *value;
			xmlNodePtr child;
			GdaSet *options = NULL;
			xmlChar *cprop;

			cprop = xmlGetProp (node, BAD_CAST "converter");
			if (cprop) {
				options = gda_set_new_inline (1, "converter", G_TYPE_STRING, (gchar*) cprop);
				xmlFree (cprop);
			}
			value = gda_holder_get_value (param);
			child = value_to_node (engine, context, value, options);
			if (options)
				g_object_unref (options);
			*created_nodes = g_slist_prepend (NULL, child);
		}
		xmlFree (prop);
		return TRUE;
	}
	else {
		g_set_error (error, 0, 0, "%s", 
			     _("Parameter name not specified"));
		return FALSE;
	}
}
Exemplo n.º 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);
	}
}
Exemplo n.º 4
0
/**
 * base_tool_output_data_model_to_string:
 */
gchar *
base_tool_output_data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream, GdaSet *options)
{
    if (!GDA_IS_DATA_MODEL (model))
        return NULL;

    if (format & BASE_TOOL_OUTPUT_FORMAT_DEFAULT) {
        gchar *tmp;
        GdaSet *local_options;
        gint width;
        base_tool_input_get_size (&width, NULL);
        local_options = gda_set_new_inline (6, "NAME", G_TYPE_BOOLEAN, TRUE,
                                            "NULL_AS_EMPTY", G_TYPE_BOOLEAN, TRUE,
                                            "MAX_WIDTH", G_TYPE_INT, width,
                                            "COLUMN_SEPARATORS", G_TYPE_BOOLEAN, TRUE,
                                            "SEPARATOR_LINE", G_TYPE_BOOLEAN, TRUE,
                                            "NAMES_ON_FIRST_LINE", G_TYPE_BOOLEAN, TRUE);
        if (options)
            gda_set_merge_with_set (local_options, options);
        tmp = gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_TEXT_TABLE, NULL, 0, NULL, 0,
                                               local_options);
        g_object_unref (local_options);
        if (GDA_IS_DATA_SELECT (model)) {
            gchar *tmp2, *tmp3;
            gdouble etime;
            g_object_get ((GObject*) model, "execution-delay", &etime, NULL);
            tmp2 = g_strdup_printf ("%s: %.03f s", _("Execution delay"), etime);
            tmp3 = g_strdup_printf ("%s\n%s", tmp, tmp2);
            g_free (tmp);
            g_free (tmp2);
            return tmp3;
        }
        else
            return tmp;
    }
    else if (format & BASE_TOOL_OUTPUT_FORMAT_XML)
        return gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_DATA_ARRAY_XML,
                                                NULL, 0,
                                                NULL, 0, NULL);
    else if (format & BASE_TOOL_OUTPUT_FORMAT_CSV) {
        gchar *retval;
        GdaSet *optexp;
        optexp = make_options_set_from_string ("csv", options);
        retval = gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_TEXT_SEPARATED,
                 NULL, 0,
                 NULL, 0, optexp);
        if (optexp)
            g_object_unref (optexp);
        return retval;
    }
    else if (format & BASE_TOOL_OUTPUT_FORMAT_HTML) {
        xmlBufferPtr buffer;
        xmlNodePtr top, div, table, node, row_node, col_node, header, meta;
        gint ncols, nrows, i, j;
        gchar *str;

        top = xmlNewNode (NULL, BAD_CAST "html");
        header = xmlNewChild (top, NULL, BAD_CAST "head", NULL);
        meta = xmlNewChild (header, NULL, BAD_CAST "meta", NULL);
        xmlSetProp (meta, BAD_CAST "http-equiv", BAD_CAST "content-type");
        xmlSetProp (meta, BAD_CAST "content", BAD_CAST "text/html; charset=UTF-8");
        div = xmlNewChild (top, NULL, BAD_CAST "body", NULL);
        table = xmlNewChild (div, NULL, BAD_CAST "table", NULL);
        xmlSetProp (table, BAD_CAST "border", BAD_CAST "1");

        if (g_object_get_data (G_OBJECT (model), "name"))
            xmlNewTextChild (table, NULL, BAD_CAST "caption", g_object_get_data (G_OBJECT (model), "name"));

        ncols = gda_data_model_get_n_columns (model);
        nrows = gda_data_model_get_n_rows (model);

        row_node = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
        for (j = 0; j < ncols; j++) {
            const gchar *cstr;
            cstr = gda_data_model_get_column_title (model, j);
            col_node = xmlNewTextChild (row_node, NULL, BAD_CAST "th", BAD_CAST cstr);
            xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "center");
        }

        for (i = 0; i < nrows; i++) {
            row_node = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
            xmlSetProp (row_node, BAD_CAST "valign", BAD_CAST "top");
            for (j = 0; j < ncols; j++) {
                const GValue *value;
                value = gda_data_model_get_value_at (model, j, i, NULL);
                if (!value) {
                    col_node = xmlNewChild (row_node, NULL, BAD_CAST "td", BAD_CAST "ERROR");
                    xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
                }
                else {
                    str = gda_value_stringify (value);
                    col_node = xmlNewTextChild (row_node, NULL, BAD_CAST "td", BAD_CAST str);
                    xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
                    g_free (str);
                }
            }
        }

        node = xmlNewChild (div, NULL, BAD_CAST "p", NULL);
        str = g_strdup_printf (ngettext ("(%d row)", "(%d rows)", nrows), nrows);
        xmlNodeSetContent (node, BAD_CAST str);
        g_free (str);

        buffer = xmlBufferCreate ();
        xmlNodeDump (buffer, NULL, top, 0, 1);
        str = g_strdup ((gchar *) xmlBufferContent (buffer));
        xmlBufferFree (buffer);
        xmlFreeNode (top);
        return str;
    }
    else
        TO_IMPLEMENT;

    return NULL;
}
Exemplo n.º 5
0
GtkWidget *
do_basic_form (GtkWidget *do_widget)
{  
	if (!window) {
		GtkWidget *vbox;
		GtkWidget *label;
		GtkWidget *form;
		
		window = gtk_dialog_new_with_buttons ("GdauiBasicForm",
						      GTK_WINDOW (do_widget),
						      0,
						      "Close", GTK_RESPONSE_NONE,
						      NULL);
		
		g_signal_connect (window, "response",
				  G_CALLBACK (gtk_widget_destroy), NULL);
		g_signal_connect (window, "destroy",
				  G_CALLBACK (gtk_widget_destroyed), &window);
		
		vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
		gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
				    vbox, TRUE, TRUE, 0);
		gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
		
		label = gtk_label_new ("This example shows 2 GdauiBasicForm widgets operating on the\n"
				       "same GdaSet. When a value is modified in one form, then it is\n"
				       "automatically updated in the other form.\n\n"
				       "Also the top form uses the default layout, while the bottom one\n"
				       "uses a custom (2 columns) layout.\n"
				       "The 'an int' entry is hidden in the top form.");
		gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
		
		/* Create the demo widget */
		GdaSet *set;
		gchar *filename;
		set = gda_set_new_inline (3,
					  "a string", G_TYPE_STRING, "A string Value",
					  "an int", G_TYPE_INT, 12,
					  "a picture", GDA_TYPE_BINARY, NULL);
		form = gdaui_basic_form_new (set);
		gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
		gdaui_basic_form_entry_set_visible (GDAUI_BASIC_FORM (form), gda_set_get_holder (set, "an int"), FALSE);

		label = gtk_label_new ("2nd form is below:");
		gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

		form = gdaui_basic_form_new (set);
		gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);

                filename = demo_find_file ("custom_layout.xml", NULL);
		gdaui_basic_form_set_layout_from_file (GDAUI_BASIC_FORM (form), filename, "simple");
		g_free (filename);

		g_object_unref (set);
	}

	gboolean visible;
	g_object_get (G_OBJECT (window), "visible", &visible, NULL);
	if (!visible)
		gtk_widget_show_all (window);
	else {
		gtk_widget_destroy (window);
		window = NULL;
	}

	return window;
}