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

/* This file is part of GNOME Boxes. License: LGPLv2+*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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 BOXES_TYPE_TRANSFER_INFO_ROW (boxes_transfer_info_row_get_type ())
#define BOXES_TRANSFER_INFO_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_TRANSFER_INFO_ROW, BoxesTransferInfoRow))
#define BOXES_TRANSFER_INFO_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_TRANSFER_INFO_ROW, BoxesTransferInfoRowClass))
#define BOXES_IS_TRANSFER_INFO_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_TRANSFER_INFO_ROW))
#define BOXES_IS_TRANSFER_INFO_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_TRANSFER_INFO_ROW))
#define BOXES_TRANSFER_INFO_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_TRANSFER_INFO_ROW, BoxesTransferInfoRowClass))

typedef struct _BoxesTransferInfoRow BoxesTransferInfoRow;
typedef struct _BoxesTransferInfoRowClass BoxesTransferInfoRowClass;
typedef struct _BoxesTransferInfoRowPrivate BoxesTransferInfoRowPrivate;
enum  {
	BOXES_TRANSFER_INFO_ROW_0_PROPERTY,
	BOXES_TRANSFER_INFO_ROW_PROGRESS_PROPERTY,
	BOXES_TRANSFER_INFO_ROW_TRANSFERRED_BYTES_PROPERTY,
	BOXES_TRANSFER_INFO_ROW_TOTAL_BYTES_PROPERTY,
	BOXES_TRANSFER_INFO_ROW_NUM_PROPERTIES
};
static GParamSpec* boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	BOXES_TRANSFER_INFO_ROW_FINISHED_SIGNAL,
	BOXES_TRANSFER_INFO_ROW_NUM_SIGNALS
};
static guint boxes_transfer_info_row_signals[BOXES_TRANSFER_INFO_ROW_NUM_SIGNALS] = {0};

struct _BoxesTransferInfoRow {
	GtkGrid parent_instance;
	BoxesTransferInfoRowPrivate * priv;
};

struct _BoxesTransferInfoRowClass {
	GtkGridClass parent_class;
};

struct _BoxesTransferInfoRowPrivate {
	GtkLabel* status_label;
	GtkLabel* details_label;
	GtkButton* cancel_button;
	GtkProgressBar* progress_bar;
	GtkImage* done_image;
	gdouble _progress;
	guint64 _total_bytes;
};

static gint BoxesTransferInfoRow_private_offset;
static gpointer boxes_transfer_info_row_parent_class = NULL;

VALA_EXTERN GType boxes_transfer_info_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesTransferInfoRow, g_object_unref)
VALA_EXTERN BoxesTransferInfoRow* boxes_transfer_info_row_new (const gchar* name);
VALA_EXTERN BoxesTransferInfoRow* boxes_transfer_info_row_construct (GType object_type,
                                                         const gchar* name);
VALA_EXTERN void boxes_transfer_info_row_set_progress (BoxesTransferInfoRow* self,
                                           gdouble value);
static gchar* boxes_transfer_info_row_trim_string (BoxesTransferInfoRow* self,
                                            const gchar* s);
static void __lambda53_ (BoxesTransferInfoRow* self);
VALA_EXTERN void boxes_transfer_info_row_finalize_transfer (BoxesTransferInfoRow* self);
static void ___lambda53__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
VALA_EXTERN gdouble boxes_transfer_info_row_get_progress (BoxesTransferInfoRow* self);
VALA_EXTERN void boxes_transfer_info_row_set_transferred_bytes (BoxesTransferInfoRow* self,
                                                    guint64 value);
VALA_EXTERN guint64 boxes_transfer_info_row_get_total_bytes (BoxesTransferInfoRow* self);
VALA_EXTERN void boxes_transfer_info_row_set_total_bytes (BoxesTransferInfoRow* self,
                                              guint64 value);
static void boxes_transfer_info_row_finalize (GObject * obj);
static GType boxes_transfer_info_row_get_type_once (void);
static void _vala_boxes_transfer_info_row_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_boxes_transfer_info_row_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);

static inline gpointer
boxes_transfer_info_row_get_instance_private (BoxesTransferInfoRow* self)
{
	return G_STRUCT_MEMBER_P (self, BoxesTransferInfoRow_private_offset);
}

static void
__lambda53_ (BoxesTransferInfoRow* self)
{
	boxes_transfer_info_row_finalize_transfer (self);
	g_signal_emit (self, boxes_transfer_info_row_signals[BOXES_TRANSFER_INFO_ROW_FINISHED_SIGNAL], 0);
}

static void
___lambda53__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda53_ ((BoxesTransferInfoRow*) self);
}

BoxesTransferInfoRow*
boxes_transfer_info_row_construct (GType object_type,
                                   const gchar* name)
{
	BoxesTransferInfoRow * self = NULL;
	gchar* msg = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GtkLabel* _tmp6_;
	GtkProgressBar* _tmp7_;
	GtkButton* _tmp8_;
	g_return_val_if_fail (name != NULL, NULL);
	self = (BoxesTransferInfoRow*) g_object_new (object_type, NULL);
	boxes_transfer_info_row_set_progress (self, (gdouble) 0);
	_tmp0_ = boxes_transfer_info_row_trim_string (self, name);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup_printf ("Copying “%s” to “Downloads”", _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup (_ (_tmp3_));
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	msg = _tmp5_;
	_tmp6_ = self->priv->status_label;
	gtk_label_set_text (_tmp6_, msg);
	_tmp7_ = self->priv->progress_bar;
	g_object_bind_property_with_closures ((GObject*) self, "progress", (GObject*) _tmp7_, "fraction", G_BINDING_BIDIRECTIONAL, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp8_ = self->priv->cancel_button;
	g_signal_connect_object (_tmp8_, "clicked", (GCallback) ___lambda53__gtk_button_clicked, self, 0);
	_g_free0 (msg);
	return self;
}

BoxesTransferInfoRow*
boxes_transfer_info_row_new (const gchar* name)
{
	return boxes_transfer_info_row_construct (BOXES_TYPE_TRANSFER_INFO_ROW, name);
}

void
boxes_transfer_info_row_finalize_transfer (BoxesTransferInfoRow* self)
{
	GtkButton* _tmp0_;
	GtkImage* _tmp1_;
	GtkButton* _tmp2_;
	GtkButton* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->cancel_button;
	_tmp1_ = self->priv->done_image;
	gtk_button_set_image (_tmp0_, (GtkWidget*) _tmp1_);
	_tmp2_ = self->priv->cancel_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp2_, FALSE);
	_tmp3_ = self->priv->cancel_button;
	gtk_widget_queue_draw ((GtkWidget*) _tmp3_);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gchar*
boxes_transfer_info_row_trim_string (BoxesTransferInfoRow* self,
                                     const gchar* s)
{
	gint _tmp0_;
	gint _tmp1_;
	gchar* _tmp10_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (s != NULL, NULL);
	_tmp0_ = strlen (s);
	_tmp1_ = _tmp0_;
	if (_tmp1_ > 23) {
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp2_ = string_substring (s, (glong) 0, (glong) 15);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_strconcat (_tmp3_, "…", NULL);
		_tmp5_ = _tmp4_;
		_tmp6_ = string_substring (s, (glong) -4, (glong) -1);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_strconcat (_tmp5_, _tmp7_, NULL);
		_tmp9_ = _tmp8_;
		_g_free0 (_tmp7_);
		_g_free0 (_tmp5_);
		_g_free0 (_tmp3_);
		result = _tmp9_;
		return result;
	}
	_tmp10_ = g_strdup (s);
	result = _tmp10_;
	return result;
}

gdouble
boxes_transfer_info_row_get_progress (BoxesTransferInfoRow* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, 0.0);
	result = self->priv->_progress;
	return result;
}

void
boxes_transfer_info_row_set_progress (BoxesTransferInfoRow* self,
                                      gdouble value)
{
	gdouble old_value;
	g_return_if_fail (self != NULL);
	old_value = boxes_transfer_info_row_get_progress (self);
	if (old_value != value) {
		self->priv->_progress = value;
		g_object_notify_by_pspec ((GObject *) self, boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_PROGRESS_PROPERTY]);
	}
}

void
boxes_transfer_info_row_set_transferred_bytes (BoxesTransferInfoRow* self,
                                               guint64 value)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	guint64 _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->details_label;
	_tmp1_ = g_format_size_full (value, G_FORMAT_SIZE_DEFAULT);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->_total_bytes;
	_tmp4_ = g_format_size_full (_tmp3_, G_FORMAT_SIZE_DEFAULT);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strdup_printf ("%s / %s", _tmp2_, _tmp5_);
	_tmp7_ = _tmp6_;
	gtk_label_set_text (_tmp0_, _tmp7_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp2_);
	g_object_notify_by_pspec ((GObject *) self, boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_TRANSFERRED_BYTES_PROPERTY]);
}

guint64
boxes_transfer_info_row_get_total_bytes (BoxesTransferInfoRow* self)
{
	guint64 result;
	g_return_val_if_fail (self != NULL, 0ULL);
	result = self->priv->_total_bytes;
	return result;
}

void
boxes_transfer_info_row_set_total_bytes (BoxesTransferInfoRow* self,
                                         guint64 value)
{
	guint64 old_value;
	g_return_if_fail (self != NULL);
	old_value = boxes_transfer_info_row_get_total_bytes (self);
	if (old_value != value) {
		self->priv->_total_bytes = value;
		g_object_notify_by_pspec ((GObject *) self, boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_TOTAL_BYTES_PROPERTY]);
	}
}

static void
boxes_transfer_info_row_class_init (BoxesTransferInfoRowClass * klass,
                                    gpointer klass_data)
{
	boxes_transfer_info_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BoxesTransferInfoRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_boxes_transfer_info_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_boxes_transfer_info_row_set_property;
	G_OBJECT_CLASS (klass)->finalize = boxes_transfer_info_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BOXES_TRANSFER_INFO_ROW_PROGRESS_PROPERTY, boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_PROGRESS_PROPERTY] = g_param_spec_double ("progress", "progress", "progress", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BOXES_TRANSFER_INFO_ROW_TRANSFERRED_BYTES_PROPERTY, boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_TRANSFERRED_BYTES_PROPERTY] = g_param_spec_uint64 ("transferred-bytes", "transferred-bytes", "transferred-bytes", 0, G_MAXUINT64, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BOXES_TRANSFER_INFO_ROW_TOTAL_BYTES_PROPERTY, boxes_transfer_info_row_properties[BOXES_TRANSFER_INFO_ROW_TOTAL_BYTES_PROPERTY] = g_param_spec_uint64 ("total-bytes", "total-bytes", "total-bytes", 0, G_MAXUINT64, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Boxes/ui/transfer-info-row.ui");
	boxes_transfer_info_row_signals[BOXES_TRANSFER_INFO_ROW_FINISHED_SIGNAL] = g_signal_new ("finished", BOXES_TYPE_TRANSFER_INFO_ROW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "status_label", FALSE, BoxesTransferInfoRow_private_offset + G_STRUCT_OFFSET (BoxesTransferInfoRowPrivate, status_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "details_label", FALSE, BoxesTransferInfoRow_private_offset + G_STRUCT_OFFSET (BoxesTransferInfoRowPrivate, details_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "cancel_button", FALSE, BoxesTransferInfoRow_private_offset + G_STRUCT_OFFSET (BoxesTransferInfoRowPrivate, cancel_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "progress_bar", FALSE, BoxesTransferInfoRow_private_offset + G_STRUCT_OFFSET (BoxesTransferInfoRowPrivate, progress_bar));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "done_image", FALSE, BoxesTransferInfoRow_private_offset + G_STRUCT_OFFSET (BoxesTransferInfoRowPrivate, done_image));
}

static void
boxes_transfer_info_row_instance_init (BoxesTransferInfoRow * self,
                                       gpointer klass)
{
	self->priv = boxes_transfer_info_row_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
boxes_transfer_info_row_finalize (GObject * obj)
{
	BoxesTransferInfoRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BOXES_TYPE_TRANSFER_INFO_ROW, BoxesTransferInfoRow);
	G_OBJECT_CLASS (boxes_transfer_info_row_parent_class)->finalize (obj);
}

static GType
boxes_transfer_info_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BoxesTransferInfoRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_transfer_info_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesTransferInfoRow), 0, (GInstanceInitFunc) boxes_transfer_info_row_instance_init, NULL };
	GType boxes_transfer_info_row_type_id;
	boxes_transfer_info_row_type_id = g_type_register_static (gtk_grid_get_type (), "BoxesTransferInfoRow", &g_define_type_info, 0);
	BoxesTransferInfoRow_private_offset = g_type_add_instance_private (boxes_transfer_info_row_type_id, sizeof (BoxesTransferInfoRowPrivate));
	return boxes_transfer_info_row_type_id;
}

GType
boxes_transfer_info_row_get_type (void)
{
	static volatile gsize boxes_transfer_info_row_type_id__once = 0;
	if (g_once_init_enter (&boxes_transfer_info_row_type_id__once)) {
		GType boxes_transfer_info_row_type_id;
		boxes_transfer_info_row_type_id = boxes_transfer_info_row_get_type_once ();
		g_once_init_leave (&boxes_transfer_info_row_type_id__once, boxes_transfer_info_row_type_id);
	}
	return boxes_transfer_info_row_type_id__once;
}

static void
_vala_boxes_transfer_info_row_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	BoxesTransferInfoRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BOXES_TYPE_TRANSFER_INFO_ROW, BoxesTransferInfoRow);
	switch (property_id) {
		case BOXES_TRANSFER_INFO_ROW_PROGRESS_PROPERTY:
		g_value_set_double (value, boxes_transfer_info_row_get_progress (self));
		break;
		case BOXES_TRANSFER_INFO_ROW_TOTAL_BYTES_PROPERTY:
		g_value_set_uint64 (value, boxes_transfer_info_row_get_total_bytes (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_boxes_transfer_info_row_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	BoxesTransferInfoRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BOXES_TYPE_TRANSFER_INFO_ROW, BoxesTransferInfoRow);
	switch (property_id) {
		case BOXES_TRANSFER_INFO_ROW_PROGRESS_PROPERTY:
		boxes_transfer_info_row_set_progress (self, g_value_get_double (value));
		break;
		case BOXES_TRANSFER_INFO_ROW_TRANSFERRED_BYTES_PROPERTY:
		boxes_transfer_info_row_set_transferred_bytes (self, g_value_get_uint64 (value));
		break;
		case BOXES_TRANSFER_INFO_ROW_TOTAL_BYTES_PROPERTY:
		boxes_transfer_info_row_set_total_bytes (self, g_value_get_uint64 (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

