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

/*
 * SPDX-License-Identifier: LGPL-2.0-or-later
 * SPDX-FileCopyrightText: 2021-2024 elementary, Inc. (https://elementary.io)
 *
 * Authored by: Sean Davis <sean@bluesabre.org>
 */

#include "sound.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <float.h>
#include <math.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_WIDGETS_DEVICE_ITEM_0_PROPERTY,
	SOUND_WIDGETS_DEVICE_ITEM_DEVICE_PROPERTY,
	SOUND_WIDGETS_DEVICE_ITEM_ROW_PROPERTY,
	SOUND_WIDGETS_DEVICE_ITEM_NUM_PROPERTIES
};
static GParamSpec* sound_widgets_device_item_properties[SOUND_WIDGETS_DEVICE_ITEM_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_WIDGETS_DEVICE_ITEM_ACTIVATED_SIGNAL,
	SOUND_WIDGETS_DEVICE_ITEM_NUM_SIGNALS
};
static guint sound_widgets_device_item_signals[SOUND_WIDGETS_DEVICE_ITEM_NUM_SIGNALS] = {0};

struct _SoundWidgetsDeviceItemPrivate {
	SoundDevice* _device;
	GtkListBoxRow* _row;
	gboolean is_priority;
	GtkRadioButton* radio_button;
};

static gint SoundWidgetsDeviceItem_private_offset;
static gpointer sound_widgets_device_item_parent_class = NULL;

static void sound_widgets_device_item_update_visible (SoundWidgetsDeviceItem* self,
                                               gboolean is_default);
static GObject * sound_widgets_device_item_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _sound_widgets_device_item___lambda54_ (SoundWidgetsDeviceItem* self);
static void __sound_widgets_device_item___lambda54__gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                        gpointer self);
static void sound_widgets_device_item_finalize (GObject * obj);
static GType sound_widgets_device_item_get_type_once (void);
static void _vala_sound_widgets_device_item_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_sound_widgets_device_item_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
sound_widgets_device_item_get_instance_private (SoundWidgetsDeviceItem* self)
{
	return G_STRUCT_MEMBER_P (self, SoundWidgetsDeviceItem_private_offset);
}

SoundWidgetsDeviceItem*
sound_widgets_device_item_construct (GType object_type,
                                     SoundDevice* device,
                                     GtkListBoxRow* row)
{
	SoundWidgetsDeviceItem * self = NULL;
	g_return_val_if_fail (device != NULL, NULL);
	self = (SoundWidgetsDeviceItem*) g_object_new (object_type, "device", device, "row", row, NULL);
	return self;
}

SoundWidgetsDeviceItem*
sound_widgets_device_item_new (SoundDevice* device,
                               GtkListBoxRow* row)
{
	return sound_widgets_device_item_construct (SOUND_WIDGETS_TYPE_DEVICE_ITEM, device, row);
}

void
sound_widgets_device_item_set_default (SoundWidgetsDeviceItem* self)
{
	GtkRadioButton* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->radio_button;
	gtk_toggle_button_set_active ((GtkToggleButton*) _tmp0_, TRUE);
	self->priv->is_priority = TRUE;
	gtk_widget_set_visible ((GtkWidget*) self, TRUE);
}

static void
sound_widgets_device_item_update_visible (SoundWidgetsDeviceItem* self,
                                          gboolean is_default)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->is_priority) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = is_default;
	}
	gtk_widget_set_visible ((GtkWidget*) self, _tmp0_);
}

SoundDevice*
sound_widgets_device_item_get_device (SoundWidgetsDeviceItem* 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_widgets_device_item_set_device (SoundWidgetsDeviceItem* self,
                                      SoundDevice* value)
{
	SoundDevice* old_value;
	g_return_if_fail (self != NULL);
	old_value = sound_widgets_device_item_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_widgets_device_item_properties[SOUND_WIDGETS_DEVICE_ITEM_DEVICE_PROPERTY]);
	}
}

GtkListBoxRow*
sound_widgets_device_item_get_row (SoundWidgetsDeviceItem* self)
{
	GtkListBoxRow* result;
	GtkListBoxRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_row;
	result = _tmp0_;
	return result;
}

static void
sound_widgets_device_item_set_row (SoundWidgetsDeviceItem* self,
                                   GtkListBoxRow* value)
{
	GtkListBoxRow* old_value;
	g_return_if_fail (self != NULL);
	old_value = sound_widgets_device_item_get_row (self);
	if (old_value != value) {
		GtkListBoxRow* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_row);
		self->priv->_row = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, sound_widgets_device_item_properties[SOUND_WIDGETS_DEVICE_ITEM_ROW_PROPERTY]);
	}
}

static void
_sound_widgets_device_item___lambda54_ (SoundWidgetsDeviceItem* self)
{
	GtkRadioButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GtkRadioButton* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	_tmp0_ = self->priv->radio_button;
	_tmp1_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		g_signal_emit (self, sound_widgets_device_item_signals[SOUND_WIDGETS_DEVICE_ITEM_ACTIVATED_SIGNAL], 0);
	}
	_tmp3_ = self->priv->radio_button;
	_tmp4_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp3_);
	_tmp5_ = _tmp4_;
	sound_widgets_device_item_update_visible (self, _tmp5_);
}

