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

« back to all changes in this revision

Viewing changes to .pc/nm-applet-use-indicator.patch/src/applet-device-cdma.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:
39
39
#include "applet.h"
40
40
#include "applet-device-cdma.h"
41
41
#include "utils.h"
42
 
#include "nm-mobile-wizard.h"
43
42
#include "applet-dialogs.h"
44
43
#include "nma-marshal.h"
45
44
#include "nm-mobile-providers.h"
89
88
        g_slice_free (CdmaMenuItemInfo, data);
90
89
}
91
90
 
92
 
typedef struct {
93
 
        AppletNewAutoConnectionCallback callback;
94
 
        gpointer callback_data;
95
 
} AutoCdmaWizardInfo;
96
 
 
97
 
static void
98
 
mobile_wizard_done (NMAMobileWizard *wizard,
99
 
                    gboolean canceled,
100
 
                    NMAMobileWizardAccessMethod *method,
101
 
                    gpointer user_data)
102
 
{
103
 
        AutoCdmaWizardInfo *info = user_data;
104
 
        NMConnection *connection = NULL;
105
 
 
106
 
        if (!canceled && method) {
107
 
                NMSetting *setting;
108
 
                char *uuid, *id;
109
 
 
110
 
                if (method->devtype != NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
111
 
                        g_warning ("Unexpected device type (not CDMA).");
112
 
                        canceled = TRUE;
113
 
                        goto done;
114
 
                }
115
 
 
116
 
                connection = nm_connection_new ();
117
 
 
118
 
                setting = nm_setting_cdma_new ();
119
 
                g_object_set (setting,
120
 
                              NM_SETTING_CDMA_NUMBER, "#777",
121
 
                              NM_SETTING_CDMA_USERNAME, method->username,
122
 
                              NM_SETTING_CDMA_PASSWORD, method->password,
123
 
                              NULL);
124
 
                nm_connection_add_setting (connection, setting);
125
 
 
126
 
                /* Serial setting */
127
 
                setting = nm_setting_serial_new ();
128
 
                g_object_set (setting,
129
 
                              NM_SETTING_SERIAL_BAUD, 115200,
130
 
                              NM_SETTING_SERIAL_BITS, 8,
131
 
                              NM_SETTING_SERIAL_PARITY, 'n',
132
 
                              NM_SETTING_SERIAL_STOPBITS, 1,
133
 
                              NULL);
134
 
                nm_connection_add_setting (connection, setting);
135
 
 
136
 
                nm_connection_add_setting (connection, nm_setting_ppp_new ());
137
 
 
138
 
                setting = nm_setting_connection_new ();
139
 
                id = utils_create_mobile_connection_id (method->provider_name, method->plan_name);
140
 
                uuid = nm_utils_uuid_generate ();
141
 
                g_object_set (setting,
142
 
                              NM_SETTING_CONNECTION_ID, id,
143
 
                              NM_SETTING_CONNECTION_TYPE, NM_SETTING_CDMA_SETTING_NAME,
144
 
                              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
145
 
                              NM_SETTING_CONNECTION_UUID, uuid,
146
 
                              NULL);
147
 
                g_free (uuid);
148
 
                g_free (id);
149
 
                nm_connection_add_setting (connection, setting);
150
 
        }
151
 
 
152
 
done:
153
 
        (*(info->callback)) (connection, TRUE, canceled, info->callback_data);
154
 
 
155
 
        if (wizard)
156
 
                nma_mobile_wizard_destroy (wizard);
157
 
        g_free (info);
158
 
}
159
 
 
160
 
static gboolean
161
 
do_mobile_wizard (AppletNewAutoConnectionCallback callback,
162
 
                  gpointer callback_data)
163
 
