/* templates.c generated by valac 0.26.0.93-693b8, the Vala compiler
 * generated from templates.vala, do not modify */

/*
 * This file is part of LaTeXila.
 *
 * Copyright © 2010-2012 Sébastien Wilmet
 *
 * LaTeXila 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.
 *
 * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include "config.h"


#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 TEMPLATES_TYPE_TEMPLATE_COLUMN (templates_template_column_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
#define _g_markup_parse_context_unref0(var) ((var == NULL) ? NULL : (var = (g_markup_parse_context_unref (var), NULL)))

struct _Templates {
	GObject parent_instance;
	TemplatesPrivate * priv;
};

struct _TemplatesClass {
	GObjectClass parent_class;
};

struct _TemplatesPrivate {
	GtkListStore* _default_store;
	GtkListStore* _personal_store;
	gint _nb_personal_templates;
	GFile* _data_dir;
	GFile* _rc_file;
	gchar* _default_template;
};

typedef enum  {
	TEMPLATES_TEMPLATE_COLUMN_PIXBUF,
	TEMPLATES_TEMPLATE_COLUMN_ICON_ID,
	TEMPLATES_TEMPLATE_COLUMN_NAME,
	TEMPLATES_TEMPLATE_COLUMN_CONTENTS,
	TEMPLATES_TEMPLATE_COLUMN_N_COLUMNS
} TemplatesTemplateColumn;


static gpointer templates_parent_class = NULL;
static Templates* templates__instance;
static Templates* templates__instance = NULL;

GType templates_get_type (void) G_GNUC_CONST;
#define TEMPLATES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_TEMPLATES, TemplatesPrivate))
enum  {
	TEMPLATES_DUMMY_PROPERTY
};
static GType templates_template_column_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
static Templates* templates_new (void);
static Templates* templates_construct (GType object_type);
static void templates_init_default_templates (Templates* self);
static void templates_init_personal_templates (Templates* self);
Templates* templates_get_default (void);
static GtkListStore* templates_create_new_store (Templates* self);
static void templates_add_template_from_string (Templates* self, GtkListStore* store, const gchar* name, const gchar* icon_id, const gchar* contents);
static void templates_add_default_template (Templates* self, const gchar* name, const gchar* icon_id, const gchar* filename);
static GFile* templates_get_personal_template_file (Templates* self, gint template_num);
static gboolean templates_add_template_from_file (Templates* self, GtkListStore* store, const gchar* name, const gchar* icon_id, GFile* file);
gchar* utils_load_file (GFile* file);
static void templates_parser_text (Templates* self, GMarkupParseContext* context, const gchar* text, gsize text_len, GError** error);
static void _templates_parser_text_gmarkup_parser_text_func (GMarkupParseContext* context, const gchar* text, gsize text_len, gpointer self, GError** error);
static gchar* templates_get_theme_icon (Templates* self, const gchar* icon_id);
void templates_delete_personal_template (Templates* self, GtkTreePath* template_path);
void utils_delete_file (GFile* file);
void templates_create_personal_template (Templates* self, const gchar* name, const gchar* icon_id, const gchar* contents);
void templates_save_rc_file (Templates* self);
gboolean utils_save_file (GFile* file, const gchar* contents, gboolean make_backup);
gchar* templates_get_icon_id (Templates* self, GtkTreePath* default_template_path);
gchar* templates_get_default_template_contents (Templates* self, GtkTreePath* path);
static gchar* templates_get_template_contents (Templates* self, GtkListStore* store, GtkTreePath* path);
gchar* templates_get_personal_template_contents (Templates* self, GtkTreePath* path);
GtkTreeView* templates_get_default_templates_list (Templates* self);
static GtkTreeView* templates_get_templates_list (Templates* self, GtkListStore* store);
GtkTreeView* templates_get_personal_templates_list (Templates* self);
static void templates_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static GType templates_template_column_get_type (void) {
	static volatile gsize templates_template_column_type_id__volatile = 0;
	if (g_once_init_enter (&templates_template_column_type_id__volatile)) {
		static const GEnumValue values[] = {{TEMPLATES_TEMPLATE_COLUMN_PIXBUF, "TEMPLATES_TEMPLATE_COLUMN_PIXBUF", "pixbuf"}, {TEMPLATES_TEMPLATE_COLUMN_ICON_ID, "TEMPLATES_TEMPLATE_COLUMN_ICON_ID", "icon-id"}, {TEMPLATES_TEMPLATE_COLUMN_NAME, "TEMPLATES_TEMPLATE_COLUMN_NAME", "name"}, {TEMPLATES_TEMPLATE_COLUMN_CONTENTS, "TEMPLATES_TEMPLATE_COLUMN_CONTENTS", "contents"}, {TEMPLATES_TEMPLATE_COLUMN_N_COLUMNS, "TEMPLATES_TEMPLATE_COLUMN_N_COLUMNS", "n-columns"}, {0, NULL, NULL}};
		GType templates_template_column_type_id;
		templates_template_column_type_id = g_enum_register_static ("TemplatesTemplateColumn", values);
		g_once_init_leave (&templates_template_column_type_id__volatile, templates_template_column_type_id);
	}
	return templates_template_column_type_id__volatile;
}


static Templates* templates_construct (GType object_type) {
	Templates * self = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	GFile* _tmp3_ = NULL;
	GFile* _tmp4_ = NULL;
	GFile* _tmp5_ = NULL;
	self = (Templates*) g_object_new (object_type, NULL);
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "latexila", NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	_g_object_unref0 (self->priv->_data_dir);
	self->priv->_data_dir = _tmp3_;
	_g_free0 (_tmp2_);
	_tmp4_ = self->priv->_data_dir;
	_tmp5_ = g_file_get_child (_tmp4_, "templatesrc");
	_g_object_unref0 (self->priv->_rc_file);
	self->priv->_rc_file = _tmp5_;
	templates_init_default_templates (self);
	templates_init_personal_templates (self);
	return self;
}


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


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


Templates* templates_get_default (void) {
	Templates* result = NULL;
	Templates* _tmp0_ = NULL;
	Templates* _tmp2_ = NULL;
	Templates* _tmp3_ = NULL;
	_tmp0_ = templates__instance;
	if (_tmp0_ == NULL) {
		Templates* _tmp1_ = NULL;
		_tmp1_ = templates_new ();
		_g_object_unref0 (templates__instance);
		templates__instance = _tmp1_;
	}
	_tmp2_ = templates__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


static void templates_init_default_templates (Templates* self) {
	GtkListStore* _tmp0_ = NULL;
	GtkListStore* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = templates_create_new_store (self);
	_g_object_unref0 (self->priv->_default_store);
	self->priv->_default_store = _tmp0_;
	_tmp1_ = self->priv->_default_store;
	_tmp2_ = _ ("Empty");
	templates_add_template_from_string (self, _tmp1_, _tmp2_, "empty", "");
	_tmp3_ = _ ("Article");
	templates_add_default_template (self, _tmp3_, "article", "article.xml");
	_tmp4_ = _ ("Report");
	templates_add_default_template (self, _tmp4_, "report", "report.xml");
	_tmp5_ = _ ("Book");
	templates_add_default_template (self, _tmp5_, "book", "book.xml");
	_tmp6_ = _ ("Letter");
	templates_add_default_template (self, _tmp6_, "letter", "letter.xml");
	_tmp7_ = _ ("Presentation");
	templates_add_default_template (self, _tmp7_, "beamer", "beamer.xml");
}


static void templates_init_personal_templates (Templates* self) {
	GtkListStore* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GKeyFile* key_file = NULL;
	GKeyFile* _tmp3_ = NULL;
	gchar** names = NULL;
	gint names_length1 = 0;
	gint _names_size_ = 0;
	gchar** icons = NULL;
	gint icons_length1 = 0;
	gint _icons_size_ = 0;
	gchar** _tmp20_ = NULL;
	gint _tmp20__length1 = 0;
	gchar** _tmp21_ = NULL;
	gint _tmp21__length1 = 0;
	gint nb_templates = 0;
	gchar** _tmp22_ = NULL;
	gint _tmp22__length1 = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = templates_create_new_store (self);
	_g_object_unref0 (self->priv->_personal_store);
	self->priv->_personal_store = _tmp0_;
	self->priv->_nb_personal_templates = 0;
	_tmp1_ = self->priv->_rc_file;
	_tmp2_ = g_file_query_exists (_tmp1_, NULL);
	if (!_tmp2_) {
		return;
	}
	_tmp3_ = g_key_file_new ();
	key_file = _tmp3_;
	{
		GKeyFile* _tmp4_ = NULL;
		GFile* _tmp5_ = NULL;
		gchar* _tmp6_ = NULL;
		gchar* _tmp7_ = NULL;
		gchar** _tmp8_ = NULL;
		GKeyFile* _tmp9_ = NULL;
		gsize _tmp10_;
		gchar** _tmp11_ = NULL;
		gint _tmp8__length1 = 0;
		gint __tmp8__size_ = 0;
		gchar** _tmp12_ = NULL;
		gint _tmp12__length1 = 0;
		gchar** _tmp13_ = NULL;
		GKeyFile* _tmp14_ = NULL;
		gsize _tmp15_;
		gchar** _tmp16_ = NULL;
		gint _tmp13__length1 = 0;
		gint __tmp13__size_ = 0;
		gchar** _tmp17_ = NULL;
		gint _tmp17__length1 = 0;
		_tmp4_ = key_file;
		_tmp5_ = self->priv->_rc_file;
		_tmp6_ = g_file_get_path (_tmp5_);
		_tmp7_ = _tmp6_;
		g_key_file_load_from_file (_tmp4_, _tmp7_, G_KEY_FILE_NONE, &_inner_error_);
		_g_free0 (_tmp7_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch45_g_error;
		}
		_tmp9_ = key_file;
		_tmp11_ = g_key_file_get_string_list (_tmp9_, PACKAGE_NAME, "names", &_tmp10_, &_inner_error_);
		_tmp8_ = _tmp11_;
		_tmp8__length1 = _tmp10_;
		__tmp8__size_ = _tmp8__length1;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch45_g_error;
		}
		_tmp12_ = _tmp8_;
		_tmp12__length1 = _tmp8__length1;
		_tmp8_ = NULL;
		_tmp8__length1 = 0;
		names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
		names = _tmp12_;
		names_length1 = _tmp12__length1;
		_names_size_ = names_length1;
		_tmp14_ = key_file;
		_tmp16_ = g_key_file_get_string_list (_tmp14_, PACKAGE_NAME, "icons", &_tmp15_, &_inner_error_);
		_tmp13_ = _tmp16_;
		_tmp13__length1 = _tmp15_;
		__tmp13__size_ = _tmp13__length1;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
			goto __catch45_g_error;
		}
		_tmp17_ = _tmp13_;
		_tmp17__length1 = _tmp13__length1;
		_tmp13_ = NULL;
		_tmp13__length1 = 0;
		icons = (_vala_array_free (icons, icons_length1, (GDestroyNotify) g_free), NULL);
		icons = _tmp17_;
		icons_length1 = _tmp17__length1;
		_icons_size_ = icons_length1;
		_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) g_free), NULL);
		_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
	}
	goto __finally45;
	__catch45_g_error:
	{
		GError* e = NULL;
		GError* _tmp18_ = NULL;
		const gchar* _tmp19_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp18_ = e;
		_tmp19_ = _tmp18_->message;
		g_warning ("templates.vala:108: Load templates failed: %s", _tmp19_);
		_g_error_free0 (e);
		icons = (_vala_array_free (icons, icons_length1, (GDestroyNotify) g_free), NULL);
		names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
		_g_key_file_unref0 (key_file);
		return;
	}
	__finally45:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		icons = (_vala_array_free (icons, icons_length1, (GDestroyNotify) g_free), NULL);
		names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
		_g_key_file_unref0 (key_file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp20_ = names;
	_tmp20__length1 = names_length1;
	_tmp21_ = icons;
	_tmp21__length1 = icons_length1;
	g_return_if_fail (_tmp20__length1 == _tmp21__length1);
	_tmp22_ = names;
	_tmp22__length1 = names_length1;
	nb_templates = _tmp22__length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp23_ = FALSE;
			_tmp23_ = TRUE;
			while (TRUE) {
				gint _tmp25_ = 0;
				gint _tmp26_ = 0;
				GFile* file = NULL;
				gint _tmp27_ = 0;
				GFile* _tmp28_ = NULL;
				GFile* _tmp29_ = NULL;
				gboolean _tmp30_ = FALSE;
				GtkListStore* _tmp34_ = NULL;
				gchar** _tmp35_ = NULL;
				gint _tmp35__length1 = 0;
				gint _tmp36_ = 0;
				const gchar* _tmp37_ = NULL;
				gchar** _tmp38_ = NULL;
				gint _tmp38__length1 = 0;
				gint _tmp39_ = 0;
				const gchar* _tmp40_ = NULL;
				GFile* _tmp41_ = NULL;
				gboolean _tmp42_ = FALSE;
				if (!_tmp23_) {
					gint _tmp24_ = 0;
					_tmp24_ = i;
					i = _tmp24_ + 1;
				}
				_tmp23_ = FALSE;
				_tmp25_ = i;
				_tmp26_ = nb_templates;
				if (!(_tmp25_ < _tmp26_)) {
					break;
				}
				_tmp27_ = i;
				_tmp28_ = templates_get_personal_template_file (self, _tmp27_);
				file = _tmp28_;
				_tmp29_ = file;
				_tmp30_ = g_file_query_exists (_tmp29_, NULL);
				if (!_tmp30_) {
					gchar** _tmp31_ = NULL;
					gint _tmp31__length1 = 0;
					gint _tmp32_ = 0;
					const gchar* _tmp33_ = NULL;
					_tmp31_ = names;
					_tmp31__length1 = names_length1;
					_tmp32_ = i;
					_tmp33_ = _tmp31_[_tmp32_];
					g_warning ("templates.vala:121: The template '%s' doesn't exist.", _tmp33_);
					_g_object_unref0 (file);
					continue;
				}
				_tmp34_ = self->priv->_personal_store;
				_tmp35_ = names;
				_tmp35__length1 = names_length1;
				_tmp36_ = i;
				_tmp37_ = _tmp35_[_tmp36_];
				_tmp38_ = icons;
				_tmp38__length1 = icons_length1;
				_tmp39_ = i;
				_tmp40_ = _tmp38_[_tmp39_];
				_tmp41_ = file;
				_tmp42_ = templates_add_template_from_file (self, _tmp34_, _tmp37_, _tmp40_, _tmp41_);
				if (_tmp42_) {
					gint _tmp43_ = 0;
					_tmp43_ = self->priv->_nb_personal_templates;
					self->priv->_nb_personal_templates = _tmp43_ + 1;
				}
				_g_object_unref0 (file);
			}
		}
	}
	icons = (_vala_array_free (icons, icons_length1, (GDestroyNotify) g_free), NULL);
	names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
	_g_key_file_unref0 (key_file);
}


static GtkListStore* templates_create_new_store (Templates* self) {
	GtkListStore* result = NULL;
	GtkListStore* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gtk_list_store_new ((gint) TEMPLATES_TEMPLATE_COLUMN_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, -1);
	result = _tmp0_;
	return result;
}


static GFile* templates_get_personal_template_file (Templates* self, gint template_num) {
	GFile* result = NULL;
	gchar* filename = NULL;
	gint _tmp0_ = 0;
	gchar* _tmp1_ = NULL;
	GFile* _tmp2_ = NULL;
	GFile* _tmp3_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = template_num;
	_tmp1_ = g_strdup_printf ("%d.tex", _tmp0_);
	filename = _tmp1_;
	_tmp2_ = self->priv->_data_dir;
	_tmp3_ = g_file_get_child (_tmp2_, filename);
	result = _tmp3_;
	_g_free0 (filename);
	return result;
}


/*************************************************************************/
static void _templates_parser_text_gmarkup_parser_text_func (GMarkupParseContext* context, const gchar* text, gsize text_len, gpointer self, GError** error) {
	templates_parser_text ((Templates*) self, context, text, text_len, error);
}


