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

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

#include "ft_core.h"
#include <glib.h>
#include <glib-object.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_INDICATOR_0_PROPERTY,
	FT_INDICATOR_NUM_PROPERTIES
};
static GParamSpec* ft_indicator_properties[FT_INDICATOR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _FtIndicatorPrivate {
	FtBackgroundManager* background_manager;
	guint background_hold_id;
};

static gint FtIndicator_private_offset;
static gpointer ft_indicator_parent_class = NULL;

static GType ft_indicator_provider_get_type_once (void);
static void ft_indicator_update_background_hold (FtIndicator* self);
static void ft_indicator_on_notify_visible (FtIndicator* self,
                                     GObject* obj,
                                     GParamSpec* pspec);
static void ft_indicator_real_initialize (FtProvidedObject* base);
static void ft_indicator_real_setup_providers (FtProvidedObject* base);
static void ft_indicator_real_provider_enabled (FtProvidedObject* base,
                                         FtIndicatorProvider* provider);
static void _ft_indicator_on_notify_visible_g_object_notify (GObject* _sender,
                                                      GParamSpec* pspec,
                                                      gpointer self);
static void ft_indicator_real_provider_disabled (FtProvidedObject* base,
                                          FtIndicatorProvider* provider);
static void ft_indicator_real_dispose (GObject* base);
static GObject * ft_indicator_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties);
static void ft_indicator_finalize (GObject * obj);
static GType ft_indicator_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gboolean
ft_indicator_provider_get_visible (FtIndicatorProvider* self)
{
	FtIndicatorProviderIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = FT_INDICATOR_PROVIDER_GET_INTERFACE (self);
	if (_iface_->get_visible) {
		return _iface_->get_visible (self);
	}
	return FALSE;
}