{
164
 
        NMAMobileWizard *wizard;
165
 
        AutoCdmaWizardInfo *info;
166
 
        NMAMobileWizardAccessMethod *method;
167
 
 
168
 
        info = g_malloc0 (sizeof (AutoCdmaWizardInfo));
169
 
        info->callback = callback;
170
 
        info->callback_data = callback_data;
171
 
 
172
 
        wizard = nma_mobile_wizard_new (NULL, NULL, NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO, FALSE,
173
 
                                                                        mobile_wizard_done, info);
174
 
        if (wizard) {
175
 
                nma_mobile_wizard_present (wizard);
176
 
                return TRUE;
177
 
        }
178
 
 
179
 
        /* Fall back to something */
180
 
        method = g_malloc0 (sizeof (NMAMobileWizardAccessMethod));
181
 
        method->devtype = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
182
 
        method->provider_name = _("CDMA");
183
 
        mobile_wizard_done (NULL, FALSE, method, info);
184
 
        g_free (method);
185
 
 
186
 
        return TRUE;
187
 
}
188
 
 
189
91
static gboolean
190
92
cdma_new_auto_connection (NMDevice *device,
191
93
                          gpointer dclass_data,
192
94
                          AppletNewAutoConnectionCallback callback,
193
95
                          gpointer callback_data)
194
96
{
195
 
        return do_mobile_wizard (callback, callback_data);
 
97
        return mobile_helper_wizard (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO,
 
98
                                     callback,
 
99
                                     callback_data);
196
100
}
197
101
 
198
102
static void
247
151
        info->applet = applet;
248
152
        info->device = g_object_ref (device);
249
153
 
250
 
        do_mobile_wizard (dbus_connect_3g_cb, info);
 
154
        if (!mobile_helper_wizard (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO,
 
155
                                   dbus_connect_3g_cb,
 
156
                                   info)) {
 
157
                g_warning ("Couldn't run mobile wizard for CDMA device");
 
158
                g_object_unref (info->device);
 
159
                g_free (info);
 
160
        }
251
161
}
252
162
 
253
163
static void
308
218
cdma_act_to_mb_act (CdmaDeviceInfo *info)
309
219
{
310
220
        if (info->evdo_state)
311
 
                return MB_TECH_EVDO_REVA; /* Always rA until we get CDMA AcT from MM */
 
221
                return MB_TECH_EVDO;
312
222
        else if (info->cdma1x_state)
313
223
                return MB_TECH_1XRTT;
314
224
        return MB_TECH_UNKNOWN;
455
365
               char **tip,
456
366
               NMApplet *applet)
457
367
{
458
 
        NMSettingConnection *s_con;
459
 
        GdkPixbuf *pixbuf = NULL;
460
 
        const char *id;
461
368
        CdmaDeviceInfo *info;
462
 
        gboolean mb_state;
463
369
 
464
370
        info = g_object_get_data (G_OBJECT (device), "devinfo");
465
371
        g_assert (info);
466
372
 
467
 
        id = nm_device_get_iface (NM_DEVICE (device));
468
 
        if (connection) {
469
 
                s_con = nm_connection_get_setting_connection (connection);
470
 
                id = nm_setting_connection_get_id (s_con);
471
 
        }
472
 
 
473
 
        switch (state) {
474
 
        case NM_DEVICE_STATE_PREPARE:
475
 
                *tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
476
 
                break;
477
 
        case NM_DEVICE_STATE_CONFIG:
478
 
                *tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
479
 
                break;
480
 
        case NM_DEVICE_STATE_NEED_AUTH:
481
 
                *tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
482
 
                break;
483
 
        case NM_DEVICE_STATE_IP_CONFIG:
484
 
                *tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
485
 
                break;
486
 
        case NM_DEVICE_STATE_ACTIVATED:
487
 
                mb_state = cdma_state_to_mb_state (info);
488
 
                pixbuf = mobile_helper_get_status_pixbuf (info->quality,
489
 
                                                          info->quality_valid,
490
 
                                                          mb_state,
491
 
                                                          cdma_act_to_mb_act (info),
492
 
                                                          applet);
493
 
 
494
 
                if ((mb_state != MB_STATE_UNKNOWN) && info->quality_valid) {
495
 
                        gboolean roaming = (mb_state == MB_STATE_ROAMING);
496
 
 
497
 
                        *tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
498
 
                                                id, info->quality,
499
 
                                                roaming ? ", " : "",
500
 
                                                roaming ? _("roaming") : "");
501
 
                } else
502
 
                        *tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
503
 
                break;
504
 
        default:
505
 
                break;
506
 
        }
507
 
 
508
 
        return pixbuf;
509
 
}
510
 
 
511
 
