Debian Codegraph @

src/connection.c

raw
1 /*
2 * ConnMan GTK GUI
3 *
4 * Copyright (C) 2015 Intel Corporation. All rights reserved.
5 * Author: Jaakko Hannikainen <[email protected]>
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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <glib.h>
22 #include <glib/gi18n.h>
23 #include <string.h>
24
25 #include "connection.h"
26
27 enum connection_type connection_type_from_string(const gchar *str)
28 {
29 if(!strcmp(str, "ethernet"))
30 return CONNECTION_TYPE_ETHERNET;
31 if(!strcmp(str, "wifi"))
32 return CONNECTION_TYPE_WIRELESS;
33 if(!strcmp(str, "bluetooth"))
34 return CONNECTION_TYPE_BLUETOOTH;
35 if(!strcmp(str, "cellular"))
36 return CONNECTION_TYPE_CELLULAR;
37 if(!strcmp(str, "p2p"))
38 return CONNECTION_TYPE_P2P;
39 if(!strcmp(str, "vpn"))
40 return CONNECTION_TYPE_VPN;
41 if(!strcmp(str, "openconnect") || !strcmp(str, "openvpn") ||
42 !strcmp(str, "vpnc") || !strcmp(str, "l2tp") || !strcmp(str, "pptp"))
43 return CONNECTION_TYPE_VPN;
44 return CONNECTION_TYPE_UNKNOWN;
45 }
46
47 enum connection_type connection_type_from_properties(GVariant *properties)
48 {
49 enum connection_type type = CONNECTION_TYPE_UNKNOWN;
50 GVariantDict *dict = g_variant_dict_new(properties);
51 GVariant *type_v = g_variant_dict_lookup_value(dict, "Type", NULL);
52 if(type_v) {
53 const gchar *type_s;
54
55 type_s = g_variant_get_string(type_v, NULL);
56 type = connection_type_from_string(type_s);
57 g_variant_unref(type_v);
58 }
59 g_variant_dict_unref(dict);
60
61 return type;
62 }
63
64 const gchar *translated_tech_name(enum connection_type type)
65 {
66 switch(type) {
67 case CONNECTION_TYPE_ETHERNET:
68 return _("Wired");
69 case CONNECTION_TYPE_WIRELESS:
70 return _("Wireless");
71 case CONNECTION_TYPE_BLUETOOTH:
72 return _("Bluetooth");
73 case CONNECTION_TYPE_CELLULAR:
74 return _("Cellular");
75 case CONNECTION_TYPE_P2P:
76 return _("P2P");
77 case CONNECTION_TYPE_VPN:
78 return _("VPN");
79 case CONNECTION_TYPE_UNKNOWN:
80 return _("Unknown");
81 case CONNECTION_TYPE_COUNT:
82 return "";
83 }
84 return "";
85 }
86
87 const gchar *mnemonic_tech_name(enum connection_type type)
88 {
89 switch(type) {
90 case CONNECTION_TYPE_ETHERNET:
91 return _("W_ired");
92 case CONNECTION_TYPE_WIRELESS:
93 return _("_Wireless");
94 case CONNECTION_TYPE_BLUETOOTH:
95 return _("_Bluetooth");
96 case CONNECTION_TYPE_CELLULAR:
97 return _("_Cellular");
98 case CONNECTION_TYPE_P2P:
99 return _("_P2P");
100 case CONNECTION_TYPE_VPN:
101 return _("_VPN");
102 case CONNECTION_TYPE_UNKNOWN:
103 return _("_Unknown");
104 case CONNECTION_TYPE_COUNT:
105 return "";
106 }
107 return "";
108 }