Commit 3bda3fb6 authored by Dan Winship's avatar Dan Winship

nmtui: initial import of nmtui

nmtui is a TUI (curses-based Text User Interface) for NetworkManager
parent 72922f20
......@@ -215,6 +215,12 @@ valgrind-*.log
/cli/src/nmcli
/tui/newt/libnmt-newt.a
/tui/nmtui
/tui/nmtui-connect
/tui/nmtui-edit
/tui/nmtui-hostname
/tools/generate-settings-spec
/vapi/*.vapi
......@@ -9,6 +9,7 @@ SUBDIRS = \
src \
callouts \
cli \
tui \
tools \
policy \
data \
......
......@@ -653,6 +653,17 @@ else
libndp_location=system
fi
AC_ARG_WITH(nmtui, AS_HELP_STRING([--with-nmtui=yes|no], [Build nmtui]))
if test "$with_nmtui" != no; then
PKG_CHECK_MODULES(NEWT, [libnewt >= 0.52.15], [build_nmtui=yes], [build_nmtui=no])
else
build_nmtui=no
fi
if test "$with_nmtui" = yes -a "$build_nmtui" = no; then
AC_MSG_ERROR([You must have libnewt installed to build nmtui.])
fi
AM_CONDITIONAL(BUILD_NMTUI, test "$build_nmtui" = yes)
NM_COMPILER_WARNINGS
......@@ -741,6 +752,8 @@ tools/Makefile
cli/Makefile
cli/src/Makefile
cli/completion/Makefile
tui/Makefile
tui/newt/Makefile
test/Makefile
initscript/RedHat/NetworkManager
initscript/Debian/NetworkManager
......@@ -817,6 +830,7 @@ echo " modemmanager-1: $with_modem_manager_1"
echo " concheck: $enable_concheck"
echo " libndp: $libndp_location"
echo " libteamdctl: $enable_teamdctl"
echo " nmtui: $build_nmtui"
echo
echo "Configuration plugins"
......
......@@ -61,4 +61,34 @@ src/nm-sleep-monitor-systemd.c
src/settings/plugins/ifcfg-rh/reader.c
src/settings/nm-settings-utils.c
test/nm-online.c
tui/newt/nmt-newt-utils.c
tui/nm-editor-utils.c
tui/nm-ui-utils.c
tui/nmt-connect-connection-list.c
tui/nmt-device-entry.c
tui/nmt-edit-connection-list.c
tui/nmt-editor.c
tui/nmt-mtu-entry.c
tui/nmt-page-bond.c
tui/nmt-page-bridge-port.c
tui/nmt-page-bridge.c
tui/nmt-page-ethernet.c
tui/nmt-page-infiniband.c
tui/nmt-page-ip4.c
tui/nmt-page-ip6.c
tui/nmt-page-main.c
tui/nmt-page-team-port.c
tui/nmt-page-team.c
tui/nmt-page-vlan.c
tui/nmt-page-wifi.c
tui/nmt-password-dialog.c
tui/nmt-password-fields.c
tui/nmt-route-editor.c
tui/nmt-route-table.c
tui/nmt-secret-agent.c
tui/nmt-slave-list.c
tui/nmt-widget-list.c
tui/nmtui-connect.c
tui/nmtui-edit.c
tui/nmtui-hostname.c
tui/nmtui.c
if BUILD_NMTUI
SUBDIRS = newt .
AM_CPPFLAGS= \
-I$(top_srcdir) \
-I$(top_srcdir)/include \
-I$(top_builddir)/include \
-I$(top_srcdir)/libnm-util \
-I$(top_builddir)/libnm-util \
-I$(top_srcdir)/libnm-glib \
-I$(srcdir)/newt \
$(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \
$(DBUS_CFLAGS) \
$(GUDEV_CFLAGS) \
-DLOCALEDIR=\""$(localedir)"\" \
$(NULL)
bin_PROGRAMS = nmtui
bin_SCRIPTS = nmtui-edit nmtui-connect nmtui-hostname
nmtui_SOURCES = \
nmtui.c \
nmtui.h \
nmtui-connect.c \
nmtui-connect.h \
nmtui-edit.c \
nmtui-edit.h \
nmtui-hostname.c \
nmtui-hostname.h \
\
nm-editor-bindings.c \
nm-editor-bindings.h \
nm-editor-utils.c \
nm-editor-utils.h \
nm-gvaluearray-compat.h \
nm-ui-utils.c \
nm-ui-utils.h \
\
nmt-address-list.c \
nmt-address-list.h \
nmt-connect-connection-list.c \
nmt-connect-connection-list.h \
nmt-device-entry.c \
nmt-device-entry.h \
nmt-edit-connection-list.c \
nmt-edit-connection-list.h \
nmt-editor-page.c \
nmt-editor-page.h \
nmt-editor.c \
nmt-editor.h \
nmt-ip-entry.c \
nmt-ip-entry.h \
nmt-mac-entry.c \
nmt-mac-entry.h \
nmt-mtu-entry.c \
nmt-mtu-entry.h \
nmt-page-bond.c \
nmt-page-bond.h \
nmt-page-bridge.c \
nmt-page-bridge.h \
nmt-page-bridge-port.c \
nmt-page-bridge-port.h \
nmt-page-device.c \
nmt-page-device.h \
nmt-page-ethernet.c \
nmt-page-ethernet.h \
nmt-page-grid.c \
nmt-page-grid.h \
nmt-page-infiniband.c \
nmt-page-infiniband.h \
nmt-page-ip4.c \
nmt-page-ip4.h \
nmt-page-ip6.c \
nmt-page-ip6.h \
nmt-page-main.c \
nmt-page-main.h \
nmt-page-team.c \
nmt-page-team.h \
nmt-page-team-port.c \
nmt-page-team-port.h \
nmt-page-vlan.c \
nmt-page-vlan.h \
nmt-page-wifi.c \
nmt-page-wifi.h \
nmt-password-dialog.c \
nmt-password-dialog.h \
nmt-password-fields.c \
nmt-password-fields.h \
nmt-route-editor.c \
nmt-route-editor.h \
nmt-route-entry.c \
nmt-route-entry.h \
nmt-route-table.c \
nmt-route-table.h \
nmt-secret-agent.c \
nmt-secret-agent.h \
nmt-slave-list.c \
nmt-slave-list.h \
nmt-utils.c \
nmt-utils.h \
nmt-widget-list.c \
nmt-widget-list.h \
$(NULL)
nmtui_LDADD = \
$(top_builddir)/libnm-util/libnm-util.la \
$(top_builddir)/libnm-glib/libnm-glib.la \
$(builddir)/newt/libnmt-newt.a \
$(GUDEV_LIBS) \
$(DBUS_LIBS) \
$(NEWT_LIBS) \
$(GLIB_LIBS) \
$(NULL)
$(bin_SCRIPTS):
ln -s nmtui $@
CLEANFILES = $(bin_SCRIPTS)
endif
AM_CPPFLAGS= \
$(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \
$(NULL)
noinst_LIBRARIES = libnmt-newt.a
libnmt_newt_a_SOURCES = \
nmt-newt.h \
nmt-newt-types.h \
nmt-newt-button.c \
nmt-newt-button.h \
nmt-newt-button-box.c \
nmt-newt-button-box.h \
nmt-newt-checkbox.c \
nmt-newt-checkbox.h \
nmt-newt-component.c \
nmt-newt-component.h \
nmt-newt-container.c \
nmt-newt-container.h \
nmt-newt-entry.c \
nmt-newt-entry.h \
nmt-newt-entry-numeric.c \
nmt-newt-entry-numeric.h \
nmt-newt-form.c \
nmt-newt-form.h \
nmt-newt-grid.c \
nmt-newt-grid.h \
nmt-newt-hacks.c \
nmt-newt-hacks.h \
nmt-newt-label.c \
nmt-newt-label.h \
nmt-newt-listbox.c \
nmt-newt-listbox.h \
nmt-newt-popup.c \
nmt-newt-popup.h \
nmt-newt-section.c \
nmt-newt-section.h \
nmt-newt-separator.c \
nmt-newt-separator.h \
nmt-newt-stack.c \
nmt-newt-stack.h \
nmt-newt-textbox.c \
nmt-newt-textbox.h \
nmt-newt-toggle-button.c \
nmt-newt-toggle-button.h \
nmt-newt-utils.c \
nmt-newt-utils.h \
nmt-newt-widget.c \
nmt-newt-widget.h \
$(NULL)
/* -*- 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.
*/
/**
* SECTION:nmt-newt-button-box
* @short_description: A container for #NmtNewtButtons
*
* #NmtNewtButtonBox is a container for creating and holding
* #NmtNewtButtons.
*
* A button box can be either horizontally or vertically laid out, and
* has two sections within it: the "start" (left or top) and "end"
* (right or bottom). Buttons are added from left to right or top to bottom
* within each of the two sections.
*/
#include "config.h"
#include <string.h>
#include "nmt-newt-button-box.h"
#include "nmt-newt-button.h"
G_DEFINE_TYPE (NmtNewtButtonBox, nmt_newt_button_box, NMT_TYPE_NEWT_CONTAINER)
#define NMT_NEWT_BUTTON_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxPrivate))
typedef struct {
NmtNewtButtonBoxOrientation orientation;
GPtrArray *start_buttons, *end_buttons;
} NmtNewtButtonBoxPrivate;
enum {
PROP_0,
PROP_ORIENTATION,
LAST_PROP
};
/**
* NmtNewtButtonBoxOrientation:
* @NMT_NEWT_BUTTON_BOX_HORIZONTAL: horizontal
* @NMT_NEWT_BUTTON_BOX_VERTICAL: vertical
*
* The orientation of an #NmtNewtButtonBox
*/
/**
* nmt_newt_button_box_new:
* @orientation: the orientation
*
* Creates a new #NmtNewtButtonBox
*
* Returns: a new #NmtNewtButtonBox
*/
NmtNewtWidget *
nmt_newt_button_box_new (NmtNewtButtonBoxOrientation orientation)
{
return g_object_new (NMT_TYPE_NEWT_BUTTON_BOX,
"orientation", orientation,
NULL);
}
static void
nmt_newt_button_box_init (NmtNewtButtonBox *bbox)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
priv->start_buttons = g_ptr_array_new ();
priv->end_buttons = g_ptr_array_new ();
}
/**
* nmt_newt_button_box_add_start:
* @bbox: an #NmtNewtButtonBox
* @label: the label for the newt button
*
* Creates a new #NmtNewtButton with the given @label, adds it
* to the "start" section of @bbox, and returns the newly-created
* button.
*
* Returns: the newly-created button, already added to @bbox
*/
NmtNewtWidget *
nmt_newt_button_box_add_start (NmtNewtButtonBox *bbox,
const char *label)
{
NmtNewtWidget *button;
button = nmt_newt_button_new (label);
nmt_newt_button_box_add_widget_start (bbox, button);
return button;
}
/**
* nmt_newt_button_box_add_widget_start:
* @bbox: an #NmtNewtButtonBox
* @widget: the #NmtNewtWidget to add
*
* Adds the given widget to the "start" section of @bbox.
*/
void
nmt_newt_button_box_add_widget_start (NmtNewtButtonBox *bbox,
NmtNewtWidget *widget)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
add (NMT_NEWT_CONTAINER (bbox), widget);
g_ptr_array_add (priv->start_buttons, widget);
}
/**
* nmt_newt_button_box_add_end:
* @bbox: an #NmtNewtButtonBox
* @label: the label for the newt button
*
* Creates a new #NmtNewtButton with the given @label, adds it
* to the "end" section of @bbox, and returns the newly-created
* button.
*
* Returns: the newly-created button, already added to @bbox
*/
NmtNewtWidget *
nmt_newt_button_box_add_end (NmtNewtButtonBox *bbox,
const char *label)
{
NmtNewtWidget *button;
button = nmt_newt_button_new (label);
nmt_newt_button_box_add_widget_end (bbox, button);
return button;
}
/**
* nmt_newt_button_box_add_widget_end:
* @bbox: an #NmtNewtButtonBox
* @widget: the #NmtNewtWidget to add
*
* Adds the given widget to the "end" section of @bbox.
*/
void
nmt_newt_button_box_add_widget_end (NmtNewtButtonBox *bbox,
NmtNewtWidget *widget)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
add (NMT_NEWT_CONTAINER (bbox), widget);
g_ptr_array_add (priv->end_buttons, widget);
}
static void
nmt_newt_button_box_remove (NmtNewtContainer *container,
NmtNewtWidget *child)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (container);
int i;
NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
remove (container, child);
for (i = 0; i < priv->start_buttons->len; i++) {
if (priv->start_buttons->pdata[i] == (gpointer) child) {
g_ptr_array_remove_index (priv->start_buttons, i);
return;
}
}
for (i = 0; i < priv->end_buttons->len; i++) {
if (priv->end_buttons->pdata[i] == (gpointer) child) {
g_ptr_array_remove_index (priv->end_buttons, i);
return;
}
}
}
static void
add_buttons (GPtrArray *buttons, GPtrArray *cos)
{
NmtNewtWidget *child;
newtComponent *child_cos;
int i, c;
for (i = 0; i < buttons->len; i++) {
child = buttons->pdata[i];
if (!nmt_newt_widget_get_visible (child))
continue;
child_cos = nmt_newt_widget_get_components (child);
for (c = 0; child_cos[c]; c++)
g_ptr_array_add (cos, child_cos[c]);
g_free (child_cos);
}
}
static newtComponent *
nmt_newt_button_box_get_components (NmtNewtWidget *widget)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget);
GPtrArray *cos;
cos = g_ptr_array_new ();
add_buttons (priv->start_buttons, cos);
add_buttons (priv->end_buttons, cos);
g_ptr_array_add (cos, NULL);
return (newtComponent *) g_ptr_array_free (cos, FALSE);
}
static void
size_request_buttons (NmtNewtButtonBox *bbox,
GPtrArray *buttons,
int *width,
int *height)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
int child_width, child_height;
int i;
for (i = 0; i < buttons->len; i++) {
NmtNewtWidget *child = buttons->pdata[i];
nmt_newt_widget_size_request (child, &child_width, &child_height);
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
*width += child_width;
if (i > 0)
*width += 1;
*height = MAX (*height, child_height);
} else {
*height += child_height;
if (i > 0)
*height += 1;
*width = MAX (*width, child_width);
}
}
}
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_newt_button_box_size_allocate (NmtNewtWidget *widget,
int x,
int y,
int width,
int height)
{
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget);
NmtNewtWidget *child;
int child_x, child_y, child_width, child_height;
int i;
child_x = x;
child_y = y;
for (i = 0; i < priv->start_buttons->len; i++) {
child = priv->start_buttons->pdata[i];
nmt_newt_widget_size_request (child, &child_width, &child_height);
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
nmt_newt_widget_size_allocate (child,
child_x, child_y + (height - child_height) / 2,
child_width, child_height);
child_x += child_width + 1;
} else {
nmt_newt_widget_size_allocate (child,
child_x + (width - child_width) / 2, child_y,
child_width, child_height);
child_y += child_height + 1;
}
}
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL)
child_x = x + width;
else
child_y = y + height;
for (i = priv->end_buttons->len - 1; i >= 0; i--) {
child = priv->end_buttons->pdata[i];
nmt_newt_widget_size_request (child, &child_width, &child_height);
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
nmt_newt_widget_size_allocate (child,
child_x - child_width,
child_y + (height - child_height) / 2,
child_width, child_height);