/* MainWindow.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from MainWindow.vala, do not modify */

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2018–2025 Cassidy James Blaede <c@ssidyjam.es>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#define APP_ID "com.cassidyjames.clairvoyant"
#define VERSION "3.1.12"
#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 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;
typedef struct _MainWindowPrivate MainWindowPrivate;

#define TYPE_FORTUNE_LABEL (fortune_label_get_type ())
#define FORTUNE_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORTUNE_LABEL, FortuneLabel))
#define FORTUNE_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORTUNE_LABEL, FortuneLabelClass))
#define IS_FORTUNE_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORTUNE_LABEL))
#define IS_FORTUNE_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORTUNE_LABEL))
#define FORTUNE_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORTUNE_LABEL, FortuneLabelClass))

typedef struct _FortuneLabel FortuneLabel;
typedef struct _FortuneLabelClass FortuneLabelClass;
enum  {
	MAIN_WINDOW_0_PROPERTY,
	MAIN_WINDOW_NUM_PROPERTIES
};
static GParamSpec* main_window_properties[MAIN_WINDOW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _FortuneLabelPrivate FortuneLabelPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block2Data Block2Data;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

struct _MainWindow {
	AdwApplicationWindow parent_instance;
	MainWindowPrivate * priv;
};

struct _MainWindowClass {
	AdwApplicationWindowClass parent_class;
};

struct _MainWindowPrivate {
	FortuneLabel* fortune_label;
};

struct _FortuneLabel {
	GtkBox parent_instance;
	FortuneLabelPrivate * priv;
	GtkStack* stack;
};

struct _FortuneLabelClass {
	GtkBoxClass parent_class;
};

struct _Block2Data {
	int _ref_count_;
	MainWindow* self;
	AdwAboutWindow* about_window;
};

static gint MainWindow_private_offset;
static gpointer main_window_parent_class = NULL;

VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
VALA_EXTERN GType fortune_label_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FortuneLabel, g_object_unref)
VALA_EXTERN MainWindow* main_window_new (GtkApplication* application);
VALA_EXTERN MainWindow* main_window_construct (GType object_type,
                                   GtkApplication* application);
static void main_window_randomize_fortune (MainWindow* self,
                                    FortuneLabel* fortune_label,
                                    gboolean allow_current);
static GObject * main_window_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
VALA_EXTERN FortuneLabel* fortune_label_new (void);
VALA_EXTERN FortuneLabel* fortune_label_construct (GType object_type);
static void _main_window___lambda4_ (MainWindow* self);
static void __main_window___lambda4__gtk_widget_realize (GtkWidget* _sender,
                                                  gpointer self);
static void _main_window___lambda5_ (Block2Data* _data2_);
static void __main_window___lambda5__gtk_button_clicked (GtkButton* _sender,
                                                  gpointer self);
static void _main_window___lambda6_ (MainWindow* self);
static void __main_window___lambda6__gtk_button_clicked (GtkButton* _sender,
                                                  gpointer self);
static void main_window_finalize (GObject * obj);
static GType main_window_get_type_once (void);

static inline gpointer
main_window_get_instance_private (MainWindow* self)
{
	return G_STRUCT_MEMBER_P (self, MainWindow_private_offset);
}

MainWindow*
main_window_construct (GType object_type,
                       GtkApplication* application)
{
	MainWindow * self = NULL;
	g_return_val_if_fail (application != NULL, NULL);
	self = (MainWindow*) g_object_new (object_type, "application", application, "icon-name", APP_ID, "resizable", FALSE, NULL);
	return self;
}

MainWindow*
main_window_new (GtkApplication* application)
{
	return main_window_construct (TYPE_MAIN_WINDOW, application);
}

static void
main_window_randomize_fortune (MainWindow* self,
                               FortuneLabel* fortune_label,
                               gboolean allow_current)
{
	gint rand = 0;
	gint current = 0;
	GtkStack* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (fortune_label != NULL);
	rand = (gint) g_random_int_range ((gint32) 1, (gint32) 29);
	_tmp0_ = fortune_label->stack;
	_tmp1_ = gtk_stack_get_visible_child_name (_tmp0_);
	_tmp2_ = _tmp1_;
	current = atoi (_tmp2_);
	if (allow_current) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = rand != current;
	}
	if (_tmp3_) {
		GtkStack* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = fortune_label->stack;
		_tmp5_ = g_strdup_printf ("%i", rand);
		_tmp6_ = _tmp5_;
		gtk_stack_set_visible_child_name (_tmp4_, _tmp6_);
		_g_free0 (_tmp6_);
		return;
	}
	main_window_randomize_fortune (self, fortune_label, FALSE);
}

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		MainWindow* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->about_window);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

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

