/* DatabaseProxy.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from DatabaseProxy.vala, do not modify */

/* DatabaseProxy.vala
 *
 * Copyright (C) 2020-2025 Jerry Casiano
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.
 *
 * If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
*/

#include <glib-object.h>
#include <gio/gio.h>
#include "font-manager.h"
#include <glib.h>
#include <json-glib/json-glib.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
#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 FONT_MANAGER_TYPE_DATABASE_PROXY (font_manager_database_proxy_get_type ())
#define FONT_MANAGER_DATABASE_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FONT_MANAGER_TYPE_DATABASE_PROXY, FontManagerDatabaseProxy))
#define FONT_MANAGER_DATABASE_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FONT_MANAGER_TYPE_DATABASE_PROXY, FontManagerDatabaseProxyClass))
#define FONT_MANAGER_IS_DATABASE_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FONT_MANAGER_TYPE_DATABASE_PROXY))
#define FONT_MANAGER_IS_DATABASE_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FONT_MANAGER_TYPE_DATABASE_PROXY))
#define FONT_MANAGER_DATABASE_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FONT_MANAGER_TYPE_DATABASE_PROXY, FontManagerDatabaseProxyClass))

typedef struct _FontManagerDatabaseProxy FontManagerDatabaseProxy;
typedef struct _FontManagerDatabaseProxyClass FontManagerDatabaseProxyClass;
typedef struct _FontManagerDatabaseProxyPrivate FontManagerDatabaseProxyPrivate;
enum  {
	FONT_MANAGER_DATABASE_PROXY_0_PROPERTY,
	FONT_MANAGER_DATABASE_PROXY_NUM_PROPERTIES
};
static GParamSpec* font_manager_database_proxy_properties[FONT_MANAGER_DATABASE_PROXY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
enum  {
	FONT_MANAGER_DATABASE_PROXY_UPDATE_STARTED_SIGNAL,
	FONT_MANAGER_DATABASE_PROXY_UPDATE_COMPLETE_SIGNAL,
	FONT_MANAGER_DATABASE_PROXY_NUM_SIGNALS
};
static guint font_manager_database_proxy_signals[FONT_MANAGER_DATABASE_PROXY_NUM_SIGNALS] = {0};

struct _FontManagerDatabaseProxy {
	GObject parent_instance;
	FontManagerDatabaseProxyPrivate * priv;
};

struct _FontManagerDatabaseProxyClass {
	GObjectClass parent_class;
};

struct _FontManagerDatabaseProxyPrivate {
	GCancellable* cancellable;
	FontManagerProgressCallback progress;
};

static gint FontManagerDatabaseProxy_private_offset;
static gpointer font_manager_database_proxy_parent_class = NULL;
static FontManagerDatabase* font_manager_database_proxy_db;
static FontManagerDatabase* font_manager_database_proxy_db = NULL;

VALA_EXTERN GType font_manager_database_proxy_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FontManagerDatabaseProxy, g_object_unref)
VALA_EXTERN FontManagerDatabase* font_manager_database_proxy_get_default_db (void);
VALA_EXTERN void font_manager_database_proxy_set_cancellable (FontManagerDatabaseProxy* self,
                                                  GCancellable* cancellable);
VALA_EXTERN void font_manager_database_proxy_set_progress_callback (FontManagerDatabaseProxy* self,
                                                        FontManagerProgressCallback progress);
VALA_EXTERN void font_manager_database_proxy_update (FontManagerDatabaseProxy* self,
                                         JsonArray* available_fonts);
