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

« back to all changes in this revision

Viewing changes to src/applet-device-gsm.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-09-20 16:40:24 UTC
  • Revision ID: package-import@ubuntu.com-20120920164024-d0kluun4mlexvzm6
Tags: 0.9.6.2-0ubuntu5
* debian/patches/nm-applet-use-indicator.patch: Plug two small leaks.
* debian/patches/lp1048520_delay_pin_dialog_in_greeter.patch: Delay PIN
  dialog when in greeter mode; it shouldn't show unless a user goes to
  activate a mobile connection which needs unlocking. (LP: #1048520)

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
        /* Unlock dialog stuff */
96
96
        GtkWidget *dialog;
97
97
        gpointer keyring_id;
 
98
 
 
99
        gboolean greeter_mode;
98
100
} GsmDeviceInfo;
99
101
 
 
102
static void unlock_dialog_new (NMDevice *device, GsmDeviceInfo *info);
100
103
static void unlock_dialog_destroy (GsmDeviceInfo *info);
101
104
static void check_start_polling (GsmDeviceInfo *info);
102
105
 
280
283
        do_mobile_wizard (dbus_connect_3g_cb, info);
281
284
}
282
285
 
 
286
typedef struct {
 
287
        NMDevice *device;
 
288
        NMConnection *connection;
 
289
        NMApplet *applet;
 
290
        gpointer dclass_data;
 
291
        guint wait_retry;
 
292
} DelayedActivationHelper;
 
293
 
 
294
gboolean delayed_activation_cb(gpointer user_data)
 
295
{
 
296
        DelayedActivationHelper *helper = user_data;
 
297
        
 
298
        if (!NM_IS_DEVICE (helper->device)) {
 
299
                // the device has been unplugged.
 
300
                return FALSE;
 
301
        }
 
302
 
 
303
        GsmDeviceInfo *devinfo = g_object_get_data (G_OBJECT (helper->device), "devinfo");
 
304
 
 
305
        if (devinfo->unlock_required == NULL) {
 
306
                // the modem was successfully unlocked
 
307
 
 
308
                applet_menu_item_activate_helper (helper->device,
 
309
                                                                                  helper->connection,
 
310
                                                                                  "/",
 
311
                                                                                  helper->applet,
 
312
                                                                                  helper->dclass_data);
 
313
                return FALSE;
 
314
        }
 
315
 
 
316
        helper->wait_retry -= 1; 
 
317
        if (helper->wait_retry == 0) {
 
318
                return FALSE;
 
319
        }
 
320
 
 
321
        return TRUE;
 
322
}
 
323
 
 
324
void gsm_menu_item_activate_unlock_dialog_destroy (GtkWidget *object,
 
325
                                                                                                   gpointer   user_data)
 
326
{
 
327
        GSMMenuItemInfo *info = (GSMMenuItemInfo *) user_data;
 
328
        GsmDeviceInfo *devinfo;
 
329
        DelayedActivationHelper *helper;
 
330
        
 
331
        /*
 
332
         * The dialog is destroyed. Either the PIN code was successfully
 
333
         * forwarded to ModemManager or the dialog was cancelled.
 
334
         * Unfortunately we don't have any means of determine which is the case.
 
335
         *
 
336
         * The solution here is to monitor GsmDeviceInfo::unlock_required. If that
 
337
         * is cleared, then we know that the modem has been activated and we can
 
338
         * continue with the activation.
 
339
         *
 
340
         * Because unlock_required is updated upon receiving a property changed
 
341
         * signal we have to give MM some time to deliver the change over D-Bus.
 
342
         *
 
343
         * Here we set up a timer which checks the state of the modem three times
 
344
         * with 1 second delay.
 
345
         *
 
346
         * If the modem was not successfully activated this delayed activation is
 
347
         * cancelled after three tries/seconds.
 
348
         */
 
349
 
 
350
        devinfo = g_object_get_data (G_OBJECT (info->device), "devinfo");
 
351
 
 
352
        helper = g_malloc (sizeof (DelayedActivationHelper));
 
353
        helper->device = info->device;
 
354
        helper->connection = info->connection;
 
355
        helper->applet = info->applet;
 
356
        helper->dclass_data = info;
 
357
        helper->wait_retry = 3;
 
358
 
 
359
        g_timeout_add_full (G_PRIORITY_DEFAULT,
 
360
                                                1 * 1000,
 
361
                                                (GSourceFunc)delayed_activation_cb,
 
362
                                                helper,
 
363
                                                (GDestroyNotify)g_free);
 
364
}
 
