Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2012 Red Hat, Inc |
4 |
|
|
* |
5 |
|
|
* Licensed under the GNU General Public License Version 2 |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "config.h" |
23 |
|
|
|
24 |
|
|
#include <glib/gi18n.h> |
25 |
|
|
#include <net/if_arp.h> |
26 |
|
|
#include <NetworkManager.h> |
27 |
|
|
|
28 |
|
|
#include "ce-page.h" |
29 |
|
|
#include "ce-page-ethernet.h" |
30 |
|
|
#include "ui-helpers.h" |
31 |
|
|
|
32 |
|
|
struct _CEPageEthernet |
33 |
|
|
{ |
34 |
|
|
AdwBin parent; |
35 |
|
|
|
36 |
|
|
GtkComboBoxText *cloned_mac_combo; |
37 |
|
|
GtkComboBoxText *mac_combo; |
38 |
|
|
GtkSpinButton *mtu_spin; |
39 |
|
|
GtkWidget *mtu_label; |
40 |
|
|
GtkEntry *name_entry; |
41 |
|
|
|
42 |
|
|
NMClient *client; |
43 |
|
|
NMSettingConnection *setting_connection; |
44 |
|
|
NMSettingWired *setting_wired; |
45 |
|
|
}; |
46 |
|
|
|
47 |
|
|
static void ce_page_iface_init (CEPageInterface *); |
48 |
|
|
|
49 |
|
✗ |
G_DEFINE_TYPE_WITH_CODE (CEPageEthernet, ce_page_ethernet, ADW_TYPE_BIN, |
50 |
|
|
G_IMPLEMENT_INTERFACE (ce_page_get_type (), ce_page_iface_init)) |
51 |
|
|
|
52 |
|
|
static void |
53 |
|
✗ |
mtu_changed (CEPageEthernet *self) |
54 |
|
|
{ |
55 |
|
✗ |
gtk_widget_set_visible (self->mtu_label, |
56 |
|
✗ |
gtk_spin_button_get_value_as_int (self->mtu_spin) != 0); |
57 |
|
✗ |
} |
58 |
|
|
|
59 |
|
|
static void |
60 |
|
✗ |
mtu_output_cb (CEPageEthernet *self) |
61 |
|
|
{ |
62 |
|
|
gint defvalue; |
63 |
|
|
gint val; |
64 |
|
✗ |
g_autofree gchar *buf = NULL; |
65 |
|
|
|
66 |
|
✗ |
val = gtk_spin_button_get_value_as_int (self->mtu_spin); |
67 |
|
✗ |
defvalue = ce_get_property_default (NM_SETTING (self->setting_wired), NM_SETTING_WIRED_MTU); |
68 |
|
✗ |
if (val == defvalue) |
69 |
|
✗ |
buf = g_strdup (_("automatic")); |
70 |
|
|
else |
71 |
|
✗ |
buf = g_strdup_printf ("%d", val); |
72 |
|
|
|
73 |
|
✗ |
if (strcmp (buf, gtk_editable_get_text (GTK_EDITABLE (self->mtu_spin)))) |
74 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->mtu_spin), buf); |
75 |
|
✗ |
} |
76 |
|
|
|
77 |
|
|
static void |
78 |
|
✗ |
connect_ethernet_page (CEPageEthernet *self) |
79 |
|
|
{ |
80 |
|
✗ |
NMSettingWired *setting = self->setting_wired; |
81 |
|
|
char **mac_list; |
82 |
|
|
const char *s_mac_str; |
83 |
|
|
const gchar *name; |
84 |
|
|
const gchar *cloned_mac; |
85 |
|
|
|
86 |
|
✗ |
name = nm_setting_connection_get_id (self->setting_connection); |
87 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->name_entry), name); |
88 |
|
|
|
89 |
|
|
/* Device MAC address */ |
90 |
|
✗ |
mac_list = ce_page_get_mac_list (self->client, NM_TYPE_DEVICE_ETHERNET, |
91 |
|
|
NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS); |
92 |
|
✗ |
s_mac_str = nm_setting_wired_get_mac_address (setting); |
93 |
|
✗ |
ce_page_setup_mac_combo (self->mac_combo, s_mac_str, mac_list); |
94 |
|
✗ |
g_strfreev (mac_list); |
95 |
|
✗ |
g_signal_connect_object (self->mac_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
96 |
|
|
|
97 |
|
|
/* Cloned MAC address */ |
98 |
|
✗ |
cloned_mac = nm_setting_wired_get_cloned_mac_address (setting); |
99 |
|
✗ |
ce_page_setup_cloned_mac_combo (self->cloned_mac_combo, cloned_mac, FALSE); |
100 |
|
✗ |
g_signal_connect_object (self->cloned_mac_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
101 |
|
|
|
102 |
|
|
/* MTU */ |
103 |
|
✗ |
g_signal_connect_object (self->mtu_spin, "output", G_CALLBACK (mtu_output_cb), self, G_CONNECT_SWAPPED); |
104 |
|
✗ |
gtk_spin_button_set_value (self->mtu_spin, (gdouble) nm_setting_wired_get_mtu (setting)); |
105 |
|
✗ |
g_signal_connect_object (self->mtu_spin, "value-changed", G_CALLBACK (mtu_changed), self, G_CONNECT_SWAPPED); |
106 |
|
✗ |
mtu_changed (self); |
107 |
|
|
|
108 |
|
✗ |
g_signal_connect_object (self->name_entry, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
109 |
|
✗ |
g_signal_connect_object (self->mtu_spin, "value-changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
110 |
|
✗ |
} |
111 |
|
|
|
112 |
|
|
static void |
113 |
|
✗ |
ui_to_setting (CEPageEthernet *self) |
114 |
|
|
{ |
115 |
|
✗ |
g_autofree gchar *device_mac = NULL; |
116 |
|
✗ |
g_autofree gchar *cloned_mac = NULL; |
117 |
|
|
const gchar *text; |
118 |
|
|
GtkWidget *entry; |
119 |
|
|
|
120 |
|
✗ |
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->mac_combo)); |
121 |
|
✗ |
if (entry) { |
122 |
|
✗ |
text = gtk_editable_get_text (GTK_EDITABLE (entry)); |
123 |
|
✗ |
device_mac = ce_page_trim_address (text); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
✗ |
cloned_mac = ce_page_cloned_mac_get (self->cloned_mac_combo); |
127 |
|
|
|
128 |
|
✗ |
g_object_set (self->setting_wired, |
129 |
|
|
NM_SETTING_WIRED_MAC_ADDRESS, device_mac, |
130 |
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac, |
131 |
|
✗ |
NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (self->mtu_spin), |
132 |
|
|
NULL); |
133 |
|
|
|
134 |
|
✗ |
g_object_set (self->setting_connection, |
135 |
|
✗ |
NM_SETTING_CONNECTION_ID, gtk_editable_get_text (GTK_EDITABLE (self->name_entry)), |
136 |
|
|
NULL); |
137 |
|
✗ |
} |
138 |
|
|
|
139 |
|
|
static const gchar * |
140 |
|
✗ |
ce_page_ethernet_get_title (CEPage *page) |
141 |
|
|
{ |
142 |
|
✗ |
return _("Identity"); |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
static gboolean |
146 |
|
✗ |
ce_page_ethernet_validate (CEPage *page, |
147 |
|
|
NMConnection *connection, |
148 |
|
|
GError **error) |
149 |
|
|
{ |
150 |
|
✗ |
CEPageEthernet *self = CE_PAGE_ETHERNET (page); |
151 |
|
|
GtkWidget *entry; |
152 |
|
✗ |
gboolean ret = TRUE; |
153 |
|
|
|
154 |
|
✗ |
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->mac_combo)); |
155 |
|
✗ |
if (entry) { |
156 |
|
✗ |
if (!ce_page_address_is_valid (gtk_editable_get_text (GTK_EDITABLE (entry)))) { |
157 |
|
✗ |
widget_set_error (entry); |
158 |
|
✗ |
ret = FALSE; |
159 |
|
|
} else { |
160 |
|
✗ |
widget_unset_error (entry); |
161 |
|
|
} |
162 |
|
|
} |
163 |
|
|
|
164 |
|
✗ |
if (!ce_page_cloned_mac_combo_valid (self->cloned_mac_combo)) { |
165 |
|
✗ |
widget_set_error (gtk_combo_box_get_child (GTK_COMBO_BOX (self->cloned_mac_combo))); |
166 |
|
✗ |
ret = FALSE; |
167 |
|
|
} else { |
168 |
|
✗ |
widget_unset_error (gtk_combo_box_get_child (GTK_COMBO_BOX (self->cloned_mac_combo))); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
✗ |
if (!ret) |
172 |
|
✗ |
return ret; |
173 |
|
|
|
174 |
|
✗ |
ui_to_setting (self); |
175 |
|
|
|
176 |
|
✗ |
return nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error) && |
177 |
|
✗ |
nm_setting_verify (NM_SETTING (self->setting_wired), NULL, error); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
static void |
181 |
|
✗ |
ce_page_ethernet_init (CEPageEthernet *self) |
182 |
|
|
{ |
183 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
184 |
|
✗ |
} |
185 |
|
|
|
186 |
|
|
static void |
187 |
|
✗ |
ce_page_ethernet_class_init (CEPageEthernetClass *klass) |
188 |
|
|
{ |
189 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
190 |
|
|
|
191 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/ethernet-page.ui"); |
192 |
|
|
|
193 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, cloned_mac_combo); |
194 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, mac_combo); |
195 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, mtu_spin); |
196 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, mtu_label); |
197 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageEthernet, name_entry); |
198 |
|
✗ |
} |
199 |
|
|
|
200 |
|
|
static void |
201 |
|
✗ |
ce_page_iface_init (CEPageInterface *iface) |
202 |
|
|
{ |
203 |
|
✗ |
iface->get_title = ce_page_ethernet_get_title; |
204 |
|
✗ |
iface->validate = ce_page_ethernet_validate; |
205 |
|
✗ |
} |
206 |
|
|
|
207 |
|
|
CEPageEthernet * |
208 |
|
✗ |
ce_page_ethernet_new (NMConnection *connection, |
209 |
|
|
NMClient *client) |
210 |
|
|
{ |
211 |
|
|
CEPageEthernet *self; |
212 |
|
|
|
213 |
|
✗ |
self = CE_PAGE_ETHERNET (g_object_new (ce_page_ethernet_get_type (), NULL)); |
214 |
|
|
|
215 |
|
✗ |
self->client = client; |
216 |
|
✗ |
self->setting_connection = nm_connection_get_setting_connection (connection); |
217 |
|
✗ |
self->setting_wired = nm_connection_get_setting_wired (connection); |
218 |
|
|
|
219 |
|
✗ |
connect_ethernet_page (self); |
220 |
|
|
|
221 |
|
✗ |
return self; |
222 |
|
|
} |
223 |
|
|
|