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

#include "omemo.h"
#include <glib-object.h>
#include <glib.h>
#include "libdino.h"
#include "xmpp-vala.h"
#include "qlite.h"
#include <stdlib.h>
#include <string.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_OMEMO_CALL_ENCRYPTION_ENTRY_0_PROPERTY,
	DINO_PLUGINS_OMEMO_CALL_ENCRYPTION_ENTRY_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_call_encryption_entry_properties[DINO_PLUGINS_OMEMO_CALL_ENCRYPTION_ENTRY_NUM_PROPERTIES];
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
enum  {
	DINO_PLUGINS_OMEMO_CALL_ENCRYPTION_WIDGET_0_PROPERTY,
	DINO_PLUGINS_OMEMO_CALL_ENCRYPTION_WIDGET_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_call_encryption_widget_properties[DINO_PLUGINS_OMEMO_CALL_ENCRYPTION_WIDGET_NUM_PROPERTIES];

struct _DinoPluginsOmemoCallEncryptionEntryPrivate {
	DinoPluginsOmemoDatabase* db;
};

struct _DinoPluginsOmemoCallEncryptionWidgetPrivate {
	gchar* title;
	gchar* icon;
	gboolean should_show_keys;
};

static gint DinoPluginsOmemoCallEncryptionEntry_private_offset;
static gpointer dino_plugins_omemo_call_encryption_entry_parent_class = NULL;
static DinoPluginsCallEncryptionEntryIface * dino_plugins_omemo_call_encryption_entry_dino_plugins_call_encryption_entry_parent_iface = NULL;
static gint DinoPluginsOmemoCallEncryptionWidget_private_offset;
static gpointer dino_plugins_omemo_call_encryption_widget_parent_class = NULL;
static DinoPluginsCallEncryptionWidgetIface * dino_plugins_omemo_call_encryption_widget_dino_plugins_call_encryption_widget_parent_iface = NULL;

static DinoPluginsCallEncryptionWidget* dino_plugins_omemo_call_encryption_entry_real_get_widget (DinoPluginsCallEncryptionEntry* base,
                                                                                           DinoEntitiesAccount* account,
                                                                                           XmppXepJingleContentEncryption* encryption);
static void dino_plugins_omemo_call_encryption_entry_finalize (GObject * obj);
static GType dino_plugins_omemo_call_encryption_entry_get_type_once (void);
static gchar* dino_plugins_omemo_call_encryption_widget_real_get_title (DinoPluginsCallEncryptionWidget* base);
static gchar* dino_plugins_omemo_call_encryption_widget_real_get_icon_name (DinoPluginsCallEncryptionWidget* base);
static gboolean dino_plugins_omemo_call_encryption_widget_real_show_keys (DinoPluginsCallEncryptionWidget* base);
static void dino_plugins_omemo_call_encryption_widget_finalize (GObject * obj);
static GType dino_plugins_omemo_call_encryption_widget_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_plugins_omemo_call_encryption_entry_get_instance_private (DinoPluginsOmemoCallEncryptionEntry* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoCallEncryptionEntry_private_offset);
}

static gpointer
_qlite_database_ref0 (gpointer self)
{
	return self ? qlite_database_ref (self) : NULL;
}

DinoPluginsOmemoCallEncryptionEntry*
dino_plugins_omemo_call_encryption_entry_construct (GType object_type,
                                                    DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoCallEncryptionEntry * self = NULL;
	DinoPluginsOmemoDatabase* _tmp0_;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoCallEncryptionEntry*) g_object_new (object_type, NULL);
	_tmp0_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp0_;
	return self;
}

DinoPluginsOmemoCallEncryptionEntry*
dino_plugins_omemo_call_encryption_entry_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_call_encryption_entry_construct (DINO_PLUGINS_OMEMO_TYPE_CALL_ENCRYPTION_ENTRY, db);
}

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

