network: Make CEIPAddressEntry
This commit is contained in:
parent
c9ea93f195
commit
c1a13ccaba
5 changed files with 186 additions and 98 deletions
99
panels/network/connection-editor/ce-ip-address-entry.c
Normal file
99
panels/network/connection-editor/ce-ip-address-entry.c
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 Canonical Ltd.
|
||||||
|
*
|
||||||
|
* 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 <NetworkManager.h>
|
||||||
|
|
||||||
|
#include "ce-ip-address-entry.h"
|
||||||
|
|
||||||
|
struct _CEIPAddressEntry
|
||||||
|
{
|
||||||
|
GtkEntry parent_instance;
|
||||||
|
|
||||||
|
int family;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void ce_ip_address_entry_editable_init (GtkEditableInterface *iface);
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (CEIPAddressEntry, ce_ip_address_entry, GTK_TYPE_ENTRY,
|
||||||
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
|
||||||
|
ce_ip_address_entry_editable_init))
|
||||||
|
|
||||||
|
static void
|
||||||
|
ce_ip_address_entry_changed (GtkEditable *editable)
|
||||||
|
{
|
||||||
|
CEIPAddressEntry *self = CE_IP_ADDRESS_ENTRY (editable);
|
||||||
|
GtkStyleContext *context;
|
||||||
|
|
||||||
|
context = gtk_widget_get_style_context (GTK_WIDGET (self));
|
||||||
|
if (ce_ip_address_entry_is_valid (self))
|
||||||
|
gtk_style_context_remove_class (context, "error");
|
||||||
|
else
|
||||||
|
gtk_style_context_add_class (context, "error");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ce_ip_address_entry_init (CEIPAddressEntry *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ce_ip_address_entry_editable_init (GtkEditableInterface *iface)
|
||||||
|
{
|
||||||
|
iface->changed = ce_ip_address_entry_changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ce_ip_address_entry_class_init (CEIPAddressEntryClass *klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CEIPAddressEntry *
|
||||||
|
ce_ip_address_entry_new (int family)
|
||||||
|
{
|
||||||
|
CEIPAddressEntry *self;
|
||||||
|
|
||||||
|
self = CE_IP_ADDRESS_ENTRY (g_object_new (ce_ip_address_entry_get_type (), NULL));
|
||||||
|
self->family = family;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ce_ip_address_entry_is_empty (CEIPAddressEntry *self)
|
||||||
|
{
|
||||||
|
const gchar *text;
|
||||||
|
|
||||||
|
g_return_val_if_fail (CE_IS_IP_ADDRESS_ENTRY (self), FALSE);
|
||||||
|
|
||||||
|
text = gtk_entry_get_text (GTK_ENTRY (self));
|
||||||
|
return text[0] == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ce_ip_address_entry_is_valid (CEIPAddressEntry *self)
|
||||||
|
{
|
||||||
|
const gchar *text;
|
||||||
|
|
||||||
|
g_return_val_if_fail (CE_IS_IP_ADDRESS_ENTRY (self), FALSE);
|
||||||
|
|
||||||
|
text = gtk_entry_get_text (GTK_ENTRY (self));
|
||||||
|
return text[0] == '\0' || nm_utils_ipaddr_valid (self->family, text);
|
||||||
|
}
|
36
panels/network/connection-editor/ce-ip-address-entry.h
Normal file
36
panels/network/connection-editor/ce-ip-address-entry.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 Canonical Ltd.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (CEIPAddressEntry, ce_ip_address_entry, CE, IP_ADDRESS_ENTRY, GtkEntry)
|
||||||
|
|
||||||
|
CEIPAddressEntry *ce_ip_address_entry_new (int family);
|
||||||
|
|
||||||
|
gboolean ce_ip_address_entry_is_empty (CEIPAddressEntry *entry);
|
||||||
|
|
||||||
|
gboolean ce_ip_address_entry_is_valid (CEIPAddressEntry *entry);
|
||||||
|
|
||||||
|
G_END_DECLS
|
|
@ -28,6 +28,7 @@
|
||||||
#include <NetworkManager.h>
|
#include <NetworkManager.h>
|
||||||
|
|
||||||
#include "list-box-helper.h"
|
#include "list-box-helper.h"
|
||||||
|
#include "ce-ip-address-entry.h"
|
||||||
#include "ce-page.h"
|
#include "ce-page.h"
|
||||||
#include "ce-page-ip4.h"
|
#include "ce-page-ip4.h"
|
||||||
#include "ui-helpers.h"
|
#include "ui-helpers.h"
|
||||||
|
@ -207,7 +208,7 @@ add_address_row (CEPageIP4 *self,
|
||||||
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "address", widget);
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
||||||
|
@ -225,7 +226,7 @@ add_address_row (CEPageIP4 *self,
|
||||||
gtk_widget_set_hexpand (widget, TRUE);
|
gtk_widget_set_hexpand (widget, TRUE);
|
||||||
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
||||||
|
@ -349,7 +350,7 @@ add_route_row (CEPageIP4 *self,
|
||||||
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "address", widget);
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
||||||
|
@ -367,7 +368,7 @@ add_route_row (CEPageIP4 *self,
|
||||||
gtk_widget_set_hexpand (widget, TRUE);
|
gtk_widget_set_hexpand (widget, TRUE);
|
||||||
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
||||||
|
@ -586,37 +587,27 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
|
|
||||||
for (GList *l = address_children; l; l = l->next) {
|
for (GList *l = address_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
CEIPAddressEntry *address_entry;
|
||||||
GtkEntry *gateway_entry;
|
CEIPAddressEntry *gateway_entry;
|
||||||
const gchar *text_address;
|
|
||||||
const gchar *text_netmask;
|
const gchar *text_netmask;
|
||||||
const gchar *text_gateway = "";
|
|
||||||
NMIPAddress *addr;
|
NMIPAddress *addr;
|
||||||
guint32 prefix;
|
guint32 prefix;
|
||||||
|
|
||||||
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
address_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
||||||
if (!entry)
|
if (!address_entry)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
text_address = gtk_entry_get_text (entry);
|
|
||||||
text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "network")));
|
text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "network")));
|
||||||
gateway_entry = g_object_get_data (G_OBJECT (row), "gateway");
|
gateway_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"));
|
||||||
text_gateway = gtk_entry_get_text (gateway_entry);
|
|
||||||
|
|
||||||
if (!*text_address && !*text_netmask && !*text_gateway) {
|
if (ce_ip_address_entry_is_empty (address_entry) && !*text_netmask && ce_ip_address_entry_is_empty (gateway_entry)) {
|
||||||
/* ignore empty rows */
|
/* ignore empty rows */
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "network"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "network"));
|
||||||
widget_unset_error (GTK_WIDGET (gateway_entry));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_utils_ipaddr_valid (AF_INET, text_address)) {
|
if (!ce_ip_address_entry_is_valid (address_entry))
|
||||||
widget_set_error (GTK_WIDGET (entry));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parse_netmask (text_netmask, &prefix)) {
|
if (!parse_netmask (text_netmask, &prefix)) {
|
||||||
widget_set_error (g_object_get_data (G_OBJECT (row), "network"));
|
widget_set_error (g_object_get_data (G_OBJECT (row), "network"));
|
||||||
|
@ -625,22 +616,19 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "network"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "network"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*text_gateway &&
|
if (!ce_ip_address_entry_is_valid (gateway_entry)) {
|
||||||
!nm_utils_ipaddr_valid (AF_INET, text_gateway)) {
|
|
||||||
widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
} else {
|
||||||
widget_unset_error (GTK_WIDGET (gateway_entry));
|
if (!ce_ip_address_entry_is_empty (gateway_entry)) {
|
||||||
if (*text_gateway) {
|
|
||||||
g_assert (default_gateway == NULL);
|
g_assert (default_gateway == NULL);
|
||||||
default_gateway = text_gateway;
|
default_gateway = gtk_entry_get_text (GTK_ENTRY (gateway_entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
addr = nm_ip_address_new (AF_INET, text_address, prefix, NULL);
|
addr = nm_ip_address_new (AF_INET, gtk_entry_get_text (GTK_ENTRY (address_entry)), prefix, NULL);
|
||||||
if (addr)
|
if (addr)
|
||||||
g_ptr_array_add (addresses, addr);
|
g_ptr_array_add (addresses, addr);
|
||||||
|
|
||||||
|
@ -695,35 +683,29 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
|
|
||||||
for (GList *l = routes_children; l; l = l->next) {
|
for (GList *l = routes_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
CEIPAddressEntry *address_entry;
|
||||||
const gchar *text_address;
|
CEIPAddressEntry *gateway_entry;
|
||||||
const gchar *text_netmask;
|
const gchar *text_netmask;
|
||||||
const gchar *text_gateway;
|
|
||||||
const gchar *text_metric;
|
const gchar *text_metric;
|
||||||
gint64 metric;
|
gint64 metric;
|
||||||
guint32 netmask;
|
guint32 netmask;
|
||||||
NMIPRoute *route;
|
NMIPRoute *route;
|
||||||
|
|
||||||
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
address_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
||||||
if (!entry)
|
if (!address_entry)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
text_address = gtk_entry_get_text (entry);
|
|
||||||
text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "netmask")));
|
text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "netmask")));
|
||||||
text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
|
gateway_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"));
|
||||||
text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric")));
|
text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric")));
|
||||||
|
|
||||||
if (!*text_address && !*text_netmask && !*text_gateway && !*text_metric) {
|
if (ce_ip_address_entry_is_empty (address_entry) && !*text_netmask && ce_ip_address_entry_is_empty (gateway_entry) && !*text_metric) {
|
||||||
/* ignore empty rows */
|
/* ignore empty rows */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text_address && !nm_utils_ipaddr_valid (AF_INET, text_address)) {
|
if (!ce_ip_address_entry_is_valid (address_entry))
|
||||||
widget_set_error (GTK_WIDGET (entry));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parse_netmask (text_netmask, &netmask)) {
|
if (!parse_netmask (text_netmask, &netmask)) {
|
||||||
widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask")));
|
widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask")));
|
||||||
|
@ -732,12 +714,8 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask")));
|
widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text_gateway && !nm_utils_ipaddr_valid (AF_INET, text_gateway)) {
|
if (!ce_ip_address_entry_is_valid (gateway_entry))
|
||||||
widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway")));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway")));
|
|
||||||
}
|
|
||||||
|
|
||||||
metric = -1;
|
metric = -1;
|
||||||
if (*text_metric) {
|
if (*text_metric) {
|
||||||
|
@ -756,7 +734,7 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
if (!ret)
|
if (!ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
route = nm_ip_route_new (AF_INET, text_address, netmask, text_gateway, metric, NULL);
|
route = nm_ip_route_new (AF_INET, gtk_entry_get_text (GTK_ENTRY (address_entry)), netmask, gtk_entry_get_text (GTK_ENTRY (gateway_entry)), metric, NULL);
|
||||||
if (route)
|
if (route)
|
||||||
g_ptr_array_add (routes, route);
|
g_ptr_array_add (routes, route);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <NetworkManager.h>
|
#include <NetworkManager.h>
|
||||||
|
|
||||||
#include "list-box-helper.h"
|
#include "list-box-helper.h"
|
||||||
|
#include "ce-ip-address-entry.h"
|
||||||
#include "ce-page.h"
|
#include "ce-page.h"
|
||||||
#include "ce-page-ip6.h"
|
#include "ce-page-ip6.h"
|
||||||
#include "ui-helpers.h"
|
#include "ui-helpers.h"
|
||||||
|
@ -189,7 +190,7 @@ add_address_row (CEPageIP6 *self,
|
||||||
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET6));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "address", widget);
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
||||||
|
@ -207,7 +208,7 @@ add_address_row (CEPageIP6 *self,
|
||||||
gtk_widget_set_hexpand (widget, TRUE);
|
gtk_widget_set_hexpand (widget, TRUE);
|
||||||
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET6));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_address_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
||||||
|
@ -323,7 +324,7 @@ add_route_row (CEPageIP6 *self,
|
||||||
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET6));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "address", widget);
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
||||||
|
@ -341,7 +342,7 @@ add_route_row (CEPageIP6 *self,
|
||||||
gtk_widget_set_hexpand (widget, TRUE);
|
gtk_widget_set_hexpand (widget, TRUE);
|
||||||
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
||||||
|
|
||||||
widget = gtk_entry_new ();
|
widget = GTK_WIDGET (ce_ip_address_entry_new (AF_INET6));
|
||||||
g_signal_connect_object (widget, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
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);
|
g_signal_connect_object (widget, "activate", G_CALLBACK (ensure_empty_routes_row), self, G_CONNECT_SWAPPED);
|
||||||
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
||||||
|
@ -545,37 +546,28 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
|
|
||||||
for (GList *l = address_children; l; l = l->next) {
|
for (GList *l = address_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
CEIPAddressEntry *address_entry;
|
||||||
const gchar *text_address;
|
CEIPAddressEntry *gateway_entry;
|
||||||
const gchar *text_prefix;
|
const gchar *text_prefix;
|
||||||
const gchar *text_gateway;
|
|
||||||
guint32 prefix;
|
guint32 prefix;
|
||||||
gchar *end;
|
gchar *end;
|
||||||
NMIPAddress *addr;
|
NMIPAddress *addr;
|
||||||
gboolean have_gateway = FALSE;
|
|
||||||
|
|
||||||
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
address_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
||||||
if (!entry)
|
if (!address_entry)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
text_address = gtk_entry_get_text (entry);
|
|
||||||
text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix")));
|
text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix")));
|
||||||
text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
|
gateway_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"));
|
||||||
|
|
||||||
if (!*text_address && !*text_prefix && !*text_gateway) {
|
if (ce_ip_address_entry_is_empty (address_entry) && !*text_prefix && ce_ip_address_entry_is_empty (gateway_entry)) {
|
||||||
/* ignore empty rows */
|
/* ignore empty rows */
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*text_address || !nm_utils_ipaddr_valid (AF_INET6, text_address)) {
|
if (!ce_ip_address_entry_is_valid (address_entry))
|
||||||
widget_set_error (GTK_WIDGET (entry));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix = strtoul (text_prefix, &end, 10);
|
prefix = strtoul (text_prefix, &end, 10);
|
||||||
if (!end || *end || prefix == 0 || prefix > 128) {
|
if (!end || *end || prefix == 0 || prefix > 128) {
|
||||||
|
@ -585,22 +577,16 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*text_gateway && !nm_utils_ipaddr_valid (AF_INET6, text_gateway)) {
|
if (!ce_ip_address_entry_is_valid (gateway_entry))
|
||||||
widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
if (*text_gateway)
|
|
||||||
have_gateway = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
addr = nm_ip_address_new (AF_INET6, text_address, prefix, NULL);
|
addr = nm_ip_address_new (AF_INET6, gtk_entry_get_text (GTK_ENTRY (address_entry)), prefix, NULL);
|
||||||
if (have_gateway)
|
if (!ce_ip_address_entry_is_empty (gateway_entry))
|
||||||
g_object_set (G_OBJECT (self->setting),
|
g_object_set (G_OBJECT (self->setting),
|
||||||
NM_SETTING_IP_CONFIG_GATEWAY, text_gateway,
|
NM_SETTING_IP_CONFIG_GATEWAY, gtk_entry_get_text (GTK_ENTRY (gateway_entry)),
|
||||||
NULL);
|
NULL);
|
||||||
nm_setting_ip_config_add_address (self->setting, addr);
|
nm_setting_ip_config_add_address (self->setting, addr);
|
||||||
|
|
||||||
|
@ -646,40 +632,32 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
|
|
||||||
for (GList *l = routes_children; l; l = l->next) {
|
for (GList *l = routes_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
CEIPAddressEntry *address_entry;
|
||||||
const gchar *text_address;
|
CEIPAddressEntry *gateway_entry;
|
||||||
const gchar *text_prefix;
|
const gchar *text_prefix;
|
||||||
const gchar *text_gateway;
|
|
||||||
const gchar *text_metric;
|
const gchar *text_metric;
|
||||||
guint32 prefix;
|
guint32 prefix;
|
||||||
gint64 metric;
|
gint64 metric;
|
||||||
gchar *end;
|
gchar *end;
|
||||||
NMIPRoute *route;
|
NMIPRoute *route;
|
||||||
|
|
||||||
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
address_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
||||||
if (!entry)
|
if (!address_entry)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
text_address = gtk_entry_get_text (entry);
|
|
||||||
text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix")));
|
text_prefix = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "prefix")));
|
||||||
text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
|
gateway_entry = CE_IP_ADDRESS_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"));
|
||||||
text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric")));
|
text_metric = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "metric")));
|
||||||
|
|
||||||
if (!*text_address && !*text_prefix && !*text_gateway && !*text_metric) {
|
if (ce_ip_address_entry_is_empty (address_entry) && !*text_prefix && ce_ip_address_entry_is_empty (gateway_entry) && !*text_metric) {
|
||||||
/* ignore empty rows */
|
/* ignore empty rows */
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "metric"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "metric"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_utils_ipaddr_valid (AF_INET6, text_address)) {
|
if (!ce_ip_address_entry_is_valid (address_entry))
|
||||||
widget_set_error (GTK_WIDGET (entry));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (GTK_WIDGET (entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix = strtoul (text_prefix, &end, 10);
|
prefix = strtoul (text_prefix, &end, 10);
|
||||||
if (!end || *end || prefix == 0 || prefix > 128) {
|
if (!end || *end || prefix == 0 || prefix > 128) {
|
||||||
|
@ -689,12 +667,8 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_utils_ipaddr_valid (AF_INET6, text_gateway)) {
|
if (!ce_ip_address_entry_is_valid (gateway_entry))
|
||||||
widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
} else {
|
|
||||||
widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
||||||
}
|
|
||||||
|
|
||||||
metric = -1;
|
metric = -1;
|
||||||
if (*text_metric) {
|
if (*text_metric) {
|
||||||
|
@ -713,7 +687,7 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
if (!ret)
|
if (!ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
route = nm_ip_route_new (AF_INET6, text_address, prefix, text_gateway, metric, NULL);
|
route = nm_ip_route_new (AF_INET6, gtk_entry_get_text (GTK_ENTRY (address_entry)), prefix, gtk_entry_get_text (GTK_ENTRY (gateway_entry)), metric, NULL);
|
||||||
nm_setting_ip_config_add_route (self->setting, route);
|
nm_setting_ip_config_add_route (self->setting, route);
|
||||||
nm_ip_route_unref (route);
|
nm_ip_route_unref (route);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
name = 'connection-editor'
|
name = 'connection-editor'
|
||||||
|
|
||||||
sources = files(
|
sources = files(
|
||||||
|
'ce-ip-address-entry.c',
|
||||||
'ce-page-8021x-security.c',
|
'ce-page-8021x-security.c',
|
||||||
'ce-page-details.c',
|
'ce-page-details.c',
|
||||||
'ce-page-ethernet.c',
|
'ce-page-ethernet.c',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue