/** * ui_formgrid_new * @model: a #GdaDataModel * @scroll_form: set to %TRUE to wrap the embedded form in a scrolled window * @flags: the #GdauiDataProxyInfoFlag, specifying what to display in the new widget * * Creates a new #UiFormGrid widget suitable to display the data in @model * * Returns: the new widget */ GtkWidget * ui_formgrid_new (GdaDataModel *model, gboolean scroll_form, GdauiDataProxyInfoFlag flags) { UiFormGrid *formgrid; GdaDataProxy *proxy; g_return_val_if_fail (!model || GDA_IS_DATA_MODEL (model), NULL); formgrid = (UiFormGrid *) g_object_new (UI_TYPE_FORMGRID, "scroll-form", scroll_form, NULL); formgrid->priv->flags = flags; /* a raw form and a raw grid for the same proxy */ g_object_set (formgrid->priv->raw_grid, "model", model, NULL); proxy = gdaui_data_proxy_get_proxy (GDAUI_DATA_PROXY (formgrid->priv->raw_grid)); g_object_set (formgrid->priv->raw_form, "model", proxy, NULL); gdaui_data_proxy_set_write_mode (GDAUI_DATA_PROXY (formgrid->priv->raw_form), GDAUI_DATA_PROXY_WRITE_ON_DEMAND); g_object_set (G_OBJECT (formgrid->priv->info), "flags", formgrid->priv->flags | GRID_FLAGS, NULL); g_signal_connect (formgrid->priv->raw_grid, "proxy-changed", G_CALLBACK (proxy_changed_cb), formgrid); /* no more than 300 rows at a time */ if (model) { gda_data_proxy_set_sample_size (proxy, 300); if (flags & GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS) g_object_set (G_OBJECT (formgrid), "compute-mod-statements", TRUE, NULL); } return (GtkWidget *) formgrid; }
GtkWidget * provider_config_new (void) { ProviderConfigPrivate *priv; GtkWidget *provider; GtkWidget *box; GtkWidget *image; GtkWidget *label; GtkWidget *sw; gchar *title; GdaDataModel *model; priv = g_new0 (ProviderConfigPrivate, 1); provider = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_show (provider); gtk_container_set_border_width (GTK_CONTAINER (provider), 6); g_object_set_data_full (G_OBJECT (provider), PROVIDER_CONFIG_DATA, priv, (GDestroyNotify) g_free); /* title */ title = g_strdup_printf ("<b>%s</b>\n%s", _("Providers"), _("Installed providers")); priv->title = gdaui_bar_new (title); g_free (title); gchar *path; path = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "gdaui-generic.png", NULL); gdaui_bar_set_icon_from_file (GDAUI_BAR (priv->title), path); g_free (path); gtk_box_pack_start (GTK_BOX (provider), priv->title, FALSE, FALSE, 0); gtk_widget_show (priv->title); /* create the provider list */ sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (provider), sw, TRUE, TRUE, 0); model = gda_config_list_providers (); priv->provider_list = gdaui_raw_grid_new (model); g_object_unref (model); gdaui_data_proxy_column_set_editable (GDAUI_DATA_PROXY (priv->provider_list), 0, FALSE); gdaui_data_selector_set_column_visible (GDAUI_DATA_SELECTOR (priv->provider_list), 2, FALSE); g_object_set (G_OBJECT (priv->provider_list), "info-cell-visible", FALSE, NULL); gtk_container_add (GTK_CONTAINER (sw), priv->provider_list); gtk_widget_show_all (sw); /* add tip */ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_widget_show (box); gtk_container_set_border_width (GTK_CONTAINER (box), 6); gtk_box_pack_start (GTK_BOX (provider), box, FALSE, FALSE, 0); image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG); gtk_widget_show (image); gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); label = gtk_label_new (_("Providers are addons that actually implement the access " "to each database using the means provided by each database vendor.")); gtk_widget_show (label); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_box_pack_start (GTK_BOX (box), label, TRUE, FALSE, 0); return provider; }
GtkWidget * do_form_model_change (GtkWidget *do_widget) { if (!window) { GdaStatement *stmt; GtkWidget *vbox; GtkWidget *label; GdaDataModel *models [3]; window = gtk_dialog_new_with_buttons ("Changing data in a GdauiForm", 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 ("The data in the same GdauiForm widget can be change don the fly."); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); /* creating data models */ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products ORDER BY ref, category LIMIT 15", NULL, NULL); models[0] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL); gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[0]), NULL); g_object_unref (stmt); stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products WHERE price > 20.2 ORDER BY ref, category LIMIT 10", NULL, NULL); models[1] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL); gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[1]), NULL); g_object_unref (stmt); stmt = gda_sql_parser_parse_string (demo_parser, "SELECT name, price, ref, category FROM products WHERE price > 20.2 ORDER BY name LIMIT 30", NULL, NULL); models[2] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL); gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[2]), NULL); g_object_unref (stmt); /* allow choosing which data model to display */ label = gtk_label_new (""); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_label_set_markup (GTK_LABEL (label), "<b>Choose which data model to display:</b>"); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); GtkWidget *layout, *rb; GSList *group = NULL; gint i; layout = gtk_grid_new (); gtk_box_pack_start (GTK_BOX (vbox), layout, FALSE, FALSE, 0); for (i = 0; i < 3; i++) { gchar *str; str = g_strdup_printf ("%d columns x %d rows", gda_data_model_get_n_columns (models[i]), gda_data_model_get_n_rows (models[i])); rb = gtk_radio_button_new_with_label (group, str); g_free (str); gtk_grid_attach (GTK_GRID (layout), rb, i, 0, 1, 1); g_signal_connect (rb, "toggled", G_CALLBACK (model_toggled_cb), models[i]); g_object_set_data_full (G_OBJECT (rb), "model", models[i], g_object_unref); group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb)); } /* Create the form widget */ label = gtk_label_new (""); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_label_set_markup (GTK_LABEL (label), "<b>GdauiForm:</b>"); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); form = gdaui_form_new (models[0]); 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); gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0); GdaDataProxy *proxy; proxy = gdaui_data_proxy_get_proxy (GDAUI_DATA_PROXY (form)); g_object_set (proxy, "cache-changes", TRUE, NULL); } 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 * dsn_config_new (void) { DsnConfigPrivate *priv; GtkWidget *dsn; GtkWidget *label; GtkWidget *sw; gchar *title; GdaDataModel *model; priv = g_new0 (DsnConfigPrivate, 1); dsn = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_widget_show (dsn); gtk_container_set_border_width (GTK_CONTAINER (dsn), 6); g_object_set_data_full (G_OBJECT (dsn), DSN_CONFIG_DATA, priv, (GDestroyNotify) free_private_data); /* title */ title = g_strdup_printf ("<b>%s</b>\n%s", _("Data Sources"), _("Data sources are the means by which database " "connections are identified: all " "the information needed to open a connection to " "a specific database using a 'provider' is referenced using " "a unique name.")); priv->title = gdaui_bar_new (title); g_free (title); gdaui_bar_set_icon_from_resource (GDAUI_BAR (priv->title), "/images/gdaui-generic.png"); gtk_box_pack_start (GTK_BOX (dsn), priv->title, FALSE, FALSE, 0); gtk_widget_show (priv->title); /* horizontal box for the provider list and its properties */ GtkWidget *hbox; hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (dsn), hbox, TRUE, TRUE, 0); /* left part */ GtkWidget *vbox; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_size_request (vbox, 150, -1); gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); /* create the data source list */ sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); model = gda_config_list_dsn (); priv->dsn_list = gdaui_raw_grid_new (model); gtk_tree_view_move_column_after (GTK_TREE_VIEW (priv->dsn_list), gtk_tree_view_get_column (GTK_TREE_VIEW (priv->dsn_list), 1), gtk_tree_view_get_column (GTK_TREE_VIEW (priv->dsn_list), 2)); g_object_unref (model); g_object_set_data (G_OBJECT (dsn), "grid", priv->dsn_list); gdaui_data_proxy_column_set_editable (GDAUI_DATA_PROXY (priv->dsn_list), 0, FALSE); gdaui_data_selector_set_column_visible (GDAUI_DATA_SELECTOR (priv->dsn_list), -1, FALSE); gdaui_data_selector_set_column_visible (GDAUI_DATA_SELECTOR (priv->dsn_list), 0, TRUE); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->dsn_list), FALSE); g_object_set (priv->dsn_list, "info-cell-visible", FALSE, NULL); gtk_container_add (GTK_CONTAINER (sw), priv->dsn_list); g_signal_connect (priv->dsn_list, "selection-changed", G_CALLBACK (list_selection_changed_cb), dsn); g_signal_connect (priv->dsn_list, "populate-popup", G_CALLBACK (list_popup_cb), dsn); /* add/delete buttons */ GtkWidget *toolbar; toolbar = gtk_toolbar_new (); gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), "inline-toolbar"); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); GtkToolItem *titem; titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "list-add-symbolic"); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.DatasourceNew"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "list-remove-symbolic"); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.DatasourceDelete"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); /* create the data source's properties */ GtkWidget *stack; stack = gtk_stack_new (); priv->stack = stack; gtk_box_pack_start (GTK_BOX (hbox), stack, TRUE, TRUE, 10); label = gtk_label_new (_("No data source selected.")); gtk_stack_add_named (GTK_STACK (stack), label, ST_NOPROP); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_stack_add_named (GTK_STACK (stack), vbox, ST_PROP); GtkWidget *form; form = gdaui_dsn_editor_new (); priv->dsn_editor = GDAUI_DSN_EDITOR (form); gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0); g_signal_connect (priv->dsn_editor, "changed", G_CALLBACK (dsn_editor_changed_cb), dsn); /* action buttons */ GtkWidget *hbox2; hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 6); GtkWidget *bbox; bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_widget_set_hexpand (bbox, TRUE); gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_CENTER); gtk_box_pack_start (GTK_BOX (hbox2), bbox, FALSE, FALSE, 6); GtkWidget *button; button = gtk_toggle_button_new_with_label (_("Definition")); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); priv->view_buttons [GDAUI_DSN_EDITOR_PANE_DEFINITION] = GTK_TOGGLE_BUTTON (button); g_signal_connect (button, "toggled", G_CALLBACK (view_toggled_cb), dsn); button = gtk_toggle_button_new_with_label (_("Parameters")); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); priv->view_buttons [GDAUI_DSN_EDITOR_PANE_PARAMS] = GTK_TOGGLE_BUTTON (button); g_signal_connect (button, "toggled", G_CALLBACK (view_toggled_cb), dsn); button = gtk_toggle_button_new_with_label (_("Authentication")); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); priv->view_buttons [GDAUI_DSN_EDITOR_PANE_AUTH] = GTK_TOGGLE_BUTTON (button); g_signal_connect (button, "toggled", G_CALLBACK (view_toggled_cb), dsn); button = gtk_button_new_from_icon_name ("document-save-symbolic", GTK_ICON_SIZE_BUTTON); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); priv->commit_button = button; gtk_widget_set_sensitive (button, FALSE); gtk_widget_set_tooltip_text (button, _("Write changes made to the DSN")); g_signal_connect (button, "clicked", G_CALLBACK (save_cb), dsn); gtk_widget_show_all (hbox); return dsn; }
static void ui_formgrid_init (UiFormGrid *formgrid) { GtkWidget *sw; GtkWidget *hbox, *button; formgrid->priv = g_new0 (UiFormGridPriv, 1); formgrid->priv->raw_grid = NULL; formgrid->priv->info = NULL; formgrid->priv->flags = GDAUI_DATA_PROXY_INFO_CURRENT_ROW | GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS; formgrid->priv->tcnc = NULL; formgrid->priv->autoupdate = TRUE; formgrid->priv->autoupdate_possible = FALSE; formgrid->priv->scroll_form = FALSE; formgrid->priv->compute_mod_stmt = FALSE; formgrid->priv->refresh_callback = NULL; formgrid->priv->refresh_user_data = NULL; gtk_orientable_set_orientation (GTK_ORIENTABLE (formgrid), GTK_ORIENTATION_VERTICAL); /* notebook */ formgrid->priv->nb = gtk_notebook_new (); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (formgrid->priv->nb), FALSE); gtk_notebook_set_show_border (GTK_NOTEBOOK (formgrid->priv->nb), FALSE); gtk_box_pack_start (GTK_BOX (formgrid), formgrid->priv->nb, TRUE, TRUE, 0); gtk_widget_show (formgrid->priv->nb); /* grid on 1st page of notebook, not added there */ formgrid->priv->raw_grid = gdaui_raw_grid_new (NULL); gdaui_data_proxy_column_show_actions (GDAUI_DATA_PROXY (formgrid->priv->raw_grid), -1, FALSE); g_signal_connect (formgrid->priv->raw_grid, "populate-popup", G_CALLBACK (form_grid_populate_popup_cb), formgrid); /* form on the 2nd page of the notebook, not added there */ formgrid->priv->raw_form = gdaui_raw_form_new (NULL); gdaui_data_proxy_column_show_actions (GDAUI_DATA_PROXY (formgrid->priv->raw_form), -1, FALSE); g_signal_connect (formgrid->priv->raw_form, "populate-popup", G_CALLBACK (form_grid_populate_popup_cb), formgrid); /* info widget and toggle button at last */ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (formgrid), hbox, FALSE, TRUE, 0); gtk_widget_show (hbox); /* button to toggle between auto update and not */ button = gtk_toggle_button_new (); GtkWidget *img = gtk_image_new_from_icon_name (_("_Execute"), GTK_ICON_SIZE_MENU); gtk_button_set_image (GTK_BUTTON (button), img); formgrid->priv->autoupdate_toggle = button; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), formgrid->priv->autoupdate); gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, TRUE, 0); g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (form_grid_autoupdate_cb), formgrid); gtk_widget_set_tooltip_text (button, _("Enable or disable auto update of data")); /* Proxy info */ formgrid->priv->info = gdaui_data_proxy_info_new (GDAUI_DATA_PROXY (formgrid->priv->raw_grid), formgrid->priv->flags | GDAUI_DATA_PROXY_INFO_CURRENT_ROW | GDAUI_DATA_PROXY_INFO_CHUNCK_CHANGE_BUTTONS); button = GTK_WIDGET (gtk_toggle_tool_button_new ()); gtk_widget_set_tooltip_text (button, _("Toggle between grid and form presentations")); gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (button), TRUE); gtk_toolbar_insert (GTK_TOOLBAR (formgrid->priv->info), GTK_TOOL_ITEM (button), 0); gtk_widget_show (button); g_signal_connect (button, "toggled", G_CALLBACK (form_grid_toggled_cb), formgrid); /* refresh button, don't show it yet */ button = GTK_WIDGET (gtk_tool_button_new (NULL, NULL)); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (button), "view-refresh-symbolic"); gtk_widget_set_tooltip_text (button, _("Refresh data")); gtk_toolbar_insert (GTK_TOOLBAR (formgrid->priv->info), GTK_TOOL_ITEM (button), 0); formgrid->priv->refresh_button = button; /* keep data in sync */ g_signal_connect (formgrid->priv->raw_grid, "selection-changed", G_CALLBACK (selection_changed_cb), formgrid); g_signal_connect (formgrid->priv->raw_form, "selection-changed", G_CALLBACK (selection_changed_cb), formgrid); }
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; }