static NmtNewtForm * nmtui_main (int argc, char **argv) { NmtNewtForm *form; NmtNewtWidget *widget, *ok; NmtNewtGrid *grid; NmtNewtListbox *listbox; NmtNewtButtonBox *bbox; NmtuiSubprogram subprogram = NULL; int i; form = g_object_new (NMT_TYPE_NEWT_FORM, "title", _("NetworkManager TUI"), "escape-exits", TRUE, NULL); widget = nmt_newt_grid_new (); nmt_newt_form_set_content (form, widget); grid = NMT_NEWT_GRID (widget); widget = nmt_newt_label_new (_("Please select an option")); nmt_newt_grid_add (grid, widget, 0, 0); widget = g_object_new (NMT_TYPE_NEWT_LISTBOX, "height", num_subprograms + 2, "skip-null-keys", TRUE, NULL); nmt_newt_grid_add (grid, widget, 0, 1); nmt_newt_widget_set_padding (widget, 0, 1, 0, 1); nmt_newt_widget_set_exit_on_activate (widget, TRUE); listbox = NMT_NEWT_LISTBOX (widget); for (i = 0; i < num_subprograms; i++) { nmt_newt_listbox_append (listbox, _(subprograms[i].display_name), subprograms[i].func); } nmt_newt_listbox_append (listbox, "", NULL); nmt_newt_listbox_append (listbox, _("Quit"), quit_func); widget = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_HORIZONTAL); nmt_newt_grid_add (grid, widget, 0, 2); bbox = NMT_NEWT_BUTTON_BOX (widget); ok = nmt_newt_button_box_add_end (bbox, _("OK")); nmt_newt_widget_set_exit_on_activate (ok, TRUE); widget = nmt_newt_form_run_sync (form); if (widget) subprogram = nmt_newt_listbox_get_active_key (listbox); g_object_unref (form); if (subprogram) return subprogram (argc, argv); else return NULL; }
static void edit_routes (NmtNewtButton *button, gpointer user_data) { NMSetting *s_ip4 = user_data; NmtNewtForm *form; form = nmt_route_editor_new (s_ip4); nmt_newt_form_run_sync (form); g_object_unref (form); }
static char * nmtui_hostname_run_dialog (void) { NmtNewtForm *form; NmtNewtWidget *widget, *ok, *cancel; NmtNewtGrid *grid; NmtNewtEntry *entry; NmtNewtButtonBox *bbox; char *hostname, *ret = NULL; form = g_object_new (NMT_TYPE_NEWT_FORM, "title", _("Set Hostname"), "escape-exits", TRUE, NULL); widget = nmt_newt_grid_new (); nmt_newt_form_set_content (form, widget); grid = NMT_NEWT_GRID (widget); widget = nmt_newt_label_new (_("Hostname")); nmt_newt_grid_add (grid, widget, 0, 0); widget = nmt_newt_entry_new (40, 0); nmt_newt_widget_set_exit_on_activate (widget, TRUE); nmt_newt_grid_add (grid, widget, 1, 0); nmt_newt_widget_set_padding (widget, 1, 0, 0, 0); entry = NMT_NEWT_ENTRY (widget); widget = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_HORIZONTAL); nmt_newt_grid_add (grid, widget, 1, 1); nmt_newt_widget_set_padding (widget, 0, 1, 0, 0); bbox = NMT_NEWT_BUTTON_BOX (widget); cancel = nmt_newt_button_box_add_end (bbox, _("Cancel")); nmt_newt_widget_set_exit_on_activate (cancel, TRUE); ok = nmt_newt_button_box_add_end (bbox, _("OK")); nmt_newt_widget_set_exit_on_activate (ok, TRUE); g_object_get (G_OBJECT (nm_client), NM_CLIENT_HOSTNAME, &hostname, NULL); nmt_newt_entry_set_text (entry, hostname); g_free (hostname); widget = nmt_newt_form_run_sync (form); if (widget == (NmtNewtWidget *)entry || widget == ok) ret = g_strdup (nmt_newt_entry_get_text (entry)); g_object_unref (form); return ret; }
static void secrets_requested (NMSecretAgentSimple *agent, const char *request_id, const char *title, const char *msg, GPtrArray *secrets, gpointer user_data) { NmtNewtForm *form; form = nmt_password_dialog_new (request_id, title, msg, secrets); nmt_newt_form_run_sync (form); if (nmt_password_dialog_succeeded (NMT_PASSWORD_DIALOG (form))) nm_secret_agent_simple_response (agent, request_id, secrets); else nm_secret_agent_simple_response (agent, request_id, NULL); g_object_unref (form); }
static void nmt_newt_popup_activated (NmtNewtWidget *widget) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (widget); NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data; NmtNewtForm *form; NmtNewtWidget *listbox, *ret; int button_x, button_y; int window_x, window_y; int list_w, list_h; int i, active; listbox = nmt_newt_listbox_new (priv->entries->len, 0); nmt_newt_widget_set_exit_on_activate (listbox, TRUE); for (i = 0; i < priv->entries->len; i++) nmt_newt_listbox_append (NMT_NEWT_LISTBOX (listbox), entries[i].label, NULL); nmt_newt_listbox_set_active (NMT_NEWT_LISTBOX (listbox), priv->active); nmt_newt_widget_set_padding (listbox, 1, 0, 1, 0); nmt_newt_widget_size_request (listbox, &list_w, &list_h); g_object_get (nmt_newt_widget_get_form (widget), "x", &window_x, "y", &window_y, NULL); newtComponentGetPosition (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)), &button_x, &button_y); /* (window_x + button_x) is the screen X coordinate of the newtComponent. A * newtButton labelled "Foo" is rendered as " <Foo>" (with a preceding * space), so the "F" is at (window_x + button_x + 2). We've added 1 column * of padding to the left of the listbox, so we need to position the popup * at (window_x + button_x + 1) in order for its text to be aligned with the * button's text. (The x and y coordinates given to NmtNewtForm are the * coordinates of the top left of the window content, ignoring the border * graphics.) */ window_x += button_x + 1; window_y += button_y - priv->active; form = g_object_new (NMT_TYPE_NEWT_FORM, "x", window_x, "y", window_y, "width", list_w, "height", list_h, "padding", 0, "escape-exits", TRUE, NULL); nmt_newt_form_set_content (form, listbox); ret = nmt_newt_form_run_sync (form); if (ret == listbox) active = nmt_newt_listbox_get_active (NMT_NEWT_LISTBOX (listbox)); else active = priv->active; g_object_unref (form); if (active != priv->active) { priv->active = active; g_object_notify (G_OBJECT (widget), "active"); g_object_notify (G_OBJECT (widget), "active-id"); nmt_newt_widget_needs_rebuild (widget); } NMT_NEWT_WIDGET_CLASS (nmt_newt_popup_parent_class)->activated (widget); }