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

/* swap-speedometer.vala
 *
 * Copyright (C) 2017 Red Hat, Inc.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Felipe Borges <felipeborges@gnome.org>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.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 USAGE_TYPE_SWAP_SPEEDOMETER (usage_swap_speedometer_get_type ())
#define USAGE_SWAP_SPEEDOMETER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometer))
#define USAGE_SWAP_SPEEDOMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometerClass))
#define USAGE_IS_SWAP_SPEEDOMETER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_SWAP_SPEEDOMETER))
#define USAGE_IS_SWAP_SPEEDOMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_SWAP_SPEEDOMETER))
#define USAGE_SWAP_SPEEDOMETER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometerClass))

typedef struct _UsageSwapSpeedometer UsageSwapSpeedometer;
typedef struct _UsageSwapSpeedometerClass UsageSwapSpeedometerClass;
typedef struct _UsageSwapSpeedometerPrivate UsageSwapSpeedometerPrivate;

#define USAGE_TYPE_SPEEDOMETER (usage_speedometer_get_type ())
#define USAGE_SPEEDOMETER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_SPEEDOMETER, UsageSpeedometer))
#define USAGE_SPEEDOMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_SPEEDOMETER, UsageSpeedometerClass))
#define USAGE_IS_SPEEDOMETER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_SPEEDOMETER))
#define USAGE_IS_SPEEDOMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_SPEEDOMETER))
#define USAGE_SPEEDOMETER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_SPEEDOMETER, UsageSpeedometerClass))

typedef struct _UsageSpeedometer UsageSpeedometer;
typedef struct _UsageSpeedometerClass UsageSpeedometerClass;
enum  {
	USAGE_SWAP_SPEEDOMETER_0_PROPERTY,
	USAGE_SWAP_SPEEDOMETER_NUM_PROPERTIES
};
static GParamSpec* usage_swap_speedometer_properties[USAGE_SWAP_SPEEDOMETER_NUM_PROPERTIES];

#define USAGE_TYPE_SYSTEM_MONITOR (usage_system_monitor_get_type ())
#define USAGE_SYSTEM_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_SYSTEM_MONITOR, UsageSystemMonitor))
#define USAGE_SYSTEM_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_SYSTEM_MONITOR, UsageSystemMonitorClass))
#define USAGE_IS_SYSTEM_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_SYSTEM_MONITOR))
#define USAGE_IS_SYSTEM_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_SYSTEM_MONITOR))
#define USAGE_SYSTEM_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_SYSTEM_MONITOR, UsageSystemMonitorClass))

typedef struct _UsageSystemMonitor UsageSystemMonitor;
typedef struct _UsageSystemMonitorClass UsageSystemMonitorClass;
typedef struct _Block14Data Block14Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _UsageSwapSpeedometer {
	AdwBin parent_instance;
	UsageSwapSpeedometerPrivate * priv;
};

struct _UsageSwapSpeedometerClass {
	AdwBinClass parent_class;
};

struct _UsageSwapSpeedometerPrivate {
	UsageSpeedometer* speedometer;
	GtkLabel* label;
	GtkLabel* swap_used;
	GtkLabel* swap_available;
	gdouble _swap_usage;
};

struct _Block14Data {
	int _ref_count_;
	UsageSwapSpeedometer* self;
	UsageSystemMonitor* monitor;
};

static gint UsageSwapSpeedometer_private_offset;
static gpointer usage_swap_speedometer_parent_class = NULL;

VALA_EXTERN GType usage_swap_speedometer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageSwapSpeedometer, g_object_unref)
VALA_EXTERN GType usage_speedometer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageSpeedometer, g_object_unref)
VALA_EXTERN UsageSwapSpeedometer* usage_swap_speedometer_new (void);
VALA_EXTERN UsageSwapSpeedometer* usage_swap_speedometer_construct (GType object_type);
static gdouble usage_swap_speedometer_get_swap_usage (UsageSwapSpeedometer* self);
static void usage_swap_speedometer_set_swap_usage (UsageSwapSpeedometer* self,
                                            gdouble value);
static GObject * usage_swap_speedometer_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
VALA_EXTERN GType usage_system_monitor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageSystemMonitor, g_object_unref)
static Block14Data* block14_data_ref (Block14Data* _data14_);
static void block14_data_unref (void * _userdata_);
VALA_EXTERN UsageSystemMonitor* usage_system_monitor_get_default (void);
static gboolean _usage_swap_speedometer___lambda28_ (Block14Data* _data14_);
VALA_EXTERN guint64 usage_system_monitor_get_swap_total (UsageSystemMonitor* self);
VALA_EXTERN guint64 usage_system_monitor_get_swap_usage (UsageSystemMonitor* self);
VALA_EXTERN void usage_speedometer_set_percentage (UsageSpeedometer* self,
                                       gint value);
VALA_EXTERN gchar* usage_utils_format_size_values (guint64 value,
                                       gulong** most_significant);
static gboolean __usage_swap_speedometer___lambda28__gsource_func (gpointer self);
static void usage_swap_speedometer_finalize (GObject * obj);
static GType usage_swap_speedometer_get_type_once (void);
static void _vala_usage_swap_speedometer_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_usage_swap_speedometer_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
usage_swap_speedometer_get_instance_private (UsageSwapSpeedometer* self)
{
	return G_STRUCT_MEMBER_P (self, UsageSwapSpeedometer_private_offset);
}

UsageSwapSpeedometer*
usage_swap_speedometer_construct (GType object_type)
{
	UsageSwapSpeedometer * self = NULL;
	self = (UsageSwapSpeedometer*) g_object_new (object_type, NULL);
	return self;
}

UsageSwapSpeedometer*
usage_swap_speedometer_new (void)
{
	return usage_swap_speedometer_construct (USAGE_TYPE_SWAP_SPEEDOMETER);
}

static gdouble
usage_swap_speedometer_get_swap_usage (UsageSwapSpeedometer* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, 0.0);
	result = self->priv->_swap_usage;
	return result;
}

static void
usage_swap_speedometer_set_swap_usage (UsageSwapSpeedometer* self,
                                       gdouble value)
{
	g_return_if_fail (self != NULL);
	self->priv->_swap_usage = value;
}

static Block14Data*
block14_data_ref (Block14Data* _data14_)
{
	g_atomic_int_inc (&_data14_->_ref_count_);
	return _data14_;
}

static void
block14_data_unref (void * _userdata_)
{
	Block14Data* _data14_;
	_data14_ = (Block14Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data14_->_ref_count_)) {
		UsageSwapSpeedometer* self;
		self = _data14_->self;
		_g_object_unref0 (_data14_->monitor);
		_g_object_unref0 (self);
		g_slice_free (Block14Data, _data14_);
	}
}

static gboolean
_usage_swap_speedometer___lambda28_ (Block14Data* _data14_)
{
	UsageSwapSpeedometer* self;
	guint64 available = 0ULL;
	UsageSystemMonitor* _tmp0_;
	guint64 _tmp1_;
	guint64 _tmp2_;
	UsageSystemMonitor* _tmp3_;
	guint64 _tmp4_;
	guint64 _tmp5_;
	gdouble percentage = 0.0;
	UsageSystemMonitor* _tmp6_;
	guint64 _tmp7_;
	guint64 _tmp8_;
	UsageSpeedometer* _tmp15_;
	GtkLabel* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	GtkLabel* _tmp21_;
	UsageSystemMonitor* _tmp22_;
	guint64 _tmp23_;
	guint64 _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	GtkLabel* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gboolean result;
	self = _data14_->self;
	_tmp0_ = _data14_->monitor;
	_tmp1_ = usage_system_monitor_get_swap_total (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _data14_->monitor;
	_tmp4_ = usage_system_monitor_get_swap_usage (_tmp3_);
	_tmp5_ = _tmp4_;
	available = _tmp2_ - _tmp5_;
	percentage = 0.0;
	_tmp6_ = _data14_->monitor;
	_tmp7_ = usage_system_monitor_get_swap_total (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp8_ > ((guint64) 0)) {
		UsageSystemMonitor* _tmp9_;
		guint64 _tmp10_;
		guint64 _tmp11_;
		UsageSystemMonitor* _tmp12_;
		guint64 _tmp13_;
		guint64 _tmp14_;
		_tmp9_ = _data14_->monitor;
		_tmp10_ = usage_system_monitor_get_swap_usage (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = _data14_->monitor;
		_tmp13_ = usage_system_monitor_get_swap_total (_tmp12_);
		_tmp14_ = _tmp13_;
		percentage = (((gdouble) _tmp11_) / _tmp14_) * 100;
	}
	_tmp15_ = self->priv->speedometer;
	usage_speedometer_set_percentage (_tmp15_, (gint) percentage);
	_tmp16_ = self->priv->label;
	_tmp17_ = g_strdup_printf ("%d", (gint) percentage);
	_tmp18_ = _tmp17_;
	_tmp19_ = g_strconcat (_tmp18_, "%", NULL);
	_tmp20_ = _tmp19_;
	gtk_label_set_label (_tmp16_, _tmp20_);
	_g_free0 (_tmp20_);
	_g_free0 (_tmp18_);
	_tmp21_ = self->priv->swap_used;
	_tmp22_ = _data14_->monitor;
	_tmp23_ = usage_system_monitor_get_swap_usage (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = usage_utils_format_size_values (_tmp24_, NULL);
	_tmp26_ = _tmp25_;
	gtk_label_set_label (_tmp21_, _tmp26_);
	_g_free0 (_tmp26_);
	_tmp27_ = self->priv->swap_available;
	_tmp28_ = usage_utils_format_size_values (available, NULL);
	_tmp29_ = _tmp28_;
	gtk_label_set_label (_tmp27_, _tmp29_);
	_g_free0 (_tmp29_);
	result = TRUE;
	return result;
}

static gboolean
__usage_swap_speedometer___lambda28__gsource_func (gpointer self)
{
	gboolean result;
	result = _usage_swap_speedometer___lambda28_ (self);
	return result;
}

static GObject *
usage_swap_speedometer_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	UsageSwapSpeedometer * self;
	Block14Data* _data14_;
	UsageSystemMonitor* _tmp0_;
	parent_class = G_OBJECT_CLASS (usage_swap_speedometer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometer);
	_data14_ = g_slice_new0 (Block14Data);
	_data14_->_ref_count_ = 1;
	_data14_->self = g_object_ref (self);
	_tmp0_ = usage_system_monitor_get_default ();
	_data14_->monitor = _tmp0_;
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 1, __usage_swap_speedometer___lambda28__gsource_func, block14_data_ref (_data14_), block14_data_unref);
	block14_data_unref (_data14_);
	_data14_ = NULL;
	return obj;
}

static void
usage_swap_speedometer_class_init (UsageSwapSpeedometerClass * klass,
                                   gpointer klass_data)
{
	usage_swap_speedometer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UsageSwapSpeedometer_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_usage_swap_speedometer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_usage_swap_speedometer_set_property;
	G_OBJECT_CLASS (klass)->constructor = usage_swap_speedometer_constructor;
	G_OBJECT_CLASS (klass)->finalize = usage_swap_speedometer_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Usage/ui/swap-speedometer.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "speedometer", FALSE, UsageSwapSpeedometer_private_offset + G_STRUCT_OFFSET (UsageSwapSpeedometerPrivate, speedometer));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "label", FALSE, UsageSwapSpeedometer_private_offset + G_STRUCT_OFFSET (UsageSwapSpeedometerPrivate, label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "swap_used", FALSE, UsageSwapSpeedometer_private_offset + G_STRUCT_OFFSET (UsageSwapSpeedometerPrivate, swap_used));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "swap_available", FALSE, UsageSwapSpeedometer_private_offset + G_STRUCT_OFFSET (UsageSwapSpeedometerPrivate, swap_available));
}

static void
usage_swap_speedometer_instance_init (UsageSwapSpeedometer * self,
                                      gpointer klass)
{
	self->priv = usage_swap_speedometer_get_instance_private (self);
	g_type_ensure (USAGE_TYPE_SPEEDOMETER);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
usage_swap_speedometer_finalize (GObject * obj)
{
	UsageSwapSpeedometer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometer);
	G_OBJECT_CLASS (usage_swap_speedometer_parent_class)->finalize (obj);
}

static GType
usage_swap_speedometer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UsageSwapSpeedometerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) usage_swap_speedometer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UsageSwapSpeedometer), 0, (GInstanceInitFunc) usage_swap_speedometer_instance_init, NULL };
	GType usage_swap_speedometer_type_id;
	usage_swap_speedometer_type_id = g_type_register_static (adw_bin_get_type (), "UsageSwapSpeedometer", &g_define_type_info, 0);
	UsageSwapSpeedometer_private_offset = g_type_add_instance_private (usage_swap_speedometer_type_id, sizeof (UsageSwapSpeedometerPrivate));
	return usage_swap_speedometer_type_id;
}

GType
usage_swap_speedometer_get_type (void)
{
	static volatile gsize usage_swap_speedometer_type_id__once = 0;
	if (g_once_init_enter (&usage_swap_speedometer_type_id__once)) {
		GType usage_swap_speedometer_type_id;
		usage_swap_speedometer_type_id = usage_swap_speedometer_get_type_once ();
		g_once_init_leave (&usage_swap_speedometer_type_id__once, usage_swap_speedometer_type_id);
	}
	return usage_swap_speedometer_type_id__once;
}

static void
_vala_usage_swap_speedometer_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	UsageSwapSpeedometer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometer);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_usage_swap_speedometer_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	UsageSwapSpeedometer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, USAGE_TYPE_SWAP_SPEEDOMETER, UsageSwapSpeedometer);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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;
}

