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

#include <glib-object.h>
#include "libdino.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "xmpp-vala.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER (dino_ui_util_audio_video_file_metadata_provider_get_type ())
#define DINO_UI_UTIL_AUDIO_VIDEO_FILE_METADATA_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER, DinoUiUtilAudioVideoFileMetadataProvider))
#define DINO_UI_UTIL_AUDIO_VIDEO_FILE_METADATA_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER, DinoUiUtilAudioVideoFileMetadataProviderClass))
#define DINO_UI_UTIL_IS_AUDIO_VIDEO_FILE_METADATA_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER))
#define DINO_UI_UTIL_IS_AUDIO_VIDEO_FILE_METADATA_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER))
#define DINO_UI_UTIL_AUDIO_VIDEO_FILE_METADATA_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER, DinoUiUtilAudioVideoFileMetadataProviderClass))

typedef struct _DinoUiUtilAudioVideoFileMetadataProvider DinoUiUtilAudioVideoFileMetadataProvider;
typedef struct _DinoUiUtilAudioVideoFileMetadataProviderClass DinoUiUtilAudioVideoFileMetadataProviderClass;
typedef struct _DinoUiUtilAudioVideoFileMetadataProviderPrivate DinoUiUtilAudioVideoFileMetadataProviderPrivate;
enum  {
	DINO_UI_UTIL_AUDIO_VIDEO_FILE_METADATA_PROVIDER_0_PROPERTY,
	DINO_UI_UTIL_AUDIO_VIDEO_FILE_METADATA_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* dino_ui_util_audio_video_file_metadata_provider_properties[DINO_UI_UTIL_AUDIO_VIDEO_FILE_METADATA_PROVIDER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#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)))
typedef struct _Block70Data Block70Data;
typedef struct _DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData;

struct _DinoUiUtilAudioVideoFileMetadataProvider {
	GObject parent_instance;
	DinoUiUtilAudioVideoFileMetadataProviderPrivate * priv;
};

struct _DinoUiUtilAudioVideoFileMetadataProviderClass {
	GObjectClass parent_class;
};

struct _Block70Data {
	int _ref_count_;
	DinoUiUtilAudioVideoFileMetadataProvider* self;
	gpointer _async_data_;
};

struct _DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoUiUtilAudioVideoFileMetadataProvider* self;
	GFile* file;
	XmppXepFileMetadataElementFileMetadata* metadata;
	Block70Data* _data70_;
	GtkMediaFile* media;
	GtkMediaFile* _tmp0_;
	GtkMediaFile* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GtkMediaFile* _tmp4_;
	GtkMediaFile* _tmp5_;
	gint64 _tmp6_;
	gint64 _tmp7_;
};

static gpointer dino_ui_util_audio_video_file_metadata_provider_parent_class = NULL;
static DinoFileMetadataProviderIface * dino_ui_util_audio_video_file_metadata_provider_dino_file_metadata_provider_parent_iface = NULL;

VALA_EXTERN GType dino_ui_util_audio_video_file_metadata_provider_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiUtilAudioVideoFileMetadataProvider, g_object_unref)
static gboolean dino_ui_util_audio_video_file_metadata_provider_real_supports_file (DinoFileMetadataProvider* base,
                                                                             GFile* file);
static void dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_data_free (gpointer _data);
static void dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata (DinoFileMetadataProvider* base,
                                                                         GFile* file,
                                                                         XmppXepFileMetadataElementFileMetadata* metadata,
                                                                         GAsyncReadyCallback _callback_,
                                                                         gpointer _user_data_);
static gboolean dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co (DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData* _data_);
static Block70Data* block70_data_ref (Block70Data* _data70_);
static void block70_data_unref (void * _userdata_);
static void ___lambda334_ (Block70Data* _data70_,
                    GObject* object,
                    GParamSpec* pspec);
