/* preferences-panel-sounds.c generated by valac 0.56.19, the Vala compiler
 * generated from preferences-panel-sounds.vala, do not modify */

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

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "ft_ui.h"
#include <adwaita.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include "ft_core.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

#define FT_TYPE_PRESET (ft_preset_get_type ())
typedef struct _FtPreset FtPreset;
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	FT_PREFERENCES_PANEL_SOUNDS_0_PROPERTY,
	FT_PREFERENCES_PANEL_SOUNDS_NUM_PROPERTIES
};
static GParamSpec* ft_preferences_panel_sounds_properties[FT_PREFERENCES_PANEL_SOUNDS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _FtPreset {
	gchar* uri;
	gchar* label;
};

struct _FtPreferencesPanelSoundsPrivate {
	AdwPreferencesPage* page;
	GtkSwitch* enable_switch;
	GtkStack* stack;
	GtkLabel* pomodoro_finished_sound_label;
	GtkLabel* break_finished_sound_label;
	GtkLabel* background_sound_label;
	GSettings* settings;
	gulong settings_changed_id;
};

static gint FtPreferencesPanelSounds_private_offset;
static gpointer ft_preferences_panel_sounds_parent_class = NULL;

VALA_EXTERN GType ft_preset_get_type (void) G_GNUC_CONST ;
VALA_EXTERN FtPreset* ft_preset_dup (const FtPreset* self);
VALA_EXTERN void ft_preset_free (FtPreset* self);
VALA_EXTERN void ft_preset_copy (const FtPreset* self,
                     FtPreset* dest);
VALA_EXTERN void ft_preset_destroy (FtPreset* self);
static gboolean ft_preferences_panel_sounds_transform_active_to_visible_child_name (GBinding* binding,
                                                                             GValue* source_value,
                                                                             GValue* target_value);
static FtSoundChooserWindow* ft_preferences_panel_sounds_create_sound_chooser (FtPreferencesPanelSounds* self,
                                                                        const gchar* title,
                                                                        const gchar* event_id,
                                                                        FtPreset* presets,
                                                                        gint presets_length1);
static gchar* ft_preferences_panel_sounds_format_sound_label (FtPreferencesPanelSounds* self,
                                                       const gchar* uri);
static void ft_preferences_panel_sounds_update_sound_labels (FtPreferencesPanelSounds* self);
static void ft_preferences_panel_sounds_on_pomodoro_finished_sound_activated (FtPreferencesPanelSounds* self,
                                                                       AdwActionRow* action_row);
static void _ft_preferences_panel_sounds_on_pomodoro_finished_sound_activated_adw_action_row_activated (AdwActionRow* _sender,
                                                                                                 gpointer self);
static void ft_preferences_panel_sounds_on_break_finished_sound_activated (FtPreferencesPanelSounds* self,
                                                                    AdwActionRow* action_row);
static void _ft_preferences_panel_sounds_on_break_finished_sound_activated_adw_action_row_activated (AdwActionRow* _sender,
                                                                                              gpointer self);
static void ft_preferences_panel_sounds_on_background_sound_activated (FtPreferencesPanelSounds* self,
                                                                AdwActionRow* action_row);
static void _ft_preferences_panel_sounds_on_background_sound_activated_adw_action_row_activated (AdwActionRow* _sender,
                                                                                          gpointer self);
static void ft_preferences_panel_sounds_on_settings_changed (FtPreferencesPanelSounds* self,
                                                      GSettings* settings,
                                                      const gchar* key);
static AdwPreferencesPage* ft_preferences_panel_sounds_real_get_preferences_page (FtPreferencesPanel* base);
static void ft_preferences_panel_sounds_real_dispose (GObject* base);
static GObject * ft_preferences_panel_sounds_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _ft_preferences_panel_sounds_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                          const gchar* key,
                                                                          gpointer self);
static gboolean _ft_preferences_panel_sounds_transform_active_to_visible_child_name_gbinding_transform_func (GBinding* binding,
                                                                                                      GValue* from_value,
                                                                                                      GValue* to_value,
                                                                                                      gpointer self);
