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

/*
 * Copyright © 2025 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: nijakow (https://github.com/nijakow)
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n-lib.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW (widgets_bypass_resolve_switch_row_get_type ())
#define WIDGETS_BYPASS_RESOLVE_SWITCH_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW, WidgetsBypassResolveSwitchRow))
#define WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW, WidgetsBypassResolveSwitchRowClass))
#define WIDGETS_IS_BYPASS_RESOLVE_SWITCH_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW))
#define WIDGETS_IS_BYPASS_RESOLVE_SWITCH_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW))
#define WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW, WidgetsBypassResolveSwitchRowClass))

typedef struct _WidgetsBypassResolveSwitchRow WidgetsBypassResolveSwitchRow;
typedef struct _WidgetsBypassResolveSwitchRowClass WidgetsBypassResolveSwitchRowClass;
typedef struct _WidgetsBypassResolveSwitchRowPrivate WidgetsBypassResolveSwitchRowPrivate;
enum  {
	WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_0_PROPERTY,
	WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_ACTIVE_PROPERTY,
	WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_NUM_PROPERTIES
};
static GParamSpec* widgets_bypass_resolve_switch_row_properties[WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_PLANIFY (planify_get_type ())
#define PLANIFY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLANIFY, Planify))
#define PLANIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLANIFY, PlanifyClass))
#define IS_PLANIFY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLANIFY))
#define IS_PLANIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLANIFY))
#define PLANIFY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLANIFY, PlanifyClass))

typedef struct _Planify Planify;
typedef struct _PlanifyClass PlanifyClass;
typedef struct _PlanifyPrivate PlanifyPrivate;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;

struct _WidgetsBypassResolveSwitchRow {
	AdwActionRow parent_instance;
	WidgetsBypassResolveSwitchRowPrivate * priv;
};

struct _WidgetsBypassResolveSwitchRowClass {
	AdwActionRowClass parent_class;
};

struct _WidgetsBypassResolveSwitchRowPrivate {
	GtkSwitch* toggle;
};

struct _Planify {
	AdwApplication parent_instance;
	PlanifyPrivate * priv;
	MainWindow* main_window;
};

struct _PlanifyClass {
	AdwApplicationClass parent_class;
};

static gint WidgetsBypassResolveSwitchRow_private_offset;
static gpointer widgets_bypass_resolve_switch_row_parent_class = NULL;
VALA_EXTERN Planify* planify__instance;

VALA_EXTERN GType widgets_bypass_resolve_switch_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsBypassResolveSwitchRow, g_object_unref)
VALA_EXTERN WidgetsBypassResolveSwitchRow* widgets_bypass_resolve_switch_row_new (void);
VALA_EXTERN WidgetsBypassResolveSwitchRow* widgets_bypass_resolve_switch_row_construct (GType object_type);
static gboolean __lambda321_ (WidgetsBypassResolveSwitchRow* self,
                       gboolean state);
static void ___lambda322_ (WidgetsBypassResolveSwitchRow* self,
                    const gchar* response);
static void ____lambda322__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                               const gchar* response,
                                               gpointer self);
VALA_EXTERN GType planify_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Planify, g_object_unref)
VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
static gboolean ___lambda321__gtk_switch_state_set (GtkSwitch* _sender,
                                             gboolean state,
                                             gpointer self);
VALA_EXTERN gboolean widgets_bypass_resolve_switch_row_get_active (WidgetsBypassResolveSwitchRow* self);
VALA_EXTERN void widgets_bypass_resolve_switch_row_set_active (WidgetsBypassResolveSwitchRow* self,
                                                   gboolean value);
static void widgets_bypass_resolve_switch_row_finalize (GObject * obj);
static GType widgets_bypass_resolve_switch_row_get_type_once (void);
static void _vala_widgets_bypass_resolve_switch_row_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec);
static void _vala_widgets_bypass_resolve_switch_row_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec);

static inline gpointer
widgets_bypass_resolve_switch_row_get_instance_private (WidgetsBypassResolveSwitchRow* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsBypassResolveSwitchRow_private_offset);
}

static void
___lambda322_ (WidgetsBypassResolveSwitchRow* self,
               const gchar* response)
{
	g_return_if_fail (response != NULL);
	if (g_strcmp0 (response, "accept") == 0) {
		GtkSwitch* _tmp0_;
		GtkSwitch* _tmp1_;
		_tmp0_ = self->priv->toggle;
		gtk_switch_set_state (_tmp0_, TRUE);
		_tmp1_ = self->priv->toggle;
		gtk_switch_set_active (_tmp1_, TRUE);
	} else {
		GtkSwitch* _tmp2_;
		GtkSwitch* _tmp3_;
		_tmp2_ = self->priv->toggle;
		gtk_switch_set_state (_tmp2_, FALSE);
		_tmp3_ = self->priv->toggle;
		gtk_switch_set_active (_tmp3_, FALSE);
	}
}

static void
____lambda322__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                          const gchar* response,
                                          gpointer self)
{
	___lambda322_ ((WidgetsBypassResolveSwitchRow*) self, response);
}

static gboolean
__lambda321_ (WidgetsBypassResolveSwitchRow* self,
              gboolean state)
{
	gboolean result;
	if (state) {
		AdwAlertDialog* dialog = NULL;
		AdwAlertDialog* _tmp0_;
		AdwAlertDialog* _tmp1_;
		AdwAlertDialog* _tmp2_;
		AdwAlertDialog* _tmp3_;
		AdwAlertDialog* _tmp4_;
		AdwAlertDialog* _tmp5_;
		Planify* _tmp6_;
		MainWindow* _tmp7_;
		_tmp0_ = (AdwAlertDialog*) adw_alert_dialog_new (_ ("Warning"), _ ("This will disable the CalDAV resolve process.\n" \
"Proceed at your own risk"));
		g_object_ref_sink (_tmp0_);
		dialog = _tmp0_;
		_tmp1_ = dialog;
		adw_alert_dialog_add_response (_tmp1_, "cancel", _ ("Cancel"));
		_tmp2_ = dialog;
		adw_alert_dialog_add_response (_tmp2_, "accept", _ ("Continue Anyway"));
		_tmp3_ = dialog;
		adw_alert_dialog_set_response_appearance (_tmp3_, "accept", ADW_RESPONSE_DESTRUCTIVE);
		_tmp4_ = dialog;
		g_signal_connect_object (_tmp4_, "response", (GCallback) ____lambda322__adw_alert_dialog_response, self, 0);
		_tmp5_ = dialog;
		_tmp6_ = planify__instance;
		_tmp7_ = _tmp6_->main_window;
		adw_dialog_present ((AdwDialog*) _tmp5_, (GtkWidget*) _tmp7_);
		result = TRUE;
		_g_object_unref0 (dialog);
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
___lambda321__gtk_switch_state_set (GtkSwitch* _sender,
                                    gboolean state,
                                    gpointer self)
{
	gboolean result;
	result = __lambda321_ ((WidgetsBypassResolveSwitchRow*) self, state);
	return result;
}

WidgetsBypassResolveSwitchRow*
widgets_bypass_resolve_switch_row_construct (GType object_type)
{
	WidgetsBypassResolveSwitchRow * self = NULL;
	GtkSwitch* _tmp0_ = NULL;
	GtkSwitch* _tmp1_;
	GtkSwitch* _tmp2_;
	GtkSwitch* _tmp3_;
	self = (WidgetsBypassResolveSwitchRow*) g_object_new (object_type, NULL);
	adw_preferences_row_set_title ((AdwPreferencesRow*) self, _ ("Bypass Location Resolve"));
	adw_action_row_set_subtitle ((AdwActionRow*) self, _ ("Workaround for CalDAV connection issues with connections using non-def" \
"ault ports"));
	_tmp0_ = (GtkSwitch*) gtk_switch_new ();
	gtk_widget_set_valign ((GtkWidget*) _tmp0_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp0_, GTK_ALIGN_END);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->toggle);
	self->priv->toggle = _tmp0_;
	_tmp1_ = self->priv->toggle;
	adw_action_row_add_suffix ((AdwActionRow*) self, (GtkWidget*) _tmp1_);
	_tmp2_ = self->priv->toggle;
	adw_action_row_set_activatable_widget ((AdwActionRow*) self, (GtkWidget*) _tmp2_);
	_tmp3_ = self->priv->toggle;
	g_signal_connect_object (_tmp3_, "state-set", (GCallback) ___lambda321__gtk_switch_state_set, self, 0);
	return self;
}

WidgetsBypassResolveSwitchRow*
widgets_bypass_resolve_switch_row_new (void)
{
	return widgets_bypass_resolve_switch_row_construct (WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW);
}

gboolean
widgets_bypass_resolve_switch_row_get_active (WidgetsBypassResolveSwitchRow* self)
{
	gboolean result;
	GtkSwitch* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->toggle;
	_tmp1_ = gtk_switch_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
widgets_bypass_resolve_switch_row_set_active (WidgetsBypassResolveSwitchRow* self,
                                              gboolean value)
{
	GtkSwitch* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->toggle;
	gtk_switch_set_active (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, widgets_bypass_resolve_switch_row_properties[WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_ACTIVE_PROPERTY]);
}

static void
widgets_bypass_resolve_switch_row_class_init (WidgetsBypassResolveSwitchRowClass * klass,
                                              gpointer klass_data)
{
	widgets_bypass_resolve_switch_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsBypassResolveSwitchRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_bypass_resolve_switch_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_bypass_resolve_switch_row_set_property;
	G_OBJECT_CLASS (klass)->finalize = widgets_bypass_resolve_switch_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_ACTIVE_PROPERTY, widgets_bypass_resolve_switch_row_properties[WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_ACTIVE_PROPERTY] = g_param_spec_boolean ("active", "active", "active", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
widgets_bypass_resolve_switch_row_instance_init (WidgetsBypassResolveSwitchRow * self,
                                                 gpointer klass)
{
	self->priv = widgets_bypass_resolve_switch_row_get_instance_private (self);
}

static void
widgets_bypass_resolve_switch_row_finalize (GObject * obj)
{
	WidgetsBypassResolveSwitchRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW, WidgetsBypassResolveSwitchRow);
	_g_object_unref0 (self->priv->toggle);
	G_OBJECT_CLASS (widgets_bypass_resolve_switch_row_parent_class)->finalize (obj);
}

static GType
widgets_bypass_resolve_switch_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsBypassResolveSwitchRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_bypass_resolve_switch_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsBypassResolveSwitchRow), 0, (GInstanceInitFunc) widgets_bypass_resolve_switch_row_instance_init, NULL };
	GType widgets_bypass_resolve_switch_row_type_id;
	widgets_bypass_resolve_switch_row_type_id = g_type_register_static (adw_action_row_get_type (), "WidgetsBypassResolveSwitchRow", &g_define_type_info, 0);
	WidgetsBypassResolveSwitchRow_private_offset = g_type_add_instance_private (widgets_bypass_resolve_switch_row_type_id, sizeof (WidgetsBypassResolveSwitchRowPrivate));
	return widgets_bypass_resolve_switch_row_type_id;
}

GType
widgets_bypass_resolve_switch_row_get_type (void)
{
	static volatile gsize widgets_bypass_resolve_switch_row_type_id__once = 0;
	if (g_once_init_enter (&widgets_bypass_resolve_switch_row_type_id__once)) {
		GType widgets_bypass_resolve_switch_row_type_id;
		widgets_bypass_resolve_switch_row_type_id = widgets_bypass_resolve_switch_row_get_type_once ();
		g_once_init_leave (&widgets_bypass_resolve_switch_row_type_id__once, widgets_bypass_resolve_switch_row_type_id);
	}
	return widgets_bypass_resolve_switch_row_type_id__once;
}

static void
_vala_widgets_bypass_resolve_switch_row_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec)
{
	WidgetsBypassResolveSwitchRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW, WidgetsBypassResolveSwitchRow);
	switch (property_id) {
		case WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_ACTIVE_PROPERTY:
		g_value_set_boolean (value, widgets_bypass_resolve_switch_row_get_active (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_bypass_resolve_switch_row_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec)
{
	WidgetsBypassResolveSwitchRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_BYPASS_RESOLVE_SWITCH_ROW, WidgetsBypassResolveSwitchRow);
	switch (property_id) {
		case WIDGETS_BYPASS_RESOLVE_SWITCH_ROW_ACTIVE_PROPERTY:
		widgets_bypass_resolve_switch_row_set_active (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