static void
__sound_widgets_device_item___lambda54__gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                   gpointer self)
{
	_sound_widgets_device_item___lambda54_ ((SoundWidgetsDeviceItem*) self);
}

static GObject *
sound_widgets_device_item_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SoundWidgetsDeviceItem * self;
	GtkLabel* label = NULL;
	SoundDevice* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GtkLabel* _tmp3_ = NULL;
	GtkImage* image = NULL;
	SoundDevice* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GtkImage* _tmp9_ = NULL;
	GtkImage* _tmp10_;
	GtkBox* box = NULL;
	GtkBox* _tmp11_;
	GtkBox* _tmp12_;
	GtkLabel* _tmp13_;
	GtkBox* _tmp14_;
	GtkImage* _tmp15_;
	GtkBox* _tmp16_;
	GtkWidget* _tmp17_;
	SoundDevice* _tmp18_;
	gboolean _tmp19_;
	gboolean _tmp20_;
	GtkRadioButton* _tmp21_ = NULL;
	GtkListBoxRow* _tmp22_;
	GtkRadioButton* _tmp29_;
	GtkRadioButton* _tmp30_;
	SoundDevice* _tmp31_;
	gboolean _tmp32_;
	gboolean _tmp33_;
	SoundDevice* _tmp34_;
	gboolean _tmp35_;
	gboolean _tmp36_;
	parent_class = G_OBJECT_CLASS (sound_widgets_device_item_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SOUND_WIDGETS_TYPE_DEVICE_ITEM, SoundWidgetsDeviceItem);
	_tmp0_ = self->priv->_device;
	_tmp1_ = sound_device_get_display_name (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = (GtkLabel*) gtk_label_new (_tmp2_);
	gtk_widget_set_halign ((GtkWidget*) _tmp3_, GTK_ALIGN_START);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp3_, TRUE);
	gtk_label_set_ellipsize (_tmp3_, PANGO_ELLIPSIZE_MIDDLE);
	g_object_ref_sink (_tmp3_);
	label = _tmp3_;
	_tmp4_ = self->priv->_device;
	_tmp5_ = sound_device_get_icon_name (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strconcat (_tmp6_, "-symbolic", NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = (GtkImage*) gtk_image_new_from_icon_name (_tmp8_, (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_set (_tmp9_, "use-fallback", TRUE, NULL);
	g_object_ref_sink (_tmp9_);
	_tmp10_ = _tmp9_;
	_g_free0 (_tmp8_);
	image = _tmp10_;
	_tmp11_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp11_);
	box = _tmp11_;
	_tmp12_ = box;
	_tmp13_ = label;
	gtk_container_add ((GtkContainer*) _tmp12_, (GtkWidget*) _tmp13_);
	_tmp14_ = box;
	_tmp15_ = image;
	gtk_container_add ((GtkContainer*) _tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = box;
	_tmp17_ = _g_object_ref0 ((GtkWidget*) _tmp16_);
	_tmp18_ = self->priv->_device;
	_tmp19_ = sound_device_get_is_default (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = (GtkRadioButton*) gtk_radio_button_new (NULL);
	g_object_set ((GtkContainer*) _tmp21_, "child", _tmp17_, NULL);
	_g_object_unref0 (_tmp17_);
	gtk_toggle_button_set_active ((GtkToggleButton*) _tmp21_, _tmp20_);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp21_, TRUE);
	g_object_set ((GtkButton*) _tmp21_, "xalign", (gfloat) 0, NULL);
	g_object_ref_sink (_tmp21_);
	_g_object_unref0 (self->priv->radio_button);
	self->priv->radio_button = _tmp21_;
	_tmp22_ = self->priv->_row;
	if (_tmp22_ != NULL) {
		SoundWidgetsDeviceItem* item = NULL;
		GtkListBoxRow* _tmp23_;
		SoundWidgetsDeviceItem* _tmp24_;
		GtkRadioButton* _tmp25_;
		SoundWidgetsDeviceItem* _tmp26_;
		GtkRadioButton* _tmp27_;
		GSList* _tmp28_;
		_tmp23_ = self->priv->_row;
		_tmp24_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, SOUND_WIDGETS_TYPE_DEVICE_ITEM, SoundWidgetsDeviceItem));
		item = _tmp24_;
		_tmp25_ = self->priv->radio_button;
		_tmp26_ = item;
		_tmp27_ = _tmp26_->priv->radio_button;
		_tmp28_ = gtk_radio_button_get_group (_tmp27_);
		gtk_radio_button_set_group (_tmp25_, _tmp28_);
		_g_object_unref0 (item);
	}
	_tmp29_ = self->priv->radio_button;
	g_object_set ((GtkContainer*) self, "child", (GtkWidget*) _tmp29_, NULL);
	gtk_widget_show_all ((GtkWidget*) self);
	gtk_list_box_row_set_selectable ((GtkListBoxRow*) self, FALSE);
	gtk_widget_set_no_show_all ((GtkWidget*) self, TRUE);
	_tmp30_ = self->priv->radio_button;
	g_signal_connect_object ((GtkToggleButton*) _tmp30_, "toggled", (GCallback) __sound_widgets_device_item___lambda54__gtk_toggle_button_toggled, self, 0);
	_tmp31_ = self->priv->_device;
	_tmp32_ = sound_device_get_is_priority (_tmp31_);
	_tmp33_ = _tmp32_;
	self->priv->is_priority = _tmp33_;
	_tmp34_ = self->priv->_device;
	_tmp35_ = sound_device_get_is_default (_tmp34_);
	_tmp36_ = _tmp35_;
	sound_widgets_device_item_update_visible (self, _tmp36_);
	_g_object_unref0 (box);
	_g_object_unref0 (image);
	_g_object_unref0 (label);
	return obj;
}

static void
sound_widgets_device_item_base_init (SoundWidgetsDeviceItemClass * klass)
{
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), GTK_STYLE_CLASS_MENUITEM);
}

