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

/*-
 * Copyright 2016-2021 elementary, Inc. (https://elementary.io)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 * Authored by: Corentin Noël <corentin@elementary.io>
 */

#include "io.elementary.settings.sound.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <granite-7.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

enum  {
	SOUND_DEVICE_ROW_0_PROPERTY,
	SOUND_DEVICE_ROW_DEVICE_PROPERTY,
	SOUND_DEVICE_ROW_NUM_PROPERTIES
};
static GParamSpec* sound_device_row_properties[SOUND_DEVICE_ROW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	SOUND_DEVICE_ROW_SET_AS_DEFAULT_SIGNAL,
	SOUND_DEVICE_ROW_NUM_SIGNALS
};
static guint sound_device_row_signals[SOUND_DEVICE_ROW_NUM_SIGNALS] = {0};

struct _SoundDeviceRowPrivate {
	SoundDevice* _device;
	GtkCheckButton* activate_radio;
	gboolean ignore_default;
};

static gint SoundDeviceRow_private_offset;
static gpointer sound_device_row_parent_class = NULL;

static GObject * sound_device_row_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void _sound_device_row___lambda24_ (SoundDeviceRow* self);
static void __sound_device_row___lambda24__gtk_list_box_row_activate (GtkListBoxRow* _sender,
                                                               gpointer self);
static void _sound_device_row___lambda25_ (SoundDeviceRow* self);
static void __sound_device_row___lambda25__gtk_check_button_toggled (GtkCheckButton* _sender,
                                                              gpointer self);
static void _sound_device_row___lambda26_ (SoundDeviceRow* self);
static void __sound_device_row___lambda26__g_object_notify (GObject* _sender,
                                                     GParamSpec* pspec,
                                                     gpointer self);
static void sound_device_row_finalize (GObject * obj);
static GType sound_device_row_get_type_once (void);
static void _vala_sound_device_row_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_sound_device_row_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
sound_device_row_get_instance_private (SoundDeviceRow* self)
{
	return G_STRUCT_MEMBER_P (self, SoundDeviceRow_private_offset);
}

SoundDeviceRow*
sound_device_row_construct (GType object_type,
                            SoundDevice* device)
{
	SoundDeviceRow * self = NULL;
	g_return_val_if_fail (device != NULL, NULL);
	self = (SoundDeviceRow*) g_object_new (object_type, "device", device, NULL);
	return self;
}

SoundDeviceRow*
sound_device_row_new (SoundDevice* device)
{
	return sound_device_row_construct (SOUND_TYPE_DEVICE_ROW, device);
}

void
sound_device_row_link_to_row (SoundDeviceRow* self,
                              SoundDeviceRow* row)
{
	GtkCheckButton* _tmp0_;
	GtkCheckButton* _tmp1_;
	GtkCheckButton* _tmp2_;
	SoundDevice* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = self->priv->activate_radio;
	_tmp1_ = row->priv->activate_radio;
	gtk_check_button_set_group (_tmp0_, _tmp1_);
	_tmp2_ = self->priv->activate_radio;
	_tmp3_ = self->priv->_device;
	_tmp4_ = sound_device_get_is_default (_tmp3_);
	_tmp5_ = _tmp4_;
	gtk_check_button_set_active (_tmp2_, _tmp5_);
}

SoundDevice*
sound_device_row_get_device (SoundDeviceRow* self)
{
	SoundDevice* result;
	SoundDevice* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_device;
	result = _tmp0_;
	return result;
}

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

static void
sound_device_row_set_device (SoundDeviceRow* self,
                             SoundDevice* value)
{
	SoundDevice* old_value;
	g_return_if_fail (self != NULL);
	old_value = sound_device_row_get_device (self);
	if (old_value != value) {
		SoundDevice* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_device);
		self->priv->_device = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, sound_device_row_properties[SOUND_DEVICE_ROW_DEVICE_PROPERTY]);
	}
}

static void
_sound_device_row___lambda24_ (SoundDeviceRow* self)
{
	GtkCheckButton* _tmp0_;
	_tmp0_ = self->priv->activate_radio;
	gtk_check_button_set_active (_tmp0_, TRUE);
}

static void
__sound_device_row___lambda24__gtk_list_box_row_activate (GtkListBoxRow* _sender,
                                                          gpointer self)
{
	_sound_device_row___lambda24_ ((SoundDeviceRow*) self);
}

