Example #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);
}
static void
adjust_border_for_allocation (NmtNewtSectionPrivate *priv,
                              int                    height)
{
	int i;

	/* We have to use a series of one-line labels rather than a multi-line
	 * textbox, because newt will hide any component that's partially offscreen,
	 * but we want the on-screen portion of the border to show even if part of
	 * it is offscreen.
	 */

	if (height == 1) {
		nmt_newt_widget_set_visible (priv->border_closed_label, TRUE);
		nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
		for (i = 0; i < priv->border_line_labels->len; i++)
			nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], FALSE);
		nmt_newt_widget_set_visible (priv->border_end_label, FALSE);
	} else {
		nmt_newt_widget_set_visible (priv->border_closed_label, FALSE);
		nmt_newt_widget_set_visible (priv->border_open_label, TRUE);
		for (i = 0; i < height - 2; i++) {
			if (i >= priv->border_line_labels->len) {
				NmtNewtWidget *label;

				label = nmt_newt_label_new (line_glyph);
				g_ptr_array_add (priv->border_line_labels, label);
				nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), label, 0, i + 1);
			} else 
				nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], TRUE);
		}
		nmt_newt_widget_set_visible (priv->border_end_label, TRUE);
		nmt_newt_grid_move (NMT_NEWT_GRID (priv->border_grid), priv->border_end_label, 0, height - 1);
	}
}
static void
nmt_route_table_init (NmtRouteTable *table)
{
	NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
	NmtNewtWidget *header, *empty;
	NmtNewtWidget *dest_prefix_label, *next_hop_label, *metric_label;
	int dest_prefix_width, next_hop_width, metric_width;
	char *text;

	priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);

	header = nmt_newt_grid_new ();

	text = g_strdup_printf ("%s/%s", _("Destination"), _("Prefix"));
	dest_prefix_width = nmt_newt_text_width (text);
	dest_prefix_label = g_object_new (NMT_TYPE_NEWT_LABEL,
	                                  "text", text,
	                                  "style", NMT_NEWT_LABEL_PLAIN,
	                                  NULL);
	g_free (text);
	nmt_newt_grid_add (NMT_NEWT_GRID (header), dest_prefix_label, 0, 0);

	text = _("Next Hop");
	next_hop_label = g_object_new (NMT_TYPE_NEWT_LABEL,
	                               "text", text,
	                               "style", NMT_NEWT_LABEL_PLAIN,
	                               NULL);
	next_hop_width = nmt_newt_text_width (text);
	nmt_newt_grid_add (NMT_NEWT_GRID (header), next_hop_label, 1, 0);

	text = _("Metric");
	metric_label = g_object_new (NMT_TYPE_NEWT_LABEL,
	                             "text", text,
	                             "style", NMT_NEWT_LABEL_PLAIN,
	                             NULL);
	metric_width = nmt_newt_text_width (text);
	nmt_newt_grid_add (NMT_NEWT_GRID (header), metric_label, 2, 0);

	priv->ip_entry_width = MAX (20, MAX (dest_prefix_width, next_hop_width));
	priv->metric_entry_width = MAX (7, metric_width);

	nmt_newt_widget_set_padding (dest_prefix_label,
	                           0, 0, priv->ip_entry_width - dest_prefix_width, 0);
	nmt_newt_widget_set_padding (next_hop_label,
	                           2, 0, priv->ip_entry_width - next_hop_width, 0);
	nmt_newt_widget_set_padding (metric_label,
	                           2, 0, priv->metric_entry_width - metric_width, 0);

	nmt_newt_grid_add (NMT_NEWT_GRID (table), header, 0, 0);

	empty = nmt_newt_label_new (_("No custom routes are defined."));
	priv->list = nmt_widget_list_new (create_route_entry, table, NULL, empty);
	g_signal_connect (priv->list, "add-clicked", G_CALLBACK (add_route), table);
	g_signal_connect (priv->list, "remove-clicked", G_CALLBACK (remove_route), table);
	nmt_newt_grid_add (NMT_NEWT_GRID (table), priv->list, 0, 1);
}
static void
nmt_password_fields_constructed (GObject *object)
{
	NmtPasswordFieldsPrivate *priv = NMT_PASSWORD_FIELDS_GET_PRIVATE (object);
	NmtNewtGrid *grid = NMT_NEWT_GRID (object);

	nmt_newt_grid_add (grid, NMT_NEWT_WIDGET (priv->entry), 0, 0);

	if (priv->extras & NMT_PASSWORD_FIELDS_ALWAYS_ASK) {
		nmt_newt_grid_add (grid, NMT_NEWT_WIDGET (priv->always_ask), 0, 1);
		g_signal_connect (priv->always_ask, "notify::active",
		                  G_CALLBACK (always_ask_changed), object);
	} else
		g_clear_object (&priv->always_ask);

	if (priv->extras & NMT_PASSWORD_FIELDS_SHOW_PASSWORD) {
		nmt_newt_grid_add (grid, NMT_NEWT_WIDGET (priv->show_password), 0, 2);
		g_signal_connect (priv->show_password, "notify::active",
		                  G_CALLBACK (show_password_changed), object);
		g_object_bind_property (priv->show_password, "active",
		                        priv->entry, "password",
		                        G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
	} else
		g_clear_object (&priv->show_password);

	G_OBJECT_CLASS (nmt_password_fields_parent_class)->constructed (object);
}
static void
nmt_mtu_entry_init (NmtMtuEntry *entry)
{

	NmtMtuEntryPrivate *priv = NMT_MTU_ENTRY_GET_PRIVATE (entry);
	NmtNewtGrid *grid = NMT_NEWT_GRID (entry);
	NmtNewtWidget *real_entry, *label;

	real_entry = nmt_newt_entry_numeric_new (10, 0, 65535);
	priv->entry = NMT_NEWT_ENTRY (real_entry);

	label = nmt_newt_label_new (_("bytes"));
	priv->label = NMT_NEWT_LABEL (label);

	nmt_newt_grid_add (grid, real_entry, 0, 0);
	nmt_newt_grid_add (grid, label, 1, 0);
	nmt_newt_widget_set_padding (label, 1, 0, 0, 0);

	nmt_newt_entry_set_validator (priv->entry, mtu_validator, entry);
	g_object_bind_property_full (entry, "mtu", real_entry, "text",
	                             G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
	                             mtu_transform_to_text,
	                             NULL,
	                             NULL, NULL);
}
Example #6
0
static void
nmt_widget_list_set_property (GObject      *object,
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
	NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (object);

	switch (prop_id) {
	case PROP_CREATE_CALLBACK:
		priv->create_callback = g_value_get_pointer (value);
		break;
	case PROP_USER_DATA:
		priv->user_data = g_value_get_pointer (value);
		break;
	case PROP_DESTROY_NOTIFY:
		priv->destroy_notify = g_value_get_pointer (value);
		break;
	case PROP_LENGTH:
		priv->length = g_value_get_int (value);
		ensure_widgets (NMT_WIDGET_LIST (object));
		break;
	case PROP_EMPTY_WIDGET:
		priv->empty_widget = g_value_get_object (value);
		if (priv->empty_widget) {
			g_object_ref_sink (priv->empty_widget);
			nmt_newt_grid_add (NMT_NEWT_GRID (object), priv->empty_widget, 0, 0);
		}
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Example #7
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 void
nmt_page_team_constructed (GObject *object)
{
	NmtPageTeam *team = NMT_PAGE_TEAM (object);
	NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE (team);
	NmtEditorSection *section;
	NmtNewtGrid *grid;
	NMSettingTeam *s_team;
	NmtNewtWidget *widget;
	NMConnection *conn;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (team));
	s_team = nm_connection_get_setting_team (conn);
	if (!s_team) {
		nm_connection_add_setting (conn, nm_setting_team_new ());
		s_team = nm_connection_get_setting_team (conn);
	}
	priv->s_team = s_team;

	section = nmt_editor_section_new (_("TEAM"), NULL, TRUE);

	widget = nmt_newt_grid_new ();
	nmt_editor_grid_append (nmt_editor_section_get_body (section), NULL, widget, NULL);

	grid = NMT_NEWT_GRID (widget);

	widget = nmt_newt_label_new (_("Slaves"));
	nmt_newt_grid_add (grid, widget, 0, 0);

	widget = nmt_slave_list_new (conn, team_connection_type_filter, team);
	g_signal_connect (widget, "notify::connections",
	                  G_CALLBACK (slaves_changed), team);
	nmt_newt_grid_add (grid, widget, 0, 1);
	nmt_newt_widget_set_padding (widget, 0, 0, 0, 1);
	priv->slaves = NMT_SLAVE_LIST (widget);
	slaves_changed (G_OBJECT (priv->slaves), NULL, team);

	widget = nmt_newt_label_new (_("JSON configuration"));
	nmt_newt_grid_add (grid, widget, 0, 2);

	widget = nmt_newt_textbox_new (NMT_NEWT_TEXTBOX_SCROLLABLE | NMT_NEWT_TEXTBOX_SET_BACKGROUND, 60);
	g_object_bind_property (s_team, NM_SETTING_TEAM_CONFIG,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (grid, widget, 0, 3);
	nmt_newt_widget_set_padding (widget, 2, 0, 2, 1);

	widget = nmt_newt_button_new (_("Edit..."));
	g_signal_connect (widget, "clicked", G_CALLBACK (edit_clicked), team);
	nmt_newt_grid_add (grid, widget, 0, 4);

	nmt_editor_page_add_section (NMT_EDITOR_PAGE (team), section);

	G_OBJECT_CLASS (nmt_page_team_parent_class)->constructed (object);
}
Example #9
0
static void
nmt_widget_list_constructed (GObject *object)
{
	NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (object);

	if (priv->length == 0 && priv->empty_widget) {
		nmt_newt_widget_set_visible (priv->empty_widget, TRUE);
		nmt_newt_grid_move (NMT_NEWT_GRID (object), priv->add_button, 0, 1);
	}

	G_OBJECT_CLASS (nmt_widget_list_parent_class)->constructed (object);
}
Example #10
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));
}
Example #11
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;
}
Example #12
0
static void
nmt_widget_list_init (NmtWidgetList *list)
{
	NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (list);

	priv->widgets = g_ptr_array_new ();
	priv->remove_buttons = g_ptr_array_new ();

	priv->add_button = nmt_newt_button_new (_("Add..."));
	g_signal_connect (priv->add_button, "clicked",
	                  G_CALLBACK (add_clicked), list);
	nmt_newt_grid_add (NMT_NEWT_GRID (list), priv->add_button, 0, 0);
}
Example #13
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;
}
static void
nmt_newt_section_init (NmtNewtSection *section)
{
	NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);

	priv->show_border = TRUE;

	priv->border_grid = nmt_newt_grid_new ();
	parent_class->add (NMT_NEWT_CONTAINER (section), priv->border_grid);

	priv->border_open_label = nmt_newt_label_new (open_glyph);
	nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
	nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_open_label, 0, 0);

	priv->border_closed_label = nmt_newt_label_new (closed_glyph);
	nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_closed_label, 0, 0);

	priv->border_end_label = nmt_newt_label_new (end_glyph);
	nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
	nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_end_label, 0, 1);

	priv->border_line_labels = g_ptr_array_new ();
}
static void
nmt_route_entry_constructed (GObject *object)
{
	NmtRouteEntryPrivate *priv = NMT_ROUTE_ENTRY_GET_PRIVATE (object);
	NmtNewtGrid *grid = NMT_NEWT_GRID (object);
	NmtNewtWidget *warning_label;

	priv->dest = nmt_ip_entry_new (priv->ip_entry_width, priv->family, TRUE, FALSE);
	priv->next_hop = nmt_ip_entry_new (priv->ip_entry_width, priv->family, FALSE, TRUE);
	priv->metric = nmt_newt_entry_numeric_new (priv->metric_entry_width, 0, 65535);

	nmt_newt_grid_add (grid, priv->dest, 0, 0);
	warning_label = create_warning_label (priv->dest);
	nmt_newt_grid_add (grid, warning_label, 1, 0);

	nmt_newt_grid_add (grid, priv->next_hop, 2, 0);
	nmt_newt_widget_set_padding (priv->next_hop, 1, 0, 0, 0);
	warning_label = create_warning_label (priv->next_hop);
	nmt_newt_grid_add (grid, warning_label, 3, 0);

	nmt_newt_grid_add (grid, priv->metric, 4, 0);
	nmt_newt_widget_set_padding (priv->metric, 1, 0, 0, 0);

	if (priv->family == AF_INET) {
		nm_editor_bind_ip4_route_to_strings (object, "ip4-route",
		                                     priv->dest, "text",
		                                     priv->next_hop, "text",
		                                     priv->metric, "text",
		                                     G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	} else if (priv->family == AF_INET6) {
		nm_editor_bind_ip6_route_to_strings (object, "ip6-route",
		                                     priv->dest, "text",
		                                     priv->next_hop, "text",
		                                     priv->metric, "text",
		                                     G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	} else
		g_assert_not_reached ();

	G_OBJECT_CLASS (nmt_route_entry_parent_class)->constructed (object);
}
static void
nmt_page_team_port_constructed (GObject *object)
{
	NmtPageTeamPort *team = NMT_PAGE_TEAM_PORT (object);
	NmtPageTeamPortPrivate *priv = NMT_PAGE_TEAM_PORT_GET_PRIVATE (team);
	NmtNewtGrid *grid;
	NMSettingTeamPort *s_port;
	NmtNewtWidget *widget;
	NMConnection *conn;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (team));
	s_port = nm_connection_get_setting_team_port (conn);
	if (!s_port) {
		nm_connection_add_setting (conn, nm_setting_team_port_new ());
		s_port = nm_connection_get_setting_team_port (conn);
	}
	priv->s_port = s_port;

	widget = nmt_newt_grid_new ();
	nmt_page_grid_append (NMT_PAGE_GRID (team), NULL, widget, NULL);

	grid = NMT_NEWT_GRID (widget);

	widget = nmt_newt_label_new (_("JSON configuration"));
	nmt_newt_grid_add (grid, widget, 0, 2);

	widget = nmt_newt_textbox_new (NMT_NEWT_TEXTBOX_SCROLLABLE | NMT_NEWT_TEXTBOX_SET_BACKGROUND, 60);
	g_object_bind_property (s_port, NM_SETTING_TEAM_PORT_CONFIG,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (grid, widget, 0, 3);
	nmt_newt_widget_set_padding (widget, 2, 0, 2, 1);

	widget = nmt_newt_button_new (_("Edit..."));
	g_signal_connect (widget, "clicked", G_CALLBACK (edit_clicked), team);
	nmt_newt_grid_add (grid, widget, 0, 4);

	G_OBJECT_CLASS (nmt_page_team_port_parent_class)->constructed (object);
}
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);
}
Example #18
0
static void
nmt_page_wifi_constructed (GObject *object)
{
	NmtPageWifiPrivate *priv = NMT_PAGE_WIFI_GET_PRIVATE (object);
	NmtPageWifi *wifi = NMT_PAGE_WIFI (object);
	NmtDeviceEntry *deventry;
	NmtEditorSection *section;
	NmtEditorGrid *grid;
	NMSettingWireless *s_wireless;
	NMSettingWirelessSecurity *s_wsec;
	NmtNewtWidget *widget, *hbox, *subgrid;
	NmtNewtWidget *mode, *band, *security, *entry;
	NmtNewtStack *stack;
	NMConnection *conn;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (wifi));
	s_wireless = nm_connection_get_setting_wireless (conn);
	if (!s_wireless) {
		nm_connection_add_setting (conn, nm_setting_wireless_new ());
		s_wireless = nm_connection_get_setting_wireless (conn);
	}

	s_wsec = nm_connection_get_setting_wireless_security (conn);
	if (!s_wsec) {
		/* It makes things simpler if we always have a
		 * NMSettingWirelessSecurity; we'll hold a ref on one, and add
		 * it to and remove it from the connection as needed.
		 */
		s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
	}
	priv->s_wsec = g_object_ref_sink (s_wsec);

	deventry = nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (object));
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS,
	                        deventry, "mac-address",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);

	section = nmt_editor_section_new (_("WI-FI"), NULL, TRUE);
	grid = nmt_editor_section_get_body (section);

	widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY);
	g_object_bind_property_full (s_wireless, NM_SETTING_WIRELESS_SSID,
	                             widget, "text",
	                             G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
	                             ssid_transform_to_entry,
	                             ssid_transform_from_entry,
	                             s_wireless, NULL);
	nmt_editor_grid_append (grid, _("SSID"), widget, NULL);

	widget = nmt_newt_popup_new (wifi_mode);
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MODE,
	                        widget, "active-id",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("Mode"), widget, NULL);
	mode = widget;

	hbox = nmt_newt_grid_new ();
	widget = nmt_newt_popup_new (wifi_band);
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_BAND,
	                        widget, "active-id",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (NMT_NEWT_GRID (hbox), widget, 0, 0);
	band = widget;

	widget = nmt_newt_entry_numeric_new (10, 0, 255);
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_CHANNEL,
	                        widget, "text",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (NMT_NEWT_GRID (hbox), widget, 1, 0);
	nmt_newt_widget_set_padding (widget, 1, 0, 0, 0);

	g_object_bind_property_full (band, "active-id", widget, "visible",
	                             G_BINDING_SYNC_CREATE,
	                             band_transform_to_channel_visibility,
	                             NULL, NULL, NULL);
	g_object_bind_property_full (mode, "active-id", hbox, "visible",
	                             G_BINDING_SYNC_CREATE,
	                             mode_transform_to_band_visibility,
	                             NULL, NULL, NULL);
	nmt_editor_grid_append (grid, _("Channel"), hbox, NULL);

	nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);

	widget = nmt_newt_popup_new (wifi_security);
	nmt_editor_grid_append (grid, _("Security"), widget, NULL);
	security = widget;

	widget = nmt_newt_stack_new ();
	stack = NMT_NEWT_STACK (widget);

	/* none */
	subgrid = nmt_editor_grid_new ();
	nmt_newt_stack_add (stack, "none", subgrid);

	/* wpa-personal */
	subgrid = nmt_editor_grid_new ();
	widget = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
	g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK,
	                        widget, "password",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL);
	nmt_newt_stack_add (stack, "wpa-personal", subgrid);

	/* "wpa-enterprise" */
	// FIXME
	widget = nmt_newt_label_new (_("(No support for wpa-enterprise yet...)"));
	nmt_newt_stack_add (stack, "wpa-enterprise", widget);

	/* wep-key */
	subgrid = nmt_editor_grid_new ();

	widget = entry = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Key"), widget, NULL);

	widget = nmt_newt_popup_new (wep_index);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("WEP index"), widget, NULL);

	nm_editor_bind_wireless_security_wep_key (s_wsec,
	                                          entry, "password",
	                                          widget, "active",
	                                          G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);

	widget = nmt_newt_popup_new (wep_auth);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Authentication"), widget, NULL);

	nmt_newt_stack_add (stack, "wep-key", subgrid);

	/* wep-passphrase */
	subgrid = nmt_editor_grid_new ();

	widget = entry = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL);

	widget = nmt_newt_popup_new (wep_index);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("WEP index"), widget, NULL);

	nm_editor_bind_wireless_security_wep_key (s_wsec,
	                                          entry, "password",
	                                          widget, "active",
	                                          G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);

	widget = nmt_newt_popup_new (wep_auth);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Authentication"), widget, NULL);

	nmt_newt_stack_add (stack, "wep-passphrase", subgrid);

	/* "dynamic-wep" */
	// FIXME
	widget = nmt_newt_label_new (_("(No support for dynamic-wep yet...)"));
	nmt_newt_stack_add (stack, "dynamic-wep", widget);

	/* leap */
	subgrid = nmt_editor_grid_new ();

	widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Username"), widget, NULL);
	g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME,
	                        widget, "text",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

	widget = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
	g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
	                        widget, "password",
	                        G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
	nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL);

	nmt_newt_stack_add (stack, "leap", subgrid);

	nmt_editor_grid_append (grid, NULL, NMT_NEWT_WIDGET (stack), NULL);
	g_object_bind_property (security, "active-id",
	                        stack, "active-id",
	                        G_BINDING_SYNC_CREATE);
	nm_editor_bind_wireless_security_method (conn, s_wsec, security, "active-id",
	                                         G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);

	nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);

	widget = nmt_mac_entry_new (40, ETH_ALEN);
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_BSSID,
	                        widget, "mac-address",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("BSSID"), widget, NULL);

	widget = nmt_mac_entry_new (40, ETH_ALEN);
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS,
	                        widget, "mac-address",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("Cloned MAC address"), widget, NULL);

	widget = nmt_mtu_entry_new ();
	g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MTU,
	                        widget, "mtu",
	                        G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, _("MTU"), widget, NULL);

	nmt_editor_page_add_section (NMT_EDITOR_PAGE (wifi), section);

	G_OBJECT_CLASS (nmt_page_wifi_parent_class)->constructed (object);
}
Example #19
0
static void
nmt_page_ppp_constructed (GObject *object)
{
	NmtPagePpp *ppp = NMT_PAGE_PPP (object);
	NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE (ppp);
	NmtEditorSection *section;
	NmtEditorGrid *grid;
	NMSettingPpp *s_ppp;
	NmtNewtWidget *widget, *use_mppe;
	NmtNewtGrid *auth_grid, *mppe_grid;
	NmtNewtSection *auth_section, *mppe_section;
	NMConnection *conn;

	conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ppp));
	s_ppp = nm_connection_get_setting_ppp (conn);
	if (s_ppp) {
		priv->lcp_echo_interval = nm_setting_ppp_get_lcp_echo_interval (s_ppp);
		priv->lcp_echo_failure = nm_setting_ppp_get_lcp_echo_failure (s_ppp);
	} else {
		s_ppp = (NMSettingPpp *) nm_setting_ppp_new ();
		nm_connection_add_setting (conn, (NMSetting *) s_ppp);

		priv->lcp_echo_interval = 30;
		priv->lcp_echo_failure = 5;
	}

	section = nmt_editor_section_new (_("PPP CONFIGURATION"), NULL, TRUE);
	grid = nmt_editor_section_get_body (section);

	/* Auth methods */
	widget = nmt_newt_section_new (FALSE);
	auth_section = NMT_NEWT_SECTION (widget);
	g_object_set (auth_section, "open", TRUE, NULL);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_label_new (_("Allowed authentication methods:"));
	nmt_newt_section_set_header (auth_section, widget);

	widget = nmt_newt_grid_new ();
	auth_grid = NMT_NEWT_GRID (widget);
	nmt_newt_section_set_body (auth_section, widget);

	widget = nmt_newt_checkbox_new (_("EAP"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_EAP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (auth_grid, widget, 0, 0);

	widget = nmt_newt_checkbox_new (_("PAP"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_PAP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (auth_grid, widget, 0, 1);

	widget = nmt_newt_checkbox_new (_("CHAP"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_CHAP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (auth_grid, widget, 0, 2);

	widget = nmt_newt_checkbox_new (_("MSCHAPv2"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_MSCHAPV2,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (auth_grid, widget, 0, 3);

	widget = nmt_newt_checkbox_new (_("MSCHAP"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_MSCHAP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (auth_grid, widget, 0, 4);

	nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);

	/* MPPE */
	widget = nmt_newt_section_new (FALSE);
	mppe_section = NMT_NEWT_SECTION (widget);
	g_object_set (mppe_section, "open", TRUE, NULL);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_checkbox_new (_("Use point-to-point encryption (MPPE)"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REQUIRE_MPPE,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_SYNC_CREATE);
	use_mppe = widget;
	nmt_newt_section_set_header (mppe_section, widget);

	widget = nmt_newt_grid_new ();
	mppe_grid = NMT_NEWT_GRID (widget);
	nmt_newt_section_set_body (mppe_section, widget);

	widget = nmt_newt_checkbox_new (_("Require 128-bit encryption"));
	g_object_bind_property (use_mppe, "active",
	                        widget, "sensitive",
	                        G_BINDING_SYNC_CREATE);
	g_object_bind_property (s_ppp, NM_SETTING_PPP_REQUIRE_MPPE_128,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (mppe_grid, widget, 0, 0);

	widget = nmt_newt_checkbox_new (_("Use stateful MPPE"));
	g_object_bind_property (use_mppe, "active",
	                        widget, "sensitive",
	                        G_BINDING_SYNC_CREATE);
	g_object_bind_property (s_ppp, NM_SETTING_PPP_MPPE_STATEFUL,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_SYNC_CREATE);
	nmt_newt_grid_add (mppe_grid, widget, 0, 1);

	nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);

	widget = nmt_newt_checkbox_new (_("Allow BSD data compression"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_NOBSDCOMP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_checkbox_new (_("Allow Deflate data compression"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_NODEFLATE,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	widget = nmt_newt_checkbox_new (_("Use TCP header compression"));
	g_object_bind_property (s_ppp, NM_SETTING_PPP_NO_VJ_COMP,
	                        widget, "active",
	                        G_BINDING_BIDIRECTIONAL |
	                        G_BINDING_INVERT_BOOLEAN |
	                        G_BINDING_SYNC_CREATE);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);

	widget = nmt_newt_checkbox_new (_("Send PPP echo packets"));
	g_object_bind_property_full (s_ppp, NM_SETTING_PPP_LCP_ECHO_INTERVAL,
	                             widget, "active",
	                             G_BINDING_BIDIRECTIONAL |
	                             G_BINDING_SYNC_CREATE,
	                             transform_lcp_echo_properties_to_checkbox,
	                             transform_checkbox_to_lcp_echo_interval,
	                             ppp, NULL);
	g_object_bind_property_full (s_ppp, NM_SETTING_PPP_LCP_ECHO_FAILURE,
	                             widget, "active",
	                             G_BINDING_BIDIRECTIONAL |
	                             G_BINDING_SYNC_CREATE,
	                             transform_lcp_echo_properties_to_checkbox,
	                             transform_checkbox_to_lcp_echo_failure,
	                             ppp, NULL);
	nmt_editor_grid_append (grid, NULL, widget, NULL);

	nmt_editor_page_add_section (NMT_EDITOR_PAGE (ppp), section);

	G_OBJECT_CLASS (nmt_page_ppp_parent_class)->constructed (object);
}
Example #20
0
static void
ensure_widgets (NmtWidgetList *list)
{
	NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (list);
	NmtNewtWidget *widget, *button, *focus;
	gboolean was_empty;
	NmtNewtForm *form;
	int i;

	was_empty = priv->widgets->len == 0;

	if (priv->length < priv->widgets->len) {
		/* remove excess widgets */
		for (i = priv->length; i < priv->widgets->len; i++) {
			nmt_newt_container_remove (NMT_NEWT_CONTAINER (list), priv->widgets->pdata[i]);
			nmt_newt_container_remove (NMT_NEWT_CONTAINER (list), priv->remove_buttons->pdata[i]);
		}
		g_ptr_array_set_size (priv->widgets, priv->length);
		g_ptr_array_set_size (priv->remove_buttons, priv->length);

	} else if (priv->length > priv->widgets->len) {
		/* add new widgets */
		for (i = priv->widgets->len; i < priv->length; i++) {
			widget = NMT_WIDGET_LIST_GET_CLASS (list)->create_widget (list, i);

			nmt_newt_grid_add (NMT_NEWT_GRID (list), widget, 0, i);
			g_ptr_array_add (priv->widgets, widget);

			button = nmt_newt_button_new (_("Remove"));
			g_signal_connect (button, "clicked",
			                  G_CALLBACK (remove_clicked), list);

			nmt_newt_grid_add (NMT_NEWT_GRID (list), button, 1, i);
			nmt_newt_widget_set_padding (button, 1, 0, 0, 0);
			g_ptr_array_add (priv->remove_buttons, button);
		}

	} else
		return;

	if (priv->widgets->len == 0 && priv->empty_widget) {
		nmt_newt_widget_set_visible (priv->empty_widget, TRUE);
		nmt_newt_grid_move (NMT_NEWT_GRID (list), priv->add_button, 0, 1);
	} else {
		if (was_empty && priv->empty_widget)
			nmt_newt_widget_set_visible (priv->empty_widget, FALSE);
		nmt_newt_grid_move (NMT_NEWT_GRID (list), priv->add_button, 0, priv->length);
	}

	form = nmt_newt_widget_get_form (NMT_NEWT_WIDGET (list));
	if (form) {
		if (priv->widgets->len) {
			if (was_empty)
				focus = priv->widgets->pdata[0];
			else
				focus = priv->widgets->pdata[priv->widgets->len - 1];
		} else
			focus = priv->add_button;
		nmt_newt_form_set_focus (form, focus);
	}

	g_clear_object (&priv->add_sensitivity);
	if (priv->widgets->len) {
		widget = priv->widgets->pdata[priv->widgets->len - 1];
		priv->add_sensitivity = g_object_bind_property (widget, "valid",
		                                                priv->add_button, "sensitive",
		                                                G_BINDING_SYNC_CREATE);
		g_object_add_weak_pointer (G_OBJECT (priv->add_sensitivity),
		                           (gpointer *)&priv->add_sensitivity);
	}
}