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

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

#include "ft_ui.h"
#include <adwaita.h>
#include <gio/gio.h>
#include "ft_core.h"
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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_PREFERENCES_PANEL_NOTIFICATIONS_0_PROPERTY,
	FT_PREFERENCES_PANEL_NOTIFICATIONS_NUM_PROPERTIES
};
static GParamSpec* ft_preferences_panel_notifications_properties[FT_PREFERENCES_PANEL_NOTIFICATIONS_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))

struct _FtPreferencesPanelNotificationsPrivate {
	AdwPreferencesPage* page;
	AdwSwitchRow* announce_about_to_end_switchrow;
	AdwSwitchRow* screen_overlay_switchrow;
	AdwComboRow* screen_overlay_lock_delay_comborow;
	AdwComboRow* screen_overlay_reopen_delay_comborow;
	GSettings* settings;
	FtIdleMonitor* idle_monitor;
};

static gint FtPreferencesPanelNotifications_private_offset;
static gpointer ft_preferences_panel_notifications_parent_class = NULL;

static GtkStringList* ft_preferences_panel_notifications_create_idle_delay_model (FtPreferencesPanelNotifications* self);
static gboolean ft_preferences_panel_notifications_idle_delay_get_mapping (GValue* value,
                                                                    GVariant* variant,
                                                                    void* user_data);
static GVariant* ft_preferences_panel_notifications_idle_delay_set_mapping (GValue* value,
                                                                     const GVariantType* expected_type,
                                                                     void* user_data);
static void ft_preferences_panel_notifications_on_settings_changed (FtPreferencesPanelNotifications* self,
                                                             GSettings* settings,
                                                             const gchar* key);
static AdwPreferencesPage* ft_preferences_panel_notifications_real_get_preferences_page (FtPreferencesPanel* base);
static void ft_preferences_panel_notifications_real_dispose (GObject* base);
static void _ft_preferences_panel_notifications_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                                 const gchar* key,
                                                                                 gpointer self);
static GObject * ft_preferences_panel_notifications_constructor (GType type,
                                                          guint n_construct_properties,
                                                          GObjectConstructParam * construct_properties);
static gboolean _ft_preferences_panel_notifications_idle_delay_get_mapping_gsettings_bind_get_mapping (GValue* value,
                                                                                                GVariant* variant,
                                                                                                void* user_data);
static GVariant* _ft_preferences_panel_notifications_idle_delay_set_mapping_gsettings_bind_set_mapping (GValue* value,
                                                                                                 const GVariantType* expected_type,
                                                                                                 void* user_data);
static void ft_preferences_panel_notifications_finalize (GObject * obj);
static GType ft_preferences_panel_notifications_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const guint FT_PREFERENCES_PANEL_NOTIFICATIONS_IDLE_DELAY_CHOICES[7] = {15U, 30U, 60U, 120U, 180U, 300U, 0U};

static inline gpointer
ft_preferences_panel_notifications_get_instance_private (FtPreferencesPanelNotifications* self)
{
	return G_STRUCT_MEMBER_P (self, FtPreferencesPanelNotifications_private_offset);
}

static GtkStringList*
ft_preferences_panel_notifications_create_idle_delay_model (FtPreferencesPanelNotifications* self)
{
	GtkStringList* list = NULL;
	GtkStringList* _tmp0_;
	GtkStringList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gtk_string_list_new (NULL);
	list = _tmp0_;
	{
		guint* seconds_collection = NULL;
		gint seconds_collection_length1 = 0;
		gint _seconds_collection_size_ = 0;
		gint seconds_it = 0;
		seconds_collection = FT_PREFERENCES_PANEL_NOTIFICATIONS_IDLE_DELAY_CHOICES;
		seconds_collection_length1 = G_N_ELEMENTS (FT_PREFERENCES_PANEL_NOTIFICATIONS_IDLE_DELAY_CHOICES);
		for (seconds_it = 0; seconds_it < seconds_collection_length1; seconds_it = seconds_it + 1) {
			guint seconds = 0U;
			seconds = seconds_collection[seconds_it];
			{
				gchar* _tmp1_ = NULL;
				gchar* label = NULL;
				gchar* _tmp4_;
				GtkStringList* _tmp5_;
				const gchar* _tmp6_;
				if (seconds != ((guint) 0)) {
					gchar* _tmp2_;
					_tmp2_ = ft_format_time (seconds);
					_g_free0 (_tmp1_);
					_tmp1_ = _tmp2_;
				} else {
					gchar* _tmp3_;
					_tmp3_ = g_strdup (_ ("Never"));
					_g_free0 (_tmp1_);
					_tmp1_ = _tmp3_;
				}
				_tmp4_ = _tmp1_;
				_tmp1_ = NULL;
				label = _tmp4_;
				_tmp5_ = list;
				_tmp6_ = label;
				gtk_string_list_append (_tmp5_, _tmp6_);
				_g_free0 (label);
				_g_free0 (_tmp1_);
			}
		}
	}
	result = list;
	return result;
}

