summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-12 15:54:58 -0400
committerDan Winship <danw@gnome.org>2014-09-12 16:30:00 -0400
commitbec9ef21cbe9c7d64a7e36e59899bfd3213160fd (patch)
treee0098773d374686d1657e9bd58de9afe47cac4bc
parenta344a3ab97e39a43c24bfe50344877f9a15a29ea (diff)
downloadNetworkManager-bec9ef21cbe9c7d64a7e36e59899bfd3213160fd.tar.gz
tui: reorganize page-creation code a bit
Allow each page type to specify whether it should be shown by default, letting us simplify NmtPageMain.
-rw-r--r--clients/tui/nmt-editor-page.c22
-rw-r--r--clients/tui/nmt-editor-page.h3
-rw-r--r--clients/tui/nmt-page-device.c7
-rw-r--r--clients/tui/nmt-page-device.h1
-rw-r--r--clients/tui/nmt-page-ip4.c9
-rw-r--r--clients/tui/nmt-page-ip4.h2
-rw-r--r--clients/tui/nmt-page-ip6.c9
-rw-r--r--clients/tui/nmt-page-ip6.h2
-rw-r--r--clients/tui/nmt-page-main.c63
9 files changed, 66 insertions, 52 deletions
diff --git a/clients/tui/nmt-editor-page.c b/clients/tui/nmt-editor-page.c
index 80fb163bb4..49419e9254 100644
--- a/clients/tui/nmt-editor-page.c
+++ b/clients/tui/nmt-editor-page.c
@@ -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 */
/**
diff --git a/clients/tui/nmt-editor-page.h b/clients/tui/nmt-editor-page.h
index 8addabebd3..f5733ff256 100644
--- a/clients/tui/nmt-editor-page.h
+++ b/clients/tui/nmt-editor-page.h
@@ -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 */
diff --git a/clients/tui/nmt-page-device.c b/clients/tui/nmt-page-device.c
index 811b5a7db8..d67a5fe019 100644
--- a/clients/tui/nmt-page-device.c
+++ b/clients/tui/nmt-page-device.c
@@ -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,
diff --git a/clients/tui/nmt-page-device.h b/clients/tui/nmt-page-device.h
index 8c90a67a08..a15595a553 100644
--- a/clients/tui/nmt-page-device.h
+++ b/clients/tui/nmt-page-device.h
@@ -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
diff --git a/clients/tui/nmt-page-ip4.c b/clients/tui/nmt-page-ip4.c
index 1c2d31744c..8d10b4aa7f 100644
--- a/clients/tui/nmt-page-ip4.c
+++ b/clients/tui/nmt-page-ip4.c
@@ -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;
}
diff --git a/clients/tui/nmt-page-ip4.h b/clients/tui/nmt-page-ip4.h
index f3bb933e0e..f631a91323 100644
--- a/clients/tui/nmt-page-ip4.h
+++ b/clients/tui/nmt-page-ip4.h
@@ -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 */
diff --git a/clients/tui/nmt-page-ip6.c b/clients/tui/nmt-page-ip6.c
index ae859bd931..7d3ef548fd 100644
--- a/clients/tui/nmt-page-ip6.c
+++ b/clients/tui/nmt-page-ip6.c
@@ -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;
}
diff --git a/clients/tui/nmt-page-ip6.h b/clients/tui/nmt-page-ip6.h
index d0d2bfa298..7ea4a578c7 100644
--- a/clients/tui/nmt-page-ip6.h
+++ b/clients/tui/nmt-page-ip6.h
@@ -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 */
diff --git a/clients/tui/nmt-page-main.c b/clients/tui/nmt-page-main.c
index 4ba7b168d5..77c8e35582 100644
--- a/clients/tui/nmt-page-main.c
+++ b/clients/tui/nmt-page-main.c
@@ -122,12 +122,15 @@ 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);
+
+ page = NMT_EDITOR_PAGE (widget);
section = nmt_newt_section_new (TRUE);
@@ -144,15 +147,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 +168,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 +199,38 @@ 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);
+ add_section_for_page (grid, 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_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);
}