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

#include "libdino.h"
#include <gio/gio.h>
#include <glib.h>
#include "xmpp-vala.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <float.h>
#include <math.h>

#define DINO_IMAGE_FILE_METADATA_PROVIDER_IMAGE_TYPE "png"
#define DINO_IMAGE_FILE_METADATA_PROVIDER_MIME_TYPE "image/png"
#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_TYPE_GENERIC_FILE_METADATA_PROVIDER (dino_generic_file_metadata_provider_get_type ())
#define DINO_GENERIC_FILE_METADATA_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_TYPE_GENERIC_FILE_METADATA_PROVIDER, DinoGenericFileMetadataProvider))
#define DINO_GENERIC_FILE_METADATA_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_TYPE_GENERIC_FILE_METADATA_PROVIDER, DinoGenericFileMetadataProviderClass))
#define DINO_IS_GENERIC_FILE_METADATA_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_TYPE_GENERIC_FILE_METADATA_PROVIDER))
#define DINO_IS_GENERIC_FILE_METADATA_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_TYPE_GENERIC_FILE_METADATA_PROVIDER))
#define DINO_GENERIC_FILE_METADATA_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_TYPE_GENERIC_FILE_METADATA_PROVIDER, DinoGenericFileMetadataProviderClass))

typedef struct _DinoGenericFileMetadataProvider DinoGenericFileMetadataProvider;
typedef struct _DinoGenericFileMetadataProviderClass DinoGenericFileMetadataProviderClass;
typedef struct _DinoGenericFileMetadataProviderPrivate DinoGenericFileMetadataProviderPrivate;
enum  {
	DINO_GENERIC_FILE_METADATA_PROVIDER_0_PROPERTY,
	DINO_GENERIC_FILE_METADATA_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* dino_generic_file_metadata_provider_properties[DINO_GENERIC_FILE_METADATA_PROVIDER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_xep_file_metadata_element_file_metadata_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_file_metadata_element_file_metadata_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DinoGenericFileMetadataProviderFillMetadataData DinoGenericFileMetadataProviderFillMetadataData;
enum  {
	DINO_IMAGE_FILE_METADATA_PROVIDER_0_PROPERTY,
	DINO_IMAGE_FILE_METADATA_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* dino_image_file_metadata_provider_properties[DINO_IMAGE_FILE_METADATA_PROVIDER_NUM_PROPERTIES];
#define _xmpp_xep_jingle_content_thumbnails_thumbnail_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_jingle_content_thumbnails_thumbnail_unref (var), NULL)))
typedef struct _DinoImageFileMetadataProviderFillMetadataData DinoImageFileMetadataProviderFillMetadataData;

struct _DinoGenericFileMetadataProvider {
	GObject parent_instance;
	DinoGenericFileMetadataProviderPrivate * priv;
};

struct _DinoGenericFileMetadataProviderClass {
	GObjectClass parent_class;
};

struct _DinoGenericFileMetadataProviderFillMetadataData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoGenericFileMetadataProvider* self;
	GFile* file;
	XmppXepFileMetadataElementFileMetadata* metadata;
	GFileInfo* info;
	GFileInfo* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GeeArrayList* checksum_types;
	GChecksumType* _tmp5_;
	GeeArrayList* _tmp6_;
	GeeHashMap* file_hashes;
	GeeArrayList* _tmp7_;
	GeeHashMap* _tmp8_;
	GeeList* _tmp9_;
	GeeHashMap* _tmp10_;
	gpointer _tmp11_;
	gchar* _tmp12_;
	XmppXepCryptographicHashesHash* _tmp13_;
	XmppXepCryptographicHashesHash* _tmp14_;
	GeeList* _tmp15_;
	GeeHashMap* _tmp16_;
	gpointer _tmp17_;
	gchar* _tmp18_;
	XmppXepCryptographicHashesHash* _tmp19_;
	XmppXepCryptographicHashesHash* _tmp20_;
	GError* _inner_error0_;
};

struct _DinoImageFileMetadataProviderFillMetadataData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoImageFileMetadataProvider* self;
	GFile* file;
	XmppXepFileMetadataElementFileMetadata* metadata;
	GFileInputStream* _tmp0_;
	GFileInputStream* _tmp1_;
	GdkPixbuf* pixbuf;
	GdkPixbuf* _tmp2_;
	GdkPixbuf* _tmp3_;
	GdkPixbuf* _tmp4_;
	gfloat ratio;
	gint _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gint thumbnail_width;
	gint thumbnail_height;
	gfloat diff;
	gint i;
	gboolean _tmp9_;
	gint _tmp10_;
	gint test_width;
	gint _tmp11_;
	gint test_height;
	gint _tmp12_;
	gfloat test_ratio;
	gfloat test_diff;
	GdkPixbuf* thumbnail_pixbuf;
	GdkPixbuf* _tmp13_;
	GdkPixbuf* _tmp14_;
	guint8* buffer;
	gint buffer_length1;
	gint _buffer_size_;
	GdkPixbuf* _tmp15_;
	guint8* _tmp16_;
	gsize _tmp17_;
	gchar* base_64;
	guint8* _tmp18_;
	gint _tmp18__length1;
	gchar* _tmp19_;
	gchar* uri;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	XmppXepJingleContentThumbnailsThumbnail* thumbnail;
	XmppXepJingleContentThumbnailsThumbnail* _tmp24_;
	XmppXepJingleContentThumbnailsThumbnail* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	XmppXepJingleContentThumbnailsThumbnail* _tmp28_;
	gchar* _tmp29_;
	XmppXepJingleContentThumbnailsThumbnail* _tmp30_;
	XmppXepJingleContentThumbnailsThumbnail* _tmp31_;
	GeeList* _tmp32_;
	XmppXepJingleContentThumbnailsThumbnail* _tmp33_;
	GError* _inner_error0_;
};

static gpointer dino_generic_file_metadata_provider_parent_class = NULL;
static DinoFileMetadataProviderIface * dino_generic_file_metadata_provider_dino_file_metadata_provider_parent_iface = NULL;
static gpointer dino_image_file_metadata_provider_parent_class = NULL;
static DinoFileMetadataProviderIface * dino_image_file_metadata_provider_dino_file_metadata_provider_parent_iface = NULL;

static GType dino_file_metadata_provider_get_type_once (void);
VALA_EXTERN GType dino_generic_file_metadata_provider_get_type (void) G_GNUC_CONST ;
static gboolean dino_generic_file_metadata_provider_real_supports_file (DinoFileMetadataProvider* base,
                                                                 GFile* file);
static void dino_generic_file_metadata_provider_real_fill_metadata_data_free (gpointer _data);
static void dino_generic_file_metadata_provider_real_fill_metadata (DinoFileMetadataProvider* base,
                                                             GFile* file,
                                                             XmppXepFileMetadataElementFileMetadata* metadata,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_);
static gboolean dino_generic_file_metadata_provider_real_fill_metadata_co (DinoGenericFileMetadataProviderFillMetadataData* _data_);
static void dino_generic_file_metadata_provider_fill_metadata_ready (GObject* source_object,
                                                              GAsyncResult* _res_,
                                                              gpointer _user_data_);
VALA_EXTERN DinoGenericFileMetadataProvider* dino_generic_file_metadata_provider_new (void);
VALA_EXTERN DinoGenericFileMetadataProvider* dino_generic_file_metadata_provider_construct (GType object_type);
static GType dino_generic_file_metadata_provider_get_type_once (void);
static gboolean dino_image_file_metadata_provider_real_supports_file (DinoFileMetadataProvider* base,
                                                               GFile* file);
static void dino_image_file_metadata_provider_real_fill_metadata_data_free (gpointer _data);
static void dino_image_file_metadata_provider_real_fill_metadata (DinoFileMetadataProvider* base,
                                                           GFile* file,
                                                           XmppXepFileMetadataElementFileMetadata* metadata,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_);
static gboolean dino_image_file_metadata_provider_real_fill_metadata_co (DinoImageFileMetadataProviderFillMetadataData* _data_);
static void dino_image_file_metadata_provider_fill_metadata_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
static GType dino_image_file_metadata_provider_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const gint DINO_IMAGE_FILE_METADATA_PROVIDER_THUMBNAIL_DIMS[5] = {1, 2, 3, 4, 8};

gboolean
dino_file_metadata_provider_supports_file (DinoFileMetadataProvider* self,
                                           GFile* file)
{
	DinoFileMetadataProviderIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = DINO_FILE_METADATA_PROVIDER_GET_INTERFACE (self);
	if (_iface_->supports_file) {
		return _iface_->supports_file (self, file);
	}
	return FALSE;
}

void
dino_file_metadata_provider_fill_metadata (DinoFileMetadataProvider* self,
                                           GFile* file,
                                           XmppXepFileMetadataElementFileMetadata* metadata,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	DinoFileMetadataProviderIface* _iface_;
	_iface_ = DINO_FILE_METADATA_PROVIDER_GET_INTERFACE (self);
	if (_iface_->fill_metadata) {
		_iface_->fill_metadata (self, file, metadata, _callback_, _user_data_);
	}
}

void
dino_file_metadata_provider_fill_metadata_finish (DinoFileMetadataProvider* self,
                                                  GAsyncResult* _res_)
{
	DinoFileMetadataProviderIface* _iface_;
	_iface_ = DINO_FILE_METADATA_PROVIDER_GET_INTERFACE (self);
	if (_iface_->fill_metadata_finish) {
		_iface_->fill_metadata_finish (self, _res_);
	}
}

static void
dino_file_metadata_provider_default_init (DinoFileMetadataProviderIface * iface,
                                          gpointer iface_data)
{
}

static GType
dino_file_metadata_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoFileMetadataProviderIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_file_metadata_provider_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType dino_file_metadata_provider_type_id;
	dino_file_metadata_provider_type_id = g_type_register_static (G_TYPE_INTERFACE, "DinoFileMetadataProvider", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (dino_file_metadata_provider_type_id, G_TYPE_OBJECT);
	return dino_file_metadata_provider_type_id;
}

GType
dino_file_metadata_provider_get_type (void)
{
	static volatile gsize dino_file_metadata_provider_type_id__once = 0;
	if (g_once_init_enter (&dino_file_metadata_provider_type_id__once)) {
		GType dino_file_metadata_provider_type_id;
		dino_file_metadata_provider_type_id = dino_file_metadata_provider_get_type_once ();
		g_once_init_leave (&dino_file_metadata_provider_type_id__once, dino_file_metadata_provider_type_id);
	}
	return dino_file_metadata_provider_type_id__once;
}

static gboolean
dino_generic_file_metadata_provider_real_supports_file (DinoFileMetadataProvider* base,
                                                        GFile* file)
{
	DinoGenericFileMetadataProvider * self;
	gboolean result;
	self = (DinoGenericFileMetadataProvider*) base;
	g_return_val_if_fail (file != NULL, FALSE);
	result = TRUE;
	return result;
}

static void
dino_generic_file_metadata_provider_real_fill_metadata_data_free (gpointer _data)
{
	DinoGenericFileMetadataProviderFillMetadataData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->file);
	_xmpp_xep_file_metadata_element_file_metadata_unref0 (_data_->metadata);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoGenericFileMetadataProviderFillMetadataData, _data_);
}

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

static gpointer
_xmpp_xep_file_metadata_element_file_metadata_ref0 (gpointer self)
{
	return self ? xmpp_xep_file_metadata_element_file_metadata_ref (self) : NULL;
}

static void
dino_generic_file_metadata_provider_real_fill_metadata (DinoFileMetadataProvider* base,
                                                        GFile* file,
                                                        XmppXepFileMetadataElementFileMetadata* metadata,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_)
{
	DinoGenericFileMetadataProvider * self;
	DinoGenericFileMetadataProviderFillMetadataData* _data_;
	DinoGenericFileMetadataProvider* _tmp0_;
	GFile* _tmp1_;
	XmppXepFileMetadataElementFileMetadata* _tmp2_;
	g_return_if_fail (file != NULL);
	g_return_if_fail (metadata != NULL);
	self = (DinoGenericFileMetadataProvider*) base;
	_data_ = g_slice_new0 (DinoGenericFileMetadataProviderFillMetadataData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_generic_file_metadata_provider_real_fill_metadata_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (file);
	_g_object_unref0 (_data_->file);
	_data_->file = _tmp1_;
	_tmp2_ = _xmpp_xep_file_metadata_element_file_metadata_ref0 (metadata);
	_xmpp_xep_file_metadata_element_file_metadata_unref0 (_data_->metadata);
	_data_->metadata = _tmp2_;
	dino_generic_file_metadata_provider_real_fill_metadata_co (_data_);
}

static void
dino_generic_file_metadata_provider_fill_metadata_finish (DinoFileMetadataProvider* base,
                                                          GAsyncResult* _res_)
{
	DinoGenericFileMetadataProviderFillMetadataData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dino_generic_file_metadata_provider_fill_metadata_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_)
{
	DinoGenericFileMetadataProviderFillMetadataData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_generic_file_metadata_provider_real_fill_metadata_co (_data_);
}

static gboolean
dino_generic_file_metadata_provider_real_fill_metadata_co (DinoGenericFileMetadataProviderFillMetadataData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_file_query_info (_data_->file, "*", G_FILE_QUERY_INFO_NONE, NULL, &_data_->_inner_error0_);
	_data_->info = _data_->_tmp0_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = g_file_info_get_display_name (_data_->info);
	xmpp_xep_file_metadata_element_file_metadata_set_name (_data_->metadata, _data_->_tmp1_);
	_data_->_tmp2_ = g_file_info_get_content_type (_data_->info);
	xmpp_xep_file_metadata_element_file_metadata_set_mime_type (_data_->metadata, _data_->_tmp2_);
	xmpp_xep_file_metadata_element_file_metadata_set_size (_data_->metadata, g_file_info_get_size (_data_->info));
	_data_->_tmp3_ = g_file_info_get_modification_date_time (_data_->info);
	_data_->_tmp4_ = _data_->_tmp3_;
	xmpp_xep_file_metadata_element_file_metadata_set_date (_data_->metadata, _data_->_tmp4_);
	_g_date_time_unref0 (_data_->_tmp4_);
	_data_->_tmp5_ = g_new0 (GChecksumType, 2);
	_data_->_tmp5_[0] = G_CHECKSUM_SHA256;
	_data_->_tmp5_[1] = G_CHECKSUM_SHA512;
	_data_->_tmp6_ = gee_array_list_new_wrap (G_TYPE_INT, NULL, NULL, _data_->_tmp5_, 2, NULL, NULL, NULL);
	_data_->checksum_types = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->checksum_types;
	_data_->_state_ = 1;
	dino_compute_file_hashes (_data_->file, (GeeList*) _data_->_tmp7_, dino_generic_file_metadata_provider_fill_metadata_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp8_ = dino_compute_file_hashes_finish (_data_->_res_);
	_data_->file_hashes = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->metadata->hashes;
	_data_->_tmp10_ = _data_->file_hashes;
	_data_->_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp10_, (gpointer) ((gintptr) G_CHECKSUM_SHA256));
	_data_->_tmp12_ = (gchar*) _data_->_tmp11_;
	_data_->_tmp13_ = xmpp_xep_cryptographic_hashes_hash_new_with_checksum (G_CHECKSUM_SHA256, _data_->_tmp12_);
	_data_->_tmp14_ = _data_->_tmp13_;
	gee_collection_add ((GeeCollection*) _data_->_tmp9_, _data_->_tmp14_);
	_g_object_unref0 (_data_->_tmp14_);
	_g_free0 (_data_->_tmp12_);
	_data_->_tmp15_ = _data_->metadata->hashes;
	_data_->_tmp16_ = _data_->file_hashes;
	_data_->_tmp17_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp16_, (gpointer) ((gintptr) G_CHECKSUM_SHA512));
	_data_->_tmp18_ = (gchar*) _data_->_tmp17_;
	_data_->_tmp19_ = xmpp_xep_cryptographic_hashes_hash_new_with_checksum (G_CHECKSUM_SHA512, _data_->_tmp18_);
	_data_->_tmp20_ = _data_->_tmp19_;
	gee_collection_add ((GeeCollection*) _data_->_tmp15_, _data_->_tmp20_);
	_g_object_unref0 (_data_->_tmp20_);
	_g_free0 (_data_->_tmp18_);
	_g_object_unref0 (_data_->file_hashes);
	_g_object_unref0 (_data_->checksum_types);
	_g_object_unref0 (_data_->info);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

DinoGenericFileMetadataProvider*
dino_generic_file_metadata_provider_construct (GType object_type)
{
	DinoGenericFileMetadataProvider * self = NULL;
	self = (DinoGenericFileMetadataProvider*) g_object_new (object_type, NULL);
	return self;
}

DinoGenericFileMetadataProvider*
dino_generic_file_metadata_provider_new (void)
{
	return dino_generic_file_metadata_provider_construct (DINO_TYPE_GENERIC_FILE_METADATA_PROVIDER);
}

static void
dino_generic_file_metadata_provider_class_init (DinoGenericFileMetadataProviderClass * klass,
                                                gpointer klass_data)
{
	dino_generic_file_metadata_provider_parent_class = g_type_class_peek_parent (klass);
}

static void
dino_generic_file_metadata_provider_dino_file_metadata_provider_interface_init (DinoFileMetadataProviderIface * iface,
                                                                                gpointer iface_data)
{
	dino_generic_file_metadata_provider_dino_file_metadata_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->supports_file = (gboolean (*) (DinoFileMetadataProvider*, GFile*)) dino_generic_file_metadata_provider_real_supports_file;
	iface->fill_metadata = (void (*) (DinoFileMetadataProvider*, GFile*, XmppXepFileMetadataElementFileMetadata*, GAsyncReadyCallback, gpointer)) dino_generic_file_metadata_provider_real_fill_metadata;
	iface->fill_metadata_finish = (void (*) (DinoFileMetadataProvider*, GAsyncResult*)) dino_generic_file_metadata_provider_fill_metadata_finish;
}

static void
dino_generic_file_metadata_provider_instance_init (DinoGenericFileMetadataProvider * self,
                                                   gpointer klass)
{
}

static GType
dino_generic_file_metadata_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoGenericFileMetadataProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_generic_file_metadata_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoGenericFileMetadataProvider), 0, (GInstanceInitFunc) dino_generic_file_metadata_provider_instance_init, NULL };
	static const GInterfaceInfo dino_file_metadata_provider_info = { (GInterfaceInitFunc) dino_generic_file_metadata_provider_dino_file_metadata_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_generic_file_metadata_provider_type_id;
	dino_generic_file_metadata_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoGenericFileMetadataProvider", &g_define_type_info, 0);
	g_type_add_interface_static (dino_generic_file_metadata_provider_type_id, DINO_TYPE_FILE_METADATA_PROVIDER, &dino_file_metadata_provider_info);
	return dino_generic_file_metadata_provider_type_id;
}

