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

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <gee.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "config.h"
#include <locale.h>
#include <gtk/gtk.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

enum  {
	GRAPHS_APPLICATION_0_PROPERTY,
	GRAPHS_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* graphs_application_properties[GRAPHS_APPLICATION_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))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_variant_dict_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_dict_unref (var), NULL)))

struct _GraphsApplicationPrivate {
	GeeList* main_windows;
	GeeList* style_editors;
};

static gint GraphsApplication_private_offset;
static gpointer graphs_application_parent_class = NULL;
static GSettings* graphs_application__settings;
static GSettings* graphs_application__settings = NULL;
static guint graphs_application__css_counter;
static guint graphs_application__css_counter = (guint) 0;

static void graphs_application_real_startup (GApplication* base);
static void graphs_application_set_settings (GSettings* value);
static void graphs_application_real_activate (GApplication* base);
static void graphs_application_real_open (GApplication* base,
                                   GFile** files,
                                   gint files_length1,
                                   const gchar* hint);
static gint graphs_application_real_command_line (GApplication* base,
                                           GApplicationCommandLine* command_line);
static gchar** _vala_array_dup12 (gchar** self,
                           gssize length);
static void graphs_application_try_quit (GraphsApplication* self);
static void graphs_application_finalize (GObject * obj);
static GType graphs_application_get_type_once (void);
static void _vala_graphs_application_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_graphs_application_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 _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const GOptionEntry GRAPHS_APPLICATION_OPTION_ENTRIES[4] = {{"new-window", 'n', (gint) 0, G_OPTION_ARG_NONE, NULL, N_ ("New window"), NULL}, {"style-editor", 's', (gint) 0, G_OPTION_ARG_NONE, NULL, N_ ("Style Editor"), NULL}, {G_OPTION_REMAINING, (gchar) 0, (gint) 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, N_ ("[FILE…]")}, {NULL}};

static inline gpointer
graphs_application_get_instance_private (GraphsApplication* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsApplication_private_offset);
}

