/* sound-chooser-window.c generated by valac 0.56.19, the Vala compiler
 * generated from sound-chooser-window.vala, do not modify */

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

#include "ft_ui.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <adwaita.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include "ft_core.h"
#include <gio/gio.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.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_SOUND_CHOOSER_WINDOW_0_PROPERTY,
	FT_SOUND_CHOOSER_WINDOW_URI_PROPERTY,
	FT_SOUND_CHOOSER_WINDOW_EVENT_ID_PROPERTY,
	FT_SOUND_CHOOSER_WINDOW_VOLUME_PROPERTY,
	FT_SOUND_CHOOSER_WINDOW_NUM_PROPERTIES
};
static GParamSpec* ft_sound_chooser_window_properties[FT_SOUND_CHOOSER_WINDOW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block29Data Block29Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _FtSoundChooserWindowPrivate {
	gdouble _volume;
	AdwToastOverlay* toast_overlay;
	AdwPreferencesRow* none_row;
	AdwPreferencesRow* add_row;
	GtkCheckButton* radio_group;
	FtVolumeSlider* volume_slider;
	gchar* _uri;
	gchar* _event_id;
	GtkListBox* list_box;
	FtSound* sound;
	FtSoundManager* sound_manager;
	AdwToast* toast;
	gint next_position;
	GCancellable* cancellable;
};

struct _Block29Data {
	int _ref_count_;
	FtSoundChooserWindow* self;
	GtkFileDialog* file_dialog;
};

static gint FtSoundChooserWindow_private_offset;
static gpointer ft_sound_chooser_window_parent_class = NULL;

static void ft_sound_chooser_window_ensure_sound (FtSoundChooserWindow* self);
static void ft_sound_chooser_window_on_sound_error (FtSoundChooserWindow* self);
static void _ft_sound_chooser_window_on_sound_error_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self);
static void ft_sound_chooser_window_destroy_sound (FtSoundChooserWindow* self);
static inline gchar* ft_sound_chooser_window_get_row_uri (GtkWidget* row);
static inline void ft_sound_chooser_window_set_row_uri (GtkWidget* row,
                                          const gchar* uri);
static GtkWidget* ft_sound_chooser_window_get_row_by_uri (FtSoundChooserWindow* self,
                                                   const gchar* uri);
static GtkWidget* ft_sound_chooser_window_get_row_by_widget (FtSoundChooserWindow* self,
                                                      GtkWidget* widget);
static void ft_sound_chooser_window_update_active_radio (FtSoundChooserWindow* self);
static void ft_sound_chooser_window_update_volume_slider_sensitivity (FtSoundChooserWindow* self);
static void ft_sound_chooser_window_update_active_row (FtSoundChooserWindow* self);
static void ft_sound_chooser_window_add_preset_internal (FtSoundChooserWindow* self,
                                                  const gchar* uri,
                                                  const gchar* label,
                                                  gboolean removable);
static void ft_sound_chooser_window_on_radio_toggled (FtSoundChooserWindow* self,
                                               GtkCheckButton* radio);
static void _ft_sound_chooser_window_on_radio_toggled_gtk_check_button_toggled (GtkCheckButton* _sender,
                                                                         gpointer self);
static void ft_sound_chooser_window_on_remove_button_clicked (FtSoundChooserWindow* self,
                                                       GtkButton* button);
static void _ft_sound_chooser_window_on_remove_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                           gpointer self);
static void ft_sound_chooser_window_open_file_chooser (FtSoundChooserWindow* self);
static Block29Data* block29_data_ref (Block29Data* _data29_);
static void block29_data_unref (void * _userdata_);
static void __lambda84_ (Block29Data* _data29_,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda84__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void ft_sound_chooser_window_preview (FtSoundChooserWindow* self);
static void ft_sound_chooser_window_on_row_activated (FtSoundChooserWindow* self,
                                               GtkListBox* listbox,
                                               GtkListBoxRow* row);
static gboolean ft_sound_chooser_window_on_key_pressed (FtSoundChooserWindow* self,
                                                 GtkEventControllerKey* event_controller,
                                                 guint keyval,
                                                 guint keycode,
                                                 GdkModifierType state);
static gboolean _ft_sound_chooser_window_on_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                       guint keyval,
                                                                                       guint keycode,
                                                                                       GdkModifierType state,
                                                                                       gpointer self);
static void ft_sound_chooser_window_real_map (GtkWidget* base);
static void ft_sound_chooser_window_real_unmap (GtkWidget* base);
static void ft_sound_chooser_window_real_dispose (GObject* base);
static GObject * ft_sound_chooser_window_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void _ft_sound_chooser_window_on_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                           GtkListBoxRow* row,
                                                                           gpointer self);
static void ft_sound_chooser_window_finalize (GObject * obj);
static GType ft_sound_chooser_window_get_type_once (void);
static void _vala_ft_sound_chooser_window_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_ft_sound_chooser_window_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_sound_chooser_window_get_instance_private (FtSoundChooserWindow* self)
{
	return G_STRUCT_MEMBER_P (self, FtSoundChooserWindow_private_offset);
}

static void
_ft_sound_chooser_window_on_sound_error_g_object_notify (GObject* _sender,
                                                         GParamSpec* pspec,
                                                         gpointer self)
{
	ft_sound_chooser_window_on_sound_error ((FtSoundChooserWindow*) self);
}