static DinoPluginsCallEncryptionWidget*
dino_plugins_omemo_call_encryption_entry_real_get_widget (DinoPluginsCallEncryptionEntry* base,
                                                          DinoEntitiesAccount* account,
                                                          XmppXepJingleContentEncryption* encryption)
{
	DinoPluginsOmemoCallEncryptionEntry * self;
	DinoPluginsOmemoDtlsSrtpVerificationDraftOmemoContentEncryption* omemo_encryption = NULL;
	DinoPluginsOmemoDtlsSrtpVerificationDraftOmemoContentEncryption* _tmp0_;
	DinoPluginsOmemoDtlsSrtpVerificationDraftOmemoContentEncryption* _tmp1_;
	gint identity_id = 0;
	DinoPluginsOmemoDatabase* _tmp2_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp3_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	QliteRow* device = NULL;
	DinoPluginsOmemoDatabase* _tmp7_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp8_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp9_;
	DinoPluginsOmemoDtlsSrtpVerificationDraftOmemoContentEncryption* _tmp10_;
	XmppJid* _tmp11_;
	XmppJid* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	DinoPluginsOmemoDtlsSrtpVerificationDraftOmemoContentEncryption* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	QliteRow* _tmp18_;
	QliteRow* _tmp19_;
	QliteRow* _tmp20_;
	DinoPluginsOmemoTrustLevel trust = 0;
	QliteRow* _tmp21_;
	DinoPluginsOmemoDatabase* _tmp22_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp23_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp24_;
	QliteColumn* _tmp25_;
	gpointer _tmp26_;
	DinoPluginsOmemoCallEncryptionWidget* _tmp27_;
	DinoPluginsCallEncryptionWidget* result;
	self = (DinoPluginsOmemoCallEncryptionEntry*) base;
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (encryption != NULL, NULL);
	_tmp0_ = _g_object_ref0 (DINO_PLUGINS_OMEMO_DTLS_SRTP_VERIFICATION_DRAFT_IS_OMEMO_CONTENT_ENCRYPTION (encryption) ? ((DinoPluginsOmemoDtlsSrtpVerificationDraftOmemoContentEncryption*) encryption) : NULL);
	omemo_encryption = _tmp0_;
	_tmp1_ = omemo_encryption;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_object_unref0 (omemo_encryption);
		return result;
	}
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_plugins_omemo_database_get_identity (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_entities_account_get_id (account);
	_tmp6_ = _tmp5_;
	identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp4_, _tmp6_);
	_tmp7_ = self->priv->db;
	_tmp8_ = dino_plugins_omemo_database_get_identity_meta (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = omemo_encryption;
	_tmp11_ = dino_plugins_omemo_dtls_srtp_verification_draft_omemo_content_encryption_get_jid (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = xmpp_jid_to_string (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = omemo_encryption;
	_tmp16_ = dino_plugins_omemo_dtls_srtp_verification_draft_omemo_content_encryption_get_sid (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = dino_plugins_omemo_database_identity_meta_table_get_device (_tmp9_, identity_id, _tmp14_, _tmp17_);
	_tmp19_ = _tmp18_;
	_g_free0 (_tmp14_);
	device = _tmp19_;
	_tmp20_ = device;
	if (_tmp20_ == NULL) {
		result = NULL;
		_qlite_row_unref0 (device);
		_g_object_unref0 (omemo_encryption);
		return result;
	}
	_tmp21_ = device;
	_tmp22_ = self->priv->db;
	_tmp23_ = dino_plugins_omemo_database_get_identity_meta (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = _tmp24_->trust_level;
	_tmp26_ = qlite_row_get (_tmp21_, G_TYPE_INT, NULL, NULL, _tmp25_);
	trust = (DinoPluginsOmemoTrustLevel) ((gint) ((gintptr) _tmp26_));
	_tmp27_ = dino_plugins_omemo_call_encryption_widget_new (trust);
	result = (DinoPluginsCallEncryptionWidget*) _tmp27_;
	_qlite_row_unref0 (device);
	_g_object_unref0 (omemo_encryption);
	return result;
}

static void
dino_plugins_omemo_call_encryption_entry_class_init (DinoPluginsOmemoCallEncryptionEntryClass * klass,
                                                     gpointer klass_data)
{
	dino_plugins_omemo_call_encryption_entry_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoCallEncryptionEntry_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_call_encryption_entry_finalize;
}

static void
dino_plugins_omemo_call_encryption_entry_dino_plugins_call_encryption_entry_interface_init (DinoPluginsCallEncryptionEntryIface * iface,
                                                                                            gpointer iface_data)
{
	dino_plugins_omemo_call_encryption_entry_dino_plugins_call_encryption_entry_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_widget = (DinoPluginsCallEncryptionWidget* (*) (DinoPluginsCallEncryptionEntry*, DinoEntitiesAccount*, XmppXepJingleContentEncryption*)) dino_plugins_omemo_call_encryption_entry_real_get_widget;
}

static void
dino_plugins_omemo_call_encryption_entry_instance_init (DinoPluginsOmemoCallEncryptionEntry * self,
                                                        gpointer klass)
{
	self->priv = dino_plugins_omemo_call_encryption_entry_get_instance_private (self);
}

static void
dino_plugins_omemo_call_encryption_entry_finalize (GObject * obj)
{
	DinoPluginsOmemoCallEncryptionEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_CALL_ENCRYPTION_ENTRY, DinoPluginsOmemoCallEncryptionEntry);
	_qlite_database_unref0 (self->priv->db);
	G_OBJECT_CLASS (dino_plugins_omemo_call_encryption_entry_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_call_encryption_entry_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoCallEncryptionEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_call_encryption_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoCallEncryptionEntry), 0, (GInstanceInitFunc) dino_plugins_omemo_call_encryption_entry_instance_init, NULL };
	static const GInterfaceInfo dino_plugins_call_encryption_entry_info = { (GInterfaceInitFunc) dino_plugins_omemo_call_encryption_entry_dino_plugins_call_encryption_entry_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_omemo_call_encryption_entry_type_id;
	dino_plugins_omemo_call_encryption_entry_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOmemoCallEncryptionEntry", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_omemo_call_encryption_entry_type_id, DINO_PLUGINS_TYPE_CALL_ENCRYPTION_ENTRY, &dino_plugins_call_encryption_entry_info);
	DinoPluginsOmemoCallEncryptionEntry_private_offset = g_type_add_instance_private (dino_plugins_omemo_call_encryption_entry_type_id, sizeof (DinoPluginsOmemoCallEncryptionEntryPrivate));
	return dino_plugins_omemo_call_encryption_entry_type_id;
}

GType
dino_plugins_omemo_call_encryption_entry_get_type (void)
{
	static volatile gsize dino_plugins_omemo_call_encryption_entry_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_call_encryption_entry_type_id__once)) {
		GType dino_plugins_omemo_call_encryption_entry_type_id;
		dino_plugins_omemo_call_encryption_entry_type_id = dino_plugins_omemo_call_encryption_entry_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_call_encryption_entry_type_id__once, dino_plugins_omemo_call_encryption_entry_type_id);
	}
	return dino_plugins_omemo_call_encryption_entry_type_id__once;
}

