/* contact_details_provider.c generated by valac 0.56.19, the Vala compiler
 * generated from contact_details_provider.vala, do not modify */

#include "openpgp.h"
#include "libdino.h"
#include <glib-object.h>
#include <glib.h>
#include <adwaita.h>
#include <stdlib.h>
#include <string.h>
#include "xmpp-vala.h"
#include <gee.h>
#include <gpgme.h>
#include <gpgme_fix.h>
#include "dino_i18n.h"
#include <gtk/gtk.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

enum  {
	DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_0_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_ID_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_TAB_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_open_pgp_contact_details_provider_properties[DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_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))
#define _gpgme_key_unref_vapi0(var) ((var == NULL) ? NULL : (var = (gpgme_key_unref_vapi (var), NULL)))

struct _DinoPluginsOpenPgpContactDetailsProviderPrivate {
	DinoStreamInteractor* stream_interactor;
};

static gint DinoPluginsOpenPgpContactDetailsProvider_private_offset;
static gpointer dino_plugins_open_pgp_contact_details_provider_parent_class = NULL;
static DinoPluginsContactDetailsProviderIface * dino_plugins_open_pgp_contact_details_provider_dino_plugins_contact_details_provider_parent_iface = NULL;

static void dino_plugins_open_pgp_contact_details_provider_real_populate (DinoPluginsContactDetailsProvider* base,
                                                                   DinoEntitiesConversation* conversation,
                                                                   DinoPluginsContactDetails* contact_details,
                                                                   DinoPluginsWidgetType type);
static GObject* dino_plugins_open_pgp_contact_details_provider_real_get_widget (DinoPluginsContactDetailsProvider* base,
                                                                         DinoEntitiesConversation* conversation);
static void dino_plugins_open_pgp_contact_details_provider_finalize (GObject * obj);
static GType dino_plugins_open_pgp_contact_details_provider_get_type_once (void);
static void _vala_dino_plugins_open_pgp_contact_details_provider_get_property (GObject * object,
                                                                        guint property_id,
                                                                        GValue * value,
                                                                        GParamSpec * pspec);
static gssize _vala_array_length (gpointer array);

static inline gpointer
dino_plugins_open_pgp_contact_details_provider_get_instance_private (DinoPluginsOpenPgpContactDetailsProvider* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOpenPgpContactDetailsProvider_private_offset);
}

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