static void
ft_sound_chooser_window_ensure_sound (FtSoundChooserWindow* self)
{
	FtSound* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	FtSound* _tmp7_;
	FtSound* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->sound;
	if (_tmp0_ != NULL) {
		return;
	}
	_tmp2_ = self->priv->_event_id;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		const gchar* _tmp3_;
		_tmp3_ = self->priv->_event_id;
		_tmp1_ = _tmp3_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		const gchar* _tmp4_;
		FtAlertSound* _tmp5_;
		_tmp4_ = self->priv->_event_id;
		_tmp5_ = ft_alert_sound_new (_tmp4_);
		_g_object_unref0 (self->priv->sound);
		self->priv->sound = (FtSound*) _tmp5_;
	} else {
		FtBackgroundSound* _tmp6_;
		_tmp6_ = ft_background_sound_new ();
		_g_object_unref0 (self->priv->sound);
		self->priv->sound = (FtSound*) _tmp6_;
	}
	_tmp7_ = self->priv->sound;
	g_signal_connect_object ((GObject*) _tmp7_, "notify::error", (GCallback) _ft_sound_chooser_window_on_sound_error_g_object_notify, self, 0);
	_tmp8_ = self->priv->sound;
	g_object_bind_property_with_closures ((GObject*) self, "volume", (GObject*) _tmp8_, "volume", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
}

static void
ft_sound_chooser_window_destroy_sound (FtSoundChooserWindow* self)
{
	FtSound* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->sound;
	if (_tmp0_ != NULL) {
		FtSound* _tmp1_;
		guint _tmp2_;
		GQuark _tmp3_;
		FtSound* _tmp4_;
		_tmp1_ = self->priv->sound;
		g_signal_parse_name ("notify::error", G_TYPE_OBJECT, &_tmp2_, &_tmp3_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, _tmp3_, NULL, (GCallback) _ft_sound_chooser_window_on_sound_error_g_object_notify, self);
		_tmp4_ = self->priv->sound;
		ft_sound_stop (_tmp4_);
		_g_object_unref0 (self->priv->sound);
		self->priv->sound = NULL;
	}
}

static inline gchar*
ft_sound_chooser_window_get_row_uri (GtkWidget* row)
{
	gconstpointer _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (row != NULL, NULL);
	_tmp0_ = g_object_get_data ((GObject*) row, "uri");
	_tmp1_ = g_strdup ((const gchar*) _tmp0_);
	result = _tmp1_;
	return result;
}

static inline void
ft_sound_chooser_window_set_row_uri (GtkWidget* row,
                                     const gchar* uri)
{
	gchar* _tmp0_;
	g_return_if_fail (row != NULL);
	g_return_if_fail (uri != NULL);
	_tmp0_ = g_strdup (uri);
	g_object_set_data_full ((GObject*) row, "uri", _tmp0_, g_free);
}

static GtkWidget*
ft_sound_chooser_window_get_row_by_uri (FtSoundChooserWindow* self,
                                        const gchar* uri)
{
	GtkWidget* row = NULL;
	AdwPreferencesRow* _tmp0_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = self->priv->none_row;
	row = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget);
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gboolean _tmp5_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp1_ = row;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = row;
		_tmp3_ = ft_sound_chooser_window_get_row_uri (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_strcmp0 (_tmp4_, uri) == 0;
		_g_free0 (_tmp4_);
		if (_tmp5_) {
			GtkWidget* _tmp6_;
			_tmp6_ = row;
			result = _tmp6_;
			return result;
		}
		_tmp7_ = row;
		_tmp8_ = gtk_widget_get_next_sibling (_tmp7_);
		row = _tmp8_;
	}
	result = NULL;
	return result;
}

static GtkWidget*
ft_sound_chooser_window_get_row_by_widget (FtSoundChooserWindow* self,
                                           GtkWidget* widget)
{
	GtkWidget* row = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (widget != NULL, NULL);
	_tmp0_ = gtk_widget_get_parent (widget);
	_tmp1_ = _tmp0_;
	row = _tmp1_;
	while (TRUE) {
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		_tmp2_ = row;
		if (!(_tmp2_ != NULL)) {
			break;
		}
		_tmp3_ = row;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, adw_action_row_get_type ())) {
			GtkWidget* _tmp4_;
			_tmp4_ = row;
			result = _tmp4_;
			return result;
		}
		_tmp5_ = row;
		_tmp6_ = gtk_widget_get_parent (_tmp5_);
		_tmp7_ = _tmp6_;
		row = _tmp7_;
	}
	result = NULL;
	return result;
}

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

static void
ft_sound_chooser_window_update_active_radio (FtSoundChooserWindow* self)
{
	g_return_if_fail (self != NULL);
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				AdwActionRow* row = NULL;
				GtkListBox* _tmp2_;
				GtkListBoxRow* _tmp3_;
				AdwActionRow* _tmp4_;
				GtkCheckButton* radio = NULL;
				AdwActionRow* _tmp5_;
				GtkWidget* _tmp6_;
				GtkWidget* _tmp7_;
				GtkCheckButton* _tmp8_;
				GtkCheckButton* _tmp9_;
				AdwActionRow* _tmp10_;
				gchar* _tmp11_;
				gchar* _tmp12_;
				const gchar* _tmp13_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = index;
					index = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(index < self->priv->next_position)) {
					break;
				}
				_tmp2_ = self->priv->list_box;
				_tmp3_ = gtk_list_box_get_row_at_index (_tmp2_, index);
				_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, adw_action_row_get_type (), AdwActionRow));
				row = _tmp4_;
				_tmp5_ = row;
				_tmp6_ = adw_action_row_get_activatable_widget (_tmp5_);
				_tmp7_ = _tmp6_;
				_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_check_button_get_type (), GtkCheckButton));
				radio = _tmp8_;
				_tmp9_ = radio;
				_tmp10_ = row;
				_tmp11_ = ft_sound_chooser_window_get_row_uri ((GtkWidget*) _tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = self->priv->_uri;
				gtk_check_button_set_active (_tmp9_, g_strcmp0 (_tmp12_, _tmp13_) == 0);
				_g_free0 (_tmp12_);
				_g_object_unref0 (radio);
				_g_object_unref0 (row);
			}
		}
	}
}

