tui: rework how editor pages work
authorDan Winship <danw@gnome.org>
Fri, 31 Oct 2014 20:01:27 +0000 (16:01 -0400)
committerDan Winship <danw@redhat.com>
Fri, 21 Nov 2014 14:01:01 +0000 (09:01 -0500)
Instead of having NmtEditorPage be a widget itself, have it just be an
object that returns a list of NmtEditorSections, where
NmtEditorSection is a subclass of NmtNewtSection.

(This will be important when adding VPN pages, which will be split up
into multiple sections, but with the different sections needing to
cooperate on updating the NMSettingVpn. This reorganization lets us
have an NMPageVpn containing multiple sections, with the NMPageVpn
object handling the coordination between the sections.)

34 files changed:
clients/tui/Makefile.am
clients/tui/nmt-editor-page-device.c
clients/tui/nmt-editor-page.c
clients/tui/nmt-editor-page.h
clients/tui/nmt-editor-section.c [new file with mode: 0644]
clients/tui/nmt-editor-section.h [new file with mode: 0644]
clients/tui/nmt-editor.c
clients/tui/nmt-page-bond.c
clients/tui/nmt-page-bond.h
clients/tui/nmt-page-bridge-port.c
clients/tui/nmt-page-bridge-port.h
clients/tui/nmt-page-bridge.c
clients/tui/nmt-page-bridge.h
clients/tui/nmt-page-dsl.c
clients/tui/nmt-page-dsl.h
clients/tui/nmt-page-ethernet.c
clients/tui/nmt-page-ethernet.h
clients/tui/nmt-page-infiniband.c
clients/tui/nmt-page-infiniband.h
clients/tui/nmt-page-ip4.c
clients/tui/nmt-page-ip4.h
clients/tui/nmt-page-ip6.c
clients/tui/nmt-page-ip6.h
clients/tui/nmt-page-ppp.c
clients/tui/nmt-page-ppp.h
clients/tui/nmt-page-team-port.c
clients/tui/nmt-page-team-port.h
clients/tui/nmt-page-team.c
clients/tui/nmt-page-team.h
clients/tui/nmt-page-vlan.c
clients/tui/nmt-page-vlan.h
clients/tui/nmt-page-wifi.c
clients/tui/nmt-page-wifi.h
po/POTFILES.in

index 18f2b37..ad9335d 100644 (file)
@@ -61,6 +61,8 @@ nmtui_SOURCES = \
        nmt-editor-page.h \
        nmt-editor-page-device.c \
        nmt-editor-page-device.h \
+       nmt-editor-section.c \
+       nmt-editor-section.h \
        nmt-editor.c \
        nmt-editor.h \
        nmt-ip-entry.c \
index 091e9fb..0a9b18e 100644 (file)
@@ -45,7 +45,6 @@ enum {
        PROP_0,
 
        PROP_DEVICE_ENTRY,
-       PROP_SHOW_BY_DEFAULT,
 
        LAST_PROP
 };
@@ -73,14 +72,6 @@ nmt_editor_page_device_get_device_entry (NmtEditorPageDevice *page)
        return priv->device_entry;
 }
 