static void templates_add_default_template (Templates* self, const gchar* name, const gchar* icon_id, const gchar* filename) {
	gchar* path = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	GFile* file = NULL;
	const gchar* _tmp2_ = NULL;
	GFile* _tmp3_ = NULL;
	GFile* _tmp4_ = NULL;
	gboolean _tmp5_ = FALSE;
	gchar* contents = NULL;
	GFile* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	const gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	GtkListStore* _tmp20_ = NULL;
	const gchar* _tmp21_ = NULL;
	const gchar* _tmp22_ = NULL;
	const gchar* _tmp23_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (icon_id != NULL);
	g_return_if_fail (filename != NULL);
	_tmp0_ = filename;
	_tmp1_ = g_build_filename (DATA_DIR, "templates", _tmp0_, NULL);
	path = _tmp1_;
	_tmp2_ = path;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	file = _tmp3_;
	_tmp4_ = file;
	_tmp5_ = g_file_query_exists (_tmp4_, NULL);
	if (!_tmp5_) {
		const gchar* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		_tmp6_ = name;
		_tmp7_ = path;
		g_warning ("templates.vala:162: The default template '%s' doesn't exist. Path: %s", _tmp6_, _tmp7_);
		_g_object_unref0 (file);
		_g_free0 (path);
		return;
	}
	_tmp8_ = file;
	_tmp9_ = utils_load_file (_tmp8_);
	contents = _tmp9_;
	_tmp10_ = contents;
	g_return_if_fail (_tmp10_ != NULL);
	_tmp11_ = g_strdup ("");
	_g_free0 (self->priv->_default_template);
	self->priv->_default_template = _tmp11_;
	{
		GMarkupParser parser = {0};
		GMarkupParser _tmp12_ = {0};
		GMarkupParseContext* context = NULL;
		GMarkupParser _tmp13_ = {0};
		GMarkupParseContext* _tmp14_ = NULL;
		GMarkupParseContext* _tmp15_ = NULL;
		const gchar* _tmp16_ = NULL;
		_tmp12_.start_element = NULL;
		_tmp12_.end_element = NULL;
		_tmp12_.text = _templates_parser_text_gmarkup_parser_text_func;
		_tmp12_.passthrough = NULL;
		_tmp12_.error = NULL;
		parser = _tmp12_;
		_tmp13_ = parser;
		_tmp14_ = g_markup_parse_context_new (&_tmp13_, 0, self, NULL);
		context = _tmp14_;
		_tmp15_ = context;
		_tmp16_ = contents;
		g_markup_parse_context_parse (_tmp15_, _tmp16_, (gssize) (-1), &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_markup_parse_context_unref0 (context);
			goto __catch46_g_error;
		}
		_g_markup_parse_context_unref0 (context);
	}
	goto __finally46;
	__catch46_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp17_ = NULL;
		GError* _tmp18_ = NULL;
		const gchar* _tmp19_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp17_ = name;
		_tmp18_ = e;
		_tmp19_ = _tmp18_->message;
		g_warning ("templates.vala:181: Impossible to load the default template '%s': %s", _tmp17_, _tmp19_);
		_g_error_free0 (e);
		_g_free0 (contents);
		_g_object_unref0 (file);
		_g_free0 (path);
		return;
	}
	__finally46:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_free0 (contents);
		_g_object_unref0 (file);
		_g_free0 (path);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp20_ = self->priv->_default_store;
	_tmp21_ = name;
	_tmp22_ = icon_id;
	_tmp23_ = self->priv->_default_template;
	templates_add_template_from_string (self, _tmp20_, _tmp21_, _tmp22_, _tmp23_);
	_g_free0 (contents);
	_g_object_unref0 (file);
	_g_free0 (path);
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	glong _tmp0_ = 0L;
	gchar _tmp1_ = '\0';
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = index;
	_tmp1_ = ((gchar*) self)[_tmp0_];
	result = _tmp1_;
	return result;
}


