/* most_used_symbols.c generated by valac 0.36.3, the Vala compiler
 * generated from most_used_symbols.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/>.
 *
 * 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;
#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))
enum  {
	MOST_USED_SYMBOLS_DUMMY_PROPERTY
};
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_TYPE_TREE_MODEL) ? ((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};
	const gchar* _tmp0_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_tmp0_ = id;
	_tmp2_ = most_used_symbols_get_iter_at_symbol_id (self, _tmp0_, &_tmp1_);
	iter = _tmp1_;
	if (!_tmp2_) {
		const gchar* _tmp3_;
		_tmp3_ = id;
		most_used_symbols_add_symbol (self, _tmp3_, 1);
	} else {
		gint num = 0;
		GtkTreeModel* model = NULL;
		GtkListStore* _tmp4_;
		GtkTreeModel* _tmp5_;
		GtkTreeModel* _tmp6_;
		GtkTreeIter _tmp7_;
		GtkListStore* _tmp8_;
		GtkTreeIter _tmp9_;
		gint _tmp10_;
		_tmp4_ = self->priv->_store;
		_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, GTK_TYPE_TREE_MODEL) ? ((GtkTreeModel*) _tmp4_) : NULL);
		model = _tmp5_;
		_tmp6_ = model;
		_tmp7_ = iter;
		gtk_tree_model_get (_tmp6_, &_tmp7_, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, &num, -1);
		_tmp8_ = self->priv->_store;
		_tmp9_ = iter;
		_tmp10_ = num;
		gtk_list_store_set (_tmp8_, &_tmp9_, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, _tmp10_ + 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_;
			const gchar* _tmp11_;
			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_TYPE_TREE_MODEL) ? ((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;
			_tmp11_ = id;
			if (g_strcmp0 (_tmp10_, _tmp11_) == 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;
	const gchar* _tmp0_;
	GdkPixbuf* _tmp1_;
	GdkPixbuf* _tmp2_;
	gchar* command = NULL;
	gchar* tooltip = NULL;
	Symbols* _tmp3_;
	Symbols* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gboolean _tmp8_;
	gboolean _tmp9_;
	GtkTreeIter iter = {0};
	GtkListStore* _tmp10_;
	GtkTreeIter _tmp11_ = {0};
	GtkListStore* _tmp12_;
	GtkTreeIter _tmp13_;
	GdkPixbuf* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gint _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_tmp0_ = id;
	_tmp1_ = symbols_get_pixbuf (_tmp0_);
	pixbuf = _tmp1_;
	_tmp2_ = pixbuf;
	if (_tmp2_ == NULL) {
		_g_object_unref0 (pixbuf);
		return;
	}
	_tmp3_ = symbols_get_default ();
	_tmp4_ = _tmp3_;
	_tmp5_ = id;
	_tmp8_ = symbols_get_symbol_info (_tmp4_, _tmp5_, &_tmp6_, &_tmp7_);
	_g_free0 (command);
	command = _tmp6_;
	_g_free0 (tooltip);
	tooltip = _tmp7_;
	_tmp9_ = !_tmp8_;
	_g_object_unref0 (_tmp4_);
	if (_tmp9_) {
		_g_free0 (tooltip);
		_g_free0 (command);
		_g_object_unref0 (pixbuf);
		return;
	}
	_tmp10_ = self->priv->_store;
	gtk_list_store_append (_tmp10_, &_tmp11_);
	iter = _tmp11_;
	_tmp12_ = self->priv->_store;
	_tmp13_ = iter;
	_tmp14_ = pixbuf;
	_tmp15_ = command;
	_tmp16_ = tooltip;
	_tmp17_ = id;
	_tmp18_ = nb_times_used;
	gtk_list_store_set (_tmp12_, &_tmp13_, SYMBOL_COLUMN_PIXBUF, _tmp14_, SYMBOL_COLUMN_COMMAND, _tmp15_, SYMBOL_COLUMN_TOOLTIP, _tmp16_, SYMBOL_COLUMN_ID, _tmp17_, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, _tmp18_, -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_, "latexila", "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_;
	gboolean _tmp2_;
	gchar* contents = NULL;
	GFile* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = most_used_symbols_get_xml_file (self);
	file = _tmp0_;
	_tmp1_ = file;
	_tmp2_ = g_file_query_exists (_tmp1_, NULL);
	if (!_tmp2_) {
		_g_object_unref0 (file);
		return;
	}
	_tmp3_ = file;
	_tmp4_ = utils_load_file (_tmp3_);
	contents = _tmp4_;
	_tmp5_ = contents;
	if (_tmp5_ == NULL) {
		_g_free0 (contents);
		_g_object_unref0 (file);
		return;
	}
	{
		GMarkupParser parser = {0};
		GMarkupParser _tmp6_ = {0};
		GMarkupParseContext* context = NULL;
		GMarkupParser _tmp7_;
		GMarkupParseContext* _tmp8_;
		GMarkupParseContext* _tmp9_;
		const gchar* _tmp10_;
		_tmp6_.start_element = _most_used_symbols_parser_start_gmarkup_parser_start_element_func;
		_tmp6_.end_element = NULL;
		_tmp6_.text = NULL;
		_tmp6_.passthrough = NULL;
		_tmp6_.error = NULL;
		parser = _tmp6_;
		_tmp7_ = parser;
		_tmp8_ = g_markup_parse_context_new (&_tmp7_, 0, self, NULL);
		context = _tmp8_;
		_tmp9_ = context;
		_tmp10_ = contents;
		g_markup_parse_context_parse (_tmp9_, _tmp10_, (gssize) -1, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_markup_parse_context_unref0 (context);
			goto __catch37_g_error;
		}
		_g_markup_parse_context_unref0 (context);
	}
	goto __finally37;
	__catch37_g_error:
	{
		GError* e = NULL;
		GError* _tmp11_;
		const gchar* _tmp12_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp11_ = e;
		_tmp12_ = _tmp11_->message;
		g_warning ("most_used_symbols.vala:156: Impossible to load the most used symbols: " \
"%s", _tmp12_);
		_g_error_free0 (e);
	}
	__finally37:
	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_;
	const gchar* _tmp1_;
	GQuark _tmp3_ = 0U;
	static GQuark _tmp2_label0 = 0;
	static GQuark _tmp2_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;
	_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 ("symbols")))) {
		switch (0) {
			default:
			{
				return;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label1) ? _tmp2_label1 : (_tmp2_label1 = g_quark_from_static_string ("symbol")))) {
		switch (0) {
			default:
			{
				gchar* id = NULL;
				gint num = 0;
				const gchar* _tmp31_;
				gint _tmp32_;
				id = NULL;
				num = 0;
				{
					gint i = 0;
					i = 0;
					{
						gboolean _tmp4_ = FALSE;
						_tmp4_ = TRUE;
						while (TRUE) {
							gint _tmp6_;
							gchar** _tmp7_;
							gint _tmp7__length1;
							gchar** _tmp8_;
							gint _tmp8__length1;
							gint _tmp9_;
							const gchar* _tmp10_;
							const gchar* _tmp11_;
							GQuark _tmp13_ = 0U;
							static GQuark _tmp12_label0 = 0;
							static GQuark _tmp12_label1 = 0;
							static GQuark _tmp12_label2 = 0;
							static GQuark _tmp12_label3 = 0;
							if (!_tmp4_) {
								gint _tmp5_;
								_tmp5_ = i;
								i = _tmp5_ + 1;
							}
							_tmp4_ = FALSE;
							_tmp6_ = i;
							_tmp7_ = attr_names;
							_tmp7__length1 = attr_names_length1;
							if (!(_tmp6_ < _tmp7__length1)) {
								break;
							}
							_tmp8_ = attr_names;
							_tmp8__length1 = attr_names_length1;
							_tmp9_ = i;
							_tmp10_ = _tmp8_[_tmp9_];
							_tmp11_ = _tmp10_;
							_tmp13_ = (NULL == _tmp11_) ? 0 : g_quark_from_string (_tmp11_);
							if (_tmp13_ == ((0 != _tmp12_label0) ? _tmp12_label0 : (_tmp12_label0 = g_quark_from_static_string ("id")))) {
								switch (0) {
									default:
									{
										gchar** _tmp14_;
										gint _tmp14__length1;
										gint _tmp15_;
										const gchar* _tmp16_;
										gchar* _tmp17_;
										_tmp14_ = attr_values;
										_tmp14__length1 = attr_values_length1;
										_tmp15_ = i;
										_tmp16_ = _tmp14_[_tmp15_];
										_tmp17_ = g_strdup (_tmp16_);
										_g_free0 (id);
										id = _tmp17_;
										break;
									}
								}
							} else if (_tmp13_ == ((0 != _tmp12_label1) ? _tmp12_label1 : (_tmp12_label1 = g_quark_from_static_string ("num")))) {
								switch (0) {
									default:
									{
										gchar** _tmp18_;
										gint _tmp18__length1;
										gint _tmp19_;
										const gchar* _tmp20_;
										gint _tmp21_;
										_tmp18_ = attr_values;
										_tmp18__length1 = attr_values_length1;
										_tmp19_ = i;
										_tmp20_ = _tmp18_[_tmp19_];
										_tmp21_ = atoi (_tmp20_);
										num = _tmp21_;
										break;
									}
								}
							} else if ((_tmp13_ == ((0 != _tmp12_label2) ? _tmp12_label2 : (_tmp12_label2 = g_quark_from_static_string ("command")))) || (_tmp13_ == ((0 != _tmp12_label3) ? _tmp12_label3 : (_tmp12_label3 = g_quark_from_static_string ("package"))))) {
								switch (0) {
									default:
									{
										break;
									}
								}
							} else {
								switch (0) {
									default:
									{
										gchar** _tmp22_;
										gint _tmp22__length1;
										gint _tmp23_;
										const gchar* _tmp24_;
										gchar* _tmp25_;
										gchar* _tmp26_;
										gchar* _tmp27_;
										gchar* _tmp28_;
										GError* _tmp29_;
										GError* _tmp30_;
										_tmp22_ = attr_names;
										_tmp22__length1 = attr_names_length1;
										_tmp23_ = i;
										_tmp24_ = _tmp22_[_tmp23_];
										_tmp25_ = g_strconcat ("unknown attribute \"", _tmp24_, NULL);
										_tmp26_ = _tmp25_;
										_tmp27_ = g_strconcat (_tmp26_, "\"", NULL);
										_tmp28_ = _tmp27_;
										_tmp29_ = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, _tmp28_);
										_tmp30_ = _tmp29_;
										_g_free0 (_tmp28_);
										_g_free0 (_tmp26_);
										_inner_error_ = _tmp30_;
										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;
										}
									}
								}
							}
						}
					}
				}
				_tmp31_ = id;
				_tmp32_ = num;
				most_used_symbols_add_symbol (self, _tmp31_, _tmp32_);
				_g_free0 (id);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				const gchar* _tmp33_;
				gchar* _tmp34_;
				gchar* _tmp35_;
				gchar* _tmp36_;
				gchar* _tmp37_;
				GError* _tmp38_;
				GError* _tmp39_;
				_tmp33_ = name;
				_tmp34_ = g_strconcat ("unknown element \"", _tmp33_, NULL);
				_tmp35_ = _tmp34_;
				_tmp36_ = g_strconcat (_tmp35_, "\"", NULL);
				_tmp37_ = _tmp36_;
				_tmp38_ = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, _tmp37_);
				_tmp39_ = _tmp38_;
				_g_free0 (_tmp37_);
				_g_free0 (_tmp35_);
				_inner_error_ = _tmp39_;
				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_TYPE_TREE_MODEL) ? ((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;
}



