/* theme-selector-dialog.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from theme-selector-dialog.vala, do not modify */

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

#define PREVIEW_FIELD_SIZE 7
#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 TYPE_MINEFIELD (minefield_get_type ())
#define MINEFIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MINEFIELD, Minefield))
#define MINEFIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MINEFIELD, MinefieldClass))
#define IS_MINEFIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MINEFIELD))
#define IS_MINEFIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MINEFIELD))
#define MINEFIELD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MINEFIELD, MinefieldClass))

typedef struct _Minefield Minefield;
typedef struct _MinefieldClass MinefieldClass;
typedef struct _MinefieldPrivate MinefieldPrivate;

#define TYPE_LOCATION (location_get_type ())
#define LOCATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LOCATION, Location))
#define LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LOCATION, LocationClass))
#define IS_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LOCATION))
#define IS_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LOCATION))
#define LOCATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LOCATION, LocationClass))

typedef struct _Location Location;
typedef struct _LocationClass LocationClass;

#define TYPE_PREVIEW_FIELD (preview_field_get_type ())
#define PREVIEW_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PREVIEW_FIELD, PreviewField))
#define PREVIEW_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PREVIEW_FIELD, PreviewFieldClass))
#define IS_PREVIEW_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PREVIEW_FIELD))
#define IS_PREVIEW_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PREVIEW_FIELD))
#define PREVIEW_FIELD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PREVIEW_FIELD, PreviewFieldClass))

typedef struct _PreviewField PreviewField;
typedef struct _PreviewFieldClass PreviewFieldClass;
typedef struct _PreviewFieldPrivate PreviewFieldPrivate;
enum  {
	PREVIEW_FIELD_0_PROPERTY,
	PREVIEW_FIELD_NUM_PROPERTIES
};
static GParamSpec* preview_field_properties[PREVIEW_FIELD_NUM_PROPERTIES];

#define TYPE_NEIGHBOUR (neighbour_get_type ())
typedef struct _Neighbour Neighbour;
typedef struct _LocationPrivate LocationPrivate;
typedef enum  {
	FLAG_TYPE_NONE,
	FLAG_TYPE_FLAG,
	FLAG_TYPE_MAYBE
} FlagType;

#define TYPE_FLAG_TYPE (flag_type_get_type ())

#define TYPE_THEME_SELECTOR_DIALOG (theme_selector_dialog_get_type ())
#define THEME_SELECTOR_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_THEME_SELECTOR_DIALOG, ThemeSelectorDialog))
#define THEME_SELECTOR_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_THEME_SELECTOR_DIALOG, ThemeSelectorDialogClass))
#define IS_THEME_SELECTOR_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_THEME_SELECTOR_DIALOG))
#define IS_THEME_SELECTOR_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_THEME_SELECTOR_DIALOG))
#define THEME_SELECTOR_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_THEME_SELECTOR_DIALOG, ThemeSelectorDialogClass))

typedef struct _ThemeSelectorDialog ThemeSelectorDialog;
typedef struct _ThemeSelectorDialogClass ThemeSelectorDialogClass;
typedef struct _ThemeSelectorDialogPrivate ThemeSelectorDialogPrivate;
enum  {
	THEME_SELECTOR_DIALOG_0_PROPERTY,
	THEME_SELECTOR_DIALOG_NUM_PROPERTIES
};
static GParamSpec* theme_selector_dialog_properties[THEME_SELECTOR_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_MINEFIELD_VIEW (minefield_view_get_type ())
#define MINEFIELD_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MINEFIELD_VIEW, MinefieldView))
#define MINEFIELD_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MINEFIELD_VIEW, MinefieldViewClass))
#define IS_MINEFIELD_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MINEFIELD_VIEW))
#define IS_MINEFIELD_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MINEFIELD_VIEW))
#define MINEFIELD_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MINEFIELD_VIEW, MinefieldViewClass))

typedef struct _MinefieldView MinefieldView;
typedef struct _MinefieldViewClass MinefieldViewClass;
typedef struct _Block3Data Block3Data;

struct _Minefield {
	GObject parent_instance;
	MinefieldPrivate * priv;
	guint width;
	guint height;
	guint n_mines;
	Location** locations;
	gint locations_length1;
	gint locations_length2;
	gboolean exploded;
	gboolean placed_mines;
	gboolean _use_autoflag;
};

struct _MinefieldClass {
	GObjectClass parent_class;
};

struct _PreviewField {
	Minefield parent_instance;
	PreviewFieldPrivate * priv;
};

struct _PreviewFieldClass {
	MinefieldClass parent_class;
};

struct _Neighbour {
	gint x;
	gint y;
};

struct _Location {
	GObject parent_instance;
	LocationPrivate * priv;
	gboolean has_mine;
	gboolean cleared;
	FlagType flag;
	gint adjacent_mines;
};

struct _LocationClass {
	GObjectClass parent_class;
};

struct _ThemeSelectorDialog {
	AdwDialog parent_instance;
	ThemeSelectorDialogPrivate * priv;
};

struct _ThemeSelectorDialogClass {
	AdwDialogClass parent_class;
};

struct _ThemeSelectorDialogPrivate {
	AdwToolbarView* toolbar;
	AdwHeaderBar* headerbar;
	GtkButton* previous;
	GtkButton* next;
	GSettings* settings;
};

struct _Block3Data {
	int _ref_count_;
	ThemeSelectorDialog* self;
	GList* themes;
	gint current_index;
	AdwApplicationWindow* window;
};

static gpointer preview_field_parent_class = NULL;
static gint ThemeSelectorDialog_private_offset;
static gpointer theme_selector_dialog_parent_class = NULL;

VALA_EXTERN GType minefield_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Minefield, g_object_unref)
VALA_EXTERN GType location_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Location, g_object_unref)
VALA_EXTERN GType preview_field_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PreviewField, g_object_unref)
VALA_EXTERN GType neighbour_get_type (void) G_GNUC_CONST ;
VALA_EXTERN Neighbour* neighbour_dup (const Neighbour* self);
VALA_EXTERN void neighbour_free (Neighbour* self);
VALA_EXTERN PreviewField* preview_field_new (void);
VALA_EXTERN PreviewField* preview_field_construct (GType object_type);
VALA_EXTERN Minefield* minefield_new (guint width,
                          guint height,
                          guint n_mines);
