/* session-manager.c generated by valac 0.56.19, the Vala compiler
 * generated from session-manager.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 <glib-object.h>
#include "ft_core.h"
#include <glib.h>
#include <gio/gio.h>
#include <gom/gom.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>

#define FT_SESSION_MANAGER_OVERDUE_TIMEOUT FT_INTERVAL_HOUR
#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

typedef enum  {
	FT_ADVANCEMENT_MODE_CONTINUOUS,
	FT_ADVANCEMENT_MODE_CONFIRM,
	FT_ADVANCEMENT_MODE_WAIT_FOR_ACTIVITY
} FtAdvancementMode;

#define FT_TYPE_ADVANCEMENT_MODE (ft_advancement_mode_get_type ())
enum  {
	FT_SESSION_MANAGER_0_PROPERTY,
	FT_SESSION_MANAGER_TIMER_PROPERTY,
	FT_SESSION_MANAGER_SCHEDULER_PROPERTY,
	FT_SESSION_MANAGER_CURRENT_SESSION_PROPERTY,
	FT_SESSION_MANAGER_CURRENT_TIME_BLOCK_PROPERTY,
	FT_SESSION_MANAGER_CURRENT_STATE_PROPERTY,
	FT_SESSION_MANAGER_CURRENT_GAP_PROPERTY,
	FT_SESSION_MANAGER_HAS_UNIFORM_BREAKS_PROPERTY,
	FT_SESSION_MANAGER_NUM_PROPERTIES
};
static GParamSpec* ft_session_manager_properties[FT_SESSION_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block40Data Block40Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block41Data Block41Data;
typedef struct _Block42Data Block42Data;
typedef struct _Block43Data Block43Data;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
typedef struct _Block44Data Block44Data;
typedef struct _Block45Data Block45Data;
typedef struct _Block46Data Block46Data;
typedef struct _FtSessionManagerSaveSessionData FtSessionManagerSaveSessionData;
typedef struct _Block47Data Block47Data;
typedef struct _FtSessionManagerSaveInternalData FtSessionManagerSaveInternalData;
typedef struct _FtSessionManagerSaveData FtSessionManagerSaveData;
typedef struct _FtSessionManagerRestoreSessionData FtSessionManagerRestoreSessionData;
typedef struct _Block48Data Block48Data;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _FtSessionManagerRestoreData FtSessionManagerRestoreData;
typedef struct _Block49Data Block49Data;
typedef struct _Block50Data Block50Data;
enum  {
	FT_SESSION_MANAGER_ENTER_SESSION_SIGNAL,
	FT_SESSION_MANAGER_LEAVE_SESSION_SIGNAL,
	FT_SESSION_MANAGER_ENTER_TIME_BLOCK_SIGNAL,
	FT_SESSION_MANAGER_LEAVE_TIME_BLOCK_SIGNAL,
	FT_SESSION_MANAGER_SESSION_RESCHEDULED_SIGNAL,
	FT_SESSION_MANAGER_SESSION_EXPIRED_SIGNAL,
	FT_SESSION_MANAGER_CONFIRM_ADVANCEMENT_SIGNAL,
	FT_SESSION_MANAGER_ADVANCED_SIGNAL,
	FT_SESSION_MANAGER_TIME_BLOCK_SAVED_SIGNAL,
	FT_SESSION_MANAGER_GAP_SAVED_SIGNAL,
	FT_SESSION_MANAGER_NUM_SIGNALS
};
static guint ft_session_manager_signals[FT_SESSION_MANAGER_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 _FtSessionManagerPrivate {
	FtTimer* _timer;
	FtScheduler* _scheduler;
	FtSession* _current_session;
	FtTimeBlock* _current_time_block;
	FtGap* _current_gap;
	FtState _current_state;
	gboolean _has_uniform_breaks;
	FtSession* next_session;
	FtTimeBlock* next_time_block;
	FtIdleMonitor* idle_monitor;
	FtTimeZoneMonitor* timezone_monitor;
	FtTimezoneHistory* timezone_history;
	FtScreenSaver* screensaver;
	FtLockScreen* lockscreen;
	gboolean auto_paused;
	gboolean current_time_block_entered;
	gulong current_time_block_changed_id;
	gboolean current_session_entered;
	gboolean current_session_changed_frozen;
	gulong current_session_notify_expiry_time_id;
	FtSession* previous_session;
	FtTimeBlock* previous_time_block;
	GSettings* settings;
	gint resolving_timer_state;
	gulong timer_resolve_state_id;
	gulong timer_state_changed_id;
	gulong timer_finished_id;
	gulong timer_suspending_id;
	gulong timer_suspended_id;
	guint expiry_timeout_id;
	guint reschedule_idle_id;
	guint active_watch_id;
	guint session_changed_idle_id;
	gboolean saving;
	gboolean save_dirty;
	gboolean save_result;
	FtAsyncCallback** save_callbacks;
	gint save_callbacks_length1;
	gint _save_callbacks_size_;
};

struct _Block40Data {
	int _ref_count_;
	FtSessionManager* self;
	GomCommand* command;
};

struct _Block41Data {
	int _ref_count_;
	FtSessionManager* self;
	GomCommand* command;
};

struct _Block42Data {
	int _ref_count_;
	FtSessionManager* self;
	GomCommand* command;
};

struct _Block43Data {
	int _ref_count_;
	FtSessionManager* self;
	GArray* keep_time_block_ids;
	GHashTable* keep_gap_ids;
	GHashTable* time_block_mapping;
	GHashTable* gap_mapping;
	GomRepository* repository;
	gpointer _async_data_;
};

struct _Block44Data {
	int _ref_count_;
	Block43Data * _data43_;
	FtTimeBlockEntry* time_block_entry;
};

struct _Block45Data {
	int _ref_count_;
	Block44Data * _data44_;
	GArray* gap_ids;
};

struct _Block46Data {
	int _ref_count_;
	Block43Data * _data43_;
	GomResourceGroup* time_block_entries;
	GomResourceGroup* gap_entries;
};

struct _FtSessionManagerSaveSessionData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtSessionManager* self;
	GomRepository* repository;
	FtSession* session;
	Block43Data* _data43_;
	gboolean _tmp0_;
	FtSessionEntry* _tmp1_;
	FtSessionEntry* _tmp2_;
	gint64 _tmp3_;
	gint64 _tmp4_;
	FtSessionEntry* session_entry;
	FtSessionEntry* _tmp5_;
	FtSessionEntry* _tmp6_;
	FtSessionEntry* _tmp7_;
	gint64 _tmp8_;
	gint64 _tmp9_;
	gboolean session_entry_needs_update;
	FtSessionEntry* _vala1_session_entry;
	FtSessionEntry* _tmp10_;
	FtSessionEntry* _tmp11_;
	GArray* _tmp12_;
	GHashFunc _tmp13_;
	GEqualFunc _tmp14_;
	GHashTable* _tmp15_;
	GHashFunc _tmp16_;
	GEqualFunc _tmp17_;
	GHashTable* _tmp18_;
	GHashFunc _tmp19_;
	GEqualFunc _tmp20_;
	GHashTable* _tmp21_;
	FtSessionEntry* _tmp22_;
	gint64 _tmp23_;
	gint64 _tmp24_;
	FtSessionEntry* _tmp25_;
	Block46Data* _data46_;
	FtSessionEntry* _tmp26_;
	GObject* _tmp27_;
	GObject* _tmp28_;
	GHashTable* _tmp29_;
	FtSessionEntry* _tmp30_;
	gint64 _tmp31_;
	gint64 _tmp32_;
	GArray* _tmp33_;
	GomResourceGroup* _tmp34_;
	GHashTable* _tmp35_;
	GObject* _tmp36_;
	GObject* _tmp37_;
	GHashTable* _tmp38_;
	GHashTable* _tmp39_;
	GomResourceGroup* _tmp40_;
	GHashTable* _tmp41_;
	GError* _error_;
	GError* _tmp42_;
	GError* _tmp43_;
	GError* _inner_error0_;
};

struct _Block47Data {
	int _ref_count_;
	FtSessionManager* self;
	gint remaining_sessions;
	gboolean success;
	gpointer _async_data_;
};

struct _FtSessionManagerSaveInternalData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtSessionManager* self;
	gboolean result;
	Block47Data* _data47_;
	GomRepository* repository;
	GomRepository* _tmp0_;
	GomRepository* _tmp1_;
	GomRepository* _tmp2_;
	FtSession* _tmp3_;
	gint _tmp4_;
	GomRepository* _tmp5_;
	FtSession* _tmp6_;
	FtSession* _tmp7_;
	gint _tmp8_;
	GomRepository* _tmp9_;
	FtSession* _tmp10_;
};

struct _FtSessionManagerSaveData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtSessionManager* self;
	gboolean result;
	FtAsyncCallback* _tmp0_;
	gboolean _result_;
	FtAsyncCallback** callbacks;
	FtAsyncCallback** _tmp1_;
	gint _tmp1__length1;
	gint callbacks_length1;
	gint _callbacks_size_;
	FtAsyncCallback** _tmp2_;
	FtAsyncCallback** _tmp3_;
	gint _tmp3__length1;
	FtAsyncCallback** callback_collection;
	gint callback_collection_length1;
	gint _callback_collection_size_;
	gint callback_it;
	FtAsyncCallback* callback;
	FtAsyncCallback* _tmp4_;
	GSourceFunc _tmp5_;
	gpointer _tmp5__target;
};

struct _FtSessionManagerRestoreSessionData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtSessionManager* self;
	GomRepository* repository;
	FtSessionEntry* session_entry;
	FtSession* result;
	GValue session_id_value;
	GValue _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	GomFilter* time_block_filter;
	GValue _tmp3_;
	GomFilter* _tmp4_;
	GomSorting* time_block_sorting;
	GObject* _tmp5_;
	GObject* _tmp6_;
	GomSorting* _tmp7_;
	GomResourceGroup* time_block_results;
	GomFilter* _tmp8_;
	GomSorting* _tmp9_;
	GomResourceGroup* _tmp10_;
	GomResourceGroup* _tmp11_;
	guint _tmp12_;
	guint _tmp13_;
	GomResourceGroup* _tmp14_;
	GomResourceGroup* _tmp15_;
	guint _tmp16_;
	guint _tmp17_;
	FtSession* session;
	FtSession* _tmp18_;
	FtSession* _tmp19_;
	gint64 _tmp20_;
	gint64 _tmp21_;
	FtSession* _tmp22_;
	FtSessionEntry* _tmp23_;
	GHashTable* time_blocks_by_id;
	GHashFunc _tmp24_;
	GEqualFunc _tmp25_;
	GHashTable* _tmp26_;
	GomFilter** gap_filters;
	GomFilter** _tmp27_;
	gint gap_filters_length1;
	gint _gap_filters_size_;
	gint i;
	gboolean _tmp28_;
	gint _tmp29_;
	GomResourceGroup* _tmp30_;
	guint _tmp31_;
	guint _tmp32_;
	FtTimeBlockEntry* time_block_entry;
	GomResourceGroup* _tmp33_;
	GomResource* _tmp34_;
	FtTimeBlockEntry* _tmp35_;
	FtTimeBlock* time_block;
	FtTimeBlockEntry* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp38_;
	FtTimeBlock* _tmp39_;
	FtTimeBlock* _tmp40_;
	FtTimeBlockEntry* _tmp41_;
	gint64 _tmp42_;
	gint64 _tmp43_;
	FtTimeBlockEntry* _tmp44_;
	gint64 _tmp45_;
	gint64 _tmp46_;
	FtTimeBlock* _tmp47_;
	FtTimeBlockEntry* _tmp48_;
	const gchar* _tmp49_;
	const gchar* _tmp50_;
	FtTimeBlock* _tmp51_;
	FtTimeBlockEntry* _tmp52_;
	gint64 _tmp53_;
	gint64 _tmp54_;
	FtTimeBlock* _tmp55_;
	FtTimeBlockEntry* _tmp56_;
	FtTimeBlockEntry* _tmp57_;
	GHashTable* _tmp58_;
	FtTimeBlockEntry* _tmp59_;
	gint64 _tmp60_;
	gint64 _tmp61_;
	gint64* _tmp62_;
	FtTimeBlock* _tmp63_;
	FtTimeBlock* _tmp64_;
	GValue time_block_id_value;
	GValue _tmp65_;
	FtTimeBlockEntry* _tmp66_;
	gint64 _tmp67_;
	gint64 _tmp68_;
	GValue _tmp69_;
	GomFilter* _tmp70_;
	FtSession* _tmp71_;
	FtTimeBlock* _tmp72_;
	GomFilter** _tmp73_;
	gint _tmp73__length1;
	GomFilter* _tmp74_;
	GomFilter** _tmp75_;
	gint _tmp75__length1;
	GomFilter** _tmp76_;
	gint _tmp76__length1;
	GomFilter* _tmp77_;
	GomFilter* _tmp78_;
	GomFilter** _tmp79_;
	gint _tmp79__length1;
	GomFilter* _tmp80_;
	GomFilter* gap_filter;
	GomFilter* _tmp81_;
	GomSorting* gap_sorting;
	GObject* _tmp82_;
	GObject* _tmp83_;
	GomSorting* _tmp84_;
	GomResourceGroup* gap_results;
	GomFilter* _tmp85_;
	GomSorting* _tmp86_;
	GomResourceGroup* _tmp87_;
	GomResourceGroup* _tmp88_;
	GomResourceGroup* _tmp89_;
	guint _tmp90_;
	guint _tmp91_;
	gint j;
	gboolean _tmp92_;
	gint _tmp93_;
	GomResourceGroup* _tmp94_;
	guint _tmp95_;
	guint _tmp96_;
	FtGapEntry* gap_entry;
	GomResourceGroup* _tmp97_;
	GomResource* _tmp98_;
	FtGapEntry* _tmp99_;
	FtTimeBlock* _vala1_time_block;
	GHashTable* _tmp100_;
	FtGapEntry* _tmp101_;
	gint64 _tmp102_;
	gint64 _tmp103_;
	gconstpointer _tmp104_;
	FtTimeBlock* _tmp105_;
	FtGap* gap;
	FtGapEntry* _tmp106_;
	const gchar* _tmp107_;
	const gchar* _tmp108_;
	FtGap* _tmp109_;
	FtGap* _tmp110_;
	FtGapEntry* _tmp111_;
	gint64 _tmp112_;
	gint64 _tmp113_;
	FtGapEntry* _tmp114_;
	gint64 _tmp115_;
	gint64 _tmp116_;
	FtGap* _tmp117_;
	FtGapEntry* _tmp118_;
	FtGapEntry* _tmp119_;
	FtGap* _tmp120_;
	gint64 _tmp121_;
	gint64 _tmp122_;
	FtTimeBlock* _tmp123_;
	gint64 _tmp124_;
	gint64 _tmp125_;
	FtGap* _tmp126_;
	FtTimeBlock* _tmp127_;
	gint64 _tmp128_;
	gint64 _tmp129_;
	gboolean _tmp130_;
	gboolean _tmp131_;
	FtGap* _tmp132_;
	gint64 _tmp133_;
	gint64 _tmp134_;
	FtTimeBlock* _tmp135_;
	gint64 _tmp136_;
	gint64 _tmp137_;
	FtGap* _tmp138_;
	gint64 _tmp139_;
	gint64 _tmp140_;
	FtTimeBlock* _tmp141_;
	gint64 _tmp142_;
	gint64 _tmp143_;
	FtGap* _tmp144_;
	FtTimeBlock* _tmp145_;
	gint64 _tmp146_;
	gint64 _tmp147_;
	gboolean _tmp148_;
	FtGap* _tmp149_;
	gint64 _tmp150_;
	gint64 _tmp151_;
	FtGap* _tmp152_;
	gint64 _tmp153_;
	gint64 _tmp154_;
	FtTimeBlock* _tmp155_;
	FtGap* _tmp156_;
	FtSession* _tmp157_;
	FtScheduler* _tmp158_;
	FtSession* _tmp159_;
	GError* _inner_error0_;
};

struct _Block48Data {
	int _ref_count_;
	FtSessionManager* self;
	FtTimeBlock* restored_time_block;
	FtGap* restored_gap;
	gpointer _async_data_;
};

struct _FtSessionManagerRestoreData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtSessionManager* self;
	gint64 timestamp;
	gboolean result;
	Block48Data* _data48_;
	FtSessionEntry* session_entry;
	FtSession* restored_session;
	GomRepository* repository;
	GomRepository* _tmp0_;
	GomRepository* _tmp1_;
	gboolean success;
	GomRepository* _tmp2_;
	FtTimeZoneMonitor* _tmp3_;
	GTimeZone* _tmp4_;
	GTimeZone* _tmp5_;
	GValue end_time_value;
	GValue _tmp6_;
	GomFilter* session_filter;
	GValue _tmp7_;
	GomFilter* _tmp8_;
	GomSorting* session_sorting;
	GObject* _tmp9_;
	GObject* _tmp10_;
	GomSorting* _tmp11_;
	GomResourceGroup* session_results;
	GomRepository* _tmp12_;
	GomFilter* _tmp13_;
	GomSorting* _tmp14_;
	GomResourceGroup* _tmp15_;
	GomResourceGroup* _tmp16_;
	guint _tmp17_;
	guint _tmp18_;
	GomResourceGroup* _tmp19_;
	GomResourceGroup* _tmp20_;
	GomResource* _tmp21_;
	FtSessionEntry* _tmp22_;
	GError* _error_;
	GError* _tmp23_;
	const gchar* _tmp24_;
	FtSessionEntry* _tmp25_;
	FtSession* _tmp26_;
	GomRepository* _tmp27_;
	FtSessionEntry* _tmp28_;
	FtSession* _tmp29_;
	FtSession* _tmp30_;
	GError* _vala1__error_;
	FtSessionEntry* _tmp31_;
	gint64 _tmp32_;
	gint64 _tmp33_;
	gchar* _tmp34_;
	gchar* _tmp35_;
	GError* _tmp36_;
	const gchar* _tmp37_;
	FtSession* _tmp38_;
	FtSession* _tmp39_;
	FtTimeBlock* _tmp40_;
	FtTimeBlock* _tmp41_;
	gboolean _tmp42_;
	gboolean _tmp43_;
	FtTimeBlock* _tmp44_;
	FtTimeBlock* _tmp45_;
	gint64 _tmp46_;
	gint64 _tmp47_;
	FtGap* _tmp48_;
	FtTimeBlock* _tmp49_;
	FtGap* _tmp50_;
	FtGap* _tmp51_;
	FtGap* _tmp52_;
	FtGap* _tmp53_;
	FtTimeBlock* _tmp54_;
	gboolean _tmp55_;
	FtSession* _tmp56_;
	FtSession* _tmp57_;
	FtSession* _tmp58_;
	FtTimeBlock* _tmp59_;
	gboolean _tmp60_;
	FtTimer* _tmp61_;
	FtTimer* _tmp62_;
	void* _tmp63_;
	void* _tmp64_;
	FtTimeBlock* _tmp65_;
	FtTimeBlock* _tmp66_;
	FtTimeBlock* _tmp67_;
	FtTimeBlock* _tmp68_;
	GError* _inner_error0_;
};

struct _Block49Data {
	int _ref_count_;
	FtSessionManager* self;
	FtTimeBlock* time_block;
	gint64 timestamp;
};

struct _Block50Data {
	int _ref_count_;
	FtSessionManager* session_manager;
};

static gint FtSessionManager_private_offset;
static gpointer ft_session_manager_parent_class = NULL;
static FtSessionManager* ft_session_manager_instance;
static FtSessionManager* ft_session_manager_instance = NULL;

VALA_EXTERN GType ft_advancement_mode_get_type (void) G_GNUC_CONST ;
static void ft_session_manager_enter_session (FtSessionManager* self,
                                       FtSession* session);
static void ft_session_manager_leave_session (FtSessionManager* self,
                                       FtSession* session);
static void ft_session_manager_enter_time_block (FtSessionManager* self,
                                          FtTimeBlock* time_block);
static void ft_session_manager_leave_time_block (FtSessionManager* self,
                                          FtTimeBlock* time_block);
static void ft_session_manager_session_rescheduled (FtSessionManager* self,
                                             FtSession* session,
                                             gint64 timestamp);
static void ft_session_manager_session_expired (FtSessionManager* self,
                                         FtSession* session,
                                         gint64 timestamp);
static gint64 ft_session_manager_get_current_time (FtSessionManager* self);
static FtSession* ft_session_manager_initialize_next_session (FtSessionManager* self,
                                                       gint64 timestamp);
static void ft_session_manager_reschedule_full (FtSessionManager* self,
                                         FtSession* session,
                                         FtTimeBlock* next_time_block,
                                         gboolean next_time_block_set,
                                         gint64 timestamp);
static FtTimeBlock* ft_session_manager_initialize_next_time_block (FtSessionManager* self,
                                                            gint64 timestamp);
static gboolean ft_session_manager_is_long_break_needed (FtSessionManager* self,
                                                  gint64 timestamp);
VALA_EXTERN void ft_time_block_set_state_internal (FtTimeBlock* self,
                                       FtState state);
static void ft_session_manager_initialize_timer_state (FtSessionManager* self,
                                                FtTimerState* state,
                                                gint64 timestamp);
static inline gboolean ft_session_manager_is_waiting_for_activity (FtSessionManager* self);
static void ft_session_manager_update_session_template (FtSessionManager* self);
static void ft_session_manager_update_timer_state (FtSessionManager* self,
                                            gint64 timestamp);
static void ft_session_manager_update_has_uniform_breaks (FtSessionManager* self);
static FtTimeBlock* ft_session_manager_schedule_pomodoro (FtSessionManager* self,
                                                   gint64 timestamp);
VALA_EXTERN void ft_scheduler_build_scheduler_context (FtScheduler* self,
                                           FtSession* session,
                                           gboolean is_resuming,
                                           gint64 timestamp,
                                           FtSchedulerContext* context,
                                           GList** first_scheduled_link);
static void ft_session_manager_emit_session_rescheduled (FtSessionManager* self,
                                                  gint64 timestamp);
static void ft_session_manager_reschedule (FtSessionManager* self);
static void ft_session_manager_reschedule_if_queued (FtSessionManager* self);
static void ft_session_manager_queue_reschedule (FtSessionManager* self);
static gboolean __lambda38_ (FtSessionManager* self);
static gboolean ___lambda38__gsource_func (gpointer self);
static void ft_session_manager_set_current_time_block_full (FtSessionManager* self,
                                                     FtSession* session,
                                                     FtTimeBlock* time_block,
                                                     gint64 timestamp);
static void ft_session_manager_freeze_current_session_changed (FtSessionManager* self);
static void ft_session_manager_mark_gap_end (FtSessionManager* self,
                                      FtGap* gap,
                                      gint64 timestamp);
static void ft_session_manager_mark_time_block_end (FtSessionManager* self,
                                             FtTimeBlock* time_block,
                                             gint64 timestamp);
static void ft_session_manager_mark_session_end (FtSessionManager* self,
                                          FtSession* session,
                                          gint64 timestamp);
static void ft_session_manager_enable_idle_monitor (FtSessionManager* self);
static void ft_session_manager_disable_idle_monitor (FtSessionManager* self);
static void ft_session_manager_thaw_current_session_changed (FtSessionManager* self);
static FtAdvancementMode ft_session_manager_resolve_advancement_mode (FtSessionManager* self,
                                                               FtState next_state,
                                                               gint64 timestamp);
static void ft_session_manager_delete_time_blocks (FtSessionManager* self,
                                            GomRepository* repository,
                                            gint64 session_id,
                                            GArray* time_block_ids_to_keep);
static Block40Data* block40_data_ref (Block40Data* _data40_);
static void block40_data_unref (void * _userdata_);
static void _vala_array_add22 (GomFilter** * array,
                        gint* length,
                        gint* size,
                        GomFilter* value);
static void __lambda42_ (Block40Data* _data40_);
static void ___lambda42__gom_adapter_callback (GomAdapter* adapter,
                                        gpointer self);
static void ft_session_manager_delete_gaps (FtSessionManager* self,
                                     GomRepository* repository,
                                     gint64 time_block_id,
                                     GArray* gap_ids_to_keep);
static Block41Data* block41_data_ref (Block41Data* _data41_);
static void block41_data_unref (void * _userdata_);
static void _vala_array_add23 (GomFilter** * array,
                        gint* length,
                        gint* size,
                        GomFilter* value);
static void __lambda43_ (Block41Data* _data41_);
static void ___lambda43__gom_adapter_callback (GomAdapter* adapter,
                                        gpointer self);
static void ft_session_manager_delete_session (FtSessionManager* self,
                                        GomRepository* repository,
                                        gint64 session_id);
static Block42Data* block42_data_ref (Block42Data* _data42_);
static void block42_data_unref (void * _userdata_);
static void __lambda44_ (Block42Data* _data42_);
static void ___lambda44__gom_adapter_callback (GomAdapter* adapter,
                                        gpointer self);
static void ft_session_manager_save_session_data_free (gpointer _data);
static void ft_session_manager_save_session (FtSessionManager* self,
                                      GomRepository* repository,
                                      FtSession* session,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
static void ft_session_manager_save_session_finish (FtSessionManager* self,
                                             GAsyncResult* _res_,
                                             GError** error);
static gboolean ft_session_manager_save_session_co (FtSessionManagerSaveSessionData* _data_);
static Block43Data* block43_data_ref (Block43Data* _data43_);
static void block43_data_unref (void * _userdata_);
VALA_EXTERN gboolean ft_session_should_create_entry (FtSession* self);
VALA_EXTERN void ft_session_unset_entry (FtSession* self);
VALA_EXTERN gboolean ft_session_should_update_entry (FtSession* self);
VALA_EXTERN FtSessionEntry* ft_session_create_or_update_entry (FtSession* self);
static void __lambda45_ (void* arr);
static void ___lambda45__gdestroy_notify (void* data);
static void __lambda46_ (Block43Data* _data43_,
                  FtTimeBlock* time_block);
static Block44Data* block44_data_ref (Block44Data* _data44_);
static void block44_data_unref (void * _userdata_);
VALA_EXTERN gboolean ft_time_block_should_create_entry (FtTimeBlock* self);
VALA_EXTERN gboolean ft_time_block_should_update_entry (FtTimeBlock* self);
static Block45Data* block45_data_ref (Block45Data* _data45_);
static void block45_data_unref (void * _userdata_);
VALA_EXTERN FtTimeBlockEntry* ft_time_block_create_or_update_entry (FtTimeBlock* self);
static void ___lambda47_ (Block45Data* _data45_,
                   FtGap* gap);
VALA_EXTERN gboolean ft_gap_should_create_entry (FtGap* self);
VALA_EXTERN gboolean ft_gap_should_update_entry (FtGap* self);
VALA_EXTERN FtGapEntry* ft_gap_create_or_update_entry (FtGap* self);
static void ____lambda47__gfunc (gconstpointer data,
                          gpointer self);
static gint64* _int64_dup (gint64* self);
static void ___lambda46__gfunc (gconstpointer data,
                         gpointer self);
static Block46Data* block46_data_ref (Block46Data* _data46_);
static void block46_data_unref (void * _userdata_);
static void ft_session_manager_save_session_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void ___lambda48_ (Block46Data* _data46_,
                   FtTimeBlock* time_block,
                   FtTimeBlockEntry* time_block_entry);
static void ____lambda48__gh_func (gconstpointer key,
                            gconstpointer value,
                            gpointer self);
static void ___lambda49_ (FtSessionManager* self,
                   FtTimeBlock* time_block,
                   FtTimeBlockEntry* time_block_entry);
static void ____lambda49__gh_func (gconstpointer key,
                            gconstpointer value,
                            gpointer self);
static void ___lambda50_ (Block46Data* _data46_,
                   FtGap* gap,
                   FtGapEntry* gap_entry);
static void ____lambda50__gh_func (gconstpointer key,
                            gconstpointer value,
                            gpointer self);
static void ___lambda51_ (Block46Data* _data46_,
                   gint64* time_block_id,
                   GArray* gap_ids_to_keep);
static void ____lambda51__gh_func (gconstpointer key,
                            gconstpointer value,
                            gpointer self);
static void ___lambda52_ (FtSessionManager* self,
                   FtGap* gap,
                   FtGapEntry* gap_entry);
static void ____lambda52__gh_func (gconstpointer key,
                            gconstpointer value,
                            gpointer self);
static void ft_session_manager_save_internal_data_free (gpointer _data);
static void ft_session_manager_save_internal (FtSessionManager* self,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
static gboolean ft_session_manager_save_internal_finish (FtSessionManager* self,
                                                  GAsyncResult* _res_);
static gboolean ft_session_manager_save_internal_co (FtSessionManagerSaveInternalData* _data_);
static Block47Data* block47_data_ref (Block47Data* _data47_);
static void block47_data_unref (void * _userdata_);
static void ___lambda53_ (Block47Data* _data47_,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda53__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void ___lambda54_ (Block47Data* _data47_,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda54__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void ft_session_manager_save_data_free (gpointer _data);
static gboolean ft_session_manager_save_co (FtSessionManagerSaveData* _data_);
static gboolean _ft_session_manager_save_co_gsource_func (gpointer self);
static void _vala_array_add24 (FtAsyncCallback** * array,
                        gint* length,
                        gint* size,
                        FtAsyncCallback* value);
static void ft_session_manager_save_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_);
static void ft_session_manager_restore_session_data_free (gpointer _data);
static void ft_session_manager_restore_session (FtSessionManager* self,
                                         GomRepository* repository,
                                         FtSessionEntry* session_entry,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
static FtSession* ft_session_manager_restore_session_finish (FtSessionManager* self,
                                                      GAsyncResult* _res_,
                                                      GError** error);
static gboolean ft_session_manager_restore_session_co (FtSessionManagerRestoreSessionData* _data_);
static void ft_session_manager_restore_session_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
static void _vala_array_add25 (GomFilter** * array,
                        gint* length,
                        gint* size,
                        GomFilter* value);
static void __lambda55_ (FtSessionManager* self,
                  FtTimeBlock* time_block);
static void ___lambda55__gfunc (gconstpointer data,
                         gpointer self);
static void ft_session_manager_restore_data_free (gpointer _data);
static gboolean ft_session_manager_restore_co (FtSessionManagerRestoreData* _data_);
static Block48Data* block48_data_ref (Block48Data* _data48_);
static void block48_data_unref (void * _userdata_);
static void ft_session_manager_mark_timezone (FtSessionManager* self,
                                       GTimeZone* timezone,
                                       gint64 timestamp);
static void ft_session_manager_restore_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
static void ___lambda56_ (Block48Data* _data48_,
                   FtTimeBlock* time_block);
static void ____lambda56__gfunc (gconstpointer data,
                          gpointer self);
static void ____lambda57_ (Block48Data* _data48_,
                    FtGap* gap);
static void _____lambda57__gfunc (gconstpointer data,
                           gpointer self);
static void ft_session_manager_extend_current_time_block (FtSessionManager* self,
                                                   gboolean resume,
                                                   gint64 timestamp);
static void ft_session_manager_swap_current_state (FtSessionManager* self,
                                            FtState new_state,
                                            gint64 timestamp);
static Block49Data* block49_data_ref (Block49Data* _data49_);
static void block49_data_unref (void * _userdata_);
static void __lambda40_ (Block49Data* _data49_,
                  FtGap* gap);
static void ___lambda40__gfunc (gconstpointer data,
                         gpointer self);
static void ft_session_manager_update_time_block_meta (FtSessionManager* self,
                                                FtTimeBlock* time_block);
static gboolean ft_session_manager_is_current_session_completed (FtSessionManager* self,
                                                          gint64 timestamp);
static void ft_session_manager_advance_to_time_block (FtSessionManager* self,
                                               FtTimeBlock* time_block,
                                               gint64 timestamp);
static void ft_session_manager_bump_expiry_time (FtSessionManager* self,
                                          gint64 timeout);
static void ft_session_manager_on_current_session_notify_expiry_time (FtSessionManager* self);
static void ft_session_manager_expire_current_session (FtSessionManager* self,
                                                gint64 timestamp);
static gboolean ___lambda39_ (FtSessionManager* self);
static gboolean ____lambda39__gsource_func (gpointer self);
static gboolean ft_session_manager_should_auto_pause (FtSessionManager* self);
static gboolean ft_session_manager_should_auto_resume (FtSessionManager* self);
static gboolean ft_session_manager_should_auto_advance (FtSessionManager* self);
static void ft_session_manager_pause (FtSessionManager* self);
static void ft_session_manager_resume (FtSessionManager* self);
static void ft_session_manager_enable_auto_pause (FtSessionManager* self);
static void ft_session_manager_on_lockscreen_notify_active (FtSessionManager* self,
                                                     GObject* object,
                                                     GParamSpec* pspec);
static void _ft_session_manager_on_lockscreen_notify_active_g_object_notify (GObject* _sender,
                                                                      GParamSpec* pspec,
                                                                      gpointer self);
static void ft_session_manager_on_screensaver_notify_active (FtSessionManager* self,
                                                      GObject* object,
                                                      GParamSpec* pspec);
static void _ft_session_manager_on_screensaver_notify_active_g_object_notify (GObject* _sender,
                                                                       GParamSpec* pspec,
                                                                       gpointer self);
static void ft_session_manager_disable_auto_pause (FtSessionManager* self);
static void ft_session_manager_update_auto_pause (FtSessionManager* self);
static void ft_session_manager_update_current_time_block (FtSessionManager* self,
                                                   const FtTimerState* current_state,
                                                   const FtTimerState* previous_state,
                                                   gint64 timestamp);
static void ft_session_manager_resolve_timer_state (FtSessionManager* self,
                                             FtTimerState* state,
                                             gint64 timestamp);
static void ft_session_manager_on_timer_resolve_state (FtSessionManager* self,
                                                FtTimerState* state,
                                                gint64 timestamp);
static void ft_session_manager_on_timer_state_changed (FtSessionManager* self,
                                                const FtTimerState* current_state,
                                                const FtTimerState* previous_state);
static void ft_session_manager_on_timer_finished (FtSessionManager* self,
                                           const FtTimerState* state);
static void ft_session_manager_on_became_active (FtSessionManager* self);
static void _ft_session_manager_on_became_active_ft_callback (gpointer self);
static void ft_session_manager_on_timer_suspending (FtSessionManager* self,
                                             gint64 start_time);
static void ft_session_manager_on_timer_suspended (FtSessionManager* self,
                                            gint64 start_time,
                                            gint64 end_time);
static void ft_session_manager_on_current_time_block_changed (FtSessionManager* self,
                                                       FtTimeBlock* time_block);
static void ft_session_manager_on_scheduler_notify_session_template (FtSessionManager* self);
static void ft_session_manager_handle_became_active (FtSessionManager* self);
static void ft_session_manager_on_timezone_changed (FtSessionManager* self);
static guint ft_session_manager_setup_expiry_timeout (guint seconds,
                                               void* session_manager_ptr);
static Block50Data* block50_data_ref (Block50Data* _data50_);
static void block50_data_unref (void * _userdata_);
static gboolean __lambda41_ (Block50Data* _data50_);
static gboolean ___lambda41__gsource_func (gpointer self);
static void ft_session_manager_on_settings_changed (FtSessionManager* self,
                                             const gchar* key);
static void ft_session_manager_real_dispose (GObject* base);
static void _ft_session_manager_on_scheduler_notify_session_template_g_object_notify (GObject* _sender,
                                                                               GParamSpec* pspec,
                                                                               gpointer self);
static void _ft_session_manager_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self);
static void _ft_session_manager_on_timer_resolve_state_ft_timer_resolve_state (FtTimer* _sender,
                                                                        FtTimerState* state,
                                                                        gint64 timestamp,
                                                                        gpointer self);
static void _ft_session_manager_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                        const FtTimerState* current_state,
                                                                        const FtTimerState* previous_state,
                                                                        gpointer self);
static void _ft_session_manager_on_timer_finished_ft_timer_finished (FtTimer* _sender,
                                                              const FtTimerState* state,
                                                              gpointer self);
static void _ft_session_manager_on_timer_suspending_ft_timer_suspended (FtTimer* _sender,
                                                                 gint64 start_time,
                                                                 gint64 end_time,
                                                                 gpointer self);
static void _ft_session_manager_on_timer_suspended_ft_timer_suspended (FtTimer* _sender,
                                                                gint64 start_time,
                                                                gint64 end_time,
                                                                gpointer self);
static void _ft_session_manager_on_current_session_notify_expiry_time_g_object_notify (GObject* _sender,
                                                                                GParamSpec* pspec,
                                                                                gpointer self);
static void _ft_session_manager_on_current_time_block_changed_ft_time_block_changed (FtTimeBlock* _sender,
                                                                              gpointer self);
VALA_EXTERN gboolean ft_is_test (void);
static void g_cclosure_user_marshal_VOID__OBJECT_INT64 (GClosure * closure,
                                                 GValue * return_value,
                                                 guint n_param_values,
                                                 const GValue * param_values,
                                                 gpointer invocation_hint,
                                                 gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure * closure,
                                                  GValue * return_value,
                                                  guint n_param_values,
                                                  const GValue * param_values,
                                                  gpointer invocation_hint,
                                                  gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT_OBJECT (GClosure * closure,
                                                                GValue * return_value,
                                                                guint n_param_values,
                                                                const GValue * param_values,
                                                                gpointer invocation_hint,
                                                                gpointer marshal_data);
static GObject * ft_session_manager_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties);
static void _ft_session_manager_on_timezone_changed_ft_time_zone_monitor_changed (FtTimeZoneMonitor* _sender,
                                                                           gpointer self);
static void ft_session_manager_finalize (GObject * obj);
static GType ft_session_manager_get_type_once (void);
static void _vala_ft_session_manager_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_ft_session_manager_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GType
ft_advancement_mode_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_ADVANCEMENT_MODE_CONTINUOUS, "FT_ADVANCEMENT_MODE_CONTINUOUS", "continuous"}, {FT_ADVANCEMENT_MODE_CONFIRM, "FT_ADVANCEMENT_MODE_CONFIRM", "confirm"}, {FT_ADVANCEMENT_MODE_WAIT_FOR_ACTIVITY, "FT_ADVANCEMENT_MODE_WAIT_FOR_ACTIVITY", "wait-for-activity"}, {0, NULL, NULL}};
	GType ft_advancement_mode_type_id;
	ft_advancement_mode_type_id = g_enum_register_static ("FtAdvancementMode", values);
	return ft_advancement_mode_type_id;
}

GType
ft_advancement_mode_get_type (void)
{
	static volatile gsize ft_advancement_mode_type_id__once = 0;
	if (g_once_init_enter (&ft_advancement_mode_type_id__once)) {
		GType ft_advancement_mode_type_id;
		ft_advancement_mode_type_id = ft_advancement_mode_get_type_once ();
		g_once_init_leave (&ft_advancement_mode_type_id__once, ft_advancement_mode_type_id);
	}
	return ft_advancement_mode_type_id__once;
}

static inline gpointer
ft_session_manager_get_instance_private (FtSessionManager* self)
{
	return G_STRUCT_MEMBER_P (self, FtSessionManager_private_offset);
}

FtSessionManager*
ft_session_manager_construct (GType object_type)
{
	FtSessionManager * self = NULL;
	FtTimer* _tmp0_;
	_tmp0_ = ft_timer_get_default ();
	self = (FtSessionManager*) g_object_new (object_type, "timer", _tmp0_, NULL);
	return self;
}

FtSessionManager*
ft_session_manager_new (void)
{
	return ft_session_manager_construct (FT_TYPE_SESSION_MANAGER);
}

FtSessionManager*
ft_session_manager_construct_with_timer (GType object_type,
                                         FtTimer* timer)
{
	FtSessionManager * self = NULL;
	g_return_val_if_fail (timer != NULL, NULL);
	self = (FtSessionManager*) g_object_new (object_type, "timer", timer, NULL);
	return self;
}

FtSessionManager*
ft_session_manager_new_with_timer (FtTimer* timer)
{
	return ft_session_manager_construct_with_timer (FT_TYPE_SESSION_MANAGER, timer);
}

/**
         * Sets a default `SessionManager`.
         *
         * The old default manager is unreffed and the new manager referenced.
         *
         * A value of null for this will cause the current default manager to be released and a new default manager
         * to be created on demand.
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

void
ft_session_manager_set_default (FtSessionManager* session_manager)
{
	FtSessionManager* _tmp0_;
	_tmp0_ = _g_object_ref0 (session_manager);
	_g_object_unref0 (ft_session_manager_instance);
	ft_session_manager_instance = _tmp0_;
}

/**
         * Return a default manager.
         *
         * A new default manager will be created on demand.
         */
