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

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

#include "graphs.h"
#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.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_STYLE_DIALOG_0_PROPERTY,
	GRAPHS_ADD_STYLE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* graphs_add_style_dialog_properties[GRAPHS_ADD_STYLE_DIALOG_NUM_PROPERTIES];
#define _gtk_expression_unref0(var) ((var == NULL) ? NULL : (var = (gtk_expression_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	GRAPHS_ADD_STYLE_DIALOG_ACCEPT_SIGNAL,
	GRAPHS_ADD_STYLE_DIALOG_NUM_SIGNALS
};
static guint graphs_add_style_dialog_signals[GRAPHS_ADD_STYLE_DIALOG_NUM_SIGNALS] = {0};

struct _GraphsAddStyleDialogPrivate {
	AdwEntryRow* _new_style_name;
	AdwComboRow* _style_templates;
};

static gint GraphsAddStyleDialog_private_offset;
static gpointer graphs_add_style_dialog_parent_class = NULL;

static AdwComboRow* graphs_add_style_dialog_get_style_templates (GraphsAddStyleDialog* self);
static void graphs_add_style_dialog_on_template_changed (GraphsAddStyleDialog* self);
static AdwEntryRow* graphs_add_style_dialog_get_new_style_name (GraphsAddStyleDialog* self);
static void _graphs_add_style_dialog_on_template_changed_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void graphs_add_style_dialog_on_accept (GraphsAddStyleDialog* self);
static void _graphs_add_style_dialog_on_accept_gtk_button_clicked (GtkButton* _sender,
                                                            gpointer self);
static void graphs_add_style_dialog_finalize (GObject * obj);
static GType graphs_add_style_dialog_get_type_once (void);
static void _vala_graphs_add_style_dialog_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
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 inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
graphs_add_style_dialog_get_instance_private (GraphsAddStyleDialog* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsAddStyleDialog_private_offset);
}

GraphsAddStyleDialog*
graphs_add_style_dialog_construct (GType object_type,
                                   GtkWidget* parent)
{
	GraphsAddStyleDialog * self = NULL;
	AdwComboRow* _tmp0_;
	GtkPropertyExpression* _tmp1_;
	GtkPropertyExpression* _tmp2_;
	AdwComboRow* _tmp3_;
	GtkFilterListModel* _tmp4_;
	GtkFilterListModel* _tmp5_;
	g_return_val_if_fail (parent != NULL, NULL);
	self = (GraphsAddStyleDialog*) g_object_new (object_type, NULL);
	_tmp0_ = self->priv->_style_templates;
	_tmp1_ = (GtkPropertyExpression*) gtk_property_expression_new (GRAPHS_TYPE_STYLE, NULL, "name");
	_tmp2_ = _tmp1_;
	adw_combo_row_set_expression (_tmp0_, (GtkExpression*) _tmp2_);
	_gtk_expression_unref0 (_tmp2_);
	_tmp3_ = self->priv->_style_templates;
	_tmp4_ = graphs_style_manager_get_filtered_style_model ();
	_tmp5_ = _tmp4_;
	adw_combo_row_set_model (_tmp3_, (GListModel*) _tmp5_);
	adw_dialog_present ((AdwDialog*) self, parent);
	return self;
}

GraphsAddStyleDialog*
graphs_add_style_dialog_new (GtkWidget* parent)
{
	return graphs_add_style_dialog_construct (GRAPHS_TYPE_ADD_STYLE_DIALOG, parent);
}

static void
graphs_add_style_dialog_on_template_changed (GraphsAddStyleDialog* self)
{
	gchar** stylenames = NULL;
	gint _tmp0_ = 0;
	gchar** _tmp1_;
	gint stylenames_length1;
	gint _stylenames_size_;
	gchar* template = NULL;
	AdwComboRow* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	AdwEntryRow* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp1_ = graphs_style_manager_list_stylenames (&_tmp0_);
	stylenames = _tmp1_;
	stylenames_length1 = _tmp0_;
	_stylenames_size_ = stylenames_length1;
	_tmp2_ = self->priv->_style_templates;
	_tmp3_ = stylenames[adw_combo_row_get_selected (_tmp2_)];
	_tmp4_ = g_strdup (_tmp3_);
	template = _tmp4_;
	_tmp5_ = self->priv->_new_style_name;
	_tmp6_ = graphs_tools_get_duplicate_string (template, stylenames, (gint) stylenames_length1);
	_tmp7_ = _tmp6_;
	gtk_editable_set_text ((GtkEditable*) _tmp5_, _tmp7_);
	_g_free0 (_tmp7_);
	_g_free0 (template);
	stylenames = (_vala_array_free (stylenames, stylenames_length1, (GDestroyNotify) g_free), NULL);
}