static void ft_preferences_panel_sounds_finalize (GObject * obj);
static GType ft_preferences_panel_sounds_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const FtPreset FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS[2] = {{"bell.ogg", N_ ("Bell")}, {"loud-bell.ogg", N_ ("Loud Bell")}};
static const FtPreset FT_PREFERENCES_PANEL_SOUNDS_BACKGROUND_PRESETS[3] = {{"clock.ogg", N_ ("Clock Ticking")}, {"metronome.ogg", N_ ("Metronome")}, {"brown-noise.ogg", N_ ("Brown Noise")}};

void
ft_preset_copy (const FtPreset* self,
                FtPreset* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = (*self).uri;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).uri);
	(*dest).uri = _tmp1_;
	_tmp2_ = (*self).label;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).label);
	(*dest).label = _tmp3_;
}

void
ft_preset_destroy (FtPreset* self)
{
	_g_free0 ((*self).uri);
	_g_free0 ((*self).label);
}

FtPreset*
ft_preset_dup (const FtPreset* self)
{
	FtPreset* dup;
	dup = g_new0 (FtPreset, 1);
	ft_preset_copy (self, dup);
	return dup;
}

void
ft_preset_free (FtPreset* self)
{
	ft_preset_destroy (self);
	g_free (self);
}

static GType
ft_preset_get_type_once (void)
{
	GType ft_preset_type_id;
	ft_preset_type_id = g_boxed_type_register_static ("FtPreset", (GBoxedCopyFunc) ft_preset_dup, (GBoxedFreeFunc) ft_preset_free);
	return ft_preset_type_id;
}

GType
ft_preset_get_type (void)
{
	static volatile gsize ft_preset_type_id__once = 0;
	if (g_once_init_enter (&ft_preset_type_id__once)) {
		GType ft_preset_type_id;
		ft_preset_type_id = ft_preset_get_type_once ();
		g_once_init_leave (&ft_preset_type_id__once, ft_preset_type_id);
	}
	return ft_preset_type_id__once;
}

static inline gpointer
ft_preferences_panel_sounds_get_instance_private (FtPreferencesPanelSounds* self)
{
	return G_STRUCT_MEMBER_P (self, FtPreferencesPanelSounds_private_offset);
}

static gboolean
ft_preferences_panel_sounds_transform_active_to_visible_child_name (GBinding* binding,
                                                                    GValue* source_value,
                                                                    GValue* target_value)
{
	const gchar* _tmp0_ = NULL;
	gboolean result;
	g_return_val_if_fail (binding != NULL, FALSE);
	g_return_val_if_fail (source_value != NULL, FALSE);
	g_return_val_if_fail (target_value != NULL, FALSE);
	if (g_value_get_boolean (source_value)) {
		_tmp0_ = "enabled";
	} else {
		_tmp0_ = "disabled";
	}
	g_value_set_string (target_value, _tmp0_);
	result = TRUE;
	return result;
}

static FtSoundChooserWindow*
ft_preferences_panel_sounds_create_sound_chooser (FtPreferencesPanelSounds* self,
                                                  const gchar* title,
                                                  const gchar* event_id,
                                                  FtPreset* presets,
                                                  gint presets_length1)
{
	FtSoundChooserWindow* chooser = NULL;
	FtSoundChooserWindow* _tmp0_;
	FtSoundChooserWindow* _tmp1_;
	FtSoundChooserWindow* _tmp2_;
	FtSoundChooserWindow* _tmp3_;
	GtkRoot* _tmp4_;
	FtSoundChooserWindow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	_tmp0_ = ft_sound_chooser_window_new ();
	g_object_ref_sink (_tmp0_);
	chooser = _tmp0_;
	_tmp1_ = chooser;
	gtk_window_set_title ((GtkWindow*) _tmp1_, title);
	_tmp2_ = chooser;
	ft_sound_chooser_window_set_event_id (_tmp2_, event_id);
	_tmp3_ = chooser;
	_tmp4_ = gtk_widget_get_root ((GtkWidget*) self);
	gtk_window_set_transient_for ((GtkWindow*) _tmp3_, G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_window_get_type (), GtkWindow));
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				FtSoundChooserWindow* _tmp7_;
				FtPreset _tmp8_;
				const gchar* _tmp9_;
				FtPreset _tmp10_;
				const gchar* _tmp11_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = index;
					index = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				if (!(index < presets_length1)) {
					break;
				}
				_tmp7_ = chooser;
				_tmp8_ = presets[index];
				_tmp9_ = _tmp8_.uri;
				_tmp10_ = presets[index];
				_tmp11_ = _tmp10_.label;
				ft_sound_chooser_window_add_preset (_tmp7_, _tmp9_, gettext (_tmp11_));
			}
		}
	}
	result = chooser;
	return result;
}