FtSessionManager*
ft_session_manager_get_default (void)
{
	FtSessionManager* _tmp0_;
	FtSessionManager* _tmp3_;
	FtSessionManager* result;
	_tmp0_ = ft_session_manager_instance;
	if (_tmp0_ == NULL) {
		FtSessionManager* _tmp1_;
		FtSessionManager* _tmp2_;
		_tmp1_ = ft_session_manager_new ();
		_tmp2_ = _tmp1_;
		ft_session_manager_set_default (_tmp2_);
		_g_object_unref0 (_tmp2_);
	}
	_tmp3_ = ft_session_manager_instance;
	result = _tmp3_;
	return result;
}

static gint64
ft_session_manager_get_current_time (FtSessionManager* self)
{
	gint64 _tmp0_ = 0LL;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	if (self->priv->resolving_timer_state > 0) {
		FtTimer* _tmp1_;
		_tmp1_ = self->priv->_timer;
		_tmp0_ = ft_timer_get_last_state_changed_time (_tmp1_);
	} else {
		FtTimer* _tmp2_;
		_tmp2_ = self->priv->_timer;
		_tmp0_ = ft_timer_get_current_time (_tmp2_, FT_TIMESTAMP_UNDEFINED);
	}
	result = _tmp0_;
	return result;
}

static FtSession*
ft_session_manager_initialize_next_session (FtSessionManager* self,
                                            gint64 timestamp)
{
	FtSession* next_session = NULL;
	FtSession* _tmp0_;
	FtSession* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_debug ("session-manager.vala:263: Initializing new session...");
	_tmp0_ = ft_session_new ();
	next_session = _tmp0_;
	ft_session_manager_reschedule_full (self, next_session, NULL, FALSE, timestamp);
	result = next_session;
	return result;
}

static FtTimeBlock*
ft_session_manager_initialize_next_time_block (FtSessionManager* self,
                                               gint64 timestamp)
{
	FtTimeBlock* next_time_block = NULL;
	FtSession* next_session = NULL;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	FtTimeBlock* _tmp2_;
	gboolean _tmp18_ = FALSE;
	FtSession* _tmp19_;
	FtSession* _tmp21_;
	gboolean _tmp49_ = FALSE;
	FtSession* _tmp50_;
	FtTimeBlock* _tmp56_;
	FtTimeBlock* _tmp57_;
	FtSession* _tmp58_;
	FtSession* _tmp59_;
	FtSession* _tmp60_;
	FtSession* _tmp61_;
	FtSession* _tmp62_;
	FtTimeBlock* _tmp63_;
	FtTimeBlock* _tmp64_;
	FtTimeBlock* result;
	g_return_val_if_fail (self != NULL, NULL);
	next_time_block = NULL;
	next_session = NULL;
	_tmp2_ = self->priv->_current_time_block;
	if (_tmp2_ != NULL) {
		FtTimeBlock* _tmp3_;
		FtState _tmp4_;
		FtState _tmp5_;
		_tmp3_ = self->priv->_current_time_block;
		_tmp4_ = ft_time_block_get_state (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ == FT_STATE_LONG_BREAK;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		FtScheduler* _tmp6_;
		FtTimeBlock* _tmp7_;
		_tmp6_ = self->priv->_scheduler;
		_tmp7_ = self->priv->_current_time_block;
		_tmp0_ = !ft_scheduler_is_time_block_completed (_tmp6_, _tmp7_, timestamp);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		FtSession* _tmp8_;
		FtSession* _tmp9_;
		_g_object_unref0 (next_time_block);
		next_time_block = NULL;
		_tmp8_ = self->priv->_current_session;
		_tmp9_ = _g_object_ref0 (_tmp8_);
		_g_object_unref0 (next_session);
		next_session = _tmp9_;
	} else {
		FtTimeBlock* _tmp10_;
		FtTimeBlock* _tmp11_;
		FtSession* _tmp12_ = NULL;
		FtTimeBlock* _tmp13_;
		FtSession* _tmp17_;
		_tmp10_ = ft_session_manager_get_next_time_block (self);
		_tmp11_ = _g_object_ref0 (_tmp10_);
		_g_object_unref0 (next_time_block);
		next_time_block = _tmp11_;
		_tmp13_ = next_time_block;
		if (_tmp13_ != NULL) {
			FtTimeBlock* _tmp14_;
			FtSession* _tmp15_;
			FtSession* _tmp16_;
			_tmp14_ = next_time_block;
			_tmp15_ = ft_time_block_get_session (_tmp14_);
			_tmp16_ = _tmp15_;
			_tmp12_ = _tmp16_;
		} else {
			_tmp12_ = NULL;
		}
		_tmp17_ = _g_object_ref0 (_tmp12_);
		_g_object_unref0 (next_session);
		next_session = _tmp17_;
	}
	_tmp19_ = next_session;
	if (_tmp19_ != NULL) {
		FtSession* _tmp20_;
		_tmp20_ = next_session;
		_tmp18_ = ft_session_is_expired (_tmp20_, timestamp);
	} else {
		_tmp18_ = FALSE;
	}
	if (_tmp18_) {
		_g_object_unref0 (next_session);
		next_session = NULL;
	}
	_tmp21_ = next_session;
	if (_tmp21_ != NULL) {
		FtSession* _tmp22_;
		gboolean _tmp23_ = FALSE;
		FtTimeBlock* _tmp24_;
		FtSession* _tmp35_;
		FtTimeBlock* _tmp36_;
		FtTimeBlock* _tmp37_;
		FtSession* _tmp38_;
		FtTimeBlock* _tmp39_;
		_tmp22_ = next_session;
		ft_session_freeze_changed (_tmp22_);
		_tmp24_ = next_time_block;
		if (_tmp24_ != NULL) {
			FtTimeBlock* _tmp25_;
			FtState _tmp26_;
			FtState _tmp27_;
			_tmp25_ = next_time_block;
			_tmp26_ = ft_time_block_get_state (_tmp25_);
			_tmp27_ = _tmp26_;
			_tmp23_ = ft_state_is_break (_tmp27_);
		} else {
			_tmp23_ = FALSE;
		}
		if (_tmp23_) {
			FtState next_state = 0;
			FtTimeBlock* _tmp29_;
			FtTimeBlock* _tmp30_;
			FtScheduler* _tmp31_;
			FtScheduler* _tmp32_;
			FtSessionTemplate _tmp33_ = {0};
			FtSessionTemplate _tmp34_;
			next_state = FT_STATE_BREAK;
			if (!self->priv->_has_uniform_breaks) {
				FtState _tmp28_ = 0;
				if (ft_session_manager_is_long_break_needed (self, timestamp)) {
					_tmp28_ = FT_STATE_LONG_BREAK;
				} else {
					_tmp28_ = FT_STATE_SHORT_BREAK;
				}
				next_state = _tmp28_;
			}
			_tmp29_ = next_time_block;
			ft_time_block_set_state_internal (_tmp29_, next_state);
			_tmp30_ = next_time_block;
			_tmp31_ = ft_session_manager_get_scheduler (self);
			_tmp32_ = _tmp31_;
			ft_scheduler_get_session_template (_tmp32_, &_tmp33_);
			_tmp34_ = _tmp33_;
			ft_schedulable_set_duration ((FtSchedulable*) _tmp30_, ft_session_template_get_duration (&_tmp34_, next_state));
		}
		_tmp35_ = next_session;
		_tmp36_ = next_time_block;
		_tmp37_ = next_time_block;
		ft_session_manager_reschedule_full (self, _tmp35_, _tmp36_, _tmp37_ != NULL, timestamp);
		_tmp38_ = next_session;
		ft_session_thaw_changed (_tmp38_);
		_tmp39_ = next_time_block;
		if (_tmp39_ == NULL) {
			FtTimeBlock* _tmp40_ = NULL;
			FtSession* _tmp41_;
			FtSession* _tmp42_;
			FtTimeBlock* _tmp48_;
			_tmp41_ = next_session;
			_tmp42_ = self->priv->_current_session;
			if (_tmp41_ == _tmp42_) {
				FtSession* _tmp43_;
				FtTimeBlock* _tmp44_;
				FtTimeBlock* _tmp45_;
				_tmp43_ = next_session;
				_tmp44_ = self->priv->_current_time_block;
				_tmp45_ = ft_session_get_next_time_block (_tmp43_, _tmp44_);
				_tmp40_ = _tmp45_;
			} else {
				FtSession* _tmp46_;
				FtTimeBlock* _tmp47_;
				_tmp46_ = next_session;
				_tmp47_ = ft_session_get_first_time_block (_tmp46_);
				_tmp40_ = _tmp47_;
			}
			_tmp48_ = _g_object_ref0 (_tmp40_);
			_g_object_unref0 (next_time_block);
			next_time_block = _tmp48_;
		}
	}
	_tmp50_ = next_session;
	if (_tmp50_ == NULL) {
		_tmp49_ = TRUE;
	} else {
		FtTimeBlock* _tmp51_;
		_tmp51_ = next_time_block;
		_tmp49_ = _tmp51_ == NULL;
	}
	if (_tmp49_) {
		FtSession* _tmp52_;
		FtSession* _tmp53_;
		FtTimeBlock* _tmp54_;
		FtTimeBlock* _tmp55_;
		_tmp52_ = ft_session_manager_initialize_next_session (self, timestamp);
		_g_object_unref0 (next_session);
		next_session = _tmp52_;
		_tmp53_ = next_session;
		_tmp54_ = ft_session_get_first_time_block (_tmp53_);
		_tmp55_ = _g_object_ref0 (_tmp54_);
		_g_object_unref0 (next_time_block);
		next_time_block = _tmp55_;
	}
	_tmp56_ = next_time_block;
	_vala_assert (_tmp56_ != NULL, "next_time_block != null");
	_tmp57_ = next_time_block;
	_tmp58_ = ft_time_block_get_session (_tmp57_);
	_tmp59_ = _tmp58_;
	_tmp60_ = next_session;
	_vala_assert (_tmp59_ == _tmp60_, "next_time_block.session == next_session");
	_tmp61_ = next_session;
	_tmp62_ = _g_object_ref0 (_tmp61_);
	_g_object_unref0 (self->priv->next_session);
	self->priv->next_session = _tmp62_;
	_tmp63_ = next_time_block;
	_tmp64_ = _g_object_ref0 (_tmp63_);
	_g_object_unref0 (self->priv->next_time_block);
	self->priv->next_time_block = _tmp64_;
	result = next_time_block;
	_g_object_unref0 (next_session);
	return result;
}

/**
         * Builds a `TimerState` according to current time-block.
         */
static void
ft_session_manager_initialize_timer_state (FtSessionManager* self,
                                           FtTimerState* state,
                                           gint64 timestamp)
{
	FtTimeBlock* current_time_block = NULL;
	FtTimeBlock* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtGap* current_gap = NULL;
	FtGap* _tmp2_;
	FtGap* _tmp3_;
	FtTimeBlock* _tmp4_;
	gint64 _tmp5_ = 0LL;
	gboolean _tmp6_ = FALSE;
	FtGap* _tmp7_;
	gint64 paused_time = 0LL;
	FtTimeBlock* _tmp14_;
	gint64 _tmp15_;
	gint64 _tmp16_;
	FtTimeBlock* _tmp17_;
	gint64 _tmp18_;
	gint64 _tmp19_;
	FtTimeBlock* _tmp45_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (state != NULL);
	_tmp0_ = self->priv->_current_time_block;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	current_time_block = _tmp1_;
	_tmp2_ = self->priv->_current_gap;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	current_gap = _tmp3_;
	_tmp4_ = current_time_block;
	if (_tmp4_ == NULL) {
		ft_timer_state_init (state);
		_g_object_unref0 (current_gap);
		_g_object_unref0 (current_time_block);
		return;
	}
	_tmp7_ = current_gap;
	if (_tmp7_ != NULL) {
		FtGap* _tmp8_;
		gint64 _tmp9_;
		gint64 _tmp10_;
		_tmp8_ = current_gap;
		_tmp9_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp8_);
		_tmp10_ = _tmp9_;
		_tmp6_ = ft_timestamp_is_undefined (_tmp10_);
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		FtGap* _tmp11_;
		gint64 _tmp12_;
		gint64 _tmp13_;
		_tmp11_ = current_gap;
		_tmp12_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp11_);
		_tmp13_ = _tmp12_;
		_tmp5_ = _tmp13_;
	} else {
		_tmp5_ = FT_TIMESTAMP_UNDEFINED;
	}
	paused_time = _tmp5_;
	if (ft_timestamp_is_defined (paused_time)) {
		timestamp = paused_time;
	}
	_tmp14_ = current_time_block;
	_tmp15_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = current_time_block;
	_tmp18_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp17_);
	_tmp19_ = _tmp18_;
	timestamp = CLAMP (timestamp, _tmp16_, _tmp19_);
	if (!ft_session_manager_is_waiting_for_activity (self)) {
		FtTimeBlock* _tmp20_;
		gint64 _tmp21_;
		gint64 _tmp22_;
		gint64 elapsed = 0LL;
		FtTimeBlock* _tmp23_;
		FtTimeBlock* _tmp24_;
		gint64 _tmp25_;
		gint64 _tmp26_;
		FtTimeBlock* _tmp27_;
		gint64 _tmp28_;
		gint64 _tmp29_;
		FtTimerState _tmp30_;
		FtTimeBlock* _tmp31_;
		gint64 _tmp32_;
		gint64 _tmp33_;
		gboolean _tmp34_ = FALSE;
		FtTimeBlock* _tmp35_;
		gint64 _tmp36_;
		gint64 _tmp37_;
		_tmp20_ = current_time_block;
		_tmp21_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp20_);
		_tmp22_ = _tmp21_;
		_vala_assert (ft_timestamp_is_defined (_tmp22_), "Ft.Timestamp.is_defined (current_time_block.start_time)");
		_tmp23_ = current_time_block;
		elapsed = ft_time_block_calculate_elapsed (_tmp23_, timestamp);
		_tmp24_ = current_time_block;
		_tmp25_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp24_);
		_tmp26_ = _tmp25_;
		(*state).offset = (timestamp - _tmp26_) - elapsed;
		_tmp27_ = current_time_block;
		_tmp28_ = ft_schedulable_get_duration ((FtSchedulable*) _tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = *state;
		(*state).duration = _tmp29_ - _tmp30_.offset;
		_tmp31_ = current_time_block;
		_tmp32_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp31_);
		_tmp33_ = _tmp32_;
		(*state).started_time = _tmp33_;
		(*state).paused_time = paused_time;
		(*state).finished_time = FT_TIMESTAMP_UNDEFINED;
		_tmp35_ = current_time_block;
		_tmp36_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp35_);
		_tmp37_ = _tmp36_;
		if (timestamp >= _tmp37_) {
			_tmp34_ = ft_timestamp_is_undefined (paused_time);
		} else {
			_tmp34_ = FALSE;
		}
		if (_tmp34_) {
			FtTimeBlock* _tmp38_;
			gint64 _tmp39_;
			gint64 _tmp40_;
			_tmp38_ = current_time_block;
			_tmp39_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp38_);
			_tmp40_ = _tmp39_;
			(*state).finished_time = _tmp40_;
		}
	} else {
		FtGap* _tmp41_;
		FtTimeBlock* _tmp42_;
		gint64 _tmp43_;
		gint64 _tmp44_;
		_tmp41_ = current_gap;
		_vala_assert (_tmp41_ == NULL, "current_gap == null");
		(*state).offset = (gint64) 0;
		_tmp42_ = current_time_block;
		_tmp43_ = ft_schedulable_get_duration ((FtSchedulable*) _tmp42_);
		_tmp44_ = _tmp43_;
		(*state).duration = _tmp44_;
		(*state).started_time = FT_TIMESTAMP_UNDEFINED;
		(*state).paused_time = FT_TIMESTAMP_UNDEFINED;
		(*state).finished_time = FT_TIMESTAMP_UNDEFINED;
	}
	_tmp45_ = current_time_block;
	(*state).user_data = _tmp45_;
	_g_object_unref0 (current_gap);
	_g_object_unref0 (current_time_block);
}

static void
ft_session_manager_update_session_template (FtSessionManager* self)
{
	FtScheduler* _tmp0_;
	FtSessionTemplate _tmp1_ = {0};
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_scheduler;
	ft_session_template_init_with_defaults (&_tmp1_);
	ft_scheduler_set_session_template (_tmp0_, &_tmp1_);
}

static void
ft_session_manager_update_timer_state (FtSessionManager* self,
                                       gint64 timestamp)
{
	FtTimeBlock* _tmp0_;
	g_return_if_fail (self != NULL);
	if (self->priv->resolving_timer_state != 0) {
		return;
	}
	_tmp0_ = self->priv->_current_time_block;
	if (_tmp0_ != NULL) {
		FtTimerState state = {0};
		FtTimer* _tmp1_;
		FtTimerState _tmp2_;
		ft_timer_state_init (&state);
		ft_session_manager_initialize_timer_state (self, &state, timestamp);
		_tmp1_ = self->priv->_timer;
		_tmp2_ = state;
		ft_timer_set_state_full (_tmp1_, &_tmp2_, timestamp);
	} else {
		FtTimer* _tmp3_;
		_tmp3_ = self->priv->_timer;
		ft_timer_reset (_tmp3_, (gint64) 0, NULL, timestamp);
	}
}

static void
ft_session_manager_update_has_uniform_breaks (FtSessionManager* self)
{
	gboolean has_uniform_breaks = FALSE;
	FtScheduler* _tmp0_;
	FtSessionTemplate _tmp1_ = {0};
	FtSessionTemplate _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	FtTimeBlock* _tmp5_;
	gboolean _tmp10_ = FALSE;
	gboolean _tmp11_ = FALSE;
	FtTimeBlock* _tmp12_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_scheduler;
	ft_scheduler_get_session_template (_tmp0_, &_tmp1_);
	_tmp2_ = _tmp1_;
	has_uniform_breaks = ft_session_template_has_uniform_breaks (&_tmp2_);
	if (has_uniform_breaks != self->priv->_has_uniform_breaks) {
		self->priv->_has_uniform_breaks = has_uniform_breaks;
		g_object_notify ((GObject*) self, "has-uniform-breaks");
	}
	_tmp5_ = self->priv->_current_time_block;
	if (_tmp5_ != NULL) {
		FtTimeBlock* _tmp6_;
		FtState _tmp7_;
		FtState _tmp8_;
		_tmp6_ = self->priv->_current_time_block;
		_tmp7_ = ft_time_block_get_state (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_ == FT_STATE_BREAK;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = !has_uniform_breaks;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		FtTimeBlock* _tmp9_;
		_tmp9_ = self->priv->_current_time_block;
		ft_time_block_set_state_internal (_tmp9_, FT_STATE_SHORT_BREAK);
	}
	_tmp12_ = self->priv->_current_time_block;
	if (_tmp12_ != NULL) {
		FtTimeBlock* _tmp13_;
		FtState _tmp14_;
		FtState _tmp15_;
		_tmp13_ = self->priv->_current_time_block;
		_tmp14_ = ft_time_block_get_state (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp11_ = _tmp15_ == FT_STATE_SHORT_BREAK;
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		_tmp10_ = has_uniform_breaks;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		FtTimeBlock* _tmp16_;
		_tmp16_ = self->priv->_current_time_block;
		ft_time_block_set_state_internal (_tmp16_, FT_STATE_BREAK);
	}
}

static FtTimeBlock*
ft_session_manager_schedule_pomodoro (FtSessionManager* self,
                                      gint64 timestamp)
{
	FtSession* _tmp0_;
	FtSchedulerContext context = {0};
	FtTimeBlock* next_time_block = NULL;
	GList* link = NULL;
	FtSession* _tmp1_;
	GList* _tmp2_;
	GList* _tmp3_;
	FtTimeBlock* _tmp16_;
	FtTimeBlock* _tmp34_;
	FtTimeBlock* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_session;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this._current_session != null", NULL);
	next_time_block = NULL;
	_tmp1_ = self->priv->_current_session;
	_tmp2_ = _tmp1_->time_blocks;
	_tmp3_ = g_list_first (_tmp2_);
	link = _tmp3_;
	while (TRUE) {
		GList* _tmp4_;
		gboolean _tmp5_ = FALSE;
		GList* _tmp6_;
		gconstpointer _tmp7_;
		GList* _tmp14_;
		GList* _tmp15_;
		_tmp4_ = link;
		if (!(_tmp4_ != NULL)) {
			break;
		}
		_tmp6_ = link;
		_tmp7_ = _tmp6_->data;
		if (ft_time_block_get_status ((FtTimeBlock*) _tmp7_) == FT_TIME_BLOCK_STATUS_SCHEDULED) {
			GList* _tmp8_;
			gconstpointer _tmp9_;
			FtState _tmp10_;
			FtState _tmp11_;
			_tmp8_ = link;
			_tmp9_ = _tmp8_->data;
			_tmp10_ = ft_time_block_get_state ((FtTimeBlock*) _tmp9_);
			_tmp11_ = _tmp10_;
			_tmp5_ = _tmp11_ == FT_STATE_POMODORO;
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			GList* _tmp12_;
			gconstpointer _tmp13_;
			_tmp12_ = link;
			_tmp13_ = _tmp12_->data;
			next_time_block = (FtTimeBlock*) _tmp13_;
			break;
		}
		_tmp14_ = link;
		_tmp15_ = _tmp14_->next;
		link = _tmp15_;
	}
	_tmp16_ = next_time_block;
	if (_tmp16_ == NULL) {
		FtScheduler* _tmp17_;
		FtSession* _tmp18_;
		FtSchedulerContext _tmp19_ = {0};
		GList* _tmp20_ = NULL;
		FtTimeBlock* resolved_time_block = NULL;
		FtScheduler* _tmp21_;
		FtSchedulerContext _tmp22_;
		FtTimeBlock* _tmp23_;
		GList* _tmp24_;
		FtTimeBlock* _tmp31_;
		_tmp17_ = self->priv->_scheduler;
		_tmp18_ = self->priv->_current_session;
		ft_scheduler_build_scheduler_context (_tmp17_, _tmp18_, TRUE, timestamp, &_tmp19_, &_tmp20_);
		context = _tmp19_;
		link = _tmp20_;
		context.timestamp = timestamp;
		context.state = FT_STATE_STOPPED;
		_tmp21_ = self->priv->_scheduler;
		_tmp22_ = context;
		_tmp23_ = ft_scheduler_resolve_time_block (_tmp21_, &_tmp22_);
		resolved_time_block = _tmp23_;
		_tmp24_ = link;
		if (_tmp24_ != NULL) {
			FtSession* _tmp25_;
			FtTimeBlock* _tmp26_;
			GList* _tmp27_;
			gconstpointer _tmp28_;
			_tmp25_ = self->priv->_current_session;
			_tmp26_ = resolved_time_block;
			_tmp27_ = link;
			_tmp28_ = _tmp27_->data;
			ft_session_insert_before (_tmp25_, _tmp26_, (FtTimeBlock*) _tmp28_);
		} else {
			FtSession* _tmp29_;
			FtTimeBlock* _tmp30_;
			_tmp29_ = self->priv->_current_session;
			_tmp30_ = resolved_time_block;
			ft_session_append (_tmp29_, _tmp30_);
		}
		_tmp31_ = resolved_time_block;
		next_time_block = _tmp31_;
		_g_object_unref0 (resolved_time_block);
	} else {
		FtScheduler* _tmp32_;
		FtTimeBlock* _tmp33_;
		_tmp32_ = self->priv->_scheduler;
		_tmp33_ = next_time_block;
		ft_scheduler_reschedule_time_block (_tmp32_, _tmp33_, timestamp);
	}
	_tmp34_ = next_time_block;
	result = _tmp34_;
	return result;
}

/**
         * Reschedule session having a pre-selected upcoming time-block.
         */
static void
ft_session_manager_reschedule_full (FtSessionManager* self,
                                    FtSession* session,
                                    FtTimeBlock* next_time_block,
                                    gboolean next_time_block_set,
                                    gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_ = FALSE;
	gboolean rescheduled = FALSE;
	FtScheduler* _tmp16_;
	gboolean _tmp17_ = FALSE;
	FtSession* _tmp18_;
	g_return_if_fail (self != NULL);
	_vala_return_if_fail (next_time_block_set || (next_time_block == NULL), "next_time_block_set || next_time_block == null");
	if (session == NULL) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_session_is_completed (session);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		FtScheduler* _tmp2_;
		_tmp2_ = self->priv->_scheduler;
		_tmp0_ = _tmp2_ == NULL;
	}
	if (_tmp0_) {
		return;
	}
	if (next_time_block_set) {
		_tmp4_ = next_time_block != NULL;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = ft_time_block_get_status (next_time_block) != FT_TIME_BLOCK_STATUS_SCHEDULED;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		next_time_block_set = FALSE;
		next_time_block = NULL;
	}
	if (ft_timestamp_is_undefined (timestamp)) {
		timestamp = ft_session_manager_get_current_time (self);
	}
	ft_session_freeze_changed (session);
	if (next_time_block_set) {
		_tmp6_ = next_time_block == NULL;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		FtSession* _tmp7_;
		_tmp7_ = self->priv->_current_session;
		_tmp5_ = session == _tmp7_;
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		FtTimeBlock* scheduled_time_block = NULL;
		FtTimeBlock* _tmp8_;
		FtTimeBlock* _tmp9_;
		gboolean _tmp10_ = FALSE;
		FtTimeBlock* _tmp11_;
		_tmp8_ = ft_session_manager_get_next_time_block (self);
		_tmp9_ = _g_object_ref0 (_tmp8_);
		scheduled_time_block = _tmp9_;
		_tmp11_ = scheduled_time_block;
		if (_tmp11_ == NULL) {
			_tmp10_ = TRUE;
		} else {
			FtTimeBlock* _tmp12_;
			FtState _tmp13_;
			FtState _tmp14_;
			_tmp12_ = scheduled_time_block;
			_tmp13_ = ft_time_block_get_state (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp10_ = _tmp14_ != FT_STATE_POMODORO;
		}
		if (_tmp10_) {
			FtTimeBlock* _tmp15_;
			_tmp15_ = ft_session_manager_schedule_pomodoro (self, timestamp);
			next_time_block = _tmp15_;
		}
		_g_object_unref0 (scheduled_time_block);
	}
	_tmp16_ = self->priv->_scheduler;
	rescheduled = ft_scheduler_reschedule_session (_tmp16_, session, next_time_block, next_time_block_set, timestamp);
	_tmp18_ = self->priv->_current_session;
	if (session == _tmp18_) {
		_tmp17_ = rescheduled;
	} else {
		_tmp17_ = FALSE;
	}
	if (_tmp17_) {
		ft_session_manager_emit_session_rescheduled (self, timestamp);
	}
	ft_session_thaw_changed (session);
}

/**
         * Try reschedule current session.
         */
static void
ft_session_manager_reschedule (FtSessionManager* self)
{
	FtSession* _tmp0_;
	gint64 _tmp1_ = 0LL;
	FtTimeBlock* _tmp2_;
	gint64 timestamp = 0LL;
	FtSession* _tmp6_;
	g_return_if_fail (self != NULL);
	if (self->priv->reschedule_idle_id != ((guint) 0)) {
		g_source_remove (self->priv->reschedule_idle_id);
		self->priv->reschedule_idle_id = (guint) 0;
	}
	_tmp0_ = self->priv->_current_session;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp2_ = self->priv->_current_time_block;
	if (_tmp2_ != NULL) {
		FtTimeBlock* _tmp3_;
		gint64 _tmp4_;
		gint64 _tmp5_;
		_tmp3_ = self->priv->_current_time_block;
		_tmp4_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_;
	} else {
		_tmp1_ = ft_session_manager_get_current_time (self);
	}
	timestamp = _tmp1_;
	_tmp6_ = self->priv->_current_session;
	ft_session_manager_reschedule_full (self, _tmp6_, NULL, FALSE, timestamp);
}

/**
         * Try reschedule current session, if it was queued.
         */
static void
ft_session_manager_reschedule_if_queued (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->reschedule_idle_id != ((guint) 0)) {
		ft_session_manager_reschedule (self);
	}
}

static gboolean
__lambda38_ (FtSessionManager* self)
{
	gboolean result;
	self->priv->reschedule_idle_id = (guint) 0;
	ft_session_manager_reschedule (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda38__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda38_ ((FtSessionManager*) self);
	return result;
}

static void
ft_session_manager_queue_reschedule (FtSessionManager* self)
{
	FtSession* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_current_session;
	if (_tmp0_ == NULL) {
		return;
	}
	if (self->priv->reschedule_idle_id != ((guint) 0)) {
		return;
	}
	self->priv->reschedule_idle_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, ___lambda38__gsource_func, g_object_ref (self), g_object_unref);
	g_source_set_name_by_id (self->priv->reschedule_idle_id, "Ft.SessionManager.reschedule");
}

/**
         * Set current time-block.
         *
         * It may ignore given session if it's completed.
         */
static void
ft_session_manager_set_current_time_block_full (FtSessionManager* self,
                                                FtSession* session,
                                                FtTimeBlock* time_block,
                                                gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	gboolean _tmp3_ = FALSE;
	FtSession* previous_session = NULL;
	FtSession* _tmp4_;
	FtSession* _tmp5_;
	FtTimeBlock* previous_time_block = NULL;
	FtTimeBlock* _tmp6_;
	FtTimeBlock* _tmp7_;
	FtGap* previous_gap = NULL;
	FtGap* _tmp8_;
	FtGap* _tmp9_;
	FtState previous_state = 0;
	FtState _tmp10_ = 0;
	FtState state = 0;
	FtTimeBlock* _tmp13_ = NULL;
	FtGap* _tmp14_ = NULL;
	FtGap* gap = NULL;
	FtGap* _tmp16_;
	gboolean _tmp17_ = FALSE;
	FtGap* _tmp18_;
	FtTimeBlock* _tmp22_;
	gboolean _tmp34_ = FALSE;
	gboolean _tmp35_ = FALSE;
	FtSession* _tmp36_;
	FtSession* _tmp52_;
	FtTimeBlock* _tmp60_;
	FtSession* _tmp67_;
	FtTimeBlock* _tmp68_;
	FtTimeBlock* _tmp69_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_current_session;
	if (session == _tmp1_) {
		FtTimeBlock* _tmp2_;
		_tmp2_ = self->priv->_current_time_block;
		_tmp0_ = time_block == _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	ft_ensure_timestamp (&timestamp);
	if (session != NULL) {
		_tmp3_ = ft_session_is_expired (session, timestamp);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		g_debug ("session-manager.vala:629: set_current_time_block_full: setting an expi" \
"red session");
	}
	_tmp4_ = self->priv->_current_session;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	previous_session = _tmp5_;
	_tmp6_ = self->priv->_current_time_block;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	previous_time_block = _tmp7_;
	_tmp8_ = self->priv->_current_gap;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	previous_gap = _tmp9_;
	previous_state = self->priv->_current_state;
	if (time_block != NULL) {
		FtState _tmp11_;
		FtState _tmp12_;
		_tmp11_ = ft_time_block_get_state (time_block);
		_tmp12_ = _tmp11_;
		_tmp10_ = _tmp12_;
	} else {
		_tmp10_ = FT_STATE_STOPPED;
	}
	state = _tmp10_;
	_tmp13_ = time_block;
	_tmp14_ = NULL;
	if (_tmp13_ != NULL) {
		FtGap* _tmp15_;
		_tmp15_ = ft_time_block_get_last_gap (_tmp13_);
		_tmp14_ = _tmp15_;
	}
	_tmp16_ = _g_object_ref0 (_tmp14_);
	gap = _tmp16_;
	_tmp18_ = gap;
	if (_tmp18_ != NULL) {
		FtGap* _tmp19_;
		gint64 _tmp20_;
		gint64 _tmp21_;
		_tmp19_ = gap;
		_tmp20_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp19_);
		_tmp21_ = _tmp20_;
		_tmp17_ = ft_timestamp_is_defined (_tmp21_);
	} else {
		_tmp17_ = FALSE;
	}
	if (_tmp17_) {
		_g_object_unref0 (gap);
		gap = NULL;
	}
	ft_session_manager_freeze_current_session_changed (self);
	_tmp22_ = previous_time_block;
	if (_tmp22_ != NULL) {
		FtGap* _tmp24_;
		FtTimeBlock* _tmp26_;
		gboolean _tmp29_ = FALSE;
		FtTimeBlock* _tmp30_;
		FtTimeBlock* _tmp31_;
		if (self->priv->current_time_block_changed_id != ((gulong) 0)) {
			FtTimeBlock* _tmp23_;
			_tmp23_ = previous_time_block;
			g_signal_handler_block (_tmp23_, self->priv->current_time_block_changed_id);
		}
		_tmp24_ = previous_gap;
		if (_tmp24_ != NULL) {
			FtGap* _tmp25_;
			_tmp25_ = previous_gap;
			ft_session_manager_mark_gap_end (self, _tmp25_, timestamp);
		}
		_tmp26_ = previous_time_block;
		if (ft_time_block_get_status (_tmp26_) == FT_TIME_BLOCK_STATUS_IN_PROGRESS) {
			FtTimeBlock* _tmp27_;
			_tmp27_ = previous_time_block;
			ft_session_manager_mark_time_block_end (self, _tmp27_, timestamp);
		}
		if (self->priv->current_time_block_entered) {
			FtTimeBlock* _tmp28_;
			_tmp28_ = previous_time_block;
			g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_LEAVE_TIME_BLOCK_SIGNAL], 0, _tmp28_);
		}
		_tmp30_ = self->priv->_current_time_block;
		_tmp31_ = previous_time_block;
		if (_tmp30_ != _tmp31_) {
			_tmp29_ = TRUE;
		} else {
			FtSession* _tmp32_;
			FtSession* _tmp33_;
			_tmp32_ = self->priv->_current_session;
			_tmp33_ = previous_session;
			_tmp29_ = _tmp32_ != _tmp33_;
		}
		if (_tmp29_) {
			g_debug ("session-manager.vala:666: The time-block was changed during `leave-tim" \
"e-block` emission.");
			_g_object_unref0 (gap);
			_g_object_unref0 (previous_gap);
			_g_object_unref0 (previous_time_block);
			_g_object_unref0 (previous_session);
			return;
		}
	}
	if (session != NULL) {
		_tmp34_ = ft_session_is_completed (session);
	} else {
		_tmp34_ = FALSE;
	}
	if (_tmp34_) {
		session = NULL;
	}
	_tmp36_ = previous_session;
	if (_tmp36_ != NULL) {
		FtSession* _tmp37_;
		_tmp37_ = previous_session;
		_tmp35_ = session != _tmp37_;
	} else {
		_tmp35_ = FALSE;
	}
	if (_tmp35_) {
		FtSession* _tmp38_;
		gboolean _tmp40_ = FALSE;
		FtTimeBlock* _tmp41_;
		FtTimeBlock* _tmp42_;
		_tmp38_ = previous_session;
		ft_session_manager_mark_session_end (self, _tmp38_, timestamp);
		if (self->priv->current_session_entered) {
			FtSession* _tmp39_;
			_tmp39_ = previous_session;
			g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_LEAVE_SESSION_SIGNAL], 0, _tmp39_);
		}
		_tmp41_ = self->priv->_current_time_block;
		_tmp42_ = previous_time_block;
		if (_tmp41_ != _tmp42_) {
			_tmp40_ = TRUE;
		} else {
			FtSession* _tmp43_;
			FtSession* _tmp44_;
			_tmp43_ = self->priv->_current_session;
			_tmp44_ = previous_session;
			_tmp40_ = _tmp43_ != _tmp44_;
		}
		if (_tmp40_) {
			g_debug ("session-manager.vala:685: The time-block was changed during `leave-ses" \
"sion` emission.");
			_g_object_unref0 (gap);
			_g_object_unref0 (previous_gap);
			_g_object_unref0 (previous_time_block);
			_g_object_unref0 (previous_session);
			return;
		}
	}
	if (session != NULL) {
		gboolean _tmp45_ = FALSE;
		gboolean _tmp46_ = FALSE;
		gboolean _tmp47_ = FALSE;
		FtSession* _tmp48_;
		_tmp48_ = self->priv->next_session;
		if (session == _tmp48_) {
			FtTimeBlock* _tmp49_;
			_tmp49_ = self->priv->next_time_block;
			_tmp47_ = time_block == _tmp49_;
		} else {
			_tmp47_ = FALSE;
		}
		if (_tmp47_) {
			_tmp46_ = time_block != NULL;
		} else {
			_tmp46_ = FALSE;
		}
		if (_tmp46_) {
			gint64 _tmp50_;
			gint64 _tmp51_;
			_tmp50_ = ft_schedulable_get_start_time ((FtSchedulable*) time_block);
			_tmp51_ = _tmp50_;
			_tmp45_ = _tmp51_ == timestamp;
		} else {
			_tmp45_ = FALSE;
		}
		if (_tmp45_) {
		} else {
			ft_session_manager_reschedule_full (self, session, time_block, TRUE, timestamp);
		}
	}
	_tmp52_ = previous_session;
	if (session != _tmp52_) {
		FtSession* _tmp53_;
		FtSession* _tmp54_;
		FtTimeBlock* _tmp55_;
		FtTimeBlock* _tmp56_;
		FtSession* _tmp57_;
		FtSession* _tmp58_;
		FtTimeBlock* _tmp59_;
		_tmp53_ = previous_session;
		_tmp54_ = _g_object_ref0 (_tmp53_);
		_g_object_unref0 (self->priv->previous_session);
		self->priv->previous_session = _tmp54_;
		_tmp55_ = previous_time_block;
		_tmp56_ = _g_object_ref0 (_tmp55_);
		_g_object_unref0 (self->priv->previous_time_block);
		self->priv->previous_time_block = _tmp56_;
		_tmp57_ = _g_object_ref0 (session);
		_g_object_unref0 (self->priv->_current_session);
		self->priv->_current_session = _tmp57_;
		_g_object_unref0 (self->priv->_current_time_block);
		self->priv->_current_time_block = NULL;
		_g_object_unref0 (self->priv->_current_gap);
		self->priv->_current_gap = NULL;
		g_object_notify ((GObject*) self, "current-session");
		if (session != NULL) {
			g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_ENTER_SESSION_SIGNAL], 0, session);
		}
		_tmp58_ = self->priv->_current_session;
		if (_tmp58_ != session) {
			g_debug ("session-manager.vala:721: The session was changed during `enter-sessio" \
"n` emission.");
			_g_object_unref0 (gap);
			_g_object_unref0 (previous_gap);
			_g_object_unref0 (previous_time_block);
			_g_object_unref0 (previous_session);
			return;
		}
		_tmp59_ = self->priv->_current_time_block;
		if (_tmp59_ != NULL) {
			g_debug ("session-manager.vala:726: The time-block was changed during `enter-ses" \
"sion` emission.");
			_g_object_unref0 (gap);
			_g_object_unref0 (previous_gap);
			_g_object_unref0 (previous_time_block);
			_g_object_unref0 (previous_session);
			return;
		}
	}
	_tmp60_ = previous_time_block;
	if (time_block != _tmp60_) {
		FtTimeBlock* _tmp61_;
		FtTimeBlock* _tmp62_;
		FtTimeBlock* _tmp63_;
		FtGap* _tmp64_;
		FtGap* _tmp65_;
		FtTimeBlock* _tmp66_;
		_tmp61_ = previous_time_block;
		_tmp62_ = _g_object_ref0 (_tmp61_);
		_g_object_unref0 (self->priv->previous_time_block);
		self->priv->previous_time_block = _tmp62_;
		_tmp63_ = _g_object_ref0 (time_block);
		_g_object_unref0 (self->priv->_current_time_block);
		self->priv->_current_time_block = _tmp63_;
		_tmp64_ = gap;
		_tmp65_ = _g_object_ref0 (_tmp64_);
		_g_object_unref0 (self->priv->_current_gap);
		self->priv->_current_gap = _tmp65_;
		self->priv->_current_state = state;
		g_object_notify ((GObject*) self, "current-time-block");
		if (state != previous_state) {
			g_object_notify ((GObject*) self, "current-state");
		}
		if (time_block != NULL) {
			g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_ENTER_TIME_BLOCK_SIGNAL], 0, time_block);
		}
		_tmp66_ = self->priv->_current_time_block;
		if (_tmp66_ != time_block) {
			g_debug ("session-manager.vala:750: The time-block was changed during `enter-tim" \
"e-block` emission.");
			_g_object_unref0 (gap);
			_g_object_unref0 (previous_gap);
			_g_object_unref0 (previous_time_block);
			_g_object_unref0 (previous_session);
			return;
		}
		ft_session_manager_update_timer_state (self, timestamp);
	}
	ft_session_manager_reschedule_if_queued (self);
	_tmp67_ = previous_session;
	_tmp68_ = previous_time_block;
	g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_ADVANCED_SIGNAL], 0, session, time_block, _tmp67_, _tmp68_);
	_tmp69_ = self->priv->_current_time_block;
	if (_tmp69_ != NULL) {
		ft_session_manager_enable_idle_monitor (self);
	} else {
		ft_session_manager_disable_idle_monitor (self);
	}
	ft_session_manager_thaw_current_session_changed (self);
	_g_object_unref0 (gap);
	_g_object_unref0 (previous_gap);
	_g_object_unref0 (previous_time_block);
	_g_object_unref0 (previous_session);
}