static void
ft_sound_chooser_window_update_volume_slider_sensitivity (FtSoundChooserWindow* self)
{
	FtVolumeSlider* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	const gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->volume_slider;
	_tmp1_ = gtk_widget_get_parent ((GtkWidget*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->_uri;
	gtk_widget_set_sensitive (_tmp2_, g_strcmp0 (_tmp3_, "") != 0);
}

static void
ft_sound_chooser_window_update_active_row (FtSoundChooserWindow* self)
{
	GtkWidget* existing_row = NULL;
	const gchar* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	FtSound* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_uri;
	_tmp1_ = ft_sound_chooser_window_get_row_by_uri (self, _tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	existing_row = _tmp2_;
	_tmp3_ = existing_row;
	if (_tmp3_ == NULL) {
		gchar* label = NULL;
		const gchar* _tmp4_;
		GFile* _tmp5_;
		GFile* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		_tmp4_ = self->priv->_uri;
		_tmp5_ = g_file_new_for_uri (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_file_get_basename (_tmp6_);
		_tmp8_ = _tmp7_;
		_g_object_unref0 (_tmp6_);
		label = _tmp8_;
		_tmp9_ = self->priv->_uri;
		_tmp10_ = label;
		ft_sound_chooser_window_add_preset_internal (self, _tmp9_, _tmp10_, TRUE);
		_g_free0 (label);
	} else {
		ft_sound_chooser_window_update_active_radio (self);
	}
	ft_sound_chooser_window_update_volume_slider_sensitivity (self);
	_tmp11_ = self->priv->sound;
	if (_tmp11_ != NULL) {
		FtSound* _tmp12_;
		_tmp12_ = self->priv->sound;
		ft_sound_stop (_tmp12_);
	}
	_g_object_unref0 (existing_row);
}

static void
_ft_sound_chooser_window_on_radio_toggled_gtk_check_button_toggled (GtkCheckButton* _sender,
                                                                    gpointer self)
{
	ft_sound_chooser_window_on_radio_toggled ((FtSoundChooserWindow*) self, _sender);
}

static void
_ft_sound_chooser_window_on_remove_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                      gpointer self)
{
	ft_sound_chooser_window_on_remove_button_clicked ((FtSoundChooserWindow*) self, _sender);
}

static void
ft_sound_chooser_window_add_preset_internal (FtSoundChooserWindow* self,
                                             const gchar* uri,
                                             const gchar* label,
                                             gboolean removable)
{
	GtkCheckButton* radio = NULL;
	GtkCheckButton* _tmp0_;
	GtkCheckButton* _tmp1_;
	GtkCheckButton* _tmp2_;
	GtkCheckButton* _tmp3_;
	GtkCheckButton* _tmp4_;
	const gchar* _tmp5_;
	GtkCheckButton* _tmp6_;
	AdwActionRow* row = NULL;
	AdwActionRow* _tmp7_;
	AdwActionRow* _tmp8_;
	AdwActionRow* _tmp9_;
	AdwActionRow* _tmp10_;
	AdwActionRow* _tmp11_;
	GtkCheckButton* _tmp12_;
	AdwActionRow* _tmp13_;
	AdwActionRow* _tmp21_;
	GtkCheckButton* _tmp22_;
	GtkListBox* _tmp23_;
	AdwActionRow* _tmp24_;
	gint _tmp25_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	g_return_if_fail (label != NULL);
	_tmp0_ = (GtkCheckButton*) gtk_check_button_new ();
	g_object_ref_sink (_tmp0_);
	radio = _tmp0_;
	_tmp1_ = radio;
	gtk_widget_set_valign ((GtkWidget*) _tmp1_, GTK_ALIGN_CENTER);
	_tmp2_ = radio;
	_tmp3_ = self->priv->radio_group;
	gtk_check_button_set_group (_tmp2_, _tmp3_);
	_tmp4_ = radio;
	_tmp5_ = self->priv->_uri;
	gtk_check_button_set_active (_tmp4_, g_strcmp0 (_tmp5_, uri) == 0);
	_tmp6_ = radio;
	g_signal_connect_object (_tmp6_, "toggled", (GCallback) _ft_sound_chooser_window_on_radio_toggled_gtk_check_button_toggled, self, 0);
	_tmp7_ = (AdwActionRow*) adw_action_row_new ();
	g_object_ref_sink (_tmp7_);
	row = _tmp7_;
	_tmp8_ = row;
	adw_preferences_row_set_use_markup ((AdwPreferencesRow*) _tmp8_, FALSE);
	_tmp9_ = row;
	adw_preferences_row_set_title ((AdwPreferencesRow*) _tmp9_, label);
	_tmp10_ = row;
	gtk_list_box_row_set_activatable ((GtkListBoxRow*) _tmp10_, TRUE);
	_tmp11_ = row;
	_tmp12_ = radio;
	adw_action_row_set_activatable_widget (_tmp11_, (GtkWidget*) _tmp12_);
	_tmp13_ = row;
	ft_sound_chooser_window_set_row_uri ((GtkWidget*) _tmp13_, uri);
	if (removable) {
		GtkButton* remove_button = NULL;
		GtkButton* _tmp14_;
		GtkButton* _tmp15_;
		GtkButton* _tmp16_;
		GtkButton* _tmp17_;
		GtkButton* _tmp18_;
		AdwActionRow* _tmp19_;
		GtkButton* _tmp20_;
		_tmp14_ = (GtkButton*) gtk_button_new ();
		g_object_ref_sink (_tmp14_);
		remove_button = _tmp14_;
		_tmp15_ = remove_button;
		gtk_button_set_icon_name (_tmp15_, "window-close-symbolic");
		_tmp16_ = remove_button;
		gtk_widget_set_valign ((GtkWidget*) _tmp16_, GTK_ALIGN_CENTER);
		_tmp17_ = remove_button;
		gtk_widget_add_css_class ((GtkWidget*) _tmp17_, "flat");
		_tmp18_ = remove_button;
		g_signal_connect_object (_tmp18_, "clicked", (GCallback) _ft_sound_chooser_window_on_remove_button_clicked_gtk_button_clicked, self, 0);
		_tmp19_ = row;
		_tmp20_ = remove_button;
		adw_action_row_add_suffix (_tmp19_, (GtkWidget*) _tmp20_);
		_g_object_unref0 (remove_button);
	}
	_tmp21_ = row;
	_tmp22_ = radio;
	adw_action_row_add_suffix (_tmp21_, (GtkWidget*) _tmp22_);
	_tmp23_ = self->priv->list_box;
	_tmp24_ = row;
	gtk_list_box_insert (_tmp23_, (GtkWidget*) _tmp24_, self->priv->next_position);
	_tmp25_ = self->priv->next_position;
	self->priv->next_position = _tmp25_ + 1;
	_g_object_unref0 (row);
	_g_object_unref0 (radio);
}

static Block29Data*
block29_data_ref (Block29Data* _data29_)
{
	g_atomic_int_inc (&_data29_->_ref_count_);
	return _data29_;
}

static void
block29_data_unref (void * _userdata_)
{
	Block29Data* _data29_;
	_data29_ = (Block29Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data29_->_ref_count_)) {
		FtSoundChooserWindow* self;
		self = _data29_->self;
		_g_object_unref0 (_data29_->file_dialog);
		_g_object_unref0 (self);
		g_slice_free (Block29Data, _data29_);
	}
}

static void
__lambda84_ (Block29Data* _data29_,
             GObject* obj,
             GAsyncResult* res)
{
	FtSoundChooserWindow* self;
	GFile* file = NULL;
	gchar* _tmp5_ = NULL;
	GFile* _tmp6_;
	gchar* uri = NULL;
	gchar* _tmp10_;
	GtkWidget* existing_row = NULL;
	const gchar* _tmp11_;
	GtkWidget* _tmp12_;
	GtkWidget* _tmp13_;
	gboolean _tmp14_ = FALSE;
	GtkWidget* _tmp15_;
	const gchar* _tmp21_;
	GError* _inner_error0_ = NULL;
	self = _data29_->self;
	g_return_if_fail (res != NULL);
	file = NULL;
	{
		GFile* _tmp0_ = NULL;
		GFile* _tmp1_;
		GFile* _tmp2_;
		_tmp1_ = gtk_file_dialog_open_finish (_data29_->file_dialog, res, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_object_unref0 (file);
		file = _tmp2_;
		_g_object_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		AdwToast* _tmp3_;
		g_clear_error (&_inner_error0_);
		_tmp3_ = self->priv->toast;
		if (_tmp3_ != NULL) {
			AdwToast* _tmp4_;
			_tmp4_ = self->priv->toast;
			adw_toast_dismiss (_tmp4_);
		}
		_g_object_unref0 (file);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_tmp6_ = file;
	if (_tmp6_ != NULL) {
		GFile* _tmp7_;
		gchar* _tmp8_;
		_tmp7_ = file;
		_tmp8_ = g_file_get_uri (_tmp7_);
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp8_;
	} else {
		gchar* _tmp9_;
		_tmp9_ = g_strdup ("");
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp9_;
	}
	_tmp10_ = _tmp5_;
	_tmp5_ = NULL;
	uri = _tmp10_;
	_tmp11_ = uri;
	_tmp12_ = ft_sound_chooser_window_get_row_by_uri (self, _tmp11_);
	_tmp13_ = _g_object_ref0 (_tmp12_);
	existing_row = _tmp13_;
	_tmp15_ = existing_row;
	if (_tmp15_ == NULL) {
		GFile* _tmp16_;
		_tmp16_ = file;
		_tmp14_ = _tmp16_ != NULL;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		const gchar* _tmp17_;
		GFile* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		_tmp17_ = uri;
		_tmp18_ = file;
		_tmp19_ = g_file_get_basename (_tmp18_);
		_tmp20_ = _tmp19_;
		ft_sound_chooser_window_add_preset_internal (self, _tmp17_, _tmp20_, TRUE);
		_g_free0 (_tmp20_);
	}
	_tmp21_ = uri;
	ft_sound_chooser_window_set_uri (self, _tmp21_);
	_g_object_unref0 (existing_row);
	_g_free0 (uri);
	_g_free0 (_tmp5_);
	_g_object_unref0 (file);
}

static void
___lambda84__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda84_ (self, source_object, res);
	block29_data_unref (self);
}

static void
ft_sound_chooser_window_open_file_chooser (FtSoundChooserWindow* self)
{
	Block29Data* _data29_;
	GCancellable* _tmp0_;
	GCancellable* _tmp2_;
	GtkFileFilter* file_filter = NULL;
	GtkFileFilter* _tmp3_;
	gint _tmp4_ = 0;
	gchar** _tmp5_;
	GtkFileDialog* _tmp9_;
	GtkFileFilter* _tmp10_;
	GCancellable* _tmp11_;
	g_return_if_fail (self != NULL);
	_data29_ = g_slice_new0 (Block29Data);
	_data29_->_ref_count_ = 1;
	_data29_->self = g_object_ref (self);
	ft_sound_chooser_window_ensure_sound (self);
	_tmp0_ = self->priv->cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		_tmp1_ = self->priv->cancellable;
		g_cancellable_cancel (_tmp1_);
	}
	_tmp2_ = g_cancellable_new ();
	_g_object_unref0 (self->priv->cancellable);
	self->priv->cancellable = _tmp2_;
	_tmp3_ = gtk_file_filter_new ();
	file_filter = _tmp3_;
	_tmp5_ = ft_sound_player_get_supported_mime_types (&_tmp4_);
	{
		gchar** mime_type_collection = NULL;
		gint mime_type_collection_length1 = 0;
		gint _mime_type_collection_size_ = 0;
		gint mime_type_it = 0;
		mime_type_collection = _tmp5_;
		mime_type_collection_length1 = _tmp4_;
		for (mime_type_it = 0; mime_type_it < mime_type_collection_length1; mime_type_it = mime_type_it + 1) {
			gchar* _tmp6_;
			gchar* mime_type = NULL;
			_tmp6_ = g_strdup (mime_type_collection[mime_type_it]);
			mime_type = _tmp6_;
			{
				GtkFileFilter* _tmp7_;
				const gchar* _tmp8_;
				_tmp7_ = file_filter;
				_tmp8_ = mime_type;
				gtk_file_filter_add_mime_type (_tmp7_, _tmp8_);
				_g_free0 (mime_type);
			}
		}
		mime_type_collection = (_vala_array_free (mime_type_collection, mime_type_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp9_ = gtk_file_dialog_new ();
	_data29_->file_dialog = _tmp9_;
	gtk_file_dialog_set_title (_data29_->file_dialog, _ ("Select Custom Sound"));
	gtk_file_dialog_set_modal (_data29_->file_dialog, TRUE);
	gtk_file_dialog_set_accept_label (_data29_->file_dialog, _ ("_Select"));
	_tmp10_ = file_filter;
	gtk_file_dialog_set_default_filter (_data29_->file_dialog, _tmp10_);
	_tmp11_ = self->priv->cancellable;
	gtk_file_dialog_open (_data29_->file_dialog, (GtkWindow*) self, _tmp11_, ___lambda84__gasync_ready_callback, block29_data_ref (_data29_));
	_g_object_unref0 (file_filter);
	block29_data_unref (_data29_);
	_data29_ = NULL;
}

static void
ft_sound_chooser_window_preview (FtSoundChooserWindow* self)
{
	AdwToast* _tmp0_;
	FtSound* _tmp2_;
	const gchar* _tmp3_;
	FtSound* _tmp4_;
	GError* _tmp5_;
	GError* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->toast;
	if (_tmp0_ != NULL) {
		AdwToast* _tmp1_;
		_tmp1_ = self->priv->toast;
		adw_toast_dismiss (_tmp1_);
		_g_object_unref0 (self->priv->toast);
		self->priv->toast = NULL;
	}
	ft_sound_chooser_window_ensure_sound (self);
	_tmp2_ = self->priv->sound;
	_tmp3_ = self->priv->_uri;
	ft_sound_set_uri (_tmp2_, _tmp3_);
	_tmp4_ = self->priv->sound;
	_tmp5_ = ft_sound_get_error (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_ == NULL) {
		FtSound* _tmp7_;
		_tmp7_ = self->priv->sound;
		ft_sound_play (_tmp7_);
	}
}

static void
ft_sound_chooser_window_on_row_activated (FtSoundChooserWindow* self,
                                          GtkListBox* listbox,
                                          GtkListBoxRow* row)
{
	AdwPreferencesRow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (listbox != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = self->priv->add_row;
	if (row == G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_list_box_row_get_type (), GtkListBoxRow)) {
		ft_sound_chooser_window_open_file_chooser (self);
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = ft_sound_chooser_window_get_row_uri ((GtkWidget*) row);
		_tmp2_ = _tmp1_;
		ft_sound_chooser_window_set_uri (self, _tmp2_);
		_g_free0 (_tmp2_);
		ft_sound_chooser_window_preview (self);
	}
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static void
ft_sound_chooser_window_on_sound_error (FtSoundChooserWindow* self)
{
	GError* _error_ = NULL;
	FtSound* _tmp0_;
	GError* _tmp1_;
	GError* _tmp2_;
	GError* _tmp3_;
	AdwToast* _tmp4_;
	GError* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->sound;
	_tmp1_ = ft_sound_get_error (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_error_copy0 (_tmp2_);
	_error_ = _tmp3_;
	_tmp4_ = self->priv->toast;
	if (_tmp4_ != NULL) {
		AdwToast* _tmp5_;
		_tmp5_ = self->priv->toast;
		adw_toast_dismiss (_tmp5_);
		_g_object_unref0 (self->priv->toast);
		self->priv->toast = NULL;
	}
	_tmp6_ = _error_;
	if (_tmp6_ != NULL) {
		GError* _tmp7_;
		const gchar* _tmp8_;
		AdwToast* _tmp9_;
		AdwToastOverlay* _tmp10_;
		AdwToast* _tmp11_;
		AdwToast* _tmp12_;
		_tmp7_ = _error_;
		_tmp8_ = _tmp7_->message;
		_tmp9_ = adw_toast_new (_tmp8_);
		_g_object_unref0 (self->priv->toast);
		self->priv->toast = _tmp9_;
		_tmp10_ = self->priv->toast_overlay;
		_tmp11_ = self->priv->toast;
		_tmp12_ = _g_object_ref0 (_tmp11_);
		adw_toast_overlay_add_toast (_tmp10_, _tmp12_);
	}
	_g_error_free0 (_error_);
}

static void
ft_sound_chooser_window_on_remove_button_clicked (FtSoundChooserWindow* self,
                                                  GtkButton* button)
{
	GtkWidget* row = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = ft_sound_chooser_window_get_row_by_widget (self, (GtkWidget*) button);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	row = _tmp1_;
	_tmp2_ = ft_sound_chooser_window_get_row_uri (row);
	_tmp3_ = _tmp2_;
	ft_sound_chooser_window_remove_preset (self, _tmp3_);
	_g_free0 (_tmp3_);
	_g_object_unref0 (row);
}

static void
ft_sound_chooser_window_on_radio_toggled (FtSoundChooserWindow* self,
                                          GtkCheckButton* radio)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (radio != NULL);
	_tmp0_ = gtk_check_button_get_active (radio);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		GtkWidget* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp2_ = ft_sound_chooser_window_get_row_by_widget (self, (GtkWidget*) radio);
		_tmp3_ = ft_sound_chooser_window_get_row_uri (_tmp2_);
		_tmp4_ = _tmp3_;
		ft_sound_chooser_window_set_uri (self, _tmp4_);
		_g_free0 (_tmp4_);
	}
}

static gboolean
ft_sound_chooser_window_on_key_pressed (FtSoundChooserWindow* self,
                                        GtkEventControllerKey* event_controller,
                                        guint keyval,
                                        guint keycode,
                                        GdkModifierType state)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (event_controller != NULL, FALSE);
	switch (keyval) {
		case GDK_KEY_Escape:
		{
			gtk_window_close ((GtkWindow*) self);
			result = TRUE;
			return result;
		}
		default:
		break;
	}
	result = FALSE;
	return result;
}

static gboolean
_ft_sound_chooser_window_on_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                              guint keyval,
                                                                              guint keycode,
                                                                              GdkModifierType state,
                                                                              gpointer self)
{
	gboolean result;
	result = ft_sound_chooser_window_on_key_pressed ((FtSoundChooserWindow*) self, _sender, keyval, keycode, state);
	return result;
}

void
ft_sound_chooser_window_add_preset (FtSoundChooserWindow* self,
                                    const gchar* uri,
                                    const gchar* label)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	g_return_if_fail (label != NULL);
	ft_sound_chooser_window_add_preset_internal (self, uri, label, FALSE);
}

void
ft_sound_chooser_window_remove_preset (FtSoundChooserWindow* self,
                                       const gchar* uri)
{
	GtkWidget* row = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	const gchar* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	_tmp0_ = ft_sound_chooser_window_get_row_by_uri (self, uri);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	row = _tmp1_;
	_tmp2_ = row;
	if (_tmp2_ != NULL) {
		GtkListBox* _tmp3_;
		GtkWidget* _tmp4_;
		gint _tmp5_;
		_tmp3_ = self->priv->list_box;
		_tmp4_ = row;
		gtk_list_box_remove (_tmp3_, _tmp4_);
		_tmp5_ = self->priv->next_position;
		self->priv->next_position = _tmp5_ - 1;
	}
	_tmp6_ = self->priv->_uri;
	if (g_strcmp0 (_tmp6_, uri) == 0) {
		ft_sound_chooser_window_set_uri (self, "");
	}
	_g_object_unref0 (row);
}

static void
ft_sound_chooser_window_real_map (GtkWidget* base)
{
	FtSoundChooserWindow * self;
	FtSoundManager* _tmp0_;
	self = (FtSoundChooserWindow*) base;
	GTK_WIDGET_CLASS (ft_sound_chooser_window_parent_class)->map ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_window_get_type (), AdwWindow));
	_tmp0_ = self->priv->sound_manager;
	ft_sound_manager_inhibit_background_sound (_tmp0_);
}

