NMConnectionEditor * nm_connection_editor_new (GtkWindow *parent_window, NMConnection *connection, NMClient *client) { NMConnectionEditor *editor; GtkWidget *hbox; gboolean is_new; GError *error = NULL; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); is_new = !nm_client_get_connection_by_uuid (client, nm_connection_get_uuid (connection)); editor = g_object_new (NM_TYPE_CONNECTION_EDITOR, NULL); editor->parent_window = parent_window ? g_object_ref (parent_window) : NULL; editor->client = g_object_ref (client); editor->is_new_connection = is_new; editor->can_modify = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM); editor->permission_id = g_signal_connect (editor->client, "permission-changed", G_CALLBACK (permissions_changed_cb), editor); editor->ok_button = ce_polkit_button_new (_("_Save"), _("Save any changes made to this connection."), _("Authenticate to save this connection for all users of this machine."), GTK_STOCK_APPLY, client, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM); gtk_button_set_use_underline (GTK_BUTTON (editor->ok_button), TRUE); g_signal_connect (editor->ok_button, "actionable", G_CALLBACK (ok_button_actionable_cb), editor); g_signal_connect (editor->ok_button, "authorized", G_CALLBACK (ok_button_actionable_cb), editor); hbox = GTK_WIDGET (gtk_builder_get_object (editor->builder, "action_area_hbox")); gtk_box_pack_end (GTK_BOX (hbox), editor->ok_button, TRUE, TRUE, 0); gtk_widget_show_all (editor->ok_button); if (!nm_connection_editor_set_connection (editor, connection, &error)) { nm_connection_editor_error (parent_window, is_new ? _("Could not create connection") : _("Could not edit connection"), "%s", error ? error->message : _("Unknown error creating connection editor dialog.")); g_clear_error (&error); g_object_unref (editor); return NULL; } if (!active_editors) active_editors = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL); g_hash_table_insert (active_editors, g_object_ref (connection), editor); return editor; }
/** * nmt_connect_connection_list_get_connection: * @list: an #NmtConnectConnectionList * @identifier: a connection ID or UUID, or device name * @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 indicated connection. * * Returns: %TRUE if there was a match, %FALSE if not. */ gboolean nmt_connect_connection_list_get_connection (NmtConnectConnectionList *list, const char *identifier, NMConnection **connection, NMDevice **device, NMObject **specific_object, NMActiveConnection **active) { NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE (list); GSList *diter, *citer; NmtConnectDevice *nmtdev; NmtConnectConnection *nmtconn = NULL; NMConnection *conn = NULL; g_return_val_if_fail (identifier, FALSE); if (nm_utils_is_uuid (identifier)) conn = NM_CONNECTION (nm_client_get_connection_by_uuid (nm_client, identifier)); if (!conn) conn = NM_CONNECTION (nm_client_get_connection_by_id (nm_client, identifier)); for (diter = priv->nmt_devices; diter; diter = diter->next) { nmtdev = diter->data; if (!nmtdev->conns) continue; for (citer = nmtdev->conns; citer; citer = citer->next) { nmtconn = citer->data; if (conn) { if (conn == nmtconn->conn) goto found; } else if (nmtconn->ssid && !strcmp (identifier, nmtconn->ssid)) goto found; } if (!conn && nmtdev->device && !strcmp (identifier, nm_device_get_ip_iface (nmtdev->device))) { nmtconn = nmtdev->conns->data; goto found; } } return FALSE; found: 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; }
NmtNewtForm * nmtui_edit (gboolean is_top, int argc, char **argv) { NMConnection *conn = NULL; if (argc == 2) { if (nm_utils_is_uuid (argv[1])) conn = NM_CONNECTION (nm_client_get_connection_by_uuid (nm_client, argv[1])); if (!conn) conn = NM_CONNECTION (nm_client_get_connection_by_id (nm_client, argv[1])); if (!conn) { nmt_newt_message_dialog ("%s: no such connection '%s'\n", argv[0], argv[1]); return NULL; } return nmt_editor_new (conn); } else return nmt_edit_main_connection_list (is_top); }