static gchar* string_slice (const gchar* self, glong start, glong end) {
	gchar* result = NULL;
	glong string_length = 0L;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	glong _tmp2_ = 0L;
	glong _tmp5_ = 0L;
	gboolean _tmp8_ = FALSE;
	glong _tmp9_ = 0L;
	gboolean _tmp12_ = FALSE;
	glong _tmp13_ = 0L;
	glong _tmp16_ = 0L;
	glong _tmp17_ = 0L;
	glong _tmp18_ = 0L;
	glong _tmp19_ = 0L;
	glong _tmp20_ = 0L;
	gchar* _tmp21_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	_tmp2_ = start;
	if (_tmp2_ < ((glong) 0)) {
		glong _tmp3_ = 0L;
		glong _tmp4_ = 0L;
		_tmp3_ = string_length;
		_tmp4_ = start;
		start = _tmp3_ + _tmp4_;
	}
	_tmp5_ = end;
	if (_tmp5_ < ((glong) 0)) {
		glong _tmp6_ = 0L;
		glong _tmp7_ = 0L;
		_tmp6_ = string_length;
		_tmp7_ = end;
		end = _tmp6_ + _tmp7_;
	}
	_tmp9_ = start;
	if (_tmp9_ >= ((glong) 0)) {
		glong _tmp10_ = 0L;
		glong _tmp11_ = 0L;
		_tmp10_ = start;
		_tmp11_ = string_length;
		_tmp8_ = _tmp10_ <= _tmp11_;
	} else {
		_tmp8_ = FALSE;
	}
	g_return_val_if_fail (_tmp8_, NULL);
	_tmp13_ = end;
	if (_tmp13_ >= ((glong) 0)) {
		glong _tmp14_ = 0L;
		glong _tmp15_ = 0L;
		_tmp14_ = end;
		_tmp15_ = string_length;
		_tmp12_ = _tmp14_ <= _tmp15_;
	} else {
		_tmp12_ = FALSE;
	}
	g_return_val_if_fail (_tmp12_, NULL);
	_tmp16_ = start;
	_tmp17_ = end;
	g_return_val_if_fail (_tmp16_ <= _tmp17_, NULL);
	_tmp18_ = start;
	_tmp19_ = end;
	_tmp20_ = start;
	_tmp21_ = g_strndup (((gchar*) self) + _tmp18_, (gsize) (_tmp19_ - _tmp20_));
	result = _tmp21_;
	return result;
}


