/* utils.c generated by valac 0.21.2.9-2b15d, the Vala compiler
 * generated from utils.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 <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib/gi18n-lib.h>

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __g_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))

#define TYPE_SYNCTEX (synctex_get_type ())
#define SYNCTEX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SYNCTEX, Synctex))
#define SYNCTEX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SYNCTEX, SynctexClass))
#define IS_SYNCTEX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SYNCTEX))
#define IS_SYNCTEX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SYNCTEX))
#define SYNCTEX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SYNCTEX, SynctexClass))

typedef struct _Synctex Synctex;
typedef struct _SynctexClass SynctexClass;
#define _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))



gchar* utils_str_middle_truncate (const gchar* str, guint max_length);
gboolean utils_char_is_escaped (const gchar* text, glong char_index);
const gchar* utils_get_string_from_resource (const gchar* resource_path);
gchar* utils_replace_home_dir_with_tilde (const gchar* uri);
gchar* utils_uri_get_dirname (const gchar* uri);
gchar* utils_get_dirname_for_display (GFile* location);
gchar* utils_get_shortname (const gchar* path);
glong utils_get_extension_pos (const gchar* path);
gchar* utils_get_extension (const gchar* path);
void utils_delete_file (GFile* file);
gboolean utils_create_parent_directories (GFile* file);
gboolean utils_save_file (GFile* file, const gchar* contents, gboolean make_backup);
gchar* utils_load_file (GFile* file);
gchar* utils_get_relative_path (GFile* origin, GFile* target, GFile* common_dir);
static void _g_object_unref0_ (gpointer var);
static void _g_list_free__g_object_unref0_ (GList* self);
void utils_show_uri (GdkScreen* screen, const gchar* uri, GError** error);
gboolean utils_default_document_viewer_is_evince (const gchar* uri);
GType synctex_get_type (void) G_GNUC_CONST;
Synctex* synctex_get_default (void);
gboolean synctex_create_evince_window (Synctex* self, const gchar* pdf_uri);
GtkScrolledWindow* utils_add_scrollbar (GtkWidget* child);
gboolean utils_tree_model_iter_prev (GtkTreeModel* model, GtkTreeIter* iter);
gint utils_get_selected_row (GtkTreeView* view, GtkTreeIter* iter);
GdkPixbuf* utils_get_pixbuf_from_stock (const gchar* stock_id, GtkIconSize size);
GtkGrid* utils_get_dialog_component (const gchar* title, GtkWidget* widget);
GtkWindow* utils_get_toplevel_window (GtkWidget* widget);
GtkDialog* utils_get_reset_all_confirm_dialog (GtkWindow* window, const gchar* msg);
void utils_flush_queue (void);


/*************************************************************************/
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;
	gboolean _tmp13_ = FALSE;
	glong _tmp14_ = 0L;
	gboolean _tmp17_ = FALSE;
	glong _tmp18_ = 0L;
	glong _tmp19_ = 0L;
	glong _tmp20_ = 0L;
	glong _tmp21_ = 0L;
	glong _tmp22_ = 0L;
	gchar* _tmp23_ = 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;
	}
	_tmp12_ = _tmp8_;
	g_return_val_if_fail (_tmp12_, NULL);
	_tmp14_ = end;
	if (_tmp14_ >= ((glong) 0)) {
		glong _tmp15_ = 0L;
		glong _tmp16_ = 0L;
		_tmp15_ = end;
		_tmp16_ = string_length;
		_tmp13_ = _tmp15_ <= _tmp16_;
	} else {
		_tmp13_ = FALSE;
	}
	_tmp17_ = _tmp13_;
	g_return_val_if_fail (_tmp17_, NULL);
	_tmp18_ = start;
	_tmp19_ = end;
	g_return_val_if_fail (_tmp18_ <= _tmp19_, NULL);
	_tmp20_ = start;
	_tmp21_ = end;
	_tmp22_ = start;
	_tmp23_ = g_strndup (((gchar*) self) + _tmp20_, (gsize) (_tmp21_ - _tmp22_));
	result = _tmp23_;
	return result;
}


