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

/* DateRow.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 <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n-lib.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
#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_DATE_ROW (paper_clip_date_row_get_type ())
#define PAPER_CLIP_DATE_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PAPER_CLIP_TYPE_DATE_ROW, PaperClipDateRow))
#define PAPER_CLIP_DATE_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PAPER_CLIP_TYPE_DATE_ROW, PaperClipDateRowClass))
#define PAPER_CLIP_IS_DATE_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PAPER_CLIP_TYPE_DATE_ROW))
#define PAPER_CLIP_IS_DATE_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PAPER_CLIP_TYPE_DATE_ROW))
#define PAPER_CLIP_DATE_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PAPER_CLIP_TYPE_DATE_ROW, PaperClipDateRowClass))

typedef struct _PaperClipDateRow PaperClipDateRow;
typedef struct _PaperClipDateRowClass PaperClipDateRowClass;
typedef struct _PaperClipDateRowPrivate PaperClipDateRowPrivate;
enum  {
	PAPER_CLIP_DATE_ROW_0_PROPERTY,
	PAPER_CLIP_DATE_ROW_DATE_PROPERTY,
	PAPER_CLIP_DATE_ROW_NUM_PROPERTIES
};
static GParamSpec* paper_clip_date_row_properties[PAPER_CLIP_DATE_ROW_NUM_PROPERTIES];
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _PaperClipDateRow {
	AdwActionRow parent_instance;
	PaperClipDateRowPrivate * priv;
};

struct _PaperClipDateRowClass {
	AdwActionRowClass parent_class;
};

struct _PaperClipDateRowPrivate {
	GtkCalendar* calendar;
	GDateTime* _date;
};

static gint PaperClipDateRow_private_offset;
static gpointer paper_clip_date_row_parent_class = NULL;

VALA_EXTERN GType paper_clip_date_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PaperClipDateRow, g_object_unref)
static void paper_clip_date_row_on_clear_button_clicked (PaperClipDateRow* self);
VALA_EXTERN void paper_clip_date_row_set_date (PaperClipDateRow* self,
                                   GDateTime* value);
static void _paper_clip_date_row_on_clear_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                      gpointer self);
static void paper_clip_date_row_on_day_selected (PaperClipDateRow* self);
static void _paper_clip_date_row_on_day_selected_gtk_calendar_day_selected (GtkCalendar* _sender,
                                                                     gpointer self);
static void paper_clip_date_row_on_today_button_clicked (PaperClipDateRow* self);
static void paper_clip_date_row_datetime_to_calendar (PaperClipDateRow* self,
                                               GDateTime* date_time);
static void _paper_clip_date_row_on_today_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                      gpointer self);
static void paper_clip_date_row_on_tomorrow_button_clicked (PaperClipDateRow* self);
static void _paper_clip_date_row_on_tomorrow_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                         gpointer self);
VALA_EXTERN PaperClipDateRow* paper_clip_date_row_new (void);
VALA_EXTERN PaperClipDateRow* paper_clip_date_row_construct (GType object_type);
VALA_EXTERN GDateTime* paper_clip_date_row_get_date (PaperClipDateRow* self);
static void paper_clip_date_row_finalize (GObject * obj);
static GType paper_clip_date_row_get_type_once (void);
static void _vala_paper_clip_date_row_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_paper_clip_date_row_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);

static inline gpointer
paper_clip_date_row_get_instance_private (PaperClipDateRow* self)
{
	return G_STRUCT_MEMBER_P (self, PaperClipDateRow_private_offset);
}

static void
paper_clip_date_row_on_clear_button_clicked (PaperClipDateRow* self)
{
	g_return_if_fail (self != NULL);
	paper_clip_date_row_set_date (self, NULL);
}

static void
_paper_clip_date_row_on_clear_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                 gpointer self)
{
	paper_clip_date_row_on_clear_button_clicked ((PaperClipDateRow*) self);
}

static void
paper_clip_date_row_on_day_selected (PaperClipDateRow* self)
{
	GtkCalendar* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->calendar;
	_tmp1_ = gtk_calendar_get_date (_tmp0_);
	_tmp2_ = _tmp1_;
	paper_clip_date_row_set_date (self, _tmp2_);
	_g_date_time_unref0 (_tmp2_);
}

static void
_paper_clip_date_row_on_day_selected_gtk_calendar_day_selected (GtkCalendar* _sender,
                                                                gpointer self)
{
	paper_clip_date_row_on_day_selected ((PaperClipDateRow*) self);
}

static void
paper_clip_date_row_on_today_button_clicked (PaperClipDateRow* self)
{
	GDateTime* today_time = NULL;
	GDateTime* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_time_new_now_local ();
	today_time = _tmp0_;
	paper_clip_date_row_datetime_to_calendar (self, today_time);
	paper_clip_date_row_set_date (self, today_time);
	_g_date_time_unref0 (today_time);
}

static void
_paper_clip_date_row_on_today_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                 gpointer self)
{
	paper_clip_date_row_on_today_button_clicked ((PaperClipDateRow*) self);
}

static void
paper_clip_date_row_on_tomorrow_button_clicked (PaperClipDateRow* self)
{
	GDateTime* tomorrow_time = NULL;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_time_new_now_local ();
	tomorrow_time = _tmp0_;
	_tmp1_ = tomorrow_time;
	_tmp2_ = g_date_time_add_days (_tmp1_, 1);
	_g_date_time_unref0 (tomorrow_time);
	tomorrow_time = _tmp2_;
	_tmp3_ = tomorrow_time;
	paper_clip_date_row_datetime_to_calendar (self, _tmp3_);
	_tmp4_ = tomorrow_time;
	paper_clip_date_row_set_date (self, _tmp4_);
	_g_date_time_unref0 (tomorrow_time);
}

static void
_paper_clip_date_row_on_tomorrow_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                    gpointer self)
{
	paper_clip_date_row_on_tomorrow_button_clicked ((PaperClipDateRow*) self);
}

static void
paper_clip_date_row_datetime_to_calendar (PaperClipDateRow* self,
                                          GDateTime* date_time)
{
	gint year = 0;
	gint month = 0;
	gint day = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	GtkCalendar* _tmp3_;
	GtkCalendar* _tmp4_;
	GtkCalendar* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date_time != NULL);
	g_date_time_get_ymd (date_time, &_tmp0_, &_tmp1_, &_tmp2_);
	year = _tmp0_;
	month = _tmp1_;
	day = _tmp2_;
	_tmp3_ = self->priv->calendar;
	g_object_set (_tmp3_, "year", year, NULL);
	_tmp4_ = self->priv->calendar;
	g_object_set (_tmp4_, "month", month - 1, NULL);
	_tmp5_ = self->priv->calendar;
	g_object_set (_tmp5_, "day", day, NULL);
}

PaperClipDateRow*
paper_clip_date_row_construct (GType object_type)
{
	PaperClipDateRow * self = NULL;
	self = (PaperClipDateRow*) g_object_new (object_type, NULL);
	return self;
}

PaperClipDateRow*
paper_clip_date_row_new (void)
{
	return paper_clip_date_row_construct (PAPER_CLIP_TYPE_DATE_ROW);
}

GDateTime*
paper_clip_date_row_get_date (PaperClipDateRow* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_date;
	result = _tmp0_;
	return result;
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

void
paper_clip_date_row_set_date (PaperClipDateRow* self,
                              GDateTime* value)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_date_time_ref0 (value);
	_g_date_time_unref0 (self->priv->_date);
	self->priv->_date = _tmp0_;
	_tmp1_ = paper_clip_date_row_get_date (self);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == NULL) {
		adw_action_row_set_subtitle ((AdwActionRow*) self, _ ("No date set"));
	} else {
		GDateTime* _tmp3_;
		GDateTime* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		GDateTime* _tmp7_;
		GDateTime* _tmp8_;
		_tmp3_ = paper_clip_date_row_get_date (self);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_date_time_format (_tmp4_, "%x");
		_tmp6_ = _tmp5_;
		adw_action_row_set_subtitle ((AdwActionRow*) self, _tmp6_);
		_g_free0 (_tmp6_);
		_tmp7_ = paper_clip_date_row_get_date (self);
		_tmp8_ = _tmp7_;
		paper_clip_date_row_datetime_to_calendar (self, _tmp8_);
	}
	g_object_notify_by_pspec ((GObject *) self, paper_clip_date_row_properties[PAPER_CLIP_DATE_ROW_DATE_PROPERTY]);
}

static void
paper_clip_date_row_class_init (PaperClipDateRowClass * klass,
                                gpointer klass_data)
{
	paper_clip_date_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PaperClipDateRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_paper_clip_date_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_paper_clip_date_row_set_property;
	G_OBJECT_CLASS (klass)->finalize = paper_clip_date_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PAPER_CLIP_DATE_ROW_DATE_PROPERTY, paper_clip_date_row_properties[PAPER_CLIP_DATE_ROW_DATE_PROPERTY] = g_param_spec_boxed ("date", "date", "date", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/diegoivan/pdf_metadata_editor/gtk/date-row.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "calendar", FALSE, PaperClipDateRow_private_offset + G_STRUCT_OFFSET (PaperClipDateRowPrivate, calendar));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_clear_button_clicked", G_CALLBACK(_paper_clip_date_row_on_clear_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_day_selected", G_CALLBACK(_paper_clip_date_row_on_day_selected_gtk_calendar_day_selected));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_today_button_clicked", G_CALLBACK(_paper_clip_date_row_on_today_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_tomorrow_button_clicked", G_CALLBACK(_paper_clip_date_row_on_tomorrow_button_clicked_gtk_button_clicked));
}

static void
paper_clip_date_row_instance_init (PaperClipDateRow * self,
                                   gpointer klass)
{
	self->priv = paper_clip_date_row_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
paper_clip_date_row_finalize (GObject * obj)
{
	PaperClipDateRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PAPER_CLIP_TYPE_DATE_ROW, PaperClipDateRow);
	_g_date_time_unref0 (self->priv->_date);
	G_OBJECT_CLASS (paper_clip_date_row_parent_class)->finalize (obj);
}

static GType
paper_clip_date_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PaperClipDateRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) paper_clip_date_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PaperClipDateRow), 0, (GInstanceInitFunc) paper_clip_date_row_instance_init, NULL };
	GType paper_clip_date_row_type_id;
	paper_clip_date_row_type_id = g_type_register_static (adw_action_row_get_type (), "PaperClipDateRow", &g_define_type_info, 0);
	PaperClipDateRow_private_offset = g_type_add_instance_private (paper_clip_date_row_type_id, sizeof (PaperClipDateRowPrivate));
	return paper_clip_date_row_type_id;
}

GType
paper_clip_date_row_get_type (void)
{
	static volatile gsize paper_clip_date_row_type_id__once = 0;
	if (g_once_init_enter (&paper_clip_date_row_type_id__once)) {
		GType paper_clip_date_row_type_id;
		paper_clip_date_row_type_id = paper_clip_date_row_get_type_once ();
		g_once_init_leave (&paper_clip_date_row_type_id__once, paper_clip_date_row_type_id);
	}
	return paper_clip_date_row_type_id__once;
}

static void
_vala_paper_clip_date_row_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	PaperClipDateRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PAPER_CLIP_TYPE_DATE_ROW, PaperClipDateRow);
	switch (property_id) {
		case PAPER_CLIP_DATE_ROW_DATE_PROPERTY:
		g_value_set_boxed (value, paper_clip_date_row_get_date (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_paper_clip_date_row_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	PaperClipDateRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PAPER_CLIP_TYPE_DATE_ROW, PaperClipDateRow);
	switch (property_id) {
		case PAPER_CLIP_DATE_ROW_DATE_PROPERTY:
		paper_clip_date_row_set_date (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

