mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 04:40:32 +01:00
tui: reorganize page-creation code a bit
Allow each page type to specify whether it should be shown by default, letting us simplify NmtPageMain.
This commit is contained in:
parent
b05b342ceb
commit
030dace710
9 changed files with 66 additions and 52 deletions
|
|
@ -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 */
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue