/* most_used_symbols.c generated by valac 0.39.91.20-3233, the Vala compiler
 * generated from most_used_symbols.vala, do not modify */

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


#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define TYPE_MOST_USED_SYMBOLS (most_used_symbols_get_type ())
#define MOST_USED_SYMBOLS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MOST_USED_SYMBOLS, MostUsedSymbols))
#define MOST_USED_SYMBOLS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MOST_USED_SYMBOLS, MostUsedSymbolsClass))
#define IS_MOST_USED_SYMBOLS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MOST_USED_SYMBOLS))
#define IS_MOST_USED_SYMBOLS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MOST_USED_SYMBOLS))
#define MOST_USED_SYMBOLS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MOST_USED_SYMBOLS, MostUsedSymbolsClass))

typedef struct _MostUsedSymbols MostUsedSymbols;
typedef struct _MostUsedSymbolsClass MostUsedSymbolsClass;
typedef struct _MostUsedSymbolsPrivate MostUsedSymbolsPrivate;
enum  {
	MOST_USED_SYMBOLS_0_PROPERTY,
	MOST_USED_SYMBOLS_NUM_PROPERTIES
};
static GParamSpec* most_used_symbols_properties[MOST_USED_SYMBOLS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_SYMBOL_COLUMN (symbol_column_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_SYMBOLS (symbols_get_type ())
#define SYMBOLS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SYMBOLS, Symbols))
#define SYMBOLS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SYMBOLS, SymbolsClass))
#define IS_SYMBOLS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SYMBOLS))
#define IS_SYMBOLS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SYMBOLS))
#define SYMBOLS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SYMBOLS, SymbolsClass))

typedef struct _Symbols Symbols;
typedef struct _SymbolsClass SymbolsClass;
#define _g_markup_parse_context_unref0(var) ((var == NULL) ? NULL : (var = (g_markup_parse_context_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _MostUsedSymbols {
	GObject parent_instance;
	MostUsedSymbolsPrivate * priv;
};

struct _MostUsedSymbolsClass {
	GObjectClass parent_class;
};

struct _MostUsedSymbolsPrivate {
	gboolean _modified;
	GtkListStore* _store;
};

typedef enum  {
	SYMBOL_COLUMN_PIXBUF,
	SYMBOL_COLUMN_COMMAND,
	SYMBOL_COLUMN_TOOLTIP,
	SYMBOL_COLUMN_ID,
	SYMBOL_COLUMN_N_COLUMNS
} SymbolColumn;


static gpointer most_used_symbols_parent_class = NULL;
static MostUsedSymbols* most_used_symbols__instance;
static MostUsedSymbols* most_used_symbols__instance = NULL;

GType most_used_symbols_get_type (void) G_GNUC_CONST;
#define MOST_USED_SYMBOLS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MOST_USED_SYMBOLS, MostUsedSymbolsPrivate))
GType symbol_column_get_type (void) G_GNUC_CONST;
#define MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM ((gint) SYMBOL_COLUMN_N_COLUMNS)
static MostUsedSymbols* most_used_symbols_new (void);
static MostUsedSymbols* most_used_symbols_construct (GType object_type);
static void most_used_symbols_init_models (MostUsedSymbols* self);
static void most_used_symbols_load_data (MostUsedSymbols* self);
MostUsedSymbols* most_used_symbols_get_default (void);
GtkTreeModel* most_used_symbols_get_model (MostUsedSymbols* self);
void most_used_symbols_clear (MostUsedSymbols* self);
void most_used_symbols_increment_symbol (MostUsedSymbols* self,
                                         const gchar* id);
static gboolean most_used_symbols_get_iter_at_symbol_id (MostUsedSymbols* self,
                                                  const gchar* id,
                                                  GtkTreeIter* iter);
static void most_used_symbols_add_symbol (MostUsedSymbols* self,
                                   const gchar* id,
                                   gint nb_times_used);
GdkPixbuf* symbols_get_pixbuf (const gchar* symbol_id);
GType symbols_get_type (void) G_GNUC_CONST;
Symbols* symbols_get_default (void);
gboolean symbols_get_symbol_info (Symbols* self,
                                  const gchar* id,
                                  gchar* * command,
                                  gchar* * tooltip);
static GFile* most_used_symbols_get_xml_file (MostUsedSymbols* self);
gchar* utils_load_file (GFile* file);
static void most_used_symbols_parser_start (MostUsedSymbols* self,
                                     GMarkupParseContext* context,
                                     const gchar* name,
                                     gchar** attr_names,
                                     int attr_names_length1,
                                     gchar** attr_values,
                                     int attr_values_length1,
                                     GError** error);
static void _most_used_symbols_parser_start_gmarkup_parser_start_element_func (GMarkupParseContext* context,
                                                                        const gchar* element_name,
                                                                        gchar** attribute_names,
                                                                        gchar** attribute_values,
                                                                        gpointer self,
                                                                        GError** error);
void most_used_symbols_save (MostUsedSymbols* self);
void utils_delete_file (GFile* file);
gboolean utils_save_file (GFile* file,
                          const gchar* contents,
                          gboolean make_backup);
static void most_used_symbols_finalize (GObject * obj);
static gint _vala_array_length (gpointer array);


static MostUsedSymbols*
most_used_symbols_construct (GType object_type)
{
	MostUsedSymbols * self = NULL;
	self = (MostUsedSymbols*) g_object_new (object_type, NULL);
	most_used_symbols_init_models (self);
	most_used_symbols_load_data (self);
	return self;
}


static MostUsedSymbols*
most_used_symbols_new (void)
{
	return most_used_symbols_construct (TYPE_MOST_USED_SYMBOLS);
}


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


MostUsedSymbols*
most_used_symbols_get_default (void)
{
	MostUsedSymbols* result = NULL;
	MostUsedSymbols* _tmp0_;
	MostUsedSymbols* _tmp2_;
	MostUsedSymbols* _tmp3_;
	_tmp0_ = most_used_symbols__instance;
	if (_tmp0_ == NULL) {
		MostUsedSymbols* _tmp1_;
		_tmp1_ = most_used_symbols_new ();
		_g_object_unref0 (most_used_symbols__instance);
		most_used_symbols__instance = _tmp1_;
	}
	_tmp2_ = most_used_symbols__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


static void
most_used_symbols_init_models (MostUsedSymbols* self)
{
	GtkListStore* _tmp0_;
	GtkListStore* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_list_store_new ((gint) (SYMBOL_COLUMN_N_COLUMNS + 1), gdk_pixbuf_get_type (), G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, -1);
	_g_object_unref0 (self->priv->_store);
	self->priv->_store = _tmp0_;
	_tmp1_ = self->priv->_store;
	gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable*) _tmp1_, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, GTK_SORT_DESCENDING);
}