static void templates_parser_text (Templates* self, GMarkupParseContext* context, const gchar* text, gsize text_len, GError** error) {
	gchar* chunk = NULL;
	GMarkupParseContext* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	GQuark _tmp4_ = 0U;
	static GQuark _tmp3_label0 = 0;
	static GQuark _tmp3_label1 = 0;
	static GQuark _tmp3_label2 = 0;
	const gchar* _tmp17_ = NULL;
	const gchar* _tmp18_ = NULL;
	gchar _tmp19_ = '\0';
	const gchar* _tmp25_ = NULL;
	const gchar* _tmp26_ = NULL;
	gchar* _tmp27_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	g_return_if_fail (text != NULL);
	chunk = NULL;
	_tmp0_ = context;
	_tmp1_ = g_markup_parse_context_get_element (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
	if (_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("chunk")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp5_ = NULL;
				gchar* _tmp6_ = NULL;
				_tmp5_ = text;
				_tmp6_ = g_strdup (_tmp5_);
				_g_free0 (chunk);
				chunk = _tmp6_;
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("translatableChunk")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp7_ = NULL;
				const gchar* _tmp8_ = NULL;
				gchar* _tmp9_ = NULL;
				_tmp7_ = text;
				_tmp8_ = _ (_tmp7_);
				_tmp9_ = g_strdup (_tmp8_);
				_g_free0 (chunk);
				chunk = _tmp9_;
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label2) ? _tmp3_label2 : (_tmp3_label2 = g_quark_from_static_string ("babel")))) {
		switch (0) {
			default:
			{
				gchar* translated_text = NULL;
				const gchar* _tmp10_ = NULL;
				const gchar* _tmp11_ = NULL;
				gchar* _tmp12_ = NULL;
				const gchar* _tmp13_ = NULL;
				const gchar* _tmp14_ = NULL;
				_tmp10_ = text;
				_tmp11_ = _ (_tmp10_);
				_tmp12_ = g_strdup (_tmp11_);
				translated_text = _tmp12_;
				_tmp13_ = translated_text;
				_tmp14_ = text;
				if (g_strcmp0 (_tmp13_, _tmp14_) != 0) {
					const gchar* _tmp15_ = NULL;
					gchar* _tmp16_ = NULL;
					_tmp15_ = translated_text;
					_tmp16_ = g_strdup (_tmp15_);
					_g_free0 (chunk);
					chunk = _tmp16_;
				}
				_g_free0 (translated_text);
				break;
			}
		}
	}
	_tmp17_ = chunk;
	if (_tmp17_ == NULL) {
		_g_free0 (chunk);
		return;
	}
	_tmp18_ = chunk;
	_tmp19_ = string_get (_tmp18_, (glong) 0);
	if (_tmp19_ == '\n') {
		const gchar* _tmp20_ = NULL;
		const gchar* _tmp21_ = NULL;
		gint _tmp22_ = 0;
		gint _tmp23_ = 0;
		gchar* _tmp24_ = NULL;
		_tmp20_ = chunk;
		_tmp21_ = chunk;
		_tmp22_ = strlen (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp24_ = string_slice (_tmp20_, (glong) 1, (glong) _tmp23_);
		_g_free0 (chunk);
		chunk = _tmp24_;
	}
	_tmp25_ = self->priv->_default_template;
	_tmp26_ = chunk;
	_tmp27_ = g_strconcat (_tmp25_, _tmp26_, NULL);
	_g_free0 (self->priv->_default_template);
	self->priv->_default_template = _tmp27_;
	_g_free0 (chunk);
}


/*************************************************************************/
static void templates_add_template_from_string (Templates* self, GtkListStore* store, const gchar* name, const gchar* icon_id, const gchar* contents) {
	GtkTreeIter iter = {0};
	GtkListStore* _tmp0_ = NULL;
	GtkTreeIter _tmp1_ = {0};
	GtkListStore* _tmp2_ = NULL;
	GtkTreeIter _tmp3_ = {0};
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	const gchar* _tmp9_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (store != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (icon_id != NULL);
	g_return_if_fail (contents != NULL);
	_tmp0_ = store;
	gtk_list_store_append (_tmp0_, &_tmp1_);
	iter = _tmp1_;
	_tmp2_ = store;
	_tmp3_ = iter;
	_tmp4_ = icon_id;
	_tmp5_ = templates_get_theme_icon (self, _tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = icon_id;
	_tmp8_ = name;
	_tmp9_ = contents;
	gtk_list_store_set (_tmp2_, &_tmp3_, TEMPLATES_TEMPLATE_COLUMN_PIXBUF, _tmp6_, TEMPLATES_TEMPLATE_COLUMN_ICON_ID, _tmp7_, TEMPLATES_TEMPLATE_COLUMN_NAME, _tmp8_, TEMPLATES_TEMPLATE_COLUMN_CONTENTS, _tmp9_, -1);
	_g_free0 (_tmp6_);
}


static gboolean templates_add_template_from_file (Templates* self, GtkListStore* store, const gchar* name, const gchar* icon_id, GFile* file) {
	gboolean result = FALSE;
	gchar* contents = NULL;
	GFile* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	GtkListStore* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (store != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	g_return_val_if_fail (icon_id != NULL, FALSE);
	g_return_val_if_fail (file != NULL, FALSE);
	_tmp0_ = file;
	_tmp1_ = utils_load_file (_tmp0_);
	contents = _tmp1_;
	_tmp2_ = contents;
	if (_tmp2_ == NULL) {
		result = FALSE;
		_g_free0 (contents);
		return result;
	}
	_tmp3_ = store;
	_tmp4_ = name;
	_tmp5_ = icon_id;
	_tmp6_ = contents;
	templates_add_template_from_string (self, _tmp3_, _tmp4_, _tmp5_, _tmp6_);
	result = TRUE;
	_g_free0 (contents);
	return result;
}


void templates_delete_personal_template (Templates* self, GtkTreePath* template_path) {
	GtkTreeModel* model = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeModel* _tmp1_ = NULL;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp2_ = NULL;
	GtkTreePath* _tmp3_ = NULL;
	GtkTreeIter _tmp4_ = {0};
	GtkListStore* _tmp5_ = NULL;
	GtkTreeIter _tmp6_ = {0};
	gint template_num = 0;
	GtkTreePath* _tmp7_ = NULL;
	gint _tmp8_ = 0;
	gint* _tmp9_ = NULL;
	gint _tmp10_ = 0;
	GFile* template_file = NULL;
	gint _tmp11_ = 0;
	GFile* _tmp12_ = NULL;
	GFile* _tmp13_ = NULL;
	gint _tmp27_ = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (template_path != NULL);
	_tmp0_ = self->priv->_personal_store;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, GTK_TYPE_TREE_MODEL, GtkTreeModel));
	model = _tmp1_;
	_tmp2_ = model;
	_tmp3_ = template_path;
	gtk_tree_model_get_iter (_tmp2_, &_tmp4_, _tmp3_);
	iter = _tmp4_;
	_tmp5_ = self->priv->_personal_store;
	_tmp6_ = iter;
	gtk_list_store_remove (_tmp5_, &_tmp6_);
	_tmp7_ = template_path;
	_tmp9_ = gtk_tree_path_get_indices_with_depth (_tmp7_, &_tmp8_);
	_tmp10_ = _tmp9_[0];
	template_num = _tmp10_;
	_tmp11_ = template_num;
	_tmp12_ = templates_get_personal_template_file (self, _tmp11_);
	template_file = _tmp12_;
	_tmp13_ = template_file;
	utils_delete_file (_tmp13_);
	{
		gint i = 0;
		gint _tmp14_ = 0;
		_tmp14_ = template_num;
		i = _tmp14_ + 1;
		{
			gboolean _tmp15_ = FALSE;
			_tmp15_ = TRUE;
			while (TRUE) {
				gint _tmp17_ = 0;
				gint _tmp18_ = 0;
				GFile* file = NULL;
				gint _tmp19_ = 0;
				GFile* _tmp20_ = NULL;
				GFile* new_file = NULL;
				gint _tmp21_ = 0;
				GFile* _tmp22_ = NULL;
				if (!_tmp15_) {
					gint _tmp16_ = 0;
					_tmp16_ = i;
					i = _tmp16_ + 1;
				}
				_tmp15_ = FALSE;
				_tmp17_ = i;
				_tmp18_ = self->priv->_nb_personal_templates;
				if (!(_tmp17_ < _tmp18_)) {
					break;
				}
				_tmp19_ = i;
				_tmp20_ = templates_get_personal_template_file (self, _tmp19_);
				file = _tmp20_;
				_tmp21_ = i;
				_tmp22_ = templates_get_personal_template_file (self, _tmp21_ - 1);
				new_file = _tmp22_;
				{
					GFile* _tmp23_ = NULL;
					GFile* _tmp24_ = NULL;
					_tmp23_ = file;
					_tmp24_ = new_file;
					g_file_move (_tmp23_, _tmp24_, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &_inner_error_);
					if (G_UNLIKELY (_inner_error_ != NULL)) {
						goto __catch47_g_error;
					}
				}
				goto __finally47;
				__catch47_g_error:
				{
					GError* e = NULL;
					GError* _tmp25_ = NULL;
					const gchar* _tmp26_ = NULL;
					e = _inner_error_;
					_inner_error_ = NULL;
					_tmp25_ = e;
					_tmp26_ = _tmp25_->message;
					g_warning ("templates.vala:275: Delete personal template, move file failed: %s", _tmp26_);
					_g_error_free0 (e);
				}
				__finally47:
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					_g_object_unref0 (new_file);
					_g_object_unref0 (file);
					_g_object_unref0 (template_file);
					_g_object_unref0 (model);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return;
				}
				_g_object_unref0 (new_file);
				_g_object_unref0 (file);
			}
		}
	}
	_tmp27_ = self->priv->_nb_personal_templates;
	self->priv->_nb_personal_templates = _tmp27_ - 1;
	_g_object_unref0 (template_file);
	_g_object_unref0 (model);
}


