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

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

#include "ft_plugin_sni.h"
#include <gio/gio.h>
#include "ft_core.h"
#include "ft_ui.h"
#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.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  {
	SNI_PREFERENCES_WINDOW_EXTENSION_0_PROPERTY,
	SNI_PREFERENCES_WINDOW_EXTENSION_NUM_PROPERTIES
};
static GParamSpec* sni_preferences_window_extension_properties[SNI_PREFERENCES_WINDOW_EXTENSION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SniPreferencesWindowExtensionPrivate {
	GSettings* settings;
	FtIndicator* indicator;
	FtPreferencesPanel* last_panel;
	AdwPreferencesGroup* indicator_group;
};

static gint SniPreferencesWindowExtension_private_offset;
static gpointer sni_preferences_window_extension_parent_class = NULL;
static GType sni_preferences_window_extension_type_id = 0;

static void sni_preferences_window_extension_setup_appearance_panel (SniPreferencesWindowExtension* self,
                                                              FtPreferencesPanel* panel);
static void sni_preferences_window_extension_taredown_appearance_panel (SniPreferencesWindowExtension* self,
                                                                 FtPreferencesPanel* panel);
static void sni_preferences_window_extension_setup (SniPreferencesWindowExtension* self);
static void sni_preferences_window_extension_taredown (SniPreferencesWindowExtension* self);
static void sni_preferences_window_extension_update (SniPreferencesWindowExtension* self);
static void sni_preferences_window_extension_on_notify_provider (SniPreferencesWindowExtension* self,
                                                          GObject* object,
                                                          GParamSpec* pspec);
static void sni_preferences_window_extension_on_notify_visible_panel (SniPreferencesWindowExtension* self,
                                                               GObject* object,
                                                               GParamSpec* pspec);
static void sni_preferences_window_extension_on_notify_window (SniPreferencesWindowExtension* self,
                                                        GObject* object,
                                                        GParamSpec* pspec);
static void _sni_preferences_window_extension_on_notify_visible_panel_g_object_notify (GObject* _sender,
                                                                                GParamSpec* pspec,
                                                                                gpointer self);
static void sni_preferences_window_extension_real_dispose (GObject* base);
static void _sni_preferences_window_extension_on_notify_provider_g_object_notify (GObject* _sender,
                                                                           GParamSpec* pspec,
                                                                           gpointer self);
static GObject * sni_preferences_window_extension_constructor (GType type,
                                                        guint n_construct_properties,
                                                        GObjectConstructParam * construct_properties);
static void _sni_preferences_window_extension_on_notify_window_g_object_notify (GObject* _sender,
                                                                         GParamSpec* pspec,
                                                                         gpointer self);
static void sni_preferences_window_extension_finalize (GObject * obj);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
sni_preferences_window_extension_get_instance_private (SniPreferencesWindowExtension* self)
{
	return G_STRUCT_MEMBER_P (self, SniPreferencesWindowExtension_private_offset);
}

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

static void
sni_preferences_window_extension_setup_appearance_panel (SniPreferencesWindowExtension* self,
                                                         FtPreferencesPanel* panel)
{
	AdwPreferencesPage* page = NULL;
	AdwPreferencesPage* _tmp0_;
	AdwPreferencesPage* _tmp1_;
	GSettings* _tmp2_;
	AdwPreferencesGroup* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (panel != NULL);
	_tmp0_ = ft_preferences_panel_get_preferences_page (panel);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	page = _tmp1_;
	_tmp2_ = self->priv->settings;
	if (_tmp2_ == NULL) {
		sni_preferences_window_extension_taredown_appearance_panel (self, panel);
		_g_object_unref0 (page);
		return;
	}
	_tmp3_ = self->priv->indicator_group;
	if (_tmp3_ == NULL) {
		AdwPreferencesGroup* indicator_group = NULL;
		AdwPreferencesGroup* _tmp4_;
		AdwPreferencesGroup* _tmp5_;
		AdwPreferencesPage* _tmp6_;
		AdwPreferencesGroup* _tmp7_;
		AdwSwitchRow* indicator_row = NULL;
		AdwSwitchRow* _tmp8_;
		AdwSwitchRow* _tmp9_;
		AdwSwitchRow* _tmp10_;
		AdwPreferencesGroup* _tmp11_;
		AdwSwitchRow* _tmp12_;
		GSettings* _tmp13_;
		AdwSwitchRow* _tmp14_;
		AdwPreferencesGroup* _tmp15_;
		_tmp4_ = (AdwPreferencesGroup*) adw_preferences_group_new ();
		g_object_ref_sink (_tmp4_);
		indicator_group = _tmp4_;
		_tmp5_ = indicator_group;
		adw_preferences_group_set_title (_tmp5_, _ ("System Tray Icon"));
		_tmp6_ = page;
		_tmp7_ = indicator_group;
		adw_preferences_page_add (_tmp6_, _tmp7_);
		_tmp8_ = (AdwSwitchRow*) adw_switch_row_new ();
		g_object_ref_sink (_tmp8_);
		indicator_row = _tmp8_;
		_tmp9_ = indicator_row;
		adw_preferences_row_set_title ((AdwPreferencesRow*) _tmp9_, _ ("Show Tray Icon"));
		_tmp10_ = indicator_row;
		adw_action_row_set_subtitle ((AdwActionRow*) _tmp10_, _ ("Closing the window keeps the app running in the background."));
		_tmp11_ = indicator_group;
		_tmp12_ = indicator_row;
		adw_preferences_group_add (_tmp11_, (GtkWidget*) _tmp12_);
		_tmp13_ = self->priv->settings;
		_tmp14_ = indicator_row;
		g_settings_bind (_tmp13_, "indicator", (GObject*) _tmp14_, "active", G_SETTINGS_BIND_DEFAULT);
		_tmp15_ = indicator_group;
		self->priv->indicator_group = _tmp15_;
		_g_object_unref0 (indicator_row);
		_g_object_unref0 (indicator_group);
	}
	_g_object_unref0 (page);
}

static void
sni_preferences_window_extension_taredown_appearance_panel (SniPreferencesWindowExtension* self,
                                                            FtPreferencesPanel* panel)
{
	AdwPreferencesGroup* _tmp0_ = NULL;
	AdwPreferencesGroup* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (panel != NULL);
	_tmp1_ = self->priv->indicator_group;
	_tmp0_ = _tmp1_;
	if (_tmp0_ != NULL) {
		gtk_widget_unparent ((GtkWidget*) _tmp0_);
	}
	self->priv->indicator_group = NULL;
}

static void
sni_preferences_window_extension_setup (SniPreferencesWindowExtension* self)
{
	FtPreferencesWindow* _tmp0_ = NULL;
	FtPreferencesWindow* _tmp1_;
	FtPreferencesWindow* _tmp2_;
	FtPreferencesPanel* _tmp3_ = NULL;
	FtPreferencesPanel* panel = NULL;
	FtPreferencesPanel* _tmp6_;
	FtPreferencesPanel* _tmp7_;
	FtPreferencesPanel* _tmp8_;
	FtPreferencesPanel* _tmp20_ = NULL;
	FtPreferencesPanel* _tmp21_;
	const gchar* _tmp22_ = NULL;
	const gchar* _tmp25_;
	GQuark _tmp27_ = 0U;
	static GQuark _tmp26_label0 = 0;
	g_return_if_fail (self != NULL);
	_tmp1_ = ft_preferences_window_extension_get_window ((FtPreferencesWindowExtension*) self);
	_tmp2_ = _tmp1_;
	_tmp0_ = _tmp2_;
	_tmp3_ = NULL;
	if (_tmp0_ != NULL) {
		FtPreferencesPanel* _tmp4_;
		FtPreferencesPanel* _tmp5_;
		_tmp4_ = ft_preferences_window_get_visible_panel (_tmp0_);
		_tmp5_ = _tmp4_;
		_tmp3_ = _tmp5_;
	}
	_tmp6_ = _g_object_ref0 (_tmp3_);
	panel = _tmp6_;
	_tmp7_ = panel;
	_tmp8_ = self->priv->last_panel;
	if (_tmp7_ != _tmp8_) {
		FtPreferencesPanel* _tmp9_ = NULL;
		FtPreferencesPanel* _tmp10_;
		const gchar* _tmp11_ = NULL;
		const gchar* _tmp14_;
		GQuark _tmp16_ = 0U;
		static GQuark _tmp15_label0 = 0;
		FtPreferencesPanel* _tmp18_;
		FtPreferencesPanel* _tmp19_;
		_tmp10_ = self->priv->last_panel;
		_tmp9_ = _tmp10_;
		_tmp11_ = NULL;
		if (_tmp9_ != NULL) {
			const gchar* _tmp12_;
			const gchar* _tmp13_;
			_tmp12_ = adw_navigation_page_get_tag ((AdwNavigationPage*) _tmp9_);
			_tmp13_ = _tmp12_;
			_tmp11_ = _tmp13_;
		}
		_tmp14_ = _tmp11_;
		_tmp16_ = (NULL == _tmp14_) ? 0 : g_quark_from_string (_tmp14_);
		if (_tmp16_ == ((0 != _tmp15_label0) ? _tmp15_label0 : (_tmp15_label0 = g_quark_from_static_string ("appearance")))) {
			switch (0) {
				default:
				{
					FtPreferencesPanel* _tmp17_;
					_tmp17_ = self->priv->last_panel;
					sni_preferences_window_extension_taredown_appearance_panel (self, _tmp17_);
					break;
				}
			}
		}
		_tmp18_ = panel;
		_tmp19_ = _g_object_ref0 (_tmp18_);
		_g_object_unref0 (self->priv->last_panel);
		self->priv->last_panel = _tmp19_;
	}
	_tmp21_ = panel;
	_tmp20_ = _tmp21_;
	_tmp22_ = NULL;
	if (_tmp20_ != NULL) {
		const gchar* _tmp23_;
		const gchar* _tmp24_;
		_tmp23_ = adw_navigation_page_get_tag ((AdwNavigationPage*) _tmp20_);
		_tmp24_ = _tmp23_;
		_tmp22_ = _tmp24_;
	}
	_tmp25_ = _tmp22_;
	_tmp27_ = (NULL == _tmp25_) ? 0 : g_quark_from_string (_tmp25_);
	if (_tmp27_ == ((0 != _tmp26_label0) ? _tmp26_label0 : (_tmp26_label0 = g_quark_from_static_string ("appearance")))) {
		switch (0) {
			default:
			{
				FtPreferencesPanel* _tmp28_;
				_tmp28_ = panel;
				sni_preferences_window_extension_setup_appearance_panel (self, _tmp28_);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				sni_preferences_window_extension_taredown (self);
				break;
			}
		}
	}
	_g_object_unref0 (panel);
	_g_object_unref0 (_tmp0_);
}

static void
sni_preferences_window_extension_taredown (SniPreferencesWindowExtension* self)
{
	FtPreferencesPanel* _tmp0_;
	FtPreferencesPanel* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->last_panel;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->last_panel;
	sni_preferences_window_extension_taredown_appearance_panel (self, _tmp1_);
	_g_object_unref0 (self->priv->last_panel);
	self->priv->last_panel = NULL;
}

static void
sni_preferences_window_extension_update (SniPreferencesWindowExtension* self)
{
	FtIndicator* _tmp0_ = NULL;
	FtIndicator* _tmp1_;
	FtIndicatorProvider* _tmp2_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->indicator;
	_tmp0_ = _tmp1_;
	_tmp2_ = NULL;
	if (_tmp0_ != NULL) {
		gconstpointer _tmp3_;
		gconstpointer _tmp4_;
		_tmp3_ = ft_provided_object_get_provider ((FtProvidedObject*) _tmp0_);
		_tmp4_ = _tmp3_;
		_tmp2_ = (FtIndicatorProvider*) _tmp4_;
	}
	if (SNI_IS_INDICATOR_PROVIDER (_tmp2_)) {
		sni_preferences_window_extension_setup (self);
	} else {
		sni_preferences_window_extension_taredown (self);
	}
}

static void
sni_preferences_window_extension_on_notify_provider (SniPreferencesWindowExtension* self,
                                                     GObject* object,
                                                     GParamSpec* pspec)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	sni_preferences_window_extension_update (self);
}