FtTimeBlock*
ft_session_manager_get_next_time_block (FtSessionManager* self)
{
	FtTimeBlock* next_time_block = NULL;
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	FtTimeBlock* _tmp28_ = NULL;
	FtTimeBlock* _tmp29_;
	FtTimeBlock* result;
	g_return_val_if_fail (self != NULL, NULL);
	next_time_block = NULL;
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ != NULL) {
		FtTimeBlock* _tmp2_;
		_tmp2_ = self->priv->_current_time_block;
		_tmp0_ = _tmp2_ == NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gboolean _tmp3_ = FALSE;
		FtTimeBlock* _tmp4_;
		_tmp4_ = self->priv->previous_time_block;
		if (_tmp4_ != NULL) {
			FtTimeBlock* _tmp5_;
			FtSession* _tmp6_;
			FtSession* _tmp7_;
			FtSession* _tmp8_;
			_tmp5_ = self->priv->previous_time_block;
			_tmp6_ = ft_time_block_get_session (_tmp5_);
			_tmp7_ = _tmp6_;
			_tmp8_ = self->priv->_current_session;
			_tmp3_ = _tmp7_ == _tmp8_;
		} else {
			_tmp3_ = FALSE;
		}
		if (_tmp3_) {
			FtSession* _tmp9_;
			FtTimeBlock* _tmp10_;
			FtTimeBlock* _tmp11_;
			FtTimeBlock* _tmp12_;
			_tmp9_ = self->priv->_current_session;
			_tmp10_ = self->priv->previous_time_block;
			_tmp11_ = ft_session_get_next_time_block (_tmp9_, _tmp10_);
			_tmp12_ = _g_object_ref0 (_tmp11_);
			_g_object_unref0 (next_time_block);
			next_time_block = _tmp12_;
		} else {
			FtSession* _tmp13_;
			FtTimeBlock* _tmp14_;
			FtTimeBlock* _tmp15_;
			_tmp13_ = self->priv->_current_session;
			_tmp14_ = ft_session_get_first_time_block (_tmp13_);
			_tmp15_ = _g_object_ref0 (_tmp14_);
			_g_object_unref0 (next_time_block);
			next_time_block = _tmp15_;
		}
	} else {
		FtSession* _tmp16_;
		_tmp16_ = self->priv->_current_session;
		if (_tmp16_ != NULL) {
			FtSession* _tmp17_;
			FtTimeBlock* _tmp18_;
			FtTimeBlock* _tmp19_;
			FtTimeBlock* _tmp20_;
			_tmp17_ = self->priv->_current_session;
			_tmp18_ = self->priv->_current_time_block;
			_tmp19_ = ft_session_get_next_time_block (_tmp17_, _tmp18_);
			_tmp20_ = _g_object_ref0 (_tmp19_);
			_g_object_unref0 (next_time_block);
			next_time_block = _tmp20_;
		}
	}
	while (TRUE) {
		gboolean _tmp21_ = FALSE;
		FtTimeBlock* _tmp22_;
		FtSession* _tmp24_;
		FtTimeBlock* _tmp25_;
		FtTimeBlock* _tmp26_;
		FtTimeBlock* _tmp27_;
		_tmp22_ = next_time_block;
		if (_tmp22_ != NULL) {
			FtTimeBlock* _tmp23_;
			_tmp23_ = next_time_block;
			_tmp21_ = ft_time_block_get_status (_tmp23_) != FT_TIME_BLOCK_STATUS_SCHEDULED;
		} else {
			_tmp21_ = FALSE;
		}
		if (!_tmp21_) {
			break;
		}
		_tmp24_ = self->priv->_current_session;
		_tmp25_ = next_time_block;
		_tmp26_ = ft_session_get_next_time_block (_tmp24_, _tmp25_);
		_tmp27_ = _g_object_ref0 (_tmp26_);
		_g_object_unref0 (next_time_block);
		next_time_block = _tmp27_;
	}
	_tmp29_ = next_time_block;
	if (_tmp29_ != NULL) {
		FtTimeBlock* _tmp30_;
		_tmp30_ = next_time_block;
		_tmp28_ = _tmp30_;
	} else {
		FtTimeBlock* _tmp31_;
		_tmp31_ = self->priv->next_time_block;
		_tmp28_ = _tmp31_;
	}
	result = _tmp28_;
	_g_object_unref0 (next_time_block);
	return result;
}

/**
         * Return cycle associated with current_time_block.
         */
FtCycle*
ft_session_manager_get_current_cycle (FtSessionManager* self)
{
	FtTimeBlock* _tmp0_ = NULL;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* current_time_block = NULL;
	FtTimeBlock* _tmp4_;
	gboolean _tmp5_ = FALSE;
	FtTimeBlock* _tmp6_;
	GList* cycles = NULL;
	FtSession* _tmp8_;
	GList* _tmp9_;
	GList* link = NULL;
	GList* _tmp10_;
	GList* _tmp11_;
	FtCycle* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->_current_time_block;
	if (_tmp1_ != NULL) {
		FtTimeBlock* _tmp2_;
		_tmp2_ = self->priv->_current_time_block;
		_tmp0_ = _tmp2_;
	} else {
		FtTimeBlock* _tmp3_;
		_tmp3_ = self->priv->previous_time_block;
		_tmp0_ = _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	current_time_block = _tmp4_;
	_tmp6_ = current_time_block;
	if (_tmp6_ == NULL) {
		_tmp5_ = TRUE;
	} else {
		FtSession* _tmp7_;
		_tmp7_ = self->priv->_current_session;
		_tmp5_ = _tmp7_ == NULL;
	}
	if (_tmp5_) {
		result = NULL;
		_g_object_unref0 (current_time_block);
		return result;
	}
	_tmp8_ = self->priv->_current_session;
	_tmp9_ = ft_session_get_cycles (_tmp8_);
	cycles = _tmp9_;
	_tmp10_ = cycles;
	_tmp11_ = g_list_first (_tmp10_);
	link = _tmp11_;
	while (TRUE) {
		GList* _tmp12_;
		GList* _tmp13_;
		gconstpointer _tmp14_;
		FtTimeBlock* _tmp15_;
		GList* _tmp18_;
		GList* _tmp19_;
		_tmp12_ = link;
		if (!(_tmp12_ != NULL)) {
			break;
		}
		_tmp13_ = link;
		_tmp14_ = _tmp13_->data;
		_tmp15_ = current_time_block;
		if (ft_cycle_contains ((FtCycle*) _tmp14_, _tmp15_)) {
			GList* _tmp16_;
			gconstpointer _tmp17_;
			_tmp16_ = link;
			_tmp17_ = _tmp16_->data;
			result = (FtCycle*) _tmp17_;
			(cycles == NULL) ? NULL : (cycles = (g_list_free (cycles), NULL));
			_g_object_unref0 (current_time_block);
			return result;
		}
		_tmp18_ = link;
		_tmp19_ = _tmp18_->next;
		link = _tmp19_;
	}
	result = NULL;
	(cycles == NULL) ? NULL : (cycles = (g_list_free (cycles), NULL));
	_g_object_unref0 (current_time_block);
	return result;
}

static FtAdvancementMode
ft_session_manager_resolve_advancement_mode (FtSessionManager* self,
                                             FtState next_state,
                                             gint64 timestamp)
{
	FtIdleMonitor* _tmp0_;
	FtState _tmp1_ = 0;
	FtTimeBlock* _tmp2_;
	FtState current_state = 0;
	FtAdvancementMode advancement_mode = 0;
	FtAdvancementMode result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->idle_monitor;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this.idle_monitor != null", 0);
	_tmp2_ = self->priv->_current_time_block;
	if (_tmp2_ != NULL) {
		FtTimeBlock* _tmp3_;
		FtState _tmp4_;
		FtState _tmp5_;
		_tmp3_ = self->priv->_current_time_block;
		_tmp4_ = ft_time_block_get_state (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_;
	} else {
		_tmp1_ = FT_STATE_STOPPED;
	}
	current_state = _tmp1_;
	advancement_mode = FT_ADVANCEMENT_MODE_CONTINUOUS;
	if (current_state == FT_STATE_POMODORO) {
		FtAdvancementMode _tmp6_ = 0;
		GSettings* _tmp7_;
		_tmp7_ = self->priv->settings;
		if (g_settings_get_boolean (_tmp7_, "confirm-starting-break")) {
			_tmp6_ = FT_ADVANCEMENT_MODE_CONFIRM;
		} else {
			_tmp6_ = FT_ADVANCEMENT_MODE_CONTINUOUS;
		}
		advancement_mode = _tmp6_;
	} else {
		if (ft_state_is_break (current_state)) {
			FtAdvancementMode _tmp8_ = 0;
			GSettings* _tmp9_;
			_tmp9_ = self->priv->settings;
			if (g_settings_get_boolean (_tmp9_, "confirm-starting-pomodoro")) {
				_tmp8_ = FT_ADVANCEMENT_MODE_CONFIRM;
			} else {
				_tmp8_ = FT_ADVANCEMENT_MODE_WAIT_FOR_ACTIVITY;
			}
			advancement_mode = _tmp8_;
		}
	}
	switch (advancement_mode) {
		case FT_ADVANCEMENT_MODE_WAIT_FOR_ACTIVITY:
		{
			FtIdleMonitor* _tmp10_;
			gboolean _tmp11_;
			gboolean _tmp12_;
			_tmp10_ = self->priv->idle_monitor;
			_tmp11_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp10_);
			_tmp12_ = _tmp11_;
			if (!_tmp12_) {
				advancement_mode = FT_ADVANCEMENT_MODE_CONFIRM;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	result = advancement_mode;
	return result;
}

/**
         * Push the removal of extra time-blocks onto SQLite queue.
         */
static Block40Data*
block40_data_ref (Block40Data* _data40_)
{
	g_atomic_int_inc (&_data40_->_ref_count_);
	return _data40_;
}

static void
block40_data_unref (void * _userdata_)
{
	Block40Data* _data40_;
	_data40_ = (Block40Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data40_->_ref_count_)) {
		FtSessionManager* self;
		self = _data40_->self;
		_g_object_unref0 (_data40_->command);
		_g_object_unref0 (self);
		g_slice_free (Block40Data, _data40_);
	}
}

static void
_vala_array_add22 (GomFilter** * array,
                   gint* length,
                   gint* size,
                   GomFilter* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GomFilter*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
__lambda42_ (Block40Data* _data40_)
{
	FtSessionManager* self;
	GError* _inner_error0_ = NULL;
	self = _data40_->self;
	{
		gom_command_execute (_data40_->command, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = _error_;
		_tmp1_ = _tmp0_->message;
		g_warning ("session-manager.vala:916: Error while deleting time-blocks: %s", _tmp1_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	g_object_unref ((GObject*) _data40_->command);
}

static void
___lambda42__gom_adapter_callback (GomAdapter* adapter,
                                   gpointer self)
{
	__lambda42_ (self);
	block40_data_unref (self);
}

static void
ft_session_manager_delete_time_blocks (FtSessionManager* self,
                                       GomRepository* repository,
                                       gint64 session_id,
                                       GArray* time_block_ids_to_keep)
{
	Block40Data* _data40_;
	GomAdapter* adapter = NULL;
	GomAdapter* _tmp0_;
	GomAdapter* _tmp1_;
	GomAdapter* _tmp2_;
	GomAdapter* _tmp3_;
	GValue session_id_value = {0};
	GValue _tmp4_ = {0};
	GomFilter** filters = NULL;
	GValue _tmp5_;
	GomFilter* _tmp6_;
	GomFilter** _tmp7_;
	gint filters_length1;
	gint _filters_size_;
	GomFilter* filter = NULL;
	GomFilter** _tmp13_;
	gint _tmp13__length1;
	GomFilter* _tmp14_;
	GomCommandBuilder* command_builder = NULL;
	GomAdapter* _tmp15_;
	GObject* _tmp16_;
	GObject* _tmp17_;
	GomCommand* _tmp18_;
	GomAdapter* _tmp19_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (repository != NULL);
	g_return_if_fail (time_block_ids_to_keep != NULL);
	_vala_return_if_fail (session_id != ((gint64) 0), "session_id != 0");
	_data40_ = g_slice_new0 (Block40Data);
	_data40_->_ref_count_ = 1;
	_data40_->self = g_object_ref (self);
	_tmp0_ = gom_repository_get_adapter (repository);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adapter = _tmp2_;
	_tmp3_ = adapter;
	_vala_assert (_tmp3_ != NULL, "adapter != null");
	g_value_init (&_tmp4_, G_TYPE_INT64);
	session_id_value = _tmp4_;
	g_value_set_int64 (&session_id_value, session_id);
	_tmp5_ = session_id_value;
	_tmp6_ = gom_filter_new_eq (FT_TYPE_TIME_BLOCK_ENTRY, "session-id", &_tmp5_);
	g_object_ref_sink (_tmp6_);
	_tmp7_ = g_new0 (GomFilter*, 1 + 1);
	_tmp7_[0] = _tmp6_;
	filters = _tmp7_;
	filters_length1 = 1;
	_filters_size_ = filters_length1;
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp8_ = FALSE;
			_tmp8_ = TRUE;
			while (TRUE) {
				gint64 time_block_id = 0LL;
				GValue time_block_id_value = {0};
				GValue _tmp10_ = {0};
				GValue _tmp11_;
				GomFilter* _tmp12_;
				if (!_tmp8_) {
					gint _tmp9_;
					_tmp9_ = index;
					index = _tmp9_ + 1;
				}
				_tmp8_ = FALSE;
				if (!(((guint) index) < time_block_ids_to_keep->len)) {
					break;
				}
				time_block_id = g_array_index (time_block_ids_to_keep, gint64, (guint) index);
				g_value_init (&_tmp10_, G_TYPE_INT64);
				time_block_id_value = _tmp10_;
				g_value_set_int64 (&time_block_id_value, time_block_id);
				_tmp11_ = time_block_id_value;
				_tmp12_ = gom_filter_new_neq (FT_TYPE_TIME_BLOCK_ENTRY, "id", &_tmp11_);
				g_object_ref_sink (_tmp12_);
				_vala_array_add22 (&filters, &filters_length1, &_filters_size_, _tmp12_);
				G_IS_VALUE (&time_block_id_value) ? (g_value_unset (&time_block_id_value), NULL) : NULL;
			}
		}
	}
	_tmp13_ = filters;
	_tmp13__length1 = filters_length1;
	_tmp14_ = gom_filter_new_and_fullv ((GomFilter**) _tmp13_);
	g_object_ref_sink (_tmp14_);
	filter = _tmp14_;
	_tmp15_ = adapter;
	_tmp16_ = g_object_new (gom_command_builder_get_type (), "resource-type", FT_TYPE_TIME_BLOCK_ENTRY, "adapter", _tmp15_, "filter", filter, NULL);
	_tmp17_ = G_IS_INITIALLY_UNOWNED (_tmp16_) ? g_object_ref_sink (_tmp16_) : _tmp16_;
	command_builder = G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, gom_command_builder_get_type (), GomCommandBuilder);
	_tmp18_ = gom_command_builder_build_delete (command_builder);
	_data40_->command = _tmp18_;
	g_object_ref ((GObject*) _data40_->command);
	_tmp19_ = adapter;
	gom_adapter_queue_write (_tmp19_, ___lambda42__gom_adapter_callback, block40_data_ref (_data40_));
	_g_object_unref0 (command_builder);
	_g_object_unref0 (filter);
	filters = (_vala_array_free (filters, filters_length1, (GDestroyNotify) g_object_unref), NULL);
	G_IS_VALUE (&session_id_value) ? (g_value_unset (&session_id_value), NULL) : NULL;
	_g_object_unref0 (adapter);
	block40_data_unref (_data40_);
	_data40_ = NULL;
}

static Block41Data*
block41_data_ref (Block41Data* _data41_)
{
	g_atomic_int_inc (&_data41_->_ref_count_);
	return _data41_;
}

static void
block41_data_unref (void * _userdata_)
{
	Block41Data* _data41_;
	_data41_ = (Block41Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data41_->_ref_count_)) {
		FtSessionManager* self;
		self = _data41_->self;
		_g_object_unref0 (_data41_->command);
		_g_object_unref0 (self);
		g_slice_free (Block41Data, _data41_);
	}
}

static void
_vala_array_add23 (GomFilter** * array,
                   gint* length,
                   gint* size,
                   GomFilter* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GomFilter*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
__lambda43_ (Block41Data* _data41_)
{
	FtSessionManager* self;
	GError* _inner_error0_ = NULL;
	self = _data41_->self;
	{
		gom_command_execute (_data41_->command, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = _error_;
		_tmp1_ = _tmp0_->message;
		g_warning ("session-manager.vala:967: Error while deleting gaps: %s", _tmp1_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	g_object_unref ((GObject*) _data41_->command);
}

static void
___lambda43__gom_adapter_callback (GomAdapter* adapter,
                                   gpointer self)
{
	__lambda43_ (self);
	block41_data_unref (self);
}

static void
ft_session_manager_delete_gaps (FtSessionManager* self,
                                GomRepository* repository,
                                gint64 time_block_id,
                                GArray* gap_ids_to_keep)
{
	Block41Data* _data41_;
	GomAdapter* adapter = NULL;
	GomAdapter* _tmp0_;
	GomAdapter* _tmp1_;
	GomAdapter* _tmp2_;
	GomAdapter* _tmp3_;
	GValue time_block_id_value = {0};
	GValue _tmp4_ = {0};
	GomFilter** filters = NULL;
	GValue _tmp5_;
	GomFilter* _tmp6_;
	GomFilter** _tmp7_;
	gint filters_length1;
	gint _filters_size_;
	GomFilter* filter = NULL;
	GomFilter** _tmp13_;
	gint _tmp13__length1;
	GomFilter* _tmp14_;
	GomCommandBuilder* command_builder = NULL;
	GomAdapter* _tmp15_;
	GObject* _tmp16_;
	GObject* _tmp17_;
	GomCommand* _tmp18_;
	GomAdapter* _tmp19_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (repository != NULL);
	g_return_if_fail (gap_ids_to_keep != NULL);
	_vala_return_if_fail (time_block_id != ((gint64) 0), "time_block_id != 0");
	_data41_ = g_slice_new0 (Block41Data);
	_data41_->_ref_count_ = 1;
	_data41_->self = g_object_ref (self);
	_tmp0_ = gom_repository_get_adapter (repository);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adapter = _tmp2_;
	_tmp3_ = adapter;
	_vala_assert (_tmp3_ != NULL, "adapter != null");
	g_value_init (&_tmp4_, G_TYPE_INT64);
	time_block_id_value = _tmp4_;
	g_value_set_int64 (&time_block_id_value, time_block_id);
	_tmp5_ = time_block_id_value;
	_tmp6_ = gom_filter_new_eq (FT_TYPE_GAP_ENTRY, "time-block-id", &_tmp5_);
	g_object_ref_sink (_tmp6_);
	_tmp7_ = g_new0 (GomFilter*, 1 + 1);
	_tmp7_[0] = _tmp6_;
	filters = _tmp7_;
	filters_length1 = 1;
	_filters_size_ = filters_length1;
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp8_ = FALSE;
			_tmp8_ = TRUE;
			while (TRUE) {
				gint64 gap_id = 0LL;
				GValue gap_id_value = {0};
				GValue _tmp10_ = {0};
				GValue _tmp11_;
				GomFilter* _tmp12_;
				if (!_tmp8_) {
					gint _tmp9_;
					_tmp9_ = index;
					index = _tmp9_ + 1;
				}
				_tmp8_ = FALSE;
				if (!(((guint) index) < gap_ids_to_keep->len)) {
					break;
				}
				gap_id = g_array_index (gap_ids_to_keep, gint64, (guint) index);
				g_value_init (&_tmp10_, G_TYPE_INT64);
				gap_id_value = _tmp10_;
				g_value_set_int64 (&gap_id_value, gap_id);
				_tmp11_ = gap_id_value;
				_tmp12_ = gom_filter_new_neq (FT_TYPE_GAP_ENTRY, "id", &_tmp11_);
				g_object_ref_sink (_tmp12_);
				_vala_array_add23 (&filters, &filters_length1, &_filters_size_, _tmp12_);
				G_IS_VALUE (&gap_id_value) ? (g_value_unset (&gap_id_value), NULL) : NULL;
			}
		}
	}
	_tmp13_ = filters;
	_tmp13__length1 = filters_length1;
	_tmp14_ = gom_filter_new_and_fullv ((GomFilter**) _tmp13_);
	g_object_ref_sink (_tmp14_);
	filter = _tmp14_;
	_tmp15_ = adapter;
	_tmp16_ = g_object_new (gom_command_builder_get_type (), "resource-type", FT_TYPE_GAP_ENTRY, "adapter", _tmp15_, "filter", filter, NULL);
	_tmp17_ = G_IS_INITIALLY_UNOWNED (_tmp16_) ? g_object_ref_sink (_tmp16_) : _tmp16_;
	command_builder = G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, gom_command_builder_get_type (), GomCommandBuilder);
	_tmp18_ = gom_command_builder_build_delete (command_builder);
	_data41_->command = _tmp18_;
	g_object_ref ((GObject*) _data41_->command);
	_tmp19_ = adapter;
	gom_adapter_queue_write (_tmp19_, ___lambda43__gom_adapter_callback, block41_data_ref (_data41_));
	_g_object_unref0 (command_builder);
	_g_object_unref0 (filter);
	filters = (_vala_array_free (filters, filters_length1, (GDestroyNotify) g_object_unref), NULL);
	G_IS_VALUE (&time_block_id_value) ? (g_value_unset (&time_block_id_value), NULL) : NULL;
	_g_object_unref0 (adapter);
	block41_data_unref (_data41_);
	_data41_ = NULL;
}

/**
         * Delete a session entry by ID, working around a floating reference bug in Gom.
         *
         * Gom's `GomResource.delete_async()` has a bug where it creates a filter with a floating
         * reference and unrefs it without sinking, causing a critical warning. This method
         * implements the delete operation directly to avoid that issue.
         *
         * XXX: fix it upstream
         */
static Block42Data*
block42_data_ref (Block42Data* _data42_)
{
	g_atomic_int_inc (&_data42_->_ref_count_);
	return _data42_;
}

static void
block42_data_unref (void * _userdata_)
{
	Block42Data* _data42_;
	_data42_ = (Block42Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data42_->_ref_count_)) {
		FtSessionManager* self;
		self = _data42_->self;
		_g_object_unref0 (_data42_->command);
		_g_object_unref0 (self);
		g_slice_free (Block42Data, _data42_);
	}
}

static void
__lambda44_ (Block42Data* _data42_)
{
	FtSessionManager* self;
	GError* _inner_error0_ = NULL;
	self = _data42_->self;
	{
		gom_command_execute (_data42_->command, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = _error_;
		_tmp1_ = _tmp0_->message;
		g_warning ("session-manager.vala:1012: Error while deleting session entry: %s", _tmp1_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	g_object_unref ((GObject*) _data42_->command);
}

static void
___lambda44__gom_adapter_callback (GomAdapter* adapter,
                                   gpointer self)
{
	__lambda44_ (self);
	block42_data_unref (self);
}

static void
ft_session_manager_delete_session (FtSessionManager* self,
                                   GomRepository* repository,
                                   gint64 session_id)
{
	Block42Data* _data42_;
	GomAdapter* adapter = NULL;
	GomAdapter* _tmp0_;
	GomAdapter* _tmp1_;
	GomAdapter* _tmp2_;
	GValue id_value = {0};
	GValue _tmp3_ = {0};
	GomFilter* filter = NULL;
	GValue _tmp4_;
	GomFilter* _tmp5_;
	GomCommandBuilder* command_builder = NULL;
	GObject* _tmp6_;
	GObject* _tmp7_;
	GomCommand* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (repository != NULL);
	_vala_return_if_fail (session_id != ((gint64) 0), "session_id != 0");
	_data42_ = g_slice_new0 (Block42Data);
	_data42_->_ref_count_ = 1;
	_data42_->self = g_object_ref (self);
	_tmp0_ = gom_repository_get_adapter (repository);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	adapter = _tmp2_;
	_vala_assert (adapter != NULL, "adapter != null");
	g_value_init (&_tmp3_, G_TYPE_INT64);
	id_value = _tmp3_;
	g_value_set_int64 (&id_value, session_id);
	_tmp4_ = id_value;
	_tmp5_ = gom_filter_new_eq (FT_TYPE_SESSION_ENTRY, "id", &_tmp4_);
	g_object_ref_sink (_tmp5_);
	filter = _tmp5_;
	_tmp6_ = g_object_new (gom_command_builder_get_type (), "resource-type", FT_TYPE_SESSION_ENTRY, "adapter", adapter, "filter", filter, NULL);
	_tmp7_ = G_IS_INITIALLY_UNOWNED (_tmp6_) ? g_object_ref_sink (_tmp6_) : _tmp6_;
	command_builder = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gom_command_builder_get_type (), GomCommandBuilder);
	_tmp8_ = gom_command_builder_build_delete (command_builder);
	_data42_->command = _tmp8_;
	g_object_ref ((GObject*) _data42_->command);
	gom_adapter_queue_write (adapter, ___lambda44__gom_adapter_callback, block42_data_ref (_data42_));
	_g_object_unref0 (command_builder);
	_g_object_unref0 (filter);
	G_IS_VALUE (&id_value) ? (g_value_unset (&id_value), NULL) : NULL;
	_g_object_unref0 (adapter);
	block42_data_unref (_data42_);
	_data42_ = NULL;
}

static void
ft_session_manager_save_session_data_free (gpointer _data)
{
	FtSessionManagerSaveSessionData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->session);
	_g_object_unref0 (_data_->self);
	g_slice_free (FtSessionManagerSaveSessionData, _data_);
}

static void
ft_session_manager_save_session (FtSessionManager* self,
                                 GomRepository* repository,
                                 FtSession* session,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	FtSessionManagerSaveSessionData* _data_;
	FtSessionManager* _tmp0_;
	GomRepository* _tmp1_;
	FtSession* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (repository != NULL);
	g_return_if_fail (session != NULL);
	_data_ = g_slice_new0 (FtSessionManagerSaveSessionData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_session_manager_save_session_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (repository);
	_g_object_unref0 (_data_->repository);
	_data_->repository = _tmp1_;
	_tmp2_ = _g_object_ref0 (session);
	_g_object_unref0 (_data_->session);
	_data_->session = _tmp2_;
	ft_session_manager_save_session_co (_data_);
}

static void
ft_session_manager_save_session_finish (FtSessionManager* self,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	FtSessionManagerSaveSessionData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block43Data*
block43_data_ref (Block43Data* _data43_)
{
	g_atomic_int_inc (&_data43_->_ref_count_);
	return _data43_;
}

static void
block43_data_unref (void * _userdata_)
{
	Block43Data* _data43_;
	_data43_ = (Block43Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data43_->_ref_count_)) {
		FtSessionManager* self;
		self = _data43_->self;
		_g_hash_table_unref0 (_data43_->gap_mapping);
		_g_hash_table_unref0 (_data43_->time_block_mapping);
		_g_hash_table_unref0 (_data43_->keep_gap_ids);
		_g_array_unref0 (_data43_->keep_time_block_ids);
		_g_object_unref0 (_data43_->repository);
		_g_object_unref0 (self);
		g_slice_free (Block43Data, _data43_);
	}
}

static void
__lambda45_ (void* arr)
{
	((GArray*) arr)->data = (g_free (((GArray*) arr)->data), NULL);
	((GArray*) arr)->data = NULL;
	((GArray*) arr)->len = 0;
}

static void
___lambda45__gdestroy_notify (void* data)
{
	__lambda45_ (data);
}

static Block44Data*
block44_data_ref (Block44Data* _data44_)
{
	g_atomic_int_inc (&_data44_->_ref_count_);
	return _data44_;
}

static void
block44_data_unref (void * _userdata_)
{
	Block44Data* _data44_;
	_data44_ = (Block44Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data44_->_ref_count_)) {
		FtSessionManager* self;
		self = _data44_->_data43_->self;
		_g_object_unref0 (_data44_->time_block_entry);
		block43_data_unref (_data44_->_data43_);
		_data44_->_data43_ = NULL;
		g_slice_free (Block44Data, _data44_);
	}
}

static Block45Data*
block45_data_ref (Block45Data* _data45_)
{
	g_atomic_int_inc (&_data45_->_ref_count_);
	return _data45_;
}

static void
block45_data_unref (void * _userdata_)
{
	Block45Data* _data45_;
	_data45_ = (Block45Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data45_->_ref_count_)) {
		FtSessionManager* self;
		self = _data45_->_data44_->_data43_->self;
		_g_array_unref0 (_data45_->gap_ids);
		block44_data_unref (_data45_->_data44_);
		_data45_->_data44_ = NULL;
		g_slice_free (Block45Data, _data45_);
	}
}

static void
___lambda47_ (Block45Data* _data45_,
              FtGap* gap)
{
	Block44Data* _data44_;
	Block43Data* _data43_;
	FtSessionManager* self;
	FtGapEntry* gap_entry = NULL;
	FtGapEntry* _tmp0_;
	FtGapEntry* _tmp1_;
	gboolean _tmp2_ = FALSE;
	FtGapEntry* _tmp3_;
	_data44_ = _data45_->_data44_;
	_data43_ = _data44_->_data43_;
	self = _data43_->self;
	g_return_if_fail (gap != NULL);
	if (!ft_gap_should_create_entry (gap)) {
		return;
	}
	_tmp0_ = gap->entry;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	gap_entry = _tmp1_;
	_tmp3_ = gap_entry;
	if (_tmp3_ != NULL) {
		FtTimeBlockEntry* _tmp4_;
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp4_ = _data44_->time_block_entry;
		_tmp5_ = ft_time_block_entry_get_id (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != ((gint64) 0);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GArray* _tmp7_;
		FtGapEntry* _tmp8_;
		gint64 _tmp9_;
		gint64 _tmp10_;
		_tmp7_ = _data45_->gap_ids;
		_tmp8_ = gap_entry;
		_tmp9_ = ft_gap_entry_get_id (_tmp8_);
		_tmp10_ = _tmp9_;
		g_array_append_val (_tmp7_, _tmp10_);
	}
	if (ft_gap_should_update_entry (gap)) {
		FtGapEntry* _tmp11_;
		FtGapEntry* _tmp12_;
		GHashTable* _tmp13_;
		FtGapEntry* _tmp14_;
		_tmp11_ = ft_gap_create_or_update_entry (gap);
		_tmp12_ = _g_object_ref0 (_tmp11_);
		_g_object_unref0 (gap_entry);
		gap_entry = _tmp12_;
		_tmp13_ = _data43_->gap_mapping;
		_tmp14_ = gap_entry;
		g_hash_table_insert (_tmp13_, gap, _tmp14_);
	}
	_g_object_unref0 (gap_entry);
}

static void
____lambda47__gfunc (gconstpointer data,
                     gpointer self)
{
	___lambda47_ (self, (FtGap*) data);
}

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

static gpointer
__int64_dup0 (gpointer self)
{
	return self ? _int64_dup (self) : NULL;
}

static gpointer
_g_array_ref0 (gpointer self)
{
	return self ? g_array_ref (self) : NULL;
}

static void
__lambda46_ (Block43Data* _data43_,
             FtTimeBlock* time_block)
{
	FtSessionManager* self;
	Block44Data* _data44_;
	FtTimeBlockEntry* _tmp0_;
	FtTimeBlockEntry* _tmp1_;
	gboolean _tmp2_ = FALSE;
	FtTimeBlockEntry* _tmp3_;
	self = _data43_->self;
	g_return_if_fail (time_block != NULL);
	_data44_ = g_slice_new0 (Block44Data);
	_data44_->_ref_count_ = 1;
	_data44_->_data43_ = block43_data_ref (_data43_);
	if (!ft_time_block_should_create_entry (time_block)) {
		block44_data_unref (_data44_);
		_data44_ = NULL;
		return;
	}
	_tmp0_ = time_block->entry;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data44_->time_block_entry = _tmp1_;
	_tmp3_ = _data44_->time_block_entry;
	if (_tmp3_ != NULL) {
		FtTimeBlockEntry* _tmp4_;
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp4_ = _data44_->time_block_entry;
		_tmp5_ = ft_time_block_entry_get_id (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != ((gint64) 0);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GArray* _tmp7_;
		FtTimeBlockEntry* _tmp8_;
		gint64 _tmp9_;
		gint64 _tmp10_;
		_tmp7_ = _data43_->keep_time_block_ids;
		_tmp8_ = _data44_->time_block_entry;
		_tmp9_ = ft_time_block_entry_get_id (_tmp8_);
		_tmp10_ = _tmp9_;
		g_array_append_val (_tmp7_, _tmp10_);
	}
	if (ft_time_block_should_update_entry (time_block)) {
		Block45Data* _data45_;
		GArray* _tmp11_;
		FtTimeBlockEntry* _tmp12_;
		FtTimeBlockEntry* _tmp13_;
		GHashTable* _tmp14_;
		FtTimeBlockEntry* _tmp15_;
		FtTimeBlockEntry* _tmp16_;
		gint64 _tmp17_;
		gint64 _tmp18_;
		_data45_ = g_slice_new0 (Block45Data);
		_data45_->_ref_count_ = 1;
		_data45_->_data44_ = block44_data_ref (_data44_);
		_tmp11_ = g_array_new (TRUE, TRUE, sizeof (gint64));
		_data45_->gap_ids = _tmp11_;
		_tmp12_ = ft_time_block_create_or_update_entry (time_block);
		_tmp13_ = _g_object_ref0 (_tmp12_);
		_g_object_unref0 (_data44_->time_block_entry);
		_data44_->time_block_entry = _tmp13_;
		_tmp14_ = _data43_->time_block_mapping;
		_tmp15_ = _data44_->time_block_entry;
		g_hash_table_insert (_tmp14_, time_block, _tmp15_);
		ft_time_block_foreach_gap (time_block, ____lambda47__gfunc, _data45_);
		_tmp16_ = _data44_->time_block_entry;
		_tmp17_ = ft_time_block_entry_get_id (_tmp16_);
		_tmp18_ = _tmp17_;
		if (_tmp18_ != ((gint64) 0)) {
			GHashTable* _tmp19_;
			FtTimeBlockEntry* _tmp20_;
			gint64 _tmp21_;
			gint64 _tmp22_;
			gint64* _tmp23_;
			GArray* _tmp24_;
			GArray* _tmp25_;
			_tmp19_ = _data43_->keep_gap_ids;
			_tmp20_ = _data44_->time_block_entry;
			_tmp21_ = ft_time_block_entry_get_id (_tmp20_);
			_tmp22_ = _tmp21_;
			_tmp23_ = __int64_dup0 (&_tmp22_);
			_tmp24_ = _data45_->gap_ids;
			_tmp25_ = _g_array_ref0 (_tmp24_);
			g_hash_table_insert (_tmp19_, _tmp23_, _tmp25_);
		}
		block45_data_unref (_data45_);
		_data45_ = NULL;
	}
	block44_data_unref (_data44_);
	_data44_ = NULL;
}

static void
___lambda46__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda46_ (self, (FtTimeBlock*) data);
}

static Block46Data*
block46_data_ref (Block46Data* _data46_)
{
	g_atomic_int_inc (&_data46_->_ref_count_);
	return _data46_;
}

static void
block46_data_unref (void * _userdata_)
{
	Block46Data* _data46_;
	_data46_ = (Block46Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data46_->_ref_count_)) {
		FtSessionManager* self;
		self = _data46_->_data43_->self;
		_g_object_unref0 (_data46_->gap_entries);
		_g_object_unref0 (_data46_->time_block_entries);
		block43_data_unref (_data46_->_data43_);
		_data46_->_data43_ = NULL;
		g_slice_free (Block46Data, _data46_);
	}
}

static void
ft_session_manager_save_session_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	FtSessionManagerSaveSessionData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_session_manager_save_session_co (_data_);
}

static void
___lambda48_ (Block46Data* _data46_,
              FtTimeBlock* time_block,
              FtTimeBlockEntry* time_block_entry)
{
	Block43Data* _data43_;
	FtSessionManager* self;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	GomResourceGroup* _tmp4_;
	_data43_ = _data46_->_data43_;
	self = _data43_->self;
	g_return_if_fail (time_block != NULL);
	g_return_if_fail (time_block_entry != NULL);
	_tmp0_ = ft_time_block_entry_get_session_id (time_block_entry);
	_tmp1_ = _tmp0_;
	_vala_assert (_tmp1_ != ((gint64) 0), "time_block_entry.session_id != 0");
	_tmp2_ = ft_time_block_entry_get_id (time_block_entry);
	_tmp3_ = _tmp2_;
	g_object_set_data_full ((GObject*) time_block_entry, "is-from-table", (gpointer) ((gintptr) (_tmp3_ != ((gint64) 0))), NULL);
	_tmp4_ = _data46_->time_block_entries;
	gom_resource_group_append (_tmp4_, (GomResource*) time_block_entry);
}

static void
____lambda48__gh_func (gconstpointer key,
                       gconstpointer value,
                       gpointer self)
{
	___lambda48_ (self, (FtTimeBlock*) key, (FtTimeBlockEntry*) value);
}

static void
___lambda49_ (FtSessionManager* self,
              FtTimeBlock* time_block,
              FtTimeBlockEntry* time_block_entry)
{
	g_return_if_fail (time_block != NULL);
	g_return_if_fail (time_block_entry != NULL);
	g_object_set_data_full ((GObject*) time_block_entry, "is-from-table", (gpointer) ((gintptr) TRUE), NULL);
	g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_TIME_BLOCK_SAVED_SIGNAL], 0, time_block, time_block_entry);
}