void templates_create_personal_template (Templates* self, const gchar* name, const gchar* icon_id, const gchar* contents) {
	GtkListStore* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	gint _tmp4_ = 0;
	GFile* file = NULL;
	gint _tmp5_ = 0;
	GFile* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (icon_id != NULL);
	g_return_if_fail (contents != NULL);
	_tmp0_ = self->priv->_personal_store;
	_tmp1_ = name;
	_tmp2_ = icon_id;
	_tmp3_ = contents;
	templates_add_template_from_string (self, _tmp0_, _tmp1_, _tmp2_, _tmp3_);
	_tmp4_ = self->priv->_nb_personal_templates;
	self->priv->_nb_personal_templates = _tmp4_ + 1;
	templates_save_rc_file (self);
	_tmp5_ = self->priv->_nb_personal_templates;
	_tmp6_ = templates_get_personal_template_file (self, _tmp5_ - 1);
	file = _tmp6_;
	_tmp7_ = contents;
	utils_save_file (file, _tmp7_, FALSE);
	_g_object_unref0 (file);
}


void templates_save_rc_file (Templates* self) {
	gint _tmp0_ = 0;
	gchar** names = NULL;
	gint _tmp2_ = 0;
	gchar** _tmp3_ = NULL;
	gint names_length1 = 0;
	gint _names_size_ = 0;
	gchar** icons = NULL;
	gint _tmp4_ = 0;
	gchar** _tmp5_ = NULL;
	gint icons_length1 = 0;
	gint _icons_size_ = 0;
	GtkTreeIter iter = {0};
	GtkTreeModel* model = NULL;
	GtkListStore* _tmp6_ = NULL;
	GtkTreeModel* _tmp7_ = NULL;
	gboolean valid_iter = FALSE;
	GtkTreeModel* _tmp8_ = NULL;
	GtkTreeIter _tmp9_ = {0};
	gboolean _tmp10_ = FALSE;
	gint template_num = 0;
	GKeyFile* key_file = NULL;
	GKeyFile* _tmp21_ = NULL;
	GKeyFile* _tmp22_ = NULL;
	gchar** _tmp23_ = NULL;
	gint _tmp23__length1 = 0;
	GKeyFile* _tmp24_ = NULL;
	gchar** _tmp25_ = NULL;
	gint _tmp25__length1 = 0;
	gchar* key_file_data = NULL;
	GKeyFile* _tmp26_ = NULL;
	gchar* _tmp27_ = NULL;
	GFile* _tmp28_ = NULL;
	const gchar* _tmp29_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_nb_personal_templates;
	if (_tmp0_ == 0) {
		GFile* _tmp1_ = NULL;
		_tmp1_ = self->priv->_rc_file;
		utils_delete_file (_tmp1_);
		return;
	}
	_tmp2_ = self->priv->_nb_personal_templates;
	_tmp3_ = g_new0 (gchar*, _tmp2_ + 1);
	names = _tmp3_;
	names_length1 = _tmp2_;
	_names_size_ = names_length1;
	_tmp4_ = self->priv->_nb_personal_templates;
	_tmp5_ = g_new0 (gchar*, _tmp4_ + 1);
	icons = _tmp5_;
	icons_length1 = _tmp4_;
	_icons_size_ = icons_length1;
	_tmp6_ = self->priv->_personal_store;
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, GTK_TYPE_TREE_MODEL) ? ((GtkTreeModel*) _tmp6_) : NULL);
	model = _tmp7_;
	_tmp8_ = model;
	_tmp10_ = gtk_tree_model_get_iter_first (_tmp8_, &_tmp9_);
	iter = _tmp9_;
	valid_iter = _tmp10_;
	template_num = 0;
	while (TRUE) {
		gboolean _tmp11_ = FALSE;
		GtkTreeModel* _tmp12_ = NULL;
		GtkTreeIter _tmp13_ = {0};
		gchar** _tmp14_ = NULL;
		gint _tmp14__length1 = 0;
		gint _tmp15_ = 0;
		gchar** _tmp16_ = NULL;
		gint _tmp16__length1 = 0;
		gint _tmp17_ = 0;
		GtkTreeModel* _tmp18_ = NULL;
		gboolean _tmp19_ = FALSE;
		gint _tmp20_ = 0;
		_tmp11_ = valid_iter;
		if (!_tmp11_) {
			break;
		}
		_tmp12_ = model;
		_tmp13_ = iter;
		_tmp14_ = names;
		_tmp14__length1 = names_length1;
		_tmp15_ = template_num;
		_tmp16_ = icons;
		_tmp16__length1 = icons_length1;
		_tmp17_ = template_num;
		gtk_tree_model_get (_tmp12_, &_tmp13_, TEMPLATES_TEMPLATE_COLUMN_NAME, &_tmp14_[_tmp15_], TEMPLATES_TEMPLATE_COLUMN_ICON_ID, &_tmp16_[_tmp17_], -1);
		_tmp18_ = model;
		_tmp19_ = gtk_tree_model_iter_next (_tmp18_, &iter);
		valid_iter = _tmp19_;
		_tmp20_ = template_num;
		template_num = _tmp20_ + 1;
	}
	_tmp21_ = g_key_file_new ();
	key_file = _tmp21_;
	_tmp22_ = key_file;
	_tmp23_ = names;
	_tmp23__length1 = names_length1;
	g_key_file_set_string_list (_tmp22_, PACKAGE_NAME, "names", (const gchar* const*) _tmp23_, _tmp23__length1);
	_tmp24_ = key_file;
	_tmp25_ = icons;
	_tmp25__length1 = icons_length1;
	g_key_file_set_string_list (_tmp24_, PACKAGE_NAME, "icons", (const gchar* const*) _tmp25_, _tmp25__length1);
	_tmp26_ = key_file;
	_tmp27_ = g_key_file_to_data (_tmp26_, NULL, NULL);
	key_file_data = _tmp27_;
	_tmp28_ = self->priv->_rc_file;
	_tmp29_ = key_file_data;
	utils_save_file (_tmp28_, _tmp29_, FALSE);
	_g_free0 (key_file_data);
	_g_key_file_unref0 (key_file);
	_g_object_unref0 (model);
	icons = (_vala_array_free (icons, icons_length1, (GDestroyNotify) g_free), NULL);
	names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
}


