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

/*
 * Copyright (c) 2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_ui.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <glib-object.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  {
	FT_ACCELERATOR_ROW_0_PROPERTY,
	FT_ACCELERATOR_ROW_ACCELERATOR_PROPERTY,
	FT_ACCELERATOR_ROW_DESCRIPTION_PROPERTY,
	FT_ACCELERATOR_ROW_NUM_PROPERTIES
};
static GParamSpec* ft_accelerator_row_properties[FT_ACCELERATOR_ROW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _FtAcceleratorRowPrivate {
	gchar* _description;
	GtkLabel* accelerator_label;
	gchar* _accelerator;
};

static gint FtAcceleratorRow_private_offset;
static gpointer ft_accelerator_row_parent_class = NULL;

static void ft_accelerator_row_update_label (FtAcceleratorRow* self);
static GObject * ft_accelerator_row_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties);
static void ft_accelerator_row_finalize (GObject * obj);
static GType ft_accelerator_row_get_type_once (void);
static void _vala_ft_accelerator_row_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_ft_accelerator_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
ft_accelerator_row_get_instance_private (FtAcceleratorRow* self)
{
	return G_STRUCT_MEMBER_P (self, FtAcceleratorRow_private_offset);
}

static void
ft_accelerator_row_update_label (FtAcceleratorRow* self)
{
	FtAccelerator _tmp0_ = {0};
	const gchar* _tmp1_;
	FtAccelerator accelerator = {0};
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_accelerator;
	if (g_strcmp0 (_tmp1_, "") != 0) {
		const gchar* _tmp2_;
		FtAccelerator _tmp3_ = {0};
		_tmp2_ = self->priv->_accelerator;
		ft_accelerator_from_string (_tmp2_, &_tmp3_);
		_tmp0_ = _tmp3_;
	} else {
		FtAccelerator _tmp4_ = {0};
		ft_accelerator_empty (&_tmp4_);
		_tmp0_ = _tmp4_;
	}
	accelerator = _tmp0_;
	if (ft_accelerator_is_empty (&accelerator)) {
		GtkLabel* _tmp5_;
		GtkLabel* _tmp6_;
		_tmp5_ = self->priv->accelerator_label;
		gtk_label_set_label (_tmp5_, _ ("Disabled"));
		_tmp6_ = self->priv->accelerator_label;
		gtk_widget_add_css_class ((GtkWidget*) _tmp6_, "dim-label");
	} else {
		GtkLabel* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		GtkLabel* _tmp10_;
		_tmp7_ = self->priv->accelerator_label;
		_tmp8_ = ft_accelerator_get_label (&accelerator);
		_tmp9_ = _tmp8_;
		gtk_label_set_label (_tmp7_, _tmp9_);
		_g_free0 (_tmp9_);
		_tmp10_ = self->priv->accelerator_label;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp10_, "dim-label");
	}
}

FtAcceleratorRow*
ft_accelerator_row_construct (GType object_type)
{
	FtAcceleratorRow * self = NULL;
	self = (FtAcceleratorRow*) g_object_new (object_type, NULL);
	return self;
}

FtAcceleratorRow*
ft_accelerator_row_new (void)
{
	return ft_accelerator_row_construct (FT_TYPE_ACCELERATOR_ROW);
}

const gchar*
ft_accelerator_row_get_accelerator (FtAcceleratorRow* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_accelerator;
	result = _tmp0_;
	return result;
}

void
ft_accelerator_row_set_accelerator (FtAcceleratorRow* self,
                                    const gchar* value)
{
	const gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	if (value == NULL) {
		value = "";
	}
	_tmp0_ = self->priv->_accelerator;
	if (g_strcmp0 (_tmp0_, value) != 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (value);
		_g_free0 (self->priv->_accelerator);
		self->priv->_accelerator = _tmp1_;
		g_object_notify ((GObject*) self, "accelerator");
	}
	ft_accelerator_row_update_label (self);
}

const gchar*
ft_accelerator_row_get_description (FtAcceleratorRow* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_description;
	result = _tmp0_;
	return result;
}

void
ft_accelerator_row_set_description (FtAcceleratorRow* self,
                                    const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_accelerator_row_get_description (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_description);
		self->priv->_description = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, ft_accelerator_row_properties[FT_ACCELERATOR_ROW_DESCRIPTION_PROPERTY]);
	}
}

static GObject *
ft_accelerator_row_constructor (GType type,
                                guint n_construct_properties,
                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtAcceleratorRow * self;
	GtkLabel* _tmp0_;
	parent_class = G_OBJECT_CLASS (ft_accelerator_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_ACCELERATOR_ROW, FtAcceleratorRow);
	_tmp0_ = self->priv->accelerator_label;
	gtk_widget_set_direction ((GtkWidget*) _tmp0_, GTK_TEXT_DIR_LTR);
	return obj;
}

static void
ft_accelerator_row_class_init (FtAcceleratorRowClass * klass,
                               gpointer klass_data)
{
	ft_accelerator_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtAcceleratorRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_accelerator_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_accelerator_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_accelerator_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_accelerator_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_ACCELERATOR_ROW_ACCELERATOR_PROPERTY, ft_accelerator_row_properties[FT_ACCELERATOR_ROW_ACCELERATOR_PROPERTY] = g_param_spec_string ("accelerator", "accelerator", "accelerator", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_ACCELERATOR_ROW_DESCRIPTION_PROPERTY, ft_accelerator_row_properties[FT_ACCELERATOR_ROW_DESCRIPTION_PROPERTY] = g_param_spec_string ("description", "description", "description", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/preferences/keyboard-shortcuts/accelerator-row.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "accelerator_label", FALSE, FtAcceleratorRow_private_offset + G_STRUCT_OFFSET (FtAcceleratorRowPrivate, accelerator_label));
}

static void
ft_accelerator_row_instance_init (FtAcceleratorRow * self,
                                  gpointer klass)
{
	self->priv = ft_accelerator_row_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_accelerator_row_finalize (GObject * obj)
{
	FtAcceleratorRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_ACCELERATOR_ROW, FtAcceleratorRow);
	_g_free0 (self->priv->_description);
	_g_free0 (self->priv->_accelerator);
	G_OBJECT_CLASS (ft_accelerator_row_parent_class)->finalize (obj);
}

static GType
ft_accelerator_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtAcceleratorRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_accelerator_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtAcceleratorRow), 0, (GInstanceInitFunc) ft_accelerator_row_instance_init, NULL };
	GType ft_accelerator_row_type_id;
	ft_accelerator_row_type_id = g_type_register_static (adw_action_row_get_type (), "FtAcceleratorRow", &g_define_type_info, 0);
	FtAcceleratorRow_private_offset = g_type_add_instance_private (ft_accelerator_row_type_id, sizeof (FtAcceleratorRowPrivate));
	return ft_accelerator_row_type_id;
}

GType
ft_accelerator_row_get_type (void)
{
	static volatile gsize ft_accelerator_row_type_id__once = 0;
	if (g_once_init_enter (&ft_accelerator_row_type_id__once)) {
		GType ft_accelerator_row_type_id;
		ft_accelerator_row_type_id = ft_accelerator_row_get_type_once ();
		g_once_init_leave (&ft_accelerator_row_type_id__once, ft_accelerator_row_type_id);
	}
	return ft_accelerator_row_type_id__once;
}

static void
_vala_ft_accelerator_row_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	FtAcceleratorRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_ACCELERATOR_ROW, FtAcceleratorRow);
	switch (property_id) {
		case FT_ACCELERATOR_ROW_ACCELERATOR_PROPERTY:
		g_value_set_string (value, ft_accelerator_row_get_accelerator (self));
		break;
		case FT_ACCELERATOR_ROW_DESCRIPTION_PROPERTY:
		g_value_set_string (value, ft_accelerator_row_get_description (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_accelerator_row_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	FtAcceleratorRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_ACCELERATOR_ROW, FtAcceleratorRow);
	switch (property_id) {
		case FT_ACCELERATOR_ROW_ACCELERATOR_PROPERTY:
		ft_accelerator_row_set_accelerator (self, g_value_get_string (value));
		break;
		case FT_ACCELERATOR_ROW_DESCRIPTION_PROPERTY:
		ft_accelerator_row_set_description (self, g_value_get_string (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;
}