static void
____lambda49__gh_func (gconstpointer key,
                       gconstpointer value,
                       gpointer self)
{
	___lambda49_ ((FtSessionManager*) self, (FtTimeBlock*) key, (FtTimeBlockEntry*) value);
}

static void
___lambda50_ (Block46Data* _data46_,
              FtGap* gap,
              FtGapEntry* gap_entry)
{
	Block43Data* _data43_;
	FtSessionManager* self;
	gint64 _tmp0_;
	gint64 _tmp1_;
	GomResourceGroup* _tmp2_;
	_data43_ = _data46_->_data43_;
	self = _data43_->self;
	g_return_if_fail (gap != NULL);
	g_return_if_fail (gap_entry != NULL);
	_tmp0_ = ft_gap_entry_get_time_block_id (gap_entry);
	_tmp1_ = _tmp0_;
	_vala_assert (_tmp1_ != ((gint64) 0), "gap_entry.time_block_id != 0");
	_tmp2_ = _data46_->gap_entries;
	gom_resource_group_append (_tmp2_, (GomResource*) gap_entry);
}

static void
____lambda50__gh_func (gconstpointer key,
                       gconstpointer value,
                       gpointer self)
{
	___lambda50_ (self, (FtGap*) key, (FtGapEntry*) value);
}

static void
___lambda51_ (Block46Data* _data46_,
              gint64* time_block_id,
              GArray* gap_ids_to_keep)
{
	Block43Data* _data43_;
	FtSessionManager* self;
	_data43_ = _data46_->_data43_;
	self = _data43_->self;
	g_return_if_fail (gap_ids_to_keep != NULL);
	ft_session_manager_delete_gaps (self, _data43_->repository, *time_block_id, gap_ids_to_keep);
}

static void
____lambda51__gh_func (gconstpointer key,
                       gconstpointer value,
                       gpointer self)
{
	___lambda51_ (self, (gint64*) key, (GArray*) value);
}

static void
___lambda52_ (FtSessionManager* self,
              FtGap* gap,
              FtGapEntry* gap_entry)
{
	g_return_if_fail (gap != NULL);
	g_return_if_fail (gap_entry != NULL);
	g_object_set_data_full ((GObject*) gap_entry, "is-from-table", (gpointer) ((gintptr) TRUE), NULL);
	g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_GAP_SAVED_SIGNAL], 0, gap, gap_entry);
}

static void
____lambda52__gh_func (gconstpointer key,
                       gconstpointer value,
                       gpointer self)
{
	___lambda52_ ((FtSessionManager*) self, (FtGap*) key, (FtGapEntry*) value);
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static gboolean
ft_session_manager_save_session_co (FtSessionManagerSaveSessionData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data43_ = g_slice_new0 (Block43Data);
	_data_->_data43_->_ref_count_ = 1;
	_data_->_data43_->self = g_object_ref (_data_->self);
	_g_object_unref0 (_data_->_data43_->repository);
	_data_->_data43_->repository = _data_->repository;
	_data_->_data43_->_async_data_ = _data_;
	if (!ft_session_should_create_entry (_data_->session)) {
		_data_->_tmp1_ = _data_->session->entry;
		if (_data_->_tmp1_ != NULL) {
			_data_->_tmp2_ = _data_->session->entry;
			_data_->_tmp3_ = ft_session_entry_get_id (_data_->_tmp2_);
			_data_->_tmp4_ = _data_->_tmp3_;
			_data_->_tmp0_ = _data_->_tmp4_ != ((gint64) 0);
		} else {
			_data_->_tmp0_ = FALSE;
		}
		if (_data_->_tmp0_) {
			_data_->_tmp5_ = _data_->session->entry;
			_data_->_tmp6_ = _g_object_ref0 (_data_->_tmp5_);
			_data_->session_entry = _data_->_tmp6_;
			ft_session_unset_entry (_data_->session);
			_data_->_tmp7_ = _data_->session_entry;
			_data_->_tmp8_ = ft_session_entry_get_id (_data_->_tmp7_);
			_data_->_tmp9_ = _data_->_tmp8_;
			ft_session_manager_delete_session (_data_->self, _data_->_data43_->repository, _data_->_tmp9_);
			_g_object_unref0 (_data_->session_entry);
		}
		block43_data_unref (_data_->_data43_);
		_data_->_data43_ = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->session_entry_needs_update = ft_session_should_update_entry (_data_->session);
	_data_->_tmp10_ = ft_session_create_or_update_entry (_data_->session);
	_data_->_tmp11_ = _g_object_ref0 (_data_->_tmp10_);
	_data_->_vala1_session_entry = _data_->_tmp11_;
	_data_->_tmp12_ = g_array_new (TRUE, TRUE, sizeof (gint64));
	_data_->_data43_->keep_time_block_ids = _data_->_tmp12_;
	_data_->_tmp13_ = g_direct_hash;
	_data_->_tmp14_ = g_direct_equal;
	_data_->_tmp15_ = g_hash_table_new_full (_data_->_tmp13_, _data_->_tmp14_, NULL, ___lambda45__gdestroy_notify);
	_data_->_data43_->keep_gap_ids = _data_->_tmp15_;
	_data_->_tmp16_ = g_direct_hash;
	_data_->_tmp17_ = g_direct_equal;
	_data_->_tmp18_ = g_hash_table_new_full (_data_->_tmp16_, _data_->_tmp17_, NULL, NULL);
	_data_->_data43_->time_block_mapping = _data_->_tmp18_;
	_data_->_tmp19_ = g_direct_hash;
	_data_->_tmp20_ = g_direct_equal;
	_data_->_tmp21_ = g_hash_table_new_full (_data_->_tmp19_, _data_->_tmp20_, NULL, NULL);
	_data_->_data43_->gap_mapping = _data_->_tmp21_;
	_data_->_tmp22_ = _data_->_vala1_session_entry;
	_data_->_tmp23_ = ft_session_entry_get_expiry_time (_data_->_tmp22_);
	_data_->_tmp24_ = _data_->_tmp23_;
	if (ft_timestamp_is_undefined (_data_->_tmp24_)) {
		_data_->_tmp25_ = _data_->_vala1_session_entry;
		ft_session_entry_set_expiry_time (_data_->_tmp25_, ft_session_manager_get_current_time (_data_->self) + FT_SESSION_MANAGER_SESSION_EXPIRY_TIMEOUT);
		_data_->session_entry_needs_update = TRUE;
	}
	ft_session_foreach (_data_->session, ___lambda46__gfunc, _data_->_data43_);
	{
		_data_->_data46_ = g_slice_new0 (Block46Data);
		_data_->_data46_->_ref_count_ = 1;
		_data_->_data46_->_data43_ = block43_data_ref (_data_->_data43_);
		if (_data_->session_entry_needs_update) {
			_data_->_tmp26_ = _data_->_vala1_session_entry;
			_data_->_state_ = 1;
			gom_resource_save_async ((GomResource*) _data_->_tmp26_, ft_session_manager_save_session_ready, _data_);
			return FALSE;
			_state_1:
			gom_resource_save_finish ((GomResource*) _data_->_tmp26_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				block46_data_unref (_data_->_data46_);
				_data_->_data46_ = NULL;
				goto __catch0_g_error;
			}
		}
		_data_->_tmp27_ = g_object_new (gom_resource_group_get_type (), "repository", _data_->_data43_->repository, "resource-type", FT_TYPE_TIME_BLOCK_ENTRY, "is-writable", TRUE, NULL);
		_data_->_tmp28_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp27_) ? g_object_ref_sink (_data_->_tmp27_) : _data_->_tmp27_;
		_data_->_data46_->time_block_entries = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp28_, gom_resource_group_get_type (), GomResourceGroup);
		_data_->_tmp29_ = _data_->_data43_->time_block_mapping;
		g_hash_table_foreach (_data_->_tmp29_, ____lambda48__gh_func, _data_->_data46_);
		_data_->_tmp30_ = _data_->_vala1_session_entry;
		_data_->_tmp31_ = ft_session_entry_get_id (_data_->_tmp30_);
		_data_->_tmp32_ = _data_->_tmp31_;
		_data_->_tmp33_ = _data_->_data43_->keep_time_block_ids;
		ft_session_manager_delete_time_blocks (_data_->self, _data_->_data43_->repository, _data_->_tmp32_, _data_->_tmp33_);
		_data_->_tmp34_ = _data_->_data46_->time_block_entries;
		gom_resource_group_write_sync (_data_->_tmp34_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			block46_data_unref (_data_->_data46_);
			_data_->_data46_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_tmp35_ = _data_->_data43_->time_block_mapping;
		g_hash_table_foreach (_data_->_tmp35_, ____lambda49__gh_func, _data_->self);
		_data_->_tmp36_ = g_object_new (gom_resource_group_get_type (), "repository", _data_->_data43_->repository, "resource-type", FT_TYPE_TIME_BLOCK_ENTRY, "is-writable", TRUE, NULL);
		_data_->_tmp37_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp36_) ? g_object_ref_sink (_data_->_tmp36_) : _data_->_tmp36_;
		_data_->_data46_->gap_entries = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp37_, gom_resource_group_get_type (), GomResourceGroup);
		_data_->_tmp38_ = _data_->_data43_->gap_mapping;
		g_hash_table_foreach (_data_->_tmp38_, ____lambda50__gh_func, _data_->_data46_);
		_data_->_tmp39_ = _data_->_data43_->keep_gap_ids;
		g_hash_table_foreach (_data_->_tmp39_, ____lambda51__gh_func, _data_->_data46_);
		_data_->_tmp40_ = _data_->_data46_->gap_entries;
		gom_resource_group_write_sync (_data_->_tmp40_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			block46_data_unref (_data_->_data46_);
			_data_->_data46_ = NULL;
			goto __catch0_g_error;
		}
		_data_->_tmp41_ = _data_->_data43_->gap_mapping;
		g_hash_table_foreach (_data_->_tmp41_, ____lambda52__gh_func, _data_->self);
		block46_data_unref (_data_->_data46_);
		_data_->_data46_ = NULL;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp42_ = _data_->_error_;
		_data_->_tmp43_ = _g_error_copy0 (_data_->_tmp42_);
		_data_->_inner_error0_ = _data_->_tmp43_;
		_g_error_free0 (_data_->_error_);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_vala1_session_entry);
		block43_data_unref (_data_->_data43_);
		_data_->_data43_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->_vala1_session_entry);
	block43_data_unref (_data_->_data43_);
	_data_->_data43_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ft_session_manager_save_internal_data_free (gpointer _data)
{
	FtSessionManagerSaveInternalData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FtSessionManagerSaveInternalData, _data_);
}

static void
ft_session_manager_save_internal (FtSessionManager* self,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	FtSessionManagerSaveInternalData* _data_;
	FtSessionManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtSessionManagerSaveInternalData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_session_manager_save_internal_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_session_manager_save_internal_co (_data_);
}

static gboolean
ft_session_manager_save_internal_finish (FtSessionManager* self,
                                         GAsyncResult* _res_)
{
	gboolean result;
	FtSessionManagerSaveInternalData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static Block47Data*
block47_data_ref (Block47Data* _data47_)
{
	g_atomic_int_inc (&_data47_->_ref_count_);
	return _data47_;
}

static void
block47_data_unref (void * _userdata_)
{
	Block47Data* _data47_;
	_data47_ = (Block47Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data47_->_ref_count_)) {
		FtSessionManager* self;
		self = _data47_->self;
		_g_object_unref0 (self);
		g_slice_free (Block47Data, _data47_);
	}
}

