~khurshid-alam/unity-control-center/use-usd-schemas

« back to all changes in this revision

Viewing changes to panels/network/network-dialogs.c

  • Committer: Sebastien Bacher
  • Author(s): Khurshid Alam
  • Date: 2019-05-17 07:34:33 UTC
  • mfrom: (12920.1.1 unity-control-center)
  • Revision ID: seb128@ubuntu.com-20190517073433-ch2kybdhhzpkmvq4
Network: Port to libnm 1.2 (lp: #1744619)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Copyright 2008 - 2011 Red Hat, Inc. 
21
21
 */
22
22
 
23
 
#include <shell/cc-shell.h>
24
 
#include <nm-utils.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>
31
26
 
32
27
#include "network-dialogs.h"
33
 
#include "nm-wifi-dialog.h"
34
 
#include "nm-mobile-wizard.h"
35
28
 
36
29
typedef struct {
37
30
        NMClient *client;
38
 
        NMRemoteSettings *settings;
39
31
} WirelessDialogClosure;
40
32
 
41
33
typedef struct {
42
34
        NMClient *client;
43
 
        NMRemoteSettings *settings;
44
35
        NMDevice *device;
45
36
} MobileDialogClosure;
46
37
 
50
41
{
51
42
        WirelessDialogClosure *closure = data;
52
43
        g_object_unref (closure->client);
53
 
        g_object_unref (closure->settings);
54
44
 
55
45
        g_slice_free (WirelessDialogClosure, data);
56
46
}
60
50
{
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);
65
54
 
66
55
        g_slice_free (MobileDialogClosure, data);
83
72
}
84
73
 
85
74
static void
86
 
activate_existing_cb (NMClient *client,
87
 
                      NMActiveConnection *active,
88
 
                      GError *error,
 
75
activate_existing_cb (GObject *source_object,
 
76
                      GAsyncResult *res,
89
77
                      gpointer user_data)
90
78
{
91
 
        if (error)
 
79
        GError *error = NULL;
 
80
 
 
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);
 
83
                g_error_free (error);
 
84
        }
93
85
}
94
86
 
95
87
static void
96
 
activate_new_cb (NMClient *client,
97
 
                 NMActiveConnection *active,
98
 
                 const char *connection_path,
99
 
                 GError *error,
 
88
activate_new_cb (GObject *source_object,
 
89
                 GAsyncResult *res,
100
90
                 gpointer user_data)
101
91
{
102
 
        if (error)
 
92
        GError *error = NULL;
 
93
 
 
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);
104
 
}
105
 
 
106
 
static void
107
 
nag_dialog_response_cb (GtkDialog *nag_dialog,
108
 
                        gint response,
109
 
                        gpointer user_data)
110
 
{
111
 
        NMAWifiDialog *wireless_dialog = NMA_WIFI_DIALOG (user_data);
112
 
 
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);
 
96
                g_error_free (error);
116
97
        }
117
98
}
118
99
 
126
107
        NMConnection *connection, *fuzzy_match = NULL;
127
108
        NMDevice *device;
128
109
        NMAccessPoint *ap;
129
 
        GSList *all, *iter;
 
110
        const GPtrArray *all;
 
111
        guint i;
130
112
 
131
113
        if (response != GTK_RESPONSE_OK)
132
114
                goto done;
133
115
 
134
 
        if (!nma_wifi_dialog_get_nag_ignored (dialog)) {
135
 
                GtkWidget *nag_dialog;
136
 
 
137
 
                /* Nag the user about certificates or whatever.  Only destroy the dialog
138
 
                 * if no nagging was done.
139
 
                 */
140
 
                nag_dialog = nma_wifi_dialog_nag_user (dialog);
141
 
                if (nag_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),
145
 
                                          dialog);
146
 
                        return;
147
 
                }
148
 
        }
149
 
 
150
116
        /* nma_wifi_dialog_get_connection() returns a connection with the
151
117
         * refcount incremented, so the caller must remember to unref it.
152
118
         */
155
121
        g_assert (device);
156
122
 
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));
164
130
                        break;
165
131
                }
166
132
        }
167
 
        g_slist_free (all);
168
133
 