-static gboolean
-nmt_editor_page_device_show_by_default (NmtEditorPage *page)
-{
-       NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE (page);
-
-       return priv->show_by_default;
-}
-
 static void
 nmt_editor_page_device_set_property (GObject      *object,
                               guint         prop_id,
@@ -93,9 +84,6 @@ nmt_editor_page_device_set_property (GObject      *object,
        case PROP_DEVICE_ENTRY:
                priv->device_entry = g_value_dup_object (value);
                break;
-       case PROP_SHOW_BY_DEFAULT:
-               priv->show_by_default = g_value_get_boolean (value);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -114,9 +102,6 @@ nmt_editor_page_device_get_property (GObject    *object,
        case PROP_DEVICE_ENTRY:
                g_value_set_object (value, priv->device_entry);
                break;
-       case PROP_SHOW_BY_DEFAULT:
-               g_value_set_boolean (value, priv->show_by_default);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -127,7 +112,6 @@ static void
 nmt_editor_page_device_class_init (NmtEditorPageDeviceClass *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 (NmtEditorPageDevicePrivate));
 
@@ -136,8 +120,6 @@ nmt_editor_page_device_class_init (NmtEditorPageDeviceClass *page_device_class)
        object_class->get_property = nmt_editor_page_device_get_property;
        object_class->finalize     = nmt_editor_page_device_finalize;
 
-       page_class->show_by_default = nmt_editor_page_device_show_by_default;
-
        /* properties */
        g_object_class_install_property
                (object_class, PROP_DEVICE_ENTRY,
@@ -146,11 +128,4 @@ nmt_editor_page_device_class_init (NmtEditorPageDeviceClass *page_device_class)
                                      G_PARAM_READWRITE |
                                      G_PARAM_CONSTRUCT_ONLY |
                                      G_PARAM_STATIC_STRINGS));
-       g_object_class_install_property
-               (object_class, PROP_SHOW_BY_DEFAULT,
-                g_param_spec_boolean ("show-by-default", "", "",
-                                      TRUE,
-                                      G_PARAM_READWRITE |
-                                      G_PARAM_CONSTRUCT_ONLY |
-                                      G_PARAM_STATIC_STRINGS));
 }
index cce9cc3..a46d0ed 100644 (file)
@@ -21,9 +21,7 @@
  * @short_description: An #NmtEditor "page"
  *
  * #NmtEditorPage is the abstract base class for #NmtEditor "pages".
- * Note that despite the name, currently all "page" types except
- * #NmtPageMain are actually displayed as collapsible sections, not
- * separate tabs/forms.
+ * A "page" is a set of related #NmtEditorSections.
  */
 
 #include "config.h"
 
 #include "nmt-editor-page.h"
 
-G_DEFINE_ABSTRACT_TYPE (NmtEditorPage, nmt_editor_page, NMT_TYPE_EDITOR_GRID)
+G_DEFINE_ABSTRACT_TYPE (NmtEditorPage, nmt_editor_page, G_TYPE_OBJECT)
 
 #define NMT_EDITOR_PAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_PAGE, NmtEditorPagePrivate))
 
 typedef struct {
-       char *title;
-       NmtNewtWidget *header_widget;
        NMConnection *connection;
+       GSList *sections;
 
 } NmtEditorPagePrivate;
 
@@ -47,7 +44,6 @@ enum {
        PROP_0,
 
        PROP_CONNECTION,
-       PROP_TITLE,
 
        LAST_PROP
 };
@@ -55,9 +51,6 @@ enum {
 static void
 nmt_editor_page_init (NmtEditorPage *page)
 {
-       NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
-
-       priv->header_widget = g_object_ref_sink (nmt_newt_separator_new ());
 }
 
 static void
@@ -65,9 +58,8 @@ nmt_editor_page_finalize (GObject *object)
 {
        NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (object);
 
-       g_free (priv->title);
-       g_clear_object (&priv->header_widget);
        g_clear_object (&priv->connection);
+       g_slist_free_full (priv->sections, g_object_unref);
 
        G_OBJECT_CLASS (nmt_editor_page_parent_class)->finalize (object);
 }
@@ -89,81 +81,37 @@ nmt_editor_page_get_connection (NmtEditorPage *page)
 }
 
 /**
- * nmt_editor_page_set_header_widget:
+ * nmt_editor_page_get_sections:
  * @page: the #NmtEditorPage
- * @widget: an #NmtNewtWidget
  *
- * Sets the page's header widget. When displayed as a subpage of
- * #NmtPageMain, this widget will be put into the corresponding
- * #NmtNewtSection's header.
+ * Gets the page's list of sections to display.
  *
- * FIXME: for consistency, this should be a property as well.
+ * Returns: (transfer none): the list of sections; this is the internal list
+ * used by the page and must not be modified or freed.
  */
-void
-nmt_editor_page_set_header_widget (NmtEditorPage *page,
-                                   NmtNewtWidget *widget)
+GSList *
+nmt_editor_page_get_sections (NmtEditorPage *page)
 {
        NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
 
-       g_clear_object (&priv->header_widget);
-
-       if (!widget)
-               widget = nmt_newt_separator_new ();
-       priv->header_widget = g_object_ref_sink (widget);
+       return priv->sections;
 }
 
 /**
- * nmt_editor_page_get_header_widget:
+ * nmt_editor_page_add_section:
  * @page: the #NmtEditorPage
+ * @section: the #NmtEditorSection
  *
- * Gets the page's header widget. When displayed as a subpage of
- * #NmtPageMain, this widget will be put into the corresponding
- * #NmtNewtSection's header.
- *
- * Returns: (transfer none): the page's header widget.
+ * Adds a section to the page. This should only be called by #NmtEditorPage
+ * subclasses.
  */
-NmtNewtWidget *
-nmt_editor_page_get_header_widget (NmtEditorPage *page)
-{
-       NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
-
-       return priv->header_widget;
-}
-
-/**
- * nmt_editor_page_get_title:
- * @page: the #NmtEditorPage
- *
- * Gets the page's title.
- *
- * Returns: the page's title
- */
-const char *
-nmt_editor_page_get_title (NmtEditorPage *page)
+void
+nmt_editor_page_add_section (NmtEditorPage *page,
+                             NmtEditorSection *section)
 {
        NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (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);
+       priv->sections = g_slist_append (priv->sections, g_object_ref_sink (section));
 }
 
 static void
@@ -178,9 +126,6 @@ nmt_editor_page_set_property (GObject      *object,
        case PROP_CONNECTION:
                priv->connection = g_value_dup_object (value);
                break;
-       case PROP_TITLE:
-               priv->title = g_value_dup_string (value);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -199,9 +144,6 @@ nmt_editor_page_get_property (GObject    *object,
        case PROP_CONNECTION:
                g_value_set_object (value, priv->connection);
                break;
-       case PROP_TITLE:
-               g_value_set_string (value, priv->title);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -220,8 +162,6 @@ 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 */
 
        /**
@@ -236,16 +176,4 @@ nmt_editor_page_class_init (NmtEditorPageClass *page_class)
                                      G_PARAM_READWRITE |
                                      G_PARAM_CONSTRUCT_ONLY |
                                      G_PARAM_STATIC_STRINGS));
-       /**
-        * NmtEditorPage:title:
-        *
-        * The page's title.
-        */
-       g_object_class_install_property
-               (object_class, PROP_TITLE,
-                g_param_spec_string ("title", "", "",
-                                     NULL,
-                                     G_PARAM_READWRITE |
-                                     G_PARAM_CONSTRUCT_ONLY |
-                                     G_PARAM_STATIC_STRINGS));
 }
index 440e664..bbc0d9e 100644 (file)
@@ -13,7 +13,7 @@
  * 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.
+ * Copyright 2013-2014 Red Hat, Inc.
  */
 
 #ifndef NMT_EDITOR_PAGE_H
@@ -22,6 +22,7 @@
 #include <NetworkManager.h>
 
 #include "nmt-editor-grid.h"
+#include "nmt-editor-section.h"
 
 G_BEGIN_DECLS
 
@@ -33,27 +34,24 @@ G_BEGIN_DECLS
 #define NMT_EDITOR_PAGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDITOR_PAGE, NmtEditorPageClass))
 
 typedef struct {
-       NmtEditorGrid parent;
+       GObject parent;
 
 } NmtEditorPage;
 
 typedef struct {
-       NmtEditorGridClass parent;
+       GObjectClass parent;
 
-       gboolean (*show_by_default) (NmtEditorPage *);
 } NmtEditorPageClass;
 
 GType nmt_editor_page_get_type (void);
 
 NMConnection  *nmt_editor_page_get_connection    (NmtEditorPage *page);
 
-void           nmt_editor_page_set_header_widget (NmtEditorPage *page,
-                                                  NmtNewtWidget *widget);
-NmtNewtWidget *nmt_editor_page_get_header_widget (NmtEditorPage *page);
+GSList        *nmt_editor_page_get_sections      (NmtEditorPage *page);
 
-const char    *nmt_editor_page_get_title         (NmtEditorPage *page);
-
-gboolean       nmt_editor_page_show_by_default   (NmtEditorPage *page);
+/*< protected >*/
+void           nmt_editor_page_add_section       (NmtEditorPage *page,
+                                                  NmtEditorSection *section);
 
 G_END_DECLS
 
diff --git a/clients/tui/nmt-editor-section.c b/clients/tui/nmt-editor-section.c
new file mode 100644 (file)
index 0000000..9d892cc
--- /dev/null
@@ -0,0 +1,281 @@
+/* -*- 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-editor-section:
+ * @short_description: A section of the #NmtEditor
+ *
+ * #NmtEditorSection is the abstract base class for #NmtEditor sections.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+
+#include "nmt-editor-section.h"
+#include "nmt-newt-toggle-button.h"
+
+G_DEFINE_TYPE (NmtEditorSection, nmt_editor_section, NMT_TYPE_NEWT_SECTION)
+
+#define NMT_EDITOR_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionPrivate))
+
+typedef struct {
+       NmtEditorGrid *header, *body;
+       char *title;
+       NmtNewtWidget *header_widget;
+       NmtNewtWidget *toggle;
+
+       gboolean show_by_default;
+} NmtEditorSectionPrivate;
+
+enum {
+       PROP_0,
+
+       PROP_TITLE,
+       PROP_SHOW_BY_DEFAULT,
+       PROP_HEADER_WIDGET,
+
+       LAST_PROP
+};
+
+/**
+ * nmt_editor_section_new:
+ * @title: the section title
+ * @header_widget: (allow-none): the widget to show next to the title
+ * @show_by_default: whether the section should be open by default
+ *
+ * Creates a new #NmtEditorSection.
+ *
+ * Returns: a new #NmtEditorSection
+ */
+NmtEditorSection *
+nmt_editor_section_new (const char *title,
+                        NmtNewtWidget *header_widget,
+                        gboolean show_by_default)
+{
+       return g_object_new (NMT_TYPE_EDITOR_SECTION,
+                            "title", title,
+                            "header-widget", header_widget,
+                            "show-by-default", show_by_default,
+                            NULL);
+}
+
+static void
+rebuild_header (NmtEditorSection *section)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
+
+       /* Removing any widget in an NmtEditorGrid removes its whole row, so we can
+        * remove the existing title/widget/toggle by asking to remove toggle.
+        */
+       nmt_newt_container_remove (NMT_NEWT_CONTAINER (priv->header), priv->toggle);
+
+       nmt_editor_grid_append (priv->header,
+                               priv->title,
+                               priv->header_widget ? priv->header_widget : nmt_newt_separator_new (),
+                               priv->toggle);
+       nmt_editor_grid_set_row_flags (priv->header,
+                                      priv->toggle,
+                                      NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT |
+                                      NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT);
+}
+
+static void
+nmt_editor_section_init (NmtEditorSection *section)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
+
+       priv->header = NMT_EDITOR_GRID (nmt_editor_grid_new ());
+       priv->body = NMT_EDITOR_GRID (nmt_editor_grid_new ());
+       priv->toggle = nmt_newt_toggle_button_new (_("Hide"), _("Show"));
+       g_object_ref_sink (priv->toggle);
+
+       nmt_newt_section_set_header (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (priv->header));
+       nmt_newt_section_set_body (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (priv->body));
+
+       g_object_bind_property (priv->toggle, "active",
+                               section, "open",
+                               G_BINDING_SYNC_CREATE);
+}
+
+static void
+nmt_editor_section_finalize (GObject *object)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (object);
+
+       g_free (priv->title);
+       g_clear_object (&priv->header_widget);
+       g_clear_object (&priv->toggle);
+
+       G_OBJECT_CLASS (nmt_editor_section_parent_class)->finalize (object);
+}
+
+/**
+ * nmt_editor_section_get_header_widget:
+ * @section: the #NmtEditorSection
+ *
+ * Gets the section's header widget.
+ *
+ * Returns: the section's header widget.
+ */
+NmtNewtWidget *
+nmt_editor_section_get_header_widget (NmtEditorSection *section)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
+
+       return priv->header_widget;
+}
+
+/**
+ * nmt_editor_section_get_body:
+ * @section: the #NmtEditorSection
+ *
+ * Gets the section's body grid, so that you can add things to it.
+ *
+ * Returns: the #NmtEditorGrid used for the section body
+ */
+NmtEditorGrid *
+nmt_editor_section_get_body (NmtEditorSection *section)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
+
+       return priv->body;
+}
+
+/**
+ * nmt_editor_section_get_title:
+ * @section: the #NmtEditorSection
+ *
+ * Gets the section's title.
+ *
+ * Returns: the section's title
+ */
+const char *
+nmt_editor_section_get_title (NmtEditorSection *section)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
+
+       return priv->title;
+}
+
+static void
+nmt_editor_section_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+       NmtEditorSection *section = NMT_EDITOR_SECTION (object);
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
+
+       switch (prop_id) {
+       case PROP_TITLE:
+               priv->title = g_value_dup_string (value);
+               rebuild_header (section);
+               break;
+       case PROP_SHOW_BY_DEFAULT:
+               priv->show_by_default = g_value_get_boolean (value);
+               nmt_newt_toggle_button_set_active (NMT_NEWT_TOGGLE_BUTTON (priv->toggle),
+                                                  priv->show_by_default);
+               break;
+       case PROP_HEADER_WIDGET:
+               priv->header_widget = g_value_get_object (value);
+               if (priv->header_widget)
+                       g_object_ref_sink (priv->header_widget);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nmt_editor_section_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+       NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (object);
+
+       switch (prop_id) {
+       case PROP_TITLE:
+               g_value_set_string (value, priv->title);
+               break;
+       case PROP_SHOW_BY_DEFAULT:
+               g_value_set_boolean (value, priv->show_by_default);
+               break;
+       case PROP_HEADER_WIDGET:
+               g_value_set_object (value, priv->header_widget);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nmt_editor_section_class_init (NmtEditorSectionClass *section_class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (section_class);
+
+       g_type_class_add_private (section_class, sizeof (NmtEditorSectionPrivate));
+
+       /* virtual methods */
+       object_class->set_property = nmt_editor_section_set_property;
+       object_class->get_property = nmt_editor_section_get_property;
+       object_class->finalize     = nmt_editor_section_finalize;
+
+       /* properties */
+
+       /**
+        * NmtEditorSection:title:
+        *
+        * The section's title.
+        */
+       g_object_class_install_property
+               (object_class, PROP_TITLE,
+                g_param_spec_string ("title", "", "",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_CONSTRUCT_ONLY |
+                                     G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NmtEditorSection:show-by-default:
+        *
+        * Whether the section should be expanded by default.
+        */
+       g_object_class_install_property
+               (object_class, PROP_SHOW_BY_DEFAULT,
+                g_param_spec_boolean ("show-by-default", "", "",
+                                      TRUE,
+                                      G_PARAM_READWRITE |
+                                      G_PARAM_STATIC_STRINGS));
+
+       /**
+        * NmtEditorSection:header-widget:
+        *
+        * The widget (if any) that appears between the section title and its toggle
+        * button.
+        */
+       g_object_class_install_property
+               (object_class, PROP_HEADER_WIDGET,
+                g_param_spec_object ("header-widget", "", "",
+                                     NMT_TYPE_NEWT_WIDGET,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS));
+}
diff --git a/clients/tui/nmt-editor-section.h b/clients/tui/nmt-editor-section.h
new file mode 100644 (file)
index 0000000..67410c7
--- /dev/null
@@ -0,0 +1,56 @@
+/* -*- 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_EDITOR_SECTION_H
+#define NMT_EDITOR_SECTION_H
+
+#include "nmt-newt-section.h"
+#include "nmt-editor-grid.h"
+
+G_BEGIN_DECLS
+
+#define NMT_TYPE_EDITOR_SECTION            (nmt_editor_section_get_type ())
+#define NMT_EDITOR_SECTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDITOR_SECTION, NmtEditorSection))
+#define NMT_EDITOR_SECTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionClass))
+#define NMT_IS_EDITOR_SECTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_EDITOR_SECTION))
+#define NMT_IS_EDITOR_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_EDITOR_SECTION))
+#define NMT_EDITOR_SECTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionClass))
+
+typedef struct {
+       NmtNewtSection parent;
+
+} NmtEditorSection;
+
+typedef struct {
+       NmtNewtSectionClass parent;
+
+} NmtEditorSectionClass;
+
+GType nmt_editor_section_get_type (void);
+
+NmtEditorSection *nmt_editor_section_new               (const char *title,
+                                                        NmtNewtWidget *header_widget,
+                                                        gboolean show_by_default);
+
+const char       *nmt_editor_section_get_title         (NmtEditorSection *section);
+NmtNewtWidget    *nmt_editor_section_get_header_widget (NmtEditorSection *section);
+NmtEditorGrid    *nmt_editor_section_get_body          (NmtEditorSection *section);
+
+G_END_DECLS
+
+#endif /* NMT_EDITOR_SECTION_H */
index 29fb529..a6b0a60 100644 (file)
@@ -64,6 +64,7 @@ typedef struct {
 
        NMEditorConnectionTypeData *type_data;
 
+       GSList *pages;
        NmtNewtWidget *ok, *cancel;
        gboolean running;
 } NmtEditorPrivate;
@@ -266,42 +267,24 @@ permissions_transform_from_allusers (GBinding     *binding,
 }
 
 static NmtNewtWidget *
-add_section_for_page (NmtEditorGrid *grid, NmtNewtWidget *widget)
+add_sections_for_page (NmtEditor *editor, NmtEditorGrid *grid, NmtEditorPage *page)
 {
-       NmtEditorPage *page;
-       NmtNewtWidget *section, *header, *toggle;
-
-       g_return_val_if_fail (NMT_IS_EDITOR_PAGE (widget), NULL);
-       g_return_val_if_fail (nmt_newt_widget_get_parent (widget) == NULL, NULL);
-
-       page = NMT_EDITOR_PAGE (widget);
-
-       section = nmt_newt_section_new (TRUE);
-
-       toggle = nmt_newt_toggle_button_new (_("Hide"), _("Show"));
-
-       header = nmt_editor_grid_new ();
-       nmt_editor_grid_append (NMT_EDITOR_GRID (header),
-                               nmt_editor_page_get_title (page),
-                               nmt_editor_page_get_header_widget (page),
-                               toggle);
-       nmt_editor_grid_set_row_flags (NMT_EDITOR_GRID (header),
-                                      nmt_editor_page_get_header_widget (page),
-                                      NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT |
-                                      NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT);
-       nmt_newt_section_set_header (NMT_NEWT_SECTION (section), header);
+       NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor);
+       NmtNewtWidget *first_section = NULL;
+       const GSList *sections, *iter;
 
-       nmt_newt_section_set_body (NMT_NEWT_SECTION (section), widget);
+       g_return_val_if_fail (NMT_IS_EDITOR_PAGE (page), NULL);
 
-       g_object_bind_property (toggle, "active",
-                               section, "open",
-                               G_BINDING_SYNC_CREATE);
+       priv->pages = g_slist_prepend (priv->pages, page);
 
-       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);
+       sections = nmt_editor_page_get_sections (page);
+       for (iter = sections; iter; iter = iter->next) {
+               if (!first_section)
+                       first_section = iter->data;
+               nmt_editor_grid_append (grid, NULL, iter->data, NULL);
+       }
 
-       nmt_editor_grid_append (grid, NULL, section, NULL);
-       return section;
+       return first_section;
 }
 
 static void
@@ -362,43 +345,43 @@ nmt_editor_constructed (GObject *object)
        /* Now add the various pages... */
 
        if (nm_connection_is_type (priv->edit_connection, NM_SETTING_BOND_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_bond_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_bond_new (priv->edit_connection, deventry));
        else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_BRIDGE_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_bridge_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_bridge_new (priv->edit_connection, deventry));
        else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_INFINIBAND_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_infiniband_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_infiniband_new (priv->edit_connection, deventry));
        else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_PPPOE_SETTING_NAME)) {
-               add_section_for_page (grid, nmt_page_dsl_new (priv->edit_connection));
-               add_section_for_page (grid, nmt_page_ethernet_new (priv->edit_connection, deventry));
-               add_section_for_page (grid, nmt_page_ppp_new (priv->edit_connection));
+               add_sections_for_page (editor, grid, nmt_page_dsl_new (priv->edit_connection));
+               add_sections_for_page (editor, grid, nmt_page_ethernet_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_ppp_new (priv->edit_connection));
        } else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_TEAM_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_team_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_team_new (priv->edit_connection, deventry));
        else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_VLAN_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_vlan_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_vlan_new (priv->edit_connection, deventry));
        else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_WIRED_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_ethernet_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_ethernet_new (priv->edit_connection, deventry));
        else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_WIRELESS_SETTING_NAME))
