2012-12-09 19:38:32 -05:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License Version 2
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2016-04-29 16:05:54 +02:00
|
|
|
#include <arpa/inet.h>
|
2012-12-09 19:38:32 -05:00
|
|
|
#include <glib/gi18n.h>
|
2016-04-29 16:05:54 +02:00
|
|
|
#include <NetworkManager.h>
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
#include "ce-ip-address-entry.h"
|
2020-12-02 11:22:32 +13:00
|
|
|
#include "ce-netmask-entry.h"
|
2019-11-06 17:16:54 +13:00
|
|
|
#include "ce-page.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
#include "ce-page-ip4.h"
|
2014-08-07 18:32:34 +02:00
|
|
|
#include "ui-helpers.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
static void ensure_empty_address_row (CEPageIP4 *self);
|
|
|
|
static void ensure_empty_routes_row (CEPageIP4 *self);
|
2017-05-23 13:04:52 -03:00
|
|
|
|
2019-11-06 14:00:07 +13:00
|
|
|
struct _CEPageIP4
|
|
|
|
{
|
2021-11-29 10:37:01 -03:00
|
|
|
AdwBin parent;
|
2019-11-06 14:00:07 +13:00
|
|
|
|
2022-05-10 10:43:50 +02:00
|
|
|
GtkLabel *address_address_label;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkBox *address_box;
|
2022-05-10 10:43:50 +02:00
|
|
|
GtkLabel *address_gateway_label;
|
|
|
|
GtkLabel *address_netmask_label;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkSizeGroup *address_sizegroup;
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
GtkLabel *auto_dns_label;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkSwitch *auto_dns_switch;
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
GtkLabel *auto_routes_label;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkSwitch *auto_routes_switch;
|
|
|
|
GtkBox *content_box;
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
GtkBox *dns_box;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkEntry *dns_entry;
|
2019-12-12 16:20:57 +01:00
|
|
|
GtkGrid *main_box;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkCheckButton *never_default_check;
|
2022-05-10 10:43:50 +02:00
|
|
|
GtkBox *routes_box;
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
GtkBox *route_config_box;
|
2023-10-18 22:20:46 +02:00
|
|
|
GtkLabel *routes_address_label;
|
2022-04-29 11:28:11 +02:00
|
|
|
GtkLabel *routes_gateway_label;
|
2023-10-18 22:20:46 +02:00
|
|
|
GtkLabel *routes_netmask_label;
|
2022-04-29 11:28:11 +02:00
|
|
|
GtkLabel *routes_metric_label;
|
2023-10-18 22:20:46 +02:00
|
|
|
GtkSizeGroup *routes_address_sizegroup;
|
|
|
|
GtkSizeGroup *routes_gateway_sizegroup;
|
|
|
|
GtkSizeGroup *routes_netmask_sizegroup;
|
2019-11-06 14:55:12 +13:00
|
|
|
GtkSizeGroup *routes_metric_sizegroup;
|
|
|
|
GtkSizeGroup *routes_sizegroup;
|
2019-11-06 14:00:07 +13:00
|
|
|
|
|
|
|
NMSettingIPConfig *setting;
|
|
|
|
|
|
|
|
GtkWidget *address_list;
|
|
|
|
GtkWidget *routes_list;
|
2022-12-12 17:44:51 +01:00
|
|
|
|
|
|
|
GActionGroup *method_group;
|
2019-11-06 14:00:07 +13:00
|
|
|
};
|
|
|
|
|
2019-11-06 17:07:42 +13:00
|
|
|
static void ce_page_iface_init (CEPageInterface *);
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (CEPageIP4, ce_page_ip4, ADW_TYPE_BIN,
|
2019-11-06 17:07:42 +13:00
|
|
|
G_IMPLEMENT_INTERFACE (ce_page_get_type (), ce_page_iface_init))
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
enum {
|
|
|
|
METHOD_COL_NAME,
|
|
|
|
METHOD_COL_METHOD
|
|
|
|
};
|
|
|
|
|
2023-10-06 13:37:08 -05:00
|
|
|
static void
|
|
|
|
sync_dns_entry_warning (CEPageIP4 *self)
|
|
|
|
{
|
|
|
|
g_autoptr(GVariant) method_variant = NULL;
|
|
|
|
const gchar *method;
|
|
|
|
|
|
|
|
method_variant = g_action_group_get_action_state (self->method_group, "ip4method");
|
|
|
|
method = g_variant_get_string (method_variant, NULL);
|
|
|
|
|
|
|
|
if (gtk_entry_get_text_length (self->dns_entry) &&
|
|
|
|
gtk_switch_get_active (self->auto_dns_switch) &&
|
|
|
|
g_strcmp0 (method, "automatic") == 0) {
|
|
|
|
gtk_entry_set_icon_from_icon_name (self->dns_entry, GTK_ENTRY_ICON_SECONDARY, "dialog-warning-symbolic");
|
|
|
|
gtk_entry_set_icon_tooltip_text (self->dns_entry, GTK_ENTRY_ICON_SECONDARY, _("Automatic DNS is enabled. Did you intend to disable Automatic DNS?"));
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self->dns_entry), "warning");
|
|
|
|
} else {
|
|
|
|
gtk_entry_set_icon_from_icon_name (self->dns_entry, GTK_ENTRY_ICON_SECONDARY, NULL);
|
|
|
|
gtk_entry_set_icon_tooltip_text (self->dns_entry, GTK_ENTRY_ICON_SECONDARY, NULL);
|
|
|
|
gtk_widget_remove_css_class (GTK_WIDGET (self->dns_entry), "warning");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
method_changed (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
gboolean addr_enabled;
|
|
|
|
gboolean dns_enabled;
|
|
|
|
gboolean routes_enabled;
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gboolean auto_enabled;
|
2022-12-12 17:44:51 +01:00
|
|
|
g_autoptr(GVariant) method_variant = NULL;
|
|
|
|
const gchar *method;
|
|
|
|
|
|
|
|
method_variant = g_action_group_get_action_state (self->method_group, "ip4method");
|
|
|
|
method = g_variant_get_string (method_variant, NULL);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2022-12-12 17:44:51 +01:00
|
|
|
if (g_str_equal (method, "disabled") ||
|
|
|
|
g_str_equal (method, "shared")) {
|
2012-12-09 19:38:32 -05:00
|
|
|
addr_enabled = FALSE;
|
|
|
|
dns_enabled = FALSE;
|
|
|
|
routes_enabled = FALSE;
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
auto_enabled = FALSE;
|
2017-05-23 01:56:08 -03:00
|
|
|
} else {
|
2022-12-12 17:44:51 +01:00
|
|
|
addr_enabled = g_str_equal (method, "manual");
|
2023-10-06 11:49:23 -05:00
|
|
|
dns_enabled = !g_str_equal (method, "local");
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
routes_enabled = !g_str_equal (method, "local");
|
|
|
|
auto_enabled = g_str_equal (method, "automatic");
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->address_box), addr_enabled);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->dns_box), dns_enabled);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->routes_box), routes_enabled);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->auto_dns_label), auto_enabled);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->auto_dns_switch), auto_enabled);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->auto_routes_label), auto_enabled);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->auto_routes_switch), auto_enabled);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2023-10-06 13:37:08 -05:00
|
|
|
sync_dns_entry_warning (self);
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
ce_page_changed (CE_PAGE (self));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
update_row_sensitivity (CEPageIP4 *self, GtkWidget *list)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child;
|
2017-05-23 13:04:52 -03:00
|
|
|
gint rows = 0, i = 0;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (list));
|
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child)) {
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *button;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
button = GTK_WIDGET (g_object_get_data (G_OBJECT (child), "delete-button"));
|
2012-12-09 19:38:32 -05:00
|
|
|
if (button != NULL)
|
|
|
|
rows++;
|
|
|
|
}
|
2021-11-29 10:37:01 -03:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (list));
|
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child)) {
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *button;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
button = GTK_WIDGET (g_object_get_data (G_OBJECT (child), "delete-button"));
|
2012-12-09 19:38:32 -05:00
|
|
|
if (button != NULL)
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 16:57:10 +02:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
update_row_gateway_sensitivity (CEPageIP4 *self)
|
2016-09-16 16:57:10 +02:00
|
|
|
{
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child;
|
2016-09-16 16:57:10 +02:00
|
|
|
gint rows = 0;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
for (child = gtk_widget_get_first_child (self->address_list);
|
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child)) {
|
2017-05-23 15:02:45 -03:00
|
|
|
GtkWidget *entry;
|
2016-09-16 16:57:10 +02:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
entry = GTK_WIDGET (g_object_get_data (G_OBJECT (child), "gateway"));
|
2016-09-16 16:57:10 +02:00
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_widget_set_sensitive (entry, (rows == 0));
|
2016-09-16 16:57:10 +02:00
|
|
|
|
|
|
|
rows++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
2020-06-20 23:52:19 +02:00
|
|
|
remove_row (CEPageIP4 *self, GtkButton *button)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
GtkWidget *list;
|
2013-06-21 20:03:53 +02:00
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *row_box;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-06-20 23:52:19 +02:00
|
|
|
row_box = gtk_widget_get_parent (GTK_WIDGET (button));
|
2013-06-21 20:03:53 +02:00
|
|
|
row = gtk_widget_get_parent (row_box);
|
2012-12-09 19:38:32 -05:00
|
|
|
list = gtk_widget_get_parent (row);
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_list_box_remove (GTK_LIST_BOX (list), row);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
ce_page_changed (CE_PAGE (self));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
update_row_sensitivity (self, list);
|
|
|
|
if (list == self->address_list)
|
|
|
|
update_row_gateway_sensitivity (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
static gboolean
|
|
|
|
validate_row (GtkWidget *row)
|
|
|
|
{
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child;
|
2017-05-23 13:04:52 -03:00
|
|
|
GtkWidget *box;
|
|
|
|
gboolean valid;
|
|
|
|
|
|
|
|
valid = FALSE;
|
2021-11-29 10:37:01 -03:00
|
|
|
box = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (row));
|
2017-05-23 13:04:52 -03:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
for (child = gtk_widget_get_first_child (box);
|
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child)) {
|
|
|
|
if (!GTK_IS_ENTRY (child))
|
2017-05-23 13:04:52 -03:00
|
|
|
continue;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
valid = valid || gtk_entry_get_text_length (GTK_ENTRY (child)) > 0;
|
2017-05-23 13:04:52 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
add_address_row (CEPageIP4 *self,
|
2012-12-09 19:38:32 -05:00
|
|
|
const gchar *address,
|
|
|
|
const gchar *network,
|
|
|
|
const gchar *gateway)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
2017-05-23 15:02:45 -03:00
|
|
|
GtkWidget *row_box;
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *delete_button;
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
row = gtk_list_box_row_new ();
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
|
2013-06-21 20:03:53 +02:00
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_widget_add_css_class (row_box, "linked");
|
2017-05-23 15:02:45 -03:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), address);
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
2022-05-10 10:43:50 +02:00
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->address_address_label, NULL,
|
2022-04-29 11:28:11 +02:00
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
widget = GTK_WIDGET (ce_netmask_entry_new ());
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
2020-12-02 11:22:32 +13:00
|
|
|
g_object_set_data (G_OBJECT (row), "netmask", widget);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), network);
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
2022-05-10 10:43:50 +02:00
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->address_netmask_label, NULL,
|
2022-04-29 11:28:11 +02:00
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), gateway ? gateway : "");
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
2022-05-10 10:43:50 +02:00
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->address_gateway_label, NULL,
|
2022-04-29 11:28:11 +02:00
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2016-09-16 16:57:10 +02:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
delete_button = gtk_button_new_from_icon_name ("edit-delete-symbolic");
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_widget_set_sensitive (delete_button, FALSE);
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (delete_button, "clicked", G_CALLBACK (remove_row), self, G_CONNECT_SWAPPED);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (delete_button),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, _("Delete Address"),
|
|
|
|
-1);
|
|
|
|
gtk_box_append (GTK_BOX (row_box), delete_button);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_size_group_add_widget (self->address_sizegroup, delete_button);
|
2013-06-21 20:03:53 +02:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), row_box);
|
|
|
|
gtk_list_box_append (GTK_LIST_BOX (self->address_list), row);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
update_row_gateway_sensitivity (self);
|
|
|
|
update_row_sensitivity (self, self->address_list);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
ensure_empty_address_row (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child = gtk_widget_get_last_child (self->address_list);
|
2017-05-23 15:02:45 -03:00
|
|
|
|
|
|
|
/* Add the last, stub row if needed*/
|
2021-11-29 10:37:01 -03:00
|
|
|
if (!child || validate_row (child))
|
2019-10-18 11:47:17 +13:00
|
|
|
add_address_row (self, "", "", "");
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
add_address_box (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
GtkWidget *list;
|
|
|
|
gint i;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
self->address_list = list = gtk_list_box_new ();
|
2013-06-21 20:03:53 +02:00
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (self->address_box, list);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
for (i = 0; i < nm_setting_ip_config_get_num_addresses (self->setting); i++) {
|
2016-04-29 16:05:54 +02:00
|
|
|
NMIPAddress *addr;
|
2012-12-09 19:38:32 -05:00
|
|
|
struct in_addr tmp_addr;
|
|
|
|
gchar network[INET_ADDRSTRLEN + 1];
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
addr = nm_setting_ip_config_get_address (self->setting, i);
|
2012-12-09 19:38:32 -05:00
|
|
|
if (!addr)
|
|
|
|
continue;
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_address_get_prefix (addr));
|
2012-12-09 19:38:32 -05:00
|
|
|
(void) inet_ntop (AF_INET, &tmp_addr, &network[0], sizeof (network));
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
add_address_row (self,
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_ip_address_get_address (addr),
|
|
|
|
network,
|
2019-10-18 11:47:17 +13:00
|
|
|
i == 0 ? nm_setting_ip_config_get_gateway (self->setting) : "");
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2019-10-18 11:47:17 +13:00
|
|
|
if (nm_setting_ip_config_get_num_addresses (self->setting) == 0)
|
|
|
|
ensure_empty_address_row (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
add_dns_section (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2017-05-23 02:44:58 -03:00
|
|
|
GString *string;
|
2012-12-09 19:38:32 -05:00
|
|
|
gint i;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_switch_set_active (self->auto_dns_switch, !nm_setting_ip_config_get_ignore_auto_dns (self->setting));
|
2023-10-06 11:49:23 -05:00
|
|
|
g_signal_connect_object (self->auto_dns_switch, "notify::active", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2023-10-06 13:37:08 -05:00
|
|
|
g_signal_connect_object (self->auto_dns_switch, "notify::active", G_CALLBACK (sync_dns_entry_warning), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
string = g_string_new ("");
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
for (i = 0; i < nm_setting_ip_config_get_num_dns (self->setting); i++) {
|
2016-04-29 16:05:54 +02:00
|
|
|
const char *address;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
address = nm_setting_ip_config_get_dns (self->setting, i);
|
2017-05-23 02:44:58 -03:00
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
g_string_append (string, ", ");
|
|
|
|
|
|
|
|
g_string_append (string, address);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->dns_entry), string->str);
|
2017-05-23 02:44:58 -03:00
|
|
|
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->dns_entry, "notify::text", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2023-10-06 13:37:08 -05:00
|
|
|
g_signal_connect_object (self->dns_entry, "notify::text", G_CALLBACK (sync_dns_entry_warning), self, G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
sync_dns_entry_warning (self);
|
2017-05-23 02:44:58 -03:00
|
|
|
|
|
|
|
g_string_free (string, TRUE);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
add_route_row (CEPageIP4 *self,
|
2012-12-09 19:38:32 -05:00
|
|
|
const gchar *address,
|
|
|
|
const gchar *netmask,
|
|
|
|
const gchar *gateway,
|
|
|
|
gint metric)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
2017-05-23 13:04:52 -03:00
|
|
|
GtkWidget *row_box;
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *delete_button;
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
row = gtk_list_box_row_new ();
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
|
2013-06-21 20:03:53 +02:00
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_widget_add_css_class (row_box, "linked");
|
2017-05-23 13:04:52 -03:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), address);
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->routes_address_label, NULL,
|
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2023-10-18 22:20:46 +02:00
|
|
|
gtk_size_group_add_widget (self->routes_address_sizegroup, widget);
|
|
|
|
|
2021-03-06 22:07:29 +01:00
|
|
|
widget = GTK_WIDGET (ce_netmask_entry_new ());
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "netmask", widget);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), netmask);
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->routes_netmask_label, NULL,
|
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2023-10-18 22:20:46 +02:00
|
|
|
gtk_size_group_add_widget (self->routes_netmask_sizegroup, widget);
|
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), gateway ? gateway : "");
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->routes_gateway_label, NULL,
|
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2023-10-18 22:20:46 +02:00
|
|
|
gtk_size_group_add_widget (self->routes_gateway_sizegroup, widget);
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "metric", widget);
|
2016-04-29 16:05:54 +02:00
|
|
|
if (metric >= 0) {
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *s = g_strdup_printf ("%d", metric);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), s);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (widget), 5);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->routes_metric_label, NULL,
|
|
|
|
-1);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), widget);
|
2017-05-23 13:04:52 -03:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_size_group_add_widget (self->routes_metric_sizegroup, widget);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
delete_button = gtk_button_new_from_icon_name ("edit-delete-symbolic");
|
|
|
|
gtk_widget_set_sensitive (delete_button, FALSE);
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (delete_button, "clicked", G_CALLBACK (remove_row), self, G_CONNECT_SWAPPED);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (delete_button),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, _("Delete Route"),
|
|
|
|
-1);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row_box), delete_button);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_size_group_add_widget (self->routes_sizegroup, delete_button);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), row_box);
|
|
|
|
gtk_list_box_append (GTK_LIST_BOX (self->routes_list), row);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
update_row_sensitivity (self, self->routes_list);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
ensure_empty_routes_row (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child = gtk_widget_get_last_child (self->routes_list);
|
2017-05-23 13:04:52 -03:00
|
|
|
|
|
|
|
/* Add the last, stub row if needed*/
|
2021-11-29 10:37:01 -03:00
|
|
|
if (!child || validate_row (child))
|
2019-10-18 11:47:17 +13:00
|
|
|
add_route_row (self, "", "", "", -1);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
add_route_config_box (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
GtkWidget *list;
|
|
|
|
gint i;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
self->routes_list = list = gtk_list_box_new ();
|
2013-06-21 20:03:53 +02:00
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gtk_box_append (GTK_BOX (self->route_config_box), list);
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_switch_set_active (self->auto_routes_switch, !nm_setting_ip_config_get_ignore_auto_routes (self->setting));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->auto_routes_switch, "notify::active", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
for (i = 0; i < nm_setting_ip_config_get_num_routes (self->setting); i++) {
|
2016-04-29 16:05:54 +02:00
|
|
|
NMIPRoute *route;
|
2012-12-09 19:38:32 -05:00
|
|
|
struct in_addr tmp_addr;
|
|
|
|
gchar netmask[INET_ADDRSTRLEN + 1];
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
route = nm_setting_ip_config_get_route (self->setting, i);
|
2012-12-09 19:38:32 -05:00
|
|
|
if (!route)
|
|
|
|
continue;
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route));
|
2012-12-09 19:38:32 -05:00
|
|
|
(void) inet_ntop (AF_INET, &tmp_addr, &netmask[0], sizeof (netmask));
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
add_route_row (self,
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_ip_route_get_dest (route),
|
|
|
|
netmask,
|
|
|
|
nm_ip_route_get_next_hop (route),
|
|
|
|
nm_ip_route_get_metric (route));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2019-10-18 11:47:17 +13:00
|
|
|
if (nm_setting_ip_config_get_num_routes (self->setting) == 0)
|
|
|
|
ensure_empty_routes_row (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
connect_ip4_page (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
const gchar *str_method;
|
2022-12-12 17:44:51 +01:00
|
|
|
gchar *method;
|
2019-10-15 12:25:48 +13:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
add_address_box (self);
|
|
|
|
add_dns_section (self);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
add_route_config_box (self);
|
2019-10-18 11:47:17 +13:00
|
|
|
|
|
|
|
str_method = nm_setting_ip_config_get_method (self->setting);
|
2018-07-11 19:36:54 +01:00
|
|
|
|
2022-12-12 17:44:51 +01:00
|
|
|
method = "automatic";
|
2012-12-09 19:38:32 -05:00
|
|
|
if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0) {
|
2022-12-12 17:44:51 +01:00
|
|
|
method = "local";
|
2012-12-09 19:38:32 -05:00
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) {
|
2022-12-12 17:44:51 +01:00
|
|
|
method = "manual";
|
2012-12-09 19:38:32 -05:00
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
|
2022-12-12 17:44:51 +01:00
|
|
|
method = "shared";
|
2012-12-09 19:38:32 -05:00
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) {
|
2022-12-12 17:44:51 +01:00
|
|
|
method = "disabled";
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (self->never_default_check),
|
|
|
|
nm_setting_ip_config_get_never_default (self->setting));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->never_default_check, "toggled", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2017-05-23 01:56:08 -03:00
|
|
|
|
2022-12-12 17:44:51 +01:00
|
|
|
g_action_group_change_action_state (self->method_group, "ip4method", g_variant_new_string (method));
|
2017-05-23 01:56:08 -03:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
method_changed (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-10-18 11:47:17 +13:00
|
|
|
ui_to_setting (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
const gchar *method;
|
2022-12-12 17:44:51 +01:00
|
|
|
g_autoptr(GVariant) method_variant = NULL;
|
2012-12-09 19:38:32 -05:00
|
|
|
gboolean ignore_auto_dns;
|
|
|
|
gboolean ignore_auto_routes;
|
|
|
|
gboolean never_default;
|
|
|
|
GPtrArray *addresses = NULL;
|
2016-04-29 16:05:54 +02:00
|
|
|
GPtrArray *dns_servers = NULL;
|
2012-12-09 19:38:32 -05:00
|
|
|
GPtrArray *routes = NULL;
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child;
|
2017-05-23 02:44:58 -03:00
|
|
|
GStrv dns_addresses = NULL;
|
2014-08-13 13:46:03 +02:00
|
|
|
gboolean ret = TRUE;
|
2016-09-16 17:01:36 +02:00
|
|
|
const char *default_gateway = NULL;
|
2021-11-29 10:37:01 -03:00
|
|
|
gboolean add_addresses = FALSE;
|
|
|
|
gboolean add_routes = FALSE;
|
2017-05-23 02:44:58 -03:00
|
|
|
gchar *dns_text = NULL;
|
|
|
|
guint i;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2022-12-12 17:44:51 +01:00
|
|
|
method_variant = g_action_group_get_action_state (self->method_group, "ip4method");
|
|
|
|
method = g_variant_get_string (method_variant, NULL);
|
|
|
|
if (g_str_equal (method, "disabled"))
|
2012-12-09 19:38:32 -05:00
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
|
2022-12-12 17:44:51 +01:00
|
|
|
else if (g_str_equal (method, "automatic"))
|
2018-07-20 11:26:05 +01:00
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
2022-12-12 17:44:51 +01:00
|
|
|
else if (g_str_equal (method, "local"))
|
2018-07-20 11:26:05 +01:00
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL;
|
2022-12-12 17:44:51 +01:00
|
|
|
else if (g_str_equal (method, "manual"))
|
2018-07-20 11:26:05 +01:00
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
|
2022-12-12 17:44:51 +01:00
|
|
|
else if (g_str_equal (method, "shared"))
|
2018-07-11 19:36:54 +01:00
|
|
|
method = NM_SETTING_IP4_CONFIG_METHOD_SHARED;
|
2022-12-12 17:44:51 +01:00
|
|
|
else
|
|
|
|
g_assert_not_reached ();
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-09-16 16:51:14 +02:00
|
|
|
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
|
2021-11-29 10:37:01 -03:00
|
|
|
add_addresses = g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
|
2014-08-13 18:26:19 +02:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
for (child = gtk_widget_get_first_child (self->address_list);
|
|
|
|
add_addresses && child;
|
|
|
|
child = gtk_widget_get_next_sibling (child)) {
|
|
|
|
GtkWidget *row = child;
|
2020-12-02 11:11:02 +13:00
|
|
|
CEIPAddressEntry *address_entry;
|
2020-12-02 11:22:32 +13:00
|
|
|
CENetmaskEntry *netmask_entry;
|
2020-12-02 11:11:02 +13:00
|
|
|
CEIPAddressEntry *gateway_entry;
|
2016-04-29 16:05:54 +02:00
|
|
|
NMIPAddress *addr;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
address_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
|
|
|
if (!address_entry)
|
2012-12-09 19:38:32 -05:00
|
|
|
continue;
|
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
netmask_entry = CE_NETMASK_ENTRY (g_object_get_data (G_OBJECT (row), "netmask"));
|
2020-12-02 11:11:02 +13:00
|
|
|
gateway_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
if (ce_ip_address_entry_is_empty (address_entry) && ce_netmask_entry_is_empty (netmask_entry) && ce_ip_address_entry_is_empty (gateway_entry)) {
|
2012-12-09 19:38:32 -05:00
|
|
|
/* ignore empty rows */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
if (!ce_ip_address_entry_is_valid (address_entry))
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
if (!ce_netmask_entry_is_valid (netmask_entry))
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
if (!ce_ip_address_entry_is_valid (gateway_entry)) {
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
2020-12-02 11:11:02 +13:00
|
|
|
if (!ce_ip_address_entry_is_empty (gateway_entry)) {
|
2016-09-16 17:01:36 +02:00
|
|
|
g_assert (default_gateway == NULL);
|
2021-11-29 10:37:01 -03:00
|
|
|
default_gateway = gtk_editable_get_text (GTK_EDITABLE (gateway_entry));
|
2016-09-16 17:01:36 +02:00
|
|
|
}
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2014-08-13 13:46:03 +02:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
continue;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
addr = nm_ip_address_new (AF_INET, gtk_editable_get_text (GTK_EDITABLE (address_entry)), ce_netmask_entry_get_prefix (netmask_entry), NULL);
|
2016-04-29 16:05:54 +02:00
|
|
|
if (addr)
|
|
|
|
g_ptr_array_add (addresses, addr);
|
2017-05-23 15:02:45 -03:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
if (!gtk_widget_get_next_sibling (row))
|
2019-10-18 11:47:17 +13:00
|
|
|
ensure_empty_address_row (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (addresses->len == 0) {
|
|
|
|
g_ptr_array_free (addresses, TRUE);
|
|
|
|
addresses = NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
dns_servers = g_ptr_array_new_with_free_func (g_free);
|
2021-11-29 10:37:01 -03:00
|
|
|
dns_text = g_strstrip (g_strdup (gtk_editable_get_text (GTK_EDITABLE (self->dns_entry))));
|
2023-10-06 11:49:23 -05:00
|
|
|
if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) ||
|
|
|
|
g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
2017-05-23 02:44:58 -03:00
|
|
|
dns_addresses = g_strsplit_set (dns_text, ", ", -1);
|
2014-08-13 18:26:19 +02:00
|
|
|
else
|
2017-05-23 02:44:58 -03:00
|
|
|
dns_addresses = NULL;
|
2014-08-13 18:26:19 +02:00
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
for (i = 0; dns_addresses && dns_addresses[i]; i++) {
|
2012-12-09 19:38:32 -05:00
|
|
|
const gchar *text;
|
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
text = dns_addresses[i];
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
if (!text || !*text)
|
2012-12-09 19:38:32 -05:00
|
|
|
continue;
|
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
if (!nm_utils_ipaddr_valid (AF_INET, text)) {
|
|
|
|
g_ptr_array_remove_range (dns_servers, 0, dns_servers->len);
|
2019-10-18 11:47:17 +13:00
|
|
|
widget_set_error (GTK_WIDGET (self->dns_entry));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2017-05-23 02:44:58 -03:00
|
|
|
break;
|
2014-08-13 13:46:03 +02:00
|
|
|
} else {
|
2019-10-18 11:47:17 +13:00
|
|
|
widget_unset_error (GTK_WIDGET (self->dns_entry));
|
2016-04-29 16:05:54 +02:00
|
|
|
g_ptr_array_add (dns_servers, g_strdup (text));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
}
|
2017-05-23 02:44:58 -03:00
|
|
|
g_clear_pointer (&dns_addresses, g_strfreev);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2023-10-06 13:31:43 -05:00
|
|
|
if (dns_text[0] == '\0')
|
|
|
|
widget_unset_error (GTK_WIDGET (self->dns_entry));
|
|
|
|
|
2016-09-13 11:45:20 +02:00
|
|
|
if (dns_servers->len == 0) {
|
|
|
|
g_ptr_array_free (dns_servers, TRUE);
|
|
|
|
dns_servers = NULL;
|
|
|
|
} else {
|
|
|
|
g_ptr_array_add (dns_servers, NULL);
|
|
|
|
}
|
|
|
|
|
2016-09-16 16:51:14 +02:00
|
|
|
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
|
2021-11-29 10:37:01 -03:00
|
|
|
add_routes = g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) ||
|
|
|
|
g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
|
2014-08-13 18:26:19 +02:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
for (child = gtk_widget_get_first_child (self->routes_list);
|
|
|
|
add_routes && child;
|
|
|
|
child = gtk_widget_get_next_sibling (child)) {
|
|
|
|
GtkWidget *row = child;
|
2020-12-02 11:11:02 +13:00
|
|
|
CEIPAddressEntry *address_entry;
|
2020-12-02 11:22:32 +13:00
|
|
|
CENetmaskEntry *netmask_entry;
|
2020-12-02 11:11:02 +13:00
|
|
|
CEIPAddressEntry *gateway_entry;
|
2012-12-09 19:38:32 -05:00
|
|
|
const gchar *text_metric;
|
2016-04-29 16:05:54 +02:00
|
|
|
gint64 metric;
|
|
|
|
NMIPRoute *route;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
address_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
|
|
|
if (!address_entry)
|
2012-12-09 19:38:32 -05:00
|
|
|
continue;
|
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
netmask_entry = CE_NETMASK_ENTRY (g_object_get_data (G_OBJECT (row), "netmask"));
|
2020-12-02 11:11:02 +13:00
|
|
|
gateway_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"));
|
2021-11-29 10:37:01 -03:00
|
|
|
text_metric = gtk_editable_get_text (GTK_EDITABLE (g_object_get_data (G_OBJECT (row), "metric")));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
if (ce_ip_address_entry_is_empty (address_entry) && ce_netmask_entry_is_empty (netmask_entry) && ce_ip_address_entry_is_empty (gateway_entry) && !*text_metric) {
|
2012-12-09 19:38:32 -05:00
|
|
|
/* ignore empty rows */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
if (!ce_ip_address_entry_is_valid (address_entry))
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:22:32 +13:00
|
|
|
if (!ce_netmask_entry_is_valid (netmask_entry))
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2020-12-02 11:11:02 +13:00
|
|
|
if (!ce_ip_address_entry_is_valid (gateway_entry))
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
metric = -1;
|
2012-12-09 19:38:32 -05:00
|
|
|
if (*text_metric) {
|
|
|
|
errno = 0;
|
2016-04-29 16:05:54 +02:00
|
|
|
metric = g_ascii_strtoull (text_metric, NULL, 10);
|
|
|
|
if (errno || metric < 0 || metric > G_MAXUINT32) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric")));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric")));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2014-08-13 13:46:03 +02:00
|
|
|
} else {
|
|
|
|
widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric")));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2014-08-13 13:46:03 +02:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
continue;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
route = nm_ip_route_new (AF_INET,
|
|
|
|
gtk_editable_get_text (GTK_EDITABLE (address_entry)),
|
|
|
|
ce_netmask_entry_get_prefix (netmask_entry),
|
|
|
|
gtk_editable_get_text (GTK_EDITABLE (gateway_entry)),
|
|
|
|
metric, NULL);
|
2016-04-29 16:05:54 +02:00
|
|
|
if (route)
|
|
|
|
g_ptr_array_add (routes, route);
|
2017-05-23 13:04:52 -03:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
if (!gtk_widget_get_next_sibling (row))
|
2019-10-18 11:47:17 +13:00
|
|
|
ensure_empty_routes_row (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (routes->len == 0) {
|
|
|
|
g_ptr_array_free (routes, TRUE);
|
|
|
|
routes = NULL;
|
|
|
|
}
|
2014-08-13 13:46:03 +02:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
goto out;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
ignore_auto_dns = !gtk_switch_get_active (self->auto_dns_switch);
|
|
|
|
ignore_auto_routes = !gtk_switch_get_active (self->auto_routes_switch);
|
2021-11-29 10:37:01 -03:00
|
|
|
never_default = gtk_check_button_get_active (GTK_CHECK_BUTTON (self->never_default_check));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
g_object_set (self->setting,
|
2016-04-29 16:05:54 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, method,
|
|
|
|
NM_SETTING_IP_CONFIG_ADDRESSES, addresses,
|
2016-09-16 17:01:36 +02:00
|
|
|
NM_SETTING_IP_CONFIG_GATEWAY, default_gateway,
|
2016-09-13 11:45:20 +02:00
|
|
|
NM_SETTING_IP_CONFIG_DNS, dns_servers ? dns_servers->pdata : NULL,
|
2016-04-29 16:05:54 +02:00
|
|
|
NM_SETTING_IP_CONFIG_ROUTES, routes,
|
|
|
|
NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
|
|
|
|
NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes,
|
|
|
|
NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
|
2012-12-09 19:38:32 -05:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (addresses)
|
|
|
|
g_ptr_array_free (addresses, TRUE);
|
|
|
|
|
|
|
|
if (dns_servers)
|
2016-04-29 16:05:54 +02:00
|
|
|
g_ptr_array_free (dns_servers, TRUE);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
if (routes)
|
|
|
|
g_ptr_array_free (routes, TRUE);
|
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
g_clear_pointer (&dns_text, g_free);
|
|
|
|
|
2014-08-13 13:46:03 +02:00
|
|
|
return ret;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2022-12-12 17:44:51 +01:00
|
|
|
static void
|
|
|
|
on_ip4_method_activated_cb (GSimpleAction* action,
|
|
|
|
GVariant* parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
CEPageIP4 *self = CE_PAGE_IP4 (user_data);
|
|
|
|
g_simple_action_set_state (action, parameter);
|
|
|
|
|
|
|
|
method_changed (self);
|
|
|
|
}
|
|
|
|
|
2019-11-06 13:38:36 +13:00
|
|
|
static const gchar *
|
|
|
|
ce_page_ip4_get_title (CEPage *page)
|
|
|
|
{
|
|
|
|
return _("IPv4");
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static gboolean
|
2019-11-06 16:33:07 +13:00
|
|
|
ce_page_ip4_validate (CEPage *self,
|
|
|
|
NMConnection *connection,
|
|
|
|
GError **error)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
if (!ui_to_setting (CE_PAGE_IP4 (self)))
|
2012-12-09 19:38:32 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
return nm_setting_verify (NM_SETTING (CE_PAGE_IP4 (self)->setting), NULL, error);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
ce_page_ip4_init (CEPageIP4 *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2022-12-12 17:44:51 +01:00
|
|
|
const GActionEntry ip4_entries[] = {
|
2023-10-05 20:43:06 +02:00
|
|
|
{ "ip4method", on_ip4_method_activated_cb, "s", "'automatic'", NULL, { 0 } },
|
2022-12-12 17:44:51 +01:00
|
|
|
};
|
|
|
|
self->method_group = G_ACTION_GROUP (g_simple_action_group_new ());
|
|
|
|
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (self->method_group), ip4_entries, G_N_ELEMENTS (ip4_entries), self);
|
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (self), "ip4page", G_ACTION_GROUP (self->method_group));
|
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-06 17:16:54 +13:00
|
|
|
ce_page_ip4_class_init (CEPageIP4Class *klass)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-11-06 17:16:54 +13:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/ip4-page.ui");
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, address_box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, address_sizegroup);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, auto_dns_label);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, auto_dns_switch);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, auto_routes_label);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, auto_routes_switch);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, content_box);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, dns_box);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, dns_entry);
|
2019-12-12 16:20:57 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, main_box);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, never_default_check);
|
2022-05-10 10:43:50 +02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, address_address_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, address_netmask_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, address_gateway_label);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_box);
|
network: fix sensitivity of DNS and route configuration widgets
When the IP method is "disabled" or "shared" then everything else is
supposed to be insensitive. This currently fails if you toggle between
the two, because it's implemented using property bindings that are just
not smart enough to handle this task. Handle sensitivity only in
method_changed() to avoid this.
Additionally, not all of the widgets are being consistently
disabled/enabled when appropriate. E.g. when the method is "local" then
only the DNS entry, route entries, and default route checkboxes become
insensitive, leaving the other widgets, including notably the Automatic
switches, sensitive. They should all become insensitive, as when the
method is "disabled" or "shared." Fix this by organizing all the related
widgets into boxes and setting the sensitivity of the entire box. (Note
the strategy followed here does not exactly match nm-connection-editor,
which always allows editing addresses. We only allow that in Manual
mode. I'm not sure if this is advisable or not, so won't touch that.)
Finally, the Automatic DNS and Automatic Routes toggles should only be
sensitive when the method is "Automatic".
2023-10-13 14:03:43 -05:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, route_config_box);
|
2022-04-29 11:28:11 +02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_address_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_netmask_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_gateway_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_metric_label);
|
2023-10-18 22:20:46 +02:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_address_sizegroup);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_netmask_sizegroup);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_gateway_sizegroup);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_metric_sizegroup);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_sizegroup);
|
2019-11-06 17:07:42 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_page_iface_init (CEPageInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_title = ce_page_ip4_get_title;
|
|
|
|
iface->validate = ce_page_ip4_validate;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
CEPageIP4 *
|
2012-12-09 19:38:32 -05:00
|
|
|
ce_page_ip4_new (NMConnection *connection,
|
2016-04-29 16:05:54 +02:00
|
|
|
NMClient *client)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
CEPageIP4 *self;
|
2019-11-06 15:05:29 +13:00
|
|
|
|
2019-11-06 15:50:40 +13:00
|
|
|
self = CE_PAGE_IP4 (g_object_new (ce_page_ip4_get_type (), NULL));
|
2019-11-06 15:05:29 +13:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
self->setting = nm_connection_get_setting_ip4_config (connection);
|
|
|
|
if (!self->setting) {
|
|
|
|
self->setting = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (self->setting));
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
connect_ip4_page (self);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
return self;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|