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

/*
 * Seahorse
 *
 * Copyright (C) 2013 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * Author: Stef Walter <stefw@redhat.com>
 */

#include "seahorse-pkcs11.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "seahorse-common.h"
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <gck/gck.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

#define SEAHORSE_PKCS11_TYPE_KEY_DELETER (seahorse_pkcs11_key_deleter_get_type ())
#define SEAHORSE_PKCS11_KEY_DELETER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_PKCS11_TYPE_KEY_DELETER, SeahorsePkcs11KeyDeleter))
#define SEAHORSE_PKCS11_KEY_DELETER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_PKCS11_TYPE_KEY_DELETER, SeahorsePkcs11KeyDeleterClass))
#define SEAHORSE_PKCS11_IS_KEY_DELETER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SEAHORSE_PKCS11_TYPE_KEY_DELETER))
#define SEAHORSE_PKCS11_IS_KEY_DELETER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SEAHORSE_PKCS11_TYPE_KEY_DELETER))
#define SEAHORSE_PKCS11_KEY_DELETER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SEAHORSE_PKCS11_TYPE_KEY_DELETER, SeahorsePkcs11KeyDeleterClass))

typedef struct _SeahorsePkcs11KeyDeleter SeahorsePkcs11KeyDeleter;
typedef struct _SeahorsePkcs11KeyDeleterClass SeahorsePkcs11KeyDeleterClass;
typedef struct _SeahorsePkcs11KeyDeleterPrivate SeahorsePkcs11KeyDeleterPrivate;
enum  {
	SEAHORSE_PKCS11_KEY_DELETER_0_PROPERTY,
	SEAHORSE_PKCS11_KEY_DELETER_NUM_PROPERTIES
};
static GParamSpec* seahorse_pkcs11_key_deleter_properties[SEAHORSE_PKCS11_KEY_DELETER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _SeahorsePkcs11KeyDeleter {
	SeahorsePkcs11Deleter parent_instance;
	SeahorsePkcs11KeyDeleterPrivate * priv;
};

struct _SeahorsePkcs11KeyDeleterClass {
	SeahorsePkcs11DeleterClass parent_class;
};

struct _SeahorsePkcs11KeyDeleterPrivate {
	SeahorsePkcs11Certificate* _cert;
	SeahorsePkcs11PrivateKey* _key;
	gchar* _label;
};

static gint SeahorsePkcs11KeyDeleter_private_offset;
static gpointer seahorse_pkcs11_key_deleter_parent_class = NULL;

VALA_EXTERN GType seahorse_pkcs11_key_deleter_get_type (void) G_GNUC_CONST ;
static GtkDialog* seahorse_pkcs11_key_deleter_real_create_confirm (SeahorseDeleter* base,
                                                            GtkWindow* parent);
VALA_EXTERN SeahorsePkcs11KeyDeleter* seahorse_pkcs11_key_deleter_new (GckObject* cert_or_key);
VALA_EXTERN SeahorsePkcs11KeyDeleter* seahorse_pkcs11_key_deleter_construct (GType object_type,
                                                                 GckObject* cert_or_key);
static gboolean seahorse_pkcs11_key_deleter_real_add_object (SeahorseDeleter* base,
                                                      GObject* obj);
static void seahorse_pkcs11_key_deleter_finalize (GObject * obj);
static GType seahorse_pkcs11_key_deleter_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
seahorse_pkcs11_key_deleter_get_instance_private (SeahorsePkcs11KeyDeleter* self)
{
	return G_STRUCT_MEMBER_P (self, SeahorsePkcs11KeyDeleter_private_offset);
}

static GtkDialog*
seahorse_pkcs11_key_deleter_real_create_confirm (SeahorseDeleter* base,
                                                 GtkWindow* parent)
{
	SeahorsePkcs11KeyDeleter * self;
	SeahorseDeleteDialog* dialog = NULL;
	const gchar* _tmp0_;
	SeahorseDeleteDialog* _tmp1_;
	GtkDialog* result;
	self = (SeahorsePkcs11KeyDeleter*) base;
	_tmp0_ = self->priv->_label;
	_tmp1_ = (SeahorseDeleteDialog*) seahorse_delete_dialog_new (parent, _ ("Are you sure you want to permanently delete %s?"), _tmp0_, NULL);
	g_object_ref_sink (_tmp1_);
	dialog = _tmp1_;
	seahorse_delete_dialog_set_check_label (dialog, _ ("I understand that this key will be permanently deleted."));
	seahorse_delete_dialog_set_check_require (dialog, TRUE);
	result = (GtkDialog*) dialog;
	return result;
}

SeahorsePkcs11KeyDeleter*
seahorse_pkcs11_key_deleter_construct (GType object_type,
                                       GckObject* cert_or_key)
{
	SeahorsePkcs11KeyDeleter * self = NULL;
	g_return_val_if_fail (cert_or_key != NULL, NULL);
	self = (SeahorsePkcs11KeyDeleter*) seahorse_pkcs11_deleter_construct (object_type, cert_or_key);
	return self;
}

SeahorsePkcs11KeyDeleter*
seahorse_pkcs11_key_deleter_new (GckObject* cert_or_key)
{
	return seahorse_pkcs11_key_deleter_construct (SEAHORSE_PKCS11_TYPE_KEY_DELETER, cert_or_key);
}

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

static gboolean
seahorse_pkcs11_key_deleter_real_add_object (SeahorseDeleter* base,
                                             GObject* obj)
{
	SeahorsePkcs11KeyDeleter * self;
	GObject* partner = NULL;
	const gchar* _tmp18_;
	gboolean result;
	self = (SeahorsePkcs11KeyDeleter*) base;
	g_return_val_if_fail (obj != NULL, FALSE);
	if (SEAHORSE_PKCS11_IS_PRIVATE_KEY (obj)) {
		SeahorsePkcs11PrivateKey* _tmp0_;
		SeahorsePkcs11Certificate* _tmp1_;
		SeahorsePkcs11PrivateKey* _tmp6_;
		SeahorsePkcs11PrivateKey* _tmp7_;
		GckObject* _tmp8_;
		_tmp0_ = self->priv->_key;
		if (_tmp0_ != NULL) {
			result = FALSE;
			_g_object_unref0 (partner);
			return result;
		}
		_tmp1_ = self->priv->_cert;
		if (_tmp1_ != NULL) {
			SeahorsePkcs11Certificate* _tmp2_;
			SeahorsePkcs11PrivateKey* _tmp3_;
			SeahorsePkcs11PrivateKey* _tmp4_;
			GObject* _tmp5_;
			_tmp2_ = self->priv->_cert;
			_tmp3_ = seahorse_pkcs11_certificate_get_partner (_tmp2_);
			_tmp4_ = _tmp3_;
			_g_object_unref0 (partner);
			partner = (GObject*) _tmp4_;
			_tmp5_ = partner;
			if (_tmp5_ != obj) {
				result = FALSE;
				_g_object_unref0 (partner);
				return result;
			}
		}
		_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_PKCS11_TYPE_PRIVATE_KEY, SeahorsePkcs11PrivateKey));
		_g_object_unref0 (self->priv->_key);
		self->priv->_key = _tmp6_;
		_tmp7_ = self->priv->_key;
		_tmp8_ = _g_object_ref0 ((GckObject*) _tmp7_);
		((SeahorsePkcs11Deleter*) self)->objects = g_list_prepend (((SeahorsePkcs11Deleter*) self)->objects, _tmp8_);
	} else {
		if (SEAHORSE_PKCS11_IS_CERTIFICATE (obj)) {
			SeahorsePkcs11Certificate* _tmp9_;
			SeahorsePkcs11PrivateKey* _tmp10_;
			SeahorsePkcs11Certificate* _tmp15_;
			SeahorsePkcs11Certificate* _tmp16_;
			GckObject* _tmp17_;
			_tmp9_ = self->priv->_cert;
			if (_tmp9_ != NULL) {
				result = FALSE;
				_g_object_unref0 (partner);
				return result;
			}
			_tmp10_ = self->priv->_key;
			if (_tmp10_ != NULL) {
				SeahorsePkcs11PrivateKey* _tmp11_;
				SeahorsePkcs11Certificate* _tmp12_;
				SeahorsePkcs11Certificate* _tmp13_;
				GObject* _tmp14_;
				_tmp11_ = self->priv->_key;
				_tmp12_ = seahorse_pkcs11_private_key_get_partner (_tmp11_);
				_tmp13_ = _tmp12_;
				_g_object_unref0 (partner);
				partner = (GObject*) _tmp13_;
				_tmp14_ = partner;
				if (_tmp14_ != obj) {
					result = FALSE;
					_g_object_unref0 (partner);
					return result;
				}
			}
			_tmp15_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_PKCS11_TYPE_CERTIFICATE, SeahorsePkcs11Certificate));
			_g_object_unref0 (self->priv->_cert);
			self->priv->_cert = _tmp15_;
			_tmp16_ = self->priv->_cert;
			_tmp17_ = _g_object_ref0 ((GckObject*) _tmp16_);
			((SeahorsePkcs11Deleter*) self)->objects = g_list_prepend (((SeahorsePkcs11Deleter*) self)->objects, _tmp17_);
		} else {
			result = FALSE;
			_g_object_unref0 (partner);
			return result;
		}
	}
	_tmp18_ = self->priv->_label;
	if (_tmp18_ == NULL) {
		gchar* _tmp19_ = NULL;
		g_object_get (obj, "label", &_tmp19_, NULL);
		_g_free0 (self->priv->_label);
		self->priv->_label = _tmp19_;
	}
	result = TRUE;
	_g_object_unref0 (partner);
	return result;
}

