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

/*
 * Copyright (c) 2021-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

#include "ft_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <gom/gom.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  {
	FT_TIME_BLOCK_0_PROPERTY,
	FT_TIME_BLOCK_STATE_PROPERTY,
	FT_TIME_BLOCK_SESSION_PROPERTY,
	FT_TIME_BLOCK_START_TIME_PROPERTY,
	FT_TIME_BLOCK_END_TIME_PROPERTY,
	FT_TIME_BLOCK_DURATION_PROPERTY,
	FT_TIME_BLOCK_NUM_PROPERTIES
};
static GParamSpec* ft_time_block_properties[FT_TIME_BLOCK_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block55Data Block55Data;
typedef struct _Block56Data Block56Data;
typedef struct _Block57Data Block57Data;
typedef struct _Block58Data Block58Data;
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	FT_TIME_BLOCK_CHANGED_SIGNAL,
	FT_TIME_BLOCK_NUM_SIGNALS
};
static guint ft_time_block_signals[FT_TIME_BLOCK_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _FtTimeBlockPrivate {
	FtSession* _session;
	GList* gaps;
	gint64 _start_time;
	gint64 _end_time;
	FtState _state;
	gint changed_freeze_count;
	gboolean changed_is_pending;
	FtTimeBlockMeta meta;
};

struct _Block55Data {
	int _ref_count_;
	FtTimeBlock* self;
	gint64 offset;
};

struct _Block56Data {
	int _ref_count_;
	FtTimeBlock* self;
	gint64 range_start;
	gint64 range_end;
	gint64 elapsed;
};

struct _Block57Data {
	int _ref_count_;
	FtTimeBlock* self;
	gint64 range_start;
	gint64 range_end;
	gint64 remaining;
};

struct _Block58Data {
	int _ref_count_;
	FtTimeBlock* self;
	gint64 range_start;
	gint64 range_end;
	gint64 duration;
	gint64 elapsed;
	gint64 timestamp;
};

static gint FtTimeBlock_private_offset;
static gpointer ft_time_block_parent_class = NULL;
static FtSchedulableIface * ft_time_block_ft_schedulable_parent_iface = NULL;

static GType ft_schedulable_get_type_once (void);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void ft_time_block_emit_changed (FtTimeBlock* self);
static void ft_time_block_real_set_time_range (FtSchedulable* base,
                                        gint64 start_time,
                                        gint64 end_time);
static void ft_time_block_real_move_by (FtSchedulable* base,
                                 gint64 offset);
static Block55Data* block55_data_ref (Block55Data* _data55_);
static void block55_data_unref (void * _userdata_);
static void __lambda6_ (Block55Data* _data55_,
                 FtGap* gap);
static void ___lambda6__gfunc (gconstpointer data,
                        gpointer self);
static void ft_time_block_real_move_to (FtSchedulable* base,
                                 gint64 start_time);
static Block56Data* block56_data_ref (Block56Data* _data56_);
static void block56_data_unref (void * _userdata_);
static void __lambda5_ (Block56Data* _data56_,
                 FtGap* gap);
static void ___lambda5__gfunc (gconstpointer data,
                        gpointer self);
static Block57Data* block57_data_ref (Block57Data* _data57_);
static void block57_data_unref (void * _userdata_);
static void __lambda9_ (Block57Data* _data57_,
                 FtGap* gap);
static void ___lambda9__gfunc (gconstpointer data,
                        gpointer self);
static Block58Data* block58_data_ref (Block58Data* _data58_);
static void block58_data_unref (void * _userdata_);
static void __lambda4_ (Block58Data* _data58_,
                 FtGap* gap);
static void ___lambda4__gfunc (gconstpointer data,
                        gpointer self);
static void ft_time_block_on_gap_changed (FtTimeBlock* self,
                                   FtGap* gap);
static void _ft_time_block_on_gap_changed_ft_gap_changed (FtGap* _sender,
                                                   gpointer self);
static gint _ft_schedulable_compare_gcompare_func (gconstpointer a,
                                            gconstpointer b);
static void ft_time_block_remove_link (FtTimeBlock* self,
                                GList* link);
VALA_EXTERN void ft_time_block_set_state_internal (FtTimeBlock* self,
                                       FtState state);
VALA_EXTERN gboolean ft_time_block_should_create_entry (FtTimeBlock* self);
VALA_EXTERN gboolean ft_time_block_should_update_entry (FtTimeBlock* self);
VALA_EXTERN FtTimeBlockEntry* ft_time_block_create_or_update_entry (FtTimeBlock* self);
VALA_EXTERN void ft_time_block_unset_entry (FtTimeBlock* self);
VALA_EXTERN void ft_gap_unset_entry (FtGap* self);
static void ft_time_block_real_dispose (GObject* base);
static GObject * ft_time_block_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties);
static void ft_time_block_finalize (GObject * obj);
static GType ft_time_block_get_type_once (void);
static void _vala_ft_time_block_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec);
static void _vala_ft_time_block_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
     * Ft.TimeBlockStatus enum.
     *
     * A time-block status is managed at a session-level by `SessionManager`.
     */
gchar*
ft_time_block_status_to_string (FtTimeBlockStatus self)
{
	gchar* result;
	switch (self) {
		case FT_TIME_BLOCK_STATUS_SCHEDULED:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("scheduled");
			result = _tmp0_;
			return result;
		}
		case FT_TIME_BLOCK_STATUS_IN_PROGRESS:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("in-progress");
			result = _tmp1_;
			return result;
		}
		case FT_TIME_BLOCK_STATUS_COMPLETED:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("completed");
			result = _tmp2_;
			return result;
		}
		case FT_TIME_BLOCK_STATUS_UNCOMPLETED:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("uncompleted");
			result = _tmp3_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

FtTimeBlockStatus
ft_time_block_status_from_string (const gchar* status)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	FtTimeBlockStatus result;
	_tmp0_ = status;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("in-progress")))) {
		switch (0) {
			default:
			{
				result = FT_TIME_BLOCK_STATUS_IN_PROGRESS;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("completed")))) {
		switch (0) {
			default:
			{
				result = FT_TIME_BLOCK_STATUS_COMPLETED;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("uncompleted")))) {
		switch (0) {
			default:
			{
				result = FT_TIME_BLOCK_STATUS_UNCOMPLETED;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = FT_TIME_BLOCK_STATUS_SCHEDULED;
				return result;
			}
		}
	}
}

static GType
ft_time_block_status_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_TIME_BLOCK_STATUS_SCHEDULED, "FT_TIME_BLOCK_STATUS_SCHEDULED", "scheduled"}, {FT_TIME_BLOCK_STATUS_IN_PROGRESS, "FT_TIME_BLOCK_STATUS_IN_PROGRESS", "in-progress"}, {FT_TIME_BLOCK_STATUS_COMPLETED, "FT_TIME_BLOCK_STATUS_COMPLETED", "completed"}, {FT_TIME_BLOCK_STATUS_UNCOMPLETED, "FT_TIME_BLOCK_STATUS_UNCOMPLETED", "uncompleted"}, {0, NULL, NULL}};
	GType ft_time_block_status_type_id;
	ft_time_block_status_type_id = g_enum_register_static ("FtTimeBlockStatus", values);
	return ft_time_block_status_type_id;
}

GType
ft_time_block_status_get_type (void)
{
	static volatile gsize ft_time_block_status_type_id__once = 0;
	if (g_once_init_enter (&ft_time_block_status_type_id__once)) {
		GType ft_time_block_status_type_id;
		ft_time_block_status_type_id = ft_time_block_status_get_type_once ();
		g_once_init_leave (&ft_time_block_status_type_id__once, ft_time_block_status_type_id);
	}
	return ft_time_block_status_type_id__once;
}

FtTimeBlockMeta*
ft_time_block_meta_dup (const FtTimeBlockMeta* self)
{
	FtTimeBlockMeta* dup;
	dup = g_new0 (FtTimeBlockMeta, 1);
	memcpy (dup, self, sizeof (FtTimeBlockMeta));
	return dup;
}

void
ft_time_block_meta_free (FtTimeBlockMeta* self)
{
	g_free (self);
}