static void
_main_window___lambda4_ (MainWindow* self)
{
	FortuneLabel* _tmp0_;
	_tmp0_ = self->priv->fortune_label;
	main_window_randomize_fortune (self, _tmp0_, TRUE);
}

static void
__main_window___lambda4__gtk_widget_realize (GtkWidget* _sender,
                                             gpointer self)
{
	_main_window___lambda4_ ((MainWindow*) self);
}

static void
_main_window___lambda5_ (Block2Data* _data2_)
{
	MainWindow* self;
	AdwAboutWindow* _tmp0_;
	self = _data2_->self;
	_tmp0_ = _data2_->about_window;
	gtk_window_present ((GtkWindow*) _tmp0_);
}

static void
__main_window___lambda5__gtk_button_clicked (GtkButton* _sender,
                                             gpointer self)
{
	_main_window___lambda5_ (self);
}

static void
_main_window___lambda6_ (MainWindow* self)
{
	FortuneLabel* _tmp0_;
	_tmp0_ = self->priv->fortune_label;
	main_window_randomize_fortune (self, _tmp0_, FALSE);
}

static void
__main_window___lambda6__gtk_button_clicked (GtkButton* _sender,
                                             gpointer self)
{
	_main_window___lambda6_ ((MainWindow*) self);
}

static GObject *
main_window_constructor (GType type,
                         guint n_construct_properties,
                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	MainWindow * self;
	Block2Data* _data2_;
	GtkButton* about_button = NULL;
	gchar* _tmp0_;
	GtkButton* _tmp1_ = NULL;
	GtkButton* _tmp2_;
	GtkWindow* _tmp3_;
	gchar* _tmp4_;
	AdwAboutWindow* _tmp5_ = NULL;
	AdwAboutWindow* _tmp6_;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	AdwAboutWindow* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	AdwAboutWindow* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	GtkHeaderBar* header = NULL;
	GtkLabel* _tmp17_;
	GtkHeaderBar* _tmp18_ = NULL;
	GtkHeaderBar* _tmp19_;
	GtkHeaderBar* _tmp20_;
	GtkButton* _tmp21_;
	FortuneLabel* _tmp22_ = NULL;
	GtkButton* ask_button = NULL;
	GtkButton* _tmp23_ = NULL;
	GtkButton* _tmp24_;
	GtkButton* _tmp25_;
	GtkBox* main_layout = NULL;
	GtkBox* _tmp26_;
	GtkBox* _tmp27_;
	GtkHeaderBar* _tmp28_;
	GtkBox* _tmp29_;
	FortuneLabel* _tmp30_;
	GtkBox* _tmp31_;
	GtkButton* _tmp32_;
	GtkWindowHandle* window_handle = NULL;
	GtkBox* _tmp33_;
	GtkWidget* _tmp34_;
	GtkWindowHandle* _tmp35_ = NULL;
	GtkWindowHandle* _tmp36_;
	FortuneLabel* _tmp37_;
	GtkButton* _tmp38_;
	GtkButton* _tmp39_;
	parent_class = G_OBJECT_CLASS (main_window_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MAIN_WINDOW, MainWindow);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = g_strdup (_ ("About"));
	_tmp1_ = (GtkButton*) gtk_button_new_from_icon_name ("about-symbolic");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp1_, _tmp0_);
	_g_free0 (_tmp0_);
	g_object_ref_sink (_tmp1_);
	about_button = _tmp1_;
	_tmp2_ = about_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp2_, "dim-label");
	_tmp3_ = _g_object_ref0 ((GtkWindow*) self);
	_tmp4_ = g_strdup (_ ("translator-credits"));
	_tmp5_ = (AdwAboutWindow*) adw_about_window_new_from_appdata ("/com/cassidyjames/clairvoyant/metainfo.xml", VERSION);
	gtk_window_set_transient_for ((GtkWindow*) _tmp5_, _tmp3_);
	_g_object_unref0 (_tmp3_);
	gtk_window_set_hide_on_close ((GtkWindow*) _tmp5_, TRUE);
	adw_about_window_set_translator_credits (_tmp5_, _tmp4_);
	_g_free0 (_tmp4_);
	g_object_ref_sink (_tmp5_);
	_data2_->about_window = _tmp5_;
	_tmp6_ = _data2_->about_window;
	_tmp7_ = g_date_time_new_now_local ();
	_tmp8_ = _tmp7_;
	_tmp9_ = _data2_->about_window;
	_tmp10_ = adw_about_window_get_developer_name (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strdup_printf ("© 2018–%i %s", g_date_time_get_year (_tmp8_), _tmp11_);
	_tmp13_ = _tmp12_;
	adw_about_window_set_copyright (_tmp6_, _tmp13_);
	_g_free0 (_tmp13_);
	_g_date_time_unref0 (_tmp8_);
	_tmp14_ = _data2_->about_window;
	_tmp15_ = adw_about_window_get_application_name (_tmp14_);
	_tmp16_ = _tmp15_;
	gtk_window_set_title ((GtkWindow*) self, _tmp16_);
	_tmp17_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp17_);
	_tmp18_ = (GtkHeaderBar*) gtk_header_bar_new ();
	gtk_header_bar_set_title_widget (_tmp18_, (GtkWidget*) _tmp17_);
	_g_object_unref0 (_tmp17_);
	g_object_ref_sink (_tmp18_);
	header = _tmp18_;
	_tmp19_ = header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp19_, "flat");
	_tmp20_ = header;
	_tmp21_ = about_button;
	gtk_header_bar_pack_start (_tmp20_, (GtkWidget*) _tmp21_);
	_tmp22_ = fortune_label_new ();
	gtk_widget_set_margin_top ((GtkWidget*) _tmp22_, 24);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp22_, 24);
	g_object_ref_sink (_tmp22_);
	_g_object_unref0 (self->priv->fortune_label);
	self->priv->fortune_label = _tmp22_;
	_tmp23_ = (GtkButton*) gtk_button_new_with_label (_ ("Ask Again"));
	gtk_widget_set_halign ((GtkWidget*) _tmp23_, GTK_ALIGN_CENTER);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp23_, 48);
	g_object_ref_sink (_tmp23_);
	ask_button = _tmp23_;
	_tmp24_ = ask_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp24_, "suggested-action");
	_tmp25_ = ask_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp25_, "pill");
	_tmp26_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp26_);
	main_layout = _tmp26_;
	_tmp27_ = main_layout;
	_tmp28_ = header;
	gtk_box_append (_tmp27_, (GtkWidget*) _tmp28_);
	_tmp29_ = main_layout;
	_tmp30_ = self->priv->fortune_label;
	gtk_box_append (_tmp29_, (GtkWidget*) _tmp30_);
	_tmp31_ = main_layout;
	_tmp32_ = ask_button;
	gtk_box_append (_tmp31_, (GtkWidget*) _tmp32_);
	_tmp33_ = main_layout;
	_tmp34_ = _g_object_ref0 ((GtkWidget*) _tmp33_);
	_tmp35_ = (GtkWindowHandle*) gtk_window_handle_new ();
	gtk_window_handle_set_child (_tmp35_, _tmp34_);
	_g_object_unref0 (_tmp34_);
	g_object_ref_sink (_tmp35_);
	window_handle = _tmp35_;
	_tmp36_ = window_handle;
	adw_application_window_set_content ((AdwApplicationWindow*) self, (GtkWidget*) _tmp36_);
	_tmp37_ = self->priv->fortune_label;
	g_signal_connect_object ((GtkWidget*) _tmp37_, "realize", (GCallback) __main_window___lambda4__gtk_widget_realize, self, 0);
	_tmp38_ = about_button;
	g_signal_connect_data (_tmp38_, "clicked", (GCallback) __main_window___lambda5__gtk_button_clicked, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	_tmp39_ = ask_button;
	g_signal_connect_object (_tmp39_, "clicked", (GCallback) __main_window___lambda6__gtk_button_clicked, self, 0);
	_g_object_unref0 (window_handle);
	_g_object_unref0 (main_layout);
	_g_object_unref0 (ask_button);
	_g_object_unref0 (header);
	_g_object_unref0 (about_button);
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return obj;
}

