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-object.h>
|
|
|
|
#include <glib/gi18n.h>
|
2016-04-29 16:05:54 +02:00
|
|
|
#include <NetworkManager.h>
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2018-04-06 13:38:40 +02:00
|
|
|
#include "list-box-helper.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
#include "ce-page-ip6.h"
|
2014-08-07 18:32:34 +02:00
|
|
|
#include "ui-helpers.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 01:56:08 -03:00
|
|
|
#define RADIO_IS_ACTIVE(x) (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object(CE_PAGE (page)->builder, x))))
|
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
static void ensure_empty_address_row (CEPageIP6 *page);
|
2017-05-23 13:04:52 -03:00
|
|
|
static void ensure_empty_routes_row (CEPageIP6 *page);
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
G_DEFINE_TYPE (CEPageIP6, ce_page_ip6, CE_TYPE_PAGE)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
METHOD_COL_NAME,
|
|
|
|
METHOD_COL_METHOD
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
IP6_METHOD_AUTO,
|
|
|
|
IP6_METHOD_DHCP,
|
|
|
|
IP6_METHOD_MANUAL,
|
|
|
|
IP6_METHOD_LINK_LOCAL,
|
|
|
|
IP6_METHOD_SHARED,
|
|
|
|
IP6_METHOD_IGNORE
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2017-05-23 01:56:08 -03:00
|
|
|
method_changed (GtkToggleButton *button, CEPageIP6 *page)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
gboolean addr_enabled;
|
|
|
|
gboolean dns_enabled;
|
|
|
|
gboolean routes_enabled;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2017-05-23 01:56:08 -03:00
|
|
|
if (RADIO_IS_ACTIVE ("radio_disabled")) {
|
2012-12-09 19:38:32 -05:00
|
|
|
addr_enabled = FALSE;
|
|
|
|
dns_enabled = FALSE;
|
|
|
|
routes_enabled = FALSE;
|
2017-05-23 01:56:08 -03:00
|
|
|
} else {
|
|
|
|
addr_enabled = RADIO_IS_ACTIVE ("radio_manual");
|
|
|
|
dns_enabled = !RADIO_IS_ACTIVE ("radio_local");
|
|
|
|
routes_enabled = !RADIO_IS_ACTIVE ("radio_local");
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
|
|
|
|
gtk_widget_set_visible (widget, addr_enabled);
|
2017-05-23 02:44:58 -03:00
|
|
|
gtk_widget_set_sensitive (page->dns_entry, dns_enabled);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_sensitive (page->routes_list, routes_enabled);
|
|
|
|
gtk_widget_set_sensitive (page->never_default, routes_enabled);
|
|
|
|
|
|
|
|
ce_page_changed (CE_PAGE (page));
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:14:24 -05:00
|
|
|
static void
|
|
|
|
switch_toggled (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
CEPage *page)
|
|
|
|
{
|
|
|
|
ce_page_changed (page);
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
|
|
|
update_row_sensitivity (CEPageIP6 *page, GtkWidget *list)
|
|
|
|
{
|
|
|
|
GList *children, *l;
|
2017-05-23 13:04:52 -03:00
|
|
|
gint rows = 0, i = 0;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (list));
|
|
|
|
for (l = children; l; l = l->next) {
|
|
|
|
GtkWidget *row = l->data;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
|
|
|
|
if (button != NULL)
|
|
|
|
rows++;
|
|
|
|
}
|
|
|
|
for (l = children; l; l = l->next) {
|
|
|
|
GtkWidget *row = l->data;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
button = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "delete-button"));
|
|
|
|
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
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_row (GtkButton *button, CEPageIP6 *page)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
2013-06-21 20:03:53 +02:00
|
|
|
GtkWidget *row_box;
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *list;
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
row_box = gtk_widget_get_parent (GTK_WIDGET (button));
|
|
|
|
row = gtk_widget_get_parent (row_box);
|
2012-12-09 19:38:32 -05:00
|
|
|
list = gtk_widget_get_parent (row);
|
|
|
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (list), row);
|
|
|
|
|
|
|
|
ce_page_changed (CE_PAGE (page));
|
|
|
|
|
|
|
|
update_row_sensitivity (page, list);
|
|
|
|
}
|
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
static gboolean
|
|
|
|
validate_row (GtkWidget *row)
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GList *children, *l;
|
|
|
|
gboolean valid;
|
|
|
|
|
|
|
|
valid = FALSE;
|
|
|
|
box = gtk_bin_get_child (GTK_BIN (row));
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (box));
|
|
|
|
|
|
|
|
for (l = children; l != NULL; l = l->next) {
|
|
|
|
if (!GTK_IS_ENTRY (l->data))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
valid = valid || gtk_entry_get_text_length (l->data) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static gint
|
|
|
|
sort_first_last (gconstpointer a, gconstpointer b, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean afirst, bfirst, alast, blast;
|
|
|
|
|
|
|
|
afirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "first"));
|
|
|
|
bfirst = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "first"));
|
|
|
|
alast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (a), "last"));
|
|
|
|
blast = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (b), "last"));
|
|
|
|
|
|
|
|
if (afirst)
|
|
|
|
return -1;
|
|
|
|
if (bfirst)
|
|
|
|
return 1;
|
|
|
|
if (alast)
|
|
|
|
return 1;
|
|
|
|
if (blast)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_address_row (CEPageIP6 *page,
|
|
|
|
const gchar *address,
|
|
|
|
const gchar *network,
|
|
|
|
const gchar *gateway)
|
|
|
|
{
|
2017-05-23 15:02:45 -03:00
|
|
|
GtkSizeGroup *group;
|
2012-12-09 19:38:32 -05:00
|
|
|
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;
|
|
|
|
GtkWidget *image;
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 15:02:45 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), address);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 15:02:45 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "prefix", widget);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), network);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 15:02:45 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_address_row), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
2016-06-14 13:46:16 +02:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), gateway ? gateway : "");
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
delete_button = gtk_button_new ();
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_widget_set_sensitive (delete_button, FALSE);
|
2013-02-07 16:23:54 -05:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button");
|
2012-12-09 19:38:32 -05:00
|
|
|
g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page);
|
2017-05-23 15:02:45 -03:00
|
|
|
image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
|
2013-02-12 11:13:08 -05:00
|
|
|
atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Address"));
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_button_set_image (GTK_BUTTON (delete_button), image);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), delete_button);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
|
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "address_sizegroup"));
|
|
|
|
gtk_size_group_add_widget (group, delete_button);
|
2013-06-21 20:03:53 +02:00
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row), row_box);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_show_all (row);
|
|
|
|
gtk_container_add (GTK_CONTAINER (page->address_list), row);
|
|
|
|
|
|
|
|
update_row_sensitivity (page, page->address_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-05-23 15:02:45 -03:00
|
|
|
ensure_empty_address_row (CEPageIP6 *page)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2017-05-23 15:02:45 -03:00
|
|
|
GList *children, *l;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
|
|
|
|
l = children;
|
|
|
|
|
|
|
|
while (l && l->next)
|
|
|
|
l = l->next;
|
|
|
|
|
|
|
|
/* Add the last, stub row if needed*/
|
|
|
|
if (!l || validate_row (l->data))
|
|
|
|
add_address_row (page, "", "", "");
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 15:02:45 -03:00
|
|
|
g_list_free (children);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_address_section (CEPageIP6 *page)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *list;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "address_section"));
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
page->address_list = list = gtk_list_box_new ();
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
|
2014-06-23 15:37:34 +02:00
|
|
|
gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
|
2013-06-21 20:03:53 +02:00
|
|
|
gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL);
|
2017-05-23 15:02:45 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (widget), list);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) {
|
|
|
|
NMIPAddress *addr;
|
|
|
|
char *netmask;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
addr = nm_setting_ip_config_get_address (page->setting, i);
|
|
|
|
netmask = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr));
|
|
|
|
add_address_row (page, nm_ip_address_get_address (addr), netmask,
|
|
|
|
i == 0 ? nm_setting_ip_config_get_gateway (page->setting) : NULL);
|
|
|
|
g_free (netmask);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2016-04-29 16:05:54 +02:00
|
|
|
if (nm_setting_ip_config_get_num_addresses (page->setting) == 0)
|
2017-05-23 15:02:45 -03:00
|
|
|
ensure_empty_address_row (page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
gtk_widget_show_all (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_dns_section (CEPageIP6 *page)
|
|
|
|
{
|
2017-05-23 02:44:58 -03:00
|
|
|
GtkEntry *entry;
|
|
|
|
GString *string;
|
2012-12-09 19:38:32 -05:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch"));
|
2016-04-29 16:05:54 +02:00
|
|
|
gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting));
|
2013-02-15 13:44:49 +01:00
|
|
|
g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
page->dns_entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "dns_entry"));
|
|
|
|
entry = GTK_ENTRY (page->dns_entry);
|
|
|
|
string = g_string_new ("");
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) {
|
|
|
|
const char *address;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
address = nm_setting_ip_config_get_dns (page->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
|
|
|
}
|
|
|
|
|
2017-05-23 02:44:58 -03:00
|
|
|
gtk_entry_set_text (entry, string->str);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (page->dns_entry, "notify::text", G_CALLBACK (ce_page_changed), page);
|
|
|
|
|
|
|
|
g_string_free (string, TRUE);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_route_row (CEPageIP6 *page,
|
|
|
|
const gchar *address,
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *prefix,
|
2012-12-09 19:38:32 -05:00
|
|
|
const gchar *gateway,
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *metric)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2017-05-23 13:04:52 -03:00
|
|
|
GtkSizeGroup *group;
|
2012-12-09 19:38:32 -05:00
|
|
|
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;
|
|
|
|
GtkWidget *image;
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
row_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (row_box), "linked");
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 13:04:52 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "address", widget);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), address);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 13:04:52 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "prefix", widget);
|
2016-04-29 16:05:54 +02:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), prefix ? prefix : "");
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 13:04:52 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "gateway", widget);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), gateway);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 16);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
2013-02-12 11:33:59 -05:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
widget = gtk_entry_new ();
|
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page);
|
2017-05-23 13:04:52 -03:00
|
|
|
g_signal_connect_swapped (widget, "activate", G_CALLBACK (ensure_empty_routes_row), page);
|
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
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), metric ? metric : "");
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (widget), 5);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), widget);
|
|
|
|
|
|
|
|
group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_metric_sizegroup"));
|
|
|
|
gtk_size_group_add_widget (group, widget);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
delete_button = gtk_button_new ();
|
2013-02-07 16:23:54 -05:00
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (delete_button), "image-button");
|
2012-12-09 19:38:32 -05:00
|
|
|
g_signal_connect (delete_button, "clicked", G_CALLBACK (remove_row), page);
|
2017-05-23 13:04:52 -03:00
|
|
|
image = gtk_image_new_from_icon_name ("edit-delete-symbolic", GTK_ICON_SIZE_MENU);
|
2013-02-12 11:13:08 -05:00
|
|
|
atk_object_set_name (gtk_widget_get_accessible (delete_button), _("Delete Route"));
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_button_set_image (GTK_BUTTON (delete_button), image);
|
|
|
|
gtk_widget_set_halign (delete_button, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (delete_button, GTK_ALIGN_CENTER);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row_box), delete_button);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_object_set_data (G_OBJECT (row), "delete-button", delete_button);
|
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
group = GTK_SIZE_GROUP (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_sizegroup"));
|
|
|
|
gtk_size_group_add_widget (group, delete_button);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (row), row_box);
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_widget_show_all (row);
|
|
|
|
gtk_container_add (GTK_CONTAINER (page->routes_list), row);
|
|
|
|
|
|
|
|
update_row_sensitivity (page, page->routes_list);
|
|
|
|
}
|
|
|
|
|
2017-05-23 13:04:52 -03:00
|
|
|
static void
|
|
|
|
ensure_empty_routes_row (CEPageIP6 *page)
|
|
|
|
{
|
|
|
|
GList *children, *l;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (page->routes_list));
|
|
|
|
l = children;
|
|
|
|
|
|
|
|
while (l && l->next)
|
|
|
|
l = l->next;
|
|
|
|
|
|
|
|
/* Add the last, stub row if needed*/
|
|
|
|
if (!l || validate_row (l->data))
|
|
|
|
add_route_row (page, "", NULL, "", NULL);
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
|
|
|
add_empty_route_row (CEPageIP6 *page)
|
|
|
|
{
|
2016-04-29 16:05:54 +02:00
|
|
|
add_route_row (page, "", NULL, "", NULL);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_routes_section (CEPageIP6 *page)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *list;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "routes_section"));
|
|
|
|
|
2013-06-21 20:03:53 +02:00
|
|
|
page->routes_list = list = gtk_list_box_new ();
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
|
2014-06-23 15:37:34 +02:00
|
|
|
gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
|
2013-06-21 20:03:53 +02:00
|
|
|
gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL);
|
2017-05-23 13:04:52 -03:00
|
|
|
gtk_container_add (GTK_CONTAINER (widget), list);
|
2012-12-09 19:38:32 -05:00
|
|
|
page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch"));
|
2016-04-29 16:05:54 +02:00
|
|
|
gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting));
|
2013-02-15 13:44:49 +01:00
|
|
|
g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) {
|
|
|
|
NMIPRoute *route;
|
|
|
|
char *prefix, *metric;
|
|
|
|
|
|
|
|
route = nm_setting_ip_config_get_route (page->setting, i);
|
|
|
|
prefix = g_strdup_printf ("%u", nm_ip_route_get_prefix (route));
|
|
|
|
metric = g_strdup_printf ("%u", (guint32) MIN (0, nm_ip_route_get_metric (route)));
|
|
|
|
add_route_row (page, nm_ip_route_get_dest (route),
|
|
|
|
prefix,
|
|
|
|
nm_ip_route_get_next_hop (route),
|
|
|
|
metric);
|
|
|
|
g_free (prefix);
|
|
|
|
g_free (metric);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2016-04-29 16:05:54 +02:00
|
|
|
if (nm_setting_ip_config_get_num_routes (page->setting) == 0)
|
2012-12-09 19:38:32 -05:00
|
|
|
add_empty_route_row (page);
|
|
|
|
|
|
|
|
gtk_widget_show_all (widget);
|
|
|
|
}
|
|
|
|
|
2017-05-23 01:56:08 -03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RADIO_AUTOMATIC,
|
|
|
|
RADIO_DHCP,
|
|
|
|
RADIO_LOCAL,
|
|
|
|
RADIO_MANUAL,
|
|
|
|
RADIO_DISABLED,
|
|
|
|
N_RADIO
|
|
|
|
};
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
|
|
|
connect_ip6_page (CEPageIP6 *page)
|
|
|
|
{
|
2017-05-23 01:56:08 -03:00
|
|
|
GtkToggleButton *radios[N_RADIO];
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *content;
|
|
|
|
const gchar *str_method;
|
|
|
|
gboolean disabled;
|
2017-05-23 01:56:08 -03:00
|
|
|
guint method, i;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
add_address_section (page);
|
|
|
|
add_dns_section (page);
|
|
|
|
add_routes_section (page);
|
|
|
|
|
2017-05-23 01:56:08 -03:00
|
|
|
page->disabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_disabled"));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
str_method = nm_setting_ip_config_get_method (page->setting);
|
2012-12-09 19:38:32 -05:00
|
|
|
disabled = g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0;
|
2017-05-23 01:56:08 -03:00
|
|
|
gtk_toggle_button_set_active (page->disabled, disabled);
|
|
|
|
g_signal_connect_swapped (page->disabled, "notify::active", G_CALLBACK (ce_page_changed), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
content = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "page_content"));
|
2017-05-23 01:56:08 -03:00
|
|
|
g_object_bind_property (page->disabled, "active",
|
2012-12-09 19:38:32 -05:00
|
|
|
content, "sensitive",
|
2017-05-23 01:56:08 -03:00
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
method = IP6_METHOD_AUTO;
|
|
|
|
if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
|
|
|
|
method = IP6_METHOD_DHCP;
|
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) {
|
|
|
|
method = IP6_METHOD_LINK_LOCAL;
|
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0) {
|
|
|
|
method = IP6_METHOD_MANUAL;
|
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) {
|
|
|
|
method = IP6_METHOD_SHARED;
|
|
|
|
} else if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) {
|
|
|
|
method = IP6_METHOD_IGNORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default),
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_setting_ip_config_get_never_default (page->setting));
|
2015-03-09 16:12:25 +01:00
|
|
|
g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 01:56:08 -03:00
|
|
|
|
|
|
|
/* Connect radio buttons */
|
|
|
|
radios[RADIO_AUTOMATIC] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_automatic"));
|
|
|
|
radios[RADIO_DHCP] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_dhcp"));
|
|
|
|
radios[RADIO_LOCAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_local"));
|
|
|
|
radios[RADIO_MANUAL] = GTK_TOGGLE_BUTTON (gtk_builder_get_object (CE_PAGE (page)->builder, "radio_manual"));
|
|
|
|
radios[RADIO_DISABLED] = page->disabled;
|
|
|
|
|
|
|
|
for (i = RADIO_AUTOMATIC; i < RADIO_DISABLED; i++)
|
|
|
|
g_signal_connect (radios[i], "toggled", G_CALLBACK (method_changed), page);
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
case IP6_METHOD_AUTO:
|
|
|
|
gtk_toggle_button_set_active (radios[RADIO_AUTOMATIC], TRUE);
|
|
|
|
break;
|
|
|
|
case IP6_METHOD_DHCP:
|
|
|
|
gtk_toggle_button_set_active (radios[RADIO_DHCP], TRUE);
|
|
|
|
break;
|
|
|
|
case IP6_METHOD_LINK_LOCAL:
|
|
|
|
gtk_toggle_button_set_active (radios[RADIO_LOCAL], TRUE);
|
|
|
|
break;
|
|
|
|
case IP6_METHOD_MANUAL:
|
|
|
|
gtk_toggle_button_set_active (radios[RADIO_MANUAL], TRUE);
|
|
|
|
break;
|
|
|
|
case IP6_METHOD_IGNORE:
|
|
|
|
gtk_toggle_button_set_active (radios[RADIO_DISABLED], TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
method_changed (NULL, page);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
ui_to_setting (CEPageIP6 *page)
|
|
|
|
{
|
|
|
|
const gchar *method;
|
|
|
|
gboolean ignore_auto_dns;
|
|
|
|
gboolean ignore_auto_routes;
|
|
|
|
gboolean never_default;
|
|
|
|
GList *children, *l;
|
2014-08-13 13:46:03 +02:00
|
|
|
gboolean ret = TRUE;
|
2017-05-23 02:44:58 -03:00
|
|
|
GStrv dns_addresses = NULL;
|
|
|
|
gchar *dns_text = NULL;
|
|
|
|
guint i;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2017-05-23 01:56:08 -03:00
|
|
|
if (gtk_toggle_button_get_active (page->disabled)) {
|
2012-12-09 19:38:32 -05:00
|
|
|
method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
|
|
|
} else {
|
2017-05-23 01:56:08 -03:00
|
|
|
if (RADIO_IS_ACTIVE ("radio_manual")) {
|
2012-12-09 19:38:32 -05:00
|
|
|
method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
|
2017-05-23 01:56:08 -03:00
|
|
|
} else if (RADIO_IS_ACTIVE ("radio_local")) {
|
2012-12-09 19:38:32 -05:00
|
|
|
method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL;
|
2017-05-23 01:56:08 -03:00
|
|
|
} else if (RADIO_IS_ACTIVE ("radio_dhcp")) {
|
2012-12-09 19:38:32 -05:00
|
|
|
method = NM_SETTING_IP6_CONFIG_METHOD_DHCP;
|
2017-05-23 01:56:08 -03:00
|
|
|
} else if (RADIO_IS_ACTIVE ("radio_automatic")) {
|
2012-12-09 19:38:32 -05:00
|
|
|
method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_setting_ip_config_clear_addresses (page->setting);
|
2016-06-14 14:03:07 +02:00
|
|
|
if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
|
2014-08-13 18:26:19 +02:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (page->address_list));
|
2016-06-14 14:03:07 +02:00
|
|
|
} else {
|
|
|
|
g_object_set (G_OBJECT (page->setting),
|
|
|
|
NM_SETTING_IP_CONFIG_GATEWAY, NULL,
|
|
|
|
NULL);
|
2014-08-13 18:26:19 +02:00
|
|
|
children = NULL;
|
2016-06-14 14:03:07 +02:00
|
|
|
}
|
2014-08-13 18:26:19 +02:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
for (l = children; l; l = l->next) {
|
|
|
|
GtkWidget *row = l->data;
|
|
|
|
GtkEntry *entry;
|
|
|
|
const gchar *text_address;
|
|
|
|
const gchar *text_prefix;
|
|
|
|
const gchar *text_gateway;
|
|
|
|
guint32 prefix;
|
|
|
|
gchar *end;
|
2016-04-29 16:05:54 +02:00
|
|
|
NMIPAddress *addr;
|
2012-12-09 19:38:32 -05:00
|
|
|
gboolean have_gateway = FALSE;
|
|
|
|
|
|
|
|
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
|
|
|
if (!entry)
|
|
|
|
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_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway")));
|
|
|
|
|
|
|
|
if (!*text_address && !*text_prefix && !*text_gateway) {
|
|
|
|
/* ignore empty rows */
|
2014-08-07 18:32:34 +02:00
|
|
|
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), "gateway"));
|
2012-12-09 19:38:32 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-06 10:30:57 +01:00
|
|
|
if (!*text_address || !nm_utils_ipaddr_valid (AF_INET6, text_address)) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (GTK_WIDGET (entry));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (GTK_WIDGET (entry));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
prefix = strtoul (text_prefix, &end, 10);
|
|
|
|
if (!end || *end || prefix == 0 || prefix > 128) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2018-02-06 10:30:57 +01:00
|
|
|
if (*text_gateway && !nm_utils_ipaddr_valid (AF_INET6, text_gateway)) {
|
2016-04-29 16:05:54 +02:00
|
|
|
widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
|
|
|
ret = FALSE;
|
2014-08-13 13:46:03 +02:00
|
|
|
} else {
|
|
|
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
2018-02-06 10:30:57 +01:00
|
|
|
if (*text_gateway)
|
|
|
|
have_gateway = TRUE;
|
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
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
addr = nm_ip_address_new (AF_INET6, text_address, prefix, NULL);
|
2012-12-09 19:38:32 -05:00
|
|
|
if (have_gateway)
|
2016-04-29 16:05:54 +02:00
|
|
|
g_object_set (G_OBJECT (page->setting),
|
|
|
|
NM_SETTING_IP_CONFIG_GATEWAY, text_gateway,
|
|
|
|
NULL);
|
|
|
|
nm_setting_ip_config_add_address (page->setting, addr);
|
2017-05-23 15:02:45 -03:00
|
|
|
|
|
|
|
if (!l || !l->next)
|
|
|
|
ensure_empty_address_row (page);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_setting_ip_config_clear_dns (page->setting);
|
2017-05-23 02:44:58 -03:00
|
|
|
dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (page->dns_entry))));
|
|
|
|
|
2014-08-13 18:26:19 +02:00
|
|
|
if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) ||
|
|
|
|
g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) ||
|
|
|
|
g_str_equal (method, NM_SETTING_IP6_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;
|
|
|
|
struct in6_addr tmp_addr;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (inet_pton (AF_INET6, text, &tmp_addr) <= 0) {
|
2017-05-23 02:44:58 -03:00
|
|
|
g_clear_pointer (&dns_addresses, g_strfreev);
|
|
|
|
widget_set_error (page->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 {
|
2017-05-23 02:44:58 -03:00
|
|
|
widget_unset_error (page->dns_entry);
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_setting_ip_config_add_dns (page->setting, text);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
nm_setting_ip_config_clear_routes (page->setting);
|
2014-08-13 18:26:19 +02:00
|
|
|
if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) ||
|
|
|
|
g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) ||
|
|
|
|
g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (page->routes_list));
|
|
|
|
else
|
|
|
|
children = NULL;
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
for (l = children; l; l = l->next) {
|
|
|
|
GtkWidget *row = l->data;
|
|
|
|
GtkEntry *entry;
|
|
|
|
const gchar *text_address;
|
|
|
|
const gchar *text_prefix;
|
|
|
|
const gchar *text_gateway;
|
|
|
|
const gchar *text_metric;
|
|
|
|
guint32 prefix, metric;
|
|
|
|
gchar *end;
|
2016-04-29 16:05:54 +02:00
|
|
|
NMIPRoute *route;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address"));
|
|
|
|
if (!entry)
|
|
|
|
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_gateway = gtk_entry_get_text (GTK_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")));
|
|
|
|
|
|
|
|
if (!*text_address && !*text_prefix && !*text_gateway && !*text_metric) {
|
|
|
|
/* ignore empty rows */
|
2014-08-07 18:32:34 +02:00
|
|
|
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), "gateway"));
|
|
|
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "metric"));
|
2012-12-09 19:38:32 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
if (!nm_utils_ipaddr_valid (AF_INET6, text_address)) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (GTK_WIDGET (entry));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (GTK_WIDGET (entry));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
prefix = strtoul (text_prefix, &end, 10);
|
|
|
|
if (!end || *end || prefix == 0 || prefix > 128) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix"));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
if (!nm_utils_ipaddr_valid (AF_INET6, text_gateway)) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway"));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
metric = 0;
|
|
|
|
if (*text_metric) {
|
|
|
|
errno = 0;
|
|
|
|
metric = strtoul (text_metric, NULL, 10);
|
|
|
|
if (errno) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (g_object_get_data (G_OBJECT (row), "metric"));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (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 (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
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
route = nm_ip_route_new (AF_INET6, text_address, prefix, text_gateway, metric, NULL);
|
|
|
|
nm_setting_ip_config_add_route (page->setting, route);
|
|
|
|
nm_ip_route_unref (route);
|
2017-05-23 13:04:52 -03:00
|
|
|
|
|
|
|
if (!l || !l->next)
|
|
|
|
ensure_empty_routes_row (page);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
|
2014-08-13 13:46:03 +02:00
|
|
|
if (!ret)
|
|
|
|
goto out;
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
ignore_auto_dns = !gtk_switch_get_active (page->auto_dns);
|
|
|
|
ignore_auto_routes = !gtk_switch_get_active (page->auto_routes);
|
|
|
|
never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default));
|
|
|
|
|
|
|
|
g_object_set (page->setting,
|
2016-04-29 16:05:54 +02:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, method,
|
|
|
|
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:
|
2017-05-23 02:44:58 -03:00
|
|
|
g_clear_pointer (&dns_addresses, g_strfreev);
|
|
|
|
g_clear_pointer (&dns_text, g_free);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2014-08-13 13:46:03 +02:00
|
|
|
return ret;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
validate (CEPage *page,
|
|
|
|
NMConnection *connection,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (!ui_to_setting (CE_PAGE_IP6 (page)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return nm_setting_verify (NM_SETTING (CE_PAGE_IP6 (page)->setting), NULL, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_page_ip6_init (CEPageIP6 *page)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_page_ip6_class_init (CEPageIP6Class *class)
|
|
|
|
{
|
|
|
|
CEPageClass *page_class= CE_PAGE_CLASS (class);
|
|
|
|
|
|
|
|
page_class->validate = validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEPage *
|
|
|
|
ce_page_ip6_new (NMConnection *connection,
|
2016-04-29 16:05:54 +02:00
|
|
|
NMClient *client)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
CEPageIP6 *page;
|
|
|
|
|
|
|
|
page = CE_PAGE_IP6 (ce_page_new (CE_TYPE_PAGE_IP6,
|
|
|
|
connection,
|
|
|
|
client,
|
|
|
|
"/org/gnome/control-center/network/ip6-page.ui",
|
|
|
|
_("IPv6")));
|
|
|
|
|
|
|
|
page->setting = nm_connection_get_setting_ip6_config (connection);
|
2012-12-17 14:17:42 -05:00
|
|
|
if (!page->setting) {
|
2016-04-29 16:05:54 +02:00
|
|
|
page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
|
2012-12-17 14:17:42 -05:00
|
|
|
nm_connection_add_setting (connection, NM_SETTING (page->setting));
|
|
|
|
}
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
connect_ip6_page (page);
|
|
|
|
|
|
|
|
return CE_PAGE (page);
|
|
|
|
}
|