~ubuntu-branches/ubuntu/saucy/network-manager-applet/saucy-updates

« back to all changes in this revision

Viewing changes to src/mobile-helpers.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2013-02-05 16:15:00 UTC
  • mfrom: (1.2.33)
  • Revision ID: package-import@ubuntu.com-20130205161500-nax1yrh7klr0o8ir
Tags: 0.9.7.995+git201301311844.0376019-0ubuntu1
* upstream snapshot 2013-01-31 18:44:13 (GMT)
  + 03760194e54eaeaf493e9b45c4835e84524d8650
* debian/patches/nm-applet-use-indicator.patch: refreshed.
* debian/patches/lp1048516_dont_req_keyring_in_greeter.patch: refreshed.
* debian/patches/lp289466_always_show_tray_icon.patch: refreshed.
* debian/patches/lp829673_gconf_hide_applet.patch: refreshed.
* debian/patches/position_dialogs_to_center_of_the_screen.patch: refreshed.
* debian/patches/hide_policy_items_env_var.patch: refreshed.
* debian/patches/lp1048520_delay_pin_dialog_in_greeter.patch: refreshed.
* debian/patches/nm-applet-use-indicator.patch: fix the addition of separator
  menu items to avoid multiple separators added in a block.
* debian/control: bump network-manager Depends and Build-Depends to the
  appropriate snapshot version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * (C) Copyright 2010 Red Hat, Inc.
21
21
 */
22
22
 
 
23
#include <ctype.h>
 
24
#include <glib/gi18n.h>
 
25
#include <nm-utils.h>
 
26
#include <gnome-keyring.h>
 
27
 
 
28
#include "utils.h"
23
29
#include "mobile-helpers.h"
24
 
#include <glib/gi18n.h>
 
30
#include "applet-dialogs.h"
25
31
 