static GType
ft_time_block_meta_get_type_once (void)
{
	GType ft_time_block_meta_type_id;
	ft_time_block_meta_type_id = g_boxed_type_register_static ("FtTimeBlockMeta", (GBoxedCopyFunc) ft_time_block_meta_dup, (GBoxedFreeFunc) ft_time_block_meta_free);
	return ft_time_block_meta_type_id;
}

GType
ft_time_block_meta_get_type (void)
{
	static volatile gsize ft_time_block_meta_type_id__once = 0;
	if (g_once_init_enter (&ft_time_block_meta_type_id__once)) {
		GType ft_time_block_meta_type_id;
		ft_time_block_meta_type_id = ft_time_block_meta_get_type_once ();
		g_once_init_leave (&ft_time_block_meta_type_id__once, ft_time_block_meta_type_id);
	}
	return ft_time_block_meta_type_id__once;
}

gboolean
ft_schedulable_has_started (FtSchedulable* self,
                            gint64 timestamp)
{
	gint64 start_time = 0LL;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gboolean result;
	_tmp0_ = ft_schedulable_get_start_time (self);
	_tmp1_ = _tmp0_;
	start_time = _tmp1_;
	if (ft_timestamp_is_undefined (start_time)) {
		result = TRUE;
		return result;
	}
	ft_ensure_timestamp (&timestamp);
	result = timestamp >= start_time;
	return result;
}

gboolean
ft_schedulable_has_ended (FtSchedulable* self,
                          gint64 timestamp)
{
	gint64 end_time = 0LL;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gboolean result;
	_tmp0_ = ft_schedulable_get_end_time (self);
	_tmp1_ = _tmp0_;
	end_time = _tmp1_;
	if (ft_timestamp_is_undefined (end_time)) {
		result = FALSE;
		return result;
	}
	ft_ensure_timestamp (&timestamp);
	result = timestamp > end_time;
	return result;
}

gint
ft_schedulable_compare (FtSchedulable* a,
                        FtSchedulable* b)
{
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	gint64 _tmp4_;
	gint64 _tmp5_;
	gint64 _tmp6_;
	gint64 _tmp7_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = ft_schedulable_get_start_time (a);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_schedulable_get_start_time (b);
	_tmp3_ = _tmp2_;
	_tmp4_ = ft_schedulable_get_start_time (a);
	_tmp5_ = _tmp4_;
	_tmp6_ = ft_schedulable_get_start_time (b);
	_tmp7_ = _tmp6_;
	result = ((gint) (_tmp1_ > _tmp3_)) - ((gint) (_tmp5_ < _tmp7_));
	return result;
}

void
ft_schedulable_set_time_range (FtSchedulable* self,
                               gint64 start_time,
                               gint64 end_time)
{
	FtSchedulableIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->set_time_range) {
		_iface_->set_time_range (self, start_time, end_time);
	}
}

void
ft_schedulable_move_by (FtSchedulable* self,
                        gint64 offset)
{
	FtSchedulableIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->move_by) {
		_iface_->move_by (self, offset);
	}
}

void
ft_schedulable_move_to (FtSchedulable* self,
                        gint64 start_time)
{
	FtSchedulableIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->move_to) {
		_iface_->move_to (self, start_time);
	}
}

gint64
ft_schedulable_get_start_time (FtSchedulable* self)
{
	FtSchedulableIface* _iface_;
	g_return_val_if_fail (self != NULL, -1LL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->get_start_time) {
		return _iface_->get_start_time (self);
	}
	return -1LL;
}

void
ft_schedulable_set_start_time (FtSchedulable* self,
                               gint64 value)
{
	FtSchedulableIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->set_start_time) {
		_iface_->set_start_time (self, value);
	}
}

gint64
ft_schedulable_get_end_time (FtSchedulable* self)
{
	FtSchedulableIface* _iface_;
	g_return_val_if_fail (self != NULL, -1LL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->get_end_time) {
		return _iface_->get_end_time (self);
	}
	return -1LL;
}

void
ft_schedulable_set_end_time (FtSchedulable* self,
                             gint64 value)
{
	FtSchedulableIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->set_end_time) {
		_iface_->set_end_time (self, value);
	}
}

gint64
ft_schedulable_get_duration (FtSchedulable* self)
{
	FtSchedulableIface* _iface_;
	g_return_val_if_fail (self != NULL, -1LL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->get_duration) {
		return _iface_->get_duration (self);
	}
	return -1LL;
}

void
ft_schedulable_set_duration (FtSchedulable* self,
                             gint64 value)
{
	FtSchedulableIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_SCHEDULABLE_GET_INTERFACE (self);
	if (_iface_->set_duration) {
		_iface_->set_duration (self, value);
	}
}