gchar* utils_str_middle_truncate (const gchar* str, guint max_length) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	guint _tmp3_ = 0U;
	guint half_length = 0U;
	guint _tmp6_ = 0U;
	gint l = 0;
	const gchar* _tmp7_ = NULL;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	const gchar* _tmp10_ = NULL;
	guint _tmp11_ = 0U;
	gchar* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	const gchar* _tmp16_ = NULL;
	gint _tmp17_ = 0;
	guint _tmp18_ = 0U;
	gint _tmp19_ = 0;
	gchar* _tmp20_ = NULL;
	gchar* _tmp21_ = NULL;
	gchar* _tmp22_ = NULL;
	gchar* _tmp23_ = NULL;
	g_return_val_if_fail (str != NULL, NULL);
	_tmp0_ = str;
	_tmp1_ = strlen (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = max_length;
	if (((guint) _tmp2_) <= _tmp3_) {
		const gchar* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		_tmp4_ = str;
		_tmp5_ = g_strdup (_tmp4_);
		result = _tmp5_;
		return result;
	}
	_tmp6_ = max_length;
	half_length = (_tmp6_ - 4) / 2;
	_tmp7_ = str;
	_tmp8_ = strlen (_tmp7_);
	_tmp9_ = _tmp8_;
	l = _tmp9_;
	_tmp10_ = str;
	_tmp11_ = half_length;
	_tmp12_ = string_slice (_tmp10_, (glong) 0, (glong) _tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_strconcat (_tmp13_, "...", NULL);
	_tmp15_ = _tmp14_;
	_tmp16_ = str;
	_tmp17_ = l;
	_tmp18_ = half_length;
	_tmp19_ = l;
	_tmp20_ = string_slice (_tmp16_, (glong) (_tmp17_ - _tmp18_), (glong) _tmp19_);
	_tmp21_ = _tmp20_;
	_tmp22_ = g_strconcat (_tmp15_, _tmp21_, NULL);
	_tmp23_ = _tmp22_;
	_g_free0 (_tmp21_);
	_g_free0 (_tmp15_);
	_g_free0 (_tmp13_);
	result = _tmp23_;
	return result;
}


static gboolean string_get_prev_char (const gchar* self, gint* index, gunichar* c) {
	gunichar _vala_c = 0U;
	gboolean result = FALSE;
	gint _tmp0_ = 0;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = *index;
	if (0 < _tmp0_) {
		gint _tmp1_ = 0;
		gchar* _tmp2_ = NULL;
		gint _tmp3_ = 0;
		gunichar _tmp4_ = 0U;
		_tmp1_ = *index;
		_tmp2_ = g_utf8_prev_char (((gchar*) self) + _tmp1_);
		*index = (gint) (_tmp2_ - ((gchar*) self));
		_tmp3_ = *index;
		_tmp4_ = g_utf8_get_char (((gchar*) self) + _tmp3_);
		_vala_c = _tmp4_;
		result = TRUE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	} else {
		_vala_c = (gunichar) 0;
		result = FALSE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	}
	if (c) {
		*c = _vala_c;
	}
}


gboolean utils_char_is_escaped (const gchar* text, glong char_index) {
	gboolean result = FALSE;
	glong _tmp0_ = 0L;
	const gchar* _tmp1_ = NULL;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	gboolean escaped = FALSE;
	gint index = 0;
	glong _tmp4_ = 0L;
	gunichar cur_char = 0U;
	g_return_val_if_fail (text != NULL, FALSE);
	_tmp0_ = char_index;
	_tmp1_ = text;
	_tmp2_ = strlen (_tmp1_);
	_tmp3_ = _tmp2_;
	g_return_val_if_fail (_tmp0_ < ((glong) _tmp3_), FALSE);
	escaped = FALSE;
	_tmp4_ = char_index;
	index = (gint) _tmp4_;
	while (TRUE) {
		const gchar* _tmp5_ = NULL;
		gunichar _tmp6_ = 0U;
		gboolean _tmp7_ = FALSE;
		gunichar _tmp8_ = 0U;
		gboolean _tmp9_ = FALSE;
		_tmp5_ = text;
		_tmp7_ = string_get_prev_char (_tmp5_, &index, &_tmp6_);
		cur_char = _tmp6_;
		if (!_tmp7_) {
			break;
		}
		_tmp8_ = cur_char;
		if (_tmp8_ != ((gunichar) '\\')) {
			break;
		}
		_tmp9_ = escaped;
		escaped = !_tmp9_;
	}
	result = escaped;
	return result;
}


const gchar* utils_get_string_from_resource (const gchar* resource_path) {
	const gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (resource_path != NULL, NULL);
	{
		GBytes* bytes = NULL;
		const gchar* _tmp0_ = NULL;
		GBytes* _tmp1_ = NULL;
		gsize _tmp2_;
		guint8* _tmp3_ = NULL;
		_tmp0_ = resource_path;
		_tmp1_ = g_resources_lookup_data (_tmp0_, 0, &_inner_error_);
		bytes = _tmp1_;
		if (_inner_error_ != NULL) {
			goto __catch69_g_error;
		}
		_tmp3_ = g_bytes_get_data (bytes, &_tmp2_);
		result = (const gchar*) _tmp3_;
		_g_bytes_unref0 (bytes);
		return result;
	}
	goto __finally69;
	__catch69_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp4_ = NULL;
		GError* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = resource_path;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_warning ("utils.vala:64: Failed to load data from resource '%s': %s", _tmp4_, _tmp6_);
		result = NULL;
		_g_error_free0 (e);
		return result;
	}
	__finally69:
	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 NULL;
}


/*************************************************************************/
gchar* utils_replace_home_dir_with_tilde (const gchar* uri) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* home = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp20_ = NULL;
	gchar* _tmp21_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	g_return_val_if_fail (_tmp0_ != NULL, NULL);
	_tmp1_ = g_get_home_dir ();
	_tmp2_ = g_strdup (_tmp1_);
	home = _tmp2_;
	_tmp3_ = uri;
	_tmp4_ = home;
	if (g_strcmp0 (_tmp3_, _tmp4_) == 0) {
		gchar* _tmp5_ = NULL;
		_tmp5_ = g_strdup ("~");
		result = _tmp5_;
		_g_free0 (home);
		return result;
	}
	_tmp6_ = uri;
	_tmp7_ = home;
	_tmp8_ = g_str_has_prefix (_tmp6_, _tmp7_);
	if (_tmp8_) {
		const gchar* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		gint _tmp11_ = 0;
		gint _tmp12_ = 0;
		const gchar* _tmp13_ = NULL;
		gint _tmp14_ = 0;
		gint _tmp15_ = 0;
		gchar* _tmp16_ = NULL;
		gchar* _tmp17_ = NULL;
		gchar* _tmp18_ = NULL;
		gchar* _tmp19_ = NULL;
		_tmp9_ = uri;
		_tmp10_ = home;
		_tmp11_ = strlen (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = uri;
		_tmp14_ = strlen (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = string_slice (_tmp9_, (glong) _tmp12_, (glong) _tmp15_);
		_tmp17_ = _tmp16_;
		_tmp18_ = g_strconcat ("~", _tmp17_, NULL);
		_tmp19_ = _tmp18_;
		_g_free0 (_tmp17_);
		result = _tmp19_;
		_g_free0 (home);
		return result;
	}
	_tmp20_ = uri;
	_tmp21_ = g_strdup (_tmp20_);
	result = _tmp21_;
	_g_free0 (home);
	return result;
}


gchar* utils_uri_get_dirname (const gchar* uri) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* dir = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	g_return_val_if_fail (_tmp0_ != NULL, NULL);
	_tmp1_ = uri;
	_tmp2_ = g_path_get_dirname (_tmp1_);
	dir = _tmp2_;
	_tmp3_ = dir;
	if (g_strcmp0 (_tmp3_, ".") == 0) {
		result = NULL;
		_g_free0 (dir);
		return result;
	}
	_tmp4_ = dir;
	_tmp5_ = utils_replace_home_dir_with_tilde (_tmp4_);
	result = _tmp5_;
	_g_free0 (dir);
	return result;
}


