/* ConvertPDF.c generated by valac 0.56.19, the Vala compiler
 * generated from ConvertPDF.vala, do not modify */

/*
* Copyright (c) 2019 Murilo Venturoso
*
* This program 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.
*
* This program 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 this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Murilo Venturoso <muriloventuroso@gmail.com>
*/

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

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define PDFTRICKS_TYPE_CONVERT_PDF (pdftricks_convert_pdf_get_type ())
#define PDFTRICKS_CONVERT_PDF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDF))
#define PDFTRICKS_CONVERT_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDFClass))
#define PDFTRICKS_IS_CONVERT_PDF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFTRICKS_TYPE_CONVERT_PDF))
#define PDFTRICKS_IS_CONVERT_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFTRICKS_TYPE_CONVERT_PDF))
#define PDFTRICKS_CONVERT_PDF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDFClass))

typedef struct _pdftricksConvertPDF pdftricksConvertPDF;
typedef struct _pdftricksConvertPDFClass pdftricksConvertPDFClass;
typedef struct _pdftricksConvertPDFPrivate pdftricksConvertPDFPrivate;
enum  {
	PDFTRICKS_CONVERT_PDF_0_PROPERTY,
	PDFTRICKS_CONVERT_PDF_WINDOW_PROPERTY,
	PDFTRICKS_CONVERT_PDF_NUM_PROPERTIES
};
static GParamSpec* pdftricks_convert_pdf_properties[PDFTRICKS_CONVERT_PDF_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block10Data Block10Data;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_thread_unref0(var) ((var == NULL) ? NULL : (var = (g_thread_unref (var), NULL)))
typedef struct _PdftricksConvertPdfConvertFileData PdftricksConvertPdfConvertFileData;
typedef struct _Block11Data Block11Data;
enum  {
	PDFTRICKS_CONVERT_PDF_PROCCESS_BEGIN_SIGNAL,
	PDFTRICKS_CONVERT_PDF_PROCCESS_FINISHED_SIGNAL,
	PDFTRICKS_CONVERT_PDF_NUM_SIGNALS
};
static guint pdftricks_convert_pdf_signals[PDFTRICKS_CONVERT_PDF_NUM_SIGNALS] = {0};

struct _pdftricksConvertPDF {
	GtkBox parent_instance;
	pdftricksConvertPDFPrivate * priv;
};

struct _pdftricksConvertPDFClass {
	GtkBoxClass parent_class;
};

struct _pdftricksConvertPDFPrivate {
	GtkFileChooserButton* filechooser;
	GtkWindow* _window;
	GtkGrid* grid;
	GtkSpinner* spinner;
	GtkComboBoxText* format_conversion;
};

struct _Block10Data {
	int _ref_count_;
	pdftricksConvertPDF* self;
	gboolean ret;
	GSourceFunc callback;
	gpointer callback_target;
	GDestroyNotify callback_target_destroy_notify;
	gchar* input;
	gchar* output_file;
	gchar* format_input;
	gchar* format_output;
	gpointer _async_data_;
};

struct _PdftricksConvertPdfConvertFileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	pdftricksConvertPDF* self;
	gchar* input;
	gchar* output_file;
	gchar* format_input;
	gchar* format_output;
	gboolean result;
	Block10Data* _data10_;
	GThreadFunc run;
	gpointer run_target;
	GThread* _tmp0_;
	GThread* _tmp1_;
	GError* e;
	GError* _tmp2_;
	const gchar* _tmp3_;
	GError* _inner_error0_;
};

struct _Block11Data {
	int _ref_count_;
	pdftricksConvertPDF* self;
	GtkButton* convert_button;
};

static gint pdftricksConvertPDF_private_offset;
static gpointer pdftricks_convert_pdf_parent_class = NULL;

VALA_EXTERN GType pdftricks_convert_pdf_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdftricksConvertPDF, g_object_unref)
VALA_EXTERN pdftricksConvertPDF* pdftricks_convert_pdf_new (GtkWindow* window);
VALA_EXTERN pdftricksConvertPDF* pdftricks_convert_pdf_construct (GType object_type,
                                                      GtkWindow* window);
static void pdftricks_convert_pdf_confirm_convert (pdftricksConvertPDF* self);
VALA_EXTERN GtkWindow* pdftricks_convert_pdf_get_window (pdftricksConvertPDF* self);
static void pdftricks_convert_pdf_convert_file (pdftricksConvertPDF* self,
                                         const gchar* input,
                                         const gchar* output_file,
                                         const gchar* format_input,
                                         const gchar* format_output,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
static gboolean pdftricks_convert_pdf_convert_file_finish (pdftricksConvertPDF* self,
                                                    GAsyncResult* _res_);
static void ___lambda34_ (pdftricksConvertPDF* self,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda34__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void pdftricks_convert_pdf_convert_file_data_free (gpointer _data);
static gboolean pdftricks_convert_pdf_convert_file_co (PdftricksConvertPdfConvertFileData* _data_);
static Block10Data* block10_data_ref (Block10Data* _data10_);
static void block10_data_unref (void * _userdata_);
static gboolean _pdftricks_convert_pdf_convert_file_co_gsource_func (gpointer self);
static void* __lambda33_ (Block10Data* _data10_);
static gpointer ___lambda33__gthread_func (gpointer self);
static void pdftricks_convert_pdf_set_window (pdftricksConvertPDF* self,
                                       GtkWindow* value);
static GObject * pdftricks_convert_pdf_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties);
static Block11Data* block11_data_ref (Block11Data* _data11_);
static void block11_data_unref (void * _userdata_);
static void _pdftricks_convert_pdf_confirm_convert_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static void _pdftricks_convert_pdf___lambda35_ (Block11Data* _data11_);
static void __pdftricks_convert_pdf___lambda35__gtk_file_chooser_button_file_set (GtkFileChooserButton* _sender,
                                                                           gpointer self);
static void _pdftricks_convert_pdf___lambda36_ (Block11Data* _data11_);
static void __pdftricks_convert_pdf___lambda36__pdftricks_convert_pdf_proccess_begin (pdftricksConvertPDF* _sender,
                                                                               gpointer self);
static void _pdftricks_convert_pdf___lambda37_ (Block11Data* _data11_,
                                         gboolean _result_);
static void __pdftricks_convert_pdf___lambda37__pdftricks_convert_pdf_proccess_finished (pdftricksConvertPDF* _sender,
                                                                                  gboolean _result_,
                                                                                  gpointer self);
static void pdftricks_convert_pdf_finalize (GObject * obj);
static GType pdftricks_convert_pdf_get_type_once (void);
static void _vala_pdftricks_convert_pdf_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_pdftricks_convert_pdf_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static inline gpointer
pdftricks_convert_pdf_get_instance_private (pdftricksConvertPDF* self)
{
	return G_STRUCT_MEMBER_P (self, pdftricksConvertPDF_private_offset);
}

pdftricksConvertPDF*
pdftricks_convert_pdf_construct (GType object_type,
                                 GtkWindow* window)
{
	pdftricksConvertPDF * self = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	self = (pdftricksConvertPDF*) g_object_new (object_type, "margin-start", 20, "margin-end", 20, "window", window, "hexpand", TRUE, "homogeneous", TRUE, NULL);
	return self;
}

pdftricksConvertPDF*
pdftricks_convert_pdf_new (GtkWindow* window)
{
	return pdftricks_convert_pdf_construct (PDFTRICKS_TYPE_CONVERT_PDF, window);
}

static void
___lambda34_ (pdftricksConvertPDF* self,
              GObject* obj,
              GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	g_signal_emit (self, pdftricks_convert_pdf_signals[PDFTRICKS_CONVERT_PDF_PROCCESS_FINISHED_SIGNAL], 0, pdftricks_convert_pdf_convert_file_finish (self, res));
}

static void
____lambda34__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda34_ ((pdftricksConvertPDF*) self, source_object, res);
	g_object_unref (self);
}