static void
seahorse_pkcs11_key_deleter_class_init (SeahorsePkcs11KeyDeleterClass * klass,
                                        gpointer klass_data)
{
	seahorse_pkcs11_key_deleter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SeahorsePkcs11KeyDeleter_private_offset);
	((SeahorseDeleterClass *) klass)->create_confirm = (GtkDialog* (*) (SeahorseDeleter*, GtkWindow*)) seahorse_pkcs11_key_deleter_real_create_confirm;
	((SeahorseDeleterClass *) klass)->add_object = (gboolean (*) (SeahorseDeleter*, GObject*)) seahorse_pkcs11_key_deleter_real_add_object;
	G_OBJECT_CLASS (klass)->finalize = seahorse_pkcs11_key_deleter_finalize;
}

static void
seahorse_pkcs11_key_deleter_instance_init (SeahorsePkcs11KeyDeleter * self,
                                           gpointer klass)
{
	self->priv = seahorse_pkcs11_key_deleter_get_instance_private (self);
}

static void
seahorse_pkcs11_key_deleter_finalize (GObject * obj)
{
	SeahorsePkcs11KeyDeleter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_PKCS11_TYPE_KEY_DELETER, SeahorsePkcs11KeyDeleter);
	_g_object_unref0 (self->priv->_cert);
	_g_object_unref0 (self->priv->_key);
	_g_free0 (self->priv->_label);
	G_OBJECT_CLASS (seahorse_pkcs11_key_deleter_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
seahorse_pkcs11_key_deleter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorsePkcs11KeyDeleterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_pkcs11_key_deleter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorsePkcs11KeyDeleter), 0, (GInstanceInitFunc) seahorse_pkcs11_key_deleter_instance_init, NULL };
	GType seahorse_pkcs11_key_deleter_type_id;
	seahorse_pkcs11_key_deleter_type_id = g_type_register_static (SEAHORSE_PKCS11_TYPE_DELETER, "SeahorsePkcs11KeyDeleter", &g_define_type_info, 0);
	SeahorsePkcs11KeyDeleter_private_offset = g_type_add_instance_private (seahorse_pkcs11_key_deleter_type_id, sizeof (SeahorsePkcs11KeyDeleterPrivate));
	return seahorse_pkcs11_key_deleter_type_id;
}

GType
seahorse_pkcs11_key_deleter_get_type (void)
{
	static volatile gsize seahorse_pkcs11_key_deleter_type_id__once = 0;
	if (g_once_init_enter (&seahorse_pkcs11_key_deleter_type_id__once)) {
		GType seahorse_pkcs11_key_deleter_type_id;
		seahorse_pkcs11_key_deleter_type_id = seahorse_pkcs11_key_deleter_get_type_once ();
		g_once_init_leave (&seahorse_pkcs11_key_deleter_type_id__once, seahorse_pkcs11_key_deleter_type_id);
	}
	return seahorse_pkcs11_key_deleter_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