static gboolean _dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co_gsource_func (gpointer self);
static void ____lambda334__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
VALA_EXTERN DinoUiUtilAudioVideoFileMetadataProvider* dino_ui_util_audio_video_file_metadata_provider_new (void);
VALA_EXTERN DinoUiUtilAudioVideoFileMetadataProvider* dino_ui_util_audio_video_file_metadata_provider_construct (GType object_type);
static GType dino_ui_util_audio_video_file_metadata_provider_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gboolean
dino_ui_util_audio_video_file_metadata_provider_real_supports_file (DinoFileMetadataProvider* base,
                                                                    GFile* file)
{
	DinoUiUtilAudioVideoFileMetadataProvider * self;
	GFileInfo* _tmp0_ = NULL;
	GFileInfo* _tmp1_;
	gchar* mime_type = NULL;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	gboolean _tmp6_ = FALSE;
	const gchar* _tmp7_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (DinoUiUtilAudioVideoFileMetadataProvider*) 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;
	if (_tmp5_ == NULL) {
		result = FALSE;
		_g_free0 (mime_type);
		_g_object_unref0 (_tmp0_);
		return result;
	}
	_tmp7_ = mime_type;
	if (g_str_has_prefix (_tmp7_, "audio")) {
		_tmp6_ = TRUE;
	} else {
		const gchar* _tmp8_;
		_tmp8_ = mime_type;
		_tmp6_ = g_str_has_prefix (_tmp8_, "video");
	}
	result = _tmp6_;
	_g_free0 (mime_type);
	_g_object_unref0 (_tmp0_);
	return result;
}

static void
dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_data_free (gpointer _data)
{
	DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData* _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 (DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData, _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_ui_util_audio_video_file_metadata_provider_real_fill_metadata (DinoFileMetadataProvider* base,
                                                                    GFile* file,
                                                                    XmppXepFileMetadataElementFileMetadata* metadata,
                                                                    GAsyncReadyCallback _callback_,
                                                                    gpointer _user_data_)
{
	DinoUiUtilAudioVideoFileMetadataProvider * self;
	DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData* _data_;
	DinoUiUtilAudioVideoFileMetadataProvider* _tmp0_;
	GFile* _tmp1_;
	XmppXepFileMetadataElementFileMetadata* _tmp2_;
	g_return_if_fail (file != NULL);
	g_return_if_fail (metadata != NULL);
	self = (DinoUiUtilAudioVideoFileMetadataProvider*) base;
	_data_ = g_slice_new0 (DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_ui_util_audio_video_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_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co (_data_);
}

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

static Block70Data*
block70_data_ref (Block70Data* _data70_)
{
	g_atomic_int_inc (&_data70_->_ref_count_);
	return _data70_;
}

static void
block70_data_unref (void * _userdata_)
{
	Block70Data* _data70_;
	_data70_ = (Block70Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data70_->_ref_count_)) {
		DinoUiUtilAudioVideoFileMetadataProvider* self;
		self = _data70_->self;
		_g_object_unref0 (self);
		g_slice_free (Block70Data, _data70_);
	}
}

static gboolean
_dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co_gsource_func (gpointer self)
{
	gboolean result;
	result = dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co (self);
	return result;
}

static void
___lambda334_ (Block70Data* _data70_,
               GObject* object,
               GParamSpec* pspec)
{
	DinoUiUtilAudioVideoFileMetadataProvider* self;
	self = _data70_->self;
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co_gsource_func, _data70_->_async_data_, NULL);
}

static void
____lambda334__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	___lambda334_ (self, _sender, pspec);
}