typedef struct {
512
 
        SecretsRequest req;
513
 
        GtkWidget *dialog;
514
 
        GtkEntry *secret_entry;
515
 
        char *secret_name;
516
 
} NMCdmaSecretsInfo;
517
 
 
518
 
static void
519
 
free_cdma_secrets_info (SecretsRequest *req)
520
 
{
521
 
        NMCdmaSecretsInfo *info = (NMCdmaSecretsInfo *) req;
522
 
 
523
 
        if (info->dialog) {
524
 
                gtk_widget_hide (info->dialog);
525
 
                gtk_widget_destroy (info->dialog);
526
 
        }
527
 
        g_free (info->secret_name);
528
 
}
529
 
 
530
 
static void
531
 
get_cdma_secrets_cb (GtkDialog *dialog,
532
 
                     gint response,
533
 
                     gpointer user_data)
534
 
{
535
 
        SecretsRequest *req = user_data;
536
 
        NMCdmaSecretsInfo *info = (NMCdmaSecretsInfo *) req;
537
 
        NMSettingCdma *setting;
538
 
        GError *error = NULL;
539
 
 
540
 
        if (response == GTK_RESPONSE_OK) {
541
 
                setting = nm_connection_get_setting_cdma (req->connection);
542
 
                if (setting) {
543
 
                        g_object_set (G_OBJECT (setting),
544
 
                                          info->secret_name, gtk_entry_get_text (info->secret_entry),
545
 
                                          NULL);
546
 
                } else {
547
 
                        error = g_error_new (NM_SECRET_AGENT_ERROR,
548
 
                                                 NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
549
 
                                                 "%s.%d (%s): no GSM setting",
550
 
                                                 __FILE__, __LINE__, __func__);
551
 
                }
552
 
        } else {
553
 
                error = g_error_new (NM_SECRET_AGENT_ERROR,
554
 
                                     NM_SECRET_AGENT_ERROR_USER_CANCELED,
555
 
                                     "%s.%d (%s): canceled",
556
 
                                     __FILE__, __LINE__, __func__);
557
 
        }
558
 
 
559
 
        applet_secrets_request_complete_setting (req, NM_SETTING_CDMA_SETTING_NAME, error);
560
 
        applet_secrets_request_free (req);
561
 
        g_clear_error (&error);
 
373
        return mobile_helper_get_icon (device,
 
374
                                       state,
 
375
                                       connection,
 
376
                                       tip,
 
377
                                       applet,
 
378
                                       cdma_state_to_mb_state (info),
 
379
                                       cdma_act_to_mb_act (info),
 
380
                                       info->quality,
 
381
                                       info->quality_valid);
562
382
}
563
383
 
564
384
static gboolean
565
385
cdma_get_secrets (SecretsRequest *req, GError **error)
566
386
{
567
 
        NMCdmaSecretsInfo *info = (NMCdmaSecretsInfo *) req;
568
 
        GtkWidget *widget;
569
 
        GtkEntry *secret_entry = NULL;
570
 
 
571
 
        applet_secrets_request_set_free_func (req, free_cdma_secrets_info);
572
 
 
573
 
        if (!req->hints || !g_strv_length (req->hints)) {
574
 
                g_set_error (error,
575
 
                             NM_SECRET_AGENT_ERROR,
576
 
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
577
 
                             "%s.%d (%s): missing secrets hints.",
578
 
                             __FILE__, __LINE__, __func__);
579
 
                return FALSE;
580
 
        }
581
 
        info->secret_name = g_strdup (req->hints[0]);
582
 
 
583
 
        if (!strcmp (info->secret_name, NM_SETTING_CDMA_PASSWORD))
584
 
                widget = applet_mobile_password_dialog_new (req->connection, &secret_entry);
585
 
        else {
586
 
                g_set_error (error,
587
 
                             NM_SECRET_AGENT_ERROR,
588
 
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
589
 
                             "%s.%d (%s): unknown secrets hint '%s'.",
590
 
                             __FILE__, __LINE__, __func__, info->secret_name);
591
 
                return FALSE;
592
 
        }
593
 
        info->dialog = widget;
594
 
        info->secret_entry = secret_entry;
595
 
 
596
 
        if (!widget || !secret_entry) {
597
 
                g_set_error (error,
598
 
                             NM_SECRET_AGENT_ERROR,
599
 
                             NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
600
 
                             "%s.%d (%s): error asking for CDMA secrets.",
601
 
                             __FILE__, __LINE__, __func__);
602
 
                return FALSE;
603
 
        }
604
 
 
605
 
        g_signal_connect (widget, "response", G_CALLBACK (get_cdma_secrets_cb), info);
606
 
 
607
 
        gtk_window_set_position (GTK_WINDOW (widget), GTK_WIN_POS_CENTER_ALWAYS);
608
 
        gtk_widget_realize (GTK_WIDGET (widget));
609
 
        gtk_window_present (GTK_WINDOW (widget));
610
 
 
611
 
        return TRUE;
 
387
        return mobile_helper_get_secrets (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO, req, error);
612
388
}
613
389
 