-               add_section_for_page (grid, nmt_page_wifi_new (priv->edit_connection, deventry));
+               add_sections_for_page (editor, grid, nmt_page_wifi_new (priv->edit_connection, deventry));
 
        nmt_editor_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))
-                       add_section_for_page (grid, nmt_page_bridge_port_new (priv->edit_connection));
+                       add_sections_for_page (editor, grid, nmt_page_bridge_port_new (priv->edit_connection));
                else if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME))
-                       add_section_for_page (grid, nmt_page_team_port_new (priv->edit_connection));
+                       add_sections_for_page (editor, grid, nmt_page_team_port_new (priv->edit_connection));
        } else {
                NmtNewtWidget *section;
 
-               section = add_section_for_page (grid, nmt_page_ip4_new (priv->edit_connection));
+               section = add_sections_for_page (editor, grid, nmt_page_ip4_new (priv->edit_connection));
 
                /* Add a separator between ip4 and ip6 that's only visible if ip4 is open */
                widget = nmt_newt_separator_new ();
                g_object_bind_property (section, "open", widget, "visible", G_BINDING_SYNC_CREATE);
                nmt_editor_grid_append (grid, NULL, widget, NULL);
 
-               add_section_for_page (grid, nmt_page_ip6_new (priv->edit_connection));
+               add_sections_for_page (editor, grid, nmt_page_ip6_new (priv->edit_connection));
 
                nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
        }