GtkTreeModel*
most_used_symbols_get_model (MostUsedSymbols* self)
{
	GtkTreeModel* result = NULL;
	GtkListStore* _tmp0_;
	GtkTreeModel* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_store;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gtk_tree_model_get_type ()) ? ((GtkTreeModel*) _tmp0_) : NULL);
	result = _tmp1_;
	return result;
}


void
most_used_symbols_clear (MostUsedSymbols* self)
{
	GtkListStore* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_store;
	gtk_list_store_clear (_tmp0_);
}


void
most_used_symbols_increment_symbol (MostUsedSymbols* self,
                                    const gchar* id)
{
	GtkTreeIter iter = {0};
	GtkTreeIter _tmp0_ = {0};
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_tmp1_ = most_used_symbols_get_iter_at_symbol_id (self, id, &_tmp0_);
	iter = _tmp0_;
	if (!_tmp1_) {
		most_used_symbols_add_symbol (self, id, 1);
	} else {
		gint num = 0;
		GtkTreeModel* model = NULL;
		GtkListStore* _tmp2_;
		GtkTreeModel* _tmp3_;
		GtkTreeModel* _tmp4_;
		GtkTreeIter _tmp5_;
		GtkListStore* _tmp6_;
		GtkTreeIter _tmp7_;
		gint _tmp8_;
		_tmp2_ = self->priv->_store;
		_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_tree_model_get_type ()) ? ((GtkTreeModel*) _tmp2_) : NULL);
		model = _tmp3_;
		_tmp4_ = model;
		_tmp5_ = iter;
		gtk_tree_model_get (_tmp4_, &_tmp5_, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, &num, -1);
		_tmp6_ = self->priv->_store;
		_tmp7_ = iter;
		_tmp8_ = num;
		gtk_list_store_set (_tmp6_, &_tmp7_, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, _tmp8_ + 1, -1);
		_g_object_unref0 (model);
	}
	self->priv->_modified = TRUE;
}


