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

/*
 * This file is part of GNOME LaTeX.
 *
 * Copyright © 2017 Sébastien Wilmet
 *
 * GNOME LaTeX is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GNOME LaTeX is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNOME LaTeX.  If not, see <http://www.gnu.org/licenses/>.
 */


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


#define TYPE_FACTORY (factory_get_type ())
#define FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FACTORY, Factory))
#define FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FACTORY, FactoryClass))
#define IS_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FACTORY))
#define IS_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FACTORY))
#define FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FACTORY, FactoryClass))

typedef struct _Factory Factory;
typedef struct _FactoryClass FactoryClass;
typedef struct _FactoryPrivate FactoryPrivate;
enum  {
	FACTORY_0_PROPERTY,
	FACTORY_NUM_PROPERTIES
};
static GParamSpec* factory_properties[FACTORY_NUM_PROPERTIES];

#define TYPE_GLATEX_APP (glatex_app_get_type ())
#define GLATEX_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GLATEX_APP, GlatexApp))
#define GLATEX_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GLATEX_APP, GlatexAppClass))
#define IS_GLATEX_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GLATEX_APP))
#define IS_GLATEX_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GLATEX_APP))
#define GLATEX_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GLATEX_APP, GlatexAppClass))

typedef struct _GlatexApp GlatexApp;
typedef struct _GlatexAppClass GlatexAppClass;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Factory {
	TeplAbstractFactoryVala parent_instance;
	FactoryPrivate * priv;
};

struct _FactoryClass {
	TeplAbstractFactoryValaClass parent_class;
};


static gpointer factory_parent_class = NULL;

GType factory_get_type (void) G_GNUC_CONST;
Factory* factory_new (void);
Factory* factory_construct (GType object_type);
static GtkApplicationWindow* factory_real_create_main_window_vala (TeplAbstractFactoryVala* base,
                                                            GtkApplication* gtk_app);
GType glatex_app_get_type (void) G_GNUC_CONST;
GType main_window_get_type (void) G_GNUC_CONST;
MainWindow* glatex_app_get_active_main_window (GlatexApp* self);
void main_window_save_state (MainWindow* self);
MainWindow* main_window_new (GlatexApp* app);
MainWindow* main_window_construct (GType object_type,
                                   GlatexApp* app);
static void factory_reopen_files (Factory* self,
                           GlatexApp* app);
static void _vala_array_add4 (GFile** * array,
                       int* length,
                       int* size,
                       GFile* value);
void glatex_app_open_documents (GlatexApp* self,
                                GFile** files,
                                int files_length1);
static void _vala_array_destroy (gpointer array,
                          gint array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gint array_length,
                       GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


Factory*
factory_construct (GType object_type)
{
	Factory * self = NULL;
#line 22 "/home/seb/gnome/gnome-latex/src/factory.vala"
	self = (Factory*) g_object_new (object_type, NULL);
#line 22 "/home/seb/gnome/gnome-latex/src/factory.vala"
	return self;
#line 122 "factory.c"
}


Factory*
factory_new (void)
{
#line 22 "/home/seb/gnome/gnome-latex/src/factory.vala"
	return factory_construct (TYPE_FACTORY);
#line 131 "factory.c"
}


static gpointer
_g_object_ref0 (gpointer self)
{
#line 29 "/home/seb/gnome/gnome-latex/src/factory.vala"
	return self ? g_object_ref (self) : NULL;
#line 140 "factory.c"
}


static GtkApplicationWindow*
factory_real_create_main_window_vala (TeplAbstractFactoryVala* base,
                                      GtkApplication* gtk_app)
{
	Factory * self;
	GtkApplicationWindow* result = NULL;
	GlatexApp* app = NULL;
	GlatexApp* _tmp0_;
	MainWindow* active_main_window = NULL;
	GlatexApp* _tmp1_;
	MainWindow* _tmp2_;
	MainWindow* _tmp3_;
	gboolean first_window = FALSE;
	MainWindow* _tmp5_;
	MainWindow* new_window = NULL;
	GlatexApp* _tmp6_;
	MainWindow* _tmp7_;
	gboolean _tmp8_;
#line 26 "/home/seb/gnome/gnome-latex/src/factory.vala"
	self = (Factory*) base;
#line 26 "/home/seb/gnome/gnome-latex/src/factory.vala"
	g_return_val_if_fail (gtk_app != NULL, NULL);
#line 28 "/home/seb/gnome/gnome-latex/src/factory.vala"
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (gtk_app, TYPE_GLATEX_APP), NULL);
#line 29 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (gtk_app, TYPE_GLATEX_APP) ? ((GlatexApp*) gtk_app) : NULL);
#line 29 "/home/seb/gnome/gnome-latex/src/factory.vala"
	app = _tmp0_;
#line 31 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp1_ = app;
#line 31 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp2_ = glatex_app_get_active_main_window (_tmp1_);
#line 31 "/home/seb/gnome/gnome-latex/src/factory.vala"
	active_main_window = _tmp2_;
#line 32 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp3_ = active_main_window;
#line 32 "/home/seb/gnome/gnome-latex/src/factory.vala"
	if (_tmp3_ != NULL) {
#line 182 "factory.c"
		MainWindow* _tmp4_;
#line 33 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp4_ = active_main_window;
#line 33 "/home/seb/gnome/gnome-latex/src/factory.vala"
		main_window_save_state (_tmp4_);
#line 188 "factory.c"
	}
#line 35 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp5_ = active_main_window;
#line 35 "/home/seb/gnome/gnome-latex/src/factory.vala"
	first_window = _tmp5_ == NULL;
#line 37 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp6_ = app;
#line 37 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp7_ = main_window_new (_tmp6_);
#line 37 "/home/seb/gnome/gnome-latex/src/factory.vala"
	g_object_ref_sink (_tmp7_);
#line 37 "/home/seb/gnome/gnome-latex/src/factory.vala"
	new_window = _tmp7_;
#line 38 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp8_ = first_window;
#line 38 "/home/seb/gnome/gnome-latex/src/factory.vala"
	if (_tmp8_) {
#line 206 "factory.c"
		GlatexApp* _tmp9_;
#line 39 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp9_ = app;
#line 39 "/home/seb/gnome/gnome-latex/src/factory.vala"
		factory_reopen_files (self, _tmp9_);
#line 212 "factory.c"
	}
#line 41 "/home/seb/gnome/gnome-latex/src/factory.vala"
	result = (GtkApplicationWindow*) new_window;
#line 41 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_g_object_unref0 (active_main_window);
#line 41 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_g_object_unref0 (app);
#line 41 "/home/seb/gnome/gnome-latex/src/factory.vala"
	return result;
#line 222 "factory.c"
}


