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)
This diff is collapsed.
/* -*- 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_NEWT_BUTTON_BOX_H
#define NMT_NEWT_BUTTON_BOX_H
#include "nmt-newt-grid.h"
G_BEGIN_DECLS
#define NMT_TYPE_NEWT_BUTTON_BOX (nmt_newt_button_box_get_type ())
#define NMT_NEWT_BUTTON_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBox))
#define NMT_NEWT_BUTTON_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxClass))
#define NMT_IS_NEWT_BUTTON_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_BUTTON_BOX))
#define NMT_IS_NEWT_BUTTON_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_BUTTON_BOX))
#define NMT_NEWT_BUTTON_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxClass))
struct _NmtNewtButtonBox {
NmtNewtContainer parent;
};
typedef struct {
NmtNewtContainerClass parent;
} NmtNewtButtonBoxClass;
GType nmt_newt_button_box_get_type (void);
typedef enum {
NMT_NEWT_BUTTON_BOX_HORIZONTAL,
NMT_NEWT_BUTTON_BOX_VERTICAL
} NmtNewtButtonBoxOrientation;
NmtNewtWidget *nmt_newt_button_box_new (NmtNewtButtonBoxOrientation orientation);
NmtNewtWidget *nmt_newt_button_box_add_start (NmtNewtButtonBox *bbox,
const char *label);
NmtNewtWidget *nmt_newt_button_box_add_end (NmtNewtButtonBox *bbox,
const char *label);
void nmt_newt_button_box_add_widget_start (NmtNewtButtonBox *bbox,
NmtNewtWidget *widget);
void nmt_newt_button_box_add_widget_end (NmtNewtButtonBox *bbox,
NmtNewtWidget *widget);
G_END_DECLS
#endif /* NMT_NEWT_BUTTON_BOX_H */
/* -*- 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
* @short_description: Push buttons
*
* #NmtNewtButton implements a button widget.
*/
#include "config.h"
#include "nmt-newt-button.h"
#include "nmt-newt-utils.h"
G_DEFINE_TYPE (NmtNewtButton, nmt_newt_button, NMT_TYPE_NEWT_COMPONENT)
#define NMT_NEWT_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonPrivate))
typedef struct {
char *label;
} NmtNewtButtonPrivate;
enum {
PROP_0,
PROP_LABEL,
LAST_PROP
};
enum {
CLICKED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/**
* nmt_newt_button_new:
* @label: the (initial) button label
*
* Creates a new button.
*
* Returns: a new #NmtNewtButton
*/
NmtNewtWidget *
nmt_newt_button_new (const char *label)
{
return g_object_new (NMT_TYPE_NEWT_BUTTON,
"label", label,
NULL);
}
/**
* nmt_newt_button_set_label:
* @button: an #NmtNewtButton
* @label: the new label
*
* Updates @button's label.
*/
void
nmt_newt_button_set_label (NmtNewtButton *button,
const char *label)
{
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (button);
if (!g_strcmp0 (priv->label, label))
return;
g_free (priv->label);
priv->label = g_strdup (label);
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (button));
}
/**
* nmt_newt_button_get_label:
* @button: an #NmtNewtButton
*
* Gets @button's label.
*
* Returns: @button's label.
*/
const char *
nmt_newt_button_get_label (NmtNewtButton *button)
{
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (button);
return priv->label;
}
static void
nmt_newt_button_init (NmtNewtButton *button)
{
}
static void
nmt_newt_button_finalize (GObject *object)
{
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (object);
g_free (priv->label);
G_OBJECT_CLASS (nmt_newt_button_parent_class)->finalize (object);
}
static newtComponent
nmt_newt_button_build_component (NmtNewtComponent *component,
gboolean sensitive)
{
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (component);
newtComponent co;
char *label = NULL, *label_lc;
if (sensitive) {
label_lc = nmt_newt_locale_from_utf8 (priv->label);
co = newtCompactButton (-1, -1, label_lc);
g_free (label_lc);
} else {
label = g_strdup_printf (" <%s>", priv->label);
label_lc = nmt_newt_locale_from_utf8 (label);
co = newtLabel (-1, -1, label_lc);
g_free (label_lc);
newtLabelSetColors (co, NMT_NEWT_COLORSET_DISABLED_BUTTON);
}
return co;
}
static void
nmt_newt_button_size_request (NmtNewtWidget *widget,
int *width,
int *height)
{
NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->size_request (widget, width, height);
/* remove the automatically-added left padding */
(*width)--;
}
static void
nmt_newt_button_size_allocate (NmtNewtWidget *widget,
int x,
int y,
int width,
int height)
{
/* account for the automatically-added left padding */
x--;
width++;
NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->size_allocate (widget, x, y, width, height);
}
static void
nmt_newt_button_activated (NmtNewtWidget *widget)
{
g_signal_emit (widget, signals[CLICKED], 0);
NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->activated (widget);
}
static void
nmt_newt_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
switch (prop_id) {
case PROP_LABEL:
nmt_newt_button_set_label (NMT_NEWT_BUTTON (object),
g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nmt_newt_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (object);
switch (prop_id) {
case PROP_LABEL:
g_value_set_string (value, priv->label);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nmt_newt_button_class_init (NmtNewtButtonClass *button_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (button_class);
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (button_class);
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (button_class);
g_type_class_add_private (button_class, sizeof (NmtNewtButtonPrivate));
/* virtual methods */
object_class->set_property = nmt_newt_button_set_property;
object_class->get_property = nmt_newt_button_get_property;
object_class->finalize = nmt_newt_button_finalize;
widget_class->size_request = nmt_newt_button_size_request;
widget_class->size_allocate = nmt_newt_button_size_allocate;
widget_class->activated = nmt_newt_button_activated;
component_class->build_component = nmt_newt_button_build_component;
/* signals */
/**
* NmtNewtButton::clicked:
* @button: the #NmtNewtButton
*
* Emitted when the button is clicked.
*/
signals[CLICKED] =
g_signal_new ("clicked",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
/* properties */
/**
* NmtNewtButton:label:
*
* The button's label
*/
g_object_class_install_property (object_class, PROP_LABEL,
g_param_spec_string ("label", "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
/* -*- 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_NEWT_BUTTON_H
#define NMT_NEWT_BUTTON_H
#include "nmt-newt-component.h"
G_BEGIN_DECLS
#define NMT_TYPE_NEWT_BUTTON (nmt_newt_button_get_type ())
#define NMT_NEWT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_BUTTON, NmtNewtButton))
#define NMT_NEWT_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonClass))
#define NMT_IS_NEWT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_BUTTON))
#define NMT_IS_NEWT_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_BUTTON))
#define NMT_NEWT_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonClass))
struct _NmtNewtButton {
NmtNewtComponent parent;
};
typedef struct {
NmtNewtComponentClass parent;
} NmtNewtButtonClass;
GType nmt_newt_button_get_type (void);
NmtNewtWidget *nmt_newt_button_new (const char *label);
void nmt_newt_button_set_label (NmtNewtButton *button,
const char *label);
const char *nmt_newt_button_get_label (NmtNewtButton *button);
G_END_DECLS
#endif /* NMT_NEWT_BUTTON_H */
/* -*- 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.