~jgonzalezdr/lightdm/test_lock_after_vt_switch

« back to all changes in this revision

Viewing changes to common/user-list.c

  • Committer: Robert Ancell
  • Date: 2014-10-03 03:41:36 UTC
  • Revision ID: robert.ancell@canonical.com-20141003034136-obo1dmzy3evxsip9
Revert changes to AccountsService properties watching - it appears it's not using org.freedesktop.DBus.Properties

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
    /* Shell for user */
118
118
    gchar *shell;
119
119
 
120
 
    /* TRUE if a system account */
121
 
    gboolean system_account;
122
 
 
123
120
    /* Image for user */
124
121
    gchar *image;
125
122
 
454
451
    }
455
452
}
456
453
 
457
 
static gboolean
458
 
update_user_property (CommonUser *user, const gchar *name, GVariant *value)
459
 
{
460
 
    CommonUserPrivate *priv = GET_USER_PRIVATE (user);
461
 
 
462
 
    if (strcmp (name, "UserName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
463
 
    {
464
 
        g_free (priv->name);
465
 
        priv->name = g_variant_dup_string (value, NULL);
466
 
        return TRUE;
467
 
    }
468
 
 
469
 
    if (strcmp (name, "RealName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
470
 
    {
471
 
        g_free (priv->real_name);
472
 
        priv->real_name = g_variant_dup_string (value, NULL);
473
 
        return TRUE;
474
 
    }
475
 
 
476
 
    if (strcmp (name, "HomeDirectory") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
477
 
    {
478
 
        g_free (priv->home_directory);
479
 
        priv->home_directory = g_variant_dup_string (value, NULL);
480
 
        return TRUE;
481
 
    }
482
 
 
483
 
    if (strcmp (name, "Shell") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
484
 
    {
485
 
        g_free (priv->shell);
486
 
        priv->shell = g_variant_dup_string (value, NULL);
487
 
        return TRUE;
488
 
    }
489
 
 
490
 
    if (strcmp (name, "SystemAccount") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
491
 
    {
492
 
        priv->system_account = g_variant_get_boolean (value);
493
 
        return TRUE;
494
 
    }
495
 
 
496
 
    if (strcmp (name, "Language") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
497
 
    {
498
 
        if (priv->language)
499
 
            g_free (priv->language);
500
 
        priv->language = g_variant_dup_string (value, NULL);
501
 
        return TRUE;
502
 
    }
503
 
 
504
 
    if (strcmp (name, "IconFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
505
 
    {
506
 
        g_free (priv->image);
507
 
        priv->image = g_variant_dup_string (value, NULL);
508
 
        if (strcmp (priv->image, "") == 0)
509
 
        {
510
 
            g_free (priv->image);
511
 
            priv->image = NULL;
512
 
        }
513
 
        return TRUE;
514
 
    }
515
 
 
516
 
    if (strcmp (name, "XSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
517
 
    {
518
 
        g_free (priv->session);
519
 
        priv->session = g_variant_dup_string (value, NULL);
520
 
        return TRUE;
521
 
    }
522
 
 
523
 
    if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
524
 
    {
525
 
        g_free (priv->background);
526
 
        priv->background = g_variant_dup_string (value, NULL);
527
 
        if (strcmp (priv->background, "") == 0)
528
 
        {
529
 
            g_free (priv->background);
530
 
            priv->background = NULL;
531
 
        }
532
 
        return TRUE;
533
 
    }
534
 
 
535
 
    if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
536
 
    {
537
 
        g_strfreev (priv->layouts);
538
 
        priv->layouts = g_variant_dup_strv (value, NULL);
539
 
        if (!priv->layouts)
540
 
        {
541
 
            priv->layouts = g_malloc (sizeof (gchar *) * 1);
542
 
            priv->layouts[0] = NULL;
543
 
        }
544
 
        return TRUE;
545
 
    }
546
 
 
547
 
    if (strcmp (name, "XHasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
548
 
    {
549
 
        priv->has_messages = g_variant_get_boolean (value);
550
 
        return TRUE;
551
 
    }
552
 
 
553
 
    if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64))
554
 
    {
555
 
        priv->uid = g_variant_get_uint64 (value);
556
 
        return TRUE;
557
 
    }
558
 
 
559
 
    return FALSE;
560
 
}
 
454
static gboolean load_accounts_user (CommonUser *user);
561
455
 
562
456
static void
563
457
accounts_user_changed_cb (GDBusConnection *connection,
569
463
                          gpointer data)
570
464
{
571
465
    CommonUser *user = data;
572
 
    CommonUserPrivate *priv = GET_USER_PRIVATE (user);
573
 
    gboolean changed = FALSE;
574
 
    GVariantIter *iter;
575
 
    GVariantIter *invalidated_properties;
576
 
    gchar *name;
577
 
    GVariant *value;
578
 
 
579
 
    g_variant_get (parameters, "(sa{sv}as)", NULL, &iter, &invalidated_properties);
580
 
    while (g_variant_iter_loop (iter, "{&sv}", &name, &value))
581
 
    {
582
 
        if (update_user_property (user, name, value))
583
 
            changed = TRUE;
584
 
    }
585
 
    g_variant_iter_free (iter);
586
 
    while (g_variant_iter_loop (invalidated_properties, "&s", &name))
587
 
    {
588
 
        GVariant *result;
589
 
        GError *error = NULL;
590
 
 
591
 
        result = g_dbus_connection_call_sync (connection,
592
 
                                              "org.freedesktop.Accounts",
593
 
                                              priv->path,
594
 
                                              "org.freedesktop.DBus.Properties",
595
 
                                              "Get",
596
 
                                              g_variant_new ("(ss)", "org.freedesktop.Accounts.User", name),
597
 
                                              G_VARIANT_TYPE ("(v)"),
598
 
                                              G_DBUS_CALL_FLAGS_NONE,
599
 
                                              -1,
600
 
                                              NULL,
601
 
                                              &error);
602
 
        if (error)
603
 
            g_warning ("Error updating user property %s: %s", name, error->message);
604
 
        g_clear_error (&error);
605
 
 
606
 
        if (result)
607
 
        {
608
 
            GVariant *value;
609
 
 
610
 
            g_variant_get (result, "(v)", &value);
611
 
            if (update_user_property (user, name, value))
612
 
                changed = TRUE;
613
 
            g_variant_unref (value);
614
 
            g_variant_unref (result);          
615
 
        }
616
 
    }
617
 
 
618
 
    if (changed)
619
 
    {
620
 
        g_debug ("User %s changed", priv->path);
 
466
    CommonUserPrivate *priv = GET_USER_PRIVATE (user);  
 
467
 
 
468
    g_debug ("User %s changed", priv->path);
 
469
    if (load_accounts_user (user))
621
470
        g_signal_emit (user, user_signals[CHANGED], 0);
622
 
    }
623
471
}
624
472
 
625
473
static gboolean
629
477
    GVariant *result, *value;
630
478
    GVariantIter *iter;
631
479
    gchar *name;
 
480
    gboolean system_account = FALSE;
632
481
    GError *error = NULL;
633
482
 
634
483
    /* Get the properties for this user */
635
484
    if (!priv->changed_signal)
636
485
        priv->changed_signal = g_dbus_connection_signal_subscribe (GET_LIST_PRIVATE (priv->user_list)->bus,
637
486
                                                                   "org.freedesktop.Accounts",
638
 
                                                                   "org.freedesktop.DBus.Properties",
639
 
                                                                   "PropertiesChanged",
 
487
                                                                   "org.freedesktop.Accounts.User",
 
488
                                                                   "Changed",
640
489
                                                                   priv->path,
641
 
                                                                   "org.freedesktop.Accounts.User",
 
490
                                                                   NULL,
642
491
                                                                   G_DBUS_SIGNAL_FLAGS_NONE,
643
492
                                                                   accounts_user_changed_cb,
644
493
                                                                   user,
663
512
    /* Store the properties we need */
664
513
    g_variant_get (result, "(a{sv})", &iter);
665
514
    while (g_variant_iter_loop (iter, "{&sv}", &name, &value))
666
 
        update_user_property (user, name, value);
 
515
    {
 
516
        if (strcmp (name, "UserName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
517
        {
 
518
            g_free (priv->name);
 
519
            priv->name = g_variant_dup_string (value, NULL);
 
520
        }
 
521
        else if (strcmp (name, "RealName") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
522
        {
 
523
            g_free (priv->real_name);
 
524
            priv->real_name = g_variant_dup_string (value, NULL);
 
525
        }
 
526
        else if (strcmp (name, "HomeDirectory") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
527
        {
 
528
            g_free (priv->home_directory);
 
529
            priv->home_directory = g_variant_dup_string (value, NULL);
 
530
        }
 
531
        else if (strcmp (name, "Shell") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
532
        {
 
533
            g_free (priv->shell);
 
534
            priv->shell = g_variant_dup_string (value, NULL);
 
535
        }
 
536
        else if (strcmp (name, "SystemAccount") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
 
537
            system_account = g_variant_get_boolean (value);
 
538
        else if (strcmp (name, "Language") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
539
        {
 
540
            if (priv->language)
 
541
                g_free (priv->language);
 
542
            priv->language = g_variant_dup_string (value, NULL);
 
543
        }
 
544
        else if (strcmp (name, "IconFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
545
        {
 
546
            g_free (priv->image);
 
547
            priv->image = g_variant_dup_string (value, NULL);
 
548
            if (strcmp (priv->image, "") == 0)
 
549
            {
 
550
                g_free (priv->image);
 
551
                priv->image = NULL;
 
552
            }
 
553
        }
 
554
        else if (strcmp (name, "XSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
555
        {
 
556
            g_free (priv->session);
 
557
            priv->session = g_variant_dup_string (value, NULL);
 
558
        }
 
559
        else if (strcmp (name, "BackgroundFile") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
 
560
        {
 
561
            g_free (priv->background);
 
562
            priv->background = g_variant_dup_string (value, NULL);
 
563
            if (strcmp (priv->background, "") == 0)
 
564
            {
 
565
                g_free (priv->background);
 
566
                priv->background = NULL;
 
567
            }
 
568
        }
 
569
        else if (strcmp (name, "XKeyboardLayouts") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY))
 
570
        {
 
571
            g_strfreev (priv->layouts);
 
572
            priv->layouts = g_variant_dup_strv (value, NULL);
 
573
            if (!priv->layouts)
 
574
            {
 
575
                priv->layouts = g_malloc (sizeof (gchar *) * 1);
 
576
                priv->layouts[0] = NULL;
 
577
            }
 
578
        }
 
579
        else if (strcmp (name, "XHasMessages") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN))
 
580
            priv->has_messages = g_variant_get_boolean (value);
 
581
        else if (strcmp (name, "Uid") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT64))
 
582
            priv->uid = g_variant_get_uint64 (value);
 
583
    }
667
584
    g_variant_iter_free (iter);
668
585
 
669
586
    g_variant_unref (result);
670
587
 
671
 
    return !priv->system_account;
 
588
    return !system_account;
672
589
}
673
590
 
674
591
static void