static gboolean
most_used_symbols_get_iter_at_symbol_id (MostUsedSymbols* self,
                                         const gchar* id,
                                         GtkTreeIter* iter)
{
	GtkTreeIter _vala_iter = {0};
	gboolean result = FALSE;
	GtkListStore* _tmp0_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (id != NULL, FALSE);
	_tmp0_ = self->priv->_store;
	_tmp2_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp0_, &_tmp1_);
	_vala_iter = _tmp1_;
	if (!_tmp2_) {
		result = FALSE;
		if (iter) {
			*iter = _vala_iter;
		}
		return result;
	}
	{
		gboolean _tmp3_ = FALSE;
		_tmp3_ = TRUE;
		while (TRUE) {
			gchar* cur_id = NULL;
			GtkTreeModel* model = NULL;
			GtkListStore* _tmp6_;
			GtkTreeModel* _tmp7_;
			GtkTreeModel* _tmp8_;
			GtkTreeIter _tmp9_;
			const gchar* _tmp10_;
			if (!_tmp3_) {
				GtkListStore* _tmp4_;
				gboolean _tmp5_;
				_tmp4_ = self->priv->_store;
				_tmp5_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp4_, &_vala_iter);
				if (!_tmp5_) {
					break;
				}
			}
			_tmp3_ = FALSE;
			_tmp6_ = self->priv->_store;
			_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, gtk_tree_model_get_type ()) ? ((GtkTreeModel*) _tmp6_) : NULL);
			model = _tmp7_;
			_tmp8_ = model;
			_tmp9_ = _vala_iter;
			gtk_tree_model_get (_tmp8_, &_tmp9_, SYMBOL_COLUMN_ID, &cur_id, -1);
			_tmp10_ = cur_id;
			if (g_strcmp0 (_tmp10_, id) == 0) {
				result = TRUE;
				_g_object_unref0 (model);
				_g_free0 (cur_id);
				if (iter) {
					*iter = _vala_iter;
				}
				return result;
			}
			_g_object_unref0 (model);
			_g_free0 (cur_id);
		}
	}
	result = FALSE;
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}


static void
most_used_symbols_add_symbol (MostUsedSymbols* self,
                              const gchar* id,
                              gint nb_times_used)
{
	GdkPixbuf* pixbuf = NULL;
	GdkPixbuf* _tmp0_;
	GdkPixbuf* _tmp1_;
	gchar* command = NULL;
	gchar* tooltip = NULL;
	Symbols* _tmp2_;
	Symbols* _tmp3_;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gboolean _tmp6_;
	gboolean _tmp7_;
	GtkTreeIter iter = {0};
	GtkListStore* _tmp8_;
	GtkTreeIter _tmp9_ = {0};
	GtkListStore* _tmp10_;
	GtkTreeIter _tmp11_;
	GdkPixbuf* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_tmp0_ = symbols_get_pixbuf (id);
	pixbuf = _tmp0_;
	_tmp1_ = pixbuf;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (pixbuf);
		return;
	}
	_tmp2_ = symbols_get_default ();
	_tmp3_ = _tmp2_;
	_tmp6_ = symbols_get_symbol_info (_tmp3_, id, &_tmp4_, &_tmp5_);
	_g_free0 (command);
	command = _tmp4_;
	_g_free0 (tooltip);
	tooltip = _tmp5_;
	_tmp7_ = !_tmp6_;
	_g_object_unref0 (_tmp3_);
	if (_tmp7_) {
		_g_free0 (tooltip);
		_g_free0 (command);
		_g_object_unref0 (pixbuf);
		return;
	}
	_tmp8_ = self->priv->_store;
	gtk_list_store_append (_tmp8_, &_tmp9_);
	iter = _tmp9_;
	_tmp10_ = self->priv->_store;
	_tmp11_ = iter;
	_tmp12_ = pixbuf;
	_tmp13_ = command;
	_tmp14_ = tooltip;
	gtk_list_store_set (_tmp10_, &_tmp11_, SYMBOL_COLUMN_PIXBUF, _tmp12_, SYMBOL_COLUMN_COMMAND, _tmp13_, SYMBOL_COLUMN_TOOLTIP, _tmp14_, SYMBOL_COLUMN_ID, id, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, nb_times_used, -1);
	_g_free0 (tooltip);
	_g_free0 (command);
	_g_object_unref0 (pixbuf);
}


