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

/*
* Copyright 2011-2020 elementary, Inc. (https://elementary.io)
*
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see http://www.gnu.org/licenses/.
*/

#include "keyboard.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <granite-7.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.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

enum  {
	KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_0_PROPERTY,
	KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_PROGRESS_PROPERTY,
	KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_NUM_PROPERTIES
};
static GParamSpec* keyboard_input_method_page_progress_dialog_properties[KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block8Data Block8Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _KeyboardInputMethodPageProgressDialogPrivate {
	GtkProgressBar* progress_bar;
};

struct _Block8Data {
	int _ref_count_;
	KeyboardInputMethodPageProgressDialog* self;
	KeyboardInputMethodPageUbuntuInstaller* installer;
};

static gint KeyboardInputMethodPageProgressDialog_private_offset;
static gpointer keyboard_input_method_page_progress_dialog_parent_class = NULL;

static GObject * keyboard_input_method_page_progress_dialog_constructor (GType type,
                                                                  guint n_construct_properties,
                                                                  GObjectConstructParam * construct_properties);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static void _keyboard_input_method_page_progress_dialog___lambda20_ (Block8Data* _data8_);
static void __keyboard_input_method_page_progress_dialog___lambda20__gtk_button_clicked (GtkButton* _sender,
                                                                                  gpointer self);
static void keyboard_input_method_page_progress_dialog_finalize (GObject * obj);
static GType keyboard_input_method_page_progress_dialog_get_type_once (void);
static void _vala_keyboard_input_method_page_progress_dialog_set_property (GObject * object,
                                                                    guint property_id,
                                                                    const GValue * value,
                                                                    GParamSpec * pspec);

static inline gpointer
keyboard_input_method_page_progress_dialog_get_instance_private (KeyboardInputMethodPageProgressDialog* self)
{
	return G_STRUCT_MEMBER_P (self, KeyboardInputMethodPageProgressDialog_private_offset);
}

KeyboardInputMethodPageProgressDialog*
keyboard_input_method_page_progress_dialog_construct (GType object_type)
{
	KeyboardInputMethodPageProgressDialog * self = NULL;
	self = (KeyboardInputMethodPageProgressDialog*) granite_dialog_construct (object_type);
	return self;
}

KeyboardInputMethodPageProgressDialog*
keyboard_input_method_page_progress_dialog_new (void)
{
	return keyboard_input_method_page_progress_dialog_construct (KEYBOARD_INPUT_METHOD_PAGE_TYPE_PROGRESS_DIALOG);
}

void
keyboard_input_method_page_progress_dialog_set_progress (KeyboardInputMethodPageProgressDialog* self,
                                                         gint value)
{
	GtkProgressBar* _tmp0_;
	g_return_if_fail (self != NULL);
	if (value >= 100) {
		gtk_window_destroy ((GtkWindow*) self);
	}
	_tmp0_ = self->priv->progress_bar;
	gtk_progress_bar_set_fraction (_tmp0_, value / 100.0);
	g_object_notify_by_pspec ((GObject *) self, keyboard_input_method_page_progress_dialog_properties[KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_PROGRESS_PROPERTY]);
}

static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		KeyboardInputMethodPageProgressDialog* self;
		self = _data8_->self;
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

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

static void
_keyboard_input_method_page_progress_dialog___lambda20_ (Block8Data* _data8_)
{
	KeyboardInputMethodPageProgressDialog* self;
	KeyboardInputMethodPageUbuntuInstaller* _tmp0_;
	self = _data8_->self;
	_tmp0_ = _data8_->installer;
	keyboard_input_method_page_ubuntu_installer_cancel_install (_tmp0_);
	gtk_window_destroy ((GtkWindow*) self);
}

static void
__keyboard_input_method_page_progress_dialog___lambda20__gtk_button_clicked (GtkButton* _sender,
                                                                             gpointer self)
{
	_keyboard_input_method_page_progress_dialog___lambda20_ (self);
}

static GObject *
keyboard_input_method_page_progress_dialog_constructor (GType type,
                                                        guint n_construct_properties,
                                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	KeyboardInputMethodPageProgressDialog * self;
	Block8Data* _data8_;
	GtkImage* image = NULL;
	GtkImage* _tmp0_ = NULL;
	GtkLabel* primary_label = NULL;
	GtkLabel* _tmp1_ = NULL;
	GtkLabel* _tmp2_;
	KeyboardInputMethodPageUbuntuInstaller* _tmp3_;
	KeyboardInputMethodPageUbuntuInstaller* _tmp4_;
	KeyboardInputMethodPageUbuntuInstallerTransactionMode _tmp5_;
	KeyboardInputMethodPageUbuntuInstallerTransactionMode _tmp6_;
	GtkProgressBar* _tmp19_ = NULL;
	GtkButton* cancel_button = NULL;
	GtkWidget* _tmp20_;
	GtkButton* _tmp21_;
	KeyboardInputMethodPageUbuntuInstaller* _tmp22_;
	GtkButton* _tmp23_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp24_ = NULL;
	GtkGrid* _tmp25_;
	GtkImage* _tmp26_;
	GtkGrid* _tmp27_;
	GtkLabel* _tmp28_;
	GtkGrid* _tmp29_;
	GtkProgressBar* _tmp30_;
	GtkBox* _tmp31_;
	GtkGrid* _tmp32_;
	GtkButton* _tmp33_;
	parent_class = G_OBJECT_CLASS (keyboard_input_method_page_progress_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBOARD_INPUT_METHOD_PAGE_TYPE_PROGRESS_DIALOG, KeyboardInputMethodPageProgressDialog);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = g_object_ref (self);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("preferences-desktop-locale");
	gtk_image_set_pixel_size (_tmp0_, 48);
	gtk_widget_set_valign ((GtkWidget*) _tmp0_, GTK_ALIGN_START);
	g_object_ref_sink (_tmp0_);
	image = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_label_set_max_width_chars (_tmp1_, 50);
	gtk_label_set_wrap (_tmp1_, TRUE);
	gtk_label_set_xalign (_tmp1_, (gfloat) 0);
	g_object_ref_sink (_tmp1_);
	primary_label = _tmp1_;
	_tmp2_ = primary_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp2_, GRANITE_STYLE_CLASS_TITLE_LABEL);
	_tmp3_ = keyboard_input_method_page_ubuntu_installer_get_default ();
	_data8_->installer = _tmp3_;
	_tmp4_ = _data8_->installer;
	_tmp5_ = keyboard_input_method_page_ubuntu_installer_get_transaction_mode (_tmp4_);
	_tmp6_ = _tmp5_;
	switch (_tmp6_) {
		case KEYBOARD_INPUT_METHOD_PAGE_UBUNTU_INSTALLER_TRANSACTION_MODE_INSTALL:
		{
			GtkLabel* _tmp7_;
			KeyboardInputMethodPageUbuntuInstaller* _tmp8_;
			const gchar* _tmp9_;
			const gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			_tmp7_ = primary_label;
			_tmp8_ = _data8_->installer;
			_tmp9_ = keyboard_input_method_page_ubuntu_installer_get_engine_to_address (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = g_strdup_printf (_ ("Installing %s"), _tmp10_);
			_tmp12_ = _tmp11_;
			gtk_label_set_label (_tmp7_, _tmp12_);
			_g_free0 (_tmp12_);
			break;
		}
		case KEYBOARD_INPUT_METHOD_PAGE_UBUNTU_INSTALLER_TRANSACTION_MODE_REMOVE:
		{
			GtkLabel* _tmp13_;
			KeyboardInputMethodPageUbuntuInstaller* _tmp14_;
			const gchar* _tmp15_;
			const gchar* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			_tmp13_ = primary_label;
			_tmp14_ = _data8_->installer;
			_tmp15_ = keyboard_input_method_page_ubuntu_installer_get_engine_to_address (_tmp14_);
			_tmp16_ = _tmp15_;
			_tmp17_ = g_strdup_printf (_ ("Removing %s"), _tmp16_);
			_tmp18_ = _tmp17_;
			gtk_label_set_label (_tmp13_, _tmp18_);
			_g_free0 (_tmp18_);
			break;
		}
		default:
		break;
	}
	_tmp19_ = (GtkProgressBar*) gtk_progress_bar_new ();
	gtk_widget_set_hexpand ((GtkWidget*) _tmp19_, TRUE);
	gtk_widget_set_valign ((GtkWidget*) _tmp19_, GTK_ALIGN_START);
	g_object_set ((GtkWidget*) _tmp19_, "width-request", 300, NULL);
	g_object_ref_sink (_tmp19_);
	_g_object_unref0 (self->priv->progress_bar);
	self->priv->progress_bar = _tmp19_;
	_tmp20_ = granite_dialog_add_button ((GraniteDialog*) self, _ ("Cancel"), 0);
	_tmp21_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, gtk_button_get_type (), GtkButton));
	cancel_button = _tmp21_;
	_tmp22_ = _data8_->installer;
	_tmp23_ = cancel_button;
	g_object_bind_property_with_closures ((GObject*) _tmp22_, "install-cancellable", (GObject*) _tmp23_, "sensitive", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp24_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_spacing (_tmp24_, 12);
	gtk_grid_set_row_spacing (_tmp24_, 6);
	g_object_ref_sink (_tmp24_);
	grid = _tmp24_;
	_tmp25_ = grid;
	_tmp26_ = image;
	gtk_grid_attach (_tmp25_, (GtkWidget*) _tmp26_, 0, 0, 1, 2);
	_tmp27_ = grid;
	_tmp28_ = primary_label;
	gtk_grid_attach (_tmp27_, (GtkWidget*) _tmp28_, 1, 0, 1, 1);
	_tmp29_ = grid;
	_tmp30_ = self->priv->progress_bar;
	gtk_grid_attach (_tmp29_, (GtkWidget*) _tmp30_, 1, 1, 1, 1);
	gtk_window_set_deletable ((GtkWindow*) self, FALSE);
	_tmp31_ = gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp32_ = grid;
	gtk_box_append (_tmp31_, (GtkWidget*) _tmp32_);
	_tmp33_ = cancel_button;
	g_signal_connect_data (_tmp33_, "clicked", (GCallback) __keyboard_input_method_page_progress_dialog___lambda20__gtk_button_clicked, block8_data_ref (_data8_), (GClosureNotify) block8_data_unref, 0);
	_g_object_unref0 (grid);
	_g_object_unref0 (cancel_button);
	_g_object_unref0 (primary_label);
	_g_object_unref0 (image);
	block8_data_unref (_data8_);
	_data8_ = NULL;
	return obj;
}

