1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2010 Richard Hughes <richard@hughsie.com>
4
* Copyright (C) 2012 Thomas Bechtold <thomasbechtold@jpberlin.de>
6
* Licensed under the GNU General Public License Version 2
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
#include <glib/gi18n.h>
29
#include <nm-device-ethernet.h>
30
#include <nm-device-modem.h>
33
#include "panel-common.h"
36
* panel_device_to_icon_name:
39
panel_device_to_icon_name (NMDevice *device)
41
const gchar *value = NULL;
43
NMDeviceModemCapabilities caps;
44
switch (nm_device_get_device_type (device)) {
45
case NM_DEVICE_TYPE_ETHERNET:
46
state = nm_device_get_state (device);
47
if (state == NM_DEVICE_STATE_UNAVAILABLE) {
48
value = "network-wired-disconnected";
50
value = "network-wired";
53
case NM_DEVICE_TYPE_WIFI:
54
case NM_DEVICE_TYPE_BT:
55
case NM_DEVICE_TYPE_OLPC_MESH:
56
value = "network-wireless";
58
case NM_DEVICE_TYPE_MODEM:
59
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
60
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
61
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
62
value = "network-wireless";
72
* panel_device_to_localized_string:
75
panel_device_to_localized_string (NMDevice *device)
77
const gchar *value = NULL;
78
NMDeviceModemCapabilities caps;
79
switch (nm_device_get_device_type (device)) {
80
case NM_DEVICE_TYPE_UNKNOWN:
81
/* TRANSLATORS: device type */
84
case NM_DEVICE_TYPE_ETHERNET:
85
/* TRANSLATORS: device type */
88
case NM_DEVICE_TYPE_WIFI:
89
/* TRANSLATORS: device type */
90
value = _("Wireless");
92
case NM_DEVICE_TYPE_MODEM:
93
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
94
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
95
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
96
/* TRANSLATORS: device type */
97
value = _("Mobile broadband");
100
case NM_DEVICE_TYPE_BT:
101
/* TRANSLATORS: device type */
102
value = _("Bluetooth");
104
case NM_DEVICE_TYPE_OLPC_MESH:
105
/* TRANSLATORS: device type */
115
* panel_device_to_sortable_string:
117
* Try to return order of approximate connection speed.
118
* But sort wifi first, since thats the common case.
121
panel_device_to_sortable_string (NMDevice *device)
123
const gchar *value = NULL;
124
NMDeviceModemCapabilities caps;
125
switch (nm_device_get_device_type (device)) {
126
case NM_DEVICE_TYPE_ETHERNET:
129
case NM_DEVICE_TYPE_WIFI:
132
case NM_DEVICE_TYPE_MODEM:
133
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
134
if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
135
(caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) {
139
case NM_DEVICE_TYPE_BT:
142
case NM_DEVICE_TYPE_OLPC_MESH:
153
* panel_ap_mode_to_localized_string:
156
panel_ap_mode_to_localized_string (NM80211Mode mode)
158
const gchar *value = NULL;
160
case NM_802_11_MODE_UNKNOWN:
161
/* TRANSLATORS: AP type */
162
value = _("Unknown");
164
case NM_802_11_MODE_ADHOC:
165
/* TRANSLATORS: AP type */
168
case NM_802_11_MODE_INFRA:
169
/* TRANSLATORS: AP type */
170
value = _("Infrastructure");
179
* panel_device_state_to_localized_string:
182
panel_device_state_to_localized_string (NMDevice *device)
187
type = nm_device_get_device_type (device);
188
state = nm_device_get_state (device);
190
const gchar *value = NULL;
192
case NM_DEVICE_STATE_UNKNOWN:
193
/* TRANSLATORS: device status */
194
value = _("Status unknown");
196
case NM_DEVICE_STATE_UNMANAGED:
197
/* TRANSLATORS: device status */
198
value = _("Unmanaged");
200
case NM_DEVICE_STATE_UNAVAILABLE:
201
/* TRANSLATORS: device status */
202
if (nm_device_get_firmware_missing (device))
203
value = _("Firmware missing");
204
else if (type == NM_DEVICE_TYPE_ETHERNET &&
205
!nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device)))
206
value = _("Cable unplugged");
208
value = _("Unavailable");
210
case NM_DEVICE_STATE_DISCONNECTED:
211
/* TRANSLATORS: device status */
212
value = _("Disconnected");
214
case NM_DEVICE_STATE_PREPARE:
215
case NM_DEVICE_STATE_CONFIG:
216
case NM_DEVICE_STATE_IP_CONFIG:
217
case NM_DEVICE_STATE_IP_CHECK:
218
/* TRANSLATORS: device status */
219
value = _("Connecting");
221
case NM_DEVICE_STATE_NEED_AUTH:
222
/* TRANSLATORS: device status */
223
value = _("Authentication required");
225
case NM_DEVICE_STATE_ACTIVATED:
226
/* TRANSLATORS: device status */
227
value = _("Connected");
229
case NM_DEVICE_STATE_DEACTIVATING:
230
/* TRANSLATORS: device status */
231
value = _("Disconnecting");
233
case NM_DEVICE_STATE_FAILED:
234
/* TRANSLATORS: device status */
235
value = _("Connection failed");
238
/* TRANSLATORS: device status */
239
value = _("Status unknown (missing)");
246
* panel_vpn_state_to_localized_string:
249
panel_vpn_state_to_localized_string (NMVPNConnectionState type)
251
const gchar *value = NULL;
253
case NM_DEVICE_STATE_UNKNOWN:
254
/* TRANSLATORS: VPN status */
255
value = _("Status unknown");
257
case NM_VPN_CONNECTION_STATE_PREPARE:
258
case NM_VPN_CONNECTION_STATE_CONNECT:
259
case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET:
260
/* TRANSLATORS: VPN status */
261
value = _("Connecting");
263
case NM_VPN_CONNECTION_STATE_NEED_AUTH:
264
/* TRANSLATORS: VPN status */
265
value = _("Authentication required");
267
case NM_VPN_CONNECTION_STATE_ACTIVATED:
268
/* TRANSLATORS: VPN status */
269
value = _("Connected");
271
case NM_VPN_CONNECTION_STATE_FAILED:
272
/* TRANSLATORS: VPN status */
273
value = _("Connection failed");
275
case NM_VPN_CONNECTION_STATE_DISCONNECTED:
276
/* TRANSLATORS: VPN status */
277
value = _("Not connected");
280
/* TRANSLATORS: VPN status */
281
value = _("Status unknown (missing)");
288
* panel_device_state_reason_to_localized_string:
291
panel_device_state_reason_to_localized_string (NMDevice *device)
293
const gchar *value = NULL;
294
NMDeviceStateReason state_reason;
296
/* we only want the StateReason's we care about */
297
nm_device_get_state_reason (device, &state_reason);
298
switch (state_reason) {
299
case NM_DEVICE_STATE_REASON_CONFIG_FAILED:
300
/* TRANSLATORS: device status reason */
301
value = _("Configuration failed");
303
case NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE:
304
/* TRANSLATORS: device status reason */
305
value = _("IP configuration failed");
307
case NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED:
308
/* TRANSLATORS: device status reason */
309
value = _("IP configuration expired");
311
case NM_DEVICE_STATE_REASON_NO_SECRETS:
312
/* TRANSLATORS: device status reason */
313
value = _("Secrets were required, but not provided");
315
case NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT:
316
/* TRANSLATORS: device status reason */
317
value = _("802.1x supplicant disconnected");
319
case NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED:
320
/* TRANSLATORS: device status reason */
321
value = _("802.1x supplicant configuration failed");
323
case NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED:
324
/* TRANSLATORS: device status reason */
325
value = _("802.1x supplicant failed");
327
case NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT:
328
/* TRANSLATORS: device status reason */
329
value = _("802.1x supplicant took too long to authenticate");
331
case NM_DEVICE_STATE_REASON_PPP_START_FAILED:
332
/* TRANSLATORS: device status reason */
333
value = _("PPP service failed to start");
335
case NM_DEVICE_STATE_REASON_PPP_DISCONNECT:
336
/* TRANSLATORS: device status reason */
337
value = _("PPP service disconnected");
339
case NM_DEVICE_STATE_REASON_PPP_FAILED:
340
/* TRANSLATORS: device status reason */
341
value = _("PPP failed");
343
case NM_DEVICE_STATE_REASON_DHCP_START_FAILED:
344
/* TRANSLATORS: device status reason */
345
value = _("DHCP client failed to start");
347
case NM_DEVICE_STATE_REASON_DHCP_ERROR:
348
/* TRANSLATORS: device status reason */
349
value = _("DHCP client error");
351
case NM_DEVICE_STATE_REASON_DHCP_FAILED:
352
/* TRANSLATORS: device status reason */
353
value = _("DHCP client failed");
355
case NM_DEVICE_STATE_REASON_SHARED_START_FAILED:
356
/* TRANSLATORS: device status reason */
357
value = _("Shared connection service failed to start");
359
case NM_DEVICE_STATE_REASON_SHARED_FAILED:
360
/* TRANSLATORS: device status reason */
361
value = _("Shared connection service failed");
363
case NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED:
364
/* TRANSLATORS: device status reason */
365
value = _("AutoIP service failed to start");
367
case NM_DEVICE_STATE_REASON_AUTOIP_ERROR:
368
/* TRANSLATORS: device status reason */
369
value = _("AutoIP service error");
371
case NM_DEVICE_STATE_REASON_AUTOIP_FAILED:
372
/* TRANSLATORS: device status reason */
373
value = _("AutoIP service failed");
375
case NM_DEVICE_STATE_REASON_MODEM_BUSY:
376
/* TRANSLATORS: device status reason */
377
value = _("Line busy");
379
case NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE:
380
/* TRANSLATORS: device status reason */
381
value = _("No dial tone");
383
case NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER:
384
/* TRANSLATORS: device status reason */
385
value = _("No carrier could be established");
387
case NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT:
388
/* TRANSLATORS: device status reason */
389
value = _("Dialing request timed out");
391
case NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED:
392
/* TRANSLATORS: device status reason */
393
value = _("Dialing attempt failed");
395
case NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED:
396
/* TRANSLATORS: device status reason */
397
value = _("Modem initialization failed");
399
case NM_DEVICE_STATE_REASON_GSM_APN_FAILED:
400
/* TRANSLATORS: device status reason */
401
value = _("Failed to select the specified APN");
403
case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING:
404
/* TRANSLATORS: device status reason */
405
value = _("Not searching for networks");
407
case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED:
408
/* TRANSLATORS: device status reason */
409
value = _("Network registration denied");
411
case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT:
412
/* TRANSLATORS: device status reason */
413
value = _("Network registration timed out");
415
case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED:
416
/* TRANSLATORS: device status reason */
417
value = _("Failed to register with the requested network");
419
case NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED:
420
/* TRANSLATORS: device status reason */
421
value = _("PIN check failed");
423
case NM_DEVICE_STATE_REASON_FIRMWARE_MISSING:
424
/* TRANSLATORS: device status reason */
425
value = _("Firmware for the device may be missing");
427
case NM_DEVICE_STATE_REASON_CONNECTION_REMOVED:
428
/* TRANSLATORS: device status reason */
429
value = _("Connection disappeared");
431
case NM_DEVICE_STATE_REASON_CARRIER:
432
/* TRANSLATORS: device status reason */
433
value = _("Carrier/link changed");
435
case NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED:
436
/* TRANSLATORS: device status reason */
437
value = _("Existing connection was assumed");
439
case NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND:
440
/* TRANSLATORS: device status reason */
441
value = _("Modem not found");
443
case NM_DEVICE_STATE_REASON_BT_FAILED:
444
/* TRANSLATORS: device status reason */
445
value = _("Bluetooth connection failed");
447
case NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED:
448
/* TRANSLATORS: device status reason */
449
value = _("SIM Card not inserted");
451
case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED:
452
/* TRANSLATORS: device status reason */
453
value = _("SIM Pin required");
455
case NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED:
456
/* TRANSLATORS: device status reason */
457
value = _("SIM Puk required");
459
case NM_DEVICE_STATE_REASON_GSM_SIM_WRONG:
460
/* TRANSLATORS: device status reason */
461
value = _("SIM wrong");
463
case NM_DEVICE_STATE_REASON_INFINIBAND_MODE:
464
/* TRANSLATORS: device status reason */
465
value = _("InfiniBand device does not support connected mode");
467
case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED:
468
/* TRANSLATORS: device status reason */
469
value = _("Connection dependency failed");
472
/* no StateReason to show */
480
panel_set_device_widget_details (GtkBuilder *builder,
481
const gchar *widget_suffix,
489
/* hide the row if there is no value */
490
heading_id = g_strdup_printf ("heading_%s", widget_suffix);
491
label_id = g_strdup_printf ("label_%s", widget_suffix);
492
heading = GTK_WIDGET (gtk_builder_get_object (builder, heading_id));
493
widget = GTK_WIDGET (gtk_builder_get_object (builder, label_id));
494
if (heading == NULL || widget == NULL) {
495
g_critical ("no widgets %s, %s found", heading_id, label_id);
502
gtk_widget_hide (heading);
503
gtk_widget_hide (widget);
505
/* there exists a value */
506
gtk_widget_show (heading);
507
gtk_widget_show (widget);
508
gtk_label_set_label (GTK_LABEL (widget), value);
515
panel_set_device_widget_header (GtkBuilder *builder,
516
const gchar *widget_suffix,
517
const gchar *heading)
519
gchar *label_id = NULL;
522
label_id = g_strdup_printf ("heading_%s", widget_suffix);
523
widget = GTK_WIDGET (gtk_builder_get_object (builder, label_id));
524
if (widget == NULL) {
525
g_critical ("no widget %s found", label_id);
528
gtk_label_set_label (GTK_LABEL (widget), heading);
534
get_ipv4_config_address_as_string (NMIP4Config *ip4_config, const char *what)
539
gchar tmp[INET_ADDRSTRLEN];
540
NMIP4Address *address;
543
list = nm_ip4_config_get_addresses (ip4_config);
547
/* we only care about one address */
548
address = list->data;
549
if (!strcmp (what, "address"))
550
addr.s_addr = nm_ip4_address_get_address (address);
551
else if (!strcmp (what, "gateway"))
552
addr.s_addr = nm_ip4_address_get_gateway (address);
553
else if (!strcmp (what, "netmask"))
554
addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (address));
558
if (!inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
560
if (g_strcmp0 (tmp, "0.0.0.0") == 0)
562
str = g_strdup (tmp);
568
get_ipv4_config_name_servers_as_string (NMIP4Config *ip4_config)
573
gchar tmp[INET_ADDRSTRLEN];
577
array = nm_ip4_config_get_nameservers (ip4_config);
578
if (array == NULL || array->len == 0)
581
dns = g_string_new (NULL);
582
for (i = 0; i < array->len; i++) {
583
addr.s_addr = g_array_index (array, guint32, i);
584
if (inet_ntop (AF_INET, &addr, tmp, sizeof(tmp)))
585
g_string_append_printf (dns, "%s ", tmp);
587
str = g_string_free (dns, FALSE);
593
get_ipv6_config_address_as_string (NMIP6Config *ip6_config)
596
const struct in6_addr *addr;
598
gchar tmp[INET6_ADDRSTRLEN];
599
NMIP6Address *address;
602
list = nm_ip6_config_get_addresses (ip6_config);
606
/* we only care about one address */
607
address = list->data;
608
addr = nm_ip6_address_get_address (address);
611
inet_ntop (AF_INET6, addr, tmp, sizeof(tmp));
612
str = g_strdup (tmp);
618
panel_set_device_widgets (GtkBuilder *builder, NMDevice *device)
620
NMIP4Config *ip4_config = NULL;
621
NMIP6Config *ip6_config = NULL;
626
/* get IPv4 parameters */
627
ip4_config = nm_device_get_ip4_config (device);
628
if (ip4_config != NULL) {
631
str_tmp = get_ipv4_config_address_as_string (ip4_config, "address");
632
panel_set_device_widget_details (builder,
635
has_ip4 = str_tmp != NULL;
639
str_tmp = get_ipv4_config_name_servers_as_string (ip4_config);
640
panel_set_device_widget_details (builder,
646
str_tmp = get_ipv4_config_address_as_string (ip4_config, "gateway");
647
panel_set_device_widget_details (builder,
654
panel_set_device_widget_details (builder,
660
panel_set_device_widget_details (builder,
665
panel_set_device_widget_details (builder,
670
/* get IPv6 parameters */
671
ip6_config = nm_device_get_ip6_config (device);
672
if (ip6_config != NULL) {
673
str_tmp = get_ipv6_config_address_as_string (ip6_config);
674
panel_set_device_widget_details (builder, "ipv6", str_tmp);
675
has_ip6 = str_tmp != NULL;
678
panel_set_device_widget_details (builder, "ipv6", NULL);
682
if (has_ip4 && has_ip6) {
683
panel_set_device_widget_header (builder, "ipv4", _("IPv4 Address"));
684
panel_set_device_widget_header (builder, "ipv6", _("IPv6 Address"));
685
} else if (has_ip4) {
686
panel_set_device_widget_header (builder, "ipv4", _("IP Address"));
687
} else if (has_ip6) {
688
panel_set_device_widget_header (builder, "ipv6", _("IP Address"));
693
panel_unset_device_widgets (GtkBuilder *builder)
695
panel_set_device_widget_details (builder, "ipv4", NULL);
696
panel_set_device_widget_details (builder, "ipv6", NULL);
697
panel_set_device_widget_details (builder, "dns", NULL);
698
panel_set_device_widget_details (builder, "route", NULL);