VALA_EXTERN Minefield* minefield_construct (GType object_type,
                                guint width,
                                guint height,
                                guint n_mines);
VALA_EXTERN void preview_field_place_mines (PreviewField* self,
                                guint x,
                                guint y);
VALA_EXTERN GType flag_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gboolean minefield_is_location (Minefield* self,
                                gint x,
                                gint y);
static GType preview_field_get_type_once (void);
VALA_EXTERN GType theme_selector_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ThemeSelectorDialog, g_object_unref)
VALA_EXTERN GList* theme_selector_dialog_list_themes (ThemeSelectorDialog* self);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
VALA_EXTERN GType minefield_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MinefieldView, g_object_unref)
static GtkWidget* theme_selector_dialog_create_preview_widget (ThemeSelectorDialog* self,
                                                        MinefieldView** view);
VALA_EXTERN MinefieldView* minefield_view_new (GSettings* settings);
VALA_EXTERN MinefieldView* minefield_view_construct (GType object_type,
                                         GSettings* settings);
VALA_EXTERN void minefield_view_set_minefield (MinefieldView* self,
                                   Minefield* value);
static void theme_selector_dialog_reveal_nonmines (ThemeSelectorDialog* self,
                                            MinefieldView* view);
VALA_EXTERN ThemeSelectorDialog* theme_selector_dialog_new (AdwApplicationWindow* window);
VALA_EXTERN ThemeSelectorDialog* theme_selector_dialog_construct (GType object_type,
                                                      AdwApplicationWindow* window);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda13_ (Block3Data* _data3_);
static void theme_selector_dialog_switch_theme_preview (ThemeSelectorDialog* self,
                                                 gint to_index,
                                                 GList* themes,
                                                 AdwApplicationWindow* window);
static void theme_selector_dialog_update_sensitivities (ThemeSelectorDialog* self,
                                                 GList* themes,
                                                 gint current_index);
static void ___lambda13__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda14_ (Block3Data* _data3_);
static void ___lambda14__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
VALA_EXTERN Minefield* minefield_view_get_minefield (MinefieldView* self);
VALA_EXTERN gboolean minefield_has_mine (Minefield* self,
                             guint x,
                             guint y);
VALA_EXTERN void minefield_clear_mine (Minefield* self,
                           guint x,
                           guint y);
VALA_EXTERN void minefield_multi_release (Minefield* self,
                              guint x,
                              guint y);
VALA_EXTERN void minefield_view_toggle_mark (MinefieldView* self,
                                 guint x,
                                 guint y);
static void theme_selector_dialog_finalize (GObject * obj);
static GType theme_selector_dialog_get_type_once (void);

static const Neighbour PREVIEW_FIELD_neighbour_map[8] = {{-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}};

PreviewField*
preview_field_construct (GType object_type)
{
	PreviewField * self = NULL;
	self = (PreviewField*) minefield_construct (object_type, (guint) PREVIEW_FIELD_SIZE, (guint) PREVIEW_FIELD_SIZE, (guint) (3 * PREVIEW_FIELD_SIZE));
	preview_field_place_mines (self, (guint) 0, (guint) 0);
	((Minefield*) self)->placed_mines = TRUE;
	return self;
}

