Beispiel #1
0
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);
}
Beispiel #2
0
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 NmtNewtForm *
nmt_connect_connection_list (void)
{
	int screen_width, screen_height;
	NmtNewtForm *form;
	NmtNewtWidget *list, *activate, *quit, *bbox, *grid;

	newtGetScreenSize (&screen_width, &screen_height);

	form = g_object_new (NMT_TYPE_NEWT_FORM,
	                     "y", 2,
	                     "height", screen_height - 4,
	                     "escape-exits", TRUE,
	                     NULL);

	grid = nmt_newt_grid_new ();

	list = nmt_connect_connection_list_new ();
	nmt_newt_grid_add (NMT_NEWT_GRID (grid), list, 0, 0);
	nmt_newt_grid_set_flags (NMT_NEWT_GRID (grid), list,
	                         NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y |
	                         NMT_NEWT_GRID_EXPAND_X | NMT_NEWT_GRID_EXPAND_Y);
	g_signal_connect (list, "activated", G_CALLBACK (listbox_activated), NULL);

	bbox = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_VERTICAL);
	nmt_newt_grid_add (NMT_NEWT_GRID (grid), bbox, 1, 0);
	nmt_newt_widget_set_padding (bbox, 1, 1, 0, 1);

	activate = nmt_newt_button_box_add_start (NMT_NEWT_BUTTON_BOX (bbox), _("Activate"));
	g_signal_connect (list, "notify::active", G_CALLBACK (listbox_active_changed), activate);
	listbox_active_changed (G_OBJECT (list), NULL, activate);
	g_signal_connect (activate, "clicked", G_CALLBACK (activate_clicked), list);

	quit = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("Quit"));
	nmt_newt_widget_set_exit_on_activate (quit, TRUE);

	nmt_newt_form_set_content (form, grid);
	return 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
nmt_newt_button_box_size_request (NmtNewtWidget *widget,
                                  int           *width,
                                  int           *height)
{
	NmtNewtButtonBox *bbox = NMT_NEWT_BUTTON_BOX (widget);
	NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget);

	*width = *height = 0;
	size_request_buttons (bbox, priv->start_buttons, width, height);
	size_request_buttons (bbox, priv->end_buttons, width, height);

	if (priv->start_buttons && priv->end_buttons) {
		if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL)
			*width += 1;
		else
			*height += 1;
	}
}
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);
}