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

/*-
 * Copyright 2018-2023 elementary, Inc. (https://elementary.io)
 *           2014 Marvin Beckers <beckersmarvin@gmail.com>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Marvin Beckers <beckersmarvin@gmail.com>
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <granite-7.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <locale.h>
#include <glib/gi18n-lib.h>

#define GETTEXT_PACKAGE "io.elementary.calculator"
#define LOCALEDIR "/usr/share/locale"
#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 PANTHEON_CALCULATOR_TYPE_APPLICATION (pantheon_calculator_application_get_type ())
#define PANTHEON_CALCULATOR_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANTHEON_CALCULATOR_TYPE_APPLICATION, PantheonCalculatorApplication))
#define PANTHEON_CALCULATOR_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANTHEON_CALCULATOR_TYPE_APPLICATION, PantheonCalculatorApplicationClass))
#define PANTHEON_CALCULATOR_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANTHEON_CALCULATOR_TYPE_APPLICATION))
#define PANTHEON_CALCULATOR_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANTHEON_CALCULATOR_TYPE_APPLICATION))
#define PANTHEON_CALCULATOR_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANTHEON_CALCULATOR_TYPE_APPLICATION, PantheonCalculatorApplicationClass))

typedef struct _PantheonCalculatorApplication PantheonCalculatorApplication;
typedef struct _PantheonCalculatorApplicationClass PantheonCalculatorApplicationClass;
typedef struct _PantheonCalculatorApplicationPrivate PantheonCalculatorApplicationPrivate;
enum  {
	PANTHEON_CALCULATOR_APPLICATION_0_PROPERTY,
	PANTHEON_CALCULATOR_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* pantheon_calculator_application_properties[PANTHEON_CALCULATOR_APPLICATION_NUM_PROPERTIES];
typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define PANTHEON_CALCULATOR_TYPE_MAIN_WINDOW (pantheon_calculator_main_window_get_type ())
#define PANTHEON_CALCULATOR_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANTHEON_CALCULATOR_TYPE_MAIN_WINDOW, PantheonCalculatorMainWindow))
#define PANTHEON_CALCULATOR_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANTHEON_CALCULATOR_TYPE_MAIN_WINDOW, PantheonCalculatorMainWindowClass))
#define PANTHEON_CALCULATOR_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANTHEON_CALCULATOR_TYPE_MAIN_WINDOW))
#define PANTHEON_CALCULATOR_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANTHEON_CALCULATOR_TYPE_MAIN_WINDOW))
#define PANTHEON_CALCULATOR_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANTHEON_CALCULATOR_TYPE_MAIN_WINDOW, PantheonCalculatorMainWindowClass))

typedef struct _PantheonCalculatorMainWindow PantheonCalculatorMainWindow;
typedef struct _PantheonCalculatorMainWindowClass PantheonCalculatorMainWindowClass;

struct _PantheonCalculatorApplication {
	GtkApplication parent_instance;
	PantheonCalculatorApplicationPrivate * priv;
};

struct _PantheonCalculatorApplicationClass {
	GtkApplicationClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	PantheonCalculatorApplication* self;
	GraniteSettings* granite_settings;
	GtkSettings* gtk_settings;
};

static gpointer pantheon_calculator_application_parent_class = NULL;

VALA_EXTERN GType pantheon_calculator_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PantheonCalculatorApplication, g_object_unref)
static void pantheon_calculator_application_real_startup (GApplication* base);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda4_ (Block1Data* _data1_);
static void ___lambda4__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static void _g_application_quit_g_simple_action_activate (GSimpleAction* _sender,
                                                   GVariant* parameter,
                                                   gpointer self);
static void pantheon_calculator_application_real_activate (GApplication* base);
VALA_EXTERN GType pantheon_calculator_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PantheonCalculatorMainWindow, g_object_unref)
VALA_EXTERN PantheonCalculatorMainWindow* pantheon_calculator_main_window_new (GtkApplication* application);
VALA_EXTERN PantheonCalculatorMainWindow* pantheon_calculator_main_window_construct (GType object_type,
                                                                         GtkApplication* application);
static gint pantheon_calculator_application_main (gchar** args,
                                           gint args_length1);
VALA_EXTERN PantheonCalculatorApplication* pantheon_calculator_application_new (void);
VALA_EXTERN PantheonCalculatorApplication* pantheon_calculator_application_construct (GType object_type);
static GObject * pantheon_calculator_application_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static GType pantheon_calculator_application_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		PantheonCalculatorApplication* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->gtk_settings);
		_g_object_unref0 (_data1_->granite_settings);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

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

static void
__lambda4_ (Block1Data* _data1_)
{
	PantheonCalculatorApplication* self;
	GtkSettings* _tmp0_;
	GraniteSettings* _tmp1_;
	GraniteSettingsColorScheme _tmp2_;
	GraniteSettingsColorScheme _tmp3_;
	self = _data1_->self;
	_tmp0_ = _data1_->gtk_settings;
	_tmp1_ = _data1_->granite_settings;
	_tmp2_ = granite_settings_get_prefers_color_scheme (_tmp1_);
	_tmp3_ = _tmp2_;
	g_object_set (_tmp0_, "gtk-application-prefer-dark-theme", _tmp3_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
}

static void
___lambda4__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda4_ (self);
}

static void
_g_application_quit_g_simple_action_activate (GSimpleAction* _sender,
                                              GVariant* parameter,
                                              gpointer self)
{
	g_application_quit ((GApplication*) self);
}

static void
pantheon_calculator_application_real_startup (GApplication* base)
{
	PantheonCalculatorApplication * self;
	Block1Data* _data1_;
	GraniteSettings* _tmp0_;
	GraniteSettings* _tmp1_;
	GtkSettings* _tmp2_;
	GtkSettings* _tmp3_;
	GtkSettings* _tmp4_;
	GtkSettings* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gboolean _tmp9_;
	GtkSettings* _tmp11_;
	GraniteSettings* _tmp12_;
	GraniteSettingsColorScheme _tmp13_;
	GraniteSettingsColorScheme _tmp14_;
	GraniteSettings* _tmp15_;
	GSimpleAction* quit_action = NULL;
	GSimpleAction* _tmp16_;
	gchar* _tmp17_;
	gchar** _tmp18_;
	gchar** _tmp19_;
	gint _tmp19__length1;
	self = (PantheonCalculatorApplication*) base;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	G_APPLICATION_CLASS (pantheon_calculator_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	_tmp0_ = granite_settings_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data1_->granite_settings = _tmp1_;
	_tmp2_ = gtk_settings_get_default ();
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_data1_->gtk_settings = _tmp3_;
	_tmp4_ = _data1_->gtk_settings;
	g_object_set (_tmp4_, "gtk-icon-theme-name", "elementary", NULL);
	_tmp5_ = _data1_->gtk_settings;
	g_object_get (_tmp5_, "gtk-theme-name", &_tmp6_, NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp9_ = !g_str_has_prefix (_tmp8_, "io.elementary");
	_g_free0 (_tmp8_);
	if (_tmp9_) {
		GtkSettings* _tmp10_;
		_tmp10_ = _data1_->gtk_settings;
		g_object_set (_tmp10_, "gtk-theme-name", "io.elementary.stylesheet.blueberry", NULL);
	}
	_tmp11_ = _data1_->gtk_settings;
	_tmp12_ = _data1_->granite_settings;
	_tmp13_ = granite_settings_get_prefers_color_scheme (_tmp12_);
	_tmp14_ = _tmp13_;
	g_object_set (_tmp11_, "gtk-application-prefer-dark-theme", _tmp14_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
	_tmp15_ = _data1_->granite_settings;
	g_signal_connect_data ((GObject*) _tmp15_, "notify::prefers-color-scheme", (GCallback) ___lambda4__g_object_notify, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_tmp16_ = g_simple_action_new ("quit", NULL);
	quit_action = _tmp16_;
	g_action_map_add_action ((GActionMap*) self, (GAction*) quit_action);
	_tmp17_ = g_strdup ("<Control>q");
	_tmp18_ = g_new0 (gchar*, 1 + 1);
	_tmp18_[0] = _tmp17_;
	_tmp19_ = _tmp18_;
	_tmp19__length1 = 1;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp19_);
	_tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) g_free), NULL);
	g_signal_connect_object (quit_action, "activate", (GCallback) _g_application_quit_g_simple_action_activate, (GApplication*) self, 0);
	_g_object_unref0 (quit_action);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
pantheon_calculator_application_real_activate (GApplication* base)
{
	PantheonCalculatorApplication * self;
	PantheonCalculatorMainWindow* window = NULL;
	PantheonCalculatorMainWindow* _tmp0_;
	self = (PantheonCalculatorApplication*) base;
	_tmp0_ = pantheon_calculator_main_window_new ((GtkApplication*) self);
	g_object_ref_sink (_tmp0_);
	window = _tmp0_;
	gtk_window_present ((GtkWindow*) window);
	_g_object_unref0 (window);
}

static gint
pantheon_calculator_application_main (gchar** args,
                                      gint args_length1)
{
	PantheonCalculatorApplication* _tmp0_;
	PantheonCalculatorApplication* _tmp1_;
	gint _tmp2_;
	gint result;
	_tmp0_ = pantheon_calculator_application_new ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_application_run ((GApplication*) _tmp1_, (gint) args_length1, args);
	_g_object_unref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

int
main (int argc,
      char ** argv)
{
	return pantheon_calculator_application_main (argv, argc);
}

PantheonCalculatorApplication*
pantheon_calculator_application_construct (GType object_type)
{
	PantheonCalculatorApplication * self = NULL;
	self = (PantheonCalculatorApplication*) g_object_new (object_type, NULL);
	return self;
}

PantheonCalculatorApplication*
pantheon_calculator_application_new (void)
{
	return pantheon_calculator_application_construct (PANTHEON_CALCULATOR_TYPE_APPLICATION);
}

static GObject *
pantheon_calculator_application_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PantheonCalculatorApplication * self;
	parent_class = G_OBJECT_CLASS (pantheon_calculator_application_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PANTHEON_CALCULATOR_TYPE_APPLICATION, PantheonCalculatorApplication);
	g_application_set_application_id ((GApplication*) self, "io.elementary.calculator");
	g_application_set_flags ((GApplication*) self, G_APPLICATION_FLAGS_NONE);
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	return obj;
}

static void
pantheon_calculator_application_class_init (PantheonCalculatorApplicationClass * klass,
                                            gpointer klass_data)
{
	pantheon_calculator_application_parent_class = g_type_class_peek_parent (klass);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) pantheon_calculator_application_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) pantheon_calculator_application_real_activate;
	G_OBJECT_CLASS (klass)->constructor = pantheon_calculator_application_constructor;
}

static void
pantheon_calculator_application_instance_init (PantheonCalculatorApplication * self,
                                               gpointer klass)
{
}

static GType
pantheon_calculator_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PantheonCalculatorApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pantheon_calculator_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PantheonCalculatorApplication), 0, (GInstanceInitFunc) pantheon_calculator_application_instance_init, NULL };
	GType pantheon_calculator_application_type_id;
	pantheon_calculator_application_type_id = g_type_register_static (gtk_application_get_type (), "PantheonCalculatorApplication", &g_define_type_info, 0);
	return pantheon_calculator_application_type_id;
}

GType
pantheon_calculator_application_get_type (void)
{
	static volatile gsize pantheon_calculator_application_type_id__once = 0;
	if (g_once_init_enter (&pantheon_calculator_application_type_id__once)) {
		GType pantheon_calculator_application_type_id;
		pantheon_calculator_application_type_id = pantheon_calculator_application_get_type_once ();
		g_once_init_leave (&pantheon_calculator_application_type_id__once, pantheon_calculator_application_type_id);
	}
	return pantheon_calculator_application_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

