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

/* StatusPanel.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 <gtk/gtk.h>
#include <gio/gio.h>
#include <glib-object.h>
#include "settings.h"
#include <glib.h>
#include "common.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

#define BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL (break_timer_settings_panels_status_panel_get_type ())
#define BREAK_TIMER_SETTINGS_PANELS_STATUS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL, BreakTimerSettingsPanelsStatusPanel))
#define BREAK_TIMER_SETTINGS_PANELS_STATUS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL, BreakTimerSettingsPanelsStatusPanelClass))
#define BREAK_TIMER_SETTINGS_PANELS_IS_STATUS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL))
#define BREAK_TIMER_SETTINGS_PANELS_IS_STATUS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL))
#define BREAK_TIMER_SETTINGS_PANELS_STATUS_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL, BreakTimerSettingsPanelsStatusPanelClass))

typedef struct _BreakTimerSettingsPanelsStatusPanel BreakTimerSettingsPanelsStatusPanel;
typedef struct _BreakTimerSettingsPanelsStatusPanelClass BreakTimerSettingsPanelsStatusPanelClass;
typedef struct _BreakTimerSettingsPanelsStatusPanelPrivate BreakTimerSettingsPanelsStatusPanelPrivate;
enum  {
	BREAK_TIMER_SETTINGS_PANELS_STATUS_PANEL_0_PROPERTY,
	BREAK_TIMER_SETTINGS_PANELS_STATUS_PANEL_NUM_PROPERTIES
};
static GParamSpec* break_timer_settings_panels_status_panel_properties[BREAK_TIMER_SETTINGS_PANELS_STATUS_PANEL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))

struct _BreakTimerSettingsPanelsStatusPanel {
	GtkBox parent_instance;
	BreakTimerSettingsPanelsStatusPanelPrivate * priv;
};

struct _BreakTimerSettingsPanelsStatusPanelClass {
	GtkBoxClass parent_class;
};

struct _BreakTimerSettingsPanelsStatusPanelPrivate {
	BreakTimerSettingsBreakManager* break_manager;
	GtkStack* stack;
	GtkBox* breaks_list;
	GtkWidget* no_breaks_message;
	GtkWidget* error_message;
};

static gint BreakTimerSettingsPanelsStatusPanel_private_offset;
static gpointer break_timer_settings_panels_status_panel_parent_class = NULL;
static GInitableIface * break_timer_settings_panels_status_panel_g_initable_parent_iface = NULL;

VALA_EXTERN GType break_timer_settings_panels_status_panel_get_type (void) G_GNUC_CONST ;
VALA_EXTERN BreakTimerSettingsPanelsStatusPanel* break_timer_settings_panels_status_panel_new (BreakTimerSettingsBreakManager* break_manager,
                                                                                   GtkBuilder* builder);
VALA_EXTERN BreakTimerSettingsPanelsStatusPanel* break_timer_settings_panels_status_panel_construct (GType object_type,
                                                                                         BreakTimerSettingsBreakManager* break_manager,
                                                                                         GtkBuilder* builder);
static GtkBox* break_timer_settings_panels_status_panel_build_breaks_list (BreakTimerSettingsPanelsStatusPanel* self,
                                                                    BreakTimerSettingsBreakManager* break_manager);
static void break_timer_settings_panels_status_panel_status_changed_cb (BreakTimerSettingsPanelsStatusPanel* self);
static void _break_timer_settings_panels_status_panel_status_changed_cb_break_timer_settings_break_manager_status_changed (BreakTimerSettingsBreakManager* _sender,
                                                                                                                    gpointer self);
static gboolean break_timer_settings_panels_status_panel_real_init (GInitable* base,
                                                             GCancellable* cancellable,
                                                             GError** error);
static BreakTimerCommonBreakStatus* _break_timer_common_break_status_dup (BreakTimerCommonBreakStatus* self);
static void break_timer_settings_panels_status_panel_finalize (GObject * obj);
static GType break_timer_settings_panels_status_panel_get_type_once (void);

static inline gpointer
break_timer_settings_panels_status_panel_get_instance_private (BreakTimerSettingsPanelsStatusPanel* self)
{
	return G_STRUCT_MEMBER_P (self, BreakTimerSettingsPanelsStatusPanel_private_offset);
}

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

static void
_break_timer_settings_panels_status_panel_status_changed_cb_break_timer_settings_break_manager_status_changed (BreakTimerSettingsBreakManager* _sender,
                                                                                                               gpointer self)
{
	break_timer_settings_panels_status_panel_status_changed_cb ((BreakTimerSettingsPanelsStatusPanel*) self);
}

BreakTimerSettingsPanelsStatusPanel*
break_timer_settings_panels_status_panel_construct (GType object_type,
                                                    BreakTimerSettingsBreakManager* break_manager,
                                                    GtkBuilder* builder)
{
	BreakTimerSettingsPanelsStatusPanel * self = NULL;
	BreakTimerSettingsBreakManager* _tmp0_;
	GtkStack* _tmp1_;
	GtkStack* _tmp2_;
	GtkBox* _tmp3_;
	GtkStack* _tmp4_;
	GtkBox* _tmp5_;
	GObject* _tmp6_;
	GtkWidget* _tmp7_;
	GtkStack* _tmp8_;
	GtkWidget* _tmp9_;
	GObject* _tmp10_;
	GtkWidget* _tmp11_;
	GtkStack* _tmp12_;
	GtkWidget* _tmp13_;
	g_return_val_if_fail (break_manager != NULL, NULL);
	g_return_val_if_fail (builder != NULL, NULL);
	self = (BreakTimerSettingsPanelsStatusPanel*) g_object_new (object_type, "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 0, NULL);
	_tmp0_ = _g_object_ref0 (break_manager);
	_g_object_unref0 (self->priv->break_manager);
	self->priv->break_manager = _tmp0_;
	gtk_widget_set_margin_top ((GtkWidget*) self, 20);
	gtk_widget_set_margin_end ((GtkWidget*) self, 20);
	gtk_widget_set_margin_bottom ((GtkWidget*) self, 20);
	gtk_widget_set_margin_start ((GtkWidget*) self, 20);
	gtk_widget_set_hexpand ((GtkWidget*) self, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) self, TRUE);
	_tmp1_ = (GtkStack*) gtk_stack_new ();
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->stack);
	self->priv->stack = _tmp1_;
	_tmp2_ = self->priv->stack;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp2_);
	_tmp3_ = break_timer_settings_panels_status_panel_build_breaks_list (self, break_manager);
	_g_object_unref0 (self->priv->breaks_list);
	self->priv->breaks_list = _tmp3_;
	_tmp4_ = self->priv->stack;
	_tmp5_ = self->priv->breaks_list;
	gtk_stack_add_child (_tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = gtk_builder_get_object (builder, "status_stopped");
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp6_) : NULL);
	_g_object_unref0 (self->priv->no_breaks_message);
	self->priv->no_breaks_message = _tmp7_;
	_tmp8_ = self->priv->stack;
	_tmp9_ = self->priv->no_breaks_message;
	gtk_stack_add_child (_tmp8_, _tmp9_);
	_tmp10_ = gtk_builder_get_object (builder, "status_error");
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp10_, gtk_widget_get_type ()) ? ((GtkWidget*) _tmp10_) : NULL);
	_g_object_unref0 (self->priv->error_message);
	self->priv->error_message = _tmp11_;
	_tmp12_ = self->priv->stack;
	_tmp13_ = self->priv->error_message;
	gtk_stack_add_child (_tmp12_, _tmp13_);
	g_signal_connect_object (break_manager, "status-changed", (GCallback) _break_timer_settings_panels_status_panel_status_changed_cb_break_timer_settings_break_manager_status_changed, self, 0);
	return self;
}

BreakTimerSettingsPanelsStatusPanel*
break_timer_settings_panels_status_panel_new (BreakTimerSettingsBreakManager* break_manager,
                                              GtkBuilder* builder)
{
	return break_timer_settings_panels_status_panel_construct (BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL, break_manager, builder);
}

static gboolean
break_timer_settings_panels_status_panel_real_init (GInitable* base,
                                                    GCancellable* cancellable,
                                                    GError** error)
{
	BreakTimerSettingsPanelsStatusPanel * self;
	BreakTimerSettingsBreakManager* _tmp0_;
	GList* _tmp1_;
	gboolean result;
	self = (BreakTimerSettingsPanelsStatusPanel*) base;
	_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_;
			{
				BreakTimerSettingsBreakBreakStatusWidget* status_widget = NULL;
				BreakTimerSettingsBreakBreakType* _tmp3_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp4_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp5_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp6_;
				GtkBox* _tmp7_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp8_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp9_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp10_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp11_;
				BreakTimerSettingsBreakBreakStatusWidget* _tmp12_;
				_tmp3_ = break_type;
				_tmp4_ = break_timer_settings_break_break_type_get_status_widget (_tmp3_);
				_tmp5_ = _tmp4_;
				_tmp6_ = _g_object_ref0 (_tmp5_);
				status_widget = _tmp6_;
				_tmp7_ = self->priv->breaks_list;
				_tmp8_ = status_widget;
				gtk_box_append (_tmp7_, (GtkWidget*) _tmp8_);
				_tmp9_ = status_widget;
				gtk_widget_set_margin_top ((GtkWidget*) _tmp9_, 18);
				_tmp10_ = status_widget;
				gtk_widget_set_margin_end ((GtkWidget*) _tmp10_, 20);
				_tmp11_ = status_widget;
				gtk_widget_set_margin_bottom ((GtkWidget*) _tmp11_, 18);
				_tmp12_ = status_widget;
				gtk_widget_set_margin_start ((GtkWidget*) _tmp12_, 20);
				_g_object_unref0 (status_widget);
				_g_object_unref0 (break_type);
			}
		}
	}
	result = TRUE;
	return result;
}

static GtkBox*
break_timer_settings_panels_status_panel_build_breaks_list (BreakTimerSettingsPanelsStatusPanel* self,
                                                            BreakTimerSettingsBreakManager* break_manager)
{
	GtkBox* breaks_list = NULL;
	GtkBox* _tmp0_;
	GtkBox* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (break_manager != NULL, NULL);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp0_);
	breaks_list = _tmp0_;
	gtk_widget_set_halign ((GtkWidget*) breaks_list, GTK_ALIGN_CENTER);
	gtk_widget_set_valign ((GtkWidget*) breaks_list, GTK_ALIGN_CENTER);
	result = breaks_list;
	return result;
}

static BreakTimerCommonBreakStatus*
_break_timer_common_break_status_dup (BreakTimerCommonBreakStatus* self)
{
	BreakTimerCommonBreakStatus* dup;
	dup = g_new0 (BreakTimerCommonBreakStatus, 1);
	memcpy (dup, self, sizeof (BreakTimerCommonBreakStatus));
	return dup;
}

static gpointer
__break_timer_common_break_status_dup0 (gpointer self)
{
	return self ? _break_timer_common_break_status_dup (self) : NULL;
}

static void
break_timer_settings_panels_status_panel_status_changed_cb (BreakTimerSettingsPanelsStatusPanel* self)
{
	gboolean any_breaks_enabled = FALSE;
	GList* all_breaks = NULL;
	BreakTimerSettingsBreakManager* _tmp0_;
	GList* _tmp1_;
	GList* _tmp2_;
	g_return_if_fail (self != NULL);
	any_breaks_enabled = FALSE;
	_tmp0_ = self->priv->break_manager;
	_tmp1_ = break_timer_settings_break_manager_all_breaks (_tmp0_);
	all_breaks = _tmp1_;
	_tmp2_ = all_breaks;
	{
		GList* break_type_collection = NULL;
		GList* break_type_it = NULL;
		break_type_collection = _tmp2_;
		for (break_type_it = break_type_collection; break_type_it != NULL; break_type_it = break_type_it->next) {
			BreakTimerSettingsBreakBreakType* _tmp3_;
			BreakTimerSettingsBreakBreakType* break_type = NULL;
			_tmp3_ = _g_object_ref0 ((BreakTimerSettingsBreakBreakType*) break_type_it->data);
			break_type = _tmp3_;
			{
				BreakTimerCommonBreakStatus* status = NULL;
				BreakTimerSettingsBreakBreakType* _tmp4_;
				BreakTimerCommonBreakStatus* _tmp5_;
				BreakTimerCommonBreakStatus* _tmp6_;
				BreakTimerCommonBreakStatus* _tmp7_;
				BreakTimerCommonBreakStatus* _tmp8_;
				_tmp4_ = break_type;
				_tmp5_ = break_timer_settings_break_break_type_get_status (_tmp4_);
				_tmp6_ = _tmp5_;
				_tmp7_ = __break_timer_common_break_status_dup0 (_tmp6_);
				status = _tmp7_;
				_tmp8_ = status;
				if (_tmp8_ != NULL) {
					BreakTimerCommonBreakStatus* _tmp9_;
					_tmp9_ = status;
					if ((*_tmp9_).is_enabled) {
						BreakTimerSettingsBreakBreakType* _tmp10_;
						BreakTimerSettingsBreakBreakStatusWidget* _tmp11_;
						BreakTimerSettingsBreakBreakStatusWidget* _tmp12_;
						_tmp10_ = break_type;
						_tmp11_ = break_timer_settings_break_break_type_get_status_widget (_tmp10_);
						_tmp12_ = _tmp11_;
						gtk_widget_show ((GtkWidget*) _tmp12_);
						any_breaks_enabled = TRUE;
					} else {
						BreakTimerSettingsBreakBreakType* _tmp13_;
						BreakTimerSettingsBreakBreakStatusWidget* _tmp14_;
						BreakTimerSettingsBreakBreakStatusWidget* _tmp15_;
						_tmp13_ = break_type;
						_tmp14_ = break_timer_settings_break_break_type_get_status_widget (_tmp13_);
						_tmp15_ = _tmp14_;
						gtk_widget_hide ((GtkWidget*) _tmp15_);
					}
				}
				_g_free0 (status);
				_g_object_unref0 (break_type);
			}
		}
	}
	if (any_breaks_enabled) {
		GtkStack* _tmp16_;
		GtkBox* _tmp17_;
		_tmp16_ = self->priv->stack;
		_tmp17_ = self->priv->breaks_list;
		gtk_stack_set_visible_child (_tmp16_, (GtkWidget*) _tmp17_);
	} else {
		BreakTimerSettingsBreakManager* _tmp18_;
		_tmp18_ = self->priv->break_manager;
		if (break_timer_settings_break_manager_is_working (_tmp18_)) {
			GtkStack* _tmp19_;
			GtkWidget* _tmp20_;
			_tmp19_ = self->priv->stack;
			_tmp20_ = self->priv->no_breaks_message;
			gtk_stack_set_visible_child (_tmp19_, _tmp20_);
		} else {
			GtkStack* _tmp21_;
			GtkWidget* _tmp22_;
			_tmp21_ = self->priv->stack;
			_tmp22_ = self->priv->error_message;
			gtk_stack_set_visible_child (_tmp21_, _tmp22_);
		}
	}
}

static void
break_timer_settings_panels_status_panel_class_init (BreakTimerSettingsPanelsStatusPanelClass * klass,
                                                     gpointer klass_data)
{
	break_timer_settings_panels_status_panel_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BreakTimerSettingsPanelsStatusPanel_private_offset);
	G_OBJECT_CLASS (klass)->finalize = break_timer_settings_panels_status_panel_finalize;
}

static void
break_timer_settings_panels_status_panel_g_initable_interface_init (GInitableIface * iface,
                                                                    gpointer iface_data)
{
	break_timer_settings_panels_status_panel_g_initable_parent_iface = g_type_interface_peek_parent (iface);
	iface->init = (gboolean (*) (GInitable*, GCancellable*, GError**)) break_timer_settings_panels_status_panel_real_init;
}

static void
break_timer_settings_panels_status_panel_instance_init (BreakTimerSettingsPanelsStatusPanel * self,
                                                        gpointer klass)
{
	self->priv = break_timer_settings_panels_status_panel_get_instance_private (self);
}

static void
break_timer_settings_panels_status_panel_finalize (GObject * obj)
{
	BreakTimerSettingsPanelsStatusPanel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BREAK_TIMER_SETTINGS_PANELS_TYPE_STATUS_PANEL, BreakTimerSettingsPanelsStatusPanel);
	_g_object_unref0 (self->priv->break_manager);
	_g_object_unref0 (self->priv->stack);
	_g_object_unref0 (self->priv->breaks_list);
	_g_object_unref0 (self->priv->no_breaks_message);
	_g_object_unref0 (self->priv->error_message);
	G_OBJECT_CLASS (break_timer_settings_panels_status_panel_parent_class)->finalize (obj);
}

static GType
break_timer_settings_panels_status_panel_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BreakTimerSettingsPanelsStatusPanelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) break_timer_settings_panels_status_panel_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BreakTimerSettingsPanelsStatusPanel), 0, (GInstanceInitFunc) break_timer_settings_panels_status_panel_instance_init, NULL };
	static const GInterfaceInfo g_initable_info = { (GInterfaceInitFunc) break_timer_settings_panels_status_panel_g_initable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType break_timer_settings_panels_status_panel_type_id;
	break_timer_settings_panels_status_panel_type_id = g_type_register_static (gtk_box_get_type (), "BreakTimerSettingsPanelsStatusPanel", &g_define_type_info, 0);
	g_type_add_interface_static (break_timer_settings_panels_status_panel_type_id, g_initable_get_type (), &g_initable_info);
	BreakTimerSettingsPanelsStatusPanel_private_offset = g_type_add_instance_private (break_timer_settings_panels_status_panel_type_id, sizeof (BreakTimerSettingsPanelsStatusPanelPrivate));
	return break_timer_settings_panels_status_panel_type_id;
}

GType
break_timer_settings_panels_status_panel_get_type (void)
{
	static volatile gsize break_timer_settings_panels_status_panel_type_id__once = 0;
	if (g_once_init_enter (&break_timer_settings_panels_status_panel_type_id__once)) {
		GType break_timer_settings_panels_status_panel_type_id;
		break_timer_settings_panels_status_panel_type_id = break_timer_settings_panels_status_panel_get_type_once ();
		g_once_init_leave (&break_timer_settings_panels_status_panel_type_id__once, break_timer_settings_panels_status_panel_type_id);
	}
	return break_timer_settings_panels_status_panel_type_id__once;
}

