Exemplo n.º 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);
}
Exemplo n.º 2
0
static NmtNewtForm *
nmt_edit_main_connection_list (gboolean is_top)
{
	int screen_width, screen_height;
	NmtNewtForm *form;
	NmtNewtWidget *quit, *list;

	newtGetScreenSize (&screen_width, &screen_height);

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

	quit = nmt_newt_button_new (is_top ? _("Quit") : _("Back"));
	nmt_newt_widget_set_exit_on_activate (quit, TRUE);

	list = g_object_new (NMT_TYPE_EDIT_CONNECTION_LIST,
	                     "extra-widget", quit,
	                     "connection-filter", edit_connection_list_filter,
	                     NULL);

	g_signal_connect (list, "add-connection",
	                  G_CALLBACK (list_add_connection), form);
	g_signal_connect (list, "edit-connection",
	                  G_CALLBACK (list_edit_connection), form);
	g_signal_connect (list, "remove-connection",
	                  G_CALLBACK (list_remove_connection), form);

	nmt_newt_form_set_content (form, list);
	return form;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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));
}
Exemplo n.º 6
0
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 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);
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
static void
nmt_newt_popup_activated (NmtNewtWidget *widget)
{
	NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (widget);
	NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data;
	NmtNewtForm *form;
	NmtNewtWidget *listbox, *ret;
	int button_x, button_y;
	int window_x, window_y;
	int list_w, list_h;
	int i, active;

	listbox = nmt_newt_listbox_new (priv->entries->len, 0);
	nmt_newt_widget_set_exit_on_activate (listbox, TRUE);
	for (i = 0; i < priv->entries->len; i++)
		nmt_newt_listbox_append (NMT_NEWT_LISTBOX (listbox), entries[i].label, NULL);
	nmt_newt_listbox_set_active (NMT_NEWT_LISTBOX (listbox), priv->active);
	nmt_newt_widget_set_padding (listbox, 1, 0, 1, 0);

	nmt_newt_widget_size_request (listbox, &list_w, &list_h);

	g_object_get (nmt_newt_widget_get_form (widget),
	              "x", &window_x,
	              "y", &window_y,
	              NULL);
	newtComponentGetPosition (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)),
	                          &button_x, &button_y);
	/* (window_x + button_x) is the screen X coordinate of the newtComponent. A
	 * newtButton labelled "Foo" is rendered as " <Foo>" (with a preceding
	 * space), so the "F" is at (window_x + button_x + 2). We've added 1 column
	 * of padding to the left of the listbox, so we need to position the popup
	 * at (window_x + button_x + 1) in order for its text to be aligned with the
	 * button's text. (The x and y coordinates given to NmtNewtForm are the
	 * coordinates of the top left of the window content, ignoring the border
	 * graphics.)
	 */
	window_x += button_x + 1;
	window_y += button_y - priv->active;

	form = g_object_new (NMT_TYPE_NEWT_FORM,
	                     "x", window_x,
	                     "y", window_y,
	                     "width", list_w,
	                     "height", list_h,
	                     "padding", 0,
	                     "escape-exits", TRUE,
	                     NULL);
	nmt_newt_form_set_content (form, listbox);

	ret = nmt_newt_form_run_sync (form);
	if (ret == listbox)
		active = nmt_newt_listbox_get_active (NMT_NEWT_LISTBOX (listbox));
	else
		active = priv->active;

	g_object_unref (form);

	if (active != priv->active) {
		priv->active = active;
		g_object_notify (G_OBJECT (widget), "active");
		g_object_notify (G_OBJECT (widget), "active-id");
		nmt_newt_widget_needs_rebuild (widget);
	}

	NMT_NEWT_WIDGET_CLASS (nmt_newt_popup_parent_class)->activated (widget);
}