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

/* BreakSettingsDialog.vala
 *
 * Copyright 2020-2021 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 <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include "config.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.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

#define BREAK_TIMER_SETTINGS_WIDGETS_TYPE_BREAK_CONFIGURATION_CHOOSER (break_timer_settings_widgets_break_configuration_chooser_get_type ())
#define BREAK_TIMER_SETTINGS_WIDGETS_BREAK_CONFIGURATION_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BREAK_TIMER_SETTINGS_WIDGETS_TYPE_BREAK_CONFIGURATION_CHOOSER, BreakTimerSettingsWidgetsBreakConfigurationChooser))
#define BREAK_TIMER_SETTINGS_WIDGETS_BREAK_CONFIGURATION_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BREAK_TIMER_SETTINGS_WIDGETS_TYPE_BREAK_CONFIGURATION_CHOOSER, BreakTimerSettingsWidgetsBreakConfigurationChooserClass))
#define BREAK_TIMER_SETTINGS_WIDGETS_IS_BREAK_CONFIGURATION_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BREAK_TIMER_SETTINGS_WIDGETS_TYPE_BREAK_CONFIGURATION_CHOOSER))
#define BREAK_TIMER_SETTINGS_WIDGETS_IS_BREAK_CONFIGURATION_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BREAK_TIMER_SETTINGS_WIDGETS_TYPE_BREAK_CONFIGURATION_CHOOSER))
#define BREAK_TIMER_SETTINGS_WIDGETS_BREAK_CONFIGURATION_CHOOSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BREAK_TIMER_SETTINGS_WIDGETS_TYPE_BREAK_CONFIGURATION_CHOOSER, BreakTimerSettingsWidgetsBreakConfigurationChooserClass))

typedef struct _BreakTimerSettingsWidgetsBreakConfigurationChooser BreakTimerSettingsWidgetsBreakConfigurationChooser;
typedef struct _BreakTimerSettingsWidgetsBreakConfigurationChooserClass BreakTimerSettingsWidgetsBreakConfigurationChooserClass;
enum  {
	BREAK_TIMER_SETTINGS_BREAK_SETTINGS_DIALOG_0_PROPERTY,
	BREAK_TIMER_SETTINGS_BREAK_SETTINGS_DIALOG_NUM_PROPERTIES
};
static GParamSpec* break_timer_settings_break_settings_dialog_properties[BREAK_TIMER_SETTINGS_BREAK_SETTINGS_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BreakTimerSettingsBreakSettingsDialogPrivate {
	BreakTimerSettingsBreakManager* break_manager;
	AdwPreferencesPage* main_preferences_page;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* configuration_chooser;
};

static gint BreakTimerSettingsBreakSettingsDialog_private_offset;
static gpointer break_timer_settings_break_settings_dialog_parent_class = NULL;

VALA_EXTERN GType break_timer_settings_widgets_break_configuration_chooser_get_type (void) G_GNUC_CONST ;
VALA_EXTERN BreakTimerSettingsWidgetsBreakConfigurationChooser* break_timer_settings_widgets_break_configuration_chooser_new (void);
VALA_EXTERN BreakTimerSettingsWidgetsBreakConfigurationChooser* break_timer_settings_widgets_break_configuration_chooser_construct (GType object_type);
VALA_EXTERN void break_timer_settings_widgets_break_configuration_chooser_add_configuration (BreakTimerSettingsWidgetsBreakConfigurationChooser* self,
                                                                                 gchar** break_ids,
                                                                                 gint break_ids_length1,
                                                                                 const gchar* label);
static void break_timer_settings_break_settings_dialog_update_break_configuration (BreakTimerSettingsBreakSettingsDialog* self);
static void _break_timer_settings_break_settings_dialog_update_break_configuration_g_object_notify (GObject* _sender,
                                                                                             GParamSpec* pspec,
                                                                                             gpointer self);
VALA_EXTERN gchar** break_timer_settings_widgets_break_configuration_chooser_get_selected_break_ids (BreakTimerSettingsWidgetsBreakConfigurationChooser* self,
                                                                                         gint* result_length1);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
static void break_timer_settings_break_settings_dialog_finalize (GObject * obj);
static GType break_timer_settings_break_settings_dialog_get_type_once (void);
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
break_timer_settings_break_settings_dialog_get_instance_private (BreakTimerSettingsBreakSettingsDialog* self)
{
	return G_STRUCT_MEMBER_P (self, BreakTimerSettingsBreakSettingsDialog_private_offset);
}

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

static void
_break_timer_settings_break_settings_dialog_update_break_configuration_g_object_notify (GObject* _sender,
                                                                                        GParamSpec* pspec,
                                                                                        gpointer self)
{
	break_timer_settings_break_settings_dialog_update_break_configuration ((BreakTimerSettingsBreakSettingsDialog*) self);
}

BreakTimerSettingsBreakSettingsDialog*
break_timer_settings_break_settings_dialog_construct (GType object_type,
                                                      BreakTimerSettingsBreakManager* break_manager)
{
	BreakTimerSettingsBreakSettingsDialog * self = NULL;
	BreakTimerSettingsBreakManager* _tmp0_;
	GSettings* settings = NULL;
	GSettings* _tmp1_;
	AdwPreferencesPage* _tmp2_;
	AdwPreferencesPage* _tmp3_;
	AdwPreferencesGroup* global_preferences_group = NULL;
	AdwPreferencesGroup* _tmp4_;
	AdwPreferencesPage* _tmp5_;
	AdwPreferencesGroup* _tmp6_;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp7_;
	AdwPreferencesGroup* _tmp8_;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp9_;
	BreakTimerSettingsBreakManager* _tmp10_;
	GList* _tmp11_;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar** _tmp20_;
	gchar** _tmp21_;
	gint _tmp21__length1;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp22_;
	gchar* _tmp23_;
	gchar** _tmp24_;
	gchar** _tmp25_;
	gint _tmp25__length1;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp26_;
	gchar* _tmp27_;
	gchar** _tmp28_;
	gchar** _tmp29_;
	gint _tmp29__length1;
	GSettings* _tmp30_;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp31_;
	BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp32_;
	g_return_val_if_fail (break_manager != NULL, NULL);
	self = (BreakTimerSettingsBreakSettingsDialog*) g_object_new (object_type, "search-enabled", FALSE, NULL);
	_tmp0_ = _g_object_ref0 (break_manager);
	_g_object_unref0 (self->priv->break_manager);
	self->priv->break_manager = _tmp0_;
	_tmp1_ = g_settings_new (APPLICATION_ID);
	settings = _tmp1_;
	_tmp2_ = (AdwPreferencesPage*) adw_preferences_page_new ();
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->main_preferences_page);
	self->priv->main_preferences_page = _tmp2_;
	_tmp3_ = self->priv->main_preferences_page;
	adw_preferences_window_add ((AdwPreferencesWindow*) self, _tmp3_);
	_tmp4_ = (AdwPreferencesGroup*) adw_preferences_group_new ();
	g_object_ref_sink (_tmp4_);
	global_preferences_group = _tmp4_;
	_tmp5_ = self->priv->main_preferences_page;
	_tmp6_ = global_preferences_group;
	adw_preferences_page_add (_tmp5_, _tmp6_);
	_tmp7_ = break_timer_settings_widgets_break_configuration_chooser_new ();
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->configuration_chooser);
	self->priv->configuration_chooser = _tmp7_;
	_tmp8_ = global_preferences_group;
	_tmp9_ = self->priv->configuration_chooser;
	adw_preferences_group_add (_tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->break_manager;
	_tmp11_ = break_timer_settings_break_manager_all_breaks (_tmp10_);
	{
		GList* break_type_collection = NULL;
		GList* break_type_it = NULL;
		break_type_collection = _tmp11_;
		for (break_type_it = break_type_collection; break_type_it != NULL; break_type_it = break_type_it->next) {
			BreakTimerSettingsBreakBreakType* _tmp12_;
			BreakTimerSettingsBreakBreakType* break_type = NULL;
			_tmp12_ = _g_object_ref0 ((BreakTimerSettingsBreakBreakType*) break_type_it->data);
			break_type = _tmp12_;
			{
				AdwPreferencesPage* _tmp13_;
				BreakTimerSettingsBreakBreakType* _tmp14_;
				BreakTimerSettingsBreakBreakSettingsWidget* _tmp15_;
				BreakTimerSettingsBreakBreakSettingsWidget* _tmp16_;
				_tmp13_ = self->priv->main_preferences_page;
				_tmp14_ = break_type;
				_tmp15_ = break_timer_settings_break_break_type_get_settings_widget (_tmp14_);
				_tmp16_ = _tmp15_;
				adw_preferences_page_add (_tmp13_, (AdwPreferencesGroup*) _tmp16_);
				_g_object_unref0 (break_type);
			}
		}
	}
	_tmp17_ = self->priv->configuration_chooser;
	_tmp18_ = g_strdup ("microbreak");
	_tmp19_ = g_strdup ("restbreak");
	_tmp20_ = g_new0 (gchar*, 2 + 1);
	_tmp20_[0] = _tmp18_;
	_tmp20_[1] = _tmp19_;
	_tmp21_ = _tmp20_;
	_tmp21__length1 = 2;
	break_timer_settings_widgets_break_configuration_chooser_add_configuration (_tmp17_, _tmp21_, (gint) 2, _ ("A mix of short breaks and long breaks"));
	_tmp21_ = (_vala_array_free (_tmp21_, _tmp21__length1, (GDestroyNotify) g_free), NULL);
	_tmp22_ = self->priv->configuration_chooser;
	_tmp23_ = g_strdup ("restbreak");
	_tmp24_ = g_new0 (gchar*, 1 + 1);
	_tmp24_[0] = _tmp23_;
	_tmp25_ = _tmp24_;
	_tmp25__length1 = 1;
	break_timer_settings_widgets_break_configuration_chooser_add_configuration (_tmp22_, _tmp25_, (gint) 1, _ ("Occasional long breaks"));
	_tmp25_ = (_vala_array_free (_tmp25_, _tmp25__length1, (GDestroyNotify) g_free), NULL);
	_tmp26_ = self->priv->configuration_chooser;
	_tmp27_ = g_strdup ("microbreak");
	_tmp28_ = g_new0 (gchar*, 1 + 1);
	_tmp28_[0] = _tmp27_;
	_tmp29_ = _tmp28_;
	_tmp29__length1 = 1;
	break_timer_settings_widgets_break_configuration_chooser_add_configuration (_tmp26_, _tmp29_, (gint) 1, _ ("Frequent short breaks"));
	_tmp29_ = (_vala_array_free (_tmp29_, _tmp29__length1, (GDestroyNotify) g_free), NULL);
	_tmp30_ = settings;
	_tmp31_ = self->priv->configuration_chooser;
	g_settings_bind (_tmp30_, "selected-breaks", (GObject*) _tmp31_, "selected-break-ids", G_SETTINGS_BIND_DEFAULT);
	_tmp32_ = self->priv->configuration_chooser;
	g_signal_connect_object ((GObject*) _tmp32_, "notify::selected-break-ids", (GCallback) _break_timer_settings_break_settings_dialog_update_break_configuration_g_object_notify, self, 0);
	_g_object_unref0 (global_preferences_group);
	_g_object_unref0 (settings);
	return self;
}

BreakTimerSettingsBreakSettingsDialog*
break_timer_settings_break_settings_dialog_new (BreakTimerSettingsBreakManager* break_manager)
{
	return break_timer_settings_break_settings_dialog_construct (BREAK_TIMER_SETTINGS_TYPE_BREAK_SETTINGS_DIALOG, break_manager);
}

gboolean
break_timer_settings_break_settings_dialog_init (BreakTimerSettingsBreakSettingsDialog* self,
                                                 GCancellable* cancellable,
                                                 GError** error)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	break_timer_settings_break_settings_dialog_update_break_configuration (self);
	result = TRUE;
	return result;
}

static gboolean
_vala_string_array_contains (gchar* * stack,
                             gssize stack_length,
                             const gchar* needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}

static void
break_timer_settings_break_settings_dialog_update_break_configuration (BreakTimerSettingsBreakSettingsDialog* self)
{
	BreakTimerSettingsBreakManager* _tmp0_;
	GList* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->break_manager;
	_tmp1_ = break_timer_settings_break_manager_all_breaks (_tmp0_);
	{
		GList* break_type_collection = NULL;
		GList* break_type_it = NULL;
		break_type_collection = _tmp1_;
		for (break_type_it = break_type_collection; break_type_it != NULL; break_type_it = break_type_it->next) {
			BreakTimerSettingsBreakBreakType* _tmp2_;
			BreakTimerSettingsBreakBreakType* break_type = NULL;
			_tmp2_ = _g_object_ref0 ((BreakTimerSettingsBreakBreakType*) break_type_it->data);
			break_type = _tmp2_;
			{
				BreakTimerSettingsBreakBreakType* _tmp3_;
				BreakTimerSettingsBreakBreakSettingsWidget* _tmp4_;
				BreakTimerSettingsBreakBreakSettingsWidget* _tmp5_;
				BreakTimerSettingsBreakBreakType* _tmp6_;
				const gchar* _tmp7_;
				const gchar* _tmp8_;
				BreakTimerSettingsWidgetsBreakConfigurationChooser* _tmp9_;
				gchar** _tmp10_;
				gint _tmp10__length1;
				gint _tmp11_ = 0;
				gchar** _tmp12_;
				gint _tmp12__length1;
				_tmp3_ = break_type;
				_tmp4_ = break_timer_settings_break_break_type_get_settings_widget (_tmp3_);
				_tmp5_ = _tmp4_;
				_tmp6_ = break_type;
				_tmp7_ = break_timer_settings_break_break_type_get_id (_tmp6_);
				_tmp8_ = _tmp7_;
				_tmp9_ = self->priv->configuration_chooser;
				_tmp10_ = break_timer_settings_widgets_break_configuration_chooser_get_selected_break_ids (_tmp9_, &_tmp11_);
				_tmp10__length1 = _tmp11_;
				_tmp12_ = _tmp10_;
				_tmp12__length1 = _tmp10__length1;
				gtk_widget_set_visible ((GtkWidget*) _tmp5_, _vala_string_array_contains (_tmp12_, _tmp12__length1, _tmp8_));
				_g_object_unref0 (break_type);
			}
		}
	}
}

static void
break_timer_settings_break_settings_dialog_class_init (BreakTimerSettingsBreakSettingsDialogClass * klass,
                                                       gpointer klass_data)
{
	break_timer_settings_break_settings_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BreakTimerSettingsBreakSettingsDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = break_timer_settings_break_settings_dialog_finalize;
}

static void
break_timer_settings_break_settings_dialog_instance_init (BreakTimerSettingsBreakSettingsDialog * self,
                                                          gpointer klass)
{
	self->priv = break_timer_settings_break_settings_dialog_get_instance_private (self);
}

static void
break_timer_settings_break_settings_dialog_finalize (GObject * obj)
{
	BreakTimerSettingsBreakSettingsDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BREAK_TIMER_SETTINGS_TYPE_BREAK_SETTINGS_DIALOG, BreakTimerSettingsBreakSettingsDialog);
	_g_object_unref0 (self->priv->break_manager);
	_g_object_unref0 (self->priv->main_preferences_page);
	_g_object_unref0 (self->priv->configuration_chooser);
	G_OBJECT_CLASS (break_timer_settings_break_settings_dialog_parent_class)->finalize (obj);
}

static GType
break_timer_settings_break_settings_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BreakTimerSettingsBreakSettingsDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) break_timer_settings_break_settings_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BreakTimerSettingsBreakSettingsDialog), 0, (GInstanceInitFunc) break_timer_settings_break_settings_dialog_instance_init, NULL };
	GType break_timer_settings_break_settings_dialog_type_id;
	break_timer_settings_break_settings_dialog_type_id = g_type_register_static (adw_preferences_window_get_type (), "BreakTimerSettingsBreakSettingsDialog", &g_define_type_info, 0);
	BreakTimerSettingsBreakSettingsDialog_private_offset = g_type_add_instance_private (break_timer_settings_break_settings_dialog_type_id, sizeof (BreakTimerSettingsBreakSettingsDialogPrivate));
	return break_timer_settings_break_settings_dialog_type_id;
}

GType
break_timer_settings_break_settings_dialog_get_type (void)
{
	static volatile gsize break_timer_settings_break_settings_dialog_type_id__once = 0;
	if (g_once_init_enter (&break_timer_settings_break_settings_dialog_type_id__once)) {
		GType break_timer_settings_break_settings_dialog_type_id;
		break_timer_settings_break_settings_dialog_type_id = break_timer_settings_break_settings_dialog_get_type_once ();
		g_once_init_leave (&break_timer_settings_break_settings_dialog_type_id__once, break_timer_settings_break_settings_dialog_type_id);
	}
	return break_timer_settings_break_settings_dialog_type_id__once;
}

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