26
32
GdkPixbuf *
27
33
mobile_helper_get_status_pixbuf (guint32 quality,
131
137
        switch (tech) {
132
138
        case MB_TECH_1XRTT:
133
139
                return _("CDMA");
134
 
        case MB_TECH_EVDO_REV0:
135
 
        case MB_TECH_EVDO_REVA:
 
140
        case MB_TECH_EVDO:
136
141
                return _("EVDO");
137
142
        case MB_TECH_GSM:
138
143
                return _("GSM");
243
248
        switch (tech) {
244
249
        case MB_TECH_1XRTT:
245
250
                return nma_icon_check_and_load ("nm-tech-cdma-1x", &applet->mb_tech_1x_icon, applet);
246
 
        case MB_TECH_EVDO_REV0:
247
 
        case MB_TECH_EVDO_REVA:
 
251
        case MB_TECH_EVDO:
248
252
                return nma_icon_check_and_load ("nm-tech-evdo", &applet->mb_tech_evdo_icon, applet);
249
253
        case MB_TECH_GSM:
250
254
        case MB_TECH_GPRS:
266
270
        }
267
271
}
268
272
 
 
273
/********************************************************************/
 
274
 
 
275
typedef struct {
 
276
        AppletNewAutoConnectionCallback callback;
 
277
        gpointer callback_data;
 
278
        NMDeviceModemCapabilities requested_capability;
 
279
} AutoWizardInfo;
 
280
 
 
281
static void
 
282
mobile_wizard_done (NMAMobileWizard *wizard,
 
283
                    gboolean cancelled,
 
284
                    NMAMobileWizardAccessMethod *method,
 
285
                    gpointer user_data)
 
286
{
 
287
        AutoWizardInfo *info = user_data;
 
288
        NMConnection *connection = NULL;
 
289
 
 
290
        if (!cancelled && method) {
 
291
                NMSetting *setting;
 
292
                char *uuid, *id;
 
293
                const char *setting_name;
 
294
 
 
295
                if (method->devtype != info->requested_capability) {
 
296
                        g_warning ("Unexpected device type");
 
297
                        cancelled = TRUE;
 
298
                        goto done;
 
299
                }
 
300
 
 
301
                connection = nm_connection_new ();
 
302
 
 
303
                if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
 
304
                        setting_name = NM_SETTING_CDMA_SETTING_NAME;
 
305
                        setting = nm_setting_cdma_new ();
 
306
                        g_object_set (setting,
 
307
                                      NM_SETTING_CDMA_NUMBER, "#777",
 
308
                                      NM_SETTING_CDMA_USERNAME, method->username,
 
309
                                      NM_SETTING_CDMA_PASSWORD, method->password,
 
310
                                      NULL);
 
311
                        nm_connection_add_setting (connection, setting);
 
312
                } else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
 
313
                        setting_name = NM_SETTING_GSM_SETTING_NAME;
 
314
                        setting = nm_setting_gsm_new ();
 
315
                        g_object_set (setting,
 
316
                                      NM_SETTING_GSM_NUMBER, "*99#",
 
317
                                      NM_SETTING_GSM_USERNAME, method->username,
 
318
                                      NM_SETTING_GSM_PASSWORD, method->password,
 
319
                                      NM_SETTING_GSM_APN, method->gsm_apn,
 
320
                                      NULL);
 
321
                        nm_connection_add_setting (connection, setting);
 
322
                } else
 
323
                        g_assert_not_reached ();
 
324
 
 
325
                /* Serial setting */
 
326
                setting = nm_setting_serial_new ();
 
327
                g_object_set (setting,
 
328
                              NM_SETTING_SERIAL_BAUD, 115200,
 
329
                              NM_SETTING_SERIAL_BITS, 8,
 
330
                              NM_SETTING_SERIAL_PARITY, 'n',
 
331
                              NM_SETTING_SERIAL_STOPBITS, 1,
 
332
                              NULL);
 
333
                nm_connection_add_setting (connection, setting);
 
334
 
 
335
                nm_connection_add_setting (connection, nm_setting_ppp_new ());
 
336
 
 
337
                setting = nm_setting_connection_new ();
 
338
                id = utils_create_mobile_connection_id (method->provider_name, method->plan_name);
 
339
                uuid = nm_utils_uuid_generate ();
 
340
                g_object_set (setting,
 
341
                              NM_SETTING_CONNECTION_ID, id,
 
342
                              NM_SETTING_CONNECTION_TYPE, setting_name,
 
343
                              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
 
344
                              NM_SETTING_CONNECTION_UUID, uuid,
 
345
                              NULL);
 
346
                g_free (uuid);
 
347
                g_free (id);
 
348
                nm_connection_add_setting (connection, setting);
 
349
        }
 
350
 
 
351
done:
 
352
        (*(info->callback)) (connection, TRUE, cancelled, info->callback_data);
 
353
 
 
354
        if (wizard)
 
355
                nma_mobile_wizard_destroy (wizard);
 
356
        g_free (info);
 
357
}
 
358
 
 
359
gboolean
 
360
mobile_helper_wizard (NMDeviceModemCapabilities capabilities,
 
361
                      AppletNewAutoConnectionCallback callback,
 
362
                      gpointer callback_data)
 
