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

/* TimerBreakStatusWidget.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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include "common.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

enum  {
	BREAK_TIMER_SETTINGS_TIMER_BREAK_TIMER_BREAK_STATUS_WIDGET_0_PROPERTY,
	BREAK_TIMER_SETTINGS_TIMER_BREAK_TIMER_BREAK_STATUS_WIDGET_NUM_PROPERTIES
};
static GParamSpec* break_timer_settings_timer_break_timer_break_status_widget_properties[BREAK_TIMER_SETTINGS_TIMER_BREAK_TIMER_BREAK_STATUS_WIDGET_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BreakTimerSettingsTimerBreakTimerBreakStatusWidgetPrivate {
	gchar* upcoming_text;
	gchar* ongoing_text;
	BreakTimerSettingsWidgetsCircleCounter* circle_counter;
	GtkLabel* status_label;
	GtkLabel* time_label;
};

static gint BreakTimerSettingsTimerBreakTimerBreakStatusWidget_private_offset;
static gpointer break_timer_settings_timer_break_timer_break_status_widget_parent_class = NULL;

static void break_timer_settings_timer_break_timer_break_status_widget_timer_status_changed_cb (BreakTimerSettingsTimerBreakTimerBreakStatusWidget* self,
                                                                                         BreakTimerCommonTimerBreakStatus* status);
static void _break_timer_settings_timer_break_timer_break_status_widget_timer_status_changed_cb_break_timer_settings_timer_break_timer_break_type_timer_status_changed (BreakTimerSettingsTimerBreakTimerBreakType* _sender,
                                                                                                                                                                 BreakTimerCommonTimerBreakStatus* status,
                                                                                                                                                                 gpointer self);
static void break_timer_settings_timer_break_timer_break_status_widget_finalize (GObject * obj);
static GType break_timer_settings_timer_break_timer_break_status_widget_get_type_once (void);

static inline gpointer
break_timer_settings_timer_break_timer_break_status_widget_get_instance_private (BreakTimerSettingsTimerBreakTimerBreakStatusWidget* self)
{
	return G_STRUCT_MEMBER_P (self, BreakTimerSettingsTimerBreakTimerBreakStatusWidget_private_offset);
}

static void
_break_timer_settings_timer_break_timer_break_status_widget_timer_status_changed_cb_break_timer_settings_timer_break_timer_break_type_timer_status_changed (BreakTimerSettingsTimerBreakTimerBreakType* _sender,
                                                                                                                                                            BreakTimerCommonTimerBreakStatus* status,
                                                                                                                                                            gpointer self)
{
	break_timer_settings_timer_break_timer_break_status_widget_timer_status_changed_cb ((BreakTimerSettingsTimerBreakTimerBreakStatusWidget*) self, status);
}

BreakTimerSettingsTimerBreakTimerBreakStatusWidget*
break_timer_settings_timer_break_timer_break_status_widget_construct (GType object_type,
                                                                      BreakTimerSettingsTimerBreakTimerBreakType* break_type,
                                                                      const gchar* upcoming_text,
                                                                      const gchar* ongoing_text)
{
	BreakTimerSettingsTimerBreakTimerBreakStatusWidget * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	BreakTimerSettingsWidgetsCircleCounter* _tmp2_;
	BreakTimerSettingsWidgetsCircleCounter* _tmp3_;
	GtkBox* labels_box = NULL;
	GtkBox* _tmp4_;
	GtkLabel* _tmp5_;
	GtkLabel* _tmp6_;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	GtkLabel* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* _tmp11_;
	g_return_val_if_fail (break_type != NULL, NULL);
	g_return_val_if_fail (upcoming_text != NULL, NULL);
	g_return_val_if_fail (ongoing_text != NULL, NULL);
	self = (BreakTimerSettingsTimerBreakTimerBreakStatusWidget*) break_timer_settings_break_break_status_widget_construct (object_type, (BreakTimerSettingsBreakBreakType*) break_type);
	_tmp0_ = g_strdup (upcoming_text);
	_g_free0 (self->priv->upcoming_text);
	self->priv->upcoming_text = _tmp0_;
	_tmp1_ = g_strdup (ongoing_text);
	_g_free0 (self->priv->ongoing_text);
	self->priv->ongoing_text = _tmp1_;
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_HORIZONTAL);
	gtk_box_set_spacing ((GtkBox*) self, 12);
	_tmp2_ = break_timer_settings_widgets_circle_counter_new ();
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->circle_counter);
	self->priv->circle_counter = _tmp2_;
	_tmp3_ = self->priv->circle_counter;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp3_);
	_tmp4_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
	g_object_ref_sink (_tmp4_);
	labels_box = _tmp4_;
	gtk_widget_set_valign ((GtkWidget*) labels_box, GTK_ALIGN_CENTER);
	gtk_box_append ((GtkBox*) self, (GtkWidget*) labels_box);
	_tmp5_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->status_label);
	self->priv->status_label = _tmp5_;
	_tmp6_ = self->priv->status_label;
	gtk_box_append (labels_box, (GtkWidget*) _tmp6_);
	_tmp7_ = self->priv->status_label;
	gtk_label_set_width_chars (_tmp7_, 25);
	_tmp8_ = self->priv->status_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, "heading");
	_tmp9_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (self->priv->time_label);
	self->priv->time_label = _tmp9_;
	_tmp10_ = self->priv->time_label;
	gtk_box_append (labels_box, (GtkWidget*) _tmp10_);
	_tmp11_ = self->priv->time_label;
	gtk_label_set_width_chars (_tmp11_, 25);
	g_signal_connect_object (break_type, "timer-status-changed", (GCallback) _break_timer_settings_timer_break_timer_break_status_widget_timer_status_changed_cb_break_timer_settings_timer_break_timer_break_type_timer_status_changed, self, 0);
	_g_object_unref0 (labels_box);
	return self;
}

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

static void
break_timer_settings_timer_break_timer_break_status_widget_timer_status_changed_cb (BreakTimerSettingsTimerBreakTimerBreakStatusWidget* self,
                                                                                    BreakTimerCommonTimerBreakStatus* status)
{
	BreakTimerSettingsTimerBreakTimerBreakType* timer_break = NULL;
	BreakTimerSettingsBreakBreakType* _tmp0_;
	BreakTimerSettingsBreakBreakType* _tmp1_;
	BreakTimerSettingsTimerBreakTimerBreakType* _tmp2_;
	g_return_if_fail (self != NULL);
	if (status == NULL) {
		return;
	}
	_tmp0_ = break_timer_settings_break_break_status_widget_get_break_type ((BreakTimerSettingsBreakBreakStatusWidget*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BREAK_TIMER_SETTINGS_TIMER_BREAK_TYPE_TIMER_BREAK_TYPE, BreakTimerSettingsTimerBreakTimerBreakType));
	timer_break = _tmp2_;
	if ((*status).is_active) {
		GtkLabel* _tmp3_;
		const gchar* _tmp4_;
		gchar* time_text = NULL;
		BreakTimerCommonNaturalTime* _tmp5_;
		BreakTimerCommonNaturalTime* _tmp6_;
		gchar* _tmp7_;
		GtkLabel* _tmp8_;
		const gchar* _tmp9_;
		BreakTimerSettingsWidgetsCircleCounter* _tmp10_;
		BreakTimerSettingsWidgetsCircleCounter* _tmp11_;
		_tmp3_ = self->priv->status_label;
		_tmp4_ = self->priv->ongoing_text;
		gtk_label_set_label (_tmp3_, _tmp4_);
		_tmp5_ = break_timer_common_natural_time_get_instance ();
		_tmp6_ = _tmp5_;
		_tmp7_ = break_timer_common_natural_time_get_countdown_for_seconds_with_start (_tmp6_, (*status).time_remaining, (*status).current_duration, NULL);
		time_text = _tmp7_;
		_tmp8_ = self->priv->time_label;
		_tmp9_ = time_text;
		gtk_label_set_label (_tmp8_, _tmp9_);
		_tmp10_ = self->priv->circle_counter;
		break_timer_settings_widgets_circle_counter_set_direction (_tmp10_, BREAK_TIMER_SETTINGS_WIDGETS_CIRCLE_COUNTER_DIRECTION_COUNT_DOWN);
		_tmp11_ = self->priv->circle_counter;
		break_timer_settings_widgets_circle_counter_set_progress (_tmp11_, ((*status).current_duration - (*status).time_remaining) / ((gdouble) (*status).current_duration));
		_g_free0 (time_text);
	} else {
		GtkLabel* _tmp12_;
		const gchar* _tmp13_;
		gchar* time_text = NULL;
		BreakTimerCommonNaturalTime* _tmp14_;
		BreakTimerCommonNaturalTime* _tmp15_;
		gchar* _tmp16_;
		GtkLabel* _tmp17_;
		const gchar* _tmp18_;
		BreakTimerSettingsWidgetsCircleCounter* _tmp19_;
		BreakTimerSettingsWidgetsCircleCounter* _tmp20_;
		BreakTimerSettingsTimerBreakTimerBreakType* _tmp21_;
		gint _tmp22_;
		gint _tmp23_;
		BreakTimerSettingsTimerBreakTimerBreakType* _tmp24_;
		gint _tmp25_;
		gint _tmp26_;
		_tmp12_ = self->priv->status_label;
		_tmp13_ = self->priv->upcoming_text;
		gtk_label_set_label (_tmp12_, _tmp13_);
		_tmp14_ = break_timer_common_natural_time_get_instance ();
		_tmp15_ = _tmp14_;
		_tmp16_ = break_timer_common_natural_time_get_countdown_for_seconds (_tmp15_, (*status).starts_in, NULL);
		time_text = _tmp16_;
		_tmp17_ = self->priv->time_label;
		_tmp18_ = time_text;
		gtk_label_set_label (_tmp17_, _tmp18_);
		_tmp19_ = self->priv->circle_counter;
		break_timer_settings_widgets_circle_counter_set_direction (_tmp19_, BREAK_TIMER_SETTINGS_WIDGETS_CIRCLE_COUNTER_DIRECTION_COUNT_UP);
		_tmp20_ = self->priv->circle_counter;
		_tmp21_ = timer_break;
		_tmp22_ = break_timer_settings_timer_break_timer_break_type_get_interval (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp24_ = timer_break;
		_tmp25_ = break_timer_settings_timer_break_timer_break_type_get_interval (_tmp24_);
		_tmp26_ = _tmp25_;
		break_timer_settings_widgets_circle_counter_set_progress (_tmp20_, (_tmp23_ - (*status).starts_in) / ((gdouble) _tmp26_));
		_g_free0 (time_text);
	}
	_g_object_unref0 (timer_break);
}

static void
break_timer_settings_timer_break_timer_break_status_widget_class_init (BreakTimerSettingsTimerBreakTimerBreakStatusWidgetClass * klass,
                                                                       gpointer klass_data)
{
	break_timer_settings_timer_break_timer_break_status_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BreakTimerSettingsTimerBreakTimerBreakStatusWidget_private_offset);
	G_OBJECT_CLASS (klass)->finalize = break_timer_settings_timer_break_timer_break_status_widget_finalize;
}

static void
break_timer_settings_timer_break_timer_break_status_widget_instance_init (BreakTimerSettingsTimerBreakTimerBreakStatusWidget * self,
                                                                          gpointer klass)
{
	self->priv = break_timer_settings_timer_break_timer_break_status_widget_get_instance_private (self);
}

static void
break_timer_settings_timer_break_timer_break_status_widget_finalize (GObject * obj)
{
	BreakTimerSettingsTimerBreakTimerBreakStatusWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BREAK_TIMER_SETTINGS_TIMER_BREAK_TYPE_TIMER_BREAK_STATUS_WIDGET, BreakTimerSettingsTimerBreakTimerBreakStatusWidget);
	_g_free0 (self->priv->upcoming_text);
	_g_free0 (self->priv->ongoing_text);
	_g_object_unref0 (self->priv->circle_counter);
	_g_object_unref0 (self->priv->status_label);
	_g_object_unref0 (self->priv->time_label);
	G_OBJECT_CLASS (break_timer_settings_timer_break_timer_break_status_widget_parent_class)->finalize (obj);
}

static GType
break_timer_settings_timer_break_timer_break_status_widget_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BreakTimerSettingsTimerBreakTimerBreakStatusWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) break_timer_settings_timer_break_timer_break_status_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BreakTimerSettingsTimerBreakTimerBreakStatusWidget), 0, (GInstanceInitFunc) break_timer_settings_timer_break_timer_break_status_widget_instance_init, NULL };
	GType break_timer_settings_timer_break_timer_break_status_widget_type_id;
	break_timer_settings_timer_break_timer_break_status_widget_type_id = g_type_register_static (BREAK_TIMER_SETTINGS_BREAK_TYPE_BREAK_STATUS_WIDGET, "BreakTimerSettingsTimerBreakTimerBreakStatusWidget", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	BreakTimerSettingsTimerBreakTimerBreakStatusWidget_private_offset = g_type_add_instance_private (break_timer_settings_timer_break_timer_break_status_widget_type_id, sizeof (BreakTimerSettingsTimerBreakTimerBreakStatusWidgetPrivate));
	return break_timer_settings_timer_break_timer_break_status_widget_type_id;
}

GType
break_timer_settings_timer_break_timer_break_status_widget_get_type (void)
{
	static volatile gsize break_timer_settings_timer_break_timer_break_status_widget_type_id__once = 0;
	if (g_once_init_enter (&break_timer_settings_timer_break_timer_break_status_widget_type_id__once)) {
		GType break_timer_settings_timer_break_timer_break_status_widget_type_id;
		break_timer_settings_timer_break_timer_break_status_widget_type_id = break_timer_settings_timer_break_timer_break_status_widget_get_type_once ();
		g_once_init_leave (&break_timer_settings_timer_break_timer_break_status_widget_type_id__once, break_timer_settings_timer_break_timer_break_status_widget_type_id);
	}
	return break_timer_settings_timer_break_timer_break_status_widget_type_id__once;
}