@@ -446,6 +429,8 @@ nmt_editor_finalize (GObject *object)
        g_clear_object (&priv->orig_connection);
        g_clear_object (&priv->edit_connection);
 
+       g_slist_free_full (priv->pages, g_object_unref);
+
        g_clear_object (&priv->ok);
        g_clear_object (&priv->cancel);
 
index be4e281..b043b51 100644 (file)
@@ -64,13 +64,12 @@ typedef struct {
        gboolean updating;
 } NmtPageBondPrivate;
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_bond_new (NMConnection   *conn,
                    NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_BOND,
                             "connection", conn,
-                            "title", _("BOND"),
                             "device-entry", deventry,
                             NULL);
 }
@@ -338,6 +337,7 @@ nmt_page_bond_constructed (GObject *object)
 {
        NmtPageBond *bond = NMT_PAGE_BOND (object);
        NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (bond);
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingBond *s_bond;
        NmtNewtWidget *widget, *label;
@@ -351,7 +351,8 @@ nmt_page_bond_constructed (GObject *object)
        }
        priv->s_bond = s_bond;
 
-       grid = NMT_EDITOR_GRID (bond);
+       section = nmt_editor_section_new (_("BOND"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_newt_separator_new ();
        nmt_editor_grid_append (grid, _("Slaves"), widget, NULL);
@@ -420,6 +421,8 @@ nmt_page_bond_constructed (GObject *object)
        bond_options_changed (G_OBJECT (s_bond), NULL, bond);
        slaves_changed (G_OBJECT (priv->slaves), NULL, bond);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (bond), section);
+
        G_OBJECT_CLASS (nmt_page_bond_parent_class)->constructed (object);
 }
 
