/* print-multiple-dialog.c generated by valac 0.56.19, the Vala compiler
 * generated from print-multiple-dialog.vala, do not modify */

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Copyright © 2014 Parin Porecha
 * Copyright © 2014 Michael Catanzaro
 *
 * This file is part of GNOME Sudoku.
 *
 * GNOME Sudoku 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 Sudoku 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 Sudoku. If not, see <http://www.gnu.org/licenses/>.
 */

#include <adwaita.h>
#include <glib-object.h>
#include "libsudoku.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gee.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.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 TYPE_SUDOKU_PRINT_DIALOG (sudoku_print_dialog_get_type ())
#define SUDOKU_PRINT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUDOKU_PRINT_DIALOG, SudokuPrintDialog))
#define SUDOKU_PRINT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUDOKU_PRINT_DIALOG, SudokuPrintDialogClass))
#define IS_SUDOKU_PRINT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUDOKU_PRINT_DIALOG))
#define IS_SUDOKU_PRINT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUDOKU_PRINT_DIALOG))
#define SUDOKU_PRINT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUDOKU_PRINT_DIALOG, SudokuPrintDialogClass))

typedef struct _SudokuPrintDialog SudokuPrintDialog;
typedef struct _SudokuPrintDialogClass SudokuPrintDialogClass;
typedef struct _SudokuPrintDialogPrivate SudokuPrintDialogPrivate;

#define TYPE_SUDOKU_WINDOW (sudoku_window_get_type ())
#define SUDOKU_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUDOKU_WINDOW, SudokuWindow))
#define SUDOKU_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUDOKU_WINDOW, SudokuWindowClass))
#define IS_SUDOKU_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUDOKU_WINDOW))
#define IS_SUDOKU_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUDOKU_WINDOW))
#define SUDOKU_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUDOKU_WINDOW, SudokuWindowClass))

typedef struct _SudokuWindow SudokuWindow;
typedef struct _SudokuWindowClass SudokuWindowClass;
enum  {
	SUDOKU_PRINT_DIALOG_0_PROPERTY,
	SUDOKU_PRINT_DIALOG_NUM_PROPERTIES
};
static GParamSpec* sudoku_print_dialog_properties[SUDOKU_PRINT_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_SUDOKU (sudoku_get_type ())
#define SUDOKU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUDOKU, Sudoku))
#define SUDOKU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUDOKU, SudokuClass))
#define IS_SUDOKU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUDOKU))
#define IS_SUDOKU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUDOKU))
#define SUDOKU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUDOKU, SudokuClass))

typedef struct _Sudoku Sudoku;
typedef struct _SudokuClass SudokuClass;
typedef struct _Block5Data Block5Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define TYPE_SUDOKU_PRINTER (sudoku_printer_get_type ())
#define SUDOKU_PRINTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUDOKU_PRINTER, SudokuPrinter))
#define SUDOKU_PRINTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUDOKU_PRINTER, SudokuPrinterClass))
#define IS_SUDOKU_PRINTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUDOKU_PRINTER))
#define IS_SUDOKU_PRINTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUDOKU_PRINTER))
#define SUDOKU_PRINTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUDOKU_PRINTER, SudokuPrinterClass))

typedef struct _SudokuPrinter SudokuPrinter;
typedef struct _SudokuPrinterClass SudokuPrinterClass;

struct _SudokuPrintDialog {
	AdwDialog parent_instance;
	SudokuPrintDialogPrivate * priv;
};

struct _SudokuPrintDialogClass {
	AdwDialogClass parent_class;
};

struct _SudokuPrintDialogPrivate {
	AdwSpinRow* puzzles_row;
	AdwSpinRow* puzzles_per_page_row;
	AdwComboRow* difficulty_row;
	AdwSwitchRow* print_current_puzzle_row;
	SudokuWindow* window;
	SudokuBackend* backend;
	GtkAdjustment* per_page_adjustment;
};

struct _Block5Data {
	int _ref_count_;
	SudokuPrintDialog* self;
	gint puzzles_per_page;
	GeeArrayList* boards;
};

static gint SudokuPrintDialog_private_offset;
static gpointer sudoku_print_dialog_parent_class = NULL;
VALA_EXTERN Sudoku* sudoku_app;

VALA_EXTERN GType sudoku_print_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SudokuPrintDialog, g_object_unref)
VALA_EXTERN GType sudoku_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SudokuWindow, g_object_unref)
VALA_EXTERN SudokuPrintDialog* sudoku_print_dialog_new (SudokuBackend* backend,
                                            SudokuWindow* window);
