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

/*
* Copyright 2019–2022 elementary, Inc. (https://elementary.io)
*
* This program 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.
*
* 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <float.h>
#include <math.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_ABSTRACT_VIEW (abstract_view_get_type ())
#define ABSTRACT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ABSTRACT_VIEW, AbstractView))
#define ABSTRACT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ABSTRACT_VIEW, AbstractViewClass))
#define IS_ABSTRACT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ABSTRACT_VIEW))
#define IS_ABSTRACT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ABSTRACT_VIEW))
#define ABSTRACT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ABSTRACT_VIEW, AbstractViewClass))

typedef struct _AbstractView AbstractView;
typedef struct _AbstractViewClass AbstractViewClass;
typedef struct _AbstractViewPrivate AbstractViewPrivate;

#define SIDELOAD_TYPE_PROGRESS_VIEW (sideload_progress_view_get_type ())
#define SIDELOAD_PROGRESS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressView))
#define SIDELOAD_PROGRESS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressViewClass))
#define SIDELOAD_IS_PROGRESS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SIDELOAD_TYPE_PROGRESS_VIEW))
#define SIDELOAD_IS_PROGRESS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SIDELOAD_TYPE_PROGRESS_VIEW))
#define SIDELOAD_PROGRESS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressViewClass))

typedef struct _SideloadProgressView SideloadProgressView;
typedef struct _SideloadProgressViewClass SideloadProgressViewClass;
typedef struct _SideloadProgressViewPrivate SideloadProgressViewPrivate;
typedef enum  {
	SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_BUNDLE_INSTALL,
	SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_REF_INSTALL
} SideloadProgressViewProgressType;

#define SIDELOAD_PROGRESS_VIEW_TYPE_PROGRESS_TYPE (sideload_progress_view_progress_type_get_type ())
enum  {
	SIDELOAD_PROGRESS_VIEW_0_PROPERTY,
	SIDELOAD_PROGRESS_VIEW_APP_NAME_PROPERTY,
	SIDELOAD_PROGRESS_VIEW_PROGRESS_PROPERTY,
	SIDELOAD_PROGRESS_VIEW_STATUS_PROPERTY,
	SIDELOAD_PROGRESS_VIEW_VIEW_TYPE_PROPERTY,
	SIDELOAD_PROGRESS_VIEW_NUM_PROPERTIES
};
static GParamSpec* sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_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))

struct _AbstractView {
	GtkBox parent_instance;
	AbstractViewPrivate * priv;
	GtkBox* button_box;
	GtkGrid* content_area;
	GtkImage* badge;
	GtkLabel* primary_label;
	GtkLabel* secondary_label;
};

struct _AbstractViewClass {
	GtkBoxClass parent_class;
};

struct _SideloadProgressView {
	AbstractView parent_instance;
	SideloadProgressViewPrivate * priv;
};

struct _SideloadProgressViewClass {
	AbstractViewClass parent_class;
};

struct _SideloadProgressViewPrivate {
	GtkProgressBar* progressbar;
	SideloadProgressViewProgressType _view_type;
};

static gint SideloadProgressView_private_offset;
static gpointer sideload_progress_view_parent_class = NULL;

VALA_EXTERN GType abstract_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AbstractView, g_object_unref)
VALA_EXTERN GType sideload_progress_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SideloadProgressView, g_object_unref)
VALA_EXTERN GType sideload_progress_view_progress_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN SideloadProgressView* sideload_progress_view_new (SideloadProgressViewProgressType type);
VALA_EXTERN SideloadProgressView* sideload_progress_view_construct (GType object_type,
                                                        SideloadProgressViewProgressType type);
VALA_EXTERN void sideload_progress_view_set_app_name (SideloadProgressView* self,
                                          const gchar* value);
VALA_EXTERN void sideload_progress_view_set_progress (SideloadProgressView* self,
                                          gdouble value);
VALA_EXTERN void sideload_progress_view_set_status (SideloadProgressView* self,
                                        const gchar* value);
VALA_EXTERN SideloadProgressViewProgressType sideload_progress_view_get_view_type (SideloadProgressView* self);
static void sideload_progress_view_set_view_type (SideloadProgressView* self,
                                           SideloadProgressViewProgressType value);
static GObject * sideload_progress_view_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static gboolean _sideload_progress_view____lambda6_ (SideloadProgressView* self);
static gboolean __sideload_progress_view____lambda6__gsource_func (gpointer self);
static void sideload_progress_view_finalize (GObject * obj);
static GType sideload_progress_view_get_type_once (void);
static void _vala_sideload_progress_view_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_sideload_progress_view_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
sideload_progress_view_get_instance_private (SideloadProgressView* self)
{
	return G_STRUCT_MEMBER_P (self, SideloadProgressView_private_offset);
}

static GType
sideload_progress_view_progress_type_get_type_once (void)
{
	static const GEnumValue values[] = {{SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_BUNDLE_INSTALL, "SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_BUNDLE_INSTALL", "bundle-install"}, {SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_REF_INSTALL, "SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_REF_INSTALL", "ref-install"}, {0, NULL, NULL}};
	GType sideload_progress_view_progress_type_type_id;
	sideload_progress_view_progress_type_type_id = g_enum_register_static ("SideloadProgressViewProgressType", values);
	return sideload_progress_view_progress_type_type_id;
}

GType
sideload_progress_view_progress_type_get_type (void)
{
	static volatile gsize sideload_progress_view_progress_type_type_id__once = 0;
	if (g_once_init_enter (&sideload_progress_view_progress_type_type_id__once)) {
		GType sideload_progress_view_progress_type_type_id;
		sideload_progress_view_progress_type_type_id = sideload_progress_view_progress_type_get_type_once ();
		g_once_init_leave (&sideload_progress_view_progress_type_type_id__once, sideload_progress_view_progress_type_type_id);
	}
	return sideload_progress_view_progress_type_type_id__once;
}

SideloadProgressView*
sideload_progress_view_construct (GType object_type,
                                  SideloadProgressViewProgressType type)
{
	SideloadProgressView * self = NULL;
	self = (SideloadProgressView*) g_object_new (object_type, "view-type", type, NULL);
	return self;
}

SideloadProgressView*
sideload_progress_view_new (SideloadProgressViewProgressType type)
{
	return sideload_progress_view_construct (SIDELOAD_TYPE_PROGRESS_VIEW, type);
}

void
sideload_progress_view_set_app_name (SideloadProgressView* self,
                                     const gchar* value)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ((AbstractView*) self)->primary_label;
	_tmp1_ = g_strdup_printf (_ ("Installing “%s”"), value);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
	g_object_notify_by_pspec ((GObject *) self, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_APP_NAME_PROPERTY]);
}

void
sideload_progress_view_set_progress (SideloadProgressView* self,
                                     gdouble value)
{
	GtkProgressBar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->progressbar;
	gtk_progress_bar_set_fraction (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_PROGRESS_PROPERTY]);
}

void
sideload_progress_view_set_status (SideloadProgressView* self,
                                   const gchar* value)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ((AbstractView*) self)->secondary_label;
	_tmp1_ = g_strdup_printf ("<span font-features='tnum'>%s</span>", value);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
	g_object_notify_by_pspec ((GObject *) self, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_STATUS_PROPERTY]);
}

SideloadProgressViewProgressType
sideload_progress_view_get_view_type (SideloadProgressView* self)
{
	SideloadProgressViewProgressType result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_view_type;
	return result;
}

static void
sideload_progress_view_set_view_type (SideloadProgressView* self,
                                      SideloadProgressViewProgressType value)
{
	SideloadProgressViewProgressType old_value;
	g_return_if_fail (self != NULL);
	old_value = sideload_progress_view_get_view_type (self);
	if (old_value != value) {
		self->priv->_view_type = value;
		g_object_notify_by_pspec ((GObject *) self, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_VIEW_TYPE_PROPERTY]);
	}
}

static gboolean
_sideload_progress_view____lambda6_ (SideloadProgressView* self)
{
	GtkProgressBar* _tmp0_;
	_tmp0_ = self->priv->progressbar;
	gtk_progress_bar_pulse (_tmp0_);
}

static gboolean
__sideload_progress_view____lambda6__gsource_func (gpointer self)
{
	gboolean result;
	result = _sideload_progress_view____lambda6_ ((SideloadProgressView*) self);
	return result;
}

static GObject *
sideload_progress_view_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SideloadProgressView * self;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkProgressBar* _tmp2_ = NULL;
	SideloadProgressViewProgressType _tmp3_;
	GtkGrid* _tmp4_;
	GtkProgressBar* _tmp5_;
	GtkButton* cancel_button = NULL;
	gchar* _tmp6_;
	GtkButton* _tmp7_ = NULL;
	GtkBox* _tmp8_;
	GtkButton* _tmp9_;
	parent_class = G_OBJECT_CLASS (sideload_progress_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressView);
	_tmp0_ = ((AbstractView*) self)->secondary_label;
	gtk_label_set_use_markup (_tmp0_, TRUE);
	_tmp1_ = ((AbstractView*) self)->secondary_label;
	gtk_label_set_label (_tmp1_, _ ("Preparing…"));
	_tmp2_ = (GtkProgressBar*) gtk_progress_bar_new ();
	gtk_progress_bar_set_pulse_step (_tmp2_, 0.05);
	gtk_progress_bar_set_fraction (_tmp2_, 0.0);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp2_, TRUE);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->progressbar);
	self->priv->progressbar = _tmp2_;
	_tmp3_ = self->priv->_view_type;
	if (_tmp3_ == SIDELOAD_PROGRESS_VIEW_PROGRESS_TYPE_BUNDLE_INSTALL) {
		g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 50, __sideload_progress_view____lambda6__gsource_func, g_object_ref (self), g_object_unref);
	}
	_tmp4_ = ((AbstractView*) self)->content_area;
	_tmp5_ = self->priv->progressbar;
	gtk_grid_attach (_tmp4_, (GtkWidget*) _tmp5_, 0, 0, 1, 1);
	_tmp6_ = g_strdup ("app.quit");
	_tmp7_ = (GtkButton*) gtk_button_new_with_label (_ ("Cancel"));
	gtk_actionable_set_action_name ((GtkActionable*) _tmp7_, _tmp6_);
	_g_free0 (_tmp6_);
	g_object_ref_sink (_tmp7_);
	cancel_button = _tmp7_;
	_tmp8_ = ((AbstractView*) self)->button_box;
	_tmp9_ = cancel_button;
	gtk_box_append (_tmp8_, (GtkWidget*) _tmp9_);
	_g_object_unref0 (cancel_button);
	return obj;
}

static void
sideload_progress_view_class_init (SideloadProgressViewClass * klass,
                                   gpointer klass_data)
{
	sideload_progress_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SideloadProgressView_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_sideload_progress_view_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sideload_progress_view_set_property;
	G_OBJECT_CLASS (klass)->constructor = sideload_progress_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = sideload_progress_view_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SIDELOAD_PROGRESS_VIEW_APP_NAME_PROPERTY, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_APP_NAME_PROPERTY] = g_param_spec_string ("app-name", "app-name", "app-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SIDELOAD_PROGRESS_VIEW_PROGRESS_PROPERTY, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_PROGRESS_PROPERTY] = g_param_spec_double ("progress", "progress", "progress", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SIDELOAD_PROGRESS_VIEW_STATUS_PROPERTY, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_STATUS_PROPERTY] = g_param_spec_string ("status", "status", "status", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SIDELOAD_PROGRESS_VIEW_VIEW_TYPE_PROPERTY, sideload_progress_view_properties[SIDELOAD_PROGRESS_VIEW_VIEW_TYPE_PROPERTY] = g_param_spec_enum ("view-type", "view-type", "view-type", SIDELOAD_PROGRESS_VIEW_TYPE_PROGRESS_TYPE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
sideload_progress_view_instance_init (SideloadProgressView * self,
                                      gpointer klass)
{
	self->priv = sideload_progress_view_get_instance_private (self);
}

static void
sideload_progress_view_finalize (GObject * obj)
{
	SideloadProgressView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressView);
	_g_object_unref0 (self->priv->progressbar);
	G_OBJECT_CLASS (sideload_progress_view_parent_class)->finalize (obj);
}

static GType
sideload_progress_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SideloadProgressViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sideload_progress_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SideloadProgressView), 0, (GInstanceInitFunc) sideload_progress_view_instance_init, NULL };
	GType sideload_progress_view_type_id;
	sideload_progress_view_type_id = g_type_register_static (TYPE_ABSTRACT_VIEW, "SideloadProgressView", &g_define_type_info, 0);
	SideloadProgressView_private_offset = g_type_add_instance_private (sideload_progress_view_type_id, sizeof (SideloadProgressViewPrivate));
	return sideload_progress_view_type_id;
}

GType
sideload_progress_view_get_type (void)
{
	static volatile gsize sideload_progress_view_type_id__once = 0;
	if (g_once_init_enter (&sideload_progress_view_type_id__once)) {
		GType sideload_progress_view_type_id;
		sideload_progress_view_type_id = sideload_progress_view_get_type_once ();
		g_once_init_leave (&sideload_progress_view_type_id__once, sideload_progress_view_type_id);
	}
	return sideload_progress_view_type_id__once;
}

static void
_vala_sideload_progress_view_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	SideloadProgressView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressView);
	switch (property_id) {
		case SIDELOAD_PROGRESS_VIEW_VIEW_TYPE_PROPERTY:
		g_value_set_enum (value, sideload_progress_view_get_view_type (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_sideload_progress_view_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	SideloadProgressView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SIDELOAD_TYPE_PROGRESS_VIEW, SideloadProgressView);
	switch (property_id) {
		case SIDELOAD_PROGRESS_VIEW_APP_NAME_PROPERTY:
		sideload_progress_view_set_app_name (self, g_value_get_string (value));
		break;
		case SIDELOAD_PROGRESS_VIEW_PROGRESS_PROPERTY:
		sideload_progress_view_set_progress (self, g_value_get_double (value));
		break;
		case SIDELOAD_PROGRESS_VIEW_STATUS_PROPERTY:
		sideload_progress_view_set_status (self, g_value_get_string (value));
		break;
		case SIDELOAD_PROGRESS_VIEW_VIEW_TYPE_PROPERTY:
		sideload_progress_view_set_view_type (self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