static void
keyboard_input_method_page_progress_dialog_class_init (KeyboardInputMethodPageProgressDialogClass * klass,
                                                       gpointer klass_data)
{
	keyboard_input_method_page_progress_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KeyboardInputMethodPageProgressDialog_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_keyboard_input_method_page_progress_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = keyboard_input_method_page_progress_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = keyboard_input_method_page_progress_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_PROGRESS_PROPERTY, keyboard_input_method_page_progress_dialog_properties[KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_PROGRESS_PROPERTY] = g_param_spec_int ("progress", "progress", "progress", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
}

static void
keyboard_input_method_page_progress_dialog_instance_init (KeyboardInputMethodPageProgressDialog * self,
                                                          gpointer klass)
{
	self->priv = keyboard_input_method_page_progress_dialog_get_instance_private (self);
}

static void
keyboard_input_method_page_progress_dialog_finalize (GObject * obj)
{
	KeyboardInputMethodPageProgressDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBOARD_INPUT_METHOD_PAGE_TYPE_PROGRESS_DIALOG, KeyboardInputMethodPageProgressDialog);
	_g_object_unref0 (self->priv->progress_bar);
	G_OBJECT_CLASS (keyboard_input_method_page_progress_dialog_parent_class)->finalize (obj);
}

static GType
keyboard_input_method_page_progress_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KeyboardInputMethodPageProgressDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) keyboard_input_method_page_progress_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KeyboardInputMethodPageProgressDialog), 0, (GInstanceInitFunc) keyboard_input_method_page_progress_dialog_instance_init, NULL };
	GType keyboard_input_method_page_progress_dialog_type_id;
	keyboard_input_method_page_progress_dialog_type_id = g_type_register_static (GRANITE_TYPE_DIALOG, "KeyboardInputMethodPageProgressDialog", &g_define_type_info, 0);
	KeyboardInputMethodPageProgressDialog_private_offset = g_type_add_instance_private (keyboard_input_method_page_progress_dialog_type_id, sizeof (KeyboardInputMethodPageProgressDialogPrivate));
	return keyboard_input_method_page_progress_dialog_type_id;
}

