Exemple #1
0
static void
handle_user_prefs_for_sql_statement (UiFormGrid *formgrid, TConnection *tcnc,
				     GdaSqlStatement *sqlst)
{
	g_assert (sqlst);
	if (sqlst->stmt_type == GDA_SQL_STATEMENT_COMPOUND) {
		GdaSqlStatementCompound *comp;
		GSList *list;
		comp = (GdaSqlStatementCompound*) sqlst->contents;
		for (list = comp->stmt_list; list; list = list->next)
			handle_user_prefs_for_sql_statement (formgrid, tcnc,
							     (GdaSqlStatement *) list->data);
	}
	else {
		GdaSet *set;
		set = (GdaSet*) ui_formgrid_get_form_data_set (UI_FORMGRID (formgrid));

		GdaSqlStatementSelect *sel;
		GSList *list;
		gint pos;
		sel = (GdaSqlStatementSelect*) sqlst->contents;
		for (pos = 0, list = sel->expr_list; list; pos ++, list = list->next) {
			GdaSqlSelectField *field = (GdaSqlSelectField*) list->data;
			if (! field->validity_meta_object ||
			    (field->validity_meta_object->obj_type != GDA_META_DB_TABLE) ||
			    !field->validity_meta_table_column)
				continue;

			gchar *plugin;
			plugin = t_connection_get_table_column_attribute (tcnc,
										GDA_META_TABLE (field->validity_meta_object),
										field->validity_meta_table_column,
										T_CONNECTION_COLUMN_PLUGIN, NULL);
			if (!plugin)
				continue;

			GdaHolder *holder;
			holder = gda_set_get_nth_holder (set, pos);
			if (holder) {
				GValue *value;
				value = gda_value_new_from_string (plugin, G_TYPE_STRING);
				gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
				gda_value_free (value);
			}
			g_free (plugin);
		}
	}
}
Exemple #2
0
GtkWidget *
do_form_pict (GtkWidget *do_widget)
{  
	if (!window) {
		GdaStatement *stmt;
		GtkWidget *vbox;
		GtkWidget *label;
		GdaDataModel *model;
		GtkWidget *form;
		GdaSet *data_set;
		GdaHolder *param;
		GValue *value;
		
		window = gtk_dialog_new_with_buttons ("Form with the 'picture' plugin",
						      GTK_WINDOW (do_widget),
						      0,
						      GTK_STOCK_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 ("The following GdauiForm widget displays data from the 'pictures' table.\n\n"
				       "The pictures are stored as BLOB inside the database and\n"
				       "are displayed using the 'picture' plugin (right click to \n"
				       "open a menu, or double click to load an image).");
		gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
		
		/* Create the demo widget */
		stmt = gda_sql_parser_parse_string (demo_parser, "SELECT id, pict FROM pictures", NULL, NULL);
		model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
		g_object_unref (stmt);
		gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), NULL);
		form = gdaui_form_new (model);
		g_object_unref (model);
		g_object_set (G_OBJECT (form), "info-flags",
			      GDAUI_DATA_PROXY_INFO_CURRENT_ROW |
			      GDAUI_DATA_PROXY_INFO_ROW_MOVE_BUTTONS |
			      GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS, NULL);

		/* specify that we want to use the 'picture' plugin */
		data_set = GDA_SET (gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (form)));
		param = gda_set_get_holder (data_set, "pict");
		value = gda_value_new_from_string ("picture", G_TYPE_STRING);
		gda_holder_set_attribute_static (param, GDAUI_ATTRIBUTE_PLUGIN, value);
		gda_value_free (value);

		gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
	}

	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;
}
GtkWidget *
do_data_model_dir (GtkWidget *do_widget)
{
    if (!window) {
        GtkWidget *vbox;
        GtkWidget *label;
        GdaDataModel *model;
        GtkWidget *form, *grid, *nb;
        GdaSet *data_set;
        GdaHolder *param;
        gchar *path;
        GValue *value;

        window = gtk_dialog_new_with_buttons ("GdaDataModelDir data model",
                                              GTK_WINDOW (do_widget),
                                              0,
                                              GTK_STOCK_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 ("The following GdauiForm widget displays data from a GdaDataModelDir "
                               "data model which lists the files contained in the selected directory.\n\n"
                               "Each file contents is then displayed using the 'picture' plugin \n"
                               "(right click to open a menu, or double click to load an image).");
        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

        /* GdaDataModelDir object */
        path = get_data_path ();
        model = gda_data_model_dir_new (path);
        g_free (path);

        /* Create the demo widget */
        nb = gtk_notebook_new ();
        gtk_box_pack_start (GTK_BOX (vbox), nb, TRUE, TRUE, 0);

        form = gdaui_form_new (model);
        gtk_notebook_append_page (GTK_NOTEBOOK (nb), form, gtk_label_new ("Form"));

        grid = gdaui_grid_new (model);
        gtk_notebook_append_page (GTK_NOTEBOOK (nb), grid, gtk_label_new ("Grid"));
        g_object_unref (model);

        /* specify that we want to use the 'picture' plugin */
        data_set = GDA_SET (gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (grid)));
        param = gda_set_get_holder (data_set, "data");

        value = gda_value_new_from_string ("picture", G_TYPE_STRING);
        gda_holder_set_attribute_static (param, GDAUI_ATTRIBUTE_PLUGIN, value);
        gdaui_data_proxy_column_show_actions (GDAUI_DATA_PROXY (grid), -1, TRUE);
        gda_value_free (value);
    }

    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;
}