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

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.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  {
	GRAPHS_ADD_EQUATION_DIALOG_0_PROPERTY,
	GRAPHS_ADD_EQUATION_DIALOG_EQUATION_PROPERTY,
	GRAPHS_ADD_EQUATION_DIALOG_X_START_PROPERTY,
	GRAPHS_ADD_EQUATION_DIALOG_X_STOP_PROPERTY,
	GRAPHS_ADD_EQUATION_DIALOG_STEP_SIZE_PROPERTY,
	GRAPHS_ADD_EQUATION_DIALOG_ITEM_NAME_PROPERTY,
	GRAPHS_ADD_EQUATION_DIALOG_NUM_PROPERTIES
};
static GParamSpec* graphs_add_equation_dialog_properties[GRAPHS_ADD_EQUATION_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	GRAPHS_ADD_EQUATION_DIALOG_ACCEPT_SIGNAL,
	GRAPHS_ADD_EQUATION_DIALOG_NUM_SIGNALS
};
static guint graphs_add_equation_dialog_signals[GRAPHS_ADD_EQUATION_DIALOG_NUM_SIGNALS] = {0};

struct _GraphsAddEquationDialogPrivate {
	AdwEntryRow* _equation;
	AdwEntryRow* _x_start;
	AdwEntryRow* _x_stop;
	AdwEntryRow* _step_size;
	AdwEntryRow* _item_name;
	AdwToastOverlay* _toast_overlay;
	GraphsApplication* application;
};

static gint GraphsAddEquationDialog_private_offset;
static gpointer graphs_add_equation_dialog_parent_class = NULL;

static void graphs_add_equation_dialog_on_accept (GraphsAddEquationDialog* self);
static AdwToastOverlay* graphs_add_equation_dialog_get_toast_overlay (GraphsAddEquationDialog* self);
static void _graphs_add_equation_dialog_on_accept_gtk_button_clicked (GtkButton* _sender,
                                                               gpointer self);
static void g_cclosure_user_marshal_STRING__STRING (GClosure * closure,
                                             GValue * return_value,
                                             guint n_param_values,
                                             const GValue * param_values,
                                             gpointer invocation_hint,
                                             gpointer marshal_data);
static void graphs_add_equation_dialog_finalize (GObject * obj);
static GType graphs_add_equation_dialog_get_type_once (void);
static void _vala_graphs_add_equation_dialog_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);

static inline gpointer
graphs_add_equation_dialog_get_instance_private (GraphsAddEquationDialog* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsAddEquationDialog_private_offset);
}

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

