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

/*
* Copyright (c) 2017 Robert San <robertsanseries@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 <float.h>
#include <math.h>
#include <pango/pango.h>
#include <glib/gi18n-lib.h>

#define CIANO_CONFIGS_PROPERTIES_TEXT_STARTING _ ("Starting...")
#define CIANO_CONFIGS_PROPERTIES_TEXT_CANCEL _ ("Cancel")
#define CIANO_CONFIGS_PROPERTIES_TEXT_CANCEL_CONVERSION _ ("Cancel conversion")
#define CIANO_CONFIGS_PROPERTIES_TEXT_REMOVE _ ("Remove")
#define CIANO_CONFIGS_PROPERTIES_TEXT_REMOVE_ITEM_FROM_LIST _ ("Remove item from list")
#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 CIANO_WIDGETS_TYPE_ROW_CONVERSION (ciano_widgets_row_conversion_get_type ())
#define CIANO_WIDGETS_ROW_CONVERSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CIANO_WIDGETS_TYPE_ROW_CONVERSION, CianoWidgetsRowConversion))
#define CIANO_WIDGETS_ROW_CONVERSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CIANO_WIDGETS_TYPE_ROW_CONVERSION, CianoWidgetsRowConversionClass))
#define CIANO_WIDGETS_IS_ROW_CONVERSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CIANO_WIDGETS_TYPE_ROW_CONVERSION))
#define CIANO_WIDGETS_IS_ROW_CONVERSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CIANO_WIDGETS_TYPE_ROW_CONVERSION))
#define CIANO_WIDGETS_ROW_CONVERSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CIANO_WIDGETS_TYPE_ROW_CONVERSION, CianoWidgetsRowConversionClass))

typedef struct _CianoWidgetsRowConversion CianoWidgetsRowConversion;
typedef struct _CianoWidgetsRowConversionClass CianoWidgetsRowConversionClass;
typedef struct _CianoWidgetsRowConversionPrivate CianoWidgetsRowConversionPrivate;
enum  {
	CIANO_WIDGETS_ROW_CONVERSION_0_PROPERTY,
	CIANO_WIDGETS_ROW_CONVERSION_NUM_PROPERTIES
};
static GParamSpec* ciano_widgets_row_conversion_properties[CIANO_WIDGETS_ROW_CONVERSION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _CianoWidgetsRowConversion {
	GtkListBoxRow parent_instance;
	CianoWidgetsRowConversionPrivate * priv;
	gint row_id;
	GtkProgressBar* progress_bar;
	GtkLabel* name_video;
	GtkLabel* value_progress;
	GtkLabel* status;
	GtkButton* button_cancel;
	GtkButton* button_remove;
	GtkLabel* convert_to;
};

struct _CianoWidgetsRowConversionClass {
	GtkListBoxRowClass parent_class;
};

struct _CianoWidgetsRowConversionPrivate {
	GtkBox* container;
	GtkBox* box_name_progress;
};

static gint CianoWidgetsRowConversion_private_offset;
static gpointer ciano_widgets_row_conversion_parent_class = NULL;

VALA_EXTERN GType ciano_widgets_row_conversion_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CianoWidgetsRowConversion, g_object_unref)
VALA_EXTERN CianoWidgetsRowConversion* ciano_widgets_row_conversion_new (const gchar* icon,
                                                             const gchar* name,
                                                             gdouble progress,
                                                             const gchar* name_format);
VALA_EXTERN CianoWidgetsRowConversion* ciano_widgets_row_conversion_construct (GType object_type,
                                                                   const gchar* icon,
                                                                   const gchar* name,
                                                                   gdouble progress,
                                                                   const gchar* name_format);
static void ciano_widgets_row_conversion_finalize (GObject * obj);
static GType ciano_widgets_row_conversion_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ciano_widgets_row_conversion_get_instance_private (CianoWidgetsRowConversion* self)
{
	return G_STRUCT_MEMBER_P (self, CianoWidgetsRowConversion_private_offset);
}

/**
         * Constructs a new {@code RowConversion} object that will display the status of each 
         * item during conversion.
         *
         * @see Ciano.Utils.StringUtil
         * @see Ciano.Configs.Properties
         * @param {@code string} icon
         * @param {@code string} name
         * @param {@code double} progress
         * @param {@code string} name_format
         */
