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

#include "omemo.h"
#include "libdino.h"
#include <glib-object.h>
#include <glib.h>
#include "xmpp-vala.h"
#include <gio/gio.h>
#include "dino_i18n.h"
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block29Data Block29Data;
#define _dino_plugins_omemo_own_notifications_unref0(var) ((var == NULL) ? NULL : (var = (dino_plugins_omemo_own_notifications_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DinoPluginsOmemoParamSpecOwnNotifications DinoPluginsOmemoParamSpecOwnNotifications;

struct _DinoPluginsOmemoOwnNotificationsPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoPluginsOmemoPlugin* plugin;
	DinoEntitiesAccount* account;
};

struct _Block29Data {
	int _ref_count_;
	DinoPluginsOmemoOwnNotifications* self;
	DinoPluginsOmemoPlugin* plugin;
	DinoEntitiesAccount* account;
};

struct _DinoPluginsOmemoParamSpecOwnNotifications {
	GParamSpec parent_instance;
};

static gint DinoPluginsOmemoOwnNotifications_private_offset;
static gpointer dino_plugins_omemo_own_notifications_parent_class = NULL;

static Block29Data* block29_data_ref (Block29Data* _data29_);
static void block29_data_unref (void * _userdata_);
static void __lambda39_ (Block29Data* _data29_,
                  XmppJid* jid,
                  gint device_id,
                  DinoPluginsOmemoBundle* bundle);
static void dino_plugins_omemo_own_notifications_display_notification (DinoPluginsOmemoOwnNotifications* self);
static void ___lambda39__dino_plugins_omemo_stream_module_bundle_fetched (DinoPluginsOmemoStreamModule* _sender,
                                                                   XmppJid* jid,
                                                                   gint device_id,
                                                                   DinoPluginsOmemoBundle* bundle,
                                                                   gpointer self);
static void dino_plugins_omemo_own_notifications_finalize (DinoPluginsOmemoOwnNotifications * obj);
static GType dino_plugins_omemo_own_notifications_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_plugins_omemo_own_notifications_get_instance_private (DinoPluginsOmemoOwnNotifications* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoOwnNotifications_private_offset);
}

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

static Block29Data*
block29_data_ref (Block29Data* _data29_)
{
	g_atomic_int_inc (&_data29_->_ref_count_);
	return _data29_;
}

static void
block29_data_unref (void * _userdata_)
{
	Block29Data* _data29_;
	_data29_ = (Block29Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data29_->_ref_count_)) {
		DinoPluginsOmemoOwnNotifications* self;
		self = _data29_->self;
		_g_object_unref0 (_data29_->plugin);
		_g_object_unref0 (_data29_->account);
		_dino_plugins_omemo_own_notifications_unref0 (self);
		g_slice_free (Block29Data, _data29_);
	}
}