/**
         * Convert settings value to a choice.
         */
static gboolean
ft_preferences_panel_notifications_idle_delay_get_mapping (GValue* value,
                                                           GVariant* variant,
                                                           void* user_data)
{
	guint32 seconds = 0U;
	gboolean result;
	g_return_val_if_fail (value != NULL, FALSE);
	g_return_val_if_fail (variant != NULL, FALSE);
	seconds = g_variant_get_uint32 (variant);
	{
		guint choice_index = 0U;
		choice_index = 0U;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				guint _tmp2_;
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = choice_index;
					choice_index = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(choice_index < ((guint) G_N_ELEMENTS (FT_PREFERENCES_PANEL_NOTIFICATIONS_IDLE_DELAY_CHOICES)))) {
					break;
				}
				_tmp2_ = FT_PREFERENCES_PANEL_NOTIFICATIONS_IDLE_DELAY_CHOICES[choice_index];
				if (seconds == ((guint32) _tmp2_)) {
					g_value_set_uint (value, choice_index);
					result = TRUE;
					return result;
				}
			}
		}
	}
	g_warning ("preferences-panel-notifications.vala:122: Could not map idle_delay to " \
"a choice");
	g_value_set_uint (value, (guint) 30);
	result = TRUE;
	return result;
}

/**
         * Convert choice to settings value.
         */
static GVariant*
ft_preferences_panel_notifications_idle_delay_set_mapping (GValue* value,
                                                           const GVariantType* expected_type,
                                                           void* user_data)
{
	guint choice_index = 0U;
	guint choice_value = 0U;
	guint _tmp0_;
	GVariant* _tmp1_;
	GVariant* result;
	g_return_val_if_fail (value != NULL, NULL);
	g_return_val_if_fail (expected_type != NULL, NULL);
	choice_index = g_value_get_uint (value);
	_tmp0_ = FT_PREFERENCES_PANEL_NOTIFICATIONS_IDLE_DELAY_CHOICES[choice_index];
	choice_value = _tmp0_;
	_tmp1_ = g_variant_new_uint32 ((guint32) choice_value);
	g_variant_ref_sink (_tmp1_);
	result = _tmp1_;
	return result;
}

static void
ft_preferences_panel_notifications_on_settings_changed (FtPreferencesPanelNotifications* self,
                                                        GSettings* settings,
                                                        const gchar* key)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (settings != NULL);
	g_return_if_fail (key != NULL);
}

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

static void
_ft_preferences_panel_notifications_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                            const gchar* key,
                                                                            gpointer self)
{
	ft_preferences_panel_notifications_on_settings_changed ((FtPreferencesPanelNotifications*) self, _sender, key);
}

static void
ft_preferences_panel_notifications_real_dispose (GObject* base)
{
	FtPreferencesPanelNotifications * self;
	GSettings* _tmp0_;
	self = (FtPreferencesPanelNotifications*) base;
	_tmp0_ = self->priv->settings;
	if (_tmp0_ != NULL) {
		GSettings* _tmp1_;
		guint _tmp2_;
		_tmp1_ = self->priv->settings;
		g_signal_parse_name ("changed", g_settings_get_type (), &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _ft_preferences_panel_notifications_on_settings_changed_g_settings_changed, self);
		_g_object_unref0 (self->priv->settings);
		self->priv->settings = NULL;
	}
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = NULL;
	G_OBJECT_CLASS (ft_preferences_panel_notifications_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PREFERENCES_PANEL, FtPreferencesPanel));
}

FtPreferencesPanelNotifications*
ft_preferences_panel_notifications_construct (GType object_type)
{
	FtPreferencesPanelNotifications * self = NULL;
	self = (FtPreferencesPanelNotifications*) ft_preferences_panel_construct (object_type);
	return self;
}

FtPreferencesPanelNotifications*
ft_preferences_panel_notifications_new (void)
{
	return ft_preferences_panel_notifications_construct (FT_TYPE_PREFERENCES_PANEL_NOTIFICATIONS);
}

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