CianoWidgetsRowConversion*
ciano_widgets_row_conversion_construct (GType object_type,
                                        const gchar* icon,
                                        const gchar* name,
                                        gdouble progress,
                                        const gchar* name_format)
{
	CianoWidgetsRowConversion * self = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkImage* icone = NULL;
	GtkImage* _tmp2_;
	GtkBox* _tmp3_;
	GtkLabel* _tmp4_;
	GtkLabel* _tmp5_;
	GtkLabel* _tmp6_;
	GtkProgressBar* _tmp7_;
	GtkProgressBar* _tmp8_;
	GtkStyleContext* _tmp9_;
	GtkProgressBar* _tmp10_;
	GtkLabel* _tmp11_;
	GtkLabel* _tmp12_;
	GtkLabel* _tmp13_;
	GtkLabel* _tmp14_;
	GtkLabel* _tmp15_;
	GtkButton* _tmp16_;
	GtkButton* _tmp17_;
	GtkStyleContext* _tmp18_;
	GtkButton* _tmp19_;
	GtkButton* _tmp20_;
	GtkButton* _tmp21_;
	GtkButton* _tmp22_;
	GtkButton* _tmp23_;
	GtkButton* _tmp24_;
	GtkButton* _tmp25_;
	GtkBox* _tmp26_;
	GtkLabel* _tmp27_;
	GtkBox* _tmp28_;
	GtkProgressBar* _tmp29_;
	GtkBox* _tmp30_;
	GtkLabel* _tmp31_;
	GtkBox* _tmp32_;
	GtkBox* _tmp33_;
	GtkBox* _tmp34_;
	GtkBox* _tmp35_;
	GtkLabel* _tmp36_;
	GtkBox* _tmp37_;
	GtkButton* _tmp38_;
	GtkBox* _tmp39_;
	GtkButton* _tmp40_;
	GtkBox* _tmp41_;
	g_return_val_if_fail (icon != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (name_format != NULL, NULL);
	self = (CianoWidgetsRowConversion*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->container);
	self->priv->container = _tmp0_;
	_tmp1_ = self->priv->container;
	g_object_set ((GtkWidget*) _tmp1_, "margin", 3, NULL);
	_tmp2_ = (GtkImage*) gtk_image_new_from_icon_name (icon, (GtkIconSize) GTK_ICON_SIZE_DIALOG);
	g_object_ref_sink (_tmp2_);
	icone = _tmp2_;
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->box_name_progress);
	self->priv->box_name_progress = _tmp3_;
	_tmp4_ = (GtkLabel*) gtk_label_new (name);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->name_video);
	self->name_video = _tmp4_;
	_tmp5_ = self->name_video;
	gtk_label_set_ellipsize (_tmp5_, PANGO_ELLIPSIZE_MIDDLE);
	_tmp6_ = self->name_video;
	gtk_widget_set_halign ((GtkWidget*) _tmp6_, GTK_ALIGN_START);
	_tmp7_ = (GtkProgressBar*) gtk_progress_bar_new ();
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->progress_bar);
	self->progress_bar = _tmp7_;
	_tmp8_ = self->progress_bar;
	_tmp9_ = gtk_widget_get_style_context ((GtkWidget*) _tmp8_);
	gtk_style_context_add_class (_tmp9_, "progress_bar");
	_tmp10_ = self->progress_bar;
	gtk_progress_bar_set_fraction (_tmp10_, progress);
	_tmp11_ = (GtkLabel*) gtk_label_new (name_format);
	g_object_ref_sink (_tmp11_);
	_g_object_unref0 (self->convert_to);
	self->convert_to = _tmp11_;
	_tmp12_ = self->convert_to;
	gtk_label_set_use_markup (_tmp12_, TRUE);
	_tmp13_ = (GtkLabel*) gtk_label_new (CIANO_CONFIGS_PROPERTIES_TEXT_STARTING);
	g_object_ref_sink (_tmp13_);
	_g_object_unref0 (self->status);
	self->status = _tmp13_;
	_tmp14_ = self->status;
	gtk_label_set_ellipsize (_tmp14_, PANGO_ELLIPSIZE_END);
	_tmp15_ = self->status;
	gtk_widget_set_halign ((GtkWidget*) _tmp15_, GTK_ALIGN_START);
	_tmp16_ = (GtkButton*) gtk_button_new_with_label (CIANO_CONFIGS_PROPERTIES_TEXT_CANCEL);
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->button_cancel);
	self->button_cancel = _tmp16_;
	_tmp17_ = self->button_cancel;
	_tmp18_ = gtk_widget_get_style_context ((GtkWidget*) _tmp17_);
	gtk_style_context_add_class (_tmp18_, GTK_STYLE_CLASS_DESTRUCTIVE_ACTION);
	_tmp19_ = self->button_cancel;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp19_, CIANO_CONFIGS_PROPERTIES_TEXT_CANCEL_CONVERSION);
	_tmp20_ = self->button_cancel;
	gtk_widget_set_valign ((GtkWidget*) _tmp20_, GTK_ALIGN_CENTER);
	_tmp21_ = self->button_cancel;
	gtk_widget_set_halign ((GtkWidget*) _tmp21_, GTK_ALIGN_CENTER);
	_tmp22_ = (GtkButton*) gtk_button_new_with_label (CIANO_CONFIGS_PROPERTIES_TEXT_REMOVE);
	g_object_ref_sink (_tmp22_);
	_g_object_unref0 (self->button_remove);
	self->button_remove = _tmp22_;
	_tmp23_ = self->button_remove;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp23_, CIANO_CONFIGS_PROPERTIES_TEXT_REMOVE_ITEM_FROM_LIST);
	_tmp24_ = self->button_remove;
	gtk_widget_set_valign ((GtkWidget*) _tmp24_, GTK_ALIGN_CENTER);
	_tmp25_ = self->button_remove;
	gtk_widget_set_halign ((GtkWidget*) _tmp25_, GTK_ALIGN_CENTER);
	_tmp26_ = self->priv->box_name_progress;
	_tmp27_ = self->name_video;
	gtk_box_pack_start (_tmp26_, (GtkWidget*) _tmp27_, TRUE, TRUE, (guint) 0);
	_tmp28_ = self->priv->box_name_progress;
	_tmp29_ = self->progress_bar;
	gtk_box_pack_start (_tmp28_, (GtkWidget*) _tmp29_, TRUE, TRUE, (guint) 0);
	_tmp30_ = self->priv->box_name_progress;
	_tmp31_ = self->status;
	gtk_box_pack_start (_tmp30_, (GtkWidget*) _tmp31_, TRUE, TRUE, (guint) 0);
	_tmp32_ = self->priv->container;
	gtk_box_pack_start (_tmp32_, (GtkWidget*) icone, FALSE, FALSE, (guint) 5);
	_tmp33_ = self->priv->container;
	_tmp34_ = self->priv->box_name_progress;
	gtk_box_pack_start (_tmp33_, (GtkWidget*) _tmp34_, TRUE, TRUE, (guint) 5);
	_tmp35_ = self->priv->container;
	_tmp36_ = self->convert_to;
	gtk_box_pack_start (_tmp35_, (GtkWidget*) _tmp36_, FALSE, FALSE, (guint) 2);
	_tmp37_ = self->priv->container;
	_tmp38_ = self->button_cancel;
	gtk_box_pack_start (_tmp37_, (GtkWidget*) _tmp38_, FALSE, FALSE, (guint) 8);
	_tmp39_ = self->priv->container;
	_tmp40_ = self->button_remove;
	gtk_box_pack_start (_tmp39_, (GtkWidget*) _tmp40_, FALSE, FALSE, (guint) 8);
	gtk_list_box_row_set_selectable ((GtkListBoxRow*) self, FALSE);
	gtk_list_box_row_set_activatable ((GtkListBoxRow*) self, FALSE);
	_tmp41_ = self->priv->container;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp41_);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (icone);
	return self;
}