PreviewField*
preview_field_new (void)
{
	return preview_field_construct (TYPE_PREVIEW_FIELD);
}

void
preview_field_place_mines (PreviewField* self,
                           guint x,
                           guint y)
{
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				Location** _tmp2_;
				gint _tmp2__length1;
				gint _tmp2__length2;
				Location* _tmp3_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				_tmp2_ = ((Minefield*) self)->locations;
				_tmp2__length1 = ((Minefield*) self)->locations_length1;
				_tmp2__length2 = ((Minefield*) self)->locations_length2;
				_tmp3_ = _tmp2_[(i * _tmp2__length2) + 0];
				_tmp3_->has_mine = i >= 5;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				Location** _tmp6_;
				gint _tmp6__length1;
				gint _tmp6__length2;
				Location* _tmp7_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				_tmp6_ = ((Minefield*) self)->locations;
				_tmp6__length1 = ((Minefield*) self)->locations_length1;
				_tmp6__length2 = ((Minefield*) self)->locations_length2;
				_tmp7_ = _tmp6_[(i * _tmp6__length2) + 1];
				_tmp7_->has_mine = FALSE;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp8_ = FALSE;
			_tmp8_ = TRUE;
			while (TRUE) {
				gboolean _tmp10_ = FALSE;
				Location** _tmp11_;
				gint _tmp11__length1;
				gint _tmp11__length2;
				Location* _tmp12_;
				if (!_tmp8_) {
					gint _tmp9_;
					_tmp9_ = i;
					i = _tmp9_ + 1;
				}
				_tmp8_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				if (i == 0) {
					_tmp10_ = TRUE;
				} else {
					_tmp10_ = i == 3;
				}
				_tmp11_ = ((Minefield*) self)->locations;
				_tmp11__length1 = ((Minefield*) self)->locations_length1;
				_tmp11__length2 = ((Minefield*) self)->locations_length2;
				_tmp12_ = _tmp11_[(i * _tmp11__length2) + 2];
				_tmp12_->has_mine = _tmp10_;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp13_ = FALSE;
			_tmp13_ = TRUE;
			while (TRUE) {
				gboolean _tmp15_ = FALSE;
				Location** _tmp16_;
				gint _tmp16__length1;
				gint _tmp16__length2;
				Location* _tmp17_;
				if (!_tmp13_) {
					gint _tmp14_;
					_tmp14_ = i;
					i = _tmp14_ + 1;
				}
				_tmp13_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				if (i == 0) {
					_tmp15_ = TRUE;
				} else {
					_tmp15_ = i == 2;
				}
				_tmp16_ = ((Minefield*) self)->locations;
				_tmp16__length1 = ((Minefield*) self)->locations_length1;
				_tmp16__length2 = ((Minefield*) self)->locations_length2;
				_tmp17_ = _tmp16_[(i * _tmp16__length2) + 3];
				_tmp17_->has_mine = _tmp15_;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp18_ = FALSE;
			_tmp18_ = TRUE;
			while (TRUE) {
				gboolean _tmp20_ = FALSE;
				gboolean _tmp21_ = FALSE;
				Location** _tmp22_;
				gint _tmp22__length1;
				gint _tmp22__length2;
				Location* _tmp23_;
				if (!_tmp18_) {
					gint _tmp19_;
					_tmp19_ = i;
					i = _tmp19_ + 1;
				}
				_tmp18_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				if (i == 0) {
					_tmp21_ = TRUE;
				} else {
					_tmp21_ = i == 2;
				}
				if (_tmp21_) {
					_tmp20_ = TRUE;
				} else {
					_tmp20_ = i > 3;
				}
				_tmp22_ = ((Minefield*) self)->locations;
				_tmp22__length1 = ((Minefield*) self)->locations_length1;
				_tmp22__length2 = ((Minefield*) self)->locations_length2;
				_tmp23_ = _tmp22_[(i * _tmp22__length2) + 4];
				_tmp23_->has_mine = _tmp20_;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp24_ = FALSE;
			_tmp24_ = TRUE;
			while (TRUE) {
				Location** _tmp26_;
				gint _tmp26__length1;
				gint _tmp26__length2;
				Location* _tmp27_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				_tmp26_ = ((Minefield*) self)->locations;
				_tmp26__length1 = ((Minefield*) self)->locations_length1;
				_tmp26__length2 = ((Minefield*) self)->locations_length2;
				_tmp27_ = _tmp26_[(i * _tmp26__length2) + 5];
				_tmp27_->has_mine = (i % 2) == 0;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp28_ = FALSE;
			_tmp28_ = TRUE;
			while (TRUE) {
				Location** _tmp30_;
				gint _tmp30__length1;
				gint _tmp30__length2;
				Location* _tmp31_;
				if (!_tmp28_) {
					gint _tmp29_;
					_tmp29_ = i;
					i = _tmp29_ + 1;
				}
				_tmp28_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				_tmp30_ = ((Minefield*) self)->locations;
				_tmp30__length1 = ((Minefield*) self)->locations_length1;
				_tmp30__length2 = ((Minefield*) self)->locations_length2;
				_tmp31_ = _tmp30_[(i * _tmp30__length2) + 6];
				_tmp31_->has_mine = i != 1;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp32_ = FALSE;
			_tmp32_ = TRUE;
			while (TRUE) {
				if (!_tmp32_) {
					gint _tmp33_;
					_tmp33_ = i;
					i = _tmp33_ + 1;
				}
				_tmp32_ = FALSE;
				if (!(i < PREVIEW_FIELD_SIZE)) {
					break;
				}
				{
					gint j = 0;
					j = 0;
					{
						gboolean _tmp34_ = FALSE;
						_tmp34_ = TRUE;
						while (TRUE) {
							if (!_tmp34_) {
								gint _tmp35_;
								_tmp35_ = j;
								j = _tmp35_ + 1;
							}
							_tmp34_ = FALSE;
							if (!(j < PREVIEW_FIELD_SIZE)) {
								break;
							}
							{
								Neighbour* neighbour_collection = NULL;
								gint neighbour_collection_length1 = 0;
								gint _neighbour_collection_size_ = 0;
								gint neighbour_it = 0;
								neighbour_collection = PREVIEW_FIELD_neighbour_map;
								neighbour_collection_length1 = G_N_ELEMENTS (PREVIEW_FIELD_neighbour_map);
								for (neighbour_it = 0; neighbour_it < neighbour_collection_length1; neighbour_it = neighbour_it + 1) {
									Neighbour neighbour = {0};
									neighbour = neighbour_collection[neighbour_it];
									{
										gint nx = 0;
										Neighbour _tmp36_;
										gint ny = 0;
										Neighbour _tmp37_;
										gboolean _tmp38_ = FALSE;
										_tmp36_ = neighbour;
										nx = i + _tmp36_.x;
										_tmp37_ = neighbour;
										ny = j + _tmp37_.y;
										if (minefield_is_location ((Minefield*) self, nx, ny)) {
											Location** _tmp39_;
											gint _tmp39__length1;
											gint _tmp39__length2;
											Location* _tmp40_;
											_tmp39_ = ((Minefield*) self)->locations;
											_tmp39__length1 = ((Minefield*) self)->locations_length1;
											_tmp39__length2 = ((Minefield*) self)->locations_length2;
											_tmp40_ = _tmp39_[(nx * _tmp39__length2) + ny];
											_tmp38_ = _tmp40_->has_mine;
										} else {
											_tmp38_ = FALSE;
										}
										if (_tmp38_) {
											Location** _tmp41_;
											gint _tmp41__length1;
											gint _tmp41__length2;
											Location* _tmp42_;
											gint _tmp43_;
											_tmp41_ = ((Minefield*) self)->locations;
											_tmp41__length1 = ((Minefield*) self)->locations_length1;
											_tmp41__length2 = ((Minefield*) self)->locations_length2;
											_tmp42_ = _tmp41_[(i * _tmp41__length2) + j];
											_tmp43_ = _tmp42_->adjacent_mines;
											_tmp42_->adjacent_mines = _tmp43_ + 1;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

static void
preview_field_class_init (PreviewFieldClass * klass,
                          gpointer klass_data)
{
	preview_field_parent_class = g_type_class_peek_parent (klass);
}

static void
preview_field_instance_init (PreviewField * self,
                             gpointer klass)
{
}

static GType
preview_field_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PreviewFieldClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) preview_field_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PreviewField), 0, (GInstanceInitFunc) preview_field_instance_init, NULL };
	GType preview_field_type_id;
	preview_field_type_id = g_type_register_static (TYPE_MINEFIELD, "PreviewField", &g_define_type_info, 0);
	return preview_field_type_id;
}

GType
preview_field_get_type (void)
{
	static volatile gsize preview_field_type_id__once = 0;
	if (g_once_init_enter (&preview_field_type_id__once)) {
		GType preview_field_type_id;
		preview_field_type_id = preview_field_get_type_once ();
		g_once_init_leave (&preview_field_type_id__once, preview_field_type_id);
	}
	return preview_field_type_id__once;
}

static inline gpointer
theme_selector_dialog_get_instance_private (ThemeSelectorDialog* self)
{
	return G_STRUCT_MEMBER_P (self, ThemeSelectorDialog_private_offset);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

GList*
theme_selector_dialog_list_themes (ThemeSelectorDialog* self)
{
	gchar* themes_dir = NULL;
	gchar* _tmp0_;
	GList* themes = NULL;
	GFile* file = NULL;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GError* _inner_error0_ = NULL;
	GList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_build_path (G_DIR_SEPARATOR_S, DATA_DIRECTORY, "themes", NULL);
	themes_dir = _tmp0_;
	themes = NULL;
	_tmp1_ = themes_dir;
	_tmp2_ = g_file_new_for_path (_tmp1_);
	file = _tmp2_;
	{
		GFileEnumerator* enumerator = NULL;
		GFile* _tmp3_;
		GFileEnumerator* _tmp4_;
		GFileInfo* info = NULL;
		_tmp3_ = file;
		_tmp4_ = g_file_enumerate_children (_tmp3_, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &_inner_error0_);
		enumerator = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		info = NULL;
		while (TRUE) {
			GFileInfo* _tmp5_ = NULL;
			GFileEnumerator* _tmp6_;
			GFileInfo* _tmp7_;
			GFileInfo* _tmp8_;
			GFileInfo* _tmp9_;
			GFileInfo* _tmp10_;
			_tmp6_ = enumerator;
			_tmp7_ = g_file_enumerator_next_file (_tmp6_, NULL, &_inner_error0_);
			_tmp5_ = _tmp7_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (info);
				_g_object_unref0 (enumerator);
				goto __catch0_g_error;
			}
			_tmp8_ = _tmp5_;
			_tmp5_ = NULL;
			_g_object_unref0 (info);
			info = _tmp8_;
			_tmp9_ = info;
			if (!(_tmp9_ != NULL)) {
				_g_object_unref0 (_tmp5_);
				break;
			}
			_tmp10_ = info;
			if (g_file_info_get_file_type (_tmp10_) == G_FILE_TYPE_DIRECTORY) {
				GFileInfo* _tmp11_;
				const gchar* _tmp12_;
				gchar* _tmp13_;
				_tmp11_ = info;
				_tmp12_ = g_file_info_get_name (_tmp11_);
				_tmp13_ = g_strdup (_tmp12_);
				themes = g_list_append (themes, _tmp13_);
			}
			_g_object_unref0 (_tmp5_);
		}
		_g_object_unref0 (info);
		_g_object_unref0 (enumerator);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp14_ = themes_dir;
		_tmp15_ = e->message;
		g_error ("theme-selector-dialog.vala:81: Error enumerating themes from directory" \
" %s : %s\n", _tmp14_, _tmp15_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (file);
		(themes == NULL) ? NULL : (themes = (_g_list_free__g_free0_ (themes), NULL));
		_g_free0 (themes_dir);
		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;
	}
	result = themes;
	_g_object_unref0 (file);
	_g_free0 (themes_dir);
	return result;
}

static GtkWidget*
theme_selector_dialog_create_preview_widget (ThemeSelectorDialog* self,
                                             MinefieldView** view)
{
	MinefieldView* _vala_view = NULL;
	GSettings* _tmp0_;
	MinefieldView* _tmp1_;
	PreviewField* _tmp2_;
	PreviewField* _tmp3_;
	GtkBox* box = NULL;
	GtkBox* _tmp4_;
	GtkAspectFrame* frame = NULL;
	GtkAspectFrame* _tmp5_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = minefield_view_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (_vala_view);
	_vala_view = _tmp1_;
	_tmp2_ = preview_field_new ();
	_tmp3_ = _tmp2_;
	minefield_view_set_minefield (_vala_view, (Minefield*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp4_);
	box = _tmp4_;
	_tmp5_ = (GtkAspectFrame*) gtk_aspect_frame_new (0.5f, 0.5f, 1.0f, FALSE);
	g_object_ref_sink (_tmp5_);
	frame = _tmp5_;
	gtk_widget_set_margin_start ((GtkWidget*) frame, 6);
	gtk_widget_set_margin_end ((GtkWidget*) frame, 6);
	gtk_widget_set_margin_top ((GtkWidget*) frame, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) frame, 6);
	gtk_aspect_frame_set_child (frame, (GtkWidget*) _vala_view);
	theme_selector_dialog_reveal_nonmines (self, _vala_view);
	gtk_box_append (box, (GtkWidget*) frame);
	result = (GtkWidget*) box;
	_g_object_unref0 (frame);
	if (view) {
		*view = _vala_view;
	} else {
		_g_object_unref0 (_vala_view);
	}
	return result;
}

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

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		ThemeSelectorDialog* self;
		self = _data3_->self;
		(_data3_->themes == NULL) ? NULL : (_data3_->themes = (_g_list_free__g_free0_ (_data3_->themes), NULL));
		_g_object_unref0 (_data3_->window);
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static void
__lambda13_ (Block3Data* _data3_)
{
	ThemeSelectorDialog* self;
	gint _tmp0_;
	GList* _tmp1_;
	AdwApplicationWindow* _tmp2_;
	GList* _tmp3_;
	self = _data3_->self;
	_data3_->current_index = _data3_->current_index + 1;
	_tmp0_ = _data3_->current_index;
	_tmp1_ = _data3_->themes;
	_tmp2_ = _data3_->window;
	theme_selector_dialog_switch_theme_preview (self, _tmp0_, _tmp1_, _tmp2_);
	_tmp3_ = _data3_->themes;
	theme_selector_dialog_update_sensitivities (self, _tmp3_, _data3_->current_index);
}

static void
___lambda13__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda13_ (self);
}

static void
__lambda14_ (Block3Data* _data3_)
{
	ThemeSelectorDialog* self;
	gint _tmp0_;
	GList* _tmp1_;
	AdwApplicationWindow* _tmp2_;
	GList* _tmp3_;
	self = _data3_->self;
	_data3_->current_index = _data3_->current_index - 1;
	_tmp0_ = _data3_->current_index;
	_tmp1_ = _data3_->themes;
	_tmp2_ = _data3_->window;
	theme_selector_dialog_switch_theme_preview (self, _tmp0_, _tmp1_, _tmp2_);
	_tmp3_ = _data3_->themes;
	theme_selector_dialog_update_sensitivities (self, _tmp3_, _data3_->current_index);
}

static void
___lambda14__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda14_ (self);
}

ThemeSelectorDialog*
theme_selector_dialog_construct (GType object_type,
                                 AdwApplicationWindow* window)
{
	ThemeSelectorDialog * self = NULL;
	Block3Data* _data3_;
	AdwApplicationWindow* _tmp0_;
	MinefieldView* minefield = NULL;
	GtkButton* _tmp1_;
	GtkButton* _tmp2_;
	GtkButton* _tmp3_;
	GtkButton* _tmp4_;
	GtkButton* _tmp5_;
	GtkButton* _tmp6_;
	GtkBox* buttons_holder = NULL;
	GtkBox* _tmp7_;
	AdwHeaderBar* _tmp8_;
	AdwHeaderBar* _tmp9_;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp10_;
	AdwToolbarView* _tmp11_;
	GtkBuilder* _tmp12_;
	MinefieldView* _tmp13_ = NULL;
	GtkWidget* _tmp14_;
	GtkWidget* _tmp15_;
	AdwToolbarView* _tmp16_;
	AdwToolbarView* _tmp17_;
	GtkBuilder* _tmp18_;
	AdwHeaderBar* _tmp19_;
	GtkBox* _tmp20_;
	GtkButton* _tmp21_;
	GtkBox* _tmp22_;
	GtkButton* _tmp23_;
	AdwHeaderBar* _tmp24_;
	GtkBox* _tmp25_;
	GList* _tmp26_;
	gchar* current_theme = NULL;
	GSettings* _tmp27_;
	gchar* _tmp28_;
	GtkButton* _tmp37_;
	GtkButton* _tmp38_;
	GList* _tmp39_;
	g_return_val_if_fail (window != NULL, NULL);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (window);
	_g_object_unref0 (_data3_->window);
	_data3_->window = _tmp0_;
	self = (ThemeSelectorDialog*) g_object_new (object_type, NULL);
	_data3_->self = g_object_ref (self);
	adw_dialog_set_title ((AdwDialog*) self, _ ("Select Theme"));
	_tmp1_ = (GtkButton*) gtk_button_new_from_icon_name ("go-previous-symbolic");
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->previous);
	self->priv->previous = _tmp1_;
	_tmp2_ = self->priv->previous;
	gtk_widget_set_valign ((GtkWidget*) _tmp2_, GTK_ALIGN_CENTER);
	_tmp3_ = self->priv->previous;
	gtk_widget_set_halign ((GtkWidget*) _tmp3_, GTK_ALIGN_START);
	_tmp4_ = (GtkButton*) gtk_button_new_from_icon_name ("go-next-symbolic");
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->next);
	self->priv->next = _tmp4_;
	_tmp5_ = self->priv->next;
	gtk_widget_set_valign ((GtkWidget*) _tmp5_, GTK_ALIGN_CENTER);
	_tmp6_ = self->priv->next;
	gtk_widget_set_halign ((GtkWidget*) _tmp6_, GTK_ALIGN_END);
	_tmp7_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp7_);
	buttons_holder = _tmp7_;
	_tmp8_ = self->priv->headerbar;
	adw_header_bar_set_show_start_title_buttons (_tmp8_, TRUE);
	_tmp9_ = self->priv->headerbar;
	adw_header_bar_set_show_end_title_buttons (_tmp9_, TRUE);
	_tmp10_ = gtk_builder_new ();
	builder = _tmp10_;
	_tmp11_ = self->priv->toolbar;
	_tmp12_ = builder;
	_tmp14_ = theme_selector_dialog_create_preview_widget (self, &_tmp13_);
	_g_object_unref0 (minefield);
	minefield = _tmp13_;
	_tmp15_ = _tmp14_;
	G_TYPE_INSTANCE_GET_INTERFACE ((GtkBuildable*) _tmp11_, gtk_buildable_get_type (), GtkBuildableIface)->add_child ((GtkBuildable*) _tmp11_, _tmp12_, (GObject*) _tmp15_, NULL);
	_g_object_unref0 (_tmp15_);
	_tmp16_ = self->priv->toolbar;
	adw_dialog_set_child ((AdwDialog*) self, (GtkWidget*) _tmp16_);
	_tmp17_ = self->priv->toolbar;
	_tmp18_ = builder;
	_tmp19_ = self->priv->headerbar;
	G_TYPE_INSTANCE_GET_INTERFACE ((GtkBuildable*) _tmp17_, gtk_buildable_get_type (), GtkBuildableIface)->add_child ((GtkBuildable*) _tmp17_, _tmp18_, (GObject*) _tmp19_, "top");
	_tmp20_ = buttons_holder;
	_tmp21_ = self->priv->previous;
	gtk_box_append (_tmp20_, (GtkWidget*) _tmp21_);
	_tmp22_ = buttons_holder;
	_tmp23_ = self->priv->next;
	gtk_box_append (_tmp22_, (GtkWidget*) _tmp23_);
	_tmp24_ = self->priv->headerbar;
	_tmp25_ = buttons_holder;
	adw_header_bar_pack_start (_tmp24_, (GtkWidget*) _tmp25_);
	_tmp26_ = theme_selector_dialog_list_themes (self);
	_data3_->themes = _tmp26_;
	_tmp27_ = self->priv->settings;
	_tmp28_ = g_settings_get_string (_tmp27_, "theme");
	current_theme = _tmp28_;
	_data3_->current_index = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp29_ = FALSE;
			_tmp29_ = TRUE;
			while (TRUE) {
				GList* _tmp31_;
				gchar* theme = NULL;
				GList* _tmp32_;
				gconstpointer _tmp33_;
				gchar* _tmp34_;
				const gchar* _tmp35_;
				const gchar* _tmp36_;
				if (!_tmp29_) {
					gint _tmp30_;
					_tmp30_ = i;
					i = _tmp30_ + 1;
				}
				_tmp29_ = FALSE;
				_tmp31_ = _data3_->themes;
				if (!(((guint) i) < g_list_length (_tmp31_))) {
					break;
				}
				_tmp32_ = _data3_->themes;
				_tmp33_ = g_list_nth_data (_tmp32_, (guint) i);
				_tmp34_ = g_strdup ((const gchar*) _tmp33_);
				theme = _tmp34_;
				_tmp35_ = current_theme;
				_tmp36_ = theme;
				if (g_strcmp0 (_tmp35_, _tmp36_) == 0) {
					_data3_->current_index = i;
				}
				_g_free0 (theme);
			}
		}
	}
	_tmp37_ = self->priv->next;
	g_signal_connect_data (_tmp37_, "clicked", (GCallback) ___lambda13__gtk_button_clicked, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_tmp38_ = self->priv->previous;
	g_signal_connect_data (_tmp38_, "clicked", (GCallback) ___lambda14__gtk_button_clicked, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	adw_dialog_set_content_height ((AdwDialog*) self, 400);
	adw_dialog_set_content_width ((AdwDialog*) self, 400);
	_tmp39_ = _data3_->themes;
	theme_selector_dialog_update_sensitivities (self, _tmp39_, _data3_->current_index);
	_g_free0 (current_theme);
	_g_object_unref0 (builder);
	_g_object_unref0 (buttons_holder);
	_g_object_unref0 (minefield);
	block3_data_unref (_data3_);
	_data3_ = NULL;
	return self;
}

ThemeSelectorDialog*
theme_selector_dialog_new (AdwApplicationWindow* window)
{
	return theme_selector_dialog_construct (TYPE_THEME_SELECTOR_DIALOG, window);
}

static void
theme_selector_dialog_switch_theme_preview (ThemeSelectorDialog* self,
                                            gint to_index,
                                            GList* themes,
                                            AdwApplicationWindow* window)
{
	GSettings* _tmp0_;
	gconstpointer _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = g_list_nth_data (themes, (guint) to_index);
	g_settings_set_string (_tmp0_, "theme", (const gchar*) _tmp1_);
	gtk_widget_queue_draw ((GtkWidget*) self);
	adw_dialog_present ((AdwDialog*) self, (GtkWidget*) window);
}

static void
theme_selector_dialog_update_sensitivities (ThemeSelectorDialog* self,
                                            GList* themes,
                                            gint current_index)
{
	GtkButton* _tmp0_;
	GtkButton* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->next;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, ((guint) current_index) < (g_list_length (themes) - 1));
	_tmp1_ = self->priv->previous;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp1_, current_index > 0);
}

static void
theme_selector_dialog_reveal_nonmines (ThemeSelectorDialog* self,
                                       MinefieldView* view)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (view != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < 7)) {
					break;
				}
				{
					gint j = 0;
					j = 0;
					{
						gboolean _tmp2_ = FALSE;
						_tmp2_ = TRUE;
						while (TRUE) {
							Minefield* _tmp4_;
							Minefield* _tmp5_;
							if (!_tmp2_) {
								gint _tmp3_;
								_tmp3_ = j;
								j = _tmp3_ + 1;
							}
							_tmp2_ = FALSE;
							if (!(j < 6)) {
								break;
							}
							_tmp4_ = minefield_view_get_minefield (view);
							_tmp5_ = _tmp4_;
							if (!minefield_has_mine (_tmp5_, (guint) i, (guint) j)) {
								Minefield* _tmp6_;
								Minefield* _tmp7_;
								Minefield* _tmp8_;
								Minefield* _tmp9_;
								_tmp6_ = minefield_view_get_minefield (view);
								_tmp7_ = _tmp6_;
								minefield_clear_mine (_tmp7_, (guint) i, (guint) j);
								_tmp8_ = minefield_view_get_minefield (view);
								_tmp9_ = _tmp8_;
								minefield_multi_release (_tmp9_, (guint) i, (guint) j);
							} else {
								minefield_view_toggle_mark (view, (guint) i, (guint) j);
							}
						}
					}
				}
			}
		}
	}
}

