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

#include "openpgp.h"
#include <glib-object.h>
#include "libdino.h"
#include <gee.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "xmpp-vala.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 DINO_PLUGINS_OPEN_PGP_TYPE_ENCRYPTION_LIST_ENTRY (dino_plugins_open_pgp_encryption_list_entry_get_type ())
#define DINO_PLUGINS_OPEN_PGP_ENCRYPTION_LIST_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_PLUGINS_OPEN_PGP_TYPE_ENCRYPTION_LIST_ENTRY, DinoPluginsOpenPgpEncryptionListEntry))
#define DINO_PLUGINS_OPEN_PGP_ENCRYPTION_LIST_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_PLUGINS_OPEN_PGP_TYPE_ENCRYPTION_LIST_ENTRY, DinoPluginsOpenPgpEncryptionListEntryClass))
#define DINO_PLUGINS_OPEN_PGP_IS_ENCRYPTION_LIST_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_PLUGINS_OPEN_PGP_TYPE_ENCRYPTION_LIST_ENTRY))
#define DINO_PLUGINS_OPEN_PGP_IS_ENCRYPTION_LIST_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_PLUGINS_OPEN_PGP_TYPE_ENCRYPTION_LIST_ENTRY))
#define DINO_PLUGINS_OPEN_PGP_ENCRYPTION_LIST_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_PLUGINS_OPEN_PGP_TYPE_ENCRYPTION_LIST_ENTRY, DinoPluginsOpenPgpEncryptionListEntryClass))

typedef struct _DinoPluginsOpenPgpEncryptionListEntry DinoPluginsOpenPgpEncryptionListEntry;
typedef struct _DinoPluginsOpenPgpEncryptionListEntryClass DinoPluginsOpenPgpEncryptionListEntryClass;
enum  {
	DINO_PLUGINS_OPEN_PGP_PLUGIN_0_PROPERTY,
	DINO_PLUGINS_OPEN_PGP_PLUGIN_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_open_pgp_plugin_properties[DINO_PLUGINS_OPEN_PGP_PLUGIN_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _DinoPluginsOpenPgpPluginPrivate {
	DinoPluginsOpenPgpEncryptionListEntry* list_entry;
	DinoPluginsOpenPgpContactDetailsProvider* contact_details_provider;
};

static gint DinoPluginsOpenPgpPlugin_private_offset;
static gpointer dino_plugins_open_pgp_plugin_parent_class = NULL;
static DinoPluginsRootInterfaceIface * dino_plugins_open_pgp_plugin_dino_plugins_root_interface_parent_iface = NULL;

VALA_EXTERN GType dino_plugins_open_pgp_encryption_list_entry_get_type (void) G_GNUC_CONST ;
static guint _dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                           gpointer self);
static gboolean _dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static void dino_plugins_open_pgp_plugin_real_registered (DinoPluginsRootInterface* base,
                                                   DinoApplication* app);
VALA_EXTERN DinoPluginsOpenPgpEncryptionListEntry* dino_plugins_open_pgp_encryption_list_entry_new (DinoStreamInteractor* stream_interactor,
                                                                                        DinoPluginsOpenPgpDatabase* db);
VALA_EXTERN DinoPluginsOpenPgpEncryptionListEntry* dino_plugins_open_pgp_encryption_list_entry_construct (GType object_type,
                                                                                              DinoStreamInteractor* stream_interactor,
                                                                                              DinoPluginsOpenPgpDatabase* db);
static void dino_plugins_open_pgp_plugin_on_initialize_account_modules (DinoPluginsOpenPgpPlugin* self,
                                                                 DinoEntitiesAccount* account,
                                                                 GeeArrayList* modules);
static void _dino_plugins_open_pgp_plugin_on_initialize_account_modules_dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                                                                                 DinoEntitiesAccount* account,
                                                                                                                 GeeArrayList* modules,
                                                                                                                 gpointer self);
static void dino_plugins_open_pgp_plugin_real_shutdown (DinoPluginsRootInterface* base);
static void dino_plugins_open_pgp_plugin_finalize (GObject * obj);
static GType dino_plugins_open_pgp_plugin_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_plugins_open_pgp_plugin_get_instance_private (DinoPluginsOpenPgpPlugin* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOpenPgpPlugin_private_offset);
}

static guint
_dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                     gpointer self)
{
	guint result;
	result = dino_entities_account_hash_func ((DinoEntitiesAccount*) v);
	return result;
}

static gboolean
_dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                        gconstpointer b,
                                                        gpointer self)
{
	gboolean result;
	result = dino_entities_account_equals_func ((DinoEntitiesAccount*) a, (DinoEntitiesAccount*) b);
	return result;
}

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

