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

/* Copyright 2011-2019 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 "locale-plug.h"
#include <gtk/gtk.h>
#include <granite.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>

enum  {
	SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_0_PROPERTY,
	SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_PROGRESS_PROPERTY,
	SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_NUM_PROPERTIES
};
static GParamSpec* switchboard_plug_locale_progress_dialog_properties[SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _SwitchboardPlugLocaleProgressDialogPrivate {
	GtkProgressBar* progress_bar;
};

struct _Block1Data {
	int _ref_count_;
	SwitchboardPlugLocaleProgressDialog* self;
	SwitchboardPlugLocaleInstallerUbuntuInstaller* installer;
};

static gint SwitchboardPlugLocaleProgressDialog_private_offset;
static gpointer switchboard_plug_locale_progress_dialog_parent_class = NULL;

static GObject * switchboard_plug_locale_progress_dialog_constructor (GType type,
                                                               guint n_construct_properties,
                                                               GObjectConstructParam * construct_properties);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void _switchboard_plug_locale_progress_dialog___lambda28_ (Block1Data* _data1_);
static void __switchboard_plug_locale_progress_dialog___lambda28__gtk_button_clicked (GtkButton* _sender,
                                                                               gpointer self);
static void switchboard_plug_locale_progress_dialog_finalize (GObject * obj);
static GType switchboard_plug_locale_progress_dialog_get_type_once (void);
static void _vala_switchboard_plug_locale_progress_dialog_set_property (GObject * object,
                                                                 guint property_id,
                                                                 const GValue * value,
                                                                 GParamSpec * pspec);

static inline gpointer
switchboard_plug_locale_progress_dialog_get_instance_private (SwitchboardPlugLocaleProgressDialog* self)
{
	return G_STRUCT_MEMBER_P (self, SwitchboardPlugLocaleProgressDialog_private_offset);
}

SwitchboardPlugLocaleProgressDialog*
switchboard_plug_locale_progress_dialog_construct (GType object_type)
{
	SwitchboardPlugLocaleProgressDialog * self = NULL;
	self = (SwitchboardPlugLocaleProgressDialog*) granite_dialog_construct (object_type);
	return self;
}

SwitchboardPlugLocaleProgressDialog*
switchboard_plug_locale_progress_dialog_new (void)
{
	return switchboard_plug_locale_progress_dialog_construct (SWITCHBOARD_PLUG_LOCALE_TYPE_PROGRESS_DIALOG);
}

void
switchboard_plug_locale_progress_dialog_set_progress (SwitchboardPlugLocaleProgressDialog* self,
                                                      gint value)
{
	GtkProgressBar* _tmp0_;
	g_return_if_fail (self != NULL);
	if (value >= 100) {
		gtk_widget_destroy ((GtkWidget*) self);
	}
	_tmp0_ = self->priv->progress_bar;
	gtk_progress_bar_set_fraction (_tmp0_, value / 100.0);
	g_object_notify_by_pspec ((GObject *) self, switchboard_plug_locale_progress_dialog_properties[SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_PROGRESS_PROPERTY]);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		SwitchboardPlugLocaleProgressDialog* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

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

static void
_switchboard_plug_locale_progress_dialog___lambda28_ (Block1Data* _data1_)
{
	SwitchboardPlugLocaleProgressDialog* self;
	SwitchboardPlugLocaleInstallerUbuntuInstaller* _tmp0_;
	self = _data1_->self;
	_tmp0_ = _data1_->installer;
	switchboard_plug_locale_installer_ubuntu_installer_cancel_install (_tmp0_);
	gtk_widget_destroy ((GtkWidget*) self);
}

static void
__switchboard_plug_locale_progress_dialog___lambda28__gtk_button_clicked (GtkButton* _sender,
                                                                          gpointer self)
{
	_switchboard_plug_locale_progress_dialog___lambda28_ (self);
}

static GObject *
switchboard_plug_locale_progress_dialog_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SwitchboardPlugLocaleProgressDialog * self;
	Block1Data* _data1_;
	GtkImage* image = NULL;
	GtkImage* _tmp0_;
	GtkImage* _tmp1_;
	SwitchboardPlugLocaleInstallerUbuntuInstaller* _tmp2_;
	gchar* transaction_language_name = NULL;
	SwitchboardPlugLocaleInstallerUbuntuInstaller* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	GtkLabel* primary_label = NULL;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	GtkLabel* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* _tmp11_;
	GtkStyleContext* _tmp12_;
	SwitchboardPlugLocaleInstallerUbuntuInstaller* _tmp13_;
	SwitchboardPlugLocaleInstallerUbuntuInstallerTransactionMode _tmp14_;
	SwitchboardPlugLocaleInstallerUbuntuInstallerTransactionMode _tmp15_;
	GtkProgressBar* _tmp25_;
	GtkProgressBar* _tmp26_;
	GtkProgressBar* _tmp27_;
	GtkProgressBar* _tmp28_;
	GtkButton* cancel_button = NULL;
	GtkWidget* _tmp29_;
	GtkButton* _tmp30_;
	SwitchboardPlugLocaleInstallerUbuntuInstaller* _tmp31_;
	GtkButton* _tmp32_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp33_;
	GtkGrid* _tmp34_;
	GtkGrid* _tmp35_;
	GtkGrid* _tmp36_;
	GtkGrid* _tmp37_;
	GtkImage* _tmp38_;
	GtkGrid* _tmp39_;
	GtkLabel* _tmp40_;
	GtkGrid* _tmp41_;
	GtkProgressBar* _tmp42_;
	GtkGrid* _tmp43_;
	GtkBox* _tmp44_;
	GtkGrid* _tmp45_;
	GtkButton* _tmp46_;
	parent_class = G_OBJECT_CLASS (switchboard_plug_locale_progress_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_LOCALE_TYPE_PROGRESS_DIALOG, SwitchboardPlugLocaleProgressDialog);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("preferences-desktop-locale", (GtkIconSize) GTK_ICON_SIZE_DIALOG);
	g_object_ref_sink (_tmp0_);
	image = _tmp0_;
	_tmp1_ = image;
	gtk_widget_set_valign ((GtkWidget*) _tmp1_, GTK_ALIGN_START);
	_tmp2_ = switchboard_plug_locale_installer_ubuntu_installer_get_default ();
	_data1_->installer = _tmp2_;
	_tmp3_ = _data1_->installer;
	_tmp4_ = switchboard_plug_locale_installer_ubuntu_installer_get_transaction_language_code (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = switchboard_plug_locale_utils_translate (_tmp5_, NULL);
	transaction_language_name = _tmp6_;
	_tmp7_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp7_);
	primary_label = _tmp7_;
	_tmp8_ = primary_label;
	gtk_label_set_max_width_chars (_tmp8_, 50);
	_tmp9_ = primary_label;
	g_object_set (_tmp9_, "wrap", TRUE, NULL);
	_tmp10_ = primary_label;
	gtk_label_set_xalign (_tmp10_, (gfloat) 0);
	_tmp11_ = primary_label;
	_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) _tmp11_);
	gtk_style_context_add_class (_tmp12_, GRANITE_STYLE_CLASS_PRIMARY_LABEL);
	_tmp13_ = _data1_->installer;
	_tmp14_ = switchboard_plug_locale_installer_ubuntu_installer_get_transaction_mode (_tmp13_);
	_tmp15_ = _tmp14_;
	switch (_tmp15_) {
		case SWITCHBOARD_PLUG_LOCALE_INSTALLER_UBUNTU_INSTALLER_TRANSACTION_MODE_INSTALL:
		{
			GtkLabel* _tmp16_;
			const gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			_tmp16_ = primary_label;
			_tmp17_ = transaction_language_name;
			_tmp18_ = g_strdup_printf (_ ("Installing %s"), _tmp17_);
			_tmp19_ = _tmp18_;
			gtk_label_set_label (_tmp16_, _tmp19_);
			_g_free0 (_tmp19_);
			break;
		}
		case SWITCHBOARD_PLUG_LOCALE_INSTALLER_UBUNTU_INSTALLER_TRANSACTION_MODE_REMOVE:
		{
			GtkLabel* _tmp20_;
			const gchar* _tmp21_;
			gchar* _tmp22_;
			gchar* _tmp23_;
			_tmp20_ = primary_label;
			_tmp21_ = transaction_language_name;
			_tmp22_ = g_strdup_printf (_ ("Removing %s"), _tmp21_);
			_tmp23_ = _tmp22_;
			gtk_label_set_label (_tmp20_, _tmp23_);
			_g_free0 (_tmp23_);
			break;
		}
		case SWITCHBOARD_PLUG_LOCALE_INSTALLER_UBUNTU_INSTALLER_TRANSACTION_MODE_INSTALL_MISSING:
		{
			GtkLabel* _tmp24_;
			_tmp24_ = primary_label;
			gtk_label_set_label (_tmp24_, _ ("Installing missing language"));
			break;
		}
		default:
		break;
	}
	_tmp25_ = (GtkProgressBar*) gtk_progress_bar_new ();
	g_object_ref_sink (_tmp25_);
	_g_object_unref0 (self->priv->progress_bar);
	self->priv->progress_bar = _tmp25_;
	_tmp26_ = self->priv->progress_bar;
	g_object_set ((GtkWidget*) _tmp26_, "width-request", 300, NULL);
	_tmp27_ = self->priv->progress_bar;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp27_, TRUE);
	_tmp28_ = self->priv->progress_bar;
	gtk_widget_set_valign ((GtkWidget*) _tmp28_, GTK_ALIGN_START);
	_tmp29_ = gtk_dialog_add_button ((GtkDialog*) self, _ ("Cancel"), 0);
	_tmp30_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp29_, gtk_button_get_type (), GtkButton));
	cancel_button = _tmp30_;
	_tmp31_ = _data1_->installer;
	_tmp32_ = cancel_button;
	g_object_bind_property_with_closures ((GObject*) _tmp31_, "install-cancellable", (GObject*) _tmp32_, "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)));
	_tmp33_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp33_);
	grid = _tmp33_;
	_tmp34_ = grid;
	gtk_grid_set_column_spacing (_tmp34_, 12);
	_tmp35_ = grid;
	gtk_grid_set_row_spacing (_tmp35_, 6);
	_tmp36_ = grid;
	g_object_set ((GtkWidget*) _tmp36_, "margin", 6, NULL);
	_tmp37_ = grid;
	_tmp38_ = image;
	gtk_grid_attach (_tmp37_, (GtkWidget*) _tmp38_, 0, 0, 1, 2);
	_tmp39_ = grid;
	_tmp40_ = primary_label;
	gtk_grid_attach (_tmp39_, (GtkWidget*) _tmp40_, 1, 0, 1, 1);
	_tmp41_ = grid;
	_tmp42_ = self->priv->progress_bar;
	gtk_grid_attach (_tmp41_, (GtkWidget*) _tmp42_, 1, 1, 1, 1);
	_tmp43_ = grid;
	gtk_widget_show_all ((GtkWidget*) _tmp43_);
	gtk_container_set_border_width ((GtkContainer*) self, (guint) 6);
	gtk_window_set_deletable ((GtkWindow*) self, FALSE);
	gtk_window_set_resizable ((GtkWindow*) self, FALSE);
	_tmp44_ = gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp45_ = grid;
	gtk_container_add ((GtkContainer*) _tmp44_, (GtkWidget*) _tmp45_);
	_tmp46_ = cancel_button;
	g_signal_connect_data (_tmp46_, "clicked", (GCallback) __switchboard_plug_locale_progress_dialog___lambda28__gtk_button_clicked, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_g_object_unref0 (grid);
	_g_object_unref0 (cancel_button);
	_g_object_unref0 (primary_label);
	_g_free0 (transaction_language_name);
	_g_object_unref0 (image);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return obj;
}

static void
switchboard_plug_locale_progress_dialog_class_init (SwitchboardPlugLocaleProgressDialogClass * klass,
                                                    gpointer klass_data)
{
	switchboard_plug_locale_progress_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SwitchboardPlugLocaleProgressDialog_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_switchboard_plug_locale_progress_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = switchboard_plug_locale_progress_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = switchboard_plug_locale_progress_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_PROGRESS_PROPERTY, switchboard_plug_locale_progress_dialog_properties[SWITCHBOARD_PLUG_LOCALE_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
switchboard_plug_locale_progress_dialog_instance_init (SwitchboardPlugLocaleProgressDialog * self,
                                                       gpointer klass)
{
	self->priv = switchboard_plug_locale_progress_dialog_get_instance_private (self);
}

static void
switchboard_plug_locale_progress_dialog_finalize (GObject * obj)
{
	SwitchboardPlugLocaleProgressDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_LOCALE_TYPE_PROGRESS_DIALOG, SwitchboardPlugLocaleProgressDialog);
	_g_object_unref0 (self->priv->progress_bar);
	G_OBJECT_CLASS (switchboard_plug_locale_progress_dialog_parent_class)->finalize (obj);
}

static GType
switchboard_plug_locale_progress_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SwitchboardPlugLocaleProgressDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) switchboard_plug_locale_progress_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwitchboardPlugLocaleProgressDialog), 0, (GInstanceInitFunc) switchboard_plug_locale_progress_dialog_instance_init, NULL };
	GType switchboard_plug_locale_progress_dialog_type_id;
	switchboard_plug_locale_progress_dialog_type_id = g_type_register_static (GRANITE_TYPE_DIALOG, "SwitchboardPlugLocaleProgressDialog", &g_define_type_info, 0);
	SwitchboardPlugLocaleProgressDialog_private_offset = g_type_add_instance_private (switchboard_plug_locale_progress_dialog_type_id, sizeof (SwitchboardPlugLocaleProgressDialogPrivate));
	return switchboard_plug_locale_progress_dialog_type_id;
}

GType
switchboard_plug_locale_progress_dialog_get_type (void)
{
	static volatile gsize switchboard_plug_locale_progress_dialog_type_id__once = 0;
	if (g_once_init_enter (&switchboard_plug_locale_progress_dialog_type_id__once)) {
		GType switchboard_plug_locale_progress_dialog_type_id;
		switchboard_plug_locale_progress_dialog_type_id = switchboard_plug_locale_progress_dialog_get_type_once ();
		g_once_init_leave (&switchboard_plug_locale_progress_dialog_type_id__once, switchboard_plug_locale_progress_dialog_type_id);
	}
	return switchboard_plug_locale_progress_dialog_type_id__once;
}

static void
_vala_switchboard_plug_locale_progress_dialog_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec)
{
	SwitchboardPlugLocaleProgressDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_LOCALE_TYPE_PROGRESS_DIALOG, SwitchboardPlugLocaleProgressDialog);
	switch (property_id) {
		case SWITCHBOARD_PLUG_LOCALE_PROGRESS_DIALOG_PROGRESS_PROPERTY:
		switchboard_plug_locale_progress_dialog_set_progress (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

