/* gitg-plugins-engine.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-plugins-engine.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2012 - Jesse van den Kieboom
 *
 * gitg 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 2 of the License, or
 * (at your option) any later version.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include <libpeas/peas.h>
#include <glib-object.h>
#include <glib.h>
#include <girepository/girepository.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 GITG_TYPE_PLUGINS_ENGINE (gitg_plugins_engine_get_type ())
#define GITG_PLUGINS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_PLUGINS_ENGINE, GitgPluginsEngine))
#define GITG_PLUGINS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_PLUGINS_ENGINE, GitgPluginsEngineClass))
#define GITG_IS_PLUGINS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_PLUGINS_ENGINE))
#define GITG_IS_PLUGINS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_PLUGINS_ENGINE))
#define GITG_PLUGINS_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_PLUGINS_ENGINE, GitgPluginsEngineClass))

typedef struct _GitgPluginsEngine GitgPluginsEngine;
typedef struct _GitgPluginsEngineClass GitgPluginsEngineClass;
typedef struct _GitgPluginsEnginePrivate GitgPluginsEnginePrivate;
enum  {
	GITG_PLUGINS_ENGINE_0_PROPERTY,
	GITG_PLUGINS_ENGINE_NUM_PROPERTIES
};
static GParamSpec* gitg_plugins_engine_properties[GITG_PLUGINS_ENGINE_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)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_PeasPluginInfo_free0(var) ((var == NULL) ? NULL : (var = (_vala_PeasPluginInfo_free (var), NULL)))

struct _GitgPluginsEngine {
	PeasEngine parent_instance;
	GitgPluginsEnginePrivate * priv;
};

struct _GitgPluginsEngineClass {
	PeasEngineClass parent_class;
};

static gpointer gitg_plugins_engine_parent_class = NULL;
static GitgPluginsEngine* gitg_plugins_engine_s_instance;
static GitgPluginsEngine* gitg_plugins_engine_s_instance = NULL;

VALA_EXTERN GType gitg_plugins_engine_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgPluginsEngine, g_object_unref)
VALA_EXTERN GitgPluginsEngine* gitg_plugins_engine_get_default (void);
VALA_EXTERN GitgPluginsEngine* gitg_plugins_engine_new (void);
VALA_EXTERN GitgPluginsEngine* gitg_plugins_engine_construct (GType object_type);
VALA_EXTERN void gitg_plugins_engine_initialize (void);
static GObject * gitg_plugins_engine_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
VALA_EXTERN gchar* gitg_dirs_get_user_plugins_dir (void);
VALA_EXTERN gchar* gitg_dirs_get_user_plugins_data_dir (void);
VALA_EXTERN gchar* gitg_dirs_get_plugins_dir (void);
VALA_EXTERN gchar* gitg_dirs_get_plugins_data_dir (void);
static PeasPluginInfo* _vala_PeasPluginInfo_copy (PeasPluginInfo* self);
static void _vala_array_add24 (PeasPluginInfo** * array,
                        gint* length,
                        gint* size,
                        PeasPluginInfo* value);
static void _vala_PeasPluginInfo_free (PeasPluginInfo* self);
static void gitg_plugins_engine_finalize (GObject * obj);
static GType gitg_plugins_engine_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

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

GitgPluginsEngine*
gitg_plugins_engine_get_default (void)
{
	GitgPluginsEngine* _tmp0_;
	GitgPluginsEngine* _tmp3_;
	GitgPluginsEngine* _tmp4_;
	GitgPluginsEngine* result;
	_tmp0_ = gitg_plugins_engine_s_instance;
	if (_tmp0_ == NULL) {
		GitgPluginsEngine* _tmp1_;
		GitgPluginsEngine* _tmp2_;
		_tmp1_ = gitg_plugins_engine_new ();
		_g_object_unref0 (gitg_plugins_engine_s_instance);
		gitg_plugins_engine_s_instance = _tmp1_;
		_tmp2_ = gitg_plugins_engine_s_instance;
		g_object_add_weak_pointer ((GObject*) _tmp2_, &gitg_plugins_engine_s_instance);
	}
	_tmp3_ = gitg_plugins_engine_s_instance;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	result = _tmp4_;
	return result;
}

void
gitg_plugins_engine_initialize (void)
{
	GitgPluginsEngine* _tmp0_;
	GitgPluginsEngine* _tmp1_;
	_tmp0_ = gitg_plugins_engine_get_default ();
	_tmp1_ = _tmp0_;
	_g_object_unref0 (_tmp1_);
}

GitgPluginsEngine*
gitg_plugins_engine_construct (GType object_type)
{
	GitgPluginsEngine * self = NULL;
	self = (GitgPluginsEngine*) g_object_new (object_type, NULL);
	return self;
}

GitgPluginsEngine*
gitg_plugins_engine_new (void)
{
	return gitg_plugins_engine_construct (GITG_TYPE_PLUGINS_ENGINE);
}

static PeasPluginInfo*
_vala_PeasPluginInfo_copy (PeasPluginInfo* self)
{
	return g_boxed_copy (peas_plugin_info_get_type (), self);
}

static gpointer
__vala_PeasPluginInfo_copy0 (gpointer self)
{
	return self ? _vala_PeasPluginInfo_copy (self) : NULL;
}

static void
_vala_array_add24 (PeasPluginInfo** * array,
                   gint* length,
                   gint* size,
                   PeasPluginInfo* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (PeasPluginInfo*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_PeasPluginInfo_free (PeasPluginInfo* self)
{
	g_boxed_free (peas_plugin_info_get_type (), self);
}

static GObject *
gitg_plugins_engine_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GitgPluginsEngine * self;
	GIRepository* repo = NULL;
	GIRepository* _tmp0_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	PeasPluginInfo** builtins = NULL;
	PeasPluginInfo** _tmp17_;
	gint builtins_length1;
	gint _builtins_size_;
	GList* _tmp18_;
	PeasPluginInfo** _tmp23_;
	gint _tmp23__length1;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (gitg_plugins_engine_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_PLUGINS_ENGINE, GitgPluginsEngine);
	peas_engine_enable_loader ((PeasEngine*) self, "python");
	_tmp0_ = gi_repository_dup_default ();
	repo = _tmp0_;
	{
		GIRepository* _tmp1_;
		GIRepository* _tmp2_;
		_tmp1_ = repo;
		gi_repository_require (_tmp1_, "Peas", "1.0", 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = repo;
		gi_repository_require (_tmp2_, "PeasGtk", "1.0", 0, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("gitg-plugins-engine.vala:40: Could not load repository: %s", _tmp4_);
		_g_error_free0 (e);
		return obj;
	}
	__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_);
	}
	_tmp5_ = gitg_dirs_get_user_plugins_dir ();
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp8_ = gitg_dirs_get_user_plugins_data_dir ();
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	peas_engine_add_search_path ((PeasEngine*) self, _tmp7_, _tmp10_);
	_g_free0 (_tmp10_);
	_g_free0 (_tmp7_);
	_tmp11_ = gitg_dirs_get_plugins_dir ();
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp14_ = gitg_dirs_get_plugins_data_dir ();
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_;
	peas_engine_add_search_path ((PeasEngine*) self, _tmp13_, _tmp16_);
	_g_free0 (_tmp16_);
	_g_free0 (_tmp13_);
	_tmp17_ = g_new0 (PeasPluginInfo*, 20 + 1);
	builtins = _tmp17_;
	builtins_length1 = 20;
	_builtins_size_ = builtins_length1;
	builtins_length1 = 0;
	_tmp18_ = peas_engine_get_plugin_list ((PeasEngine*) self);
	{
		GList* info_collection = NULL;
		GList* info_it = NULL;
		info_collection = _tmp18_;
		for (info_it = info_collection; info_it != NULL; info_it = info_it->next) {
			PeasPluginInfo* _tmp19_;
			PeasPluginInfo* info = NULL;
			_tmp19_ = __vala_PeasPluginInfo_copy0 ((PeasPluginInfo*) info_it->data);
			info = _tmp19_;
			{
				PeasPluginInfo* _tmp20_;
				_tmp20_ = info;
				if (peas_plugin_info_is_builtin (_tmp20_)) {
					PeasPluginInfo* _tmp21_;
					PeasPluginInfo* _tmp22_;
					_tmp21_ = info;
					_tmp22_ = __vala_PeasPluginInfo_copy0 (_tmp21_);
					_vala_array_add24 (&builtins, &builtins_length1, &_builtins_size_, _tmp22_);
				}
				__vala_PeasPluginInfo_free0 (info);
			}
		}
	}
	_tmp23_ = builtins;
	_tmp23__length1 = builtins_length1;
	{
		PeasPluginInfo** info_collection = NULL;
		gint info_collection_length1 = 0;
		gint _info_collection_size_ = 0;
		gint info_it = 0;
		info_collection = _tmp23_;
		info_collection_length1 = _tmp23__length1;
		for (info_it = 0; info_it < info_collection_length1; info_it = info_it + 1) {
			PeasPluginInfo* _tmp24_;
			PeasPluginInfo* info = NULL;
			_tmp24_ = __vala_PeasPluginInfo_copy0 (info_collection[info_it]);
			info = _tmp24_;
			{
				PeasPluginInfo* _tmp25_;
				_tmp25_ = info;
				g_signal_emit_by_name ((PeasEngine*) self, "load-plugin", _tmp25_);
				__vala_PeasPluginInfo_free0 (info);
			}
		}
	}
	builtins = (_vala_array_free (builtins, builtins_length1, (GDestroyNotify) _vala_PeasPluginInfo_free), NULL);
	return obj;
}

static void
gitg_plugins_engine_class_init (GitgPluginsEngineClass * klass,
                                gpointer klass_data)
{
	gitg_plugins_engine_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = gitg_plugins_engine_constructor;
	G_OBJECT_CLASS (klass)->finalize = gitg_plugins_engine_finalize;
}

static void
gitg_plugins_engine_instance_init (GitgPluginsEngine * self,
                                   gpointer klass)
{
}

static void
gitg_plugins_engine_finalize (GObject * obj)
{
	GitgPluginsEngine * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_PLUGINS_ENGINE, GitgPluginsEngine);
	G_OBJECT_CLASS (gitg_plugins_engine_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_plugins_engine_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgPluginsEngineClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_plugins_engine_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgPluginsEngine), 0, (GInstanceInitFunc) gitg_plugins_engine_instance_init, NULL };
	GType gitg_plugins_engine_type_id;
	gitg_plugins_engine_type_id = g_type_register_static (peas_engine_get_type (), "GitgPluginsEngine", &g_define_type_info, 0);
	return gitg_plugins_engine_type_id;
}

GType
gitg_plugins_engine_get_type (void)
{
	static gsize gitg_plugins_engine_type_id__once = 0;
	if (g_once_init_enter (&gitg_plugins_engine_type_id__once)) {
		GType gitg_plugins_engine_type_id;
		gitg_plugins_engine_type_id = gitg_plugins_engine_get_type_once ();
		g_once_init_leave (&gitg_plugins_engine_type_id__once, gitg_plugins_engine_type_id);
	}
	return gitg_plugins_engine_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