363
{
 
364
        NMAMobileWizard *wizard;
 
365
        AutoWizardInfo *info;
 
366
        NMAMobileWizardAccessMethod *method;
 
367
        NMDeviceModemCapabilities wizard_capability;
 
368
 
 
369
        /* Convert the input capabilities mask into a single value */
 
370
        if (capabilities & NM_DEVICE_MODEM_CAPABILITY_LTE)
 
371
                /* All LTE modems treated as GSM/UMTS for the wizard */
 
372
                wizard_capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
 
373
        else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
 
374
                wizard_capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
 
375
        else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
 
376
                wizard_capability = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
 
377
        else {
 
378
                g_warning ("Unknown modem capabilities (0x%X): can't launch wizard", capabilities);
 
379
                return FALSE;
 
380
        }
 
381
 
 
382
        info = g_malloc0 (sizeof (AutoWizardInfo));
 
383
        info->callback = callback;
 
384
        info->callback_data = callback_data;
 
385
        info->requested_capability = wizard_capability;
 
386
 
 
387
        wizard = nma_mobile_wizard_new (NULL,
 
388
                                        NULL,
 
389
                                        wizard_capability,
 
390
                                        FALSE,
 
391
                                                                        mobile_wizard_done,
 
392
                                        info);
 
393
        if (wizard) {
 
394
                nma_mobile_wizard_present (wizard);
 
395
                return TRUE;
 
396
        }
 
397
 
 
398
        /* Fall back to something */
 
399
        method = g_malloc0 (sizeof (NMAMobileWizardAccessMethod));
 
400
        method->devtype = wizard_capability;
 
401
 
 
402
        if (wizard_capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
 
403
                method->provider_name = _("GSM");
 
404
        else if (wizard_capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
 
405
                method->provider_name = _("CDMA");
 
406
        else
 
407
                g_assert_not_reached ();
 
408
 
 
409
        mobile_wizard_done (NULL, FALSE, method, info);
 
410
        g_free (method);
 
411
 
 
412
        return TRUE;
 
413
}
 
414
 
 
415
/********************************************************************/
 
416
 
 
417
static void
 
418
save_pin_cb (GnomeKeyringResult result, guint32 val, gpointer user_data)
 
419
{
 
420
        if (result != GNOME_KEYRING_RESULT_OK)
 
421
                g_warning ("%s: result %d", (const char *) user_data, result);
 
422
}
 
423
 
 
424
void
 
425
mobile_helper_save_pin_in_keyring (const char *devid,
 
426
                                   const char *simid,
 
427
                                   const char *pin)
 
428
{
 
429
        GnomeKeyringAttributeList *attributes;
 
430
        GnomeKeyringAttribute attr;
 
431
        const char *name;
 
432
        char *error_msg;
 
433
 
 
434
        name = g_strdup_printf (_("PIN code for SIM card '%s' on '%s'"),
 
435
                                simid ? simid : "unknown",
 
436
                                devid);
 
437
 
 
438
        attributes = gnome_keyring_attribute_list_new ();
 
439
        attr.name = g_strdup ("devid");
 
440
        attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
 
441
        attr.value.string = g_strdup (devid);
 
442
        g_array_append_val (attributes, attr);
 
443
 
 
444
        if (simid) {
 
445
                attr.name = g_strdup ("simid");
 
446
                attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
 
447
                attr.value.string = g_strdup (simid);
 
448
                g_array_append_val (attributes, attr);
 
449
        }
 
450
 
 
451
        error_msg = g_strdup_printf ("Saving PIN code in keyring for devid:%s simid:%s failed",
 
452
                                     devid, simid ? simid : "(unknown)");
 
453
 
 
454
        gnome_keyring_item_create (NULL,
 
455
                                   GNOME_KEYRING_ITEM_GENERIC_SECRET,
 
456
                                   name,
 
457
                                   attributes,
 
458
                                   pin,
 
459
                                   TRUE,
 
460
                                   save_pin_cb,
 
461
                                   error_msg,
 
462
                                   (GDestroyNotify) g_free);
 
463
 
 
464
        gnome_keyring_attribute_list_free (attributes);
 
465
}
 
466
 
 
467
static void
 
468
delete_pin_cb (GnomeKeyringResult result, gpointer user_data)
 
469
{
 
470
        /* nothing to do */
 
471
}
 
472
 
 
473
static void
 
474
delete_pins_find_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
 
475
{
 
476
        GList *iter;
 
477
 
 
478
        if (result == GNOME_KEYRING_RESULT_OK) {
 
479
                for (iter = list; iter; iter = g_list_next (iter)) {
 
480
                        GnomeKeyringFound *found = iter->data;
 
481
 
 
482
                        gnome_keyring_item_delete (found->keyring, found->item_id, delete_pin_cb, NULL, NULL);
 
483
                }
 
484
        }
 
485
}
 
486
 
 
487
void
 
488
mobile_helper_delete_pin_in_keyring (const char *devid)
 
489
{
 
490
        gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
 
491
                                   delete_pins_find_cb,
 
492
                                   NULL,
 
493
                                   NULL,
 
494
                                   "devid",
 
495
                                   GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
 
496
                                   devid,
 
497
                                   NULL);
 
498
}
 
499
 
 
500
/********************************************************************/
 
501
 
 
502
static void
 
503
free_secrets_info (SecretsRequest *req)
 
504
{
 
505
        MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req;
 
506
 
 
507
        if (info->dialog) {
 
508
                gtk_widget_hide (info->dialog);
 
509
                gtk_widget_destroy (info->dialog);
 
510
        }
 
511
 
 
512
        g_free (info->secret_name);
 
513
}
 
514
 
 
515
static void
 
516
get_secrets_cb (GtkDialog *dialog,
 
517
                gint response,
 
518
                gpointer user_data)
 
519
{
 
520
        SecretsRequest *req = user_data;
 
521
        MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req;
 
522
        GError *error = NULL;
 
523
 
 
524
        if (response == GTK_RESPONSE_OK) {
 
525
                if (info->capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
 
526
                        NMSettingGsm *setting;
 
527
 
 
528
                        setting = nm_connection_get_setting_gsm (req->connection);
 
529
                        if (setting) {
 
530
                                g_object_set (G_OBJECT (setting),
 
531
                                              info->secret_name, gtk_entry_get_text (info->secret_entry),
 
532
                                              NULL);
 
533
                        } else {
 
534
                                error = g_error_new (NM_SECRET_AGENT_ERROR,
 
535
                                                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
536
                                                     "%s.%d (%s): no GSM setting",
 
537
                                                     __FILE__, __LINE__, __func__);
 
538
                        }
 
539
                } else if (info->capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
 
540
                                NMSettingCdma *setting;
 
541
 
 
542
                                setting = nm_connection_get_setting_cdma (req->connection);
 
543
                                if (setting) {
 
544
                                        g_object_set (G_OBJECT (setting),
 
545
                                                      info->secret_name, gtk_entry_get_text (info->secret_entry),
 
546
                                                      NULL);
 
547
                                } else {
 
548
                                        error = g_error_new (NM_SECRET_AGENT_ERROR,
 
549
                                                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
550
                                                             "%s.%d (%s): no CDMA setting",
 
551
                                                             __FILE__, __LINE__, __func__);
 
552
                                }
 
553
                } else
 
554
                        g_assert_not_reached ();
 
555
        } else {
 
556
                error = g_error_new (NM_SECRET_AGENT_ERROR,
 
557
                                     NM_SECRET_AGENT_ERROR_USER_CANCELED,
 
558
                                     "%s.%d (%s): canceled",
 
559
                                     __FILE__, __LINE__, __func__);
 
560
        }
 
561
 
 
562
        if (info->capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
 
563
                applet_secrets_request_complete_setting (req, NM_SETTING_GSM_SETTING_NAME, error);
 
564
        else if (info->capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
 
565
                applet_secrets_request_complete_setting (req, NM_SETTING_CDMA_SETTING_NAME, error);
 
566
        else
 
567
                g_assert_not_reached ();
 
568
 
 
569
        applet_secrets_request_free (req);
 
570
        g_clear_error (&error);
 
571
}
 
572
 
 
573
static void
 
574
pin_entry_changed (GtkEditable *editable, gpointer user_data)
 
575
{
 
576
        GtkWidget *ok_button = GTK_WIDGET (user_data);
 
577
        const char *s;
 
578
        int i;
 
579
        gboolean valid = FALSE;
 
580
        guint32 len;
 
581
 
 
582
        s = gtk_entry_get_text (GTK_ENTRY (editable));
 
583
        if (s) {
 
584
                len = strlen (s);
 
585
                if ((len >= 4) && (len <= 8)) {
 
586
                        valid = TRUE;
 
587
                        for (i = 0; i < len; i++) {
 
588
                                if (!g_ascii_isdigit (s[i])) {
 
589
                                        valid = FALSE;
 
590
                                        break;
 
591
                                }
 
592
                        }
 
593
                }
 
594
        }
 
595
 
 
596
        gtk_widget_set_sensitive (ok_button, valid);
 
597
}
 
598
 
 
599
static GtkWidget *
 
600
ask_for_pin (GtkEntry **out_secret_entry)
 
601
{
 
602
        GtkDialog *dialog;
 
603
        GtkWidget *w = NULL, *ok_button = NULL;
 
604
        GtkBox *box = NULL, *vbox = NULL;
 
605
 
 
606
        dialog = GTK_DIALOG (gtk_dialog_new ());
 
607
        gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
608
        gtk_window_set_title (GTK_WINDOW (dialog), _("PIN code required"));
 
609
 
 
610
        ok_button = gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
 
611
        ok_button = gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
 
612
        gtk_window_set_default (GTK_WINDOW (dialog), ok_button);
 
613
 
 
614
        vbox = GTK_BOX (gtk_dialog_get_content_area (dialog));
 
615
 
 
616
        w = gtk_label_new (_("PIN code is needed for the mobile broadband device"));
 
617
        gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
 
618
 
 
619
        w = gtk_alignment_new (0.5, 0.5, 0, 1.0);
 
620
        gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
 
621
 
 
622
#if GTK_CHECK_VERSION(3,1,6)
 
623
        box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6));
 
624
#else
 
625
        box = GTK_BOX (gtk_hbox_new (FALSE, 6));
 
626
#endif
 
627
        gtk_container_set_border_width (GTK_CONTAINER (box), 6);
 
628
        gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (box));
 
629
 
 
630
        gtk_box_pack_start (box, gtk_label_new ("PIN:"), FALSE, FALSE, 0);
 
631
 
 
632
        w = gtk_entry_new ();
 
633
        *out_secret_entry = GTK_ENTRY (w);
 
634
        gtk_entry_set_max_length (GTK_ENTRY (w), 8);
 
635
        gtk_entry_set_width_chars (GTK_ENTRY (w), 8);
 
636
        gtk_entry_set_activates_default (GTK_ENTRY (w), TRUE);
 
637
        gtk_entry_set_visibility (GTK_ENTRY (w), FALSE);
 
638
        gtk_box_pack_start (box, w, FALSE, FALSE, 0);
 
639
        g_signal_connect (w, "changed", G_CALLBACK (pin_entry_changed), ok_button);
 
640
        pin_entry_changed (GTK_EDITABLE (w), ok_button);
 
641
 
 
642
        gtk_widget_show_all (GTK_WIDGET (vbox));
 
643
        return GTK_WIDGET (dialog);
 
644
}
 