static GFile*
most_used_symbols_get_xml_file (MostUsedSymbols* self)
{
	GFile* result = NULL;
	gchar* path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	GFile* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "gnome-latex", "most_used_symbols.xml", NULL);
	path = _tmp1_;
	_tmp2_ = g_file_new_for_path (path);
	result = _tmp2_;
	_g_free0 (path);
	return result;
}


static void
_most_used_symbols_parser_start_gmarkup_parser_start_element_func (GMarkupParseContext* context,
                                                                   const gchar* element_name,
                                                                   gchar** attribute_names,
                                                                   gchar** attribute_values,
                                                                   gpointer self,
                                                                   GError** error)
{
	most_used_symbols_parser_start ((MostUsedSymbols*) self, context, element_name, attribute_names, _vala_array_length (attribute_names), attribute_values, _vala_array_length (attribute_values), error);
}


static void
most_used_symbols_load_data (MostUsedSymbols* self)
{
	GFile* file = NULL;
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* contents = NULL;
	GFile* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = most_used_symbols_get_xml_file (self);
	file = _tmp0_;
	_tmp1_ = file;
	if (!g_file_query_exists (_tmp1_, NULL)) {
		_g_object_unref0 (file);
		return;
	}
	_tmp2_ = file;
	_tmp3_ = utils_load_file (_tmp2_);
	contents = _tmp3_;
	_tmp4_ = contents;
	if (_tmp4_ == NULL) {
		_g_free0 (contents);
		_g_object_unref0 (file);
		return;
	}
	{
		GMarkupParser parser = {0};
		GMarkupParser _tmp5_ = {0};
		GMarkupParseContext* context = NULL;
		GMarkupParser _tmp6_;
		GMarkupParseContext* _tmp7_;
		GMarkupParseContext* _tmp8_;
		const gchar* _tmp9_;
		_tmp5_.start_element = _most_used_symbols_parser_start_gmarkup_parser_start_element_func;
		_tmp5_.end_element = NULL;
		_tmp5_.text = NULL;
		_tmp5_.passthrough = NULL;
		_tmp5_.error = NULL;
		parser = _tmp5_;
		_tmp6_ = parser;
		_tmp7_ = g_markup_parse_context_new (&_tmp6_, 0, self, NULL);
		context = _tmp7_;
		_tmp8_ = context;
		_tmp9_ = contents;
		g_markup_parse_context_parse (_tmp8_, _tmp9_, (gssize) -1, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_markup_parse_context_unref0 (context);
			goto __catch34_g_error;
		}
		_g_markup_parse_context_unref0 (context);
	}
	goto __finally34;
	__catch34_g_error:
	{
		GError* e = NULL;
		GError* _tmp10_;
		const gchar* _tmp11_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp10_ = e;
		_tmp11_ = _tmp10_->message;
		g_warning ("most_used_symbols.vala:156: Impossible to load the most used symbols: " \
"%s", _tmp11_);
		_g_error_free0 (e);
	}
	__finally34:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_free0 (contents);
		_g_object_unref0 (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;
	}
	_g_free0 (contents);
	_g_object_unref0 (file);
}