static void
ft_schedulable_default_init (FtSchedulableIface * iface,
                             gpointer iface_data)
{
	g_object_interface_install_property (iface, g_param_spec_int64 ("start-time", "start-time", "start-time", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_interface_install_property (iface, g_param_spec_int64 ("end-time", "end-time", "end-time", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_interface_install_property (iface, g_param_spec_int64 ("duration", "duration", "duration", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static GType
ft_schedulable_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtSchedulableIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_schedulable_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType ft_schedulable_type_id;
	ft_schedulable_type_id = g_type_register_static (G_TYPE_INTERFACE, "FtSchedulable", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (ft_schedulable_type_id, G_TYPE_OBJECT);
	return ft_schedulable_type_id;
}

GType
ft_schedulable_get_type (void)
{
	static volatile gsize ft_schedulable_type_id__once = 0;
	if (g_once_init_enter (&ft_schedulable_type_id__once)) {
		GType ft_schedulable_type_id;
		ft_schedulable_type_id = ft_schedulable_get_type_once ();
		g_once_init_leave (&ft_schedulable_type_id__once, ft_schedulable_type_id);
	}
	return ft_schedulable_type_id__once;
}

static inline gpointer
ft_time_block_get_instance_private (FtTimeBlock* self)
{
	return G_STRUCT_MEMBER_P (self, FtTimeBlock_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

FtTimeBlock*
ft_time_block_construct (GType object_type,
                         FtState state)
{
	FtTimeBlock * self = NULL;
	self = (FtTimeBlock*) g_object_new (object_type, "state", state, NULL);
	return self;
}

FtTimeBlock*
ft_time_block_new (FtState state)
{
	return ft_time_block_construct (FT_TYPE_TIME_BLOCK, state);
}

FtTimeBlock*
ft_time_block_construct_with_start_time (GType object_type,
                                         gint64 start_time,
                                         FtState state)
{
	FtTimeBlock * self = NULL;
	self = (FtTimeBlock*) g_object_new (object_type, "state", state, NULL);
	ft_schedulable_set_time_range ((FtSchedulable*) self, start_time, ft_timestamp_add_interval (start_time, ft_state_get_default_duration (state)));
	return self;
}

FtTimeBlock*
ft_time_block_new_with_start_time (gint64 start_time,
                                   FtState state)
{
	return ft_time_block_construct_with_start_time (FT_TYPE_TIME_BLOCK, start_time, state);
}

static void
ft_time_block_emit_changed (FtTimeBlock* self)
{
	gulong _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->version;
	self->version = _tmp0_ + 1;
	if (self->priv->changed_freeze_count > 0) {
		self->priv->changed_is_pending = TRUE;
	} else {
		self->priv->changed_is_pending = FALSE;
		g_signal_emit (self, ft_time_block_signals[FT_TIME_BLOCK_CHANGED_SIGNAL], 0);
	}
}

/**
         * Increases the freeze count on this.
         */
void
ft_time_block_freeze_changed (FtTimeBlock* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->changed_freeze_count;
	self->priv->changed_freeze_count = _tmp0_ + 1;
}

/**
         * Decrease the freeze count on this.
         */
void
ft_time_block_thaw_changed (FtTimeBlock* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->changed_freeze_count;
	self->priv->changed_freeze_count = _tmp0_ - 1;
	if (self->priv->changed_freeze_count == 0) {
		ft_time_block_emit_changed (self);
	}
}

static void
ft_time_block_real_set_time_range (FtSchedulable* base,
                                   gint64 start_time,
                                   gint64 end_time)
{
	FtTimeBlock * self;
	gint64 old_start_time = 0LL;
	gint64 old_end_time = 0LL;
	gint64 old_duration = 0LL;
	gboolean changed = FALSE;
	self = (FtTimeBlock*) base;
	old_start_time = self->priv->_start_time;
	old_end_time = self->priv->_end_time;
	old_duration = self->priv->_end_time - self->priv->_start_time;
	changed = FALSE;
	self->priv->_start_time = start_time;
	self->priv->_end_time = end_time;
	if (self->priv->_start_time != old_start_time) {
		g_object_notify ((GObject*) self, "start-time");
		changed = TRUE;
	}
	if (self->priv->_end_time != old_end_time) {
		g_object_notify ((GObject*) self, "end-time");
		changed = TRUE;
	}
	if ((self->priv->_end_time - self->priv->_start_time) != old_duration) {
		g_object_notify ((GObject*) self, "duration");
	}
	if (changed) {
		ft_time_block_emit_changed (self);
	}
}

static Block55Data*
block55_data_ref (Block55Data* _data55_)
{
	g_atomic_int_inc (&_data55_->_ref_count_);
	return _data55_;
}

static void
block55_data_unref (void * _userdata_)
{
	Block55Data* _data55_;
	_data55_ = (Block55Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data55_->_ref_count_)) {
		FtTimeBlock* self;
		self = _data55_->self;
		_g_object_unref0 (self);
		g_slice_free (Block55Data, _data55_);
	}
}

static void
__lambda6_ (Block55Data* _data55_,
            FtGap* gap)
{
	FtTimeBlock* self;
	self = _data55_->self;
	g_return_if_fail (gap != NULL);
	ft_schedulable_move_by ((FtSchedulable*) gap, _data55_->offset);
}

static void
___lambda6__gfunc (gconstpointer data,
                   gpointer self)
{
	__lambda6_ (self, (FtGap*) data);
}

static void
ft_time_block_real_move_by (FtSchedulable* base,
                            gint64 offset)
{
	FtTimeBlock * self;
	Block55Data* _data55_;
	gint64 _tmp0_ = 0LL;
	gint64 start_time = 0LL;
	gint64 _tmp1_ = 0LL;
	gint64 end_time = 0LL;
	GList* _tmp2_;
	self = (FtTimeBlock*) base;
	_data55_ = g_slice_new0 (Block55Data);
	_data55_->_ref_count_ = 1;
	_data55_->self = g_object_ref (self);
	_data55_->offset = offset;
	if (_data55_->offset == ((gint64) 0)) {
		block55_data_unref (_data55_);
		_data55_ = NULL;
		return;
	}
	if (ft_timestamp_is_defined (self->priv->_start_time)) {
		_tmp0_ = ft_timestamp_add_interval (self->priv->_start_time, _data55_->offset);
	} else {
		_tmp0_ = FT_TIMESTAMP_UNDEFINED;
	}
	start_time = _tmp0_;
	if (ft_timestamp_is_defined (self->priv->_end_time)) {
		_tmp1_ = ft_timestamp_add_interval (self->priv->_end_time, _data55_->offset);
	} else {
		_tmp1_ = FT_TIMESTAMP_UNDEFINED;
	}
	end_time = _tmp1_;
	ft_time_block_freeze_changed (self);
	_tmp2_ = self->priv->gaps;
	g_list_foreach (_tmp2_, ___lambda6__gfunc, _data55_);
	ft_schedulable_set_time_range ((FtSchedulable*) self, start_time, end_time);
	ft_time_block_thaw_changed (self);
	block55_data_unref (_data55_);
	_data55_ = NULL;
}

static inline gboolean
vala_g_list_is_empty (GList* self)
{
	gboolean result;
	result = ((GList*) self) == NULL;
	return result;
}

static void
ft_time_block_real_move_to (FtSchedulable* base,
                            gint64 start_time)
{
	FtTimeBlock * self;
	gboolean _tmp0_ = FALSE;
	self = (FtTimeBlock*) base;
	if (ft_timestamp_is_undefined (self->priv->_start_time)) {
		_tmp0_ = ft_timestamp_is_undefined (self->priv->_end_time);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GList* _tmp1_;
		_tmp1_ = self->priv->gaps;
		if (!vala_g_list_is_empty (_tmp1_)) {
			g_warning ("time-block.vala:333: Unable to move time-block gaps. Time-block start-" \
"time is undefined.");
		}
		ft_schedulable_set_time_range ((FtSchedulable*) self, start_time, self->priv->_end_time);
		return;
	}
	if (ft_timestamp_is_undefined (self->priv->_start_time)) {
		g_warning ("time-block.vala:341: Unable to move time-block. Time-block start-time " \
"is undefined.");
		return;
	}
	ft_schedulable_move_by ((FtSchedulable*) self, ft_timestamp_subtract (start_time, self->priv->_start_time));
}

/**
         * Calculate elapsed time excluding gaps/interruptions.
         */
static Block56Data*
block56_data_ref (Block56Data* _data56_)
{
	g_atomic_int_inc (&_data56_->_ref_count_);
	return _data56_;
}

static void
block56_data_unref (void * _userdata_)
{
	Block56Data* _data56_;
	_data56_ = (Block56Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data56_->_ref_count_)) {
		FtTimeBlock* self;
		self = _data56_->self;
		_g_object_unref0 (self);
		g_slice_free (Block56Data, _data56_);
	}
}

static void
__lambda5_ (Block56Data* _data56_,
            FtGap* gap)
{
	FtTimeBlock* self;
	gint64 gap_start_time = 0LL;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 gap_end_time = 0LL;
	gint64 _tmp2_;
	gint64 _tmp3_;
	self = _data56_->self;
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp1_ = _tmp0_;
	gap_start_time = CLAMP (_tmp1_, _data56_->range_start, _data56_->range_end);
	_tmp2_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp3_ = _tmp2_;
	gap_end_time = _tmp3_;
	if (ft_timestamp_is_undefined (gap_end_time)) {
		gap_end_time = _data56_->range_end;
	} else {
		if (gap_end_time > gap_start_time) {
			gap_end_time = CLAMP (gap_end_time, _data56_->range_start, _data56_->range_end);
		} else {
			return;
		}
	}
	_data56_->elapsed = ft_interval_subtract (_data56_->elapsed, ft_timestamp_subtract (gap_end_time, gap_start_time));
	_data56_->range_start = gap_end_time;
}

static void
___lambda5__gfunc (gconstpointer data,
                   gpointer self)
{
	__lambda5_ (self, (FtGap*) data);
}

gint64
ft_time_block_calculate_elapsed (FtTimeBlock* self,
                                 gint64 timestamp)
{
	Block56Data* _data56_;
	gboolean _tmp0_ = FALSE;
	gint64 _tmp1_ = 0LL;
	GList* _tmp2_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	_data56_ = g_slice_new0 (Block56Data);
	_data56_->_ref_count_ = 1;
	_data56_->self = g_object_ref (self);
	ft_ensure_timestamp (&timestamp);
	if (ft_timestamp_is_undefined (self->priv->_start_time)) {
		result = (gint64) 0;
		block56_data_unref (_data56_);
		_data56_ = NULL;
		return result;
	}
	if (self->priv->_start_time >= timestamp) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->_start_time >= self->priv->_end_time;
	}
	if (_tmp0_) {
		result = (gint64) 0;
		block56_data_unref (_data56_);
		_data56_ = NULL;
		return result;
	}
	_data56_->range_start = self->priv->_start_time;
	if (ft_timestamp_is_defined (self->priv->_end_time)) {
		_tmp1_ = MIN (self->priv->_end_time, timestamp);
	} else {
		_tmp1_ = timestamp;
	}
	_data56_->range_end = _tmp1_;
	_data56_->elapsed = ft_timestamp_subtract (_data56_->range_end, _data56_->range_start);
	_tmp2_ = self->priv->gaps;
	g_list_foreach (_tmp2_, ___lambda5__gfunc, _data56_);
	result = _data56_->elapsed;
	block56_data_unref (_data56_);
	_data56_ = NULL;
	return result;
}

/**
         * Calculate remaining time excluding gaps/interruptions.
         */
static Block57Data*
block57_data_ref (Block57Data* _data57_)
{
	g_atomic_int_inc (&_data57_->_ref_count_);
	return _data57_;
}

static void
block57_data_unref (void * _userdata_)
{
	Block57Data* _data57_;
	_data57_ = (Block57Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data57_->_ref_count_)) {
		FtTimeBlock* self;
		self = _data57_->self;
		_g_object_unref0 (self);
		g_slice_free (Block57Data, _data57_);
	}
}

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

static void
__lambda9_ (Block57Data* _data57_,
            FtGap* gap)
{
	FtTimeBlock* self;
	gint64 gap_start_time = 0LL;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 gap_end_time = 0LL;
	gint64 _tmp2_;
	gint64 _tmp3_;
	gboolean _tmp4_ = FALSE;
	self = _data57_->self;
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp1_ = _tmp0_;
	gap_start_time = CLAMP (_tmp1_, _data57_->range_start, _data57_->range_end);
	_tmp2_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp3_ = _tmp2_;
	gap_end_time = _tmp3_;
	if (ft_timestamp_is_undefined (gap_end_time)) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = gap_start_time >= gap_end_time;
	}
	if (_tmp4_) {
		return;
	}
	gap_end_time = CLAMP (gap_end_time, _data57_->range_start, _data57_->range_end);
	_data57_->remaining = ft_interval_subtract (_data57_->remaining, ft_timestamp_subtract (gap_end_time, gap_start_time));
	_data57_->range_start = CLAMP (gap_end_time, _data57_->range_start, _data57_->range_end);
}

static void
___lambda9__gfunc (gconstpointer data,
                   gpointer self)
{
	__lambda9_ (self, (FtGap*) data);
}

gint64
ft_time_block_calculate_remaining (FtTimeBlock* self,
                                   gint64 timestamp)
{
	Block57Data* _data57_;
	FtGap* last_gap = NULL;
	FtGap* _tmp0_;
	FtGap* _tmp1_;
	gboolean _tmp2_ = FALSE;
	FtGap* _tmp3_;
	GList* _tmp10_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	_data57_ = g_slice_new0 (Block57Data);
	_data57_->_ref_count_ = 1;
	_data57_->self = g_object_ref (self);
	ft_ensure_timestamp (&timestamp);
	if (ft_timestamp_is_undefined (self->priv->_end_time)) {
		result = (gint64) 0;
		block57_data_unref (_data57_);
		_data57_ = NULL;
		return result;
	}
	_tmp0_ = ft_time_block_get_last_gap (self);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	last_gap = _tmp1_;
	_tmp3_ = last_gap;
	if (_tmp3_ != NULL) {
		FtGap* _tmp4_;
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp4_ = last_gap;
		_tmp5_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = ft_timestamp_is_undefined (_tmp6_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		FtGap* _tmp7_;
		gint64 _tmp8_;
		gint64 _tmp9_;
		_tmp7_ = last_gap;
		_tmp8_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp7_);
		_tmp9_ = _tmp8_;
		timestamp = MIN (_tmp9_, timestamp);
	}
	_data57_->range_start = MAX (self->priv->_start_time, timestamp);
	_data57_->range_end = self->priv->_end_time;
	_data57_->remaining = ft_timestamp_subtract (_data57_->range_end, _data57_->range_start);
	_tmp10_ = self->priv->gaps;
	g_list_foreach (_tmp10_, ___lambda9__gfunc, _data57_);
	result = MAX (_data57_->remaining, (gint64) 0);
	_g_object_unref0 (last_gap);
	block57_data_unref (_data57_);
	_data57_ = NULL;
	return result;
}

/**
         * Calculate progress - elapsed time compared to completion-time.
         */
static Block58Data*
block58_data_ref (Block58Data* _data58_)
{
	g_atomic_int_inc (&_data58_->_ref_count_);
	return _data58_;
}

static void
block58_data_unref (void * _userdata_)
{
	Block58Data* _data58_;
	_data58_ = (Block58Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data58_->_ref_count_)) {
		FtTimeBlock* self;
		self = _data58_->self;
		_g_object_unref0 (self);
		g_slice_free (Block58Data, _data58_);
	}
}

static void
__lambda4_ (Block58Data* _data58_,
            FtGap* gap)
{
	FtTimeBlock* self;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp4_;
	gint64 _tmp5_;
	gint64 _tmp6_;
	gint64 _tmp7_;
	gint64 _tmp8_;
	gint64 _tmp9_;
	gint64 _tmp10_;
	gint64 _tmp11_;
	gint64 _tmp12_;
	gint64 _tmp13_;
	gint64 _tmp14_;
	gint64 _tmp15_;
	gint64 _tmp16_;
	gint64 _tmp17_;
	self = _data58_->self;
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp1_ = _tmp0_;
	if (ft_timestamp_is_undefined (_tmp1_)) {
		gint64 _tmp2_;
		gint64 _tmp3_;
		_tmp2_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
		_tmp3_ = _tmp2_;
		_data58_->elapsed = ft_interval_subtract (_data58_->elapsed, ft_timestamp_subtract (_data58_->timestamp, CLAMP (_tmp3_, _data58_->range_start, _data58_->timestamp)));
		_data58_->range_start = _data58_->range_end;
		return;
	}
	_tmp4_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp5_ = _tmp4_;
	_tmp6_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp7_ = _tmp6_;
	if (_tmp5_ <= _tmp7_) {
		return;
	}
	_tmp8_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp9_ = _tmp8_;
	_tmp10_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp11_ = _tmp10_;
	_data58_->duration = ft_interval_subtract (_data58_->duration, ft_timestamp_subtract (CLAMP (_tmp9_, _data58_->range_start, _data58_->range_end), CLAMP (_tmp11_, _data58_->range_start, _data58_->range_end)));
	_tmp12_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp13_ = _tmp12_;
	_tmp14_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp15_ = _tmp14_;
	_data58_->elapsed = ft_interval_subtract (_data58_->elapsed, ft_timestamp_subtract (CLAMP (_tmp13_, _data58_->range_start, _data58_->timestamp), CLAMP (_tmp15_, _data58_->range_start, _data58_->timestamp)));
	_tmp16_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp17_ = _tmp16_;
	_data58_->range_start = CLAMP (_tmp17_, _data58_->range_start, _data58_->range_end);
}

static void
___lambda4__gfunc (gconstpointer data,
                   gpointer self)
{
	__lambda4_ (self, (FtGap*) data);
}

gdouble
ft_time_block_calculate_progress (FtTimeBlock* self,
                                  gint64 timestamp)
{
	Block58Data* _data58_;
	gboolean _tmp0_ = FALSE;
	FtTimeBlockMeta _tmp1_;
	FtTimeBlockMeta _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gint64 _tmp6_ = 0LL;
	FtTimeBlockMeta _tmp7_;
	GList* _tmp9_;
	gdouble _tmp10_ = 0.0;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_data58_ = g_slice_new0 (Block58Data);
	_data58_->_ref_count_ = 1;
	_data58_->self = g_object_ref (self);
	_data58_->timestamp = timestamp;
	ft_ensure_timestamp (&_data58_->timestamp);
	_tmp1_ = self->priv->meta;
	if (_tmp1_.status == FT_TIME_BLOCK_STATUS_SCHEDULED) {
		_tmp0_ = TRUE;
	} else {
		FtTimeBlockMeta _tmp2_;
		_tmp2_ = self->priv->meta;
		_tmp0_ = _tmp2_.status == FT_TIME_BLOCK_STATUS_UNCOMPLETED;
	}
	if (_tmp0_) {
		result = 0.0;
		block58_data_unref (_data58_);
		_data58_ = NULL;
		return result;
	}
	_tmp3_ = self->priv->meta;
	if (_tmp3_.status == FT_TIME_BLOCK_STATUS_COMPLETED) {
		result = 1.0;
		block58_data_unref (_data58_);
		_data58_ = NULL;
		return result;
	}
	if (ft_timestamp_is_undefined (self->priv->_start_time)) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = ft_timestamp_is_undefined (self->priv->_end_time);
	}
	if (_tmp4_) {
		result = 0.0;
		block58_data_unref (_data58_);
		_data58_ = NULL;
		return result;
	}
	if (self->priv->_start_time >= _data58_->timestamp) {
		_tmp5_ = TRUE;
	} else {
		_tmp5_ = self->priv->_start_time >= self->priv->_end_time;
	}
	if (_tmp5_) {
		result = 0.0;
		block58_data_unref (_data58_);
		_data58_ = NULL;
		return result;
	}
	_data58_->range_start = self->priv->_start_time;
	_tmp7_ = self->priv->meta;
	if (ft_timestamp_is_defined (_tmp7_.completion_time)) {
		FtTimeBlockMeta _tmp8_;
		_tmp8_ = self->priv->meta;
		_tmp6_ = _tmp8_.completion_time;
	} else {
		_tmp6_ = self->priv->_end_time;
	}
	_data58_->range_end = _tmp6_;
	_data58_->duration = ft_timestamp_subtract (_data58_->range_end, _data58_->range_start);
	_data58_->elapsed = ft_timestamp_subtract (_data58_->timestamp, _data58_->range_start);
	_tmp9_ = self->priv->gaps;
	g_list_foreach (_tmp9_, ___lambda4__gfunc, _data58_);
	if (_data58_->duration > ((gint64) 0)) {
		_tmp10_ = ((gdouble) _data58_->elapsed) / ((gdouble) _data58_->duration);
	} else {
		_tmp10_ = 0.0;
	}
	result = _tmp10_;
	block58_data_unref (_data58_);
	_data58_ = NULL;
	return result;
}

static void
ft_time_block_on_gap_changed (FtTimeBlock* self,
                              FtGap* gap)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (gap != NULL);
	ft_time_block_emit_changed (self);
}

static void
_ft_time_block_on_gap_changed_ft_gap_changed (FtGap* _sender,
                                              gpointer self)
{
	ft_time_block_on_gap_changed ((FtTimeBlock*) self, _sender);
}

static gint
_ft_schedulable_compare_gcompare_func (gconstpointer a,
                                       gconstpointer b)
{
	gint result;
	result = ft_schedulable_compare ((FtSchedulable*) a, (FtSchedulable*) b);
	return result;
}

void
ft_time_block_add_gap (FtTimeBlock* self,
                       FtGap* gap)
{
	FtTimeBlock* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtGap* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_gap_get_time_block (gap);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == self) {
		return;
	}
	_tmp2_ = ft_gap_get_time_block (gap);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != NULL) {
		FtTimeBlock* _tmp4_;
		FtTimeBlock* _tmp5_;
		_tmp4_ = ft_gap_get_time_block (gap);
		_tmp5_ = _tmp4_;
		ft_time_block_remove_gap (_tmp5_, gap);
	}
	ft_gap_set_time_block (gap, self);
	g_signal_connect_object (gap, "changed", (GCallback) _ft_time_block_on_gap_changed_ft_gap_changed, self, 0);
	_tmp6_ = _g_object_ref0 (gap);
	self->priv->gaps = g_list_insert_sorted (self->priv->gaps, _tmp6_, _ft_schedulable_compare_gcompare_func);
	ft_time_block_emit_changed (self);
}

