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 <NetworkManager.h> |
26 |
|
|
#include <net/if_arp.h> |
27 |
|
|
|
28 |
|
|
#include "ce-page.h" |
29 |
|
|
#include "ce-page-wifi.h" |
30 |
|
|
#include "ui-helpers.h" |
31 |
|
|
|
32 |
|
|
struct _CEPageWifi |
33 |
|
|
{ |
34 |
|
|
AdwBin parent; |
35 |
|
|
|
36 |
|
|
GtkComboBoxText *bssid_combo; |
37 |
|
|
GtkComboBoxText *cloned_mac_combo; |
38 |
|
|
GtkComboBoxText *mac_combo; |
39 |
|
|
GtkEntry *ssid_entry; |
40 |
|
|
|
41 |
|
|
NMClient *client; |
42 |
|
|
NMSettingWireless *setting; |
43 |
|
|
}; |
44 |
|
|
|
45 |
|
|
static void ce_page_iface_init (CEPageInterface *); |
46 |
|
|
|
47 |
|
✗ |
G_DEFINE_TYPE_WITH_CODE (CEPageWifi, ce_page_wifi, ADW_TYPE_BIN, |
48 |
|
|
G_IMPLEMENT_INTERFACE (ce_page_get_type (), ce_page_iface_init)) |
49 |
|
|
|
50 |
|
|
static void |
51 |
|
✗ |
connect_wifi_page (CEPageWifi *self) |
52 |
|
|
{ |
53 |
|
|
GBytes *ssid; |
54 |
|
✗ |
g_autofree gchar *utf8_ssid = NULL; |
55 |
|
|
GPtrArray *bssid_array; |
56 |
|
|
gchar **bssid_list; |
57 |
|
|
const char *s_bssid_str; |
58 |
|
|
gchar **mac_list; |
59 |
|
|
const gchar *s_mac_str; |
60 |
|
|
const gchar *cloned_mac; |
61 |
|
|
gint i; |
62 |
|
|
|
63 |
|
✗ |
ssid = nm_setting_wireless_get_ssid (self->setting); |
64 |
|
✗ |
if (ssid) |
65 |
|
✗ |
utf8_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); |
66 |
|
|
else |
67 |
|
✗ |
utf8_ssid = g_strdup (""); |
68 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->ssid_entry), utf8_ssid); |
69 |
|
|
|
70 |
|
✗ |
g_signal_connect_object (self->ssid_entry, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
71 |
|
|
|
72 |
|
✗ |
bssid_array = g_ptr_array_new (); |
73 |
|
✗ |
for (i = 0; i < nm_setting_wireless_get_num_seen_bssids (self->setting); i++) { |
74 |
|
✗ |
g_ptr_array_add (bssid_array, g_strdup (nm_setting_wireless_get_seen_bssid (self->setting, i))); |
75 |
|
|
} |
76 |
|
✗ |
g_ptr_array_add (bssid_array, NULL); |
77 |
|
✗ |
bssid_list = (gchar **) g_ptr_array_free (bssid_array, FALSE); |
78 |
|
✗ |
s_bssid_str = nm_setting_wireless_get_bssid (self->setting); |
79 |
|
✗ |
ce_page_setup_mac_combo (self->bssid_combo, s_bssid_str, bssid_list); |
80 |
|
✗ |
g_strfreev (bssid_list); |
81 |
|
✗ |
g_signal_connect_object (self->bssid_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
82 |
|
|
|
83 |
|
✗ |
mac_list = ce_page_get_mac_list (self->client, NM_TYPE_DEVICE_WIFI, |
84 |
|
|
NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS); |
85 |
|
✗ |
s_mac_str = nm_setting_wireless_get_mac_address (self->setting); |
86 |
|
✗ |
ce_page_setup_mac_combo (self->mac_combo, s_mac_str, mac_list); |
87 |
|
✗ |
g_strfreev (mac_list); |
88 |
|
✗ |
g_signal_connect_object (self->mac_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
89 |
|
|
|
90 |
|
✗ |
cloned_mac = nm_setting_wireless_get_cloned_mac_address (self->setting); |
91 |
|
✗ |
ce_page_setup_cloned_mac_combo (self->cloned_mac_combo, cloned_mac, TRUE); |
92 |
|
✗ |
g_signal_connect_object (self->cloned_mac_combo, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
93 |
|
✗ |
} |
94 |
|
|
|
95 |
|
|
static void |
96 |
|
✗ |
ui_to_setting (CEPageWifi *self) |
97 |
|
|
{ |
98 |
|
✗ |
g_autoptr(GBytes) ssid = NULL; |
99 |
|
|
const gchar *utf8_ssid, *bssid; |
100 |
|
|
GtkWidget *entry; |
101 |
|
✗ |
g_autofree gchar *device_mac = NULL; |
102 |
|
✗ |
g_autofree gchar *cloned_mac = NULL; |
103 |
|
|
|
104 |
|
✗ |
utf8_ssid = gtk_editable_get_text (GTK_EDITABLE (self->ssid_entry)); |
105 |
|
✗ |
if (!utf8_ssid || !*utf8_ssid) |
106 |
|
✗ |
ssid = NULL; |
107 |
|
|
else { |
108 |
|
✗ |
ssid = g_bytes_new_static (utf8_ssid, strlen (utf8_ssid)); |
109 |
|
|
} |
110 |
|
✗ |
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->bssid_combo)); |
111 |
|
✗ |
bssid = gtk_editable_get_text (GTK_EDITABLE (entry)); |
112 |
|
✗ |
if (*bssid == '\0') |
113 |
|
✗ |
bssid = NULL; |
114 |
|
✗ |
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->mac_combo)); |
115 |
|
✗ |
device_mac = ce_page_trim_address (gtk_editable_get_text (GTK_EDITABLE (entry))); |
116 |
|
✗ |
cloned_mac = ce_page_cloned_mac_get (self->cloned_mac_combo); |
117 |
|
|
|
118 |
|
✗ |
g_object_set (self->setting, |
119 |
|
|
NM_SETTING_WIRELESS_SSID, ssid, |
120 |
|
|
NM_SETTING_WIRELESS_BSSID, bssid, |
121 |
|
|
NM_SETTING_WIRELESS_MAC_ADDRESS, device_mac, |
122 |
|
|
NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, cloned_mac, |
123 |
|
|
NULL); |
124 |
|
✗ |
} |
125 |
|
|
|
126 |
|
|
static const gchar * |
127 |
|
✗ |
ce_page_wifi_get_title (CEPage *page) |
128 |
|
|
{ |
129 |
|
✗ |
return _("Identity"); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
static gboolean |
133 |
|
✗ |
ce_page_wifi_class_validate (CEPage *parent, |
134 |
|
|
NMConnection *connection, |
135 |
|
|
GError **error) |
136 |
|
|
{ |
137 |
|
✗ |
CEPageWifi *self = (CEPageWifi *) parent; |
138 |
|
|
GtkWidget *entry; |
139 |
|
✗ |
gboolean ret = TRUE; |
140 |
|
|
|
141 |
|
✗ |
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->bssid_combo)); |
142 |
|
✗ |
if (!ce_page_address_is_valid (gtk_editable_get_text (GTK_EDITABLE (entry)))) { |
143 |
|
✗ |
widget_set_error (entry); |
144 |
|
✗ |
ret = FALSE; |
145 |
|
|
} else { |
146 |
|
✗ |
widget_unset_error (entry); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
✗ |
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (self->mac_combo)); |
150 |
|
✗ |
if (!ce_page_address_is_valid (gtk_editable_get_text (GTK_EDITABLE (entry)))) { |
151 |
|
✗ |
widget_set_error (entry); |
152 |
|
✗ |
ret = FALSE; |
153 |
|
|
} else { |
154 |
|
✗ |
widget_unset_error (entry); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
✗ |
if (!ce_page_cloned_mac_combo_valid (self->cloned_mac_combo)) { |
158 |
|
✗ |
widget_set_error (gtk_combo_box_get_child (GTK_COMBO_BOX (self->cloned_mac_combo))); |
159 |
|
✗ |
ret = FALSE; |
160 |
|
|
} else { |
161 |
|
✗ |
widget_unset_error (gtk_combo_box_get_child (GTK_COMBO_BOX (self->cloned_mac_combo))); |
162 |
|
|
} |
163 |
|
|
|
164 |
|
✗ |
if (!ret) |
165 |
|
✗ |
return ret; |
166 |
|
|
|
167 |
|
✗ |
ui_to_setting (CE_PAGE_WIFI (self)); |
168 |
|
|
|
169 |
|
✗ |
return ret; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
static void |
173 |
|
✗ |
ce_page_wifi_init (CEPageWifi *self) |
174 |
|
|
{ |
175 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
176 |
|
✗ |
} |
177 |
|
|
|
178 |
|
|
static void |
179 |
|
✗ |
ce_page_wifi_class_init (CEPageWifiClass *klass) |
180 |
|
|
{ |
181 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
182 |
|
|
|
183 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/wifi-page.ui"); |
184 |
|
|
|
185 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageWifi, bssid_combo); |
186 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageWifi, cloned_mac_combo); |
187 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageWifi, mac_combo); |
188 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageWifi, ssid_entry); |
189 |
|
✗ |
} |
190 |
|
|
|
191 |
|
|
static void |
192 |
|
✗ |
ce_page_iface_init (CEPageInterface *iface) |
193 |
|
|
{ |
194 |
|
✗ |
iface->get_title = ce_page_wifi_get_title; |
195 |
|
✗ |
iface->validate = ce_page_wifi_class_validate; |
196 |
|
✗ |
} |
197 |
|
|
|
198 |
|
|
CEPageWifi * |
199 |
|
✗ |
ce_page_wifi_new (NMConnection *connection, |
200 |
|
|
NMClient *client) |
201 |
|
|
{ |
202 |
|
|
CEPageWifi *self; |
203 |
|
|
|
204 |
|
✗ |
self = CE_PAGE_WIFI (g_object_new (ce_page_wifi_get_type (), NULL)); |
205 |
|
|
|
206 |
|
✗ |
self->client = client; |
207 |
|
✗ |
self->setting = nm_connection_get_setting_wireless (connection); |
208 |
|
|
|
209 |
|
✗ |
connect_wifi_page (self); |
210 |
|
|
|
211 |
|
✗ |
return self; |
212 |
|
|
} |
213 |
|
|
|