static void
most_used_symbols_parser_start (MostUsedSymbols* self,
                                GMarkupParseContext* context,
                                const gchar* name,
                                gchar** attr_names,
                                int attr_names_length1,
                                gchar** attr_values,
                                int attr_values_length1,
                                GError** error)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = name;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("symbols")))) {
		switch (0) {
			default:
			{
				return;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("symbol")))) {
		switch (0) {
			default:
			{
				gchar* id = NULL;
				gint num = 0;
				const gchar* _tmp24_;
				gint _tmp25_;
				id = NULL;
				num = 0;
				{
					gint i = 0;
					i = 0;
					{
						gboolean _tmp3_ = FALSE;
						_tmp3_ = TRUE;
						while (TRUE) {
							gint _tmp5_;
							gint _tmp6_;
							const gchar* _tmp7_;
							const gchar* _tmp8_;
							GQuark _tmp10_ = 0U;
							static GQuark _tmp9_label0 = 0;
							static GQuark _tmp9_label1 = 0;
							static GQuark _tmp9_label2 = 0;
							static GQuark _tmp9_label3 = 0;
							if (!_tmp3_) {
								gint _tmp4_;
								_tmp4_ = i;
								i = _tmp4_ + 1;
							}
							_tmp3_ = FALSE;
							_tmp5_ = i;
							if (!(_tmp5_ < attr_names_length1)) {
								break;
							}
							_tmp6_ = i;
							_tmp7_ = attr_names[_tmp6_];
							_tmp8_ = _tmp7_;
							_tmp10_ = (NULL == _tmp8_) ? 0 : g_quark_from_string (_tmp8_);
							if (_tmp10_ == ((0 != _tmp9_label0) ? _tmp9_label0 : (_tmp9_label0 = g_quark_from_static_string ("id")))) {
								switch (0) {
									default:
									{
										gint _tmp11_;
										const gchar* _tmp12_;
										gchar* _tmp13_;
										_tmp11_ = i;
										_tmp12_ = attr_values[_tmp11_];
										_tmp13_ = g_strdup (_tmp12_);
										_g_free0 (id);
										id = _tmp13_;
										break;
									}
								}
							} else if (_tmp10_ == ((0 != _tmp9_label1) ? _tmp9_label1 : (_tmp9_label1 = g_quark_from_static_string ("num")))) {
								switch (0) {
									default:
									{
										gint _tmp14_;
										const gchar* _tmp15_;
										_tmp14_ = i;
										_tmp15_ = attr_values[_tmp14_];
										num = atoi (_tmp15_);
										break;
									}
								}
							} else if ((_tmp10_ == ((0 != _tmp9_label2) ? _tmp9_label2 : (_tmp9_label2 = g_quark_from_static_string ("command")))) || (_tmp10_ == ((0 != _tmp9_label3) ? _tmp9_label3 : (_tmp9_label3 = g_quark_from_static_string ("package"))))) {
								switch (0) {
									default:
									{
										break;
									}
								}
							} else {
								switch (0) {
									default:
									{
										gint _tmp16_;
										const gchar* _tmp17_;
										gchar* _tmp18_;
										gchar* _tmp19_;
										gchar* _tmp20_;
										gchar* _tmp21_;
										GError* _tmp22_;
										GError* _tmp23_;
										_tmp16_ = i;
										_tmp17_ = attr_names[_tmp16_];
										_tmp18_ = g_strconcat ("unknown attribute \"", _tmp17_, NULL);
										_tmp19_ = _tmp18_;
										_tmp20_ = g_strconcat (_tmp19_, "\"", NULL);
										_tmp21_ = _tmp20_;
										_tmp22_ = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, _tmp21_);
										_tmp23_ = _tmp22_;
										_g_free0 (_tmp21_);
										_g_free0 (_tmp19_);
										_inner_error_ = _tmp23_;
										if (_inner_error_->domain == G_MARKUP_ERROR) {
											g_propagate_error (error, _inner_error_);
											_g_free0 (id);
											return;
										} else {
											_g_free0 (id);
											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;
										}
									}
								}
							}
						}
					}
				}
				_tmp24_ = id;
				_tmp25_ = num;
				most_used_symbols_add_symbol (self, _tmp24_, _tmp25_);
				_g_free0 (id);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				gchar* _tmp26_;
				gchar* _tmp27_;
				gchar* _tmp28_;
				gchar* _tmp29_;
				GError* _tmp30_;
				GError* _tmp31_;
				_tmp26_ = g_strconcat ("unknown element \"", name, NULL);
				_tmp27_ = _tmp26_;
				_tmp28_ = g_strconcat (_tmp27_, "\"", NULL);
				_tmp29_ = _tmp28_;
				_tmp30_ = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, _tmp29_);
				_tmp31_ = _tmp30_;
				_g_free0 (_tmp29_);
				_g_free0 (_tmp27_);
				_inner_error_ = _tmp31_;
				if (_inner_error_->domain == G_MARKUP_ERROR) {
					g_propagate_error (error, _inner_error_);
					return;
				} else {
					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;
				}
			}
		}
	}
}