static inline gpointer
dino_plugins_omemo_call_encryption_widget_get_instance_private (DinoPluginsOmemoCallEncryptionWidget* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoCallEncryptionWidget_private_offset);
}

DinoPluginsOmemoCallEncryptionWidget*
dino_plugins_omemo_call_encryption_widget_construct (GType object_type,
                                                     DinoPluginsOmemoTrustLevel trust)
{
	DinoPluginsOmemoCallEncryptionWidget * self = NULL;
	self = (DinoPluginsOmemoCallEncryptionWidget*) g_object_new (object_type, NULL);
	if (trust == DINO_PLUGINS_OMEMO_TRUST_LEVEL_VERIFIED) {
		gchar* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = g_strdup ("This call is <b>encrypted and verified</b> with OMEMO.");
		_g_free0 (self->priv->title);
		self->priv->title = _tmp0_;
		_tmp1_ = g_strdup ("dino-security-high-symbolic");
		_g_free0 (self->priv->icon);
		self->priv->icon = _tmp1_;
		self->priv->should_show_keys = FALSE;
	} else {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("This call is encrypted with OMEMO.");
		_g_free0 (self->priv->title);
		self->priv->title = _tmp2_;
		self->priv->should_show_keys = TRUE;
	}
	return self;
}

DinoPluginsOmemoCallEncryptionWidget*
dino_plugins_omemo_call_encryption_widget_new (DinoPluginsOmemoTrustLevel trust)
{
	return dino_plugins_omemo_call_encryption_widget_construct (DINO_PLUGINS_OMEMO_TYPE_CALL_ENCRYPTION_WIDGET, trust);
}