GType
dino_generic_file_metadata_provider_get_type (void)
{
	static volatile gsize dino_generic_file_metadata_provider_type_id__once = 0;
	if (g_once_init_enter (&dino_generic_file_metadata_provider_type_id__once)) {
		GType dino_generic_file_metadata_provider_type_id;
		dino_generic_file_metadata_provider_type_id = dino_generic_file_metadata_provider_get_type_once ();
		g_once_init_leave (&dino_generic_file_metadata_provider_type_id__once, dino_generic_file_metadata_provider_type_id);
	}
	return dino_generic_file_metadata_provider_type_id__once;
}

static gboolean
dino_image_file_metadata_provider_real_supports_file (DinoFileMetadataProvider* base,
                                                      GFile* file)
{
	DinoImageFileMetadataProvider * self;
	GFileInfo* _tmp0_ = NULL;
	GFileInfo* _tmp1_;
	gchar* mime_type = NULL;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (DinoImageFileMetadataProvider*) base;
	g_return_val_if_fail (file != NULL, FALSE);
	_tmp1_ = g_file_query_info (file, "*", G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
	_tmp0_ = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp2_ = FALSE;
		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 _tmp2_;
	}
	_tmp3_ = g_file_info_get_content_type (_tmp0_);
	_tmp4_ = g_strdup (_tmp3_);
	mime_type = _tmp4_;
	_tmp5_ = mime_type;
	result = dino_util_is_pixbuf_supported_mime_type (_tmp5_);
	_g_free0 (mime_type);
	_g_object_unref0 (_tmp0_);
	return result;
}

