/* deletable.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from deletable.vala, do not modify */

/*
 * Seahorse
 *
 * Copyright (C) 2004,2005 Stefan Walter
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2012 Stefan Walter
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "seahorse-common.h"
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))

struct _Block1Data {
	int _ref_count_;
	GMainLoop* loop;
	GAsyncResult* _result_;
};

static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void ____lambda8_ (Block1Data* _data1_,
                   GObject* obj,
                   GAsyncResult* res);
static void _____lambda8__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static GType seahorse_deletable_get_type_once (void);

SeahorseDeleter*
seahorse_deletable_create_deleter (SeahorseDeletable* self)
{
	SeahorseDeletableIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = SEAHORSE_DELETABLE_GET_INTERFACE (self);
	if (_iface_->create_deleter) {
		return _iface_->create_deleter (self);
	}
	return NULL;
}

gboolean
seahorse_deletable_can_delete (GObject* obj)
{
	gboolean result;
	g_return_val_if_fail (obj != NULL, FALSE);
	if (SEAHORSE_IS_DELETABLE (obj)) {
		gboolean _tmp0_;
		gboolean _tmp1_;
		_tmp0_ = seahorse_deletable_get_deletable (G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_TYPE_DELETABLE, SeahorseDeletable));
		_tmp1_ = _tmp0_;
		result = _tmp1_;
		return result;
	}
	result = FALSE;
	return result;
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		_g_object_unref0 (_data1_->_result_);
		_g_main_loop_unref0 (_data1_->loop);
		g_slice_free (Block1Data, _data1_);
	}
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
____lambda8_ (Block1Data* _data1_,
              GObject* obj,
              GAsyncResult* res)
{
	GAsyncResult* _tmp0_;
	GMainLoop* _tmp1_;
	g_return_if_fail (res != NULL);
	_tmp0_ = _g_object_ref0 (res);
	_g_object_unref0 (_data1_->_result_);
	_data1_->_result_ = _tmp0_;
	_tmp1_ = _data1_->loop;
	g_main_loop_quit (_tmp1_);
}

static void
_____lambda8__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	____lambda8_ (self, source_object, res);
	block1_data_unref (self);
}

gint
seahorse_deletable_delete_with_prompt_wait (GList* objects,
                                            GtkWindow* parent,
                                            GError** error)
{
	Block1Data* _data1_;
	GMainLoop* _tmp0_;
	gint count = 0;
	GHashTable* pending = NULL;
	GHashFunc _tmp1_;
	GEqualFunc _tmp2_;
	GHashTable* _tmp3_;
	GError* _inner_error0_ = NULL;
	gint result;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	_data1_->loop = _tmp0_;
	_data1_->_result_ = NULL;
	count = 0;
	_tmp1_ = g_direct_hash;
	_tmp2_ = g_direct_equal;
	_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, NULL, NULL);
	pending = _tmp3_;
	{
		GList* obj_collection = NULL;
		GList* obj_it = NULL;
		obj_collection = objects;
		for (obj_it = obj_collection; obj_it != NULL; obj_it = obj_it->next) {
			GObject* _tmp4_;
			GObject* obj = NULL;
			_tmp4_ = _g_object_ref0 ((GObject*) obj_it->data);
			obj = _tmp4_;
			{
				GHashTable* _tmp5_;
				GObject* _tmp6_;
				_tmp5_ = pending;
				_tmp6_ = obj;
				g_hash_table_add (_tmp5_, _tmp6_);
				_g_object_unref0 (obj);
			}
		}
	}
	{
		GList* obj_collection = NULL;
		GList* obj_it = NULL;
		obj_collection = objects;
		for (obj_it = obj_collection; obj_it != NULL; obj_it = obj_it->next) {
			GObject* _tmp7_;
			GObject* obj = NULL;
			_tmp7_ = _g_object_ref0 ((GObject*) obj_it->data);
			obj = _tmp7_;
			{
				GHashTable* _tmp8_;
				GObject* _tmp9_;
				GObject* _tmp10_;
				SeahorseDeleter* deleter = NULL;
				GObject* _tmp13_;
				SeahorseDeleter* _tmp14_;
				gboolean ret = FALSE;
				SeahorseDeleter* _tmp22_;
				SeahorseDeleter* _tmp23_;
				GMainLoop* _tmp24_;
				gboolean _tmp25_ = FALSE;
				SeahorseDeleter* _tmp26_;
				GAsyncResult* _tmp27_;
				_tmp8_ = pending;
				_tmp9_ = obj;
				if (!g_hash_table_contains (_tmp8_, _tmp9_)) {
					_g_object_unref0 (obj);
					continue;
				}
				_tmp10_ = obj;
				if (!seahorse_deletable_can_delete (_tmp10_)) {
					GHashTable* _tmp11_;
					GObject* _tmp12_;
					_tmp11_ = pending;
					_tmp12_ = obj;
					g_hash_table_remove (_tmp11_, _tmp12_);
					_g_object_unref0 (obj);
					continue;
				}
				_tmp13_ = obj;
				_tmp14_ = seahorse_deletable_create_deleter (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, SEAHORSE_TYPE_DELETABLE, SeahorseDeletable));
				deleter = _tmp14_;
				{
					GList* x_collection = NULL;
					GList* x_it = NULL;
					x_collection = objects;
					for (x_it = x_collection; x_it != NULL; x_it = x_it->next) {
						GObject* _tmp15_;
						GObject* x = NULL;
						_tmp15_ = _g_object_ref0 ((GObject*) x_it->data);
						x = _tmp15_;
						{
							GObject* _tmp16_;
							GObject* _tmp17_;
							GHashTable* _tmp18_;
							GObject* _tmp19_;
							_tmp16_ = x;
							_tmp17_ = obj;
							if (_tmp16_ == _tmp17_) {
								_g_object_unref0 (x);
								continue;
							}
							_tmp18_ = pending;
							_tmp19_ = x;
							if (g_hash_table_contains (_tmp18_, _tmp19_)) {
								SeahorseDeleter* _tmp20_;
								GObject* _tmp21_;
								_tmp20_ = deleter;
								_tmp21_ = x;
								seahorse_deleter_add_object (_tmp20_, _tmp21_);
							}
							_g_object_unref0 (x);
						}
					}
				}
				_tmp22_ = deleter;
				ret = seahorse_deleter_prompt (_tmp22_, parent);
				if (!ret) {
					_g_object_unref0 (deleter);
					_g_object_unref0 (obj);
					break;
				}
				_tmp23_ = deleter;
				seahorse_deleter_delete (_tmp23_, NULL, _____lambda8__gasync_ready_callback, block1_data_ref (_data1_));
				_tmp24_ = _data1_->loop;
				g_main_loop_run (_tmp24_);
				_tmp26_ = deleter;
				_tmp27_ = _data1_->_result_;
				_tmp25_ = seahorse_deleter_delete_finish (_tmp26_, _tmp27_, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp28_ = -1;
					g_propagate_error (error, _inner_error0_);
					_g_object_unref0 (deleter);
					_g_object_unref0 (obj);
					_g_hash_table_unref0 (pending);
					block1_data_unref (_data1_);
					_data1_ = NULL;
					return _tmp28_;
				}
				if (_tmp25_) {
					SeahorseDeleter* _tmp29_;
					GList* _tmp30_;
					_tmp29_ = deleter;
					_tmp30_ = seahorse_deleter_get_objects (_tmp29_);
					{
						GList* x_collection = NULL;
						GList* x_it = NULL;
						x_collection = _tmp30_;
						for (x_it = x_collection; x_it != NULL; x_it = x_it->next) {
							GObject* _tmp31_;
							GObject* x = NULL;
							_tmp31_ = _g_object_ref0 ((GObject*) x_it->data);
							x = _tmp31_;
							{
								GHashTable* _tmp32_;
								GObject* _tmp33_;
								gint _tmp34_;
								_tmp32_ = pending;
								_tmp33_ = x;
								g_hash_table_remove (_tmp32_, _tmp33_);
								_tmp34_ = count;
								count = _tmp34_ + 1;
								_g_object_unref0 (x);
							}
						}
					}
				} else {
					_g_object_unref0 (deleter);
					_g_object_unref0 (obj);
					break;
				}
				_g_object_unref0 (deleter);
				_g_object_unref0 (obj);
			}
		}
	}
	result = count;
	_g_hash_table_unref0 (pending);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}

gboolean
seahorse_deletable_get_deletable (SeahorseDeletable* self)
{
	SeahorseDeletableIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = SEAHORSE_DELETABLE_GET_INTERFACE (self);
	if (_iface_->get_deletable) {
		return _iface_->get_deletable (self);
	}
	return FALSE;
}

static void
seahorse_deletable_default_init (SeahorseDeletableIface * iface,
                                 gpointer iface_data)
{
	g_object_interface_install_property (iface, g_param_spec_boolean ("deletable", "deletable", "deletable", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

 G_GNUC_NO_INLINE static GType
seahorse_deletable_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseDeletableIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_deletable_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType seahorse_deletable_type_id;
	seahorse_deletable_type_id = g_type_register_static (G_TYPE_INTERFACE, "SeahorseDeletable", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (seahorse_deletable_type_id, G_TYPE_OBJECT);
	return seahorse_deletable_type_id;
}

GType
seahorse_deletable_get_type (void)
{
	static volatile gsize seahorse_deletable_type_id__once = 0;
	if (g_once_init_enter (&seahorse_deletable_type_id__once)) {
		GType seahorse_deletable_type_id;
		seahorse_deletable_type_id = seahorse_deletable_get_type_once ();
		g_once_init_leave (&seahorse_deletable_type_id__once, seahorse_deletable_type_id);
	}
	return seahorse_deletable_type_id__once;
}