614
390
static void
728
504
                g_value_array_free (array);
729
505
        }
730
506
 
731
 
        if (new_sid && (new_sid != info->sid)) {
 
507
        if (new_sid != info->sid) {
732
508
                info->sid = new_sid;
733
 
                if (info->mobile_providers_database) {
734
 
                        NMAMobileProvider *provider;
735
 
 
736
 
                        g_free (info->provider_name);
737
 
 
738
 
                        provider = nma_mobile_providers_database_lookup_cdma_sid (info->mobile_providers_database, new_sid);
739
 
                        info->provider_name = (provider ?
740
 
                                               g_strdup (nma_mobile_provider_get_name (provider)) :
741
 
                                               NULL);
742
 
                }
743
 
        } else if (!new_sid) {
744
 
                info->sid = 0;
745
509
                g_free (info->provider_name);
746
 
                info->provider_name = NULL;
 
510
                info->provider_name = mobile_helper_parse_3gpp2_operator_name (&(info->mobile_providers_database), info->sid);
747
511
        }
748
512
 
749
513
        g_clear_error (&error);
859
623
        applet_schedule_update_icon (info->applet);
860
624
}
861
625
 
862
 
#define MM_DBUS_INTERFACE_MODEM "org.freedesktop.ModemManager.Modem"
 
626
#define MM_OLD_DBUS_INTERFACE_MODEM "org.freedesktop.ModemManager.Modem"
863
627
#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
864
628
 
865
629
static void
871
635
        CdmaDeviceInfo *info = user_data;
872
636
        GValue *value;
873
637
 
874
 
        if (!strcmp (interface, MM_DBUS_INTERFACE_MODEM)) {
 
638
        if (!strcmp (interface, MM_OLD_DBUS_INTERFACE_MODEM)) {
875
639
                value = g_hash_table_lookup (props, "Enabled");
876
640
                if (value && G_VALUE_HOLDS_BOOLEAN (value)) {
877
641
                        info->modem_enabled = g_value_get_boolean (value);
915
679
        info->bus = bus;
916
680
        info->quality_valid = FALSE;
917
681
 
918
 
        info->mobile_providers_database = nma_mobile_providers_database_new_sync (NULL, NULL, NULL, &error);
919
 
        if (!info->mobile_providers_database) {
920
 
                g_warning ("Couldn't read database: %s", error->message);
921
 
                g_clear_error (&error);
922
 
        }
923
 
 
924
682
        info->props_proxy = dbus_g_proxy_new_for_name (bus,
925
683
                                                       "org.freedesktop.ModemManager",
926
684
                                                       udi,
972
730
        /* Ask whether the device is enabled */
973
731
        dbus_g_proxy_begin_call (info->props_proxy, "Get",
974
732
                                 enabled_reply, info, NULL,
975
 
                                 G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
 
733
                                 G_TYPE_STRING, MM_OLD_DBUS_INTERFACE_MODEM,
976
734
                                 G_TYPE_STRING, "Enabled",
977
735
                                 G_TYPE_INVALID);
978
736
}
991
749
        dclass->device_state_changed = cdma_device_state_changed;
992
750
        dclass->get_icon = cdma_get_icon;
993
751
        dclass->get_secrets = cdma_get_secrets;
994
 
        dclass->secrets_request_size = sizeof (NMCdmaSecretsInfo);
 
752
        dclass->secrets_request_size = sizeof (MobileHelperSecretsInfo);
995
753
        dclass->device_added = cdma_device_added;
996
754
 
997
755
        return dclass;