static void nmt_editor_constructed (GObject *object) { NmtEditor *editor = NMT_EDITOR (object); NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor); NmtNewtWidget *vbox, *buttons, *page; if (G_OBJECT_CLASS (nmt_editor_parent_class)->constructed) G_OBJECT_CLASS (nmt_editor_parent_class)->constructed (object); priv->edit_connection = build_edit_connection (priv->orig_connection); vbox = nmt_newt_grid_new (); page = nmt_page_main_new (priv->edit_connection, priv->type_data); nmt_newt_grid_add (NMT_NEWT_GRID (vbox), page, 0, 0); buttons = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_HORIZONTAL); nmt_newt_grid_add (NMT_NEWT_GRID (vbox), buttons, 0, 1); nmt_newt_widget_set_padding (buttons, 0, 1, 0, 0); priv->cancel = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (buttons), _("Cancel")); nmt_newt_widget_set_exit_on_activate (priv->cancel, TRUE); priv->ok = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (buttons), _("OK")); g_signal_connect (priv->ok, "clicked", G_CALLBACK (save_connection_and_exit), editor); g_object_bind_property (page, "valid", priv->ok, "sensitive", G_BINDING_SYNC_CREATE); nmt_newt_form_set_content (NMT_NEWT_FORM (editor), vbox); }
static void nmt_newt_form_needs_rebuild (NmtNewtWidget *widget) { NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (widget); if (!priv->dirty) { priv->dirty = TRUE; nmt_newt_form_redraw (NMT_NEWT_FORM (widget)); } }
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)); }
static void nmt_add_connection_init (NmtAddConnection *form) { NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE (form); NmtNewtWidget *textbox, *listbox, *button; NmtNewtGrid *grid, *buttons; grid = NMT_NEWT_GRID (nmt_newt_grid_new ()); textbox = nmt_newt_textbox_new (0, 60); priv->textbox = NMT_NEWT_TEXTBOX (textbox); nmt_newt_grid_add (grid, textbox, 0, 0); listbox = nmt_newt_listbox_new (5, NMT_NEWT_LISTBOX_SCROLL); priv->listbox = NMT_NEWT_LISTBOX (listbox); g_signal_connect (priv->listbox, "activated", G_CALLBACK (create_connection), form); nmt_newt_grid_add (grid, listbox, 0, 1); nmt_newt_widget_set_padding (listbox, 0, 1, 0, 0); nmt_newt_grid_set_flags (grid, listbox, NMT_NEWT_GRID_EXPAND_X); // FIXME: VPN description textbox buttons = NMT_NEWT_GRID (nmt_newt_grid_new ()); nmt_newt_grid_add (grid, NMT_NEWT_WIDGET (buttons), 0, 2); nmt_newt_widget_set_padding (NMT_NEWT_WIDGET (buttons), 0, 1, 0, 0); button = g_object_ref_sink (nmt_newt_button_new (_("Cancel"))); nmt_newt_widget_set_exit_on_activate (button, TRUE); nmt_newt_grid_add (NMT_NEWT_GRID (buttons), button, 0, 0); nmt_newt_widget_set_padding (button, 0, 0, 1, 0); nmt_newt_grid_set_flags (NMT_NEWT_GRID (buttons), button, NMT_NEWT_GRID_EXPAND_X | NMT_NEWT_GRID_ANCHOR_RIGHT | NMT_NEWT_GRID_FILL_Y); button = g_object_ref_sink (nmt_newt_button_new (_("Create"))); g_signal_connect (button, "clicked", G_CALLBACK (create_connection), form); nmt_newt_grid_add (NMT_NEWT_GRID (buttons), button, 1, 0); nmt_newt_form_set_content (NMT_NEWT_FORM (form), NMT_NEWT_WIDGET (grid)); }
static void nmt_password_dialog_constructed (GObject *object) { NmtPasswordDialog *dialog = NMT_PASSWORD_DIALOG (object); NmtPasswordDialogPrivate *priv = NMT_PASSWORD_DIALOG_GET_PRIVATE (dialog); NmtNewtWidget *widget; NmtNewtGrid *grid, *secret_grid; NmtNewtButtonBox *bbox; int i; widget = nmt_newt_grid_new (); nmt_newt_form_set_content (NMT_NEWT_FORM (dialog), widget); grid = NMT_NEWT_GRID (widget); widget = nmt_newt_textbox_new (0, 60); nmt_newt_textbox_set_text (NMT_NEWT_TEXTBOX (widget), priv->prompt); nmt_newt_grid_add (grid, widget, 0, 0); widget = nmt_newt_grid_new (); nmt_newt_grid_add (grid, widget, 0, 1); nmt_newt_widget_set_padding (widget, 0, 1, 0, 1); priv->secret_grid = widget; secret_grid = NMT_NEWT_GRID (widget); for (i = 0; i < priv->secrets->len; i++) { NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i]; NmtNewtEntryFlags flags; widget = nmt_newt_label_new (secret->name); nmt_newt_grid_add (secret_grid, widget, 0, i); nmt_newt_widget_set_padding (widget, 4, 0, 1, 0); flags = NMT_NEWT_ENTRY_NONEMPTY; if (secret->password) flags |= NMT_NEWT_ENTRY_PASSWORD; widget = nmt_newt_entry_new (30, flags); nmt_newt_grid_add (secret_grid, widget, 1, i); g_ptr_array_add (priv->entries, widget); if (i == priv->secrets->len - 1) { priv->last_entry = widget; g_signal_connect (widget, "activated", G_CALLBACK (maybe_save_input_and_exit), dialog); } } 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); priv->cancel = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("Cancel")); nmt_newt_widget_set_exit_on_activate (priv->cancel, TRUE); priv->ok = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("OK")); g_signal_connect (priv->ok, "activated", G_CALLBACK (maybe_save_input_and_exit), dialog); g_object_bind_property (priv->secret_grid, "valid", priv->ok, "sensitive", G_BINDING_SYNC_CREATE); G_OBJECT_CLASS (nmt_password_dialog_parent_class)->constructed (object); }