tui: add support for editing DSL connections (rh #1105753)

This commit is contained in:
Dan Winship 2014-09-16 08:00:23 -04:00
commit 35eb538282
17 changed files with 603 additions and 68 deletions

View file

@ -73,6 +73,8 @@ nmtui_SOURCES = \
nmt-page-bridge-port.h \
nmt-page-device.c \
nmt-page-device.h \
nmt-page-dsl.c \
nmt-page-dsl.h \
nmt-page-ethernet.c \
nmt-page-ethernet.h \
nmt-page-grid.c \
@ -85,6 +87,8 @@ nmtui_SOURCES = \
nmt-page-ip6.h \
nmt-page-main.c \
nmt-page-main.h \
nmt-page-ppp.c \
nmt-page-ppp.h \
nmt-page-team.c \
nmt-page-team.h \
nmt-page-team-port.c \

View file

@ -30,8 +30,9 @@
* in the section's header to the section's #NmtNewtSection:open
* property.)
*
* In addition to the header and body, the #NmtNewtSection also draws
* a border along the left side, indicating the extent of the section.
* In addition to the header and body, the #NmtNewtSection also
* optionally draws a border along the left side, indicating the
* extent of the section.
*/
#include "config.h"
@ -54,6 +55,7 @@ typedef struct {
NmtNewtWidget *body;
int bheight_req, bwidth_req;
gboolean show_border;
NmtNewtWidget *border_grid;
NmtNewtWidget *border_open_label;
NmtNewtWidget *border_closed_label;
@ -68,6 +70,7 @@ static char *closed_glyph, *open_glyph, *line_glyph, *end_glyph;
enum {
PROP_0,
PROP_SHOW_BORDER,
PROP_OPEN,
LAST_PROP
@ -75,15 +78,17 @@ enum {
/**
* nmt_newt_section_new:
* @show_border: whether to show the border on the side of the section
*
* Creates a new #NmtNewtSection
*
* Returns: a new #NmtNewtSection
*/
NmtNewtWidget *
nmt_newt_section_new (void)
nmt_newt_section_new (gboolean show_border)
{
return g_object_new (NMT_TYPE_NEWT_SECTION,
"show-border", show_border,
NULL);
}
@ -93,6 +98,8 @@ 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);
@ -224,10 +231,12 @@ nmt_newt_section_get_components (NmtNewtWidget *widget)
cos = g_ptr_array_new ();
child_cos = nmt_newt_widget_get_components (priv->border_grid);
for (i = 0; child_cos[i]; i++)
g_ptr_array_add (cos, child_cos[i]);
g_free (child_cos);
if (priv->show_border) {
child_cos = nmt_newt_widget_get_components (priv->border_grid);
for (i = 0; child_cos[i]; i++)
g_ptr_array_add (cos, child_cos[i]);
g_free (child_cos);
}
child_cos = nmt_newt_widget_get_components (priv->header);
for (i = 0; child_cos[i]; i++)
@ -255,12 +264,16 @@ nmt_newt_section_size_request (NmtNewtWidget *widget,
g_return_if_fail (priv->header != NULL && priv->body != NULL);
nmt_newt_widget_size_request (priv->border_grid, &border_width, &border_height);
if (priv->show_border)
nmt_newt_widget_size_request (priv->border_grid, &border_width, &border_height);
nmt_newt_widget_size_request (priv->header, &priv->hwidth_req, &priv->hheight_req);
nmt_newt_widget_size_request (priv->body, &priv->bwidth_req, &priv->bheight_req);
*width = MAX (priv->hwidth_req, priv->bwidth_req) + 2;
*height = priv->open ? priv->hheight_req + priv->bheight_req + 1 : priv->hheight_req;
if (priv->open)
*height = priv->hheight_req + priv->bheight_req + (priv->show_border ? 1 : 0);
else
*height = priv->hheight_req;
}
static void
@ -308,10 +321,13 @@ nmt_newt_section_size_allocate (NmtNewtWidget *widget,
{
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget);
adjust_border_for_allocation (priv, height);
if (priv->show_border) {
adjust_border_for_allocation (priv, height);
nmt_newt_widget_size_allocate (priv->border_grid, x, y, 1, height);
nmt_newt_widget_size_allocate (priv->header, x + 2, y, width, priv->hheight_req);
} else
nmt_newt_widget_size_allocate (priv->header, x, y, width, priv->hheight_req);
nmt_newt_widget_size_allocate (priv->border_grid, x, y, 1, height);
nmt_newt_widget_size_allocate (priv->header, x + 2, y, width, priv->hheight_req);
if (priv->open) {
nmt_newt_widget_size_allocate (priv->body, x + 2, y + priv->hheight_req,
width, height - priv->hheight_req);
@ -327,6 +343,10 @@ nmt_newt_section_set_property (GObject *object,
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (object);
switch (prop_id) {
case PROP_SHOW_BORDER:
priv->show_border = g_value_get_boolean (value);
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (object));
break;
case PROP_OPEN:
priv->open = g_value_get_boolean (value);
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (object));
@ -346,6 +366,9 @@ nmt_newt_section_get_property (GObject *object,
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (object);
switch (prop_id) {
case PROP_SHOW_BORDER:
g_value_set_boolean (value, priv->show_border);
break;
case PROP_OPEN:
g_value_set_boolean (value, priv->open);
break;
@ -377,6 +400,18 @@ nmt_newt_section_class_init (NmtNewtSectionClass *section_class)
/* properties */
/**
* NmtNewtSection:show-border:
*
* %TRUE if the section should show a border along the left side.
*/
g_object_class_install_property
(object_class, PROP_SHOW_BORDER,
g_param_spec_boolean ("show-border", "", "",
TRUE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NmtNewtSection:open:
*

View file

@ -42,7 +42,7 @@ typedef struct {
GType nmt_newt_section_get_type (void);
NmtNewtWidget *nmt_newt_section_new (void);
NmtNewtWidget *nmt_newt_section_new (gboolean show_border);
void nmt_newt_section_set_header (NmtNewtSection *section,
NmtNewtWidget *header);

View file

@ -176,6 +176,7 @@ nm_editor_utils_get_connection_type_list (void)
item->id_format = _("Mobile broadband connection %d");
item->no_autoconnect = TRUE;
g_ptr_array_add (array, item);
#endif
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
item->data.name = _("DSL");
@ -185,7 +186,6 @@ nm_editor_utils_get_connection_type_list (void)
item->id_format = _("DSL connection %d");
item->no_autoconnect = TRUE;
g_ptr_array_add (array, item);
#endif
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
item->data.name = _("Bond");

View file

@ -146,6 +146,26 @@ nmt_editor_page_get_title (NmtEditorPage *page)
return priv->title;
}
static gboolean
nmt_editor_page_real_show_by_default (NmtEditorPage *page)
{
return TRUE;
}
/**
* nmt_editor_page_show_by_default:
* @page: the #NmtEditorPage
*
* Checks if @page should be shown expanded by default
*
* Returns: %TRUE or %FALSE
*/
gboolean
nmt_editor_page_show_by_default (NmtEditorPage *page)
{
return NMT_EDITOR_PAGE_GET_CLASS (page)->show_by_default (page);
}
static void
nmt_editor_page_set_property (GObject *object,
guint prop_id,
@ -200,6 +220,8 @@ nmt_editor_page_class_init (NmtEditorPageClass *page_class)
object_class->get_property = nmt_editor_page_get_property;
object_class->finalize = nmt_editor_page_finalize;
page_class->show_by_default = nmt_editor_page_real_show_by_default;
/* properties */
/**

View file

@ -40,6 +40,7 @@ typedef struct {
typedef struct {
NmtPageGridClass parent;
gboolean (*show_by_default) (NmtEditorPage *);
} NmtEditorPageClass;
GType nmt_editor_page_get_type (void);
@ -52,6 +53,8 @@ NmtNewtWidget *nmt_editor_page_get_header_widget (NmtEditorPage *page);
const char *nmt_editor_page_get_title (NmtEditorPage *page);
gboolean nmt_editor_page_show_by_default (NmtEditorPage *page);
G_END_DECLS
#endif /* NMT_EDITOR_PAGE_H */

View file

@ -73,8 +73,8 @@ nmt_page_device_get_device_entry (NmtPageDevice *page)
return priv->device_entry;
}
gboolean
nmt_page_device_get_show_by_default (NmtPageDevice *page)
static gboolean
nmt_page_device_show_by_default (NmtEditorPage *page)
{
NmtPageDevicePrivate *priv = NMT_PAGE_DEVICE_GET_PRIVATE (page);
@ -127,6 +127,7 @@ static void
nmt_page_device_class_init (NmtPageDeviceClass *page_device_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (page_device_class);
NmtEditorPageClass *page_class = NMT_EDITOR_PAGE_CLASS (page_device_class);
g_type_class_add_private (page_device_class, sizeof (NmtPageDevicePrivate));
@ -135,6 +136,8 @@ nmt_page_device_class_init (NmtPageDeviceClass *page_device_class)
object_class->get_property = nmt_page_device_get_property;
object_class->finalize = nmt_page_device_finalize;
page_class->show_by_default = nmt_page_device_show_by_default;
/* properties */
g_object_class_install_property
(object_class, PROP_DEVICE_ENTRY,

View file

@ -44,7 +44,6 @@ typedef struct {
GType nmt_page_device_get_type (void);
NmtDeviceEntry *nmt_page_device_get_device_entry (NmtPageDevice *page);
gboolean nmt_page_device_get_show_by_default (NmtPageDevice *page);
G_END_DECLS

View file

@ -0,0 +1,93 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Red Hat, Inc.
*/
/**
* SECTION:nmt-page-dsl
* @short_description: The editor page for DSL connections
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "nmt-page-dsl.h"
#include "nmt-password-fields.h"
G_DEFINE_TYPE (NmtPageDsl, nmt_page_dsl, NMT_TYPE_EDITOR_PAGE)
NmtNewtWidget *
nmt_page_dsl_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_DSL,
"connection", conn,
"title", _("DSL"),
NULL);
}
static void
nmt_page_dsl_init (NmtPageDsl *dsl)
{
}
static void
nmt_page_dsl_constructed (GObject *object)
{
NmtPageDsl *dsl = NMT_PAGE_DSL (object);
NmtPageGrid *grid;
NMSettingPppoe *s_pppoe;
NmtNewtWidget *widget;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (dsl));
s_pppoe = nm_connection_get_setting_pppoe (conn);
if (!s_pppoe) {
nm_connection_add_setting (conn, nm_setting_pppoe_new ());
s_pppoe = nm_connection_get_setting_pppoe (conn);
}
grid = NMT_PAGE_GRID (dsl);
widget = nmt_newt_entry_new (40, 0);
nmt_page_grid_append (grid, _("Username"), widget, NULL);
g_object_bind_property (s_pppoe, NM_SETTING_PPPOE_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_pppoe, NM_SETTING_PPPOE_PASSWORD,
widget, "password",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (grid, _("Password"), widget, NULL);
widget = nmt_newt_entry_new (40, 0);
nmt_page_grid_append (grid, _("Service"), widget, NULL);
g_object_bind_property (s_pppoe, NM_SETTING_PPPOE_SERVICE,
widget, "text",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
G_OBJECT_CLASS (nmt_page_dsl_parent_class)->constructed (object);
}
static void
nmt_page_dsl_class_init (NmtPageDslClass *dsl_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (dsl_class);
object_class->constructed = nmt_page_dsl_constructed;
}

View file

@ -0,0 +1,49 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_PAGE_DSL_H
#define NMT_PAGE_DSL_H
#include "nmt-editor-page.h"
G_BEGIN_DECLS
#define NMT_TYPE_PAGE_DSL (nmt_page_dsl_get_type ())
#define NMT_PAGE_DSL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_PAGE_DSL, NmtPageDsl))
#define NMT_PAGE_DSL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_PAGE_DSL, NmtPageDslClass))
#define NMT_IS_PAGE_DSL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_PAGE_DSL))
#define NMT_IS_PAGE_DSL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_PAGE_DSL))
#define NMT_PAGE_DSL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_DSL, NmtPageDslClass))
typedef struct {
NmtEditorPage parent;
} NmtPageDsl;
typedef struct {
NmtEditorPageClass parent;
} NmtPageDslClass;
GType nmt_page_dsl_get_type (void);
NmtNewtWidget *nmt_page_dsl_new (NMConnection *conn);
G_END_DECLS
#endif /* NMT_PAGE_DSL_H */

View file

@ -55,13 +55,13 @@ nmt_page_ip4_new (NMConnection *conn)
NULL);
}
gboolean
nmt_page_ip4_is_non_empty (NmtPageIP4 *ip4)
static gboolean
nmt_page_ip4_show_by_default (NmtEditorPage *page)
{
NMConnection *conn;
NMSettingIP4Config *s_ip4;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip4));
conn = nmt_editor_page_get_connection (page);
s_ip4 = nm_connection_get_setting_ip4_config (conn);
if ( !g_strcmp0 (nm_setting_ip4_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
|| nm_setting_ip4_config_get_num_addresses (s_ip4))
@ -198,6 +198,9 @@ static void
nmt_page_ip4_class_init (NmtPageIP4Class *ip4_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ip4_class);
NmtEditorPageClass *page_class = NMT_EDITOR_PAGE_CLASS (ip4_class);
object_class->constructed = nmt_page_ip4_constructed;
page_class->show_by_default = nmt_page_ip4_show_by_default;
}

View file

@ -44,8 +44,6 @@ GType nmt_page_ip4_get_type (void);
NmtNewtWidget *nmt_page_ip4_new (NMConnection *conn);
gboolean nmt_page_ip4_is_non_empty (NmtPageIP4 *ip4);
G_END_DECLS
#endif /* NMT_PAGE_IP4_H */

View file

@ -55,13 +55,13 @@ nmt_page_ip6_new (NMConnection *conn)
NULL);
}
gboolean
nmt_page_ip6_is_non_empty (NmtPageIP6 *ip6)
static gboolean
nmt_page_ip6_show_by_default (NmtEditorPage *page)
{
NMConnection *conn;
NMSettingIP6Config *s_ip6;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip6));
conn = nmt_editor_page_get_connection (page);
s_ip6 = nm_connection_get_setting_ip6_config (conn);
if ( !g_strcmp0 (nm_setting_ip6_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)
|| nm_setting_ip6_config_get_num_addresses (s_ip6))
@ -196,6 +196,9 @@ static void
nmt_page_ip6_class_init (NmtPageIP6Class *ip6_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ip6_class);
NmtEditorPageClass *page_class = NMT_EDITOR_PAGE_CLASS (ip6_class);
object_class->constructed = nmt_page_ip6_constructed;
page_class->show_by_default = nmt_page_ip6_show_by_default;
}

View file

@ -44,8 +44,6 @@ GType nmt_page_ip6_get_type (void);
NmtNewtWidget *nmt_page_ip6_new (NMConnection *conn);
gboolean nmt_page_ip6_is_non_empty (NmtPageIP6 *ip6);
G_END_DECLS
#endif /* NMT_PAGE_IP6_H */

View file

@ -41,10 +41,12 @@
#include "nmt-page-bond.h"
#include "nmt-page-bridge.h"
#include "nmt-page-bridge-port.h"
#include "nmt-page-dsl.h"
#include "nmt-page-ethernet.h"
#include "nmt-page-infiniband.h"
#include "nmt-page-ip4.h"
#include "nmt-page-ip6.h"
#include "nmt-page-ppp.h"
#include "nmt-page-team.h"
#include "nmt-page-team-port.h"
#include "nmt-page-vlan.h"
@ -122,14 +124,17 @@ permissions_transform_from_allusers (GBinding *binding,
}
static NmtNewtWidget *
build_section_for_page (NmtEditorPage *page,
gboolean open)
add_section_for_page (NmtPageGrid *grid, NmtNewtWidget *widget)
{
NmtEditorPage *page;
NmtNewtWidget *section, *header, *toggle;
g_return_val_if_fail (nmt_newt_widget_get_parent (NMT_NEWT_WIDGET (page)) == NULL, NULL);
g_return_if_fail (NMT_IS_EDITOR_PAGE (widget));
g_return_val_if_fail (nmt_newt_widget_get_parent (widget) == NULL, NULL);
section = nmt_newt_section_new ();
page = NMT_EDITOR_PAGE (widget);
section = nmt_newt_section_new (TRUE);
toggle = nmt_newt_toggle_button_new (_("Hide"), _("Show"));
@ -144,15 +149,16 @@ build_section_for_page (NmtEditorPage *page,
NMT_PAGE_GRID_ROW_EXTRA_ALIGN_RIGHT);
nmt_newt_section_set_header (NMT_NEWT_SECTION (section), header);
nmt_newt_section_set_body (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (page));
nmt_newt_section_set_body (NMT_NEWT_SECTION (section), widget);
g_object_bind_property (toggle, "active",
section, "open",
G_BINDING_SYNC_CREATE);
if (open || !nmt_newt_widget_get_valid (section))
if (nmt_editor_page_show_by_default (page) || !nmt_newt_widget_get_valid (section))
nmt_newt_toggle_button_set_active (NMT_NEWT_TOGGLE_BUTTON (toggle), TRUE);
nmt_page_grid_append (grid, NULL, section, NULL);
return section;
}
@ -164,7 +170,7 @@ nmt_page_main_constructed (GObject *object)
NmtPageGrid *grid;
NMConnection *conn;
NMSettingConnection *s_con;
NmtNewtWidget *widget, *section, *page, *separator;
NmtNewtWidget *widget, *section, *separator;
NmtDeviceEntry *deventry;
GType hardware_type;
const char *slave_type;
@ -195,57 +201,42 @@ nmt_page_main_constructed (GObject *object)
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
if (nm_connection_is_type (conn, NM_SETTING_BOND_SETTING_NAME))
page = nmt_page_bond_new (conn, deventry);
add_section_for_page (grid, nmt_page_bond_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_BRIDGE_SETTING_NAME))
page = nmt_page_bridge_new (conn, deventry);
add_section_for_page (grid, nmt_page_bridge_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_INFINIBAND_SETTING_NAME))
page = nmt_page_infiniband_new (conn, deventry);
else if (nm_connection_is_type (conn, NM_SETTING_TEAM_SETTING_NAME))
page = nmt_page_team_new (conn, deventry);
add_section_for_page (grid, nmt_page_infiniband_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_PPPOE_SETTING_NAME)) {
add_section_for_page (grid, nmt_page_dsl_new (conn));
add_section_for_page (grid, nmt_page_ethernet_new (conn, deventry));
add_section_for_page (grid, nmt_page_ppp_new (conn));
} else if (nm_connection_is_type (conn, NM_SETTING_TEAM_SETTING_NAME))
add_section_for_page (grid, nmt_page_team_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_VLAN_SETTING_NAME))
page = nmt_page_vlan_new (conn, deventry);
add_section_for_page (grid, nmt_page_vlan_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_WIRED_SETTING_NAME))
page = nmt_page_ethernet_new (conn, deventry);
add_section_for_page (grid, nmt_page_ethernet_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_WIRELESS_SETTING_NAME))
page = nmt_page_wifi_new (conn, deventry);
else
page = NULL;
if (page) {
gboolean show_by_default = nmt_page_device_get_show_by_default (NMT_PAGE_DEVICE (page));
section = build_section_for_page (NMT_EDITOR_PAGE (page), show_by_default);
nmt_page_grid_append (grid, NULL, section, NULL);
}
add_section_for_page (grid, nmt_page_wifi_new (conn, deventry));
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
slave_type = nm_setting_connection_get_slave_type (s_con);
if (slave_type) {
if (!strcmp (slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) {
page = nmt_page_bridge_port_new (conn);
section = build_section_for_page (NMT_EDITOR_PAGE (page), TRUE);
nmt_page_grid_append (grid, NULL, section, NULL);
} else if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME)) {
page = nmt_page_team_port_new (conn);
section = build_section_for_page (NMT_EDITOR_PAGE (page), TRUE);
nmt_page_grid_append (grid, NULL, section, NULL);
}
if (!strcmp (slave_type, NM_SETTING_BRIDGE_SETTING_NAME))
add_section_for_page (grid, nmt_page_bridge_port_new (conn));
else if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME))
add_section_for_page (grid, nmt_page_team_port_new (conn));
} else {
page = nmt_page_ip4_new (conn);
section = build_section_for_page (NMT_EDITOR_PAGE (page),
nmt_page_ip4_is_non_empty (NMT_PAGE_IP4 (page)));
nmt_page_grid_append (grid, NULL, section, NULL);
section = add_section_for_page (grid, nmt_page_ip4_new (conn));
/* Add a separator between ip4 and ip6 that's only visible if ip4 is open */
separator = nmt_newt_separator_new ();
g_object_bind_property (section, "open", separator, "visible", G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, separator, NULL);
page = nmt_page_ip6_new (conn);
section = build_section_for_page (NMT_EDITOR_PAGE (page),
nmt_page_ip6_is_non_empty (NMT_PAGE_IP6 (page)));
nmt_page_grid_append (grid, NULL, section, NULL);
add_section_for_page (grid, nmt_page_ip6_new (conn));
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
}