CianoWidgetsRowConversion*
ciano_widgets_row_conversion_new (const gchar* icon,
                                  const gchar* name,
                                  gdouble progress,
                                  const gchar* name_format)
{
	return ciano_widgets_row_conversion_construct (CIANO_WIDGETS_TYPE_ROW_CONVERSION, icon, name, progress, name_format);
}

static void
ciano_widgets_row_conversion_class_init (CianoWidgetsRowConversionClass * klass,
                                         gpointer klass_data)
{
	ciano_widgets_row_conversion_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &CianoWidgetsRowConversion_private_offset);
	G_OBJECT_CLASS (klass)->finalize = ciano_widgets_row_conversion_finalize;
}

static void
ciano_widgets_row_conversion_instance_init (CianoWidgetsRowConversion * self,
                                            gpointer klass)
{
	self->priv = ciano_widgets_row_conversion_get_instance_private (self);
}

static void
ciano_widgets_row_conversion_finalize (GObject * obj)
{
	CianoWidgetsRowConversion * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CIANO_WIDGETS_TYPE_ROW_CONVERSION, CianoWidgetsRowConversion);
	_g_object_unref0 (self->priv->container);
	_g_object_unref0 (self->priv->box_name_progress);
	_g_object_unref0 (self->progress_bar);
	_g_object_unref0 (self->name_video);
	_g_object_unref0 (self->value_progress);
	_g_object_unref0 (self->status);
	_g_object_unref0 (self->button_cancel);
	_g_object_unref0 (self->button_remove);
	_g_object_unref0 (self->convert_to);
	G_OBJECT_CLASS (ciano_widgets_row_conversion_parent_class)->finalize (obj);
}