static GList*
vala_g_list_remove_full (GList* self,
                         gconstpointer data,
                         GFreeFunc func)
{
	GList* l = NULL;
	GList* result;
	l = self;
	while (TRUE) {
		GList* _tmp0_;
		GList* _tmp1_;
		gconstpointer _tmp2_;
		_tmp0_ = l;
		if (!(_tmp0_ != NULL)) {
			break;
		}
		_tmp1_ = l;
		_tmp2_ = ((GList*) _tmp1_)->data;
		if (_tmp2_ != data) {
			GList* _tmp3_;
			GList* _tmp4_;
			_tmp3_ = l;
			_tmp4_ = ((GList*) _tmp3_)->next;
			l = _tmp4_;
		} else {
			GList* _tmp5_;
			gconstpointer _tmp6_;
			GList* _tmp7_;
			_tmp5_ = l;
			_tmp6_ = ((GList*) _tmp5_)->data;
			func (_tmp6_);
			_tmp7_ = l;
			self = g_list_delete_link (self, (GList*) _tmp7_);
			break;
		}
	}
	result = self;
	return result;
}

void
ft_time_block_remove_gap (FtTimeBlock* self,
                          FtGap* gap)
{
	FtTimeBlock* _tmp0_;
	FtTimeBlock* _tmp1_;
	guint _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_gap_get_time_block (gap);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != self) {
		return;
	}
	g_signal_parse_name ("changed", FT_TYPE_GAP, &_tmp2_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (gap, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _ft_time_block_on_gap_changed_ft_gap_changed, self);
	ft_gap_set_time_block (gap, NULL);
	self->priv->gaps = vala_g_list_remove_full (self->priv->gaps, gap, _g_object_unref0_);
	ft_time_block_emit_changed (self);
}