static void
___lambda53_ (Block47Data* _data47_,
              GObject* obj,
              GAsyncResult* res)
{
	FtSessionManager* self;
	gint _tmp2_;
	GError* _inner_error0_ = NULL;
	self = _data47_->self;
	g_return_if_fail (res != NULL);
	{
		ft_session_manager_save_session_finish (self, res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = _error_;
		_tmp1_ = _tmp0_->message;
		g_warning ("session-manager.vala:1194: Error while saving previous session: %s", _tmp1_);
		_data47_->success = FALSE;
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_tmp2_ = _data47_->remaining_sessions;
	_data47_->remaining_sessions = _tmp2_ - 1;
	if (_data47_->remaining_sessions == 0) {
		ft_session_manager_save_internal_co (_data47_->_async_data_);
	}
}

static void
____lambda53__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda53_ (self, source_object, res);
	block47_data_unref (self);
}

static void
___lambda54_ (Block47Data* _data47_,
              GObject* obj,
              GAsyncResult* res)
{
	FtSessionManager* self;
	gint _tmp2_;
	GError* _inner_error0_ = NULL;
	self = _data47_->self;
	g_return_if_fail (res != NULL);
	{
		ft_session_manager_save_session_finish (self, res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = _error_;
		_tmp1_ = _tmp0_->message;
		g_warning ("session-manager.vala:1218: Error while saving current session: %s", _tmp1_);
		_data47_->success = FALSE;
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_tmp2_ = _data47_->remaining_sessions;
	_data47_->remaining_sessions = _tmp2_ - 1;
	if (_data47_->remaining_sessions == 0) {
		ft_session_manager_save_internal_co (_data47_->_async_data_);
	}
}

static void
____lambda54__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda54_ (self, source_object, res);
	block47_data_unref (self);
}

static gboolean
ft_session_manager_save_internal_co (FtSessionManagerSaveInternalData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data47_ = g_slice_new0 (Block47Data);
	_data_->_data47_->_ref_count_ = 1;
	_data_->_data47_->self = g_object_ref (_data_->self);
	_data_->_data47_->_async_data_ = _data_;
	_data_->_tmp0_ = ft_database_get_repository ();
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->repository = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->repository;
	_vala_assert (_data_->_tmp2_ != NULL, "repository != null");
	_data_->_data47_->remaining_sessions = 0;
	_data_->_data47_->success = TRUE;
	_data_->_tmp3_ = _data_->self->priv->previous_session;
	if (_data_->_tmp3_ != NULL) {
		_data_->_tmp4_ = _data_->_data47_->remaining_sessions;
		_data_->_data47_->remaining_sessions = _data_->_tmp4_ + 1;
		_data_->_tmp5_ = _data_->repository;
		_data_->_tmp6_ = _data_->self->priv->previous_session;
		ft_session_manager_save_session (_data_->self, _data_->_tmp5_, _data_->_tmp6_, ____lambda53__gasync_ready_callback, block47_data_ref (_data_->_data47_));
	}
	_data_->_tmp7_ = _data_->self->priv->_current_session;
	if (_data_->_tmp7_ != NULL) {
		_data_->_tmp8_ = _data_->_data47_->remaining_sessions;
		_data_->_data47_->remaining_sessions = _data_->_tmp8_ + 1;
		_data_->_tmp9_ = _data_->repository;
		_data_->_tmp10_ = _data_->self->priv->_current_session;
		ft_session_manager_save_session (_data_->self, _data_->_tmp9_, _data_->_tmp10_, ____lambda54__gasync_ready_callback, block47_data_ref (_data_->_data47_));
	}
	if (_data_->_data47_->remaining_sessions > 0) {
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
	}
	_data_->result = _data_->_data47_->success;
	_g_object_unref0 (_data_->repository);
	block47_data_unref (_data_->_data47_);
	_data_->_data47_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ft_session_manager_save_data_free (gpointer _data)
{
	FtSessionManagerSaveData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FtSessionManagerSaveData, _data_);
}

void
ft_session_manager_save (FtSessionManager* self,
                         GAsyncReadyCallback _callback_,
                         gpointer _user_data_)
{
	FtSessionManagerSaveData* _data_;
	FtSessionManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtSessionManagerSaveData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_session_manager_save_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_session_manager_save_co (_data_);
}

gboolean
ft_session_manager_save_finish (FtSessionManager* self,
                                GAsyncResult* _res_)
{
	gboolean result;
	FtSessionManagerSaveData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

/**
         * Save session state to database.
         *
         * Concurrent calls are coalesced: while a save is in progress, all further
         * callers wait and are resumed together after one additional save completes.
         */
static gboolean
_ft_session_manager_save_co_gsource_func (gpointer self)
{
	gboolean result;
	result = ft_session_manager_save_co (self);
	return result;
}

static void
_vala_array_add24 (FtAsyncCallback** * array,
                   gint* length,
                   gint* size,
                   FtAsyncCallback* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (FtAsyncCallback*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
ft_session_manager_save_ready (GObject* source_object,
                               GAsyncResult* _res_,
                               gpointer _user_data_)
{
	FtSessionManagerSaveData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_session_manager_save_co (_data_);
}

static gboolean
ft_session_manager_save_co (FtSessionManagerSaveData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->saving) {
		_data_->self->priv->save_dirty = TRUE;
		_data_->_tmp0_ = ft_async_callback_new (_ft_session_manager_save_co_gsource_func, _data_, NULL);
		_vala_array_add24 (&_data_->self->priv->save_callbacks, &_data_->self->priv->save_callbacks_length1, &_data_->self->priv->_save_callbacks_size_, _data_->_tmp0_);
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
		_data_->result = _data_->self->priv->save_result;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->self->priv->saving = TRUE;
	_data_->_state_ = 2;
	ft_session_manager_save_internal (_data_->self, ft_session_manager_save_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_result_ = ft_session_manager_save_internal_finish (_data_->self, _data_->_res_);
	while (TRUE) {
		if (!_data_->self->priv->save_dirty) {
			break;
		}
		_data_->self->priv->save_dirty = FALSE;
		_data_->_tmp1_ = _data_->self->priv->save_callbacks;
		_data_->_tmp1__length1 = _data_->self->priv->save_callbacks_length1;
		_data_->self->priv->save_callbacks = NULL;
		_data_->self->priv->save_callbacks_length1 = 0;
		_data_->callbacks = _data_->_tmp1_;
		_data_->callbacks_length1 = _data_->_tmp1__length1;
		_data_->_callbacks_size_ = _data_->callbacks_length1;
		_data_->_tmp2_ = g_new0 (FtAsyncCallback*, 0 + 1);
		_data_->self->priv->save_callbacks = (_vala_array_free (_data_->self->priv->save_callbacks, _data_->self->priv->save_callbacks_length1, (GDestroyNotify) ft_async_callback_free), NULL);
		_data_->self->priv->save_callbacks = _data_->_tmp2_;
		_data_->self->priv->save_callbacks_length1 = 0;
		_data_->self->priv->_save_callbacks_size_ = _data_->self->priv->save_callbacks_length1;
		_data_->_state_ = 3;
		ft_session_manager_save_internal (_data_->self, ft_session_manager_save_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_result_ = ft_session_manager_save_internal_finish (_data_->self, _data_->_res_);
		_data_->self->priv->save_result = _data_->_result_;
		_data_->_tmp3_ = _data_->callbacks;
		_data_->_tmp3__length1 = _data_->callbacks_length1;
		{
			_data_->callback_collection_length1 = 0;
			_data_->_callback_collection_size_ = 0;
			_data_->callback_collection = _data_->_tmp3_;
			_data_->callback_collection_length1 = _data_->_tmp3__length1;
			for (_data_->callback_it = 0; _data_->callback_it < _data_->callback_collection_length1; _data_->callback_it = _data_->callback_it + 1) {
				_data_->callback = _data_->callback_collection[_data_->callback_it];
				{
					_data_->_tmp4_ = _data_->callback;
					_data_->_tmp5_ = _data_->_tmp4_->func;
					_data_->_tmp5__target = _data_->_tmp4_->func_target;
					_data_->_tmp5_ (_data_->_tmp5__target);
				}
			}
		}
		_data_->callbacks = (_vala_array_free (_data_->callbacks, _data_->callbacks_length1, (GDestroyNotify) ft_async_callback_free), NULL);
	}
	_data_->self->priv->saving = FALSE;
	_data_->result = _data_->_result_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ft_session_manager_restore_session_data_free (gpointer _data)
{
	FtSessionManagerRestoreSessionData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->repository);
	_g_object_unref0 (_data_->session_entry);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (FtSessionManagerRestoreSessionData, _data_);
}

static void
ft_session_manager_restore_session (FtSessionManager* self,
                                    GomRepository* repository,
                                    FtSessionEntry* session_entry,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	FtSessionManagerRestoreSessionData* _data_;
	FtSessionManager* _tmp0_;
	GomRepository* _tmp1_;
	FtSessionEntry* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (repository != NULL);
	g_return_if_fail (session_entry != NULL);
	_data_ = g_slice_new0 (FtSessionManagerRestoreSessionData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_session_manager_restore_session_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (repository);
	_g_object_unref0 (_data_->repository);
	_data_->repository = _tmp1_;
	_tmp2_ = _g_object_ref0 (session_entry);
	_g_object_unref0 (_data_->session_entry);
	_data_->session_entry = _tmp2_;
	ft_session_manager_restore_session_co (_data_);
}

static FtSession*
ft_session_manager_restore_session_finish (FtSessionManager* self,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	FtSession* result;
	FtSessionManagerRestoreSessionData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
ft_session_manager_restore_session_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	FtSessionManagerRestoreSessionData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_session_manager_restore_session_co (_data_);
}

static void
_g_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_free (var), NULL));
}

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

static void
_vala_array_add25 (GomFilter** * array,
                   gint* length,
                   gint* size,
                   GomFilter* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GomFilter*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
__lambda55_ (FtSessionManager* self,
             FtTimeBlock* time_block)
{
	g_return_if_fail (time_block != NULL);
	ft_time_block_normalize_gaps (time_block);
}

static void
___lambda55__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda55_ ((FtSessionManager*) self, (FtTimeBlock*) data);
}

static gboolean
ft_session_manager_restore_session_co (FtSessionManagerRestoreSessionData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	memset (&_data_->_tmp0_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp0_, G_TYPE_INT64);
	_data_->session_id_value = _data_->_tmp0_;
	_data_->_tmp1_ = ft_session_entry_get_id (_data_->session_entry);
	_data_->_tmp2_ = _data_->_tmp1_;
	g_value_set_int64 (&_data_->session_id_value, _data_->_tmp2_);
	_data_->_tmp3_ = _data_->session_id_value;
	_data_->_tmp4_ = gom_filter_new_eq (FT_TYPE_TIME_BLOCK_ENTRY, "session-id", &_data_->_tmp3_);
	g_object_ref_sink (_data_->_tmp4_);
	_data_->time_block_filter = _data_->_tmp4_;
	_data_->_tmp5_ = g_object_new (gom_sorting_get_type (), NULL);
	_data_->_tmp6_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp5_) ? g_object_ref_sink (_data_->_tmp5_) : _data_->_tmp5_;
	_data_->time_block_sorting = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp6_, gom_sorting_get_type (), GomSorting);
	_data_->_tmp7_ = _data_->time_block_sorting;
	gom_sorting_add (_data_->_tmp7_, FT_TYPE_TIME_BLOCK_ENTRY, "start-time", GOM_SORTING_ASCENDING);
	_data_->_tmp8_ = _data_->time_block_filter;
	_data_->_tmp9_ = _data_->time_block_sorting;
	_data_->_state_ = 1;
	gom_repository_find_sorted_async (_data_->repository, FT_TYPE_TIME_BLOCK_ENTRY, _data_->_tmp8_, _data_->_tmp9_, ft_session_manager_restore_session_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp10_ = gom_repository_find_finish (_data_->repository, _data_->_res_, &_data_->_inner_error0_);
	_data_->time_block_results = _data_->_tmp10_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->time_block_sorting);
		_g_object_unref0 (_data_->time_block_filter);
		G_IS_VALUE (&_data_->session_id_value) ? (g_value_unset (&_data_->session_id_value), NULL) : NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->time_block_results;
	_data_->_tmp12_ = gom_resource_group_get_count (_data_->_tmp11_);
	_data_->_tmp13_ = _data_->_tmp12_;
	if (_data_->_tmp13_ == ((guint) 0)) {
		_data_->result = NULL;
		_g_object_unref0 (_data_->time_block_results);
		_g_object_unref0 (_data_->time_block_sorting);
		_g_object_unref0 (_data_->time_block_filter);
		G_IS_VALUE (&_data_->session_id_value) ? (g_value_unset (&_data_->session_id_value), NULL) : NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp14_ = _data_->time_block_results;
	_data_->_tmp15_ = _data_->time_block_results;
	_data_->_tmp16_ = gom_resource_group_get_count (_data_->_tmp15_);
	_data_->_tmp17_ = _data_->_tmp16_;
	_data_->_state_ = 2;
	gom_resource_group_fetch_async (_data_->_tmp14_, (guint) 0, _data_->_tmp17_, ft_session_manager_restore_session_ready, _data_);
	return FALSE;
	_state_2:
	gom_resource_group_fetch_finish (_data_->_tmp14_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->time_block_results);
		_g_object_unref0 (_data_->time_block_sorting);
		_g_object_unref0 (_data_->time_block_filter);
		G_IS_VALUE (&_data_->session_id_value) ? (g_value_unset (&_data_->session_id_value), NULL) : NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp18_ = ft_session_new ();
	_data_->session = _data_->_tmp18_;
	_data_->_tmp19_ = _data_->session;
	_data_->_tmp20_ = ft_session_entry_get_expiry_time (_data_->session_entry);
	_data_->_tmp21_ = _data_->_tmp20_;
	ft_session_set_expiry_time (_data_->_tmp19_, _data_->_tmp21_);
	_data_->_tmp22_ = _data_->session;
	_data_->_tmp23_ = _g_object_ref0 (_data_->session_entry);
	_g_object_unref0 (_data_->_tmp22_->entry);
	_data_->_tmp22_->entry = _data_->_tmp23_;
	_data_->_tmp24_ = g_int64_hash;
	_data_->_tmp25_ = g_int64_equal;
	_data_->_tmp26_ = g_hash_table_new_full (_data_->_tmp24_, _data_->_tmp25_, _g_free0_, _g_object_unref0_);
	_data_->time_blocks_by_id = _data_->_tmp26_;
	_data_->_tmp27_ = g_new0 (GomFilter*, 0 + 1);
	_data_->gap_filters = _data_->_tmp27_;
	_data_->gap_filters_length1 = 0;
	_data_->_gap_filters_size_ = _data_->gap_filters_length1;
	{
		_data_->i = 0;
		{
			_data_->_tmp28_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp28_) {
					_data_->_tmp29_ = _data_->i;
					_data_->i = _data_->_tmp29_ + 1;
				}
				_data_->_tmp28_ = FALSE;
				_data_->_tmp30_ = _data_->time_block_results;
				_data_->_tmp31_ = gom_resource_group_get_count (_data_->_tmp30_);
				_data_->_tmp32_ = _data_->_tmp31_;
				if (!(((guint) _data_->i) < _data_->_tmp32_)) {
					break;
				}
				_data_->_tmp33_ = _data_->time_block_results;
				_data_->_tmp34_ = gom_resource_group_get_index (_data_->_tmp33_, (guint) _data_->i);
				_data_->_tmp35_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp34_, FT_TYPE_TIME_BLOCK_ENTRY, FtTimeBlockEntry));
				_data_->time_block_entry = _data_->_tmp35_;
				_data_->_tmp36_ = _data_->time_block_entry;
				_data_->_tmp37_ = ft_time_block_entry_get_state (_data_->_tmp36_);
				_data_->_tmp38_ = _data_->_tmp37_;
				_data_->_tmp39_ = ft_time_block_new (ft_state_from_string (_data_->_tmp38_));
				g_object_ref_sink (_data_->_tmp39_);
				_data_->time_block = _data_->_tmp39_;
				_data_->_tmp40_ = _data_->time_block;
				_data_->_tmp41_ = _data_->time_block_entry;
				_data_->_tmp42_ = ft_time_block_entry_get_start_time (_data_->_tmp41_);
				_data_->_tmp43_ = _data_->_tmp42_;
				_data_->_tmp44_ = _data_->time_block_entry;
				_data_->_tmp45_ = ft_time_block_entry_get_end_time (_data_->_tmp44_);
				_data_->_tmp46_ = _data_->_tmp45_;
				ft_schedulable_set_time_range ((FtSchedulable*) _data_->_tmp40_, _data_->_tmp43_, _data_->_tmp46_);
				_data_->_tmp47_ = _data_->time_block;
				_data_->_tmp48_ = _data_->time_block_entry;
				_data_->_tmp49_ = ft_time_block_entry_get_status (_data_->_tmp48_);
				_data_->_tmp50_ = _data_->_tmp49_;
				ft_time_block_set_status (_data_->_tmp47_, ft_time_block_status_from_string (_data_->_tmp50_));
				_data_->_tmp51_ = _data_->time_block;
				_data_->_tmp52_ = _data_->time_block_entry;
				_data_->_tmp53_ = ft_time_block_entry_get_intended_duration (_data_->_tmp52_);
				_data_->_tmp54_ = _data_->_tmp53_;
				ft_time_block_set_intended_duration (_data_->_tmp51_, _data_->_tmp54_);
				_data_->_tmp55_ = _data_->time_block;
				_data_->_tmp56_ = _data_->time_block_entry;
				_data_->_tmp57_ = _g_object_ref0 (_data_->_tmp56_);
				_g_object_unref0 (_data_->_tmp55_->entry);
				_data_->_tmp55_->entry = _data_->_tmp57_;
				_data_->_tmp58_ = _data_->time_blocks_by_id;
				_data_->_tmp59_ = _data_->time_block_entry;
				_data_->_tmp60_ = ft_time_block_entry_get_id (_data_->_tmp59_);
				_data_->_tmp61_ = _data_->_tmp60_;
				_data_->_tmp62_ = __int64_dup0 (&_data_->_tmp61_);
				_data_->_tmp63_ = _data_->time_block;
				_data_->_tmp64_ = _g_object_ref0 (_data_->_tmp63_);
				g_hash_table_insert (_data_->_tmp58_, _data_->_tmp62_, _data_->_tmp64_);
				memset (&_data_->_tmp65_, 0, sizeof (GValue));
				g_value_init (&_data_->_tmp65_, G_TYPE_INT64);
				_data_->time_block_id_value = _data_->_tmp65_;
				_data_->_tmp66_ = _data_->time_block_entry;
				_data_->_tmp67_ = ft_time_block_entry_get_id (_data_->_tmp66_);
				_data_->_tmp68_ = _data_->_tmp67_;
				g_value_set_int64 (&_data_->time_block_id_value, _data_->_tmp68_);
				_data_->_tmp69_ = _data_->time_block_id_value;
				_data_->_tmp70_ = gom_filter_new_eq (FT_TYPE_GAP_ENTRY, "time-block-id", &_data_->_tmp69_);
				g_object_ref_sink (_data_->_tmp70_);
				_vala_array_add25 (&_data_->gap_filters, &_data_->gap_filters_length1, &_data_->_gap_filters_size_, _data_->_tmp70_);
				_data_->_tmp71_ = _data_->session;
				_data_->_tmp72_ = _data_->time_block;
				ft_session_append (_data_->_tmp71_, _data_->_tmp72_);
				G_IS_VALUE (&_data_->time_block_id_value) ? (g_value_unset (&_data_->time_block_id_value), NULL) : NULL;
				_g_object_unref0 (_data_->time_block);
				_g_object_unref0 (_data_->time_block_entry);
			}
		}
	}
	_data_->_tmp73_ = _data_->gap_filters;
	_data_->_tmp73__length1 = _data_->gap_filters_length1;
	if (_data_->_tmp73__length1 > 0) {
		_data_->_tmp75_ = _data_->gap_filters;
		_data_->_tmp75__length1 = _data_->gap_filters_length1;
		if (_data_->_tmp75__length1 == 1) {
			_data_->_tmp76_ = _data_->gap_filters;
			_data_->_tmp76__length1 = _data_->gap_filters_length1;
			_data_->_tmp77_ = _data_->_tmp76_[0];
			_data_->_tmp78_ = _g_object_ref0 (_data_->_tmp77_);
			_g_object_unref0 (_data_->_tmp74_);
			_data_->_tmp74_ = _data_->_tmp78_;
		} else {
			_data_->_tmp79_ = _data_->gap_filters;
			_data_->_tmp79__length1 = _data_->gap_filters_length1;
			_data_->_tmp80_ = gom_filter_new_or_fullv ((GomFilter**) _data_->_tmp79_);
			g_object_ref_sink (_data_->_tmp80_);
			_g_object_unref0 (_data_->_tmp74_);
			_data_->_tmp74_ = _data_->_tmp80_;
		}
		_data_->_tmp81_ = _data_->_tmp74_;
		_data_->_tmp74_ = NULL;
		_data_->gap_filter = _data_->_tmp81_;
		_data_->_tmp82_ = g_object_new (gom_sorting_get_type (), NULL);
		_data_->_tmp83_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp82_) ? g_object_ref_sink (_data_->_tmp82_) : _data_->_tmp82_;
		_data_->gap_sorting = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp83_, gom_sorting_get_type (), GomSorting);
		_data_->_tmp84_ = _data_->gap_sorting;
		gom_sorting_add (_data_->_tmp84_, FT_TYPE_GAP_ENTRY, "start-time", GOM_SORTING_ASCENDING);
		_data_->_tmp85_ = _data_->gap_filter;
		_data_->_tmp86_ = _data_->gap_sorting;
		_data_->_state_ = 3;
		gom_repository_find_sorted_async (_data_->repository, FT_TYPE_GAP_ENTRY, _data_->_tmp85_, _data_->_tmp86_, ft_session_manager_restore_session_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp87_ = gom_repository_find_finish (_data_->repository, _data_->_res_, &_data_->_inner_error0_);
		_data_->gap_results = _data_->_tmp87_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->gap_sorting);
			_g_object_unref0 (_data_->gap_filter);
			_g_object_unref0 (_data_->_tmp74_);
			_data_->gap_filters = (_vala_array_free (_data_->gap_filters, _data_->gap_filters_length1, (GDestroyNotify) g_object_unref), NULL);
			_g_hash_table_unref0 (_data_->time_blocks_by_id);
			_g_object_unref0 (_data_->session);
			_g_object_unref0 (_data_->time_block_results);
			_g_object_unref0 (_data_->time_block_sorting);
			_g_object_unref0 (_data_->time_block_filter);
			G_IS_VALUE (&_data_->session_id_value) ? (g_value_unset (&_data_->session_id_value), NULL) : NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp88_ = _data_->gap_results;
		_data_->_tmp89_ = _data_->gap_results;
		_data_->_tmp90_ = gom_resource_group_get_count (_data_->_tmp89_);
		_data_->_tmp91_ = _data_->_tmp90_;
		_data_->_state_ = 4;
		gom_resource_group_fetch_async (_data_->_tmp88_, (guint) 0, _data_->_tmp91_, ft_session_manager_restore_session_ready, _data_);
		return FALSE;
		_state_4:
		gom_resource_group_fetch_finish (_data_->_tmp88_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->gap_results);
			_g_object_unref0 (_data_->gap_sorting);
			_g_object_unref0 (_data_->gap_filter);
			_g_object_unref0 (_data_->_tmp74_);
			_data_->gap_filters = (_vala_array_free (_data_->gap_filters, _data_->gap_filters_length1, (GDestroyNotify) g_object_unref), NULL);
			_g_hash_table_unref0 (_data_->time_blocks_by_id);
			_g_object_unref0 (_data_->session);
			_g_object_unref0 (_data_->time_block_results);
			_g_object_unref0 (_data_->time_block_sorting);
			_g_object_unref0 (_data_->time_block_filter);
			G_IS_VALUE (&_data_->session_id_value) ? (g_value_unset (&_data_->session_id_value), NULL) : NULL;
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		{
			_data_->j = 0;
			{
				_data_->_tmp92_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp92_) {
						_data_->_tmp93_ = _data_->j;
						_data_->j = _data_->_tmp93_ + 1;
					}
					_data_->_tmp92_ = FALSE;
					_data_->_tmp94_ = _data_->gap_results;
					_data_->_tmp95_ = gom_resource_group_get_count (_data_->_tmp94_);
					_data_->_tmp96_ = _data_->_tmp95_;
					if (!(((guint) _data_->j) < _data_->_tmp96_)) {
						break;
					}
					_data_->_tmp97_ = _data_->gap_results;
					_data_->_tmp98_ = gom_resource_group_get_index (_data_->_tmp97_, (guint) _data_->j);
					_data_->_tmp99_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp98_, FT_TYPE_GAP_ENTRY, FtGapEntry));
					_data_->gap_entry = _data_->_tmp99_;
					_data_->_tmp100_ = _data_->time_blocks_by_id;
					_data_->_tmp101_ = _data_->gap_entry;
					_data_->_tmp102_ = ft_gap_entry_get_time_block_id (_data_->_tmp101_);
					_data_->_tmp103_ = _data_->_tmp102_;
					_data_->_tmp104_ = g_hash_table_lookup (_data_->_tmp100_, &_data_->_tmp103_);
					_data_->_tmp105_ = _g_object_ref0 ((FtTimeBlock*) _data_->_tmp104_);
					_data_->_vala1_time_block = _data_->_tmp105_;
					_data_->_tmp106_ = _data_->gap_entry;
					_data_->_tmp107_ = ft_gap_entry_get_flags (_data_->_tmp106_);
					_data_->_tmp108_ = _data_->_tmp107_;
					_data_->_tmp109_ = ft_gap_new (ft_gap_flags_from_string (_data_->_tmp108_));
					g_object_ref_sink (_data_->_tmp109_);
					_data_->gap = _data_->_tmp109_;
					_data_->_tmp110_ = _data_->gap;
					_data_->_tmp111_ = _data_->gap_entry;
					_data_->_tmp112_ = ft_gap_entry_get_start_time (_data_->_tmp111_);
					_data_->_tmp113_ = _data_->_tmp112_;
					_data_->_tmp114_ = _data_->gap_entry;
					_data_->_tmp115_ = ft_gap_entry_get_end_time (_data_->_tmp114_);
					_data_->_tmp116_ = _data_->_tmp115_;
					ft_schedulable_set_time_range ((FtSchedulable*) _data_->_tmp110_, _data_->_tmp113_, _data_->_tmp116_);
					_data_->_tmp117_ = _data_->gap;
					_data_->_tmp118_ = _data_->gap_entry;
					_data_->_tmp119_ = _g_object_ref0 (_data_->_tmp118_);
					_g_object_unref0 (_data_->_tmp117_->entry);
					_data_->_tmp117_->entry = _data_->_tmp119_;
					_data_->_tmp120_ = _data_->gap;
					_data_->_tmp121_ = ft_schedulable_get_start_time ((FtSchedulable*) _data_->_tmp120_);
					_data_->_tmp122_ = _data_->_tmp121_;
					_data_->_tmp123_ = _data_->_vala1_time_block;
					_data_->_tmp124_ = ft_schedulable_get_start_time ((FtSchedulable*) _data_->_tmp123_);
					_data_->_tmp125_ = _data_->_tmp124_;
					if (_data_->_tmp122_ < _data_->_tmp125_) {
						_data_->_tmp126_ = _data_->gap;
						_data_->_tmp127_ = _data_->_vala1_time_block;
						_data_->_tmp128_ = ft_schedulable_get_start_time ((FtSchedulable*) _data_->_tmp127_);
						_data_->_tmp129_ = _data_->_tmp128_;
						ft_schedulable_set_start_time ((FtSchedulable*) _data_->_tmp126_, _data_->_tmp129_);
					}
					_data_->_tmp132_ = _data_->gap;
					_data_->_tmp133_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp132_);
					_data_->_tmp134_ = _data_->_tmp133_;
					if (ft_timestamp_is_defined (_data_->_tmp134_)) {
						_data_->_tmp135_ = _data_->_vala1_time_block;
						_data_->_tmp136_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp135_);
						_data_->_tmp137_ = _data_->_tmp136_;
						_data_->_tmp131_ = ft_timestamp_is_defined (_data_->_tmp137_);
					} else {
						_data_->_tmp131_ = FALSE;
					}
					if (_data_->_tmp131_) {
						_data_->_tmp138_ = _data_->gap;
						_data_->_tmp139_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp138_);
						_data_->_tmp140_ = _data_->_tmp139_;
						_data_->_tmp141_ = _data_->_vala1_time_block;
						_data_->_tmp142_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp141_);
						_data_->_tmp143_ = _data_->_tmp142_;
						_data_->_tmp130_ = _data_->_tmp140_ > _data_->_tmp143_;
					} else {
						_data_->_tmp130_ = FALSE;
					}
					if (_data_->_tmp130_) {
						_data_->_tmp144_ = _data_->gap;
						_data_->_tmp145_ = _data_->_vala1_time_block;
						_data_->_tmp146_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp145_);
						_data_->_tmp147_ = _data_->_tmp146_;
						ft_schedulable_set_end_time ((FtSchedulable*) _data_->_tmp144_, _data_->_tmp147_);
					}
					_data_->_tmp149_ = _data_->gap;
					_data_->_tmp150_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp149_);
					_data_->_tmp151_ = _data_->_tmp150_;
					if (ft_timestamp_is_undefined (_data_->_tmp151_)) {
						_data_->_tmp148_ = TRUE;
					} else {
						_data_->_tmp152_ = _data_->gap;
						_data_->_tmp153_ = ft_schedulable_get_duration ((FtSchedulable*) _data_->_tmp152_);
						_data_->_tmp154_ = _data_->_tmp153_;
						_data_->_tmp148_ = _data_->_tmp154_ > ((gint64) 0);
					}
					if (_data_->_tmp148_) {
						_data_->_tmp155_ = _data_->_vala1_time_block;
						_data_->_tmp156_ = _data_->gap;
						ft_time_block_add_gap (_data_->_tmp155_, _data_->_tmp156_);
					}
					_g_object_unref0 (_data_->gap);
					_g_object_unref0 (_data_->_vala1_time_block);
					_g_object_unref0 (_data_->gap_entry);
				}
			}
		}
		_g_object_unref0 (_data_->gap_results);
		_g_object_unref0 (_data_->gap_sorting);
		_g_object_unref0 (_data_->gap_filter);
		_g_object_unref0 (_data_->_tmp74_);
	}
	_data_->_tmp157_ = _data_->session;
	ft_session_foreach (_data_->_tmp157_, ___lambda55__gfunc, _data_->self);
	_data_->_tmp158_ = _data_->self->priv->_scheduler;
	_data_->_tmp159_ = _data_->session;
	ft_scheduler_ensure_session_meta (_data_->_tmp158_, _data_->_tmp159_);
	_data_->result = _data_->session;
	_data_->gap_filters = (_vala_array_free (_data_->gap_filters, _data_->gap_filters_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_hash_table_unref0 (_data_->time_blocks_by_id);
	_g_object_unref0 (_data_->time_block_results);
	_g_object_unref0 (_data_->time_block_sorting);
	_g_object_unref0 (_data_->time_block_filter);
	G_IS_VALUE (&_data_->session_id_value) ? (g_value_unset (&_data_->session_id_value), NULL) : NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ft_session_manager_restore_data_free (gpointer _data)
{
	FtSessionManagerRestoreData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FtSessionManagerRestoreData, _data_);
}

void
ft_session_manager_restore (FtSessionManager* self,
                            gint64 timestamp,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	FtSessionManagerRestoreData* _data_;
	FtSessionManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtSessionManagerRestoreData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_session_manager_restore_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->timestamp = timestamp;
	ft_session_manager_restore_co (_data_);
}

gboolean
ft_session_manager_restore_finish (FtSessionManager* self,
                                   GAsyncResult* _res_)
{
	gboolean result;
	FtSessionManagerRestoreData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

/**
         * Restore session from database.
         */
static Block48Data*
block48_data_ref (Block48Data* _data48_)
{
	g_atomic_int_inc (&_data48_->_ref_count_);
	return _data48_;
}

static void
block48_data_unref (void * _userdata_)
{
	Block48Data* _data48_;
	_data48_ = (Block48Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data48_->_ref_count_)) {
		FtSessionManager* self;
		self = _data48_->self;
		_g_object_unref0 (_data48_->restored_gap);
		_g_object_unref0 (_data48_->restored_time_block);
		_g_object_unref0 (self);
		g_slice_free (Block48Data, _data48_);
	}
}

static void
ft_session_manager_restore_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	FtSessionManagerRestoreData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_session_manager_restore_co (_data_);
}

static void
___lambda56_ (Block48Data* _data48_,
              FtTimeBlock* time_block)
{
	FtSessionManager* self;
	self = _data48_->self;
	g_return_if_fail (time_block != NULL);
	if (ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_IN_PROGRESS) {
		FtTimeBlock* _tmp0_;
		_tmp0_ = _g_object_ref0 (time_block);
		_g_object_unref0 (_data48_->restored_time_block);
		_data48_->restored_time_block = _tmp0_;
	}
}

static void
____lambda56__gfunc (gconstpointer data,
                     gpointer self)
{
	___lambda56_ (self, (FtTimeBlock*) data);
}

static void
____lambda57_ (Block48Data* _data48_,
               FtGap* gap)
{
	FtSessionManager* self;
	gint64 _tmp0_;
	gint64 _tmp1_;
	self = _data48_->self;
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp1_ = _tmp0_;
	if (ft_timestamp_is_undefined (_tmp1_)) {
		FtGap* _tmp2_;
		_tmp2_ = _g_object_ref0 (gap);
		_g_object_unref0 (_data48_->restored_gap);
		_data48_->restored_gap = _tmp2_;
	}
}

static void
_____lambda57__gfunc (gconstpointer data,
                      gpointer self)
{
	____lambda57_ (self, (FtGap*) data);
}

static gboolean
ft_session_manager_restore_co (FtSessionManagerRestoreData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data48_ = g_slice_new0 (Block48Data);
	_data_->_data48_->_ref_count_ = 1;
	_data_->_data48_->self = g_object_ref (_data_->self);
	_data_->_data48_->_async_data_ = _data_;
	_data_->session_entry = NULL;
	_data_->restored_session = NULL;
	_data_->_data48_->restored_time_block = NULL;
	_data_->_data48_->restored_gap = NULL;
	ft_ensure_timestamp (&_data_->timestamp);
	_data_->_tmp0_ = ft_database_get_repository ();
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->repository = _data_->_tmp1_;
	_data_->success = TRUE;
	_data_->_tmp2_ = _data_->repository;
	_vala_assert (_data_->_tmp2_ != NULL, "repository != null");
	_data_->_tmp3_ = _data_->self->priv->timezone_monitor;
	_data_->_tmp4_ = ft_time_zone_monitor_get_timezone (_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	ft_session_manager_mark_timezone (_data_->self, _data_->_tmp5_, _data_->timestamp);
	memset (&_data_->_tmp6_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp6_, G_TYPE_INT64);
	_data_->end_time_value = _data_->_tmp6_;
	g_value_set_int64 (&_data_->end_time_value, _data_->timestamp - FT_SESSION_MANAGER_SESSION_EXPIRY_TIMEOUT);
	_data_->_tmp7_ = _data_->end_time_value;
	_data_->_tmp8_ = gom_filter_new_gte (FT_TYPE_SESSION_ENTRY, "end-time", &_data_->_tmp7_);
	g_object_ref_sink (_data_->_tmp8_);
	_data_->session_filter = _data_->_tmp8_;
	_data_->_tmp9_ = g_object_new (gom_sorting_get_type (), NULL);
	_data_->_tmp10_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp9_) ? g_object_ref_sink (_data_->_tmp9_) : _data_->_tmp9_;
	_data_->session_sorting = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, gom_sorting_get_type (), GomSorting);
	_data_->_tmp11_ = _data_->session_sorting;
	gom_sorting_add (_data_->_tmp11_, FT_TYPE_SESSION_ENTRY, "start-time", GOM_SORTING_DESCENDING);
	{
		_data_->_tmp12_ = _data_->repository;
		_data_->_tmp13_ = _data_->session_filter;
		_data_->_tmp14_ = _data_->session_sorting;
		_data_->_state_ = 1;
		gom_repository_find_sorted_async (_data_->_tmp12_, FT_TYPE_SESSION_ENTRY, _data_->_tmp13_, _data_->_tmp14_, ft_session_manager_restore_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp15_ = gom_repository_find_finish (_data_->_tmp12_, _data_->_res_, &_data_->_inner_error0_);
		_data_->session_results = _data_->_tmp15_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp16_ = _data_->session_results;
		_data_->_tmp17_ = gom_resource_group_get_count (_data_->_tmp16_);
		_data_->_tmp18_ = _data_->_tmp17_;
		if (_data_->_tmp18_ > ((guint) 0)) {
			_data_->_tmp19_ = _data_->session_results;
			_data_->_state_ = 2;
			gom_resource_group_fetch_async (_data_->_tmp19_, (guint) 0, (guint) 1, ft_session_manager_restore_ready, _data_);
			return FALSE;
			_state_2:
			gom_resource_group_fetch_finish (_data_->_tmp19_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->session_results);
				goto __catch0_g_error;
			}
			_data_->_tmp20_ = _data_->session_results;
			_data_->_tmp21_ = gom_resource_group_get_index (_data_->_tmp20_, (guint) 0);
			_data_->_tmp22_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp21_, FT_TYPE_SESSION_ENTRY, FtSessionEntry));
			_g_object_unref0 (_data_->session_entry);
			_data_->session_entry = _data_->_tmp22_;
		}
		_g_object_unref0 (_data_->session_results);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp23_ = _data_->_error_;
		_data_->_tmp24_ = _data_->_tmp23_->message;
		g_warning ("session-manager.vala:1438: Unable to fetch last session: %s", _data_->_tmp24_);
		_data_->success = FALSE;
		_g_error_free0 (_data_->_error_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->session_sorting);
		_g_object_unref0 (_data_->session_filter);
		G_IS_VALUE (&_data_->end_time_value) ? (g_value_unset (&_data_->end_time_value), NULL) : NULL;
		_g_object_unref0 (_data_->repository);
		_g_object_unref0 (_data_->restored_session);
		_g_object_unref0 (_data_->session_entry);
		block48_data_unref (_data_->_data48_);
		_data_->_data48_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp25_ = _data_->session_entry;
	if (_data_->_tmp25_ != NULL) {
		{
			_data_->_tmp27_ = _data_->repository;
			_data_->_tmp28_ = _data_->session_entry;
			_data_->_state_ = 3;
			ft_session_manager_restore_session (_data_->self, _data_->_tmp27_, _data_->_tmp28_, ft_session_manager_restore_ready, _data_);
			return FALSE;
			_state_3:
			_data_->_tmp29_ = ft_session_manager_restore_session_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp26_ = _data_->_tmp29_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			_data_->_tmp30_ = _data_->_tmp26_;
			_data_->_tmp26_ = NULL;
			_g_object_unref0 (_data_->restored_session);
			_data_->restored_session = _data_->_tmp30_;
			_g_object_unref0 (_data_->_tmp26_);
		}
		goto __finally1;
		__catch1_g_error:
		{
			_data_->_vala1__error_ = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp31_ = _data_->session_entry;
			_data_->_tmp32_ = ft_session_entry_get_id (_data_->_tmp31_);
			_data_->_tmp33_ = _data_->_tmp32_;
			_data_->_tmp34_ = g_strdup_printf ("%" G_GINT64_FORMAT, _data_->_tmp33_);
			_data_->_tmp35_ = _data_->_tmp34_;
			_data_->_tmp36_ = _data_->_vala1__error_;
			_data_->_tmp37_ = _data_->_tmp36_->message;
			g_warning ("session-manager.vala:1449: Unable to restore session #%s: %s", _data_->_tmp35_, _data_->_tmp37_);
			_g_free0 (_data_->_tmp35_);
			_data_->success = FALSE;
			_g_error_free0 (_data_->_vala1__error_);
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->session_sorting);
			_g_object_unref0 (_data_->session_filter);
			G_IS_VALUE (&_data_->end_time_value) ? (g_value_unset (&_data_->end_time_value), NULL) : NULL;
			_g_object_unref0 (_data_->repository);
			_g_object_unref0 (_data_->restored_session);
			_g_object_unref0 (_data_->session_entry);
			block48_data_unref (_data_->_data48_);
			_data_->_data48_ = NULL;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp38_ = _data_->restored_session;
	if (_data_->_tmp38_ != NULL) {
		_data_->_tmp39_ = _data_->restored_session;
		ft_session_foreach (_data_->_tmp39_, ____lambda56__gfunc, _data_->_data48_);
		_data_->_tmp41_ = _data_->_data48_->restored_time_block;
		_data_->_tmp40_ = _data_->_tmp41_;
		if (_data_->_tmp40_ != NULL) {
			ft_time_block_foreach_gap (_data_->_tmp40_, _____lambda57__gfunc, _data_->_data48_);
		}
		_data_->_tmp44_ = _data_->_data48_->restored_time_block;
		if (_data_->_tmp44_ != NULL) {
			_data_->_tmp45_ = _data_->_data48_->restored_time_block;
			_data_->_tmp46_ = ft_schedulable_get_end_time ((FtSchedulable*) _data_->_tmp45_);
			_data_->_tmp47_ = _data_->_tmp46_;
			_data_->_tmp43_ = _data_->_tmp47_ > _data_->timestamp;
		} else {
			_data_->_tmp43_ = FALSE;
		}
		if (_data_->_tmp43_) {
			_data_->_tmp48_ = _data_->_data48_->restored_gap;
			_data_->_tmp42_ = _data_->_tmp48_ == NULL;
		} else {
			_data_->_tmp42_ = FALSE;
		}
		if (_data_->_tmp42_) {
			g_warning ("session-manager.vala:1474: Restoring a time-block that hasn't been pau" \
"sed. Rewinding to last known position...");
			_data_->_tmp49_ = _data_->_data48_->restored_time_block;
			_data_->_tmp50_ = ft_time_block_get_last_gap (_data_->_tmp49_);
			_data_->_tmp51_ = _g_object_ref0 (_data_->_tmp50_);
			_g_object_unref0 (_data_->_data48_->restored_gap);
			_data_->_data48_->restored_gap = _data_->_tmp51_;
			_data_->_tmp52_ = _data_->_data48_->restored_gap;
			if (_data_->_tmp52_ != NULL) {
				_data_->_tmp53_ = _data_->_data48_->restored_gap;
				ft_schedulable_set_end_time ((FtSchedulable*) _data_->_tmp53_, FT_TIMESTAMP_UNDEFINED);
			} else {
				_data_->_tmp54_ = _data_->_data48_->restored_time_block;
				ft_time_block_set_status (_data_->_tmp54_, FT_TIME_BLOCK_STATUS_SCHEDULED);
				_g_object_unref0 (_data_->_data48_->restored_time_block);
				_data_->_data48_->restored_time_block = NULL;
			}
		}
		_data_->_tmp56_ = _data_->restored_session;
		if (!ft_session_is_completed (_data_->_tmp56_)) {
			_data_->_tmp57_ = _data_->restored_session;
			_data_->_tmp55_ = !ft_session_is_expired (_data_->_tmp57_, _data_->timestamp);
		} else {
			_data_->_tmp55_ = FALSE;
		}
		if (_data_->_tmp55_) {
			_data_->_tmp58_ = _data_->restored_session;
			_data_->_tmp59_ = _data_->_data48_->restored_time_block;
			ft_session_manager_set_current_time_block_full (_data_->self, _data_->_tmp58_, _data_->_tmp59_, _data_->timestamp);
		}
		_data_->_tmp61_ = _data_->self->priv->_timer;
		if (ft_timer_is_finished (_data_->_tmp61_)) {
			_data_->_tmp62_ = _data_->self->priv->_timer;
			_data_->_tmp63_ = ft_timer_get_user_data (_data_->_tmp62_);
			_data_->_tmp64_ = _data_->_tmp63_;
			_data_->_tmp65_ = _data_->_data48_->restored_time_block;
			_data_->_tmp60_ = _data_->_tmp64_ == _data_->_tmp65_;
		} else {
			_data_->_tmp60_ = FALSE;
		}
		if (_data_->_tmp60_) {
			_data_->_tmp66_ = _data_->self->priv->_current_time_block;
			_data_->_tmp67_ = ft_session_manager_initialize_next_time_block (_data_->self, _data_->timestamp);
			_data_->_tmp68_ = _data_->_tmp67_;
			g_signal_emit (_data_->self, ft_session_manager_signals[FT_SESSION_MANAGER_CONFIRM_ADVANCEMENT_SIGNAL], 0, _data_->_tmp66_, _data_->_tmp68_);
			_g_object_unref0 (_data_->_tmp68_);
		}
	}
	_data_->result = _data_->success;
	_g_object_unref0 (_data_->session_sorting);
	_g_object_unref0 (_data_->session_filter);
	G_IS_VALUE (&_data_->end_time_value) ? (g_value_unset (&_data_->end_time_value), NULL) : NULL;
	_g_object_unref0 (_data_->repository);
	_g_object_unref0 (_data_->restored_session);
	_g_object_unref0 (_data_->session_entry);
	block48_data_unref (_data_->_data48_);
	_data_->_data48_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

/**
         * Extend current time-block, as if it was started from scratch.
         */
static void
ft_session_manager_extend_current_time_block (FtSessionManager* self,
                                              gboolean resume,
                                              gint64 timestamp)
{
	FtTimeBlock* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtTimer* _tmp2_;
	void* _tmp3_;
	void* _tmp4_;
	gint64 duration = 0LL;
	FtTimer* _tmp5_;
	FtTimeBlock* _tmp6_;
	FtTimer* _tmp7_;
	gboolean _tmp11_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_current_time_block;
	_vala_return_if_fail (_tmp0_ != NULL, "this._current_time_block != null");
	_tmp1_ = self->priv->_current_time_block;
	_tmp2_ = self->priv->_timer;
	_tmp3_ = ft_timer_get_user_data (_tmp2_);
	_tmp4_ = _tmp3_;
	_vala_return_if_fail (_tmp1_ == _tmp4_, "this._current_time_block == this._timer.user_data");
	_tmp5_ = self->priv->_timer;
	_tmp6_ = self->priv->_current_time_block;
	duration = ft_timer_calculate_elapsed (_tmp5_, timestamp) + ft_time_block_get_intended_duration (_tmp6_);
	_tmp7_ = self->priv->_timer;
	if (ft_timer_is_finished (_tmp7_)) {
		FtTimer* _tmp8_;
		FtTimerState _tmp9_ = {0};
		FtTimerState _tmp10_;
		_tmp8_ = self->priv->_timer;
		ft_timer_get_state (_tmp8_, &_tmp9_);
		_tmp10_ = _tmp9_;
		duration += timestamp - _tmp10_.finished_time;
	}
	if (resume) {
		FtTimer* _tmp12_;
		_tmp12_ = self->priv->_timer;
		_tmp11_ = ft_timer_is_paused (_tmp12_);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		FtTimerState new_state = {0};
		FtTimer* _tmp13_;
		FtTimerState _tmp14_ = {0};
		FtTimerState _tmp15_;
		FtTimerState _tmp16_ = {0};
		FtTimerState _tmp17_;
		FtTimer* _tmp18_;
		FtTimerState _tmp19_;
		_tmp13_ = self->priv->_timer;
		ft_timer_get_state (_tmp13_, &_tmp14_);
		_tmp15_ = _tmp14_;
		ft_timer_state_copy (&_tmp15_, &_tmp16_);
		new_state = _tmp16_;
		new_state.duration = duration;
		_tmp17_ = new_state;
		new_state.offset = new_state.offset + (timestamp - _tmp17_.paused_time);
		new_state.paused_time = FT_TIMESTAMP_UNDEFINED;
		_tmp18_ = self->priv->_timer;
		_tmp19_ = new_state;
		ft_timer_set_state_full (_tmp18_, &_tmp19_, timestamp);
	} else {
		FtTimer* _tmp20_;
		_tmp20_ = self->priv->_timer;
		ft_timer_set_duration_full (_tmp20_, duration, timestamp);
	}
}

static void
ft_session_manager_swap_current_state (FtSessionManager* self,
                                       FtState new_state,
                                       gint64 timestamp)
{
	FtTimeBlock* _tmp0_;
	FtTimeBlock* time_block = NULL;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtScheduler* _tmp3_;
	FtSessionTemplate _tmp4_ = {0};
	FtSessionTemplate _tmp5_;
	FtState _tmp6_;
	FtState _tmp7_;
	FtScheduler* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_current_time_block;
	_vala_return_if_fail (_tmp0_ != NULL, "this._current_time_block != null");
	_vala_return_if_fail (ft_state_is_break (self->priv->_current_state), "this._current_state.is_break ()");
	_tmp1_ = self->priv->_current_time_block;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	time_block = _tmp2_;
	ft_time_block_freeze_changed (time_block);
	ft_time_block_set_state_internal (time_block, new_state);
	_tmp3_ = self->priv->_scheduler;
	ft_scheduler_get_session_template (_tmp3_, &_tmp4_);
	_tmp5_ = _tmp4_;
	_tmp6_ = ft_time_block_get_state (time_block);
	_tmp7_ = _tmp6_;
	ft_time_block_set_intended_duration (time_block, ft_session_template_get_duration (&_tmp5_, _tmp7_));
	_tmp8_ = self->priv->_scheduler;
	ft_time_block_set_completion_time (time_block, ft_scheduler_calculate_time_block_completion_time (_tmp8_, time_block));
	ft_session_manager_extend_current_time_block (self, TRUE, timestamp);
	ft_time_block_thaw_changed (time_block);
	_g_object_unref0 (time_block);
}

static void
ft_session_manager_mark_gap_end (FtSessionManager* self,
                                 FtGap* gap,
                                 gint64 timestamp)
{
	gint64 _tmp0_;
	gint64 _tmp1_;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gap != NULL);
	_tmp0_ = ft_schedulable_get_start_time ((FtSchedulable*) gap);
	_tmp1_ = _tmp0_;
	_vala_return_if_fail (timestamp >= _tmp1_, "timestamp >= gap.start_time");
	ft_schedulable_set_end_time ((FtSchedulable*) gap, timestamp);
	if (ft_gap_has_flag (gap, FT_GAP_FLAGS_INTERRUPTION)) {
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = ft_context_get_event_source ();
		_tmp4_ = _tmp3_;
		_tmp2_ = g_strcmp0 (_tmp4_, "timer.reset") == 0;
		_g_free0 (_tmp4_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ft_gap_unset_flag (gap, FT_GAP_FLAGS_INTERRUPTION);
	}
}

/**
         * Adjust time-blocks `end-time` and its status.
         */
static Block49Data*
block49_data_ref (Block49Data* _data49_)
{
	g_atomic_int_inc (&_data49_->_ref_count_);
	return _data49_;
}

static void
block49_data_unref (void * _userdata_)
{
	Block49Data* _data49_;
	_data49_ = (Block49Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data49_->_ref_count_)) {
		FtSessionManager* self;
		self = _data49_->self;
		_g_object_unref0 (_data49_->time_block);
		_g_object_unref0 (self);
		g_slice_free (Block49Data, _data49_);
	}
}

static void
__lambda40_ (Block49Data* _data49_,
             FtGap* gap)
{
	FtSessionManager* self;
	gint64 _tmp0_ = 0LL;
	gint64 _tmp1_;
	gint64 _tmp2_;
	self = _data49_->self;
	g_return_if_fail (gap != NULL);
	_tmp1_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
	_tmp2_ = _tmp1_;
	if (ft_timestamp_is_undefined (_tmp2_)) {
		gint64 _tmp3_;
		gint64 _tmp4_;
		_tmp3_ = ft_schedulable_get_end_time ((FtSchedulable*) _data49_->time_block);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp5_ = ft_schedulable_get_end_time ((FtSchedulable*) gap);
		_tmp6_ = _tmp5_;
		_tmp0_ = MIN (_tmp6_, _data49_->timestamp);
	}
	ft_schedulable_set_end_time ((FtSchedulable*) gap, _tmp0_);
}