gchar* utils_get_dirname_for_display (GFile* location) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (location != NULL, NULL);
	{
		GMount* mount = NULL;
		GFile* _tmp0_ = NULL;
		GMount* _tmp1_ = NULL;
		gchar* mount_name = NULL;
		GMount* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		GFile* _tmp5_ = NULL;
		gchar* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gchar* dirname = NULL;
		const gchar* _tmp10_ = NULL;
		gchar* _tmp11_ = NULL;
		gboolean _tmp12_ = FALSE;
		const gchar* _tmp13_ = NULL;
		gboolean _tmp15_ = FALSE;
		const gchar* _tmp16_ = NULL;
		gchar* _tmp17_ = NULL;
		gchar* _tmp18_ = NULL;
		const gchar* _tmp19_ = NULL;
		gchar* _tmp20_ = NULL;
		gchar* _tmp21_ = NULL;
		_tmp0_ = location;
		_tmp1_ = g_file_find_enclosing_mount (_tmp0_, NULL, &_inner_error_);
		mount = _tmp1_;
		if (_inner_error_ != NULL) {
			goto __catch70_g_error;
		}
		_tmp2_ = mount;
		_tmp3_ = g_mount_get_name (_tmp2_);
		mount_name = _tmp3_;
		_tmp5_ = location;
		_tmp6_ = g_file_get_path (_tmp5_);
		_tmp4_ = _tmp6_;
		_tmp7_ = _tmp4_;
		if (_tmp7_ == NULL) {
			GFile* _tmp8_ = NULL;
			gchar* _tmp9_ = NULL;
			_tmp8_ = location;
			_tmp9_ = g_file_get_uri (_tmp8_);
			_g_free0 (_tmp4_);
			_tmp4_ = _tmp9_;
		}
		_tmp10_ = _tmp4_;
		_tmp11_ = utils_uri_get_dirname (_tmp10_);
		dirname = _tmp11_;
		_tmp13_ = dirname;
		if (_tmp13_ == NULL) {
			_tmp12_ = TRUE;
		} else {
			const gchar* _tmp14_ = NULL;
			_tmp14_ = dirname;
			_tmp12_ = g_strcmp0 (_tmp14_, ".") == 0;
		}
		_tmp15_ = _tmp12_;
		if (_tmp15_) {
			result = mount_name;
			_g_free0 (dirname);
			_g_free0 (_tmp4_);
			_g_object_unref0 (mount);
			return result;
		}
		_tmp16_ = mount_name;
		_tmp17_ = g_strconcat (_tmp16_, " ", NULL);
		_tmp18_ = _tmp17_;
		_tmp19_ = dirname;
		_tmp20_ = g_strconcat (_tmp18_, _tmp19_, NULL);
		_tmp21_ = _tmp20_;
		_g_free0 (_tmp18_);
		result = _tmp21_;
		_g_free0 (dirname);
		_g_free0 (_tmp4_);
		_g_free0 (mount_name);
		_g_object_unref0 (mount);
		return result;
	}
	goto __finally70;
	__catch70_g_error:
	{
		GError* e = NULL;
		gchar* _tmp22_ = NULL;
		GFile* _tmp23_ = NULL;
		gchar* _tmp24_ = NULL;
		const gchar* _tmp25_ = NULL;
		const gchar* _tmp28_ = NULL;
		gchar* _tmp29_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp23_ = location;
		_tmp24_ = g_file_get_path (_tmp23_);
		_tmp22_ = _tmp24_;
		_tmp25_ = _tmp22_;
		if (_tmp25_ == NULL) {
			GFile* _tmp26_ = NULL;
			gchar* _tmp27_ = NULL;
			_tmp26_ = location;
			_tmp27_ = g_file_get_uri (_tmp26_);
			_g_free0 (_tmp22_);
			_tmp22_ = _tmp27_;
		}
		_tmp28_ = _tmp22_;
		_tmp29_ = utils_uri_get_dirname (_tmp28_);
		result = _tmp29_;
		_g_free0 (_tmp22_);
		_g_error_free0 (e);
		return result;
	}
	__finally70:
	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 NULL;
}


gchar* utils_get_shortname (const gchar* path) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	glong _tmp2_ = 0L;
	gchar* _tmp3_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = path;
	_tmp1_ = path;
	_tmp2_ = utils_get_extension_pos (_tmp1_);
	_tmp3_ = string_slice (_tmp0_, (glong) 0, _tmp2_);
	result = _tmp3_;
	return result;
}


gchar* utils_get_extension (const gchar* path) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	glong _tmp2_ = 0L;
	const gchar* _tmp3_ = NULL;
	gint _tmp4_ = 0;
	gint _tmp5_ = 0;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = path;
	_tmp1_ = path;
	_tmp2_ = utils_get_extension_pos (_tmp1_);
	_tmp3_ = path;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = string_slice (_tmp0_, _tmp2_, (glong) _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_utf8_strdown (_tmp7_, (gssize) (-1));
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	result = _tmp9_;
	return result;
}


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


glong utils_get_extension_pos (const gchar* path) {
	glong result = 0L;
	glong l = 0L;
	const gchar* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	g_return_val_if_fail (path != NULL, 0L);
	_tmp0_ = path;
	_tmp1_ = strlen (_tmp0_);
	_tmp2_ = _tmp1_;
	l = (glong) _tmp2_;
	{
		glong i = 0L;
		glong _tmp3_ = 0L;
		_tmp3_ = l;
		i = _tmp3_ - 1;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp5_ = FALSE;
				glong _tmp7_ = 0L;
				const gchar* _tmp8_ = NULL;
				glong _tmp9_ = 0L;
				gchar _tmp10_ = '\0';
				_tmp5_ = _tmp4_;
				if (!_tmp5_) {
					glong _tmp6_ = 0L;
					_tmp6_ = i;
					i = _tmp6_ - 1;
				}
				_tmp4_ = FALSE;
				_tmp7_ = i;
				if (!(_tmp7_ >= ((glong) 0))) {
					break;
				}
				_tmp8_ = path;
				_tmp9_ = i;
				_tmp10_ = string_get (_tmp8_, _tmp9_);
				if (_tmp10_ == '/') {
					result = l;
					return result;
				} else {
					const gchar* _tmp11_ = NULL;
					glong _tmp12_ = 0L;
					gchar _tmp13_ = '\0';
					_tmp11_ = path;
					_tmp12_ = i;
					_tmp13_ = string_get (_tmp11_, _tmp12_);
					if (_tmp13_ == '.') {
						result = i;
						return result;
					}
				}
			}
		}
	}
	result = l;
	return result;
}