FtGap*
ft_time_block_get_last_gap (FtTimeBlock* self)
{
	GList* link = NULL;
	GList* _tmp0_;
	GList* _tmp1_;
	FtGap* _tmp2_ = NULL;
	GList* _tmp3_;
	FtGap* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->gaps;
	_tmp1_ = g_list_last (_tmp0_);
	link = _tmp1_;
	_tmp3_ = link;
	if (_tmp3_ != NULL) {
		GList* _tmp4_;
		gconstpointer _tmp5_;
		_tmp4_ = link;
		_tmp5_ = _tmp4_->data;
		_tmp2_ = (FtGap*) _tmp5_;
	} else {
		_tmp2_ = NULL;
	}
	result = _tmp2_;
	return result;
}

FtGap*
ft_time_block_get_nth_gap (FtTimeBlock* self,
                           guint index)
{
	GList* _tmp0_;
	gconstpointer _tmp1_;
	FtGap* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->gaps;
	_tmp1_ = g_list_nth_data (_tmp0_, index);
	result = (FtGap*) _tmp1_;
	return result;
}

void
ft_time_block_foreach_gap (FtTimeBlock* self,
                           GFunc func,
                           gpointer func_target)
{
	GList* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gaps;
	g_list_foreach (_tmp0_, func, func_target);
}

static void
ft_time_block_remove_link (FtTimeBlock* self,
                           GList* link)
{
	g_return_if_fail (self != NULL);
	if (link == NULL) {
		return;
	}
	_g_object_unref0 (link->data);
	link->data = NULL;
	self->priv->gaps = g_list_delete_link (self->priv->gaps, link);
}

/**
         * Cleanup gaps.
         *
         * Handling of overlapped gaps is tailored for the rewind action.
         */