static void
_vala_array_add4 (GFile** * array,
                  int* length,
                  int* size,
                  GFile* value)
{
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
	if ((*length) == (*size)) {
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
		*size = (*size) ? (2 * (*size)) : 4;
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
		*array = g_renew (GFile*, *array, (*size) + 1);
#line 238 "factory.c"
	}
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
	(*array)[(*length)++] = value;
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
	(*array)[*length] = NULL;
#line 244 "factory.c"
}


static void
factory_reopen_files (Factory* self,
                      GlatexApp* app)
{
	GSettings* editor_settings = NULL;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
#line 44 "/home/seb/gnome/gnome-latex/src/factory.vala"
	g_return_if_fail (self != NULL);
#line 44 "/home/seb/gnome/gnome-latex/src/factory.vala"
	g_return_if_fail (app != NULL);
#line 46 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp0_ = g_settings_new ("org.gnome.gnome-latex.preferences.editor");
#line 46 "/home/seb/gnome/gnome-latex/src/factory.vala"
	editor_settings = _tmp0_;
#line 49 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_tmp1_ = editor_settings;
#line 49 "/home/seb/gnome/gnome-latex/src/factory.vala"
	if (g_settings_get_boolean (_tmp1_, "reopen-files")) {
#line 267 "factory.c"
		GSettings* window_settings = NULL;
		GSettings* _tmp2_;
		gchar** uris = NULL;
		GSettings* _tmp3_;
		gchar** _tmp4_;
		gchar** _tmp5_;
		gint uris_length1;
		gint _uris_size_;
		GFile** files = NULL;
		GFile** _tmp6_;
		gint files_length1;
		gint _files_size_;
		gchar** _tmp7_;
		gint _tmp7__length1;
		GFile** _tmp15_;
		gint _tmp15__length1;
#line 51 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp2_ = g_settings_new ("org.gnome.gnome-latex.state.window");
#line 51 "/home/seb/gnome/gnome-latex/src/factory.vala"
		window_settings = _tmp2_;
#line 54 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp3_ = window_settings;
#line 54 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp5_ = _tmp4_ = g_settings_get_strv (_tmp3_, "documents");
#line 54 "/home/seb/gnome/gnome-latex/src/factory.vala"
		uris = _tmp5_;
#line 54 "/home/seb/gnome/gnome-latex/src/factory.vala"
		uris_length1 = _vala_array_length (_tmp4_);
#line 54 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_uris_size_ = uris_length1;
#line 55 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp6_ = g_new0 (GFile*, 0 + 1);
#line 55 "/home/seb/gnome/gnome-latex/src/factory.vala"
		files = _tmp6_;
#line 55 "/home/seb/gnome/gnome-latex/src/factory.vala"
		files_length1 = 0;
#line 55 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_files_size_ = files_length1;
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp7_ = uris;
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp7__length1 = uris_length1;
#line 310 "factory.c"
		{
			gchar** uri_collection = NULL;
			gint uri_collection_length1 = 0;
			gint _uri_collection_size_ = 0;
			gint uri_it = 0;
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
			uri_collection = _tmp7_;
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
			uri_collection_length1 = _tmp7__length1;
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
			for (uri_it = 0; uri_it < _tmp7__length1; uri_it = uri_it + 1) {
#line 322 "factory.c"
				gchar* _tmp8_;
				gchar* uri = NULL;
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
				_tmp8_ = g_strdup (uri_collection[uri_it]);
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
				uri = _tmp8_;
#line 329 "factory.c"
				{
					const gchar* _tmp9_;
					gint _tmp10_;
					gint _tmp11_;
#line 58 "/home/seb/gnome/gnome-latex/src/factory.vala"
					_tmp9_ = uri;
#line 58 "/home/seb/gnome/gnome-latex/src/factory.vala"
					_tmp10_ = strlen (_tmp9_);
#line 58 "/home/seb/gnome/gnome-latex/src/factory.vala"
					_tmp11_ = _tmp10_;
#line 58 "/home/seb/gnome/gnome-latex/src/factory.vala"
					if (0 < _tmp11_) {
#line 342 "factory.c"
						GFile** _tmp12_;
						gint _tmp12__length1;
						const gchar* _tmp13_;
						GFile* _tmp14_;
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
						_tmp12_ = files;
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
						_tmp12__length1 = files_length1;
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
						_tmp13_ = uri;
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
						_tmp14_ = g_file_new_for_uri (_tmp13_);
#line 59 "/home/seb/gnome/gnome-latex/src/factory.vala"
						_vala_array_add4 (&files, &files_length1, &_files_size_, _tmp14_);
#line 357 "factory.c"
					}
#line 56 "/home/seb/gnome/gnome-latex/src/factory.vala"
					_g_free0 (uri);
#line 361 "factory.c"
				}
			}
		}
#line 62 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp15_ = files;
#line 62 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_tmp15__length1 = files_length1;
#line 62 "/home/seb/gnome/gnome-latex/src/factory.vala"
		glatex_app_open_documents (app, _tmp15_, _tmp15__length1);
#line 49 "/home/seb/gnome/gnome-latex/src/factory.vala"
		files = (_vala_array_free (files, files_length1, (GDestroyNotify) g_object_unref), NULL);
#line 49 "/home/seb/gnome/gnome-latex/src/factory.vala"
		uris = (_vala_array_free (uris, uris_length1, (GDestroyNotify) g_free), NULL);
#line 49 "/home/seb/gnome/gnome-latex/src/factory.vala"
		_g_object_unref0 (window_settings);
#line 377 "factory.c"
	}
#line 44 "/home/seb/gnome/gnome-latex/src/factory.vala"
	_g_object_unref0 (editor_settings);
#line 381 "factory.c"
}