169
134
        if (fuzzy_match) {
170
 
                nm_client_activate_connection (closure->client,
171
 
                                               fuzzy_match,
172
 
                                               device,
173
 
                                               ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
174
 
                                               activate_existing_cb,
175
 
                                               NULL);
 
135
                nm_client_activate_connection_async (closure->client,
 
136
                                                     fuzzy_match,
 
137
                                                     device,
 
138
                                                     ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
 
139
                                                     NULL,
 
140
                                                     activate_existing_cb,
 
141
                                                     NULL);
176
142
        } else {
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);
194
160
                }
195
161
 
196
 
                nm_client_add_and_activate_connection (closure->client,
197
 
                                                       connection,
198
 
                                                       device,
199
 
                                                       ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
200
 
                                                       activate_new_cb,
201
 
                                                       NULL);
 
162
                nm_client_add_and_activate_connection_async (closure->client,
 
163
                                                             connection,
 
164
                                                             device,
 
165
                                                             ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
 
166
                                                             NULL,
 
167
                                                             activate_new_cb,
 
168
                                                             NULL);
202
169
        }
203
170
 
204
171
        /* Balance nma_wifi_dialog_get_connection() */
210
177
}
211
178
 
212
179
static void
213
 
show_wireless_dialog (CcNetworkPanel   *panel,
 
180
show_wireless_dialog (GtkWidget        *toplevel,
214
181
                      NMClient         *client,
215
 
                      NMRemoteSettings *settings,
216
182
                      GtkWidget        *dialog)
217
183
{
218
 
        GtkWidget *toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
219
184
        WirelessDialogClosure *closure;
220
185
 
221
186
        g_debug ("About to parent and show a network dialog");
228
193
 
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);
239
203
}
240
204
 
241
205
void
242
 
cc_network_panel_create_wifi_network (CcNetworkPanel   *panel,
243
 
                                      NMClient         *client,
244
 
                                      NMRemoteSettings *settings)
 
206
cc_network_panel_create_wifi_network (GtkWidget        *toplevel,
 
207
                                      NMClient         *client)
245
208
{
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));
249
212
  }
250
213
}
251
214
 
252
215
void
253
 
cc_network_panel_connect_to_hidden_network (CcNetworkPanel   *panel,
254
 
                                            NMClient         *client,
255
 
                                            NMRemoteSettings *settings)
 
216
cc_network_panel_connect_to_hidden_network (GtkWidget        *toplevel,
 
217
                                            NMClient         *client)
256
218
{
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));
260
222
}
261
223
 
262
224
void
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)
268
229
{
295
256
                return;
296
257
        }
297
258
 
298
 
        connection = nm_connection_new ();
 
259
        connection = nm_simple_connection_new ();
299
260
 
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,
312
272
                      NULL);
313
273
 
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));
322
282
 
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);
325
285
}
326
286
 
327
287
static void
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.
339
299
                 */
340
 
                nm_client_add_and_activate_connection (closure->client,
341
 
                                                       connection,
342
 
                                                       closure->device,
343
 
                                                       "/",
344
 
                                                       activate_new_cb,
345
 
                                                       NULL);
 
300
                nm_client_add_and_activate_connection_async (closure->client,
 
301
                                                             connection,
 
302
                                                             closure->device,
 
303
                                                             "/",
 
304
                                                             NULL,
 
305
                                                             activate_new_cb,
 
306
                                                             NULL);
346
307
        }
347
308
 
348
309
        mobile_dialog_closure_free (closure);
366
327
                        goto done;
367
328
                }
368
329
 
369
 
                connection = nm_connection_new ();
 
330
                connection = nm_simple_connection_new ();
370
331
 
371
332
                setting = nm_setting_cdma_new ();
372
333
                g_object_set (setting,
428
389
                        goto done;
429
390
                }
430
391
 
431
 
                connection = nm_connection_new ();
 
392
                connection = nm_simple_connection_new ();
432
393
 
433
394
                setting = nm_setting_gsm_new ();
434
395
                g_object_set (setting,
493
454
}
494
455
 
495
456
void
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)
500
460
{
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;
513
472
 
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);
518
476
 
519
477
        caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));