1 /* Forms/Using the picture plugin
2 *
3 * A GdauiForm widget where the 'picture' plugin is used to display an image
4 * internally stored as a BLOB
5 */
6
7 #include <libgda-ui/libgda-ui.h>
8 #include <sql-parser/gda-sql-parser.h>
9
10 extern GdaConnection *demo_cnc;
11 extern GdaSqlParser *demo_parser;
12 static GtkWidget *window = NULL;
13
14 GtkWidget *
do_form_pict(GtkWidget * do_widget)15 do_form_pict (GtkWidget *do_widget)
16 {
17 if (!window) {
18 GdaStatement *stmt;
19 GtkWidget *vbox;
20 GtkWidget *label;
21 GdaDataModel *model;
22 GtkWidget *form;
23 GdaSet *data_set;
24 GdaHolder *param;
25 GValue *value;
26
27 window = gtk_dialog_new_with_buttons ("Form with the 'picture' plugin",
28 GTK_WINDOW (do_widget),
29 0,
30 GTK_STOCK_CLOSE,
31 GTK_RESPONSE_NONE,
32 NULL);
33
34 g_signal_connect (window, "response",
35 G_CALLBACK (gtk_widget_destroy), NULL);
36 g_signal_connect (window, "destroy",
37 G_CALLBACK (gtk_widget_destroyed), &window);
38
39 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
40 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
41 vbox, TRUE, TRUE, 0);
42 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
43
44 label = gtk_label_new ("The following GdauiForm widget displays data from the 'pictures' table.\n\n"
45 "The pictures are stored as BLOB inside the database and\n"
46 "are displayed using the 'picture' plugin (right click to \n"
47 "open a menu, or double click to load an image).");
48 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
49
50 /* Create the demo widget */
51 stmt = gda_sql_parser_parse_string (demo_parser, "SELECT id, pict FROM pictures", NULL, NULL);
52 model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
53 g_object_unref (stmt);
54 gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), NULL);
55 form = gdaui_form_new (model);
56 g_object_unref (model);
57 g_object_set (G_OBJECT (form), "info-flags",
58 GDAUI_DATA_PROXY_INFO_CURRENT_ROW |
59 GDAUI_DATA_PROXY_INFO_ROW_MOVE_BUTTONS |
60 GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS, NULL);
61
62 /* specify that we want to use the 'picture' plugin */
63 data_set = GDA_SET (gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (form)));
64 param = gda_set_get_holder (data_set, "pict");
65 value = gda_value_new_from_string ("picture", G_TYPE_STRING);
66 gda_holder_set_attribute_static (param, GDAUI_ATTRIBUTE_PLUGIN, value);
67 gda_value_free (value);
68
69 gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
70 }
71
72 gboolean visible;
73 g_object_get (G_OBJECT (window), "visible", &visible, NULL);
74 if (!visible)
75 gtk_widget_show_all (window);
76 else {
77 gtk_widget_destroy (window);
78 window = NULL;
79 }
80
81 return window;
82 }
83
84
85