static gchar*
ft_preferences_panel_sounds_format_sound_label (FtPreferencesPanelSounds* self,
                                                const gchar* uri)
{
	gboolean _tmp0_ = FALSE;
	GFile* _tmp12_;
	GFile* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (uri != NULL, NULL);
	if (g_strcmp0 (uri, "") == 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = uri == NULL;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (_ ("None"));
		result = _tmp1_;
		return result;
	}
	{
		FtPreset* preset_collection = NULL;
		gint preset_collection_length1 = 0;
		gint _preset_collection_size_ = 0;
		gint preset_it = 0;
		preset_collection = FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS;
		preset_collection_length1 = G_N_ELEMENTS (FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS);
		for (preset_it = 0; preset_it < preset_collection_length1; preset_it = preset_it + 1) {
			FtPreset preset = {0};
			preset = preset_collection[preset_it];
			{
				FtPreset _tmp2_;
				const gchar* _tmp3_;
				_tmp2_ = preset;
				_tmp3_ = _tmp2_.uri;
				if (g_strcmp0 (_tmp3_, uri) == 0) {
					FtPreset _tmp4_;
					const gchar* _tmp5_;
					gchar* _tmp6_;
					_tmp4_ = preset;
					_tmp5_ = _tmp4_.label;
					_tmp6_ = g_strdup (gettext (_tmp5_));
					result = _tmp6_;
					return result;
				}
			}
		}
	}
	{
		FtPreset* preset_collection = NULL;
		gint preset_collection_length1 = 0;
		gint _preset_collection_size_ = 0;
		gint preset_it = 0;
		preset_collection = FT_PREFERENCES_PANEL_SOUNDS_BACKGROUND_PRESETS;
		preset_collection_length1 = G_N_ELEMENTS (FT_PREFERENCES_PANEL_SOUNDS_BACKGROUND_PRESETS);
		for (preset_it = 0; preset_it < preset_collection_length1; preset_it = preset_it + 1) {
			FtPreset preset = {0};
			preset = preset_collection[preset_it];
			{
				FtPreset _tmp7_;
				const gchar* _tmp8_;
				_tmp7_ = preset;
				_tmp8_ = _tmp7_.uri;
				if (g_strcmp0 (_tmp8_, uri) == 0) {
					FtPreset _tmp9_;
					const gchar* _tmp10_;
					gchar* _tmp11_;
					_tmp9_ = preset;
					_tmp10_ = _tmp9_.label;
					_tmp11_ = g_strdup (gettext (_tmp10_));
					result = _tmp11_;
					return result;
				}
			}
		}
	}
	_tmp12_ = g_file_new_for_uri (uri);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_file_get_basename (_tmp13_);
	_tmp15_ = _tmp14_;
	_g_object_unref0 (_tmp13_);
	result = _tmp15_;
	return result;
}