static void
sni_preferences_window_extension_on_notify_visible_panel (SniPreferencesWindowExtension* self,
                                                          GObject* object,
                                                          GParamSpec* pspec)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	sni_preferences_window_extension_update (self);
}

static void
_sni_preferences_window_extension_on_notify_visible_panel_g_object_notify (GObject* _sender,
                                                                           GParamSpec* pspec,
                                                                           gpointer self)
{
	sni_preferences_window_extension_on_notify_visible_panel ((SniPreferencesWindowExtension*) self, _sender, pspec);
}

static void
sni_preferences_window_extension_on_notify_window (SniPreferencesWindowExtension* self,
                                                   GObject* object,
                                                   GParamSpec* pspec)
{
	FtPreferencesWindow* _tmp0_;
	FtPreferencesWindow* _tmp1_;
	FtPreferencesWindow* _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = ft_preferences_window_extension_get_window ((FtPreferencesWindowExtension*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		FtPreferencesWindow* _tmp4_;
		FtPreferencesWindow* _tmp5_;
		FtPreferencesWindow* _tmp6_;
		_tmp4_ = ft_preferences_window_extension_get_window ((FtPreferencesWindowExtension*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_;
		g_signal_connect_object ((GObject*) _tmp6_, "notify::visible-panel", (GCallback) _sni_preferences_window_extension_on_notify_visible_panel_g_object_notify, self, 0);
		_g_object_unref0 (_tmp6_);
	}
}

static void
_sni_preferences_window_extension_on_notify_provider_g_object_notify (GObject* _sender,
                                                                      GParamSpec* pspec,
                                                                      gpointer self)
{
	sni_preferences_window_extension_on_notify_provider ((SniPreferencesWindowExtension*) self, _sender, pspec);
}

static void
sni_preferences_window_extension_real_dispose (GObject* base)
{
	SniPreferencesWindowExtension * self;
	FtPreferencesWindow* _tmp0_;
	FtPreferencesWindow* _tmp1_;
	FtPreferencesWindow* _tmp2_;
	gboolean _tmp3_;
	FtIndicator* _tmp9_;
	self = (SniPreferencesWindowExtension*) base;
	sni_preferences_window_extension_taredown (self);
	_tmp0_ = ft_preferences_window_extension_get_window ((FtPreferencesWindowExtension*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		FtPreferencesWindow* _tmp4_;
		FtPreferencesWindow* _tmp5_;
		FtPreferencesWindow* _tmp6_;
		guint _tmp7_;
		GQuark _tmp8_;
		_tmp4_ = ft_preferences_window_extension_get_window ((FtPreferencesWindowExtension*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_;
		g_signal_parse_name ("notify::visible-panel", G_TYPE_OBJECT, &_tmp7_, &_tmp8_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp6_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp7_, _tmp8_, NULL, (GCallback) _sni_preferences_window_extension_on_notify_visible_panel_g_object_notify, self);
		_g_object_unref0 (_tmp6_);
	}
	_tmp9_ = self->priv->indicator;
	if (_tmp9_ != NULL) {
		FtIndicator* _tmp10_;
		guint _tmp11_;
		GQuark _tmp12_;
		_tmp10_ = self->priv->indicator;
		g_signal_parse_name ("notify::provider", G_TYPE_OBJECT, &_tmp11_, &_tmp12_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp10_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp11_, _tmp12_, NULL, (GCallback) _sni_preferences_window_extension_on_notify_provider_g_object_notify, self);
		_g_object_unref0 (self->priv->indicator);
		self->priv->indicator = NULL;
	}
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = NULL;
	G_OBJECT_CLASS (sni_preferences_window_extension_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PREFERENCES_WINDOW_EXTENSION, FtPreferencesWindowExtension));
}

SniPreferencesWindowExtension*
sni_preferences_window_extension_construct (GType object_type)
{
	SniPreferencesWindowExtension * self = NULL;
	self = (SniPreferencesWindowExtension*) ft_preferences_window_extension_construct (object_type);
	return self;
}

SniPreferencesWindowExtension*
sni_preferences_window_extension_new (void)
{
	return sni_preferences_window_extension_construct (SNI_TYPE_PREFERENCES_WINDOW_EXTENSION);
}

static void
_sni_preferences_window_extension_on_notify_window_g_object_notify (GObject* _sender,
                                                                    GParamSpec* pspec,
                                                                    gpointer self)
{
	sni_preferences_window_extension_on_notify_window ((SniPreferencesWindowExtension*) self, _sender, pspec);
}

static GObject *
sni_preferences_window_extension_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SniPreferencesWindowExtension * self;
	GSettings* _tmp0_;
	FtIndicator* _tmp1_;
	FtIndicator* _tmp2_;
	parent_class = G_OBJECT_CLASS (sni_preferences_window_extension_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SNI_TYPE_PREFERENCES_WINDOW_EXTENSION, SniPreferencesWindowExtension);
	_tmp0_ = g_settings_new ("io.github.focustimerhq.FocusTimer.plugins.sni");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp0_;
	_tmp1_ = ft_indicator_new ();
	_g_object_unref0 (self->priv->indicator);
	self->priv->indicator = _tmp1_;
	_tmp2_ = self->priv->indicator;
	g_signal_connect_object ((GObject*) _tmp2_, "notify::provider", (GCallback) _sni_preferences_window_extension_on_notify_provider_g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) self, "notify::window", (GCallback) _sni_preferences_window_extension_on_notify_window_g_object_notify, self, 0);
	return obj;
}

static void
sni_preferences_window_extension_class_init (SniPreferencesWindowExtensionClass * klass,
                                             gpointer klass_data)
{
	sni_preferences_window_extension_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SniPreferencesWindowExtension_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) sni_preferences_window_extension_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = sni_preferences_window_extension_constructor;
	G_OBJECT_CLASS (klass)->finalize = sni_preferences_window_extension_finalize;
}

static void
sni_preferences_window_extension_instance_init (SniPreferencesWindowExtension * self,
                                                gpointer klass)
{
	self->priv = sni_preferences_window_extension_get_instance_private (self);
	self->priv->settings = NULL;
	self->priv->indicator = NULL;
	self->priv->last_panel = NULL;
	self->priv->indicator_group = NULL;
}

static void
sni_preferences_window_extension_finalize (GObject * obj)
{
	SniPreferencesWindowExtension * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SNI_TYPE_PREFERENCES_WINDOW_EXTENSION, SniPreferencesWindowExtension);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->indicator);
	_g_object_unref0 (self->priv->last_panel);
	G_OBJECT_CLASS (sni_preferences_window_extension_parent_class)->finalize (obj);
}

/**
     * Offer to disable the indicator as it may be buggy or less useful with some hosts.
     * Other indicator implementations can't be disabled, so the toggle is specific to
     * SNI plugin.
     */
GType
sni_preferences_window_extension_get_type (void)
{
	return sni_preferences_window_extension_type_id;
}

GType
sni_preferences_window_extension_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (SniPreferencesWindowExtensionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sni_preferences_window_extension_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SniPreferencesWindowExtension), 0, (GInstanceInitFunc) sni_preferences_window_extension_instance_init, NULL };
	sni_preferences_window_extension_type_id = g_type_module_register_type (module, FT_TYPE_PREFERENCES_WINDOW_EXTENSION, "SniPreferencesWindowExtension", &g_define_type_info, 0);
	SniPreferencesWindowExtension_private_offset = sizeof (SniPreferencesWindowExtensionPrivate);
	return sni_preferences_window_extension_type_id;
}

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

