static void
unlock_or_complete_this_prompt (GkdSecretCreate *self)
{
	GkdSecretUnlock *unlock;
	GkdSecretPrompt *prompt;

	g_object_ref (self);
	prompt = GKD_SECRET_PROMPT (self);

	unlock = gkd_secret_unlock_new (gkd_secret_prompt_get_service (prompt),
	                                gkd_secret_prompt_get_caller (prompt),
	                                gkd_secret_dispatch_get_object_path (GKD_SECRET_DISPATCH (self)));
	gkd_secret_unlock_queue (unlock, self->result_path);

	/*
	 * If any need to be unlocked, then replace this prompt
	 * object with an unlock prompt object, and call the prompt
	 * method.
	 */
	if (gkd_secret_unlock_have_queued (unlock)) {
		gkd_secret_service_publish_dispatch (gkd_secret_prompt_get_service (prompt),
		                                     gkd_secret_prompt_get_caller (prompt),
		                                     GKD_SECRET_DISPATCH (unlock));
		gkd_secret_unlock_call_prompt (unlock, gkd_secret_prompt_get_window_id (prompt));
	}

	g_object_unref (unlock);
	g_object_unref (self);
}
static gboolean
create_collection_with_secret (GkdSecretCreate *self, GkdSecretSecret *master)
{
	DBusError derr = DBUS_ERROR_INIT;
	GkdSecretService *service;
	gchar *identifier;

	g_assert (GKD_SECRET_IS_CREATE (self));
	g_assert (master);
	g_assert (!self->result_path);

	self->result_path = gkd_secret_create_with_secret (self->pkcs11_attrs, master, &derr);

	if (!self->result_path) {
		g_warning ("couldn't create new collection: %s", derr.message);
		dbus_error_free (&derr);
		return FALSE;
	}

	if (self->alias) {
		if (!gkd_secret_util_parse_path (self->result_path, &identifier, NULL))
			g_assert_not_reached ();
		service = gkd_secret_prompt_get_service (GKD_SECRET_PROMPT (self));
		gkd_secret_service_set_alias (service, self->alias, identifier);
		g_free (identifier);
	}

	return TRUE;
}
static gboolean
create_collection_with_secret (GkdSecretCreate *self, GkdSecretSecret *master)
{
    GError *error = NULL;
    GkdSecretService *service;
    gchar *identifier;

    g_assert (GKD_SECRET_IS_CREATE (self));
    g_assert (master);
    g_assert (!self->result_path);

    self->result_path = gkd_secret_create_with_secret (self->attributes, master, &error);

    if (!self->result_path) {
        g_warning ("couldn't create new collection: %s", error->message);
        g_error_free (error);
        return FALSE;
    }

    service = gkd_secret_prompt_get_service (GKD_SECRET_PROMPT (self));

    if (self->alias) {
        if (!gkd_secret_util_parse_path (self->result_path, &identifier, NULL))
            g_assert_not_reached ();
        gkd_secret_service_set_alias (service, self->alias, identifier);
        g_free (identifier);
    }

    /* Notify the callers that a collection was created */
    gkd_secret_service_emit_collection_created (service, self->result_path);

    return TRUE;
}
static gboolean
locate_alias_collection_if_exists (GkdSecretCreate *self)
{
	GkdSecretService *service;
	GkdSecretObjects *objects;
	GckObject *collection;
	const gchar *identifier;
	const gchar *caller;
	gchar *path;

	if (!self->alias)
		return FALSE;

	g_assert (!self->result_path);

	service = gkd_secret_prompt_get_service (GKD_SECRET_PROMPT (self));
	caller = gkd_secret_prompt_get_caller (GKD_SECRET_PROMPT (self));
	objects = gkd_secret_prompt_get_objects (GKD_SECRET_PROMPT (self));

	identifier = gkd_secret_service_get_alias (service, self->alias);
	if (!identifier)
		return FALSE;

	/* Make sure it actually exists */
	path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, -1);
	collection = gkd_secret_objects_lookup_collection (objects, caller, path);

	if (collection) {
		self->result_path = path;
		g_object_unref (collection);
		return TRUE;
	} else {
		g_free (path);
		return FALSE;
	}
}