void
ft_time_block_normalize_gaps (FtTimeBlock* self)
{
	GList* link = NULL;
	GList* _tmp0_;
	GList* _tmp1_;
	GList* tmp = NULL;
	gboolean changed = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gaps;
	_tmp1_ = g_list_last (_tmp0_);
	link = _tmp1_;
	changed = FALSE;
	ft_time_block_freeze_changed (self);
	while (TRUE) {
		GList* _tmp2_;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		GList* _tmp5_;
		gconstpointer _tmp6_;
		gint64 _tmp7_;
		gint64 _tmp8_;
		gboolean _tmp25_ = FALSE;
		GList* _tmp26_;
		GList* _tmp27_;
		GList* _tmp67_;
		GList* _tmp68_;
		_tmp2_ = link;
		if (!(_tmp2_ != NULL)) {
			break;
		}
		_tmp5_ = link;
		_tmp6_ = _tmp5_->data;
		_tmp7_ = ft_schedulable_get_end_time ((FtSchedulable*) ((FtGap*) _tmp6_));
		_tmp8_ = _tmp7_;
		if (ft_timestamp_is_defined (_tmp8_)) {
			GList* _tmp9_;
			gconstpointer _tmp10_;
			gint64 _tmp11_;
			gint64 _tmp12_;
			GList* _tmp13_;
			gconstpointer _tmp14_;
			gint64 _tmp15_;
			gint64 _tmp16_;
			_tmp9_ = link;
			_tmp10_ = _tmp9_->data;
			_tmp11_ = ft_schedulable_get_end_time ((FtSchedulable*) ((FtGap*) _tmp10_));
			_tmp12_ = _tmp11_;
			_tmp13_ = link;
			_tmp14_ = _tmp13_->data;
			_tmp15_ = ft_schedulable_get_start_time ((FtSchedulable*) ((FtGap*) _tmp14_));
			_tmp16_ = _tmp15_;
			_tmp4_ = _tmp12_ < _tmp16_;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			_tmp3_ = TRUE;
		} else {
			GList* _tmp17_;
			gconstpointer _tmp18_;
			gint64 _tmp19_;
			gint64 _tmp20_;
			_tmp17_ = link;
			_tmp18_ = _tmp17_->data;
			_tmp19_ = ft_schedulable_get_start_time ((FtSchedulable*) ((FtGap*) _tmp18_));
			_tmp20_ = _tmp19_;
			_tmp3_ = ft_timestamp_is_undefined (_tmp20_);
		}
		if (_tmp3_) {
			GList* _tmp21_;
			GList* _tmp22_;
			GList* _tmp23_;
			GList* _tmp24_;
			g_debug ("time-block.vala:594: normalize_gaps: removing invalid gap");
			_tmp21_ = link;
			_tmp22_ = _tmp21_->prev;
			tmp = _tmp22_;
			_tmp23_ = link;
			ft_time_block_remove_link (self, _tmp23_);
			_tmp24_ = tmp;
			link = _tmp24_;
			changed = TRUE;
			continue;
		}
		_tmp26_ = link;
		_tmp27_ = _tmp26_->next;
		if (_tmp27_ != NULL) {
			GList* _tmp28_;
			gconstpointer _tmp29_;
			gint64 _tmp30_;
			gint64 _tmp31_;
			GList* _tmp32_;
			GList* _tmp33_;
			gconstpointer _tmp34_;
			gint64 _tmp35_;
			gint64 _tmp36_;
			_tmp28_ = link;
			_tmp29_ = _tmp28_->data;
			_tmp30_ = ft_schedulable_get_end_time ((FtSchedulable*) ((FtGap*) _tmp29_));
			_tmp31_ = _tmp30_;
			_tmp32_ = link;
			_tmp33_ = _tmp32_->next;
			_tmp34_ = _tmp33_->data;
			_tmp35_ = ft_schedulable_get_start_time ((FtSchedulable*) ((FtGap*) _tmp34_));
			_tmp36_ = _tmp35_;
			_tmp25_ = _tmp31_ > _tmp36_;
		} else {
			_tmp25_ = FALSE;
		}
		if (_tmp25_) {
			gint64 overlap = 0LL;
			GList* _tmp37_;
			gconstpointer _tmp38_;
			gint64 _tmp39_;
			gint64 _tmp40_;
			GList* _tmp41_;
			GList* _tmp42_;
			gconstpointer _tmp43_;
			gint64 _tmp44_;
			gint64 _tmp45_;
			GList* _tmp46_;
			GList* _tmp47_;
			gconstpointer _tmp48_;
			gint64 _tmp49_;
			gint64 _tmp50_;
			_tmp37_ = link;
			_tmp38_ = _tmp37_->data;
			_tmp39_ = ft_schedulable_get_end_time ((FtSchedulable*) ((FtGap*) _tmp38_));
			_tmp40_ = _tmp39_;
			_tmp41_ = link;
			_tmp42_ = _tmp41_->next;
			_tmp43_ = _tmp42_->data;
			_tmp44_ = ft_schedulable_get_start_time ((FtSchedulable*) ((FtGap*) _tmp43_));
			_tmp45_ = _tmp44_;
			overlap = _tmp40_ - _tmp45_;
			_tmp46_ = link;
			_tmp47_ = _tmp46_->next;
			_tmp48_ = _tmp47_->data;
			_tmp49_ = ft_schedulable_get_end_time ((FtSchedulable*) ((FtGap*) _tmp48_));
			_tmp50_ = _tmp49_;
			if (ft_timestamp_is_undefined (_tmp50_)) {
				GList* _tmp51_;
				gconstpointer _tmp52_;
				GList* _tmp53_;
				GList* _tmp54_;
				gboolean _tmp55_ = FALSE;
				_tmp51_ = link;
				_tmp52_ = _tmp51_->data;
				ft_schedulable_move_by ((FtSchedulable*) ((FtGap*) _tmp52_), -overlap);
				_tmp53_ = link;
				_tmp54_ = _tmp53_->prev;
				link = _tmp54_;
				if (overlap > ((gint64) 0)) {
					_tmp55_ = TRUE;
				} else {
					_tmp55_ = changed;
				}
				changed = _tmp55_;
			} else {
				GList* _tmp56_;
				GList* _tmp57_;
				GList* _tmp58_;
				GList* _tmp59_;
				gconstpointer _tmp60_;
				GList* _tmp61_;
				gconstpointer _tmp62_;
				gint64 _tmp63_;
				gint64 _tmp64_;
				GList* _tmp65_;
				GList* _tmp66_;
				_tmp56_ = link;
				_tmp57_ = _tmp56_->prev;
				tmp = _tmp57_;
				_tmp58_ = link;
				_tmp59_ = _tmp58_->next;
				_tmp60_ = _tmp59_->data;
				_tmp61_ = link;
				_tmp62_ = _tmp61_->data;
				_tmp63_ = ft_schedulable_get_start_time ((FtSchedulable*) ((FtGap*) _tmp62_));
				_tmp64_ = _tmp63_;
				ft_schedulable_set_start_time ((FtSchedulable*) ((FtGap*) _tmp60_), ft_timestamp_subtract_interval (_tmp64_, overlap));
				_tmp65_ = link;
				ft_time_block_remove_link (self, _tmp65_);
				_tmp66_ = tmp;
				link = _tmp66_;
				changed = TRUE;
			}
			continue;
		}
		_tmp67_ = link;
		_tmp68_ = _tmp67_->prev;
		link = _tmp68_;
	}
	if (changed) {
		ft_time_block_emit_changed (self);
	}
	ft_time_block_thaw_changed (self);
}

/**
         * We don't allow changing of `TimeBlock.state` after the time-block changes status to in-progress.
         * However, it's allowed to change state of a scheduled time-block.
         */
void
ft_time_block_set_state_internal (FtTimeBlock* self,
                                  FtState state)
{
	g_return_if_fail (self != NULL);
	if (self->priv->_state == state) {
		return;
	}
	self->priv->_state = state;
	g_object_notify ((GObject*) self, "state");
	ft_time_block_emit_changed (self);
}

void
ft_time_block_get_meta (FtTimeBlock* self,
                        FtTimeBlockMeta* result)
{
	FtTimeBlockMeta _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->meta;
	*result = _tmp0_;
	return;
}

void
ft_time_block_set_meta (FtTimeBlock* self,
                        FtTimeBlockMeta* meta)
{
	FtTimeBlockMeta _tmp0_;
	gulong _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (meta != NULL);
	_tmp0_ = *meta;
	self->priv->meta = _tmp0_;
	_tmp1_ = self->version;
	self->version = _tmp1_ + 1;
}

/**
         * Convenience alias for `Session.get_time_block_status(...)`
         */
FtTimeBlockStatus
ft_time_block_get_status (FtTimeBlock* self)
{
	FtTimeBlockMeta _tmp0_;
	FtTimeBlockStatus result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->meta;
	result = _tmp0_.status;
	return result;
}

/**
         * Convenience alias for `Session.set_time_block_status(...)`
         */
void
ft_time_block_set_status (FtTimeBlock* self,
                          FtTimeBlockStatus status)
{
	FtTimeBlockMeta _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->meta;
	if (_tmp0_.status != status) {
		gulong _tmp1_;
		self->priv->meta.status = status;
		_tmp1_ = self->version;
		self->version = _tmp1_ + 1;
	}
}

gint64
ft_time_block_get_intended_duration (FtTimeBlock* self)
{
	FtTimeBlockMeta _tmp0_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	_tmp0_ = self->priv->meta;
	result = _tmp0_.intended_duration;
	return result;
}

void
ft_time_block_set_intended_duration (FtTimeBlock* self,
                                     gint64 intended_duration)
{
	FtTimeBlockMeta _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->meta;
	if (_tmp0_.intended_duration != intended_duration) {
		self->priv->meta.intended_duration = intended_duration;
		ft_time_block_emit_changed (self);
	}
}

gdouble
ft_time_block_get_weight (FtTimeBlock* self)
{
	FtTimeBlockMeta _tmp0_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->meta;
	result = _tmp0_.weight;
	return result;
}

void
ft_time_block_set_weight (FtTimeBlock* self,
                          gdouble weight)
{
	FtTimeBlockMeta _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->meta;
	if (_tmp0_.weight != weight) {
		self->priv->meta.weight = weight;
		ft_time_block_emit_changed (self);
	}
}

gint64
ft_time_block_get_completion_time (FtTimeBlock* self)
{
	FtTimeBlockMeta _tmp0_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	_tmp0_ = self->priv->meta;
	result = _tmp0_.completion_time;
	return result;
}