DinoPluginsOpenPgpContactDetailsProvider*
dino_plugins_open_pgp_contact_details_provider_construct (GType object_type,
                                                          DinoStreamInteractor* stream_interactor)
{
	DinoPluginsOpenPgpContactDetailsProvider * self = NULL;
	DinoStreamInteractor* _tmp0_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	self = (DinoPluginsOpenPgpContactDetailsProvider*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	return self;
}

DinoPluginsOpenPgpContactDetailsProvider*
dino_plugins_open_pgp_contact_details_provider_new (DinoStreamInteractor* stream_interactor)
{
	return dino_plugins_open_pgp_contact_details_provider_construct (DINO_PLUGINS_OPEN_PGP_TYPE_CONTACT_DETAILS_PROVIDER, stream_interactor);
}

static void
dino_plugins_open_pgp_contact_details_provider_real_populate (DinoPluginsContactDetailsProvider* base,
                                                              DinoEntitiesConversation* conversation,
                                                              DinoPluginsContactDetails* contact_details,
                                                              DinoPluginsWidgetType type)
{
	DinoPluginsOpenPgpContactDetailsProvider * self;
	self = (DinoPluginsOpenPgpContactDetailsProvider*) base;
	g_return_if_fail (conversation != NULL);
	g_return_if_fail (contact_details != NULL);
}

static const gchar*
gpgme_key_get_fpr (struct _gpgme_key* self)
{
	const gchar* result;
	struct _gpgme_subkey* _tmp0_;
	gint _tmp0__length1;
	struct _gpgme_subkey _tmp1_;
	const gchar* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->subkeys;
	_tmp0__length1 = _vala_array_length (self->subkeys);
	_tmp1_ = _tmp0_[0];
	_tmp2_ = _tmp1_.fpr;
	result = _tmp2_;
	return result;
}

static GObject*
dino_plugins_open_pgp_contact_details_provider_real_get_widget (DinoPluginsContactDetailsProvider* base,
                                                                DinoEntitiesConversation* conversation)
{
	DinoPluginsOpenPgpContactDetailsProvider * self;
	AdwPreferencesGroup* preferences_group = NULL;
	gchar* _tmp0_;
	AdwPreferencesGroup* _tmp1_ = NULL;
	DinoEntitiesConversationType _tmp2_;
	DinoEntitiesConversationType _tmp3_;
	gchar* key_id = NULL;
	DinoStreamInteractor* _tmp4_;
	DinoModuleIdentity* _tmp5_;
	gpointer _tmp6_;
	DinoPluginsOpenPgpManager* _tmp7_;
	DinoEntitiesAccount* _tmp8_;
	DinoEntitiesAccount* _tmp9_;
	XmppJid* _tmp10_;
	XmppJid* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	GeeList* keys = NULL;
	gchar* str = NULL;
	gchar* _tmp19_;
	gboolean _tmp20_ = FALSE;
	GeeList* _tmp21_;
	AdwActionRow* view = NULL;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	const gchar* _tmp40_;
	gchar* _tmp41_;
	AdwActionRow* _tmp42_ = NULL;
	AdwPreferencesGroup* _tmp43_;
	AdwActionRow* _tmp44_;
	GError* _inner_error0_ = NULL;
	GObject* result;
	self = (DinoPluginsOpenPgpContactDetailsProvider*) base;
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = g_strdup ("OpenPGP");
	_tmp1_ = (AdwPreferencesGroup*) adw_preferences_group_new ();
	adw_preferences_group_set_title (_tmp1_, _tmp0_);
	_g_free0 (_tmp0_);
	g_object_ref_sink (_tmp1_);
	preferences_group = _tmp1_;
	_tmp2_ = dino_entities_conversation_get_type_ (conversation);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != DINO_ENTITIES_CONVERSATION_TYPE_CHAT) {
		result = NULL;
		_g_object_unref0 (preferences_group);
		return result;
	}
	_tmp4_ = self->priv->stream_interactor;
	_tmp5_ = dino_plugins_open_pgp_manager_IDENTITY;
	_tmp6_ = dino_stream_interactor_get_module (_tmp4_, DINO_PLUGINS_OPEN_PGP_TYPE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp5_);
	_tmp7_ = (DinoPluginsOpenPgpManager*) _tmp6_;
	_tmp8_ = dino_entities_conversation_get_account (conversation);
	_tmp9_ = _tmp8_;
	_tmp10_ = dino_entities_conversation_get_counterpart (conversation);
	_tmp11_ = _tmp10_;
	_tmp12_ = dino_plugins_open_pgp_manager_get_key_id (_tmp7_, _tmp9_, _tmp11_);
	_tmp13_ = _tmp12_;
	_g_object_unref0 (_tmp7_);
	key_id = _tmp13_;
	_tmp14_ = key_id;
	if (_tmp14_ == NULL) {
		result = NULL;
		_g_free0 (key_id);
		_g_object_unref0 (preferences_group);
		return result;
	}
	keys = NULL;
	{
		GeeList* _tmp15_ = NULL;
		const gchar* _tmp16_;
		GeeList* _tmp17_;
		GeeList* _tmp18_;
		_tmp16_ = key_id;
		_tmp17_ = gpg_helper_get_keylist (_tmp16_, FALSE, &_inner_error0_);
		_tmp15_ = _tmp17_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp18_ = _tmp15_;
		_tmp15_ = NULL;
		_g_object_unref0 (keys);
		keys = _tmp18_;
		_g_object_unref0 (_tmp15_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (keys);
		_g_free0 (key_id);
		_g_object_unref0 (preferences_group);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	_tmp19_ = g_strdup ("");
	str = _tmp19_;
	_tmp21_ = keys;
	if (_tmp21_ != NULL) {
		GeeList* _tmp22_;
		gint _tmp23_;
		gint _tmp24_;
		_tmp22_ = keys;
		_tmp23_ = gee_collection_get_size ((GeeCollection*) _tmp22_);
		_tmp24_ = _tmp23_;
		_tmp20_ = _tmp24_ > 0;
	} else {
		_tmp20_ = FALSE;
	}
	if (_tmp20_) {
		GeeList* _tmp25_;
		gpointer _tmp26_;
		struct _gpgme_key* _tmp27_;
		const gchar* _tmp28_;
		const gchar* _tmp29_;
		gchar* _tmp30_;
		_tmp25_ = keys;
		_tmp26_ = gee_list_get (_tmp25_, 0);
		_tmp27_ = (struct _gpgme_key*) _tmp26_;
		_tmp28_ = gpgme_key_get_fpr (_tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = dino_plugins_open_pgp_markup_id (_tmp29_, TRUE);
		_g_free0 (str);
		str = _tmp30_;
		_gpgme_key_unref_vapi0 (_tmp27_);
	} else {
		const gchar* _tmp31_;
		gchar* _tmp32_;
		gchar* _tmp33_;
		const gchar* _tmp34_;
		gchar* _tmp35_;
		gchar* _tmp36_;
		gchar* _tmp37_;
		_tmp31_ = dino_gettext ("Key not in keychain");
		_tmp32_ = g_strconcat (_tmp31_, "\n", NULL);
		_tmp33_ = _tmp32_;
		_tmp34_ = key_id;
		_tmp35_ = dino_plugins_open_pgp_markup_id (_tmp34_, FALSE);
		_tmp36_ = _tmp35_;
		_tmp37_ = g_strconcat (_tmp33_, _tmp36_, NULL);
		_g_free0 (str);
		str = _tmp37_;
		_g_free0 (_tmp36_);
		_g_free0 (_tmp33_);
	}
	_tmp38_ = dino_gettext ("Fingerprint");
	_tmp39_ = g_strdup (_tmp38_);
	_tmp40_ = str;
	_tmp41_ = g_strdup (_tmp40_);
	_tmp42_ = (AdwActionRow*) adw_action_row_new ();
	adw_preferences_row_set_title ((AdwPreferencesRow*) _tmp42_, _tmp39_);
	_g_free0 (_tmp39_);
	adw_action_row_set_subtitle (_tmp42_, _tmp41_);
	_g_free0 (_tmp41_);
	g_object_ref_sink (_tmp42_);
	view = _tmp42_;
	_tmp43_ = preferences_group;
	_tmp44_ = view;
	adw_preferences_group_add (_tmp43_, (GtkWidget*) _tmp44_);
	result = (GObject*) preferences_group;
	_g_object_unref0 (view);
	_g_free0 (str);
	_g_object_unref0 (keys);
	_g_free0 (key_id);
	return result;
}

static const gchar*
dino_plugins_open_pgp_contact_details_provider_real_get_id (DinoPluginsContactDetailsProvider* base)
{
	const gchar* result;
	DinoPluginsOpenPgpContactDetailsProvider* self;
	self = (DinoPluginsOpenPgpContactDetailsProvider*) base;
	result = "pgp_info";
	return result;
}

static const gchar*
dino_plugins_open_pgp_contact_details_provider_real_get_tab (DinoPluginsContactDetailsProvider* base)
{
	const gchar* result;
	DinoPluginsOpenPgpContactDetailsProvider* self;
	self = (DinoPluginsOpenPgpContactDetailsProvider*) base;
	result = "encryption";
	return result;
}

static void
dino_plugins_open_pgp_contact_details_provider_class_init (DinoPluginsOpenPgpContactDetailsProviderClass * klass,
                                                           gpointer klass_data)
{
	dino_plugins_open_pgp_contact_details_provider_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOpenPgpContactDetailsProvider_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_plugins_open_pgp_contact_details_provider_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_open_pgp_contact_details_provider_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_ID_PROPERTY, dino_plugins_open_pgp_contact_details_provider_properties[DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_TAB_PROPERTY, dino_plugins_open_pgp_contact_details_provider_properties[DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_TAB_PROPERTY] = g_param_spec_string ("tab", "tab", "tab", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
dino_plugins_open_pgp_contact_details_provider_dino_plugins_contact_details_provider_interface_init (DinoPluginsContactDetailsProviderIface * iface,
                                                                                                     gpointer iface_data)
{
	dino_plugins_open_pgp_contact_details_provider_dino_plugins_contact_details_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->populate = (void (*) (DinoPluginsContactDetailsProvider*, DinoEntitiesConversation*, DinoPluginsContactDetails*, DinoPluginsWidgetType)) dino_plugins_open_pgp_contact_details_provider_real_populate;
	iface->get_widget = (GObject* (*) (DinoPluginsContactDetailsProvider*, DinoEntitiesConversation*)) dino_plugins_open_pgp_contact_details_provider_real_get_widget;
	iface->get_id = dino_plugins_open_pgp_contact_details_provider_real_get_id;
	iface->get_tab = dino_plugins_open_pgp_contact_details_provider_real_get_tab;
}

static void
dino_plugins_open_pgp_contact_details_provider_instance_init (DinoPluginsOpenPgpContactDetailsProvider * self,
                                                              gpointer klass)
{
	self->priv = dino_plugins_open_pgp_contact_details_provider_get_instance_private (self);
}

static void
dino_plugins_open_pgp_contact_details_provider_finalize (GObject * obj)
{
	DinoPluginsOpenPgpContactDetailsProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OPEN_PGP_TYPE_CONTACT_DETAILS_PROVIDER, DinoPluginsOpenPgpContactDetailsProvider);
	_g_object_unref0 (self->priv->stream_interactor);
	G_OBJECT_CLASS (dino_plugins_open_pgp_contact_details_provider_parent_class)->finalize (obj);
}

static GType
dino_plugins_open_pgp_contact_details_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOpenPgpContactDetailsProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_open_pgp_contact_details_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOpenPgpContactDetailsProvider), 0, (GInstanceInitFunc) dino_plugins_open_pgp_contact_details_provider_instance_init, NULL };
	static const GInterfaceInfo dino_plugins_contact_details_provider_info = { (GInterfaceInitFunc) dino_plugins_open_pgp_contact_details_provider_dino_plugins_contact_details_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_open_pgp_contact_details_provider_type_id;
	dino_plugins_open_pgp_contact_details_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOpenPgpContactDetailsProvider", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_open_pgp_contact_details_provider_type_id, DINO_PLUGINS_TYPE_CONTACT_DETAILS_PROVIDER, &dino_plugins_contact_details_provider_info);
	DinoPluginsOpenPgpContactDetailsProvider_private_offset = g_type_add_instance_private (dino_plugins_open_pgp_contact_details_provider_type_id, sizeof (DinoPluginsOpenPgpContactDetailsProviderPrivate));
	return dino_plugins_open_pgp_contact_details_provider_type_id;
}

GType
dino_plugins_open_pgp_contact_details_provider_get_type (void)
{
	static volatile gsize dino_plugins_open_pgp_contact_details_provider_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_open_pgp_contact_details_provider_type_id__once)) {
		GType dino_plugins_open_pgp_contact_details_provider_type_id;
		dino_plugins_open_pgp_contact_details_provider_type_id = dino_plugins_open_pgp_contact_details_provider_get_type_once ();
		g_once_init_leave (&dino_plugins_open_pgp_contact_details_provider_type_id__once, dino_plugins_open_pgp_contact_details_provider_type_id);
	}
	return dino_plugins_open_pgp_contact_details_provider_type_id__once;
}

static void
_vala_dino_plugins_open_pgp_contact_details_provider_get_property (GObject * object,
                                                                   guint property_id,
                                                                   GValue * value,
                                                                   GParamSpec * pspec)
{
	DinoPluginsOpenPgpContactDetailsProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_PLUGINS_OPEN_PGP_TYPE_CONTACT_DETAILS_PROVIDER, DinoPluginsOpenPgpContactDetailsProvider);
	switch (property_id) {
		case DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_ID_PROPERTY:
		g_value_set_string (value, dino_plugins_contact_details_provider_get_id ((DinoPluginsContactDetailsProvider*) self));
		break;
		case DINO_PLUGINS_OPEN_PGP_CONTACT_DETAILS_PROVIDER_TAB_PROPERTY:
		g_value_set_string (value, dino_plugins_contact_details_provider_get_tab ((DinoPluginsContactDetailsProvider*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