GraphsAddEquationDialog*
graphs_add_equation_dialog_construct (GType object_type,
                                      GraphsApplication* application)
{
	GraphsAddEquationDialog * self = NULL;
	GraphsApplication* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	GraphsWindow* _tmp3_;
	GraphsWindow* _tmp4_;
	g_return_val_if_fail (application != NULL, NULL);
	self = (GraphsAddEquationDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (application);
	_g_object_unref0 (self->priv->application);
	self->priv->application = _tmp0_;
	_tmp1_ = graphs_application_get_settings_child (application, "add-equation");
	_tmp2_ = _tmp1_;
	graphs_tools_bind_settings_to_widgets (_tmp2_, (GtkWidget*) self);
	_g_object_unref0 (_tmp2_);
	_tmp3_ = graphs_application_get_window (application);
	_tmp4_ = _tmp3_;
	adw_dialog_present ((AdwDialog*) self, (GtkWidget*) _tmp4_);
	return self;
}

GraphsAddEquationDialog*
graphs_add_equation_dialog_new (GraphsApplication* application)
{
	return graphs_add_equation_dialog_construct (GRAPHS_TYPE_ADD_EQUATION_DIALOG, application);
}

static void
graphs_add_equation_dialog_on_accept (GraphsAddEquationDialog* self)
{
	gchar* _error_ = NULL;
	AdwEntryRow* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	const gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_item_name;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	g_signal_emit (self, graphs_add_equation_dialog_signals[GRAPHS_ADD_EQUATION_DIALOG_ACCEPT_SIGNAL], 0, _tmp1_, &_tmp2_);
	_error_ = _tmp2_;
	_tmp3_ = _error_;
	if (g_strcmp0 (_tmp3_, "") == 0) {
		adw_dialog_close ((AdwDialog*) self);
	} else {
		AdwToastOverlay* _tmp4_;
		const gchar* _tmp5_;
		AdwToast* _tmp6_;
		_tmp4_ = self->priv->_toast_overlay;
		_tmp5_ = _error_;
		_tmp6_ = adw_toast_new (_tmp5_);
		adw_toast_overlay_add_toast (_tmp4_, _tmp6_);
	}
	_g_free0 (_error_);
}

static void
_graphs_add_equation_dialog_on_accept_gtk_button_clicked (GtkButton* _sender,
                                                          gpointer self)
{
	graphs_add_equation_dialog_on_accept ((GraphsAddEquationDialog*) self);
}

AdwEntryRow*
graphs_add_equation_dialog_get_equation (GraphsAddEquationDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_equation;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_add_equation_dialog_get_x_start (GraphsAddEquationDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_x_start;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_add_equation_dialog_get_x_stop (GraphsAddEquationDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_x_stop;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_add_equation_dialog_get_step_size (GraphsAddEquationDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_step_size;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_add_equation_dialog_get_item_name (GraphsAddEquationDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_item_name;
	result = _tmp0_;
	return result;
}

static AdwToastOverlay*
graphs_add_equation_dialog_get_toast_overlay (GraphsAddEquationDialog* self)
{
	AdwToastOverlay* result;
	AdwToastOverlay* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_toast_overlay;
	result = _tmp0_;
	return result;
}

static void
g_cclosure_user_marshal_STRING__STRING (GClosure * closure,
                                        GValue * return_value,
                                        guint n_param_values,
                                        const GValue * param_values,
                                        gpointer invocation_hint,
                                        gpointer marshal_data)
{
	typedef const char* (*GMarshalFunc_STRING__STRING) (gpointer data1, const char* arg_1, gpointer data2);
	register GMarshalFunc_STRING__STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	const char* v_return;
	cc = (GCClosure *) closure;
	g_return_if_fail (return_value != NULL);
	g_return_if_fail (n_param_values == 2);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_STRING__STRING) (marshal_data ? marshal_data : cc->callback);
	v_return = callback (data1, g_value_get_string (param_values + 1), data2);
	g_value_take_string (return_value, v_return);
}

static void
graphs_add_equation_dialog_class_init (GraphsAddEquationDialogClass * klass,
                                       gpointer klass_data)
{
	graphs_add_equation_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsAddEquationDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_add_equation_dialog_get_property;
	G_OBJECT_CLASS (klass)->finalize = graphs_add_equation_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_ADD_EQUATION_DIALOG_EQUATION_PROPERTY, graphs_add_equation_dialog_properties[GRAPHS_ADD_EQUATION_DIALOG_EQUATION_PROPERTY] = g_param_spec_object ("equation", "equation", "equation", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_ADD_EQUATION_DIALOG_X_START_PROPERTY, graphs_add_equation_dialog_properties[GRAPHS_ADD_EQUATION_DIALOG_X_START_PROPERTY] = g_param_spec_object ("x-start", "x-start", "x-start", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_ADD_EQUATION_DIALOG_X_STOP_PROPERTY, graphs_add_equation_dialog_properties[GRAPHS_ADD_EQUATION_DIALOG_X_STOP_PROPERTY] = g_param_spec_object ("x-stop", "x-stop", "x-stop", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_ADD_EQUATION_DIALOG_STEP_SIZE_PROPERTY, graphs_add_equation_dialog_properties[GRAPHS_ADD_EQUATION_DIALOG_STEP_SIZE_PROPERTY] = g_param_spec_object ("step-size", "step-size", "step-size", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_ADD_EQUATION_DIALOG_ITEM_NAME_PROPERTY, graphs_add_equation_dialog_properties[GRAPHS_ADD_EQUATION_DIALOG_ITEM_NAME_PROPERTY] = g_param_spec_object ("item-name", "item-name", "item-name", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/se/sjoerd/Graphs/ui/add-equation.ui");
	graphs_add_equation_dialog_signals[GRAPHS_ADD_EQUATION_DIALOG_ACCEPT_SIGNAL] = g_signal_new ("accept", GRAPHS_TYPE_ADD_EQUATION_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_STRING__STRING, G_TYPE_STRING, 1, G_TYPE_STRING);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "equation", FALSE, GraphsAddEquationDialog_private_offset + G_STRUCT_OFFSET (GraphsAddEquationDialogPrivate, _equation));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "x_start", FALSE, GraphsAddEquationDialog_private_offset + G_STRUCT_OFFSET (GraphsAddEquationDialogPrivate, _x_start));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "x_stop", FALSE, GraphsAddEquationDialog_private_offset + G_STRUCT_OFFSET (GraphsAddEquationDialogPrivate, _x_stop));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "step_size", FALSE, GraphsAddEquationDialog_private_offset + G_STRUCT_OFFSET (GraphsAddEquationDialogPrivate, _step_size));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "item_name", FALSE, GraphsAddEquationDialog_private_offset + G_STRUCT_OFFSET (GraphsAddEquationDialogPrivate, _item_name));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "toast_overlay", FALSE, GraphsAddEquationDialog_private_offset + G_STRUCT_OFFSET (GraphsAddEquationDialogPrivate, _toast_overlay));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_accept", G_CALLBACK(_graphs_add_equation_dialog_on_accept_gtk_button_clicked));
}

static void
graphs_add_equation_dialog_instance_init (GraphsAddEquationDialog * self,
                                          gpointer klass)
{
	self->priv = graphs_add_equation_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
graphs_add_equation_dialog_finalize (GObject * obj)
{
	GraphsAddEquationDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_ADD_EQUATION_DIALOG, GraphsAddEquationDialog);
	_g_object_unref0 (self->priv->application);
	G_OBJECT_CLASS (graphs_add_equation_dialog_parent_class)->finalize (obj);
}

/**
     * Add Equation dialog.
     */
static GType
graphs_add_equation_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsAddEquationDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_add_equation_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsAddEquationDialog), 0, (GInstanceInitFunc) graphs_add_equation_dialog_instance_init, NULL };
	GType graphs_add_equation_dialog_type_id;
	graphs_add_equation_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "GraphsAddEquationDialog", &g_define_type_info, 0);
	GraphsAddEquationDialog_private_offset = g_type_add_instance_private (graphs_add_equation_dialog_type_id, sizeof (GraphsAddEquationDialogPrivate));
	return graphs_add_equation_dialog_type_id;
}