285
clients/tui/nmt-page-ppp.c Normal file
View file

@ -0,0 +1,285 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Red Hat, Inc.
*/
/**
* SECTION:nmt-page-ppp
* @short_description: The editor page for PPP configuration
*/
#include "config.h"
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "nmt-page-ppp.h"
#include "nmt-newt-section.h"
#include "nmt-newt-separator.h"
G_DEFINE_TYPE (NmtPagePpp, nmt_page_ppp, NMT_TYPE_EDITOR_PAGE)
typedef struct {
guint32 lcp_echo_failure;
guint32 lcp_echo_interval;
} NmtPagePppPrivate;
#define NMT_PAGE_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_PPP, NmtPagePppPrivate))
NmtNewtWidget *
nmt_page_ppp_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_PPP,
"connection", conn,
"title", _("PPP CONFIGURATION"),
NULL);
}
static void
nmt_page_ppp_init (NmtPagePpp *ppp)
{
}
static gboolean
transform_lcp_echo_properties_to_checkbox (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer user_data)
{
NMSettingPpp *s_ppp = NM_SETTING_PPP (g_binding_get_source (binding));
if ( nm_setting_ppp_get_lcp_echo_interval (s_ppp) != 0
&& nm_setting_ppp_get_lcp_echo_failure (s_ppp) != 0)
g_value_set_boolean (to_value, TRUE);
else
g_value_set_boolean (to_value, FALSE);
return TRUE;
}
static gboolean
transform_checkbox_to_lcp_echo_interval (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer user_data)
{
NmtPagePpp *ppp = user_data;
NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE (ppp);
if (g_value_get_boolean (from_value))
g_value_set_uint (to_value, priv->lcp_echo_interval);
else
g_value_set_uint (to_value, 0);
return TRUE;
}
static gboolean
transform_checkbox_to_lcp_echo_failure (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer user_data)
{
NmtPagePpp *ppp = user_data;
NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE (ppp);
if (g_value_get_boolean (from_value))
g_value_set_uint (to_value, priv->lcp_echo_failure);
else
g_value_set_uint (to_value, 0);
return TRUE;
}
static void
nmt_page_ppp_constructed (GObject *object)
{
NmtPagePpp *ppp = NMT_PAGE_PPP (object);
NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE (ppp);
NmtPageGrid *grid;
NMSettingPpp *s_ppp;
NmtNewtWidget *widget, *use_mppe;
NmtNewtGrid *auth_grid, *mppe_grid;
NmtNewtSection *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;
}
grid = NMT_PAGE_GRID (ppp);
/* Auth methods */
widget = nmt_newt_section_new (FALSE);
section = NMT_NEWT_SECTION (widget);
g_object_set (section, "open", TRUE, NULL);
nmt_page_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_label_new (_("Allowed authentication methods:"));
nmt_newt_section_set_header (section, widget);
widget = nmt_newt_grid_new ();
auth_grid = NMT_NEWT_GRID (widget);
nmt_newt_section_set_body (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_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
/* MPPE */
widget = nmt_newt_section_new (FALSE);
section = NMT_NEWT_SECTION (widget);
g_object_set (section, "open", TRUE, NULL);
nmt_page_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 (section, widget);
widget = nmt_newt_grid_new ();
mppe_grid = NMT_NEWT_GRID (widget);
nmt_newt_section_set_body (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_page_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_page_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_page_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_page_grid_append (grid, NULL, widget, NULL);
nmt_page_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_page_grid_append (grid, NULL, widget, NULL);
G_OBJECT_CLASS (nmt_page_ppp_parent_class)->constructed (object);
}
static void
nmt_page_ppp_class_init (NmtPagePppClass *ppp_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ppp_class);
g_type_class_add_private (object_class, sizeof (NmtPagePppPrivate));
object_class->constructed = nmt_page_ppp_constructed;
}

View file

@ -0,0 +1,49 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Red Hat, Inc.
*/
#ifndef NMT_PAGE_PPP_H
#define NMT_PAGE_PPP_H
#include "nmt-editor-page.h"
G_BEGIN_DECLS
#define NMT_TYPE_PAGE_PPP (nmt_page_ppp_get_type ())
#define NMT_PAGE_PPP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_PAGE_PPP, NmtPagePpp))
#define NMT_PAGE_PPP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_PAGE_PPP, NmtPagePppClass))
#define NMT_IS_PAGE_PPP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_PAGE_PPP))
#define NMT_IS_PAGE_PPP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_PAGE_PPP))
#define NMT_PAGE_PPP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_PPP, NmtPagePppClass))
typedef struct {
NmtEditorPage parent;
} NmtPagePpp;
typedef struct {
NmtEditorPageClass parent;
} NmtPagePppClass;
GType nmt_page_ppp_get_type (void);
NmtNewtWidget *nmt_page_ppp_new (NMConnection *conn);
G_END_DECLS
#endif /* NMT_PAGE_PPP_H */