static void
___lambda40__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda40_ (self, (FtGap*) data);
}

static void
ft_session_manager_mark_time_block_end (FtSessionManager* self,
                                        FtTimeBlock* time_block,
                                        gint64 timestamp)
{
	gint64 _tmp0_;
	gint64 _tmp1_;
	Block49Data* _data49_;
	FtTimeBlock* _tmp2_;
	gboolean _tmp3_ = FALSE;
	FtTimer* _tmp4_;
	FtTimeBlockStatus _tmp11_ = 0;
	FtScheduler* _tmp12_;
	gint64 _tmp13_;
	gint64 _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_vala_return_if_fail (ft_time_block_get_status (time_block) != FT_TIME_BLOCK_STATUS_SCHEDULED, "time_block.get_status () != Ft.TimeBlockStatus.SCHEDULED");
	_tmp0_ = ft_schedulable_get_start_time ((FtSchedulable*) time_block);
	_tmp1_ = _tmp0_;
	_vala_return_if_fail (timestamp >= _tmp1_, "timestamp >= time_block.start_time");
	_data49_ = g_slice_new0 (Block49Data);
	_data49_->_ref_count_ = 1;
	_data49_->self = g_object_ref (self);
	_tmp2_ = _g_object_ref0 (time_block);
	_g_object_unref0 (_data49_->time_block);
	_data49_->time_block = _tmp2_;
	_data49_->timestamp = timestamp;
	ft_time_block_freeze_changed (_data49_->time_block);
	_tmp4_ = self->priv->_timer;
	if (ft_timer_is_finished (_tmp4_)) {
		FtTimer* _tmp5_;
		void* _tmp6_;
		void* _tmp7_;
		_tmp5_ = self->priv->_timer;
		_tmp6_ = ft_timer_get_user_data (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp3_ = _tmp7_ == _data49_->time_block;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		FtTimer* _tmp8_;
		FtTimerState _tmp9_ = {0};
		FtTimerState _tmp10_;
		_tmp8_ = self->priv->_timer;
		ft_timer_get_state (_tmp8_, &_tmp9_);
		_tmp10_ = _tmp9_;
		ft_schedulable_set_end_time ((FtSchedulable*) _data49_->time_block, MIN (_tmp10_.finished_time + FT_SESSION_MANAGER_OVERDUE_TIMEOUT, _data49_->timestamp));
	} else {
		ft_schedulable_set_end_time ((FtSchedulable*) _data49_->time_block, _data49_->timestamp);
	}
	ft_time_block_foreach_gap (_data49_->time_block, ___lambda40__gfunc, _data49_);
	_tmp12_ = self->priv->_scheduler;
	_tmp13_ = ft_schedulable_get_end_time ((FtSchedulable*) _data49_->time_block);
	_tmp14_ = _tmp13_;
	if (ft_scheduler_is_time_block_completed (_tmp12_, _data49_->time_block, _tmp14_)) {
		_tmp11_ = FT_TIME_BLOCK_STATUS_COMPLETED;
	} else {
		_tmp11_ = FT_TIME_BLOCK_STATUS_UNCOMPLETED;
	}
	ft_time_block_set_status (_data49_->time_block, _tmp11_);
	ft_session_manager_update_time_block_meta (self, _data49_->time_block);
	ft_time_block_thaw_changed (_data49_->time_block);
	block49_data_unref (_data49_);
	_data49_ = NULL;
}

/**
         * Discard time-blocks that were not marked as ended.
         * Ensure there is no in-progress time block.
         */
static void
ft_session_manager_mark_session_end (FtSessionManager* self,
                                     FtSession* session,
                                     gint64 timestamp)
{
	FtTimeBlock* last_time_block = NULL;
	FtTimeBlock* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	ft_session_freeze_changed (session);
	ft_session_remove_scheduled (session);
	_tmp0_ = ft_session_get_last_time_block (session);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	last_time_block = _tmp1_;
	_tmp2_ = last_time_block;
	if (_tmp2_ != NULL) {
		FtTimeBlock* _tmp3_;
		_tmp3_ = last_time_block;
		_vala_assert (ft_time_block_get_status (_tmp3_) != FT_TIME_BLOCK_STATUS_IN_PROGRESS, "last_time_block.get_status () != Ft.TimeBlockStatus.IN_PROGRESS");
	}
	ft_session_set_expiry_time (session, timestamp);
	ft_session_thaw_changed (session);
	_g_object_unref0 (last_time_block);
}

static void
ft_session_manager_mark_timezone (FtSessionManager* self,
                                  GTimeZone* timezone,
                                  gint64 timestamp)
{
	FtTimezoneHistory* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (timezone != NULL);
	ft_ensure_timestamp (&timestamp);
	_tmp0_ = self->priv->timezone_history;
	ft_timezone_history_insert (_tmp0_, timestamp, timezone);
}

static gboolean
ft_session_manager_is_long_break_needed (FtSessionManager* self,
                                         gint64 timestamp)
{
	FtSchedulerContext context = {0};
	FtSession* _tmp0_;
	FtScheduler* _tmp1_;
	FtSession* _tmp2_;
	FtSchedulerContext _tmp3_ = {0};
	FtSchedulerContext _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_current_session;
	if (_tmp0_ == NULL) {
		result = FALSE;
		return result;
	}
	_tmp1_ = self->priv->_scheduler;
	_tmp2_ = self->priv->_current_session;
	ft_scheduler_build_scheduler_context (_tmp1_, _tmp2_, TRUE, timestamp, &_tmp3_, NULL);
	context = _tmp3_;
	_tmp4_ = context;
	result = _tmp4_.needs_long_break;
	return result;
}

static gboolean
ft_session_manager_is_current_session_completed (FtSessionManager* self,
                                                 gint64 timestamp)
{
	FtSession* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtSession* _tmp3_;
	gboolean _tmp4_ = FALSE;
	FtTimeBlock* _tmp5_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_current_session;
	if (_tmp0_ == NULL) {
		result = FALSE;
		return result;
	}
	_tmp1_ = self->priv->_current_time_block;
	if (_tmp1_ == NULL) {
		FtSession* _tmp2_;
		_tmp2_ = self->priv->_current_session;
		result = ft_session_is_completed (_tmp2_);
		return result;
	}
	_tmp3_ = self->priv->_current_session;
	if (ft_session_is_completed (_tmp3_)) {
		result = TRUE;
		return result;
	}
	_tmp5_ = self->priv->_current_time_block;
	if (_tmp5_ != NULL) {
		gboolean _tmp6_ = FALSE;
		FtTimeBlock* _tmp7_;
		FtState _tmp8_;
		FtState _tmp9_;
		_tmp7_ = self->priv->_current_time_block;
		_tmp8_ = ft_time_block_get_state (_tmp7_);
		_tmp9_ = _tmp8_;
		if (_tmp9_ == FT_STATE_LONG_BREAK) {
			_tmp6_ = TRUE;
		} else {
			FtTimeBlock* _tmp10_;
			FtState _tmp11_;
			FtState _tmp12_;
			_tmp10_ = self->priv->_current_time_block;
			_tmp11_ = ft_time_block_get_state (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp6_ = _tmp12_ == FT_STATE_BREAK;
		}
		_tmp4_ = _tmp6_;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		FtScheduler* _tmp13_;
		FtTimeBlock* _tmp14_;
		_tmp13_ = self->priv->_scheduler;
		_tmp14_ = self->priv->_current_time_block;
		result = ft_scheduler_is_time_block_completed (_tmp13_, _tmp14_, timestamp);
		return result;
	}
	result = FALSE;
	return result;
}

static inline gboolean
ft_session_manager_is_waiting_for_activity (FtSessionManager* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->active_watch_id != ((guint) 0);
	return result;
}

/**
         * Start given time-block.
         *
         * It ends previous time-block and switches to a new one, even if it's of same state.
         * There are many similarities with `set_current_time_block()`, except for handling
         * timer stop (passing `null` time-block). `advance_to_time_block` ensures we advance to
         * another session instead of `null`.
         *
         * When we advance to a break - its type may be change during rescheduling.
         */
static void
ft_session_manager_advance_to_time_block (FtSessionManager* self,
                                          FtTimeBlock* time_block,
                                          gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_ = NULL;
	FtSession* session = NULL;
	FtSession* _tmp5_;
	gboolean _tmp6_ = FALSE;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp10_ = FALSE;
	FtSession* _tmp14_;
	g_return_if_fail (self != NULL);
	if (time_block == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_SCHEDULED;
	}
	_vala_assert (_tmp0_, "time_block == null ||                     time_block.get_status () == Ft.TimeBlockStatus.SCHEDULED");
	ft_ensure_timestamp (&timestamp);
	if (time_block != NULL) {
		FtSession* _tmp2_;
		FtSession* _tmp3_;
		_tmp2_ = ft_time_block_get_session (time_block);
		_tmp3_ = _tmp2_;
		_tmp1_ = _tmp3_;
	} else {
		FtSession* _tmp4_;
		_tmp4_ = self->priv->_current_session;
		_tmp1_ = _tmp4_;
	}
	_tmp5_ = _g_object_ref0 (_tmp1_);
	session = _tmp5_;
	if (time_block != NULL) {
		FtSession* _tmp8_;
		_tmp8_ = session;
		_tmp7_ = _tmp8_ != NULL;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		FtSession* _tmp9_;
		_tmp9_ = session;
		_tmp6_ = ft_session_is_expired (_tmp9_, timestamp);
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		g_warning ("session-manager.vala:1703: Advancing to a time-block of expired sessio" \
"n.");
	}
	if (time_block == NULL) {
		gboolean _tmp11_ = FALSE;
		FtSession* _tmp12_;
		_tmp12_ = self->priv->_current_session;
		if (_tmp12_ == NULL) {
			_tmp11_ = TRUE;
		} else {
			_tmp11_ = ft_session_manager_is_current_session_completed (self, timestamp);
		}
		_tmp10_ = _tmp11_;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		FtSession* _tmp13_;
		_tmp13_ = ft_session_manager_initialize_next_session (self, timestamp);
		_g_object_unref0 (session);
		session = _tmp13_;
	}
	_tmp14_ = session;
	ft_session_manager_set_current_time_block_full (self, _tmp14_, time_block, timestamp);
	_g_object_unref0 (session);
}

/**
         * Switch to a given state.
         *
         * Unlike `advance_to_time_block()`, it tries to extend current time-block and can handle Ft.State.BREAK.
         * This is the preferred method of advancing the timer states as it tries to avoid emitting enter- leave-
         * signals unnecessarily. Switching between break types will cause creation a of a new time-block.
         *
         * This method allows you to force a short or long break.
         */
void
ft_session_manager_advance_to_state (FtSessionManager* self,
                                     FtState state,
                                     gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp2_ = FALSE;
	FtTimeBlock* _tmp3_;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp8_ = FALSE;
	FtTimeBlock* _tmp9_;
	FtTimeBlock* next_time_block = NULL;
	FtTimeBlock* _tmp13_;
	FtTimeBlock* _tmp14_;
	FtSession* _tmp15_ = NULL;
	FtTimeBlock* _tmp16_;
	FtSession* next_session = NULL;
	FtSession* _tmp20_;
	gboolean _tmp21_ = FALSE;
	gboolean _tmp22_ = FALSE;
	FtSession* _tmp23_;
	gboolean _tmp28_ = FALSE;
	FtSession* _tmp29_;
	gboolean _tmp35_ = FALSE;
	FtTimeBlock* _tmp36_;
	FtTimeBlock* _tmp52_;
	g_return_if_fail (self != NULL);
	ft_ensure_timestamp (&timestamp);
	if (state == FT_STATE_STOPPED) {
		ft_session_manager_advance_to_time_block (self, NULL, timestamp);
		return;
	}
	if (state == FT_STATE_BREAK) {
		_tmp0_ = !self->priv->_has_uniform_breaks;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		FtState _tmp1_ = 0;
		if (ft_session_manager_is_long_break_needed (self, timestamp)) {
			_tmp1_ = FT_STATE_LONG_BREAK;
		} else {
			_tmp1_ = FT_STATE_SHORT_BREAK;
		}
		state = _tmp1_;
	}
	_tmp3_ = self->priv->_current_time_block;
	if (_tmp3_ != NULL) {
		FtTimeBlock* _tmp4_;
		FtState _tmp5_;
		FtState _tmp6_;
		_tmp4_ = self->priv->_current_time_block;
		_tmp5_ = ft_time_block_get_state (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ == state;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ft_session_manager_extend_current_time_block (self, TRUE, timestamp);
		return;
	}
	_tmp9_ = self->priv->_current_time_block;
	if (_tmp9_ != NULL) {
		FtTimeBlock* _tmp10_;
		FtState _tmp11_;
		FtState _tmp12_;
		_tmp10_ = self->priv->_current_time_block;
		_tmp11_ = ft_time_block_get_state (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp8_ = ft_state_is_break (_tmp12_);
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		_tmp7_ = ft_state_is_break (state);
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		ft_session_manager_swap_current_state (self, state, timestamp);
		return;
	}
	ft_session_manager_freeze_current_session_changed (self);
	_tmp13_ = ft_session_manager_get_next_time_block (self);
	_tmp14_ = _g_object_ref0 (_tmp13_);
	next_time_block = _tmp14_;
	_tmp16_ = next_time_block;
	if (_tmp16_ != NULL) {
		FtTimeBlock* _tmp17_;
		FtSession* _tmp18_;
		FtSession* _tmp19_;
		_tmp17_ = next_time_block;
		_tmp18_ = ft_time_block_get_session (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp15_ = _tmp19_;
	} else {
		_tmp15_ = NULL;
	}
	_tmp20_ = _g_object_ref0 (_tmp15_);
	next_session = _tmp20_;
	_tmp23_ = next_session;
	if (_tmp23_ == NULL) {
		FtSession* _tmp24_;
		_tmp24_ = self->priv->_current_session;
		_tmp22_ = _tmp24_ != NULL;
	} else {
		_tmp22_ = FALSE;
	}
	if (_tmp22_) {
		FtSession* _tmp25_;
		_tmp25_ = self->priv->_current_session;
		_tmp21_ = !ft_session_is_completed (_tmp25_);
	} else {
		_tmp21_ = FALSE;
	}
	if (_tmp21_) {
		FtSession* _tmp26_;
		FtSession* _tmp27_;
		_tmp26_ = self->priv->_current_session;
		_tmp27_ = _g_object_ref0 (_tmp26_);
		_g_object_unref0 (next_session);
		next_session = _tmp27_;
		_g_object_unref0 (next_time_block);
		next_time_block = NULL;
	}
	_tmp29_ = next_session;
	if (_tmp29_ == NULL) {
		_tmp28_ = TRUE;
	} else {
		FtSession* _tmp30_;
		_tmp30_ = next_session;
		_tmp28_ = ft_session_is_expired (_tmp30_, timestamp);
	}
	if (_tmp28_) {
		FtSession* _tmp31_;
		FtSession* _tmp32_;
		FtTimeBlock* _tmp33_;
		FtTimeBlock* _tmp34_;
		_tmp31_ = ft_session_manager_initialize_next_session (self, timestamp);
		_g_object_unref0 (next_session);
		next_session = _tmp31_;
		_tmp32_ = next_session;
		_tmp33_ = ft_session_get_first_time_block (_tmp32_);
		_tmp34_ = _g_object_ref0 (_tmp33_);
		_g_object_unref0 (next_time_block);
		next_time_block = _tmp34_;
	}
	_tmp36_ = next_time_block;
	if (_tmp36_ != NULL) {
		FtTimeBlock* _tmp37_;
		FtState _tmp38_;
		FtState _tmp39_;
		_tmp37_ = next_time_block;
		_tmp38_ = ft_time_block_get_state (_tmp37_);
		_tmp39_ = _tmp38_;
		_tmp35_ = _tmp39_ != state;
	} else {
		_tmp35_ = FALSE;
	}
	if (_tmp35_) {
		FtTimeBlock* time_block = NULL;
		FtTimeBlock* _tmp40_;
		FtSession* _tmp41_;
		FtTimeBlock* _tmp42_;
		FtTimeBlock* _tmp43_;
		FtTimeBlock* _tmp44_;
		FtTimeBlock* _tmp45_;
		_tmp40_ = ft_time_block_new_with_start_time (timestamp, state);
		g_object_ref_sink (_tmp40_);
		time_block = _tmp40_;
		_tmp41_ = next_session;
		_tmp42_ = time_block;
		_tmp43_ = next_time_block;
		ft_session_insert_before (_tmp41_, _tmp42_, _tmp43_);
		_tmp44_ = time_block;
		_tmp45_ = _g_object_ref0 (_tmp44_);
		_g_object_unref0 (next_time_block);
		next_time_block = _tmp45_;
		_g_object_unref0 (time_block);
	} else {
		FtTimeBlock* _tmp46_;
		_tmp46_ = next_time_block;
		if (_tmp46_ == NULL) {
			FtTimeBlock* time_block = NULL;
			FtTimeBlock* _tmp47_;
			FtSession* _tmp48_;
			FtTimeBlock* _tmp49_;
			FtTimeBlock* _tmp50_;
			FtTimeBlock* _tmp51_;
			_tmp47_ = ft_time_block_new_with_start_time (timestamp, state);
			g_object_ref_sink (_tmp47_);
			time_block = _tmp47_;
			_tmp48_ = next_session;
			_tmp49_ = time_block;
			ft_session_append (_tmp48_, _tmp49_);
			_tmp50_ = time_block;
			_tmp51_ = _g_object_ref0 (_tmp50_);
			_g_object_unref0 (next_time_block);
			next_time_block = _tmp51_;
			_g_object_unref0 (time_block);
		}
	}
	_tmp52_ = next_time_block;
	ft_session_manager_advance_to_time_block (self, _tmp52_, timestamp);
	ft_session_manager_thaw_current_session_changed (self);
	_g_object_unref0 (next_session);
	_g_object_unref0 (next_time_block);
}

/**
         * Jump to next scheduled time-block.
         */
void
ft_session_manager_advance (FtSessionManager* self,
                            gint64 timestamp)
{
	FtTimeBlock* next_time_block = NULL;
	FtTimeBlock* _tmp0_;
	g_return_if_fail (self != NULL);
	ft_ensure_timestamp (&timestamp);
	ft_session_manager_freeze_current_session_changed (self);
	_tmp0_ = ft_session_manager_initialize_next_time_block (self, timestamp);
	next_time_block = _tmp0_;
	ft_session_manager_advance_to_time_block (self, next_time_block, timestamp);
	ft_session_manager_thaw_current_session_changed (self);
	_g_object_unref0 (next_time_block);
}

/**
         * Update session `expiry-time`.
         *
         * The given timeout is relative to last action in the session.
         */
static void
ft_session_manager_bump_expiry_time (FtSessionManager* self,
                                     gint64 timeout)
{
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	g_return_if_fail (self != NULL);
	if (self->priv->expiry_timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->expiry_timeout_id);
		self->priv->expiry_timeout_id = (guint) 0;
	}
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ != NULL) {
		FtSession* _tmp2_;
		_tmp2_ = self->priv->_current_session;
		_tmp0_ = !ft_session_is_scheduled (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint64 _tmp3_ = 0LL;
		FtTimer* _tmp4_;
		gint64 expiry_time = 0LL;
		FtSession* _tmp6_;
		FtSession* _tmp7_;
		FtSession* _tmp8_;
		_tmp4_ = self->priv->_timer;
		if (ft_timer_is_running (_tmp4_)) {
			_tmp3_ = FT_TIMESTAMP_UNDEFINED;
		} else {
			FtTimer* _tmp5_;
			_tmp5_ = self->priv->_timer;
			_tmp3_ = ft_timer_get_last_state_changed_time (_tmp5_) + timeout;
		}
		expiry_time = _tmp3_;
		_tmp6_ = self->priv->_current_session;
		g_signal_handler_block (_tmp6_, self->priv->current_session_notify_expiry_time_id);
		_tmp7_ = self->priv->_current_session;
		ft_session_set_expiry_time (_tmp7_, expiry_time);
		_tmp8_ = self->priv->_current_session;
		g_signal_handler_unblock (_tmp8_, self->priv->current_session_notify_expiry_time_id);
		ft_session_manager_on_current_session_notify_expiry_time (self);
	}
}

static void
ft_session_manager_expire_current_session (FtSessionManager* self,
                                           gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	FtSession* current_session = NULL;
	FtSession* _tmp3_;
	FtSession* _tmp4_;
	FtSession* _tmp5_;
	FtSession* _tmp6_;
	FtSession* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		FtSession* _tmp2_;
		_tmp2_ = self->priv->_current_session;
		_tmp0_ = ft_session_is_scheduled (_tmp2_);
	}
	if (_tmp0_) {
		return;
	}
	ft_ensure_timestamp (&timestamp);
	_tmp3_ = self->priv->_current_session;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	current_session = _tmp4_;
	_tmp5_ = self->priv->_current_session;
	g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_SESSION_EXPIRED_SIGNAL], 0, _tmp5_, timestamp);
	_tmp6_ = self->priv->_current_session;
	_tmp7_ = current_session;
	if (_tmp6_ == _tmp7_) {
		ft_session_manager_reset (self, timestamp);
	} else {
		g_debug ("session-manager.vala:1862: The session was changed during `session-exp" \
"ired` emission.");
	}
	_g_object_unref0 (current_session);
}

static gboolean
___lambda39_ (FtSessionManager* self)
{
	gboolean result;
	g_debug ("session-manager.vala:1875: Calling `thaw_current_session_changed` late" \
"...");
	self->priv->session_changed_idle_id = 0U;
	ft_session_manager_thaw_current_session_changed (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
____lambda39__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda39_ ((FtSessionManager*) self);
	return result;
}

static void
ft_session_manager_freeze_current_session_changed (FtSessionManager* self)
{
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ != NULL) {
		_tmp0_ = !self->priv->current_session_changed_frozen;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		FtSession* _tmp2_;
		self->priv->current_session_changed_frozen = TRUE;
		_tmp2_ = self->priv->_current_session;
		ft_session_freeze_changed (_tmp2_);
		self->priv->session_changed_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ____lambda39__gsource_func, g_object_ref (self), g_object_unref);
		g_source_set_name_by_id (self->priv->session_changed_idle_id, "Ft.SessionManager.thaw_current_session_changed");
	}
}

static void
ft_session_manager_thaw_current_session_changed (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->session_changed_idle_id != 0U) {
		g_source_remove (self->priv->session_changed_idle_id);
		self->priv->session_changed_idle_id = 0U;
	}
	if (self->priv->current_session_changed_frozen) {
		FtSession* _tmp0_;
		FtSession* _tmp1_;
		_tmp0_ = self->priv->_current_session;
		_vala_assert (_tmp0_ != NULL, "this._current_session != null");
		self->priv->current_session_changed_frozen = FALSE;
		_tmp1_ = self->priv->_current_session;
		ft_session_thaw_changed (_tmp1_);
	}
}

static void
ft_session_manager_emit_session_rescheduled (FtSessionManager* self,
                                             gint64 timestamp)
{
	FtSession* _tmp0_;
	FtSession* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_current_session;
	if (_tmp0_ == NULL) {
		return;
	}
	if (ft_timestamp_is_undefined (timestamp)) {
		timestamp = ft_session_manager_get_current_time (self);
	}
	_tmp1_ = self->priv->_current_session;
	g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_SESSION_RESCHEDULED_SIGNAL], 0, _tmp1_, timestamp);
}