void utils_delete_file (GFile* file) {
	GFile* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (file != NULL);
	_tmp0_ = file;
	_tmp1_ = g_file_query_exists (_tmp0_, NULL);
	if (!_tmp1_) {
		return;
	}
	{
		GFile* _tmp2_ = NULL;
		_tmp2_ = file;
		g_file_delete (_tmp2_, NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch71_g_error;
		}
	}
	goto __finally71;
	__catch71_g_error:
	{
		GError* e = NULL;
		GFile* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		GError* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = file;
		_tmp4_ = g_file_get_parse_name (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_warning ("utils.vala:158: Delete file '%s' failed: %s", _tmp5_, _tmp7_);
		_g_free0 (_tmp5_);
		_g_error_free0 (e);
	}
	__finally71:
	if (_inner_error_ != NULL) {
		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;
	}
}


gboolean utils_create_parent_directories (GFile* file) {
	gboolean result = FALSE;
	GFile* parent = NULL;
	GFile* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GFile* _tmp3_ = NULL;
	gboolean _tmp6_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, FALSE);
	_tmp0_ = file;
	_tmp1_ = g_file_get_parent (_tmp0_);
	parent = _tmp1_;
	_tmp3_ = parent;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		GFile* _tmp4_ = NULL;
		gboolean _tmp5_ = FALSE;
		_tmp4_ = parent;
		_tmp5_ = g_file_query_exists (_tmp4_, NULL);
		_tmp2_ = _tmp5_;
	}
	_tmp6_ = _tmp2_;
	if (_tmp6_) {
		result = TRUE;
		_g_object_unref0 (parent);
		return result;
	}
	{
		GFile* _tmp7_ = NULL;
		_tmp7_ = parent;
		g_file_make_directory_with_parents (_tmp7_, NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch72_g_error;
		}
	}
	goto __finally72;
	__catch72_g_error:
	{
		GError* e = NULL;
		GFile* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		gchar* _tmp10_ = NULL;
		GError* _tmp11_ = NULL;
		const gchar* _tmp12_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp8_ = file;
		_tmp9_ = g_file_get_parse_name (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = e;
		_tmp12_ = _tmp11_->message;
		g_warning ("utils.vala:175: Failed to create directory parents for the file '%s': " \
"%s", _tmp10_, _tmp12_);
		_g_free0 (_tmp10_);
		result = FALSE;
		_g_error_free0 (e);
		_g_object_unref0 (parent);
		return result;
	}
	__finally72:
	if (_inner_error_ != NULL) {
		_g_object_unref0 (parent);
		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 FALSE;
	}
	result = TRUE;
	_g_object_unref0 (parent);
	return result;
}


static guint8* string_get_data (const gchar* self, int* result_length1) {
	guint8* result;
	guint8* res = NULL;
	gint res_length1 = 0;
	gint _res_size_ = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	guint8* _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	guint8* _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res_length1;
	_tmp3_ = res;
	_tmp3__length1 = res_length1;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _tmp3__length1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}


gboolean utils_save_file (GFile* file, const gchar* contents, gboolean make_backup) {
	gboolean result = FALSE;
	GFile* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, FALSE);
	g_return_val_if_fail (contents != NULL, FALSE);
	_tmp0_ = file;
	_tmp1_ = utils_create_parent_directories (_tmp0_);
	if (!_tmp1_) {
		result = FALSE;
		return result;
	}
	{
		GFile* _tmp2_ = NULL;
		const gchar* _tmp3_ = NULL;
		guint8* _tmp4_ = NULL;
		gint _tmp4__length1 = 0;
		guint8* _tmp5_ = NULL;
		gint _tmp5__length1 = 0;
		gboolean _tmp6_ = FALSE;
		_tmp2_ = file;
		_tmp3_ = contents;
		_tmp4_ = string_get_data (_tmp3_, &_tmp4__length1);
		_tmp5_ = _tmp4_;
		_tmp5__length1 = _tmp4__length1;
		_tmp6_ = make_backup;
		g_file_replace_contents (_tmp2_, _tmp5_, (gsize) _tmp5__length1, NULL, _tmp6_, G_FILE_CREATE_NONE, NULL, NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch73_g_error;
		}
	}
	goto __finally73;
	__catch73_g_error:
	{
		GError* e = NULL;
		GFile* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		GError* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp7_ = file;
		_tmp8_ = g_file_get_parse_name (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = e;
		_tmp11_ = _tmp10_->message;
		g_warning ("utils.vala:195: Failed to save the file '%s': %s", _tmp9_, _tmp11_);
		_g_free0 (_tmp9_);
		result = FALSE;
		_g_error_free0 (e);
		return result;
	}
	__finally73:
	if (_inner_error_ != NULL) {
		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 FALSE;
	}
	result = TRUE;
	return result;
}


gchar* utils_load_file (GFile* file) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	{
		guint8* chars = NULL;
		gint chars_length1 = 0;
		gint _chars_size_ = 0;
		GFile* _tmp0_ = NULL;
		guint8* _tmp1_ = NULL;
		gsize _tmp2_;
		guint8* _tmp3_ = NULL;
		gint _tmp3__length1 = 0;
		_tmp0_ = file;
		g_file_load_contents (_tmp0_, NULL, &_tmp1_, &_tmp2_, NULL, &_inner_error_);
		chars = (g_free (chars), NULL);
		chars = _tmp1_;
		chars_length1 = _tmp2_;
		_chars_size_ = chars_length1;
		if (_inner_error_ != NULL) {
			chars = (g_free (chars), NULL);
			goto __catch74_g_error;
		}
		_tmp3_ = chars;
		_tmp3__length1 = chars_length1;
		chars = NULL;
		result = (gchar*) _tmp3_;
		chars = (g_free (chars), NULL);
		return result;
	}
	goto __finally74;
	__catch74_g_error:
	{
		GError* e = NULL;
		GFile* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		gchar* _tmp6_ = NULL;
		GError* _tmp7_ = NULL;
		const gchar* _tmp8_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = file;
		_tmp5_ = g_file_get_parse_name (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		g_warning ("utils.vala:214: Failed to load the file '%s': %s", _tmp6_, _tmp8_);
		_g_free0 (_tmp6_);
		result = NULL;
		_g_error_free0 (e);
		return result;
	}
	__finally74:
	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 NULL;
}


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


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static void _g_list_free__g_object_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
	g_list_free (self);
}


