static void
gkd_secret_create_prompt_ready (GkdSecretPrompt *prompt)
{
	GkdSecretCreate *self = GKD_SECRET_CREATE (prompt);
	GkdSecretSecret *master;

	if (!gku_prompt_has_response (GKU_PROMPT (prompt))) {

		/* Does the alias exist? */
		if (locate_alias_collection_if_exists (self))
			unlock_or_complete_this_prompt (self);

		/* Otherwise we're going to prompt */
		else
			prepare_create_prompt (self);

		return;
	}

	/* Already prompted, create collection */
	g_return_if_fail (gku_prompt_get_response (GKU_PROMPT (prompt)) == GKU_RESPONSE_OK);
	master = gkd_secret_prompt_get_secret (prompt, "password");

	if (master && create_collection_with_secret (self, master))
		gkd_secret_prompt_complete (prompt);
	else
		gkd_secret_prompt_dismiss (prompt);

	gkd_secret_secret_free (master);
}
static void
on_prompt_password_complete (GObject *source,
                             GAsyncResult *result,
                             gpointer user_data)
{
    GkdSecretCreate *self = GKD_SECRET_CREATE (source);
    GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
    GError *error = NULL;

    gcr_prompt_password_finish (GCR_PROMPT (source), result, &error);

    if (error != NULL) {
        gkd_secret_prompt_dismiss_with_error (prompt, error);
        g_error_free (error);
        return;
    }

    self->master = gkd_secret_prompt_take_secret (prompt);
    if (self->master == NULL) {
        gkd_secret_prompt_dismiss (prompt);
        return;
    }

    /* If the password strength is greater than zero, then don't confirm */
    if (gcr_prompt_get_password_strength (GCR_PROMPT (source)) > 0)
        self->confirmed = TRUE;

    perform_prompting (self);
}
static GVariant *
gkd_secret_create_encode_result (GkdSecretPrompt *base)
{
    GkdSecretCreate *self = GKD_SECRET_CREATE (base);
    const gchar *path;

    path = self->result_path ? self->result_path : "/";
    return g_variant_new_variant (g_variant_new_object_path (path));
}
static void
gkd_secret_create_finalize (GObject *obj)
{
	GkdSecretCreate *self = GKD_SECRET_CREATE (obj);

	gck_attributes_unref (self->pkcs11_attrs);
	g_free (self->result_path);
	g_free (self->alias);

	G_OBJECT_CLASS (gkd_secret_create_parent_class)->finalize (obj);
}
static void
gkd_secret_create_encode_result (GkdSecretPrompt *base, DBusMessageIter *iter)
{
	GkdSecretCreate *self = GKD_SECRET_CREATE (base);
	DBusMessageIter variant;
	const gchar *path;

	dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "o", &variant);
	path = self->result_path ? self->result_path : "/";
	dbus_message_iter_append_basic (&variant, DBUS_TYPE_OBJECT_PATH, &path);
	dbus_message_iter_close_container (iter, &variant);
}
static void
gkd_secret_create_get_property (GObject *obj, guint prop_id, GValue *value,
                                GParamSpec *pspec)
{
	GkdSecretCreate *self = GKD_SECRET_CREATE (obj);

	switch (prop_id) {
	case PROP_PKCS11_ATTRIBUTES:
		g_value_set_boxed (value, self->pkcs11_attrs);
		break;
	case PROP_ALIAS:
		g_value_set_string (value, self->alias);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
		break;
	}
}
static void
gkd_secret_create_set_property (GObject *obj, guint prop_id, const GValue *value,
                                GParamSpec *pspec)
{
    GkdSecretCreate *self = GKD_SECRET_CREATE (obj);

    switch (prop_id) {
    case PROP_PKCS11_ATTRIBUTES:
        g_return_if_fail (!self->attributes);
        self->attributes = g_value_dup_boxed (value);
        g_return_if_fail (self->attributes);
        break;
    case PROP_ALIAS:
        g_return_if_fail (!self->alias);
        self->alias = g_value_dup_string (value);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
        break;
    }
}
static void
on_prompt_confirmation_complete (GObject *source,
                                 GAsyncResult *result,
                                 gpointer user_data)
{
    GkdSecretCreate *self = GKD_SECRET_CREATE (source);
    GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
    GError *error = NULL;

    self->confirmed = gcr_prompt_confirm_finish (GCR_PROMPT (source), result, &error);
    if (error != NULL) {
        gkd_secret_prompt_dismiss_with_error (prompt, error);
        g_error_free (error);
        return;
    }

    /* If not confirmed, then prompt again */
    if (!self->confirmed) {
        gkd_secret_secret_free (self->master);
        self->master = NULL;
    }

    perform_prompting (self);
}
static void
gkd_secret_create_prompt_ready (GkdSecretPrompt *prompt)
{
    perform_prompting (GKD_SECRET_CREATE (prompt));
}