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

/*
* Copyright (c) 2025-2026 (https://github.com/phase1geo/Minder)
*
* 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 2 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <gobject/gvaluecollector.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

typedef enum  {
	TEMPLATE_TYPE_STYLE_GENERAL,
	TEMPLATE_TYPE_STYLE_NODE,
	TEMPLATE_TYPE_STYLE_CONNECTION,
	TEMPLATE_TYPE_STYLE_CALLOUT,
	TEMPLATE_TYPE_STYLE_OPTION_BRANCH,
	TEMPLATE_TYPE_STYLE_OPTION_LINK,
	TEMPLATE_TYPE_STYLE_OPTION_NODE,
	TEMPLATE_TYPE_STYLE_OPTION_CONNECTION,
	TEMPLATE_TYPE_STYLE_OPTION_CALLOUT,
	TEMPLATE_TYPE_NUM
} TemplateType;

#define TYPE_TEMPLATE_TYPE (template_type_get_type ())

#define TYPE_TEMPLATE (template_get_type ())
#define TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEMPLATE, Template))
#define TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEMPLATE, TemplateClass))
#define IS_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEMPLATE))
#define IS_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEMPLATE))
#define TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEMPLATE, TemplateClass))

typedef struct _Template Template;
typedef struct _TemplateClass TemplateClass;

#define TYPE_STYLE_TEMPLATE (style_template_get_type ())
#define STYLE_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_STYLE_TEMPLATE, StyleTemplate))
#define STYLE_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_STYLE_TEMPLATE, StyleTemplateClass))
#define IS_STYLE_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_STYLE_TEMPLATE))
#define IS_STYLE_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_STYLE_TEMPLATE))
#define STYLE_TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_STYLE_TEMPLATE, StyleTemplateClass))

typedef struct _StyleTemplate StyleTemplate;
typedef struct _StyleTemplateClass StyleTemplateClass;
typedef void (*TemplateAddLoadFunc) (Template* template, gpointer user_data);
typedef void (*TemplateDeleteFunc) (gpointer user_data);

#define TYPE_TEMPLATES (templates_get_type ())
#define TEMPLATES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEMPLATES, Templates))
#define TEMPLATES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEMPLATES, TemplatesClass))
#define IS_TEMPLATES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEMPLATES))
#define IS_TEMPLATES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEMPLATES))
#define TEMPLATES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEMPLATES, TemplatesClass))

typedef struct _Templates Templates;
typedef struct _TemplatesClass TemplatesClass;
typedef struct _TemplatesPrivate TemplatesPrivate;

#define TYPE_TEMPLATE_GROUP (template_group_get_type ())
#define TEMPLATE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEMPLATE_GROUP, TemplateGroup))
#define TEMPLATE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEMPLATE_GROUP, TemplateGroupClass))
#define IS_TEMPLATE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEMPLATE_GROUP))
#define IS_TEMPLATE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEMPLATE_GROUP))
#define TEMPLATE_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEMPLATE_GROUP, TemplateGroupClass))

typedef struct _TemplateGroup TemplateGroup;
typedef struct _TemplateGroupClass TemplateGroupClass;
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _template_group_unref0(var) ((var == NULL) ? NULL : (var = (template_group_unref (var), NULL)))

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmlFreeDoc0(var) ((var == NULL) ? NULL : (var = (xmlFreeDoc (var), NULL)))
typedef struct _ParamSpecTemplates ParamSpecTemplates;

struct _Templates {
	GTypeInstance parent_instance;
	volatile int ref_count;
	TemplatesPrivate * priv;
	GArray* _template_groups;
};

struct _TemplatesClass {
	GTypeClass parent_class;
	void (*finalize) (Templates *self);
};

struct _ParamSpecTemplates {
	GParamSpec parent_instance;
};

static gpointer templates_parent_class = NULL;

VALA_EXTERN GType template_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* template_type_to_string (TemplateType self);
VALA_EXTERN gchar* template_type_label (TemplateType self);
VALA_EXTERN TemplateType template_type_parse (const gchar* val);
VALA_EXTERN gpointer template_ref (gpointer instance);
VALA_EXTERN void template_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_template (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void value_set_template (GValue* value,
                         gpointer v_object);
VALA_EXTERN void value_take_template (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer value_get_template (const GValue* value);
VALA_EXTERN GType template_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Template, template_unref)
VALA_EXTERN Template* template_type_create_template (TemplateType self,
                                         const gchar* name);
VALA_EXTERN StyleTemplate* style_template_new (TemplateType ttype,
                                   const gchar* name);
VALA_EXTERN StyleTemplate* style_template_construct (GType object_type,
                                         TemplateType ttype,
                                         const gchar* name);
VALA_EXTERN GType style_template_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (StyleTemplate, template_unref)
VALA_EXTERN gpointer templates_ref (gpointer instance);
VALA_EXTERN void templates_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_templates (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags);
VALA_EXTERN void value_set_templates (GValue* value,
                          gpointer v_object);
VALA_EXTERN void value_take_templates (GValue* value,
                           gpointer v_object);
VALA_EXTERN gpointer value_get_templates (const GValue* value);
VALA_EXTERN GType templates_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Templates, templates_unref)
VALA_EXTERN gpointer template_group_ref (gpointer instance);
VALA_EXTERN void template_group_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_template_group (const gchar* name,
                                       const gchar* nick,
                                       const gchar* blurb,
                                       GType object_type,
                                       GParamFlags flags);
VALA_EXTERN void value_set_template_group (GValue* value,
                               gpointer v_object);
VALA_EXTERN void value_take_template_group (GValue* value,
                                gpointer v_object);
VALA_EXTERN gpointer value_get_template_group (const GValue* value);
VALA_EXTERN GType template_group_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TemplateGroup, template_group_unref)
VALA_EXTERN Templates* templates_new (void);
VALA_EXTERN Templates* templates_construct (GType object_type);
static void _template_group_unref0_ (gpointer var);
static void _vala_TemplateGroup_free_function_content_of (gpointer data);
VALA_EXTERN TemplateGroup* template_group_new (TemplateType ttype);
VALA_EXTERN TemplateGroup* template_group_construct (GType object_type,
                                         TemplateType ttype);
static void _____lambda30_ (Templates* self);
VALA_EXTERN void templates_save (Templates* self);
static void ______lambda30__template_group_changed (TemplateGroup* _sender,
                                             gpointer self);
VALA_EXTERN TemplateGroup* templates_get_template_group (Templates* self,
                                             TemplateType ttype);
VALA_EXTERN Template* templates_get_template (Templates* self,
                                  TemplateType ttype,
                                  const gchar* name);
VALA_EXTERN Template* template_group_get_template (TemplateGroup* self,
                                       const gchar* name);
VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
VALA_EXTERN void templates_add_menus (Templates* self,
                          TemplateType ttype,
                          GtkWidget* w,
                          MainWindow* win,
                          TemplateAddLoadFunc add_func,
                          gpointer add_func_target,
                          TemplateAddLoadFunc load_func,
                          gpointer load_func_target,
                          TemplateDeleteFunc del_func,
                          gpointer del_func_target);
VALA_EXTERN void template_group_add_menus (TemplateGroup* self,
                               GtkWidget* w,
                               MainWindow* win,
                               TemplateAddLoadFunc add_func,
                               gpointer add_func_target,
                               TemplateAddLoadFunc load_func,
                               gpointer load_func_target,
                               TemplateDeleteFunc del_func,
                               gpointer del_func_target);
VALA_EXTERN GtkPopoverMenu* templates_get_template_group_menu (Templates* self,
                                                   TemplateType ttype);
VALA_EXTERN GtkPopoverMenu* template_group_get_menu (TemplateGroup* self);
VALA_EXTERN void templates_add_template (Templates* self,
                             Template* template);
VALA_EXTERN TemplateType template_get_ttype (Template* self);
VALA_EXTERN gboolean template_group_add_template (TemplateGroup* self,
                                      Template* template);
VALA_EXTERN void templates_delete_template (Templates* self,
                                TemplateType ttype,
                                const gchar* name);
VALA_EXTERN gboolean template_group_delete_template (TemplateGroup* self,
                                         const gchar* name);
VALA_EXTERN xmlNode* template_group_save (TemplateGroup* self);
VALA_EXTERN void templates_load (Templates* self);
VALA_EXTERN void template_group_load (TemplateGroup* self,
                          xmlNode* node);
static void templates_finalize (Templates * obj);
static GType templates_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gchar*
template_type_to_string (TemplateType self)
{
	gchar* result;
	switch (self) {
		case TEMPLATE_TYPE_STYLE_GENERAL:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("style-general");
			result = _tmp0_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_NODE:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("style-node");
			result = _tmp1_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_CONNECTION:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("style-connection");
			result = _tmp2_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_CALLOUT:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("style-callout");
			result = _tmp3_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_BRANCH:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("style-option-branch");
			result = _tmp4_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_LINK:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("style-option-link");
			result = _tmp5_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_NODE:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup ("style-option-node");
			result = _tmp6_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_CONNECTION:
		{
			gchar* _tmp7_;
			_tmp7_ = g_strdup ("style-option-connection");
			result = _tmp7_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_CALLOUT:
		{
			gchar* _tmp8_;
			_tmp8_ = g_strdup ("style-option-callout");
			result = _tmp8_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

gchar*
template_type_label (TemplateType self)
{
	gchar* result;
	switch (self) {
		case TEMPLATE_TYPE_STYLE_GENERAL:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup (_ ("All Options"));
			result = _tmp0_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_NODE:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup (_ ("Node Options"));
			result = _tmp1_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_CONNECTION:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup (_ ("Connection Options"));
			result = _tmp2_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_CALLOUT:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("Callout Options"));
			result = _tmp3_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_BRANCH:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (_ ("Node Branch Options"));
			result = _tmp4_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_LINK:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup (_ ("Node Link Options"));
			result = _tmp5_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_NODE:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup (_ ("Node Options"));
			result = _tmp6_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_CONNECTION:
		{
			gchar* _tmp7_;
			_tmp7_ = g_strdup (_ ("Connection Options"));
			result = _tmp7_;
			return result;
		}
		case TEMPLATE_TYPE_STYLE_OPTION_CALLOUT:
		{
			gchar* _tmp8_;
			_tmp8_ = g_strdup (_ ("Callout Options"));
			result = _tmp8_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

TemplateType
template_type_parse (const gchar* val)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	static GQuark _tmp1_label7 = 0;
	static GQuark _tmp1_label8 = 0;
	TemplateType result;
	g_return_val_if_fail (val != NULL, 0);
	_tmp0_ = val;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("style-general")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_GENERAL;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("style-node")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_NODE;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("style-connection")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_CONNECTION;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("style-callout")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_CALLOUT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("style-option-branch")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_OPTION_BRANCH;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("style-option-link")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_OPTION_LINK;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("style-option-node")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_OPTION_NODE;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label7) ? _tmp1_label7 : (_tmp1_label7 = g_quark_from_static_string ("style-option-connection")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_OPTION_CONNECTION;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label8) ? _tmp1_label8 : (_tmp1_label8 = g_quark_from_static_string ("style-option-callout")))) {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_STYLE_OPTION_CALLOUT;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = TEMPLATE_TYPE_NUM;
				return result;
			}
		}
	}
}

Template*
template_type_create_template (TemplateType self,
                               const gchar* name)
{
	Template* result;
	g_return_val_if_fail (name != NULL, NULL);
	switch (self) {
		case TEMPLATE_TYPE_STYLE_GENERAL:
		case TEMPLATE_TYPE_STYLE_NODE:
		case TEMPLATE_TYPE_STYLE_CONNECTION:
		case TEMPLATE_TYPE_STYLE_CALLOUT:
		case TEMPLATE_TYPE_STYLE_OPTION_BRANCH:
		case TEMPLATE_TYPE_STYLE_OPTION_LINK:
		case TEMPLATE_TYPE_STYLE_OPTION_NODE:
		case TEMPLATE_TYPE_STYLE_OPTION_CONNECTION:
		case TEMPLATE_TYPE_STYLE_OPTION_CALLOUT:
		{
			StyleTemplate* _tmp0_;
			_tmp0_ = style_template_new (self, name);
			result = (Template*) _tmp0_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GType
template_type_get_type_once (void)
{
	static const GEnumValue values[] = {{TEMPLATE_TYPE_STYLE_GENERAL, "TEMPLATE_TYPE_STYLE_GENERAL", "style-general"}, {TEMPLATE_TYPE_STYLE_NODE, "TEMPLATE_TYPE_STYLE_NODE", "style-node"}, {TEMPLATE_TYPE_STYLE_CONNECTION, "TEMPLATE_TYPE_STYLE_CONNECTION", "style-connection"}, {TEMPLATE_TYPE_STYLE_CALLOUT, "TEMPLATE_TYPE_STYLE_CALLOUT", "style-callout"}, {TEMPLATE_TYPE_STYLE_OPTION_BRANCH, "TEMPLATE_TYPE_STYLE_OPTION_BRANCH", "style-option-branch"}, {TEMPLATE_TYPE_STYLE_OPTION_LINK, "TEMPLATE_TYPE_STYLE_OPTION_LINK", "style-option-link"}, {TEMPLATE_TYPE_STYLE_OPTION_NODE, "TEMPLATE_TYPE_STYLE_OPTION_NODE", "style-option-node"}, {TEMPLATE_TYPE_STYLE_OPTION_CONNECTION, "TEMPLATE_TYPE_STYLE_OPTION_CONNECTION", "style-option-connection"}, {TEMPLATE_TYPE_STYLE_OPTION_CALLOUT, "TEMPLATE_TYPE_STYLE_OPTION_CALLOUT", "style-option-callout"}, {TEMPLATE_TYPE_NUM, "TEMPLATE_TYPE_NUM", "num"}, {0, NULL, NULL}};
	GType template_type_type_id;
	template_type_type_id = g_enum_register_static ("TemplateType", values);
	return template_type_type_id;
}

GType
template_type_get_type (void)
{
	static volatile gsize template_type_type_id__once = 0;
	if (g_once_init_enter (&template_type_type_id__once)) {
		GType template_type_type_id;
		template_type_type_id = template_type_get_type_once ();
		g_once_init_leave (&template_type_type_id__once, template_type_type_id);
	}
	return template_type_type_id__once;
}

static void
_template_group_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (template_group_unref (var), NULL));
}

static void
_vala_TemplateGroup_free_function_content_of (gpointer data)
{
	TemplateGroup* self;
	self = *((TemplateGroup**) data);
	_template_group_unref0_ (self);
}

static void
_____lambda30_ (Templates* self)
{
	templates_save (self);
}

static void
______lambda30__template_group_changed (TemplateGroup* _sender,
                                        gpointer self)
{
	_____lambda30_ ((Templates*) self);
}

static gpointer
_template_group_ref0 (gpointer self)
{
	return self ? template_group_ref (self) : NULL;
}

Templates*
templates_construct (GType object_type)
{
	Templates* self = NULL;
	GArray* _tmp0_;
	self = (Templates*) g_type_create_instance (object_type);
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (TemplateGroup*));
	g_array_set_clear_func (_tmp0_, (GDestroyNotify) _vala_TemplateGroup_free_function_content_of);
	_g_array_unref0 (self->_template_groups);
	self->_template_groups = _tmp0_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				TemplateType ttype = 0;
				TemplateGroup* group = NULL;
				TemplateGroup* _tmp3_;
				TemplateGroup* _tmp4_;
				GArray* _tmp5_;
				TemplateGroup* _tmp6_;
				TemplateGroup* _tmp7_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				if (!(i < ((gint) TEMPLATE_TYPE_NUM))) {
					break;
				}
				ttype = (TemplateType) i;
				_tmp3_ = template_group_new (ttype);
				group = _tmp3_;
				_tmp4_ = group;
				g_signal_connect (_tmp4_, "changed", (GCallback) ______lambda30__template_group_changed, self);
				_tmp5_ = self->_template_groups;
				_tmp6_ = group;
				_tmp7_ = _template_group_ref0 (_tmp6_);
				g_array_append_val (_tmp5_, _tmp7_);
				_template_group_unref0 (group);
			}
		}
	}
	return self;
}

Templates*
templates_new (void)
{
	return templates_construct (TYPE_TEMPLATES);
}

TemplateGroup*
templates_get_template_group (Templates* self,
                              TemplateType ttype)
{
	GArray* _tmp0_;
	TemplateGroup* _tmp1_;
	TemplateGroup* _tmp2_;
	TemplateGroup* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->_template_groups;
	_tmp1_ = g_array_index (_tmp0_, TemplateGroup*, (guint) ((gint) ttype));
	_tmp2_ = _template_group_ref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

Template*
templates_get_template (Templates* self,
                        TemplateType ttype,
                        const gchar* name)
{
	GArray* _tmp0_;
	TemplateGroup* _tmp1_;
	Template* _tmp2_;
	Template* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->_template_groups;
	_tmp1_ = g_array_index (_tmp0_, TemplateGroup*, (guint) ((gint) ttype));
	_tmp2_ = template_group_get_template (_tmp1_, name);
	result = _tmp2_;
	return result;
}

void
templates_add_menus (Templates* self,
                     TemplateType ttype,
                     GtkWidget* w,
                     MainWindow* win,
                     TemplateAddLoadFunc add_func,
                     gpointer add_func_target,
                     TemplateAddLoadFunc load_func,
                     gpointer load_func_target,
                     TemplateDeleteFunc del_func,
                     gpointer del_func_target)
{
	GArray* _tmp0_;
	TemplateGroup* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	g_return_if_fail (win != NULL);
	_tmp0_ = self->_template_groups;
	_tmp1_ = g_array_index (_tmp0_, TemplateGroup*, (guint) ((gint) ttype));
	template_group_add_menus (_tmp1_, w, win, add_func, add_func_target, load_func, load_func_target, del_func, del_func_target);
}

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

GtkPopoverMenu*
templates_get_template_group_menu (Templates* self,
                                   TemplateType ttype)
{
	GArray* _tmp0_;
	TemplateGroup* _tmp1_;
	GtkPopoverMenu* _tmp2_;
	GtkPopoverMenu* _tmp3_;
	GtkPopoverMenu* _tmp4_;
	GtkPopoverMenu* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->_template_groups;
	_tmp1_ = g_array_index (_tmp0_, TemplateGroup*, (guint) ((gint) ttype));
	_tmp2_ = template_group_get_menu (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	result = _tmp4_;
	return result;
}

void
templates_add_template (Templates* self,
                        Template* template)
{
	GArray* _tmp0_;
	TemplateType _tmp1_;
	TemplateType _tmp2_;
	TemplateGroup* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (template != NULL);
	_tmp0_ = self->_template_groups;
	_tmp1_ = template_get_ttype (template);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_array_index (_tmp0_, TemplateGroup*, (guint) ((gint) _tmp2_));
	template_group_add_template (_tmp3_, template);
	templates_save (self);
}

void
templates_delete_template (Templates* self,
                           TemplateType ttype,
                           const gchar* name)
{
	GArray* _tmp0_;
	TemplateGroup* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = self->_template_groups;
	_tmp1_ = g_array_index (_tmp0_, TemplateGroup*, (guint) ((gint) ttype));
	template_group_delete_template (_tmp1_, name);
	templates_save (self);
}

void
templates_save (Templates* self)
{
	gchar* dir = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* fname = NULL;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	xmlDoc* doc = NULL;
	xmlDoc* _tmp5_;
	xmlNode* root = NULL;
	xmlNode* _tmp6_;
	xmlNode* _tmp7_;
	xmlDoc* _tmp8_;
	xmlNode* _tmp9_;
	xmlDoc* _tmp17_;
	const gchar* _tmp18_;
	xmlDoc* _tmp19_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "minder", NULL);
	dir = _tmp1_;
	_tmp2_ = dir;
	if (g_mkdir_with_parents (_tmp2_, 0775) != 0) {
		_g_free0 (dir);
		return;
	}
	_tmp3_ = dir;
	_tmp4_ = g_build_filename (_tmp3_, "templates.xml", NULL);
	fname = _tmp4_;
	_tmp5_ = xmlNewDoc ((xmlChar*) "1.0");
	doc = _tmp5_;
	_tmp6_ = xmlNewNode (NULL, (xmlChar*) "templates");
	root = _tmp6_;
	_tmp7_ = root;
	xmlNewProp (_tmp7_, (xmlChar*) "version", (xmlChar*) "2");
	_tmp8_ = doc;
	_tmp9_ = root;
	xmlDocSetRootElement (_tmp8_, _tmp9_);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp10_ = FALSE;
			_tmp10_ = TRUE;
			while (TRUE) {
				GArray* _tmp12_;
				xmlNode* _tmp13_;
				GArray* _tmp14_;
				TemplateGroup* _tmp15_;
				xmlNode* _tmp16_;
				if (!_tmp10_) {
					gint _tmp11_;
					_tmp11_ = i;
					i = _tmp11_ + 1;
				}
				_tmp10_ = FALSE;
				_tmp12_ = self->_template_groups;
				if (!(((guint) i) < _tmp12_->len)) {
					break;
				}
				_tmp13_ = root;
				_tmp14_ = self->_template_groups;
				_tmp15_ = g_array_index (_tmp14_, TemplateGroup*, (guint) i);
				_tmp16_ = template_group_save (_tmp15_);
				xmlAddChild (_tmp13_, _tmp16_);
			}
		}
	}
	_tmp17_ = doc;
	_tmp18_ = fname;
	xmlSaveFormatFile (_tmp18_, _tmp17_, 1);
	_tmp19_ = doc;
	_xmlFreeDoc0 (_tmp19_);
	_g_free0 (fname);
	_g_free0 (dir);
}

void
templates_load (Templates* self)
{
	gchar* fname = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	xmlDoc* doc = NULL;
	const gchar* _tmp3_;
	xmlDoc* _tmp4_;
	xmlDoc* _tmp5_;
	xmlNode* root = NULL;
	xmlDoc* _tmp6_;
	xmlNode* _tmp7_;
	gchar* version = NULL;
	xmlNode* _tmp8_;
	gchar* _tmp9_;
	xmlDoc* _tmp27_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "minder", "templates.xml", NULL);
	fname = _tmp1_;
	_tmp2_ = fname;
	if (!g_file_test (_tmp2_, G_FILE_TEST_EXISTS)) {
		_g_free0 (fname);
		return;
	}
	_tmp3_ = fname;
	_tmp4_ = xmlParseFile (_tmp3_);
	doc = _tmp4_;
	_tmp5_ = doc;
	if (_tmp5_ == NULL) {
		_g_free0 (fname);
		return;
	}
	_tmp6_ = doc;
	_tmp7_ = xmlDocGetRootElement (_tmp6_);
	root = _tmp7_;
	_tmp8_ = root;
	_tmp9_ = (gchar*) xmlGetProp (_tmp8_, (xmlChar*) "version");
	version = _tmp9_;
	{
		xmlNode* it = NULL;
		xmlNode* _tmp10_;
		xmlNode* _tmp11_;
		_tmp10_ = root;
		_tmp11_ = _tmp10_->children;
		it = _tmp11_;
		{
			gboolean _tmp12_ = FALSE;
			_tmp12_ = TRUE;
			while (TRUE) {
				xmlNode* _tmp15_;
				gboolean _tmp16_ = FALSE;
				xmlNode* _tmp17_;
				if (!_tmp12_) {
					xmlNode* _tmp13_;
					xmlNode* _tmp14_;
					_tmp13_ = it;
					_tmp14_ = _tmp13_->next;
					it = _tmp14_;
				}
				_tmp12_ = FALSE;
				_tmp15_ = it;
				if (!(_tmp15_ != NULL)) {
					break;
				}
				_tmp17_ = it;
				if (_tmp17_->type == XML_ELEMENT_NODE) {
					xmlNode* _tmp18_;
					const gchar* _tmp19_;
					_tmp18_ = it;
					_tmp19_ = _tmp18_->name;
					_tmp16_ = g_strcmp0 (_tmp19_, "template-group") == 0;
				} else {
					_tmp16_ = FALSE;
				}
				if (_tmp16_) {
					gchar* gt = NULL;
					xmlNode* _tmp20_;
					gchar* _tmp21_;
					const gchar* _tmp22_;
					_tmp20_ = it;
					_tmp21_ = (gchar*) xmlGetProp (_tmp20_, (xmlChar*) "name");
					gt = _tmp21_;
					_tmp22_ = gt;
					if (_tmp22_ != NULL) {
						gint group_index = 0;
						const gchar* _tmp23_;
						GArray* _tmp24_;
						TemplateGroup* _tmp25_;
						xmlNode* _tmp26_;
						_tmp23_ = gt;
						group_index = (gint) template_type_parse (_tmp23_);
						_tmp24_ = self->_template_groups;
						_tmp25_ = g_array_index (_tmp24_, TemplateGroup*, (guint) group_index);
						_tmp26_ = it;
						template_group_load (_tmp25_, _tmp26_);
					}
					_g_free0 (gt);
				}
			}
		}
	}
	_tmp27_ = doc;
	_xmlFreeDoc0 (_tmp27_);
	_g_free0 (version);
	_g_free0 (fname);
}

static void
value_templates_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
value_templates_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		templates_unref (value->data[0].v_pointer);
	}
}

static void
value_templates_copy_value (const GValue* src_value,
                            GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = templates_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
value_templates_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
value_templates_collect_value (GValue* value,
                               guint n_collect_values,
                               GTypeCValue* collect_values,
                               guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		Templates * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = templates_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
value_templates_lcopy_value (const GValue* value,
                             guint n_collect_values,
                             GTypeCValue* collect_values,
                             guint collect_flags)
{
	Templates ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = templates_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
param_spec_templates (const gchar* name,
                      const gchar* nick,
                      const gchar* blurb,
                      GType object_type,
                      GParamFlags flags)
{
	ParamSpecTemplates* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_TEMPLATES), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
value_get_templates (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_TEMPLATES), NULL);
	return value->data[0].v_pointer;
}

void
value_set_templates (GValue* value,
                     gpointer v_object)
{
	Templates * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_TEMPLATES));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_TEMPLATES));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		templates_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		templates_unref (old);
	}
}

void
value_take_templates (GValue* value,
                      gpointer v_object)
{
	Templates * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_TEMPLATES));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_TEMPLATES));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		templates_unref (old);
	}
}

static void
templates_class_init (TemplatesClass * klass,
                      gpointer klass_data)
{
	templates_parent_class = g_type_class_peek_parent (klass);
	((TemplatesClass *) klass)->finalize = templates_finalize;
}

static void
templates_instance_init (Templates * self,
                         gpointer klass)
{
	self->ref_count = 1;
}

static void
templates_finalize (Templates * obj)
{
	Templates * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEMPLATES, Templates);
	g_signal_handlers_destroy (self);
	_g_array_unref0 (self->_template_groups);
}

static GType
templates_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { value_templates_init, value_templates_free_value, value_templates_copy_value, value_templates_peek_pointer, "p", value_templates_collect_value, "p", value_templates_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (TemplatesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) templates_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Templates), 0, (GInstanceInitFunc) templates_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType templates_type_id;
	templates_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Templates", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return templates_type_id;
}

GType
templates_get_type (void)
{
	static volatile gsize templates_type_id__once = 0;
	if (g_once_init_enter (&templates_type_id__once)) {
		GType templates_type_id;
		templates_type_id = templates_get_type_once ();
		g_once_init_leave (&templates_type_id__once, templates_type_id);
	}
	return templates_type_id__once;
}

gpointer
templates_ref (gpointer instance)
{
	Templates * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
templates_unref (gpointer instance)
{
	Templates * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		TEMPLATES_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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;
}