gchar* utils_get_relative_path (GFile* origin, GFile* target, GFile* common_dir) {
	gchar* result = NULL;
	GFile* origin_dir = NULL;
	GFile* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GFile* target_parent = NULL;
	GFile* _tmp7_ = NULL;
	GFile* _tmp8_ = NULL;
	GFile* _tmp9_ = NULL;
	GFile* _tmp10_ = NULL;
	GFile* _tmp11_ = NULL;
	GFile* _tmp12_ = NULL;
	gboolean _tmp13_ = FALSE;
	GList* target_dirs = NULL;
	GList* origin_dirs = NULL;
	guint dir_index = 0U;
	guint nb_common_dirs = 0U;
	guint _tmp56_ = 0U;
	gchar* relative_path = NULL;
	gchar* _tmp57_ = NULL;
	guint nb_remaining_origin_dirs = 0U;
	GList* _tmp58_ = NULL;
	guint _tmp59_ = 0U;
	guint _tmp60_ = 0U;
	const gchar* _tmp86_ = NULL;
	GFile* _tmp87_ = NULL;
	gchar* _tmp88_ = NULL;
	gchar* _tmp89_ = NULL;
	gchar* _tmp90_ = NULL;
	g_return_val_if_fail (origin != NULL, NULL);
	g_return_val_if_fail (target != NULL, NULL);
	g_return_val_if_fail (common_dir != NULL, NULL);
	_tmp0_ = origin;
	_tmp1_ = common_dir;
	_tmp2_ = g_file_equal (_tmp0_, _tmp1_);
	if (_tmp2_) {
		GFile* _tmp3_ = NULL;
		GFile* _tmp4_ = NULL;
		_tmp3_ = origin;
		_tmp4_ = _g_object_ref0 (_tmp3_);
		_g_object_unref0 (origin_dir);
		origin_dir = _tmp4_;
	} else {
		GFile* _tmp5_ = NULL;
		GFile* _tmp6_ = NULL;
		_tmp5_ = origin;
		_tmp6_ = g_file_get_parent (_tmp5_);
		_g_object_unref0 (origin_dir);
		origin_dir = _tmp6_;
	}
	_tmp7_ = target;
	_tmp8_ = g_file_get_parent (_tmp7_);
	target_parent = _tmp8_;
	_tmp9_ = origin_dir;
	g_return_val_if_fail (_tmp9_ != NULL, NULL);
	_tmp10_ = target_parent;
	g_return_val_if_fail (_tmp10_ != NULL, NULL);
	_tmp11_ = target_parent;
	_tmp12_ = origin_dir;
	_tmp13_ = g_file_equal (_tmp11_, _tmp12_);
	if (_tmp13_) {
		GFile* _tmp14_ = NULL;
		gchar* _tmp15_ = NULL;
		_tmp14_ = target;
		_tmp15_ = g_file_get_basename (_tmp14_);
		result = _tmp15_;
		_g_object_unref0 (target_parent);
		_g_object_unref0 (origin_dir);
		return result;
	}
	target_dirs = NULL;
	origin_dirs = NULL;
	while (TRUE) {
		gboolean _tmp16_ = FALSE;
		GFile* _tmp17_ = NULL;
		gboolean _tmp21_ = FALSE;
		GFile* _tmp22_ = NULL;
		GFile* _tmp23_ = NULL;
		GFile* _tmp24_ = NULL;
		GFile* _tmp25_ = NULL;
		_tmp17_ = target_parent;
		if (_tmp17_ != NULL) {
			GFile* _tmp18_ = NULL;
			GFile* _tmp19_ = NULL;
			gboolean _tmp20_ = FALSE;
			_tmp18_ = target_parent;
			_tmp19_ = common_dir;
			_tmp20_ = g_file_equal (_tmp18_, _tmp19_);
			_tmp16_ = !_tmp20_;
		} else {
			_tmp16_ = FALSE;
		}
		_tmp21_ = _tmp16_;
		if (!_tmp21_) {
			break;
		}
		_tmp22_ = target_parent;
		_tmp23_ = _g_object_ref0 (_tmp22_);
		target_dirs = g_list_prepend (target_dirs, _tmp23_);
		_tmp24_ = target_parent;
		_tmp25_ = g_file_get_parent (_tmp24_);
		_g_object_unref0 (target_parent);
		target_parent = _tmp25_;
	}
	while (TRUE) {
		gboolean _tmp26_ = FALSE;
		GFile* _tmp27_ = NULL;
		gboolean _tmp31_ = FALSE;
		GFile* _tmp32_ = NULL;
		GFile* _tmp33_ = NULL;
		GFile* _tmp34_ = NULL;
		GFile* _tmp35_ = NULL;
		_tmp27_ = origin_dir;
		if (_tmp27_ != NULL) {
			GFile* _tmp28_ = NULL;
			GFile* _tmp29_ = NULL;
			gboolean _tmp30_ = FALSE;
			_tmp28_ = origin_dir;
			_tmp29_ = common_dir;
			_tmp30_ = g_file_equal (_tmp28_, _tmp29_);
			_tmp26_ = !_tmp30_;
		} else {
			_tmp26_ = FALSE;
		}
		_tmp31_ = _tmp26_;
		if (!_tmp31_) {
			break;
		}
		_tmp32_ = origin_dir;
		_tmp33_ = _g_object_ref0 (_tmp32_);
		origin_dirs = g_list_prepend (origin_dirs, _tmp33_);
		_tmp34_ = origin_dir;
		_tmp35_ = g_file_get_parent (_tmp34_);
		_g_object_unref0 (origin_dir);
		origin_dir = _tmp35_;
	}
	dir_index = (guint) 0;
	while (TRUE) {
		gboolean _tmp36_ = FALSE;
		guint _tmp37_ = 0U;
		GList* _tmp38_ = NULL;
		guint _tmp39_ = 0U;
		gboolean _tmp43_ = FALSE;
		GFile* cur_target_dir = NULL;
		GList* _tmp44_ = NULL;
		guint _tmp45_ = 0U;
		gconstpointer _tmp46_ = NULL;
		GFile* _tmp47_ = NULL;
		GFile* cur_origin_dir = NULL;
		GList* _tmp48_ = NULL;
		guint _tmp49_ = 0U;
		gconstpointer _tmp50_ = NULL;
		GFile* _tmp51_ = NULL;
		GFile* _tmp52_ = NULL;
		GFile* _tmp53_ = NULL;
		gboolean _tmp54_ = FALSE;
		guint _tmp55_ = 0U;
		_tmp37_ = dir_index;
		_tmp38_ = target_dirs;
		_tmp39_ = g_list_length (_tmp38_);
		if (_tmp37_ < _tmp39_) {
			guint _tmp40_ = 0U;
			GList* _tmp41_ = NULL;
			guint _tmp42_ = 0U;
			_tmp40_ = dir_index;
			_tmp41_ = origin_dirs;
			_tmp42_ = g_list_length (_tmp41_);
			_tmp36_ = _tmp40_ < _tmp42_;
		} else {
			_tmp36_ = FALSE;
		}
		_tmp43_ = _tmp36_;
		if (!_tmp43_) {
			break;
		}
		_tmp44_ = target_dirs;
		_tmp45_ = dir_index;
		_tmp46_ = g_list_nth_data (_tmp44_, _tmp45_);
		_tmp47_ = _g_object_ref0 ((GFile*) _tmp46_);
		cur_target_dir = _tmp47_;
		_tmp48_ = origin_dirs;
		_tmp49_ = dir_index;
		_tmp50_ = g_list_nth_data (_tmp48_, _tmp49_);
		_tmp51_ = _g_object_ref0 ((GFile*) _tmp50_);
		cur_origin_dir = _tmp51_;
		_tmp52_ = cur_target_dir;
		_tmp53_ = cur_origin_dir;
		_tmp54_ = g_file_equal (_tmp52_, _tmp53_);
		if (!_tmp54_) {
			_g_object_unref0 (cur_origin_dir);
			_g_object_unref0 (cur_target_dir);
			break;
		}
		_tmp55_ = dir_index;
		dir_index = _tmp55_ + 1;
		_g_object_unref0 (cur_origin_dir);
		_g_object_unref0 (cur_target_dir);
	}
	_tmp56_ = dir_index;
	nb_common_dirs = _tmp56_;
	_tmp57_ = g_strdup ("");
	relative_path = _tmp57_;
	_tmp58_ = origin_dirs;
	_tmp59_ = g_list_length (_tmp58_);
	_tmp60_ = nb_common_dirs;
	nb_remaining_origin_dirs = _tmp59_ - _tmp60_;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp61_ = FALSE;
			_tmp61_ = TRUE;
			while (TRUE) {
				gboolean _tmp62_ = FALSE;
				guint _tmp64_ = 0U;
				guint _tmp65_ = 0U;
				const gchar* _tmp66_ = NULL;
				gchar* _tmp67_ = NULL;
				_tmp62_ = _tmp61_;
				if (!_tmp62_) {
					guint _tmp63_ = 0U;
					_tmp63_ = i;
					i = _tmp63_ + 1;
				}
				_tmp61_ = FALSE;
				_tmp64_ = i;
				_tmp65_ = nb_remaining_origin_dirs;
				if (!(_tmp64_ < _tmp65_)) {
					break;
				}
				_tmp66_ = relative_path;
				_tmp67_ = g_strconcat (_tmp66_, "../", NULL);
				_g_free0 (relative_path);
				relative_path = _tmp67_;
			}
		}
	}
	{
		guint i = 0U;
		guint _tmp68_ = 0U;
		_tmp68_ = nb_common_dirs;
		i = _tmp68_;
		{
			gboolean _tmp69_ = FALSE;
			_tmp69_ = TRUE;
			while (TRUE) {
				gboolean _tmp70_ = FALSE;
				guint _tmp72_ = 0U;
				GList* _tmp73_ = NULL;
				guint _tmp74_ = 0U;
				GFile* cur_target_dir = NULL;
				GList* _tmp75_ = NULL;
				guint _tmp76_ = 0U;
				gconstpointer _tmp77_ = NULL;
				GFile* _tmp78_ = NULL;
				const gchar* _tmp79_ = NULL;
				GFile* _tmp80_ = NULL;
				gchar* _tmp81_ = NULL;
				gchar* _tmp82_ = NULL;
				gchar* _tmp83_ = NULL;
				gchar* _tmp84_ = NULL;
				gchar* _tmp85_ = NULL;
				_tmp70_ = _tmp69_;
				if (!_tmp70_) {
					guint _tmp71_ = 0U;
					_tmp71_ = i;
					i = _tmp71_ + 1;
				}
				_tmp69_ = FALSE;
				_tmp72_ = i;
				_tmp73_ = target_dirs;
				_tmp74_ = g_list_length (_tmp73_);
				if (!(_tmp72_ < _tmp74_)) {
					break;
				}
				_tmp75_ = target_dirs;
				_tmp76_ = i;
				_tmp77_ = g_list_nth_data (_tmp75_, _tmp76_);
				_tmp78_ = _g_object_ref0 ((GFile*) _tmp77_);
				cur_target_dir = _tmp78_;
				_tmp79_ = relative_path;
				_tmp80_ = cur_target_dir;
				_tmp81_ = g_file_get_basename (_tmp80_);
				_tmp82_ = _tmp81_;
				_tmp83_ = g_strconcat (_tmp82_, "/", NULL);
				_tmp84_ = _tmp83_;
				_tmp85_ = g_strconcat (_tmp79_, _tmp84_, NULL);
				_g_free0 (relative_path);
				relative_path = _tmp85_;
				_g_free0 (_tmp84_);
				_g_free0 (_tmp82_);
				_g_object_unref0 (cur_target_dir);
			}
		}
	}
	_tmp86_ = relative_path;
	_tmp87_ = target;
	_tmp88_ = g_file_get_basename (_tmp87_);
	_tmp89_ = _tmp88_;
	_tmp90_ = g_strconcat (_tmp86_, _tmp89_, NULL);
	_g_free0 (relative_path);
	relative_path = _tmp90_;
	_g_free0 (_tmp89_);
	result = relative_path;
	__g_list_free__g_object_unref0_0 (origin_dirs);
	__g_list_free__g_object_unref0_0 (target_dirs);
	_g_object_unref0 (target_parent);
	_g_object_unref0 (origin_dir);
	return result;
}