645
 
 
646
gboolean
 
647
mobile_helper_get_secrets (NMDeviceModemCapabilities capabilities,
 
648
                           SecretsRequest *req,
 
649
                           GError **error)
 
650
{
 
651
        MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req;
 
652
        GtkWidget *widget;
 
653
        GtkEntry *secret_entry = NULL;
 
654
 
 
655
        applet_secrets_request_set_free_func (req, free_secrets_info);
 
656
 
 
657
        if (!req->hints || !g_strv_length (req->hints)) {
 
658
                g_set_error (error,
 
659
                             NM_SECRET_AGENT_ERROR,
 
660
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
661
                             "%s.%d (%s): missing secrets hints.",
 
662
                             __FILE__, __LINE__, __func__);
 
663
                return FALSE;
 
664
        }
 
665
        info->secret_name = g_strdup (req->hints[0]);
 
666
 
 
667
        /* Convert the input capabilities mask into a single value */
 
668
        if (capabilities & NM_DEVICE_MODEM_CAPABILITY_LTE)
 
669
                /* All LTE modems treated as GSM/UMTS for the settings */
 
670
                info->capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
 
671
        else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
 
672
                info->capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
 
673
        else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
 
674
                info->capability = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
 
675
        else {
 
676
                g_set_error (error,
 
677
                             NM_SECRET_AGENT_ERROR,
 
678
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
679
                             "%s.%d (%s): unknown modem capabilities (0x%X).",
 
680
                             __FILE__, __LINE__, __func__, capabilities);
 
681
                return FALSE;
 
682
        }
 
683
 
 
684
        if (!strcmp (info->secret_name, NM_SETTING_GSM_PIN)) {
 
685
                widget = ask_for_pin (&secret_entry);
 
686
        } else if (!strcmp (info->secret_name, NM_SETTING_GSM_PASSWORD) ||
 
687
                   !strcmp (info->secret_name, NM_SETTING_CDMA_PASSWORD))
 
688
                widget = applet_mobile_password_dialog_new (req->connection, &secret_entry);
 
689
        else {
 
690
                g_set_error (error,
 
691
                             NM_SECRET_AGENT_ERROR,
 
692
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
693
                             "%s.%d (%s): unknown secrets hint '%s'.",
 
694
                             __FILE__, __LINE__, __func__, info->secret_name);
 
695
                return FALSE;
 
696
        }
 
697
        info->dialog = widget;
 
698
        info->secret_entry = secret_entry;
 
699
 
 
700
        if (!widget || !secret_entry) {
 
701
                g_set_error (error,
 
702
                             NM_SECRET_AGENT_ERROR,
 
703
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
704
                             "%s.%d (%s): error asking for mobile secrets.",
 
705
                             __FILE__, __LINE__, __func__);
 
706
                return FALSE;
 
707
        }
 
708
 
 
709
        g_signal_connect (widget, "response", G_CALLBACK (get_secrets_cb), info);
 
710
 
 
711
        gtk_window_set_position (GTK_WINDOW (widget), GTK_WIN_POS_CENTER_ALWAYS);
 
712
        gtk_widget_realize (GTK_WIDGET (widget));
 
713
        gtk_window_present (GTK_WINDOW (widget));
 
714
 
 
715
        return TRUE;
 
716
}
 