static gboolean
ft_session_manager_should_auto_pause (FtSessionManager* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	FtTimeBlock* _tmp3_;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp10_ = FALSE;
	FtLockScreen* _tmp11_;
	gboolean _tmp18_ = FALSE;
	gboolean _tmp19_ = FALSE;
	FtScreenSaver* _tmp20_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp3_ = self->priv->_current_time_block;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		FtTimeBlock* _tmp4_;
		FtState _tmp5_;
		FtState _tmp6_;
		_tmp4_ = self->priv->_current_time_block;
		_tmp5_ = ft_time_block_get_state (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != FT_STATE_POMODORO;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		gboolean _tmp7_ = FALSE;
		FtTimer* _tmp8_;
		_tmp8_ = self->priv->_timer;
		if (!ft_timer_is_running (_tmp8_)) {
			_tmp7_ = !self->priv->auto_paused;
		} else {
			_tmp7_ = FALSE;
		}
		_tmp1_ = _tmp7_;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->resolving_timer_state > 0;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp11_ = self->priv->lockscreen;
	if (_tmp11_ != NULL) {
		FtLockScreen* _tmp12_;
		gboolean _tmp13_;
		gboolean _tmp14_;
		_tmp12_ = self->priv->lockscreen;
		_tmp13_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp12_);
		_tmp14_ = _tmp13_;
		_tmp10_ = _tmp14_;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		FtLockScreen* _tmp15_;
		gboolean _tmp16_;
		gboolean _tmp17_;
		_tmp15_ = self->priv->lockscreen;
		_tmp16_ = ft_lock_screen_get_active (_tmp15_);
		_tmp17_ = _tmp16_;
		_tmp9_ = _tmp17_;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		result = TRUE;
		return result;
	}
	_tmp20_ = self->priv->screensaver;
	if (_tmp20_ != NULL) {
		FtScreenSaver* _tmp21_;
		gboolean _tmp22_;
		gboolean _tmp23_;
		_tmp21_ = self->priv->screensaver;
		_tmp22_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp21_);
		_tmp23_ = _tmp22_;
		_tmp19_ = _tmp23_;
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		FtScreenSaver* _tmp24_;
		gboolean _tmp25_;
		gboolean _tmp26_;
		_tmp24_ = self->priv->screensaver;
		_tmp25_ = ft_screen_saver_get_active (_tmp24_);
		_tmp26_ = _tmp25_;
		_tmp18_ = _tmp26_;
	} else {
		_tmp18_ = FALSE;
	}
	if (_tmp18_) {
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
ft_session_manager_should_auto_resume (FtSessionManager* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	FtLockScreen* _tmp2_;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp10_ = FALSE;
	FtScreenSaver* _tmp11_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (!self->priv->auto_paused) {
		result = FALSE;
		return result;
	}
	_tmp2_ = self->priv->lockscreen;
	if (_tmp2_ != NULL) {
		FtLockScreen* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp3_ = self->priv->lockscreen;
		_tmp4_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		FtLockScreen* _tmp6_;
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp6_ = self->priv->lockscreen;
		_tmp7_ = ft_lock_screen_get_active (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp0_ = _tmp8_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp11_ = self->priv->screensaver;
	if (_tmp11_ != NULL) {
		FtScreenSaver* _tmp12_;
		gboolean _tmp13_;
		gboolean _tmp14_;
		_tmp12_ = self->priv->screensaver;
		_tmp13_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp12_);
		_tmp14_ = _tmp13_;
		_tmp10_ = _tmp14_;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		FtScreenSaver* _tmp15_;
		gboolean _tmp16_;
		gboolean _tmp17_;
		_tmp15_ = self->priv->screensaver;
		_tmp16_ = ft_screen_saver_get_active (_tmp15_);
		_tmp17_ = _tmp16_;
		_tmp9_ = _tmp17_;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		result = FALSE;
		return result;
	}
	result = TRUE;
	return result;
}

static gboolean
ft_session_manager_should_auto_advance (FtSessionManager* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	FtTimer* _tmp4_;
	gboolean _tmp13_ = FALSE;
	gboolean _tmp14_ = FALSE;
	FtLockScreen* _tmp15_;
	gboolean _tmp22_ = FALSE;
	gboolean _tmp23_ = FALSE;
	FtScreenSaver* _tmp24_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp4_ = self->priv->_timer;
	if (!ft_timer_is_finished (_tmp4_)) {
		_tmp3_ = TRUE;
	} else {
		FtTimeBlock* _tmp5_;
		_tmp5_ = self->priv->_current_time_block;
		_tmp3_ = _tmp5_ == NULL;
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		FtTimeBlock* _tmp6_;
		FtState _tmp7_;
		FtState _tmp8_;
		_tmp6_ = self->priv->_current_time_block;
		_tmp7_ = ft_time_block_get_state (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp2_ = _tmp8_ != FT_STATE_POMODORO;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		FtTimeBlock* _tmp9_;
		_tmp9_ = self->priv->next_time_block;
		_tmp1_ = _tmp9_ == NULL;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		FtTimeBlock* _tmp10_;
		FtState _tmp11_;
		FtState _tmp12_;
		_tmp10_ = self->priv->next_time_block;
		_tmp11_ = ft_time_block_get_state (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp0_ = !ft_state_is_break (_tmp12_);
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp15_ = self->priv->lockscreen;
	if (_tmp15_ != NULL) {
		FtLockScreen* _tmp16_;
		gboolean _tmp17_;
		gboolean _tmp18_;
		_tmp16_ = self->priv->lockscreen;
		_tmp17_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp16_);
		_tmp18_ = _tmp17_;
		_tmp14_ = _tmp18_;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		FtLockScreen* _tmp19_;
		gboolean _tmp20_;
		gboolean _tmp21_;
		_tmp19_ = self->priv->lockscreen;
		_tmp20_ = ft_lock_screen_get_active (_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp13_ = _tmp21_;
	} else {
		_tmp13_ = FALSE;
	}
	if (_tmp13_) {
		result = TRUE;
		return result;
	}
	_tmp24_ = self->priv->screensaver;
	if (_tmp24_ != NULL) {
		FtScreenSaver* _tmp25_;
		gboolean _tmp26_;
		gboolean _tmp27_;
		_tmp25_ = self->priv->screensaver;
		_tmp26_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp25_);
		_tmp27_ = _tmp26_;
		_tmp23_ = _tmp27_;
	} else {
		_tmp23_ = FALSE;
	}
	if (_tmp23_) {
		FtScreenSaver* _tmp28_;
		gboolean _tmp29_;
		gboolean _tmp30_;
		_tmp28_ = self->priv->screensaver;
		_tmp29_ = ft_screen_saver_get_active (_tmp28_);
		_tmp30_ = _tmp29_;
		_tmp22_ = _tmp30_;
	} else {
		_tmp22_ = FALSE;
	}
	if (_tmp22_) {
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static void
ft_session_manager_pause (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	if (!self->priv->auto_paused) {
		FtTimer* _tmp0_;
		self->priv->auto_paused = TRUE;
		ft_context_set_event_source ("session-manager.auto-pause", FT_TIMESTAMP_UNDEFINED);
		_tmp0_ = self->priv->_timer;
		ft_timer_pause (_tmp0_, FT_TIMESTAMP_UNDEFINED);
	}
}

static void
ft_session_manager_resume (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->auto_paused) {
		FtTimer* _tmp0_;
		self->priv->auto_paused = FALSE;
		ft_context_set_event_source ("session-manager.auto-resume", FT_TIMESTAMP_UNDEFINED);
		_tmp0_ = self->priv->_timer;
		ft_timer_resume (_tmp0_, FT_TIMESTAMP_UNDEFINED);
	}
}

static void
_ft_session_manager_on_lockscreen_notify_active_g_object_notify (GObject* _sender,
                                                                 GParamSpec* pspec,
                                                                 gpointer self)
{
	ft_session_manager_on_lockscreen_notify_active ((FtSessionManager*) self, _sender, pspec);
}

static void
_ft_session_manager_on_screensaver_notify_active_g_object_notify (GObject* _sender,
                                                                  GParamSpec* pspec,
                                                                  gpointer self)
{
	ft_session_manager_on_screensaver_notify_active ((FtSessionManager*) self, _sender, pspec);
}

static void
ft_session_manager_enable_auto_pause (FtSessionManager* self)
{
	FtLockScreen* _tmp0_;
	FtScreenSaver* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->lockscreen;
	if (_tmp0_ == NULL) {
		FtLockScreen* _tmp1_;
		FtLockScreen* _tmp2_;
		_tmp1_ = ft_lock_screen_new ();
		_g_object_unref0 (self->priv->lockscreen);
		self->priv->lockscreen = _tmp1_;
		_tmp2_ = self->priv->lockscreen;
		g_signal_connect_object ((GObject*) _tmp2_, "notify::active", (GCallback) _ft_session_manager_on_lockscreen_notify_active_g_object_notify, self, 0);
	}
	_tmp3_ = self->priv->screensaver;
	if (_tmp3_ == NULL) {
		FtScreenSaver* _tmp4_;
		FtScreenSaver* _tmp5_;
		_tmp4_ = ft_screen_saver_new ();
		_g_object_unref0 (self->priv->screensaver);
		self->priv->screensaver = _tmp4_;
		_tmp5_ = self->priv->screensaver;
		g_signal_connect_object ((GObject*) _tmp5_, "notify::active", (GCallback) _ft_session_manager_on_screensaver_notify_active_g_object_notify, self, 0);
	}
	if (ft_session_manager_should_auto_pause (self)) {
		ft_session_manager_pause (self);
	}
}

static void
ft_session_manager_disable_auto_pause (FtSessionManager* self)
{
	FtLockScreen* _tmp0_;
	FtScreenSaver* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->lockscreen;
	if (_tmp0_ != NULL) {
		FtLockScreen* _tmp1_;
		guint _tmp2_;
		GQuark _tmp3_;
		_tmp1_ = self->priv->lockscreen;
		g_signal_parse_name ("notify::active", G_TYPE_OBJECT, &_tmp2_, &_tmp3_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, _tmp3_, NULL, (GCallback) _ft_session_manager_on_lockscreen_notify_active_g_object_notify, self);
		_g_object_unref0 (self->priv->lockscreen);
		self->priv->lockscreen = NULL;
	}
	_tmp4_ = self->priv->screensaver;
	if (_tmp4_ != NULL) {
		FtScreenSaver* _tmp5_;
		guint _tmp6_;
		GQuark _tmp7_;
		_tmp5_ = self->priv->screensaver;
		g_signal_parse_name ("notify::active", G_TYPE_OBJECT, &_tmp6_, &_tmp7_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp5_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp6_, _tmp7_, NULL, (GCallback) _ft_session_manager_on_screensaver_notify_active_g_object_notify, self);
		_g_object_unref0 (self->priv->screensaver);
		self->priv->screensaver = NULL;
	}
	ft_session_manager_resume (self);
}

static void
ft_session_manager_update_auto_pause (FtSessionManager* self)
{
	gboolean _tmp0_ = FALSE;
	FtTimeBlock* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_current_time_block;
	if (_tmp1_ != NULL) {
		GSettings* _tmp2_;
		_tmp2_ = self->priv->settings;
		_tmp0_ = g_settings_get_boolean (_tmp2_, "pause-on-lockscreen");
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ft_session_manager_enable_auto_pause (self);
	} else {
		ft_session_manager_disable_auto_pause (self);
	}
}

static void
ft_session_manager_update_time_block_meta (FtSessionManager* self,
                                           FtTimeBlock* time_block)
{
	gint64 completion_time = 0LL;
	FtScheduler* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtTimeBlock* _tmp4_;
	gdouble weight = 0.0;
	FtScheduler* _tmp5_;
	FtTimeBlock* _tmp6_;
	FtTimeBlock* _tmp7_;
	FtTimeBlock* _tmp8_;
	FtTimeBlock* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_tmp0_ = self->priv->_scheduler;
	_tmp1_ = ft_session_manager_get_current_time_block (self);
	_tmp2_ = _tmp1_;
	completion_time = ft_scheduler_calculate_time_block_completion_time (_tmp0_, _tmp2_);
	_tmp3_ = ft_session_manager_get_current_time_block (self);
	_tmp4_ = _tmp3_;
	ft_time_block_set_completion_time (_tmp4_, completion_time);
	_tmp5_ = self->priv->_scheduler;
	_tmp6_ = ft_session_manager_get_current_time_block (self);
	_tmp7_ = _tmp6_;
	weight = ft_scheduler_calculate_time_block_weight (_tmp5_, _tmp7_);
	_tmp8_ = ft_session_manager_get_current_time_block (self);
	_tmp9_ = _tmp8_;
	ft_time_block_set_weight (_tmp9_, weight);
}

/**
         * Update time-block according to changes in timer state.
         */
static void
ft_session_manager_update_current_time_block (FtSessionManager* self,
                                              const FtTimerState* current_state,
                                              const FtTimerState* previous_state,
                                              gint64 timestamp)
{
	FtTimerState _tmp0_;
	void* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtTimeBlock* previous_time_block = NULL;
	FtTimeBlock* _tmp4_;
	FtTimeBlock* _tmp5_;
	FtTimeBlock* current_time_block = NULL;
	FtTimeBlock* _tmp6_;
	FtTimeBlock* _tmp7_;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_ = FALSE;
	FtTimerState _tmp10_;
	void* _tmp11_;
	FtTimerState _tmp12_;
	void* _tmp13_;
	gint64 _tmp23_ = 0LL;
	FtTimeBlock* _tmp32_;
	gboolean _tmp33_ = FALSE;
	gboolean _tmp34_ = FALSE;
	FtTimerState _tmp35_;
	void* _tmp36_;
	FtTimerState _tmp37_;
	void* _tmp38_;
	FtTimeBlock* _tmp86_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	_tmp0_ = *current_state;
	_tmp1_ = _tmp0_.user_data;
	_tmp2_ = self->priv->_current_time_block;
	_vala_return_if_fail (_tmp1_ == _tmp2_, "current_state.user_data == this._current_time_block");
	_tmp3_ = self->priv->_current_time_block;
	_vala_return_if_fail (_tmp3_ != NULL, "this._current_time_block != null");
	_vala_return_if_fail (ft_timestamp_is_defined (timestamp), "Ft.Timestamp.is_defined (timestamp)");
	_tmp4_ = self->priv->previous_time_block;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	previous_time_block = _tmp5_;
	_tmp6_ = self->priv->_current_time_block;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	current_time_block = _tmp7_;
	ft_session_manager_freeze_current_session_changed (self);
	_tmp10_ = *current_state;
	_tmp11_ = _tmp10_.user_data;
	_tmp12_ = *previous_state;
	_tmp13_ = _tmp12_.user_data;
	if (_tmp11_ == _tmp13_) {
		_tmp9_ = ft_timer_state_is_started (current_state);
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		_tmp8_ = !ft_timer_state_is_started (previous_state);
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		gint64 overdue = 0LL;
		FtTimerState _tmp14_;
		FtTimeBlock* _tmp15_;
		gint64 _tmp16_;
		gint64 _tmp17_;
		gboolean _tmp18_ = FALSE;
		FtTimeBlock* _tmp19_;
		FtTimeBlock* _tmp21_;
		FtTimerState _tmp22_;
		_tmp14_ = *current_state;
		_tmp15_ = previous_time_block;
		_tmp16_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp15_);
		_tmp17_ = _tmp16_;
		overdue = _tmp14_.started_time - _tmp17_;
		_tmp19_ = previous_time_block;
		if (_tmp19_ != NULL) {
			_tmp18_ = overdue < FT_SESSION_MANAGER_OVERDUE_TIMEOUT;
		} else {
			_tmp18_ = FALSE;
		}
		if (_tmp18_) {
			FtTimeBlock* _tmp20_;
			_tmp20_ = previous_time_block;
			ft_session_manager_mark_time_block_end (self, _tmp20_, timestamp);
		}
		_tmp21_ = current_time_block;
		_tmp22_ = *current_state;
		ft_schedulable_move_to ((FtSchedulable*) _tmp21_, _tmp22_.started_time);
	}
	if (ft_timer_state_is_started (current_state)) {
		FtTimerState _tmp24_;
		FtTimerState _tmp25_;
		FtTimerState _tmp26_;
		_tmp24_ = *current_state;
		_tmp25_ = *current_state;
		_tmp26_ = *current_state;
		_tmp23_ = (_tmp24_.started_time + _tmp25_.offset) + _tmp26_.duration;
	} else {
		FtTimeBlock* _tmp27_;
		gint64 _tmp28_;
		gint64 _tmp29_;
		FtTimerState _tmp30_;
		FtTimerState _tmp31_;
		_tmp27_ = current_time_block;
		_tmp28_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = *current_state;
		_tmp31_ = *current_state;
		_tmp23_ = (_tmp29_ + _tmp30_.offset) + _tmp31_.duration;
	}
	_tmp32_ = current_time_block;
	ft_schedulable_set_end_time ((FtSchedulable*) _tmp32_, _tmp23_);
	_tmp35_ = *current_state;
	_tmp36_ = _tmp35_.user_data;
	_tmp37_ = *previous_state;
	_tmp38_ = _tmp37_.user_data;
	if (_tmp36_ == _tmp38_) {
		FtTimerState _tmp39_;
		FtTimerState _tmp40_;
		_tmp39_ = *current_state;
		_tmp40_ = *previous_state;
		_tmp34_ = _tmp39_.paused_time == _tmp40_.paused_time;
	} else {
		_tmp34_ = FALSE;
	}
	if (_tmp34_) {
		FtTimerState _tmp41_;
		FtTimerState _tmp42_;
		_tmp41_ = *current_state;
		_tmp42_ = *previous_state;
		_tmp33_ = _tmp41_.offset != _tmp42_.offset;
	} else {
		_tmp33_ = FALSE;
	}
	if (_tmp33_) {
		gint64 interval = 0LL;
		FtTimerState _tmp43_;
		FtTimerState _tmp44_;
		FtGapFlags _tmp45_ = 0U;
		FtTimeBlock* _tmp46_;
		FtState _tmp47_;
		FtState _tmp48_;
		FtGapFlags gap_flags = 0U;
		FtGap* gap = NULL;
		FtGap* _tmp49_;
		gint64 _tmp50_ = 0LL;
		FtGap* _tmp51_;
		FtGap* _tmp55_;
		FtGap* _tmp56_;
		FtGap* _tmp57_;
		gint64 _tmp58_;
		gint64 _tmp59_;
		FtTimeBlock* _tmp60_;
		gint64 _tmp61_;
		gint64 _tmp62_;
		FtTimeBlock* _tmp63_;
		FtGap* _tmp64_;
		FtTimeBlock* _tmp65_;
		_tmp43_ = *current_state;
		_tmp44_ = *previous_state;
		interval = _tmp43_.offset - _tmp44_.offset;
		_tmp46_ = current_time_block;
		_tmp47_ = ft_time_block_get_state (_tmp46_);
		_tmp48_ = _tmp47_;
		if (_tmp48_ == FT_STATE_POMODORO) {
			_tmp45_ = FT_GAP_FLAGS_INTERRUPTION;
		} else {
			_tmp45_ = FT_GAP_FLAGS_DEFAULT;
		}
		gap_flags = _tmp45_;
		_tmp49_ = ft_gap_new (gap_flags);
		g_object_ref_sink (_tmp49_);
		gap = _tmp49_;
		_tmp51_ = self->priv->_current_gap;
		if (_tmp51_ != NULL) {
			FtGap* _tmp52_;
			gint64 _tmp53_;
			gint64 _tmp54_;
			_tmp52_ = self->priv->_current_gap;
			_tmp53_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp52_);
			_tmp54_ = _tmp53_;
			_tmp50_ = _tmp54_;
		} else {
			_tmp50_ = timestamp;
		}
		_tmp55_ = gap;
		ft_schedulable_set_end_time ((FtSchedulable*) _tmp55_, _tmp50_);
		_tmp56_ = gap;
		_tmp57_ = gap;
		_tmp58_ = ft_schedulable_get_end_time ((FtSchedulable*) _tmp57_);
		_tmp59_ = _tmp58_;
		_tmp60_ = current_time_block;
		_tmp61_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp60_);
		_tmp62_ = _tmp61_;
		ft_schedulable_set_start_time ((FtSchedulable*) _tmp56_, MAX (ft_timestamp_subtract_interval (_tmp59_, interval), _tmp62_));
		_tmp63_ = current_time_block;
		_tmp64_ = gap;
		ft_time_block_add_gap (_tmp63_, _tmp64_);
		_tmp65_ = current_time_block;
		ft_time_block_normalize_gaps (_tmp65_);
		_g_object_unref0 (gap);
	} else {
		if (ft_timer_state_is_paused (current_state)) {
			FtGap* _tmp66_;
			_tmp66_ = self->priv->_current_gap;
			if (_tmp66_ == NULL) {
				gchar* event_source = NULL;
				gchar* _tmp67_;
				FtGapFlags _tmp68_ = 0U;
				gboolean _tmp69_ = FALSE;
				FtTimeBlock* _tmp70_;
				FtState _tmp71_;
				FtState _tmp72_;
				FtGapFlags gap_flags = 0U;
				FtTimerState _tmp76_;
				FtGap* _tmp77_;
				FtTimeBlock* _tmp78_;
				FtGap* _tmp79_;
				_tmp67_ = ft_context_get_event_source ();
				event_source = _tmp67_;
				_tmp70_ = current_time_block;
				_tmp71_ = ft_time_block_get_state (_tmp70_);
				_tmp72_ = _tmp71_;
				if (_tmp72_ == FT_STATE_POMODORO) {
					gboolean _tmp73_ = FALSE;
					const gchar* _tmp74_;
					_tmp74_ = event_source;
					if (g_strcmp0 (_tmp74_, "timer.pause") == 0) {
						_tmp73_ = TRUE;
					} else {
						const gchar* _tmp75_;
						_tmp75_ = event_source;
						_tmp73_ = g_strcmp0 (_tmp75_, "session-manager.auto-pause") == 0;
					}
					_tmp69_ = _tmp73_;
				} else {
					_tmp69_ = FALSE;
				}
				if (_tmp69_) {
					_tmp68_ = FT_GAP_FLAGS_INTERRUPTION;
				} else {
					_tmp68_ = FT_GAP_FLAGS_DEFAULT;
				}
				gap_flags = _tmp68_;
				_tmp76_ = *current_state;
				_tmp77_ = ft_gap_new_with_start_time (_tmp76_.paused_time, gap_flags);
				g_object_ref_sink (_tmp77_);
				_g_object_unref0 (self->priv->_current_gap);
				self->priv->_current_gap = _tmp77_;
				_tmp78_ = self->priv->_current_time_block;
				_tmp79_ = self->priv->_current_gap;
				ft_time_block_add_gap (_tmp78_, _tmp79_);
				_g_free0 (event_source);
			} else {
				FtGap* _tmp80_;
				gint64 _tmp81_;
				gint64 _tmp82_;
				FtTimerState _tmp83_;
				_tmp80_ = self->priv->_current_gap;
				_tmp81_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp80_);
				_tmp82_ = _tmp81_;
				_tmp83_ = *current_state;
				if (_tmp82_ != _tmp83_.paused_time) {
					g_warning ("session-manager.vala:2120: `Gap.start_time` does not match `TimerState" \
".paused_time`.");
				}
			}
		} else {
			FtGap* _tmp84_;
			_tmp84_ = self->priv->_current_gap;
			if (_tmp84_ != NULL) {
				FtGap* _tmp85_;
				_tmp85_ = self->priv->_current_gap;
				ft_session_manager_mark_gap_end (self, _tmp85_, timestamp);
				_g_object_unref0 (self->priv->_current_gap);
				self->priv->_current_gap = NULL;
			}
		}
	}
	_tmp86_ = current_time_block;
	ft_session_manager_update_time_block_meta (self, _tmp86_);
	_g_object_unref0 (current_time_block);
	_g_object_unref0 (previous_time_block);
}

/**
         * Update resolving timer state according to current session.
         *
         * Start a session or reschedule existing in order to construct a final timer state.
         */
static void
ft_session_manager_resolve_timer_state (FtSessionManager* self,
                                        FtTimerState* state,
                                        gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_ = FALSE;
	gboolean _tmp14_ = FALSE;
	gboolean _tmp22_ = FALSE;
	FtTimerState _tmp23_;
	void* _tmp24_;
	FtTimeBlock* _tmp25_;
	gboolean _tmp31_ = FALSE;
	FtSession* _tmp32_;
	FtTimeBlock* _tmp39_;
	FtTimerState _tmp45_;
	void* _tmp46_;
	FtTimeBlock* _tmp47_;
	FtTimeBlock* _tmp48_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (state != NULL);
	if (ft_timer_state_is_finished (state)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = ft_timer_state_is_paused (state);
	}
	if (_tmp0_) {
		FtTimerState _tmp1_;
		void* _tmp2_;
		FtTimeBlock* _tmp3_;
		FtTimeBlock* _tmp4_;
		_tmp1_ = *state;
		_tmp2_ = _tmp1_.user_data;
		_tmp3_ = self->priv->_current_time_block;
		_vala_warn_if_fail (_tmp2_ == _tmp3_, "state.user_data == this._current_time_block");
		_tmp4_ = self->priv->_current_time_block;
		_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp4_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
		return;
	}
	if (!ft_timer_state_is_started (state)) {
		FtTimerState _tmp7_;
		void* _tmp8_;
		FtTimeBlock* _tmp9_;
		_tmp7_ = *state;
		_tmp8_ = _tmp7_.user_data;
		_tmp9_ = self->priv->_current_time_block;
		_tmp6_ = _tmp8_ == _tmp9_;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		_tmp5_ = self->priv->active_watch_id != ((guint) 0);
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		FtTimerState _tmp10_;
		void* _tmp11_;
		FtTimeBlock* _tmp12_;
		FtTimeBlock* _tmp13_;
		_tmp10_ = *state;
		_tmp11_ = _tmp10_.user_data;
		_tmp12_ = self->priv->_current_time_block;
		_vala_warn_if_fail (_tmp11_ == _tmp12_, "state.user_data == this._current_time_block");
		_tmp13_ = self->priv->_current_time_block;
		_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp13_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
		return;
	}
	if (!ft_timer_state_is_started (state)) {
		FtTimerState _tmp15_;
		void* _tmp16_;
		_tmp15_ = *state;
		_tmp16_ = _tmp15_.user_data;
		_tmp14_ = _tmp16_ == NULL;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		FtTimeBlock* _tmp17_;
		FtTimerState _tmp18_;
		void* _tmp19_;
		FtTimeBlock* _tmp20_;
		FtTimeBlock* _tmp21_;
		_tmp17_ = self->priv->_current_time_block;
		if (_tmp17_ != NULL) {
			ft_session_manager_advance_to_time_block (self, NULL, timestamp);
			ft_session_manager_initialize_timer_state (self, state, timestamp);
		}
		_tmp18_ = *state;
		_tmp19_ = _tmp18_.user_data;
		_tmp20_ = self->priv->_current_time_block;
		_vala_warn_if_fail (_tmp19_ == _tmp20_, "state.user_data == this._current_time_block");
		_tmp21_ = self->priv->_current_time_block;
		_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp21_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
		return;
	}
	_tmp23_ = *state;
	_tmp24_ = _tmp23_.user_data;
	_tmp25_ = self->priv->_current_time_block;
	if (_tmp24_ == _tmp25_) {
		FtTimeBlock* _tmp26_;
		_tmp26_ = self->priv->_current_time_block;
		_tmp22_ = _tmp26_ != NULL;
	} else {
		_tmp22_ = FALSE;
	}
	if (_tmp22_) {
		FtTimerState _tmp27_;
		void* _tmp28_;
		FtTimeBlock* _tmp29_;
		FtTimeBlock* _tmp30_;
		_tmp27_ = *state;
		_tmp28_ = _tmp27_.user_data;
		_tmp29_ = self->priv->_current_time_block;
		_vala_warn_if_fail (_tmp28_ == _tmp29_, "state.user_data == this._current_time_block");
		_tmp30_ = self->priv->_current_time_block;
		_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp30_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
		return;
	}
	_tmp32_ = self->priv->_current_session;
	if (_tmp32_ != NULL) {
		FtSession* _tmp33_;
		_tmp33_ = self->priv->_current_session;
		_tmp31_ = ft_session_is_expired (_tmp33_, timestamp);
	} else {
		_tmp31_ = FALSE;
	}
	if (_tmp31_) {
		FtTimerState _tmp34_;
		FtTimerState _tmp35_;
		void* _tmp36_;
		FtTimeBlock* _tmp37_;
		FtTimeBlock* _tmp38_;
		_tmp34_ = *state;
		ft_session_manager_advance (self, _tmp34_.started_time);
		ft_session_manager_initialize_timer_state (self, state, timestamp);
		_tmp35_ = *state;
		_tmp36_ = _tmp35_.user_data;
		_tmp37_ = self->priv->_current_time_block;
		_vala_warn_if_fail (_tmp36_ == _tmp37_, "state.user_data == this._current_time_block");
		_tmp38_ = self->priv->_current_time_block;
		_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp38_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
		return;
	}
	_tmp39_ = self->priv->_current_time_block;
	if (_tmp39_ == NULL) {
		FtTimerState _tmp40_;
		FtTimerState _tmp41_;
		void* _tmp42_;
		FtTimeBlock* _tmp43_;
		FtTimeBlock* _tmp44_;
		_tmp40_ = *state;
		ft_session_manager_advance_to_state (self, FT_STATE_POMODORO, _tmp40_.started_time);
		ft_session_manager_initialize_timer_state (self, state, timestamp);
		_tmp41_ = *state;
		_tmp42_ = _tmp41_.user_data;
		_tmp43_ = self->priv->_current_time_block;
		_vala_warn_if_fail (_tmp42_ == _tmp43_, "state.user_data == this._current_time_block");
		_tmp44_ = self->priv->_current_time_block;
		_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp44_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
		return;
	}
	_tmp45_ = *state;
	_tmp46_ = _tmp45_.user_data;
	_tmp47_ = self->priv->_current_time_block;
	_vala_warn_if_fail (_tmp46_ == _tmp47_, "state.user_data == this._current_time_block");
	_tmp48_ = self->priv->_current_time_block;
	_vala_warn_if_fail (self->priv->current_time_block_entered == (_tmp48_ != NULL), "this.current_time_block_entered == (this._current_time_block != null)");
}

static void
ft_session_manager_on_timer_resolve_state (FtSessionManager* self,
                                           FtTimerState* state,
                                           gint64 timestamp)
{
	FtTimerState _tmp0_;
	void* _tmp1_;
	FtTimerState _tmp2_;
	void* _tmp3_;
	FtTimeBlock* _tmp4_;
	gint _tmp5_;
	FtTimeBlock* _tmp6_;
	gint _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (state != NULL);
	_tmp0_ = *state;
	_tmp1_ = _tmp0_.user_data;
	_tmp2_ = *state;
	_tmp3_ = _tmp2_.user_data;
	_tmp4_ = self->priv->_current_time_block;
	_vala_return_if_fail ((_tmp1_ == NULL) || (_tmp3_ == _tmp4_), "state.user_data == null ||                                                        state.user_data == this._current_time_block");
	_tmp5_ = self->priv->resolving_timer_state;
	self->priv->resolving_timer_state = _tmp5_ + 1;
	ft_session_manager_resolve_timer_state (self, state, timestamp);
	_tmp6_ = self->priv->_current_time_block;
	if (_tmp6_ != NULL) {
		FtTimerState _tmp7_;
		FtTimer* _tmp8_;
		FtTimerState _tmp9_ = {0};
		FtTimerState _tmp10_;
		_tmp7_ = *state;
		_tmp8_ = self->priv->_timer;
		ft_timer_get_state (_tmp8_, &_tmp9_);
		_tmp10_ = _tmp9_;
		ft_session_manager_update_current_time_block (self, &_tmp7_, &_tmp10_, timestamp);
	}
	_tmp11_ = self->priv->resolving_timer_state;
	self->priv->resolving_timer_state = _tmp11_ - 1;
}

/**
         * React to timer state changes.
         */
static void
ft_session_manager_on_timer_state_changed (FtSessionManager* self,
                                           const FtTimerState* current_state,
                                           const FtTimerState* previous_state)
{
	gboolean _tmp0_ = FALSE;
	gint _tmp5_;
	gint _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	if (self->priv->active_watch_id != ((guint) 0)) {
		gboolean _tmp1_ = FALSE;
		if (ft_timer_state_is_started (current_state)) {
			_tmp1_ = TRUE;
		} else {
			FtTimerState _tmp2_;
			void* _tmp3_;
			_tmp2_ = *current_state;
			_tmp3_ = _tmp2_.user_data;
			_tmp1_ = _tmp3_ == NULL;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		FtIdleMonitor* _tmp4_;
		_tmp4_ = self->priv->idle_monitor;
		ft_idle_monitor_remove_watch (_tmp4_, self->priv->active_watch_id);
		self->priv->active_watch_id = (guint) 0;
	}
	_tmp5_ = self->priv->resolving_timer_state;
	self->priv->resolving_timer_state = _tmp5_ + 1;
	ft_session_manager_bump_expiry_time (self, FT_SESSION_MANAGER_SESSION_EXPIRY_TIMEOUT);
	ft_session_manager_update_auto_pause (self);
	ft_session_manager_reschedule_if_queued (self);
	ft_session_manager_thaw_current_session_changed (self);
	_tmp6_ = self->priv->resolving_timer_state;
	self->priv->resolving_timer_state = _tmp6_ - 1;
}

static void
_ft_session_manager_on_became_active_ft_callback (gpointer self)
{
	ft_session_manager_on_became_active ((FtSessionManager*) self);
}

static void
ft_session_manager_on_timer_finished (FtSessionManager* self,
                                      const FtTimerState* state)
{
	gint64 timestamp = 0LL;
	FtTimerState _tmp0_;
	FtTimeBlock* next_time_block = NULL;
	FtTimeBlock* _tmp1_;
	FtAdvancementMode advancement_mode = 0;
	FtTimeBlock* _tmp2_;
	FtState _tmp3_;
	FtState _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (state != NULL);
	ft_session_manager_freeze_current_session_changed (self);
	ft_session_manager_enable_idle_monitor (self);
	_tmp0_ = *state;
	timestamp = _tmp0_.finished_time;
	_tmp1_ = ft_session_manager_initialize_next_time_block (self, timestamp);
	next_time_block = _tmp1_;
	_tmp2_ = next_time_block;
	_tmp3_ = ft_time_block_get_state (_tmp2_);
	_tmp4_ = _tmp3_;
	advancement_mode = ft_session_manager_resolve_advancement_mode (self, _tmp4_, timestamp);
	switch (advancement_mode) {
		case FT_ADVANCEMENT_MODE_CONTINUOUS:
		{
			FtTimeBlock* _tmp6_;
			if (self->priv->active_watch_id != ((guint) 0)) {
				FtIdleMonitor* _tmp5_;
				_tmp5_ = self->priv->idle_monitor;
				ft_idle_monitor_remove_watch (_tmp5_, self->priv->active_watch_id);
				self->priv->active_watch_id = (guint) 0;
			}
			_tmp6_ = next_time_block;
			ft_session_manager_advance_to_time_block (self, _tmp6_, timestamp);
			break;
		}
		case FT_ADVANCEMENT_MODE_WAIT_FOR_ACTIVITY:
		{
			FtTimeBlock* _tmp8_;
			if (self->priv->active_watch_id == ((guint) 0)) {
				FtIdleMonitor* _tmp7_;
				_tmp7_ = self->priv->idle_monitor;
				self->priv->active_watch_id = ft_idle_monitor_add_active_watch (_tmp7_, _ft_session_manager_on_became_active_ft_callback, g_object_ref (self), g_object_unref, FT_TIMESTAMP_UNDEFINED);
			}
			_tmp8_ = next_time_block;
			ft_session_manager_advance_to_time_block (self, _tmp8_, timestamp);
			break;
		}
		case FT_ADVANCEMENT_MODE_CONFIRM:
		{
			FtTimeBlock* _tmp10_;
			FtTimeBlock* _tmp11_;
			if (self->priv->active_watch_id != ((guint) 0)) {
				FtIdleMonitor* _tmp9_;
				_tmp9_ = self->priv->idle_monitor;
				ft_idle_monitor_remove_watch (_tmp9_, self->priv->active_watch_id);
				self->priv->active_watch_id = (guint) 0;
			}
			_tmp10_ = self->priv->_current_time_block;
			_tmp11_ = next_time_block;
			g_signal_emit (self, ft_session_manager_signals[FT_SESSION_MANAGER_CONFIRM_ADVANCEMENT_SIGNAL], 0, _tmp10_, _tmp11_);
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_g_object_unref0 (next_time_block);
}

static void
ft_session_manager_on_timer_suspending (FtSessionManager* self,
                                        gint64 start_time)
{
	FtTimeBlock* _tmp0_;
	FtSession* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_current_time_block;
	if (_tmp0_ != NULL) {
		FtGapFlags gap_flags = 0U;
		gboolean _tmp1_ = FALSE;
		FtTimeBlock* _tmp2_;
		FtState _tmp3_;
		FtState _tmp4_;
		FtGap* _tmp6_;
		ft_session_manager_pause (self);
		gap_flags = FT_GAP_FLAGS_SLEEP;
		_tmp2_ = self->priv->_current_time_block;
		_tmp3_ = ft_time_block_get_state (_tmp2_);
		_tmp4_ = _tmp3_;
		if (_tmp4_ == FT_STATE_POMODORO) {
			FtTimer* _tmp5_;
			_tmp5_ = self->priv->_timer;
			_tmp1_ = ft_timer_is_running (_tmp5_);
		} else {
			_tmp1_ = FALSE;
		}
		if (_tmp1_) {
			gap_flags |= FT_GAP_FLAGS_INTERRUPTION;
		}
		_tmp6_ = self->priv->_current_gap;
		if (_tmp6_ == NULL) {
			FtGap* _tmp7_;
			FtTimeBlock* _tmp8_;
			FtGap* _tmp9_;
			_tmp7_ = ft_gap_new_with_start_time (start_time, gap_flags);
			g_object_ref_sink (_tmp7_);
			_g_object_unref0 (self->priv->_current_gap);
			self->priv->_current_gap = _tmp7_;
			_tmp8_ = self->priv->_current_time_block;
			_tmp9_ = self->priv->_current_gap;
			ft_time_block_add_gap (_tmp8_, _tmp9_);
		} else {
			FtGap* _tmp10_;
			_tmp10_ = self->priv->_current_gap;
			ft_gap_set_flag (_tmp10_, gap_flags);
		}
	}
	_tmp11_ = self->priv->_current_session;
	if (_tmp11_ != NULL) {
		FtSession* _tmp12_;
		FtSession* _tmp13_;
		FtSession* _tmp14_;
		_tmp12_ = self->priv->_current_session;
		g_signal_handler_block (_tmp12_, self->priv->current_session_notify_expiry_time_id);
		_tmp13_ = self->priv->_current_session;
		ft_session_set_expiry_time (_tmp13_, start_time + FT_SESSION_MANAGER_SESSION_EXPIRY_TIMEOUT);
		_tmp14_ = self->priv->_current_session;
		g_signal_handler_unblock (_tmp14_, self->priv->current_session_notify_expiry_time_id);
	}
	if (self->priv->expiry_timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->expiry_timeout_id);
		self->priv->expiry_timeout_id = (guint) 0;
	}
}

static void
ft_session_manager_on_timer_suspended (FtSessionManager* self,
                                       gint64 start_time,
                                       gint64 end_time)
{
	FtSession* _tmp0_;
	FtSession* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	FtGap* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_current_session;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->_current_session;
	if (ft_session_is_expired (_tmp1_, end_time)) {
		ft_session_manager_expire_current_session (self, end_time);
	} else {
		ft_session_manager_bump_expiry_time (self, FT_SESSION_MANAGER_SESSION_EXPIRY_TIMEOUT);
	}
	_tmp5_ = self->priv->_current_gap;
	if (_tmp5_ != NULL) {
		FtGap* _tmp6_;
		gint64 _tmp7_;
		gint64 _tmp8_;
		_tmp6_ = self->priv->_current_gap;
		_tmp7_ = ft_schedulable_get_start_time ((FtSchedulable*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_ == start_time;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		FtGap* _tmp9_;
		_tmp9_ = self->priv->_current_gap;
		_tmp3_ = ft_gap_has_flag (_tmp9_, FT_GAP_FLAGS_SLEEP);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		_tmp2_ = !self->priv->auto_paused;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		FtGap* _tmp10_;
		_tmp10_ = self->priv->_current_gap;
		ft_session_manager_mark_gap_end (self, _tmp10_, end_time);
		_g_object_unref0 (self->priv->_current_gap);
		self->priv->_current_gap = NULL;
	}
}

static void
ft_session_manager_on_current_time_block_changed (FtSessionManager* self,
                                                  FtTimeBlock* time_block)
{
	FtState _tmp0_;
	FtState _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	if (self->priv->resolving_timer_state == 0) {
		ft_session_manager_reschedule (self);
	} else {
		ft_session_manager_queue_reschedule (self);
	}
	_tmp0_ = ft_time_block_get_state (time_block);
	_tmp1_ = _tmp0_;
	if (self->priv->_current_state != _tmp1_) {
		FtState _tmp2_;
		FtState _tmp3_;
		_tmp2_ = ft_time_block_get_state (time_block);
		_tmp3_ = _tmp2_;
		self->priv->_current_state = _tmp3_;
		g_object_notify ((GObject*) self, "current-state");
	}
}

static void
ft_session_manager_on_scheduler_notify_session_template (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	ft_session_manager_update_has_uniform_breaks (self);
	ft_session_manager_queue_reschedule (self);
}

static void
ft_session_manager_handle_became_active (FtSessionManager* self)
{
	gboolean _tmp0_ = FALSE;
	FtTimer* _tmp1_;
	void* _tmp2_;
	void* _tmp3_;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_ = FALSE;
	FtScreenSaver* _tmp7_;
	FtTimer* _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_timer;
	_tmp2_ = ft_timer_get_user_data (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		FtTimer* _tmp4_;
		_tmp4_ = self->priv->_timer;
		_tmp0_ = ft_timer_is_started (_tmp4_);
	}
	if (_tmp0_) {
		return;
	}
	_tmp7_ = self->priv->screensaver;
	if (_tmp7_ != NULL) {
		FtScreenSaver* _tmp8_;
		gboolean _tmp9_;
		gboolean _tmp10_;
		_tmp8_ = self->priv->screensaver;
		_tmp9_ = ft_screen_saver_get_active (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp6_ = _tmp10_;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		_tmp5_ = TRUE;
	} else {
		gboolean _tmp11_ = FALSE;
		FtLockScreen* _tmp12_;
		_tmp12_ = self->priv->lockscreen;
		if (_tmp12_ != NULL) {
			FtLockScreen* _tmp13_;
			gboolean _tmp14_;
			gboolean _tmp15_;
			_tmp13_ = self->priv->lockscreen;
			_tmp14_ = ft_lock_screen_get_active (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp11_ = _tmp15_;
		} else {
			_tmp11_ = FALSE;
		}
		_tmp5_ = _tmp11_;
	}
	if (_tmp5_) {
		return;
	}
	_tmp16_ = self->priv->_timer;
	ft_timer_start (_tmp16_, FT_TIMESTAMP_UNDEFINED);
}

static void
ft_session_manager_on_lockscreen_notify_active (FtSessionManager* self,
                                                GObject* object,
                                                GParamSpec* pspec)
{
	FtLockScreen* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	if (ft_session_manager_should_auto_pause (self)) {
		ft_session_manager_pause (self);
	} else {
		if (ft_session_manager_should_auto_resume (self)) {
			ft_session_manager_resume (self);
		} else {
			if (ft_session_manager_should_auto_advance (self)) {
				ft_session_manager_advance (self, FT_TIMESTAMP_UNDEFINED);
			}
		}
	}
	_tmp0_ = self->priv->lockscreen;
	_tmp1_ = ft_lock_screen_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		ft_session_manager_handle_became_active (self);
	}
}

static void
ft_session_manager_on_screensaver_notify_active (FtSessionManager* self,
                                                 GObject* object,
                                                 GParamSpec* pspec)
{
	FtScreenSaver* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	if (ft_session_manager_should_auto_pause (self)) {
		ft_session_manager_pause (self);
	} else {
		if (ft_session_manager_should_auto_resume (self)) {
			ft_session_manager_resume (self);
		} else {
			if (ft_session_manager_should_auto_advance (self)) {
				ft_session_manager_advance (self, FT_TIMESTAMP_UNDEFINED);
			}
		}
	}
	_tmp0_ = self->priv->screensaver;
	_tmp1_ = ft_screen_saver_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		ft_session_manager_handle_became_active (self);
	}
}

static void
ft_session_manager_on_became_active (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	self->priv->active_watch_id = (guint) 0;
	ft_session_manager_handle_became_active (self);
}

static void
ft_session_manager_on_timezone_changed (FtSessionManager* self)
{
	FtTimeZoneMonitor* _tmp0_;
	GTimeZone* _tmp1_;
	GTimeZone* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timezone_monitor;
	_tmp1_ = ft_time_zone_monitor_get_timezone (_tmp0_);
	_tmp2_ = _tmp1_;
	ft_session_manager_mark_timezone (self, _tmp2_, FT_TIMESTAMP_UNDEFINED);
}

/**
         * A wrapper for `Timeout.add_seconds`.
         *
         * We don't want expiry callback to increment the `SessionManager` reference counter,
         * hence the static method and the use of pointer.
         */
static Block50Data*
block50_data_ref (Block50Data* _data50_)
{
	g_atomic_int_inc (&_data50_->_ref_count_);
	return _data50_;
}

static void
block50_data_unref (void * _userdata_)
{
	Block50Data* _data50_;
	_data50_ = (Block50Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data50_->_ref_count_)) {
		g_slice_free (Block50Data, _data50_);
	}
}

static gboolean
__lambda41_ (Block50Data* _data50_)
{
	FtSession* _tmp0_;
	FtSession* _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	gboolean result;
	_data50_->session_manager->priv->expiry_timeout_id = (guint) 0;
	_tmp0_ = ft_session_manager_get_current_session (_data50_->session_manager);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_session_get_expiry_time (_tmp1_);
	_tmp3_ = _tmp2_;
	ft_session_manager_expire_current_session (_data50_->session_manager, _tmp3_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda41__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda41_ (self);
	return result;
}

static guint
ft_session_manager_setup_expiry_timeout (guint seconds,
                                         void* session_manager_ptr)
{
	Block50Data* _data50_;
	guint timeout_id = 0U;
	guint result;
	_data50_ = g_slice_new0 (Block50Data);
	_data50_->_ref_count_ = 1;
	_data50_->session_manager = G_TYPE_CHECK_INSTANCE_CAST (session_manager_ptr, FT_TYPE_SESSION_MANAGER, FtSessionManager);
	timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, seconds, ___lambda41__gsource_func, block50_data_ref (_data50_), block50_data_unref);
	g_source_set_name_by_id (timeout_id, "Ft.SessionManager.expire_current_session");
	result = timeout_id;
	block50_data_unref (_data50_);
	_data50_ = NULL;
	return result;
}

static void
ft_session_manager_on_current_session_notify_expiry_time (FtSessionManager* self)
{
	gint64 current_time = 0LL;
	FtSession* _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	g_return_if_fail (self != NULL);
	current_time = ft_session_manager_get_current_time (self);
	if (self->priv->expiry_timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->expiry_timeout_id);
		self->priv->expiry_timeout_id = (guint) 0;
	}
	_tmp0_ = self->priv->_current_session;
	_tmp1_ = ft_session_get_expiry_time (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ > current_time) {
		guint timeout_seconds = 0U;
		FtSession* _tmp3_;
		gint64 _tmp4_;
		gint64 _tmp5_;
		_tmp3_ = self->priv->_current_session;
		_tmp4_ = ft_session_get_expiry_time (_tmp3_);
		_tmp5_ = _tmp4_;
		timeout_seconds = ft_timestamp_to_seconds_uint (ft_timestamp_round_seconds (_tmp5_ - current_time));
		self->priv->expiry_timeout_id = ft_session_manager_setup_expiry_timeout (timeout_seconds, self);
	}
}

static void
ft_session_manager_on_settings_changed (FtSessionManager* self,
                                        const gchar* key)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (key != NULL);
	_tmp0_ = key;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if ((((_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("pomodoro-duration")))) || (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("short-break-duration"))))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("long-break-duration"))))) || (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("cycles"))))) {
		switch (0) {
			default:
			{
				ft_session_manager_update_session_template (self);
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("pause-on-lockscreen")))) {
		switch (0) {
			default:
			{
				ft_session_manager_update_auto_pause (self);
				break;
			}
		}
	} else if ((_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("pomodoro-advancement-mode")))) || (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("break-advancement-mode"))))) {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
}

static void
ft_session_manager_enable_idle_monitor (FtSessionManager* self)
{
	FtIdleMonitor* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->idle_monitor;
	if (_tmp0_ == NULL) {
		FtIdleMonitor* _tmp1_;
		_tmp1_ = ft_idle_monitor_new ();
		_g_object_unref0 (self->priv->idle_monitor);
		self->priv->idle_monitor = _tmp1_;
	}
}

static void
ft_session_manager_disable_idle_monitor (FtSessionManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->active_watch_id != ((guint) 0)) {
		FtIdleMonitor* _tmp0_;
		_tmp0_ = self->priv->idle_monitor;
		ft_idle_monitor_remove_watch (_tmp0_, self->priv->active_watch_id);
		self->priv->active_watch_id = (guint) 0;
	}
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = NULL;
}

