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

/*
 * EstimateBox.vala
 *
 * Copyright 2012-2018 Tony George <teejeetech@gmail.com>
 *
 * 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 2 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 <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <pango/pango.h>
#include <libxapp/xapp-gtk-window.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_ESTIMATE_BOX (estimate_box_get_type ())
#define ESTIMATE_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ESTIMATE_BOX, EstimateBox))
#define ESTIMATE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ESTIMATE_BOX, EstimateBoxClass))
#define IS_ESTIMATE_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ESTIMATE_BOX))
#define IS_ESTIMATE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ESTIMATE_BOX))
#define ESTIMATE_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ESTIMATE_BOX, EstimateBoxClass))

typedef struct _EstimateBox EstimateBox;
typedef struct _EstimateBoxClass EstimateBoxClass;
typedef struct _EstimateBoxPrivate EstimateBoxPrivate;
enum  {
	ESTIMATE_BOX_0_PROPERTY,
	ESTIMATE_BOX_NUM_PROPERTIES
};
static GParamSpec* estimate_box_properties[ESTIMATE_BOX_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_MAIN (main_get_type ())
#define MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN, Main))
#define MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN, MainClass))
#define IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN))
#define IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN))
#define MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN, MainClass))

typedef struct _Main Main;
typedef struct _MainClass MainClass;
typedef void (*MainprogressCallback) (gpointer user_data);

struct _EstimateBox {
	GtkBox parent_instance;
	EstimateBoxPrivate * priv;
};

struct _EstimateBoxClass {
	GtkBoxClass parent_class;
};

struct _EstimateBoxPrivate {
	GtkProgressBar* progressbar;
	GtkWindow* parent_window;
};

static gint EstimateBox_private_offset;
static gpointer estimate_box_parent_class = NULL;
VALA_EXTERN guint64 main_first_snapshot_size;
VALA_EXTERN Main* App;

VALA_EXTERN GType estimate_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EstimateBox, g_object_unref)
VALA_EXTERN EstimateBox* estimate_box_new (GtkWindow* _parent_window);
VALA_EXTERN EstimateBox* estimate_box_construct (GType object_type,
                                     GtkWindow* _parent_window);
VALA_EXTERN void tee_jee_logging_log_debug (const gchar* message);
VALA_EXTERN GtkLabel* tee_jee_gtk_helper_add_label_header (GtkBox* box,
                                               const gchar* text,
                                               gboolean large_heading);
VALA_EXTERN GtkLabel* tee_jee_gtk_helper_add_label (GtkBox* box,
                                        const gchar* text,
                                        gboolean bold,
                                        gboolean italic,
                                        gboolean large);
VALA_EXTERN void estimate_box_estimate_system_size (EstimateBox* self);
VALA_EXTERN GType main_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Main, g_object_unref)
VALA_EXTERN guint64 main_estimate_system_size (Main* self,
                                   MainprogressCallback callback,
                                   gpointer callback_target);
static void _gtk_progress_bar_pulse_mainprogress_callback (gpointer self);
static void estimate_box_finalize (GObject * obj);
static GType estimate_box_get_type_once (void);

static inline gpointer
estimate_box_get_instance_private (EstimateBox* self)
{
	return G_STRUCT_MEMBER_P (self, EstimateBox_private_offset);
}

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

EstimateBox*
estimate_box_construct (GType object_type,
                        GtkWindow* _parent_window)
{
	EstimateBox * self = NULL;
	GtkWindow* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkBox* hbox_status = NULL;
	GtkBox* _tmp3_;
	GtkSpinner* spinner = NULL;
	GtkSpinner* _tmp4_;
	GtkLabel* lbl_msg = NULL;
	GtkLabel* _tmp5_;
	GtkProgressBar* _tmp6_;
	GtkProgressBar* _tmp7_;
	GtkProgressBar* _tmp8_;
	g_return_val_if_fail (_parent_window != NULL, NULL);
	tee_jee_logging_log_debug ("EstimateBox: EstimateBox()");
	self = (EstimateBox*) g_object_new (object_type, "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 6, NULL);
	_tmp0_ = _g_object_ref0 (_parent_window);
	_g_object_unref0 (self->priv->parent_window);
	self->priv->parent_window = _tmp0_;
	g_object_set ((GtkWidget*) self, "margin", 12, NULL);
	_tmp1_ = tee_jee_gtk_helper_add_label_header ((GtkBox*) self, _ ("Estimating System Size..."), TRUE);
	_tmp2_ = _tmp1_;
	_g_object_unref0 (_tmp2_);
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp3_);
	hbox_status = _tmp3_;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) hbox_status);
	_tmp4_ = (GtkSpinner*) gtk_spinner_new ();
	g_object_ref_sink (_tmp4_);
	spinner = _tmp4_;
	g_object_set (spinner, "active", TRUE, NULL);
	gtk_container_add ((GtkContainer*) hbox_status, (GtkWidget*) spinner);
	_tmp5_ = tee_jee_gtk_helper_add_label (hbox_status, _ ("Please wait..."), FALSE, FALSE, FALSE);
	lbl_msg = _tmp5_;
	gtk_widget_set_halign ((GtkWidget*) lbl_msg, GTK_ALIGN_START);
	gtk_label_set_ellipsize (lbl_msg, PANGO_ELLIPSIZE_END);
	gtk_label_set_max_width_chars (lbl_msg, 50);
	_tmp6_ = (GtkProgressBar*) gtk_progress_bar_new ();
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->progressbar);
	self->priv->progressbar = _tmp6_;
	_tmp7_ = self->priv->progressbar;
	gtk_progress_bar_set_pulse_step (_tmp7_, 0.01);
	_tmp8_ = self->priv->progressbar;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp8_);
	tee_jee_logging_log_debug ("EstimateBox: EstimateBox(): exit");
	_g_object_unref0 (lbl_msg);
	_g_object_unref0 (spinner);
	_g_object_unref0 (hbox_status);
	return self;
}

EstimateBox*
estimate_box_new (GtkWindow* _parent_window)
{
	return estimate_box_construct (TYPE_ESTIMATE_BOX, _parent_window);
}

static void
_gtk_progress_bar_pulse_mainprogress_callback (gpointer self)
{
	gtk_progress_bar_pulse ((GtkProgressBar*) self);
}

void
estimate_box_estimate_system_size (EstimateBox* self)
{
	GtkWindow* _tmp0_;
	GtkProgressBar* _tmp1_;
	Main* _tmp2_;
	GtkProgressBar* _tmp3_;
	GtkWindow* _tmp4_;
	g_return_if_fail (self != NULL);
	if (main_first_snapshot_size > ((guint64) 0)) {
		tee_jee_logging_log_debug ("EstimateBox: size > 0");
		return;
	}
	tee_jee_logging_log_debug ("EstimateBox: thread started");
	_tmp0_ = self->priv->parent_window;
	xapp_set_window_progress_pulse (_tmp0_, TRUE);
	_tmp1_ = self->priv->progressbar;
	gtk_progress_bar_pulse (_tmp1_);
	_tmp2_ = App;
	_tmp3_ = self->priv->progressbar;
	main_estimate_system_size (_tmp2_, _gtk_progress_bar_pulse_mainprogress_callback, _tmp3_);
	_tmp4_ = self->priv->parent_window;
	xapp_set_window_progress_pulse (_tmp4_, FALSE);
}

static void
estimate_box_class_init (EstimateBoxClass * klass,
                         gpointer klass_data)
{
	estimate_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &EstimateBox_private_offset);
	G_OBJECT_CLASS (klass)->finalize = estimate_box_finalize;
}

static void
estimate_box_instance_init (EstimateBox * self,
                            gpointer klass)
{
	self->priv = estimate_box_get_instance_private (self);
}

static void
estimate_box_finalize (GObject * obj)
{
	EstimateBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ESTIMATE_BOX, EstimateBox);
	_g_object_unref0 (self->priv->progressbar);
	_g_object_unref0 (self->priv->parent_window);
	G_OBJECT_CLASS (estimate_box_parent_class)->finalize (obj);
}

static GType
estimate_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (EstimateBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) estimate_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (EstimateBox), 0, (GInstanceInitFunc) estimate_box_instance_init, NULL };
	GType estimate_box_type_id;
	estimate_box_type_id = g_type_register_static (gtk_box_get_type (), "EstimateBox", &g_define_type_info, 0);
	EstimateBox_private_offset = g_type_add_instance_private (estimate_box_type_id, sizeof (EstimateBoxPrivate));
	return estimate_box_type_id;
}

GType
estimate_box_get_type (void)
{
	static volatile gsize estimate_box_type_id__once = 0;
	if (g_once_init_enter (&estimate_box_type_id__once)) {
		GType estimate_box_type_id;
		estimate_box_type_id = estimate_box_get_type_once ();
		g_once_init_leave (&estimate_box_type_id__once, estimate_box_type_id);
	}
	return estimate_box_type_id__once;
}