void
most_used_symbols_save (MostUsedSymbols* self)
{
	gboolean _tmp0_;
	GFile* file = NULL;
	GFile* _tmp1_;
	GtkTreeIter iter = {0};
	gboolean is_empty = FALSE;
	GtkListStore* _tmp2_;
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_;
	gboolean _tmp5_;
	gchar* content = NULL;
	gchar* _tmp7_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	GFile* _tmp23_;
	const gchar* _tmp24_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_modified;
	if (!_tmp0_) {
		return;
	}
	self->priv->_modified = FALSE;
	_tmp1_ = most_used_symbols_get_xml_file (self);
	file = _tmp1_;
	_tmp2_ = self->priv->_store;
	_tmp4_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp2_, &_tmp3_);
	iter = _tmp3_;
	is_empty = !_tmp4_;
	_tmp5_ = is_empty;
	if (_tmp5_) {
		GFile* _tmp6_;
		_tmp6_ = file;
		utils_delete_file (_tmp6_);
		_g_object_unref0 (file);
		return;
	}
	_tmp7_ = g_strdup ("<symbols>\n");
	content = _tmp7_;
	{
		gboolean _tmp8_ = FALSE;
		_tmp8_ = TRUE;
		while (TRUE) {
			gchar* id = NULL;
			gint num = 0;
			GtkTreeModel* model = NULL;
			GtkListStore* _tmp11_;
			GtkTreeModel* _tmp12_;
			GtkTreeModel* _tmp13_;
			GtkTreeIter _tmp14_;
			const gchar* _tmp15_;
			const gchar* _tmp16_;
			gint _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			if (!_tmp8_) {
				GtkListStore* _tmp9_;
				gboolean _tmp10_;
				_tmp9_ = self->priv->_store;
				_tmp10_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp9_, &iter);
				if (!_tmp10_) {
					break;
				}
			}
			_tmp8_ = FALSE;
			_tmp11_ = self->priv->_store;
			_tmp12_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp11_, gtk_tree_model_get_type ()) ? ((GtkTreeModel*) _tmp11_) : NULL);
			model = _tmp12_;
			_tmp13_ = model;
			_tmp14_ = iter;
			gtk_tree_model_get (_tmp13_, &_tmp14_, SYMBOL_COLUMN_ID, &id, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, &num, -1);
			_tmp15_ = content;
			_tmp16_ = id;
			_tmp17_ = num;
			_tmp18_ = g_strdup_printf ("  <symbol id=\"%s\" num=\"%d\" />\n", _tmp16_, _tmp17_);
			_tmp19_ = _tmp18_;
			_tmp20_ = g_strconcat (_tmp15_, _tmp19_, NULL);
			_g_free0 (content);
			content = _tmp20_;
			_g_free0 (_tmp19_);
			_g_object_unref0 (model);
			_g_free0 (id);
		}
	}
	_tmp21_ = content;
	_tmp22_ = g_strconcat (_tmp21_, "</symbols>\n", NULL);
	_g_free0 (content);
	content = _tmp22_;
	_tmp23_ = file;
	_tmp24_ = content;
	utils_save_file (_tmp23_, _tmp24_, FALSE);
	_g_free0 (content);
	_g_object_unref0 (file);
}


static void
most_used_symbols_class_init (MostUsedSymbolsClass * klass)
{
	most_used_symbols_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MostUsedSymbolsPrivate));
	G_OBJECT_CLASS (klass)->finalize = most_used_symbols_finalize;
}


static void
most_used_symbols_instance_init (MostUsedSymbols * self)
{
	self->priv = MOST_USED_SYMBOLS_GET_PRIVATE (self);
	self->priv->_modified = FALSE;
}


static void
most_used_symbols_finalize (GObject * obj)
{
	MostUsedSymbols * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MOST_USED_SYMBOLS, MostUsedSymbols);
	_g_object_unref0 (self->priv->_store);
	G_OBJECT_CLASS (most_used_symbols_parent_class)->finalize (obj);
}


GType
most_used_symbols_get_type (void)
{
	static volatile gsize most_used_symbols_type_id__volatile = 0;
	if (g_once_init_enter (&most_used_symbols_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (MostUsedSymbolsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) most_used_symbols_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MostUsedSymbols), 0, (GInstanceInitFunc) most_used_symbols_instance_init, NULL };
		GType most_used_symbols_type_id;
		most_used_symbols_type_id = g_type_register_static (G_TYPE_OBJECT, "MostUsedSymbols", &g_define_type_info, 0);
		g_once_init_leave (&most_used_symbols_type_id__volatile, most_used_symbols_type_id);
	}
	return most_used_symbols_type_id__volatile;
}


static gint
_vala_array_length (gpointer array)
{
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



