Line | Branch | Exec | Source |
---|---|---|---|
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- | ||
2 | * | ||
3 | * Copyright (C) 2011-2012 Richard Hughes <richard@hughsie.com> | ||
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-object.h> | ||
25 | #include <glib/gi18n.h> | ||
26 | #include <NetworkManager.h> | ||
27 | |||
28 | #include "panel-common.h" | ||
29 | |||
30 | #include "connection-editor/net-connection-editor.h" | ||
31 | #include "connection-editor/ce-page.h" | ||
32 | |||
33 | #include "net-device-ethernet.h" | ||
34 | |||
35 | struct _NetDeviceEthernet | ||
36 | { | ||
37 | AdwPreferencesGroup parent; | ||
38 | |||
39 | GtkListBox *connection_list; | ||
40 | GtkStack *connection_stack; | ||
41 | GtkButton *details_button; | ||
42 | GtkListBox *details_listbox; | ||
43 | AdwActionRow *details_row; | ||
44 | GtkSwitch *device_off_switch; | ||
45 | |||
46 | NMClient *client; | ||
47 | NMDevice *device; | ||
48 | gboolean updating_device; | ||
49 | GHashTable *connections; | ||
50 | }; | ||
51 | |||
52 |
6/7✓ Branch 0 taken 1 times.
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 73 times.
|
152 | G_DEFINE_TYPE (NetDeviceEthernet, net_device_ethernet, ADW_TYPE_PREFERENCES_GROUP) |
53 | |||
54 | static void | ||
55 | 1 | add_details_row (GtkWidget *details, gint top, const gchar *heading, const gchar *value) | |
56 | { | ||
57 | GtkWidget *heading_label; | ||
58 | GtkWidget *value_label; | ||
59 | |||
60 | 1 | heading_label = gtk_label_new (heading); | |
61 | 1 | gtk_widget_add_css_class (heading_label, "dim-label"); | |
62 | 1 | gtk_widget_set_halign (heading_label, GTK_ALIGN_END); | |
63 | 1 | gtk_widget_set_valign (heading_label, GTK_ALIGN_START); | |
64 | 1 | gtk_widget_set_hexpand (heading_label, TRUE); | |
65 | |||
66 | 1 | gtk_grid_attach (GTK_GRID (details), heading_label, 0, top, 1, 1); | |
67 | |||
68 | 1 | value_label = gtk_label_new (value); | |
69 | 1 | gtk_widget_set_halign (value_label, GTK_ALIGN_START); | |
70 | 1 | gtk_widget_set_hexpand (value_label, TRUE); | |
71 | 1 | gtk_label_set_selectable (GTK_LABEL (value_label), TRUE); | |
72 | |||
73 | 1 | gtk_label_set_mnemonic_widget (GTK_LABEL (heading_label), value_label); | |
74 | |||
75 | 1 | gtk_grid_attach (GTK_GRID (details), value_label, 1, top, 1, 1); | |
76 | 1 | } | |
77 | |||
78 | static gchar * | ||
79 | ✗ | get_last_used_string (NMConnection *connection) | |
80 | { | ||
81 | ✗ | g_autoptr(GDateTime) now = NULL; | |
82 | ✗ | g_autoptr(GDateTime) then = NULL; | |
83 | gint days; | ||
84 | GTimeSpan diff; | ||
85 | guint64 timestamp; | ||
86 | NMSettingConnection *s_con; | ||
87 | |||
88 | ✗ | s_con = nm_connection_get_setting_connection (connection); | |
89 | ✗ | if (s_con == NULL) | |
90 | ✗ | return NULL; | |
91 | ✗ | timestamp = nm_setting_connection_get_timestamp (s_con); | |
92 | ✗ | if (timestamp == 0) | |
93 | ✗ | return g_strdup (_("never")); | |
94 | |||
95 | /* calculate the amount of time that has elapsed */ | ||
96 | ✗ | now = g_date_time_new_now_utc (); | |
97 | ✗ | then = g_date_time_new_from_unix_utc (timestamp); | |
98 | ✗ | diff = g_date_time_difference (now, then); | |
99 | ✗ | days = diff / G_TIME_SPAN_DAY; | |
100 | ✗ | if (days == 0) | |
101 | ✗ | return g_strdup (_("today")); | |
102 | ✗ | else if (days == 1) | |
103 | ✗ | return g_strdup (_("yesterday")); | |
104 | else | ||
105 | ✗ | return g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days); | |
106 | } | ||
107 | |||
108 | static void | ||
109 | 1 | add_details (GtkWidget *details, NMDevice *device, NMConnection *connection) | |
110 | { | ||
111 | 1 | NMIPConfig *ip4_config = NULL; | |
112 | 1 | NMIPConfig *ip6_config = NULL; | |
113 | 1 | const gchar *ip4_address = NULL; | |
114 | 1 | const gchar *ip4_route = NULL; | |
115 | 1 | g_autofree gchar *ip4_dns = NULL; | |
116 | 1 | g_autofree gchar *ip6_addresses = NULL; | |
117 | 1 | const gchar *ip6_route = NULL; | |
118 | 1 | g_autofree gchar *ip6_dns = NULL; | |
119 | 1 | gint i = 0; | |
120 | |||
121 | 1 | ip4_config = nm_device_get_ip4_config (device); | |
122 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ip4_config) { |
123 | GPtrArray *addresses; | ||
124 | |||
125 | ✗ | addresses = nm_ip_config_get_addresses (ip4_config); | |
126 | ✗ | if (addresses->len > 0) | |
127 | ✗ | ip4_address = nm_ip_address_get_address (g_ptr_array_index (addresses, 0)); | |
128 | |||
129 | ✗ | ip4_route = nm_ip_config_get_gateway (ip4_config); | |
130 | ✗ | ip4_dns = g_strjoinv (" ", (char **) nm_ip_config_get_nameservers (ip4_config)); | |
131 | ✗ | if (!*ip4_dns) | |
132 | ✗ | ip4_dns = NULL; | |
133 | } | ||
134 | 1 | ip6_config = nm_device_get_ip6_config (device); | |
135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ip6_config) { |
136 | ✗ | ip6_addresses = net_device_get_ip6_addresses (ip6_config); | |
137 | ✗ | ip6_route = nm_ip_config_get_gateway (ip6_config); | |
138 | ✗ | ip6_dns = g_strjoinv (" ", (char **) nm_ip_config_get_nameservers (ip6_config)); | |
139 | ✗ | if (!*ip6_dns) | |
140 | ✗ | ip6_dns = NULL; | |
141 | } | ||
142 | |||
143 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | if (ip4_address && ip6_addresses) { |
144 | ✗ | add_details_row (details, i++, _("IPv4 Address"), ip4_address); | |
145 | ✗ | gtk_widget_set_valign (details, GTK_ALIGN_START); | |
146 | ✗ | add_details_row (details, i++, _("IPv6 Address"), ip6_addresses); | |
147 | ✗ | gtk_widget_set_valign (details, GTK_ALIGN_START); | |
148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (ip4_address) { |
149 | ✗ | add_details_row (details, i++, _("IP Address"), ip4_address); | |
150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (ip6_addresses) { |
151 | ✗ | add_details_row (details, i++, _("IP Address"), ip6_addresses); | |
152 | } | ||
153 | |||
154 | 1 | add_details_row (details, i++, _("Hardware Address"), nm_device_get_hw_address (device)); | |
155 | |||
156 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | if (ip4_route && ip6_route) { |
157 | ✗ | g_autofree gchar *ip_routes = g_strjoin ("\n", ip4_route, ip6_route, NULL); | |
158 | ✗ | add_details_row (details, i++, _("Default Route"), ip_routes); | |
159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (ip4_route) { |
160 | ✗ | add_details_row (details, i++, _("Default Route"), ip4_route); | |
161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (ip6_route) { |
162 | ✗ | add_details_row (details, i++, _("Default Route"), ip6_route); | |
163 | } | ||
164 | |||
165 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | if (ip4_dns && ip6_dns) { |
166 | ✗ | add_details_row (details, i++, _("DNS4"), ip4_dns); | |
167 | ✗ | add_details_row (details, i++, _("DNS6"), ip6_dns); | |
168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (ip4_dns) { |
169 | ✗ | add_details_row (details, i++, _("DNS"), ip4_dns); | |
170 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (ip6_dns) { |
171 | ✗ | add_details_row (details, i++, _("DNS"), ip6_dns); | |
172 | } | ||
173 | |||
174 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED) { |
175 | ✗ | g_autofree gchar *last_used = NULL; | |
176 | ✗ | last_used = get_last_used_string (connection); | |
177 | ✗ | add_details_row (details, i++, _("Last used"), last_used); | |
178 | } | ||
179 | 1 | } | |
180 | |||
181 | static void populate_ui (NetDeviceEthernet *self); | ||
182 | |||
183 | static gboolean | ||
184 | 22 | device_state_to_off_switch (NMDeviceState state) | |
185 | { | ||
186 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
|
22 | switch (state) { |
187 | 20 | case NM_DEVICE_STATE_UNMANAGED: | |
188 | case NM_DEVICE_STATE_UNAVAILABLE: | ||
189 | case NM_DEVICE_STATE_DISCONNECTED: | ||
190 | case NM_DEVICE_STATE_DEACTIVATING: | ||
191 | case NM_DEVICE_STATE_FAILED: | ||
192 | 20 | return FALSE; | |
193 | 2 | default: | |
194 | 2 | return TRUE; | |
195 | } | ||
196 | } | ||
197 | |||
198 | static void | ||
199 | 22 | device_ethernet_refresh_ui (NetDeviceEthernet *self) | |
200 | { | ||
201 | NMDeviceState state; | ||
202 | 22 | g_autofree gchar *speed_text = NULL; | |
203 | 22 | g_autofree gchar *status = NULL; | |
204 | |||
205 | 22 | state = nm_device_get_state (self->device); | |
206 |
3/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
22 | gtk_widget_set_sensitive (GTK_WIDGET (self->device_off_switch), |
207 | state != NM_DEVICE_STATE_UNAVAILABLE | ||
208 | && state != NM_DEVICE_STATE_UNMANAGED); | ||
209 | 22 | self->updating_device = TRUE; | |
210 | 22 | gtk_switch_set_active (self->device_off_switch, device_state_to_off_switch (state)); | |
211 | 22 | self->updating_device = FALSE; | |
212 | |||
213 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 15 times.
|
22 | if (state != NM_DEVICE_STATE_UNAVAILABLE) { |
214 | 7 | guint speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (self->device)); | |
215 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (speed > 0) { |
216 | /* Translators: the %'d is replaced by the network device speed with | ||
217 | * thousands separator, so do not change to %d */ | ||
218 | 7 | speed_text = g_strdup_printf (_("%'d Mb/s"), speed); | |
219 | } | ||
220 | } | ||
221 | 22 | status = panel_device_status_to_localized_string (self->device, speed_text); | |
222 | 22 | adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self->details_row), status); | |
223 | |||
224 | 22 | populate_ui (self); | |
225 | 22 | } | |
226 | |||
227 | static void | ||
228 | ✗ | editor_done (NetDeviceEthernet *self) | |
229 | { | ||
230 | ✗ | device_ethernet_refresh_ui (self); | |
231 | ✗ | } | |
232 | |||
233 | static void | ||
234 | ✗ | show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title) | |
235 | { | ||
236 | GtkWidget *row; | ||
237 | NMConnection *connection; | ||
238 | NetConnectionEditor *editor; | ||
239 | |||
240 | ✗ | row = g_object_get_data (G_OBJECT (button), "row"); | |
241 | ✗ | connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection")); | |
242 | |||
243 | ✗ | editor = net_connection_editor_new (connection, self->device, NULL, self->client); | |
244 | ✗ | gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_native (GTK_WIDGET (self)))); | |
245 | ✗ | if (title) | |
246 | ✗ | net_connection_editor_set_title (editor, title); | |
247 | ✗ | g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); | |
248 | ✗ | gtk_window_present (GTK_WINDOW (editor)); | |
249 | ✗ | } | |
250 | |||
251 | static void | ||
252 | ✗ | show_details_for_row (NetDeviceEthernet *self, GtkButton *button) | |
253 | { | ||
254 | ✗ | show_details (self, button, NULL); | |
255 | ✗ | } | |
256 | |||
257 | static void | ||
258 | ✗ | details_button_clicked_cb (NetDeviceEthernet *self) | |
259 | { | ||
260 | /* Translators: This is used as the title of the connection | ||
261 | * details window for ethernet, if there is only a single | ||
262 | * profile. It is also used to display ethernet in the | ||
263 | * device list. | ||
264 | */ | ||
265 | ✗ | show_details (self, self->details_button, _("Wired")); | |
266 | ✗ | } | |
267 | |||
268 | static void | ||
269 | 4 | add_row (NetDeviceEthernet *self, NMConnection *connection) | |
270 | { | ||
271 | GtkWidget *row; | ||
272 | GtkWidget *widget; | ||
273 | GtkWidget *box; | ||
274 | GtkWidget *details; | ||
275 | NMActiveConnection *aconn; | ||
276 | gboolean active; | ||
277 | |||
278 | 4 | active = FALSE; | |
279 | |||
280 | 4 | aconn = nm_device_get_active_connection (self->device); | |
281 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (aconn) { |
282 | const gchar *uuid1, *uuid2; | ||
283 | 2 | uuid1 = nm_active_connection_get_uuid (aconn); | |
284 | 2 | uuid2 = nm_connection_get_uuid (connection); | |
285 | 2 | active = g_strcmp0 (uuid1, uuid2) == 0; | |
286 | } | ||
287 | |||
288 | 4 | row = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); | |
289 | 4 | box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); | |
290 | 4 | gtk_box_append (GTK_BOX (row), box); | |
291 | 4 | widget = gtk_label_new (nm_connection_get_id (connection)); | |
292 | 4 | gtk_widget_set_margin_start (widget, 12); | |
293 | 4 | gtk_widget_set_margin_end (widget, 12); | |
294 | 4 | gtk_widget_set_margin_top (widget, 8); | |
295 | 4 | gtk_widget_set_margin_bottom (widget, 8); | |
296 | 4 | gtk_box_append (GTK_BOX (box), widget); | |
297 | |||
298 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (active) { |
299 | 1 | widget = gtk_image_new_from_icon_name ("object-select-symbolic"); | |
300 | 1 | gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); | |
301 | 1 | gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); | |
302 | 1 | gtk_box_append (GTK_BOX (box), widget); | |
303 | |||
304 | 1 | details = gtk_grid_new (); | |
305 | 1 | gtk_grid_set_row_spacing (GTK_GRID (details), 10); | |
306 | 1 | gtk_grid_set_column_spacing (GTK_GRID (details), 10); | |
307 | |||
308 | 1 | gtk_box_append (GTK_BOX (row), details); | |
309 | |||
310 | 1 | add_details (details, self->device, connection); | |
311 | } | ||
312 | |||
313 | /* filler */ | ||
314 | 4 | widget = gtk_label_new (""); | |
315 | 4 | gtk_widget_set_hexpand (widget, TRUE); | |
316 | 4 | gtk_box_append (GTK_BOX (box), widget); | |
317 | |||
318 | 4 | widget = gtk_button_new_from_icon_name ("emblem-system-symbolic"); | |
319 | 4 | gtk_widget_set_margin_start (widget, 12); | |
320 | 4 | gtk_widget_set_margin_end (widget, 12); | |
321 | 4 | gtk_widget_set_margin_top (widget, 8); | |
322 | 4 | gtk_widget_set_margin_bottom (widget, 8); | |
323 | 4 | gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); | |
324 | 4 | gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); | |
325 | 4 | gtk_accessible_update_property (GTK_ACCESSIBLE (widget), | |
326 | GTK_ACCESSIBLE_PROPERTY_LABEL, _("Options…"), | ||
327 | -1); | ||
328 | 4 | gtk_box_append (GTK_BOX (box), widget); | |
329 | 4 | g_object_set_data (G_OBJECT (widget), "edit", widget); | |
330 | 4 | g_object_set_data (G_OBJECT (widget), "row", row); | |
331 | 4 | g_signal_connect_object (widget, "clicked", G_CALLBACK (show_details_for_row), self, G_CONNECT_SWAPPED); | |
332 | |||
333 | 4 | g_object_set_data (G_OBJECT (row), "connection", connection); | |
334 | |||
335 | 4 | gtk_list_box_append (self->connection_list, row); | |
336 | 4 | } | |
337 | |||
338 | static void | ||
339 | ✗ | connection_removed (NetDeviceEthernet *self, NMRemoteConnection *connection) | |
340 | { | ||
341 | ✗ | if (g_hash_table_remove (self->connections, connection)) | |
342 | ✗ | device_ethernet_refresh_ui (self); | |
343 | ✗ | } | |
344 | |||
345 | static void | ||
346 | 22 | populate_ui (NetDeviceEthernet *self) | |
347 | { | ||
348 | GSList *connections, *l; | ||
349 | NMConnection *connection; | ||
350 | GtkWidget *child; | ||
351 | gint n_connections; | ||
352 | |||
353 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 3 taken 22 times.
|
24 | while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->connection_list))) != NULL) |
354 | 2 | gtk_list_box_remove (self->connection_list, child); | |
355 | |||
356 | 22 | connections = net_device_get_valid_connections (self->client, self->device); | |
357 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 22 times.
|
31 | for (l = connections; l; l = l->next) { |
358 | 9 | NMConnection *connection = l->data; | |
359 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 5 times.
|
9 | if (!g_hash_table_contains (self->connections, connection)) { |
360 | 4 | g_hash_table_add (self->connections, connection); | |
361 | } | ||
362 | } | ||
363 | 22 | n_connections = g_slist_length (connections); | |
364 | |||
365 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
|
22 | if (n_connections > 1) { |
366 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | for (l = connections; l; l = l->next) { |
367 | 4 | NMConnection *connection = l->data; | |
368 | 4 | add_row (self, connection); | |
369 | } | ||
370 | 2 | gtk_stack_set_visible_child (self->connection_stack, | |
371 | 2 | GTK_WIDGET (self->connection_list)); | |
372 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15 times.
|
20 | } else if (n_connections == 1) { |
373 | 5 | connection = connections->data; | |
374 | 5 | gtk_stack_set_visible_child (self->connection_stack, | |
375 | 5 | GTK_WIDGET (self->details_listbox)); | |
376 | 5 | g_object_set_data (G_OBJECT (self->details_button), "row", self->details_button); | |
377 | 5 | g_object_set_data (G_OBJECT (self->details_button), "connection", connection); | |
378 | |||
379 | } | ||
380 | |||
381 | 22 | gtk_widget_set_visible (GTK_WIDGET (self->connection_stack), n_connections >= 1); | |
382 | |||
383 | 22 | g_slist_free (connections); | |
384 | 22 | } | |
385 | |||
386 | static void | ||
387 | 4 | client_connection_added_cb (NetDeviceEthernet *self) | |
388 | { | ||
389 | 4 | device_ethernet_refresh_ui (self); | |
390 | 4 | } | |
391 | |||
392 | static void | ||
393 | ✗ | add_profile_button_clicked_cb (NetDeviceEthernet *self) | |
394 | { | ||
395 | NMConnection *connection; | ||
396 | NMSettingConnection *sc; | ||
397 | ✗ | g_autofree gchar *uuid = NULL; | |
398 | ✗ | g_autofree gchar *id = NULL; | |
399 | NetConnectionEditor *editor; | ||
400 | const GPtrArray *connections; | ||
401 | const char *iface; | ||
402 | |||
403 | ✗ | connection = nm_simple_connection_new (); | |
404 | ✗ | sc = NM_SETTING_CONNECTION (nm_setting_connection_new ()); | |
405 | ✗ | nm_connection_add_setting (connection, NM_SETTING (sc)); | |
406 | |||
407 | ✗ | uuid = nm_utils_uuid_generate (); | |
408 | |||
409 | ✗ | connections = nm_client_get_connections (self->client); | |
410 | ✗ | id = ce_page_get_next_available_name (connections, NAME_FORMAT_PROFILE, NULL); | |
411 | |||
412 | ✗ | g_object_set (sc, | |
413 | NM_SETTING_CONNECTION_UUID, uuid, | ||
414 | NM_SETTING_CONNECTION_ID, id, | ||
415 | NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, | ||
416 | NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, | ||
417 | NULL); | ||
418 | |||
419 | ✗ | iface = nm_device_get_iface (self->device); | |
420 | ✗ | g_object_set (sc, | |
421 | NM_SETTING_CONNECTION_INTERFACE_NAME, iface, | ||
422 | NULL); | ||
423 | |||
424 | ✗ | nm_connection_add_setting (connection, nm_setting_wired_new ()); | |
425 | |||
426 | ✗ | editor = net_connection_editor_new (connection, self->device, NULL, self->client); | |
427 | ✗ | gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_native (GTK_WIDGET (self)))); | |
428 | ✗ | g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED); | |
429 | ✗ | gtk_window_present (GTK_WINDOW (editor)); | |
430 | ✗ | } | |
431 | |||
432 | static void | ||
433 | 3 | device_off_switch_changed_cb (NetDeviceEthernet *self) | |
434 | { | ||
435 | NMConnection *connection; | ||
436 | |||
437 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (self->updating_device) |
438 | 2 | return; | |
439 | |||
440 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (gtk_switch_get_active (self->device_off_switch)) { |
441 | ✗ | connection = net_device_get_find_connection (self->client, self->device); | |
442 | ✗ | if (connection != NULL) { | |
443 | ✗ | nm_client_activate_connection_async (self->client, | |
444 | connection, | ||
445 | self->device, | ||
446 | NULL, NULL, NULL, NULL); | ||
447 | } | ||
448 | } else { | ||
449 | 1 | nm_device_disconnect_async (self->device, NULL, NULL, NULL); | |
450 | } | ||
451 | } | ||
452 | |||
453 | static void | ||
454 | ✗ | connection_list_row_activated_cb (NetDeviceEthernet *self, GtkListBoxRow *row) | |
455 | { | ||
456 | NMConnection *connection; | ||
457 | GtkWidget *child; | ||
458 | |||
459 | ✗ | if (!NM_IS_DEVICE_ETHERNET (self->device) || | |
460 | ✗ | !nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (self->device))) | |
461 | ✗ | return; | |
462 | |||
463 | ✗ | child = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (row)); | |
464 | ✗ | connection = NM_CONNECTION (g_object_get_data (G_OBJECT (child), "connection")); | |
465 | |||
466 | ✗ | nm_client_activate_connection_async (self->client, | |
467 | connection, | ||
468 | self->device, | ||
469 | NULL, NULL, NULL, NULL); | ||
470 | } | ||
471 | |||
472 | static void | ||
473 | 13 | device_ethernet_finalize (GObject *object) | |
474 | { | ||
475 | 13 | NetDeviceEthernet *self = NET_DEVICE_ETHERNET (object); | |
476 | |||
477 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | g_clear_object (&self->client); |
478 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | g_clear_object (&self->device); |
479 | 13 | g_hash_table_destroy (self->connections); | |
480 | |||
481 | 13 | G_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object); | |
482 | 13 | } | |
483 | |||
484 | static void | ||
485 | 1 | net_device_ethernet_class_init (NetDeviceEthernetClass *klass) | |
486 | { | ||
487 | 1 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
488 | 1 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); | |
489 | |||
490 | 1 | object_class->finalize = device_ethernet_finalize; | |
491 | |||
492 | 1 | gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/network-ethernet.ui"); | |
493 | |||
494 | 1 | gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, connection_list); | |
495 | 1 | gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, connection_stack); | |
496 | 1 | gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_button); | |
497 | 1 | gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_listbox); | |
498 | 1 | gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_row); | |
499 | 1 | gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, device_off_switch); | |
500 | |||
501 | 1 | gtk_widget_class_bind_template_callback (widget_class, connection_list_row_activated_cb); | |
502 | 1 | gtk_widget_class_bind_template_callback (widget_class, device_off_switch_changed_cb); | |
503 | 1 | gtk_widget_class_bind_template_callback (widget_class, details_button_clicked_cb); | |
504 | 1 | gtk_widget_class_bind_template_callback (widget_class, add_profile_button_clicked_cb); | |
505 | 1 | } | |
506 | |||
507 | static void | ||
508 | 13 | net_device_ethernet_init (NetDeviceEthernet *self) | |
509 | { | ||
510 | 13 | gtk_widget_init_template (GTK_WIDGET (self)); | |
511 | |||
512 | 13 | self->connections = g_hash_table_new (NULL, NULL); | |
513 | 13 | } | |
514 | |||
515 | NetDeviceEthernet * | ||
516 | 13 | net_device_ethernet_new (NMClient *client, NMDevice *device) | |
517 | { | ||
518 | NetDeviceEthernet *self; | ||
519 | |||
520 | 13 | self = g_object_new (net_device_ethernet_get_type (), NULL); | |
521 | 13 | self->client = g_object_ref (client); | |
522 | 13 | self->device = g_object_ref (device); | |
523 | |||
524 | 13 | g_signal_connect_object (client, NM_CLIENT_CONNECTION_ADDED, | |
525 | G_CALLBACK (client_connection_added_cb), self, G_CONNECT_SWAPPED); | ||
526 | 13 | g_signal_connect_object (client, NM_CLIENT_CONNECTION_REMOVED, | |
527 | G_CALLBACK (connection_removed), self, G_CONNECT_SWAPPED); | ||
528 | |||
529 | 13 | g_signal_connect_object (device, "state-changed", G_CALLBACK (device_ethernet_refresh_ui), self, G_CONNECT_SWAPPED); | |
530 | |||
531 | 13 | device_ethernet_refresh_ui (self); | |
532 | |||
533 | 13 | return self; | |
534 | } | ||
535 | |||
536 | NMDevice * | ||
537 | 24 | net_device_ethernet_get_device (NetDeviceEthernet *self) | |
538 | { | ||
539 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
|
24 | g_return_val_if_fail (NET_IS_DEVICE_ETHERNET (self), NULL); |
540 | 24 | return self->device; | |
541 | } | ||
542 |