void
ft_time_block_set_completion_time (FtTimeBlock* self,
                                   gint64 completion_time)
{
	FtTimeBlockMeta _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->meta;
	if (_tmp0_.completion_time != completion_time) {
		self->priv->meta.completion_time = completion_time;
		ft_time_block_emit_changed (self);
	}
}

gboolean
ft_time_block_should_create_entry (FtTimeBlock* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	FtTimeBlockMeta _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp2_ = self->priv->meta;
	if (_tmp2_.status != FT_TIME_BLOCK_STATUS_SCHEDULED) {
		FtState _tmp3_;
		FtState _tmp4_;
		_tmp3_ = ft_time_block_get_state (self);
		_tmp4_ = _tmp3_;
		_tmp1_ = _tmp4_ != FT_STATE_STOPPED;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp5_ = ft_schedulable_get_start_time ((FtSchedulable*) self);
		_tmp6_ = _tmp5_;
		_tmp0_ = ft_timestamp_is_defined (_tmp6_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

gboolean
ft_time_block_should_update_entry (FtTimeBlock* self)
{
	gboolean _tmp0_ = FALSE;
	FtTimeBlockEntry* _tmp1_;
	gboolean _tmp5_ = FALSE;
	FtTimeBlockEntry* _tmp6_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->entry;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		FtTimeBlockEntry* _tmp2_;
		gint64 _tmp3_;
		gint64 _tmp4_;
		_tmp2_ = self->entry;
		_tmp3_ = ft_time_block_entry_get_id (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ == ((gint64) 0);
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	_tmp6_ = self->entry;
	if (_tmp6_->version != self->version) {
		_tmp5_ = TRUE;
	} else {
		FtTimeBlockEntry* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		FtTimeBlockMeta _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp7_ = self->entry;
		_tmp8_ = ft_time_block_entry_get_status (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = self->priv->meta;
		_tmp11_ = ft_time_block_status_to_string (_tmp10_.status);
		_tmp12_ = _tmp11_;
		_tmp5_ = g_strcmp0 (_tmp9_, _tmp12_) != 0;
		_g_free0 (_tmp12_);
	}
	result = _tmp5_;
	return result;
}

FtTimeBlockEntry*
ft_time_block_create_or_update_entry (FtTimeBlock* self)
{
	FtSession* _tmp0_;
	FtTimeBlockEntry* _tmp1_;
	FtTimeBlockEntry* _tmp8_;
	FtTimeBlockEntry* _tmp9_;
	FtTimeBlockEntry* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	FtTimeBlockEntry* _tmp13_;
	FtTimeBlockMeta _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	FtTimeBlockEntry* _tmp17_;
	FtTimeBlockMeta _tmp18_;
	FtTimeBlockEntry* _tmp19_;
	FtTimeBlockEntry* _tmp20_;
	FtTimeBlockEntry* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_session;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this.session != null", NULL);
	_tmp1_ = self->entry;
	if (_tmp1_ == NULL) {
		FtTimeBlockEntry* _tmp2_;
		FtTimeBlockEntry* _tmp3_;
		GomRepository* _tmp4_;
		FtSession* _tmp5_;
		FtSessionEntry* _tmp6_;
		FtTimeBlockEntry* _tmp7_;
		_tmp2_ = ft_time_block_entry_new ();
		_g_object_unref0 (self->entry);
		self->entry = _tmp2_;
		_tmp3_ = self->entry;
		_tmp4_ = ft_database_get_repository ();
		g_object_set ((GomResource*) _tmp3_, "repository", _tmp4_, NULL);
		_tmp5_ = self->priv->_session;
		_tmp6_ = _tmp5_->entry;
		_tmp7_ = self->entry;
		g_object_bind_property_with_closures ((GObject*) _tmp6_, "id", (GObject*) _tmp7_, "session-id", 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)));
	}
	_tmp8_ = self->entry;
	ft_time_block_entry_set_start_time (_tmp8_, self->priv->_start_time);
	_tmp9_ = self->entry;
	ft_time_block_entry_set_end_time (_tmp9_, self->priv->_end_time);
	_tmp10_ = self->entry;
	_tmp11_ = ft_state_to_string (self->priv->_state);
	_tmp12_ = _tmp11_;
	ft_time_block_entry_set_state (_tmp10_, _tmp12_);
	_g_free0 (_tmp12_);
	_tmp13_ = self->entry;
	_tmp14_ = self->priv->meta;
	_tmp15_ = ft_time_block_status_to_string (_tmp14_.status);
	_tmp16_ = _tmp15_;
	ft_time_block_entry_set_status (_tmp13_, _tmp16_);
	_g_free0 (_tmp16_);
	_tmp17_ = self->entry;
	_tmp18_ = self->priv->meta;
	ft_time_block_entry_set_intended_duration (_tmp17_, _tmp18_.intended_duration);
	_tmp19_ = self->entry;
	_tmp19_->version = self->version;
	_tmp20_ = self->entry;
	result = _tmp20_;
	return result;
}

void
ft_time_block_unset_entry (FtTimeBlock* self)
{
	GList* link = NULL;
	GList* _tmp0_;
	GList* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gaps;
	_tmp1_ = g_list_first (_tmp0_);
	link = _tmp1_;
	while (TRUE) {
		GList* _tmp2_;
		GList* _tmp3_;
		gconstpointer _tmp4_;
		GList* _tmp5_;
		GList* _tmp6_;
		_tmp2_ = link;
		if (!(_tmp2_ != NULL)) {
			break;
		}
		_tmp3_ = link;
		_tmp4_ = _tmp3_->data;
		ft_gap_unset_entry ((FtGap*) _tmp4_);
		_tmp5_ = link;
		_tmp6_ = _tmp5_->next;
		link = _tmp6_;
	}
	_g_object_unref0 (self->entry);
	self->entry = NULL;
}

static void
ft_time_block_real_dispose (GObject* base)
{
	FtTimeBlock * self;
	self = (FtTimeBlock*) base;
	_g_object_unref0 (self->entry);
	self->entry = NULL;
	(self->priv->gaps == NULL) ? NULL : (self->priv->gaps = (_g_list_free__g_object_unref0_ (self->priv->gaps), NULL));
	self->priv->gaps = NULL;
	G_OBJECT_CLASS (ft_time_block_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned));
}

FtState
ft_time_block_get_state (FtTimeBlock* self)
{
	FtState result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_state;
	return result;
}

static void
ft_time_block_set_state (FtTimeBlock* self,
                         FtState value)
{
	g_return_if_fail (self != NULL);
	self->priv->_state = value;
	g_object_notify_by_pspec ((GObject *) self, ft_time_block_properties[FT_TIME_BLOCK_STATE_PROPERTY]);
}

FtSession*
ft_time_block_get_session (FtTimeBlock* self)
{
	FtSession* result;
	FtSession* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_session;
	result = _tmp0_;
	return result;
}

void
ft_time_block_set_session (FtTimeBlock* self,
                           FtSession* value)
{
	FtSession* old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_time_block_get_session (self);
	if (old_value != value) {
		self->priv->_session = value;
		g_object_notify_by_pspec ((GObject *) self, ft_time_block_properties[FT_TIME_BLOCK_SESSION_PROPERTY]);
	}
}

static gint64
ft_time_block_real_get_start_time (FtSchedulable* base)
{
	gint64 result;
	FtTimeBlock* self;
	self = (FtTimeBlock*) base;
	result = self->priv->_start_time;
	return result;
}

static void
ft_time_block_real_set_start_time (FtSchedulable* base,
                                   gint64 value)
{
	FtTimeBlock* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	self = (FtTimeBlock*) base;
	if (self->priv->_start_time == value) {
		return;
	}
	if (ft_timestamp_is_undefined (value)) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_timestamp_is_undefined (self->priv->_end_time);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = value <= self->priv->_end_time;
	}
	if (_tmp0_) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, value, self->priv->_end_time);
	} else {
		ft_schedulable_set_time_range ((FtSchedulable*) self, value, value);
	}
}

static gint64
ft_time_block_real_get_end_time (FtSchedulable* base)
{
	gint64 result;
	FtTimeBlock* self;
	self = (FtTimeBlock*) base;
	result = self->priv->_end_time;
	return result;
}

