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

/* TimeChooser.vala
 *
 * Copyright 2020 Dylan McCall <dylan@dylanmccall.ca>
 *
 * 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 "settings.h"
#include <gio/gio.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include <adwaita.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  {
	BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_0_PROPERTY,
	BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_TIME_SECONDS_PROPERTY,
	BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_NUM_PROPERTIES
};
static GParamSpec* break_timer_settings_widgets_time_chooser_row_properties[BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _gtk_expression_unref0(var) ((var == NULL) ? NULL : (var = (gtk_expression_unref (var), NULL)))

struct _BreakTimerSettingsWidgetsTimeChooserRowPrivate {
	GListStore* list_store;
	guint custom_option_position;
	gint _time_seconds;
};

static gint BreakTimerSettingsWidgetsTimeChooserRow_private_offset;
static gpointer break_timer_settings_widgets_time_chooser_row_parent_class = NULL;

static void break_timer_settings_widgets_time_chooser_row_on_selected_item_changed (BreakTimerSettingsWidgetsTimeChooserRow* self);
static void _break_timer_settings_widgets_time_chooser_row_on_selected_item_changed_g_object_notify (GObject* _sender,
                                                                                              GParamSpec* pspec,
                                                                                              gpointer self);
static void break_timer_settings_widgets_time_chooser_row_on_time_seconds_changed (BreakTimerSettingsWidgetsTimeChooserRow* self);
static void _break_timer_settings_widgets_time_chooser_row_on_time_seconds_changed_g_object_notify (GObject* _sender,
                                                                                             GParamSpec* pspec,
                                                                                             gpointer self);
static gboolean break_timer_settings_widgets_time_chooser_row_find_position_for_time_seconds (BreakTimerSettingsWidgetsTimeChooserRow* self,
                                                                                       gint time_seconds,
                                                                                       guint* out_position);
static gboolean break_timer_settings_widgets_time_chooser_row_set_custom_option (BreakTimerSettingsWidgetsTimeChooserRow* self,
                                                                          gint time_seconds,
                                                                          guint* out_position);
static void break_timer_settings_widgets_time_chooser_row_finalize (GObject * obj);
static GType break_timer_settings_widgets_time_chooser_row_get_type_once (void);
static void _vala_break_timer_settings_widgets_time_chooser_row_get_property (GObject * object,
                                                                       guint property_id,
                                                                       GValue * value,
                                                                       GParamSpec * pspec);
static void _vala_break_timer_settings_widgets_time_chooser_row_set_property (GObject * object,
                                                                       guint property_id,
                                                                       const GValue * value,
                                                                       GParamSpec * pspec);

static inline gpointer
break_timer_settings_widgets_time_chooser_row_get_instance_private (BreakTimerSettingsWidgetsTimeChooserRow* self)
{
	return G_STRUCT_MEMBER_P (self, BreakTimerSettingsWidgetsTimeChooserRow_private_offset);
}

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

static void
_break_timer_settings_widgets_time_chooser_row_on_selected_item_changed_g_object_notify (GObject* _sender,
                                                                                         GParamSpec* pspec,
                                                                                         gpointer self)
{
	break_timer_settings_widgets_time_chooser_row_on_selected_item_changed ((BreakTimerSettingsWidgetsTimeChooserRow*) self);
}

static void
_break_timer_settings_widgets_time_chooser_row_on_time_seconds_changed_g_object_notify (GObject* _sender,
                                                                                        GParamSpec* pspec,
                                                                                        gpointer self)
{
	break_timer_settings_widgets_time_chooser_row_on_time_seconds_changed ((BreakTimerSettingsWidgetsTimeChooserRow*) self);
}

BreakTimerSettingsWidgetsTimeChooserRow*
break_timer_settings_widgets_time_chooser_row_construct (GType object_type,
                                                         BreakTimerSettingsTimerBreakBreakTimeOption** default_options,
                                                         gint default_options_length1)
{
	BreakTimerSettingsWidgetsTimeChooserRow * self = NULL;
	GListStore* _tmp0_;
	GListStore* _tmp4_;
	GtkPropertyExpression* _tmp5_;
	GtkPropertyExpression* _tmp6_;
	self = (BreakTimerSettingsWidgetsTimeChooserRow*) g_object_new (object_type, NULL);
	_tmp0_ = g_list_store_new (BREAK_TIMER_SETTINGS_TIMER_BREAK_TYPE_BREAK_TIME_OPTION);
	_g_object_unref0 (self->priv->list_store);
	self->priv->list_store = _tmp0_;
	{
		BreakTimerSettingsTimerBreakBreakTimeOption** option_collection = NULL;
		gint option_collection_length1 = 0;
		gint _option_collection_size_ = 0;
		gint option_it = 0;
		option_collection = default_options;
		option_collection_length1 = default_options_length1;
		for (option_it = 0; option_it < option_collection_length1; option_it = option_it + 1) {
			BreakTimerSettingsTimerBreakBreakTimeOption* _tmp1_;
			BreakTimerSettingsTimerBreakBreakTimeOption* option = NULL;
			_tmp1_ = _g_object_ref0 (option_collection[option_it]);
			option = _tmp1_;
			{
				GListStore* _tmp2_;
				BreakTimerSettingsTimerBreakBreakTimeOption* _tmp3_;
				_tmp2_ = self->priv->list_store;
				_tmp3_ = option;
				g_list_store_append (_tmp2_, (GObject*) _tmp3_);
				_g_object_unref0 (option);
			}
		}
	}
	_tmp4_ = self->priv->list_store;
	adw_combo_row_set_model ((AdwComboRow*) self, (GListModel*) _tmp4_);
	_tmp5_ = (GtkPropertyExpression*) gtk_property_expression_new (BREAK_TIMER_SETTINGS_TIMER_BREAK_TYPE_BREAK_TIME_OPTION, NULL, "label");
	_tmp6_ = _tmp5_;
	adw_combo_row_set_expression ((AdwComboRow*) self, (GtkExpression*) _tmp6_);
	_gtk_expression_unref0 (_tmp6_);
	g_signal_connect_object ((GObject*) self, "notify::selected-item", (GCallback) _break_timer_settings_widgets_time_chooser_row_on_selected_item_changed_g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) self, "notify::time-seconds", (GCallback) _break_timer_settings_widgets_time_chooser_row_on_time_seconds_changed_g_object_notify, self, 0);
	return self;
}

BreakTimerSettingsWidgetsTimeChooserRow*
break_timer_settings_widgets_time_chooser_row_new (BreakTimerSettingsTimerBreakBreakTimeOption** default_options,
                                                   gint default_options_length1)
{
	return break_timer_settings_widgets_time_chooser_row_construct (BREAK_TIMER_SETTINGS_WIDGETS_TYPE_TIME_CHOOSER_ROW, default_options, default_options_length1);
}

static void
break_timer_settings_widgets_time_chooser_row_on_selected_item_changed (BreakTimerSettingsWidgetsTimeChooserRow* self)
{
	BreakTimerSettingsTimerBreakBreakTimeOption* option = NULL;
	GObject* _tmp0_;
	BreakTimerSettingsTimerBreakBreakTimeOption* _tmp1_;
	BreakTimerSettingsTimerBreakBreakTimeOption* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = adw_combo_row_get_selected_item ((AdwComboRow*) self);
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, BREAK_TIMER_SETTINGS_TIMER_BREAK_TYPE_BREAK_TIME_OPTION, BreakTimerSettingsTimerBreakBreakTimeOption));
	option = _tmp1_;
	_tmp2_ = option;
	if (_tmp2_ != NULL) {
		BreakTimerSettingsTimerBreakBreakTimeOption* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = option;
		_tmp4_ = break_timer_settings_timer_break_break_time_option_get_time_seconds (_tmp3_);
		_tmp5_ = _tmp4_;
		break_timer_settings_widgets_time_chooser_row_set_time_seconds (self, _tmp5_);
	}
	_g_object_unref0 (option);
}

static void
break_timer_settings_widgets_time_chooser_row_on_time_seconds_changed (BreakTimerSettingsWidgetsTimeChooserRow* self)
{
	guint find_position = 0U;
	gint _tmp0_;
	guint _tmp1_ = 0U;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_time_seconds;
	_tmp2_ = break_timer_settings_widgets_time_chooser_row_find_position_for_time_seconds (self, _tmp0_, &_tmp1_);
	find_position = _tmp1_;
	if (_tmp2_) {
		adw_combo_row_set_selected ((AdwComboRow*) self, find_position);
	} else {
		gint _tmp3_;
		guint _tmp4_ = 0U;
		gboolean _tmp5_;
		_tmp3_ = self->priv->_time_seconds;
		_tmp5_ = break_timer_settings_widgets_time_chooser_row_set_custom_option (self, _tmp3_, &_tmp4_);
		find_position = _tmp4_;
		if (_tmp5_) {
			adw_combo_row_set_selected ((AdwComboRow*) self, find_position);
		}
	}
}

static gboolean
break_timer_settings_widgets_time_chooser_row_set_custom_option (BreakTimerSettingsWidgetsTimeChooserRow* self,
                                                                 gint time_seconds,
                                                                 guint* out_position)
{
	guint _vala_out_position = 0U;
	BreakTimerSettingsTimerBreakBreakTimeOption* custom_option = NULL;
	gint _tmp0_;
	BreakTimerSettingsTimerBreakBreakTimeOption* _tmp1_;
	GListStore* _tmp2_;
	guint _tmp3_;
	guint _tmp4_;
	GListStore* _tmp9_;
	BreakTimerSettingsTimerBreakBreakTimeOption* _tmp10_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_time_seconds;
	_tmp1_ = break_timer_settings_timer_break_break_time_option_new (_tmp0_);
	custom_option = _tmp1_;
	_tmp2_ = self->priv->list_store;
	g_object_get (_tmp2_, "n-items", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	if (self->priv->custom_option_position < _tmp4_) {
		GListStore* _tmp5_;
		_tmp5_ = self->priv->list_store;
		g_list_store_remove (_tmp5_, self->priv->custom_option_position);
	} else {
		GListStore* _tmp6_;
		guint _tmp7_;
		guint _tmp8_;
		_tmp6_ = self->priv->list_store;
		g_object_get (_tmp6_, "n-items", &_tmp7_, NULL);
		_tmp8_ = _tmp7_;
		self->priv->custom_option_position = _tmp8_;
	}
	_tmp9_ = self->priv->list_store;
	_tmp10_ = custom_option;
	g_list_store_insert (_tmp9_, self->priv->custom_option_position, (GObject*) _tmp10_);
	_vala_out_position = self->priv->custom_option_position;
	result = TRUE;
	_g_object_unref0 (custom_option);
	if (out_position) {
		*out_position = _vala_out_position;
	}
	return result;
}

static gboolean
break_timer_settings_widgets_time_chooser_row_find_position_for_time_seconds (BreakTimerSettingsWidgetsTimeChooserRow* self,
                                                                              gint time_seconds,
                                                                              guint* out_position)
{
	guint _vala_out_position = 0U;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GListStore* _tmp2_;
				guint _tmp3_;
				guint _tmp4_;
				BreakTimerSettingsTimerBreakBreakTimeOption* option = NULL;
				GListStore* _tmp5_;
				GObject* _tmp6_;
				BreakTimerSettingsTimerBreakBreakTimeOption* _tmp7_;
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->list_store;
				g_object_get (_tmp2_, "n-items", &_tmp3_, NULL);
				_tmp4_ = _tmp3_;
				if (!(i < _tmp4_)) {
					break;
				}
				_tmp5_ = self->priv->list_store;
				_tmp6_ = g_list_model_get_object ((GListModel*) _tmp5_, i);
				option = G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, BREAK_TIMER_SETTINGS_TIMER_BREAK_TYPE_BREAK_TIME_OPTION, BreakTimerSettingsTimerBreakBreakTimeOption);
				_tmp7_ = option;
				if (_tmp7_ == NULL) {
					_g_object_unref0 (option);
					continue;
				} else {
					BreakTimerSettingsTimerBreakBreakTimeOption* _tmp8_;
					gint _tmp9_;
					gint _tmp10_;
					_tmp8_ = option;
					_tmp9_ = break_timer_settings_timer_break_break_time_option_get_time_seconds (_tmp8_);
					_tmp10_ = _tmp9_;
					if (_tmp10_ == time_seconds) {
						_vala_out_position = i;
						result = TRUE;
						_g_object_unref0 (option);
						if (out_position) {
							*out_position = _vala_out_position;
						}
						return result;
					}
				}
				_g_object_unref0 (option);
			}
		}
	}
	_vala_out_position = GTK_INVALID_LIST_POSITION;
	result = FALSE;
	if (out_position) {
		*out_position = _vala_out_position;
	}
	return result;
}

gint
break_timer_settings_widgets_time_chooser_row_get_time_seconds (BreakTimerSettingsWidgetsTimeChooserRow* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_time_seconds;
	return result;
}

void
break_timer_settings_widgets_time_chooser_row_set_time_seconds (BreakTimerSettingsWidgetsTimeChooserRow* self,
                                                                gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = break_timer_settings_widgets_time_chooser_row_get_time_seconds (self);
	if (old_value != value) {
		self->priv->_time_seconds = value;
		g_object_notify_by_pspec ((GObject *) self, break_timer_settings_widgets_time_chooser_row_properties[BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_TIME_SECONDS_PROPERTY]);
	}
}

static void
break_timer_settings_widgets_time_chooser_row_class_init (BreakTimerSettingsWidgetsTimeChooserRowClass * klass,
                                                          gpointer klass_data)
{
	break_timer_settings_widgets_time_chooser_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BreakTimerSettingsWidgetsTimeChooserRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_break_timer_settings_widgets_time_chooser_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_break_timer_settings_widgets_time_chooser_row_set_property;
	G_OBJECT_CLASS (klass)->finalize = break_timer_settings_widgets_time_chooser_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_TIME_SECONDS_PROPERTY, break_timer_settings_widgets_time_chooser_row_properties[BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_TIME_SECONDS_PROPERTY] = g_param_spec_int ("time-seconds", "time-seconds", "time-seconds", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
break_timer_settings_widgets_time_chooser_row_instance_init (BreakTimerSettingsWidgetsTimeChooserRow * self,
                                                             gpointer klass)
{
	self->priv = break_timer_settings_widgets_time_chooser_row_get_instance_private (self);
	self->priv->custom_option_position = GTK_INVALID_LIST_POSITION;
}

static void
break_timer_settings_widgets_time_chooser_row_finalize (GObject * obj)
{
	BreakTimerSettingsWidgetsTimeChooserRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BREAK_TIMER_SETTINGS_WIDGETS_TYPE_TIME_CHOOSER_ROW, BreakTimerSettingsWidgetsTimeChooserRow);
	_g_object_unref0 (self->priv->list_store);
	G_OBJECT_CLASS (break_timer_settings_widgets_time_chooser_row_parent_class)->finalize (obj);
}

static GType
break_timer_settings_widgets_time_chooser_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BreakTimerSettingsWidgetsTimeChooserRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) break_timer_settings_widgets_time_chooser_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BreakTimerSettingsWidgetsTimeChooserRow), 0, (GInstanceInitFunc) break_timer_settings_widgets_time_chooser_row_instance_init, NULL };
	GType break_timer_settings_widgets_time_chooser_row_type_id;
	break_timer_settings_widgets_time_chooser_row_type_id = g_type_register_static (adw_combo_row_get_type (), "BreakTimerSettingsWidgetsTimeChooserRow", &g_define_type_info, 0);
	BreakTimerSettingsWidgetsTimeChooserRow_private_offset = g_type_add_instance_private (break_timer_settings_widgets_time_chooser_row_type_id, sizeof (BreakTimerSettingsWidgetsTimeChooserRowPrivate));
	return break_timer_settings_widgets_time_chooser_row_type_id;
}

GType
break_timer_settings_widgets_time_chooser_row_get_type (void)
{
	static volatile gsize break_timer_settings_widgets_time_chooser_row_type_id__once = 0;
	if (g_once_init_enter (&break_timer_settings_widgets_time_chooser_row_type_id__once)) {
		GType break_timer_settings_widgets_time_chooser_row_type_id;
		break_timer_settings_widgets_time_chooser_row_type_id = break_timer_settings_widgets_time_chooser_row_get_type_once ();
		g_once_init_leave (&break_timer_settings_widgets_time_chooser_row_type_id__once, break_timer_settings_widgets_time_chooser_row_type_id);
	}
	return break_timer_settings_widgets_time_chooser_row_type_id__once;
}

static void
_vala_break_timer_settings_widgets_time_chooser_row_get_property (GObject * object,
                                                                  guint property_id,
                                                                  GValue * value,
                                                                  GParamSpec * pspec)
{
	BreakTimerSettingsWidgetsTimeChooserRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BREAK_TIMER_SETTINGS_WIDGETS_TYPE_TIME_CHOOSER_ROW, BreakTimerSettingsWidgetsTimeChooserRow);
	switch (property_id) {
		case BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_TIME_SECONDS_PROPERTY:
		g_value_set_int (value, break_timer_settings_widgets_time_chooser_row_get_time_seconds (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_break_timer_settings_widgets_time_chooser_row_set_property (GObject * object,
                                                                  guint property_id,
                                                                  const GValue * value,
                                                                  GParamSpec * pspec)
{
	BreakTimerSettingsWidgetsTimeChooserRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BREAK_TIMER_SETTINGS_WIDGETS_TYPE_TIME_CHOOSER_ROW, BreakTimerSettingsWidgetsTimeChooserRow);
	switch (property_id) {
		case BREAK_TIMER_SETTINGS_WIDGETS_TIME_CHOOSER_ROW_TIME_SECONDS_PROPERTY:
		break_timer_settings_widgets_time_chooser_row_set_time_seconds (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