static void
_dino_plugins_open_pgp_plugin_on_initialize_account_modules_dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                                                                            DinoEntitiesAccount* account,
                                                                                                            GeeArrayList* modules,
                                                                                                            gpointer self)
{
	dino_plugins_open_pgp_plugin_on_initialize_account_modules ((DinoPluginsOpenPgpPlugin*) self, account, modules);
}

static void
dino_plugins_open_pgp_plugin_real_registered (DinoPluginsRootInterface* base,
                                              DinoApplication* app)
{
	DinoPluginsOpenPgpPlugin * self;
	DinoApplication* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	DinoPluginsOpenPgpDatabase* _tmp5_;
	DinoStreamInteractor* _tmp6_;
	DinoStreamInteractor* _tmp7_;
	DinoPluginsOpenPgpDatabase* _tmp8_;
	DinoPluginsOpenPgpEncryptionListEntry* _tmp9_;
	DinoStreamInteractor* _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoPluginsOpenPgpContactDetailsProvider* _tmp12_;
	DinoPluginsRegistry* _tmp13_;
	DinoPluginsRegistry* _tmp14_;
	DinoPluginsOpenPgpEncryptionListEntry* _tmp15_;
	DinoPluginsRegistry* _tmp16_;
	DinoPluginsRegistry* _tmp17_;
	DinoPluginsOpenPgpPgpPreferencesEntry* _tmp18_;
	DinoPluginsOpenPgpPgpPreferencesEntry* _tmp19_;
	DinoPluginsRegistry* _tmp20_;
	DinoPluginsRegistry* _tmp21_;
	DinoPluginsOpenPgpContactDetailsProvider* _tmp22_;
	DinoStreamInteractor* _tmp23_;
	DinoStreamInteractor* _tmp24_;
	DinoModuleManager* _tmp25_;
	DinoStreamInteractor* _tmp26_;
	DinoStreamInteractor* _tmp27_;
	DinoPluginsOpenPgpDatabase* _tmp28_;
	DinoStreamInteractor* _tmp29_;
	DinoStreamInteractor* _tmp30_;
	DinoModuleIdentity* _tmp31_;
	gpointer _tmp32_;
	DinoFileManager* _tmp33_;
	DinoStreamInteractor* _tmp34_;
	DinoStreamInteractor* _tmp35_;
	DinoPluginsOpenPgpPgpFileEncryptor* _tmp36_;
	DinoPluginsOpenPgpPgpFileEncryptor* _tmp37_;
	DinoStreamInteractor* _tmp38_;
	DinoStreamInteractor* _tmp39_;
	DinoModuleIdentity* _tmp40_;
	gpointer _tmp41_;
	DinoFileManager* _tmp42_;
	DinoPluginsOpenPgpPgpFileDecryptor* _tmp43_;
	DinoPluginsOpenPgpPgpFileDecryptor* _tmp44_;
	DinoJingleFileHelperRegistry* _tmp45_;
	DinoJingleFileHelperRegistry* _tmp46_;
	DinoJingleFileEncryptionHelperTransferOnly* _tmp47_;
	DinoJingleFileEncryptionHelperTransferOnly* _tmp48_;
	DinoSearchPathGenerator* _tmp49_;
	DinoSearchPathGenerator* _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	self = (DinoPluginsOpenPgpPlugin*) base;
	g_return_if_fail (app != NULL);
	_tmp0_ = _g_object_ref0 (app);
	_g_object_unref0 (self->app);
	self->app = _tmp0_;
	_tmp1_ = dino_application_get_storage_dir ();
	_tmp2_ = _tmp1_;
	_tmp3_ = g_build_filename (_tmp2_, "pgp.db", NULL);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_plugins_open_pgp_database_new (_tmp4_);
	_qlite_database_unref0 (self->db);
	self->db = _tmp5_;
	_g_free0 (_tmp4_);
	_g_free0 (_tmp2_);
	_tmp6_ = dino_application_get_stream_interactor (app);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->db;
	_tmp9_ = dino_plugins_open_pgp_encryption_list_entry_new (_tmp7_, _tmp8_);
	_g_object_unref0 (self->priv->list_entry);
	self->priv->list_entry = _tmp9_;
	_tmp10_ = dino_application_get_stream_interactor (app);
	_tmp11_ = _tmp10_;
	_tmp12_ = dino_plugins_open_pgp_contact_details_provider_new (_tmp11_);
	_g_object_unref0 (self->priv->contact_details_provider);
	self->priv->contact_details_provider = _tmp12_;
	_tmp13_ = dino_application_get_plugin_registry (app);
	_tmp14_ = _tmp13_;
	_tmp15_ = self->priv->list_entry;
	dino_plugins_registry_register_encryption_list_entry (_tmp14_, (DinoPluginsEncryptionListEntry*) _tmp15_);
	_tmp16_ = dino_application_get_plugin_registry (app);
	_tmp17_ = _tmp16_;
	_tmp18_ = dino_plugins_open_pgp_pgp_preferences_entry_new (self);
	_tmp19_ = _tmp18_;
	dino_plugins_registry_register_encryption_preferences_entry (_tmp17_, (DinoPluginsEncryptionPreferencesEntry*) _tmp19_);
	_g_object_unref0 (_tmp19_);
	_tmp20_ = dino_application_get_plugin_registry (app);
	_tmp21_ = _tmp20_;
	_tmp22_ = self->priv->contact_details_provider;
	dino_plugins_registry_register_contact_details_entry (_tmp21_, (DinoPluginsContactDetailsProvider*) _tmp22_);
	_tmp23_ = dino_application_get_stream_interactor (app);
	_tmp24_ = _tmp23_;
	_tmp25_ = _tmp24_->module_manager;
	g_signal_connect_object (_tmp25_, "initialize-account-modules", (GCallback) _dino_plugins_open_pgp_plugin_on_initialize_account_modules_dino_module_manager_initialize_account_modules, self, 0);
	_tmp26_ = dino_application_get_stream_interactor (app);
	_tmp27_ = _tmp26_;
	_tmp28_ = self->db;
	dino_plugins_open_pgp_manager_start (_tmp27_, _tmp28_);
	_tmp29_ = dino_application_get_stream_interactor (app);
	_tmp30_ = _tmp29_;
	_tmp31_ = dino_file_manager_IDENTITY;
	_tmp32_ = dino_stream_interactor_get_module (_tmp30_, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp31_);
	_tmp33_ = (DinoFileManager*) _tmp32_;
	_tmp34_ = dino_application_get_stream_interactor (app);
	_tmp35_ = _tmp34_;
	_tmp36_ = dino_plugins_open_pgp_pgp_file_encryptor_new (_tmp35_);
	_tmp37_ = _tmp36_;
	dino_file_manager_add_file_encryptor (_tmp33_, (DinoFileEncryptor*) _tmp37_);
	_g_object_unref0 (_tmp37_);
	_g_object_unref0 (_tmp33_);
	_tmp38_ = dino_application_get_stream_interactor (app);
	_tmp39_ = _tmp38_;
	_tmp40_ = dino_file_manager_IDENTITY;
	_tmp41_ = dino_stream_interactor_get_module (_tmp39_, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp40_);
	_tmp42_ = (DinoFileManager*) _tmp41_;
	_tmp43_ = dino_plugins_open_pgp_pgp_file_decryptor_new ();
	_tmp44_ = _tmp43_;
	dino_file_manager_add_file_decryptor (_tmp42_, (DinoFileDecryptor*) _tmp44_);
	_g_object_unref0 (_tmp44_);
	_g_object_unref0 (_tmp42_);
	_tmp45_ = dino_jingle_file_helper_registry_get_instance ();
	_tmp46_ = _tmp45_;
	_tmp47_ = dino_jingle_file_encryption_helper_transfer_only_new ();
	_tmp48_ = _tmp47_;
	dino_jingle_file_helper_registry_add_encryption_helper (_tmp46_, DINO_ENTITIES_ENCRYPTION_PGP, (DinoJingleFileEncryptionHelper*) _tmp48_);
	_g_object_unref0 (_tmp48_);
	_tmp49_ = dino_application_get_search_path_generator (app);
	_tmp50_ = _tmp49_;
	_tmp51_ = dino_search_path_generator_get_locale_path (_tmp50_, GETTEXT_PACKAGE, LOCALE_INSTALL_DIR);
	_tmp52_ = _tmp51_;
	dino_internationalize (GETTEXT_PACKAGE, _tmp52_);
	_g_free0 (_tmp52_);
}

