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

/*
 * Copyright 2011-2017 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include "granite-7.h"
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <float.h>
#include <math.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 TYPE_DEMO_PAGE (demo_page_get_type ())
#define DEMO_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DEMO_PAGE, DemoPage))
#define DEMO_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DEMO_PAGE, DemoPageClass))
#define IS_DEMO_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DEMO_PAGE))
#define IS_DEMO_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DEMO_PAGE))
#define DEMO_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DEMO_PAGE, DemoPageClass))

typedef struct _DemoPage DemoPage;
typedef struct _DemoPageClass DemoPageClass;
typedef struct _DemoPagePrivate DemoPagePrivate;

#define TYPE_DATE_TIME_PICKER_VIEW (date_time_picker_view_get_type ())
#define DATE_TIME_PICKER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DATE_TIME_PICKER_VIEW, DateTimePickerView))
#define DATE_TIME_PICKER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DATE_TIME_PICKER_VIEW, DateTimePickerViewClass))
#define IS_DATE_TIME_PICKER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DATE_TIME_PICKER_VIEW))
#define IS_DATE_TIME_PICKER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DATE_TIME_PICKER_VIEW))
#define DATE_TIME_PICKER_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DATE_TIME_PICKER_VIEW, DateTimePickerViewClass))

typedef struct _DateTimePickerView DateTimePickerView;
typedef struct _DateTimePickerViewClass DateTimePickerViewClass;
typedef struct _DateTimePickerViewPrivate DateTimePickerViewPrivate;
enum  {
	DATE_TIME_PICKER_VIEW_0_PROPERTY,
	DATE_TIME_PICKER_VIEW_NUM_PROPERTIES
};
static GParamSpec* date_time_picker_view_properties[DATE_TIME_PICKER_VIEW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#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 _DemoPage {
	GraniteToolBox parent_instance;
	DemoPagePrivate * priv;
};

struct _DemoPageClass {
	GraniteToolBoxClass parent_class;
};

struct _DateTimePickerView {
	DemoPage parent_instance;
	DateTimePickerViewPrivate * priv;
};

struct _DateTimePickerViewClass {
	DemoPageClass parent_class;
};

struct _DateTimePickerViewPrivate {
	GtkLabel* relative_datetime;
	GraniteDatePicker* datepicker;
	GraniteTimePicker* timepicker;
};

static gint DateTimePickerView_private_offset;
static gpointer date_time_picker_view_parent_class = NULL;

VALA_EXTERN GType demo_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DemoPage, g_object_unref)
VALA_EXTERN GType date_time_picker_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DateTimePickerView, g_object_unref)
static void date_time_picker_view_set_selected_datetime (DateTimePickerView* self);
VALA_EXTERN DateTimePickerView* date_time_picker_view_new (void);
VALA_EXTERN DateTimePickerView* date_time_picker_view_construct (GType object_type);
VALA_EXTERN DemoPage* demo_page_new (void);
VALA_EXTERN DemoPage* demo_page_construct (GType object_type);
static GObject * date_time_picker_view_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties);
static void _date_time_picker_view___lambda8_ (DateTimePickerView* self);
static void __date_time_picker_view___lambda8__gtk_editable_changed (GtkEditable* _sender,
                                                              gpointer self);
static void _date_time_picker_view___lambda9_ (DateTimePickerView* self);
static void __date_time_picker_view___lambda9__gtk_editable_changed (GtkEditable* _sender,
                                                              gpointer self);
VALA_EXTERN void demo_page_set_child (DemoPage* self,
                          GtkWidget* value);
static void date_time_picker_view_finalize (GObject * obj);
static GType date_time_picker_view_get_type_once (void);

static inline gpointer
date_time_picker_view_get_instance_private (DateTimePickerView* self)
{
	return G_STRUCT_MEMBER_P (self, DateTimePickerView_private_offset);
}

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

static void
date_time_picker_view_set_selected_datetime (DateTimePickerView* self)
{
	GDateTime* selected_date_time = NULL;
	GraniteDatePicker* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GraniteTimePicker* _tmp5_;
	GDateTime* _tmp6_;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	GDateTime* _tmp9_;
	GraniteTimePicker* _tmp10_;
	GDateTime* _tmp11_;
	GDateTime* _tmp12_;
	GDateTime* _tmp13_;
	GtkLabel* _tmp14_;
	GDateTime* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->datepicker;
	_tmp1_ = granite_date_picker_get_date (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_date_time_ref0 (_tmp2_);
	selected_date_time = _tmp3_;
	_tmp4_ = selected_date_time;
	_tmp5_ = self->priv->timepicker;
	_tmp6_ = granite_time_picker_get_time (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_date_time_add_hours (_tmp4_, g_date_time_get_hour (_tmp7_));
	_g_date_time_unref0 (selected_date_time);
	selected_date_time = _tmp8_;
	_tmp9_ = selected_date_time;
	_tmp10_ = self->priv->timepicker;
	_tmp11_ = granite_time_picker_get_time (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_date_time_add_minutes (_tmp9_, g_date_time_get_minute (_tmp12_));
	_g_date_time_unref0 (selected_date_time);
	selected_date_time = _tmp13_;
	_tmp14_ = self->priv->relative_datetime;
	_tmp15_ = selected_date_time;
	_tmp16_ = granite_date_time_get_relative_datetime (_tmp15_);
	_tmp17_ = _tmp16_;
	gtk_label_set_label (_tmp14_, _tmp17_);
	_g_free0 (_tmp17_);
	_g_date_time_unref0 (selected_date_time);
}

DateTimePickerView*
date_time_picker_view_construct (GType object_type)
{
	DateTimePickerView * self = NULL;
	self = (DateTimePickerView*) demo_page_construct (object_type);
	return self;
}

DateTimePickerView*
date_time_picker_view_new (void)
{
	return date_time_picker_view_construct (TYPE_DATE_TIME_PICKER_VIEW);
}

static void
_date_time_picker_view___lambda8_ (DateTimePickerView* self)
{
	date_time_picker_view_set_selected_datetime (self);
}

static void
__date_time_picker_view___lambda8__gtk_editable_changed (GtkEditable* _sender,
                                                         gpointer self)
{
	_date_time_picker_view___lambda8_ ((DateTimePickerView*) self);
}

static void
_date_time_picker_view___lambda9_ (DateTimePickerView* self)
{
	date_time_picker_view_set_selected_datetime (self);
}

static void
__date_time_picker_view___lambda9__gtk_editable_changed (GtkEditable* _sender,
                                                         gpointer self)
{
	_date_time_picker_view___lambda9_ ((DateTimePickerView*) self);
}

static GObject *
date_time_picker_view_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DateTimePickerView * self;
	GraniteHeaderLabel* pickers_label = NULL;
	GraniteHeaderLabel* _tmp0_;
	GtkLabel* date_label = NULL;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GraniteDatePicker* _tmp3_;
	GtkLabel* time_label = NULL;
	GtkLabel* _tmp4_;
	GtkLabel* _tmp5_;
	GraniteTimePicker* _tmp6_;
	GraniteHeaderLabel* formatting_label = NULL;
	GraniteHeaderLabel* _tmp7_;
	GraniteHeaderLabel* _tmp8_;
	GtkLabel* current_time_label = NULL;
	GtkLabel* _tmp9_;
	GtkLabel* _tmp10_;
	GDateTime* now = NULL;
	GDateTime* _tmp11_;
	GSettings* settings = NULL;
	GSettings* _tmp12_;
	gchar* time_format = NULL;
	GSettings* _tmp13_;
	gchar* _tmp14_;
	GtkLabel* current_time = NULL;
	GDateTime* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	GtkLabel* _tmp19_;
	GtkLabel* _tmp20_;
	GtkLabel* _tmp21_;
	const gchar* _tmp22_;
	GtkLabel* _tmp23_;
	GtkLabel* current_date_label = NULL;
	GtkLabel* _tmp24_;
	GtkLabel* _tmp25_;
	gchar* date_format = NULL;
	gchar* _tmp26_;
	GtkLabel* current_date = NULL;
	GDateTime* _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	GtkLabel* _tmp31_;
	GtkLabel* _tmp32_;
	GtkLabel* _tmp33_;
	const gchar* _tmp34_;
	GtkLabel* _tmp35_;
	GtkLabel* relative_datetime_label = NULL;
	GtkLabel* _tmp36_;
	GtkLabel* _tmp37_;
	GtkLabel* _tmp38_;
	GtkLabel* _tmp39_;
	GraniteDatePicker* _tmp40_;
	GraniteTimePicker* _tmp41_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp42_ = NULL;
	GtkGrid* _tmp43_;
	GraniteHeaderLabel* _tmp44_;
	GtkGrid* _tmp45_;
	GtkLabel* _tmp46_;
	GtkGrid* _tmp47_;
	GraniteDatePicker* _tmp48_;
	GtkGrid* _tmp49_;
	GtkLabel* _tmp50_;
	GtkGrid* _tmp51_;
	GraniteTimePicker* _tmp52_;
	GtkGrid* _tmp53_;
	GraniteHeaderLabel* _tmp54_;
	GtkGrid* _tmp55_;
	GtkLabel* _tmp56_;
	GtkGrid* _tmp57_;
	GtkLabel* _tmp58_;
	GtkGrid* _tmp59_;
	GtkLabel* _tmp60_;
	GtkGrid* _tmp61_;
	GtkLabel* _tmp62_;
	GtkGrid* _tmp63_;
	GtkLabel* _tmp64_;
	GtkGrid* _tmp65_;
	GtkLabel* _tmp66_;
	GtkGrid* _tmp67_;
	parent_class = G_OBJECT_CLASS (date_time_picker_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DATE_TIME_PICKER_VIEW, DateTimePickerView);
	_tmp0_ = granite_header_label_new ("Picker Widgets");
	g_object_ref_sink (_tmp0_);
	pickers_label = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new ("DatePicker:");
	g_object_ref_sink (_tmp1_);
	date_label = _tmp1_;
	_tmp2_ = date_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_END);
	_tmp3_ = granite_date_picker_new ();
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->datepicker);
	self->priv->datepicker = _tmp3_;
	_tmp4_ = (GtkLabel*) gtk_label_new ("TimePicker:");
	g_object_ref_sink (_tmp4_);
	time_label = _tmp4_;
	_tmp5_ = time_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_END);
	_tmp6_ = granite_time_picker_new ();
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->timepicker);
	self->priv->timepicker = _tmp6_;
	_tmp7_ = granite_header_label_new ("String Formatting");
	g_object_ref_sink (_tmp7_);
	formatting_label = _tmp7_;
	_tmp8_ = formatting_label;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp8_, 6);
	_tmp9_ = (GtkLabel*) gtk_label_new ("Localized time:");
	g_object_ref_sink (_tmp9_);
	current_time_label = _tmp9_;
	_tmp10_ = current_time_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp10_, GTK_ALIGN_END);
	_tmp11_ = g_date_time_new_now_local ();
	now = _tmp11_;
	_tmp12_ = g_settings_new ("org.gnome.desktop.interface");
	settings = _tmp12_;
	_tmp13_ = settings;
	_tmp14_ = granite_date_time_get_default_time_format (g_settings_get_enum (_tmp13_, "clock-format") == 1, FALSE);
	time_format = _tmp14_;
	_tmp15_ = now;
	_tmp16_ = time_format;
	_tmp17_ = g_date_time_format (_tmp15_, _tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = (GtkLabel*) gtk_label_new (_tmp18_);
	g_object_ref_sink (_tmp19_);
	_tmp20_ = _tmp19_;
	_g_free0 (_tmp18_);
	current_time = _tmp20_;
	_tmp21_ = current_time;
	_tmp22_ = time_format;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp21_, _tmp22_);
	_tmp23_ = current_time;
	gtk_label_set_xalign (_tmp23_, (gfloat) 0);
	_tmp24_ = (GtkLabel*) gtk_label_new ("Localized date:");
	g_object_ref_sink (_tmp24_);
	current_date_label = _tmp24_;
	_tmp25_ = current_date_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp25_, GTK_ALIGN_END);
	_tmp26_ = granite_date_time_get_default_date_format (TRUE, TRUE, TRUE);
	date_format = _tmp26_;
	_tmp27_ = now;
	_tmp28_ = date_format;
	_tmp29_ = g_date_time_format (_tmp27_, _tmp28_);
	_tmp30_ = _tmp29_;
	_tmp31_ = (GtkLabel*) gtk_label_new (_tmp30_);
	g_object_ref_sink (_tmp31_);
	_tmp32_ = _tmp31_;
	_g_free0 (_tmp30_);
	current_date = _tmp32_;
	_tmp33_ = current_date;
	_tmp34_ = date_format;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp33_, _tmp34_);
	_tmp35_ = current_date;
	gtk_label_set_xalign (_tmp35_, (gfloat) 0);
	_tmp36_ = (GtkLabel*) gtk_label_new ("Relative datetime:");
	g_object_ref_sink (_tmp36_);
	relative_datetime_label = _tmp36_;
	_tmp37_ = relative_datetime_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp37_, GTK_ALIGN_END);
	_tmp38_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp38_);
	_g_object_unref0 (self->priv->relative_datetime);
	self->priv->relative_datetime = _tmp38_;
	_tmp39_ = self->priv->relative_datetime;
	gtk_label_set_xalign (_tmp39_, (gfloat) 0);
	date_time_picker_view_set_selected_datetime (self);
	_tmp40_ = self->priv->datepicker;
	g_signal_connect_object ((GtkEditable*) _tmp40_, "changed", (GCallback) __date_time_picker_view___lambda8__gtk_editable_changed, self, 0);
	_tmp41_ = self->priv->timepicker;
	g_signal_connect_object ((GtkEditable*) _tmp41_, "changed", (GCallback) __date_time_picker_view___lambda9__gtk_editable_changed, self, 0);
	_tmp42_ = (GtkGrid*) gtk_grid_new ();
	gtk_widget_set_halign ((GtkWidget*) _tmp42_, GTK_ALIGN_CENTER);
	gtk_widget_set_valign ((GtkWidget*) _tmp42_, GTK_ALIGN_CENTER);
	gtk_grid_set_column_spacing (_tmp42_, 12);
	gtk_grid_set_row_spacing (_tmp42_, 6);
	g_object_ref_sink (_tmp42_);
	grid = _tmp42_;
	_tmp43_ = grid;
	_tmp44_ = pickers_label;
	gtk_grid_attach (_tmp43_, (GtkWidget*) _tmp44_, 0, 0, 1, 1);
	_tmp45_ = grid;
	_tmp46_ = date_label;
	gtk_grid_attach (_tmp45_, (GtkWidget*) _tmp46_, 0, 1, 1, 1);
	_tmp47_ = grid;
	_tmp48_ = self->priv->datepicker;
	gtk_grid_attach (_tmp47_, (GtkWidget*) _tmp48_, 1, 1, 1, 1);
	_tmp49_ = grid;
	_tmp50_ = time_label;
	gtk_grid_attach (_tmp49_, (GtkWidget*) _tmp50_, 0, 2, 1, 1);
	_tmp51_ = grid;
	_tmp52_ = self->priv->timepicker;
	gtk_grid_attach (_tmp51_, (GtkWidget*) _tmp52_, 1, 2, 1, 1);
	_tmp53_ = grid;
	_tmp54_ = formatting_label;
	gtk_grid_attach (_tmp53_, (GtkWidget*) _tmp54_, 0, 3, 1, 1);
	_tmp55_ = grid;
	_tmp56_ = current_time_label;
	gtk_grid_attach (_tmp55_, (GtkWidget*) _tmp56_, 0, 4, 1, 1);
	_tmp57_ = grid;
	_tmp58_ = current_time;
	gtk_grid_attach (_tmp57_, (GtkWidget*) _tmp58_, 1, 4, 1, 1);
	_tmp59_ = grid;
	_tmp60_ = current_date_label;
	gtk_grid_attach (_tmp59_, (GtkWidget*) _tmp60_, 0, 5, 1, 1);
	_tmp61_ = grid;
	_tmp62_ = current_date;
	gtk_grid_attach (_tmp61_, (GtkWidget*) _tmp62_, 1, 5, 1, 1);
	_tmp63_ = grid;
	_tmp64_ = relative_datetime_label;
	gtk_grid_attach (_tmp63_, (GtkWidget*) _tmp64_, 0, 6, 1, 1);
	_tmp65_ = grid;
	_tmp66_ = self->priv->relative_datetime;
	gtk_grid_attach (_tmp65_, (GtkWidget*) _tmp66_, 1, 6, 1, 1);
	_tmp67_ = grid;
	demo_page_set_child ((DemoPage*) self, (GtkWidget*) _tmp67_);
	_g_object_unref0 (grid);
	_g_object_unref0 (relative_datetime_label);
	_g_object_unref0 (current_date);
	_g_free0 (date_format);
	_g_object_unref0 (current_date_label);
	_g_object_unref0 (current_time);
	_g_free0 (time_format);
	_g_object_unref0 (settings);
	_g_date_time_unref0 (now);
	_g_object_unref0 (current_time_label);
	_g_object_unref0 (formatting_label);
	_g_object_unref0 (time_label);
	_g_object_unref0 (date_label);
	_g_object_unref0 (pickers_label);
	return obj;
}

static void
date_time_picker_view_class_init (DateTimePickerViewClass * klass,
                                  gpointer klass_data)
{
	date_time_picker_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DateTimePickerView_private_offset);
	G_OBJECT_CLASS (klass)->constructor = date_time_picker_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = date_time_picker_view_finalize;
}

static void
date_time_picker_view_instance_init (DateTimePickerView * self,
                                     gpointer klass)
{
	self->priv = date_time_picker_view_get_instance_private (self);
}

static void
date_time_picker_view_finalize (GObject * obj)
{
	DateTimePickerView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DATE_TIME_PICKER_VIEW, DateTimePickerView);
	_g_object_unref0 (self->priv->relative_datetime);
	_g_object_unref0 (self->priv->datepicker);
	_g_object_unref0 (self->priv->timepicker);
	G_OBJECT_CLASS (date_time_picker_view_parent_class)->finalize (obj);
}

static GType
date_time_picker_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DateTimePickerViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) date_time_picker_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DateTimePickerView), 0, (GInstanceInitFunc) date_time_picker_view_instance_init, NULL };
	GType date_time_picker_view_type_id;
	date_time_picker_view_type_id = g_type_register_static (TYPE_DEMO_PAGE, "DateTimePickerView", &g_define_type_info, 0);
	DateTimePickerView_private_offset = g_type_add_instance_private (date_time_picker_view_type_id, sizeof (DateTimePickerViewPrivate));
	return date_time_picker_view_type_id;
}

GType
date_time_picker_view_get_type (void)
{
	static volatile gsize date_time_picker_view_type_id__once = 0;
	if (g_once_init_enter (&date_time_picker_view_type_id__once)) {
		GType date_time_picker_view_type_id;
		date_time_picker_view_type_id = date_time_picker_view_get_type_once ();
		g_once_init_leave (&date_time_picker_view_type_id__once, date_time_picker_view_type_id);
	}
	return date_time_picker_view_type_id__once;
}