static gchar*
dino_plugins_omemo_call_encryption_widget_real_get_title (DinoPluginsCallEncryptionWidget* base)
{
	DinoPluginsOmemoCallEncryptionWidget * self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	self = (DinoPluginsOmemoCallEncryptionWidget*) base;
	_tmp0_ = self->priv->title;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

static gchar*
dino_plugins_omemo_call_encryption_widget_real_get_icon_name (DinoPluginsCallEncryptionWidget* base)
{
	DinoPluginsOmemoCallEncryptionWidget * self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	self = (DinoPluginsOmemoCallEncryptionWidget*) base;
	_tmp0_ = self->priv->icon;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

static gboolean
dino_plugins_omemo_call_encryption_widget_real_show_keys (DinoPluginsCallEncryptionWidget* base)
{
	DinoPluginsOmemoCallEncryptionWidget * self;
	gboolean result;
	self = (DinoPluginsOmemoCallEncryptionWidget*) base;
	result = self->priv->should_show_keys;
	return result;
}

static void
dino_plugins_omemo_call_encryption_widget_class_init (DinoPluginsOmemoCallEncryptionWidgetClass * klass,
                                                      gpointer klass_data)
{
	dino_plugins_omemo_call_encryption_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoCallEncryptionWidget_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_call_encryption_widget_finalize;
}

static void
dino_plugins_omemo_call_encryption_widget_dino_plugins_call_encryption_widget_interface_init (DinoPluginsCallEncryptionWidgetIface * iface,
                                                                                              gpointer iface_data)
{
	dino_plugins_omemo_call_encryption_widget_dino_plugins_call_encryption_widget_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_title = (gchar* (*) (DinoPluginsCallEncryptionWidget*)) dino_plugins_omemo_call_encryption_widget_real_get_title;
	iface->get_icon_name = (gchar* (*) (DinoPluginsCallEncryptionWidget*)) dino_plugins_omemo_call_encryption_widget_real_get_icon_name;
	iface->show_keys = (gboolean (*) (DinoPluginsCallEncryptionWidget*)) dino_plugins_omemo_call_encryption_widget_real_show_keys;
}

static void
dino_plugins_omemo_call_encryption_widget_instance_init (DinoPluginsOmemoCallEncryptionWidget * self,
                                                         gpointer klass)
{
	self->priv = dino_plugins_omemo_call_encryption_widget_get_instance_private (self);
	self->priv->title = NULL;
	self->priv->icon = NULL;
	self->priv->should_show_keys = FALSE;
}

static void
dino_plugins_omemo_call_encryption_widget_finalize (GObject * obj)
{
	DinoPluginsOmemoCallEncryptionWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_CALL_ENCRYPTION_WIDGET, DinoPluginsOmemoCallEncryptionWidget);
	_g_free0 (self->priv->title);
	_g_free0 (self->priv->icon);
	G_OBJECT_CLASS (dino_plugins_omemo_call_encryption_widget_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_call_encryption_widget_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoCallEncryptionWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_call_encryption_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoCallEncryptionWidget), 0, (GInstanceInitFunc) dino_plugins_omemo_call_encryption_widget_instance_init, NULL };
	static const GInterfaceInfo dino_plugins_call_encryption_widget_info = { (GInterfaceInitFunc) dino_plugins_omemo_call_encryption_widget_dino_plugins_call_encryption_widget_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_omemo_call_encryption_widget_type_id;
	dino_plugins_omemo_call_encryption_widget_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOmemoCallEncryptionWidget", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_omemo_call_encryption_widget_type_id, DINO_PLUGINS_TYPE_CALL_ENCRYPTION_WIDGET, &dino_plugins_call_encryption_widget_info);
	DinoPluginsOmemoCallEncryptionWidget_private_offset = g_type_add_instance_private (dino_plugins_omemo_call_encryption_widget_type_id, sizeof (DinoPluginsOmemoCallEncryptionWidgetPrivate));
	return dino_plugins_omemo_call_encryption_widget_type_id;
}

GType
dino_plugins_omemo_call_encryption_widget_get_type (void)
{
	static volatile gsize dino_plugins_omemo_call_encryption_widget_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_call_encryption_widget_type_id__once)) {
		GType dino_plugins_omemo_call_encryption_widget_type_id;
		dino_plugins_omemo_call_encryption_widget_type_id = dino_plugins_omemo_call_encryption_widget_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_call_encryption_widget_type_id__once, dino_plugins_omemo_call_encryption_widget_type_id);
	}
	return dino_plugins_omemo_call_encryption_widget_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;
}