static gboolean
_ft_preferences_panel_notifications_idle_delay_get_mapping_gsettings_bind_get_mapping (GValue* value,
                                                                                       GVariant* variant,
                                                                                       void* user_data)
{
	gboolean result;
	result = ft_preferences_panel_notifications_idle_delay_get_mapping (value, variant, user_data);
	return result;
}

static GVariant*
_ft_preferences_panel_notifications_idle_delay_set_mapping_gsettings_bind_set_mapping (GValue* value,
                                                                                       const GVariantType* expected_type,
                                                                                       void* user_data)
{
	GVariant* result;
	result = ft_preferences_panel_notifications_idle_delay_set_mapping (value, expected_type, user_data);
	return result;
}

static GObject *
ft_preferences_panel_notifications_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtPreferencesPanelNotifications * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	FtIdleMonitor* _tmp3_;
	AdwComboRow* _tmp4_;
	GtkStringList* _tmp5_;
	GtkStringList* _tmp6_;
	AdwComboRow* _tmp7_;
	GtkStringList* _tmp8_;
	GtkStringList* _tmp9_;
	GSettings* _tmp10_;
	AdwSwitchRow* _tmp11_;
	GSettings* _tmp12_;
	AdwSwitchRow* _tmp13_;
	GSettings* _tmp14_;
	AdwComboRow* _tmp15_;
	GSettings* _tmp16_;
	AdwComboRow* _tmp17_;
	FtIdleMonitor* _tmp18_;
	AdwComboRow* _tmp19_;
	FtIdleMonitor* _tmp20_;
	AdwComboRow* _tmp21_;
	AdwSwitchRow* _tmp22_;
	AdwComboRow* _tmp23_;
	AdwSwitchRow* _tmp24_;
	AdwComboRow* _tmp25_;
	parent_class = G_OBJECT_CLASS (ft_preferences_panel_notifications_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PREFERENCES_PANEL_NOTIFICATIONS, FtPreferencesPanelNotifications);
	_tmp0_ = ft_get_settings ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp1_;
	_tmp2_ = self->priv->settings;
	g_signal_connect_object (_tmp2_, "changed", (GCallback) _ft_preferences_panel_notifications_on_settings_changed_g_settings_changed, self, 0);
	_tmp3_ = ft_idle_monitor_new ();
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = _tmp3_;
	_tmp4_ = self->priv->screen_overlay_lock_delay_comborow;
	_tmp5_ = ft_preferences_panel_notifications_create_idle_delay_model (self);
	_tmp6_ = _tmp5_;
	adw_combo_row_set_model (_tmp4_, (GListModel*) _tmp6_);
	_g_object_unref0 (_tmp6_);
	_tmp7_ = self->priv->screen_overlay_reopen_delay_comborow;
	_tmp8_ = ft_preferences_panel_notifications_create_idle_delay_model (self);
	_tmp9_ = _tmp8_;
	adw_combo_row_set_model (_tmp7_, (GListModel*) _tmp9_);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = self->priv->settings;
	_tmp11_ = self->priv->announce_about_to_end_switchrow;
	g_settings_bind (_tmp10_, "announce-about-to-end", (GObject*) _tmp11_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp12_ = self->priv->settings;
	_tmp13_ = self->priv->screen_overlay_switchrow;
	g_settings_bind (_tmp12_, "screen-overlay", (GObject*) _tmp13_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp14_ = self->priv->settings;
	_tmp15_ = self->priv->screen_overlay_lock_delay_comborow;
	g_settings_bind_with_mapping (_tmp14_, "screen-overlay-lock-delay", (GObject*) _tmp15_, "selected", G_SETTINGS_BIND_DEFAULT, _ft_preferences_panel_notifications_idle_delay_get_mapping_gsettings_bind_get_mapping, _ft_preferences_panel_notifications_idle_delay_set_mapping_gsettings_bind_set_mapping, NULL, NULL);
	_tmp16_ = self->priv->settings;
	_tmp17_ = self->priv->screen_overlay_reopen_delay_comborow;
	g_settings_bind_with_mapping (_tmp16_, "screen-overlay-reopen-delay", (GObject*) _tmp17_, "selected", G_SETTINGS_BIND_DEFAULT, _ft_preferences_panel_notifications_idle_delay_get_mapping_gsettings_bind_get_mapping, _ft_preferences_panel_notifications_idle_delay_set_mapping_gsettings_bind_set_mapping, NULL, NULL);
	_tmp18_ = self->priv->idle_monitor;
	_tmp19_ = self->priv->screen_overlay_lock_delay_comborow;
	g_object_bind_property_with_closures ((GObject*) _tmp18_, "enabled", (GObject*) _tmp19_, "visible", 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)));
	_tmp20_ = self->priv->idle_monitor;
	_tmp21_ = self->priv->screen_overlay_reopen_delay_comborow;
	g_object_bind_property_with_closures ((GObject*) _tmp20_, "enabled", (GObject*) _tmp21_, "visible", 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)));
	_tmp22_ = self->priv->screen_overlay_switchrow;
	_tmp23_ = self->priv->screen_overlay_lock_delay_comborow;
	g_object_bind_property_with_closures ((GObject*) _tmp22_, "active", (GObject*) _tmp23_, "sensitive", 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)));
	_tmp24_ = self->priv->screen_overlay_switchrow;
	_tmp25_ = self->priv->screen_overlay_reopen_delay_comborow;
	g_object_bind_property_with_closures ((GObject*) _tmp24_, "active", (GObject*) _tmp25_, "sensitive", 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)));
	return obj;
}