static void
ft_sound_chooser_window_real_unmap (GtkWidget* base)
{
	FtSoundChooserWindow * self;
	FtSoundManager* _tmp0_;
	self = (FtSoundChooserWindow*) base;
	GTK_WIDGET_CLASS (ft_sound_chooser_window_parent_class)->unmap ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_window_get_type (), AdwWindow));
	ft_sound_chooser_window_destroy_sound (self);
	_tmp0_ = self->priv->sound_manager;
	ft_sound_manager_uninhibit_background_sound (_tmp0_);
}

static void
ft_sound_chooser_window_real_dispose (GObject* base)
{
	FtSoundChooserWindow * self;
	GCancellable* _tmp0_;
	self = (FtSoundChooserWindow*) base;
	_tmp0_ = self->priv->cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		_tmp1_ = self->priv->cancellable;
		g_cancellable_cancel (_tmp1_);
		_g_object_unref0 (self->priv->cancellable);
		self->priv->cancellable = NULL;
	}
	self->priv->list_box = NULL;
	_g_object_unref0 (self->priv->sound_manager);
	self->priv->sound_manager = NULL;
	G_OBJECT_CLASS (ft_sound_chooser_window_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_window_get_type (), AdwWindow));
}

FtSoundChooserWindow*
ft_sound_chooser_window_construct (GType object_type)
{
	FtSoundChooserWindow * self = NULL;
	self = (FtSoundChooserWindow*) g_object_new (object_type, NULL);
	return self;
}

