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

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

#include "ft_core.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.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_TIME_ZONE_MONITOR_0_PROPERTY,
	FT_TIME_ZONE_MONITOR_TIMEZONE_PROPERTY,
	FT_TIME_ZONE_MONITOR_NUM_PROPERTIES
};
static GParamSpec* ft_time_zone_monitor_properties[FT_TIME_ZONE_MONITOR_NUM_PROPERTIES];
#define _g_time_zone_unref0(var) ((var == NULL) ? NULL : (var = (g_time_zone_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	FT_TIME_ZONE_MONITOR_CHANGED_SIGNAL,
	FT_TIME_ZONE_MONITOR_NUM_SIGNALS
};
static guint ft_time_zone_monitor_signals[FT_TIME_ZONE_MONITOR_NUM_SIGNALS] = {0};

struct _FtTimeZoneMonitorPrivate {
	GTimeZone* _timezone;
};

static gint FtTimeZoneMonitor_private_offset;
static gpointer ft_time_zone_monitor_parent_class = NULL;

static GType ft_time_zone_monitor_provider_get_type_once (void);
static void ft_time_zone_monitor_update_timezone (FtTimeZoneMonitor* self,
                                           const gchar* timezone_identifier);
static void ft_time_zone_monitor_on_notify_identifier (FtTimeZoneMonitor* self,
                                                GObject* object,
                                                GParamSpec* pspec);
static void ft_time_zone_monitor_real_initialize (FtProvidedObject* base);
static void ft_time_zone_monitor_real_setup_providers (FtProvidedObject* base);
static void ft_time_zone_monitor_real_provider_enabled (FtProvidedObject* base,
                                                 FtTimeZoneMonitorProvider* provider);
static void _ft_time_zone_monitor_on_notify_identifier_g_object_notify (GObject* _sender,
                                                                 GParamSpec* pspec,
                                                                 gpointer self);
static void ft_time_zone_monitor_real_provider_disabled (FtProvidedObject* base,
                                                  FtTimeZoneMonitorProvider* provider);
static GObject * ft_time_zone_monitor_constructor (GType type,
                                            guint n_construct_properties,
                                            GObjectConstructParam * construct_properties);
static void ft_time_zone_monitor_finalize (GObject * obj);
static GType ft_time_zone_monitor_get_type_once (void);
static void _vala_ft_time_zone_monitor_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

const gchar*
ft_time_zone_monitor_provider_get_identifier (FtTimeZoneMonitorProvider* self)
{
	FtTimeZoneMonitorProviderIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = FT_TIME_ZONE_MONITOR_PROVIDER_GET_INTERFACE (self);
	if (_iface_->get_identifier) {
		return _iface_->get_identifier (self);
	}
	return NULL;
}

