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 create_connection (NmtNewtWidget *widget, gpointer list) { NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE (list); GType type = (GType) GPOINTER_TO_SIZE (nmt_newt_listbox_get_active_key (priv->listbox)); NMConnection *connection; connection = nm_editor_utils_create_connection (type, priv->master, nm_client); nmt_edit_connection (connection); g_object_unref (connection); nmt_newt_form_quit (list); }
/** * nmt_connect_connection_list_get_selection: * @list: an #NmtConnectConnectionList * @connection: (out) (transfer none): the #NMConnection to be activated * @device: (out) (transfer none): the #NMDevice to activate @connection on * @specific_object: (out) (transfer none): the "specific object" to connect to * @active: (out) (transfer none): the #NMActiveConnection corresponding * to the selection, if any. * * Gets information about the selected row. * * Returns: %TRUE if there is a selection, %FALSE if not. */ gboolean nmt_connect_connection_list_get_selection (NmtConnectConnectionList *list, NMConnection **connection, NMDevice **device, NMObject **specific_object, NMActiveConnection **active) { NmtConnectConnection *nmtconn; nmtconn = nmt_newt_listbox_get_active_key (NMT_NEWT_LISTBOX (list)); if (!nmtconn) return FALSE; if (connection) *connection = nmtconn->conn; if (device) *device = nmtconn->device; if (specific_object) *specific_object = NM_OBJECT (nmtconn->ap); if (active) *active = nmtconn->active; return TRUE; }