static void
ft_indicator_provider_default_init (FtIndicatorProviderIface * iface,
                                    gpointer iface_data)
{
	g_object_interface_install_property (iface, g_param_spec_boolean ("visible", "visible", "visible", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static GType
ft_indicator_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtIndicatorProviderIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_indicator_provider_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType ft_indicator_provider_type_id;
	ft_indicator_provider_type_id = g_type_register_static (G_TYPE_INTERFACE, "FtIndicatorProvider", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (ft_indicator_provider_type_id, FT_TYPE_PROVIDER);
	return ft_indicator_provider_type_id;
}

GType
ft_indicator_provider_get_type (void)
{
	static volatile gsize ft_indicator_provider_type_id__once = 0;
	if (g_once_init_enter (&ft_indicator_provider_type_id__once)) {
		GType ft_indicator_provider_type_id;
		ft_indicator_provider_type_id = ft_indicator_provider_get_type_once ();
		g_once_init_leave (&ft_indicator_provider_type_id__once, ft_indicator_provider_type_id);
	}
	return ft_indicator_provider_type_id__once;
}

static inline gpointer
ft_indicator_get_instance_private (FtIndicator* self)
{
	return G_STRUCT_MEMBER_P (self, FtIndicator_private_offset);
}

static void
ft_indicator_update_background_hold (FtIndicator* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gconstpointer _tmp2_;
	gconstpointer _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp2_ = ft_provided_object_get_provider ((FtProvidedObject*) self);
	_tmp3_ = _tmp2_;
	if (((FtIndicatorProvider*) _tmp3_) != NULL) {
		gconstpointer _tmp4_;
		gconstpointer _tmp5_;
		gboolean _tmp6_;
		gboolean _tmp7_;
		_tmp4_ = ft_provided_object_get_provider ((FtProvidedObject*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = ft_provider_get_enabled ((FtProvider*) ((FtIndicatorProvider*) _tmp5_));
		_tmp7_ = _tmp6_;
		_tmp1_ = _tmp7_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		gconstpointer _tmp8_;
		gconstpointer _tmp9_;
		gboolean _tmp10_;
		gboolean _tmp11_;
		_tmp8_ = ft_provided_object_get_provider ((FtProvidedObject*) self);
		_tmp9_ = _tmp8_;
		_tmp10_ = ft_indicator_provider_get_visible ((FtIndicatorProvider*) _tmp9_);
		_tmp11_ = _tmp10_;
		_tmp0_ = _tmp11_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		if (self->priv->background_hold_id == 0U) {
			FtBackgroundManager* _tmp12_;
			_tmp12_ = self->priv->background_manager;
			self->priv->background_hold_id = ft_background_manager_hold_sync (_tmp12_, "");
		}
	} else {
		if (self->priv->background_hold_id != 0U) {
			FtBackgroundManager* _tmp13_;
			_tmp13_ = self->priv->background_manager;
			ft_background_manager_release (_tmp13_, self->priv->background_hold_id);
			self->priv->background_hold_id = (guint) 0;
		}
	}
}

static void
ft_indicator_on_notify_visible (FtIndicator* self,
                                GObject* obj,
                                GParamSpec* pspec)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (obj != NULL);
	g_return_if_fail (pspec != NULL);
	ft_indicator_update_background_hold (self);
}

static void
ft_indicator_real_initialize (FtProvidedObject* base)
{
	FtIndicator * self;
	FtBackgroundManager* _tmp0_;
	self = (FtIndicator*) base;
	_tmp0_ = ft_background_manager_new ();
	_g_object_unref0 (self->priv->background_manager);
	self->priv->background_manager = _tmp0_;
}

static void
ft_indicator_real_setup_providers (FtProvidedObject* base)
{
	FtIndicator * self;
	self = (FtIndicator*) base;
}

static void
_ft_indicator_on_notify_visible_g_object_notify (GObject* _sender,
                                                 GParamSpec* pspec,
                                                 gpointer self)
{
	ft_indicator_on_notify_visible ((FtIndicator*) self, _sender, pspec);
}

static void
ft_indicator_real_provider_enabled (FtProvidedObject* base,
                                    FtIndicatorProvider* provider)
{
	FtIndicator * self;
	self = (FtIndicator*) base;
	g_return_if_fail (provider != NULL);
	g_signal_connect_object ((GObject*) provider, "notify::visible", (GCallback) _ft_indicator_on_notify_visible_g_object_notify, self, 0);
	ft_indicator_update_background_hold (self);
}

static void
ft_indicator_real_provider_disabled (FtProvidedObject* base,
                                     FtIndicatorProvider* provider)
{
	FtIndicator * self;
	guint _tmp0_;
	GQuark _tmp1_;
	self = (FtIndicator*) base;
	g_return_if_fail (provider != NULL);
	g_signal_parse_name ("notify::visible", 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_indicator_on_notify_visible_g_object_notify, self);
	ft_indicator_update_background_hold (self);
}

static void
ft_indicator_real_dispose (GObject* base)
{
	FtIndicator * self;
	self = (FtIndicator*) base;
	if (self->priv->background_hold_id != 0U) {
		FtBackgroundManager* _tmp0_;
		_tmp0_ = self->priv->background_manager;
		ft_background_manager_release (_tmp0_, self->priv->background_hold_id);
		self->priv->background_hold_id = 0U;
	}
	_g_object_unref0 (self->priv->background_manager);
	self->priv->background_manager = NULL;
	G_OBJECT_CLASS (ft_indicator_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PROVIDED_OBJECT, FtProvidedObject));
}

FtIndicator*
ft_indicator_construct (GType object_type)
{
	FtIndicator * self = NULL;
	self = (FtIndicator*) ft_provided_object_construct (object_type, FT_TYPE_INDICATOR_PROVIDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref);
	return self;
}

FtIndicator*
ft_indicator_new (void)
{
	return ft_indicator_construct (FT_TYPE_INDICATOR);
}

static GObject *
ft_indicator_constructor (GType type,
                          guint n_construct_properties,
                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	static GWeakRef FtIndicator_singleton__ref;
	static GMutex FtIndicator_singleton__lock;
	FtIndicator * self;
	g_mutex_lock (&FtIndicator_singleton__lock);
	obj = g_weak_ref_get (&FtIndicator_singleton__ref);
	if (obj != NULL) {
		g_mutex_unlock (&FtIndicator_singleton__lock);
		return obj;
	}
	parent_class = G_OBJECT_CLASS (ft_indicator_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_INDICATOR, FtIndicator);
	g_weak_ref_set (&FtIndicator_singleton__ref, obj);
	g_mutex_unlock (&FtIndicator_singleton__lock);
	return obj;
}

static void
ft_indicator_class_init (FtIndicatorClass * klass,
                         gpointer klass_data)
{
	ft_indicator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtIndicator_private_offset);
	((FtProvidedObjectClass *) klass)->initialize = (void (*) (FtProvidedObject*)) ft_indicator_real_initialize;
	((FtProvidedObjectClass *) klass)->setup_providers = (void (*) (FtProvidedObject*)) ft_indicator_real_setup_providers;
	((FtProvidedObjectClass *) klass)->provider_enabled = (void (*) (FtProvidedObject*, gconstpointer)) ft_indicator_real_provider_enabled;
	((FtProvidedObjectClass *) klass)->provider_disabled = (void (*) (FtProvidedObject*, gconstpointer)) ft_indicator_real_provider_disabled;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_indicator_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = ft_indicator_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_indicator_finalize;
}

static void
ft_indicator_instance_init (FtIndicator * self,
                            gpointer klass)
{
	self->priv = ft_indicator_get_instance_private (self);
	self->priv->background_manager = NULL;
	self->priv->background_hold_id = 0U;
}

static void
ft_indicator_finalize (GObject * obj)
{
	FtIndicator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_INDICATOR, FtIndicator);
	_g_object_unref0 (self->priv->background_manager);
	G_OBJECT_CLASS (ft_indicator_parent_class)->finalize (obj);
}

/**
     * A helper primitive to ensure only one indicator is enabled at a time.
     *
     * Also, to run the app in background when an indicator is available.
     */
static GType
ft_indicator_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtIndicatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_indicator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtIndicator), 0, (GInstanceInitFunc) ft_indicator_instance_init, NULL };
	GType ft_indicator_type_id;
	ft_indicator_type_id = g_type_register_static (FT_TYPE_PROVIDED_OBJECT, "FtIndicator", &g_define_type_info, 0);
	FtIndicator_private_offset = g_type_add_instance_private (ft_indicator_type_id, sizeof (FtIndicatorPrivate));
	return ft_indicator_type_id;
}

GType
ft_indicator_get_type (void)
{
	static volatile gsize ft_indicator_type_id__once = 0;
	if (g_once_init_enter (&ft_indicator_type_id__once)) {
		GType ft_indicator_type_id;
		ft_indicator_type_id = ft_indicator_get_type_once ();
		g_once_init_leave (&ft_indicator_type_id__once, ft_indicator_type_id);
	}
	return ft_indicator_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;
}