static void __lambda20_ (FontManagerDatabaseProxy* self,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda20__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
VALA_EXTERN FontManagerDatabaseProxy* font_manager_database_proxy_new (void);
VALA_EXTERN FontManagerDatabaseProxy* font_manager_database_proxy_construct (GType object_type);
static void font_manager_database_proxy_finalize (GObject * obj);
static GType font_manager_database_proxy_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
font_manager_database_proxy_get_instance_private (FontManagerDatabaseProxy* self)
{
	return G_STRUCT_MEMBER_P (self, FontManagerDatabaseProxy_private_offset);
}

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

FontManagerDatabase*
font_manager_database_proxy_get_default_db (void)
{
	FontManagerDatabase* _tmp0_;
	FontManagerDatabase* _tmp2_;
	FontManagerDatabase* _tmp3_;
	FontManagerDatabase* _tmp4_;
	FontManagerDatabase* result;
	_tmp0_ = font_manager_database_proxy_db;
	if (_tmp0_ == NULL) {
		FontManagerDatabase* _tmp1_;
		_tmp1_ = font_manager_database_new ();
		_g_object_unref0 (font_manager_database_proxy_db);
		font_manager_database_proxy_db = _tmp1_;
	}
	_tmp2_ = font_manager_database_proxy_db;
	g_object_ref ((GObject*) _tmp2_);
	_tmp3_ = font_manager_database_proxy_db;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	result = _tmp4_;
	return result;
}

void
font_manager_database_proxy_set_cancellable (FontManagerDatabaseProxy* self,
                                             GCancellable* cancellable)
{
	GCancellable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (self->priv->cancellable);
	self->priv->cancellable = _tmp0_;
	return;
}

void
font_manager_database_proxy_set_progress_callback (FontManagerDatabaseProxy* self,
                                                   FontManagerProgressCallback progress)
{
	g_return_if_fail (self != NULL);
	self->priv->progress = progress;
	return;
}

static void
__lambda20_ (FontManagerDatabaseProxy* self,
             GObject* obj,
             GAsyncResult* res)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (res != NULL);
	{
		font_manager_update_database_finish (res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		g_signal_emit (self, font_manager_database_proxy_signals[FONT_MANAGER_DATABASE_PROXY_UPDATE_COMPLETE_SIGNAL], 0);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = e;
		_tmp1_ = _tmp0_->message;
		g_critical ("DatabaseProxy.vala:62: %s", _tmp1_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

static void
___lambda20__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda20_ ((FontManagerDatabaseProxy*) self, source_object, res);
	g_object_unref (self);
}

void
font_manager_database_proxy_update (FontManagerDatabaseProxy* self,
                                    JsonArray* available_fonts)
{
	FontManagerDatabase* _tmp0_;
	FontManagerDatabase* _tmp1_;
	FontManagerProgressCallback _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (available_fonts != NULL);
	g_signal_emit (self, font_manager_database_proxy_signals[FONT_MANAGER_DATABASE_PROXY_UPDATE_STARTED_SIGNAL], 0);
	_tmp0_ = font_manager_database_proxy_get_default_db ();
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->progress;
	_tmp3_ = self->priv->cancellable;
	font_manager_update_database (_tmp1_, available_fonts, _tmp2_, _tmp3_, ___lambda20__gasync_ready_callback, g_object_ref (self));
	_g_object_unref0 (_tmp1_);
	return;
}

FontManagerDatabaseProxy*
font_manager_database_proxy_construct (GType object_type)
{
	FontManagerDatabaseProxy * self = NULL;
	self = (FontManagerDatabaseProxy*) g_object_new (object_type, NULL);
	return self;
}

FontManagerDatabaseProxy*
font_manager_database_proxy_new (void)
{
	return font_manager_database_proxy_construct (FONT_MANAGER_TYPE_DATABASE_PROXY);
}

static void
font_manager_database_proxy_class_init (FontManagerDatabaseProxyClass * klass,
                                        gpointer klass_data)
{
	font_manager_database_proxy_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FontManagerDatabaseProxy_private_offset);
	G_OBJECT_CLASS (klass)->finalize = font_manager_database_proxy_finalize;
	font_manager_database_proxy_signals[FONT_MANAGER_DATABASE_PROXY_UPDATE_STARTED_SIGNAL] = g_signal_new ("update-started", FONT_MANAGER_TYPE_DATABASE_PROXY, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	font_manager_database_proxy_signals[FONT_MANAGER_DATABASE_PROXY_UPDATE_COMPLETE_SIGNAL] = g_signal_new ("update-complete", FONT_MANAGER_TYPE_DATABASE_PROXY, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
font_manager_database_proxy_instance_init (FontManagerDatabaseProxy * self,
                                           gpointer klass)
{
	self->priv = font_manager_database_proxy_get_instance_private (self);
	self->priv->cancellable = NULL;
	self->priv->progress = NULL;
}

static void
font_manager_database_proxy_finalize (GObject * obj)
{
	FontManagerDatabaseProxy * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FONT_MANAGER_TYPE_DATABASE_PROXY, FontManagerDatabaseProxy);
	_g_object_unref0 (self->priv->cancellable);
	G_OBJECT_CLASS (font_manager_database_proxy_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
font_manager_database_proxy_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FontManagerDatabaseProxyClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) font_manager_database_proxy_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FontManagerDatabaseProxy), 0, (GInstanceInitFunc) font_manager_database_proxy_instance_init, NULL };
	GType font_manager_database_proxy_type_id;
	font_manager_database_proxy_type_id = g_type_register_static (G_TYPE_OBJECT, "FontManagerDatabaseProxy", &g_define_type_info, 0);
	FontManagerDatabaseProxy_private_offset = g_type_add_instance_private (font_manager_database_proxy_type_id, sizeof (FontManagerDatabaseProxyPrivate));
	return font_manager_database_proxy_type_id;
}

GType
font_manager_database_proxy_get_type (void)
{
	static volatile gsize font_manager_database_proxy_type_id__once = 0;
	if (g_once_init_enter (&font_manager_database_proxy_type_id__once)) {
		GType font_manager_database_proxy_type_id;
		font_manager_database_proxy_type_id = font_manager_database_proxy_get_type_once ();
		g_once_init_leave (&font_manager_database_proxy_type_id__once, font_manager_database_proxy_type_id);
	}
	return font_manager_database_proxy_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;
}