index 970b757..b77477d 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_bond_get_type (void);
 
-NmtNewtWidget *nmt_page_bond_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_bond_new (NMConnection   *conn,
                                   NmtDeviceEntry *deventry);
 
 G_END_DECLS
index c7ea82f..c9ef14e 100644 (file)
 
 G_DEFINE_TYPE (NmtPageBridgePort, nmt_page_bridge_port, NMT_TYPE_EDITOR_PAGE)
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_bridge_port_new (NMConnection *conn)
 {
        return g_object_new (NMT_TYPE_PAGE_BRIDGE_PORT,
                             "connection", conn,
-                            "title", _("BRIDGE PORT"),
                             NULL);
 }
 
@@ -48,6 +47,7 @@ static void
 nmt_page_bridge_port_constructed (GObject *object)
 {
        NmtPageBridgePort *bridge = NMT_PAGE_BRIDGE_PORT (object);
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingBridgePort *s_port;
        NmtNewtWidget *widget;
@@ -60,7 +60,8 @@ nmt_page_bridge_port_constructed (GObject *object)
                s_port = nm_connection_get_setting_bridge_port (conn);
        }
 
-       grid = NMT_EDITOR_GRID (bridge);
+       section = nmt_editor_section_new (_("BRIDGE PORT"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_newt_entry_numeric_new (10, 0, 63);
        g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_PRIORITY,
@@ -80,6 +81,8 @@ nmt_page_bridge_port_constructed (GObject *object)
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
        nmt_editor_grid_append (grid, NULL, widget, NULL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (bridge), section);
+
        G_OBJECT_CLASS (nmt_page_bridge_port_parent_class)->constructed (object);
 }
 
index 7fe3a92..c566dbc 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_bridge_port_get_type (void);
 
-NmtNewtWidget *nmt_page_bridge_port_new (NMConnection *conn);
+NmtEditorPage *nmt_page_bridge_port_new (NMConnection *conn);
 
 G_END_DECLS
 
index c77b90e..460be60 100644 (file)
 
 G_DEFINE_TYPE (NmtPageBridge, nmt_page_bridge, NMT_TYPE_EDITOR_PAGE_DEVICE)
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_bridge_new (NMConnection   *conn,
                      NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_BRIDGE,
                             "connection", conn,
-                            "title", _("BRIDGE"),
                             "device-entry", deventry,
                             NULL);
 }
@@ -62,6 +61,7 @@ static void
 nmt_page_bridge_constructed (GObject *object)
 {
        NmtPageBridge *bridge = NMT_PAGE_BRIDGE (object);
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingBridge *s_bridge;
        NmtNewtWidget *widget, *label, *stp;
@@ -74,7 +74,8 @@ nmt_page_bridge_constructed (GObject *object)
                s_bridge = nm_connection_get_setting_bridge (conn);
        }
 
-       grid = NMT_EDITOR_GRID (bridge);
+       section = nmt_editor_section_new (_("BRIDGE"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_newt_separator_new ();
        nmt_editor_grid_append (grid, _("Slaves"), widget, NULL);
@@ -135,6 +136,8 @@ nmt_page_bridge_constructed (GObject *object)
        label = nmt_newt_label_new (_("seconds"));
        nmt_editor_grid_append (grid, _("Max age"), widget, label);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (bridge), section);
+
        G_OBJECT_CLASS (nmt_page_bridge_parent_class)->constructed (object);
 }
 
index a17a6b7..60cbdea 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_bridge_get_type (void);
 
-NmtNewtWidget *nmt_page_bridge_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_bridge_new (NMConnection   *conn,
                                     NmtDeviceEntry *deventry);
 
 G_END_DECLS