static void
ft_preferences_panel_sounds_update_sound_labels (FtPreferencesPanelSounds* self)
{
	GtkLabel* _tmp0_;
	GSettings* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GtkLabel* _tmp6_;
	GSettings* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GtkLabel* _tmp12_;
	GSettings* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->pomodoro_finished_sound_label;
	_tmp1_ = self->priv->settings;
	_tmp2_ = g_settings_get_string (_tmp1_, "pomodoro-finished-sound");
	_tmp3_ = _tmp2_;
	_tmp4_ = ft_preferences_panel_sounds_format_sound_label (self, _tmp3_);
	_tmp5_ = _tmp4_;
	gtk_label_set_label (_tmp0_, _tmp5_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_tmp6_ = self->priv->break_finished_sound_label;
	_tmp7_ = self->priv->settings;
	_tmp8_ = g_settings_get_string (_tmp7_, "break-finished-sound");
	_tmp9_ = _tmp8_;
	_tmp10_ = ft_preferences_panel_sounds_format_sound_label (self, _tmp9_);
	_tmp11_ = _tmp10_;
	gtk_label_set_label (_tmp6_, _tmp11_);
	_g_free0 (_tmp11_);
	_g_free0 (_tmp9_);
	_tmp12_ = self->priv->background_sound_label;
	_tmp13_ = self->priv->settings;
	_tmp14_ = g_settings_get_string (_tmp13_, "background-sound");
	_tmp15_ = _tmp14_;
	_tmp16_ = ft_preferences_panel_sounds_format_sound_label (self, _tmp15_);
	_tmp17_ = _tmp16_;
	gtk_label_set_label (_tmp12_, _tmp17_);
	_g_free0 (_tmp17_);
	_g_free0 (_tmp15_);
}

static void
ft_preferences_panel_sounds_on_pomodoro_finished_sound_activated (FtPreferencesPanelSounds* self,
                                                                  AdwActionRow* action_row)
{
	FtSoundChooserWindow* chooser = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	FtSoundChooserWindow* _tmp2_;
	GSettings* _tmp3_;
	GSettings* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action_row != NULL);
	_tmp0_ = adw_preferences_row_get_title ((AdwPreferencesRow*) action_row);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_preferences_panel_sounds_create_sound_chooser (self, _tmp1_, "pomodoro-finished", FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS, (gint) G_N_ELEMENTS (FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS));
	chooser = _tmp2_;
	_tmp3_ = self->priv->settings;
	g_settings_bind (_tmp3_, "pomodoro-finished-sound", (GObject*) chooser, "uri", G_SETTINGS_BIND_DEFAULT);
	_tmp4_ = self->priv->settings;
	g_settings_bind (_tmp4_, "pomodoro-finished-sound-volume", (GObject*) chooser, "volume", G_SETTINGS_BIND_DEFAULT);
	gtk_window_present ((GtkWindow*) chooser);
	_g_object_unref0 (chooser);
}

static void
_ft_preferences_panel_sounds_on_pomodoro_finished_sound_activated_adw_action_row_activated (AdwActionRow* _sender,
                                                                                            gpointer self)
{
	ft_preferences_panel_sounds_on_pomodoro_finished_sound_activated ((FtPreferencesPanelSounds*) self, _sender);
}

static void
ft_preferences_panel_sounds_on_break_finished_sound_activated (FtPreferencesPanelSounds* self,
                                                               AdwActionRow* action_row)
{
	FtSoundChooserWindow* chooser = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	FtSoundChooserWindow* _tmp2_;
	GSettings* _tmp3_;
	GSettings* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action_row != NULL);
	_tmp0_ = adw_preferences_row_get_title ((AdwPreferencesRow*) action_row);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_preferences_panel_sounds_create_sound_chooser (self, _tmp1_, "break-finished", FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS, (gint) G_N_ELEMENTS (FT_PREFERENCES_PANEL_SOUNDS_ALERT_PRESETS));
	chooser = _tmp2_;
	_tmp3_ = self->priv->settings;
	g_settings_bind (_tmp3_, "break-finished-sound", (GObject*) chooser, "uri", G_SETTINGS_BIND_DEFAULT);
	_tmp4_ = self->priv->settings;
	g_settings_bind (_tmp4_, "break-finished-sound-volume", (GObject*) chooser, "volume", G_SETTINGS_BIND_DEFAULT);
	gtk_window_present ((GtkWindow*) chooser);
	_g_object_unref0 (chooser);
}

static void
_ft_preferences_panel_sounds_on_break_finished_sound_activated_adw_action_row_activated (AdwActionRow* _sender,
                                                                                         gpointer self)
{
	ft_preferences_panel_sounds_on_break_finished_sound_activated ((FtPreferencesPanelSounds*) self, _sender);
}

static void
ft_preferences_panel_sounds_on_background_sound_activated (FtPreferencesPanelSounds* self,
                                                           AdwActionRow* action_row)
{
	FtSoundChooserWindow* chooser = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	FtSoundChooserWindow* _tmp2_;
	GSettings* _tmp3_;
	GSettings* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action_row != NULL);
	_tmp0_ = adw_preferences_row_get_title ((AdwPreferencesRow*) action_row);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_preferences_panel_sounds_create_sound_chooser (self, _tmp1_, NULL, FT_PREFERENCES_PANEL_SOUNDS_BACKGROUND_PRESETS, (gint) G_N_ELEMENTS (FT_PREFERENCES_PANEL_SOUNDS_BACKGROUND_PRESETS));
	chooser = _tmp2_;
	_tmp3_ = self->priv->settings;
	g_settings_bind (_tmp3_, "background-sound", (GObject*) chooser, "uri", G_SETTINGS_BIND_DEFAULT);
	_tmp4_ = self->priv->settings;
	g_settings_bind (_tmp4_, "background-sound-volume", (GObject*) chooser, "volume", G_SETTINGS_BIND_DEFAULT);
	gtk_window_present ((GtkWindow*) chooser);
	_g_object_unref0 (chooser);
}