static void
_sound_device_row___lambda25_ (SoundDeviceRow* self)
{
	gboolean _tmp0_ = FALSE;
	GtkCheckButton* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	_tmp1_ = self->priv->activate_radio;
	_tmp2_ = gtk_check_button_get_active (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp0_ = !self->priv->ignore_default;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_signal_emit (self, sound_device_row_signals[SOUND_DEVICE_ROW_SET_AS_DEFAULT_SIGNAL], 0);
	}
}

static void
__sound_device_row___lambda25__gtk_check_button_toggled (GtkCheckButton* _sender,
                                                         gpointer self)
{
	_sound_device_row___lambda25_ ((SoundDeviceRow*) self);
}

static void
_sound_device_row___lambda26_ (SoundDeviceRow* self)
{
	GtkCheckButton* _tmp0_;
	SoundDevice* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	self->priv->ignore_default = TRUE;
	_tmp0_ = self->priv->activate_radio;
	_tmp1_ = self->priv->_device;
	_tmp2_ = sound_device_get_is_default (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_check_button_set_active (_tmp0_, _tmp3_);
	self->priv->ignore_default = FALSE;
}

static void
__sound_device_row___lambda26__g_object_notify (GObject* _sender,
                                                GParamSpec* pspec,
                                                gpointer self)
{
	_sound_device_row___lambda26_ ((SoundDeviceRow*) self);
}

static GObject *
sound_device_row_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SoundDeviceRow * self;
	GtkCheckButton* _tmp0_;
	GtkImage* image = NULL;
	SoundDevice* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	SoundDevice* _tmp4_;
	gchar* _tmp5_;
	GtkImage* _tmp6_ = NULL;
	GtkLabel* name_label = NULL;
	SoundDevice* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	GtkLabel* _tmp10_ = NULL;
	GtkLabel* description_label = NULL;
	SoundDevice* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	GtkLabel* _tmp14_ = NULL;
	GtkLabel* _tmp15_;
	GtkLabel* _tmp16_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp17_ = NULL;
	GtkGrid* _tmp18_;
	GtkCheckButton* _tmp19_;
	GtkGrid* _tmp20_;
	GtkImage* _tmp21_;
	GtkGrid* _tmp22_;
	GtkLabel* _tmp23_;
	GtkGrid* _tmp24_;
	GtkLabel* _tmp25_;
	GtkGrid* _tmp26_;
	GtkCheckButton* _tmp27_;
	SoundDevice* _tmp28_;
	GtkLabel* _tmp29_;
	SoundDevice* _tmp30_;
	GtkLabel* _tmp31_;
	SoundDevice* _tmp32_;
	parent_class = G_OBJECT_CLASS (sound_device_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SOUND_TYPE_DEVICE_ROW, SoundDeviceRow);
	_tmp0_ = (GtkCheckButton*) gtk_check_button_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->activate_radio);
	self->priv->activate_radio = _tmp0_;
	_tmp1_ = self->priv->_device;
	_tmp2_ = sound_device_get_icon_name (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->priv->_device;
	_tmp5_ = sound_device_get_nice_form_factor (_tmp4_);
	_tmp6_ = (GtkImage*) gtk_image_new_from_icon_name (_tmp3_);
	gtk_image_set_pixel_size (_tmp6_, 32);
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp6_, _tmp5_);
	_g_free0 (_tmp5_);
	g_object_set (_tmp6_, "use-fallback", TRUE, NULL);
	g_object_ref_sink (_tmp6_);
	image = _tmp6_;
	_tmp7_ = self->priv->_device;
	_tmp8_ = sound_device_get_display_name (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = (GtkLabel*) gtk_label_new (_tmp9_);
	gtk_label_set_xalign (_tmp10_, (gfloat) 0);
	g_object_ref_sink (_tmp10_);
	name_label = _tmp10_;
	_tmp11_ = self->priv->_device;
	_tmp12_ = sound_device_get_description (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = (GtkLabel*) gtk_label_new (_tmp13_);
	gtk_label_set_xalign (_tmp14_, (gfloat) 0);
	g_object_ref_sink (_tmp14_);
	description_label = _tmp14_;
	_tmp15_ = description_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp15_, GRANITE_STYLE_CLASS_DIM_LABEL);
	_tmp16_ = description_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp16_, GRANITE_STYLE_CLASS_SMALL_LABEL);
	_tmp17_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_spacing (_tmp17_, 12);
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp17_, GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp17_);
	grid = _tmp17_;
	_tmp18_ = grid;
	_tmp19_ = self->priv->activate_radio;
	gtk_grid_attach (_tmp18_, (GtkWidget*) _tmp19_, 0, 0, 1, 2);
	_tmp20_ = grid;
	_tmp21_ = image;
	gtk_grid_attach (_tmp20_, (GtkWidget*) _tmp21_, 1, 0, 1, 2);
	_tmp22_ = grid;
	_tmp23_ = name_label;
	gtk_grid_attach (_tmp22_, (GtkWidget*) _tmp23_, 2, 0, 1, 1);
	_tmp24_ = grid;
	_tmp25_ = description_label;
	gtk_grid_attach (_tmp24_, (GtkWidget*) _tmp25_, 2, 1, 1, 1);
	_tmp26_ = grid;
	gtk_list_box_row_set_child ((GtkListBoxRow*) self, (GtkWidget*) _tmp26_);
	g_signal_connect_object ((GtkListBoxRow*) self, "activate", (GCallback) __sound_device_row___lambda24__gtk_list_box_row_activate, self, 0);
	_tmp27_ = self->priv->activate_radio;
	g_signal_connect_object (_tmp27_, "toggled", (GCallback) __sound_device_row___lambda25__gtk_check_button_toggled, self, 0);
	_tmp28_ = self->priv->_device;
	_tmp29_ = name_label;
	g_object_bind_property_with_closures ((GObject*) _tmp28_, "display-name", (GObject*) _tmp29_, "label", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp30_ = self->priv->_device;
	_tmp31_ = description_label;
	g_object_bind_property_with_closures ((GObject*) _tmp30_, "description", (GObject*) _tmp31_, "label", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp32_ = self->priv->_device;
	g_signal_connect_object ((GObject*) _tmp32_, "notify::is-default", (GCallback) __sound_device_row___lambda26__g_object_notify, self, 0);
	_g_object_unref0 (grid);
	_g_object_unref0 (description_label);
	_g_object_unref0 (name_label);
	_g_object_unref0 (image);
	return obj;
}

static void
sound_device_row_class_init (SoundDeviceRowClass * klass,
                             gpointer klass_data)
{
	sound_device_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SoundDeviceRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_sound_device_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sound_device_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = sound_device_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = sound_device_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SOUND_DEVICE_ROW_DEVICE_PROPERTY, sound_device_row_properties[SOUND_DEVICE_ROW_DEVICE_PROPERTY] = g_param_spec_object ("device", "device", "device", SOUND_TYPE_DEVICE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	sound_device_row_signals[SOUND_DEVICE_ROW_SET_AS_DEFAULT_SIGNAL] = g_signal_new ("set-as-default", SOUND_TYPE_DEVICE_ROW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
sound_device_row_instance_init (SoundDeviceRow * self,
                                gpointer klass)
{
	self->priv = sound_device_row_get_instance_private (self);
	self->priv->ignore_default = FALSE;
}

static void
sound_device_row_finalize (GObject * obj)
{
	SoundDeviceRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SOUND_TYPE_DEVICE_ROW, SoundDeviceRow);
	_g_object_unref0 (self->priv->_device);
	_g_object_unref0 (self->priv->activate_radio);
	G_OBJECT_CLASS (sound_device_row_parent_class)->finalize (obj);
}

static GType
sound_device_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SoundDeviceRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sound_device_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SoundDeviceRow), 0, (GInstanceInitFunc) sound_device_row_instance_init, NULL };
	GType sound_device_row_type_id;
	sound_device_row_type_id = g_type_register_static (gtk_list_box_row_get_type (), "SoundDeviceRow", &g_define_type_info, 0);
	SoundDeviceRow_private_offset = g_type_add_instance_private (sound_device_row_type_id, sizeof (SoundDeviceRowPrivate));
	return sound_device_row_type_id;
}

GType
sound_device_row_get_type (void)
{
	static volatile gsize sound_device_row_type_id__once = 0;
	if (g_once_init_enter (&sound_device_row_type_id__once)) {
		GType sound_device_row_type_id;
		sound_device_row_type_id = sound_device_row_get_type_once ();
		g_once_init_leave (&sound_device_row_type_id__once, sound_device_row_type_id);
	}
	return sound_device_row_type_id__once;
}

static void
_vala_sound_device_row_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	SoundDeviceRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SOUND_TYPE_DEVICE_ROW, SoundDeviceRow);
	switch (property_id) {
		case SOUND_DEVICE_ROW_DEVICE_PROPERTY:
		g_value_set_object (value, sound_device_row_get_device (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_sound_device_row_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	SoundDeviceRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SOUND_TYPE_DEVICE_ROW, SoundDeviceRow);
	switch (property_id) {
		case SOUND_DEVICE_ROW_DEVICE_PROPERTY:
		sound_device_row_set_device (self, g_value_get_object (value));
		break;
		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;
}