717
 
 
718
/********************************************************************/
 
719
 
 
720
void
 
721
mobile_helper_get_icon (NMDevice *device,
 
722
                        NMDeviceState state,
 
723
                        NMConnection *connection,
 
724
                        GdkPixbuf **out_pixbuf,
 
725
                        char **out_indicator_icon,
 
726
                        char **tip,
 
727
                        NMApplet *applet,
 
728
                        guint32 mb_state,
 
729
                        guint32 mb_tech,
 
730
                        guint32 quality,
 
731
                        gboolean quality_valid)
 
732
{
 
733
        NMSettingConnection *s_con;
 
734
        const char *id;
 
735
 
 
736
        id = nm_device_get_iface (NM_DEVICE (device));
 
737
        if (connection) {
 
738
                s_con = nm_connection_get_setting_connection (connection);
 
739
                id = nm_setting_connection_get_id (s_con);
 
740
        }
 
741
 
 
742
        switch (state) {
 
743
        case NM_DEVICE_STATE_PREPARE:
 
744
                *tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
 
745
                break;
 
746
        case NM_DEVICE_STATE_CONFIG:
 
747
                *tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
 
748
                break;
 
749
        case NM_DEVICE_STATE_NEED_AUTH:
 
750
                *tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
 
751
                break;
 
752
        case NM_DEVICE_STATE_IP_CONFIG:
 
753
                *tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
 
754
                break;
 
755
        case NM_DEVICE_STATE_ACTIVATED:
 
756
                *out_pixbuf = mobile_helper_get_status_pixbuf (quality,
 
757
                                                               quality_valid,
 
758
                                                               mb_state,
 
759
                                                               mb_tech,
 
760
                                                               applet);
 
761
 
 
762
                *out_indicator_icon = mobile_helper_get_quality_icon (quality_valid ?
 
763
                                                                      quality : 0,
 
764
                                                                      applet);
 
765
 
 
766
                if ((mb_state != MB_STATE_UNKNOWN) && quality_valid) {
 
767
                        gboolean roaming = (mb_state == MB_STATE_ROAMING);
 
768
 
 
769
                        *tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
 
770
                                                id, quality,
 
771
                                                roaming ? ", " : "",
 
772
                                                roaming ? _("roaming") : "");
 
773
                } else
 
774
                        *tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
 
775
                break;
 
776
        default:
 
777
                break;
 
778
        }
 