static void
pdftricks_convert_pdf_confirm_convert (pdftricksConvertPDF* self)
{
	gboolean convert = FALSE;
	gchar* format = NULL;
	GtkComboBoxText* _tmp0_;
	gchar* _tmp1_;
	gchar* file_pdf = NULL;
	GtkFileChooserButton* _tmp2_;
	gchar* _tmp3_;
	gchar** file_name_split = NULL;
	const gchar* _tmp4_;
	gchar** _tmp5_;
	gchar** _tmp6_;
	gint file_name_split_length1;
	gint _file_name_split_size_;
	gchar* input_format = NULL;
	gchar** _tmp7_;
	gint _tmp7__length1;
	gchar** _tmp8_;
	gint _tmp8__length1;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	gchar* output_file = NULL;
	gchar* _tmp19_;
	GtkFileChooserNative* chooser_output = NULL;
	GtkWindow* _tmp20_;
	GtkFileChooserNative* _tmp21_;
	gchar** split_filename = NULL;
	const gchar* _tmp22_;
	gchar** _tmp23_;
	gchar** _tmp24_;
	gint split_filename_length1;
	gint _split_filename_size_;
	gchar* filename = NULL;
	gchar** _tmp25_;
	gint _tmp25__length1;
	gchar** _tmp26_;
	gint _tmp26__length1;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	GtkFileChooserNative* _tmp29_;
	const gchar* _tmp30_;
	GtkFileChooserNative* _tmp31_;
	const gchar* _tmp32_;
	gchar** _tmp33_;
	gchar** _tmp34_;
	gchar** _tmp35_;
	gint _tmp35__length1;
	const gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	const gchar* _tmp39_;
	gchar* _tmp40_;
	gchar* _tmp41_;
	GtkFileChooserNative* _tmp42_;
	GtkFileChooserNative* _tmp43_;
	GtkFileChooserNative* _tmp46_;
	g_return_if_fail (self != NULL);
	convert = FALSE;
	_tmp0_ = self->priv->format_conversion;
	_tmp1_ = gtk_combo_box_text_get_active_text (_tmp0_);
	format = _tmp1_;
	_tmp2_ = self->priv->filechooser;
	_tmp3_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp2_);
	file_pdf = _tmp3_;
	_tmp4_ = file_pdf;
	_tmp6_ = _tmp5_ = g_strsplit (_tmp4_, ".", 0);
	file_name_split = _tmp6_;
	file_name_split_length1 = _vala_array_length (_tmp5_);
	_file_name_split_size_ = file_name_split_length1;
	_tmp7_ = file_name_split;
	_tmp7__length1 = file_name_split_length1;
	_tmp8_ = file_name_split;
	_tmp8__length1 = file_name_split_length1;
	_tmp9_ = _tmp7_[_tmp8__length1 - 1];
	_tmp10_ = g_strdup (_tmp9_);
	input_format = _tmp10_;
	_tmp11_ = input_format;
	_tmp12_ = format;
	if (g_strcmp0 (_tmp11_, _tmp12_) == 0) {
		GraniteMessageDialog* message_dialog = NULL;
		GraniteMessageDialog* _tmp13_;
		GraniteMessageDialog* _tmp14_;
		GtkWindow* _tmp15_;
		GraniteMessageDialog* _tmp16_;
		GraniteMessageDialog* _tmp17_;
		GraniteMessageDialog* _tmp18_;
		_tmp13_ = granite_message_dialog_new_with_image_from_icon_name (_ ("Failure."), _ ("The input format is the same as the output format."), "process-stop", GTK_BUTTONS_CLOSE);
		g_object_ref_sink (_tmp13_);
		message_dialog = _tmp13_;
		_tmp14_ = message_dialog;
		_tmp15_ = self->priv->_window;
		gtk_window_set_transient_for ((GtkWindow*) _tmp14_, _tmp15_);
		_tmp16_ = message_dialog;
		gtk_widget_show_all ((GtkWidget*) _tmp16_);
		_tmp17_ = message_dialog;
		gtk_dialog_run ((GtkDialog*) _tmp17_);
		_tmp18_ = message_dialog;
		gtk_widget_destroy ((GtkWidget*) _tmp18_);
		_g_object_unref0 (message_dialog);
		_g_free0 (input_format);
		file_name_split = (_vala_array_free (file_name_split, file_name_split_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (file_pdf);
		_g_free0 (format);
		return;
	}
	_tmp19_ = g_strdup ("");
	output_file = _tmp19_;
	_tmp20_ = self->priv->_window;
	_tmp21_ = gtk_file_chooser_native_new (_ ("Select the file to save"), _tmp20_, GTK_FILE_CHOOSER_ACTION_SAVE, _ ("Save"), _ ("Cancel"));
	chooser_output = _tmp21_;
	_tmp22_ = file_pdf;
	_tmp24_ = _tmp23_ = g_strsplit (_tmp22_, "/", 0);
	split_filename = _tmp24_;
	split_filename_length1 = _vala_array_length (_tmp23_);
	_split_filename_size_ = split_filename_length1;
	_tmp25_ = split_filename;
	_tmp25__length1 = split_filename_length1;
	_tmp26_ = split_filename;
	_tmp26__length1 = split_filename_length1;
	_tmp27_ = _tmp25_[_tmp26__length1 - 1];
	_tmp28_ = g_strdup (_tmp27_);
	filename = _tmp28_;
	_tmp29_ = chooser_output;
	_tmp30_ = file_pdf;
	gtk_file_chooser_set_current_folder ((GtkFileChooser*) _tmp29_, _tmp30_);
	_tmp31_ = chooser_output;
	_tmp32_ = filename;
	_tmp34_ = _tmp33_ = g_strsplit (_tmp32_, ".", 0);
	_tmp35_ = _tmp34_;
	_tmp35__length1 = _vala_array_length (_tmp33_);
	_tmp36_ = _tmp35_[0];
	_tmp37_ = g_strconcat (_tmp36_, ".", NULL);
	_tmp38_ = _tmp37_;
	_tmp39_ = format;
	_tmp40_ = g_strconcat (_tmp38_, _tmp39_, NULL);
	_tmp41_ = _tmp40_;
	gtk_file_chooser_set_current_name ((GtkFileChooser*) _tmp31_, _tmp41_);
	_g_free0 (_tmp41_);
	_g_free0 (_tmp38_);
	_tmp35_ = (_vala_array_free (_tmp35_, _tmp35__length1, (GDestroyNotify) g_free), NULL);
	_tmp42_ = chooser_output;
	gtk_file_chooser_set_do_overwrite_confirmation ((GtkFileChooser*) _tmp42_, TRUE);
	_tmp43_ = chooser_output;
	if (gtk_native_dialog_run ((GtkNativeDialog*) _tmp43_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		GtkFileChooserNative* _tmp44_;
		gchar* _tmp45_;
		_tmp44_ = chooser_output;
		_tmp45_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp44_);
		_g_free0 (output_file);
		output_file = _tmp45_;
		convert = TRUE;
	}
	_tmp46_ = chooser_output;
	gtk_native_dialog_destroy ((GtkNativeDialog*) _tmp46_);
	if (convert == TRUE) {
		const gchar* _tmp47_;
		const gchar* _tmp48_;
		const gchar* _tmp49_;
		const gchar* _tmp50_;
		g_signal_emit (self, pdftricks_convert_pdf_signals[PDFTRICKS_CONVERT_PDF_PROCCESS_BEGIN_SIGNAL], 0);
		_tmp47_ = file_pdf;
		_tmp48_ = output_file;
		_tmp49_ = input_format;
		_tmp50_ = format;
		pdftricks_convert_pdf_convert_file (self, _tmp47_, _tmp48_, _tmp49_, _tmp50_, ____lambda34__gasync_ready_callback, g_object_ref (self));
	}
	_g_free0 (filename);
	split_filename = (_vala_array_free (split_filename, split_filename_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (chooser_output);
	_g_free0 (output_file);
	_g_free0 (input_format);
	file_name_split = (_vala_array_free (file_name_split, file_name_split_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (file_pdf);
	_g_free0 (format);
}

static void
pdftricks_convert_pdf_convert_file_data_free (gpointer _data)
{
	PdftricksConvertPdfConvertFileData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PdftricksConvertPdfConvertFileData, _data_);
}

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

static void
pdftricks_convert_pdf_convert_file (pdftricksConvertPDF* self,
                                    const gchar* input,
                                    const gchar* output_file,
                                    const gchar* format_input,
                                    const gchar* format_output,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	PdftricksConvertPdfConvertFileData* _data_;
	pdftricksConvertPDF* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (input != NULL);
	g_return_if_fail (output_file != NULL);
	g_return_if_fail (format_input != NULL);
	g_return_if_fail (format_output != NULL);
	_data_ = g_slice_new0 (PdftricksConvertPdfConvertFileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, pdftricks_convert_pdf_convert_file_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (input);
	_g_free0 (_data_->input);
	_data_->input = _tmp1_;
	_tmp2_ = g_strdup (output_file);
	_g_free0 (_data_->output_file);
	_data_->output_file = _tmp2_;
	_tmp3_ = g_strdup (format_input);
	_g_free0 (_data_->format_input);
	_data_->format_input = _tmp3_;
	_tmp4_ = g_strdup (format_output);
	_g_free0 (_data_->format_output);
	_data_->format_output = _tmp4_;
	pdftricks_convert_pdf_convert_file_co (_data_);
}

static gboolean
pdftricks_convert_pdf_convert_file_finish (pdftricksConvertPDF* self,
                                           GAsyncResult* _res_)
{
	gboolean result;
	PdftricksConvertPdfConvertFileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static Block10Data*
block10_data_ref (Block10Data* _data10_)
{
	g_atomic_int_inc (&_data10_->_ref_count_);
	return _data10_;
}

static void
block10_data_unref (void * _userdata_)
{
	Block10Data* _data10_;
	_data10_ = (Block10Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data10_->_ref_count_)) {
		pdftricksConvertPDF* self;
		self = _data10_->self;
		(_data10_->callback_target_destroy_notify == NULL) ? NULL : (_data10_->callback_target_destroy_notify (_data10_->callback_target), NULL);
		_data10_->callback = NULL;
		_data10_->callback_target = NULL;
		_data10_->callback_target_destroy_notify = NULL;
		_g_free0 (_data10_->input);
		_g_free0 (_data10_->output_file);
		_g_free0 (_data10_->format_input);
		_g_free0 (_data10_->format_output);
		_g_object_unref0 (self);
		g_slice_free (Block10Data, _data10_);
	}
}

static gboolean
_pdftricks_convert_pdf_convert_file_co_gsource_func (gpointer self)
{
	gboolean result;
	result = pdftricks_convert_pdf_convert_file_co (self);
	return result;
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

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

static void*
__lambda33_ (Block10Data* _data10_)
{
	pdftricksConvertPDF* self;
	gchar* output = NULL;
	gchar* stderr = NULL;
	gchar* cmd = NULL;
	gchar* _tmp0_;
	gint exit_status = 0;
	const gchar* _tmp73_;
	GSourceFunc _tmp92_;
	gpointer _tmp92__target;
	GDestroyNotify _tmp92__target_destroy_notify;
	GError* _inner_error0_ = NULL;
	void* result;
	self = _data10_->self;
	_tmp0_ = g_strdup ("");
	cmd = _tmp0_;
	exit_status = 0;
	if (g_strcmp0 (_data10_->format_input, "pdf") == 0) {
		if (g_strcmp0 (_data10_->format_output, "jpg") == 0) {
			gchar* n_output_file = NULL;
			gchar* _tmp1_;
			const gchar* _tmp2_;
			gchar* _tmp3_;
			gchar* _tmp4_;
			gchar* _tmp5_;
			gchar* _tmp6_;
			gchar* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			_tmp1_ = string_replace (_data10_->output_file, ".jpg", "-%03d.jpg");
			n_output_file = _tmp1_;
			_tmp2_ = n_output_file;
			_tmp3_ = g_strconcat ("gs -sDEVICE=jpeg -r144 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=\"", _tmp2_, NULL);
			_tmp4_ = _tmp3_;
			_tmp5_ = g_strconcat (_tmp4_, "\" \"", NULL);
			_tmp6_ = _tmp5_;
			_tmp7_ = g_strconcat (_tmp6_, _data10_->input, NULL);
			_tmp8_ = _tmp7_;
			_tmp9_ = g_strconcat (_tmp8_, "\"", NULL);
			_g_free0 (cmd);
			cmd = _tmp9_;
			_g_free0 (_tmp8_);
			_g_free0 (_tmp6_);
			_g_free0 (_tmp4_);
			_g_free0 (n_output_file);
		} else {
			if (g_strcmp0 (_data10_->format_output, "png") == 0) {
				gchar* n_output_file = NULL;
				gchar* _tmp10_;
				const gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				gchar* _tmp17_;
				gchar* _tmp18_;
				_tmp10_ = string_replace (_data10_->output_file, ".png", "-%03d.png");
				n_output_file = _tmp10_;
				_tmp11_ = n_output_file;
				_tmp12_ = g_strconcat ("gs -sDEVICE=png16m -r144 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=\"", _tmp11_, NULL);
				_tmp13_ = _tmp12_;
				_tmp14_ = g_strconcat (_tmp13_, "\" \"", NULL);
				_tmp15_ = _tmp14_;
				_tmp16_ = g_strconcat (_tmp15_, _data10_->input, NULL);
				_tmp17_ = _tmp16_;
				_tmp18_ = g_strconcat (_tmp17_, "\"", NULL);
				_g_free0 (cmd);
				cmd = _tmp18_;
				_g_free0 (_tmp17_);
				_g_free0 (_tmp15_);
				_g_free0 (_tmp13_);
				_g_free0 (n_output_file);
			} else {
				if (g_strcmp0 (_data10_->format_output, "txt") == 0) {
					gchar* n_output_file = NULL;
					gchar* _tmp19_;
					const gchar* _tmp20_;
					gchar* _tmp21_;
					gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					gchar* _tmp26_;
					gchar* _tmp27_;
					_tmp19_ = g_strdup (_data10_->output_file);
					n_output_file = _tmp19_;
					_tmp20_ = n_output_file;
					_tmp21_ = g_strconcat ("gs -ps2ascii -sDEVICE=txtwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=" \
"\"", _tmp20_, NULL);
					_tmp22_ = _tmp21_;
					_tmp23_ = g_strconcat (_tmp22_, "\" \"", NULL);
					_tmp24_ = _tmp23_;
					_tmp25_ = g_strconcat (_tmp24_, _data10_->input, NULL);
					_tmp26_ = _tmp25_;
					_tmp27_ = g_strconcat (_tmp26_, "\"", NULL);
					_g_free0 (cmd);
					cmd = _tmp27_;
					_g_free0 (_tmp26_);
					_g_free0 (_tmp24_);
					_g_free0 (_tmp22_);
					_g_free0 (n_output_file);
				}
			}
		}
	} else {
		if (g_strcmp0 (_data10_->format_input, "jpg") == 0) {
			gchar* n_output_file = NULL;
			gchar* _tmp28_;
			gchar* _tmp29_;
			gchar* _tmp30_;
			gchar* _tmp31_;
			gchar* _tmp32_;
			const gchar* _tmp33_;
			gchar* _tmp34_;
			gchar* _tmp35_;
			gchar* _tmp36_;
			_tmp28_ = g_strdup (_data10_->output_file);
			n_output_file = _tmp28_;
			_tmp29_ = g_strconcat ("convert \"", _data10_->input, NULL);
			_tmp30_ = _tmp29_;
			_tmp31_ = g_strconcat (_tmp30_, "\" \"", NULL);
			_tmp32_ = _tmp31_;
			_tmp33_ = n_output_file;
			_tmp34_ = g_strconcat (_tmp32_, _tmp33_, NULL);
			_tmp35_ = _tmp34_;
			_tmp36_ = g_strconcat (_tmp35_, "\"", NULL);
			_g_free0 (cmd);
			cmd = _tmp36_;
			_g_free0 (_tmp35_);
			_g_free0 (_tmp32_);
			_g_free0 (_tmp30_);
			_g_free0 (n_output_file);
		} else {
			if (g_strcmp0 (_data10_->format_input, "png") == 0) {
				gchar* n_output_file = NULL;
				gchar* _tmp37_;
				gchar* _tmp38_;
				gchar* _tmp39_;
				gchar* _tmp40_;
				gchar* _tmp41_;
				const gchar* _tmp42_;
				gchar* _tmp43_;
				gchar* _tmp44_;
				gchar* _tmp45_;
				_tmp37_ = g_strdup (_data10_->output_file);
				n_output_file = _tmp37_;
				_tmp38_ = g_strconcat ("convert -verbose \"", _data10_->input, NULL);
				_tmp39_ = _tmp38_;
				_tmp40_ = g_strconcat (_tmp39_, "\" \"", NULL);
				_tmp41_ = _tmp40_;
				_tmp42_ = n_output_file;
				_tmp43_ = g_strconcat (_tmp41_, _tmp42_, NULL);
				_tmp44_ = _tmp43_;
				_tmp45_ = g_strconcat (_tmp44_, "\"", NULL);
				_g_free0 (cmd);
				cmd = _tmp45_;
				_g_free0 (_tmp44_);
				_g_free0 (_tmp41_);
				_g_free0 (_tmp39_);
				_g_free0 (n_output_file);
			} else {
				if (g_strcmp0 (_data10_->format_input, "jpeg") == 0) {
					gchar* n_output_file = NULL;
					gchar* _tmp46_;
					gchar* _tmp47_;
					gchar* _tmp48_;
					gchar* _tmp49_;
					gchar* _tmp50_;
					const gchar* _tmp51_;
					gchar* _tmp52_;
					gchar* _tmp53_;
					gchar* _tmp54_;
					_tmp46_ = g_strdup (_data10_->output_file);
					n_output_file = _tmp46_;
					_tmp47_ = g_strconcat ("convert \"", _data10_->input, NULL);
					_tmp48_ = _tmp47_;
					_tmp49_ = g_strconcat (_tmp48_, "\" \"", NULL);
					_tmp50_ = _tmp49_;
					_tmp51_ = n_output_file;
					_tmp52_ = g_strconcat (_tmp50_, _tmp51_, NULL);
					_tmp53_ = _tmp52_;
					_tmp54_ = g_strconcat (_tmp53_, "\"", NULL);
					_g_free0 (cmd);
					cmd = _tmp54_;
					_g_free0 (_tmp53_);
					_g_free0 (_tmp50_);
					_g_free0 (_tmp48_);
					_g_free0 (n_output_file);
				} else {
					if (g_strcmp0 (_data10_->format_input, "svg") == 0) {
						gchar* n_output_file = NULL;
						gchar* _tmp55_;
						gchar* _tmp56_;
						gchar* _tmp57_;
						gchar* _tmp58_;
						gchar* _tmp59_;
						const gchar* _tmp60_;
						gchar* _tmp61_;
						gchar* _tmp62_;
						gchar* _tmp63_;
						_tmp55_ = g_strdup (_data10_->output_file);
						n_output_file = _tmp55_;
						_tmp56_ = g_strconcat ("convert \"", _data10_->input, NULL);
						_tmp57_ = _tmp56_;
						_tmp58_ = g_strconcat (_tmp57_, "\" \"", NULL);
						_tmp59_ = _tmp58_;
						_tmp60_ = n_output_file;
						_tmp61_ = g_strconcat (_tmp59_, _tmp60_, NULL);
						_tmp62_ = _tmp61_;
						_tmp63_ = g_strconcat (_tmp62_, "\"", NULL);
						_g_free0 (cmd);
						cmd = _tmp63_;
						_g_free0 (_tmp62_);
						_g_free0 (_tmp59_);
						_g_free0 (_tmp57_);
						_g_free0 (n_output_file);
					} else {
						if (g_strcmp0 (_data10_->format_input, "bmp") == 0) {
							gchar* n_output_file = NULL;
							gchar* _tmp64_;
							gchar* _tmp65_;
							gchar* _tmp66_;
							gchar* _tmp67_;
							gchar* _tmp68_;
							const gchar* _tmp69_;
							gchar* _tmp70_;
							gchar* _tmp71_;
							gchar* _tmp72_;
							_tmp64_ = g_strdup (_data10_->output_file);
							n_output_file = _tmp64_;
							_tmp65_ = g_strconcat ("convert \"", _data10_->input, NULL);
							_tmp66_ = _tmp65_;
							_tmp67_ = g_strconcat (_tmp66_, "\" \"", NULL);
							_tmp68_ = _tmp67_;
							_tmp69_ = n_output_file;
							_tmp70_ = g_strconcat (_tmp68_, _tmp69_, NULL);
							_tmp71_ = _tmp70_;
							_tmp72_ = g_strconcat (_tmp71_, "\"", NULL);
							_g_free0 (cmd);
							cmd = _tmp72_;
							_g_free0 (_tmp71_);
							_g_free0 (_tmp68_);
							_g_free0 (_tmp66_);
							_g_free0 (n_output_file);
						}
					}
				}
			}
		}
	}
	_tmp73_ = cmd;
	if (g_strcmp0 (_tmp73_, "") != 0) {
		gboolean _tmp80_ = FALSE;
		gboolean _tmp81_ = FALSE;
		const gchar* _tmp82_;
		{
			const gchar* _tmp74_;
			gchar* _tmp75_ = NULL;
			gchar* _tmp76_ = NULL;
			gint _tmp77_ = 0;
			_tmp74_ = cmd;
			g_spawn_command_line_sync (_tmp74_, &_tmp75_, &_tmp76_, &_tmp77_, &_inner_error0_);
			_g_free0 (output);
			output = _tmp75_;
			_g_free0 (stderr);
			stderr = _tmp76_;
			exit_status = _tmp77_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp78_;
			const gchar* _tmp79_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp78_ = e;
			_tmp79_ = _tmp78_->message;
			g_critical ("ConvertPDF.vala:219: %s", _tmp79_);
			_data10_->ret = FALSE;
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (cmd);
			_g_free0 (stderr);
			_g_free0 (output);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp82_ = output;
		if (g_strcmp0 (_tmp82_, "") != 0) {
			_tmp81_ = TRUE;
		} else {
			_tmp81_ = exit_status != 0;
		}
		if (_tmp81_) {
			_tmp80_ = TRUE;
		} else {
			const gchar* _tmp83_;
			_tmp83_ = stderr;
			_tmp80_ = g_strcmp0 (_tmp83_, "") != 0;
		}
		if (_tmp80_) {
			const gchar* _tmp84_;
			const gchar* _tmp85_;
			_tmp84_ = output;
			if (string_contains (_tmp84_, "Error")) {
				_data10_->ret = FALSE;
			}
			_tmp85_ = stderr;
			if (string_contains (_tmp85_, "not authorized")) {
				GraniteMessageDialog* message_dialog = NULL;
				GraniteMessageDialog* _tmp86_;
				GraniteMessageDialog* _tmp87_;
				GtkWindow* _tmp88_;
				GraniteMessageDialog* _tmp89_;
				GraniteMessageDialog* _tmp90_;
				GraniteMessageDialog* _tmp91_;
				_tmp86_ = granite_message_dialog_new_with_image_from_icon_name (_ ("ImageMagick Policies"), _ ("Change the ImageMagick security policies that prevent this operation a" \
"nd try again."), "process-stop", GTK_BUTTONS_CLOSE);
				g_object_ref_sink (_tmp86_);
				message_dialog = _tmp86_;
				_tmp87_ = message_dialog;
				_tmp88_ = self->priv->_window;
				gtk_window_set_transient_for ((GtkWindow*) _tmp87_, _tmp88_);
				_tmp89_ = message_dialog;
				gtk_widget_show_all ((GtkWidget*) _tmp89_);
				_tmp90_ = message_dialog;
				gtk_dialog_run ((GtkDialog*) _tmp90_);
				_tmp91_ = message_dialog;
				gtk_widget_destroy ((GtkWidget*) _tmp91_);
				_data10_->ret = FALSE;
				_g_object_unref0 (message_dialog);
			}
			if (exit_status != 0) {
				_data10_->ret = FALSE;
			}
		}
	}
	_tmp92_ = _data10_->callback;
	_tmp92__target = _data10_->callback_target;
	_tmp92__target_destroy_notify = _data10_->callback_target_destroy_notify;
	_data10_->callback = NULL;
	_data10_->callback_target = NULL;
	_data10_->callback_target_destroy_notify = NULL;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _tmp92_, _tmp92__target, _tmp92__target_destroy_notify);
	result = NULL;
	_g_free0 (cmd);
	_g_free0 (stderr);
	_g_free0 (output);
	return result;
}

static gpointer
___lambda33__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda33_ (self);
	block10_data_unref (self);
	return result;
}

static gboolean
pdftricks_convert_pdf_convert_file_co (PdftricksConvertPdfConvertFileData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data10_ = g_slice_new0 (Block10Data);
	_data_->_data10_->_ref_count_ = 1;
	_data_->_data10_->self = g_object_ref (_data_->self);
	_g_free0 (_data_->_data10_->input);
	_data_->_data10_->input = _data_->input;
	_g_free0 (_data_->_data10_->output_file);
	_data_->_data10_->output_file = _data_->output_file;
	_g_free0 (_data_->_data10_->format_input);
	_data_->_data10_->format_input = _data_->format_input;
	_g_free0 (_data_->_data10_->format_output);
	_data_->_data10_->format_output = _data_->format_output;
	_data_->_data10_->_async_data_ = _data_;
	_data_->_data10_->ret = TRUE;
	_data_->_data10_->callback = _pdftricks_convert_pdf_convert_file_co_gsource_func;
	_data_->_data10_->callback_target = _data_;
	_data_->_data10_->callback_target_destroy_notify = NULL;
	_data_->run = ___lambda33__gthread_func;
	_data_->run_target = block10_data_ref (_data_->_data10_);
	{
		_data_->_tmp0_ = g_thread_try_new (NULL, _data_->run, _data_->run_target, &_data_->_inner_error0_);
		_data_->_tmp1_ = _data_->_tmp0_;
		_g_thread_unref0 (_data_->_tmp1_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp2_ = _data_->e;
		_data_->_tmp3_ = _data_->_tmp2_->message;
		g_warning ("ConvertPDF.vala:245: %s", _data_->_tmp3_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		block10_data_unref (_data_->_data10_);
		_data_->_data10_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	_data_->result = _data_->_data10_->ret;
	block10_data_unref (_data_->_data10_);
	_data_->_data10_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

GtkWindow*
pdftricks_convert_pdf_get_window (pdftricksConvertPDF* self)
{
	GtkWindow* result;
	GtkWindow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_window;
	result = _tmp0_;
	return result;
}

static void
pdftricks_convert_pdf_set_window (pdftricksConvertPDF* self,
                                  GtkWindow* value)
{
	GtkWindow* old_value;
	g_return_if_fail (self != NULL);
	old_value = pdftricks_convert_pdf_get_window (self);
	if (old_value != value) {
		GtkWindow* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_window);
		self->priv->_window = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, pdftricks_convert_pdf_properties[PDFTRICKS_CONVERT_PDF_WINDOW_PROPERTY]);
	}
}

static Block11Data*
block11_data_ref (Block11Data* _data11_)
{
	g_atomic_int_inc (&_data11_->_ref_count_);
	return _data11_;
}

static void
block11_data_unref (void * _userdata_)
{
	Block11Data* _data11_;
	_data11_ = (Block11Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data11_->_ref_count_)) {
		pdftricksConvertPDF* self;
		self = _data11_->self;
		_g_object_unref0 (_data11_->convert_button);
		_g_object_unref0 (self);
		g_slice_free (Block11Data, _data11_);
	}
}

static void
_pdftricks_convert_pdf_confirm_convert_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	pdftricks_convert_pdf_confirm_convert ((pdftricksConvertPDF*) self);
}

static void
_pdftricks_convert_pdf___lambda35_ (Block11Data* _data11_)
{
	pdftricksConvertPDF* self;
	gchar* file_pdf = NULL;
	GtkFileChooserButton* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** file_name_split = NULL;
	const gchar* _tmp5_;
	gchar** _tmp6_;
	gchar** _tmp7_;
	gint file_name_split_length1;
	gint _file_name_split_size_;
	gchar* input_format = NULL;
	gchar** _tmp8_;
	gint _tmp8__length1;
	gchar** _tmp9_;
	gint _tmp9__length1;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	GtkComboBoxText* _tmp12_;
	const gchar* _tmp13_;
	GtkButton* _tmp33_;
	self = _data11_->self;
	_tmp0_ = self->priv->filechooser;
	_tmp1_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_replace (_tmp2_, "%20", " ");
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	file_pdf = _tmp4_;
	_tmp5_ = file_pdf;
	_tmp7_ = _tmp6_ = g_strsplit (_tmp5_, ".", 0);
	file_name_split = _tmp7_;
	file_name_split_length1 = _vala_array_length (_tmp6_);
	_file_name_split_size_ = file_name_split_length1;
	_tmp8_ = file_name_split;
	_tmp8__length1 = file_name_split_length1;
	_tmp9_ = file_name_split;
	_tmp9__length1 = file_name_split_length1;
	_tmp10_ = _tmp8_[_tmp9__length1 - 1];
	_tmp11_ = g_strdup (_tmp10_);
	input_format = _tmp11_;
	_tmp12_ = self->priv->format_conversion;
	gtk_combo_box_text_remove_all (_tmp12_);
	_tmp13_ = input_format;
	if (g_strcmp0 (_tmp13_, "pdf") == 0) {
		GtkComboBoxText* _tmp14_;
		GtkComboBoxText* _tmp15_;
		GtkComboBoxText* _tmp16_;
		GtkComboBoxText* _tmp17_;
		_tmp14_ = self->priv->format_conversion;
		gtk_combo_box_text_append_text (_tmp14_, "jpg");
		_tmp15_ = self->priv->format_conversion;
		gtk_combo_box_text_append_text (_tmp15_, "png");
		_tmp16_ = self->priv->format_conversion;
		gtk_combo_box_text_append_text (_tmp16_, "txt");
		_tmp17_ = self->priv->format_conversion;
		gtk_combo_box_set_active ((GtkComboBox*) _tmp17_, 0);
	} else {
		const gchar* _tmp18_;
		_tmp18_ = input_format;
		if (g_strcmp0 (_tmp18_, "jpg") == 0) {
			GtkComboBoxText* _tmp19_;
			GtkComboBoxText* _tmp20_;
			_tmp19_ = self->priv->format_conversion;
			gtk_combo_box_text_append_text (_tmp19_, "pdf");
			_tmp20_ = self->priv->format_conversion;
			gtk_combo_box_set_active ((GtkComboBox*) _tmp20_, 0);
		} else {
			const gchar* _tmp21_;
			_tmp21_ = input_format;
			if (g_strcmp0 (_tmp21_, "png") == 0) {
				GtkComboBoxText* _tmp22_;
				GtkComboBoxText* _tmp23_;
				_tmp22_ = self->priv->format_conversion;
				gtk_combo_box_text_append_text (_tmp22_, "pdf");
				_tmp23_ = self->priv->format_conversion;
				gtk_combo_box_set_active ((GtkComboBox*) _tmp23_, 0);
			} else {
				const gchar* _tmp24_;
				_tmp24_ = input_format;
				if (g_strcmp0 (_tmp24_, "jpeg") == 0) {
					GtkComboBoxText* _tmp25_;
					GtkComboBoxText* _tmp26_;
					_tmp25_ = self->priv->format_conversion;
					gtk_combo_box_text_append_text (_tmp25_, "pdf");
					_tmp26_ = self->priv->format_conversion;
					gtk_combo_box_set_active ((GtkComboBox*) _tmp26_, 0);
				} else {
					const gchar* _tmp27_;
					_tmp27_ = input_format;
					if (g_strcmp0 (_tmp27_, "svg") == 0) {
						GtkComboBoxText* _tmp28_;
						GtkComboBoxText* _tmp29_;
						_tmp28_ = self->priv->format_conversion;
						gtk_combo_box_text_append_text (_tmp28_, "pdf");
						_tmp29_ = self->priv->format_conversion;
						gtk_combo_box_set_active ((GtkComboBox*) _tmp29_, 0);
					} else {
						const gchar* _tmp30_;
						_tmp30_ = input_format;
						if (g_strcmp0 (_tmp30_, "bmp") == 0) {
							GtkComboBoxText* _tmp31_;
							GtkComboBoxText* _tmp32_;
							_tmp31_ = self->priv->format_conversion;
							gtk_combo_box_text_append_text (_tmp31_, "pdf");
							_tmp32_ = self->priv->format_conversion;
							gtk_combo_box_set_active ((GtkComboBox*) _tmp32_, 0);
						} else {
							_g_free0 (input_format);
							file_name_split = (_vala_array_free (file_name_split, file_name_split_length1, (GDestroyNotify) g_free), NULL);
							_g_free0 (file_pdf);
							return;
						}
					}
				}
			}
		}
	}
	_tmp33_ = _data11_->convert_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp33_, TRUE);
	_g_free0 (input_format);
	file_name_split = (_vala_array_free (file_name_split, file_name_split_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (file_pdf);
}

static void
__pdftricks_convert_pdf___lambda35__gtk_file_chooser_button_file_set (GtkFileChooserButton* _sender,
                                                                      gpointer self)
{
	_pdftricks_convert_pdf___lambda35_ (self);
}

static void
_pdftricks_convert_pdf___lambda36_ (Block11Data* _data11_)
{
	pdftricksConvertPDF* self;
	GtkSpinner* _tmp0_;
	GtkButton* _tmp1_;
	self = _data11_->self;
	_tmp0_ = self->priv->spinner;
	g_object_set (_tmp0_, "active", TRUE, NULL);
	_tmp1_ = _data11_->convert_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp1_, FALSE);
}

static void
__pdftricks_convert_pdf___lambda36__pdftricks_convert_pdf_proccess_begin (pdftricksConvertPDF* _sender,
                                                                          gpointer self)
{
	_pdftricks_convert_pdf___lambda36_ (self);
}

static void
_pdftricks_convert_pdf___lambda37_ (Block11Data* _data11_,
                                    gboolean _result_)
{
	pdftricksConvertPDF* self;
	GtkSpinner* _tmp0_;
	GtkButton* _tmp1_;
	self = _data11_->self;
	_tmp0_ = self->priv->spinner;
	g_object_set (_tmp0_, "active", FALSE, NULL);
	_tmp1_ = _data11_->convert_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp1_, TRUE);
	if (_result_) {
		GraniteMessageDialog* message_dialog = NULL;
		GraniteMessageDialog* _tmp2_;
		GraniteMessageDialog* _tmp3_;
		GtkWindow* _tmp4_;
		GraniteMessageDialog* _tmp5_;
		GraniteMessageDialog* _tmp6_;
		GraniteMessageDialog* _tmp7_;
		_tmp2_ = granite_message_dialog_new_with_image_from_icon_name (_ ("Success."), _ ("File converted."), "gtk-apply", GTK_BUTTONS_CLOSE);
		g_object_ref_sink (_tmp2_);
		message_dialog = _tmp2_;
		_tmp3_ = message_dialog;
		_tmp4_ = self->priv->_window;
		gtk_window_set_transient_for ((GtkWindow*) _tmp3_, _tmp4_);
		_tmp5_ = message_dialog;
		gtk_widget_show_all ((GtkWidget*) _tmp5_);
		_tmp6_ = message_dialog;
		gtk_dialog_run ((GtkDialog*) _tmp6_);
		_tmp7_ = message_dialog;
		gtk_widget_destroy ((GtkWidget*) _tmp7_);
		_g_object_unref0 (message_dialog);
	} else {
		GraniteMessageDialog* message_dialog = NULL;
		GraniteMessageDialog* _tmp8_;
		GraniteMessageDialog* _tmp9_;
		GtkWindow* _tmp10_;
		GraniteMessageDialog* _tmp11_;
		GraniteMessageDialog* _tmp12_;
		GraniteMessageDialog* _tmp13_;
		_tmp8_ = granite_message_dialog_new_with_image_from_icon_name (_ ("Failure."), _ ("Could not convert this file."), "process-stop", GTK_BUTTONS_CLOSE);
		g_object_ref_sink (_tmp8_);
		message_dialog = _tmp8_;
		_tmp9_ = message_dialog;
		_tmp10_ = self->priv->_window;
		gtk_window_set_transient_for ((GtkWindow*) _tmp9_, _tmp10_);
		_tmp11_ = message_dialog;
		gtk_widget_show_all ((GtkWidget*) _tmp11_);
		_tmp12_ = message_dialog;
		gtk_dialog_run ((GtkDialog*) _tmp12_);
		_tmp13_ = message_dialog;
		gtk_widget_destroy ((GtkWidget*) _tmp13_);
		_g_object_unref0 (message_dialog);
	}
}

static void
__pdftricks_convert_pdf___lambda37__pdftricks_convert_pdf_proccess_finished (pdftricksConvertPDF* _sender,
                                                                             gboolean _result_,
                                                                             gpointer self)
{
	_pdftricks_convert_pdf___lambda37_ (self, _result_);
}

static GObject *
pdftricks_convert_pdf_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	pdftricksConvertPDF * self;
	Block11Data* _data11_;
	GtkFileChooserButton* _tmp0_;
	GtkComboBoxText* _tmp1_;
	GtkComboBoxText* _tmp2_;
	GtkComboBoxText* _tmp3_;
	GtkComboBoxText* _tmp4_;
	GtkComboBoxText* _tmp5_;
	GtkButton* _tmp6_;
	GtkButton* _tmp7_;
	GtkStyleContext* _tmp8_;
	GtkButton* _tmp9_;
	GtkButton* _tmp10_;
	GtkButton* _tmp11_;
	GtkButton* _tmp12_;
	GtkFileChooserButton* _tmp13_;
	GtkGrid* _tmp14_;
	GtkGrid* _tmp15_;
	GtkGrid* _tmp16_;
	GtkGrid* _tmp17_;
	GtkGrid* _tmp18_;
	GtkGrid* _tmp19_;
	GtkGrid* _tmp20_;
	GtkGrid* _tmp21_;
	GraniteHeaderLabel* _tmp22_;
	GraniteHeaderLabel* _tmp23_;
	GtkGrid* _tmp24_;
	GtkFileChooserButton* _tmp25_;
	GtkGrid* _tmp26_;
	GraniteHeaderLabel* _tmp27_;
	GraniteHeaderLabel* _tmp28_;
	GtkGrid* _tmp29_;
	GtkComboBoxText* _tmp30_;
	GtkGrid* _tmp31_;
	GtkButton* _tmp32_;
	GtkSpinner* _tmp33_;
	GtkSpinner* _tmp34_;
	GtkGrid* _tmp35_;
	GtkSpinner* _tmp36_;
	GtkGrid* _tmp37_;
	parent_class = G_OBJECT_CLASS (pdftricks_convert_pdf_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDF);
	_data11_ = g_slice_new0 (Block11Data);
	_data11_->_ref_count_ = 1;
	_data11_->self = g_object_ref (self);
	_tmp0_ = (GtkFileChooserButton*) gtk_file_chooser_button_new (_ ("Select the file to convert"), GTK_FILE_CHOOSER_ACTION_OPEN);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->filechooser);
	self->priv->filechooser = _tmp0_;
	_tmp1_ = (GtkComboBoxText*) gtk_combo_box_text_new ();
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->format_conversion);
	self->priv->format_conversion = _tmp1_;
	_tmp2_ = self->priv->format_conversion;
	gtk_combo_box_text_append_text (_tmp2_, "pdf");
	_tmp3_ = self->priv->format_conversion;
	gtk_combo_box_text_append_text (_tmp3_, "jpg");
	_tmp4_ = self->priv->format_conversion;
	gtk_combo_box_text_append_text (_tmp4_, "png");
	_tmp5_ = self->priv->format_conversion;
	gtk_combo_box_text_append_text (_tmp5_, "txt");
	_tmp6_ = (GtkButton*) gtk_button_new_with_label (_ ("Convert"));
	g_object_ref_sink (_tmp6_);
	_data11_->convert_button = _tmp6_;
	_tmp7_ = _data11_->convert_button;
	_tmp8_ = gtk_widget_get_style_context ((GtkWidget*) _tmp7_);
	gtk_style_context_add_class (_tmp8_, GTK_STYLE_CLASS_SUGGESTED_ACTION);
	_tmp9_ = _data11_->convert_button;
	gtk_widget_set_can_default ((GtkWidget*) _tmp9_, TRUE);
	_tmp10_ = _data11_->convert_button;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp10_, TRUE);
	_tmp11_ = _data11_->convert_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp11_, FALSE);
	_tmp12_ = _data11_->convert_button;
	g_signal_connect_object (_tmp12_, "clicked", (GCallback) _pdftricks_convert_pdf_confirm_convert_gtk_button_clicked, self, 0);
	_tmp13_ = self->priv->filechooser;
	g_signal_connect_data (_tmp13_, "file-set", (GCallback) __pdftricks_convert_pdf___lambda35__gtk_file_chooser_button_file_set, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	_tmp14_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp14_);
	_g_object_unref0 (self->priv->grid);
	self->priv->grid = _tmp14_;
	_tmp15_ = self->priv->grid;
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp15_, GTK_ORIENTATION_VERTICAL);
	_tmp16_ = self->priv->grid;
	gtk_widget_set_halign ((GtkWidget*) _tmp16_, GTK_ALIGN_CENTER);
	_tmp17_ = self->priv->grid;
	gtk_widget_set_valign ((GtkWidget*) _tmp17_, GTK_ALIGN_CENTER);
	_tmp18_ = self->priv->grid;
	gtk_grid_set_column_spacing (_tmp18_, 16);
	_tmp19_ = self->priv->grid;
	gtk_grid_set_row_spacing (_tmp19_, 8);
	_tmp20_ = self->priv->grid;
	gtk_grid_set_column_homogeneous (_tmp20_, TRUE);
	_tmp21_ = self->priv->grid;
	_tmp22_ = granite_header_label_new (_ ("File to Convert:"));
	g_object_ref_sink (_tmp22_);
	_tmp23_ = _tmp22_;
	gtk_grid_attach (_tmp21_, (GtkWidget*) _tmp23_, 0, 0, 1, 1);
	_g_object_unref0 (_tmp23_);
	_tmp24_ = self->priv->grid;
	_tmp25_ = self->priv->filechooser;
	gtk_grid_attach (_tmp24_, (GtkWidget*) _tmp25_, 1, 0, 1, 1);
	_tmp26_ = self->priv->grid;
	_tmp27_ = granite_header_label_new (_ ("Format to Convert:"));
	g_object_ref_sink (_tmp27_);
	_tmp28_ = _tmp27_;
	gtk_grid_attach (_tmp26_, (GtkWidget*) _tmp28_, 0, 1, 1, 1);
	_g_object_unref0 (_tmp28_);
	_tmp29_ = self->priv->grid;
	_tmp30_ = self->priv->format_conversion;
	gtk_grid_attach (_tmp29_, (GtkWidget*) _tmp30_, 1, 1, 1, 1);
	_tmp31_ = self->priv->grid;
	_tmp32_ = _data11_->convert_button;
	gtk_grid_attach (_tmp31_, (GtkWidget*) _tmp32_, 0, 2, 2, 2);
	_tmp33_ = (GtkSpinner*) gtk_spinner_new ();
	g_object_ref_sink (_tmp33_);
	_g_object_unref0 (self->priv->spinner);
	self->priv->spinner = _tmp33_;
	_tmp34_ = self->priv->spinner;
	g_object_set (_tmp34_, "active", FALSE, NULL);
	_tmp35_ = self->priv->grid;
	_tmp36_ = self->priv->spinner;
	gtk_grid_attach (_tmp35_, (GtkWidget*) _tmp36_, 0, 5, 2, 2);
	_tmp37_ = self->priv->grid;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp37_);
	g_signal_connect_data (self, "proccess-begin", (GCallback) __pdftricks_convert_pdf___lambda36__pdftricks_convert_pdf_proccess_begin, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	g_signal_connect_data (self, "proccess-finished", (GCallback) __pdftricks_convert_pdf___lambda37__pdftricks_convert_pdf_proccess_finished, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	block11_data_unref (_data11_);
	_data11_ = NULL;
	return obj;
}

static void
pdftricks_convert_pdf_class_init (pdftricksConvertPDFClass * klass,
                                  gpointer klass_data)
{
	pdftricks_convert_pdf_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &pdftricksConvertPDF_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_pdftricks_convert_pdf_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_pdftricks_convert_pdf_set_property;
	G_OBJECT_CLASS (klass)->constructor = pdftricks_convert_pdf_constructor;
	G_OBJECT_CLASS (klass)->finalize = pdftricks_convert_pdf_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PDFTRICKS_CONVERT_PDF_WINDOW_PROPERTY, pdftricks_convert_pdf_properties[PDFTRICKS_CONVERT_PDF_WINDOW_PROPERTY] = g_param_spec_object ("window", "window", "window", gtk_window_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	pdftricks_convert_pdf_signals[PDFTRICKS_CONVERT_PDF_PROCCESS_BEGIN_SIGNAL] = g_signal_new ("proccess-begin", PDFTRICKS_TYPE_CONVERT_PDF, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	pdftricks_convert_pdf_signals[PDFTRICKS_CONVERT_PDF_PROCCESS_FINISHED_SIGNAL] = g_signal_new ("proccess-finished", PDFTRICKS_TYPE_CONVERT_PDF, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}

static void
pdftricks_convert_pdf_instance_init (pdftricksConvertPDF * self,
                                     gpointer klass)
{
	self->priv = pdftricks_convert_pdf_get_instance_private (self);
}

static void
pdftricks_convert_pdf_finalize (GObject * obj)
{
	pdftricksConvertPDF * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDF);
	_g_object_unref0 (self->priv->filechooser);
	_g_object_unref0 (self->priv->_window);
	_g_object_unref0 (self->priv->grid);
	_g_object_unref0 (self->priv->spinner);
	_g_object_unref0 (self->priv->format_conversion);
	G_OBJECT_CLASS (pdftricks_convert_pdf_parent_class)->finalize (obj);
}

static GType
pdftricks_convert_pdf_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (pdftricksConvertPDFClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pdftricks_convert_pdf_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (pdftricksConvertPDF), 0, (GInstanceInitFunc) pdftricks_convert_pdf_instance_init, NULL };
	GType pdftricks_convert_pdf_type_id;
	pdftricks_convert_pdf_type_id = g_type_register_static (gtk_box_get_type (), "pdftricksConvertPDF", &g_define_type_info, 0);
	pdftricksConvertPDF_private_offset = g_type_add_instance_private (pdftricks_convert_pdf_type_id, sizeof (pdftricksConvertPDFPrivate));
	return pdftricks_convert_pdf_type_id;
}

GType
pdftricks_convert_pdf_get_type (void)
{
	static volatile gsize pdftricks_convert_pdf_type_id__once = 0;
	if (g_once_init_enter (&pdftricks_convert_pdf_type_id__once)) {
		GType pdftricks_convert_pdf_type_id;
		pdftricks_convert_pdf_type_id = pdftricks_convert_pdf_get_type_once ();
		g_once_init_leave (&pdftricks_convert_pdf_type_id__once, pdftricks_convert_pdf_type_id);
	}
	return pdftricks_convert_pdf_type_id__once;
}

static void
_vala_pdftricks_convert_pdf_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	pdftricksConvertPDF * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDF);
	switch (property_id) {
		case PDFTRICKS_CONVERT_PDF_WINDOW_PROPERTY:
		g_value_set_object (value, pdftricks_convert_pdf_get_window (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_pdftricks_convert_pdf_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	pdftricksConvertPDF * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PDFTRICKS_TYPE_CONVERT_PDF, pdftricksConvertPDF);
	switch (property_id) {
		case PDFTRICKS_CONVERT_PDF_WINDOW_PROPERTY:
		pdftricks_convert_pdf_set_window (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