/**
     * The {@code RowConversion} class is responsible for displaying list of items that
     * are being converted or have been converted   
     *
     * @see Gtk.ListBoxRow
     * @since 0.1.0
     */
static GType
ciano_widgets_row_conversion_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CianoWidgetsRowConversionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ciano_widgets_row_conversion_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CianoWidgetsRowConversion), 0, (GInstanceInitFunc) ciano_widgets_row_conversion_instance_init, NULL };
	GType ciano_widgets_row_conversion_type_id;
	ciano_widgets_row_conversion_type_id = g_type_register_static (gtk_list_box_row_get_type (), "CianoWidgetsRowConversion", &g_define_type_info, 0);
	CianoWidgetsRowConversion_private_offset = g_type_add_instance_private (ciano_widgets_row_conversion_type_id, sizeof (CianoWidgetsRowConversionPrivate));
	return ciano_widgets_row_conversion_type_id;
}

GType
ciano_widgets_row_conversion_get_type (void)
{
	static volatile gsize ciano_widgets_row_conversion_type_id__once = 0;
	if (g_once_init_enter (&ciano_widgets_row_conversion_type_id__once)) {
		GType ciano_widgets_row_conversion_type_id;
		ciano_widgets_row_conversion_type_id = ciano_widgets_row_conversion_get_type_once ();
		g_once_init_leave (&ciano_widgets_row_conversion_type_id__once, ciano_widgets_row_conversion_type_id);
	}
	return ciano_widgets_row_conversion_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

