2012-12-17 14:17:42 -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 <glib/gi18n.h>
|
2016-04-29 16:05:54 +02:00
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <NetworkManager.h>
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
#include "ce-page.h"
|
2012-12-17 14:17:42 -05:00
|
|
|
#include "ce-page-ethernet.h"
|
2014-08-07 18:32:34 +02:00
|
|
|
#include "ui-helpers.h"
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-11-06 14:00:07 +13:00
|
|
|
struct _CEPageEthernet
|
|
|
|
{
|
2019-11-06 17:16:54 +13:00
|
|
|
GtkGrid parent;
|
2019-11-06 14:00:07 +13:00
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
GtkComboBoxText *cloned_mac_combo;
|
|
|
|
GtkComboBoxText *mac_combo;
|
|
|
|
GtkSpinButton *mtu_spin;
|
2019-11-06 14:00:07 +13:00
|
|
|
GtkWidget *mtu_label;
|
2019-11-06 17:16:54 +13:00
|
|
|
GtkEntry *name_entry;
|
2019-11-06 14:19:56 +13:00
|
|
|
|
|
|
|
NMClient *client;
|
|
|
|
NMSettingConnection *setting_connection;
|
|
|
|
NMSettingWired *setting_wired;
|
2019-11-06 14:00:07 +13:00
|
|
|
};
|
|
|
|
|
2019-11-06 17:07:42 +13:00
|
|
|
static void ce_page_iface_init (CEPageInterface *);
|
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (CEPageEthernet, ce_page_ethernet, GTK_TYPE_GRID,
|
2019-11-06 17:07:42 +13:00
|
|
|
G_IMPLEMENT_INTERFACE (ce_page_get_type (), ce_page_iface_init))
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
mtu_changed (CEPageEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-11-06 17:16:54 +13:00
|
|
|
if (gtk_spin_button_get_value_as_int (self->mtu_spin) == 0)
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_widget_hide (self->mtu_label);
|
2012-12-17 14:17:42 -05:00
|
|
|
else
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_widget_show (self->mtu_label);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
2019-10-15 11:15:30 +13:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
mtu_output_cb (CEPageEthernet *self)
|
2019-10-18 10:25:25 +13:00
|
|
|
{
|
2019-10-15 11:15:30 +13:00
|
|
|
gint defvalue;
|
2019-10-18 10:25:25 +13:00
|
|
|
gint val;
|
|
|
|
g_autofree gchar *buf = NULL;
|
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
val = gtk_spin_button_get_value_as_int (self->mtu_spin);
|
2019-10-18 11:47:17 +13:00
|
|
|
defvalue = ce_get_property_default (NM_SETTING (self->setting_wired), NM_SETTING_WIRED_MTU);
|
2019-10-18 10:25:25 +13:00
|
|
|
if (val == defvalue)
|
|
|
|
buf = g_strdup (_("automatic"));
|
|
|
|
else
|
|
|
|
buf = g_strdup_printf ("%d", val);
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
if (strcmp (buf, gtk_editable_get_text (GTK_EDITABLE (self->mtu_spin))))
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->mtu_spin), buf);
|
2019-10-18 10:25:25 +13:00
|
|
|
}
|
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
connect_ethernet_page (CEPageEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
NMSettingWired *setting = self->setting_wired;
|
2012-12-17 14:17:42 -05:00
|
|
|
char **mac_list;
|
2016-04-29 16:05:54 +02:00
|
|
|
const char *s_mac_str;
|
2012-12-17 14:17:42 -05:00
|
|
|
const gchar *name;
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *cloned_mac;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
name = nm_setting_connection_get_id (self->setting_connection);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->name_entry), name);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
/* Device MAC address */
|
2019-11-06 14:19:56 +13:00
|
|
|
mac_list = ce_page_get_mac_list (self->client, NM_TYPE_DEVICE_ETHERNET,
|
2012-12-17 14:17:42 -05:00
|
|
|
NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
|
2016-04-29 16:05:54 +02:00
|
|
|
s_mac_str = nm_setting_wired_get_mac_address (setting);
|
2019-11-06 17:16:54 +13:00
|
|
|
ce_page_setup_mac_combo (self->mac_combo, s_mac_str, mac_list);
|
2012-12-17 14:17:42 -05:00
|
|
|
g_strfreev (mac_list);
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->mac_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
/* Cloned MAC address */
|
2016-04-29 16:05:54 +02:00
|
|
|
cloned_mac = nm_setting_wired_get_cloned_mac_address (setting);
|
2019-11-06 17:16:54 +13:00
|
|
|
ce_page_setup_cloned_mac_combo (self->cloned_mac_combo, cloned_mac);
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->cloned_mac_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
/* MTU */
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->mtu_spin, "output", G_CALLBACK (mtu_output_cb), self, G_CONNECT_SWAPPED);
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_spin_button_set_value (self->mtu_spin, (gdouble) nm_setting_wired_get_mtu (setting));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->mtu_spin, "value-changed", G_CALLBACK (mtu_changed), self, G_CONNECT_SWAPPED);
|
2019-10-18 11:47:17 +13:00
|
|
|
mtu_changed (self);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (self->name_entry, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (self->mtu_spin, "value-changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
ui_to_setting (CEPageEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *device_mac = NULL;
|
|
|
|
g_autofree gchar *cloned_mac = NULL;
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *text;
|
2012-12-17 14:17:42 -05:00
|
|
|
GtkWidget *entry;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->mac_combo));
|
2016-04-29 16:05:54 +02:00
|
|
|
if (entry) {
|
2021-11-29 10:37:01 -03:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry));
|
2016-04-29 16:05:54 +02:00
|
|
|
device_mac = ce_page_trim_address (text);
|
|
|
|
}
|
2018-01-31 17:00:47 +01:00
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
cloned_mac = ce_page_cloned_mac_get (self->cloned_mac_combo);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
g_object_set (self->setting_wired,
|
2012-12-17 14:17:42 -05:00
|
|
|
NM_SETTING_WIRED_MAC_ADDRESS, device_mac,
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac,
|
2019-11-06 17:16:54 +13:00
|
|
|
NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (self->mtu_spin),
|
2012-12-17 14:17:42 -05:00
|
|
|
NULL);
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
g_object_set (self->setting_connection,
|
2021-11-29 10:37:01 -03:00
|
|
|
NM_SETTING_CONNECTION_ID, gtk_editable_get_text (GTK_EDITABLE (self->name_entry)),
|
2012-12-17 14:17:42 -05:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2019-11-06 13:38:36 +13:00
|
|
|
static const gchar *
|
|
|
|
ce_page_ethernet_get_title (CEPage *page)
|
|
|
|
{
|
|
|
|
return _("Identity");
|
|
|
|
}
|
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
static gboolean
|
2019-11-06 16:33:07 +13:00
|
|
|
ce_page_ethernet_validate (CEPage *page,
|
|
|
|
NMConnection *connection,
|
|
|
|
GError **error)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
CEPageEthernet *self = CE_PAGE_ETHERNET (page);
|
|
|
|
GtkWidget *entry;
|
2014-08-13 13:46:03 +02:00
|
|
|
gboolean ret = TRUE;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->mac_combo));
|
2012-12-17 14:17:42 -05:00
|
|
|
if (entry) {
|
2021-11-29 10:37:01 -03:00
|
|
|
if (!ce_page_address_is_valid (gtk_editable_get_text (GTK_EDITABLE (entry)))) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (entry);
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (entry);
|
2014-08-07 18:32:34 +02:00
|
|
|
}
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
if (!ce_page_cloned_mac_combo_valid (self->cloned_mac_combo)) {
|
2021-11-29 10:37:01 -03:00
|
|
|
widget_set_error (gtk_combo_box_get_child (GTK_COMBO_BOX (self->cloned_mac_combo)));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
2021-11-29 10:37:01 -03:00
|
|
|
widget_unset_error (gtk_combo_box_get_child (GTK_COMBO_BOX (self->cloned_mac_combo)));
|
2014-08-07 18:32:34 +02:00
|
|
|
}
|
2014-08-13 13:46:03 +02:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return ret;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
ui_to_setting (self);
|
|
|
|
|
|
|
|
return nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error) &&
|
|
|
|
nm_setting_verify (NM_SETTING (self->setting_wired), NULL, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
ce_page_ethernet_init (CEPageEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-06 17:16:54 +13:00
|
|
|
ce_page_ethernet_class_init (CEPageEthernetClass *klass)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-11-06 17:16:54 +13:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/ethernet-page.ui");
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, cloned_mac_combo);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, mac_combo);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, mtu_spin);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, mtu_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, name_entry);
|
2019-11-06 17:07:42 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_page_iface_init (CEPageInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_title = ce_page_ethernet_get_title;
|
|
|
|
iface->validate = ce_page_ethernet_validate;
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
CEPageEthernet *
|
2012-12-17 14:17:42 -05:00
|
|
|
ce_page_ethernet_new (NMConnection *connection,
|
2016-04-29 16:05:54 +02:00
|
|
|
NMClient *client)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
CEPageEthernet *self;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-11-06 15:50:40 +13:00
|
|
|
self = CE_PAGE_ETHERNET (g_object_new (ce_page_ethernet_get_type (), NULL));
|
2019-11-06 15:05:29 +13:00
|
|
|
|
2019-11-06 14:19:56 +13:00
|
|
|
self->client = client;
|
2019-10-18 11:47:17 +13:00
|
|
|
self->setting_connection = nm_connection_get_setting_connection (connection);
|
|
|
|
self->setting_wired = nm_connection_get_setting_wired (connection);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
connect_ethernet_page (self);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-11-06 17:16:54 +13:00
|
|
|
return self;
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|