static gchar* templates_get_theme_icon (Templates* self, const gchar* icon_id) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GQuark _tmp3_ = 0U;
	static GQuark _tmp2_label0 = 0;
	static GQuark _tmp2_label1 = 0;
	static GQuark _tmp2_label2 = 0;
	static GQuark _tmp2_label3 = 0;
	static GQuark _tmp2_label4 = 0;
	static GQuark _tmp2_label5 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (icon_id != NULL, NULL);
	_tmp0_ = icon_id;
	_tmp1_ = _tmp0_;
	_tmp3_ = (NULL == _tmp1_) ? 0 : g_quark_from_string (_tmp1_);
	if (_tmp3_ == ((0 != _tmp2_label0) ? _tmp2_label0 : (_tmp2_label0 = g_quark_from_static_string ("empty")))) {
		switch (0) {
			default:
			{
				gchar* _tmp4_ = NULL;
				_tmp4_ = g_strdup ("text-x-preview");
				result = _tmp4_;
				return result;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label1) ? _tmp2_label1 : (_tmp2_label1 = g_quark_from_static_string ("article")))) {
		switch (0) {
			default:
			{
				gchar* _tmp5_ = NULL;
				_tmp5_ = g_strdup ("text-x-generic");
				result = _tmp5_;
				return result;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label2) ? _tmp2_label2 : (_tmp2_label2 = g_quark_from_static_string ("report")))) {
		switch (0) {
			default:
			{
				gchar* _tmp6_ = NULL;
				_tmp6_ = g_strdup ("x-office-document");
				result = _tmp6_;
				return result;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label3) ? _tmp2_label3 : (_tmp2_label3 = g_quark_from_static_string ("book")))) {
		switch (0) {
			default:
			{
				gchar* _tmp7_ = NULL;
				_tmp7_ = g_strdup ("accessories-dictionary");
				result = _tmp7_;
				return result;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label4) ? _tmp2_label4 : (_tmp2_label4 = g_quark_from_static_string ("letter")))) {
		switch (0) {
			default:
			{
				gchar* _tmp8_ = NULL;
				_tmp8_ = g_strdup ("emblem-mail");
				result = _tmp8_;
				return result;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label5) ? _tmp2_label5 : (_tmp2_label5 = g_quark_from_static_string ("beamer")))) {
		switch (0) {
			default:
			{
				gchar* _tmp9_ = NULL;
				_tmp9_ = g_strdup ("x-office-presentation");
				result = _tmp9_;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				g_return_val_if_reached (NULL);
			}
		}
	}
}


/*************************************************************************/
gchar* templates_get_icon_id (Templates* self, GtkTreePath* default_template_path) {
	gchar* result = NULL;
	GtkTreeModel* model = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeModel* _tmp1_ = NULL;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp2_ = NULL;
	GtkTreePath* _tmp3_ = NULL;
	GtkTreeIter _tmp4_ = {0};
	gboolean _tmp5_ = FALSE;
	gchar* icon_id = NULL;
	GtkTreeModel* _tmp7_ = NULL;
	GtkTreeIter _tmp8_ = {0};
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (default_template_path != NULL, NULL);
	_tmp0_ = self->priv->_default_store;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, GTK_TYPE_TREE_MODEL) ? ((GtkTreeModel*) _tmp0_) : NULL);
	model = _tmp1_;
	_tmp2_ = model;
	_tmp3_ = default_template_path;
	_tmp5_ = gtk_tree_model_get_iter (_tmp2_, &_tmp4_, _tmp3_);
	iter = _tmp4_;
	if (!_tmp5_) {
		gchar* _tmp6_ = NULL;
		g_warning ("templates.vala:373: Failed to get template icon id");
		_tmp6_ = g_strdup ("");
		result = _tmp6_;
		_g_object_unref0 (model);
		return result;
	}
	_tmp7_ = model;
	_tmp8_ = iter;
	gtk_tree_model_get (_tmp7_, &_tmp8_, TEMPLATES_TEMPLATE_COLUMN_ICON_ID, &icon_id, -1);
	result = icon_id;
	_g_object_unref0 (model);
	return result;
}


gchar* templates_get_default_template_contents (Templates* self, GtkTreePath* path) {
	gchar* result = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreePath* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = self->priv->_default_store;
	_tmp1_ = path;
	_tmp2_ = templates_get_template_contents (self, _tmp0_, _tmp1_);
	result = _tmp2_;
	return result;
}


gchar* templates_get_personal_template_contents (Templates* self, GtkTreePath* path) {
	gchar* result = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreePath* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = self->priv->_personal_store;
	_tmp1_ = path;
	_tmp2_ = templates_get_template_contents (self, _tmp0_, _tmp1_);
	result = _tmp2_;
	return result;
}