365
 
283
366
static void
284
367
gsm_menu_item_activate (GtkMenuItem *item, gpointer user_data)
285
368
{
286
369
        GSMMenuItemInfo *info = (GSMMenuItemInfo *) user_data;
 
370
        GsmDeviceInfo *devinfo;
 
371
 
 
372
        devinfo = g_object_get_data (G_OBJECT (info->device), "devinfo");
 
373
        if (devinfo->greeter_mode && devinfo->unlock_required != NULL) {
 
374
 
 
375
                /* We need to delay the activation until the modem is unlocked. */
 
376
 
 
377
                unlock_dialog_new(devinfo->device, devinfo);
 
378
                /* 
 
379
                 * The dialog gets destroyed if
 
380
                 *
 
381
                 * A) User enters the correct PIN and ModemManager tells nm-applet
 
382
                 *    that the modem was successfully activated.
 
383
                 *
 
384
                 *        The dialog does not get destroyed, however, if the PIN code
 
385
                 *    is incorrect. The dialog shows an error message and the user can
 
386
                 *    either enter a new PIN code or Cancel.
 
387
                 *
 
388
                 *    All this happens in the dialogs response handler or callback that
 
389
                 *    handles the PIN activation return value from ModemManager.
 
390
                 *    See the relevant functions later in this file. 
 
391
                 *
 
392
                 * B) The user cancels the dialog.
 
393
                 */
 
394
                g_signal_connect (devinfo->dialog, "destroy", G_CALLBACK (gsm_menu_item_activate_unlock_dialog_destroy), info);
 
395
                return;
 
396
        }
287
397
 
288
398
        applet_menu_item_activate_helper (info->device,
289
399
                                          info->connection,
1395
1505
        info->keyring_id = NULL;
1396
1506
 
1397
1507
        if (result != GNOME_KEYRING_RESULT_OK) {
1398
 
                /* No saved PIN, just ask the user */
1399
 
                unlock_dialog_new (info->device, info);
 
1508
                if (!info->greeter_mode) {
 
1509
                        /* No saved PIN, just ask the user */
 
1510
                        unlock_dialog_new (info->device, info);
 
1511
                }
1400
1512
                return;
1401
1513
        }
1402
1514
 
1478
1590
                                                                      info->devid,
1479
1591
                                                                      NULL);
1480
1592
                } else {
1481
 
                        /* Couldn't get a device ID, but unlock required; present dialog */
1482
 
                        unlock_dialog_new (info->device, info);
 
1593
                        if (!info->greeter_mode) {
 
1594
                                /* Couldn't get a device ID, but unlock required; present dialog */
 
1595
                                unlock_dialog_new (info->device, info);
 
1596
                        }
1483
1597
                }
1484
1598
        }
1485
1599
 
1721
1835
        info->device = device;
1722
1836
        info->bus = bus;
1723
1837
 
 
1838
        info->greeter_mode = FALSE;
 
1839
        if (getenv ("INDICATOR_GREETER_MODE"))
 
1840
                info->greeter_mode = TRUE;
 
1841
 
1724
1842
        info->props_proxy = dbus_g_proxy_new_for_name (info->bus,
1725
1843
                                                       "org.freedesktop.ModemManager",
1726
1844
                                                       udi,