static void
_ft_preferences_panel_sounds_on_background_sound_activated_adw_action_row_activated (AdwActionRow* _sender,
                                                                                     gpointer self)
{
	ft_preferences_panel_sounds_on_background_sound_activated ((FtPreferencesPanelSounds*) self, _sender);
}

static void
ft_preferences_panel_sounds_on_settings_changed (FtPreferencesPanelSounds* self,
                                                 GSettings* settings,
                                                 const gchar* key)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (settings != NULL);
	g_return_if_fail (key != NULL);
	_tmp0_ = key;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (((_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("pomodoro-finished-sound")))) || (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("break-finished-sound"))))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("background-sound"))))) {
		switch (0) {
			default:
			{
				ft_preferences_panel_sounds_update_sound_labels (self);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
}

static AdwPreferencesPage*
ft_preferences_panel_sounds_real_get_preferences_page (FtPreferencesPanel* base)
{
	FtPreferencesPanelSounds * self;
	AdwPreferencesPage* _tmp0_;
	AdwPreferencesPage* result;
	self = (FtPreferencesPanelSounds*) base;
	_tmp0_ = self->priv->page;
	result = _tmp0_;
	return result;
}

static void
ft_preferences_panel_sounds_real_dispose (GObject* base)
{
	FtPreferencesPanelSounds * self;
	self = (FtPreferencesPanelSounds*) base;
	if (self->priv->settings_changed_id != ((gulong) 0)) {
		GSettings* _tmp0_;
		_tmp0_ = self->priv->settings;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->settings_changed_id);
		self->priv->settings_changed_id = (gulong) 0;
	}
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = NULL;
	G_OBJECT_CLASS (ft_preferences_panel_sounds_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PREFERENCES_PANEL, FtPreferencesPanel));
}

FtPreferencesPanelSounds*
ft_preferences_panel_sounds_construct (GType object_type)
{
	FtPreferencesPanelSounds * self = NULL;
	self = (FtPreferencesPanelSounds*) ft_preferences_panel_construct (object_type);
	return self;
}

FtPreferencesPanelSounds*
ft_preferences_panel_sounds_new (void)
{
	return ft_preferences_panel_sounds_construct (FT_TYPE_PREFERENCES_PANEL_SOUNDS);
}

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

static void
_ft_preferences_panel_sounds_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                     const gchar* key,
                                                                     gpointer self)
{
	ft_preferences_panel_sounds_on_settings_changed ((FtPreferencesPanelSounds*) self, _sender, key);
}

static gboolean
_ft_preferences_panel_sounds_transform_active_to_visible_child_name_gbinding_transform_func (GBinding* binding,
                                                                                             GValue* from_value,
                                                                                             GValue* to_value,
                                                                                             gpointer self)
{
	gboolean result;
	result = ft_preferences_panel_sounds_transform_active_to_visible_child_name (binding, from_value, to_value);
	return result;
}