static void
dino_plugins_open_pgp_plugin_real_shutdown (DinoPluginsRootInterface* base)
{
	DinoPluginsOpenPgpPlugin * self;
	self = (DinoPluginsOpenPgpPlugin*) base;
}

static void
dino_plugins_open_pgp_plugin_on_initialize_account_modules (DinoPluginsOpenPgpPlugin* self,
                                                            DinoEntitiesAccount* account,
                                                            GeeArrayList* modules)
{
	DinoPluginsOpenPgpModule* module = NULL;
	DinoPluginsOpenPgpDatabase* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	DinoPluginsOpenPgpModule* _tmp3_;
	DinoPluginsOpenPgpModule* _tmp4_;
	GeeHashMap* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (modules != NULL);
	_tmp0_ = self->db;
	_tmp1_ = dino_plugins_open_pgp_database_get_account_key (_tmp0_, account);
	_tmp2_ = _tmp1_;
	_tmp3_ = dino_plugins_open_pgp_module_new (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	module = _tmp4_;
	_tmp5_ = self->modules;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp5_, account, module);
	gee_abstract_collection_add ((GeeAbstractCollection*) modules, (XmppXmppStreamModule*) module);
	_g_object_unref0 (module);
}

DinoPluginsOpenPgpPlugin*
dino_plugins_open_pgp_plugin_construct (GType object_type)
{
	DinoPluginsOpenPgpPlugin * self = NULL;
	self = (DinoPluginsOpenPgpPlugin*) g_object_new (object_type, NULL);
	return self;
}

