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

/* KeywordRow.vala
 *
 * Copyright 2023 Diego Iván <diegoivan.mae@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/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.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 PAPER_CLIP_TYPE_KEYWORD_ROW (paper_clip_keyword_row_get_type ())
#define PAPER_CLIP_KEYWORD_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRow))
#define PAPER_CLIP_KEYWORD_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRowClass))
#define PAPER_CLIP_IS_KEYWORD_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PAPER_CLIP_TYPE_KEYWORD_ROW))
#define PAPER_CLIP_IS_KEYWORD_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PAPER_CLIP_TYPE_KEYWORD_ROW))
#define PAPER_CLIP_KEYWORD_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRowClass))

typedef struct _PaperClipKeywordRow PaperClipKeywordRow;
typedef struct _PaperClipKeywordRowClass PaperClipKeywordRowClass;
typedef struct _PaperClipKeywordRowPrivate PaperClipKeywordRowPrivate;

#define PAPER_CLIP_TYPE_DOCUMENT (paper_clip_document_get_type ())
#define PAPER_CLIP_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PAPER_CLIP_TYPE_DOCUMENT, PaperClipDocument))
#define PAPER_CLIP_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PAPER_CLIP_TYPE_DOCUMENT, PaperClipDocumentClass))
#define PAPER_CLIP_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PAPER_CLIP_TYPE_DOCUMENT))
#define PAPER_CLIP_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PAPER_CLIP_TYPE_DOCUMENT))
#define PAPER_CLIP_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PAPER_CLIP_TYPE_DOCUMENT, PaperClipDocumentClass))

typedef struct _PaperClipDocument PaperClipDocument;
typedef struct _PaperClipDocumentClass PaperClipDocumentClass;
enum  {
	PAPER_CLIP_KEYWORD_ROW_0_PROPERTY,
	PAPER_CLIP_KEYWORD_ROW_DOCUMENT_PROPERTY,
	PAPER_CLIP_KEYWORD_ROW_NUM_PROPERTIES
};
static GParamSpec* paper_clip_keyword_row_properties[PAPER_CLIP_KEYWORD_ROW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _PaperClipKeywordRow {
	AdwEntryRow parent_instance;
	PaperClipKeywordRowPrivate * priv;
};

struct _PaperClipKeywordRowClass {
	AdwEntryRowClass parent_class;
};

struct _PaperClipKeywordRowPrivate {
	PaperClipDocument* _document;
};

static gint PaperClipKeywordRow_private_offset;
static gpointer paper_clip_keyword_row_parent_class = NULL;

VALA_EXTERN GType paper_clip_keyword_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PaperClipKeywordRow, g_object_unref)
VALA_EXTERN GType paper_clip_document_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PaperClipDocument, g_object_unref)
static void paper_clip_keyword_row_on_delete_clicked (PaperClipKeywordRow* self);
VALA_EXTERN PaperClipDocument* paper_clip_keyword_row_get_document (PaperClipKeywordRow* self);
VALA_EXTERN gboolean paper_clip_document_remove_keyword (PaperClipDocument* self,
                                             const gchar* keyword);
VALA_EXTERN PaperClipKeywordRow* paper_clip_keyword_row_new (void);
VALA_EXTERN PaperClipKeywordRow* paper_clip_keyword_row_construct (GType object_type);
VALA_EXTERN void paper_clip_keyword_row_set_document (PaperClipKeywordRow* self,
                                          PaperClipDocument* value);
static GObject * paper_clip_keyword_row_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _paper_clip_keyword_row_on_delete_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self);
static void paper_clip_keyword_row_finalize (GObject * obj);
static GType paper_clip_keyword_row_get_type_once (void);
static void _vala_paper_clip_keyword_row_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_paper_clip_keyword_row_set_property (GObject * object,
                                                guint property_id,
                                                const 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
paper_clip_keyword_row_get_instance_private (PaperClipKeywordRow* self)
{
	return G_STRUCT_MEMBER_P (self, PaperClipKeywordRow_private_offset);
}

static void
paper_clip_keyword_row_on_delete_clicked (PaperClipKeywordRow* self)
{
	PaperClipDocument* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_document;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) self);
	_tmp2_ = _tmp1_;
	paper_clip_document_remove_keyword (_tmp0_, _tmp2_);
}

PaperClipKeywordRow*
paper_clip_keyword_row_construct (GType object_type)
{
	PaperClipKeywordRow * self = NULL;
	self = (PaperClipKeywordRow*) g_object_new (object_type, NULL);
	return self;
}

PaperClipKeywordRow*
paper_clip_keyword_row_new (void)
{
	return paper_clip_keyword_row_construct (PAPER_CLIP_TYPE_KEYWORD_ROW);
}

PaperClipDocument*
paper_clip_keyword_row_get_document (PaperClipKeywordRow* self)
{
	PaperClipDocument* result;
	PaperClipDocument* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_document;
	result = _tmp0_;
	return result;
}

void
paper_clip_keyword_row_set_document (PaperClipKeywordRow* self,
                                     PaperClipDocument* value)
{
	PaperClipDocument* old_value;
	g_return_if_fail (self != NULL);
	old_value = paper_clip_keyword_row_get_document (self);
	if (old_value != value) {
		self->priv->_document = value;
		g_object_notify_by_pspec ((GObject *) self, paper_clip_keyword_row_properties[PAPER_CLIP_KEYWORD_ROW_DOCUMENT_PROPERTY]);
	}
}

static void
_paper_clip_keyword_row_on_delete_clicked_gtk_button_clicked (GtkButton* _sender,
                                                              gpointer self)
{
	paper_clip_keyword_row_on_delete_clicked ((PaperClipKeywordRow*) self);
}

static GObject *
paper_clip_keyword_row_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PaperClipKeywordRow * self;
	GtkButton* delete_button = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar* _tmp2_;
	GtkButton* _tmp3_ = NULL;
	GtkButton* _tmp4_;
	GtkButton* _tmp5_;
	parent_class = G_OBJECT_CLASS (paper_clip_keyword_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRow);
	gtk_widget_set_focusable ((GtkWidget*) self, TRUE);
	_tmp0_ = g_strdup ("flat");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = g_strdup (_ ("Delete Keyword"));
	_tmp3_ = (GtkButton*) gtk_button_new_from_icon_name ("cross-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp3_, _tmp1_);
	_tmp1_ = (_vala_array_free (_tmp1_, 1, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp3_, _tmp2_);
	_g_free0 (_tmp2_);
	g_object_ref_sink (_tmp3_);
	delete_button = _tmp3_;
	_tmp4_ = delete_button;
	adw_entry_row_add_prefix ((AdwEntryRow*) self, (GtkWidget*) _tmp4_);
	_tmp5_ = delete_button;
	g_signal_connect_object (_tmp5_, "clicked", (GCallback) _paper_clip_keyword_row_on_delete_clicked_gtk_button_clicked, self, 0);
	_g_object_unref0 (delete_button);
	return obj;
}

static void
paper_clip_keyword_row_class_init (PaperClipKeywordRowClass * klass,
                                   gpointer klass_data)
{
	paper_clip_keyword_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PaperClipKeywordRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_paper_clip_keyword_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_paper_clip_keyword_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = paper_clip_keyword_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = paper_clip_keyword_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PAPER_CLIP_KEYWORD_ROW_DOCUMENT_PROPERTY, paper_clip_keyword_row_properties[PAPER_CLIP_KEYWORD_ROW_DOCUMENT_PROPERTY] = g_param_spec_object ("document", "document", "document", PAPER_CLIP_TYPE_DOCUMENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
paper_clip_keyword_row_instance_init (PaperClipKeywordRow * self,
                                      gpointer klass)
{
	self->priv = paper_clip_keyword_row_get_instance_private (self);
}

static void
paper_clip_keyword_row_finalize (GObject * obj)
{
	PaperClipKeywordRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRow);
	G_OBJECT_CLASS (paper_clip_keyword_row_parent_class)->finalize (obj);
}

static GType
paper_clip_keyword_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PaperClipKeywordRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) paper_clip_keyword_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PaperClipKeywordRow), 0, (GInstanceInitFunc) paper_clip_keyword_row_instance_init, NULL };
	GType paper_clip_keyword_row_type_id;
	paper_clip_keyword_row_type_id = g_type_register_static (adw_entry_row_get_type (), "PaperClipKeywordRow", &g_define_type_info, 0);
	PaperClipKeywordRow_private_offset = g_type_add_instance_private (paper_clip_keyword_row_type_id, sizeof (PaperClipKeywordRowPrivate));
	return paper_clip_keyword_row_type_id;
}

GType
paper_clip_keyword_row_get_type (void)
{
	static volatile gsize paper_clip_keyword_row_type_id__once = 0;
	if (g_once_init_enter (&paper_clip_keyword_row_type_id__once)) {
		GType paper_clip_keyword_row_type_id;
		paper_clip_keyword_row_type_id = paper_clip_keyword_row_get_type_once ();
		g_once_init_leave (&paper_clip_keyword_row_type_id__once, paper_clip_keyword_row_type_id);
	}
	return paper_clip_keyword_row_type_id__once;
}

static void
_vala_paper_clip_keyword_row_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	PaperClipKeywordRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRow);
	switch (property_id) {
		case PAPER_CLIP_KEYWORD_ROW_DOCUMENT_PROPERTY:
		g_value_set_object (value, paper_clip_keyword_row_get_document (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_paper_clip_keyword_row_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	PaperClipKeywordRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PAPER_CLIP_TYPE_KEYWORD_ROW, PaperClipKeywordRow);
	switch (property_id) {
		case PAPER_CLIP_KEYWORD_ROW_DOCUMENT_PROPERTY:
		paper_clip_keyword_row_set_document (self, g_value_get_object (value));
		break;
		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);
}

