diff options
| author | Michael Biebl <biebl@debian.org> | 2023-08-09 21:55:35 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2023-08-09 21:55:35 +0200 |
| commit | 05e4a733f2141995181a551854d5df929f084adf (patch) | |
| tree | 83bb937740a6667525ba0df046748ecaa829c269 /src/nmtui | |
| parent | 14b0f3a9dc9ea90d60a3b057350fd4d637dc021a (diff) | |
New upstream version 1.44.0 upstream/1.44.0
Diffstat (limited to 'src/nmtui')
| -rw-r--r-- | src/nmtui/meson.build | 3 | ||||
| -rw-r--r-- | src/nmtui/nm-editor-utils.c | 70 | ||||
| -rw-r--r-- | src/nmtui/nm-editor-utils.h | 5 | ||||
| -rw-r--r-- | src/nmtui/nmt-edit-connection-list.c | 2 | ||||
| -rw-r--r-- | src/nmtui/nmt-editor-grid.c | 6 | ||||
| -rw-r--r-- | src/nmtui/nmt-editor-page.c | 2 | ||||
| -rw-r--r-- | src/nmtui/nmt-editor-section.c | 2 | ||||
| -rw-r--r-- | src/nmtui/nmt-editor.c | 12 | ||||
| -rw-r--r-- | src/nmtui/nmt-page-bond.c | 48 | ||||
| -rw-r--r-- | src/nmtui/nmt-page-bridge.c | 10 | ||||
| -rw-r--r-- | src/nmtui/nmt-page-team.c | 42 | ||||
| -rw-r--r-- | src/nmtui/nmt-port-list.c | 254 | ||||
| -rw-r--r-- | src/nmtui/nmt-port-list.h | 37 | ||||
| -rw-r--r-- | src/nmtui/nmt-slave-list.c | 253 | ||||
| -rw-r--r-- | src/nmtui/nmt-slave-list.h | 38 | ||||
| -rw-r--r-- | src/nmtui/nmt-utils.c | 4 | ||||
| -rw-r--r-- | src/nmtui/nmt-widget-list.c | 2 | ||||
| -rw-r--r-- | src/nmtui/nmtui-connect.c | 110 | ||||
| -rw-r--r-- | src/nmtui/nmtui-edit.c | 72 | ||||
| -rw-r--r-- | src/nmtui/nmtui-edit.h | 2 | ||||
| -rw-r--r-- | src/nmtui/nmtui-radio.c | 130 | ||||
| -rw-r--r-- | src/nmtui/nmtui-radio.h | 11 | ||||
| -rw-r--r-- | src/nmtui/nmtui.c | 4 |
23 files changed, 599 insertions, 520 deletions
diff --git a/src/nmtui/meson.build b/src/nmtui/meson.build index 48f2fbf4..13aa8647 100644 --- a/src/nmtui/meson.build +++ b/src/nmtui/meson.build @@ -40,13 +40,14 @@ executable( 'nmt-route-editor.c', 'nmt-route-entry.c', 'nmt-route-table.c', - 'nmt-slave-list.c', + 'nmt-port-list.c', 'nmt-wireguard-peer-list.c', 'nmt-wireguard-peer-editor.c', 'nmtui.c', 'nmtui-connect.c', 'nmtui-edit.c', 'nmtui-hostname.c', + 'nmtui-radio.c', 'nmt-utils.c', 'nmt-widget-list.c', ), diff --git a/src/nmtui/nm-editor-utils.c b/src/nmtui/nm-editor-utils.c index 0f69c962..718c0aef 100644 --- a/src/nmtui/nm-editor-utils.c +++ b/src/nmtui/nm-editor-utils.c @@ -201,22 +201,22 @@ nm_editor_utils_get_connection_type_list(void) item->connection_setup_func = bond_connection_setup_func; g_ptr_array_add(array, item); - item = g_new0(NMEditorConnectionTypeDataReal, 1); - item->data.name = _("Bridge"); - item->data.setting_type = NM_TYPE_SETTING_BRIDGE; - item->data.slave_setting_type = NM_TYPE_SETTING_BRIDGE_PORT; - item->data.device_type = NM_TYPE_DEVICE_BRIDGE; - item->data.virtual = TRUE; - item->id_format = _("Bridge connection %d"); + item = g_new0(NMEditorConnectionTypeDataReal, 1); + item->data.name = _("Bridge"); + item->data.setting_type = NM_TYPE_SETTING_BRIDGE; + item->data.port_setting_type = NM_TYPE_SETTING_BRIDGE_PORT; + item->data.device_type = NM_TYPE_DEVICE_BRIDGE; + item->data.virtual = TRUE; + item->id_format = _("Bridge connection %d"); g_ptr_array_add(array, item); - item = g_new0(NMEditorConnectionTypeDataReal, 1); - item->data.name = _("Team"); - item->data.setting_type = NM_TYPE_SETTING_TEAM; - item->data.slave_setting_type = NM_TYPE_SETTING_TEAM_PORT; - item->data.device_type = NM_TYPE_DEVICE_TEAM; - item->data.virtual = TRUE; - item->id_format = _("Team connection %d"); + item = g_new0(NMEditorConnectionTypeDataReal, 1); + item->data.name = _("Team"); + item->data.setting_type = NM_TYPE_SETTING_TEAM; + item->data.port_setting_type = NM_TYPE_SETTING_TEAM_PORT; + item->data.device_type = NM_TYPE_DEVICE_TEAM; + item->data.virtual = TRUE; + item->id_format = _("Team connection %d"); g_ptr_array_add(array, item); item = g_new0(NMEditorConnectionTypeDataReal, 1); @@ -367,46 +367,46 @@ get_available_iface_name(const char *try_name, NMClient *client) /** * nm_editor_utils_create_connection: * @type: the type of the connection's primary #NMSetting - * @master: (allow-none): the connection's master, if any + * @controller: (nullable): the connection's controller, if any * @client: an #NMClient * * Creates a new #NMConnection of the given type, automatically * creating a UUID and an appropriate not-currently-in-use connection * name, setting #NMSettingConnection:autoconnect appropriately for - * the connection type, filling in slave-related information if - * @master is not %NULL, and initializing any other mandatory-to-set + * the connection type, filling in port-related information if + * @controller is not %NULL, and initializing any other mandatory-to-set * properties to reasonable initial values. * * Returns: a new #NMConnection */ NMConnection * -nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client) +nm_editor_utils_create_connection(GType type, NMConnection *controller, NMClient *client) { NMEditorConnectionTypeData **types; - NMEditorConnectionTypeDataReal *type_data = NULL; - const char *master_setting_type = NULL, *master_uuid = NULL; - GType master_type = G_TYPE_INVALID, slave_setting_type = G_TYPE_INVALID; + NMEditorConnectionTypeDataReal *type_data = NULL; + const char *controller_setting_type = NULL, *controller_uuid = NULL; + GType controller_type = G_TYPE_INVALID, port_setting_type = G_TYPE_INVALID; NMConnection *connection; NMSettingConnection *s_con; - NMSetting *s_hw, *s_slave; + NMSetting *s_hw, *s_port; char *uuid, *id, *ifname; int i; - if (master) { - NMSettingConnection *master_s_con; + if (controller) { + NMSettingConnection *controller_s_con; - master_s_con = nm_connection_get_setting_connection(master); - master_setting_type = nm_setting_connection_get_connection_type(master_s_con); - master_uuid = nm_setting_connection_get_uuid(master_s_con); - master_type = nm_setting_lookup_type(master_setting_type); + controller_s_con = nm_connection_get_setting_connection(controller); + controller_setting_type = nm_setting_connection_get_connection_type(controller_s_con); + controller_uuid = nm_setting_connection_get_uuid(controller_s_con); + controller_type = nm_setting_lookup_type(controller_setting_type); } types = nm_editor_utils_get_connection_type_list(); for (i = 0; types[i]; i++) { if (types[i]->setting_type == type) type_data = (NMEditorConnectionTypeDataReal *) types[i]; - if (types[i]->setting_type == master_type) - slave_setting_type = types[i]->slave_setting_type; + if (types[i]->setting_type == controller_type) + port_setting_type = types[i]->port_setting_type; } if (!type_data) { g_return_val_if_reached(NULL); @@ -430,9 +430,9 @@ nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *cl else ifname = NULL; - if (slave_setting_type != G_TYPE_INVALID) { - s_slave = g_object_new(slave_setting_type, NULL); - nm_connection_add_setting(connection, s_slave); + if (port_setting_type != G_TYPE_INVALID) { + s_port = g_object_new(port_setting_type, NULL); + nm_connection_add_setting(connection, s_port); } uuid = nm_utils_uuid_generate(); @@ -448,9 +448,9 @@ nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *cl NM_SETTING_CONNECTION_AUTOCONNECT, !type_data->no_autoconnect, NM_SETTING_CONNECTION_MASTER, - master_uuid, + controller_uuid, NM_SETTING_CONNECTION_SLAVE_TYPE, - master_setting_type, + controller_setting_type, NM_SETTING_CONNECTION_INTERFACE_NAME, ifname, NULL); diff --git a/src/nmtui/nm-editor-utils.h b/src/nmtui/nm-editor-utils.h index decbc271..98f59595 100644 --- a/src/nmtui/nm-editor-utils.h +++ b/src/nmtui/nm-editor-utils.h @@ -9,7 +9,7 @@ typedef struct { const char *name; GType setting_type; - GType slave_setting_type; + GType port_setting_type; GType device_type; gboolean virtual; } NMEditorConnectionTypeData; @@ -17,6 +17,7 @@ typedef struct { NMEditorConnectionTypeData **nm_editor_utils_get_connection_type_list(void); NMEditorConnectionTypeData *nm_editor_utils_get_connection_type_data(NMConnection *conn); -NMConnection *nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client); +NMConnection * +nm_editor_utils_create_connection(GType type, NMConnection *controller, NMClient *client); #endif /* NM_EDITOR_UTILS_H */ diff --git a/src/nmtui/nmt-edit-connection-list.c b/src/nmtui/nmt-edit-connection-list.c index aec669c8..f8d8303b 100644 --- a/src/nmtui/nmt-edit-connection-list.c +++ b/src/nmtui/nmt-edit-connection-list.c @@ -490,7 +490,7 @@ nmt_edit_connection_list_class_init(NmtEditConnectionListClass *list_class) * * If %TRUE, connections should be grouped by type, with headers * indicating the types (as in the main connection list). If %FALSE, - * they will not be grouped (as in slave connection lists). + * they will not be grouped (as in port connection lists). */ g_object_class_install_property( object_class, diff --git a/src/nmtui/nmt-editor-grid.c b/src/nmtui/nmt-editor-grid.c index e3524084..9b76e3fe 100644 --- a/src/nmtui/nmt-editor-grid.c +++ b/src/nmtui/nmt-editor-grid.c @@ -85,9 +85,9 @@ nmt_editor_grid_finalize(GObject *object) /** * nmt_editor_grid_append: * @grid: the #NmtEditorGrid - * @label: (allow-none): the label text for @widget, or %NULL - * @widget: (allow-none): the (main) widget - * @extra: (allow-none): optional extra widget + * @label: (nullable): the label text for @widget, or %NULL + * @widget: (nullable): the (main) widget + * @extra: (nullable): optional extra widget * * Adds a row to @grid. * diff --git a/src/nmtui/nmt-editor-page.c b/src/nmtui/nmt-editor-page.c index d94b1f0f..7af277fc 100644 --- a/src/nmtui/nmt-editor-page.c +++ b/src/nmtui/nmt-editor-page.c @@ -104,7 +104,7 @@ nmt_editor_page_add_section(NmtEditorPage *page, NmtEditorSection *section) * * This method is called when the user saves the connection. It gives * the page a chance to do save its data outside the connections (such as - * recommit the slave connections). + * recommit the port connections). */ void nmt_editor_page_saved(NmtEditorPage *page) diff --git a/src/nmtui/nmt-editor-section.c b/src/nmtui/nmt-editor-section.c index 462d1f89..0f8aa6e0 100644 --- a/src/nmtui/nmt-editor-section.c +++ b/src/nmtui/nmt-editor-section.c @@ -42,7 +42,7 @@ enum { /** * nmt_editor_section_new: * @title: the section title - * @header_widget: (allow-none): the widget to show next to the title + * @header_widget: (nullable): the widget to show next to the title * @show_by_default: whether the section should be open by default * * Creates a new #NmtEditorSection. diff --git a/src/nmtui/nmt-editor.c b/src/nmtui/nmt-editor.c index 9a64333a..ad8803b6 100644 --- a/src/nmtui/nmt-editor.c +++ b/src/nmtui/nmt-editor.c @@ -306,7 +306,7 @@ nmt_editor_constructed(GObject *object) const char *deventry_label; NmtDeviceEntry *deventry; GType hardware_type; - const char *slave_type; + const char *port_type; NmtEditorPage *page; if (G_OBJECT_CLASS(nmt_editor_parent_class)->constructed) @@ -385,13 +385,13 @@ nmt_editor_constructed(GObject *object) add_sections_for_page(editor, grid, page); 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)) + port_type = nm_setting_connection_get_slave_type(s_con); + if (port_type) { + if (!strcmp(port_type, NM_SETTING_BRIDGE_SETTING_NAME)) add_sections_for_page(editor, grid, nmt_page_bridge_port_new(priv->edit_connection)); - else if (!strcmp(slave_type, NM_SETTING_TEAM_SETTING_NAME)) + else if (!strcmp(port_type, NM_SETTING_TEAM_SETTING_NAME)) add_sections_for_page(editor, grid, nmt_page_team_port_new(priv->edit_connection)); - else if (nm_streq(slave_type, NM_SETTING_BOND_SETTING_NAME)) + else if (nm_streq(port_type, NM_SETTING_BOND_SETTING_NAME)) add_sections_for_page(editor, grid, nmt_page_bond_port_new(priv->edit_connection)); } else { NmtNewtWidget *section; diff --git a/src/nmtui/nmt-page-bond.c b/src/nmtui/nmt-page-bond.c index edcf681e..5a64590c 100644 --- a/src/nmtui/nmt-page-bond.c +++ b/src/nmtui/nmt-page-bond.c @@ -22,7 +22,7 @@ #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "nmt-mac-entry.h" #include "nmt-address-list.h" -#include "nmt-slave-list.h" +#include "nmt-port-list.h" G_DEFINE_TYPE(NmtPageBond, nmt_page_bond, NMT_TYPE_EDITOR_PAGE_DEVICE) @@ -36,7 +36,7 @@ typedef enum { } NmtPageBondMonitoringMode; typedef struct { - NmtSlaveList *slaves; + NmtPortList *ports; /* Note: when adding new options to the UI also ensure they are * initialized in bond_connection_setup_func() @@ -53,7 +53,7 @@ typedef struct { NmtPageBondMonitoringMode monitoring_mode; NMSettingBond *s_bond; - GType slave_type; + GType port_type; gboolean updating; } NmtPageBondPrivate; @@ -75,7 +75,7 @@ nmt_page_bond_init(NmtPageBond *bond) NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); priv->monitoring_mode = NMT_PAGE_BOND_MONITORING_UNKNOWN; - priv->slave_type = G_TYPE_NONE; + priv->port_type = G_TYPE_NONE; } static NmtNewtPopupEntry bond_mode[] = { @@ -141,7 +141,7 @@ bond_options_changed(GObject *object, GParamSpec *pspec, gpointer user_data) nmt_newt_entry_set_text(priv->arp_interval, val ?: "0"); val = nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_ARP_IP_TARGET); - ips = nm_utils_bond_option_arp_ip_targets_split(val); + ips = nm_utils_bond_option_ip_split(val); g_object_set(G_OBJECT(priv->arp_ip_target), "strings", ips ?: NM_PTRARRAY_EMPTY(const char *), @@ -159,30 +159,30 @@ bond_options_changed(GObject *object, GParamSpec *pspec, gpointer user_data) } static void -slaves_changed(GObject *object, GParamSpec *pspec, gpointer user_data) +ports_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NmtPageBond *bond = NMT_PAGE_BOND(user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); - GPtrArray *slaves; + GPtrArray *ports; - g_object_get(object, "connections", &slaves, NULL); - if (slaves->len == 0) { - if (priv->slave_type == G_TYPE_NONE) + g_object_get(object, "connections", &ports, NULL); + if (ports->len == 0) { + if (priv->port_type == G_TYPE_NONE) return; - priv->slave_type = G_TYPE_NONE; + priv->port_type = G_TYPE_NONE; } else { - NMConnection *slave = slaves->pdata[0]; + NMConnection *port = ports->pdata[0]; - if (priv->slave_type != G_TYPE_NONE) + if (priv->port_type != G_TYPE_NONE) return; - if (nm_connection_is_type(slave, NM_SETTING_INFINIBAND_SETTING_NAME)) - priv->slave_type = NM_TYPE_SETTING_INFINIBAND; + if (nm_connection_is_type(port, NM_SETTING_INFINIBAND_SETTING_NAME)) + priv->port_type = NM_TYPE_SETTING_INFINIBAND; else - priv->slave_type = NM_TYPE_SETTING_WIRED; + priv->port_type = NM_TYPE_SETTING_WIRED; } - if (priv->slave_type == NM_TYPE_SETTING_INFINIBAND) { + if (priv->port_type == NM_TYPE_SETTING_INFINIBAND) { nmt_newt_popup_set_active_id(priv->mode, "active-backup"); nmt_newt_component_set_sensitive(NMT_NEWT_COMPONENT(priv->mode), FALSE); } else @@ -314,9 +314,9 @@ bond_connection_type_filter(GType connection_type, gpointer user_data) NmtPageBond *bond = user_data; NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); - if (priv->slave_type != NM_TYPE_SETTING_WIRED && connection_type == NM_TYPE_SETTING_INFINIBAND) + if (priv->port_type != NM_TYPE_SETTING_WIRED && connection_type == NM_TYPE_SETTING_INFINIBAND) return TRUE; - if (priv->slave_type != NM_TYPE_SETTING_INFINIBAND && connection_type == NM_TYPE_SETTING_WIRED) + if (priv->port_type != NM_TYPE_SETTING_INFINIBAND && connection_type == NM_TYPE_SETTING_WIRED) return TRUE; return FALSE; @@ -346,10 +346,10 @@ nmt_page_bond_constructed(GObject *object) nmt_editor_grid_append(grid, _("Slaves"), widget, NULL); nmt_editor_grid_set_row_flags(grid, widget, NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT); - widget = nmt_slave_list_new(conn, bond_connection_type_filter, bond); - g_signal_connect(widget, "notify::connections", G_CALLBACK(slaves_changed), bond); + widget = nmt_port_list_new(conn, bond_connection_type_filter, bond); + g_signal_connect(widget, "notify::connections", G_CALLBACK(ports_changed), bond); nmt_editor_grid_append(grid, NULL, widget, NULL); - priv->slaves = NMT_SLAVE_LIST(widget); + priv->ports = NMT_PORT_LIST(widget); widget = nmt_newt_popup_new(bond_mode); g_signal_connect(widget, "notify::active-id", G_CALLBACK(mode_widget_changed), bond); @@ -408,7 +408,7 @@ nmt_page_bond_constructed(GObject *object) G_CALLBACK(bond_options_changed), bond); bond_options_changed(G_OBJECT(s_bond), NULL, bond); - slaves_changed(G_OBJECT(priv->slaves), NULL, bond); + ports_changed(G_OBJECT(priv->ports), NULL, bond); nmt_editor_page_add_section(NMT_EDITOR_PAGE(bond), section); @@ -420,7 +420,7 @@ nmt_page_bond_saved(NmtEditorPage *editor_page) { NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(editor_page); - nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->slaves)); + nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->ports)); } static void diff --git a/src/nmtui/nmt-page-bridge.c b/src/nmtui/nmt-page-bridge.c index bc32e2a2..e84af1d8 100644 --- a/src/nmtui/nmt-page-bridge.c +++ b/src/nmtui/nmt-page-bridge.c @@ -14,7 +14,7 @@ #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "nmt-address-list.h" -#include "nmt-slave-list.h" +#include "nmt-port-list.h" G_DEFINE_TYPE(NmtPageBridge, nmt_page_bridge, NMT_TYPE_EDITOR_PAGE_DEVICE) @@ -22,7 +22,7 @@ G_DEFINE_TYPE(NmtPageBridge, nmt_page_bridge, NMT_TYPE_EDITOR_PAGE_DEVICE) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_PAGE_BRIDGE, NmtPageBridgePrivate)) typedef struct { - NmtSlaveList *slaves; + NmtPortList *ports; } NmtPageBridgePrivate; NmtEditorPage * @@ -63,9 +63,9 @@ nmt_page_bridge_constructed(GObject *object) nmt_editor_grid_append(grid, _("Slaves"), widget, NULL); nmt_editor_grid_set_row_flags(grid, widget, NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT); - widget = nmt_slave_list_new(conn, bridge_connection_type_filter, bridge); + widget = nmt_port_list_new(conn, bridge_connection_type_filter, bridge); nmt_editor_grid_append(grid, NULL, widget, NULL); - priv->slaves = NMT_SLAVE_LIST(widget); + priv->ports = NMT_PORT_LIST(widget); widget = nmt_newt_entry_numeric_new(10, 0, 1000000); g_object_bind_property(s_bridge, @@ -165,7 +165,7 @@ nmt_page_bridge_saved(NmtEditorPage *editor_page) { NmtPageBridgePrivate *priv = NMT_PAGE_BRIDGE_GET_PRIVATE(editor_page); - nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->slaves)); + nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->ports)); } static void diff --git a/src/nmtui/nmt-page-team.c b/src/nmtui/nmt-page-team.c index 1a554aad..f6311c7e 100644 --- a/src/nmtui/nmt-page-team.c +++ b/src/nmtui/nmt-page-team.c @@ -13,7 +13,7 @@ #include "nmt-page-team.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" -#include "nmt-slave-list.h" +#include "nmt-port-list.h" G_DEFINE_TYPE(NmtPageTeam, nmt_page_team, NMT_TYPE_EDITOR_PAGE_DEVICE) @@ -21,10 +21,10 @@ G_DEFINE_TYPE(NmtPageTeam, nmt_page_team, NMT_TYPE_EDITOR_PAGE_DEVICE) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_PAGE_TEAM, NmtPageTeamPrivate)) typedef struct { - NmtSlaveList *slaves; + NmtPortList *ports; NMSettingTeam *s_team; - GType slave_type; + GType port_type; } NmtPageTeamPrivate; @@ -39,26 +39,26 @@ nmt_page_team_init(NmtPageTeam *team) { NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); - priv->slave_type = G_TYPE_NONE; + priv->port_type = G_TYPE_NONE; } static void -slaves_changed(GObject *object, GParamSpec *pspec, gpointer user_data) +ports_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NmtPageTeam *team = NMT_PAGE_TEAM(user_data); NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); - GPtrArray *slaves; + GPtrArray *ports; - g_object_get(object, "connections", &slaves, NULL); - if (slaves->len == 0) { - priv->slave_type = G_TYPE_NONE; - } else if (priv->slave_type == G_TYPE_NONE) { - NMConnection *slave = slaves->pdata[0]; + g_object_get(object, "connections", &ports, NULL); + if (ports->len == 0) { + priv->port_type = G_TYPE_NONE; + } else if (priv->port_type == G_TYPE_NONE) { + NMConnection *port = ports->pdata[0]; - if (nm_connection_is_type(slave, NM_SETTING_INFINIBAND_SETTING_NAME)) - priv->slave_type = NM_TYPE_SETTING_INFINIBAND; + if (nm_connection_is_type(port, NM_SETTING_INFINIBAND_SETTING_NAME)) + priv->port_type = NM_TYPE_SETTING_INFINIBAND; else - priv->slave_type = NM_TYPE_SETTING_WIRED; + priv->port_type = NM_TYPE_SETTING_WIRED; } } @@ -68,11 +68,11 @@ team_connection_type_filter(GType connection_type, gpointer user_data) NmtPageTeam *team = user_data; NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); - if (priv->slave_type != NM_TYPE_SETTING_WIRED) { + if (priv->port_type != NM_TYPE_SETTING_WIRED) { if (connection_type == NM_TYPE_SETTING_INFINIBAND) return TRUE; } - if (priv->slave_type != NM_TYPE_SETTING_INFINIBAND) { + if (priv->port_type != NM_TYPE_SETTING_INFINIBAND) { if (connection_type == NM_TYPE_SETTING_WIRED || connection_type == NM_TYPE_SETTING_WIRELESS || connection_type == NM_TYPE_SETTING_VLAN) return TRUE; @@ -126,12 +126,12 @@ nmt_page_team_constructed(GObject *object) widget = nmt_newt_label_new(_("Slaves")); nmt_newt_grid_add(grid, widget, 0, 0); - widget = nmt_slave_list_new(conn, team_connection_type_filter, team); - g_signal_connect(widget, "notify::connections", G_CALLBACK(slaves_changed), team); + widget = nmt_port_list_new(conn, team_connection_type_filter, team); + g_signal_connect(widget, "notify::connections", G_CALLBACK(ports_changed), team); nmt_newt_grid_add(grid, widget, 0, 1); nmt_newt_widget_set_padding(widget, 0, 0, 0, 1); - priv->slaves = NMT_SLAVE_LIST(widget); - slaves_changed(G_OBJECT(priv->slaves), NULL, team); + priv->ports = NMT_PORT_LIST(widget); + ports_changed(G_OBJECT(priv->ports), NULL, team); widget = nmt_newt_label_new(_("JSON configuration")); nmt_newt_grid_add(grid, widget, 0, 2); @@ -156,7 +156,7 @@ nmt_page_team_saved(NmtEditorPage *editor_page) { NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(editor_page); - nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->slaves)); + nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->ports)); } static void diff --git a/src/nmtui/nmt-port-list.c b/src/nmtui/nmt-port-list.c new file mode 100644 index 00000000..9f964c73 --- /dev/null +++ b/src/nmtui/nmt-port-list.c @@ -0,0 +1,254 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2013 Red Hat, Inc. + */ + +/** + * SECTION:nmt-port-list: + * @short_description: An editable list of a connection's ports + * + * #NmtPortList implements an #NmtEditConnectionList for the + * ports of a connection. + */ + +#include "libnm-client-aux-extern/nm-default-client.h" + +#include "nmt-port-list.h" + +G_DEFINE_TYPE(NmtPortList, nmt_port_list, NMT_TYPE_EDIT_CONNECTION_LIST) + +#define NMT_PORT_LIST_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_PORT_LIST, NmtPortListPrivate)) + +typedef struct { + NMConnection *controller; + const char *controller_type, *controller_uuid; + + NmtAddConnectionTypeFilter type_filter; + gpointer type_filter_data; +} NmtPortListPrivate; + +enum { + PROP_0, + PROP_CONTROLLER, + PROP_TYPE_FILTER, + PROP_TYPE_FILTER_DATA, + + LAST_PROP +}; + +static gboolean nmt_port_list_connection_filter(NmtEditConnectionList *list, + NMConnection *connection, + gpointer user_data); + +/** + * nmt_port_list_new: + * @controller: the controller #NMConnection whose ports are being listed + * @type_filter: (nullable): a function to limit the available port types + * @type_filter_data: (nullable): data for @type_filter. + * + * Creates a new #NmtPortList. + * + * If @type_filter is non-%NULL, it will be used to limit the connection + * types that are available when the user clicks on the "Add" button to add + * a new port. If the @type_filter filters the list down to only a single + * connection type, then the user will not be presented with a connection-type + * dialog, and will instead be immediately taken to an editor window for the + * new port after clicking "Add". + * + * Returns: a new #NmtPortList. + */ +NmtNewtWidget * +nmt_port_list_new(NMConnection *controller, + NmtAddConnectionTypeFilter type_filter, + gpointer type_filter_data) +{ + return g_object_new(NMT_TYPE_PORT_LIST, + "controller", + controller, + "type-filter", + type_filter, + "type-filter-data", + type_filter_data, + "grouped", + FALSE, + "connection-filter", + nmt_port_list_connection_filter, + NULL); +} + +static void +nmt_port_list_init(NmtPortList *list) +{} + +static void +nmt_port_list_finalize(GObject *object) +{ + NmtPortListPrivate *priv = NMT_PORT_LIST_GET_PRIVATE(object); + + g_object_unref(priv->controller); + + G_OBJECT_CLASS(nmt_port_list_parent_class)->finalize(object); +} + +static gboolean +nmt_port_list_connection_filter(NmtEditConnectionList *list, + NMConnection *connection, + gpointer user_data) +{ + NmtPortListPrivate *priv = NMT_PORT_LIST_GET_PRIVATE(list); + NMSettingConnection *s_con; + const char *controller, *controller_ifname, *port_type; + + s_con = nm_connection_get_setting_connection(connection); + g_return_val_if_fail(s_con != NULL, FALSE); + + port_type = nm_setting_connection_get_slave_type(s_con); + if (g_strcmp0(port_type, priv->controller_type) != 0) + return FALSE; + + controller = nm_setting_connection_get_master(s_con); + if (!controller) + return FALSE; + + controller_ifname = nm_connection_get_interface_name(priv->controller); + if (g_strcmp0(controller, controller_ifname) != 0 + && g_strcmp0(controller, priv->controller_uuid) != 0) + return FALSE; + + return TRUE; +} + +static void +nmt_port_list_add_connection(NmtEditConnectionList *list) +{ + NmtPortListPrivate *priv = NMT_PORT_LIST_GET_PRIVATE(list); + + nmt_add_connection_full(_("Select the type of slave connection you wish to add."), + NULL, + priv->controller, + priv->type_filter, + priv->type_filter_data); +} + +static void +nmt_port_list_edit_connection(NmtEditConnectionList *list, NMConnection *connection) +{ + nmt_edit_connection(connection); +} + +static void +nmt_port_list_remove_connection(NmtEditConnectionList *list, NMRemoteConnection *connection) +{ + nmt_remove_connection(connection); +} + +static void +nmt_port_list_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NmtPortListPrivate *priv = NMT_PORT_LIST_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_CONTROLLER: + priv->controller = g_value_dup_object(value); + if (priv->controller) { + NMSettingConnection *s_con = nm_connection_get_setting_connection(priv->controller); + + priv->controller_type = nm_setting_connection_get_connection_type(s_con); + priv->controller_uuid = nm_setting_connection_get_uuid(s_con); + } + break; + case PROP_TYPE_FILTER: + priv->type_filter = g_value_get_pointer(value); + break; + case PROP_TYPE_FILTER_DATA: + priv->type_filter_data = g_value_get_pointer(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +nmt_port_list_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NmtPortListPrivate *priv = NMT_PORT_LIST_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_CONTROLLER: + g_value_set_object(value, priv->controller); + break; + case PROP_TYPE_FILTER: + g_value_set_pointer(value, priv->type_filter); + break; + case PROP_TYPE_FILTER_DATA: + g_value_set_pointer(value, priv->type_filter_data); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +nmt_port_list_class_init(NmtPortListClass *list_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS(list_class); + NmtEditConnectionListClass *connection_list_class = NMT_EDIT_CONNECTION_LIST_CLASS(list_class); + + g_type_class_add_private(list_class, sizeof(NmtPortListPrivate)); + + /* virtual methods */ + object_class->set_property = nmt_port_list_set_property; + object_class->get_property = nmt_port_list_get_property; + object_class->finalize = nmt_port_list_finalize; + + connection_list_class->add_connection = nmt_port_list_add_connection; + connection_list_class->edit_connection = nmt_port_list_edit_connection; + connection_list_class->remove_connection = nmt_port_list_remove_connection; + + /** + * NmtPortList:controller: + * + * The controller #NMConnection whose ports are being displayed. + */ + g_object_class_install_property( + object_class, + PROP_CONTROLLER, + g_param_spec_object("controller", + "", + "", + NM_TYPE_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + /** + * NmtPortList:type-filter: + * + * If non-%NULL, this will be used to limit the connection types + * that are available when the user clicks on the "Add" button to + * add a new port. If the filter filters the list down to only a + * single connection type, then the user will not be presented + * with a connection-type dialog, and will instead be immediately + * taken to an editor window for the new port after clicking + * "Add". + */ + g_object_class_install_property( + object_class, + PROP_TYPE_FILTER, + g_param_spec_pointer("type-filter", + "", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + /** + * NmtPortList:type-filter-data: + * + * User data passed to #NmtPortList:type-filter + */ + g_object_class_install_property( + object_class, + PROP_TYPE_FILTER_DATA, + g_param_spec_pointer("type-filter-data", + "", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); +} diff --git a/src/nmtui/nmt-port-list.h b/src/nmtui/nmt-port-list.h new file mode 100644 index 00000000..df4f22ff --- /dev/null +++ b/src/nmtui/nmt-port-list.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2013 Red Hat, Inc. + */ + +#ifndef NMT_PORT_LIST_H +#define NMT_PORT_LIST_H + +#include "nmt-edit-connection-list.h" +#include "nmtui-edit.h" + +#define NMT_TYPE_PORT_LIST (nmt_port_list_get_type()) +#define NMT_PORT_LIST(obj) (_NM_G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_PORT_LIST, NmtPortList)) +#define NMT_PORT_LIST_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_PORT_LIST, NmtPortListClass)) +#define NMT_IS_PORT_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_PORT_LIST)) +#define NMT_IS_PORT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_PORT_LIST)) +#define NMT_PORT_LIST_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_PORT_LIST, NmtPortListClass)) + +typedef struct { + NmtEditConnectionList parent; + +} NmtPortList; + +typedef struct { + NmtEditConnectionListClass parent; + +} NmtPortListClass; + +GType nmt_port_list_get_type(void); + +NmtNewtWidget *nmt_port_list_new(NMConnection *controller, + NmtAddConnectionTypeFilter type_filter, + gpointer type_filter_data); + +#endif /* NMT_PORT_LIST_H */ diff --git a/src/nmtui/nmt-slave-list.c b/src/nmtui/nmt-slave-list.c deleted file mode 100644 index b3ba8dc4..00000000 --- a/src/nmtui/nmt-slave-list.c +++ /dev/null @@ -1,253 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2013 Red Hat, Inc. - */ - -/** - * SECTION:nmt-slave-list: - * @short_description: An editable list of a connection's slaves - * - * #NmtSlaveList implements an #NmtEditConnectionList for the - * slaves of a connection. - */ - -#include "libnm-client-aux-extern/nm-default-client.h" - -#include "nmt-slave-list.h" - -G_DEFINE_TYPE(NmtSlaveList, nmt_slave_list, NMT_TYPE_EDIT_CONNECTION_LIST) - -#define NMT_SLAVE_LIST_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_SLAVE_LIST, NmtSlaveListPrivate)) - -typedef struct { - NMConnection *master; - const char *master_type, *master_uuid; - - NmtAddConnectionTypeFilter type_filter; - gpointer type_filter_data; -} NmtSlaveListPrivate; - -enum { - PROP_0, - PROP_MASTER, - PROP_TYPE_FILTER, - PROP_TYPE_FILTER_DATA, - - LAST_PROP -}; - -static gboolean nmt_slave_list_connection_filter(NmtEditConnectionList *list, - NMConnection *connection, - gpointer user_data); - -/** - * nmt_slave_list_new: - * @master: the master #NMConnection whose slaves are being listed - * @type_filter: (allow-none): a function to limit the available slave types - * @type_filter_data: (allow-none): data for @type_filter. - * - * Creates a new #NmtSlaveList. - * - * If @type_filter is non-%NULL, it will be used to limit the connection - * types that are available when the user clicks on the "Add" button to add - * a new slave. If the @type_filter filters the list down to only a single - * connection type, then the user will not be presented with a connection-type - * dialog, and will instead be immediately taken to an editor window for the - * new slave after clicking "Add". - * - * Returns: a new #NmtSlaveList. - */ -NmtNewtWidget * -nmt_slave_list_new(NMConnection *master, - NmtAddConnectionTypeFilter type_filter, - gpointer type_filter_data) -{ - return g_object_new(NMT_TYPE_SLAVE_LIST, - "master", - master, - "type-filter", - type_filter, - "type-filter-data", - type_filter_data, - "grouped", - FALSE, - "connection-filter", - nmt_slave_list_connection_filter, - NULL); -} - -static void -nmt_slave_list_init(NmtSlaveList *list) -{} - -static void -nmt_slave_list_finalize(GObject *object) -{ - NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE(object); - - g_object_unref(priv->master); - - G_OBJECT_CLASS(nmt_slave_list_parent_class)->finalize(object); -} - -static gboolean -nmt_slave_list_connection_filter(NmtEditConnectionList *list, - NMConnection *connection, - gpointer user_data) -{ - NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE(list); - NMSettingConnection *s_con; - const char *master, *master_ifname, *slave_type; - - s_con = nm_connection_get_setting_connection(connection); - g_return_val_if_fail(s_con != NULL, FALSE); - - slave_type = nm_setting_connection_get_slave_type(s_con); - if (g_strcmp0(slave_type, priv->master_type) != 0) - return FALSE; - - master = nm_setting_connection_get_master(s_con); - if (!master) - return FALSE; - - master_ifname = nm_connection_get_interface_name(priv->master); - if (g_strcmp0(master, master_ifname) != 0 && g_strcmp0(master, priv->master_uuid) != 0) - return FALSE; - - return TRUE; -} - -static void -nmt_slave_list_add_connection(NmtEditConnectionList *list) -{ - NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE(list); - - nmt_add_connection_full(_("Select the type of slave connection you wish to add."), - NULL, - priv->master, - priv->type_filter, - priv->type_filter_data); -} - -static void -nmt_slave_list_edit_connection(NmtEditConnectionList *list, NMConnection *connection) -{ - nmt_edit_connection(connection); -} - -static void -nmt_slave_list_remove_connection(NmtEditConnectionList *list, NMRemoteConnection *connection) -{ - nmt_remove_connection(connection); -} - -static void -nmt_slave_list_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_MASTER: - priv->master = g_value_dup_object(value); - if (priv->master) { - NMSettingConnection *s_con = nm_connection_get_setting_connection(priv->master); - - priv->master_type = nm_setting_connection_get_connection_type(s_con); - priv->master_uuid = nm_setting_connection_get_uuid(s_con); - } - break; - case PROP_TYPE_FILTER: - priv->type_filter = g_value_get_pointer(value); - break; - case PROP_TYPE_FILTER_DATA: - priv->type_filter_data = g_value_get_pointer(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -static void -nmt_slave_list_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_MASTER: - g_value_set_object(value, priv->master); - break; - case PROP_TYPE_FILTER: - g_value_set_pointer(value, priv->type_filter); - break; - case PROP_TYPE_FILTER_DATA: - g_value_set_pointer(value, priv->type_filter_data); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -static void -nmt_slave_list_class_init(NmtSlaveListClass *list_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS(list_class); - NmtEditConnectionListClass *connection_list_class = NMT_EDIT_CONNECTION_LIST_CLASS(list_class); - - g_type_class_add_private(list_class, sizeof(NmtSlaveListPrivate)); - - /* virtual methods */ - object_class->set_property = nmt_slave_list_set_property; - object_class->get_property = nmt_slave_list_get_property; - object_class->finalize = nmt_slave_list_finalize; - - connection_list_class->add_connection = nmt_slave_list_add_connection; - connection_list_class->edit_connection = nmt_slave_list_edit_connection; - connection_list_class->remove_connection = nmt_slave_list_remove_connection; - - /** - * NmtSlaveList:master: - * - * The master #NMConnection whose slaves are being displayed. - */ - g_object_class_install_property( - object_class, - PROP_MASTER, - g_param_spec_object("master", - "", - "", - NM_TYPE_CONNECTION, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - /** - * NmtSlaveList:type-filter: - * - * If non-%NULL, this will be used to limit the connection types - * that are available when the user clicks on the "Add" button to - * add a new slave. If the filter filters the list down to only a - * single connection type, then the user will not be presented - * with a connection-type dialog, and will instead be immediately - * taken to an editor window for the new slave after clicking - * "Add". - */ - g_object_class_install_property( - object_class, - PROP_TYPE_FILTER, - g_param_spec_pointer("type-filter", - "", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - /** - * NmtSlaveList:type-filter-data: - * - * User data passed to #NmtSlaveList:type-filter - */ - g_object_class_install_property( - object_class, - PROP_TYPE_FILTER_DATA, - g_param_spec_pointer("type-filter-data", - "", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); -} diff --git a/src/nmtui/nmt-slave-list.h b/src/nmtui/nmt-slave-list.h deleted file mode 100644 index 7bb60c59..00000000 --- a/src/nmtui/nmt-slave-list.h +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2013 Red Hat, Inc. - */ - -#ifndef NMT_SLAVE_LIST_H -#define NMT_SLAVE_LIST_H - -#include "nmt-edit-connection-list.h" -#include "nmtui-edit.h" - -#define NMT_TYPE_SLAVE_LIST (nmt_slave_list_get_type()) -#define NMT_SLAVE_LIST(obj) \ - (_NM_G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_SLAVE_LIST, NmtSlaveList)) -#define NMT_SLAVE_LIST_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_SLAVE_LIST, NmtSlaveListClass)) -#define NMT_IS_SLAVE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_SLAVE_LIST)) -#define NMT_IS_SLAVE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_SLAVE_LIST)) -#define NMT_SLAVE_LIST_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_SLAVE_LIST, NmtSlaveListClass)) - -typedef struct { - NmtEditConnectionList parent; - -} NmtSlaveList; - -typedef struct { - NmtEditConnectionListClass parent; - -} NmtSlaveListClass; - -GType nmt_slave_list_get_type(void); - -NmtNewtWidget *nmt_slave_list_new(NMConnection *master, - NmtAddConnectionTypeFilter type_filter, - gpointer type_filter_data); - -#endif /* NMT_SLAVE_LIST_H */ diff --git a/src/nmtui/nmt-utils.c b/src/nmtui/nmt-utils.c index 84d9e9bb..7a500542 100644 --- a/src/nmtui/nmt-utils.c +++ b/src/nmtui/nmt-utils.c @@ -78,7 +78,7 @@ nmt_sync_op_wait_boolean(NmtSyncOp *op, GError **error) * nmt_sync_op_complete_boolean: * @op: the #NmtSyncOp * @result: the result of the operation - * @error: (allow-none): the error, or %NULL + * @error: (nullable): the error, or %NULL * * Completes @op and returns @result and/or @error to the caller. */ @@ -115,7 +115,7 @@ nmt_sync_op_wait_pointer(NmtSyncOp *op, GError **error) * nmt_sync_op_complete_pointer: * @op: the #NmtSyncOp * @result: the result of the operation - * @error: (allow-none): the error, or %NULL + * @error: (nullable): the error, or %NULL * * Completes @op and returns @result and/or @error to the caller. */ diff --git a/src/nmtui/nmt-widget-list.c b/src/nmtui/nmt-widget-list.c index 18d4d16e..d150eee0 100644 --- a/src/nmtui/nmt-widget-list.c +++ b/src/nmtui/nmt-widget-list.c @@ -95,7 +95,7 @@ static void remove_clicked(NmtNewtButton *button, gpointer user_data); * @create_callback: callback to create new widgets * @user_data: user data for @create_callback * @destroy_notify: #GDestroyNotify for @user_data - * @empty_widget: (allow-none): a widget to display when there are + * @empty_widget: (nullable): a widget to display when there are * no "real" widgets in the list. * * Creates a new #NmtWidgetList. diff --git a/src/nmtui/nmtui-connect.c b/src/nmtui/nmtui-connect.c index 8c4625ec..0dfbf6ac 100644 --- a/src/nmtui/nmtui-connect.c +++ b/src/nmtui/nmtui-connect.c @@ -26,58 +26,6 @@ #include "libnmc-base/nm-client-utils.h" #include "nmt-utils.h" -/** - * Runs openconnect to authenticate. The current screen state is saved - * before starting the command and restored after it returns. - */ -static gboolean -openconnect_authenticate(NMConnection *connection, char **cookie, char **gateway, char **gwcert) -{ - GError *error = NULL; - NMSettingVpn *s_vpn; - gboolean ret; - int status = 0; - const char *gw, *port; - - nmt_newt_message_dialog( - _("openconnect will be run to authenticate.\nIt will return to nmtui when completed.")); - - /* Get port */ - s_vpn = nm_connection_get_setting_vpn(connection); - gw = nm_setting_vpn_get_data_item(s_vpn, "gateway"); - port = gw ? strrchr(gw, ':') : NULL; - - newtSuspend(); - - ret = nm_vpn_openconnect_authenticate_helper(gw, cookie, gateway, gwcert, &status, &error); - - newtResume(); - - if (!ret) { - nmt_newt_message_dialog(_("Error: openconnect failed: %s"), error->message); - g_clear_error(&error); - return FALSE; - } - - if (WIFEXITED(status)) { - if (WEXITSTATUS(status) != 0) { - nmt_newt_message_dialog(_("openconnect failed with status %d"), WEXITSTATUS(status)); - return FALSE; - } - } else if (WIFSIGNALED(status)) { - nmt_newt_message_dialog(_("openconnect failed with signal %d"), WTERMSIG(status)); - return FALSE; - } - - if (gateway && *gateway && port) { - char *tmp = *gateway; - *gateway = g_strdup_printf("%s%s", *gateway, port); - g_free(tmp); - } - - return TRUE; -} - static void secrets_requested(NMSecretAgentSimple *agent, const char *request_id, @@ -86,9 +34,8 @@ secrets_requested(NMSecretAgentSimple *agent, GPtrArray *secrets, gpointer user_data) { - NmtNewtForm *form; NMConnection *connection = NM_CONNECTION(user_data); - int i; + gboolean success = FALSE; /* Get secrets for OpenConnect VPN */ if (connection && nm_connection_is_type(connection, NM_SETTING_VPN_SETTING_NAME)) { @@ -96,45 +43,32 @@ secrets_requested(NMSecretAgentSimple *agent, if (nm_streq0(nm_setting_vpn_get_service_type(s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) { - gs_free char *cookie = NULL; - gs_free char *gateway = NULL; - gs_free char *gwcert = NULL; - - openconnect_authenticate(connection, &cookie, &gateway, &gwcert); - - for (i = 0; i < secrets->len; i++) { - NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - - if (secret->secret_type != NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET) - continue; - if (!nm_streq0(secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) - continue; - if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "cookie")) { - g_free(secret->value); - secret->value = g_steal_pointer(&cookie); - } else if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gateway")) { - g_free(secret->value); - secret->value = g_steal_pointer(&gateway); - } else if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gwcert")) { - g_free(secret->value); - secret->value = g_steal_pointer(&gwcert); - } - } + gs_free_error GError *error = NULL; + + nmt_newt_message_dialog(_("openconnect will be run to authenticate.\nIt will return to " + "nmtui when completed.")); + + newtSuspend(); + + success = nm_vpn_openconnect_authenticate_helper(s_vpn, secrets, &error); + + newtResume(); + + if (!success) + nmt_newt_message_dialog(_("Error: openconnect failed: %s"), error->message); } } - form = nmt_password_dialog_new(request_id, title, msg, secrets); - nmt_newt_form_run_sync(form); + if (!success) { + gs_unref_object NmtNewtForm *form = NULL; - if (nmt_password_dialog_succeeded(NMT_PASSWORD_DIALOG(form))) - nm_secret_agent_simple_response(agent, request_id, secrets); - else - nm_secret_agent_simple_response(agent, request_id, NULL); + form = nmt_password_dialog_new(request_id, title, msg, secrets); + nmt_newt_form_run_sync(form); - g_object_unref(form); + success = nmt_password_dialog_succeeded(NMT_PASSWORD_DIALOG(form)); + } + + nm_secret_agent_simple_response(agent, request_id, success ? secrets : NULL); } typedef struct { diff --git a/src/nmtui/nmtui-edit.c b/src/nmtui/nmtui-edit.c index 4eed22dd..3cedf197 100644 --- a/src/nmtui/nmtui-edit.c +++ b/src/nmtui/nmtui-edit.c @@ -49,22 +49,22 @@ edit_connection_list_filter(NmtEditConnectionList *list, gpointer user_data) { NMSettingConnection *s_con; - const char *master, *slave_type; + const char *controller, *port_type; const char *uuid, *ifname; const GPtrArray *conns; int i; - gboolean found_master = FALSE; + gboolean found_controller = FALSE; s_con = nm_connection_get_setting_connection(connection); g_return_val_if_fail(s_con != NULL, FALSE); - master = nm_setting_connection_get_master(s_con); - if (!master) + controller = nm_setting_connection_get_master(s_con); + if (!controller) return TRUE; - slave_type = nm_setting_connection_get_slave_type(s_con); - if (g_strcmp0(slave_type, NM_SETTING_BOND_SETTING_NAME) != 0 - && g_strcmp0(slave_type, NM_SETTING_TEAM_SETTING_NAME) != 0 - && g_strcmp0(slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0) + port_type = nm_setting_connection_get_slave_type(s_con); + if (g_strcmp0(port_type, NM_SETTING_BOND_SETTING_NAME) != 0 + && g_strcmp0(port_type, NM_SETTING_TEAM_SETTING_NAME) != 0 + && g_strcmp0(port_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0) return TRUE; conns = nm_client_get_connections(nm_client); @@ -73,13 +73,13 @@ edit_connection_list_filter(NmtEditConnectionList *list, uuid = nm_connection_get_uuid(candidate); ifname = nm_connection_get_interface_name(candidate); - if (!g_strcmp0(master, uuid) || !g_strcmp0(master, ifname)) { - found_master = TRUE; + if (!g_strcmp0(controller, uuid) || !g_strcmp0(controller, ifname)) { + found_controller = TRUE; break; } } - return !found_master; + return !found_controller; } static NmtNewtForm * @@ -132,7 +132,7 @@ typedef struct { char *primary_text; char *secondary_text; - NMConnection *master; + NMConnection *controller; NmtAddConnectionTypeFilter type_filter; gpointer type_filter_data; @@ -144,7 +144,7 @@ enum { PROP_PRIMARY_TEXT, PROP_SECONDARY_TEXT, - PROP_MASTER, + PROP_CONTROLLER, PROP_TYPE_FILTER, PROP_TYPE_FILTER_DATA, @@ -158,7 +158,7 @@ create_connection(NmtNewtWidget *widget, gpointer list) GType type = (GType) GPOINTER_TO_SIZE(nmt_newt_listbox_get_active_key(priv->listbox)); NMConnection *connection; - connection = nm_editor_utils_create_connection(type, priv->master, nm_client); + connection = nm_editor_utils_create_connection(type, priv->controller, nm_client); nmt_edit_connection(connection); g_object_unref(connection); } @@ -262,7 +262,7 @@ nmt_add_connection_finalize(GObject *object) g_free(priv->primary_text); g_free(priv->secondary_text); - g_clear_object(&priv->master); + g_clear_object(&priv->controller); G_OBJECT_CLASS(nmt_add_connection_parent_class)->finalize(object); } @@ -282,8 +282,8 @@ nmt_add_connection_set_property(GObject *object, case PROP_SECONDARY_TEXT: priv->secondary_text = g_value_dup_string(value); break; - case PROP_MASTER: - priv->master = g_value_dup_object(value); + case PROP_CONTROLLER: + priv->controller = g_value_dup_object(value); break; case PROP_TYPE_FILTER: priv->type_filter = g_value_get_pointer(value); @@ -309,8 +309,8 @@ nmt_add_connection_get_property(GObject *object, guint prop_id, GValue *value, G case PROP_SECONDARY_TEXT: g_value_set_string(value, priv->secondary_text); break; - case PROP_MASTER: - g_value_set_object(value, priv->master); + case PROP_CONTROLLER: + g_value_set_object(value, priv->controller); break; case PROP_TYPE_FILTER: g_value_set_pointer(value, priv->type_filter); @@ -364,8 +364,8 @@ nmt_add_connection_class_init(NmtAddConnectionClass *add_class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); g_object_class_install_property( object_class, - PROP_MASTER, - g_param_spec_object("master", + PROP_CONTROLLER, + g_param_spec_object("controller", "", "", NM_TYPE_CONNECTION, @@ -399,7 +399,7 @@ nmt_add_connection(void) void nmt_add_connection_full(const char *primary_text, const char *secondary_text, - NMConnection *master, + NMConnection *controller, NmtAddConnectionTypeFilter type_filter, gpointer type_filter_data) { @@ -412,8 +412,8 @@ nmt_add_connection_full(const char *primary_text, primary_text, "secondary-text", secondary_text, - "master", - master, + "controller", + controller, "type-filter", type_filter, "type-filter-data", @@ -500,11 +500,11 @@ void nmt_remove_connection(NMRemoteConnection *connection) { const GPtrArray *all_conns; - GSList *slaves, *iter; + GSList *ports, *iter; int i; - NMRemoteConnection *slave; + NMRemoteConnection *port; NMSettingConnection *s_con; - const char *uuid, *iface, *master; + const char *uuid, *iface, *controller; int choice; choice = nmt_newt_choice_dialog(_("Cancel"), @@ -521,20 +521,20 @@ nmt_remove_connection(NMRemoteConnection *connection) iface = nm_connection_get_interface_name(NM_CONNECTION(connection)); all_conns = nm_client_get_connections(nm_client); - slaves = NULL; + ports = NULL; for (i = 0; i < all_conns->len; i++) { - slave = all_conns->pdata[i]; - s_con = nm_connection_get_setting_connection(NM_CONNECTION(slave)); - master = nm_setting_connection_get_master(s_con); - if (master) { - if (!g_strcmp0(master, uuid) || !g_strcmp0(master, iface)) - slaves = g_slist_prepend(slaves, g_object_ref(slave)); + port = all_conns->pdata[i]; + s_con = nm_connection_get_setting_connection(NM_CONNECTION(port)); + controller = nm_setting_connection_get_master(s_con); + if (controller) { + if (!g_strcmp0(controller, uuid) || !g_strcmp0(controller, iface)) + ports = g_slist_prepend(ports, g_object_ref(port)); } } - for (iter = slaves; iter; iter = iter->next) + for (iter = ports; iter; iter = iter->next) remove_one_connection(iter->data); - g_slist_free_full(slaves, g_object_unref); + g_slist_free_full(ports, g_object_unref); g_object_unref(connection); } diff --git a/src/nmtui/nmtui-edit.h b/src/nmtui/nmtui-edit.h index e8685602..45d6d7af 100644 --- a/src/nmtui/nmtui-edit.h +++ b/src/nmtui/nmtui-edit.h @@ -15,7 +15,7 @@ NmtNewtForm *nmtui_edit(gboolean is_top, int argc, char **argv); void nmt_add_connection(void); void nmt_add_connection_full(const char *primary_text, const char *secondary_text, - NMConnection *master, + NMConnection *controller, NmtAddConnectionTypeFilter type_filter, gpointer type_filter_data); diff --git a/src/nmtui/nmtui-radio.c b/src/nmtui/nmtui-radio.c new file mode 100644 index 00000000..c8636037 --- /dev/null +++ b/src/nmtui/nmtui-radio.c @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023 Javier Sánchez Parra, javsanpar@riseup.net + */ + +/** + * SECTION:nmtui-radio + * @short_description: radio-setting functionality + * + */ + +#include "libnm-client-aux-extern/nm-default-client.h" + +#include "libnmt-newt/nmt-newt-toggle-button.h" +#include "libnmt-newt/nmt-newt-types.h" +#include "libnmt-newt/nmt-newt.h" + +#include "nmtui.h" +#include "nmtui-radio.h" +#include "nmt-utils.h" + +static void +nmtui_radio_toggle_wifi(GObject *object, gpointer radio_type) +{ + NmtNewtToggleButton *button = NMT_NEWT_TOGGLE_BUTTON(object); + gboolean enable_flag; + + enable_flag = nmt_newt_toggle_button_get_active(button); + nm_client_wireless_set_enabled(nm_client, enable_flag); +} + +static void +nmtui_radio_toggle_wwan(GObject *object, gpointer radio_type) +{ + NmtNewtToggleButton *button = NMT_NEWT_TOGGLE_BUTTON(object); + gboolean enable_flag; + + enable_flag = nmt_newt_toggle_button_get_active(button); + nm_client_wwan_set_enabled(nm_client, enable_flag); +} + +static void +nmtui_radio_run_dialog(void) +{ + gs_unref_object NmtNewtForm *form = NULL; + NmtNewtToggleButton *toggle_wifi, *toggle_wwan; + NmtNewtButtonBox *bbox; + NmtNewtWidget *widget; + NmtNewtGrid *grid; + gboolean enable_flag; + + form = g_object_new(NMT_TYPE_NEWT_FORM, "title", _("Set the radio switches status"), NULL); + + widget = nmt_newt_grid_new(); + nmt_newt_form_set_content(form, widget); + grid = NMT_NEWT_GRID(widget); + + widget = nmt_newt_label_new(_("Wi-Fi")); + nmt_newt_grid_add(grid, widget, 0, 0); + + widget = nmt_newt_label_new(_("Hardware:")); + nmt_newt_grid_add(grid, widget, 0, 1); + + if (!(nm_client_get_radio_flags(nm_client) & NM_RADIO_FLAG_WLAN_AVAILABLE)) { + widget = nmt_newt_label_new(_("Missing")); + } else { + enable_flag = nm_client_wireless_hardware_get_enabled(nm_client); + widget = nmt_newt_label_new(enable_flag ? _("Enabled") : _("Disabled")); + } + nmt_newt_grid_add(grid, widget, 1, 1); + nmt_newt_widget_set_padding(widget, 1, 0, 0, 0); + + widget = nmt_newt_label_new(_("Software:")); + nmt_newt_grid_add(grid, widget, 2, 1); + nmt_newt_widget_set_padding(widget, 3, 0, 0, 0); + + widget = nmt_newt_toggle_button_new(_("Enabled"), _("Disabled")); + nmt_newt_grid_add(grid, widget, 3, 1); + nmt_newt_widget_set_padding(widget, 1, 0, 0, 0); + toggle_wifi = NMT_NEWT_TOGGLE_BUTTON(widget); + enable_flag = nm_client_wireless_get_enabled(nm_client); + nmt_newt_toggle_button_set_active(toggle_wifi, enable_flag); + g_signal_connect(widget, "activated", G_CALLBACK(nmtui_radio_toggle_wifi), NULL); + + widget = nmt_newt_label_new(_("WWAN")); + nmt_newt_grid_add(grid, widget, 0, 2); + nmt_newt_widget_set_padding(widget, 0, 1, 0, 0); + + widget = nmt_newt_label_new(_("Hardware:")); + nmt_newt_grid_add(grid, widget, 0, 3); + + if (!(nm_client_get_radio_flags(nm_client) & NM_RADIO_FLAG_WWAN_AVAILABLE)) { + widget = nmt_newt_label_new(_("Missing")); + } else { + enable_flag = nm_client_wwan_hardware_get_enabled(nm_client); + widget = nmt_newt_label_new(enable_flag ? _("Enabled") : _("Disabled")); + } + nmt_newt_grid_add(grid, widget, 1, 3); + nmt_newt_widget_set_padding(widget, 1, 0, 0, 0); + + widget = nmt_newt_label_new(_("Software:")); + nmt_newt_grid_add(grid, widget, 2, 3); + nmt_newt_widget_set_padding(widget, 3, 0, 0, 0); + + widget = nmt_newt_toggle_button_new(_("Enabled"), _("Disabled")); + nmt_newt_grid_add(grid, widget, 3, 3); + nmt_newt_widget_set_padding(widget, 1, 0, 0, 0); + toggle_wwan = NMT_NEWT_TOGGLE_BUTTON(widget); + enable_flag = nm_client_wwan_get_enabled(nm_client); + nmt_newt_toggle_button_set_active(toggle_wwan, enable_flag); + g_signal_connect(widget, "activated", G_CALLBACK(nmtui_radio_toggle_wwan), NULL); + + widget = nmt_newt_button_box_new(NMT_NEWT_BUTTON_BOX_HORIZONTAL); + nmt_newt_grid_add(grid, widget, 3, 4); + nmt_newt_widget_set_padding(widget, 0, 1, 0, 0); + bbox = NMT_NEWT_BUTTON_BOX(widget); + + widget = nmt_newt_button_box_add_end(bbox, _("Back")); + nmt_newt_widget_set_exit_on_activate(widget, TRUE); + + nmt_newt_form_run_sync(form); +} + +NmtNewtForm * +nmtui_radio(gboolean is_top, int argc, char **argv) +{ + nmtui_radio_run_dialog(); + + return NULL; +} diff --git a/src/nmtui/nmtui-radio.h b/src/nmtui/nmtui-radio.h new file mode 100644 index 00000000..53d60b9a --- /dev/null +++ b/src/nmtui/nmtui-radio.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023 Javier Sánchez Parra, javsanpar@riseup.net + */ + +#ifndef NMTUI_RADIO_H +#define NMTUI_RADIO_H + +NmtNewtForm *nmtui_radio(gboolean is_top, int argc, char **argv); + +#endif /* NMTUI_RADIO_H */ diff --git a/src/nmtui/nmtui.c b/src/nmtui/nmtui.c index 37c26e9d..9927e40a 100644 --- a/src/nmtui/nmtui.c +++ b/src/nmtui/nmtui.c @@ -26,6 +26,7 @@ #include "nmtui-edit.h" #include "nmtui-connect.h" #include "nmtui-hostname.h" +#include "nmtui-radio.h" NMClient *nm_client; static GMainLoop *loop; @@ -39,7 +40,8 @@ static const struct { } subprograms[] = { {"edit", "nmtui-edit", N_("connection"), N_("Edit a connection"), nmtui_edit}, {"connect", "nmtui-connect", N_("connection"), N_("Activate a connection"), nmtui_connect}, - {"hostname", "nmtui-hostname", N_("new hostname"), N_("Set system hostname"), nmtui_hostname}}; + {"hostname", "nmtui-hostname", N_("new hostname"), N_("Set system hostname"), nmtui_hostname}, + {"radio", "nmtui-radio", N_("radio"), N_("Radio"), nmtui_radio}}; static const int num_subprograms = G_N_ELEMENTS(subprograms); static NmtNewtForm *toplevel_form; |