779
}
 
780
 
 
781
/********************************************************************/
 
782
 
 
783
char *
 
784
mobile_helper_parse_3gpp_operator_name (NMAMobileProvidersDatabase **mpd, /* I/O */
 
785
                                        const char *orig,
 
786
                                        const char *op_code)
 
787
{
 
788
        NMAMobileProvider *provider;
 
789
        guint i, orig_len;
 
790
 
 
791
        g_assert (mpd != NULL);
 
792
 
 
793
        /* Some devices return the MCC/MNC if they haven't fully initialized
 
794
         * or gotten all the info from the network yet.  Handle that.
 
795
         */
 
796
 
 
797
        orig_len = orig ? strlen (orig) : 0;
 
798
        if (orig_len == 0) {
 
799
                /* If the operator name isn't valid, maybe we can look up the MCC/MNC
 
800
                 * from the operator code instead.
 
801
                 */
 
802
                if (op_code && strlen (op_code)) {
 
803
                        orig = op_code;
 
804
                        orig_len = strlen (orig);
 
805
                } else
 
806
                        return NULL;
 
807
        } else if (orig_len < 5 || orig_len > 6)
 
808
                return g_strdup (orig);  /* not an MCC/MNC */
 
809
 
 
810
        for (i = 0; i < orig_len; i++) {
 
811
                if (!isdigit (orig[i]))
 
812
                        return strdup (orig);
 
813
        }
 
814
 
 
815
        /* At this point we have a 5 or 6 character all-digit string; that's
 
816
         * probably an MCC/MNC.  Look that up.
 
817
         */
 
818
 
 
819
        if (*mpd == NULL) {
 
820
                GError *error = NULL;
 
821
 
 
822
                *mpd = nma_mobile_providers_database_new_sync (NULL, NULL, NULL, &error);
 
823
                if (*mpd == NULL) {
 
824
                        g_warning ("Couldn't read database: %s", error->message);
 
825
                        g_error_free (error);
 
826
                        return strdup (orig);
 
827
                }
 
828
        }
 
829
 
 
830
        provider = nma_mobile_providers_database_lookup_3gpp_mcc_mnc (*mpd, orig);
 
831
        return (provider ? g_strdup (nma_mobile_provider_get_name (provider)) : NULL);
 
832
}
 
833
 
 
834
char *
 
835
mobile_helper_parse_3gpp2_operator_name (NMAMobileProvidersDatabase **mpd, /* I/O */
 
836
                                         guint32 sid)
 
837
{
 
838
        NMAMobileProvider *provider;
 
839
 
 
840
        g_assert (mpd != NULL);
 
841
 
 
842
        if (!sid)
 
843
                return NULL;
 
844
 
 
845
        if (*mpd == NULL) {
 
846
                GError *error = NULL;
 
847
 
 
848
                *mpd = nma_mobile_providers_database_new_sync (NULL, NULL, NULL, &error);
 
849
                if (*mpd == NULL) {
 
850
                        g_warning ("Couldn't read database: %s", error->message);
 
851
                        g_error_free (error);
 
852
                        return NULL;
 
853
                }
 
854
        }
 
855
 
 
856
        provider = nma_mobile_providers_database_lookup_cdma_sid (*mpd, sid);
 
857
        return (provider ? g_strdup (nma_mobile_provider_get_name (provider)) : NULL);
 
858
}