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

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

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

struct _GnomeWindowExtensionPrivate {
	GnomeShellExtension* shell_extension;
	AdwToast* install_extension_toast;
};

static gint GnomeWindowExtension_private_offset;
static gpointer gnome_window_extension_parent_class = NULL;
static gboolean gnome_window_extension_install_extension_toast_dismissed;
static gboolean gnome_window_extension_install_extension_toast_dismissed = FALSE;
static GType gnome_window_extension_type_id = 0;

static void gnome_window_extension_show_install_extension_toast (GnomeWindowExtension* self);
static void __lambda6_ (GnomeWindowExtension* self);
static void ___lambda6__adw_toast_button_clicked (AdwToast* _sender,
                                           gpointer self);
static void gnome_window_extension_on_install_extension_toast_dismissed (GnomeWindowExtension* self,
                                                                  AdwToast* toast);
static void _gnome_window_extension_on_install_extension_toast_dismissed_adw_toast_dismissed (AdwToast* _sender,
                                                                                       gpointer self);
static void gnome_window_extension_update_install_extension_toast (GnomeWindowExtension* self);
static void gnome_window_extension_on_notify_window (GnomeWindowExtension* self,
                                              GObject* object,
                                              GParamSpec* pspec);
static void gnome_window_extension_on_map (GnomeWindowExtension* self);
static void _gnome_window_extension_on_map_gtk_widget_map (GtkWidget* _sender,
                                                    gpointer self);
static void gnome_window_extension_on_extension_notify_available (GnomeWindowExtension* self,
                                                           GObject* object,
                                                           GParamSpec* pspec);
static void gnome_window_extension_real_dispose (GObject* base);
static void _gnome_window_extension_on_extension_notify_available_g_object_notify (GObject* _sender,
                                                                            GParamSpec* pspec,
                                                                            gpointer self);
static GObject * gnome_window_extension_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _gnome_window_extension_on_notify_window_g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self);
static void gnome_window_extension_finalize (GObject * obj);

static inline gpointer
gnome_window_extension_get_instance_private (GnomeWindowExtension* self)
{
	return G_STRUCT_MEMBER_P (self, GnomeWindowExtension_private_offset);
}