FtSoundChooserWindow*
ft_sound_chooser_window_new (void)
{
	return ft_sound_chooser_window_construct (FT_TYPE_SOUND_CHOOSER_WINDOW);
}

const gchar*
ft_sound_chooser_window_get_uri (FtSoundChooserWindow* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_uri;
	result = _tmp0_;
	return result;
}

void
ft_sound_chooser_window_set_uri (FtSoundChooserWindow* self,
                                 const gchar* value)
{
	const gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_uri;
	if (g_strcmp0 (_tmp0_, value) != 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (value);
		_g_free0 (self->priv->_uri);
		self->priv->_uri = _tmp1_;
		ft_sound_chooser_window_update_active_row (self);
		g_object_notify ((GObject*) self, "uri");
	}
}

const gchar*
ft_sound_chooser_window_get_event_id (FtSoundChooserWindow* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_event_id;
	result = _tmp0_;
	return result;
}

void
ft_sound_chooser_window_set_event_id (FtSoundChooserWindow* self,
                                      const gchar* value)
{
	const gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_event_id;
	if (g_strcmp0 (_tmp0_, value) != 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (value);
		_g_free0 (self->priv->_event_id);
		self->priv->_event_id = _tmp1_;
		ft_sound_chooser_window_destroy_sound (self);
		ft_sound_chooser_window_ensure_sound (self);
		g_object_notify ((GObject*) self, "event-id");
	}
}