static void
dino_image_file_metadata_provider_real_fill_metadata_data_free (gpointer _data)
{
	DinoImageFileMetadataProviderFillMetadataData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->file);
	_xmpp_xep_file_metadata_element_file_metadata_unref0 (_data_->metadata);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoImageFileMetadataProviderFillMetadataData, _data_);
}

static void
dino_image_file_metadata_provider_real_fill_metadata (DinoFileMetadataProvider* base,
                                                      GFile* file,
                                                      XmppXepFileMetadataElementFileMetadata* metadata,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_)
{
	DinoImageFileMetadataProvider * self;
	DinoImageFileMetadataProviderFillMetadataData* _data_;
	DinoImageFileMetadataProvider* _tmp0_;
	GFile* _tmp1_;
	XmppXepFileMetadataElementFileMetadata* _tmp2_;
	g_return_if_fail (file != NULL);
	g_return_if_fail (metadata != NULL);
	self = (DinoImageFileMetadataProvider*) base;
	_data_ = g_slice_new0 (DinoImageFileMetadataProviderFillMetadataData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_image_file_metadata_provider_real_fill_metadata_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (file);
	_g_object_unref0 (_data_->file);
	_data_->file = _tmp1_;
	_tmp2_ = _xmpp_xep_file_metadata_element_file_metadata_ref0 (metadata);
	_xmpp_xep_file_metadata_element_file_metadata_unref0 (_data_->metadata);
	_data_->metadata = _tmp2_;
	dino_image_file_metadata_provider_real_fill_metadata_co (_data_);
}

static void
dino_image_file_metadata_provider_fill_metadata_finish (DinoFileMetadataProvider* base,
                                                        GAsyncResult* _res_)
{
	DinoImageFileMetadataProviderFillMetadataData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dino_image_file_metadata_provider_fill_metadata_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	DinoImageFileMetadataProviderFillMetadataData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_image_file_metadata_provider_real_fill_metadata_co (_data_);
}

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 gboolean
dino_image_file_metadata_provider_real_fill_metadata_co (DinoImageFileMetadataProviderFillMetadataData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	g_file_read_async (_data_->file, G_PRIORITY_DEFAULT, NULL, dino_image_file_metadata_provider_fill_metadata_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = g_file_read_finish (_data_->file, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = gdk_pixbuf_new_from_stream ((GInputStream*) _data_->_tmp0_, NULL, &_data_->_inner_error0_);
	_data_->pixbuf = _data_->_tmp2_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->_tmp0_);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp3_ = _data_->pixbuf;
	xmpp_xep_file_metadata_element_file_metadata_set_width (_data_->metadata, gdk_pixbuf_get_width (_data_->_tmp3_));
	_data_->_tmp4_ = _data_->pixbuf;
	xmpp_xep_file_metadata_element_file_metadata_set_height (_data_->metadata, gdk_pixbuf_get_height (_data_->_tmp4_));
	_data_->_tmp5_ = xmpp_xep_file_metadata_element_file_metadata_get_width (_data_->metadata);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = xmpp_xep_file_metadata_element_file_metadata_get_height (_data_->metadata);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->ratio = ((gfloat) _data_->_tmp6_) / ((gfloat) _data_->_tmp8_);
	_data_->thumbnail_width = -1;
	_data_->thumbnail_height = -1;
	_data_->diff = INFINITY;
	{
		_data_->i = 0;
		{
			_data_->_tmp9_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp9_) {
					_data_->_tmp10_ = _data_->i;
					_data_->i = _data_->_tmp10_ + 1;
				}
				_data_->_tmp9_ = FALSE;
				if (!(_data_->i < G_N_ELEMENTS (DINO_IMAGE_FILE_METADATA_PROVIDER_THUMBNAIL_DIMS))) {
					break;
				}
				_data_->_tmp11_ = DINO_IMAGE_FILE_METADATA_PROVIDER_THUMBNAIL_DIMS[_data_->i];
				_data_->test_width = _data_->_tmp11_;
				_data_->_tmp12_ = DINO_IMAGE_FILE_METADATA_PROVIDER_THUMBNAIL_DIMS[(G_N_ELEMENTS (DINO_IMAGE_FILE_METADATA_PROVIDER_THUMBNAIL_DIMS) - 1) - _data_->i];
				_data_->test_height = _data_->_tmp12_;
				_data_->test_ratio = ((gfloat) _data_->test_width) / ((gfloat) _data_->test_height);
				_data_->test_diff = fabsf (_data_->test_ratio - _data_->ratio);
				if (_data_->test_diff < _data_->diff) {
					_data_->thumbnail_width = _data_->test_width;
					_data_->thumbnail_height = _data_->test_height;
					_data_->diff = _data_->test_diff;
				}
			}
		}
	}
	_data_->_tmp13_ = _data_->pixbuf;
	_data_->_tmp14_ = gdk_pixbuf_scale_simple (_data_->_tmp13_, _data_->thumbnail_width, _data_->thumbnail_height, GDK_INTERP_BILINEAR);
	_data_->thumbnail_pixbuf = _data_->_tmp14_;
	_data_->buffer_length1 = 0;
	_data_->_buffer_size_ = 0;
	_data_->_tmp15_ = _data_->thumbnail_pixbuf;
	_data_->_tmp16_ = NULL;
	_data_->_tmp17_ = 0;
	gdk_pixbuf_save_to_buffer (_data_->_tmp15_, &_data_->_tmp16_, &_data_->_tmp17_, DINO_IMAGE_FILE_METADATA_PROVIDER_IMAGE_TYPE, &_data_->_inner_error0_, NULL);
	_data_->buffer = (g_free (_data_->buffer), NULL);
	_data_->buffer = _data_->_tmp16_;
	_data_->buffer_length1 = _data_->_tmp17_;
	_data_->_buffer_size_ = _data_->buffer_length1;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_data_->buffer = (g_free (_data_->buffer), NULL);
		_g_object_unref0 (_data_->thumbnail_pixbuf);
		_g_object_unref0 (_data_->pixbuf);
		_g_object_unref0 (_data_->_tmp0_);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp18_ = _data_->buffer;
	_data_->_tmp18__length1 = _data_->buffer_length1;
	_data_->_tmp19_ = g_base64_encode (_data_->_tmp18_, (gint) _data_->_tmp18__length1);
	_data_->base_64 = _data_->_tmp19_;
	_data_->_tmp20_ = string_to_string (DINO_IMAGE_FILE_METADATA_PROVIDER_MIME_TYPE);
	_data_->_tmp21_ = _data_->base_64;
	_data_->_tmp22_ = string_to_string (_data_->_tmp21_);
	_data_->_tmp23_ = g_strconcat ("data:", _data_->_tmp20_, ";base64,", _data_->_tmp22_, NULL);
	_data_->uri = _data_->_tmp23_;
	_data_->_tmp24_ = xmpp_xep_jingle_content_thumbnails_thumbnail_new ();
	_data_->thumbnail = _data_->_tmp24_;
	_data_->_tmp25_ = _data_->thumbnail;
	_data_->_tmp26_ = _data_->uri;
	_data_->_tmp27_ = g_strdup (_data_->_tmp26_);
	_g_free0 (_data_->_tmp25_->uri);
	_data_->_tmp25_->uri = _data_->_tmp27_;
	_data_->_tmp28_ = _data_->thumbnail;
	_data_->_tmp29_ = g_strdup (DINO_IMAGE_FILE_METADATA_PROVIDER_MIME_TYPE);
	_g_free0 (_data_->_tmp28_->media_type);
	_data_->_tmp28_->media_type = _data_->_tmp29_;
	_data_->_tmp30_ = _data_->thumbnail;
	_data_->_tmp30_->width = _data_->thumbnail_width;
	_data_->_tmp31_ = _data_->thumbnail;
	_data_->_tmp31_->height = _data_->thumbnail_height;
	_data_->_tmp32_ = _data_->metadata->thumbnails;
	_data_->_tmp33_ = _data_->thumbnail;
	gee_collection_add ((GeeCollection*) _data_->_tmp32_, _data_->_tmp33_);
	_xmpp_xep_jingle_content_thumbnails_thumbnail_unref0 (_data_->thumbnail);
	_g_free0 (_data_->uri);
	_g_free0 (_data_->base_64);
	_data_->buffer = (g_free (_data_->buffer), NULL);
	_g_object_unref0 (_data_->thumbnail_pixbuf);
	_g_object_unref0 (_data_->pixbuf);
	_g_object_unref0 (_data_->_tmp0_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

DinoImageFileMetadataProvider*
dino_image_file_metadata_provider_construct (GType object_type)
{
	DinoImageFileMetadataProvider * self = NULL;
	self = (DinoImageFileMetadataProvider*) g_object_new (object_type, NULL);
	return self;
}

DinoImageFileMetadataProvider*
dino_image_file_metadata_provider_new (void)
{
	return dino_image_file_metadata_provider_construct (DINO_TYPE_IMAGE_FILE_METADATA_PROVIDER);
}

static void
dino_image_file_metadata_provider_class_init (DinoImageFileMetadataProviderClass * klass,
                                              gpointer klass_data)
{
	dino_image_file_metadata_provider_parent_class = g_type_class_peek_parent (klass);
}

static void
dino_image_file_metadata_provider_dino_file_metadata_provider_interface_init (DinoFileMetadataProviderIface * iface,
                                                                              gpointer iface_data)
{
	dino_image_file_metadata_provider_dino_file_metadata_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->supports_file = (gboolean (*) (DinoFileMetadataProvider*, GFile*)) dino_image_file_metadata_provider_real_supports_file;
	iface->fill_metadata = (void (*) (DinoFileMetadataProvider*, GFile*, XmppXepFileMetadataElementFileMetadata*, GAsyncReadyCallback, gpointer)) dino_image_file_metadata_provider_real_fill_metadata;
	iface->fill_metadata_finish = (void (*) (DinoFileMetadataProvider*, GAsyncResult*)) dino_image_file_metadata_provider_fill_metadata_finish;
}

static void
dino_image_file_metadata_provider_instance_init (DinoImageFileMetadataProvider * self,
                                                 gpointer klass)
{
}

static GType
dino_image_file_metadata_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoImageFileMetadataProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_image_file_metadata_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoImageFileMetadataProvider), 0, (GInstanceInitFunc) dino_image_file_metadata_provider_instance_init, NULL };
	static const GInterfaceInfo dino_file_metadata_provider_info = { (GInterfaceInitFunc) dino_image_file_metadata_provider_dino_file_metadata_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_image_file_metadata_provider_type_id;
	dino_image_file_metadata_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoImageFileMetadataProvider", &g_define_type_info, 0);
	g_type_add_interface_static (dino_image_file_metadata_provider_type_id, DINO_TYPE_FILE_METADATA_PROVIDER, &dino_file_metadata_provider_info);
	return dino_image_file_metadata_provider_type_id;
}

GType
dino_image_file_metadata_provider_get_type (void)
{
	static volatile gsize dino_image_file_metadata_provider_type_id__once = 0;
	if (g_once_init_enter (&dino_image_file_metadata_provider_type_id__once)) {
		GType dino_image_file_metadata_provider_type_id;
		dino_image_file_metadata_provider_type_id = dino_image_file_metadata_provider_get_type_once ();
		g_once_init_leave (&dino_image_file_metadata_provider_type_id__once, dino_image_file_metadata_provider_type_id);
	}
	return dino_image_file_metadata_provider_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;
}