static void
ft_preferences_panel_notifications_class_init (FtPreferencesPanelNotificationsClass * klass,
                                               gpointer klass_data)
{
	ft_preferences_panel_notifications_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtPreferencesPanelNotifications_private_offset);
	((FtPreferencesPanelClass *) klass)->get_preferences_page = (AdwPreferencesPage* (*) (FtPreferencesPanel*)) ft_preferences_panel_notifications_real_get_preferences_page;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_preferences_panel_notifications_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = ft_preferences_panel_notifications_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_preferences_panel_notifications_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/preferences/notifications/preferences-panel-notifications.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "page", FALSE, FtPreferencesPanelNotifications_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelNotificationsPrivate, page));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "announce_about_to_end_switchrow", FALSE, FtPreferencesPanelNotifications_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelNotificationsPrivate, announce_about_to_end_switchrow));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "screen_overlay_switchrow", FALSE, FtPreferencesPanelNotifications_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelNotificationsPrivate, screen_overlay_switchrow));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "screen_overlay_lock_delay_comborow", FALSE, FtPreferencesPanelNotifications_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelNotificationsPrivate, screen_overlay_lock_delay_comborow));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "screen_overlay_reopen_delay_comborow", FALSE, FtPreferencesPanelNotifications_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelNotificationsPrivate, screen_overlay_reopen_delay_comborow));
}

static void
ft_preferences_panel_notifications_instance_init (FtPreferencesPanelNotifications * self,
                                                  gpointer klass)
{
	self->priv = ft_preferences_panel_notifications_get_instance_private (self);
	self->priv->idle_monitor = NULL;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_preferences_panel_notifications_finalize (GObject * obj)
{
	FtPreferencesPanelNotifications * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PREFERENCES_PANEL_NOTIFICATIONS, FtPreferencesPanelNotifications);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->idle_monitor);
	G_OBJECT_CLASS (ft_preferences_panel_notifications_parent_class)->finalize (obj);
}

static GType
ft_preferences_panel_notifications_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtPreferencesPanelNotificationsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_preferences_panel_notifications_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtPreferencesPanelNotifications), 0, (GInstanceInitFunc) ft_preferences_panel_notifications_instance_init, NULL };
	GType ft_preferences_panel_notifications_type_id;
	ft_preferences_panel_notifications_type_id = g_type_register_static (FT_TYPE_PREFERENCES_PANEL, "FtPreferencesPanelNotifications", &g_define_type_info, 0);
	FtPreferencesPanelNotifications_private_offset = g_type_add_instance_private (ft_preferences_panel_notifications_type_id, sizeof (FtPreferencesPanelNotificationsPrivate));
	return ft_preferences_panel_notifications_type_id;
}

GType
ft_preferences_panel_notifications_get_type (void)
{
	static volatile gsize ft_preferences_panel_notifications_type_id__once = 0;
	if (g_once_init_enter (&ft_preferences_panel_notifications_type_id__once)) {
		GType ft_preferences_panel_notifications_type_id;
		ft_preferences_panel_notifications_type_id = ft_preferences_panel_notifications_get_type_once ();
		g_once_init_leave (&ft_preferences_panel_notifications_type_id__once, ft_preferences_panel_notifications_type_id);
	}
	return ft_preferences_panel_notifications_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;
}