static void
ft_time_zone_monitor_provider_default_init (FtTimeZoneMonitorProviderIface * iface,
                                            gpointer iface_data)
{
	g_object_interface_install_property (iface, g_param_spec_string ("identifier", "identifier", "identifier", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static GType
ft_time_zone_monitor_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtTimeZoneMonitorProviderIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_time_zone_monitor_provider_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType ft_time_zone_monitor_provider_type_id;
	ft_time_zone_monitor_provider_type_id = g_type_register_static (G_TYPE_INTERFACE, "FtTimeZoneMonitorProvider", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (ft_time_zone_monitor_provider_type_id, FT_TYPE_PROVIDER);
	return ft_time_zone_monitor_provider_type_id;
}

GType
ft_time_zone_monitor_provider_get_type (void)
{
	static volatile gsize ft_time_zone_monitor_provider_type_id__once = 0;
	if (g_once_init_enter (&ft_time_zone_monitor_provider_type_id__once)) {
		GType ft_time_zone_monitor_provider_type_id;
		ft_time_zone_monitor_provider_type_id = ft_time_zone_monitor_provider_get_type_once ();
		g_once_init_leave (&ft_time_zone_monitor_provider_type_id__once, ft_time_zone_monitor_provider_type_id);
	}
	return ft_time_zone_monitor_provider_type_id__once;
}

static inline gpointer
ft_time_zone_monitor_get_instance_private (FtTimeZoneMonitor* self)
{
	return G_STRUCT_MEMBER_P (self, FtTimeZoneMonitor_private_offset);
}

static GTimeZone*
vala_g_time_zone_new_identifier (const gchar* identifier,
                                 GError** error)
{
	GTimeZone* self;
	GError* _inner_error0_ = NULL;
	self = (GTimeZone*) g_time_zone_new_identifier (identifier);
	if (((GTimeZone*) self) == NULL) {
		GError* _tmp0_;
		_tmp0_ = g_error_new_literal (G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, "Invalid identifier argument");
		_inner_error0_ = _tmp0_;
		g_propagate_error (error, _inner_error0_);
		_g_time_zone_unref0 (self);
		return NULL;
	}
	return self;
}

static gpointer
_g_time_zone_ref0 (gpointer self)
{
	return self ? g_time_zone_ref (self) : NULL;
}

static void
ft_time_zone_monitor_update_timezone (FtTimeZoneMonitor* self,
                                      const gchar* timezone_identifier)
{
	GTimeZone* timezone = NULL;
	gboolean _tmp7_ = FALSE;
	GTimeZone* _tmp8_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	timezone = NULL;
	if (timezone_identifier != NULL) {
		{
			GTimeZone* _tmp0_ = NULL;
			GTimeZone* _tmp1_;
			GTimeZone* _tmp2_;
			_tmp1_ = vala_g_time_zone_new_identifier (timezone_identifier, &_inner_error0_);
			_tmp0_ = _tmp1_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp2_ = _tmp0_;
			_tmp0_ = NULL;
			_g_time_zone_unref0 (timezone);
			timezone = _tmp2_;
			_g_time_zone_unref0 (_tmp0_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* _error_ = NULL;
			GError* _tmp3_;
			const gchar* _tmp4_;
			GTimeZone* _tmp5_;
			_error_ = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp3_ = _error_;
			_tmp4_ = _tmp3_->message;
			g_warning ("timezone-monitor.vala:36: Could not find timezone \"%s\": %s", timezone_identifier, _tmp4_);
			_tmp5_ = g_time_zone_new_local ();
			_g_time_zone_unref0 (timezone);
			timezone = _tmp5_;
			_g_error_free0 (_error_);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_time_zone_unref0 (timezone);
			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;
		}
	} else {
		GTimeZone* _tmp6_;
		_tmp6_ = g_time_zone_new_local ();
		_g_time_zone_unref0 (timezone);
		timezone = _tmp6_;
	}
	_tmp8_ = self->priv->_timezone;
	if (_tmp8_ == NULL) {
		_tmp7_ = TRUE;
	} else {
		GTimeZone* _tmp9_;
		const gchar* _tmp10_;
		GTimeZone* _tmp11_;
		const gchar* _tmp12_;
		_tmp9_ = self->priv->_timezone;
		_tmp10_ = g_time_zone_get_identifier (_tmp9_);
		_tmp11_ = timezone;
		_tmp12_ = g_time_zone_get_identifier (_tmp11_);
		_tmp7_ = g_strcmp0 (_tmp10_, _tmp12_) != 0;
	}
	if (_tmp7_) {
		GTimeZone* _tmp13_;
		GTimeZone* _tmp14_;
		_tmp13_ = timezone;
		_tmp14_ = _g_time_zone_ref0 (_tmp13_);
		_g_time_zone_unref0 (self->priv->_timezone);
		self->priv->_timezone = _tmp14_;
		g_object_notify ((GObject*) self, "timezone");
		g_signal_emit (self, ft_time_zone_monitor_signals[FT_TIME_ZONE_MONITOR_CHANGED_SIGNAL], 0);
	}
	_g_time_zone_unref0 (timezone);
}

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

static void
ft_time_zone_monitor_on_notify_identifier (FtTimeZoneMonitor* self,
                                           GObject* object,
                                           GParamSpec* pspec)
{
	FtTimeZoneMonitorProvider* provider = NULL;
	FtTimeZoneMonitorProvider* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_TIME_ZONE_MONITOR_PROVIDER, FtTimeZoneMonitorProvider));
	provider = _tmp0_;
	_tmp1_ = ft_time_zone_monitor_provider_get_identifier (provider);
	_tmp2_ = _tmp1_;
	ft_time_zone_monitor_update_timezone (self, _tmp2_);
	_g_object_unref0 (provider);
}

static void
ft_time_zone_monitor_real_initialize (FtProvidedObject* base)
{
	FtTimeZoneMonitor * self;
	GTimeZone* _tmp0_;
	self = (FtTimeZoneMonitor*) base;
	_tmp0_ = g_time_zone_new_local ();
	_g_time_zone_unref0 (self->priv->_timezone);
	self->priv->_timezone = _tmp0_;
}

static void
ft_time_zone_monitor_real_setup_providers (FtProvidedObject* base)
{
	FtTimeZoneMonitor * self;
	self = (FtTimeZoneMonitor*) base;
}

static void
_ft_time_zone_monitor_on_notify_identifier_g_object_notify (GObject* _sender,
                                                            GParamSpec* pspec,
                                                            gpointer self)
{
	ft_time_zone_monitor_on_notify_identifier ((FtTimeZoneMonitor*) self, _sender, pspec);
}

static void
ft_time_zone_monitor_real_provider_enabled (FtProvidedObject* base,
                                            FtTimeZoneMonitorProvider* provider)
{
	FtTimeZoneMonitor * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	self = (FtTimeZoneMonitor*) base;
	g_return_if_fail (provider != NULL);
	g_signal_connect_object ((GObject*) provider, "notify::identifier", (GCallback) _ft_time_zone_monitor_on_notify_identifier_g_object_notify, self, 0);
	_tmp0_ = ft_time_zone_monitor_provider_get_identifier (provider);
	_tmp1_ = _tmp0_;
	ft_time_zone_monitor_update_timezone (self, _tmp1_);
}

static void
ft_time_zone_monitor_real_provider_disabled (FtProvidedObject* base,
                                             FtTimeZoneMonitorProvider* provider)
{
	FtTimeZoneMonitor * self;
	guint _tmp0_;
	GQuark _tmp1_;
	self = (FtTimeZoneMonitor*) base;
	g_return_if_fail (provider != NULL);
	g_signal_parse_name ("notify::identifier", G_TYPE_OBJECT, &_tmp0_, &_tmp1_, TRUE);
	g_signal_handlers_disconnect_matched ((GObject*) provider, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, _tmp1_, NULL, (GCallback) _ft_time_zone_monitor_on_notify_identifier_g_object_notify, self);
}

FtTimeZoneMonitor*
ft_time_zone_monitor_construct (GType object_type)
{
	FtTimeZoneMonitor * self = NULL;
	self = (FtTimeZoneMonitor*) ft_provided_object_construct (object_type, FT_TYPE_TIME_ZONE_MONITOR_PROVIDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref);
	return self;
}

FtTimeZoneMonitor*
ft_time_zone_monitor_new (void)
{
	return ft_time_zone_monitor_construct (FT_TYPE_TIME_ZONE_MONITOR);
}

GTimeZone*
ft_time_zone_monitor_get_timezone (FtTimeZoneMonitor* self)
{
	GTimeZone* result;
	GTimeZone* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_timezone;
	result = _tmp0_;
	return result;
}

static GObject *
ft_time_zone_monitor_constructor (GType type,
                                  guint n_construct_properties,
                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	static GWeakRef FtTimeZoneMonitor_singleton__ref;
	static GMutex FtTimeZoneMonitor_singleton__lock;
	FtTimeZoneMonitor * self;
	g_mutex_lock (&FtTimeZoneMonitor_singleton__lock);
	obj = g_weak_ref_get (&FtTimeZoneMonitor_singleton__ref);
	if (obj != NULL) {
		g_mutex_unlock (&FtTimeZoneMonitor_singleton__lock);
		return obj;
	}
	parent_class = G_OBJECT_CLASS (ft_time_zone_monitor_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIME_ZONE_MONITOR, FtTimeZoneMonitor);
	g_weak_ref_set (&FtTimeZoneMonitor_singleton__ref, obj);
	g_mutex_unlock (&FtTimeZoneMonitor_singleton__lock);
	return obj;
}

static void
ft_time_zone_monitor_class_init (FtTimeZoneMonitorClass * klass,
                                 gpointer klass_data)
{
	ft_time_zone_monitor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtTimeZoneMonitor_private_offset);
	((FtProvidedObjectClass *) klass)->initialize = (void (*) (FtProvidedObject*)) ft_time_zone_monitor_real_initialize;
	((FtProvidedObjectClass *) klass)->setup_providers = (void (*) (FtProvidedObject*)) ft_time_zone_monitor_real_setup_providers;
	((FtProvidedObjectClass *) klass)->provider_enabled = (void (*) (FtProvidedObject*, gconstpointer)) ft_time_zone_monitor_real_provider_enabled;
	((FtProvidedObjectClass *) klass)->provider_disabled = (void (*) (FtProvidedObject*, gconstpointer)) ft_time_zone_monitor_real_provider_disabled;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_time_zone_monitor_get_property;
	G_OBJECT_CLASS (klass)->constructor = ft_time_zone_monitor_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_time_zone_monitor_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_ZONE_MONITOR_TIMEZONE_PROPERTY, ft_time_zone_monitor_properties[FT_TIME_ZONE_MONITOR_TIMEZONE_PROPERTY] = g_param_spec_boxed ("timezone", "timezone", "timezone", G_TYPE_TIME_ZONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	ft_time_zone_monitor_signals[FT_TIME_ZONE_MONITOR_CHANGED_SIGNAL] = g_signal_new ("changed", FT_TYPE_TIME_ZONE_MONITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
ft_time_zone_monitor_instance_init (FtTimeZoneMonitor * self,
                                    gpointer klass)
{
	self->priv = ft_time_zone_monitor_get_instance_private (self);
}

static void
ft_time_zone_monitor_finalize (GObject * obj)
{
	FtTimeZoneMonitor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIME_ZONE_MONITOR, FtTimeZoneMonitor);
	_g_time_zone_unref0 (self->priv->_timezone);
	G_OBJECT_CLASS (ft_time_zone_monitor_parent_class)->finalize (obj);
}

static GType
ft_time_zone_monitor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtTimeZoneMonitorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_time_zone_monitor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtTimeZoneMonitor), 0, (GInstanceInitFunc) ft_time_zone_monitor_instance_init, NULL };
	GType ft_time_zone_monitor_type_id;
	ft_time_zone_monitor_type_id = g_type_register_static (FT_TYPE_PROVIDED_OBJECT, "FtTimeZoneMonitor", &g_define_type_info, 0);
	FtTimeZoneMonitor_private_offset = g_type_add_instance_private (ft_time_zone_monitor_type_id, sizeof (FtTimeZoneMonitorPrivate));
	return ft_time_zone_monitor_type_id;
}

GType
ft_time_zone_monitor_get_type (void)
{
	static volatile gsize ft_time_zone_monitor_type_id__once = 0;
	if (g_once_init_enter (&ft_time_zone_monitor_type_id__once)) {
		GType ft_time_zone_monitor_type_id;
		ft_time_zone_monitor_type_id = ft_time_zone_monitor_get_type_once ();
		g_once_init_leave (&ft_time_zone_monitor_type_id__once, ft_time_zone_monitor_type_id);
	}
	return ft_time_zone_monitor_type_id__once;
}

static void
_vala_ft_time_zone_monitor_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	FtTimeZoneMonitor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_TIME_ZONE_MONITOR, FtTimeZoneMonitor);
	switch (property_id) {
		case FT_TIME_ZONE_MONITOR_TIMEZONE_PROPERTY:
		g_value_set_boxed (value, ft_time_zone_monitor_get_timezone (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