index 8ecf312..d1d3396 100644 (file)
 
 G_DEFINE_TYPE (NmtPageDsl, nmt_page_dsl, NMT_TYPE_EDITOR_PAGE)
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_dsl_new (NMConnection *conn) 
 {
        return g_object_new (NMT_TYPE_PAGE_DSL,
                             "connection", conn,
-                            "title", _("DSL"),
                             NULL);
 }
 
@@ -49,6 +48,7 @@ static void
 nmt_page_dsl_constructed (GObject *object)
 {
        NmtPageDsl *dsl = NMT_PAGE_DSL (object);
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingPppoe *s_pppoe;
        NmtNewtWidget *widget;
@@ -61,7 +61,8 @@ nmt_page_dsl_constructed (GObject *object)
                s_pppoe = nm_connection_get_setting_pppoe (conn);
        }
 
-       grid = NMT_EDITOR_GRID (dsl);
+       section = nmt_editor_section_new (_("DSL"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_newt_entry_new (40, 0);
        nmt_editor_grid_append (grid, _("Username"), widget, NULL);
@@ -81,6 +82,8 @@ nmt_page_dsl_constructed (GObject *object)
                                widget, "text",
                                G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (dsl), section);
+
        G_OBJECT_CLASS (nmt_page_dsl_parent_class)->constructed (object);
 }
 
index 61fc23a..7a27fd0 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_dsl_get_type (void);
 
-NmtNewtWidget *nmt_page_dsl_new (NMConnection *conn);
+NmtEditorPage *nmt_page_dsl_new (NMConnection *conn);
 
 G_END_DECLS
 
index 53907bb..cf4ef2c 100644 (file)
 
 G_DEFINE_TYPE (NmtPageEthernet, nmt_page_ethernet, NMT_TYPE_EDITOR_PAGE_DEVICE)
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_ethernet_new (NMConnection   *conn,
                        NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_ETHERNET,
                             "connection", conn,
-                            "title", _("ETHERNET"),
                             "device-entry", deventry,
-                            "show-by-default", FALSE,
                             NULL);
 }
 
@@ -54,6 +52,7 @@ nmt_page_ethernet_constructed (GObject *object)
 {
        NmtPageEthernet *ethernet = NMT_PAGE_ETHERNET (object);
        NmtDeviceEntry *deventry;
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingWired *s_wired;
        NmtNewtWidget *widget;
@@ -71,7 +70,8 @@ nmt_page_ethernet_constructed (GObject *object)
                                deventry, "mac-address",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
-       grid = NMT_EDITOR_GRID (ethernet);
+       section = nmt_editor_section_new (_("ETHERNET"), NULL, FALSE);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_mac_entry_new (40, ETH_ALEN);
        g_object_bind_property (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
@@ -85,6 +85,8 @@ nmt_page_ethernet_constructed (GObject *object)
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
        nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (ethernet), section);
+
        G_OBJECT_CLASS (nmt_page_ethernet_parent_class)->constructed (object);
 }
 
index 8b11bf9..bdf3d67 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_ethernet_get_type (void);
 
-NmtNewtWidget *nmt_page_ethernet_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_ethernet_new (NMConnection   *conn,
                                       NmtDeviceEntry *deventry);
 
 G_END_DECLS
index 5ffb733..f39b0b8 100644 (file)
 
 G_DEFINE_TYPE (NmtPageInfiniband, nmt_page_infiniband, NMT_TYPE_EDITOR_PAGE_DEVICE)
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_infiniband_new (NMConnection   *conn,
                          NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_INFINIBAND,
                             "connection", conn,
-                            "title", _("INFINIBAND"),
                             "device-entry", deventry,
                             NULL);
 }
@@ -58,6 +57,7 @@ nmt_page_infiniband_constructed (GObject *object)
 {
        NmtPageInfiniband *infiniband = NMT_PAGE_INFINIBAND (object);
        NmtDeviceEntry *deventry;
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingInfiniband *s_ib;
        NmtNewtWidget *widget;
@@ -81,7 +81,8 @@ nmt_page_infiniband_constructed (GObject *object)
                                deventry, "mac-address",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
-       grid = NMT_EDITOR_GRID (infiniband);
+       section = nmt_editor_section_new (_("INFINIBAND"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_newt_popup_new (transport_mode);
        g_object_bind_property (s_ib, NM_SETTING_INFINIBAND_TRANSPORT_MODE,
@@ -95,6 +96,8 @@ nmt_page_infiniband_constructed (GObject *object)
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
        nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (infiniband), section);
+
        G_OBJECT_CLASS (nmt_page_infiniband_parent_class)->constructed (object);
 }
 
index faa5adf..f51e087 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_infiniband_get_type (void);
 
-NmtNewtWidget *nmt_page_infiniband_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_infiniband_new (NMConnection   *conn,
                                         NmtDeviceEntry *deventry);
 
 G_END_DECLS
index b7d6c32..df3f0b6 100644 (file)
@@ -46,29 +46,14 @@ static NmtNewtPopupEntry ip4methods[] = {
        { NULL, NULL }
 };
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_ip4_new (NMConnection *conn)
 {
        return g_object_new (NMT_TYPE_PAGE_IP4,
                             "connection", conn,
-                            "title", _("IPv4 CONFIGURATION"),
                             NULL);
 }
 
-static gboolean
-nmt_page_ip4_show_by_default (NmtEditorPage *page)
-{
-       NMConnection *conn;
-       NMSettingIPConfig *s_ip4;
-
-       conn = nmt_editor_page_get_connection (page);
-       s_ip4 = nm_connection_get_setting_ip4_config (conn);
-       if (   !g_strcmp0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
-           || nm_setting_ip_config_get_num_addresses (s_ip4))
-               return TRUE;
-       return FALSE;
-}
-
 static void
 nmt_page_ip4_init (NmtPageIP4 *ip4)
 {
@@ -114,6 +99,8 @@ static void
 nmt_page_ip4_constructed (GObject *object)
 {
        NmtPageIP4 *ip4 = NMT_PAGE_IP4 (object);
+       gboolean show_by_default;
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingIPConfig *s_ip4;
        NmtNewtWidget *widget, *button;
@@ -133,9 +120,16 @@ nmt_page_ip4_constructed (GObject *object)
        g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_METHOD,
                                widget, "active-id",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
-       nmt_editor_page_set_header_widget (NMT_EDITOR_PAGE (ip4), widget);
 
-       grid = NMT_EDITOR_GRID (ip4);
+       if (!g_strcmp0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
+               show_by_default = TRUE;
+       else if (nm_setting_ip_config_get_num_addresses (s_ip4))
+               show_by_default = TRUE;
+       else
+               show_by_default = FALSE;
+
+       section = nmt_editor_section_new (_("IPv4 CONFIGURATION"), widget, show_by_default);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4_WITH_PREFIX);
        nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET,
@@ -194,6 +188,8 @@ nmt_page_ip4_constructed (GObject *object)
                                G_BINDING_INVERT_BOOLEAN);
        nmt_editor_grid_append (grid, NULL, widget, NULL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip4), section);
+
        G_OBJECT_CLASS (nmt_page_ip4_parent_class)->constructed (object);
 }
 
@@ -201,9 +197,6 @@ 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;
 }