static void
ft_time_block_real_set_end_time (FtSchedulable* base,
                                 gint64 value)
{
	FtTimeBlock* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	self = (FtTimeBlock*) base;
	if (self->priv->_end_time == value) {
		return;
	}
	if (ft_timestamp_is_undefined (value)) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_timestamp_is_undefined (self->priv->_start_time);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = value >= self->priv->_start_time;
	}
	if (_tmp0_) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, self->priv->_start_time, value);
	} else {
		ft_schedulable_set_time_range ((FtSchedulable*) self, value, value);
	}
}

static gint64
ft_time_block_real_get_duration (FtSchedulable* base)
{
	gint64 result;
	FtTimeBlock* self;
	self = (FtTimeBlock*) base;
	result = ft_timestamp_subtract (self->priv->_end_time, self->priv->_start_time);
	return result;
}

static void
ft_time_block_real_set_duration (FtSchedulable* base,
                                 gint64 value)
{
	FtTimeBlock* self;
	self = (FtTimeBlock*) base;
	if (ft_timestamp_is_defined (self->priv->_start_time)) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, self->priv->_start_time, ft_timestamp_add_interval (self->priv->_start_time, value));
	} else {
		g_warning ("time-block.vala:199: Can't change time-block duration without a define" \
"d start-time.");
	}
}

static GObject *
ft_time_block_constructor (GType type,
                           guint n_construct_properties,
                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtTimeBlock * self;
	FtTimeBlockMeta _tmp0_ = {0};
	parent_class = G_OBJECT_CLASS (ft_time_block_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIME_BLOCK, FtTimeBlock);
	memset (&_tmp0_, 0, sizeof (FtTimeBlockMeta));
	_tmp0_.status = FT_TIME_BLOCK_STATUS_SCHEDULED;
	_tmp0_.intended_duration = (gint64) 0;
	_tmp0_.weight = ((double) NAN);
	_tmp0_.completion_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->meta = _tmp0_;
	return obj;
}

static void
ft_time_block_class_init (FtTimeBlockClass * klass,
                          gpointer klass_data)
{
	ft_time_block_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtTimeBlock_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_time_block_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_time_block_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_time_block_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_time_block_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_time_block_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_BLOCK_STATE_PROPERTY, ft_time_block_properties[FT_TIME_BLOCK_STATE_PROPERTY] = g_param_spec_enum ("state", "state", "state", FT_TYPE_STATE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_BLOCK_SESSION_PROPERTY, ft_time_block_properties[FT_TIME_BLOCK_SESSION_PROPERTY] = g_param_spec_object ("session", "session", "session", FT_TYPE_SESSION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_BLOCK_START_TIME_PROPERTY, ft_time_block_properties[FT_TIME_BLOCK_START_TIME_PROPERTY] = g_param_spec_int64 ("start-time", "start-time", "start-time", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_BLOCK_END_TIME_PROPERTY, ft_time_block_properties[FT_TIME_BLOCK_END_TIME_PROPERTY] = g_param_spec_int64 ("end-time", "end-time", "end-time", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	/**
	         * `duration` of a time block, including gaps
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_BLOCK_DURATION_PROPERTY, ft_time_block_properties[FT_TIME_BLOCK_DURATION_PROPERTY] = g_param_spec_int64 ("duration", "duration", "duration", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	ft_time_block_signals[FT_TIME_BLOCK_CHANGED_SIGNAL] = g_signal_new ("changed", FT_TYPE_TIME_BLOCK, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
ft_time_block_ft_schedulable_interface_init (FtSchedulableIface * iface,
                                             gpointer iface_data)
{
	ft_time_block_ft_schedulable_parent_iface = g_type_interface_peek_parent (iface);
	iface->set_time_range = (void (*) (FtSchedulable*, gint64, gint64)) ft_time_block_real_set_time_range;
	iface->move_by = (void (*) (FtSchedulable*, gint64)) ft_time_block_real_move_by;
	iface->move_to = (void (*) (FtSchedulable*, gint64)) ft_time_block_real_move_to;
	iface->get_start_time = ft_time_block_real_get_start_time;
	iface->set_start_time = ft_time_block_real_set_start_time;
	iface->get_end_time = ft_time_block_real_get_end_time;
	iface->set_end_time = ft_time_block_real_set_end_time;
	iface->get_duration = ft_time_block_real_get_duration;
	iface->set_duration = ft_time_block_real_set_duration;
}

static void
ft_time_block_instance_init (FtTimeBlock * self,
                             gpointer klass)
{
	self->priv = ft_time_block_get_instance_private (self);
	self->version = (gulong) 0;
	self->entry = NULL;
	self->priv->gaps = NULL;
	self->priv->_start_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->_end_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->_state = FT_STATE_STOPPED;
	self->priv->changed_freeze_count = 0;
	self->priv->changed_is_pending = FALSE;
}

static void
ft_time_block_finalize (GObject * obj)
{
	FtTimeBlock * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIME_BLOCK, FtTimeBlock);
	_g_object_unref0 (self->entry);
	(self->priv->gaps == NULL) ? NULL : (self->priv->gaps = (_g_list_free__g_object_unref0_ (self->priv->gaps), NULL));
	G_OBJECT_CLASS (ft_time_block_parent_class)->finalize (obj);
}

static GType
ft_time_block_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtTimeBlockClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_time_block_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtTimeBlock), 0, (GInstanceInitFunc) ft_time_block_instance_init, NULL };
	static const GInterfaceInfo ft_schedulable_info = { (GInterfaceInitFunc) ft_time_block_ft_schedulable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType ft_time_block_type_id;
	ft_time_block_type_id = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "FtTimeBlock", &g_define_type_info, 0);
	g_type_add_interface_static (ft_time_block_type_id, FT_TYPE_SCHEDULABLE, &ft_schedulable_info);
	FtTimeBlock_private_offset = g_type_add_instance_private (ft_time_block_type_id, sizeof (FtTimeBlockPrivate));
	return ft_time_block_type_id;
}

GType
ft_time_block_get_type (void)
{
	static volatile gsize ft_time_block_type_id__once = 0;
	if (g_once_init_enter (&ft_time_block_type_id__once)) {
		GType ft_time_block_type_id;
		ft_time_block_type_id = ft_time_block_get_type_once ();
		g_once_init_leave (&ft_time_block_type_id__once, ft_time_block_type_id);
	}
	return ft_time_block_type_id__once;
}

static void
_vala_ft_time_block_get_property (GObject * object,
                                  guint property_id,
                                  GValue * value,
                                  GParamSpec * pspec)
{
	FtTimeBlock * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_TIME_BLOCK, FtTimeBlock);
	switch (property_id) {
		case FT_TIME_BLOCK_STATE_PROPERTY:
		g_value_set_enum (value, ft_time_block_get_state (self));
		break;
		case FT_TIME_BLOCK_SESSION_PROPERTY:
		g_value_set_object (value, ft_time_block_get_session (self));
		break;
		case FT_TIME_BLOCK_START_TIME_PROPERTY:
		g_value_set_int64 (value, ft_schedulable_get_start_time ((FtSchedulable*) self));
		break;
		case FT_TIME_BLOCK_END_TIME_PROPERTY:
		g_value_set_int64 (value, ft_schedulable_get_end_time ((FtSchedulable*) self));
		break;
		case FT_TIME_BLOCK_DURATION_PROPERTY:
		g_value_set_int64 (value, ft_schedulable_get_duration ((FtSchedulable*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_time_block_set_property (GObject * object,
                                  guint property_id,
                                  const GValue * value,
                                  GParamSpec * pspec)
{
	FtTimeBlock * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_TIME_BLOCK, FtTimeBlock);
	switch (property_id) {
		case FT_TIME_BLOCK_STATE_PROPERTY:
		ft_time_block_set_state (self, g_value_get_enum (value));
		break;
		case FT_TIME_BLOCK_SESSION_PROPERTY:
		ft_time_block_set_session (self, g_value_get_object (value));
		break;
		case FT_TIME_BLOCK_START_TIME_PROPERTY:
		ft_schedulable_set_start_time ((FtSchedulable*) self, g_value_get_int64 (value));
		break;
		case FT_TIME_BLOCK_END_TIME_PROPERTY:
		ft_schedulable_set_end_time ((FtSchedulable*) self, g_value_get_int64 (value));
		break;
		case FT_TIME_BLOCK_DURATION_PROPERTY:
		ft_schedulable_set_duration ((FtSchedulable*) self, g_value_get_int64 (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