GType
graphs_add_equation_dialog_get_type (void)
{
	static volatile gsize graphs_add_equation_dialog_type_id__once = 0;
	if (g_once_init_enter (&graphs_add_equation_dialog_type_id__once)) {
		GType graphs_add_equation_dialog_type_id;
		graphs_add_equation_dialog_type_id = graphs_add_equation_dialog_get_type_once ();
		g_once_init_leave (&graphs_add_equation_dialog_type_id__once, graphs_add_equation_dialog_type_id);
	}
	return graphs_add_equation_dialog_type_id__once;
}

static void
_vala_graphs_add_equation_dialog_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	GraphsAddEquationDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_ADD_EQUATION_DIALOG, GraphsAddEquationDialog);
	switch (property_id) {
		case GRAPHS_ADD_EQUATION_DIALOG_EQUATION_PROPERTY:
		g_value_set_object (value, graphs_add_equation_dialog_get_equation (self));
		break;
		case GRAPHS_ADD_EQUATION_DIALOG_X_START_PROPERTY:
		g_value_set_object (value, graphs_add_equation_dialog_get_x_start (self));
		break;
		case GRAPHS_ADD_EQUATION_DIALOG_X_STOP_PROPERTY:
		g_value_set_object (value, graphs_add_equation_dialog_get_x_stop (self));
		break;
		case GRAPHS_ADD_EQUATION_DIALOG_STEP_SIZE_PROPERTY:
		g_value_set_object (value, graphs_add_equation_dialog_get_step_size (self));
		break;
		case GRAPHS_ADD_EQUATION_DIALOG_ITEM_NAME_PROPERTY:
		g_value_set_object (value, graphs_add_equation_dialog_get_item_name (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