VALA_EXTERN SudokuPrintDialog* sudoku_print_dialog_construct (GType object_type,
                                                  SudokuBackend* backend,
                                                  SudokuWindow* window);
VALA_EXTERN GType sudoku_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Sudoku, g_object_unref)
VALA_EXTERN DifficultyCategory sudoku_get_start_button_selected (Sudoku* self);
static void __lambda14_ (SudokuPrintDialog* self);
static void ___lambda14__gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                gpointer self);
VALA_EXTERN void sudoku_print_dialog_print (SudokuPrintDialog* self);
static Block5Data* block5_data_ref (Block5Data* _data5_);
static void block5_data_unref (void * _userdata_);
static void sudoku_print_dialog_send_to_printer (SudokuPrintDialog* self,
                                          GeeList* boards,
                                          gint puzzles_per_page);
static void __lambda15_ (Block5Data* _data5_,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda15__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void _sudoku_print_dialog_print_gtk_button_clicked (GtkButton* _sender,
                                                    gpointer self);
VALA_EXTERN GType sudoku_printer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SudokuPrinter, g_object_unref)
VALA_EXTERN SudokuPrinter* sudoku_printer_new (GeeList* boards,
                                   gint sudokus_per_page);
VALA_EXTERN SudokuPrinter* sudoku_printer_construct (GType object_type,
                                         GeeList* boards,
                                         gint sudokus_per_page);
VALA_EXTERN GtkPrintOperationResult sudoku_printer_print_sudoku (SudokuPrinter* self,
                                                     GtkWindow* window);
static void sudoku_print_dialog_finalize (GObject * obj);
static GType sudoku_print_dialog_get_type_once (void);

static inline gpointer
sudoku_print_dialog_get_instance_private (SudokuPrintDialog* self)
{
	return G_STRUCT_MEMBER_P (self, SudokuPrintDialog_private_offset);
}

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

