gdm_session_worker_handle_initialize (GdmDBusWorker         *object,
                                      GDBusMethodInvocation *invocation,
                                      GVariant              *details)
{
        GdmSessionWorker *worker = GDM_SESSION_WORKER (object);
        GVariantIter      iter;
        char             *key;
        GVariant         *value;
        gboolean          wait_for_settings = FALSE;

        if (!validate_state_change (worker, invocation, GDM_SESSION_WORKER_STATE_SETUP_COMPLETE))
                return TRUE;

        g_variant_iter_init (&iter, details);
        while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
                if (g_strcmp0 (key, "service") == 0) {
                        worker->priv->service = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "extensions") == 0) {
                        worker->priv->extensions = filter_extensions (g_variant_get_strv (value, NULL));
                } else if (g_strcmp0 (key, "username") == 0) {
                        worker->priv->username = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "is-program-session") == 0) {
                        worker->priv->is_program_session = g_variant_get_boolean (value);
                } else if (g_strcmp0 (key, "log-file") == 0) {
                        worker->priv->log_file = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "x11-display-name") == 0) {
                        worker->priv->x11_display_name = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "x11-authority-file") == 0) {
                        worker->priv->x11_authority_file = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "console") == 0) {
                        worker->priv->display_device = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "seat-id") == 0) {
                        worker->priv->display_seat_id = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "hostname") == 0) {
                        worker->priv->hostname = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "display-is-local") == 0) {
                        worker->priv->display_is_local = g_variant_get_boolean (value);
                } else if (g_strcmp0 (key, "display-is-initial") == 0) {
                        worker->priv->display_is_initial = g_variant_get_boolean (value);
                }
        }

        worker->priv->pending_invocation = invocation;

        if (!worker->priv->is_program_session) {
                g_signal_connect_swapped (worker->priv->user_settings,
                                          "notify::language-name",
                                          G_CALLBACK (on_saved_language_name_read),
                                          worker);

                g_signal_connect_swapped (worker->priv->user_settings,
                                          "notify::session-name",
                                          G_CALLBACK (on_saved_session_name_read),
                                          worker);

                if (worker->priv->username) {
                        wait_for_settings = !gdm_session_settings_load (worker->priv->user_settings,
                                                                        worker->priv->username);
                }
        }

        if (wait_for_settings) {
                /* Load settings from accounts daemon before continuing
                 */
                g_signal_connect (G_OBJECT (worker->priv->user_settings),
                                  "notify::is-loaded",
                                  G_CALLBACK (on_settings_is_loaded_changed),
                                  worker);
        } else {
                queue_state_change (worker);
        }

        return TRUE;
}
gdm_session_worker_handle_initialize (GdmDBusWorker         *object,
                                      GDBusMethodInvocation *invocation,
                                      GVariant              *details)
{
        GdmSessionWorker *worker = GDM_SESSION_WORKER (object);
        GVariantIter      iter;
        char             *key;
        GVariant         *value;
        gboolean          wait_for_settings = FALSE;

        if (!validate_state_change (worker, invocation, GDM_SESSION_WORKER_STATE_SETUP_COMPLETE))
                return TRUE;

        g_variant_iter_init (&iter, details);
        while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
                if (g_strcmp0 (key, "service") == 0) {
                        worker->priv->service = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "extensions") == 0) {
                        worker->priv->extensions = filter_extensions (g_variant_get_strv (value, NULL));
                } else if (g_strcmp0 (key, "username") == 0) {
                        worker->priv->username = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "is-program-session") == 0) {
                        worker->priv->is_program_session = g_variant_get_boolean (value);
                } else if (g_strcmp0 (key, "log-file") == 0) {
                        worker->priv->log_file = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "x11-display-name") == 0) {
                        worker->priv->x11_display_name = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "x11-authority-file") == 0) {
                        worker->priv->x11_authority_file = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "console") == 0) {
                        worker->priv->display_device = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "seat-id") == 0) {
                        worker->priv->display_seat_id = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "hostname") == 0) {
                        worker->priv->hostname = g_variant_dup_string (value, NULL);
                } else if (g_strcmp0 (key, "display-is-local") == 0) {
                        worker->priv->display_is_local = g_variant_get_boolean (value);
                } else if (g_strcmp0 (key, "display-is-initial") == 0) {
                        worker->priv->display_is_initial = g_variant_get_boolean (value);
                }
        }

        worker->priv->pending_invocation = invocation;

        if (!worker->priv->is_program_session) {
                g_signal_connect_swapped (worker->priv->user_settings,
                                          "notify::language-name",
                                          G_CALLBACK (on_saved_language_name_read),
                                          worker);

                g_signal_connect_swapped (worker->priv->user_settings,
                                          "notify::session-name",
                                          G_CALLBACK (on_saved_session_name_read),
                                          worker);

                if (worker->priv->username) {
                        wait_for_settings = !gdm_session_settings_load (worker->priv->user_settings,
                                                                        worker->priv->username);
                }
        }

        if (wait_for_settings) {
                 
                g_signal_connect (G_OBJECT (worker->priv->user_settings),
                                  "notify::is-loaded",
                                  G_CALLBACK (on_settings_is_loaded_changed),
                                  worker);
        } else {
                queue_state_change (worker);
        }

        return TRUE;
}