20
20
* Copyright 2008 - 2011 Red Hat, Inc.
23
#include <shell/cc-shell.h>
25
#include <nm-connection.h>
26
#include <nm-setting-gsm.h>
27
#include <nm-setting-cdma.h>
28
#include <nm-setting-serial.h>
29
#include <nm-device-modem.h>
30
#include <nm-device-wifi.h>
23
#include <NetworkManager.h>
24
#include <nma-wifi-dialog.h>
25
#include <nma-mobile-wizard.h>
32
27
#include "network-dialogs.h"
33
#include "nm-wifi-dialog.h"
34
#include "nm-mobile-wizard.h"
38
NMRemoteSettings *settings;
39
31
} WirelessDialogClosure;
43
NMRemoteSettings *settings;
45
36
} MobileDialogClosure;
51
42
WirelessDialogClosure *closure = data;
52
43
g_object_unref (closure->client);
53
g_object_unref (closure->settings);
55
45
g_slice_free (WirelessDialogClosure, data);
61
51
MobileDialogClosure *closure = data;
62
52
g_object_unref (closure->client);
63
g_object_unref (closure->settings);
64
53
g_object_unref (closure->device);
66
55
g_slice_free (MobileDialogClosure, data);
86
activate_existing_cb (NMClient *client,
87
NMActiveConnection *active,
75
activate_existing_cb (GObject *source_object,
89
77
gpointer user_data)
81
if (!nm_client_activate_connection_finish (NM_CLIENT (source_object), res, &error)) {
92
82
g_warning ("Failed to activate connection: (%d) %s", error->code, error->message);
96
activate_new_cb (NMClient *client,
97
NMActiveConnection *active,
98
const char *connection_path,
88
activate_new_cb (GObject *source_object,
100
90
gpointer user_data)
94
if (!nm_client_add_and_activate_connection_finish (NM_CLIENT (source_object), res, &error)) {
103
95
g_warning ("Failed to add new connection: (%d) %s", error->code, error->message);
107
nag_dialog_response_cb (GtkDialog *nag_dialog,
111
NMAWifiDialog *wireless_dialog = NMA_WIFI_DIALOG (user_data);
113
if (response == GTK_RESPONSE_NO) { /* user opted not to correct the warning */
114
nma_wifi_dialog_set_nag_ignored (wireless_dialog, TRUE);
115
gtk_dialog_response (GTK_DIALOG (wireless_dialog), GTK_RESPONSE_OK);
126
107
NMConnection *connection, *fuzzy_match = NULL;
127
108
NMDevice *device;
128
109
NMAccessPoint *ap;
110
const GPtrArray *all;
131
113
if (response != GTK_RESPONSE_OK)
134
if (!nma_wifi_dialog_get_nag_ignored (dialog)) {
135
GtkWidget *nag_dialog;
137
/* Nag the user about certificates or whatever. Only destroy the dialog
138
* if no nagging was done.
140
nag_dialog = nma_wifi_dialog_nag_user (dialog);
142
gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
143
g_signal_connect (nag_dialog, "response",
144
G_CALLBACK (nag_dialog_response_cb),
150
116
/* nma_wifi_dialog_get_connection() returns a connection with the
151
117
* refcount incremented, so the caller must remember to unref it.
155
121
g_assert (device);
157
123
/* Find a similar connection and use that instead */
158
all = nm_remote_settings_list_connections (closure->settings);
159
for (iter = all; iter; iter = g_slist_next (iter)) {
124
all = nm_client_get_connections (closure->client);
125
for (i = 0; i < all->len; i++) {
160
126
if (nm_connection_compare (connection,
161
NM_CONNECTION (iter->data),
127
NM_CONNECTION (g_ptr_array_index (all, i)),
162
128
(NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) {
163
fuzzy_match = NM_CONNECTION (iter->data);
129
fuzzy_match = NM_CONNECTION (g_ptr_array_index (all, i));
169
134
if (fuzzy_match) {
170
nm_client_activate_connection (closure->client,
173
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
174
activate_existing_cb,
135
nm_client_activate_connection_async (closure->client,
138
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
140
activate_existing_cb,
177
143
NMSetting *s_con;
178
144
NMSettingWireless *s_wifi;
193
159
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
196
nm_client_add_and_activate_connection (closure->client,
199
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
162
nm_client_add_and_activate_connection_async (closure->client,
165
ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
204
171
/* Balance nma_wifi_dialog_get_connection() */
213
show_wireless_dialog (CcNetworkPanel *panel,
180
show_wireless_dialog (GtkWidget *toplevel,
214
181
NMClient *client,
215
NMRemoteSettings *settings,
216
182
GtkWidget *dialog)
218
GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
219
184
WirelessDialogClosure *closure;
221
186
g_debug ("About to parent and show a network dialog");
229
194
closure = g_slice_new (WirelessDialogClosure);
230
195
closure->client = g_object_ref (client);
231
closure->settings = g_object_ref (settings);
232
196
g_signal_connect_data (dialog, "response",
233
197
G_CALLBACK (wireless_dialog_response_cb),
234
198
closure, wireless_dialog_closure_closure_notify, 0);
242
cc_network_panel_create_wifi_network (CcNetworkPanel *panel,
244
NMRemoteSettings *settings)
206
cc_network_panel_create_wifi_network (GtkWidget *toplevel,
246
209
if (wifi_can_create_wifi_network (client)) {
247
show_wireless_dialog (panel, client, settings,
248
nma_wifi_dialog_new_for_create (client, settings));
210
show_wireless_dialog (toplevel, client,
211
nma_wifi_dialog_new_for_create (client));
253
cc_network_panel_connect_to_hidden_network (CcNetworkPanel *panel,
255
NMRemoteSettings *settings)
216
cc_network_panel_connect_to_hidden_network (GtkWidget *toplevel,
257
219
g_debug ("connect to hidden wifi");
258
show_wireless_dialog (panel, client, settings,
259
nma_wifi_dialog_new_for_other (client, settings));
220
show_wireless_dialog (toplevel, client,
221
nma_wifi_dialog_new_for_hidden (client));
263
cc_network_panel_connect_to_8021x_network (CcNetworkPanel *panel,
225
cc_network_panel_connect_to_8021x_network (GtkWidget *toplevel,
264
226
NMClient *client,
265
NMRemoteSettings *settings,
266
227
NMDevice *device,
267
228
const gchar *arg_access_point)
298
connection = nm_connection_new ();
259
connection = nm_simple_connection_new ();
300
261
/* Need a UUID for the "always ask" stuff in the Dialog of Doom */
301
262
s_con = (NMSettingConnection *) nm_setting_connection_new ();
308
269
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
309
270
g_object_set (s_wifi,
310
271
NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid (ap),
311
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
314
274
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
320
280
g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
321
281
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
323
dialog = nma_wifi_dialog_new (client, settings, connection, device, ap, FALSE);
324
show_wireless_dialog (panel, client, settings, dialog);
283
dialog = nma_wifi_dialog_new (client, connection, device, ap, FALSE);
284
show_wireless_dialog (toplevel, client, dialog);
337
297
/* Ask NM to add the new connection and activate it; NM will fill in the
338
298
* missing details based on the specific object and the device.
340
nm_client_add_and_activate_connection (closure->client,
300
nm_client_add_and_activate_connection_async (closure->client,
348
309
mobile_dialog_closure_free (closure);
496
cc_network_panel_connect_to_3g_network (CcNetworkPanel *panel,
457
cc_network_panel_connect_to_3g_network (GtkWidget *toplevel,
497
458
NMClient *client,
498
NMRemoteSettings *settings,
499
459
NMDevice *device)
501
GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
502
461
MobileDialogClosure *closure;
503
462
NMAMobileWizard *wizard;
504
463
NMDeviceModemCapabilities caps;
514
473
closure = g_slice_new (MobileDialogClosure);
515
474
closure->client = g_object_ref (client);
516
closure->settings = g_object_ref (settings);
517
475
closure->device = g_object_ref (device);
519
477
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));