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); }
static void save_connection_and_exit (NmtNewtButton *button, gpointer user_data) { NmtEditor *editor = user_data; NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor); NmtSyncOp op; GError *error = NULL; if (!nm_connection_replace_settings_from_connection (priv->orig_connection, priv->edit_connection, &error)) { nmt_newt_message_dialog (_("Error saving connection: %s"), error->message); g_error_free (error); return; } nmt_sync_op_init (&op); if (NM_IS_REMOTE_CONNECTION (priv->orig_connection)) { nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (priv->orig_connection), connection_updated, &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { nmt_newt_message_dialog (_("Unable to save connection: %s"), error->message); g_error_free (error); return; } /* Clear secrets so they don't lay around in memory; they'll get * requested again anyway next time the connection is edited. */ nm_connection_clear_secrets (priv->orig_connection); } else { nm_remote_settings_add_connection (nm_settings, priv->orig_connection, connection_added, &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { nmt_newt_message_dialog (_("Unable to add new connection: %s"), error->message); g_error_free (error); return; } } nmt_newt_form_quit (NMT_NEWT_FORM (editor)); }
/* A "normal" newt program would call newtFormRun() to run newt's main loop * and process events. But we want to let GLib's main loop control the program * (eg, so libnm can process D-Bus notifications). So we call this function * to run a single iteration of newt's main loop (or rather, to run newt's * main loop for 1ms) whenever there are events for newt to process (redrawing * or keypresses). */ static void nmt_newt_form_iterate (NmtNewtForm *form) { NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form); NmtNewtWidget *focus; struct newtExitStruct es; if (priv->dirty) { nmt_newt_form_destroy (form); nmt_newt_form_build (form); } newtFormSetTimer (priv->form, 1); newtFormRun (priv->form, &es); if ( es.reason == NEWT_EXIT_HOTKEY || es.reason == NEWT_EXIT_ERROR) { /* The user hit Esc or there was an error. */ g_clear_object (&priv->focus); nmt_newt_form_quit (form); return; } if (es.reason == NEWT_EXIT_COMPONENT) { /* The user hit Return/Space on a component; update the form focus * to point that that component, and activate it. */ focus = nmt_newt_widget_find_component (priv->content, es.u.co); if (focus) { nmt_newt_form_set_focus (form, focus); nmt_newt_widget_activated (focus); } } else { /* The 1ms timer ran out. Update focus but don't do anything else. */ focus = nmt_newt_widget_find_component (priv->content, newtFormGetCurrent (priv->form)); if (focus) nmt_newt_form_set_focus (form, focus); } }
static void maybe_save_input_and_exit (NmtNewtWidget *widget, gpointer dialog) { NmtPasswordDialogPrivate *priv = NMT_PASSWORD_DIALOG_GET_PRIVATE (dialog); int i; /* This gets invoked when the user types Return in the final entry, * but the form may not be fully valid in that case. */ if (!nmt_newt_widget_get_valid (priv->secret_grid)) return; priv->succeeded = TRUE; for (i = 0; i < priv->secrets->len; i++) { NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i]; g_free (secret->value); g_object_get (priv->entries->pdata[i], "text", &secret->value, NULL); } nmt_newt_form_quit (nmt_newt_widget_get_form (widget)); }
static void activate_connection (NMConnection *connection, NMDevice *device, NMObject *specific_object) { NmtNewtForm *form; gs_unref_object NMSecretAgentOld *agent = NULL; NmtNewtWidget *label; NmtSyncOp op; const char *specific_object_path; NMActiveConnection *ac; GError *error = NULL; form = g_object_new (NMT_TYPE_NEWT_FORM, "escape-exits", TRUE, NULL); label = nmt_newt_label_new (_("Connecting...")); nmt_newt_form_set_content (form, label); agent = nm_secret_agent_simple_new ("nmtui"); if (agent) { if (connection) { nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent), nm_object_get_path (NM_OBJECT (connection))); } g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), NULL); } specific_object_path = specific_object ? nm_object_get_path (specific_object) : NULL; /* There's no way to cancel an nm_client_activate_connection() / * nm_client_add_and_activate_connection() call, so we always let them * complete, even if the user hits Esc; they shouldn't normally take long * to complete anyway. */ nmt_sync_op_init (&op); if (connection) { nm_client_activate_connection_async (nm_client, connection, device, specific_object_path, NULL, activate_callback, &op); } else { nm_client_add_and_activate_connection_async (nm_client, NULL, device, specific_object_path, NULL, add_and_activate_callback, &op); } nmt_newt_form_show (form); ac = nmt_sync_op_wait_pointer (&op, &error); if (!ac) { nmt_newt_message_dialog (_("Could not activate connection: %s"), error->message); g_clear_error (&error); goto done; } else if (nm_active_connection_get_state (ac) == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { /* Already active */ goto done; } else if (!nmt_newt_widget_get_realized (NMT_NEWT_WIDGET (form))) { /* User already hit Esc */ goto done; } if (agent && !connection) { connection = NM_CONNECTION (nm_active_connection_get_connection (ac)); if (connection) { nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent), nm_object_get_path (NM_OBJECT (connection))); } } /* Now wait for the connection to actually reach the ACTIVATED state, * allowing the user to cancel if it takes too long. */ nmt_sync_op_init (&op); g_signal_connect (form, "quit", G_CALLBACK (connect_cancelled), &op); g_signal_connect (ac, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (activate_ac_state_changed), &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) nmt_newt_message_dialog (_("Could not activate connection: %s"), error->message); g_clear_error (&error); } g_signal_handlers_disconnect_by_func (form, G_CALLBACK (connect_cancelled), &op); g_signal_handlers_disconnect_by_func (ac, G_CALLBACK (activate_ac_state_changed), &op); done: if (nmt_newt_widget_get_realized (NMT_NEWT_WIDGET (form))) nmt_newt_form_quit (form); g_object_unref (form); if (agent) nm_secret_agent_old_unregister (agent, NULL, NULL); }