void utils_show_uri (GdkScreen* screen, const gchar* uri, GError** error) {
	gboolean _tmp0_ = FALSE;
	GdkScreen* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp11_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (uri != NULL);
	_tmp1_ = screen;
	_tmp2_ = uri;
	_tmp3_ = gtk_show_uri (_tmp1_, _tmp2_, (guint32) GDK_CURRENT_TIME, &_inner_error_);
	_tmp0_ = _tmp3_;
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		return;
	}
	if (!_tmp0_) {
		return;
	}
	_tmp5_ = uri;
	_tmp6_ = utils_get_extension (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strcmp0 (_tmp7_, ".pdf") == 0;
	_g_free0 (_tmp7_);
	if (_tmp8_) {
		const gchar* _tmp9_ = NULL;
		gboolean _tmp10_ = FALSE;
		_tmp9_ = uri;
		_tmp10_ = utils_default_document_viewer_is_evince (_tmp9_);
		_tmp4_ = _tmp10_;
	} else {
		_tmp4_ = FALSE;
	}
	_tmp11_ = _tmp4_;
	if (_tmp11_) {
		Synctex* synctex = NULL;
		Synctex* _tmp12_ = NULL;
		Synctex* _tmp13_ = NULL;
		const gchar* _tmp14_ = NULL;
		_tmp12_ = synctex_get_default ();
		synctex = _tmp12_;
		_tmp13_ = synctex;
		_tmp14_ = uri;
		synctex_create_evince_window (_tmp13_, _tmp14_);
		_g_object_unref0 (synctex);
	}
}