static gboolean
dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata_co (DinoUiUtilAudioVideoFileMetadataProviderFillMetadataData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data70_ = g_slice_new0 (Block70Data);
	_data_->_data70_->_ref_count_ = 1;
	_data_->_data70_->self = g_object_ref (_data_->self);
	_data_->_data70_->_async_data_ = _data_;
	_data_->_tmp0_ = (GtkMediaFile*) gtk_media_file_new_for_file (_data_->file);
	_data_->media = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->media;
	g_object_get ((GtkMediaStream*) _data_->_tmp1_, "prepared", &_data_->_tmp2_, NULL);
	_data_->_tmp3_ = _data_->_tmp2_;
	if (!_data_->_tmp3_) {
		_data_->_tmp4_ = _data_->media;
		g_signal_connect_data ((GObject*) _data_->_tmp4_, "notify::prepared", (GCallback) ____lambda334__g_object_notify, block70_data_ref (_data_->_data70_), (GClosureNotify) block70_data_unref, 0);
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
	}
	_data_->_tmp5_ = _data_->media;
	_data_->_tmp6_ = gtk_media_stream_get_duration ((GtkMediaStream*) _data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	xmpp_xep_file_metadata_element_file_metadata_set_length (_data_->metadata, _data_->_tmp7_ / 1000);
	_g_object_unref0 (_data_->media);
	block70_data_unref (_data_->_data70_);
	_data_->_data70_ = NULL;
	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;
}

DinoUiUtilAudioVideoFileMetadataProvider*
dino_ui_util_audio_video_file_metadata_provider_construct (GType object_type)
{
	DinoUiUtilAudioVideoFileMetadataProvider * self = NULL;
	self = (DinoUiUtilAudioVideoFileMetadataProvider*) g_object_new (object_type, NULL);
	return self;
}

DinoUiUtilAudioVideoFileMetadataProvider*
dino_ui_util_audio_video_file_metadata_provider_new (void)
{
	return dino_ui_util_audio_video_file_metadata_provider_construct (DINO_UI_UTIL_TYPE_AUDIO_VIDEO_FILE_METADATA_PROVIDER);
}

static void
dino_ui_util_audio_video_file_metadata_provider_class_init (DinoUiUtilAudioVideoFileMetadataProviderClass * klass,
                                                            gpointer klass_data)
{
	dino_ui_util_audio_video_file_metadata_provider_parent_class = g_type_class_peek_parent (klass);
}

static void
dino_ui_util_audio_video_file_metadata_provider_dino_file_metadata_provider_interface_init (DinoFileMetadataProviderIface * iface,
                                                                                            gpointer iface_data)
{
	dino_ui_util_audio_video_file_metadata_provider_dino_file_metadata_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->supports_file = (gboolean (*) (DinoFileMetadataProvider*, GFile*)) dino_ui_util_audio_video_file_metadata_provider_real_supports_file;
	iface->fill_metadata = (void (*) (DinoFileMetadataProvider*, GFile*, XmppXepFileMetadataElementFileMetadata*, GAsyncReadyCallback, gpointer)) dino_ui_util_audio_video_file_metadata_provider_real_fill_metadata;
	iface->fill_metadata_finish = (void (*) (DinoFileMetadataProvider*, GAsyncResult*)) dino_ui_util_audio_video_file_metadata_provider_fill_metadata_finish;
}

static void
dino_ui_util_audio_video_file_metadata_provider_instance_init (DinoUiUtilAudioVideoFileMetadataProvider * self,
                                                               gpointer klass)
{
}

static GType
dino_ui_util_audio_video_file_metadata_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoUiUtilAudioVideoFileMetadataProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_ui_util_audio_video_file_metadata_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUiUtilAudioVideoFileMetadataProvider), 0, (GInstanceInitFunc) dino_ui_util_audio_video_file_metadata_provider_instance_init, NULL };
	static const GInterfaceInfo dino_file_metadata_provider_info = { (GInterfaceInitFunc) dino_ui_util_audio_video_file_metadata_provider_dino_file_metadata_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_ui_util_audio_video_file_metadata_provider_type_id;
	dino_ui_util_audio_video_file_metadata_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoUiUtilAudioVideoFileMetadataProvider", &g_define_type_info, 0);
	g_type_add_interface_static (dino_ui_util_audio_video_file_metadata_provider_type_id, DINO_TYPE_FILE_METADATA_PROVIDER, &dino_file_metadata_provider_info);
	return dino_ui_util_audio_video_file_metadata_provider_type_id;
}

GType
dino_ui_util_audio_video_file_metadata_provider_get_type (void)
{
	static volatile gsize dino_ui_util_audio_video_file_metadata_provider_type_id__once = 0;
	if (g_once_init_enter (&dino_ui_util_audio_video_file_metadata_provider_type_id__once)) {
		GType dino_ui_util_audio_video_file_metadata_provider_type_id;
		dino_ui_util_audio_video_file_metadata_provider_type_id = dino_ui_util_audio_video_file_metadata_provider_get_type_once ();
		g_once_init_leave (&dino_ui_util_audio_video_file_metadata_provider_type_id__once, dino_ui_util_audio_video_file_metadata_provider_type_id);
	}
	return dino_ui_util_audio_video_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;
}