static void
__lambda39_ (Block29Data* _data29_,
             XmppJid* jid,
             gint device_id,
             DinoPluginsOmemoBundle* bundle)
{
	DinoPluginsOmemoOwnNotifications* self;
	gboolean _tmp0_ = FALSE;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	XmppJid* _tmp3_;
	gboolean _tmp4_;
	self = _data29_->self;
	g_return_if_fail (jid != NULL);
	g_return_if_fail (bundle != NULL);
	_tmp1_ = dino_entities_account_get_bare_jid (_data29_->account);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = xmpp_jid_equals (jid, _tmp3_);
	_xmpp_jid_unref0 (_tmp3_);
	if (_tmp4_) {
		XmppJid* _tmp5_;
		XmppJid* _tmp6_;
		XmppJid* _tmp7_;
		_tmp5_ = dino_entities_account_get_bare_jid (_data29_->account);
		_tmp6_ = _tmp5_;
		_tmp7_ = _tmp6_;
		_tmp0_ = dino_plugins_omemo_plugin_has_new_devices (_data29_->plugin, _data29_->account, _tmp7_);
		_xmpp_jid_unref0 (_tmp7_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		dino_plugins_omemo_own_notifications_display_notification (self);
	}
}

static void
___lambda39__dino_plugins_omemo_stream_module_bundle_fetched (DinoPluginsOmemoStreamModule* _sender,
                                                              XmppJid* jid,
                                                              gint device_id,
                                                              DinoPluginsOmemoBundle* bundle,
                                                              gpointer self)
{
	__lambda39_ (self, jid, device_id, bundle);
}

DinoPluginsOmemoOwnNotifications*
dino_plugins_omemo_own_notifications_construct (GType object_type,
                                                DinoPluginsOmemoPlugin* plugin,
                                                DinoStreamInteractor* stream_interactor,
                                                DinoEntitiesAccount* account)
{
	DinoPluginsOmemoOwnNotifications* self = NULL;
	Block29Data* _data29_;
	DinoPluginsOmemoPlugin* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	DinoStreamInteractor* _tmp2_;
	DinoPluginsOmemoPlugin* _tmp3_;
	DinoEntitiesAccount* _tmp4_;
	DinoModuleManager* _tmp5_;
	XmppModuleIdentity* _tmp6_;
	gpointer _tmp7_;
	DinoPluginsOmemoStreamModule* _tmp8_;
	XmppJid* _tmp9_;
	XmppJid* _tmp10_;
	XmppJid* _tmp11_;
	gboolean _tmp12_;
	g_return_val_if_fail (plugin != NULL, NULL);
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	self = (DinoPluginsOmemoOwnNotifications*) g_type_create_instance (object_type);
	_data29_ = g_slice_new0 (Block29Data);
	_data29_->_ref_count_ = 1;
	_data29_->self = dino_plugins_omemo_own_notifications_ref (self);
	_tmp0_ = _g_object_ref0 (plugin);
	_g_object_unref0 (_data29_->plugin);
	_data29_->plugin = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data29_->account);
	_data29_->account = _tmp1_;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (stream_interactor, DINO_TYPE_STREAM_INTERACTOR, DinoStreamInteractor));
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp2_;
	_tmp3_ = _g_object_ref0 (_data29_->plugin);
	_g_object_unref0 (self->priv->plugin);
	self->priv->plugin = _tmp3_;
	_tmp4_ = _g_object_ref0 (_data29_->account);
	_g_object_unref0 (self->priv->account);
	self->priv->account = _tmp4_;
	_tmp5_ = stream_interactor->module_manager;
	_tmp6_ = dino_plugins_omemo_stream_module_IDENTITY;
	_tmp7_ = dino_module_manager_get_module (_tmp5_, DINO_PLUGINS_OMEMO_TYPE_STREAM_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data29_->account, _tmp6_);
	_tmp8_ = (DinoPluginsOmemoStreamModule*) _tmp7_;
	g_signal_connect_data (_tmp8_, "bundle-fetched", (GCallback) ___lambda39__dino_plugins_omemo_stream_module_bundle_fetched, block29_data_ref (_data29_), (GClosureNotify) block29_data_unref, G_CONNECT_AFTER);
	_g_object_unref0 (_tmp8_);
	_tmp9_ = dino_entities_account_get_bare_jid (_data29_->account);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp12_ = dino_plugins_omemo_plugin_has_new_devices (_data29_->plugin, _data29_->account, _tmp11_);
	_xmpp_jid_unref0 (_tmp11_);
	if (_tmp12_) {
		dino_plugins_omemo_own_notifications_display_notification (self);
	}
	block29_data_unref (_data29_);
	_data29_ = NULL;
	return self;
}