GraphsApplication*
graphs_application_construct (GType object_type)
{
	GraphsApplication * self = NULL;
	self = (GraphsApplication*) g_object_new (object_type, "application-id", APPLICATION_ID, "version", VERSION, "flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN, NULL);
	g_application_add_main_option_entries ((GApplication*) self, GRAPHS_APPLICATION_OPTION_ENTRIES);
	return self;
}

GraphsApplication*
graphs_application_new (void)
{
	return graphs_application_construct (GRAPHS_TYPE_APPLICATION);
}

/**
         * Setup the application.
         */
static void
graphs_application_real_startup (GApplication* base)
{
	GraphsApplication * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GSettings* _tmp2_;
	GSettings* _tmp3_;
	GeeLinkedList* _tmp4_;
	GeeLinkedList* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	self = (GraphsApplication*) base;
	G_APPLICATION_CLASS (graphs_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_application_get_type (), AdwApplication));
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	setlocale (LC_NUMERIC, "C");
	_tmp0_ = g_application_get_application_id ((GApplication*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_settings_new (_tmp1_);
	_tmp3_ = _tmp2_;
	graphs_application_set_settings (_tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = gee_linked_list_new (GRAPHS_TYPE_WINDOW, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->main_windows);
	self->priv->main_windows = (GeeList*) _tmp4_;
	_tmp5_ = gee_linked_list_new (GRAPHS_TYPE_STYLE_EDITOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->style_editors);
	self->priv->style_editors = (GeeList*) _tmp5_;
	_tmp6_ = g_application_get_application_id ((GApplication*) self);
	_tmp7_ = _tmp6_;
	gtk_window_set_default_icon_name (_tmp7_);
	graphs_actions_setup_global ();
}

/**
         * Activate the application.
         */
static void
graphs_application_real_activate (GApplication* base)
{
	GraphsApplication * self;
	GraphsWindow* _tmp0_ = NULL;
	GeeList* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GraphsWindow* window = NULL;
	GraphsWindow* _tmp7_;
	self = (GraphsApplication*) base;
	G_APPLICATION_CLASS (graphs_application_parent_class)->activate ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_application_get_type (), AdwApplication));
	_tmp1_ = self->priv->main_windows;
	_tmp2_ = gee_collection_get_is_empty ((GeeCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		GraphsWindow* _tmp4_;
		_tmp4_ = graphs_application_create_main_window (self);
		_g_object_unref0 (_tmp0_);
		_tmp0_ = _tmp4_;
	} else {
		GeeList* _tmp5_;
		gpointer _tmp6_;
		_tmp5_ = self->priv->main_windows;
		_tmp6_ = gee_list_get (_tmp5_, 0);
		_g_object_unref0 (_tmp0_);
		_tmp0_ = (GraphsWindow*) _tmp6_;
	}
	_tmp7_ = _tmp0_;
	_tmp0_ = NULL;
	window = _tmp7_;
	gtk_window_present ((GtkWindow*) window);
	_g_object_unref0 (window);
	_g_object_unref0 (_tmp0_);
}

/**
         * Handle File Opening.
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
graphs_application_real_open (GApplication* base,
                              GFile** files,
                              gint files_length1,
                              const gchar* hint)
{
	GraphsApplication * self;
	GraphsWindow* window = NULL;
	GraphsWindow* _tmp38_;
	GraphsWindow* _tmp40_;
	GListStore* settings_list = NULL;
	GListStore* _tmp41_;
	GraphsWindow* _tmp48_;
	GListStore* _tmp49_;
	GraphsImportDialog* _tmp50_;
	GraphsImportDialog* _tmp51_;
	self = (GraphsApplication*) base;
	g_return_if_fail (hint != NULL);
	G_APPLICATION_CLASS (graphs_application_parent_class)->open ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_application_get_type (), AdwApplication), files, (gint) files_length1, hint);
	if (files_length1 == 1) {
		GFile* file = NULL;
		GFile* _tmp0_;
		GFile* _tmp1_;
		gchar* uri = NULL;
		GFile* _tmp2_;
		gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp0_ = files[0];
		_tmp1_ = _g_object_ref0 (_tmp0_);
		file = _tmp1_;
		_tmp2_ = file;
		_tmp3_ = g_file_get_uri (_tmp2_);
		uri = _tmp3_;
		_tmp4_ = uri;
		if (g_str_has_suffix (_tmp4_, ".graphs")) {
			GraphsWindow* window = NULL;
			GraphsWindow* _tmp5_;
			GraphsWindow* _tmp6_;
			GraphsWindow* _tmp7_;
			GraphsWindow* _tmp8_;
			GraphsData* _tmp9_;
			GraphsData* _tmp10_;
			GFile* _tmp11_;
			_tmp5_ = graphs_application_create_main_window (self);
			window = _tmp5_;
			_tmp6_ = window;
			gtk_window_present ((GtkWindow*) _tmp6_);
			_tmp7_ = window;
			_tmp8_ = window;
			_tmp9_ = graphs_window_get_data (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = file;
			graphs_project_load (_tmp7_, _tmp10_, _tmp11_, GRAPHS_PROJECT_PARSE_FLAGS_NONE, NULL, NULL);
			_g_object_unref0 (window);
			_g_free0 (uri);
			_g_object_unref0 (file);
			return;
		} else {
			const gchar* _tmp12_;
			_tmp12_ = uri;
			if (g_str_has_suffix (_tmp12_, ".mplstyle")) {
				GraphsStyleEditor* style_editor = NULL;
				GraphsStyleEditor* _tmp13_;
				GraphsStyleEditor* _tmp14_;
				GFile* _tmp15_;
				GraphsStyleEditor* _tmp16_;
				_tmp13_ = graphs_application_create_style_editor (self);
				style_editor = _tmp13_;
				_tmp14_ = style_editor;
				_tmp15_ = file;
				graphs_style_editor_load (_tmp14_, _tmp15_);
				_tmp16_ = style_editor;
				gtk_window_present ((GtkWindow*) _tmp16_);
				_g_object_unref0 (style_editor);
				_g_free0 (uri);
				_g_object_unref0 (file);
				return;
			}
		}
		_g_free0 (uri);
		_g_object_unref0 (file);
	}
	window = NULL;
	{
		GeeList* _pot_window_list = NULL;
		GeeList* _tmp17_;
		gint _pot_window_size = 0;
		GeeList* _tmp18_;
		gint _tmp19_;
		gint _tmp20_;
		gint _pot_window_index = 0;
		_tmp17_ = self->priv->main_windows;
		_pot_window_list = _tmp17_;
		_tmp18_ = _pot_window_list;
		_tmp19_ = gee_collection_get_size ((GeeCollection*) _tmp18_);
		_tmp20_ = _tmp19_;
		_pot_window_size = _tmp20_;
		_pot_window_index = -1;
		while (TRUE) {
			gint _tmp21_;
			gint _tmp22_;
			GraphsWindow* pot_window = NULL;
			GeeList* _tmp23_;
			gpointer _tmp24_;
			gboolean _tmp25_ = FALSE;
			GraphsWindow* _tmp26_;
			GraphsData* _tmp27_;
			GraphsData* _tmp28_;
			gboolean _tmp29_;
			gboolean _tmp30_;
			_pot_window_index = _pot_window_index + 1;
			_tmp21_ = _pot_window_index;
			_tmp22_ = _pot_window_size;
			if (!(_tmp21_ < _tmp22_)) {
				break;
			}
			_tmp23_ = _pot_window_list;
			_tmp24_ = gee_list_get (_tmp23_, _pot_window_index);
			pot_window = (GraphsWindow*) _tmp24_;
			_tmp26_ = pot_window;
			_tmp27_ = graphs_window_get_data (_tmp26_);
			_tmp28_ = _tmp27_;
			_tmp29_ = graphs_data_get_unsaved (_tmp28_);
			_tmp30_ = _tmp29_;
			if (!_tmp30_) {
				GraphsWindow* _tmp31_;
				GraphsData* _tmp32_;
				GraphsData* _tmp33_;
				GFile* _tmp34_;
				GFile* _tmp35_;
				_tmp31_ = pot_window;
				_tmp32_ = graphs_window_get_data (_tmp31_);
				_tmp33_ = _tmp32_;
				_tmp34_ = graphs_data_get_file (_tmp33_);
				_tmp35_ = _tmp34_;
				_tmp25_ = _tmp35_ == NULL;
			} else {
				_tmp25_ = FALSE;
			}
			if (_tmp25_) {
				GraphsWindow* _tmp36_;
				GraphsWindow* _tmp37_;
				_tmp36_ = pot_window;
				_tmp37_ = _g_object_ref0 (_tmp36_);
				_g_object_unref0 (window);
				window = _tmp37_;
				_g_object_unref0 (pot_window);
				break;
			}
			_g_object_unref0 (pot_window);
		}
	}
	_tmp38_ = window;
	if (_tmp38_ == NULL) {
		GraphsWindow* _tmp39_;
		_tmp39_ = graphs_application_create_main_window (self);
		_g_object_unref0 (window);
		window = _tmp39_;
	}
	_tmp40_ = window;
	gtk_window_present ((GtkWindow*) _tmp40_);
	_tmp41_ = g_list_store_new (GRAPHS_TYPE_IMPORT_SETTINGS);
	settings_list = _tmp41_;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp42_ = FALSE;
			_tmp42_ = TRUE;
			while (TRUE) {
				GListStore* _tmp44_;
				GFile* _tmp45_;
				GraphsImportSettings* _tmp46_;
				GraphsImportSettings* _tmp47_;
				if (!_tmp42_) {
					guint _tmp43_;
					_tmp43_ = i;
					i = _tmp43_ + 1;
				}
				_tmp42_ = FALSE;
				if (!(i < ((guint) files_length1))) {
					break;
				}
				_tmp44_ = settings_list;
				_tmp45_ = files[i];
				_tmp46_ = graphs_data_importer_get_settings_for_file (_tmp45_);
				_tmp47_ = _tmp46_;
				g_list_store_append (_tmp44_, (GObject*) _tmp47_);
				_g_object_unref0 (_tmp47_);
			}
		}
	}
	_tmp48_ = window;
	_tmp49_ = settings_list;
	_tmp50_ = graphs_import_dialog_new (_tmp48_, _tmp49_);
	g_object_ref_sink (_tmp50_);
	_tmp51_ = _tmp50_;
	_g_object_unref0 (_tmp51_);
	_g_object_unref0 (settings_list);
	_g_object_unref0 (window);
}

static gpointer
_g_variant_dict_ref0 (gpointer self)
{
	return self ? g_variant_dict_ref (self) : NULL;
}

static gchar**
_vala_array_dup12 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gint
graphs_application_real_command_line (GApplication* base,
                                      GApplicationCommandLine* command_line)
{
	GraphsApplication * self;
	GVariantDict* options = NULL;
	GVariantDict* _tmp0_;
	GVariantDict* _tmp1_;
	gboolean new_window = FALSE;
	gboolean new_style_editor = FALSE;
	GVariantDict* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GVariantDict* _tmp4_;
	gboolean _tmp5_ = FALSE;
	GVariant* val = NULL;
	GVariantDict* _tmp6_;
	const GVariantType* _tmp7_;
	GVariant* _tmp8_;
	GVariant* _tmp9_;
	gint result;
	self = (GraphsApplication*) base;
	g_return_val_if_fail (command_line != NULL, -1);
	_tmp0_ = g_application_command_line_get_options_dict (command_line);
	_tmp1_ = _g_variant_dict_ref0 (_tmp0_);
	options = _tmp1_;
	_tmp2_ = options;
	g_variant_dict_lookup (_tmp2_, "new-window", "b", &_tmp3_, NULL);
	new_window = _tmp3_;
	_tmp4_ = options;
	g_variant_dict_lookup (_tmp4_, "style-editor", "b", &_tmp5_, NULL);
	new_style_editor = _tmp5_;
	_tmp6_ = options;
	_tmp7_ = G_VARIANT_TYPE_STRING_ARRAY;
	_tmp8_ = g_variant_dict_lookup_value (_tmp6_, G_OPTION_REMAINING, _tmp7_);
	val = _tmp8_;
	_tmp9_ = val;
	if (_tmp9_ != NULL) {
		gchar** remaining = NULL;
		GVariant* _tmp10_;
		gsize _tmp11_ = 0;
		const gchar** _tmp12_;
		gchar** _tmp13_;
		gint _tmp13__length1;
		gint remaining_length1;
		gint _remaining_size_;
		GFile** files = NULL;
		gchar** _tmp14_;
		gint _tmp14__length1;
		GFile** _tmp15_;
		gint files_length1;
		gint _files_size_;
		GFile** _tmp23_;
		gint _tmp23__length1;
		_tmp10_ = val;
		_tmp12_ = g_variant_get_strv (_tmp10_, &_tmp11_);
		_tmp13_ = (_tmp12_ != NULL) ? _vala_array_dup12 (_tmp12_, _tmp11_) : _tmp12_;
		_tmp13__length1 = _tmp11_;
		_tmp12_ = (g_free (_tmp12_), NULL);
		remaining = _tmp13_;
		remaining_length1 = _tmp13__length1;
		_remaining_size_ = remaining_length1;
		_tmp14_ = remaining;
		_tmp14__length1 = remaining_length1;
		_tmp15_ = g_new0 (GFile*, _tmp14__length1 + 1);
		files = _tmp15_;
		files_length1 = _tmp14__length1;
		_files_size_ = files_length1;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp16_ = FALSE;
				_tmp16_ = TRUE;
				while (TRUE) {
					gchar** _tmp18_;
					gint _tmp18__length1;
					GFile** _tmp19_;
					gint _tmp19__length1;
					gchar** _tmp20_;
					gint _tmp20__length1;
					const gchar* _tmp21_;
					GFile* _tmp22_;
					if (!_tmp16_) {
						gint _tmp17_;
						_tmp17_ = i;
						i = _tmp17_ + 1;
					}
					_tmp16_ = FALSE;
					_tmp18_ = remaining;
					_tmp18__length1 = remaining_length1;
					if (!(i < _tmp18__length1)) {
						break;
					}
					_tmp19_ = files;
					_tmp19__length1 = files_length1;
					_tmp20_ = remaining;
					_tmp20__length1 = remaining_length1;
					_tmp21_ = _tmp20_[i];
					_tmp22_ = g_application_command_line_create_file_for_arg (command_line, _tmp21_);
					_g_object_unref0 (_tmp19_[i]);
					_tmp19_[i] = _tmp22_;
				}
			}
		}
		_tmp23_ = files;
		_tmp23__length1 = files_length1;
		g_application_open ((GApplication*) self, _tmp23_, (gint) _tmp23__length1, "");
		files = (_vala_array_free (files, files_length1, (GDestroyNotify) g_object_unref), NULL);
		remaining = (_vala_array_free (remaining, remaining_length1, (GDestroyNotify) g_free), NULL);
	} else {
		if (new_window) {
			GraphsWindow* window = NULL;
			GraphsWindow* _tmp24_;
			GraphsWindow* _tmp25_;
			_tmp24_ = graphs_application_create_main_window (self);
			window = _tmp24_;
			_tmp25_ = window;
			gtk_window_present ((GtkWindow*) _tmp25_);
			_g_object_unref0 (window);
		} else {
			if (new_style_editor) {
				GraphsStyleEditor* style_editor = NULL;
				GraphsStyleEditor* _tmp26_;
				GraphsStyleEditor* _tmp27_;
				_tmp26_ = graphs_application_create_style_editor (self);
				style_editor = _tmp26_;
				_tmp27_ = style_editor;
				gtk_window_present ((GtkWindow*) _tmp27_);
				_g_object_unref0 (style_editor);
			} else {
				g_application_activate ((GApplication*) self);
			}
		}
	}
	result = 0;
	_g_variant_unref0 (val);
	_g_variant_dict_unref0 (options);
	return result;
}

GraphsWindow*
graphs_application_create_main_window (GraphsApplication* self)
{
	GraphsWindow* window = NULL;
	GraphsWindow* _tmp0_;
	GeeList* _tmp1_;
	GraphsWindow* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = graphs_python_helper_create_window ();
	window = _tmp0_;
	_tmp1_ = self->priv->main_windows;
	gee_collection_add ((GeeCollection*) _tmp1_, window);
	gtk_application_add_window ((GtkApplication*) self, (GtkWindow*) window);
	result = window;
	return result;
}

GraphsStyleEditor*
graphs_application_create_style_editor (GraphsApplication* self)
{
	GraphsStyleEditor* style_editor = NULL;
	GraphsStyleEditor* _tmp0_;
	GeeList* _tmp1_;
	GraphsStyleEditor* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = graphs_python_helper_create_style_editor ();
	style_editor = _tmp0_;
	_tmp1_ = self->priv->style_editors;
	gee_collection_add ((GeeCollection*) _tmp1_, style_editor);
	gtk_application_add_window ((GtkApplication*) self, (GtkWindow*) style_editor);
	result = style_editor;
	return result;
}

gchar*
graphs_application_get_next_css_name (void)
{
	guint _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = graphs_application__css_counter;
	graphs_application__css_counter = _tmp0_ + 1;
	_tmp1_ = g_strdup_printf ("%u", graphs_application__css_counter);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat ("view", _tmp2_, NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	result = _tmp4_;
	return result;
}

/**
         * Retrieve a child of the applications settings.
         *
         * @param path a slash-separated path
         */
GSettings*
graphs_application_get_settings_child (const gchar* path)
{
	GSettings* settings_child = NULL;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	GSettings* result;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = graphs_application_get_settings ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	settings_child = _tmp2_;
	_tmp4_ = _tmp3_ = g_strsplit (path, "/", 0);
	{
		gchar** child_name_collection = NULL;
		gint child_name_collection_length1 = 0;
		gint _child_name_collection_size_ = 0;
		gint child_name_it = 0;
		child_name_collection = _tmp4_;
		child_name_collection_length1 = _vala_array_length (_tmp3_);
		for (child_name_it = 0; child_name_it < child_name_collection_length1; child_name_it = child_name_it + 1) {
			gchar* _tmp5_;
			gchar* child_name = NULL;
			_tmp5_ = g_strdup (child_name_collection[child_name_it]);
			child_name = _tmp5_;
			{
				GSettings* _tmp6_;
				const gchar* _tmp7_;
				GSettings* _tmp8_;
				_tmp6_ = settings_child;
				_tmp7_ = child_name;
				_tmp8_ = g_settings_get_child (_tmp6_, _tmp7_);
				_g_object_unref0 (settings_child);
				settings_child = _tmp8_;
				_g_free0 (child_name);
			}
		}
		child_name_collection = (_vala_array_free (child_name_collection, child_name_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = settings_child;
	return result;
}

void
graphs_application_on_main_window_closed (GraphsApplication* self,
                                          GraphsWindow* window)
{
	GeeList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	_tmp0_ = self->priv->main_windows;
	gee_collection_remove ((GeeCollection*) _tmp0_, window);
	graphs_application_try_quit (self);
}

void
graphs_application_on_style_editor_closed (GraphsApplication* self,
                                           GraphsStyleEditor* style_editor)
{
	GeeList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (style_editor != NULL);
	_tmp0_ = self->priv->style_editors;
	gee_collection_remove ((GeeCollection*) _tmp0_, style_editor);
	graphs_application_try_quit (self);
}

static void
graphs_application_try_quit (GraphsApplication* self)
{
	gboolean _tmp0_ = FALSE;
	GeeList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->main_windows;
	_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == 0) {
		GeeList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		_tmp4_ = self->priv->style_editors;
		_tmp5_ = gee_collection_get_size ((GeeCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_ == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_application_quit ((GApplication*) self);
	}
}

void
graphs_application_quit_action (GraphsApplication* self)
{
	GeeList* _tmp0_;
	gint _tmp1_ = 0;
	gpointer* _tmp2_;
	GeeList* _tmp5_;
	gint _tmp6_ = 0;
	gpointer* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->main_windows;
	_tmp2_ = gee_collection_to_array ((GeeCollection*) _tmp0_, &_tmp1_);
	{
		GraphsWindow** window_collection = NULL;
		gint window_collection_length1 = 0;
		gint _window_collection_size_ = 0;
		gint window_it = 0;
		window_collection = _tmp2_;
		window_collection_length1 = _tmp1_;
		for (window_it = 0; window_it < window_collection_length1; window_it = window_it + 1) {
			GraphsWindow* _tmp3_;
			GraphsWindow* window = NULL;
			_tmp3_ = _g_object_ref0 (window_collection[window_it]);
			window = _tmp3_;
			{
				GraphsWindow* _tmp4_;
				_tmp4_ = window;
				gtk_window_close ((GtkWindow*) _tmp4_);
				_g_object_unref0 (window);
			}
		}
		window_collection = (_vala_array_free (window_collection, window_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	_tmp5_ = self->priv->style_editors;
	_tmp7_ = gee_collection_to_array ((GeeCollection*) _tmp5_, &_tmp6_);
	{
		GraphsStyleEditor** style_editor_collection = NULL;
		gint style_editor_collection_length1 = 0;
		gint _style_editor_collection_size_ = 0;
		gint style_editor_it = 0;
		style_editor_collection = _tmp7_;
		style_editor_collection_length1 = _tmp6_;
		for (style_editor_it = 0; style_editor_it < style_editor_collection_length1; style_editor_it = style_editor_it + 1) {
			GraphsStyleEditor* _tmp8_;
			GraphsStyleEditor* style_editor = NULL;
			_tmp8_ = _g_object_ref0 (style_editor_collection[style_editor_it]);
			style_editor = _tmp8_;
			{
				GraphsStyleEditor* _tmp9_;
				_tmp9_ = style_editor;
				gtk_window_close ((GtkWindow*) _tmp9_);
				_g_object_unref0 (style_editor);
			}
		}
		style_editor_collection = (_vala_array_free (style_editor_collection, style_editor_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
}

GSettings*
graphs_application_get_settings (void)
{
	GSettings* result;
	GSettings* _tmp0_;
	_tmp0_ = graphs_application__settings;
	result = _tmp0_;
	return result;
}

static void
graphs_application_set_settings (GSettings* value)
{
	GSettings* _tmp0_;
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (graphs_application__settings);
	graphs_application__settings = _tmp0_;
}

static void
graphs_application_class_init (GraphsApplicationClass * klass,
                               gpointer klass_data)
{
	graphs_application_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsApplication_private_offset);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) graphs_application_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) graphs_application_real_activate;
	((GApplicationClass *) klass)->open = (void (*) (GApplication*, GFile**, gint, const gchar*)) graphs_application_real_open;
	((GApplicationClass *) klass)->command_line = (gint (*) (GApplication*, GApplicationCommandLine*)) graphs_application_real_command_line;
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_application_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_graphs_application_set_property;
	G_OBJECT_CLASS (klass)->finalize = graphs_application_finalize;
}

static void
graphs_application_instance_init (GraphsApplication * self,
                                  gpointer klass)
{
	self->priv = graphs_application_get_instance_private (self);
}

static void
graphs_application_finalize (GObject * obj)
{
	GraphsApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_APPLICATION, GraphsApplication);
	_g_object_unref0 (self->priv->main_windows);
	_g_object_unref0 (self->priv->style_editors);
	G_OBJECT_CLASS (graphs_application_parent_class)->finalize (obj);
}

/**
     * Graphs application
     */
static GType
graphs_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsApplication), 0, (GInstanceInitFunc) graphs_application_instance_init, NULL };
	GType graphs_application_type_id;
	graphs_application_type_id = g_type_register_static (adw_application_get_type (), "GraphsApplication", &g_define_type_info, 0);
	GraphsApplication_private_offset = g_type_add_instance_private (graphs_application_type_id, sizeof (GraphsApplicationPrivate));
	return graphs_application_type_id;
}

GType
graphs_application_get_type (void)
{
	static volatile gsize graphs_application_type_id__once = 0;
	if (g_once_init_enter (&graphs_application_type_id__once)) {
		GType graphs_application_type_id;
		graphs_application_type_id = graphs_application_get_type_once ();
		g_once_init_leave (&graphs_application_type_id__once, graphs_application_type_id);
	}
	return graphs_application_type_id__once;
}

static void
_vala_graphs_application_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	GraphsApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_APPLICATION, GraphsApplication);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_graphs_application_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	GraphsApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_APPLICATION, GraphsApplication);
	switch (property_id) {
		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;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