static void
__lambda14_ (SudokuPrintDialog* self)
{
	gdouble per_page = 0.0;
	GtkAdjustment* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	AdwSpinRow* _tmp3_;
	GtkAdjustment* _tmp4_;
	GtkAdjustment* _tmp5_;
	AdwSpinRow* _tmp6_;
	GtkAdjustment* _tmp7_;
	GtkAdjustment* _tmp8_;
	AdwSpinRow* _tmp9_;
	GtkAdjustment* _tmp10_;
	GtkAdjustment* _tmp11_;
	AdwSpinRow* _tmp12_;
	GtkAdjustment* _tmp13_;
	GtkAdjustment* _tmp14_;
	gdouble _tmp15_;
	gdouble _tmp16_;
	_tmp0_ = self->priv->per_page_adjustment;
	_tmp1_ = gtk_adjustment_get_value (_tmp0_);
	_tmp2_ = _tmp1_;
	per_page = _tmp2_;
	_tmp3_ = self->priv->puzzles_row;
	_tmp4_ = adw_spin_row_get_adjustment (_tmp3_);
	_tmp5_ = _tmp4_;
	gtk_adjustment_set_step_increment (_tmp5_, per_page);
	_tmp6_ = self->priv->puzzles_row;
	_tmp7_ = adw_spin_row_get_adjustment (_tmp6_);
	_tmp8_ = _tmp7_;
	gtk_adjustment_set_page_increment (_tmp8_, per_page * 5);
	_tmp9_ = self->priv->puzzles_row;
	_tmp10_ = adw_spin_row_get_adjustment (_tmp9_);
	_tmp11_ = _tmp10_;
	gtk_adjustment_set_lower (_tmp11_, per_page);
	_tmp12_ = self->priv->puzzles_row;
	_tmp13_ = adw_spin_row_get_adjustment (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = gtk_adjustment_get_value (_tmp14_);
	_tmp16_ = _tmp15_;
	if (fmod (_tmp16_, per_page) != ((gdouble) 0)) {
		AdwSpinRow* _tmp17_;
		GtkAdjustment* _tmp18_;
		GtkAdjustment* _tmp19_;
		AdwSpinRow* _tmp20_;
		GtkAdjustment* _tmp21_;
		GtkAdjustment* _tmp22_;
		gdouble _tmp23_;
		gdouble _tmp24_;
		AdwSpinRow* _tmp25_;
		GtkAdjustment* _tmp26_;
		GtkAdjustment* _tmp27_;
		gdouble _tmp28_;
		gdouble _tmp29_;
		_tmp17_ = self->priv->puzzles_row;
		_tmp18_ = adw_spin_row_get_adjustment (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = self->priv->puzzles_row;
		_tmp21_ = adw_spin_row_get_adjustment (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = gtk_adjustment_get_value (_tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = self->priv->puzzles_row;
		_tmp26_ = adw_spin_row_get_adjustment (_tmp25_);
		_tmp27_ = _tmp26_;
		_tmp28_ = gtk_adjustment_get_value (_tmp27_);
		_tmp29_ = _tmp28_;
		gtk_adjustment_set_value (_tmp22_, _tmp24_ + (per_page - fmod (_tmp29_, per_page)));
	}
}

static void
___lambda14__gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                           gpointer self)
{
	__lambda14_ ((SudokuPrintDialog*) self);
}

SudokuPrintDialog*
sudoku_print_dialog_construct (GType object_type,
                               SudokuBackend* backend,
                               SudokuWindow* window)
{
	SudokuPrintDialog * self = NULL;
	SudokuWindow* _tmp0_;
	SudokuBackend* _tmp1_;
	Sudoku* _tmp2_;
	DifficultyCategory _tmp3_;
	DifficultyCategory _tmp4_;
	AdwSwitchRow* _tmp9_;
	SudokuGame* _tmp10_;
	SudokuGame* _tmp11_;
	AdwSpinRow* _tmp12_;
	GtkAdjustment* _tmp13_;
	GtkAdjustment* _tmp14_;
	GtkAdjustment* _tmp15_;
	g_return_val_if_fail (backend != NULL, NULL);
	g_return_val_if_fail (window != NULL, NULL);
	self = (SudokuPrintDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (window);
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp0_;
	_tmp1_ = _g_object_ref0 (backend);
	_g_object_unref0 (self->priv->backend);
	self->priv->backend = _tmp1_;
	_tmp2_ = sudoku_app;
	_tmp3_ = sudoku_get_start_button_selected (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ != DIFFICULTY_CATEGORY_CUSTOM) {
		AdwComboRow* _tmp5_;
		Sudoku* _tmp6_;
		DifficultyCategory _tmp7_;
		DifficultyCategory _tmp8_;
		_tmp5_ = self->priv->difficulty_row;
		_tmp6_ = sudoku_app;
		_tmp7_ = sudoku_get_start_button_selected (_tmp6_);
		_tmp8_ = _tmp7_;
		adw_combo_row_set_selected (_tmp5_, (guint) (((gint) _tmp8_) - 1));
	}
	_tmp9_ = self->priv->print_current_puzzle_row;
	_tmp10_ = sudoku_backend_get_game (backend);
	_tmp11_ = _tmp10_;
	gtk_widget_set_visible ((GtkWidget*) _tmp9_, _tmp11_ != NULL);
	_tmp12_ = self->priv->puzzles_per_page_row;
	_tmp13_ = adw_spin_row_get_adjustment (_tmp12_);
	_tmp14_ = _g_object_ref0 (_tmp13_);
	_g_object_unref0 (self->priv->per_page_adjustment);
	self->priv->per_page_adjustment = _tmp14_;
	_tmp15_ = self->priv->per_page_adjustment;
	g_signal_connect_object (_tmp15_, "value-changed", (GCallback) ___lambda14__gtk_adjustment_value_changed, self, 0);
	return self;
}

SudokuPrintDialog*
sudoku_print_dialog_new (SudokuBackend* backend,
                         SudokuWindow* window)
{
	return sudoku_print_dialog_construct (TYPE_SUDOKU_PRINT_DIALOG, backend, window);
}

static Block5Data*
block5_data_ref (Block5Data* _data5_)
{
	g_atomic_int_inc (&_data5_->_ref_count_);
	return _data5_;
}

static void
block5_data_unref (void * _userdata_)
{
	Block5Data* _data5_;
	_data5_ = (Block5Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
		SudokuPrintDialog* self;
		self = _data5_->self;
		_g_object_unref0 (_data5_->boards);
		_g_object_unref0 (self);
		g_slice_free (Block5Data, _data5_);
	}
}

static void
__lambda15_ (Block5Data* _data5_,
             GObject* obj,
             GAsyncResult* res)
{
	SudokuPrintDialog* self;
	GError* _inner_error0_ = NULL;
	self = _data5_->self;
	g_return_if_fail (res != NULL);
	{
		GeeList* _tmp0_ = NULL;
		GeeList* _tmp1_;
		GeeArrayList* _tmp2_;
		GeeArrayList* _tmp3_;
		_tmp1_ = sudoku_generator_generate_boards_finish (res, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_THREAD_ERROR) {
				goto __catch0_g_thread_error;
			}
			if (_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_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;
		}
		_tmp2_ = _data5_->boards;
		gee_array_list_add_all (_tmp2_, (GeeCollection*) _tmp0_);
		_tmp3_ = _data5_->boards;
		sudoku_print_dialog_send_to_printer (self, (GeeList*) _tmp3_, _data5_->puzzles_per_page);
		_g_object_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_thread_error:
	{
		GError* e = NULL;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = e->message;
		g_error ("print-multiple-dialog.vala:84: Thread error: %s\n", _tmp4_);
		_g_error_free0 (e);
	}
	goto __finally0;
	__catch0_g_io_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = e;
		if (!g_error_matches (_tmp5_, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			GError* _tmp6_;
			const gchar* _tmp7_;
			_tmp6_ = e;
			_tmp7_ = _tmp6_->message;
			g_warning ("print-multiple-dialog.vala:89: Error: %s\n", _tmp7_);
		}
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
	adw_dialog_close ((AdwDialog*) self);
}

static void
___lambda15__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda15_ (self, source_object, res);
	block5_data_unref (self);
}

void
sudoku_print_dialog_print (SudokuPrintDialog* self)
{
	Block5Data* _data5_;
	gint puzzles_to_generate = 0;
	AdwSpinRow* _tmp0_;
	GtkAdjustment* _tmp1_;
	AdwSpinRow* _tmp2_;
	GtkAdjustment* _tmp3_;
	DifficultyCategory diff_cat = 0;
	AdwComboRow* _tmp4_;
	GeeArrayList* _tmp5_;
	gboolean _tmp6_ = FALSE;
	SudokuBackend* _tmp7_;
	SudokuGame* _tmp8_;
	SudokuGame* _tmp9_;
	g_return_if_fail (self != NULL);
	_data5_ = g_slice_new0 (Block5Data);
	_data5_->_ref_count_ = 1;
	_data5_->self = g_object_ref (self);
	_tmp0_ = self->priv->puzzles_row;
	_tmp1_ = adw_spin_row_get_adjustment (_tmp0_);
	puzzles_to_generate = (gint) gtk_adjustment_get_value (_tmp1_);
	_tmp2_ = self->priv->puzzles_per_page_row;
	_tmp3_ = adw_spin_row_get_adjustment (_tmp2_);
	_data5_->puzzles_per_page = (gint) gtk_adjustment_get_value (_tmp3_);
	_tmp4_ = self->priv->difficulty_row;
	diff_cat = ((DifficultyCategory) adw_combo_row_get_selected (_tmp4_)) + 1;
	_tmp5_ = gee_array_list_new (TYPE_SUDOKU_BOARD, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data5_->boards = _tmp5_;
	_tmp7_ = self->priv->backend;
	_tmp8_ = sudoku_backend_get_game (_tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ != NULL) {
		AdwSwitchRow* _tmp10_;
		gboolean _tmp11_;
		gboolean _tmp12_;
		_tmp10_ = self->priv->print_current_puzzle_row;
		_tmp11_ = adw_switch_row_get_active (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp6_ = _tmp12_;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		GeeArrayList* _tmp13_;
		SudokuBackend* _tmp14_;
		SudokuGame* _tmp15_;
		SudokuGame* _tmp16_;
		SudokuBoard* _tmp17_;
		SudokuBoard* _tmp18_;
		gint _tmp19_;
		_tmp13_ = _data5_->boards;
		_tmp14_ = self->priv->backend;
		_tmp15_ = sudoku_backend_get_game (_tmp14_);
		_tmp16_ = _tmp15_;
		_tmp17_ = sudoku_game_get_board (_tmp16_);
		_tmp18_ = _tmp17_;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp13_, _tmp18_);
		_tmp19_ = puzzles_to_generate;
		puzzles_to_generate = _tmp19_ - 1;
		if (puzzles_to_generate == 0) {
			GeeArrayList* _tmp20_;
			_tmp20_ = _data5_->boards;
			sudoku_print_dialog_send_to_printer (self, (GeeList*) _tmp20_, _data5_->puzzles_per_page);
			block5_data_unref (_data5_);
			_data5_ = NULL;
			return;
		}
	}
	sudoku_generator_generate_boards_async (puzzles_to_generate, diff_cat, NULL, ___lambda15__gasync_ready_callback, block5_data_ref (_data5_));
	block5_data_unref (_data5_);
	_data5_ = NULL;
}

static void
_sudoku_print_dialog_print_gtk_button_clicked (GtkButton* _sender,
                                               gpointer self)
{
	sudoku_print_dialog_print ((SudokuPrintDialog*) self);
}

static void
sudoku_print_dialog_send_to_printer (SudokuPrintDialog* self,
                                     GeeList* boards,
                                     gint puzzles_per_page)
{
	SudokuPrinter* printer = NULL;
	SudokuPrinter* _tmp0_;
	SudokuPrinter* _tmp1_;
	SudokuWindow* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (boards != NULL);
	_tmp0_ = sudoku_printer_new (boards, puzzles_per_page);
	printer = _tmp0_;
	_tmp1_ = printer;
	_tmp2_ = self->priv->window;
	if (sudoku_printer_print_sudoku (_tmp1_, (GtkWindow*) _tmp2_) == GTK_PRINT_OPERATION_RESULT_APPLY) {
		{
			GeeList* _board_list = NULL;
			gint _board_size = 0;
			GeeList* _tmp3_;
			gint _tmp4_;
			gint _tmp5_;
			gint _board_index = 0;
			_board_list = boards;
			_tmp3_ = _board_list;
			_tmp4_ = gee_collection_get_size ((GeeCollection*) _tmp3_);
			_tmp5_ = _tmp4_;
			_board_size = _tmp5_;
			_board_index = -1;
			while (TRUE) {
				gint _tmp6_;
				gint _tmp7_;
				SudokuBoard* board = NULL;
				GeeList* _tmp8_;
				gpointer _tmp9_;
				SudokuBackend* _tmp10_;
				SudokuBoard* _tmp11_;
				_board_index = _board_index + 1;
				_tmp6_ = _board_index;
				_tmp7_ = _board_size;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = _board_list;
				_tmp9_ = gee_list_get (_tmp8_, _board_index);
				board = (SudokuBoard*) _tmp9_;
				_tmp10_ = self->priv->backend;
				_tmp11_ = board;
				sudoku_backend_add_board_to_printed (_tmp10_, _tmp11_);
				_g_object_unref0 (board);
			}
		}
	}
	_g_object_unref0 (printer);
}

static void
sudoku_print_dialog_class_init (SudokuPrintDialogClass * klass,
                                gpointer klass_data)
{
	sudoku_print_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SudokuPrintDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = sudoku_print_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Sudoku/ui/print-multiple-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "puzzles_row", FALSE, SudokuPrintDialog_private_offset + G_STRUCT_OFFSET (SudokuPrintDialogPrivate, puzzles_row));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "puzzles_per_page_row", FALSE, SudokuPrintDialog_private_offset + G_STRUCT_OFFSET (SudokuPrintDialogPrivate, puzzles_per_page_row));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "difficulty_row", FALSE, SudokuPrintDialog_private_offset + G_STRUCT_OFFSET (SudokuPrintDialogPrivate, difficulty_row));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "print_current_puzzle_row", FALSE, SudokuPrintDialog_private_offset + G_STRUCT_OFFSET (SudokuPrintDialogPrivate, print_current_puzzle_row));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "print", G_CALLBACK(_sudoku_print_dialog_print_gtk_button_clicked));
}

static void
sudoku_print_dialog_instance_init (SudokuPrintDialog * self,
                                   gpointer klass)
{
	self->priv = sudoku_print_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
sudoku_print_dialog_finalize (GObject * obj)
{
	SudokuPrintDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SUDOKU_PRINT_DIALOG, SudokuPrintDialog);
	_g_object_unref0 (self->priv->window);
	_g_object_unref0 (self->priv->backend);
	_g_object_unref0 (self->priv->per_page_adjustment);
	G_OBJECT_CLASS (sudoku_print_dialog_parent_class)->finalize (obj);
}

static GType
sudoku_print_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SudokuPrintDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sudoku_print_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SudokuPrintDialog), 0, (GInstanceInitFunc) sudoku_print_dialog_instance_init, NULL };
	GType sudoku_print_dialog_type_id;
	sudoku_print_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "SudokuPrintDialog", &g_define_type_info, 0);
	SudokuPrintDialog_private_offset = g_type_add_instance_private (sudoku_print_dialog_type_id, sizeof (SudokuPrintDialogPrivate));
	return sudoku_print_dialog_type_id;
}

GType
sudoku_print_dialog_get_type (void)
{
	static volatile gsize sudoku_print_dialog_type_id__once = 0;
	if (g_once_init_enter (&sudoku_print_dialog_type_id__once)) {
		GType sudoku_print_dialog_type_id;
		sudoku_print_dialog_type_id = sudoku_print_dialog_get_type_once ();
		g_once_init_leave (&sudoku_print_dialog_type_id__once, sudoku_print_dialog_type_id);
	}
	return sudoku_print_dialog_type_id__once;
}