DinoPluginsOmemoOwnNotifications*
dino_plugins_omemo_own_notifications_new (DinoPluginsOmemoPlugin* plugin,
                                          DinoStreamInteractor* stream_interactor,
                                          DinoEntitiesAccount* account)
{
	return dino_plugins_omemo_own_notifications_construct (DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS, plugin, stream_interactor, account);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
dino_plugins_omemo_own_notifications_display_notification (DinoPluginsOmemoOwnNotifications* self)
{
	GNotification* notification = NULL;
	const gchar* _tmp0_;
	GNotification* _tmp1_;
	DinoEntitiesAccount* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GVariant* _tmp5_;
	GVariant* _tmp6_;
	const gchar* _tmp7_;
	DinoEntitiesAccount* _tmp8_;
	XmppJid* _tmp9_;
	XmppJid* _tmp10_;
	XmppJid* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	DinoPluginsOmemoPlugin* _tmp17_;
	DinoApplication* _tmp18_;
	DinoEntitiesAccount* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	g_return_if_fail (self != NULL);
	_tmp0_ = dino_gettext ("OMEMO trust decision required");
	_tmp1_ = g_notification_new (_tmp0_);
	notification = _tmp1_;
	_tmp2_ = self->priv->account;
	_tmp3_ = dino_entities_account_get_id (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_variant_new_int32 ((gint32) _tmp4_);
	g_variant_ref_sink (_tmp5_);
	_tmp6_ = _tmp5_;
	g_notification_set_default_action_and_target_value (notification, "app.own-keys", _tmp6_);
	_g_variant_unref0 (_tmp6_);
	_tmp7_ = dino_gettext ("Did you add a new device for account %s?");
	_tmp8_ = self->priv->account;
	_tmp9_ = dino_entities_account_get_bare_jid (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp12_ = xmpp_jid_to_string (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = string_to_string (_tmp13_);
	_tmp15_ = g_strdup_printf (_tmp7_, _tmp14_);
	_tmp16_ = _tmp15_;
	g_notification_set_body (notification, _tmp16_);
	_g_free0 (_tmp16_);
	_g_free0 (_tmp13_);
	_xmpp_jid_unref0 (_tmp11_);
	_tmp17_ = self->priv->plugin;
	_tmp18_ = _tmp17_->app;
	_tmp19_ = self->priv->account;
	_tmp20_ = dino_entities_account_get_id (_tmp19_);
	_tmp21_ = _tmp20_;
	_tmp22_ = g_strdup_printf ("%i", _tmp21_);
	_tmp23_ = _tmp22_;
	_tmp24_ = g_strconcat (_tmp23_, "-new-device", NULL);
	_tmp25_ = _tmp24_;
	g_application_send_notification ((GApplication*) _tmp18_, _tmp25_, notification);
	_g_free0 (_tmp25_);
	_g_free0 (_tmp23_);
	_g_object_unref0 (notification);
}

static void
dino_plugins_omemo_value_own_notifications_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dino_plugins_omemo_value_own_notifications_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dino_plugins_omemo_own_notifications_unref (value->data[0].v_pointer);
	}
}

static void
dino_plugins_omemo_value_own_notifications_copy_value (const GValue* src_value,
                                                       GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dino_plugins_omemo_own_notifications_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dino_plugins_omemo_value_own_notifications_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dino_plugins_omemo_value_own_notifications_collect_value (GValue* value,
                                                          guint n_collect_values,
                                                          GTypeCValue* collect_values,
                                                          guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DinoPluginsOmemoOwnNotifications * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dino_plugins_omemo_own_notifications_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dino_plugins_omemo_value_own_notifications_lcopy_value (const GValue* value,
                                                        guint n_collect_values,
                                                        GTypeCValue* collect_values,
                                                        guint collect_flags)
{
	DinoPluginsOmemoOwnNotifications ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dino_plugins_omemo_own_notifications_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dino_plugins_omemo_param_spec_own_notifications (const gchar* name,
                                                 const gchar* nick,
                                                 const gchar* blurb,
                                                 GType object_type,
                                                 GParamFlags flags)
{
	DinoPluginsOmemoParamSpecOwnNotifications* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dino_plugins_omemo_value_get_own_notifications (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS), NULL);
	return value->data[0].v_pointer;
}

void
dino_plugins_omemo_value_set_own_notifications (GValue* value,
                                                gpointer v_object)
{
	DinoPluginsOmemoOwnNotifications * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dino_plugins_omemo_own_notifications_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_plugins_omemo_own_notifications_unref (old);
	}
}

void
dino_plugins_omemo_value_take_own_notifications (GValue* value,
                                                 gpointer v_object)
{
	DinoPluginsOmemoOwnNotifications * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_plugins_omemo_own_notifications_unref (old);
	}
}

static void
dino_plugins_omemo_own_notifications_class_init (DinoPluginsOmemoOwnNotificationsClass * klass,
                                                 gpointer klass_data)
{
	dino_plugins_omemo_own_notifications_parent_class = g_type_class_peek_parent (klass);
	((DinoPluginsOmemoOwnNotificationsClass *) klass)->finalize = dino_plugins_omemo_own_notifications_finalize;
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoOwnNotifications_private_offset);
}

static void
dino_plugins_omemo_own_notifications_instance_init (DinoPluginsOmemoOwnNotifications * self,
                                                    gpointer klass)
{
	self->priv = dino_plugins_omemo_own_notifications_get_instance_private (self);
	self->ref_count = 1;
}

static void
dino_plugins_omemo_own_notifications_finalize (DinoPluginsOmemoOwnNotifications * obj)
{
	DinoPluginsOmemoOwnNotifications * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_OWN_NOTIFICATIONS, DinoPluginsOmemoOwnNotifications);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->stream_interactor);
	_g_object_unref0 (self->priv->plugin);
	_g_object_unref0 (self->priv->account);
}

static GType
dino_plugins_omemo_own_notifications_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_plugins_omemo_value_own_notifications_init, dino_plugins_omemo_value_own_notifications_free_value, dino_plugins_omemo_value_own_notifications_copy_value, dino_plugins_omemo_value_own_notifications_peek_pointer, "p", dino_plugins_omemo_value_own_notifications_collect_value, "p", dino_plugins_omemo_value_own_notifications_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoOwnNotificationsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_own_notifications_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoOwnNotifications), 0, (GInstanceInitFunc) dino_plugins_omemo_own_notifications_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dino_plugins_omemo_own_notifications_type_id;
	dino_plugins_omemo_own_notifications_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoPluginsOmemoOwnNotifications", &g_define_type_info, &g_define_type_fundamental_info, 0);
	DinoPluginsOmemoOwnNotifications_private_offset = g_type_add_instance_private (dino_plugins_omemo_own_notifications_type_id, sizeof (DinoPluginsOmemoOwnNotificationsPrivate));
	return dino_plugins_omemo_own_notifications_type_id;
}

GType
dino_plugins_omemo_own_notifications_get_type (void)
{
	static volatile gsize dino_plugins_omemo_own_notifications_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_own_notifications_type_id__once)) {
		GType dino_plugins_omemo_own_notifications_type_id;
		dino_plugins_omemo_own_notifications_type_id = dino_plugins_omemo_own_notifications_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_own_notifications_type_id__once, dino_plugins_omemo_own_notifications_type_id);
	}
	return dino_plugins_omemo_own_notifications_type_id__once;
}

gpointer
dino_plugins_omemo_own_notifications_ref (gpointer instance)
{
	DinoPluginsOmemoOwnNotifications * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dino_plugins_omemo_own_notifications_unref (gpointer instance)
{
	DinoPluginsOmemoOwnNotifications * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_PLUGINS_OMEMO_OWN_NOTIFICATIONS_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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;
}