static gboolean string_contains (const gchar* self, const gchar* needle) {
	gboolean result = FALSE;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = needle;
	_tmp1_ = strstr ((gchar*) self, (gchar*) _tmp0_);
	result = _tmp1_ != NULL;
	return result;
}


gboolean utils_default_document_viewer_is_evince (const gchar* uri) {
	gboolean result = FALSE;
	GFile* file = NULL;
	const gchar* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	GAppInfo* app = NULL;
	GAppInfo* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	gboolean _tmp9_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (uri != NULL, FALSE);
	_tmp0_ = uri;
	_tmp1_ = g_file_new_for_uri (_tmp0_);
	file = _tmp1_;
	{
		GAppInfo* _tmp2_ = NULL;
		GFile* _tmp3_ = NULL;
		GAppInfo* _tmp4_ = NULL;
		_tmp3_ = file;
		_tmp4_ = g_file_query_default_handler (_tmp3_, NULL, &_inner_error_);
		_tmp2_ = _tmp4_;
		if (_inner_error_ != NULL) {
			goto __catch75_g_error;
		}
		_g_object_unref0 (app);
		app = _tmp2_;
	}
	goto __finally75;
	__catch75_g_error:
	{
		GError* e = NULL;
		GError* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_warning ("utils.vala:313: Impossible to know if evince is the default document v" \
"iewer: %s", _tmp6_);
		result = FALSE;
		_g_error_free0 (e);
		_g_object_unref0 (app);
		_g_object_unref0 (file);
		return result;
	}
	__finally75:
	if (_inner_error_ != NULL) {
		_g_object_unref0 (app);
		_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 FALSE;
	}
	_tmp7_ = app;
	_tmp8_ = g_app_info_get_executable (_tmp7_);
	_tmp9_ = string_contains (_tmp8_, "evince");
	result = _tmp9_;
	_g_object_unref0 (app);
	_g_object_unref0 (file);
	return result;
}


/*************************************************************************/
GtkScrolledWindow* utils_add_scrollbar (GtkWidget* child) {
	GtkScrolledWindow* result = NULL;
	GtkScrolledWindow* sw = NULL;
	GtkScrolledWindow* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	g_return_val_if_fail (child != NULL, NULL);
	_tmp0_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp0_);
	sw = _tmp0_;
	_tmp1_ = child;
	gtk_container_add ((GtkContainer*) sw, _tmp1_);
	result = sw;
	return result;
}


gboolean utils_tree_model_iter_prev (GtkTreeModel* model, GtkTreeIter* iter) {
	gboolean result = FALSE;
	GtkTreePath* path = NULL;
	GtkTreeModel* _tmp0_ = NULL;
	GtkTreeIter _tmp1_ = {0};
	GtkTreePath* _tmp2_ = NULL;
	GtkTreePath* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	g_return_val_if_fail (model != NULL, FALSE);
	g_return_val_if_fail (iter != NULL, FALSE);
	_tmp0_ = model;
	_tmp1_ = *iter;
	_tmp2_ = gtk_tree_model_get_path (_tmp0_, &_tmp1_);
	path = _tmp2_;
	_tmp3_ = path;
	_tmp4_ = gtk_tree_path_prev (_tmp3_);
	if (_tmp4_) {
		gboolean ret = FALSE;
		GtkTreeModel* _tmp5_ = NULL;
		GtkTreePath* _tmp6_ = NULL;
		GtkTreeIter _tmp7_ = {0};
		gboolean _tmp8_ = FALSE;
		_tmp5_ = model;
		_tmp6_ = path;
		_tmp8_ = gtk_tree_model_get_iter (_tmp5_, &_tmp7_, _tmp6_);
		*iter = _tmp7_;
		ret = _tmp8_;
		result = ret;
		_gtk_tree_path_free0 (path);
		return result;
	}
	result = FALSE;
	_gtk_tree_path_free0 (path);
	return result;
}


