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 |
|
|
|
26 |
|
|
#include <NetworkManager.h> |
27 |
|
|
|
28 |
|
|
#include "ce-page.h" |
29 |
|
|
#include "ce-page-details.h" |
30 |
|
|
|
31 |
|
|
#include "../panel-common.h" |
32 |
|
|
|
33 |
|
|
struct _CEPageDetails |
34 |
|
|
{ |
35 |
|
|
AdwBin parent; |
36 |
|
|
|
37 |
|
|
GtkCheckButton *all_user_check; |
38 |
|
|
GtkCheckButton *auto_connect_check; |
39 |
|
|
GtkLabel *dns4_heading_label; |
40 |
|
|
GtkLabel *dns4_label; |
41 |
|
|
GtkLabel *dns6_heading_label; |
42 |
|
|
GtkLabel *dns6_label; |
43 |
|
|
GtkButton *forget_button; |
44 |
|
|
GtkLabel *freq_heading_label; |
45 |
|
|
GtkLabel *freq_label; |
46 |
|
|
GtkLabel *ipv4_heading_label; |
47 |
|
|
GtkLabel *ipv4_label; |
48 |
|
|
GtkLabel *ipv6_heading_label; |
49 |
|
|
GtkLabel *ipv6_label; |
50 |
|
|
GtkLabel *last_used_heading_label; |
51 |
|
|
GtkLabel *last_used_label; |
52 |
|
|
GtkLabel *mac_heading_label; |
53 |
|
|
GtkLabel *mac_label; |
54 |
|
|
GtkCheckButton *restrict_data_check; |
55 |
|
|
GtkLabel *route_heading_label; |
56 |
|
|
GtkLabel *route_label; |
57 |
|
|
GtkLabel *security_heading_label; |
58 |
|
|
GtkLabel *security_label; |
59 |
|
|
GtkLabel *speed_heading_label; |
60 |
|
|
GtkLabel *speed_label; |
61 |
|
|
GtkLabel *strength_heading_label; |
62 |
|
|
GtkLabel *strength_label; |
63 |
|
|
|
64 |
|
|
NMConnection *connection; |
65 |
|
|
NMDevice *device; |
66 |
|
|
NMAccessPoint *ap; |
67 |
|
|
NetConnectionEditor *editor; |
68 |
|
|
gboolean is_new_connection; |
69 |
|
|
}; |
70 |
|
|
|
71 |
|
|
static void ce_page_iface_init (CEPageInterface *); |
72 |
|
|
|
73 |
|
✗ |
G_DEFINE_TYPE_WITH_CODE (CEPageDetails, ce_page_details, ADW_TYPE_BIN, |
74 |
|
|
G_IMPLEMENT_INTERFACE (ce_page_get_type (), ce_page_iface_init)) |
75 |
|
|
|
76 |
|
|
static void |
77 |
|
✗ |
on_forget_cb (CEPageDetails *self, |
78 |
|
|
gchar *response) |
79 |
|
|
{ |
80 |
|
✗ |
if (g_strcmp0 (response, "forget") == 0) |
81 |
|
✗ |
net_connection_editor_forget (self->editor); |
82 |
|
✗ |
} |
83 |
|
|
|
84 |
|
|
static void |
85 |
|
✗ |
forget_cb (CEPageDetails *self) |
86 |
|
|
{ |
87 |
|
|
GtkWidget *dialog; |
88 |
|
|
GtkNative *native; |
89 |
|
✗ |
g_autofree gchar *message = NULL; |
90 |
|
|
|
91 |
|
✗ |
native = gtk_widget_get_native (GTK_WIDGET (self)); |
92 |
|
|
/* Translators: "%s" is the user visible name of the network */ |
93 |
|
✗ |
message = g_strdup_printf (_("Saved details for “%s” will be permanently lost. This includes passwords and any network changes."), |
94 |
|
|
nm_connection_get_id (self->connection)); |
95 |
|
✗ |
dialog = adw_message_dialog_new (GTK_WINDOW (native), |
96 |
|
✗ |
_("Forget Connection?"), |
97 |
|
|
message); |
98 |
|
|
|
99 |
|
✗ |
adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog), |
100 |
|
|
"cancel", _("_Cancel"), |
101 |
|
|
"forget", _("Forget"), |
102 |
|
|
NULL); |
103 |
|
✗ |
adw_message_dialog_set_response_appearance (ADW_MESSAGE_DIALOG (dialog), |
104 |
|
|
"forget", |
105 |
|
|
ADW_RESPONSE_DESTRUCTIVE); |
106 |
|
✗ |
adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG (dialog), "cancel"); |
107 |
|
✗ |
adw_message_dialog_set_close_response (ADW_MESSAGE_DIALOG (dialog), "cancel"); |
108 |
|
|
|
109 |
|
✗ |
g_signal_connect_swapped (dialog, "response", G_CALLBACK (on_forget_cb), self); |
110 |
|
✗ |
gtk_window_present (GTK_WINDOW (dialog)); |
111 |
|
✗ |
} |
112 |
|
|
|
113 |
|
|
static gchar * |
114 |
|
✗ |
get_ap_security_string (NMAccessPoint *ap) |
115 |
|
|
{ |
116 |
|
|
NM80211ApSecurityFlags wpa_flags, rsn_flags; |
117 |
|
|
NM80211ApFlags flags; |
118 |
|
|
GString *str; |
119 |
|
|
|
120 |
|
✗ |
flags = nm_access_point_get_flags (ap); |
121 |
|
✗ |
wpa_flags = nm_access_point_get_wpa_flags (ap); |
122 |
|
✗ |
rsn_flags = nm_access_point_get_rsn_flags (ap); |
123 |
|
|
|
124 |
|
✗ |
str = g_string_new (""); |
125 |
|
✗ |
if ((flags & NM_802_11_AP_FLAGS_PRIVACY) && |
126 |
|
✗ |
(wpa_flags == NM_802_11_AP_SEC_NONE) && |
127 |
|
|
(rsn_flags == NM_802_11_AP_SEC_NONE)) { |
128 |
|
|
/* TRANSLATORS: this WEP WiFi security */ |
129 |
|
✗ |
g_string_append_printf (str, "%s, ", _("WEP")); |
130 |
|
|
} |
131 |
|
✗ |
if (wpa_flags != NM_802_11_AP_SEC_NONE) { |
132 |
|
|
/* TRANSLATORS: this WPA WiFi security */ |
133 |
|
✗ |
g_string_append_printf (str, "%s, ", _("WPA")); |
134 |
|
|
} |
135 |
|
✗ |
if (rsn_flags != NM_802_11_AP_SEC_NONE) { |
136 |
|
|
#if NM_CHECK_VERSION(1,20,6) |
137 |
|
✗ |
if (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_SAE) { |
138 |
|
|
/* TRANSLATORS: this WPA3 WiFi security */ |
139 |
|
✗ |
g_string_append_printf (str, "%s, ", _("WPA3")); |
140 |
|
|
} |
141 |
|
|
#if NM_CHECK_VERSION(1,24,0) |
142 |
|
✗ |
else if (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_OWE) { |
143 |
|
|
/* TRANSLATORS: this Enhanced Open WiFi security */ |
144 |
|
✗ |
g_string_append_printf (str, "%s, ", _("Enhanced Open")); |
145 |
|
|
} |
146 |
|
|
#endif |
147 |
|
|
#if NM_CHECK_VERSION(1,26,0) |
148 |
|
✗ |
else if (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_OWE_TM) { |
149 |
|
|
/* Connected to open OWE-TM network. */ |
150 |
|
|
} |
151 |
|
|
#endif |
152 |
|
|
else |
153 |
|
|
#endif |
154 |
|
|
{ |
155 |
|
|
/* TRANSLATORS: this WPA WiFi security */ |
156 |
|
✗ |
g_string_append_printf (str, "%s, ", _("WPA2")); |
157 |
|
|
} |
158 |
|
|
} |
159 |
|
✗ |
if ((wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) || |
160 |
|
✗ |
(rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { |
161 |
|
|
/* TRANSLATORS: this Enterprise WiFi security */ |
162 |
|
✗ |
g_string_append_printf (str, "%s, ", _("Enterprise")); |
163 |
|
|
} |
164 |
|
✗ |
if (str->len > 0) |
165 |
|
✗ |
g_string_set_size (str, str->len - 2); |
166 |
|
|
else { |
167 |
|
✗ |
g_string_append (str, C_("Wifi security", "None")); |
168 |
|
|
} |
169 |
|
✗ |
return g_string_free (str, FALSE); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
static void |
173 |
|
✗ |
update_last_used (CEPageDetails *self, NMConnection *connection) |
174 |
|
|
{ |
175 |
|
✗ |
g_autofree gchar *last_used = NULL; |
176 |
|
✗ |
g_autoptr(GDateTime) now = NULL; |
177 |
|
✗ |
g_autoptr(GDateTime) then = NULL; |
178 |
|
|
gint days; |
179 |
|
|
GTimeSpan diff; |
180 |
|
|
guint64 timestamp; |
181 |
|
|
NMSettingConnection *s_con; |
182 |
|
|
|
183 |
|
✗ |
s_con = nm_connection_get_setting_connection (connection); |
184 |
|
✗ |
if (s_con == NULL) |
185 |
|
✗ |
goto out; |
186 |
|
✗ |
timestamp = nm_setting_connection_get_timestamp (s_con); |
187 |
|
✗ |
if (timestamp == 0) { |
188 |
|
✗ |
last_used = g_strdup (_("Never")); |
189 |
|
✗ |
goto out; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
/* calculate the amount of time that has elapsed */ |
193 |
|
✗ |
now = g_date_time_new_now_utc (); |
194 |
|
✗ |
then = g_date_time_new_from_unix_utc (timestamp); |
195 |
|
|
|
196 |
|
✗ |
diff = g_date_time_difference (now, then); |
197 |
|
✗ |
days = diff / G_TIME_SPAN_DAY; |
198 |
|
✗ |
if (days == 0) |
199 |
|
✗ |
last_used = g_strdup (_("Today")); |
200 |
|
✗ |
else if (days == 1) |
201 |
|
✗ |
last_used = g_strdup (_("Yesterday")); |
202 |
|
|
else |
203 |
|
✗ |
last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days); |
204 |
|
✗ |
out: |
205 |
|
✗ |
gtk_label_set_label (self->last_used_label, last_used); |
206 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->last_used_heading_label), last_used != NULL); |
207 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->last_used_label), last_used != NULL); |
208 |
|
✗ |
} |
209 |
|
|
|
210 |
|
|
static void |
211 |
|
✗ |
all_user_changed (CEPageDetails *self) |
212 |
|
|
{ |
213 |
|
|
gboolean all_users; |
214 |
|
|
NMSettingConnection *sc; |
215 |
|
|
|
216 |
|
✗ |
sc = nm_connection_get_setting_connection (self->connection); |
217 |
|
✗ |
all_users = gtk_check_button_get_active (GTK_CHECK_BUTTON (self->all_user_check)); |
218 |
|
|
|
219 |
|
✗ |
g_object_set (sc, "permissions", NULL, NULL); |
220 |
|
✗ |
if (!all_users) |
221 |
|
✗ |
nm_setting_connection_add_permission (sc, "user", g_get_user_name (), NULL); |
222 |
|
✗ |
} |
223 |
|
|
|
224 |
|
|
static void |
225 |
|
✗ |
restrict_data_changed (CEPageDetails *self) |
226 |
|
|
{ |
227 |
|
|
NMSettingConnection *s_con; |
228 |
|
|
NMMetered metered; |
229 |
|
|
|
230 |
|
✗ |
s_con = nm_connection_get_setting_connection (self->connection); |
231 |
|
|
|
232 |
|
✗ |
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (self->restrict_data_check))) |
233 |
|
✗ |
metered = NM_METERED_YES; |
234 |
|
|
else |
235 |
|
✗ |
metered = NM_METERED_NO; |
236 |
|
|
|
237 |
|
✗ |
g_object_set (s_con, "metered", metered, NULL); |
238 |
|
✗ |
} |
239 |
|
|
|
240 |
|
|
static void |
241 |
|
✗ |
update_restrict_data (CEPageDetails *self) |
242 |
|
|
{ |
243 |
|
|
NMSettingConnection *s_con; |
244 |
|
|
NMMetered metered; |
245 |
|
|
const gchar *type; |
246 |
|
|
|
247 |
|
✗ |
s_con = nm_connection_get_setting_connection (self->connection); |
248 |
|
|
|
249 |
|
✗ |
if (s_con == NULL) |
250 |
|
✗ |
return; |
251 |
|
|
|
252 |
|
|
/* Disable for VPN; NetworkManager does not implement that yet (see |
253 |
|
|
* bug https://bugzilla.gnome.org/show_bug.cgi?id=792618) */ |
254 |
|
✗ |
type = nm_setting_connection_get_connection_type (s_con); |
255 |
|
✗ |
if (g_str_equal (type, NM_SETTING_VPN_SETTING_NAME) || |
256 |
|
✗ |
g_str_equal (type, NM_SETTING_WIREGUARD_SETTING_NAME)) { |
257 |
|
✗ |
gtk_widget_set_visible(GTK_WIDGET (self->restrict_data_check), FALSE); |
258 |
|
✗ |
return; |
259 |
|
|
} |
260 |
|
|
|
261 |
|
✗ |
metered = nm_setting_connection_get_metered (s_con); |
262 |
|
|
|
263 |
|
✗ |
gtk_check_button_set_active (GTK_CHECK_BUTTON (self->restrict_data_check), |
264 |
|
|
metered == NM_METERED_YES || metered == NM_METERED_GUESS_YES); |
265 |
|
|
|
266 |
|
✗ |
g_signal_connect_object (self->restrict_data_check, "notify::active", G_CALLBACK (restrict_data_changed), self, G_CONNECT_SWAPPED); |
267 |
|
✗ |
g_signal_connect_object (self->restrict_data_check, "notify::active", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
268 |
|
|
} |
269 |
|
|
|
270 |
|
|
static void |
271 |
|
✗ |
connect_details_page (CEPageDetails *self) |
272 |
|
|
{ |
273 |
|
|
NMSettingConnection *sc; |
274 |
|
|
guint speed; |
275 |
|
|
NMDeviceWifiCapabilities wifi_caps; |
276 |
|
|
guint frequency; |
277 |
|
|
guint strength; |
278 |
|
|
NMDeviceState state; |
279 |
|
|
NMAccessPoint *active_ap; |
280 |
|
✗ |
g_autofree gchar *speed_label = NULL; |
281 |
|
|
const gchar *type; |
282 |
|
✗ |
const gchar *hw_address = NULL; |
283 |
|
✗ |
g_autofree gchar *security_string = NULL; |
284 |
|
✗ |
const gchar *freq_string = NULL; |
285 |
|
|
const gchar *strength_label; |
286 |
|
|
gboolean device_is_active; |
287 |
|
✗ |
NMIPConfig *ipv4_config = NULL, *ipv6_config = NULL; |
288 |
|
✗ |
gboolean have_ipv4_address = FALSE, have_ipv6_address = FALSE; |
289 |
|
✗ |
gboolean have_dns4 = FALSE, have_dns6 = FALSE; |
290 |
|
✗ |
const gchar *route4_text = NULL, *route6_text = NULL; |
291 |
|
|
|
292 |
|
✗ |
sc = nm_connection_get_setting_connection (self->connection); |
293 |
|
✗ |
type = nm_setting_connection_get_connection_type (sc); |
294 |
|
|
|
295 |
|
✗ |
if (NM_IS_DEVICE_WIFI (self->device)) |
296 |
|
✗ |
active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (self->device)); |
297 |
|
|
else |
298 |
|
✗ |
active_ap = NULL; |
299 |
|
✗ |
frequency = active_ap ? nm_access_point_get_frequency (active_ap) : 0; |
300 |
|
|
|
301 |
|
✗ |
state = self->device ? nm_device_get_state (self->device) : NM_DEVICE_STATE_DISCONNECTED; |
302 |
|
|
|
303 |
|
✗ |
device_is_active = FALSE; |
304 |
|
✗ |
speed = 0; |
305 |
|
✗ |
wifi_caps = 0; |
306 |
|
✗ |
if (active_ap && self->ap == active_ap && state != NM_DEVICE_STATE_UNAVAILABLE) { |
307 |
|
✗ |
device_is_active = TRUE; |
308 |
|
✗ |
if (NM_IS_DEVICE_WIFI (self->device)) { |
309 |
|
✗ |
speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (self->device)) / 1000; |
310 |
|
✗ |
wifi_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (self->device)); |
311 |
|
|
} |
312 |
|
✗ |
} else if (self->device) { |
313 |
|
|
NMActiveConnection *ac; |
314 |
|
|
const gchar *p1, *p2; |
315 |
|
|
|
316 |
|
✗ |
ac = nm_device_get_active_connection (self->device); |
317 |
|
✗ |
p1 = ac ? nm_active_connection_get_uuid (ac) : NULL; |
318 |
|
✗ |
p2 = nm_connection_get_uuid (self->connection); |
319 |
|
✗ |
if (g_strcmp0 (p1, p2) == 0) { |
320 |
|
✗ |
device_is_active = TRUE; |
321 |
|
✗ |
if (NM_IS_DEVICE_WIFI (self->device)) { |
322 |
|
✗ |
speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (self->device)) / 1000; |
323 |
|
✗ |
wifi_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (self->device)); |
324 |
|
✗ |
} else if (NM_IS_DEVICE_ETHERNET (self->device)) |
325 |
|
✗ |
speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (self->device)); |
326 |
|
|
} |
327 |
|
|
} |
328 |
|
|
|
329 |
|
✗ |
if (speed > 0 && frequency > 0) |
330 |
|
✗ |
speed_label = g_strdup_printf (_("%d Mb/s (%1.1f GHz)"), speed, (float) (frequency) / 1000.0); |
331 |
|
✗ |
else if (speed > 0) |
332 |
|
✗ |
speed_label = g_strdup_printf (_("%d Mb/s"), speed); |
333 |
|
✗ |
gtk_label_set_label (self->speed_label, speed_label); |
334 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->speed_heading_label), speed_label != NULL); |
335 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->speed_label), speed_label != NULL); |
336 |
|
|
|
337 |
|
✗ |
if (self->device) |
338 |
|
✗ |
hw_address = nm_device_get_hw_address (self->device); |
339 |
|
|
|
340 |
|
✗ |
gtk_label_set_label (self->mac_label, hw_address); |
341 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->mac_heading_label), hw_address != NULL); |
342 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->mac_label), hw_address != NULL); |
343 |
|
|
|
344 |
|
✗ |
if (wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_VALID) { |
345 |
|
|
/* Check 6 GHz support in Network Manager */ |
346 |
|
|
#if NM_CHECK_VERSION (1, 45, 4) |
347 |
|
✗ |
if (wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_2GHZ && |
348 |
|
✗ |
wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_5GHZ && |
349 |
|
✗ |
wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_6GHZ) |
350 |
|
✗ |
freq_string = _("2.4 GHz / 5 GHz / 6 GHz"); |
351 |
|
✗ |
else if (wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_5GHZ && |
352 |
|
✗ |
wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_6GHZ) |
353 |
|
✗ |
freq_string = _("5 GHz / 6 GHz"); |
354 |
|
|
else |
355 |
|
|
#endif |
356 |
|
✗ |
if (wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_2GHZ && |
357 |
|
✗ |
wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_5GHZ) |
358 |
|
✗ |
freq_string = _("2.4 GHz / 5 GHz"); |
359 |
|
✗ |
else if (wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_2GHZ) |
360 |
|
✗ |
freq_string = _("2.4 GHz"); |
361 |
|
✗ |
else if (wifi_caps & NM_WIFI_DEVICE_CAP_FREQ_5GHZ) |
362 |
|
✗ |
freq_string = _("5 GHz"); |
363 |
|
|
} |
364 |
|
|
|
365 |
|
✗ |
gtk_label_set_label (self->freq_label, freq_string); |
366 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->freq_heading_label), freq_string != NULL); |
367 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->freq_label), freq_string != NULL); |
368 |
|
|
|
369 |
|
✗ |
if (device_is_active && active_ap) |
370 |
|
✗ |
security_string = get_ap_security_string (active_ap); |
371 |
|
✗ |
gtk_label_set_label (self->security_label, security_string); |
372 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->security_heading_label), security_string != NULL); |
373 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->security_label), security_string != NULL); |
374 |
|
|
|
375 |
|
✗ |
strength = 0; |
376 |
|
✗ |
if (self->ap != NULL) |
377 |
|
✗ |
strength = nm_access_point_get_strength (self->ap); |
378 |
|
|
|
379 |
|
✗ |
if (strength <= 0) |
380 |
|
✗ |
strength_label = NULL; |
381 |
|
✗ |
else if (strength < 20) |
382 |
|
✗ |
strength_label = C_("Signal strength", "None"); |
383 |
|
✗ |
else if (strength < 40) |
384 |
|
✗ |
strength_label = C_("Signal strength", "Weak"); |
385 |
|
✗ |
else if (strength < 50) |
386 |
|
✗ |
strength_label = C_("Signal strength", "Ok"); |
387 |
|
✗ |
else if (strength < 80) |
388 |
|
✗ |
strength_label = C_("Signal strength", "Good"); |
389 |
|
|
else |
390 |
|
✗ |
strength_label = C_("Signal strength", "Excellent"); |
391 |
|
✗ |
gtk_label_set_label (self->strength_label, strength_label); |
392 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->strength_heading_label), strength_label != NULL); |
393 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->strength_label), strength_label != NULL); |
394 |
|
|
|
395 |
|
✗ |
if (device_is_active && self->device != NULL) { |
396 |
|
✗ |
ipv4_config = nm_device_get_ip4_config (self->device); |
397 |
|
✗ |
ipv6_config = nm_device_get_ip6_config (self->device); |
398 |
|
|
} |
399 |
|
|
|
400 |
|
✗ |
if (ipv4_config != NULL) { |
401 |
|
|
GPtrArray *addresses; |
402 |
|
✗ |
const gchar *ipv4_text = NULL; |
403 |
|
✗ |
g_autofree gchar *ip4_dns = NULL; |
404 |
|
|
|
405 |
|
✗ |
addresses = nm_ip_config_get_addresses (ipv4_config); |
406 |
|
✗ |
if (addresses->len > 0) |
407 |
|
✗ |
ipv4_text = nm_ip_address_get_address (g_ptr_array_index (addresses, 0)); |
408 |
|
✗ |
gtk_label_set_label (self->ipv4_label, ipv4_text); |
409 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv4_heading_label), ipv4_text != NULL); |
410 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv4_label), ipv4_text != NULL); |
411 |
|
✗ |
have_ipv4_address = ipv4_text != NULL; |
412 |
|
|
|
413 |
|
✗ |
ip4_dns = g_strjoinv (" ", (char **) nm_ip_config_get_nameservers (ipv4_config)); |
414 |
|
✗ |
if (!*ip4_dns) |
415 |
|
✗ |
ip4_dns = NULL; |
416 |
|
✗ |
gtk_label_set_label (self->dns4_label, ip4_dns); |
417 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns4_heading_label), ip4_dns != NULL); |
418 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns4_label), ip4_dns != NULL); |
419 |
|
✗ |
have_dns4 = ip4_dns != NULL; |
420 |
|
|
|
421 |
|
✗ |
route4_text = nm_ip_config_get_gateway (ipv4_config); |
422 |
|
|
} else { |
423 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv4_heading_label), FALSE); |
424 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv4_label), FALSE); |
425 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns4_heading_label), FALSE); |
426 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns4_label), FALSE); |
427 |
|
|
} |
428 |
|
|
|
429 |
|
✗ |
if (ipv6_config != NULL) { |
430 |
|
✗ |
g_autofree gchar *ipv6_text = NULL; |
431 |
|
✗ |
g_autofree gchar *ip6_dns = NULL; |
432 |
|
|
|
433 |
|
✗ |
ipv6_text = net_device_get_ip6_addresses (ipv6_config); |
434 |
|
✗ |
gtk_label_set_label (self->ipv6_label, ipv6_text); |
435 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv6_heading_label), ipv6_text != NULL); |
436 |
|
✗ |
gtk_widget_set_valign (GTK_WIDGET (self->ipv6_heading_label), GTK_ALIGN_START); |
437 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv6_label), ipv6_text != NULL); |
438 |
|
✗ |
have_ipv6_address = ipv6_text != NULL; |
439 |
|
|
|
440 |
|
✗ |
ip6_dns = g_strjoinv (" ", (char **) nm_ip_config_get_nameservers (ipv6_config)); |
441 |
|
✗ |
if (!*ip6_dns) |
442 |
|
✗ |
ip6_dns = NULL; |
443 |
|
✗ |
gtk_label_set_label (self->dns6_label, ip6_dns); |
444 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns6_heading_label), ip6_dns != NULL); |
445 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns6_label), ip6_dns != NULL); |
446 |
|
✗ |
have_dns6 = ip6_dns != NULL; |
447 |
|
|
|
448 |
|
✗ |
route6_text = nm_ip_config_get_gateway (ipv6_config); |
449 |
|
|
} else { |
450 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv6_heading_label), FALSE); |
451 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->ipv6_label), FALSE); |
452 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns6_heading_label), FALSE); |
453 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->dns6_label), FALSE); |
454 |
|
|
} |
455 |
|
|
|
456 |
|
✗ |
if (have_ipv4_address && have_ipv6_address) { |
457 |
|
✗ |
gtk_label_set_label (self->ipv4_heading_label, _("IPv4 Address")); |
458 |
|
✗ |
gtk_label_set_label (self->ipv6_heading_label, _("IPv6 Address")); |
459 |
|
|
} else { |
460 |
|
✗ |
gtk_label_set_label (self->ipv4_heading_label, _("IP Address")); |
461 |
|
✗ |
gtk_label_set_label (self->ipv6_heading_label, _("IP Address")); |
462 |
|
|
} |
463 |
|
|
|
464 |
|
✗ |
if (have_dns4 && have_dns6) { |
465 |
|
✗ |
gtk_label_set_label (self->dns4_heading_label, _("DNS4")); |
466 |
|
✗ |
gtk_label_set_label (self->dns6_heading_label, _("DNS6")); |
467 |
|
|
} else { |
468 |
|
✗ |
gtk_label_set_label (self->dns4_heading_label, _("DNS")); |
469 |
|
✗ |
gtk_label_set_label (self->dns6_heading_label, _("DNS")); |
470 |
|
|
} |
471 |
|
|
|
472 |
|
✗ |
if (route4_text != NULL || route6_text != NULL) { |
473 |
|
✗ |
g_autofree const gchar *routes_text = NULL; |
474 |
|
|
|
475 |
|
✗ |
if (route4_text == NULL) { |
476 |
|
✗ |
routes_text = g_strdup (route6_text); |
477 |
|
✗ |
} else if (route6_text == NULL) { |
478 |
|
✗ |
routes_text = g_strdup (route4_text); |
479 |
|
|
} else { |
480 |
|
✗ |
routes_text = g_strjoin ("\n", route4_text, route6_text, NULL); |
481 |
|
|
} |
482 |
|
✗ |
gtk_label_set_label (self->route_label, routes_text); |
483 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->route_heading_label), routes_text != NULL); |
484 |
|
✗ |
gtk_widget_set_valign (GTK_WIDGET (self->route_heading_label), GTK_ALIGN_START); |
485 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->route_label), routes_text != NULL); |
486 |
|
|
} else { |
487 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->route_heading_label), FALSE); |
488 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->route_label), FALSE); |
489 |
|
|
} |
490 |
|
|
|
491 |
|
✗ |
if (!device_is_active && self->connection && !self->is_new_connection) |
492 |
|
✗ |
update_last_used (self, self->connection); |
493 |
|
|
else { |
494 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->last_used_heading_label), FALSE); |
495 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->last_used_label), FALSE); |
496 |
|
|
} |
497 |
|
|
|
498 |
|
|
/* Auto connect check */ |
499 |
|
✗ |
if (g_str_equal (type, NM_SETTING_VPN_SETTING_NAME) || |
500 |
|
✗ |
g_str_equal(type, NM_SETTING_WIREGUARD_SETTING_NAME)) { |
501 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->auto_connect_check), FALSE); |
502 |
|
|
} else { |
503 |
|
✗ |
g_object_bind_property (sc, "autoconnect", |
504 |
|
✗ |
self->auto_connect_check, "active", |
505 |
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); |
506 |
|
✗ |
g_signal_connect_object (self->auto_connect_check, "toggled", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
507 |
|
|
} |
508 |
|
|
|
509 |
|
|
/* All users check */ |
510 |
|
✗ |
gtk_check_button_set_active (GTK_CHECK_BUTTON (self->all_user_check), |
511 |
|
✗ |
nm_setting_connection_get_num_permissions (sc) == 0); |
512 |
|
✗ |
g_signal_connect_object (self->all_user_check, "toggled", G_CALLBACK (all_user_changed), self, G_CONNECT_SWAPPED); |
513 |
|
✗ |
g_signal_connect_object (self->all_user_check, "toggled", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
514 |
|
|
|
515 |
|
|
/* Restrict Data check */ |
516 |
|
✗ |
update_restrict_data (self); |
517 |
|
|
|
518 |
|
|
/* Forget button */ |
519 |
|
✗ |
if (!self->is_new_connection) { |
520 |
|
✗ |
g_signal_connect_object (self->forget_button, "clicked", G_CALLBACK (forget_cb), self, G_CONNECT_SWAPPED); |
521 |
|
|
|
522 |
|
✗ |
if (g_str_equal (type, NM_SETTING_WIRELESS_SETTING_NAME)) |
523 |
|
✗ |
gtk_button_set_label (self->forget_button, _("Forget Connection…")); |
524 |
|
✗ |
else if (g_str_equal (type, NM_SETTING_WIRED_SETTING_NAME)) |
525 |
|
✗ |
gtk_button_set_label (self->forget_button, _("Remove Connection Profile…")); |
526 |
|
✗ |
else if (g_str_equal (type, NM_SETTING_BLUETOOTH_SETTING_NAME)) |
527 |
|
✗ |
gtk_button_set_label (self->forget_button, _("Remove Connection…")); |
528 |
|
✗ |
else if (g_str_equal (type, NM_SETTING_VPN_SETTING_NAME) || |
529 |
|
✗ |
g_str_equal (type, NM_SETTING_WIREGUARD_SETTING_NAME)) |
530 |
|
✗ |
gtk_button_set_label (self->forget_button, _("Remove VPN…")); |
531 |
|
|
else |
532 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->forget_button), FALSE); |
533 |
|
|
} else { |
534 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->forget_button), FALSE); |
535 |
|
|
} |
536 |
|
✗ |
} |
537 |
|
|
|
538 |
|
|
static void |
539 |
|
✗ |
ce_page_details_dispose (GObject *object) |
540 |
|
|
{ |
541 |
|
✗ |
CEPageDetails *self = CE_PAGE_DETAILS (object); |
542 |
|
|
|
543 |
|
✗ |
g_clear_object (&self->connection); |
544 |
|
|
|
545 |
|
✗ |
G_OBJECT_CLASS (ce_page_details_parent_class)->dispose (object); |
546 |
|
✗ |
} |
547 |
|
|
|
548 |
|
|
static const gchar * |
549 |
|
✗ |
ce_page_details_get_title (CEPage *page) |
550 |
|
|
{ |
551 |
|
✗ |
return _("Details"); |
552 |
|
|
} |
553 |
|
|
|
554 |
|
|
static void |
555 |
|
✗ |
ce_page_details_init (CEPageDetails *self) |
556 |
|
|
{ |
557 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
558 |
|
✗ |
} |
559 |
|
|
|
560 |
|
|
static void |
561 |
|
✗ |
ce_page_details_class_init (CEPageDetailsClass *klass) |
562 |
|
|
{ |
563 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
564 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
565 |
|
|
|
566 |
|
✗ |
object_class->dispose = ce_page_details_dispose; |
567 |
|
|
|
568 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/details-page.ui"); |
569 |
|
|
|
570 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, all_user_check); |
571 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, auto_connect_check); |
572 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, dns4_heading_label); |
573 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, dns4_label); |
574 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, dns6_heading_label); |
575 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, dns6_label); |
576 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, forget_button); |
577 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, freq_heading_label); |
578 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, freq_label); |
579 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, ipv4_heading_label); |
580 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, ipv4_label); |
581 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, ipv6_heading_label); |
582 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, ipv6_label); |
583 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, last_used_heading_label); |
584 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, last_used_label); |
585 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, mac_heading_label); |
586 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, mac_label); |
587 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, restrict_data_check); |
588 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, route_heading_label); |
589 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, route_label); |
590 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, security_heading_label); |
591 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, security_label); |
592 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, speed_heading_label); |
593 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, speed_label); |
594 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, strength_heading_label); |
595 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageDetails, strength_label); |
596 |
|
✗ |
} |
597 |
|
|
|
598 |
|
|
static void |
599 |
|
✗ |
ce_page_iface_init (CEPageInterface *iface) |
600 |
|
|
{ |
601 |
|
✗ |
iface->get_title = ce_page_details_get_title; |
602 |
|
✗ |
} |
603 |
|
|
|
604 |
|
|
CEPageDetails * |
605 |
|
✗ |
ce_page_details_new (NMConnection *connection, |
606 |
|
|
NMDevice *device, |
607 |
|
|
NMAccessPoint *ap, |
608 |
|
|
NetConnectionEditor *editor, |
609 |
|
|
gboolean is_new_connection) |
610 |
|
|
{ |
611 |
|
|
CEPageDetails *self; |
612 |
|
|
|
613 |
|
✗ |
self = CE_PAGE_DETAILS (g_object_new (ce_page_details_get_type (), NULL)); |
614 |
|
|
|
615 |
|
✗ |
self->connection = g_object_ref (connection); |
616 |
|
✗ |
self->editor = editor; |
617 |
|
✗ |
self->device = device; |
618 |
|
✗ |
self->ap = ap; |
619 |
|
✗ |
self->is_new_connection = is_new_connection; |
620 |
|
|
|
621 |
|
✗ |
connect_details_page (self); |
622 |
|
|
|
623 |
|
✗ |
return self; |
624 |
|
|
} |
625 |
|
|
|