static GObject *
ft_preferences_panel_sounds_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtPreferencesPanelSounds * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	GtkSwitch* _tmp3_;
	GSettings* _tmp4_;
	gulong _tmp5_;
	GtkSwitch* _tmp6_;
	GtkStack* _tmp7_;
	parent_class = G_OBJECT_CLASS (ft_preferences_panel_sounds_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PREFERENCES_PANEL_SOUNDS, FtPreferencesPanelSounds);
	_tmp0_ = ft_get_settings ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp1_;
	_tmp2_ = self->priv->settings;
	_tmp3_ = self->priv->enable_switch;
	g_settings_bind (_tmp2_, "sounds", (GObject*) _tmp3_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp4_ = self->priv->settings;
	_tmp5_ = g_signal_connect_object (_tmp4_, "changed", (GCallback) _ft_preferences_panel_sounds_on_settings_changed_g_settings_changed, self, 0);
	self->priv->settings_changed_id = _tmp5_;
	_tmp6_ = self->priv->enable_switch;
	_tmp7_ = self->priv->stack;
	g_object_bind_property_with_closures ((GObject*) _tmp6_, "active", (GObject*) _tmp7_, "visible-child-name", G_BINDING_SYNC_CREATE, (GClosure*) g_cclosure_new ((GCallback) _ft_preferences_panel_sounds_transform_active_to_visible_child_name_gbinding_transform_func, NULL, (GClosureNotify) NULL), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	ft_preferences_panel_sounds_update_sound_labels (self);
	return obj;
}

static void
ft_preferences_panel_sounds_class_init (FtPreferencesPanelSoundsClass * klass,
                                        gpointer klass_data)
{
	ft_preferences_panel_sounds_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtPreferencesPanelSounds_private_offset);
	((FtPreferencesPanelClass *) klass)->get_preferences_page = (AdwPreferencesPage* (*) (FtPreferencesPanel*)) ft_preferences_panel_sounds_real_get_preferences_page;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_preferences_panel_sounds_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = ft_preferences_panel_sounds_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_preferences_panel_sounds_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/preferences/sounds/preferences-panel-sounds.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "page", FALSE, FtPreferencesPanelSounds_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelSoundsPrivate, page));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "enable_switch", FALSE, FtPreferencesPanelSounds_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelSoundsPrivate, enable_switch));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "stack", FALSE, FtPreferencesPanelSounds_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelSoundsPrivate, stack));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "pomodoro_finished_sound_label", FALSE, FtPreferencesPanelSounds_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelSoundsPrivate, pomodoro_finished_sound_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "break_finished_sound_label", FALSE, FtPreferencesPanelSounds_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelSoundsPrivate, break_finished_sound_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "background_sound_label", FALSE, FtPreferencesPanelSounds_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelSoundsPrivate, background_sound_label));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_pomodoro_finished_sound_activated", G_CALLBACK(_ft_preferences_panel_sounds_on_pomodoro_finished_sound_activated_adw_action_row_activated));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_break_finished_sound_activated", G_CALLBACK(_ft_preferences_panel_sounds_on_break_finished_sound_activated_adw_action_row_activated));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_background_sound_activated", G_CALLBACK(_ft_preferences_panel_sounds_on_background_sound_activated_adw_action_row_activated));
}

static void
ft_preferences_panel_sounds_instance_init (FtPreferencesPanelSounds * self,
                                           gpointer klass)
{
	self->priv = ft_preferences_panel_sounds_get_instance_private (self);
	self->priv->settings = NULL;
	self->priv->settings_changed_id = (gulong) 0;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_preferences_panel_sounds_finalize (GObject * obj)
{
	FtPreferencesPanelSounds * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PREFERENCES_PANEL_SOUNDS, FtPreferencesPanelSounds);
	_g_object_unref0 (self->priv->settings);
	G_OBJECT_CLASS (ft_preferences_panel_sounds_parent_class)->finalize (obj);
}

static GType
ft_preferences_panel_sounds_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtPreferencesPanelSoundsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_preferences_panel_sounds_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtPreferencesPanelSounds), 0, (GInstanceInitFunc) ft_preferences_panel_sounds_instance_init, NULL };
	GType ft_preferences_panel_sounds_type_id;
	ft_preferences_panel_sounds_type_id = g_type_register_static (FT_TYPE_PREFERENCES_PANEL, "FtPreferencesPanelSounds", &g_define_type_info, 0);
	FtPreferencesPanelSounds_private_offset = g_type_add_instance_private (ft_preferences_panel_sounds_type_id, sizeof (FtPreferencesPanelSoundsPrivate));
	return ft_preferences_panel_sounds_type_id;
}

GType
ft_preferences_panel_sounds_get_type (void)
{
	static volatile gsize ft_preferences_panel_sounds_type_id__once = 0;
	if (g_once_init_enter (&ft_preferences_panel_sounds_type_id__once)) {
		GType ft_preferences_panel_sounds_type_id;
		ft_preferences_panel_sounds_type_id = ft_preferences_panel_sounds_get_type_once ();
		g_once_init_leave (&ft_preferences_panel_sounds_type_id__once, ft_preferences_panel_sounds_type_id);
	}
	return ft_preferences_panel_sounds_type_id__once;
}

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