static void
factory_class_init (FactoryClass * klass)
{
#line 20 "/home/seb/gnome/gnome-latex/src/factory.vala"
	factory_parent_class = g_type_class_peek_parent (klass);
#line 20 "/home/seb/gnome/gnome-latex/src/factory.vala"
	((TeplAbstractFactoryValaClass *) klass)->create_main_window_vala = (GtkApplicationWindow* (*) (TeplAbstractFactoryVala *, GtkApplication*)) factory_real_create_main_window_vala;
#line 392 "factory.c"
}


static void
factory_instance_init (Factory * self)
{
}


GType
factory_get_type (void)
{
	static volatile gsize factory_type_id__volatile = 0;
	if (g_once_init_enter (&factory_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FactoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) factory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Factory), 0, (GInstanceInitFunc) factory_instance_init, NULL };
		GType factory_type_id;
		factory_type_id = g_type_register_static (tepl_abstract_factory_vala_get_type (), "Factory", &g_define_type_info, 0);
		g_once_init_leave (&factory_type_id__volatile, factory_type_id);
	}
	return factory_type_id__volatile;
}


static void
_vala_array_destroy (gpointer array,
                     gint array_length,
                     GDestroyNotify destroy_func)
{
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
	if ((array != NULL) && (destroy_func != NULL)) {
#line 423 "factory.c"
		int i;
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
		for (i = 0; i < array_length; i = i + 1) {
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
			if (((gpointer*) array)[i] != NULL) {
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
				destroy_func (((gpointer*) array)[i]);
#line 431 "factory.c"
			}
		}
	}
}


static void
_vala_array_free (gpointer array,
                  gint array_length,
                  GDestroyNotify destroy_func)
{
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
	_vala_array_destroy (array, array_length, destroy_func);
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
	g_free (array);
#line 447 "factory.c"
}


static gint
_vala_array_length (gpointer array)
{
	int length;
	length = 0;
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
	if (array) {
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
		while (((gpointer*) array)[length]) {
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
			length++;
#line 462 "factory.c"
		}
	}
#line 27 "/home/seb/gnome/gnome-latex/src/build_tools_preferences.vala"
	return length;
#line 467 "factory.c"
}