/**
         * Initialize session if missing or expired.
         */
void
ft_session_manager_ensure_session (FtSessionManager* self,
                                   gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	g_return_if_fail (self != NULL);
	ft_ensure_timestamp (&timestamp);
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		FtSession* _tmp2_;
		_tmp2_ = self->priv->_current_session;
		_tmp0_ = ft_session_is_expired (_tmp2_, timestamp);
	}
	if (_tmp0_) {
		FtSession* next_session = NULL;
		FtSession* _tmp3_;
		FtSession* _tmp4_;
		_tmp3_ = ft_session_manager_initialize_next_session (self, timestamp);
		next_session = _tmp3_;
		_tmp4_ = next_session;
		ft_session_manager_set_current_time_block_full (self, _tmp4_, NULL, timestamp);
		_g_object_unref0 (next_session);
	}
}

gboolean
ft_session_manager_can_reset (FtSessionManager* self)
{
	FtSession* current_session = NULL;
	FtSession* _tmp0_;
	FtSession* _tmp1_;
	gboolean _tmp2_ = FALSE;
	FtTimer* _tmp3_;
	gboolean is_waiting_for_activity = FALSE;
	gboolean _tmp7_ = FALSE;
	FtSession* _tmp8_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_current_session;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	current_session = _tmp1_;
	_tmp3_ = self->priv->_timer;
	if (!ft_timer_is_started (_tmp3_)) {
		FtTimer* _tmp4_;
		void* _tmp5_;
		void* _tmp6_;
		_tmp4_ = self->priv->_timer;
		_tmp5_ = ft_timer_get_user_data (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	is_waiting_for_activity = _tmp2_;
	_tmp8_ = current_session;
	if (_tmp8_ != NULL) {
		gboolean _tmp9_ = FALSE;
		FtSession* _tmp10_;
		_tmp10_ = current_session;
		if (!ft_session_is_scheduled (_tmp10_)) {
			_tmp9_ = !is_waiting_for_activity;
		} else {
			_tmp9_ = FALSE;
		}
		_tmp7_ = _tmp9_;
	} else {
		_tmp7_ = FALSE;
	}
	result = _tmp7_;
	_g_object_unref0 (current_session);
	return result;
}

/**
         * Start a new session. The `timestamp` marks the end time of ongoing session.
         */
void
ft_session_manager_reset (FtSessionManager* self,
                          gint64 timestamp)
{
	gint64 now = 0LL;
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	g_return_if_fail (self != NULL);
	now = ft_timestamp_from_now ();
	if (ft_timestamp_is_undefined (timestamp)) {
		timestamp = now;
	}
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ != NULL) {
		FtSession* _tmp2_;
		_tmp2_ = self->priv->_current_session;
		_tmp0_ = !ft_session_is_scheduled (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		FtSession* next_session = NULL;
		FtSession* _tmp3_;
		FtSession* _tmp4_;
		_tmp3_ = ft_session_manager_initialize_next_session (self, now);
		next_session = _tmp3_;
		_tmp4_ = next_session;
		ft_session_manager_set_current_time_block_full (self, _tmp4_, NULL, timestamp);
		_g_object_unref0 (next_session);
	}
}

/**
         * Check and expire session if needed. Used in tests.
         */
void
ft_session_manager_check_current_session_expired (FtSessionManager* self)
{
	gint64 timestamp = 0LL;
	gboolean _tmp0_ = FALSE;
	FtSession* _tmp1_;
	g_return_if_fail (self != NULL);
	timestamp = ft_timestamp_from_now ();
	_tmp1_ = self->priv->_current_session;
	if (_tmp1_ != NULL) {
		FtSession* _tmp2_;
		_tmp2_ = self->priv->_current_session;
		_tmp0_ = ft_session_is_expired (_tmp2_, timestamp);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ft_session_manager_expire_current_session (self, timestamp);
	}
}

static void
_ft_session_manager_on_scheduler_notify_session_template_g_object_notify (GObject* _sender,
                                                                          GParamSpec* pspec,
                                                                          gpointer self)
{
	ft_session_manager_on_scheduler_notify_session_template ((FtSessionManager*) self);
}

static void
_ft_session_manager_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self)
{
	ft_session_manager_on_settings_changed ((FtSessionManager*) self, key);
}

static void
ft_session_manager_real_dispose (GObject* base)
{
	FtSessionManager * self;
	FtTimer* _tmp0_;
	FtScheduler* _tmp6_;
	GSettings* _tmp10_;
	self = (FtSessionManager*) base;
	_tmp0_ = self->priv->_timer;
	if (_tmp0_ != NULL) {
		if (self->priv->timer_resolve_state_id != ((gulong) 0)) {
			FtTimer* _tmp1_;
			_tmp1_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp1_, self->priv->timer_resolve_state_id);
			self->priv->timer_resolve_state_id = (gulong) 0;
		}
		if (self->priv->timer_state_changed_id != ((gulong) 0)) {
			FtTimer* _tmp2_;
			_tmp2_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->timer_state_changed_id);
			self->priv->timer_state_changed_id = (gulong) 0;
		}
		if (self->priv->timer_finished_id != ((gulong) 0)) {
			FtTimer* _tmp3_;
			_tmp3_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->timer_finished_id);
			self->priv->timer_finished_id = (gulong) 0;
		}
		if (self->priv->timer_suspending_id != ((gulong) 0)) {
			FtTimer* _tmp4_;
			_tmp4_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp4_, self->priv->timer_suspending_id);
			self->priv->timer_suspending_id = (gulong) 0;
		}
		if (self->priv->timer_suspended_id != ((gulong) 0)) {
			FtTimer* _tmp5_;
			_tmp5_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp5_, self->priv->timer_suspended_id);
			self->priv->timer_suspended_id = (gulong) 0;
		}
	}
	_tmp6_ = self->priv->_scheduler;
	if (_tmp6_ != NULL) {
		FtScheduler* _tmp7_;
		guint _tmp8_;
		GQuark _tmp9_;
		_tmp7_ = self->priv->_scheduler;
		g_signal_parse_name ("notify::session-template", G_TYPE_OBJECT, &_tmp8_, &_tmp9_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp7_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp8_, _tmp9_, NULL, (GCallback) _ft_session_manager_on_scheduler_notify_session_template_g_object_notify, self);
	}
	_tmp10_ = self->priv->settings;
	if (_tmp10_ != NULL) {
		GSettings* _tmp11_;
		guint _tmp12_;
		_tmp11_ = self->priv->settings;
		g_signal_parse_name ("changed", g_settings_get_type (), &_tmp12_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp11_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp12_, 0, NULL, (GCallback) _ft_session_manager_on_settings_changed_g_settings_changed, self);
	}
	if (self->priv->reschedule_idle_id != ((guint) 0)) {
		g_source_remove (self->priv->reschedule_idle_id);
		self->priv->reschedule_idle_id = (guint) 0;
	}
	if (self->priv->session_changed_idle_id != ((guint) 0)) {
		g_source_remove (self->priv->session_changed_idle_id);
		self->priv->session_changed_idle_id = (guint) 0;
	}
	if (self->priv->expiry_timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->expiry_timeout_id);
		self->priv->expiry_timeout_id = (guint) 0;
	}
	ft_session_manager_disable_auto_pause (self);
	ft_session_manager_disable_idle_monitor (self);
	_g_object_unref0 (self->priv->_current_gap);
	self->priv->_current_gap = NULL;
	_g_object_unref0 (self->priv->_current_time_block);
	self->priv->_current_time_block = NULL;
	_g_object_unref0 (self->priv->_current_session);
	self->priv->_current_session = NULL;
	_g_object_unref0 (self->priv->_timer);
	self->priv->_timer = NULL;
	_g_object_unref0 (self->priv->_scheduler);
	self->priv->_scheduler = NULL;
	_g_object_unref0 (self->priv->next_time_block);
	self->priv->next_time_block = NULL;
	_g_object_unref0 (self->priv->next_session);
	self->priv->next_session = NULL;
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = NULL;
	_g_object_unref0 (self->priv->timezone_monitor);
	self->priv->timezone_monitor = NULL;
	_g_object_unref0 (self->priv->timezone_history);
	self->priv->timezone_history = NULL;
	_g_object_unref0 (self->priv->lockscreen);
	self->priv->lockscreen = NULL;
	_g_object_unref0 (self->priv->screensaver);
	self->priv->screensaver = NULL;
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = NULL;
	G_OBJECT_CLASS (ft_session_manager_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

FtTimer*
ft_session_manager_get_timer (FtSessionManager* self)
{
	FtTimer* result;
	FtTimer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_timer;
	result = _tmp0_;
	return result;
}

static void
_ft_session_manager_on_timer_resolve_state_ft_timer_resolve_state (FtTimer* _sender,
                                                                   FtTimerState* state,
                                                                   gint64 timestamp,
                                                                   gpointer self)
{
	ft_session_manager_on_timer_resolve_state ((FtSessionManager*) self, state, timestamp);
}

static void
_ft_session_manager_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                   const FtTimerState* current_state,
                                                                   const FtTimerState* previous_state,
                                                                   gpointer self)
{
	ft_session_manager_on_timer_state_changed ((FtSessionManager*) self, current_state, previous_state);
}

static void
_ft_session_manager_on_timer_finished_ft_timer_finished (FtTimer* _sender,
                                                         const FtTimerState* state,
                                                         gpointer self)
{
	ft_session_manager_on_timer_finished ((FtSessionManager*) self, state);
}

static void
_ft_session_manager_on_timer_suspending_ft_timer_suspended (FtTimer* _sender,
                                                            gint64 start_time,
                                                            gint64 end_time,
                                                            gpointer self)
{
	ft_session_manager_on_timer_suspending ((FtSessionManager*) self, start_time);
}

static void
_ft_session_manager_on_timer_suspended_ft_timer_suspended (FtTimer* _sender,
                                                           gint64 start_time,
                                                           gint64 end_time,
                                                           gpointer self)
{
	ft_session_manager_on_timer_suspended ((FtSessionManager*) self, start_time, end_time);
}

static void
ft_session_manager_set_timer (FtSessionManager* self,
                              FtTimer* value)
{
	FtTimer* _tmp0_;
	FtTimer* _tmp1_;
	FtTimer* _tmp2_;
	gulong _tmp3_;
	FtTimer* _tmp4_;
	gulong _tmp5_;
	FtTimer* _tmp6_;
	gulong _tmp7_;
	FtTimer* _tmp8_;
	gulong _tmp9_;
	FtTimer* _tmp10_;
	gulong _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_timer);
	self->priv->_timer = _tmp0_;
	_tmp1_ = self->priv->_timer;
	ft_timer_reset (_tmp1_, (gint64) 0, NULL, FT_TIMESTAMP_UNDEFINED);
	_tmp2_ = self->priv->_timer;
	_tmp3_ = g_signal_connect_object (_tmp2_, "resolve-state", (GCallback) _ft_session_manager_on_timer_resolve_state_ft_timer_resolve_state, self, 0);
	self->priv->timer_resolve_state_id = _tmp3_;
	_tmp4_ = self->priv->_timer;
	_tmp5_ = g_signal_connect_object (_tmp4_, "state-changed", (GCallback) _ft_session_manager_on_timer_state_changed_ft_timer_state_changed, self, 0);
	self->priv->timer_state_changed_id = _tmp5_;
	_tmp6_ = self->priv->_timer;
	_tmp7_ = g_signal_connect_object (_tmp6_, "finished", (GCallback) _ft_session_manager_on_timer_finished_ft_timer_finished, self, 0);
	self->priv->timer_finished_id = _tmp7_;
	_tmp8_ = self->priv->_timer;
	_tmp9_ = g_signal_connect_object (_tmp8_, "suspended", (GCallback) _ft_session_manager_on_timer_suspending_ft_timer_suspended, self, 0);
	self->priv->timer_suspending_id = _tmp9_;
	_tmp10_ = self->priv->_timer;
	_tmp11_ = g_signal_connect_object (_tmp10_, "suspended", (GCallback) _ft_session_manager_on_timer_suspended_ft_timer_suspended, self, 0);
	self->priv->timer_suspended_id = _tmp11_;
	g_object_notify_by_pspec ((GObject *) self, ft_session_manager_properties[FT_SESSION_MANAGER_TIMER_PROPERTY]);
}

FtScheduler*
ft_session_manager_get_scheduler (FtSessionManager* self)
{
	FtScheduler* result;
	FtScheduler* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_scheduler;
	result = _tmp0_;
	return result;
}

void
ft_session_manager_set_scheduler (FtSessionManager* self,
                                  FtScheduler* value)
{
	FtScheduler* _tmp0_;
	FtScheduler* _tmp1_;
	FtScheduler* _tmp5_;
	FtScheduler* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_scheduler;
	if (_tmp0_ == value) {
		return;
	}
	_tmp1_ = self->priv->_scheduler;
	if (_tmp1_ != NULL) {
		FtScheduler* _tmp2_;
		guint _tmp3_;
		GQuark _tmp4_;
		_tmp2_ = self->priv->_scheduler;
		g_signal_parse_name ("notify::session-template", G_TYPE_OBJECT, &_tmp3_, &_tmp4_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp2_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, _tmp4_, NULL, (GCallback) _ft_session_manager_on_scheduler_notify_session_template_g_object_notify, self);
	}
	_tmp5_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_scheduler);
	self->priv->_scheduler = _tmp5_;
	_tmp6_ = self->priv->_scheduler;
	if (_tmp6_ != NULL) {
		FtScheduler* _tmp7_;
		_tmp7_ = self->priv->_scheduler;
		g_signal_connect_object ((GObject*) _tmp7_, "notify::session-template", (GCallback) _ft_session_manager_on_scheduler_notify_session_template_g_object_notify, self, 0);
	}
	ft_session_manager_reschedule (self);
	ft_session_manager_update_has_uniform_breaks (self);
	g_object_notify ((GObject*) self, "scheduler");
}

FtSession*
ft_session_manager_get_current_session (FtSessionManager* self)
{
	FtSession* result;
	FtSession* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_session;
	result = _tmp0_;
	return result;
}

void
ft_session_manager_set_current_session (FtSessionManager* self,
                                        FtSession* value)
{
	g_return_if_fail (self != NULL);
	ft_session_manager_set_current_time_block_full (self, value, NULL, FT_TIMESTAMP_UNDEFINED);
}

FtTimeBlock*
ft_session_manager_get_current_time_block (FtSessionManager* self)
{
	FtTimeBlock* result;
	FtTimeBlock* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_time_block;
	result = _tmp0_;
	return result;
}

void
ft_session_manager_set_current_time_block (FtSessionManager* self,
                                           FtTimeBlock* value)
{
	FtSession* _tmp0_ = NULL;
	FtSession* session = NULL;
	FtSession* _tmp4_;
	g_return_if_fail (self != NULL);
	if (value != NULL) {
		FtSession* _tmp1_;
		FtSession* _tmp2_;
		_tmp1_ = ft_time_block_get_session (value);
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_;
	} else {
		FtSession* _tmp3_;
		_tmp3_ = self->priv->_current_session;
		_tmp0_ = _tmp3_;
	}
	_tmp4_ = _g_object_ref0 (_tmp0_);
	session = _tmp4_;
	ft_session_manager_set_current_time_block_full (self, session, value, FT_TIMESTAMP_UNDEFINED);
	_g_object_unref0 (session);
}

FtState
ft_session_manager_get_current_state (FtSessionManager* self)
{
	FtState result;
	FtState _tmp0_ = 0;
	FtTimeBlock* _tmp1_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp1_ = self->priv->_current_time_block;
	if (_tmp1_ != NULL) {
		FtTimeBlock* _tmp2_;
		FtState _tmp3_;
		FtState _tmp4_;
		_tmp2_ = self->priv->_current_time_block;
		_tmp3_ = ft_time_block_get_state (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FT_STATE_STOPPED;
	}
	result = _tmp0_;
	return result;
}

void
ft_session_manager_set_current_state (FtSessionManager* self,
                                      FtState value)
{
	g_return_if_fail (self != NULL);
	ft_session_manager_advance_to_state (self, value, FT_TIMESTAMP_UNDEFINED);
}

FtGap*
ft_session_manager_get_current_gap (FtSessionManager* self)
{
	FtGap* result;
	FtGap* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_current_gap;
	result = _tmp0_;
	return result;
}

gboolean
ft_session_manager_get_has_uniform_breaks (FtSessionManager* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_has_uniform_breaks;
	return result;
}

static void
_ft_session_manager_on_current_session_notify_expiry_time_g_object_notify (GObject* _sender,
                                                                           GParamSpec* pspec,
                                                                           gpointer self)
{
	ft_session_manager_on_current_session_notify_expiry_time ((FtSessionManager*) self);
}

static void
ft_session_manager_real_enter_session (FtSessionManager* self,
                                       FtSession* session)
{
	FtSession* _tmp0_;
	FtSession* _tmp1_;
	gulong _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	_tmp0_ = self->priv->_current_session;
	_vala_assert (session == _tmp0_, "session == this._current_session");
	self->priv->current_session_entered = TRUE;
	_tmp1_ = self->priv->_current_session;
	_tmp2_ = g_signal_connect_object ((GObject*) _tmp1_, "notify::expiry-time", (GCallback) _ft_session_manager_on_current_session_notify_expiry_time_g_object_notify, self, 0);
	self->priv->current_session_notify_expiry_time_id = _tmp2_;
	ft_session_manager_update_has_uniform_breaks (self);
	ft_session_manager_emit_session_rescheduled (self, FT_TIMESTAMP_UNDEFINED);
}

static void
ft_session_manager_real_leave_session (FtSessionManager* self,
                                       FtSession* session)
{
	FtSession* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	_tmp0_ = self->priv->_current_session;
	_vala_assert (session == _tmp0_, "session == this._current_session");
	ft_session_manager_thaw_current_session_changed (self);
	g_signal_handler_disconnect ((GObject*) session, self->priv->current_session_notify_expiry_time_id);
	self->priv->current_session_entered = FALSE;
	self->priv->current_session_notify_expiry_time_id = (gulong) 0;
}

static void
_ft_session_manager_on_current_time_block_changed_ft_time_block_changed (FtTimeBlock* _sender,
                                                                         gpointer self)
{
	ft_session_manager_on_current_time_block_changed ((FtSessionManager*) self, _sender);
}

static void
ft_session_manager_real_enter_time_block (FtSessionManager* self,
                                          FtTimeBlock* time_block)
{
	FtTimeBlock* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gulong _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_tmp0_ = self->priv->_current_time_block;
	_vala_assert (time_block == _tmp0_, "time_block == this._current_time_block");
	if (ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_SCHEDULED) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_IN_PROGRESS;
	}
	_vala_assert (_tmp1_, "time_block.get_status () == Ft.TimeBlockStatus.SCHEDULED ||                     time_block.get_status () == Ft.TimeBlockStatus.IN_PROGRESS");
	if (self->priv->current_time_block_changed_id != ((gulong) 0)) {
		g_warning ("session-manager.vala:2605: `TimeBlock.changed` signal handler has not " \
"been disconnected properly");
	}
	self->priv->current_time_block_entered = TRUE;
	_tmp2_ = g_signal_connect_object (time_block, "changed", (GCallback) _ft_session_manager_on_current_time_block_changed_ft_time_block_changed, self, 0);
	self->priv->current_time_block_changed_id = _tmp2_;
	_g_object_unref0 (self->priv->next_session);
	self->priv->next_session = NULL;
	_g_object_unref0 (self->priv->next_time_block);
	self->priv->next_time_block = NULL;
	ft_time_block_set_status (time_block, FT_TIME_BLOCK_STATUS_IN_PROGRESS);
}

static void
ft_session_manager_real_leave_time_block (FtSessionManager* self,
                                          FtTimeBlock* time_block)
{
	FtTimeBlock* _tmp0_;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_tmp0_ = self->priv->_current_time_block;
	_vala_assert (time_block == _tmp0_, "time_block == this._current_time_block");
	if (ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_COMPLETED) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_UNCOMPLETED;
	}
	_vala_assert (_tmp1_, "time_block.get_status () == Ft.TimeBlockStatus.COMPLETED ||                     time_block.get_status () == Ft.TimeBlockStatus.UNCOMPLETED");
	self->priv->current_time_block_entered = FALSE;
	if (self->priv->current_time_block_changed_id != ((gulong) 0)) {
		g_signal_handler_disconnect ((GObject*) time_block, self->priv->current_time_block_changed_id);
		self->priv->current_time_block_changed_id = (gulong) 0;
	}
}

static void
ft_session_manager_real_session_rescheduled (FtSessionManager* self,
                                             FtSession* session,
                                             gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	if (self->priv->current_session_changed_frozen) {
		_tmp0_ = ft_is_test ();
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_debug ("session-manager.vala:2635: Rescheduled session while setting current-t" \
"ime-block");
	}
}

static void
g_cclosure_user_marshal_VOID__OBJECT_INT64 (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_INT64) (gpointer data1, gpointer arg_1, gint64 arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_INT64 callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_INT64) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_int64 (param_values + 2), data2);
}

static void
ft_session_manager_real_session_expired (FtSessionManager* self,
                                         FtSession* session,
                                         gint64 timestamp)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	g_debug ("session-manager.vala:2642: Session expired");
}

static void
g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure * closure,
                                             GValue * return_value,
                                             guint n_param_values,
                                             const GValue * param_values,
                                             gpointer invocation_hint,
                                             gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_OBJECT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_object (param_values + 2), data2);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT_OBJECT (GClosure * closure,
                                                           GValue * return_value,
                                                           guint n_param_values,
                                                           const GValue * param_values,
                                                           gpointer invocation_hint,
                                                           gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT_OBJECT) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer arg_3, gpointer arg_4, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT_OBJECT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 5);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_object (param_values + 2), g_value_get_object (param_values + 3), g_value_get_object (param_values + 4), data2);
}

static void
_ft_session_manager_on_timezone_changed_ft_time_zone_monitor_changed (FtTimeZoneMonitor* _sender,
                                                                      gpointer self)
{
	ft_session_manager_on_timezone_changed ((FtSessionManager*) self);
}

static GObject *
ft_session_manager_constructor (GType type,
                                guint n_construct_properties,
                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtSessionManager * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	FtSimpleScheduler* _tmp2_;
	FtSimpleScheduler* _tmp3_;
	FtTimeZoneMonitor* _tmp4_;
	FtTimezoneHistory* _tmp5_;
	FtAsyncCallback** _tmp6_;
	GSettings* _tmp7_;
	FtTimeZoneMonitor* _tmp8_;
	parent_class = G_OBJECT_CLASS (ft_session_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_SESSION_MANAGER, FtSessionManager);
	_tmp0_ = ft_get_settings ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp1_;
	_tmp2_ = ft_simple_scheduler_new ();
	_tmp3_ = _tmp2_;
	ft_session_manager_set_scheduler (self, (FtScheduler*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = ft_time_zone_monitor_new ();
	_g_object_unref0 (self->priv->timezone_monitor);
	self->priv->timezone_monitor = _tmp4_;
	_tmp5_ = ft_timezone_history_new ();
	_g_object_unref0 (self->priv->timezone_history);
	self->priv->timezone_history = _tmp5_;
	_tmp6_ = g_new0 (FtAsyncCallback*, 0 + 1);
	self->priv->save_callbacks = (_vala_array_free (self->priv->save_callbacks, self->priv->save_callbacks_length1, (GDestroyNotify) ft_async_callback_free), NULL);
	self->priv->save_callbacks = _tmp6_;
	self->priv->save_callbacks_length1 = 0;
	self->priv->_save_callbacks_size_ = self->priv->save_callbacks_length1;
	_tmp7_ = self->priv->settings;
	g_signal_connect_object (_tmp7_, "changed", (GCallback) _ft_session_manager_on_settings_changed_g_settings_changed, self, 0);
	_tmp8_ = self->priv->timezone_monitor;
	g_signal_connect_object (_tmp8_, "changed", (GCallback) _ft_session_manager_on_timezone_changed_ft_time_zone_monitor_changed, self, 0);
	ft_session_manager_update_session_template (self);
	return obj;
}

static void
ft_session_manager_class_init (FtSessionManagerClass * klass,
                               gpointer klass_data)
{
	ft_session_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtSessionManager_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_session_manager_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_session_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_session_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_session_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_session_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SESSION_MANAGER_TIMER_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_TIMER_PROPERTY] = g_param_spec_object ("timer", "timer", "timer", FT_TYPE_TIMER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SESSION_MANAGER_SCHEDULER_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_SCHEDULER_PROPERTY] = g_param_spec_object ("scheduler", "scheduler", "scheduler", FT_TYPE_SCHEDULER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	/**
	         * A current session.
	         *
	         * Setter replaces current session with another one without adjusting either of them.
	         * To correct the timing use `advance_*` methods. After selecting session manually, the current time-block
	         * is null and the timer is stopped.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SESSION_MANAGER_CURRENT_SESSION_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_CURRENT_SESSION_PROPERTY] = g_param_spec_object ("current-session", "current-session", "current-session", FT_TYPE_SESSION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	/**
	         * Current time-block.
	         *
	         * Only `SessionManager` is aware which time-block is current. Current time-block is reflected in `Timer.state`,
	         * but it's not 1:1 equivalent. Time-block has clearly defined gaps, while timer only keeps track of offset.
	         *
	         * `null` means that current time-block has not yet started and that timer is stopped.
	         *
	         * Setter replaces current time-block with another one without adjusting either of them.
	         * To correct the timing use `advance_*` methods. Setter is meant only for unit testing.
	         * Time-block must be assigned to a session beforehand. Setting a time-block with a different session will
	         * also switch to a new session. All blocks within new session preceding given `time-block` will be removed.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SESSION_MANAGER_CURRENT_TIME_BLOCK_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_CURRENT_TIME_BLOCK_PROPERTY] = g_param_spec_object ("current-time-block", "current-time-block", "current-time-block", FT_TYPE_TIME_BLOCK, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	/**
	         * Convenience property to track current state.
	         *
	         * The `this._current_state` is used for the property notification only.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SESSION_MANAGER_CURRENT_STATE_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_CURRENT_STATE_PROPERTY] = g_param_spec_enum ("current-state", "current-state", "current-state", FT_TYPE_STATE, 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_SESSION_MANAGER_CURRENT_GAP_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_CURRENT_GAP_PROPERTY] = g_param_spec_object ("current-gap", "current-gap", "current-gap", FT_TYPE_GAP, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	         * Convenience property to track whether there are several cycles per session.
	         *
	         * It equivalent to whether a session has short breaks.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_SESSION_MANAGER_HAS_UNIFORM_BREAKS_PROPERTY, ft_session_manager_properties[FT_SESSION_MANAGER_HAS_UNIFORM_BREAKS_PROPERTY] = g_param_spec_boolean ("has-uniform-breaks", "has-uniform-breaks", "has-uniform-breaks", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY));
	/**
	         * Session is entered as soon as current-session property is set.
	         */
	ft_session_manager_signals[FT_SESSION_MANAGER_ENTER_SESSION_SIGNAL] = g_signal_new_class_handler ("enter-session", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_FIRST, (GCallback) ft_session_manager_real_enter_session, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, FT_TYPE_SESSION);
	ft_session_manager_signals[FT_SESSION_MANAGER_LEAVE_SESSION_SIGNAL] = g_signal_new_class_handler ("leave-session", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_FIRST, (GCallback) ft_session_manager_real_leave_session, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, FT_TYPE_SESSION);
	/**
	         * Time block is entered as soon as current-time-block property is set.
	         * You should check timer whether time block has really started.
	         */
	ft_session_manager_signals[FT_SESSION_MANAGER_ENTER_TIME_BLOCK_SIGNAL] = g_signal_new_class_handler ("enter-time-block", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_FIRST, (GCallback) ft_session_manager_real_enter_time_block, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, FT_TYPE_TIME_BLOCK);
	ft_session_manager_signals[FT_SESSION_MANAGER_LEAVE_TIME_BLOCK_SIGNAL] = g_signal_new_class_handler ("leave-time-block", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_FIRST, (GCallback) ft_session_manager_real_leave_time_block, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, FT_TYPE_TIME_BLOCK);
	ft_session_manager_signals[FT_SESSION_MANAGER_SESSION_RESCHEDULED_SIGNAL] = g_signal_new_class_handler ("session-rescheduled", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_LAST, (GCallback) ft_session_manager_real_session_rescheduled, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_INT64, G_TYPE_NONE, 2, FT_TYPE_SESSION, G_TYPE_INT64);
	ft_session_manager_signals[FT_SESSION_MANAGER_SESSION_EXPIRED_SIGNAL] = g_signal_new_class_handler ("session-expired", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_LAST, (GCallback) ft_session_manager_real_session_expired, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_INT64, G_TYPE_NONE, 2, FT_TYPE_SESSION, G_TYPE_INT64);
	/**
	         * Outward signal that we need a confirmation before advancing to a next time-block.
	         * Until then the timer will indicate that it has finished, the session-manager will keep current time-block
	         * intact. You should use skip action or `.advance()` to jump to the next time-block.
	         *
	         * XXX: rename to `request_advancement`?
	         */
	ft_session_manager_signals[FT_SESSION_MANAGER_CONFIRM_ADVANCEMENT_SIGNAL] = g_signal_new ("confirm-advancement", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, FT_TYPE_TIME_BLOCK, FT_TYPE_TIME_BLOCK);
	/**
	         * A convenience signal to handle transition between time-blocks.
	         *
	         * It's emitted after entering the current_time_block.
	         */
	ft_session_manager_signals[FT_SESSION_MANAGER_ADVANCED_SIGNAL] = g_signal_new ("advanced", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT_OBJECT, G_TYPE_NONE, 4, FT_TYPE_SESSION, FT_TYPE_TIME_BLOCK, FT_TYPE_SESSION, FT_TYPE_TIME_BLOCK);
	ft_session_manager_signals[FT_SESSION_MANAGER_TIME_BLOCK_SAVED_SIGNAL] = g_signal_new ("time-block-saved", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, FT_TYPE_TIME_BLOCK, FT_TYPE_TIME_BLOCK_ENTRY);
	ft_session_manager_signals[FT_SESSION_MANAGER_GAP_SAVED_SIGNAL] = g_signal_new ("gap-saved", FT_TYPE_SESSION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, FT_TYPE_GAP, FT_TYPE_GAP_ENTRY);
}

static void
ft_session_manager_instance_init (FtSessionManager * self,
                                  gpointer klass)
{
	self->priv = ft_session_manager_get_instance_private (self);
	self->priv->_current_session = NULL;
	self->priv->_current_time_block = NULL;
	self->priv->_current_gap = NULL;
	self->priv->_current_state = FT_STATE_STOPPED;
	self->priv->_has_uniform_breaks = FALSE;
	self->priv->next_session = NULL;
	self->priv->next_time_block = NULL;
	self->priv->idle_monitor = NULL;
	self->priv->timezone_monitor = NULL;
	self->priv->timezone_history = NULL;
	self->priv->screensaver = NULL;
	self->priv->lockscreen = NULL;
	self->priv->auto_paused = FALSE;
	self->priv->current_time_block_entered = FALSE;
	self->priv->current_time_block_changed_id = (gulong) 0;
	self->priv->current_session_entered = FALSE;
	self->priv->current_session_changed_frozen = FALSE;
	self->priv->current_session_notify_expiry_time_id = (gulong) 0;
	self->priv->previous_session = NULL;
	self->priv->previous_time_block = NULL;
	self->priv->settings = NULL;
	self->priv->resolving_timer_state = 0;
	self->priv->timer_resolve_state_id = (gulong) 0;
	self->priv->timer_state_changed_id = (gulong) 0;
	self->priv->timer_finished_id = (gulong) 0;
	self->priv->timer_suspending_id = (gulong) 0;
	self->priv->timer_suspended_id = (gulong) 0;
	self->priv->expiry_timeout_id = (guint) 0;
	self->priv->reschedule_idle_id = (guint) 0;
	self->priv->active_watch_id = (guint) 0;
	self->priv->session_changed_idle_id = (guint) 0;
	self->priv->saving = FALSE;
	self->priv->save_dirty = FALSE;
	self->priv->save_result = FALSE;
}

static void
ft_session_manager_finalize (GObject * obj)
{
	FtSessionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_SESSION_MANAGER, FtSessionManager);
	_g_object_unref0 (self->priv->_timer);
	_g_object_unref0 (self->priv->_scheduler);
	_g_object_unref0 (self->priv->_current_session);
	_g_object_unref0 (self->priv->_current_time_block);
	_g_object_unref0 (self->priv->_current_gap);
	_g_object_unref0 (self->priv->next_session);
	_g_object_unref0 (self->priv->next_time_block);
	_g_object_unref0 (self->priv->idle_monitor);
	_g_object_unref0 (self->priv->timezone_monitor);
	_g_object_unref0 (self->priv->timezone_history);
	_g_object_unref0 (self->priv->screensaver);
	_g_object_unref0 (self->priv->lockscreen);
	_g_object_unref0 (self->priv->previous_session);
	_g_object_unref0 (self->priv->previous_time_block);
	_g_object_unref0 (self->priv->settings);
	self->priv->save_callbacks = (_vala_array_free (self->priv->save_callbacks, self->priv->save_callbacks_length1, (GDestroyNotify) ft_async_callback_free), NULL);
	G_OBJECT_CLASS (ft_session_manager_parent_class)->finalize (obj);
}

/**
     * `SessionManager` sets up the timer, advances time-blocks and sessions.
     */
static GType
ft_session_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtSessionManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_session_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtSessionManager), 0, (GInstanceInitFunc) ft_session_manager_instance_init, NULL };
	GType ft_session_manager_type_id;
	ft_session_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "FtSessionManager", &g_define_type_info, 0);
	FtSessionManager_private_offset = g_type_add_instance_private (ft_session_manager_type_id, sizeof (FtSessionManagerPrivate));
	return ft_session_manager_type_id;
}

GType
ft_session_manager_get_type (void)
{
	static volatile gsize ft_session_manager_type_id__once = 0;
	if (g_once_init_enter (&ft_session_manager_type_id__once)) {
		GType ft_session_manager_type_id;
		ft_session_manager_type_id = ft_session_manager_get_type_once ();
		g_once_init_leave (&ft_session_manager_type_id__once, ft_session_manager_type_id);
	}
	return ft_session_manager_type_id__once;
}

static void
_vala_ft_session_manager_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	FtSessionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_SESSION_MANAGER, FtSessionManager);
	switch (property_id) {
		case FT_SESSION_MANAGER_TIMER_PROPERTY:
		g_value_set_object (value, ft_session_manager_get_timer (self));
		break;
		case FT_SESSION_MANAGER_SCHEDULER_PROPERTY:
		g_value_set_object (value, ft_session_manager_get_scheduler (self));
		break;
		case FT_SESSION_MANAGER_CURRENT_SESSION_PROPERTY:
		g_value_set_object (value, ft_session_manager_get_current_session (self));
		break;
		case FT_SESSION_MANAGER_CURRENT_TIME_BLOCK_PROPERTY:
		g_value_set_object (value, ft_session_manager_get_current_time_block (self));
		break;
		case FT_SESSION_MANAGER_CURRENT_STATE_PROPERTY:
		g_value_set_enum (value, ft_session_manager_get_current_state (self));
		break;
		case FT_SESSION_MANAGER_CURRENT_GAP_PROPERTY:
		g_value_set_object (value, ft_session_manager_get_current_gap (self));
		break;
		case FT_SESSION_MANAGER_HAS_UNIFORM_BREAKS_PROPERTY:
		g_value_set_boolean (value, ft_session_manager_get_has_uniform_breaks (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_session_manager_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	FtSessionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_SESSION_MANAGER, FtSessionManager);
	switch (property_id) {
		case FT_SESSION_MANAGER_TIMER_PROPERTY:
		ft_session_manager_set_timer (self, g_value_get_object (value));
		break;
		case FT_SESSION_MANAGER_SCHEDULER_PROPERTY:
		ft_session_manager_set_scheduler (self, g_value_get_object (value));
		break;
		case FT_SESSION_MANAGER_CURRENT_SESSION_PROPERTY:
		ft_session_manager_set_current_session (self, g_value_get_object (value));
		break;
		case FT_SESSION_MANAGER_CURRENT_TIME_BLOCK_PROPERTY:
		ft_session_manager_set_current_time_block (self, g_value_get_object (value));
		break;
		case FT_SESSION_MANAGER_CURRENT_STATE_PROPERTY:
		ft_session_manager_set_current_state (self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