static void
_graphs_add_style_dialog_on_template_changed_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	graphs_add_style_dialog_on_template_changed ((GraphsAddStyleDialog*) self);
}

static void
graphs_add_style_dialog_on_accept (GraphsAddStyleDialog* self)
{
	guint template = 0U;
	AdwComboRow* _tmp0_;
	GFile* file = NULL;
	AdwEntryRow* _tmp1_;
	const gchar* _tmp2_;
	GFile* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_style_templates;
	template = adw_combo_row_get_selected (_tmp0_) + 1;
	_tmp1_ = self->priv->_new_style_name;
	_tmp2_ = gtk_editable_get_text ((GtkEditable*) _tmp1_);
	_tmp3_ = graphs_style_manager_create_style (template, _tmp2_);
	file = _tmp3_;
	adw_dialog_close ((AdwDialog*) self);
	g_signal_emit (self, graphs_add_style_dialog_signals[GRAPHS_ADD_STYLE_DIALOG_ACCEPT_SIGNAL], 0, file);
	_g_object_unref0 (file);
}

static void
_graphs_add_style_dialog_on_accept_gtk_button_clicked (GtkButton* _sender,
                                                       gpointer self)
{
	graphs_add_style_dialog_on_accept ((GraphsAddStyleDialog*) self);
}

static AdwEntryRow*
graphs_add_style_dialog_get_new_style_name (GraphsAddStyleDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_new_style_name;
	result = _tmp0_;
	return result;
}

static AdwComboRow*
graphs_add_style_dialog_get_style_templates (GraphsAddStyleDialog* self)
{
	AdwComboRow* result;
	AdwComboRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_style_templates;
	result = _tmp0_;
	return result;
}

static void
graphs_add_style_dialog_class_init (GraphsAddStyleDialogClass * klass,
                                    gpointer klass_data)
{
	graphs_add_style_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsAddStyleDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_add_style_dialog_get_property;
	G_OBJECT_CLASS (klass)->finalize = graphs_add_style_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/se/sjoerd/Graphs/ui/style-editor/add-style.ui");
	graphs_add_style_dialog_signals[GRAPHS_ADD_STYLE_DIALOG_ACCEPT_SIGNAL] = g_signal_new ("accept", GRAPHS_TYPE_ADD_STYLE_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, g_file_get_type ());
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "new_style_name", FALSE, GraphsAddStyleDialog_private_offset + G_STRUCT_OFFSET (GraphsAddStyleDialogPrivate, _new_style_name));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "style_templates", FALSE, GraphsAddStyleDialog_private_offset + G_STRUCT_OFFSET (GraphsAddStyleDialogPrivate, _style_templates));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_template_changed", G_CALLBACK(_graphs_add_style_dialog_on_template_changed_g_object_notify));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_accept", G_CALLBACK(_graphs_add_style_dialog_on_accept_gtk_button_clicked));
}

static void
graphs_add_style_dialog_instance_init (GraphsAddStyleDialog * self,
                                       gpointer klass)
{
	self->priv = graphs_add_style_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
graphs_add_style_dialog_finalize (GObject * obj)
{
	GraphsAddStyleDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_ADD_STYLE_DIALOG, GraphsAddStyleDialog);
	G_OBJECT_CLASS (graphs_add_style_dialog_parent_class)->finalize (obj);
}

/**
     * Add style dialog
     */
static GType
graphs_add_style_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsAddStyleDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_add_style_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsAddStyleDialog), 0, (GInstanceInitFunc) graphs_add_style_dialog_instance_init, NULL };
	GType graphs_add_style_dialog_type_id;
	graphs_add_style_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "GraphsAddStyleDialog", &g_define_type_info, 0);
	GraphsAddStyleDialog_private_offset = g_type_add_instance_private (graphs_add_style_dialog_type_id, sizeof (GraphsAddStyleDialogPrivate));
	return graphs_add_style_dialog_type_id;
}

GType
graphs_add_style_dialog_get_type (void)
{
	static volatile gsize graphs_add_style_dialog_type_id__once = 0;
	if (g_once_init_enter (&graphs_add_style_dialog_type_id__once)) {
		GType graphs_add_style_dialog_type_id;
		graphs_add_style_dialog_type_id = graphs_add_style_dialog_get_type_once ();
		g_once_init_leave (&graphs_add_style_dialog_type_id__once, graphs_add_style_dialog_type_id);
	}
	return graphs_add_style_dialog_type_id__once;
}

static void
_vala_graphs_add_style_dialog_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	GraphsAddStyleDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_ADD_STYLE_DIALOG, GraphsAddStyleDialog);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