DinoPluginsOpenPgpPlugin*
dino_plugins_open_pgp_plugin_new (void)
{
	return dino_plugins_open_pgp_plugin_construct (DINO_PLUGINS_OPEN_PGP_TYPE_PLUGIN);
}

static void
dino_plugins_open_pgp_plugin_class_init (DinoPluginsOpenPgpPluginClass * klass,
                                         gpointer klass_data)
{
	dino_plugins_open_pgp_plugin_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOpenPgpPlugin_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_open_pgp_plugin_finalize;
}

static void
dino_plugins_open_pgp_plugin_dino_plugins_root_interface_interface_init (DinoPluginsRootInterfaceIface * iface,
                                                                         gpointer iface_data)
{
	dino_plugins_open_pgp_plugin_dino_plugins_root_interface_parent_iface = g_type_interface_peek_parent (iface);
	iface->registered = (void (*) (DinoPluginsRootInterface*, DinoApplication*)) dino_plugins_open_pgp_plugin_real_registered;
	iface->shutdown = (void (*) (DinoPluginsRootInterface*)) dino_plugins_open_pgp_plugin_real_shutdown;
}

static void
dino_plugins_open_pgp_plugin_instance_init (DinoPluginsOpenPgpPlugin * self,
                                            gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_plugins_open_pgp_plugin_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, DINO_PLUGINS_OPEN_PGP_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->modules = _tmp0_;
}

static void
dino_plugins_open_pgp_plugin_finalize (GObject * obj)
{
	DinoPluginsOpenPgpPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OPEN_PGP_TYPE_PLUGIN, DinoPluginsOpenPgpPlugin);
	_g_object_unref0 (self->app);
	_qlite_database_unref0 (self->db);
	_g_object_unref0 (self->modules);
	_g_object_unref0 (self->priv->list_entry);
	_g_object_unref0 (self->priv->contact_details_provider);
	G_OBJECT_CLASS (dino_plugins_open_pgp_plugin_parent_class)->finalize (obj);
}

static GType
dino_plugins_open_pgp_plugin_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOpenPgpPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_open_pgp_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOpenPgpPlugin), 0, (GInstanceInitFunc) dino_plugins_open_pgp_plugin_instance_init, NULL };
	static const GInterfaceInfo dino_plugins_root_interface_info = { (GInterfaceInitFunc) dino_plugins_open_pgp_plugin_dino_plugins_root_interface_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_open_pgp_plugin_type_id;
	dino_plugins_open_pgp_plugin_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOpenPgpPlugin", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_open_pgp_plugin_type_id, DINO_PLUGINS_TYPE_ROOT_INTERFACE, &dino_plugins_root_interface_info);
	DinoPluginsOpenPgpPlugin_private_offset = g_type_add_instance_private (dino_plugins_open_pgp_plugin_type_id, sizeof (DinoPluginsOpenPgpPluginPrivate));
	return dino_plugins_open_pgp_plugin_type_id;
}

GType
dino_plugins_open_pgp_plugin_get_type (void)
{
	static volatile gsize dino_plugins_open_pgp_plugin_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_open_pgp_plugin_type_id__once)) {
		GType dino_plugins_open_pgp_plugin_type_id;
		dino_plugins_open_pgp_plugin_type_id = dino_plugins_open_pgp_plugin_get_type_once ();
		g_once_init_leave (&dino_plugins_open_pgp_plugin_type_id__once, dino_plugins_open_pgp_plugin_type_id);
	}
	return dino_plugins_open_pgp_plugin_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;
}