static void
theme_selector_dialog_class_init (ThemeSelectorDialogClass * klass,
                                  gpointer klass_data)
{
	theme_selector_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ThemeSelectorDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = theme_selector_dialog_finalize;
}

static void
theme_selector_dialog_instance_init (ThemeSelectorDialog * self,
                                     gpointer klass)
{
	AdwToolbarView* _tmp0_;
	AdwHeaderBar* _tmp1_;
	GSettings* _tmp2_;
	self->priv = theme_selector_dialog_get_instance_private (self);
	_tmp0_ = (AdwToolbarView*) adw_toolbar_view_new ();
	g_object_ref_sink (_tmp0_);
	self->priv->toolbar = _tmp0_;
	_tmp1_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp1_);
	self->priv->headerbar = _tmp1_;
	_tmp2_ = g_settings_new ("org.gnome.Mines");
	self->priv->settings = _tmp2_;
}

static void
theme_selector_dialog_finalize (GObject * obj)
{
	ThemeSelectorDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_THEME_SELECTOR_DIALOG, ThemeSelectorDialog);
	_g_object_unref0 (self->priv->toolbar);
	_g_object_unref0 (self->priv->headerbar);
	_g_object_unref0 (self->priv->previous);
	_g_object_unref0 (self->priv->next);
	_g_object_unref0 (self->priv->settings);
	G_OBJECT_CLASS (theme_selector_dialog_parent_class)->finalize (obj);
}

static GType
theme_selector_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ThemeSelectorDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) theme_selector_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ThemeSelectorDialog), 0, (GInstanceInitFunc) theme_selector_dialog_instance_init, NULL };
	GType theme_selector_dialog_type_id;
	theme_selector_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "ThemeSelectorDialog", &g_define_type_info, 0);
	ThemeSelectorDialog_private_offset = g_type_add_instance_private (theme_selector_dialog_type_id, sizeof (ThemeSelectorDialogPrivate));
	return theme_selector_dialog_type_id;
}

GType
theme_selector_dialog_get_type (void)
{
	static volatile gsize theme_selector_dialog_type_id__once = 0;
	if (g_once_init_enter (&theme_selector_dialog_type_id__once)) {
		GType theme_selector_dialog_type_id;
		theme_selector_dialog_type_id = theme_selector_dialog_get_type_once ();
		g_once_init_leave (&theme_selector_dialog_type_id__once, theme_selector_dialog_type_id);
	}
	return theme_selector_dialog_type_id__once;
}

