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

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

#include <handy.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <libvirt-gobject/libvirt-gobject.h>
#include <glib.h>
#include <osinfo/osinfo.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.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_MEMORY_ROW (boxes_memory_row_get_type ())
#define BOXES_MEMORY_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_MEMORY_ROW, BoxesMemoryRow))
#define BOXES_MEMORY_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_MEMORY_ROW, BoxesMemoryRowClass))
#define BOXES_IS_MEMORY_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_MEMORY_ROW))
#define BOXES_IS_MEMORY_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_MEMORY_ROW))
#define BOXES_MEMORY_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_MEMORY_ROW, BoxesMemoryRowClass))

typedef struct _BoxesMemoryRow BoxesMemoryRow;
typedef struct _BoxesMemoryRowClass BoxesMemoryRowClass;
typedef struct _BoxesMemoryRowPrivate BoxesMemoryRowPrivate;

#define BOXES_TYPE_RAM_ROW (boxes_ram_row_get_type ())
#define BOXES_RAM_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_RAM_ROW, BoxesRamRow))
#define BOXES_RAM_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_RAM_ROW, BoxesRamRowClass))
#define BOXES_IS_RAM_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_RAM_ROW))
#define BOXES_IS_RAM_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_RAM_ROW))
#define BOXES_RAM_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_RAM_ROW, BoxesRamRowClass))

typedef struct _BoxesRamRow BoxesRamRow;
typedef struct _BoxesRamRowClass BoxesRamRowClass;
typedef struct _BoxesRamRowPrivate BoxesRamRowPrivate;
enum  {
	BOXES_RAM_ROW_0_PROPERTY,
	BOXES_RAM_ROW_NUM_PROPERTIES
};
static GParamSpec* boxes_ram_row_properties[BOXES_RAM_ROW_NUM_PROPERTIES];

#define BOXES_TYPE_APP (boxes_app_get_type ())
#define BOXES_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_APP, BoxesApp))
#define BOXES_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_APP, BoxesAppClass))
#define BOXES_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_APP))
#define BOXES_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_APP))
#define BOXES_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_APP, BoxesAppClass))

typedef struct _BoxesApp BoxesApp;
typedef struct _BoxesAppClass BoxesAppClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_GVirNodeInfo_free0(var) ((var == NULL) ? NULL : (var = (_vala_GVirNodeInfo_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _BoxesMemoryRow {
	HdyActionRow parent_instance;
	BoxesMemoryRowPrivate * priv;
	GtkStack* stack;
	GtkLabel* used_label;
	GtkSpinButton* spin_button;
};

struct _BoxesMemoryRowClass {
	HdyActionRowClass parent_class;
};

struct _BoxesRamRow {
	BoxesMemoryRow parent_instance;
	BoxesRamRowPrivate * priv;
};

struct _BoxesRamRowClass {
	BoxesMemoryRowClass parent_class;
};

static gpointer boxes_ram_row_parent_class = NULL;
VALA_EXTERN BoxesApp* boxes_app_app;

VALA_EXTERN GType boxes_memory_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesMemoryRow, g_object_unref)
VALA_EXTERN GType boxes_ram_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesRamRow, g_object_unref)
VALA_EXTERN BoxesRamRow* boxes_ram_row_new (void);
VALA_EXTERN BoxesRamRow* boxes_ram_row_construct (GType object_type);
VALA_EXTERN BoxesMemoryRow* boxes_memory_row_new (void);
VALA_EXTERN BoxesMemoryRow* boxes_memory_row_construct (GType object_type);
static GObject * boxes_ram_row_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties);
VALA_EXTERN GType boxes_app_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesApp, g_object_unref)
VALA_EXTERN GVirConnection* boxes_app_get_default_connection (BoxesApp* self);
static void _vala_GVirNodeInfo_free (GVirNodeInfo* self);
static GType boxes_ram_row_get_type_once (void);

BoxesRamRow*
boxes_ram_row_construct (GType object_type)
{
	BoxesRamRow * self = NULL;
	self = (BoxesRamRow*) boxes_memory_row_construct (object_type);
	return self;
}

BoxesRamRow*
boxes_ram_row_new (void)
{
	return boxes_ram_row_construct (BOXES_TYPE_RAM_ROW);
}

static void
_vala_GVirNodeInfo_free (GVirNodeInfo* self)
{
	g_boxed_free (gvir_node_info_get_type (), self);
}

static GObject *
boxes_ram_row_constructor (GType type,
                           guint n_construct_properties,
                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	BoxesRamRow * self;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (boxes_ram_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BOXES_TYPE_RAM_ROW, BoxesRamRow);
	{
		GVirNodeInfo* host_topology = NULL;
		BoxesApp* _tmp0_;
		GVirConnection* _tmp1_;
		GVirConnection* _tmp2_;
		GVirConnection* _tmp3_;
		GVirNodeInfo* _tmp4_;
		GVirNodeInfo* _tmp5_;
		gulong available_ram = 0UL;
		GVirNodeInfo* _tmp6_;
		guint64 max_ram = 0ULL;
		guint64 min_ram = 0ULL;
		GtkSpinButton* _tmp7_;
		GtkSpinButton* _tmp8_;
		_tmp0_ = boxes_app_app;
		_tmp1_ = boxes_app_get_default_connection (_tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gvir_connection_get_node_info (_tmp3_, &_inner_error0_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		host_topology = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp6_ = host_topology;
		available_ram = _tmp6_->memory;
		max_ram = (guint64) (available_ram * OSINFO_KIBIBYTES);
		min_ram = (guint64) (64 * OSINFO_MEBIBYTES);
		_tmp7_ = ((BoxesMemoryRow*) self)->spin_button;
		gtk_spin_button_set_range (_tmp7_, (gdouble) min_ram, (gdouble) max_ram);
		_tmp8_ = ((BoxesMemoryRow*) self)->spin_button;
		gtk_spin_button_set_increments (_tmp8_, (gdouble) min_ram, (gdouble) max_ram);
		__vala_GVirNodeInfo_free0 (host_topology);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp9_;
		const gchar* _tmp10_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp9_ = _error_;
		_tmp10_ = _tmp9_->message;
		g_warning ("ram-row.vala:15: Failed to obtain virtual resources %s", _tmp10_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
	}
	return obj;
}

static void
boxes_ram_row_class_init (BoxesRamRowClass * klass,
                          gpointer klass_data)
{
	boxes_ram_row_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = boxes_ram_row_constructor;
}

static void
boxes_ram_row_instance_init (BoxesRamRow * self,
                             gpointer klass)
{
}

static GType
boxes_ram_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BoxesRamRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_ram_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesRamRow), 0, (GInstanceInitFunc) boxes_ram_row_instance_init, NULL };
	GType boxes_ram_row_type_id;
	boxes_ram_row_type_id = g_type_register_static (BOXES_TYPE_MEMORY_ROW, "BoxesRamRow", &g_define_type_info, 0);
	return boxes_ram_row_type_id;
}

GType
boxes_ram_row_get_type (void)
{
	static volatile gsize boxes_ram_row_type_id__once = 0;
	if (g_once_init_enter (&boxes_ram_row_type_id__once)) {
		GType boxes_ram_row_type_id;
		boxes_ram_row_type_id = boxes_ram_row_get_type_once ();
		g_once_init_leave (&boxes_ram_row_type_id__once, boxes_ram_row_type_id);
	}
	return boxes_ram_row_type_id__once;
}