static void
__lambda6_ (GnomeWindowExtension* self)
{
	GnomeInstallExtensionDialog* dialog = NULL;
	GnomeInstallExtensionDialog* _tmp0_;
	FtWindow* _tmp1_;
	FtWindow* _tmp2_;
	FtWindow* _tmp3_;
	_tmp0_ = gnome_install_extension_dialog_new ();
	g_object_ref_sink (_tmp0_);
	dialog = _tmp0_;
	_tmp1_ = ft_window_extension_get_window ((FtWindowExtension*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	adw_dialog_present ((AdwDialog*) dialog, (GtkWidget*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	_g_object_unref0 (self->priv->install_extension_toast);
	self->priv->install_extension_toast = NULL;
	_g_object_unref0 (dialog);
}

static void
___lambda6__adw_toast_button_clicked (AdwToast* _sender,
                                      gpointer self)
{
	__lambda6_ ((GnomeWindowExtension*) self);
}

static void
_gnome_window_extension_on_install_extension_toast_dismissed_adw_toast_dismissed (AdwToast* _sender,
                                                                                  gpointer self)
{
	gnome_window_extension_on_install_extension_toast_dismissed ((GnomeWindowExtension*) self, _sender);
}

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

static void
gnome_window_extension_show_install_extension_toast (GnomeWindowExtension* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	AdwToast* toast = NULL;
	AdwToast* _tmp6_;
	AdwToast* _tmp7_;
	AdwToast* _tmp8_;
	AdwToast* _tmp9_;
	AdwToast* _tmp10_;
	AdwToast* _tmp11_;
	AdwToast* _tmp12_;
	AdwToast* _tmp13_;
	FtWindow* _tmp14_;
	FtWindow* _tmp15_;
	FtWindow* _tmp16_;
	AdwToast* _tmp17_;
	AdwToast* _tmp18_;
	g_return_if_fail (self != NULL);
	if (gnome_window_extension_install_extension_toast_dismissed) {
		_tmp1_ = TRUE;
	} else {
		AdwToast* _tmp2_;
		_tmp2_ = self->priv->install_extension_toast;
		_tmp1_ = _tmp2_ != NULL;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		FtWindow* _tmp3_;
		FtWindow* _tmp4_;
		FtWindow* _tmp5_;
		_tmp3_ = ft_window_extension_get_window ((FtWindowExtension*) self);
		_tmp4_ = _tmp3_;
		_tmp5_ = _tmp4_;
		_tmp0_ = _tmp5_ == NULL;
		_g_object_unref0 (_tmp5_);
	}
	if (_tmp0_) {
		return;
	}
	_tmp6_ = adw_toast_new (_ ("GNOME Shell extension available"));
	toast = _tmp6_;
	_tmp7_ = toast;
	adw_toast_set_button_label (_tmp7_, _ ("Learn More"));
	_tmp8_ = toast;
	adw_toast_set_priority (_tmp8_, ADW_TOAST_PRIORITY_HIGH);
	_tmp9_ = toast;
	adw_toast_set_timeout (_tmp9_, (guint) 0);
	_tmp10_ = toast;
	g_signal_connect_object (_tmp10_, "button-clicked", (GCallback) ___lambda6__adw_toast_button_clicked, self, 0);
	_tmp11_ = toast;
	g_signal_connect_object (_tmp11_, "dismissed", (GCallback) _gnome_window_extension_on_install_extension_toast_dismissed_adw_toast_dismissed, self, 0);
	_tmp12_ = toast;
	_tmp13_ = _g_object_ref0 (_tmp12_);
	_g_object_unref0 (self->priv->install_extension_toast);
	self->priv->install_extension_toast = _tmp13_;
	_tmp14_ = ft_window_extension_get_window ((FtWindowExtension*) self);
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_;
	_tmp17_ = toast;
	_tmp18_ = _g_object_ref0 (_tmp17_);
	ft_window_add_toast (_tmp16_, _tmp18_);
	_g_object_unref0 (_tmp16_);
	_g_object_unref0 (toast);
}

static void
gnome_window_extension_update_install_extension_toast (GnomeWindowExtension* self)
{
	gboolean _tmp0_ = FALSE;
	FtWindow* _tmp1_;
	FtWindow* _tmp2_;
	FtWindow* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp8_ = FALSE;
	GnomeShellExtension* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	g_return_if_fail (self != NULL);
	if (!GNOME_SHELL_EXTENSION_IS_PUBLISHED) {
		return;
	}
	_tmp1_ = ft_window_extension_get_window ((FtWindowExtension*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_ == NULL;
	_g_object_unref0 (_tmp3_);
	if (_tmp4_) {
		_tmp0_ = TRUE;
	} else {
		FtWindow* _tmp5_;
		FtWindow* _tmp6_;
		FtWindow* _tmp7_;
		_tmp5_ = ft_window_extension_get_window ((FtWindowExtension*) self);
		_tmp6_ = _tmp5_;
		_tmp7_ = _tmp6_;
		_tmp0_ = !gtk_widget_get_mapped ((GtkWidget*) _tmp7_);
		_g_object_unref0 (_tmp7_);
	}
	if (_tmp0_) {
		return;
	}
	_tmp9_ = self->priv->shell_extension;
	_tmp10_ = gnome_shell_extension_get_available (_tmp9_);
	_tmp11_ = _tmp10_;
	if (_tmp11_) {
		GnomeShellExtension* _tmp12_;
		_tmp12_ = self->priv->shell_extension;
		_tmp8_ = !gnome_shell_extension_is_installed (_tmp12_);
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		gnome_window_extension_show_install_extension_toast (self);
	} else {
		AdwToast* _tmp13_;
		_tmp13_ = self->priv->install_extension_toast;
		if (_tmp13_ != NULL) {
			AdwToast* _tmp14_;
			guint _tmp15_;
			AdwToast* _tmp16_;
			_tmp14_ = self->priv->install_extension_toast;
			g_signal_parse_name ("dismissed", adw_toast_get_type (), &_tmp15_, NULL, FALSE);
			g_signal_handlers_disconnect_matched (_tmp14_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp15_, 0, NULL, (GCallback) _gnome_window_extension_on_install_extension_toast_dismissed_adw_toast_dismissed, self);
			_tmp16_ = self->priv->install_extension_toast;
			adw_toast_dismiss (_tmp16_);
			_g_object_unref0 (self->priv->install_extension_toast);
			self->priv->install_extension_toast = NULL;
		}
	}
}

static void
_gnome_window_extension_on_map_gtk_widget_map (GtkWidget* _sender,
                                               gpointer self)
{
	gnome_window_extension_on_map ((GnomeWindowExtension*) self);
}

static void
gnome_window_extension_on_notify_window (GnomeWindowExtension* self,
                                         GObject* object,
                                         GParamSpec* pspec)
{
	FtWindow* _tmp0_;
	FtWindow* _tmp1_;
	FtWindow* _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = ft_window_extension_get_window ((FtWindowExtension*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		FtWindow* _tmp4_;
		FtWindow* _tmp5_;
		FtWindow* _tmp6_;
		_tmp4_ = ft_window_extension_get_window ((FtWindowExtension*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_;
		g_signal_connect_object ((GtkWidget*) _tmp6_, "map", (GCallback) _gnome_window_extension_on_map_gtk_widget_map, self, 0);
		_g_object_unref0 (_tmp6_);
	}
}

static void
gnome_window_extension_on_map (GnomeWindowExtension* self)
{
	g_return_if_fail (self != NULL);
	gnome_window_extension_update_install_extension_toast (self);
}

static void
gnome_window_extension_on_extension_notify_available (GnomeWindowExtension* self,
                                                      GObject* object,
                                                      GParamSpec* pspec)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	gnome_window_extension_update_install_extension_toast (self);
}

static void
gnome_window_extension_on_install_extension_toast_dismissed (GnomeWindowExtension* self,
                                                             AdwToast* toast)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (toast != NULL);
	_g_object_unref0 (self->priv->install_extension_toast);
	self->priv->install_extension_toast = NULL;
	gnome_window_extension_install_extension_toast_dismissed = TRUE;
}

static void
_gnome_window_extension_on_extension_notify_available_g_object_notify (GObject* _sender,
                                                                       GParamSpec* pspec,
                                                                       gpointer self)
{
	gnome_window_extension_on_extension_notify_available ((GnomeWindowExtension*) self, _sender, pspec);
}

static void
gnome_window_extension_real_dispose (GObject* base)
{
	GnomeWindowExtension * self;
	FtWindow* _tmp0_;
	FtWindow* _tmp1_;
	FtWindow* _tmp2_;
	gboolean _tmp3_;
	GnomeShellExtension* _tmp8_;
	self = (GnomeWindowExtension*) base;
	_tmp0_ = ft_window_extension_get_window ((FtWindowExtension*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		FtWindow* _tmp4_;
		FtWindow* _tmp5_;
		FtWindow* _tmp6_;
		guint _tmp7_;
		_tmp4_ = ft_window_extension_get_window ((FtWindowExtension*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_;
		g_signal_parse_name ("map", gtk_widget_get_type (), &_tmp7_, NULL, FALSE);
		g_signal_handlers_disconnect_matched ((GtkWidget*) _tmp6_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp7_, 0, NULL, (GCallback) _gnome_window_extension_on_map_gtk_widget_map, self);
		_g_object_unref0 (_tmp6_);
	}
	_tmp8_ = self->priv->shell_extension;
	if (_tmp8_ != NULL) {
		GnomeShellExtension* _tmp9_;
		guint _tmp10_;
		GQuark _tmp11_;
		_tmp9_ = self->priv->shell_extension;
		g_signal_parse_name ("notify::available", G_TYPE_OBJECT, &_tmp10_, &_tmp11_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp9_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp10_, _tmp11_, NULL, (GCallback) _gnome_window_extension_on_extension_notify_available_g_object_notify, self);
		_g_object_unref0 (self->priv->shell_extension);
		self->priv->shell_extension = NULL;
	}
	_g_object_unref0 (self->priv->install_extension_toast);
	self->priv->install_extension_toast = NULL;
	G_OBJECT_CLASS (gnome_window_extension_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_WINDOW_EXTENSION, FtWindowExtension));
}

GnomeWindowExtension*
gnome_window_extension_construct (GType object_type)
{
	GnomeWindowExtension * self = NULL;
	self = (GnomeWindowExtension*) ft_window_extension_construct (object_type);
	return self;
}

GnomeWindowExtension*
gnome_window_extension_new (void)
{
	return gnome_window_extension_construct (GNOME_TYPE_WINDOW_EXTENSION);
}

static void
_gnome_window_extension_on_notify_window_g_object_notify (GObject* _sender,
                                                          GParamSpec* pspec,
                                                          gpointer self)
{
	gnome_window_extension_on_notify_window ((GnomeWindowExtension*) self, _sender, pspec);
}

static GObject *
gnome_window_extension_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GnomeWindowExtension * self;
	GnomeShellExtension* _tmp0_;
	GnomeShellExtension* _tmp1_;
	parent_class = G_OBJECT_CLASS (gnome_window_extension_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_WINDOW_EXTENSION, GnomeWindowExtension);
	_tmp0_ = gnome_shell_extension_new ();
	_g_object_unref0 (self->priv->shell_extension);
	self->priv->shell_extension = _tmp0_;
	_tmp1_ = self->priv->shell_extension;
	g_signal_connect_object ((GObject*) _tmp1_, "notify::available", (GCallback) _gnome_window_extension_on_extension_notify_available_g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) self, "notify::window", (GCallback) _gnome_window_extension_on_notify_window_g_object_notify, self, 0);
	return obj;
}

static void
gnome_window_extension_class_init (GnomeWindowExtensionClass * klass,
                                   gpointer klass_data)
{
	gnome_window_extension_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GnomeWindowExtension_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) gnome_window_extension_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = gnome_window_extension_constructor;
	G_OBJECT_CLASS (klass)->finalize = gnome_window_extension_finalize;
}

static void
gnome_window_extension_instance_init (GnomeWindowExtension * self,
                                      gpointer klass)
{
	self->priv = gnome_window_extension_get_instance_private (self);
	self->priv->shell_extension = NULL;
	self->priv->install_extension_toast = NULL;
}

static void
gnome_window_extension_finalize (GObject * obj)
{
	GnomeWindowExtension * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_WINDOW_EXTENSION, GnomeWindowExtension);
	_g_object_unref0 (self->priv->shell_extension);
	_g_object_unref0 (self->priv->install_extension_toast);
	G_OBJECT_CLASS (gnome_window_extension_parent_class)->finalize (obj);
}

GType
gnome_window_extension_get_type (void)
{
	return gnome_window_extension_type_id;
}

GType
gnome_window_extension_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomeWindowExtensionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_window_extension_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomeWindowExtension), 0, (GInstanceInitFunc) gnome_window_extension_instance_init, NULL };
	gnome_window_extension_type_id = g_type_module_register_type (module, FT_TYPE_WINDOW_EXTENSION, "GnomeWindowExtension", &g_define_type_info, 0);
	GnomeWindowExtension_private_offset = sizeof (GnomeWindowExtensionPrivate);
	return gnome_window_extension_type_id;
}