gdouble
ft_sound_chooser_window_get_volume (FtSoundChooserWindow* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	result = self->priv->_volume;
	return result;
}

void
ft_sound_chooser_window_set_volume (FtSoundChooserWindow* self,
                                    gdouble value)
{
	gdouble old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_sound_chooser_window_get_volume (self);
	if (old_value != value) {
		self->priv->_volume = value;
		g_object_notify_by_pspec ((GObject *) self, ft_sound_chooser_window_properties[FT_SOUND_CHOOSER_WINDOW_VOLUME_PROPERTY]);
	}
}

static void
_ft_sound_chooser_window_on_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                      GtkListBoxRow* row,
                                                                      gpointer self)
{
	ft_sound_chooser_window_on_row_activated ((FtSoundChooserWindow*) self, _sender, row);
}

static GObject *
ft_sound_chooser_window_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtSoundChooserWindow * self;
	FtSoundManager* _tmp0_;
	AdwPreferencesRow* _tmp1_;
	gchar* _tmp2_;
	AdwPreferencesRow* _tmp3_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp5_;
	GtkListBox* _tmp6_;
	GtkListBox* _tmp7_;
	FtVolumeSlider* _tmp8_;
	parent_class = G_OBJECT_CLASS (ft_sound_chooser_window_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_SOUND_CHOOSER_WINDOW, FtSoundChooserWindow);
	_tmp0_ = ft_sound_manager_new ();
	_g_object_unref0 (self->priv->sound_manager);
	self->priv->sound_manager = _tmp0_;
	_tmp1_ = self->priv->none_row;
	_tmp2_ = g_strdup ("");
	g_object_set_data_full ((GObject*) _tmp1_, "uri", _tmp2_, g_free);
	_tmp3_ = self->priv->none_row;
	_tmp4_ = gtk_widget_get_parent ((GtkWidget*) _tmp3_);
	_tmp5_ = _tmp4_;
	self->priv->list_box = G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_list_box_get_type (), GtkListBox);
	_tmp6_ = self->priv->list_box;
	gtk_list_box_set_activate_on_single_click (_tmp6_, TRUE);
	_tmp7_ = self->priv->list_box;
	g_signal_connect_object (_tmp7_, "row-activated", (GCallback) _ft_sound_chooser_window_on_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp8_ = self->priv->volume_slider;
	g_object_bind_property_with_closures ((GObject*) self, "volume", (GObject*) _tmp8_, "value", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	ft_sound_chooser_window_update_volume_slider_sensitivity (self);
	return obj;
}

static void
ft_sound_chooser_window_class_init (FtSoundChooserWindowClass * klass,
                                    gpointer klass_data)
{
	ft_sound_chooser_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtSoundChooserWindow_private_offset);
	((GtkWidgetClass *) klass)->map = (void (*) (GtkWidget*)) ft_sound_chooser_window_real_map;
	((GtkWidgetClass *) klass)->unmap = (void (*) (GtkWidget*)) ft_sound_chooser_window_real_unmap;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_sound_chooser_window_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_sound_chooser_window_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_sound_chooser_window_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_sound_chooser_window_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_sound_chooser_window_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SOUND_CHOOSER_WINDOW_URI_PROPERTY, ft_sound_chooser_window_properties[FT_SOUND_CHOOSER_WINDOW_URI_PROPERTY] = g_param_spec_string ("uri", "uri", "uri", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SOUND_CHOOSER_WINDOW_EVENT_ID_PROPERTY, ft_sound_chooser_window_properties[FT_SOUND_CHOOSER_WINDOW_EVENT_ID_PROPERTY] = g_param_spec_string ("event-id", "event-id", "event-id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SOUND_CHOOSER_WINDOW_VOLUME_PROPERTY, ft_sound_chooser_window_properties[FT_SOUND_CHOOSER_WINDOW_VOLUME_PROPERTY] = g_param_spec_double ("volume", "volume", "volume", -G_MAXDOUBLE, G_MAXDOUBLE, 1.0, 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/sounds/sound-chooser-window.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "toast_overlay", FALSE, FtSoundChooserWindow_private_offset + G_STRUCT_OFFSET (FtSoundChooserWindowPrivate, toast_overlay));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "none_row", FALSE, FtSoundChooserWindow_private_offset + G_STRUCT_OFFSET (FtSoundChooserWindowPrivate, none_row));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "add_row", FALSE, FtSoundChooserWindow_private_offset + G_STRUCT_OFFSET (FtSoundChooserWindowPrivate, add_row));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "radio_group", FALSE, FtSoundChooserWindow_private_offset + G_STRUCT_OFFSET (FtSoundChooserWindowPrivate, radio_group));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "volume_slider", FALSE, FtSoundChooserWindow_private_offset + G_STRUCT_OFFSET (FtSoundChooserWindowPrivate, volume_slider));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_radio_toggled", G_CALLBACK(_ft_sound_chooser_window_on_radio_toggled_gtk_check_button_toggled));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_key_pressed", G_CALLBACK(_ft_sound_chooser_window_on_key_pressed_gtk_event_controller_key_key_pressed));
}

static void
ft_sound_chooser_window_instance_init (FtSoundChooserWindow * self,
                                       gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	self->priv = ft_sound_chooser_window_get_instance_private (self);
	self->priv->_volume = 1.0;
	_tmp0_ = g_strdup ("");
	self->priv->_uri = _tmp0_;
	_tmp1_ = g_strdup ("");
	self->priv->_event_id = _tmp1_;
	self->priv->list_box = NULL;
	self->priv->sound = NULL;
	self->priv->sound_manager = NULL;
	self->priv->toast = NULL;
	self->priv->next_position = 1;
	self->priv->cancellable = NULL;
	g_type_ensure (FT_TYPE_VOLUME_SLIDER);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_sound_chooser_window_finalize (GObject * obj)
{
	FtSoundChooserWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_SOUND_CHOOSER_WINDOW, FtSoundChooserWindow);
	_g_free0 (self->priv->_uri);
	_g_free0 (self->priv->_event_id);
	_g_object_unref0 (self->priv->sound);
	_g_object_unref0 (self->priv->sound_manager);
	_g_object_unref0 (self->priv->toast);
	_g_object_unref0 (self->priv->cancellable);
	G_OBJECT_CLASS (ft_sound_chooser_window_parent_class)->finalize (obj);
}

static GType
ft_sound_chooser_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtSoundChooserWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_sound_chooser_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtSoundChooserWindow), 0, (GInstanceInitFunc) ft_sound_chooser_window_instance_init, NULL };
	GType ft_sound_chooser_window_type_id;
	ft_sound_chooser_window_type_id = g_type_register_static (adw_window_get_type (), "FtSoundChooserWindow", &g_define_type_info, 0);
	FtSoundChooserWindow_private_offset = g_type_add_instance_private (ft_sound_chooser_window_type_id, sizeof (FtSoundChooserWindowPrivate));
	return ft_sound_chooser_window_type_id;
}