gint utils_get_selected_row (GtkTreeView* view, GtkTreeIter* iter) {
	GtkTreeIter _vala_iter = {0};
	gint result = 0;
	GtkTreeSelection* select = NULL;
	GtkTreeView* _tmp0_ = NULL;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeSelection* _tmp2_ = NULL;
	GtkTreeSelection* _tmp3_ = NULL;
	GtkTreeIter _tmp4_ = {0};
	gboolean _tmp5_ = FALSE;
	g_return_val_if_fail (view != NULL, 0);
	_tmp0_ = view;
	_tmp1_ = gtk_tree_view_get_selection (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	select = _tmp2_;
	_tmp3_ = select;
	_tmp5_ = gtk_tree_selection_get_selected (_tmp3_, NULL, &_tmp4_);
	_vala_iter = _tmp4_;
	if (_tmp5_) {
		GtkTreeModel* model = NULL;
		GtkTreeView* _tmp6_ = NULL;
		GtkTreeModel* _tmp7_ = NULL;
		GtkTreeModel* _tmp8_ = NULL;
		GtkTreePath* path = NULL;
		GtkTreeModel* _tmp9_ = NULL;
		GtkTreeIter _tmp10_ = {0};
		GtkTreePath* _tmp11_ = NULL;
		GtkTreePath* _tmp12_ = NULL;
		gint _tmp13_ = 0;
		gint* _tmp14_ = NULL;
		gint _tmp15_ = 0;
		_tmp6_ = view;
		_tmp7_ = gtk_tree_view_get_model (_tmp6_);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		model = _tmp8_;
		_tmp9_ = model;
		_tmp10_ = _vala_iter;
		_tmp11_ = gtk_tree_model_get_path (_tmp9_, &_tmp10_);
		path = _tmp11_;
		_tmp12_ = path;
		_tmp14_ = gtk_tree_path_get_indices_with_depth (_tmp12_, &_tmp13_);
		_tmp15_ = _tmp14_[0];
		result = _tmp15_;
		_gtk_tree_path_free0 (path);
		_g_object_unref0 (model);
		_g_object_unref0 (select);
		if (iter) {
			*iter = _vala_iter;
		}
		return result;
	}
	result = -1;
	_g_object_unref0 (select);
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}


GdkPixbuf* utils_get_pixbuf_from_stock (const gchar* stock_id, GtkIconSize size) {
	GdkPixbuf* result = NULL;
	GtkInvisible* widget = NULL;
	GtkInvisible* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GtkIconSize _tmp2_ = 0;
	GdkPixbuf* _tmp3_ = NULL;
	GdkPixbuf* _tmp4_ = NULL;
	g_return_val_if_fail (stock_id != NULL, NULL);
	_tmp0_ = (GtkInvisible*) gtk_invisible_new ();
	g_object_ref_sink (_tmp0_);
	widget = _tmp0_;
	_tmp1_ = stock_id;
	_tmp2_ = size;
	_tmp3_ = gtk_widget_render_icon_pixbuf ((GtkWidget*) widget, _tmp1_, _tmp2_);
	_tmp4_ = _g_object_ref0 (_tmp3_);
	result = _tmp4_;
	_g_object_unref0 (widget);
	return result;
}


GtkGrid* utils_get_dialog_component (const gchar* title, GtkWidget* widget) {
	GtkGrid* result = NULL;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp0_ = NULL;
	GtkLabel* label = NULL;
	GtkLabel* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	GtkWidget* _tmp7_ = NULL;
	GtkWidget* _tmp8_ = NULL;
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (widget != NULL, NULL);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp0_);
	grid = _tmp0_;
	gtk_orientable_set_orientation ((GtkOrientable*) grid, GTK_ORIENTATION_VERTICAL);
	gtk_grid_set_row_spacing (grid, (guint) 6);
	gtk_container_set_border_width ((GtkContainer*) grid, (guint) 6);
	_tmp1_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp1_);
	label = _tmp1_;
	_tmp2_ = title;
	_tmp3_ = g_strconcat ("<b>", _tmp2_, NULL);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat (_tmp4_, "</b>", NULL);
	_tmp6_ = _tmp5_;
	gtk_label_set_markup (label, _tmp6_);
	_g_free0 (_tmp6_);
	_g_free0 (_tmp4_);
	gtk_widget_set_halign ((GtkWidget*) label, GTK_ALIGN_START);
	gtk_container_add ((GtkContainer*) grid, (GtkWidget*) label);
	_tmp7_ = widget;
	gtk_widget_set_margin_left (_tmp7_, 12);
	_tmp8_ = widget;
	gtk_container_add ((GtkContainer*) grid, _tmp8_);
	result = grid;
	_g_object_unref0 (label);
	return result;
}


GtkWindow* utils_get_toplevel_window (GtkWidget* widget) {
	GtkWindow* result = NULL;
	GtkWidget* toplevel = NULL;
	GtkWidget* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkWidget* _tmp2_ = NULL;
	g_return_val_if_fail (widget != NULL, NULL);
	_tmp0_ = widget;
	_tmp1_ = gtk_widget_get_toplevel (_tmp0_);
	toplevel = _tmp1_;
	_tmp2_ = toplevel;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, GTK_TYPE_WINDOW)) {
		GtkWidget* _tmp3_ = NULL;
		_tmp3_ = toplevel;
		result = G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, GTK_TYPE_WINDOW) ? ((GtkWindow*) _tmp3_) : NULL;
		return result;
	}
	result = NULL;
	return result;
}


GtkDialog* utils_get_reset_all_confirm_dialog (GtkWindow* window, const gchar* msg) {
	GtkDialog* result = NULL;
	GtkDialog* dialog = NULL;
	GtkWindow* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GtkMessageDialog* _tmp2_ = NULL;
	GtkButton* button = NULL;
	const gchar* _tmp3_ = NULL;
	GtkButton* _tmp4_ = NULL;
	GtkImage* image = NULL;
	GtkImage* _tmp5_ = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	g_return_val_if_fail (msg != NULL, NULL);
	_tmp0_ = window;
	_tmp1_ = msg;
	_tmp2_ = (GtkMessageDialog*) gtk_message_dialog_new (_tmp0_, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", _tmp1_);
	g_object_ref_sink (_tmp2_);
	dialog = (GtkDialog*) _tmp2_;
	gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, (gint) GTK_RESPONSE_CANCEL);
	_tmp3_ = _ ("Reset All");
	_tmp4_ = (GtkButton*) gtk_button_new_with_label (_tmp3_);
	g_object_ref_sink (_tmp4_);
	button = _tmp4_;
	_tmp5_ = (GtkImage*) gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (_tmp5_);
	image = _tmp5_;
	gtk_button_set_image (button, (GtkWidget*) image);
	gtk_widget_show_all ((GtkWidget*) button);
	gtk_dialog_add_action_widget (dialog, (GtkWidget*) button, (gint) GTK_RESPONSE_YES);
	result = dialog;
	_g_object_unref0 (image);
	_g_object_unref0 (button);
	return result;
}


/*************************************************************************/
void utils_flush_queue (void) {
	while (TRUE) {
		gboolean _tmp0_ = FALSE;
		_tmp0_ = gtk_events_pending ();
		if (!_tmp0_) {
			break;
		}
		gtk_main_iteration ();
	}
}