static void
main_window_class_init (MainWindowClass * klass,
                        gpointer klass_data)
{
	main_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MainWindow_private_offset);
	G_OBJECT_CLASS (klass)->constructor = main_window_constructor;
	G_OBJECT_CLASS (klass)->finalize = main_window_finalize;
}

static void
main_window_instance_init (MainWindow * self,
                           gpointer klass)
{
	self->priv = main_window_get_instance_private (self);
}

static void
main_window_finalize (GObject * obj)
{
	MainWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MAIN_WINDOW, MainWindow);
	_g_object_unref0 (self->priv->fortune_label);
	G_OBJECT_CLASS (main_window_parent_class)->finalize (obj);
}

static GType
main_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MainWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) main_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MainWindow), 0, (GInstanceInitFunc) main_window_instance_init, NULL };
	GType main_window_type_id;
	main_window_type_id = g_type_register_static (adw_application_window_get_type (), "MainWindow", &g_define_type_info, 0);
	MainWindow_private_offset = g_type_add_instance_private (main_window_type_id, sizeof (MainWindowPrivate));
	return main_window_type_id;
}

GType
main_window_get_type (void)
{
	static volatile gsize main_window_type_id__once = 0;
	if (g_once_init_enter (&main_window_type_id__once)) {
		GType main_window_type_id;
		main_window_type_id = main_window_get_type_once ();
		g_once_init_leave (&main_window_type_id__once, main_window_type_id);
	}
	return main_window_type_id__once;
}