static void
sound_widgets_device_item_class_init (SoundWidgetsDeviceItemClass * klass,
                                      gpointer klass_data)
{
	sound_widgets_device_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SoundWidgetsDeviceItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_sound_widgets_device_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sound_widgets_device_item_set_property;
	G_OBJECT_CLASS (klass)->constructor = sound_widgets_device_item_constructor;
	G_OBJECT_CLASS (klass)->finalize = sound_widgets_device_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SOUND_WIDGETS_DEVICE_ITEM_DEVICE_PROPERTY, sound_widgets_device_item_properties[SOUND_WIDGETS_DEVICE_ITEM_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));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SOUND_WIDGETS_DEVICE_ITEM_ROW_PROPERTY, sound_widgets_device_item_properties[SOUND_WIDGETS_DEVICE_ITEM_ROW_PROPERTY] = g_param_spec_object ("row", "row", "row", gtk_list_box_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	sound_widgets_device_item_signals[SOUND_WIDGETS_DEVICE_ITEM_ACTIVATED_SIGNAL] = g_signal_new ("activated", SOUND_WIDGETS_TYPE_DEVICE_ITEM, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
sound_widgets_device_item_instance_init (SoundWidgetsDeviceItem * self,
                                         gpointer klass)
{
	self->priv = sound_widgets_device_item_get_instance_private (self);
}

static void
sound_widgets_device_item_finalize (GObject * obj)
{
	SoundWidgetsDeviceItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SOUND_WIDGETS_TYPE_DEVICE_ITEM, SoundWidgetsDeviceItem);
	_g_object_unref0 (self->priv->_device);
	_g_object_unref0 (self->priv->_row);
	_g_object_unref0 (self->priv->radio_button);
	G_OBJECT_CLASS (sound_widgets_device_item_parent_class)->finalize (obj);
}

static GType
sound_widgets_device_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SoundWidgetsDeviceItemClass), (GBaseInitFunc) sound_widgets_device_item_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sound_widgets_device_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SoundWidgetsDeviceItem), 0, (GInstanceInitFunc) sound_widgets_device_item_instance_init, NULL };
	GType sound_widgets_device_item_type_id;
	sound_widgets_device_item_type_id = g_type_register_static (gtk_list_box_row_get_type (), "SoundWidgetsDeviceItem", &g_define_type_info, 0);
	SoundWidgetsDeviceItem_private_offset = g_type_add_instance_private (sound_widgets_device_item_type_id, sizeof (SoundWidgetsDeviceItemPrivate));
	return sound_widgets_device_item_type_id;
}

GType
sound_widgets_device_item_get_type (void)
{
	static volatile gsize sound_widgets_device_item_type_id__once = 0;
	if (g_once_init_enter (&sound_widgets_device_item_type_id__once)) {
		GType sound_widgets_device_item_type_id;
		sound_widgets_device_item_type_id = sound_widgets_device_item_get_type_once ();
		g_once_init_leave (&sound_widgets_device_item_type_id__once, sound_widgets_device_item_type_id);
	}
	return sound_widgets_device_item_type_id__once;
}

static void
_vala_sound_widgets_device_item_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	SoundWidgetsDeviceItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SOUND_WIDGETS_TYPE_DEVICE_ITEM, SoundWidgetsDeviceItem);
	switch (property_id) {
		case SOUND_WIDGETS_DEVICE_ITEM_DEVICE_PROPERTY:
		g_value_set_object (value, sound_widgets_device_item_get_device (self));
		break;
		case SOUND_WIDGETS_DEVICE_ITEM_ROW_PROPERTY:
		g_value_set_object (value, sound_widgets_device_item_get_row (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_sound_widgets_device_item_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	SoundWidgetsDeviceItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SOUND_WIDGETS_TYPE_DEVICE_ITEM, SoundWidgetsDeviceItem);
	switch (property_id) {
		case SOUND_WIDGETS_DEVICE_ITEM_DEVICE_PROPERTY:
		sound_widgets_device_item_set_device (self, g_value_get_object (value));
		break;
		case SOUND_WIDGETS_DEVICE_ITEM_ROW_PROPERTY:
		sound_widgets_device_item_set_row (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