GType
ft_sound_chooser_window_get_type (void)
{
	static volatile gsize ft_sound_chooser_window_type_id__once = 0;
	if (g_once_init_enter (&ft_sound_chooser_window_type_id__once)) {
		GType ft_sound_chooser_window_type_id;
		ft_sound_chooser_window_type_id = ft_sound_chooser_window_get_type_once ();
		g_once_init_leave (&ft_sound_chooser_window_type_id__once, ft_sound_chooser_window_type_id);
	}
	return ft_sound_chooser_window_type_id__once;
}

static void
_vala_ft_sound_chooser_window_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	FtSoundChooserWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_SOUND_CHOOSER_WINDOW, FtSoundChooserWindow);
	switch (property_id) {
		case FT_SOUND_CHOOSER_WINDOW_URI_PROPERTY:
		g_value_set_string (value, ft_sound_chooser_window_get_uri (self));
		break;
		case FT_SOUND_CHOOSER_WINDOW_EVENT_ID_PROPERTY:
		g_value_set_string (value, ft_sound_chooser_window_get_event_id (self));
		break;
		case FT_SOUND_CHOOSER_WINDOW_VOLUME_PROPERTY:
		g_value_set_double (value, ft_sound_chooser_window_get_volume (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_sound_chooser_window_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	FtSoundChooserWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_SOUND_CHOOSER_WINDOW, FtSoundChooserWindow);
	switch (property_id) {
		case FT_SOUND_CHOOSER_WINDOW_URI_PROPERTY:
		ft_sound_chooser_window_set_uri (self, g_value_get_string (value));
		break;
		case FT_SOUND_CHOOSER_WINDOW_EVENT_ID_PROPERTY:
		ft_sound_chooser_window_set_event_id (self, g_value_get_string (value));
		break;
		case FT_SOUND_CHOOSER_WINDOW_VOLUME_PROPERTY:
		ft_sound_chooser_window_set_volume (self, g_value_get_double (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