index f631a91..e3c5a00 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_ip4_get_type (void);
 
-NmtNewtWidget *nmt_page_ip4_new          (NMConnection *conn);
+NmtEditorPage *nmt_page_ip4_new          (NMConnection *conn);
 
 G_END_DECLS
 
index 9d34e65..1513dbf 100644 (file)
@@ -46,29 +46,14 @@ static NmtNewtPopupEntry ip6methods[] = {
        { NULL, NULL }
 };
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_ip6_new (NMConnection *conn)
 {
        return g_object_new (NMT_TYPE_PAGE_IP6,
                             "connection", conn,
-                            "title", _("IPv6 CONFIGURATION"),
                             NULL);
 }
 
-static gboolean
-nmt_page_ip6_show_by_default (NmtEditorPage *page)
-{
-       NMConnection *conn;
-       NMSettingIPConfig *s_ip6;
-
-       conn = nmt_editor_page_get_connection (page);
-       s_ip6 = nm_connection_get_setting_ip6_config (conn);
-       if (   !g_strcmp0 (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)
-           || nm_setting_ip_config_get_num_addresses (s_ip6))
-               return TRUE;
-       return FALSE;
-}
-
 static void
 nmt_page_ip6_init (NmtPageIP6 *ip6)
 {
@@ -114,6 +99,8 @@ static void
 nmt_page_ip6_constructed (GObject *object)
 {
        NmtPageIP6 *ip6 = NMT_PAGE_IP6 (object);
+       gboolean show_by_default;
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingIPConfig *s_ip6;
        NmtNewtWidget *widget, *button;
@@ -133,9 +120,16 @@ nmt_page_ip6_constructed (GObject *object)
        g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_METHOD,
                                widget, "active-id",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
-       nmt_editor_page_set_header_widget (NMT_EDITOR_PAGE (ip6), widget);
 
-       grid = NMT_EDITOR_GRID (ip6);
+       if (!g_strcmp0 (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
+               show_by_default = TRUE;
+       else if (nm_setting_ip_config_get_num_addresses (s_ip6))
+               show_by_default = TRUE;
+       else
+               show_by_default = FALSE;
+
+       section = nmt_editor_section_new (_("IPv6 CONFIGURATION"), widget, show_by_default);
+       grid = nmt_editor_section_get_body (section);
 
        widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6_WITH_PREFIX);
        nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET6,
@@ -192,6 +186,8 @@ nmt_page_ip6_constructed (GObject *object)
                                G_BINDING_INVERT_BOOLEAN);
        nmt_editor_grid_append (grid, NULL, widget, NULL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip6), section);
+
        G_OBJECT_CLASS (nmt_page_ip6_parent_class)->constructed (object);
 }
 
@@ -199,9 +195,6 @@ 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;
 }
index 7ea4a57..498261e 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_ip6_get_type (void);
 
-NmtNewtWidget *nmt_page_ip6_new          (NMConnection *conn);
+NmtEditorPage *nmt_page_ip6_new          (NMConnection *conn);
 
 G_END_DECLS
 
index 983e42d..cec3654 100644 (file)
@@ -41,12 +41,11 @@ typedef struct {
 
 #define NMT_PAGE_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_PPP, NmtPagePppPrivate))
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_ppp_new (NMConnection *conn)
 {
        return g_object_new (NMT_TYPE_PAGE_PPP,
                             "connection", conn,
-                            "title", _("PPP CONFIGURATION"),
                             NULL);
 }
 
@@ -111,11 +110,12 @@ 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 *section;
+       NmtNewtSection *auth_section, *mppe_section;
        NMConnection *conn;
 
        conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ppp));
@@ -131,20 +131,21 @@ nmt_page_ppp_constructed (GObject *object)
                priv->lcp_echo_failure = 5;
        }
 
-       grid = NMT_EDITOR_GRID (ppp);
+       section = nmt_editor_section_new (_("PPP CONFIGURATION"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        /* Auth methods */
        widget = nmt_newt_section_new (FALSE);
-       section = NMT_NEWT_SECTION (widget);
-       g_object_set (section, "open", TRUE, NULL);
+       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 (section, widget);
+       nmt_newt_section_set_header (auth_section, widget);
 
        widget = nmt_newt_grid_new ();
        auth_grid = NMT_NEWT_GRID (widget);
-       nmt_newt_section_set_body (section, 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,
@@ -190,8 +191,8 @@ nmt_page_ppp_constructed (GObject *object)
 
        /* MPPE */
        widget = nmt_newt_section_new (FALSE);
-       section = NMT_NEWT_SECTION (widget);
-       g_object_set (section, "open", TRUE, NULL);
+       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)"));
@@ -200,11 +201,11 @@ nmt_page_ppp_constructed (GObject *object)
                                G_BINDING_BIDIRECTIONAL |
                                G_BINDING_SYNC_CREATE);
        use_mppe = widget;
-       nmt_newt_section_set_header (section, 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 (section, 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",
@@ -271,6 +272,8 @@ nmt_page_ppp_constructed (GObject *object)
                                     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);
 }
 
index 4bc04d8..7910323 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_ppp_get_type (void);
 
-NmtNewtWidget *nmt_page_ppp_new (NMConnection *conn);
+NmtEditorPage *nmt_page_ppp_new (NMConnection *conn);
 
 G_END_DECLS
 
index 786fc1f..645dc9d 100644 (file)
@@ -37,12 +37,11 @@ typedef struct {
 
 } NmtPageTeamPortPrivate;
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_team_port_new (NMConnection *conn)
 {
        return g_object_new (NMT_TYPE_PAGE_TEAM_PORT,
                             "connection", conn,
-                            "title", _("TEAM PORT"),
                             NULL);
 }
 
@@ -79,6 +78,7 @@ nmt_page_team_port_constructed (GObject *object)
 {
        NmtPageTeamPort *team = NMT_PAGE_TEAM_PORT (object);
        NmtPageTeamPortPrivate *priv = NMT_PAGE_TEAM_PORT_GET_PRIVATE (team);
+       NmtEditorSection *section;
        NmtNewtGrid *grid;
        NMSettingTeamPort *s_port;
        NmtNewtWidget *widget;
@@ -92,8 +92,10 @@ nmt_page_team_port_constructed (GObject *object)
        }
        priv->s_port = s_port;
 
+       section = nmt_editor_section_new (_("TEAM PORT"), NULL, TRUE);
+
        widget = nmt_newt_grid_new ();
-       nmt_editor_grid_append (NMT_EDITOR_GRID (team), NULL, widget, NULL);
+       nmt_editor_grid_append (nmt_editor_section_get_body (section), NULL, widget, NULL);
 
        grid = NMT_NEWT_GRID (widget);
 
@@ -111,6 +113,8 @@ nmt_page_team_port_constructed (GObject *object)
        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_port_parent_class)->constructed (object);
 }
 
