51
52
static void wireless_dialog_response_cb (GtkDialog *dialog, gint response, gpointer user_data);
54
static void nag_dialog_response_cb (GtkDialog *nag_dialog, gint response, gpointer user_data);
53
56
static NMAccessPoint *update_active_ap (NMDevice *device, NMDeviceState state, NMApplet *applet);
58
static void _do_new_auto_connection (NMApplet *applet,
61
AppletNewAutoConnectionCallback callback,
62
gpointer callback_data);
56
65
show_ignore_focus_stealing_prevention (GtkWidget *widget)
58
69
gtk_widget_realize (widget);
59
70
gtk_widget_show (widget);
60
gtk_window_present_with_time (GTK_WINDOW (widget),
61
gdk_x11_get_server_time (gtk_widget_get_window (widget)));
71
window = gtk_widget_get_window (widget);
72
gtk_window_present_with_time (GTK_WINDOW (widget), gdk_x11_get_server_time (window));
65
other_wireless_activate_cb (GtkWidget *menu_item,
76
applet_wifi_connect_to_hidden_network (NMApplet *applet)
70
80
dialog = nma_wireless_dialog_new_for_other (applet);
74
g_signal_connect (dialog, "response",
75
G_CALLBACK (wireless_dialog_response_cb),
78
show_ignore_focus_stealing_prevention (dialog);
82
g_signal_connect (dialog, "response",
83
G_CALLBACK (wireless_dialog_response_cb),
85
show_ignore_focus_stealing_prevention (dialog);
90
99
gtk_container_add (GTK_CONTAINER (menu_item), label);
91
100
gtk_widget_show_all (menu_item);
92
101
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
93
g_signal_connect (menu_item, "activate", G_CALLBACK (other_wireless_activate_cb), applet);
97
new_network_activate_cb (GtkWidget *menu_item, NMApplet *applet)
102
g_signal_connect_swapped (menu_item, "activate",
103
G_CALLBACK (applet_wifi_connect_to_hidden_network),
108
applet_wifi_can_create_wifi_network (NMApplet *applet)
110
gboolean disabled, allowed = FALSE;
111
NMClientPermissionResult perm;
112
GError *error = NULL;
114
/* FIXME: check WIFI_SHARE_PROTECTED too, and make the wireless dialog
115
* handle the permissions as well so that admins can restrict open network
116
* creation separately from protected network creation.
118
perm = nm_client_get_permission_result (applet->nm_client, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN);
119
if (perm == NM_CLIENT_PERMISSION_RESULT_YES || perm == NM_CLIENT_PERMISSION_RESULT_AUTH) {
120
disabled = gconf_client_get_bool (applet->gconf_client, PREF_DISABLE_WIFI_CREATE, &error);
121
if (!disabled && !error)
123
g_clear_error (&error);
129
applet_wifi_create_wifi_network (NMApplet *applet)
99
131
GtkWidget *dialog;
101
133
dialog = nma_wireless_dialog_new_for_create (applet);
105
g_signal_connect (dialog, "response",
106
G_CALLBACK (wireless_dialog_response_cb),
109
show_ignore_focus_stealing_prevention (dialog);
135
g_signal_connect (dialog, "response",
136
G_CALLBACK (wireless_dialog_response_cb),
138
show_ignore_focus_stealing_prevention (dialog);
123
152
gtk_container_add (GTK_CONTAINER (menu_item), label);
124
153
gtk_widget_show_all (menu_item);
125
154
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
126
g_signal_connect (menu_item, "activate", G_CALLBACK (new_network_activate_cb), applet);
155
g_signal_connect_swapped (menu_item, "activate",
156
G_CALLBACK (applet_wifi_create_wifi_network),
128
/* FIXME: should really use PolicyKit and NM permissions here instead
129
* using using GConf mandatory settings. But this works for now.
131
disabled = gconf_client_get_bool (applet->gconf_client, PREF_DISABLE_WIFI_CREATE, &error);
132
if (error || disabled)
159
if (!applet_wifi_can_create_wifi_network (applet))
133
160
gtk_widget_set_sensitive (GTK_WIDGET (menu_item), FALSE);
134
g_clear_error (&error);
164
dbus_8021x_add_and_activate_cb (NMClient *client,
165
NMActiveConnection *active,
166
const char *connection_path,
171
g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
181
dbus_connect_8021x_cb (NMConnection *connection,
182
gboolean auto_created,
186
Dbus8021xInfo *info = user_data;
188
if (canceled == FALSE) {
189
g_return_if_fail (connection != NULL);
191
/* Ask NM to add the new connection and activate it; NM will fill in the
192
* missing details based on the specific object and the device.
194
nm_client_add_and_activate_connection (info->applet->nm_client,
197
nm_object_get_path (NM_OBJECT (info->ap)),
198
dbus_8021x_add_and_activate_cb,
202
g_object_unref (info->device);
203
g_object_unref (info->ap);
204
memset (info, 0, sizeof (*info));
209
applet_wifi_connect_to_8021x_network (NMApplet *applet,
215
info = g_malloc0 (sizeof (*info));
216
info->applet = applet;
217
info->device = g_object_ref (device);
218
info->ap = g_object_ref (ap);
220
_do_new_auto_connection (applet, device, ap, dbus_connect_8021x_cb, info);
210
add_ciphers_from_flags (NMSettingWirelessSecurity *sec,
215
if (flags & NM_802_11_AP_SEC_PAIR_TKIP)
216
nm_setting_wireless_security_add_pairwise (sec, "tkip");
217
if (flags & NM_802_11_AP_SEC_PAIR_CCMP)
218
nm_setting_wireless_security_add_pairwise (sec, "ccmp");
220
if (flags & NM_802_11_AP_SEC_GROUP_WEP40)
221
nm_setting_wireless_security_add_group (sec, "wep40");
222
if (flags & NM_802_11_AP_SEC_GROUP_WEP104)
223
nm_setting_wireless_security_add_group (sec, "wep104");
224
if (flags & NM_802_11_AP_SEC_GROUP_TKIP)
225
nm_setting_wireless_security_add_group (sec, "tkip");
226
if (flags & NM_802_11_AP_SEC_GROUP_CCMP)
227
nm_setting_wireless_security_add_group (sec, "ccmp");
231
static NMSettingWirelessSecurity *
232
get_security_for_ap (NMAccessPoint *ap,
235
NMSetting8021x **s_8021x)
237
NMSettingWirelessSecurity *sec;
243
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
244
g_return_val_if_fail (supported != NULL, NULL);
245
g_return_val_if_fail (*supported == TRUE, NULL);
246
g_return_val_if_fail (s_8021x != NULL, NULL);
247
g_return_val_if_fail (*s_8021x == NULL, NULL);
249
sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
251
mode = nm_access_point_get_mode (ap);
252
flags = nm_access_point_get_flags (ap);
253
wpa_flags = nm_access_point_get_wpa_flags (ap);
254
rsn_flags = nm_access_point_get_rsn_flags (ap);
257
if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
258
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
259
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
262
/* Static WEP, Dynamic WEP, or LEAP */
263
if (flags & NM_802_11_AP_FLAGS_PRIVACY) {
264
if ((dev_caps & NM_WIFI_DEVICE_CAP_RSN) || (dev_caps & NM_WIFI_DEVICE_CAP_WPA)) {
265
/* If the device can do WPA/RSN but the AP has no WPA/RSN informatoin
266
* elements, it must be LEAP or static/dynamic WEP.
268
if ((wpa_flags == NM_802_11_AP_SEC_NONE) && (rsn_flags == NM_802_11_AP_SEC_NONE)) {
270
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
271
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 0,
275
/* Otherwise, the AP supports WPA or RSN, which is preferred */
277
/* Device can't do WPA/RSN, but can at least pass through the
278
* WPA/RSN information elements from a scan. Since Privacy was
279
* advertised, LEAP or static/dynamic WEP must be in use.
282
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
283
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 0,
289
/* Stuff after this point requires infrastructure */
290
if (mode != NM_802_11_MODE_INFRA) {
296
if ( (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)
297
&& (dev_caps & NM_WIFI_DEVICE_CAP_RSN)) {
298
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
299
nm_setting_wireless_security_add_proto (sec, "rsn");
300
add_ciphers_from_flags (sec, rsn_flags, TRUE);
301
add_ciphers_from_flags (sec, rsn_flags, FALSE);
306
if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)
307
&& (dev_caps & NM_WIFI_DEVICE_CAP_WPA)) {
308
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
309
nm_setting_wireless_security_add_proto (sec, "wpa");
310
add_ciphers_from_flags (sec, wpa_flags, TRUE);
311
add_ciphers_from_flags (sec, wpa_flags, FALSE);
315
/* WPA2 Enterprise */
316
if ( (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
317
&& (dev_caps & NM_WIFI_DEVICE_CAP_RSN)) {
318
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
319
nm_setting_wireless_security_add_proto (sec, "rsn");
320
add_ciphers_from_flags (sec, rsn_flags, TRUE);
321
add_ciphers_from_flags (sec, rsn_flags, FALSE);
323
*s_8021x = NM_SETTING_802_1X (nm_setting_802_1x_new ());
324
nm_setting_802_1x_add_eap_method (*s_8021x, "ttls");
325
g_object_set (*s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
330
if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
331
&& (dev_caps & NM_WIFI_DEVICE_CAP_WPA)) {
332
g_object_set (sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
333
nm_setting_wireless_security_add_proto (sec, "wpa");
334
add_ciphers_from_flags (sec, wpa_flags, TRUE);
335
add_ciphers_from_flags (sec, wpa_flags, FALSE);
337
*s_8021x = NM_SETTING_802_1X (nm_setting_802_1x_new ());
338
nm_setting_802_1x_add_eap_method (*s_8021x, "ttls");
339
g_object_set (*s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
346
g_object_unref (sec);
351
313
clamp_ap_to_bssid (NMAccessPoint *ap, NMSettingWireless *s_wifi)
353
315
const char *str_bssid;
341
AppletNewAutoConnectionCallback callback;
342
gpointer callback_data;
346
more_info_wifi_dialog_response_cb (GtkDialog *foo,
350
NMAWirelessDialog *dialog = NMA_WIRELESS_DIALOG (foo);
351
MoreInfo *info = user_data;
352
NMConnection *connection = NULL;
353
NMDevice *device = NULL;
354
NMAccessPoint *ap = NULL;
356
if (response != GTK_RESPONSE_OK) {
357
info->callback (NULL, FALSE, TRUE, info->callback_data);
361
if (!nma_wireless_dialog_get_nag_ignored (dialog)) {
362
GtkWidget *nag_dialog;
364
/* Nag the user about certificates or whatever. Only destroy the dialog
365
* if no nagging was done.
367
nag_dialog = nma_wireless_dialog_nag_user (dialog);
369
gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
370
g_signal_connect (nag_dialog, "response",
371
G_CALLBACK (nag_dialog_response_cb),
377
/* nma_wireless_dialog_get_connection() returns a connection with the
378
* refcount incremented, so the caller must remember to unref it.
380
connection = nma_wireless_dialog_get_connection (dialog, &device, &ap);
381
g_assert (connection);
384
info->callback (connection, TRUE, FALSE, info->callback_data);
386
/* Balance nma_wireless_dialog_get_connection() */
387
g_object_unref (connection);
391
gtk_widget_hide (GTK_WIDGET (dialog));
392
gtk_widget_destroy (GTK_WIDGET (dialog));
396
_do_new_auto_connection (NMApplet *applet,
399
AppletNewAutoConnectionCallback callback,
400
gpointer callback_data)
402
NMConnection *connection = NULL;
403
NMSettingConnection *s_con = NULL;
404
NMSettingWireless *s_wifi = NULL;
405
NMSettingWirelessSecurity *s_wsec = NULL;
406
NMSetting8021x *s_8021x = NULL;
407
const GByteArray *ssid;
408
NM80211ApSecurityFlags wpa_flags, rsn_flags;
417
connection = nm_connection_new ();
419
ssid = nm_access_point_get_ssid (ap);
420
if ( (nm_access_point_get_mode (ap) == NM_802_11_MODE_INFRA)
421
&& (is_manufacturer_default_ssid (ssid) == TRUE)) {
423
/* Lock connection to this AP if it's a manufacturer-default SSID
424
* so that we don't randomly connect to some other 'linksys'
426
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
427
clamp_ap_to_bssid (ap, s_wifi);
428
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
431
/* If the AP is WPA[2]-Enterprise then we need to set up a minimal 802.1x
432
* setting and ask the user for more information.
434
rsn_flags = nm_access_point_get_rsn_flags (ap);
435
wpa_flags = nm_access_point_get_wpa_flags (ap);
436
if ( (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
437
|| (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
439
/* Need a UUID for the "always ask" stuff in the Dialog of Doom */
440
s_con = (NMSettingConnection *) nm_setting_connection_new ();
441
uuid = nm_utils_uuid_generate ();
442
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
444
nm_connection_add_setting (connection, NM_SETTING (s_con));
447
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
448
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
450
g_object_set (s_wifi,
451
NM_SETTING_WIRELESS_SSID, ssid,
452
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
455
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
456
g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
457
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
459
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
460
nm_setting_802_1x_add_eap_method (s_8021x, "ttls");
461
g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
462
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
465
/* If it's an 802.1x connection, we need more information, so pop up the
469
more_info = g_malloc0 (sizeof (*more_info));
470
more_info->applet = applet;
471
more_info->callback = callback;
472
more_info->callback_data = callback_data;
474
dialog = nma_wireless_dialog_new (applet, connection, device, ap);
476
g_signal_connect (dialog, "response",
477
G_CALLBACK (more_info_wifi_dialog_response_cb),
479
show_ignore_focus_stealing_prevention (dialog);
482
/* Everything else can just get activated right away */
483
callback (connection, TRUE, FALSE, callback_data);
378
488
wireless_new_auto_connection (NMDevice *device,
379
489
gpointer dclass_data,
381
491
gpointer callback_data)
383
493
WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) dclass_data;
384
NMConnection *connection = NULL;
385
NMSettingConnection *s_con = NULL;
386
NMSettingWireless *s_wireless = NULL;
387
NMSettingWirelessSecurity *s_wireless_sec = NULL;
388
NMSetting8021x *s_8021x = NULL;
389
const GByteArray *ap_ssid;
395
gboolean supported = TRUE;
398
g_warning ("%s: AP not set", __func__);
402
s_wireless = (NMSettingWireless *) nm_setting_wireless_new ();
404
ap_ssid = nm_access_point_get_ssid (info->ap);
405
g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, ap_ssid, NULL);
407
mode = nm_access_point_get_mode (info->ap);
408
if (mode == NM_802_11_MODE_ADHOC)
409
g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, "adhoc", NULL);
410
else if (mode == NM_802_11_MODE_INFRA) {
411
g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL);
412
/* Lock connection to this AP if it's a manufacturer-default SSID */
413
if (is_manufacturer_default_ssid (ap_ssid))
414
clamp_ap_to_bssid (info->ap, s_wireless);
416
g_assert_not_reached ();
418
dev_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device));
419
s_wireless_sec = get_security_for_ap (info->ap, dev_caps, &supported, &s_8021x);
421
g_warning ("Unsupported AP configuration: dev_caps 0x%X, ap_flags 0x%X, "
422
"wpa_flags 0x%X, rsn_flags 0x%x, mode %d",
424
nm_access_point_get_flags (info->ap),
425
nm_access_point_get_wpa_flags (info->ap),
426
nm_access_point_get_rsn_flags (info->ap),
427
nm_access_point_get_mode (info->ap));
428
g_object_unref (s_wireless);
430
} else if (s_wireless_sec)
431
g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL);
433
connection = nm_connection_new ();
434
nm_connection_add_setting (connection, NM_SETTING (s_wireless));
436
nm_connection_add_setting (connection, NM_SETTING (s_wireless_sec));
438
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
440
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
442
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
443
NM_SETTING_CONNECTION_AUTOCONNECT, !is_manufacturer_default_ssid (ap_ssid),
446
memset (buf, 0, sizeof (buf));
447
buf_len = MIN(ap_ssid->len, sizeof (buf) - 1);
448
memcpy (buf, ap_ssid->data, buf_len);
449
id = g_strdup_printf ("Auto %s", nm_utils_ssid_to_utf8 (buf, buf_len));
450
g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
453
id = nm_utils_uuid_generate ();
454
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, id, NULL);
457
nm_connection_add_setting (connection, NM_SETTING (s_con));
459
(*callback) (connection, TRUE, FALSE, callback_data);
495
g_return_val_if_fail (device != NULL, FALSE);
496
g_return_val_if_fail (info->ap != NULL, FALSE);
498
_do_new_auto_connection (info->applet, device, info->ap, callback, callback_data);
464
504
wireless_menu_item_activate (GtkMenuItem *item, gpointer user_data)
1446
1444
g_assert (connection);
1447
1445
g_assert (device);
1449
/* If it's a system connection we just need to tell NM to activate it */
1450
if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
1451
service = NM_DBUS_SERVICE_SYSTEM_SETTINGS;
1447
/* Find a similar connection and use that instead */
1448
all = applet_get_all_connections (applet);
1449
for (iter = all; iter; iter = g_slist_next (iter)) {
1450
if (nm_connection_compare (connection,
1451
NM_CONNECTION (iter->data),
1452
(NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) {
1453
fuzzy_match = NM_CONNECTION (iter->data);
1455
if (NMA_IS_GCONF_CONNECTION (connection)) {
1456
/* Not a new or system connection, save the updated settings to GConf */
1457
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
1460
nm_client_activate_connection (applet->nm_client,
1463
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
1464
activate_existing_cb,
1463
/* Find a similar connection and use that instead */
1464
all = applet_get_all_connections (applet);
1465
for (iter = all; iter; iter = g_slist_next (iter)) {
1466
if (nm_connection_compare (connection,
1467
NM_CONNECTION (iter->data),
1468
(NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) {
1469
fuzzy_match = g_object_ref (NM_CONNECTION (iter->data));
1476
if (nm_connection_get_scope (fuzzy_match) == NM_CONNECTION_SCOPE_SYSTEM) {
1477
// FIXME: do something other than just use the system connection?
1479
NMSettingWirelessSecurity *s_wireless_sec;
1481
/* Copy secrets & wireless security */
1482
s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
1483
if (s_wireless_sec) {
1485
NMSetting *dup_setting;
1487
hash = nm_setting_to_hash (NM_SETTING (s_wireless_sec));
1488
dup_setting = nm_setting_new_from_hash (NM_TYPE_SETTING_WIRELESS_SECURITY, hash);
1489
g_hash_table_destroy (hash);
1490
nm_connection_add_setting (fuzzy_match, dup_setting);
1494
/* Balance nma_wireless_dialog_get_connection() */
1495
g_object_unref (connection);
1496
connection = g_object_ref (fuzzy_match);
1498
/* Entirely new connection */
1499
NMAGConfConnection *new_gconf_connection;
1500
NMSettingConnection *s_con;
1503
/* Update a new connection's name and autoconnect status */
1504
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
1505
id = (char *) nm_setting_connection_get_id (s_con);
1508
NMSettingWireless *s_wireless;
1509
const GByteArray *ssid;
1512
s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
1513
ssid = nm_setting_wireless_get_ssid (s_wireless);
1515
id = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
1516
g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
1519
// FIXME: don't autoconnect until the connection is successful at least once
1520
/* Don't autoconnect adhoc networks by default for now */
1521
mode = nm_setting_wireless_get_mode (s_wireless);
1522
if (!mode || !strcmp (mode, "infrastructure"))
1523
g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
1526
/* Export it over D-Bus */
1527
new_gconf_connection = nma_gconf_settings_add_connection (applet->gconf_settings, connection);
1528
if (!new_gconf_connection) {
1529
nm_warning ("Couldn't create new network connection.");
1533
/* Balance nma_wireless_dialog_get_connection() */
1534
g_object_unref (connection);
1535
connection = g_object_ref (new_gconf_connection);
1468
NMSettingWireless *s_wifi = NULL;
1469
const char *mode = NULL;
1471
/* Entirely new connection */
1473
/* Don't autoconnect adhoc networks by default for now */
1474
s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
1476
mode = nm_setting_wireless_get_mode (s_wifi);
1477
if (g_strcmp0 (mode, "adhoc") == 0) {
1478
s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
1480
s_con = nm_setting_connection_new ();
1481
nm_connection_add_setting (connection, s_con);
1483
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
1486
nm_client_add_and_activate_connection (applet->nm_client,
1489
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
1540
nm_client_activate_connection (applet->nm_client,
1542
nm_connection_get_path (connection),
1544
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
1494
/* Balance nma_wireless_dialog_get_connection() */
1495
g_object_unref (connection);
1549
/* Balance nma_wireless_dialog_get_connection() */
1551
g_object_unref (connection);
1553
1498
gtk_widget_hide (GTK_WIDGET (dialog));
1554
1499
gtk_widget_destroy (GTK_WIDGET (dialog));
1558
wireless_get_more_info (NMDevice *device,
1559
NMConnection *connection,
1563
WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) user_data;
1566
dialog = nma_wireless_dialog_new (applet, connection, device, info->ap);
1567
g_return_if_fail (dialog != NULL);
1569
g_signal_connect (dialog, "response",
1570
G_CALLBACK (wireless_dialog_response_cb),
1573
show_ignore_focus_stealing_prevention (dialog);
1576
1502
static gboolean
1577
1503
add_one_setting (GHashTable *settings,
1578
1504
NMConnection *connection,
1658
/* Got a user response, clear the NMActiveConnection destroy handler for
1659
* this dialog since this function will now take over dialog destruction.
1661
g_object_weak_unref (G_OBJECT (info->active_connection), destroy_wifi_dialog, info);
1663
1581
if (response != GTK_RESPONSE_OK) {
1664
1582
g_set_error (&error,
1665
NM_SETTINGS_INTERFACE_ERROR,
1666
NM_SETTINGS_INTERFACE_ERROR_SECRETS_REQUEST_CANCELED,
1583
NM_SECRET_AGENT_ERROR,
1584
NM_SECRET_AGENT_ERROR_USER_CANCELED,
1667
1585
"%s.%d (%s): canceled",
1668
1586
__FILE__, __LINE__, __func__);
1672
connection = nma_wireless_dialog_get_connection (dialog, &device, NULL);
1590
connection = nma_wireless_dialog_get_connection (dialog, NULL, NULL);
1673
1591
if (!connection) {
1674
1592
g_set_error (&error,
1675
NM_SETTINGS_INTERFACE_ERROR,
1676
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1593
NM_SECRET_AGENT_ERROR,
1594
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
1677
1595
"%s.%d (%s): couldn't get connection from wireless dialog.",
1678
1596
__FILE__, __LINE__, __func__);
1738
1656
/* Add the 802-11-wireless-security setting no matter what */
1739
if (!add_one_setting (settings, connection, NM_SETTING (s_wireless_sec), &error))
1742
info->callback (NM_SETTINGS_CONNECTION_INTERFACE (connection), settings, NULL, info->callback_data);
1744
/* Save the connection back to GConf _after_ hashing it, because
1745
* saving to GConf might trigger the GConf change notifiers, resulting
1746
* in the connection being read back in from GConf which clears secrets.
1748
if (NMA_IS_GCONF_CONNECTION (connection)) {
1749
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
1657
add_one_setting (settings, connection, NM_SETTING (s_wireless_sec), &error);
1660
applet_secrets_request_complete (req, settings, error);
1661
applet_secrets_request_free (req);
1756
1664
g_hash_table_destroy (settings);
1759
g_warning ("%s", error->message);
1760
info->callback (NM_SETTINGS_CONNECTION_INTERFACE (connection), NULL, error, info->callback_data);
1761
g_error_free (error);
1764
1665
if (connection)
1765
1666
nm_connection_clear_secrets (connection);
1767
destroy_wifi_dialog (info, NULL);
1770
1669
static gboolean
1771
wireless_get_secrets (NMDevice *device,
1772
NMSettingsConnectionInterface *connection,
1773
NMActiveConnection *active_connection,
1774
const char *setting_name,
1776
NMANewSecretsRequestedFunc callback,
1777
gpointer callback_data,
1670
wireless_get_secrets (SecretsRequest *req, GError **error)
1783
const char *specific_object;
1785
if (!setting_name || !active_connection) {
1787
NM_SETTINGS_INTERFACE_ERROR,
1788
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1789
"%s.%d (%s): setting name and active connection object required",
1790
__FILE__, __LINE__, __func__);
1794
specific_object = nm_active_connection_get_specific_object (active_connection);
1795
if (!specific_object) {
1797
NM_SETTINGS_INTERFACE_ERROR,
1798
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1799
"%s.%d (%s): could not determine AP for specific object",
1800
__FILE__, __LINE__, __func__);
1804
info = g_malloc0 (sizeof (NMWifiInfo));
1806
ap = nm_device_wifi_get_access_point_by_path (NM_DEVICE_WIFI (device), specific_object);
1807
info->dialog = nma_wireless_dialog_new (applet, NM_CONNECTION (connection), device, ap);
1808
if (!info->dialog) {
1810
NM_SETTINGS_INTERFACE_ERROR,
1811
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
1672
NMWifiInfo *info = (NMWifiInfo *) req;
1674
applet_secrets_request_set_free_func (req, free_wifi_info);
1676
info->dialog = nma_wireless_dialog_new (req->applet, req->connection, NULL, NULL);
1678
g_signal_connect (info->dialog, "response",
1679
G_CALLBACK (get_secrets_dialog_response_cb),
1681
show_ignore_focus_stealing_prevention (info->dialog);
1684
NM_SECRET_AGENT_ERROR,
1685
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
1812
1686
"%s.%d (%s): couldn't display secrets UI",
1813
1687
__FILE__, __LINE__, __func__);
1818
info->applet = applet;
1819
info->active_connection = active_connection;
1820
info->callback = callback;
1821
info->callback_data = callback_data;
1822
info->setting_name = g_strdup (setting_name);
1824
g_signal_connect (info->dialog, "response",
1825
G_CALLBACK (get_secrets_dialog_response_cb),
1828
/* Attach a destroy notifier to the NMActiveConnection so we can destroy
1829
* the dialog when the active connection goes away.
1831
g_object_weak_ref (G_OBJECT (active_connection), destroy_wifi_dialog, info);
1833
show_ignore_focus_stealing_prevention (info->dialog);
1689
return !!info->dialog;
1837
1692
NMADeviceClass *