static gchar* templates_get_template_contents (Templates* self, GtkListStore* store, GtkTreePath* path) {
	gchar* result = NULL;
	GtkTreeIter iter = {0};
	GtkTreeModel* model = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeModel* _tmp1_ = NULL;
	GtkTreeModel* _tmp2_ = NULL;
	GtkTreePath* _tmp3_ = NULL;
	GtkTreeIter _tmp4_ = {0};
	gboolean _tmp5_ = FALSE;
	gchar* contents = NULL;
	GtkTreeModel* _tmp7_ = NULL;
	GtkTreeIter _tmp8_ = {0};
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (store != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = store;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, GTK_TYPE_TREE_MODEL) ? ((GtkTreeModel*) _tmp0_) : NULL);
	model = _tmp1_;
	_tmp2_ = model;
	_tmp3_ = path;
	_tmp5_ = gtk_tree_model_get_iter (_tmp2_, &_tmp4_, _tmp3_);
	iter = _tmp4_;
	if (!_tmp5_) {
		gchar* _tmp6_ = NULL;
		g_warning ("templates.vala:399: Failed to get template contents");
		_tmp6_ = g_strdup ("");
		result = _tmp6_;
		_g_object_unref0 (model);
		return result;
	}
	_tmp7_ = model;
	_tmp8_ = iter;
	gtk_tree_model_get (_tmp7_, &_tmp8_, TEMPLATES_TEMPLATE_COLUMN_CONTENTS, &contents, -1);
	result = contents;
	_g_object_unref0 (model);
	return result;
}


/*************************************************************************/
GtkTreeView* templates_get_default_templates_list (Templates* self) {
	GtkTreeView* result = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeView* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_default_store;
	_tmp1_ = templates_get_templates_list (self, _tmp0_);
	result = _tmp1_;
	return result;
}


GtkTreeView* templates_get_personal_templates_list (Templates* self) {
	GtkTreeView* result = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeView* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_personal_store;
	_tmp1_ = templates_get_templates_list (self, _tmp0_);
	result = _tmp1_;
	return result;
}


static GtkTreeView* templates_get_templates_list (Templates* self, GtkListStore* store) {
	GtkTreeView* result = NULL;
	GtkTreeView* view = NULL;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeView* _tmp1_ = NULL;
	GtkTreeSelection* select = NULL;
	GtkTreeSelection* _tmp2_ = NULL;
	GtkTreeSelection* _tmp3_ = NULL;
	GtkCellRendererPixbuf* pixbuf_renderer = NULL;
	GtkCellRendererPixbuf* _tmp4_ = NULL;
	GtkTreeViewColumn* column = NULL;
	GtkTreeViewColumn* _tmp5_ = NULL;
	GtkTreeViewColumn* _tmp6_ = NULL;
	GtkCellRendererText* text_renderer = NULL;
	GtkCellRendererText* _tmp7_ = NULL;
	GtkTreeViewColumn* _tmp8_ = NULL;
	GtkTreeViewColumn* _tmp9_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (store != NULL, NULL);
	_tmp0_ = store;
	_tmp1_ = (GtkTreeView*) gtk_tree_view_new_with_model ((GtkTreeModel*) _tmp0_);
	g_object_ref_sink (_tmp1_);
	view = _tmp1_;
	gtk_tree_view_set_headers_visible (view, FALSE);
	g_object_set ((GtkWidget*) view, "expand", TRUE, NULL);
	_tmp2_ = gtk_tree_view_get_selection (view);
	_tmp3_ = _g_object_ref0 (_tmp2_);
	select = _tmp3_;
	gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
	_tmp4_ = (GtkCellRendererPixbuf*) gtk_cell_renderer_pixbuf_new ();
	g_object_ref_sink (_tmp4_);
	pixbuf_renderer = _tmp4_;
	g_object_set (pixbuf_renderer, "stock-size", (guint) GTK_ICON_SIZE_BUTTON, NULL);
	_tmp5_ = gtk_tree_view_column_new_with_attributes ("Icon", (GtkCellRenderer*) pixbuf_renderer, "icon-name", TEMPLATES_TEMPLATE_COLUMN_PIXBUF, NULL, NULL);
	g_object_ref_sink (_tmp5_);
	column = _tmp5_;
	_tmp6_ = column;
	gtk_tree_view_append_column (view, _tmp6_);
	_tmp7_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp7_);
	text_renderer = _tmp7_;
	_tmp8_ = gtk_tree_view_column_new_with_attributes ("Name", (GtkCellRenderer*) text_renderer, "text", TEMPLATES_TEMPLATE_COLUMN_NAME, NULL, NULL);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (column);
	column = _tmp8_;
	_tmp9_ = column;
	gtk_tree_view_append_column (view, _tmp9_);
	result = view;
	_g_object_unref0 (text_renderer);
	_g_object_unref0 (column);
	_g_object_unref0 (pixbuf_renderer);
	_g_object_unref0 (select);
	return result;
}


static void templates_class_init (TemplatesClass * klass) {
	templates_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (TemplatesPrivate));
	G_OBJECT_CLASS (klass)->finalize = templates_finalize;
}


static void templates_instance_init (Templates * self) {
	self->priv = TEMPLATES_GET_PRIVATE (self);
}


static void templates_finalize (GObject* obj) {
	Templates * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEMPLATES, Templates);
	_g_object_unref0 (self->priv->_default_store);
	_g_object_unref0 (self->priv->_personal_store);
	_g_object_unref0 (self->priv->_data_dir);
	_g_object_unref0 (self->priv->_rc_file);
	_g_free0 (self->priv->_default_template);
	G_OBJECT_CLASS (templates_parent_class)->finalize (obj);
}


GType templates_get_type (void) {
	static volatile gsize templates_type_id__volatile = 0;
	if (g_once_init_enter (&templates_type_id__volatile)) {
		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, NULL };
		GType templates_type_id;
		templates_type_id = g_type_register_static (G_TYPE_OBJECT, "Templates", &g_define_type_info, 0);
		g_once_init_leave (&templates_type_id__volatile, templates_type_id);
	}
	return templates_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



