/* most_used_symbols.c generated by valac 0.18.0.1-c1117, 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_free0(var) ((var == NULL) ? NULL : (var = (g_markup_parse_context_free (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_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
	_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_ = FALSE;
	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;
		GtkListStore* _tmp4_;
		GtkTreeModel* _tmp5_;
		GtkTreeModel* model;
		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_ = FALSE;
	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_;
		_tmp3_ = TRUE;
		while (TRUE) {
			gboolean _tmp4_;
			gchar* cur_id = NULL;
			GtkListStore* _tmp7_;
			GtkTreeModel* _tmp8_;
			GtkTreeModel* model;
			GtkTreeModel* _tmp9_;
			GtkTreeIter _tmp10_;
			const gchar* _tmp11_;
			const gchar* _tmp12_;
			_tmp4_ = _tmp3_;
			if (!_tmp4_) {
				GtkListStore* _tmp5_;
				gboolean _tmp6_ = FALSE;
				_tmp5_ = self->priv->_store;
				_tmp6_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp5_, &_vala_iter);
				if (!_tmp6_) {
					break;
				}
			}
			_tmp3_ = FALSE;
			_tmp7_ = self->priv->_store;
			_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, GTK_TYPE_TREE_MODEL) ? ((GtkTreeModel*) _tmp7_) : NULL);
			model = _tmp8_;
			_tmp9_ = model;
			_tmp10_ = _vala_iter;
			gtk_tree_model_get (_tmp9_, &_tmp10_, SYMBOL_COLUMN_ID, &cur_id, -1);
			_tmp11_ = cur_id;
			_tmp12_ = id;
			if (g_strcmp0 (_tmp11_, _tmp12_) == 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) {
	const gchar* _tmp0_;
	GdkPixbuf* _tmp1_ = NULL;
	GdkPixbuf* pixbuf;
	GdkPixbuf* _tmp2_;
	gchar* command = NULL;
	gchar* tooltip = NULL;
	Symbols* _tmp3_ = NULL;
	Symbols* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gboolean _tmp8_ = FALSE;
	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;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* path;
	GFile* _tmp2_ = NULL;
	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 (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* _tmp0_ = NULL;
	GFile* file;
	GFile* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GFile* _tmp3_;
	gchar* _tmp4_ = NULL;
	gchar* contents;
	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 _tmp6_ = {0};
		GMarkupParser parser;
		GMarkupParser _tmp7_;
		GMarkupParseContext* _tmp8_;
		GMarkupParseContext* context;
		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 (_inner_error_ != NULL) {
			_g_markup_parse_context_free0 (context);
			goto __catch44_g_error;
		}
		_g_markup_parse_context_free0 (context);
	}
	goto __finally44;
	__catch44_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);
	}
	__finally44:
	if (_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;
				gint num;
				const gchar* _tmp32_;
				gint _tmp33_;
				id = NULL;
				num = 0;
				{
					gint i;
					i = 0;
					{
						gboolean _tmp4_;
						_tmp4_ = TRUE;
						while (TRUE) {
							gboolean _tmp5_;
							gint _tmp7_;
							gchar** _tmp8_;
							gint _tmp8__length1;
							gchar** _tmp9_;
							gint _tmp9__length1;
							gint _tmp10_;
							const gchar* _tmp11_;
							const gchar* _tmp12_;
							GQuark _tmp14_ = 0U;
							static GQuark _tmp13_label0 = 0;
							static GQuark _tmp13_label1 = 0;
							static GQuark _tmp13_label2 = 0;
							static GQuark _tmp13_label3 = 0;
							_tmp5_ = _tmp4_;
							if (!_tmp5_) {
								gint _tmp6_;
								_tmp6_ = i;
								i = _tmp6_ + 1;
							}
							_tmp4_ = FALSE;
							_tmp7_ = i;
							_tmp8_ = attr_names;
							_tmp8__length1 = attr_names_length1;
							if (!(_tmp7_ < _tmp8__length1)) {
								break;
							}
							_tmp9_ = attr_names;
							_tmp9__length1 = attr_names_length1;
							_tmp10_ = i;
							_tmp11_ = _tmp9_[_tmp10_];
							_tmp12_ = _tmp11_;
							_tmp14_ = (NULL == _tmp12_) ? 0 : g_quark_from_string (_tmp12_);
							if (_tmp14_ == ((0 != _tmp13_label0) ? _tmp13_label0 : (_tmp13_label0 = g_quark_from_static_string ("id")))) {
								switch (0) {
									default:
									{
										gchar** _tmp15_;
										gint _tmp15__length1;
										gint _tmp16_;
										const gchar* _tmp17_;
										gchar* _tmp18_;
										_tmp15_ = attr_values;
										_tmp15__length1 = attr_values_length1;
										_tmp16_ = i;
										_tmp17_ = _tmp15_[_tmp16_];
										_tmp18_ = g_strdup (_tmp17_);
										_g_free0 (id);
										id = _tmp18_;
										break;
									}
								}
							} else if (_tmp14_ == ((0 != _tmp13_label1) ? _tmp13_label1 : (_tmp13_label1 = g_quark_from_static_string ("num")))) {
								switch (0) {
									default:
									{
										gchar** _tmp19_;
										gint _tmp19__length1;
										gint _tmp20_;
										const gchar* _tmp21_;
										gint _tmp22_ = 0;
										_tmp19_ = attr_values;
										_tmp19__length1 = attr_values_length1;
										_tmp20_ = i;
										_tmp21_ = _tmp19_[_tmp20_];
										_tmp22_ = atoi (_tmp21_);
										num = _tmp22_;
										break;
									}
								}
							} else if ((_tmp14_ == ((0 != _tmp13_label2) ? _tmp13_label2 : (_tmp13_label2 = g_quark_from_static_string ("command")))) || (_tmp14_ == ((0 != _tmp13_label3) ? _tmp13_label3 : (_tmp13_label3 = g_quark_from_static_string ("package"))))) {
								switch (0) {
									default:
									{
										break;
									}
								}
							} else {
								switch (0) {
									default:
									{
										gchar** _tmp23_;
										gint _tmp23__length1;
										gint _tmp24_;
										const gchar* _tmp25_;
										gchar* _tmp26_;
										gchar* _tmp27_;
										gchar* _tmp28_;
										gchar* _tmp29_;
										GError* _tmp30_;
										GError* _tmp31_;
										_tmp23_ = attr_names;
										_tmp23__length1 = attr_names_length1;
										_tmp24_ = i;
										_tmp25_ = _tmp23_[_tmp24_];
										_tmp26_ = g_strconcat ("unknown attribute \"", _tmp25_, NULL);
										_tmp27_ = _tmp26_;
										_tmp28_ = g_strconcat (_tmp27_, "\"", NULL);
										_tmp29_ = _tmp28_;
										_tmp30_ = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, _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_);
											_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;
										}
									}
								}
							}
						}
					}
				}
				_tmp32_ = id;
				_tmp33_ = num;
				most_used_symbols_add_symbol (self, _tmp32_, _tmp33_);
				_g_free0 (id);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				const gchar* _tmp34_;
				gchar* _tmp35_;
				gchar* _tmp36_;
				gchar* _tmp37_;
				gchar* _tmp38_;
				GError* _tmp39_;
				GError* _tmp40_;
				_tmp34_ = name;
				_tmp35_ = g_strconcat ("unknown element \"", _tmp34_, NULL);
				_tmp36_ = _tmp35_;
				_tmp37_ = g_strconcat (_tmp36_, "\"", NULL);
				_tmp38_ = _tmp37_;
				_tmp39_ = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, _tmp38_);
				_tmp40_ = _tmp39_;
				_g_free0 (_tmp38_);
				_g_free0 (_tmp36_);
				_inner_error_ = _tmp40_;
				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* _tmp1_ = NULL;
	GFile* file;
	GtkTreeIter iter = {0};
	GtkListStore* _tmp2_;
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_ = FALSE;
	gboolean is_empty;
	gboolean _tmp5_;
	gchar* _tmp7_;
	gchar* content;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	GFile* _tmp24_;
	const gchar* _tmp25_;
	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_;
		_tmp8_ = TRUE;
		while (TRUE) {
			gboolean _tmp9_;
			gchar* id = NULL;
			gint num = 0;
			GtkListStore* _tmp12_;
			GtkTreeModel* _tmp13_;
			GtkTreeModel* model;
			GtkTreeModel* _tmp14_;
			GtkTreeIter _tmp15_;
			const gchar* _tmp16_;
			const gchar* _tmp17_;
			gint _tmp18_;
			gchar* _tmp19_ = NULL;
			gchar* _tmp20_;
			gchar* _tmp21_;
			_tmp9_ = _tmp8_;
			if (!_tmp9_) {
				GtkListStore* _tmp10_;
				gboolean _tmp11_ = FALSE;
				_tmp10_ = self->priv->_store;
				_tmp11_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp10_, &iter);
				if (!_tmp11_) {
					break;
				}
			}
			_tmp8_ = FALSE;
			_tmp12_ = self->priv->_store;
			_tmp13_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp12_, GTK_TYPE_TREE_MODEL) ? ((GtkTreeModel*) _tmp12_) : NULL);
			model = _tmp13_;
			_tmp14_ = model;
			_tmp15_ = iter;
			gtk_tree_model_get (_tmp14_, &_tmp15_, SYMBOL_COLUMN_ID, &id, MOST_USED_SYMBOLS_SYMBOL_COLUMN_NUM, &num, -1);
			_tmp16_ = content;
			_tmp17_ = id;
			_tmp18_ = num;
			_tmp19_ = g_strdup_printf ("  <symbol id=\"%s\" num=\"%d\" />\n", _tmp17_, _tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_strconcat (_tmp16_, _tmp20_, NULL);
			_g_free0 (content);
			content = _tmp21_;
			_g_free0 (_tmp20_);
			_g_object_unref0 (model);
			_g_free0 (id);
		}
	}
	_tmp22_ = content;
	_tmp23_ = g_strconcat (_tmp22_, "</symbols>\n", NULL);
	_g_free0 (content);
	content = _tmp23_;
	_tmp24_ = file;
	_tmp25_ = content;
	utils_save_file (_tmp24_, _tmp25_, 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;
}