GType
keyboard_input_method_page_progress_dialog_get_type (void)
{
	static volatile gsize keyboard_input_method_page_progress_dialog_type_id__once = 0;
	if (g_once_init_enter (&keyboard_input_method_page_progress_dialog_type_id__once)) {
		GType keyboard_input_method_page_progress_dialog_type_id;
		keyboard_input_method_page_progress_dialog_type_id = keyboard_input_method_page_progress_dialog_get_type_once ();
		g_once_init_leave (&keyboard_input_method_page_progress_dialog_type_id__once, keyboard_input_method_page_progress_dialog_type_id);
	}
	return keyboard_input_method_page_progress_dialog_type_id__once;
}

static void
_vala_keyboard_input_method_page_progress_dialog_set_property (GObject * object,
                                                               guint property_id,
                                                               const GValue * value,
                                                               GParamSpec * pspec)
{
	KeyboardInputMethodPageProgressDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KEYBOARD_INPUT_METHOD_PAGE_TYPE_PROGRESS_DIALOG, KeyboardInputMethodPageProgressDialog);
	switch (property_id) {
		case KEYBOARD_INPUT_METHOD_PAGE_PROGRESS_DIALOG_PROGRESS_PROPERTY:
		keyboard_input_method_page_progress_dialog_set_progress (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