index 89381c0..2d8fa12 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_team_port_get_type (void);
 
-NmtNewtWidget *nmt_page_team_port_new (NMConnection *conn);
+NmtEditorPage *nmt_page_team_port_new (NMConnection *conn);
 
 G_END_DECLS
 
index e378bbc..e520b02 100644 (file)
@@ -42,13 +42,12 @@ typedef struct {
 
 } NmtPageTeamPrivate;
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_team_new (NMConnection   *conn,
                    NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_TEAM,
                             "connection", conn,
-                            "title", _("TEAM"),
                             "device-entry", deventry,
                             NULL);
 }
@@ -132,6 +131,7 @@ 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;
@@ -145,8 +145,10 @@ nmt_page_team_constructed (GObject *object)
        }
        priv->s_team = s_team;
 
+       section = nmt_editor_section_new (_("TEAM"), NULL, TRUE);
+
        widget = nmt_newt_grid_new ();
-       nmt_editor_grid_append (NMT_EDITOR_GRID (team), NULL, widget, NULL);
+       nmt_editor_grid_append (nmt_editor_section_get_body (section), NULL, widget, NULL);
 
        grid = NMT_NEWT_GRID (widget);
 
@@ -175,6 +177,8 @@ nmt_page_team_constructed (GObject *object)
        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);
 }
 
index 4c0ca6a..2d8bf07 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_team_get_type (void);
 
-NmtNewtWidget *nmt_page_team_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_team_new (NMConnection   *conn,
                                   NmtDeviceEntry *deventry);
 
 G_END_DECLS
index b9e7146..9b9c8f5 100644 (file)
@@ -42,13 +42,12 @@ typedef struct {
 
 } NmtPageVlanPrivate;
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_vlan_new (NMConnection   *conn,
                    NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_VLAN,
                             "connection", conn,
-                            "title", _("VLAN"),
                             "device-entry", deventry,
                             NULL);
 }
@@ -72,6 +71,7 @@ nmt_page_vlan_constructed (GObject *object)
 {
        NmtPageVlan *vlan = NMT_PAGE_VLAN (object);
        NmtPageVlanPrivate *priv = NMT_PAGE_VLAN_GET_PRIVATE (vlan);
+       NmtEditorSection *section;
        NmtEditorGrid *grid;
        NMSettingWired *s_wired;
        NMSettingVlan *s_vlan;
@@ -94,7 +94,8 @@ nmt_page_vlan_constructed (GObject *object)
        }
        priv->s_wired = g_object_ref_sink (s_wired);
 
-       grid = NMT_EDITOR_GRID (vlan);
+       section = nmt_editor_section_new (_("VLAN"), NULL, TRUE);
+       grid = nmt_editor_section_get_body (section);
 
        nm_editor_bind_vlan_name (s_vlan, nm_connection_get_setting_connection (conn));
 
@@ -129,6 +130,8 @@ nmt_page_vlan_constructed (GObject *object)
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
        nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
 
+       nmt_editor_page_add_section (NMT_EDITOR_PAGE (vlan), section);
+
        G_OBJECT_CLASS (nmt_page_vlan_parent_class)->constructed (object);
 }
 
index 3b87b2a..db7c409 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_vlan_get_type (void);
 
-NmtNewtWidget *nmt_page_vlan_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_vlan_new (NMConnection   *conn,
                                   NmtDeviceEntry *deventry);
 
 G_END_DECLS
index ac6dd5b..9cd20ab 100644 (file)
@@ -48,13 +48,12 @@ typedef struct {
 
 } NmtPageWifiPrivate;
 
-NmtNewtWidget *
+NmtEditorPage *
 nmt_page_wifi_new (NMConnection   *conn,
                    NmtDeviceEntry *deventry)
 {
        return g_object_new (NMT_TYPE_PAGE_WIFI,
                             "connection", conn,
-                            "title", _("WI-FI"),
                             "device-entry", deventry,
                             NULL);
 }
@@ -184,6 +183,7 @@ 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;
@@ -214,7 +214,8 @@ nmt_page_wifi_constructed (GObject *object)
                                deventry, "mac-address",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
-       grid = NMT_EDITOR_GRID (wifi);
+       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,
@@ -371,6 +372,8 @@ nmt_page_wifi_constructed (GObject *object)
                                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);
 }
 
index 826f340..7ce5058 100644 (file)
@@ -42,7 +42,7 @@ typedef struct {
 
 GType nmt_page_wifi_get_type (void);
 
-NmtNewtWidget *nmt_page_wifi_new (NMConnection   *conn,
+NmtEditorPage *nmt_page_wifi_new (NMConnection   *conn,
                                   NmtDeviceEntry *deventry);
 
 G_END_DECLS
index 7234e54..1bc1ccb 100644 (file)
@@ -18,6 +18,7 @@ clients/tui/nm-editor-utils.c
 clients/tui/nmt-connect-connection-list.c
 clients/tui/nmt-device-entry.c
 clients/tui/nmt-edit-connection-list.c
+clients/tui/nmt-editor-section.c
 clients/tui/nmt-editor.c
 clients/tui/nmt-mtu-entry.c
 clients/tui/nmt-page-bond.c