293
275
gpointer user_data)
295
NMBtSecretsInfo *info = user_data;
277
SecretsRequest *req = user_data;
278
NMBtSecretsInfo *info = (NMBtSecretsInfo *) req;
296
279
NMSetting *setting;
297
GHashTable *settings_hash;
301
/* Got a user response, clear the NMActiveConnection destroy handler for
302
* this dialog since this function will now take over dialog destruction.
304
g_object_weak_unref (G_OBJECT (info->active_connection), destroy_secrets_dialog, info);
306
if (response != GTK_RESPONSE_OK) {
308
NM_SETTINGS_INTERFACE_ERROR,
309
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
280
GError *error = NULL;
282
if (response == GTK_RESPONSE_OK) {
283
setting = nm_connection_get_setting_by_name (req->connection, req->setting_name);
285
/* Normally we'd want to get all the settings's secrets and return those
286
* to NM too (since NM wants them), but since the only other secrets for 3G
287
* connections are PINs, and since the phone obviously has to be unlocked
288
* to even make the Bluetooth connection, we can skip doing that here for
292
/* Update the password */
293
g_object_set (G_OBJECT (setting),
294
info->secret_name, gtk_entry_get_text (info->secret_entry),
298
NM_SECRET_AGENT_ERROR,
299
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
300
"%s.%d (%s): unhandled setting '%s'",
301
__FILE__, __LINE__, __func__, req->setting_name);
305
NM_SECRET_AGENT_ERROR,
306
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
310
307
"%s.%d (%s): canceled",
311
308
__FILE__, __LINE__, __func__);
315
setting = nm_connection_get_setting_by_name (NM_CONNECTION (info->connection), info->setting_name);
318
NM_SETTINGS_INTERFACE_ERROR,
319
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
320
"%s.%d (%s): unhandled setting '%s'",
321
__FILE__, __LINE__, __func__, info->setting_name);
325
/* Normally we'd want to get all the settings's secrets and return those
326
* to NM too (since NM wants them), but since the only other secrets for 3G
327
* connections are PINs, and since the phone obviously has to be unlocked
328
* to even make the Bluetooth connection, we can skip doing that here for
332
/* Update the password */
333
g_object_set (G_OBJECT (setting),
334
info->secret_name, gtk_entry_get_text (info->secret_entry),
337
secrets = nm_setting_to_hash (NM_SETTING (setting));
340
NM_SETTINGS_INTERFACE_ERROR,
341
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
342
"%s.%d (%s): failed to hash setting '%s'.",
343
__FILE__, __LINE__, __func__,
344
nm_setting_get_name (NM_SETTING (setting)));
348
/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
349
* will contain all the individual settings hashes.
351
settings_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
352
g_free, (GDestroyNotify) g_hash_table_destroy);
354
g_hash_table_insert (settings_hash, g_strdup (nm_setting_get_name (NM_SETTING (setting))), secrets);
355
info->callback (info->connection, settings_hash, NULL, info->callback_data);
356
g_hash_table_destroy (settings_hash);
358
/* Save the connection back to GConf _after_ hashing it, because
359
* saving to GConf might trigger the GConf change notifiers, resulting
360
* in the connection being read back in from GConf which clears secrets.
362
if (NMA_IS_GCONF_CONNECTION (info->connection))
363
nm_settings_connection_interface_update (info->connection, update_cb, NULL);
367
g_warning ("%s", err->message);
368
info->callback (info->connection, NULL, err, info->callback_data);
372
nm_connection_clear_secrets (NM_CONNECTION (info->connection));
373
destroy_secrets_dialog (info, NULL);
311
applet_secrets_request_complete_setting (req, req->setting_name, error);
312
applet_secrets_request_free (req);
313
g_clear_error (&error);
377
bt_get_secrets (NMDevice *device,
378
NMSettingsConnectionInterface *connection,
379
NMActiveConnection *active_connection,
380
const char *setting_name,
382
NMANewSecretsRequestedFunc callback,
383
gpointer callback_data,
317
bt_get_secrets (SecretsRequest *req, GError **error)
387
NMBtSecretsInfo *info;
319
NMBtSecretsInfo *info = (NMBtSecretsInfo *) req;
388
320
GtkWidget *widget;
389
321
GtkEntry *secret_entry = NULL;
391
if (!hints || !g_strv_length ((char **) hints)) {
323
applet_secrets_request_set_free_func (req, free_bt_secrets_info);
325
if (!req->hints || !g_strv_length (req->hints)) {
392
326
g_set_error (error,
393
NM_SETTINGS_INTERFACE_ERROR,
394
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
327
NM_SECRET_AGENT_ERROR,
328
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
395
329
"%s.%d (%s): missing secrets hints.",
396
330
__FILE__, __LINE__, __func__);
333
info->secret_name = g_strdup (req->hints[0]);
400
if ( (!strcmp (setting_name, NM_SETTING_CDMA_SETTING_NAME) && !strcmp (hints[0], NM_SETTING_CDMA_PASSWORD))
401
|| (!strcmp (setting_name, NM_SETTING_GSM_SETTING_NAME) && !strcmp (hints[0], NM_SETTING_GSM_PASSWORD)))
402
widget = applet_mobile_password_dialog_new (device, NM_CONNECTION (connection), &secret_entry);
335
if ( (!strcmp (req->setting_name, NM_SETTING_CDMA_SETTING_NAME) && !strcmp (info->secret_name, NM_SETTING_CDMA_PASSWORD))
336
|| (!strcmp (req->setting_name, NM_SETTING_GSM_SETTING_NAME) && !strcmp (info->secret_name, NM_SETTING_GSM_PASSWORD)))
337
widget = applet_mobile_password_dialog_new (req->connection, &secret_entry);
404
339
g_set_error (error,
405
NM_SETTINGS_INTERFACE_ERROR,
406
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
340
NM_SECRET_AGENT_ERROR,
341
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
407
342
"%s.%d (%s): unknown secrets hint '%s'.",
408
__FILE__, __LINE__, __func__, hints[0]);
343
__FILE__, __LINE__, __func__, info->secret_name);
346
info->dialog = widget;
347
info->secret_entry = secret_entry;
412
349
if (!widget || !secret_entry) {
413
350
g_set_error (error,
414
NM_SETTINGS_INTERFACE_ERROR,
415
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
351
NM_SECRET_AGENT_ERROR,
352
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
416
353
"%s.%d (%s): error asking for CDMA secrets.",
417
354
__FILE__, __LINE__, __func__);
421
info = g_malloc0 (sizeof (NMBtSecretsInfo));
422
info->callback = callback;
423
info->callback_data = callback_data;
424
info->applet = applet;
425
info->active_connection = active_connection;
426
info->connection = g_object_ref (connection);
427
info->secret_name = g_strdup (hints[0]);
428
info->setting_name = g_strdup (setting_name);
429
info->dialog = widget;
430
info->secret_entry = secret_entry;
432
358
g_signal_connect (widget, "response", G_CALLBACK (get_bt_secrets_cb), info);
434
/* Attach a destroy notifier to the NMActiveConnection so we can destroy
435
* the dialog when the active connection goes away.
437
g_object_weak_ref (G_OBJECT (active_connection), destroy_secrets_dialog, info);
439
360
gtk_window_set_position (GTK_WINDOW (widget), GTK_WIN_POS_CENTER_ALWAYS);
440
361
gtk_widget_realize (GTK_WIDGET (widget));
441
362
gtk_window_present (GTK_WINDOW (widget));