/* preferences-panel-timer.c generated by valac 0.56.19, the Vala compiler
 * generated from preferences-panel-timer.vala, do not modify */

/*
 * Copyright (c) 2023-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_ui.h"
#include <adwaita.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib.h>
#include "ft_core.h"
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>

#define FT_PREFERENCES_PANEL_TIMER_MIN_TOAST_TIMEOUT ((guint) 3)
#define FT_PREFERENCES_PANEL_TIMER_MAX_TOAST_TIMEOUT ((guint) 30)
#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  {
	FT_PREFERENCES_PANEL_TIMER_0_PROPERTY,
	FT_PREFERENCES_PANEL_TIMER_NUM_PROPERTIES
};
static GParamSpec* ft_preferences_panel_timer_properties[FT_PREFERENCES_PANEL_TIMER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _FtPreferencesPanelTimerPrivate {
	AdwPreferencesPage* page;
	FtLogScaleRow* long_break_duration_row;
	GtkAdjustment* pomodoro_duration_adjustment;
	GtkAdjustment* short_break_duration_adjustment;
	GtkAdjustment* long_break_duration_adjustment;
	GtkAdjustment* cycles_adjustment;
	GtkLabel* session_stats_label;
	GtkLabel* breaks_stats_label;
	AdwSwitchRow* pause_on_lockscreen_switchrow;
	AdwSwitchRow* confirm_starting_break_switchrow;
	AdwSwitchRow* confirm_starting_pomodoro_switchrow;
	GSettings* settings;
	gulong settings_changed_id;
	FtTimer* timer;
	gulong timer_state_changed_id;
	FtIdleMonitor* idle_monitor;
	AdwToast* apply_changes_toast;
};

static gint FtPreferencesPanelTimer_private_offset;
static gpointer ft_preferences_panel_timer_parent_class = NULL;

static void ft_preferences_panel_timer_update_long_break_row_sensitivity (FtPreferencesPanelTimer* self);
static void ft_preferences_panel_timer_update_stats_labels (FtPreferencesPanelTimer* self);
static void ft_preferences_panel_timer_apply_changes (FtPreferencesPanelTimer* self);
static guint ft_preferences_panel_timer_calculate_apply_changes_toast_timeout (FtPreferencesPanelTimer* self,
                                                                        FtState changed_state);
static void ft_preferences_panel_timer_show_apply_changes_toast (FtPreferencesPanelTimer* self,
                                                          FtState changed_state,
                                                          guint timeout);
static void ___lambda86_ (FtPreferencesPanelTimer* self);
static void ____lambda86__adw_toast_button_clicked (AdwToast* _sender,
                                             gpointer self);
static void ___lambda87_ (FtPreferencesPanelTimer* self);
static void ____lambda87__adw_toast_dismissed (AdwToast* _sender,
                                        gpointer self);
static void ft_preferences_panel_timer_hide_apply_changes_toast (FtPreferencesPanelTimer* self);
static void ft_preferences_panel_timer_on_timer_state_changed (FtPreferencesPanelTimer* self,
                                                        const FtTimerState* current_state,
                                                        const FtTimerState* previous_state);
static void ft_preferences_panel_timer_on_settings_changed (FtPreferencesPanelTimer* self,
                                                     GSettings* settings,
                                                     const gchar* key);
static void ft_preferences_panel_timer_on_pomodoro_duration_changed (FtPreferencesPanelTimer* self);
static void _ft_preferences_panel_timer_on_pomodoro_duration_changed_ft_log_scale_row_value_changed (FtLogScaleRow* _sender,
                                                                                              gpointer self);
static void ft_preferences_panel_timer_on_short_break_duration_changed (FtPreferencesPanelTimer* self);
static void _ft_preferences_panel_timer_on_short_break_duration_changed_ft_log_scale_row_value_changed (FtLogScaleRow* _sender,
                                                                                                 gpointer self);
static void ft_preferences_panel_timer_on_long_break_duration_changed (FtPreferencesPanelTimer* self);
static void _ft_preferences_panel_timer_on_long_break_duration_changed_ft_log_scale_row_value_changed (FtLogScaleRow* _sender,
                                                                                                gpointer self);
static AdwPreferencesPage* ft_preferences_panel_timer_real_get_preferences_page (FtPreferencesPanel* base);
static void ft_preferences_panel_timer_real_dispose (GObject* base);
static GObject * ft_preferences_panel_timer_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void _ft_preferences_panel_timer_update_stats_labels_gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                                   gpointer self);
static void _ft_preferences_panel_timer_update_long_break_row_sensitivity_gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                                                 gpointer self);
static void _ft_preferences_panel_timer_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                         const gchar* key,
                                                                         gpointer self);
static void _ft_preferences_panel_timer_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                                const FtTimerState* current_state,
                                                                                const FtTimerState* previous_state,
                                                                                gpointer self);
static void ft_preferences_panel_timer_finalize (GObject * obj);
static GType ft_preferences_panel_timer_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_preferences_panel_timer_get_instance_private (FtPreferencesPanelTimer* self)
{
	return G_STRUCT_MEMBER_P (self, FtPreferencesPanelTimer_private_offset);
}

static void
ft_preferences_panel_timer_update_long_break_row_sensitivity (FtPreferencesPanelTimer* self)
{
	FtLogScaleRow* _tmp0_;
	GtkAdjustment* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->long_break_duration_row;
	_tmp1_ = self->priv->cycles_adjustment;
	_tmp2_ = gtk_adjustment_get_value (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, _tmp3_ > 1.0);
}

static void
ft_preferences_panel_timer_update_stats_labels (FtPreferencesPanelTimer* self)
{
	FtSessionTemplate session_template = {0};
	GtkAdjustment* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	GtkAdjustment* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	GtkAdjustment* _tmp6_;
	gdouble _tmp7_;
	gdouble _tmp8_;
	GtkAdjustment* _tmp9_;
	gdouble _tmp10_;
	gdouble _tmp11_;
	guint total_duration = 0U;
	guint break_percentage = 0U;
	GtkLabel* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	GtkLabel* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	g_return_if_fail (self != NULL);
	memset (&session_template, 0, sizeof (FtSessionTemplate));
	_tmp0_ = self->priv->pomodoro_duration_adjustment;
	_tmp1_ = gtk_adjustment_get_value (_tmp0_);
	_tmp2_ = _tmp1_;
	session_template.pomodoro_duration = ft_timestamp_from_seconds_uint ((guint) round (_tmp2_));
	_tmp3_ = self->priv->short_break_duration_adjustment;
	_tmp4_ = gtk_adjustment_get_value (_tmp3_);
	_tmp5_ = _tmp4_;
	session_template.short_break_duration = ft_timestamp_from_seconds_uint ((guint) round (_tmp5_));
	_tmp6_ = self->priv->long_break_duration_adjustment;
	_tmp7_ = gtk_adjustment_get_value (_tmp6_);
	_tmp8_ = _tmp7_;
	session_template.long_break_duration = ft_timestamp_from_seconds_uint ((guint) round (_tmp8_));
	_tmp9_ = self->priv->cycles_adjustment;
	_tmp10_ = gtk_adjustment_get_value (_tmp9_);
	_tmp11_ = _tmp10_;
	session_template.cycles = (guint) round (_tmp11_);
	total_duration = ft_timestamp_to_seconds_uint (ft_session_template_calculate_total_duration (&session_template));
	break_percentage = (guint) round (ft_session_template_calculate_break_percentage (&session_template));
	_tmp12_ = self->priv->session_stats_label;
	_tmp13_ = ft_format_time (total_duration);
	_tmp14_ = _tmp13_;
	_tmp15_ = g_strdup_printf (_ ("A single session will take <b>%s</b>."), _tmp14_);
	_tmp16_ = _tmp15_;
	gtk_label_set_label (_tmp12_, _tmp16_);
	_g_free0 (_tmp16_);
	_g_free0 (_tmp14_);
	_tmp17_ = self->priv->breaks_stats_label;
	_tmp18_ = g_strdup_printf (_ ("<b>%u%%</b> of the time will be allocated for breaks."), break_percentage);
	_tmp19_ = _tmp18_;
	gtk_label_set_label (_tmp17_, _tmp19_);
	_g_free0 (_tmp19_);
}

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

static void
ft_preferences_panel_timer_apply_changes (FtPreferencesPanelTimer* self)
{
	FtTimeBlock* current_time_block = NULL;
	FtTimer* _tmp0_;
	void* _tmp1_;
	void* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtTimeBlock* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timer;
	_tmp1_ = ft_timer_get_user_data (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, FT_TYPE_TIME_BLOCK) ? ((FtTimeBlock*) _tmp2_) : NULL);
	current_time_block = _tmp3_;
	_tmp4_ = current_time_block;
	if (_tmp4_ != NULL) {
		gint64 duration = 0LL;
		FtTimeBlock* _tmp5_;
		FtState _tmp6_;
		FtState _tmp7_;
		FtTimeBlock* _tmp8_;
		FtTimer* _tmp9_;
		_tmp5_ = current_time_block;
		_tmp6_ = ft_time_block_get_state (_tmp5_);
		_tmp7_ = _tmp6_;
		duration = ft_state_get_default_duration (_tmp7_);
		_tmp8_ = current_time_block;
		ft_time_block_set_intended_duration (_tmp8_, duration);
		_tmp9_ = self->priv->timer;
		ft_timer_set_duration (_tmp9_, duration);
	}
	_g_object_unref0 (current_time_block);
}

static guint
ft_preferences_panel_timer_calculate_apply_changes_toast_timeout (FtPreferencesPanelTimer* self,
                                                                  FtState changed_state)
{
	FtTimeBlock* current_time_block = NULL;
	FtTimer* _tmp0_;
	void* _tmp1_;
	void* _tmp2_;
	FtTimeBlock* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	FtTimeBlock* _tmp6_;
	FtTimer* _tmp14_;
	guint timeout = 0U;
	FtTimeBlock* _tmp15_;
	FtState _tmp16_;
	FtState _tmp17_;
	FtTimer* _tmp18_;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->priv->timer;
	_tmp1_ = ft_timer_get_user_data (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, FT_TYPE_TIME_BLOCK) ? ((FtTimeBlock*) _tmp2_) : NULL);
	current_time_block = _tmp3_;
	_tmp6_ = current_time_block;
	if (_tmp6_ == NULL) {
		_tmp5_ = TRUE;
	} else {
		FtTimeBlock* _tmp7_;
		FtState _tmp8_;
		FtState _tmp9_;
		_tmp7_ = current_time_block;
		_tmp8_ = ft_time_block_get_state (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp5_ = _tmp9_ != changed_state;
	}
	if (_tmp5_) {
		_tmp4_ = TRUE;
	} else {
		FtTimeBlock* _tmp10_;
		FtTimeBlock* _tmp11_;
		FtState _tmp12_;
		FtState _tmp13_;
		_tmp10_ = current_time_block;
		_tmp11_ = current_time_block;
		_tmp12_ = ft_time_block_get_state (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp4_ = ft_time_block_get_intended_duration (_tmp10_) == ft_state_get_default_duration (_tmp13_);
	}
	if (_tmp4_) {
		result = 0U;
		_g_object_unref0 (current_time_block);
		return result;
	}
	_tmp14_ = self->priv->timer;
	if (ft_timer_is_paused (_tmp14_)) {
		result = FT_PREFERENCES_PANEL_TIMER_MAX_TOAST_TIMEOUT;
		_g_object_unref0 (current_time_block);
		return result;
	}
	_tmp15_ = current_time_block;
	_tmp16_ = ft_time_block_get_state (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = self->priv->timer;
	timeout = ft_timestamp_to_seconds_uint (ft_state_get_default_duration (_tmp17_) - ft_timer_calculate_elapsed (_tmp18_, FT_TIMESTAMP_UNDEFINED));
	result = MIN (timeout, FT_PREFERENCES_PANEL_TIMER_MAX_TOAST_TIMEOUT);
	_g_object_unref0 (current_time_block);
	return result;
}

static void
___lambda86_ (FtPreferencesPanelTimer* self)
{
	_g_object_unref0 (self->priv->apply_changes_toast);
	self->priv->apply_changes_toast = NULL;
	ft_preferences_panel_timer_apply_changes (self);
}

static void
____lambda86__adw_toast_button_clicked (AdwToast* _sender,
                                        gpointer self)
{
	___lambda86_ ((FtPreferencesPanelTimer*) self);
}

static void
___lambda87_ (FtPreferencesPanelTimer* self)
{
	_g_object_unref0 (self->priv->apply_changes_toast);
	self->priv->apply_changes_toast = NULL;
}

static void
____lambda87__adw_toast_dismissed (AdwToast* _sender,
                                   gpointer self)
{
	___lambda87_ ((FtPreferencesPanelTimer*) self);
}

static void
ft_preferences_panel_timer_show_apply_changes_toast (FtPreferencesPanelTimer* self,
                                                     FtState changed_state,
                                                     guint timeout)
{
	FtPreferencesWindow* window = NULL;
	GtkRoot* _tmp0_;
	FtPreferencesWindow* _tmp1_;
	AdwToast* toast = NULL;
	AdwToast* _tmp2_;
	AdwToast* _tmp3_;
	AdwToast* _tmp4_;
	AdwToast* _tmp13_;
	FtPreferencesWindow* _tmp14_ = NULL;
	FtPreferencesWindow* _tmp15_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_root ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (FT_IS_PREFERENCES_WINDOW (_tmp0_) ? ((FtPreferencesWindow*) _tmp0_) : NULL);
	window = _tmp1_;
	_tmp2_ = self->priv->apply_changes_toast;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	toast = _tmp3_;
	_tmp4_ = toast;
	if (_tmp4_ == NULL) {
		const gchar* _tmp5_ = NULL;
		AdwToast* _tmp6_;
		AdwToast* _tmp7_;
		AdwToast* _tmp8_;
		AdwToast* _tmp9_;
		AdwToast* _tmp10_;
		AdwToast* _tmp11_;
		AdwToast* _tmp12_;
		if (changed_state == FT_STATE_POMODORO) {
			_tmp5_ = _ ("Apply changes to ongoing Pomodoro?");
		} else {
			_tmp5_ = _ ("Apply changes to ongoing break?");
		}
		_tmp6_ = adw_toast_new (_tmp5_);
		_g_object_unref0 (toast);
		toast = _tmp6_;
		_tmp7_ = toast;
		adw_toast_set_use_markup (_tmp7_, FALSE);
		_tmp8_ = toast;
		adw_toast_set_button_label (_tmp8_, _ ("Apply"));
		_tmp9_ = toast;
		g_signal_connect_object (_tmp9_, "button-clicked", (GCallback) ____lambda86__adw_toast_button_clicked, self, 0);
		_tmp10_ = toast;
		g_signal_connect_object (_tmp10_, "dismissed", (GCallback) ____lambda87__adw_toast_dismissed, self, 0);
		_tmp11_ = toast;
		_tmp12_ = _g_object_ref0 (_tmp11_);
		_g_object_unref0 (self->priv->apply_changes_toast);
		self->priv->apply_changes_toast = _tmp12_;
	}
	_tmp13_ = toast;
	adw_toast_set_timeout (_tmp13_, timeout);
	_tmp15_ = window;
	_tmp14_ = _tmp15_;
	if (_tmp14_ != NULL) {
		AdwToast* _tmp16_;
		AdwToast* _tmp17_;
		_tmp16_ = toast;
		_tmp17_ = _g_object_ref0 (_tmp16_);
		ft_preferences_window_add_toast (_tmp14_, _tmp17_);
	}
	_g_object_unref0 (toast);
	_g_object_unref0 (window);
}

static void
ft_preferences_panel_timer_hide_apply_changes_toast (FtPreferencesPanelTimer* self)
{
	AdwToast* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->apply_changes_toast;
	if (_tmp0_ != NULL) {
		AdwToast* _tmp1_;
		_tmp1_ = self->priv->apply_changes_toast;
		adw_toast_dismiss (_tmp1_);
	}
}

static void
ft_preferences_panel_timer_on_timer_state_changed (FtPreferencesPanelTimer* self,
                                                   const FtTimerState* current_state,
                                                   const FtTimerState* previous_state)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	ft_preferences_panel_timer_hide_apply_changes_toast (self);
}

static void
ft_preferences_panel_timer_on_settings_changed (FtPreferencesPanelTimer* self,
                                                GSettings* settings,
                                                const gchar* key)
{
	FtState changed_state = 0;
	FtSessionManager* session_manager = NULL;
	FtSessionManager* _tmp0_;
	FtSessionManager* _tmp1_;
	const gchar* _tmp2_;
	GQuark _tmp4_ = 0U;
	static GQuark _tmp3_label0 = 0;
	static GQuark _tmp3_label1 = 0;
	static GQuark _tmp3_label2 = 0;
	gboolean _tmp6_ = FALSE;
	FtSessionManager* _tmp7_;
	FtTimeBlock* _tmp8_;
	FtTimeBlock* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (settings != NULL);
	g_return_if_fail (key != NULL);
	changed_state = FT_STATE_STOPPED;
	_tmp0_ = ft_session_manager_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	session_manager = _tmp1_;
	_tmp2_ = key;
	_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
	if (_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("pomodoro-duration")))) {
		switch (0) {
			default:
			{
				changed_state = FT_STATE_POMODORO;
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("short-break-duration")))) {
		switch (0) {
			default:
			{
				FtState _tmp5_ = 0;
				if (g_settings_get_uint (settings, "cycles") > ((guint) 1)) {
					_tmp5_ = FT_STATE_SHORT_BREAK;
				} else {
					_tmp5_ = FT_STATE_BREAK;
				}
				changed_state = _tmp5_;
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label2) ? _tmp3_label2 : (_tmp3_label2 = g_quark_from_static_string ("long-break-duration")))) {
		switch (0) {
			default:
			{
				changed_state = FT_STATE_LONG_BREAK;
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
	_tmp7_ = session_manager;
	_tmp8_ = ft_session_manager_get_current_time_block (_tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ != NULL) {
		FtSessionManager* _tmp10_;
		FtTimeBlock* _tmp11_;
		FtTimeBlock* _tmp12_;
		FtState _tmp13_;
		FtState _tmp14_;
		_tmp10_ = session_manager;
		_tmp11_ = ft_session_manager_get_current_time_block (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = ft_time_block_get_state (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp6_ = _tmp14_ == changed_state;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		guint apply_changes_toast_timeout = 0U;
		apply_changes_toast_timeout = ft_preferences_panel_timer_calculate_apply_changes_toast_timeout (self, changed_state);
		if (apply_changes_toast_timeout >= FT_PREFERENCES_PANEL_TIMER_MIN_TOAST_TIMEOUT) {
			ft_preferences_panel_timer_show_apply_changes_toast (self, changed_state, apply_changes_toast_timeout);
		} else {
			ft_preferences_panel_timer_hide_apply_changes_toast (self);
		}
	}
	_g_object_unref0 (session_manager);
}

static void
ft_preferences_panel_timer_on_pomodoro_duration_changed (FtPreferencesPanelTimer* self)
{
	GSettings* _tmp0_;
	GtkAdjustment* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = self->priv->pomodoro_duration_adjustment;
	_tmp2_ = gtk_adjustment_get_value (_tmp1_);
	_tmp3_ = _tmp2_;
	g_settings_set_uint (_tmp0_, "pomodoro-duration", (guint) round (_tmp3_));
}

static void
_ft_preferences_panel_timer_on_pomodoro_duration_changed_ft_log_scale_row_value_changed (FtLogScaleRow* _sender,
                                                                                         gpointer self)
{
	ft_preferences_panel_timer_on_pomodoro_duration_changed ((FtPreferencesPanelTimer*) self);
}

static void
ft_preferences_panel_timer_on_short_break_duration_changed (FtPreferencesPanelTimer* self)
{
	GSettings* _tmp0_;
	GtkAdjustment* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = self->priv->short_break_duration_adjustment;
	_tmp2_ = gtk_adjustment_get_value (_tmp1_);
	_tmp3_ = _tmp2_;
	g_settings_set_uint (_tmp0_, "short-break-duration", (guint) round (_tmp3_));
}

static void
_ft_preferences_panel_timer_on_short_break_duration_changed_ft_log_scale_row_value_changed (FtLogScaleRow* _sender,
                                                                                            gpointer self)
{
	ft_preferences_panel_timer_on_short_break_duration_changed ((FtPreferencesPanelTimer*) self);
}

static void
ft_preferences_panel_timer_on_long_break_duration_changed (FtPreferencesPanelTimer* self)
{
	GSettings* _tmp0_;
	GtkAdjustment* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = self->priv->long_break_duration_adjustment;
	_tmp2_ = gtk_adjustment_get_value (_tmp1_);
	_tmp3_ = _tmp2_;
	g_settings_set_uint (_tmp0_, "long-break-duration", (guint) round (_tmp3_));
}

static void
_ft_preferences_panel_timer_on_long_break_duration_changed_ft_log_scale_row_value_changed (FtLogScaleRow* _sender,
                                                                                           gpointer self)
{
	ft_preferences_panel_timer_on_long_break_duration_changed ((FtPreferencesPanelTimer*) self);
}

static AdwPreferencesPage*
ft_preferences_panel_timer_real_get_preferences_page (FtPreferencesPanel* base)
{
	FtPreferencesPanelTimer * self;
	AdwPreferencesPage* _tmp0_;
	AdwPreferencesPage* result;
	self = (FtPreferencesPanelTimer*) base;
	_tmp0_ = self->priv->page;
	result = _tmp0_;
	return result;
}

static void
ft_preferences_panel_timer_real_dispose (GObject* base)
{
	FtPreferencesPanelTimer * self;
	self = (FtPreferencesPanelTimer*) base;
	ft_preferences_panel_timer_hide_apply_changes_toast (self);
	if (self->priv->settings_changed_id != ((gulong) 0)) {
		GSettings* _tmp0_;
		_tmp0_ = self->priv->settings;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->settings_changed_id);
		self->priv->settings_changed_id = (gulong) 0;
	}
	if (self->priv->timer_state_changed_id != ((gulong) 0)) {
		FtTimer* _tmp1_;
		_tmp1_ = self->priv->timer;
		g_signal_handler_disconnect ((GObject*) _tmp1_, self->priv->timer_state_changed_id);
		self->priv->timer_state_changed_id = (gulong) 0;
	}
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = NULL;
	_g_object_unref0 (self->priv->timer);
	self->priv->timer = NULL;
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = NULL;
	G_OBJECT_CLASS (ft_preferences_panel_timer_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PREFERENCES_PANEL, FtPreferencesPanel));
}

FtPreferencesPanelTimer*
ft_preferences_panel_timer_construct (GType object_type)
{
	FtPreferencesPanelTimer * self = NULL;
	self = (FtPreferencesPanelTimer*) ft_preferences_panel_construct (object_type);
	return self;
}

FtPreferencesPanelTimer*
ft_preferences_panel_timer_new (void)
{
	return ft_preferences_panel_timer_construct (FT_TYPE_PREFERENCES_PANEL_TIMER);
}

static void
_ft_preferences_panel_timer_update_stats_labels_gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                              gpointer self)
{
	ft_preferences_panel_timer_update_stats_labels ((FtPreferencesPanelTimer*) self);
}

static void
_ft_preferences_panel_timer_update_long_break_row_sensitivity_gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                                            gpointer self)
{
	ft_preferences_panel_timer_update_long_break_row_sensitivity ((FtPreferencesPanelTimer*) self);
}

static void
_ft_preferences_panel_timer_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                    const gchar* key,
                                                                    gpointer self)
{
	ft_preferences_panel_timer_on_settings_changed ((FtPreferencesPanelTimer*) self, _sender, key);
}

static void
_ft_preferences_panel_timer_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                           const FtTimerState* current_state,
                                                                           const FtTimerState* previous_state,
                                                                           gpointer self)
{
	ft_preferences_panel_timer_on_timer_state_changed ((FtPreferencesPanelTimer*) self, current_state, previous_state);
}

static GObject *
ft_preferences_panel_timer_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtPreferencesPanelTimer * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	GtkAdjustment* _tmp3_;
	GSettings* _tmp4_;
	GtkAdjustment* _tmp5_;
	GSettings* _tmp6_;
	GtkAdjustment* _tmp7_;
	GSettings* _tmp8_;
	GtkAdjustment* _tmp9_;
	GSettings* _tmp10_;
	AdwSwitchRow* _tmp11_;
	GSettings* _tmp12_;
	AdwSwitchRow* _tmp13_;
	GSettings* _tmp14_;
	AdwSwitchRow* _tmp15_;
	GtkAdjustment* _tmp16_;
	GtkAdjustment* _tmp17_;
	GtkAdjustment* _tmp18_;
	GtkAdjustment* _tmp19_;
	GtkAdjustment* _tmp20_;
	FtIdleMonitor* _tmp21_;
	FtIdleMonitor* _tmp22_;
	AdwSwitchRow* _tmp23_;
	GSettings* _tmp24_;
	gulong _tmp25_;
	FtTimer* _tmp26_;
	FtTimer* _tmp27_;
	parent_class = G_OBJECT_CLASS (ft_preferences_panel_timer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PREFERENCES_PANEL_TIMER, FtPreferencesPanelTimer);
	_tmp0_ = ft_get_settings ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp1_;
	_tmp2_ = self->priv->settings;
	_tmp3_ = self->priv->pomodoro_duration_adjustment;
	g_settings_bind (_tmp2_, "pomodoro-duration", (GObject*) _tmp3_, "value", G_SETTINGS_BIND_GET);
	_tmp4_ = self->priv->settings;
	_tmp5_ = self->priv->short_break_duration_adjustment;
	g_settings_bind (_tmp4_, "short-break-duration", (GObject*) _tmp5_, "value", G_SETTINGS_BIND_GET);
	_tmp6_ = self->priv->settings;
	_tmp7_ = self->priv->long_break_duration_adjustment;
	g_settings_bind (_tmp6_, "long-break-duration", (GObject*) _tmp7_, "value", G_SETTINGS_BIND_GET);
	_tmp8_ = self->priv->settings;
	_tmp9_ = self->priv->cycles_adjustment;
	g_settings_bind (_tmp8_, "cycles", (GObject*) _tmp9_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp10_ = self->priv->settings;
	_tmp11_ = self->priv->pause_on_lockscreen_switchrow;
	g_settings_bind (_tmp10_, "pause-on-lockscreen", (GObject*) _tmp11_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp12_ = self->priv->settings;
	_tmp13_ = self->priv->confirm_starting_break_switchrow;
	g_settings_bind (_tmp12_, "confirm-starting-break", (GObject*) _tmp13_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp14_ = self->priv->settings;
	_tmp15_ = self->priv->confirm_starting_pomodoro_switchrow;
	g_settings_bind (_tmp14_, "confirm-starting-pomodoro", (GObject*) _tmp15_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp16_ = self->priv->pomodoro_duration_adjustment;
	g_signal_connect_object (_tmp16_, "value-changed", (GCallback) _ft_preferences_panel_timer_update_stats_labels_gtk_adjustment_value_changed, self, 0);
	_tmp17_ = self->priv->short_break_duration_adjustment;
	g_signal_connect_object (_tmp17_, "value-changed", (GCallback) _ft_preferences_panel_timer_update_stats_labels_gtk_adjustment_value_changed, self, 0);
	_tmp18_ = self->priv->long_break_duration_adjustment;
	g_signal_connect_object (_tmp18_, "value-changed", (GCallback) _ft_preferences_panel_timer_update_stats_labels_gtk_adjustment_value_changed, self, 0);
	_tmp19_ = self->priv->cycles_adjustment;
	g_signal_connect_object (_tmp19_, "value-changed", (GCallback) _ft_preferences_panel_timer_update_stats_labels_gtk_adjustment_value_changed, self, 0);
	_tmp20_ = self->priv->cycles_adjustment;
	g_signal_connect_object (_tmp20_, "value-changed", (GCallback) _ft_preferences_panel_timer_update_long_break_row_sensitivity_gtk_adjustment_value_changed, self, 0);
	_tmp21_ = ft_idle_monitor_new ();
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = _tmp21_;
	_tmp22_ = self->priv->idle_monitor;
	_tmp23_ = self->priv->confirm_starting_pomodoro_switchrow;
	g_object_bind_property_with_closures ((GObject*) _tmp22_, "enabled", (GObject*) _tmp23_, "visible", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp24_ = self->priv->settings;
	_tmp25_ = g_signal_connect_object (_tmp24_, "changed", (GCallback) _ft_preferences_panel_timer_on_settings_changed_g_settings_changed, self, 0);
	self->priv->settings_changed_id = _tmp25_;
	_tmp26_ = ft_timer_get_default ();
	_tmp27_ = _g_object_ref0 (_tmp26_);
	_g_object_unref0 (self->priv->timer);
	self->priv->timer = _tmp27_;
	if (self->priv->timer_state_changed_id == ((gulong) 0)) {
		FtTimer* _tmp28_;
		gulong _tmp29_;
		_tmp28_ = self->priv->timer;
		_tmp29_ = g_signal_connect_object (_tmp28_, "state-changed", (GCallback) _ft_preferences_panel_timer_on_timer_state_changed_ft_timer_state_changed, self, 0);
		self->priv->timer_state_changed_id = _tmp29_;
	}
	ft_preferences_panel_timer_update_long_break_row_sensitivity (self);
	ft_preferences_panel_timer_update_stats_labels (self);
	return obj;
}

static void
ft_preferences_panel_timer_class_init (FtPreferencesPanelTimerClass * klass,
                                       gpointer klass_data)
{
	ft_preferences_panel_timer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtPreferencesPanelTimer_private_offset);
	((FtPreferencesPanelClass *) klass)->get_preferences_page = (AdwPreferencesPage* (*) (FtPreferencesPanel*)) ft_preferences_panel_timer_real_get_preferences_page;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_preferences_panel_timer_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = ft_preferences_panel_timer_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_preferences_panel_timer_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/preferences/timer/preferences-panel-timer.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "page", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, page));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "long_break_duration_row", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, long_break_duration_row));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "pomodoro_duration_adjustment", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, pomodoro_duration_adjustment));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "short_break_duration_adjustment", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, short_break_duration_adjustment));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "long_break_duration_adjustment", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, long_break_duration_adjustment));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "cycles_adjustment", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, cycles_adjustment));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "session_stats_label", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, session_stats_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "breaks_stats_label", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, breaks_stats_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "pause_on_lockscreen_switchrow", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, pause_on_lockscreen_switchrow));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "confirm_starting_break_switchrow", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, confirm_starting_break_switchrow));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "confirm_starting_pomodoro_switchrow", FALSE, FtPreferencesPanelTimer_private_offset + G_STRUCT_OFFSET (FtPreferencesPanelTimerPrivate, confirm_starting_pomodoro_switchrow));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_pomodoro_duration_changed", G_CALLBACK(_ft_preferences_panel_timer_on_pomodoro_duration_changed_ft_log_scale_row_value_changed));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_short_break_duration_changed", G_CALLBACK(_ft_preferences_panel_timer_on_short_break_duration_changed_ft_log_scale_row_value_changed));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_long_break_duration_changed", G_CALLBACK(_ft_preferences_panel_timer_on_long_break_duration_changed_ft_log_scale_row_value_changed));
}

static void
ft_preferences_panel_timer_instance_init (FtPreferencesPanelTimer * self,
                                          gpointer klass)
{
	self->priv = ft_preferences_panel_timer_get_instance_private (self);
	self->priv->settings_changed_id = (gulong) 0;
	self->priv->timer_state_changed_id = (gulong) 0;
	g_type_ensure (FT_TYPE_LOG_SCALE_ROW);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_preferences_panel_timer_finalize (GObject * obj)
{
	FtPreferencesPanelTimer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PREFERENCES_PANEL_TIMER, FtPreferencesPanelTimer);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->timer);
	_g_object_unref0 (self->priv->idle_monitor);
	_g_object_unref0 (self->priv->apply_changes_toast);
	G_OBJECT_CLASS (ft_preferences_panel_timer_parent_class)->finalize (obj);
}

static GType
ft_preferences_panel_timer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtPreferencesPanelTimerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_preferences_panel_timer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtPreferencesPanelTimer), 0, (GInstanceInitFunc) ft_preferences_panel_timer_instance_init, NULL };
	GType ft_preferences_panel_timer_type_id;
	ft_preferences_panel_timer_type_id = g_type_register_static (FT_TYPE_PREFERENCES_PANEL, "FtPreferencesPanelTimer", &g_define_type_info, 0);
	FtPreferencesPanelTimer_private_offset = g_type_add_instance_private (ft_preferences_panel_timer_type_id, sizeof (FtPreferencesPanelTimerPrivate));
	return ft_preferences_panel_timer_type_id;
}

GType
ft_preferences_panel_timer_get_type (void)
{
	static volatile gsize ft_preferences_panel_timer_type_id__once = 0;
	if (g_once_init_enter (&ft_preferences_panel_timer_type_id__once)) {
		GType ft_preferences_panel_timer_type_id;
		ft_preferences_panel_timer_type_id = ft_preferences_panel_timer_get_type_once ();
		g_once_init_leave (&ft_preferences_panel_timer_type_id__once, ft_preferences_panel_timer_type_id);
	}
	return ft_preferences_panel_timer_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

