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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include "planify.h"
#include <gio/gio.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define SERVICES_TYPE_BACKUP_MANAGER (services_backup_manager_get_type ())
#define SERVICES_BACKUP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVICES_TYPE_BACKUP_MANAGER, ServicesBackupManager))
#define SERVICES_BACKUP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVICES_TYPE_BACKUP_MANAGER, ServicesBackupManagerClass))
#define SERVICES_IS_BACKUP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVICES_TYPE_BACKUP_MANAGER))
#define SERVICES_IS_BACKUP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVICES_TYPE_BACKUP_MANAGER))
#define SERVICES_BACKUP_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVICES_TYPE_BACKUP_MANAGER, ServicesBackupManagerClass))

typedef struct _ServicesBackupManager ServicesBackupManager;
typedef struct _ServicesBackupManagerClass ServicesBackupManagerClass;
typedef struct _ServicesBackupManagerPrivate ServicesBackupManagerPrivate;

#define OBJECTS_TYPE_BACKUP (objects_backup_get_type ())
#define OBJECTS_BACKUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OBJECTS_TYPE_BACKUP, ObjectsBackup))
#define OBJECTS_BACKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OBJECTS_TYPE_BACKUP, ObjectsBackupClass))
#define OBJECTS_IS_BACKUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OBJECTS_TYPE_BACKUP))
#define OBJECTS_IS_BACKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OBJECTS_TYPE_BACKUP))
#define OBJECTS_BACKUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OBJECTS_TYPE_BACKUP, ObjectsBackupClass))

typedef struct _ObjectsBackup ObjectsBackup;
typedef struct _ObjectsBackupClass ObjectsBackupClass;
enum  {
	SERVICES_BACKUP_MANAGER_0_PROPERTY,
	SERVICES_BACKUP_MANAGER_BACKUPS_PROPERTY,
	SERVICES_BACKUP_MANAGER_NUM_PROPERTIES
};
static GParamSpec* services_backup_manager_properties[SERVICES_BACKUP_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_time_zone_unref0(var) ((var == NULL) ? NULL : (var = (g_time_zone_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block15Data Block15Data;

#define TYPE_PLANIFY (planify_get_type ())
#define PLANIFY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLANIFY, Planify))
#define PLANIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLANIFY, PlanifyClass))
#define IS_PLANIFY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLANIFY))
#define IS_PLANIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLANIFY))
#define PLANIFY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLANIFY, PlanifyClass))

typedef struct _Planify Planify;
typedef struct _PlanifyClass PlanifyClass;
typedef struct _PlanifyPrivate PlanifyPrivate;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;
typedef struct _Block16Data Block16Data;
typedef struct _ServicesBackupManagerChooseBackupFileData ServicesBackupManagerChooseBackupFileData;
enum  {
	SERVICES_BACKUP_MANAGER_BACKUP_ADDED_SIGNAL,
	SERVICES_BACKUP_MANAGER_NUM_SIGNALS
};
static guint services_backup_manager_signals[SERVICES_BACKUP_MANAGER_NUM_SIGNALS] = {0};

struct _ServicesBackupManager {
	GObject parent_instance;
	ServicesBackupManagerPrivate * priv;
};

struct _ServicesBackupManagerClass {
	GObjectClass parent_class;
};

struct _ServicesBackupManagerPrivate {
	JsonGenerator* generator;
	JsonBuilder* builder;
	JsonParser* parser;
	gchar* path;
	GeeArrayList* _backups;
};

struct _Block15Data {
	int _ref_count_;
	ServicesBackupManager* self;
	ObjectsBackup* backup;
};

struct _Planify {
	AdwApplication parent_instance;
	PlanifyPrivate * priv;
	MainWindow* main_window;
};

struct _PlanifyClass {
	AdwApplicationClass parent_class;
};

struct _Block16Data {
	int _ref_count_;
	ServicesBackupManager* self;
	GtkFileDialog* dialog;
	ObjectsBackup* backup;
};

struct _ServicesBackupManagerChooseBackupFileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesBackupManager* self;
	GFile* result;
	GtkFileDialog* dialog;
	GtkFileDialog* _tmp0_;
	GFile* file;
	Planify* _tmp1_;
	MainWindow* _tmp2_;
	GFile* _tmp3_;
	GError* e;
	GError* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GError* _inner_error0_;
};

static gint ServicesBackupManager_private_offset;
static gpointer services_backup_manager_parent_class = NULL;
static ServicesBackupManager* services_backup_manager__instance;
static ServicesBackupManager* services_backup_manager__instance = NULL;
VALA_EXTERN Planify* planify__instance;

VALA_EXTERN GType services_backup_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ServicesBackupManager, g_object_unref)
VALA_EXTERN GType objects_backup_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ObjectsBackup, g_object_unref)
VALA_EXTERN ServicesBackupManager* services_backup_manager_get_default (void);
VALA_EXTERN ServicesBackupManager* services_backup_manager_new (void);
VALA_EXTERN ServicesBackupManager* services_backup_manager_construct (GType object_type);
VALA_EXTERN void services_backup_manager_init_auto_backup (ServicesBackupManager* self);
static void _services_backup_manager_check_missed_backup (ServicesBackupManager* self);
static void __lambda358_ (ServicesBackupManager* self);
VALA_EXTERN void services_backup_manager_create_and_distribute_backup (ServicesBackupManager* self);
static void ___lambda358__services_event_bus_day_changed (ServicesEventBus* _sender,
                                                   gpointer self);
VALA_EXTERN GeeArrayList* services_backup_manager_get_backups_collection (ServicesBackupManager* self);
VALA_EXTERN gboolean services_backup_manager_is_backup_file (const gchar* mime_type);
VALA_EXTERN ObjectsBackup* objects_backup_new_from_file (GFile* file);
VALA_EXTERN ObjectsBackup* objects_backup_construct_from_file (GType object_type,
                                                   GFile* file);
VALA_EXTERN gchar* services_backup_manager_export_to_json (ServicesBackupManager* self);
VALA_EXTERN GFile* services_backup_manager_create_backup (ServicesBackupManager* self);
static void services_backup_manager_copy_to_extra_folders (ServicesBackupManager* self,
                                                    GFile* source_file);
VALA_EXTERN void services_backup_manager_add_extra_folder (ServicesBackupManager* self,
                                               const gchar* folder_path);
VALA_EXTERN void services_backup_manager_remove_extra_folder (ServicesBackupManager* self,
                                                  const gchar* folder_path);
VALA_EXTERN void services_backup_manager_delete_backup (ServicesBackupManager* self,
                                            ObjectsBackup* backup);
static Block15Data* block15_data_ref (Block15Data* _data15_);
static void block15_data_unref (void * _userdata_);
VALA_EXTERN GType planify_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Planify, g_object_unref)
VALA_EXTERN Planify* planify_get_instance (void);
VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
static void __lambda359_ (Block15Data* _data15_,
                   const gchar* response);
VALA_EXTERN const gchar* objects_backup_get_path (ObjectsBackup* self);
static void ___lambda359__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                              const gchar* response,
                                              gpointer self);
VALA_EXTERN void services_backup_manager_save_file_as (ServicesBackupManager* self,
                                           ObjectsBackup* backup);
static Block16Data* block16_data_ref (Block16Data* _data16_);
static void block16_data_unref (void * _userdata_);
VALA_EXTERN const gchar* objects_backup_get_title (ObjectsBackup* self);
static void services_backup_manager_add_filters (ServicesBackupManager* self,
                                          GtkFileDialog* file_dialog);
static void __lambda360_ (Block16Data* _data16_,
                   GObject* obj,
                   GAsyncResult* res);
static void ___lambda360__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void services_backup_manager_choose_backup_file_data_free (gpointer _data);
VALA_EXTERN void services_backup_manager_choose_backup_file (ServicesBackupManager* self,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GFile* services_backup_manager_choose_backup_file_finish (ServicesBackupManager* self,
                                                          GAsyncResult* _res_);
static gboolean services_backup_manager_choose_backup_file_co (ServicesBackupManagerChooseBackupFileData* _data_);
static void services_backup_manager_choose_backup_file_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
VALA_EXTERN void services_backup_manager_patch_backup (ServicesBackupManager* self,
                                           ObjectsBackup* backup);
VALA_EXTERN const gchar* objects_backup_get_local_inbox_project_id (ObjectsBackup* self);
VALA_EXTERN GeeArrayList* objects_backup_get_sources (ObjectsBackup* self);
VALA_EXTERN GeeArrayList* objects_backup_get_labels (ObjectsBackup* self);
VALA_EXTERN GeeArrayList* objects_backup_get_projects (ObjectsBackup* self);
VALA_EXTERN GeeArrayList* objects_backup_get_sections (ObjectsBackup* self);
VALA_EXTERN GeeArrayList* objects_backup_get_items (ObjectsBackup* self);
static void services_backup_manager_show_message (ServicesBackupManager* self);
static void __lambda361_ (ServicesBackupManager* self,
                   const gchar* response);
static void services_backup_manager_restart_application (ServicesBackupManager* self);
static void ___lambda361__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                              const gchar* response,
                                              gpointer self);
VALA_EXTERN void planify_recreate_main_window (Planify* self);
VALA_EXTERN GeeArrayList* services_backup_manager_get_backups (ServicesBackupManager* self);
static GObject * services_backup_manager_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void services_backup_manager_finalize (GObject * obj);
static GType services_backup_manager_get_type_once (void);
static void _vala_services_backup_manager_get_property (GObject * object,
                                                 guint property_id,
                                                 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 gssize _vala_array_length (gpointer array);

static inline gpointer
services_backup_manager_get_instance_private (ServicesBackupManager* self)
{
	return G_STRUCT_MEMBER_P (self, ServicesBackupManager_private_offset);
}

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

ServicesBackupManager*
services_backup_manager_get_default (void)
{
	ServicesBackupManager* _tmp0_;
	ServicesBackupManager* _tmp2_;
	ServicesBackupManager* _tmp3_;
	ServicesBackupManager* result;
	_tmp0_ = services_backup_manager__instance;
	if (_tmp0_ == NULL) {
		ServicesBackupManager* _tmp1_;
		_tmp1_ = services_backup_manager_new ();
		_g_object_unref0 (services_backup_manager__instance);
		services_backup_manager__instance = _tmp1_;
	}
	_tmp2_ = services_backup_manager__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

static void
__lambda358_ (ServicesBackupManager* self)
{
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gboolean _tmp3_;
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp3_ = g_settings_get_boolean (_tmp2_, "backup-automatic");
	_g_object_unref0 (_tmp1_);
	if (_tmp3_) {
		ServicesLogService* _tmp4_;
		ServicesLogService* _tmp5_;
		_tmp4_ = services_log_service_get_default ();
		_tmp5_ = _tmp4_;
		services_log_service_info (_tmp5_, "BackupManager", "Auto backup triggered by day change");
		_g_object_unref0 (_tmp5_);
		services_backup_manager_create_and_distribute_backup (self);
	} else {
		ServicesLogService* _tmp6_;
		ServicesLogService* _tmp7_;
		_tmp6_ = services_log_service_get_default ();
		_tmp7_ = _tmp6_;
		services_log_service_debug (_tmp7_, "BackupManager", "Auto backup skipped — disabled in settings");
		_g_object_unref0 (_tmp7_);
	}
}

static void
___lambda358__services_event_bus_day_changed (ServicesEventBus* _sender,
                                              gpointer self)
{
	__lambda358_ ((ServicesBackupManager*) self);
}

void
services_backup_manager_init_auto_backup (ServicesBackupManager* self)
{
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gboolean _tmp3_;
	ServicesEventBus* _tmp4_;
	ServicesEventBus* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp3_ = g_settings_get_boolean (_tmp2_, "backup-automatic");
	_g_object_unref0 (_tmp1_);
	if (_tmp3_) {
		_services_backup_manager_check_missed_backup (self);
	}
	_tmp4_ = services_event_bus_get_default ();
	_tmp5_ = _tmp4_;
	g_signal_connect_object (_tmp5_, "day-changed", (GCallback) ___lambda358__services_event_bus_day_changed, self, 0);
	_g_object_unref0 (_tmp5_);
}

static void
_services_backup_manager_check_missed_backup (ServicesBackupManager* self)
{
	gchar* last_date_str = NULL;
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GDateTime* today = NULL;
	GDateTime* _tmp5_;
	const gchar* _tmp6_;
	GDateTime* last_date = NULL;
	const gchar* _tmp9_;
	GTimeZone* _tmp10_;
	GTimeZone* _tmp11_;
	GDateTime* _tmp12_;
	GDateTime* _tmp13_;
	GDateTime* _tmp14_;
	gboolean _tmp15_ = FALSE;
	GDateTime* _tmp16_;
	GDateTime* _tmp17_;
	g_return_if_fail (self != NULL);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp3_ = g_settings_get_string (_tmp2_, "backup-last-date");
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp1_);
	last_date_str = _tmp4_;
	_tmp5_ = g_date_time_new_now_local ();
	today = _tmp5_;
	_tmp6_ = last_date_str;
	if (g_strcmp0 (_tmp6_, "") == 0) {
		ServicesLogService* _tmp7_;
		ServicesLogService* _tmp8_;
		_tmp7_ = services_log_service_get_default ();
		_tmp8_ = _tmp7_;
		services_log_service_info (_tmp8_, "BackupManager", "No previous backup found, running initial backup");
		_g_object_unref0 (_tmp8_);
		services_backup_manager_create_and_distribute_backup (self);
		_g_date_time_unref0 (today);
		_g_free0 (last_date_str);
		return;
	}
	_tmp9_ = last_date_str;
	_tmp10_ = g_time_zone_new_local ();
	_tmp11_ = _tmp10_;
	_tmp12_ = g_date_time_new_from_iso8601 (_tmp9_, _tmp11_);
	_tmp13_ = _tmp12_;
	_g_time_zone_unref0 (_tmp11_);
	last_date = _tmp13_;
	_tmp14_ = last_date;
	if (_tmp14_ == NULL) {
		services_backup_manager_create_and_distribute_backup (self);
		_g_date_time_unref0 (last_date);
		_g_date_time_unref0 (today);
		_g_free0 (last_date_str);
		return;
	}
	_tmp16_ = today;
	_tmp17_ = last_date;
	if (g_date_time_get_day_of_year (_tmp16_) != g_date_time_get_day_of_year (_tmp17_)) {
		_tmp15_ = TRUE;
	} else {
		GDateTime* _tmp18_;
		GDateTime* _tmp19_;
		_tmp18_ = today;
		_tmp19_ = last_date;
		_tmp15_ = g_date_time_get_year (_tmp18_) != g_date_time_get_year (_tmp19_);
	}
	if (_tmp15_) {
		ServicesLogService* _tmp20_;
		ServicesLogService* _tmp21_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		_tmp20_ = services_log_service_get_default ();
		_tmp21_ = _tmp20_;
		_tmp22_ = last_date_str;
		_tmp23_ = g_strdup_printf ("Missed backup detected (last: %s), running now", _tmp22_);
		_tmp24_ = _tmp23_;
		services_log_service_info (_tmp21_, "BackupManager", _tmp24_);
		_g_free0 (_tmp24_);
		_g_object_unref0 (_tmp21_);
		services_backup_manager_create_and_distribute_backup (self);
	}
	_g_date_time_unref0 (last_date);
	_g_date_time_unref0 (today);
	_g_free0 (last_date_str);
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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 NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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 NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	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 NULL;
}

GeeArrayList*
services_backup_manager_get_backups_collection (ServicesBackupManager* self)
{
	GeeArrayList* return_value = NULL;
	GeeArrayList* _tmp0_;
	GFile* directory = NULL;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp38_;
	GError* _inner_error0_ = NULL;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gee_array_list_new (OBJECTS_TYPE_BACKUP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	return_value = _tmp0_;
	_tmp1_ = self->priv->path;
	_tmp2_ = g_file_new_for_path (_tmp1_);
	directory = _tmp2_;
	{
		GFileEnumerator* children = NULL;
		GFile* _tmp3_;
		GFileEnumerator* _tmp4_;
		GFileInfo* file_info = NULL;
		GFileEnumerator* _tmp34_;
		GFileEnumerator* _tmp35_;
		_tmp3_ = directory;
		_tmp4_ = g_file_enumerate_children (_tmp3_, "standard::*," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
		children = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		file_info = NULL;
		while (TRUE) {
			GFileInfo* _tmp5_ = NULL;
			GFileEnumerator* _tmp6_;
			GFileInfo* _tmp7_;
			GFileInfo* _tmp8_;
			GFileInfo* _tmp9_;
			GFileInfo* _tmp10_;
			GFileInfo* _tmp11_;
			_tmp6_ = children;
			_tmp7_ = g_file_enumerator_next_file (_tmp6_, NULL, &_inner_error0_);
			_tmp5_ = _tmp7_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (file_info);
				_g_object_unref0 (children);
				goto __catch0_g_error;
			}
			_tmp8_ = _tmp5_;
			_tmp5_ = NULL;
			_g_object_unref0 (file_info);
			file_info = _tmp8_;
			_tmp9_ = file_info;
			if (!(_tmp9_ != NULL)) {
				_g_object_unref0 (_tmp5_);
				break;
			}
			_tmp10_ = file_info;
			if (g_file_info_get_is_hidden (_tmp10_)) {
				_g_object_unref0 (_tmp5_);
				continue;
			}
			_tmp11_ = file_info;
			if (g_file_info_get_is_symlink (_tmp11_)) {
				_g_object_unref0 (_tmp5_);
				continue;
			} else {
				GFileInfo* _tmp12_;
				_tmp12_ = file_info;
				if (g_file_info_get_file_type (_tmp12_) == G_FILE_TYPE_DIRECTORY) {
					_g_object_unref0 (_tmp5_);
					continue;
				} else {
					gchar* mime_type = NULL;
					GFileInfo* _tmp13_;
					const gchar* _tmp14_;
					gchar* _tmp15_;
					gchar* uri = NULL;
					GFile* _tmp16_;
					gchar* _tmp17_;
					gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					GFileInfo* _tmp21_;
					const gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					gchar* _tmp26_;
					const gchar* _tmp27_;
					_tmp13_ = file_info;
					_tmp14_ = g_file_info_get_content_type (_tmp13_);
					_tmp15_ = g_strdup (_tmp14_);
					mime_type = _tmp15_;
					_tmp16_ = directory;
					_tmp17_ = g_file_get_uri (_tmp16_);
					_tmp18_ = _tmp17_;
					_tmp19_ = g_strconcat (_tmp18_, "/", NULL);
					_tmp20_ = _tmp19_;
					_tmp21_ = file_info;
					_tmp22_ = g_file_info_get_name (_tmp21_);
					_tmp23_ = string_replace (_tmp22_, "#", "%23");
					_tmp24_ = _tmp23_;
					_tmp25_ = g_strconcat (_tmp20_, _tmp24_, NULL);
					_tmp26_ = _tmp25_;
					_g_free0 (_tmp24_);
					_g_free0 (_tmp20_);
					_g_free0 (_tmp18_);
					uri = _tmp26_;
					_tmp27_ = mime_type;
					if (services_backup_manager_is_backup_file (_tmp27_)) {
						GFile* file = NULL;
						const gchar* _tmp28_;
						GFile* _tmp29_;
						ObjectsBackup* backup = NULL;
						GFile* _tmp30_;
						ObjectsBackup* _tmp31_;
						GeeArrayList* _tmp32_;
						ObjectsBackup* _tmp33_;
						_tmp28_ = uri;
						_tmp29_ = g_file_new_for_uri (_tmp28_);
						file = _tmp29_;
						_tmp30_ = file;
						_tmp31_ = objects_backup_new_from_file (_tmp30_);
						backup = _tmp31_;
						_tmp32_ = return_value;
						_tmp33_ = backup;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp32_, _tmp33_);
						_g_object_unref0 (backup);
						_g_object_unref0 (file);
					}
					_g_free0 (uri);
					_g_free0 (mime_type);
				}
			}
			_g_object_unref0 (_tmp5_);
		}
		_tmp34_ = children;
		g_file_enumerator_close (_tmp34_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (file_info);
			_g_object_unref0 (children);
			goto __catch0_g_error;
		}
		_tmp35_ = children;
		g_object_run_dispose ((GObject*) _tmp35_);
		_g_object_unref0 (file_info);
		_g_object_unref0 (children);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp36_;
		const gchar* _tmp37_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp36_ = err;
		_tmp37_ = _tmp36_->message;
		g_warning ("BackupManager.vala:129: %s\n", _tmp37_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (directory);
		_g_object_unref0 (return_value);
		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 NULL;
	}
	_tmp38_ = directory;
	g_object_run_dispose ((GObject*) _tmp38_);
	result = return_value;
	_g_object_unref0 (directory);
	return result;
}

gboolean
services_backup_manager_is_backup_file (const gchar* mime_type)
{
	gboolean result;
	g_return_val_if_fail (mime_type != NULL, FALSE);
	result = g_strcmp0 (mime_type, "application/json") == 0;
	return result;
}

gchar*
services_backup_manager_export_to_json (ServicesBackupManager* self)
{
	ServicesBackupExporter* _tmp0_;
	ServicesBackupExporter* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = services_backup_exporter_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = services_backup_exporter_export_to_json (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}

static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

void
services_backup_manager_create_and_distribute_backup (ServicesBackupManager* self)
{
	GFile* backup_file = NULL;
	GFile* _tmp0_;
	GFile* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = services_backup_manager_create_backup (self);
	backup_file = _tmp0_;
	_tmp1_ = backup_file;
	if (_tmp1_ != NULL) {
		ServicesLogService* _tmp2_;
		ServicesLogService* _tmp3_;
		GFile* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		ServicesSettings* _tmp9_;
		ServicesSettings* _tmp10_;
		GSettings* _tmp11_;
		GDateTime* _tmp12_;
		GDateTime* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		GFile* _tmp16_;
		_tmp2_ = services_log_service_get_default ();
		_tmp3_ = _tmp2_;
		_tmp4_ = backup_file;
		_tmp5_ = g_file_get_path (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strdup_printf ("Backup created: %s", _tmp6_);
		_tmp8_ = _tmp7_;
		services_log_service_info (_tmp3_, "BackupManager", _tmp8_);
		_g_free0 (_tmp8_);
		_g_free0 (_tmp6_);
		_g_object_unref0 (_tmp3_);
		_tmp9_ = services_settings_get_default ();
		_tmp10_ = _tmp9_;
		_tmp11_ = _tmp10_->settings;
		_tmp12_ = g_date_time_new_now_local ();
		_tmp13_ = _tmp12_;
		_tmp14_ = g_date_time_to_string (_tmp13_);
		_tmp15_ = _tmp14_;
		g_settings_set_string (_tmp11_, "backup-last-date", _tmp15_);
		_g_free0 (_tmp15_);
		_g_date_time_unref0 (_tmp13_);
		_g_object_unref0 (_tmp10_);
		_tmp16_ = backup_file;
		services_backup_manager_copy_to_extra_folders (self, _tmp16_);
	} else {
		ServicesLogService* _tmp17_;
		ServicesLogService* _tmp18_;
		AdwToast* toast = NULL;
		AdwToast* _tmp19_ = NULL;
		ServicesEventBus* _tmp20_;
		ServicesEventBus* _tmp21_;
		AdwToast* _tmp22_;
		_tmp17_ = services_log_service_get_default ();
		_tmp18_ = _tmp17_;
		services_log_service_warn (_tmp18_, "BackupManager", "Backup failed — create_backup returned null");
		_g_object_unref0 (_tmp18_);
		_tmp19_ = adw_toast_new (_ ("Automatic backup failed"));
		adw_toast_set_priority (_tmp19_, ADW_TOAST_PRIORITY_HIGH);
		toast = _tmp19_;
		_tmp20_ = services_event_bus_get_default ();
		_tmp21_ = _tmp20_;
		_tmp22_ = toast;
		g_signal_emit_by_name (_tmp21_, "send-toast", _tmp22_);
		_g_object_unref0 (_tmp21_);
		_g_object_unref0 (toast);
	}
	_g_object_unref0 (backup_file);
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

GFile*
services_backup_manager_create_backup (ServicesBackupManager* self)
{
	GDateTime* datetime = NULL;
	GDateTime* _tmp0_;
	gchar* file_name = NULL;
	GDateTime* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* file_path = NULL;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GFile* file = NULL;
	const gchar* _tmp12_;
	GFile* _tmp13_;
	GError* _inner_error0_ = NULL;
	GFile* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_new_now_local ();
	datetime = _tmp0_;
	_tmp1_ = datetime;
	_tmp2_ = g_date_time_format (_tmp1_, "%c");
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf ("Planify backup %s.json", _tmp3_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	file_name = _tmp5_;
	_tmp6_ = self->priv->path;
	_tmp7_ = g_strconcat (_tmp6_, "/", NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = file_name;
	_tmp10_ = g_strconcat (_tmp8_, _tmp9_, NULL);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp8_);
	file_path = _tmp11_;
	_tmp12_ = file_path;
	_tmp13_ = g_file_new_for_path (_tmp12_);
	file = _tmp13_;
	{
		GFileOutputStream* stream = NULL;
		GFile* _tmp14_;
		GFileOutputStream* _tmp15_;
		GFileOutputStream* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		guint8* _tmp19_;
		gint _tmp19__length1;
		gint _tmp20_ = 0;
		guint8* _tmp21_;
		gint _tmp21__length1;
		GFileOutputStream* _tmp22_;
		GFile* _tmp23_;
		_tmp14_ = file;
		_tmp15_ = g_file_create (_tmp14_, G_FILE_CREATE_NONE, NULL, &_inner_error0_);
		stream = _tmp15_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp16_ = stream;
		_tmp17_ = services_backup_manager_export_to_json (self);
		_tmp18_ = _tmp17_;
		_tmp19_ = string_get_data (_tmp18_, &_tmp20_);
		_tmp19__length1 = _tmp20_;
		_tmp21_ = _tmp19_;
		_tmp21__length1 = _tmp19__length1;
		g_output_stream_write ((GOutputStream*) _tmp16_, _tmp21_, (gsize) _tmp21__length1, NULL, &_inner_error0_);
		_g_free0 (_tmp18_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (stream);
			goto __catch0_g_error;
		}
		_tmp22_ = stream;
		g_output_stream_close ((GOutputStream*) _tmp22_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (stream);
			goto __catch0_g_error;
		}
		_tmp23_ = file;
		if (g_file_query_exists (_tmp23_, NULL)) {
			ObjectsBackup* backup = NULL;
			GFile* _tmp24_;
			ObjectsBackup* _tmp25_;
			ObjectsBackup* _tmp26_;
			GeeArrayList* _tmp27_;
			ObjectsBackup* _tmp28_;
			_tmp24_ = file;
			_tmp25_ = objects_backup_new_from_file (_tmp24_);
			backup = _tmp25_;
			_tmp26_ = backup;
			g_signal_emit (self, services_backup_manager_signals[SERVICES_BACKUP_MANAGER_BACKUP_ADDED_SIGNAL], 0, _tmp26_);
			_tmp27_ = self->priv->_backups;
			_tmp28_ = backup;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp27_, _tmp28_);
			result = file;
			_g_object_unref0 (backup);
			_g_object_unref0 (stream);
			_g_free0 (file_path);
			_g_free0 (file_name);
			_g_date_time_unref0 (datetime);
			return result;
		}
		_g_object_unref0 (stream);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp29_;
		const gchar* _tmp30_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp29_ = e;
		_tmp30_ = _tmp29_->message;
		g_debug ("BackupManager.vala:179: Error: %s\n", _tmp30_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (file);
		_g_free0 (file_path);
		_g_free0 (file_name);
		_g_date_time_unref0 (datetime);
		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 NULL;
	}
	result = NULL;
	_g_object_unref0 (file);
	_g_free0 (file_path);
	_g_free0 (file_name);
	_g_date_time_unref0 (datetime);
	return result;
}

static void
services_backup_manager_copy_to_extra_folders (ServicesBackupManager* self,
                                               GFile* source_file)
{
	gchar** extra_folders = NULL;
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	gchar** _tmp5_;
	gint _tmp5__length1;
	gint extra_folders_length1;
	gint _extra_folders_size_;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar** _tmp9_;
	gint _tmp9__length1;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source_file != NULL);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp4_ = _tmp3_ = g_settings_get_strv (_tmp2_, "backup-extra-folders");
	_tmp5_ = _tmp4_;
	_tmp5__length1 = _vala_array_length (_tmp3_);
	_g_object_unref0 (_tmp1_);
	extra_folders = _tmp5_;
	extra_folders_length1 = _tmp5__length1;
	_extra_folders_size_ = extra_folders_length1;
	_tmp6_ = extra_folders;
	_tmp6__length1 = extra_folders_length1;
	if (_tmp6__length1 == 0) {
		ServicesLogService* _tmp7_;
		ServicesLogService* _tmp8_;
		_tmp7_ = services_log_service_get_default ();
		_tmp8_ = _tmp7_;
		services_log_service_debug (_tmp8_, "BackupManager", "No extra folders configured, skipping copy");
		_g_object_unref0 (_tmp8_);
		extra_folders = (_vala_array_free (extra_folders, extra_folders_length1, (GDestroyNotify) g_free), NULL);
		return;
	}
	_tmp9_ = extra_folders;
	_tmp9__length1 = extra_folders_length1;
	{
		gchar** folder_path_collection = NULL;
		gint folder_path_collection_length1 = 0;
		gint _folder_path_collection_size_ = 0;
		gint folder_path_it = 0;
		folder_path_collection = _tmp9_;
		folder_path_collection_length1 = _tmp9__length1;
		for (folder_path_it = 0; folder_path_it < folder_path_collection_length1; folder_path_it = folder_path_it + 1) {
			gchar* _tmp10_;
			gchar* folder_path = NULL;
			_tmp10_ = g_strdup (folder_path_collection[folder_path_it]);
			folder_path = _tmp10_;
			{
				GFile* dest = NULL;
				const gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				gchar* _tmp17_;
				GFile* _tmp18_;
				GFile* _tmp19_;
				_tmp11_ = folder_path;
				_tmp12_ = g_strconcat (_tmp11_, "/", NULL);
				_tmp13_ = _tmp12_;
				_tmp14_ = g_file_get_basename (source_file);
				_tmp15_ = _tmp14_;
				_tmp16_ = g_strconcat (_tmp13_, _tmp15_, NULL);
				_tmp17_ = _tmp16_;
				_tmp18_ = g_file_new_for_path (_tmp17_);
				_tmp19_ = _tmp18_;
				_g_free0 (_tmp17_);
				_g_free0 (_tmp15_);
				_g_free0 (_tmp13_);
				dest = _tmp19_;
				{
					GFile* _tmp20_;
					ServicesLogService* _tmp21_;
					ServicesLogService* _tmp22_;
					const gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					_tmp20_ = dest;
					g_file_copy (source_file, _tmp20_, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch0_g_error;
					}
					_tmp21_ = services_log_service_get_default ();
					_tmp22_ = _tmp21_;
					_tmp23_ = folder_path;
					_tmp24_ = g_strdup_printf ("Backup copied to: %s", _tmp23_);
					_tmp25_ = _tmp24_;
					services_log_service_info (_tmp22_, "BackupManager", _tmp25_);
					_g_free0 (_tmp25_);
					_g_object_unref0 (_tmp22_);
				}
				goto __finally0;
				__catch0_g_error:
				{
					GError* e = NULL;
					ServicesLogService* _tmp26_;
					ServicesLogService* _tmp27_;
					const gchar* _tmp28_;
					GError* _tmp29_;
					const gchar* _tmp30_;
					gchar* _tmp31_;
					gchar* _tmp32_;
					AdwToast* toast = NULL;
					const gchar* _tmp33_;
					gchar* _tmp34_;
					gchar* _tmp35_;
					AdwToast* _tmp36_ = NULL;
					AdwToast* _tmp37_;
					ServicesEventBus* _tmp38_;
					ServicesEventBus* _tmp39_;
					AdwToast* _tmp40_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp26_ = services_log_service_get_default ();
					_tmp27_ = _tmp26_;
					_tmp28_ = folder_path;
					_tmp29_ = e;
					_tmp30_ = _tmp29_->message;
					_tmp31_ = g_strdup_printf ("Failed to copy backup to %s: %s", _tmp28_, _tmp30_);
					_tmp32_ = _tmp31_;
					services_log_service_warn (_tmp27_, "BackupManager", _tmp32_);
					_g_free0 (_tmp32_);
					_g_object_unref0 (_tmp27_);
					_tmp33_ = folder_path;
					_tmp34_ = g_strdup_printf (_ ("Failed to copy backup to %s"), _tmp33_);
					_tmp35_ = _tmp34_;
					_tmp36_ = adw_toast_new (_tmp35_);
					adw_toast_set_priority (_tmp36_, ADW_TOAST_PRIORITY_HIGH);
					_tmp37_ = _tmp36_;
					_g_free0 (_tmp35_);
					toast = _tmp37_;
					_tmp38_ = services_event_bus_get_default ();
					_tmp39_ = _tmp38_;
					_tmp40_ = toast;
					g_signal_emit_by_name (_tmp39_, "send-toast", _tmp40_);
					_g_object_unref0 (_tmp39_);
					_g_object_unref0 (toast);
					_g_error_free0 (e);
				}
				__finally0:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (dest);
					_g_free0 (folder_path);
					extra_folders = (_vala_array_free (extra_folders, extra_folders_length1, (GDestroyNotify) g_free), 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_unref0 (dest);
				_g_free0 (folder_path);
			}
		}
	}
	extra_folders = (_vala_array_free (extra_folders, extra_folders_length1, (GDestroyNotify) g_free), NULL);
}

void
services_backup_manager_add_extra_folder (ServicesBackupManager* self,
                                          const gchar* folder_path)
{
	GeeArrayList* folders = NULL;
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	GeeArrayList* _tmp5_;
	GeeArrayList* _tmp6_;
	GeeArrayList* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (folder_path != NULL);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp4_ = _tmp3_ = g_settings_get_strv (_tmp2_, "backup-extra-folders");
	_tmp5_ = gee_array_list_new_wrap (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp4_, _vala_array_length (_tmp3_), NULL, NULL, NULL);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp1_);
	folders = _tmp6_;
	_tmp7_ = folders;
	if (!gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp7_, folder_path)) {
		GeeArrayList* _tmp8_;
		ServicesSettings* _tmp9_;
		ServicesSettings* _tmp10_;
		GSettings* _tmp11_;
		GeeArrayList* _tmp12_;
		gint _tmp13_ = 0;
		gpointer* _tmp14_;
		gchar** _tmp15_;
		gint _tmp15__length1;
		_tmp8_ = folders;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp8_, folder_path);
		_tmp9_ = services_settings_get_default ();
		_tmp10_ = _tmp9_;
		_tmp11_ = _tmp10_->settings;
		_tmp12_ = folders;
		_tmp14_ = gee_collection_to_array ((GeeCollection*) _tmp12_, &_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp15__length1 = _tmp13_;
		g_settings_set_strv (_tmp11_, "backup-extra-folders", _tmp15_);
		_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL);
		_g_object_unref0 (_tmp10_);
	}
	_g_object_unref0 (folders);
}

void
services_backup_manager_remove_extra_folder (ServicesBackupManager* self,
                                             const gchar* folder_path)
{
	GeeArrayList* folders = NULL;
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	GeeArrayList* _tmp5_;
	GeeArrayList* _tmp6_;
	ServicesSettings* _tmp7_;
	ServicesSettings* _tmp8_;
	GSettings* _tmp9_;
	gint _tmp10_ = 0;
	gpointer* _tmp11_;
	gchar** _tmp12_;
	gint _tmp12__length1;
	g_return_if_fail (self != NULL);
	g_return_if_fail (folder_path != NULL);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->settings;
	_tmp4_ = _tmp3_ = g_settings_get_strv (_tmp2_, "backup-extra-folders");
	_tmp5_ = gee_array_list_new_wrap (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp4_, _vala_array_length (_tmp3_), NULL, NULL, NULL);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp1_);
	folders = _tmp6_;
	gee_abstract_collection_remove ((GeeAbstractCollection*) folders, folder_path);
	_tmp7_ = services_settings_get_default ();
	_tmp8_ = _tmp7_;
	_tmp9_ = _tmp8_->settings;
	_tmp11_ = gee_collection_to_array ((GeeCollection*) folders, &_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp12__length1 = _tmp10_;
	g_settings_set_strv (_tmp9_, "backup-extra-folders", _tmp12_);
	_tmp12_ = (_vala_array_free (_tmp12_, _tmp12__length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (_tmp8_);
	_g_object_unref0 (folders);
}

static Block15Data*
block15_data_ref (Block15Data* _data15_)
{
	g_atomic_int_inc (&_data15_->_ref_count_);
	return _data15_;
}

static void
block15_data_unref (void * _userdata_)
{
	Block15Data* _data15_;
	_data15_ = (Block15Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data15_->_ref_count_)) {
		ServicesBackupManager* self;
		self = _data15_->self;
		_g_object_unref0 (_data15_->backup);
		_g_object_unref0 (self);
		g_slice_free (Block15Data, _data15_);
	}
}

static void
__lambda359_ (Block15Data* _data15_,
              const gchar* response)
{
	ServicesBackupManager* self;
	GError* _inner_error0_ = NULL;
	self = _data15_->self;
	g_return_if_fail (response != NULL);
	if (g_strcmp0 (response, "delete") == 0) {
		GFile* db_file = NULL;
		const gchar* _tmp0_;
		const gchar* _tmp1_;
		GFile* _tmp2_;
		GFile* _tmp3_;
		_tmp0_ = objects_backup_get_path (_data15_->backup);
		_tmp1_ = _tmp0_;
		_tmp2_ = g_file_new_for_path (_tmp1_);
		db_file = _tmp2_;
		_tmp3_ = db_file;
		if (g_file_query_exists (_tmp3_, NULL)) {
			{
				gboolean _tmp4_ = FALSE;
				GFile* _tmp5_;
				_tmp5_ = db_file;
				_tmp4_ = g_file_delete (_tmp5_, NULL, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				if (_tmp4_) {
					GeeArrayList* _tmp6_;
					g_signal_emit_by_name (_data15_->backup, "deleted");
					_tmp6_ = self->priv->_backups;
					gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp6_, _data15_->backup);
				}
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* err = NULL;
				GError* _tmp7_;
				const gchar* _tmp8_;
				err = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp7_ = err;
				_tmp8_ = _tmp7_->message;
				g_warning ("BackupManager.vala:242: %s", _tmp8_);
				_g_error_free0 (err);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (db_file);
				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_unref0 (db_file);
	}
}

static void
___lambda359__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                         const gchar* response,
                                         gpointer self)
{
	__lambda359_ (self, response);
}

void
services_backup_manager_delete_backup (ServicesBackupManager* self,
                                       ObjectsBackup* backup)
{
	Block15Data* _data15_;
	ObjectsBackup* _tmp0_;
	AdwAlertDialog* dialog = NULL;
	AdwAlertDialog* _tmp1_;
	Planify* _tmp2_;
	Planify* _tmp3_;
	MainWindow* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (backup != NULL);
	_data15_ = g_slice_new0 (Block15Data);
	_data15_->_ref_count_ = 1;
	_data15_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (backup);
	_g_object_unref0 (_data15_->backup);
	_data15_->backup = _tmp0_;
	_tmp1_ = (AdwAlertDialog*) adw_alert_dialog_new (_ ("Delete Backup"), _ ("This can not be undone"));
	g_object_ref_sink (_tmp1_);
	dialog = _tmp1_;
	adw_alert_dialog_add_response (dialog, "cancel", _ ("Cancel"));
	adw_alert_dialog_add_response (dialog, "delete", _ ("Delete"));
	adw_alert_dialog_set_response_appearance (dialog, "delete", ADW_RESPONSE_DESTRUCTIVE);
	_tmp2_ = planify_get_instance ();
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_->main_window;
	adw_dialog_present ((AdwDialog*) dialog, (GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_window_get_type (), GtkWindow));
	g_signal_connect_data (dialog, "response", (GCallback) ___lambda359__adw_alert_dialog_response, block15_data_ref (_data15_), (GClosureNotify) block15_data_unref, 0);
	_g_object_unref0 (dialog);
	block15_data_unref (_data15_);
	_data15_ = NULL;
}

static Block16Data*
block16_data_ref (Block16Data* _data16_)
{
	g_atomic_int_inc (&_data16_->_ref_count_);
	return _data16_;
}

static void
block16_data_unref (void * _userdata_)
{
	Block16Data* _data16_;
	_data16_ = (Block16Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data16_->_ref_count_)) {
		ServicesBackupManager* self;
		self = _data16_->self;
		_g_object_unref0 (_data16_->dialog);
		_g_object_unref0 (_data16_->backup);
		_g_object_unref0 (self);
		g_slice_free (Block16Data, _data16_);
	}
}

static void
__lambda360_ (Block16Data* _data16_,
              GObject* obj,
              GAsyncResult* res)
{
	ServicesBackupManager* self;
	GError* _inner_error0_ = NULL;
	self = _data16_->self;
	g_return_if_fail (res != NULL);
	{
		GFile* file = NULL;
		GFile* _tmp0_;
		GFile* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gboolean _tmp6_;
		GFile* source_file = NULL;
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		GFile* _tmp15_;
		GFile* _tmp16_;
		_tmp0_ = gtk_file_dialog_save_finish (_data16_->dialog, res, &_inner_error0_);
		file = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = file;
		_tmp2_ = g_file_get_basename (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_utf8_strdown (_tmp3_, (gssize) -1);
		_tmp5_ = _tmp4_;
		_tmp6_ = !g_str_has_suffix (_tmp5_, ".json");
		_g_free0 (_tmp5_);
		_g_free0 (_tmp3_);
		if (_tmp6_) {
			GFile* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			GFile* _tmp12_;
			_tmp7_ = file;
			_tmp8_ = g_file_get_path (_tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = g_strconcat (_tmp9_, ".json", NULL);
			_tmp11_ = _tmp10_;
			_tmp12_ = g_file_new_for_path (_tmp11_);
			_g_object_unref0 (file);
			file = _tmp12_;
			_g_free0 (_tmp11_);
			_g_free0 (_tmp9_);
		}
		_tmp13_ = objects_backup_get_path (_data16_->backup);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_file_new_for_path (_tmp14_);
		source_file = _tmp15_;
		_tmp16_ = source_file;
		if (g_file_query_exists (_tmp16_, NULL)) {
			GFile* _tmp17_;
			GFile* _tmp18_;
			_tmp17_ = source_file;
			_tmp18_ = file;
			g_file_copy (_tmp17_, _tmp18_, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (source_file);
				_g_object_unref0 (file);
				goto __catch0_g_error;
			}
		} else {
			g_debug ("BackupManager.vala:266: Error during save backup");
		}
		_g_object_unref0 (source_file);
		_g_object_unref0 (file);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp19_;
		const gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp19_ = e;
		_tmp20_ = _tmp19_->message;
		_tmp21_ = g_strdup_printf ("Error during save backup: %s", _tmp20_);
		_tmp22_ = _tmp21_;
		g_debug ("BackupManager.vala:269: %s", _tmp22_);
		_g_free0 (_tmp22_);
		_g_error_free0 (e);
	}
	__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;
	}
}

static void
___lambda360__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	__lambda360_ (self, source_object, res);
	block16_data_unref (self);
}

void
services_backup_manager_save_file_as (ServicesBackupManager* self,
                                      ObjectsBackup* backup)
{
	Block16Data* _data16_;
	ObjectsBackup* _tmp0_;
	GtkFileDialog* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	Planify* _tmp6_;
	MainWindow* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (backup != NULL);
	_data16_ = g_slice_new0 (Block16Data);
	_data16_->_ref_count_ = 1;
	_data16_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (backup);
	_g_object_unref0 (_data16_->backup);
	_data16_->backup = _tmp0_;
	_tmp1_ = gtk_file_dialog_new ();
	_data16_->dialog = _tmp1_;
	_tmp2_ = objects_backup_get_title (_data16_->backup);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf ("Planify backup %s.json", _tmp3_);
	_tmp5_ = _tmp4_;
	gtk_file_dialog_set_initial_name (_data16_->dialog, _tmp5_);
	_g_free0 (_tmp5_);
	services_backup_manager_add_filters (self, _data16_->dialog);
	_tmp6_ = planify__instance;
	_tmp7_ = _tmp6_->main_window;
	gtk_file_dialog_save (_data16_->dialog, (GtkWindow*) _tmp7_, NULL, ___lambda360__gasync_ready_callback, block16_data_ref (_data16_));
	block16_data_unref (_data16_);
	_data16_ = NULL;
}

static void
services_backup_manager_choose_backup_file_data_free (gpointer _data)
{
	ServicesBackupManagerChooseBackupFileData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesBackupManagerChooseBackupFileData, _data_);
}

void
services_backup_manager_choose_backup_file (ServicesBackupManager* self,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	ServicesBackupManagerChooseBackupFileData* _data_;
	ServicesBackupManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ServicesBackupManagerChooseBackupFileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_backup_manager_choose_backup_file_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	services_backup_manager_choose_backup_file_co (_data_);
}

GFile*
services_backup_manager_choose_backup_file_finish (ServicesBackupManager* self,
                                                   GAsyncResult* _res_)
{
	GFile* result;
	ServicesBackupManagerChooseBackupFileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
services_backup_manager_choose_backup_file_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	ServicesBackupManagerChooseBackupFileData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_backup_manager_choose_backup_file_co (_data_);
}

static gboolean
services_backup_manager_choose_backup_file_co (ServicesBackupManagerChooseBackupFileData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gtk_file_dialog_new ();
	_data_->dialog = _data_->_tmp0_;
	services_backup_manager_add_filters (_data_->self, _data_->dialog);
	{
		_data_->_tmp1_ = planify__instance;
		_data_->_tmp2_ = _data_->_tmp1_->main_window;
		_data_->_state_ = 1;
		gtk_file_dialog_open (_data_->dialog, (GtkWindow*) _data_->_tmp2_, NULL, services_backup_manager_choose_backup_file_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = gtk_file_dialog_open_finish (_data_->dialog, _data_->_res_, &_data_->_inner_error0_);
		_data_->file = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->result = _data_->file;
		_g_object_unref0 (_data_->dialog);
		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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp4_ = _data_->e;
		_data_->_tmp5_ = _data_->_tmp4_->message;
		_data_->_tmp6_ = g_strdup_printf ("Error during import backup: %s", _data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		g_debug ("BackupManager.vala:283: %s", _data_->_tmp7_);
		_g_free0 (_data_->_tmp7_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->dialog);
		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_->result = NULL;
	_g_object_unref0 (_data_->dialog);
	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;
}

void
services_backup_manager_patch_backup (ServicesBackupManager* self,
                                      ObjectsBackup* backup)
{
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	ServicesSettings* _tmp2_;
	ServicesSettings* _tmp3_;
	GSettings* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	ServicesDatabase* _tmp7_;
	ServicesDatabase* _tmp8_;
	ServicesDatabase* _tmp9_;
	ServicesDatabase* _tmp10_;
	Util* _tmp11_;
	Util* _tmp12_;
	ObjectsSource* _tmp13_;
	ObjectsSource* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (backup != NULL);
	_tmp0_ = services_settings_get_default ();
	_tmp1_ = _tmp0_;
	services_settings_reset_settings (_tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = services_settings_get_default ();
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_->settings;
	_tmp5_ = objects_backup_get_local_inbox_project_id (backup);
	_tmp6_ = _tmp5_;
	g_settings_set_string (_tmp4_, "local-inbox-project-id", _tmp6_);
	_g_object_unref0 (_tmp3_);
	_tmp7_ = services_database_get_default ();
	_tmp8_ = _tmp7_;
	services_database_clear_database (_tmp8_);
	_g_object_unref0 (_tmp8_);
	_tmp9_ = services_database_get_default ();
	_tmp10_ = _tmp9_;
	services_database_init_database (_tmp10_);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = util_get_default ();
	_tmp12_ = _tmp11_;
	_tmp13_ = util_create_local_source (_tmp12_);
	_tmp14_ = _tmp13_;
	_g_object_unref0 (_tmp14_);
	_g_object_unref0 (_tmp12_);
	{
		GeeArrayList* _source_list = NULL;
		GeeArrayList* _tmp15_;
		GeeArrayList* _tmp16_;
		gint _source_size = 0;
		GeeArrayList* _tmp17_;
		gint _tmp18_;
		gint _tmp19_;
		gint _source_index = 0;
		_tmp15_ = objects_backup_get_sources (backup);
		_tmp16_ = _tmp15_;
		_source_list = _tmp16_;
		_tmp17_ = _source_list;
		_tmp18_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp17_);
		_tmp19_ = _tmp18_;
		_source_size = _tmp19_;
		_source_index = -1;
		while (TRUE) {
			gint _tmp20_;
			gint _tmp21_;
			ObjectsSource* source = NULL;
			GeeArrayList* _tmp22_;
			gpointer _tmp23_;
			ServicesStore* _tmp24_;
			ObjectsSource* _tmp25_;
			_source_index = _source_index + 1;
			_tmp20_ = _source_index;
			_tmp21_ = _source_size;
			if (!(_tmp20_ < _tmp21_)) {
				break;
			}
			_tmp22_ = _source_list;
			_tmp23_ = gee_abstract_list_get ((GeeAbstractList*) _tmp22_, _source_index);
			source = (ObjectsSource*) _tmp23_;
			_tmp24_ = services_store_instance ();
			_tmp25_ = source;
			services_store_insert_source (_tmp24_, _tmp25_);
			_g_object_unref0 (source);
		}
	}
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp26_;
		GeeArrayList* _tmp27_;
		gint _item_size = 0;
		GeeArrayList* _tmp28_;
		gint _tmp29_;
		gint _tmp30_;
		gint _item_index = 0;
		_tmp26_ = objects_backup_get_labels (backup);
		_tmp27_ = _tmp26_;
		_item_list = _tmp27_;
		_tmp28_ = _item_list;
		_tmp29_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp28_);
		_tmp30_ = _tmp29_;
		_item_size = _tmp30_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp31_;
			gint _tmp32_;
			ObjectsLabel* item = NULL;
			GeeArrayList* _tmp33_;
			gpointer _tmp34_;
			ServicesStore* _tmp35_;
			ObjectsLabel* _tmp36_;
			_item_index = _item_index + 1;
			_tmp31_ = _item_index;
			_tmp32_ = _item_size;
			if (!(_tmp31_ < _tmp32_)) {
				break;
			}
			_tmp33_ = _item_list;
			_tmp34_ = gee_abstract_list_get ((GeeAbstractList*) _tmp33_, _item_index);
			item = (ObjectsLabel*) _tmp34_;
			_tmp35_ = services_store_instance ();
			_tmp36_ = item;
			services_store_insert_label (_tmp35_, _tmp36_);
			_g_object_unref0 (item);
		}
	}
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp37_;
		GeeArrayList* _tmp38_;
		gint _item_size = 0;
		GeeArrayList* _tmp39_;
		gint _tmp40_;
		gint _tmp41_;
		gint _item_index = 0;
		_tmp37_ = objects_backup_get_projects (backup);
		_tmp38_ = _tmp37_;
		_item_list = _tmp38_;
		_tmp39_ = _item_list;
		_tmp40_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp39_);
		_tmp41_ = _tmp40_;
		_item_size = _tmp41_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp42_;
			gint _tmp43_;
			ObjectsProject* item = NULL;
			GeeArrayList* _tmp44_;
			gpointer _tmp45_;
			ObjectsProject* _tmp46_;
			const gchar* _tmp47_;
			const gchar* _tmp48_;
			_item_index = _item_index + 1;
			_tmp42_ = _item_index;
			_tmp43_ = _item_size;
			if (!(_tmp42_ < _tmp43_)) {
				break;
			}
			_tmp44_ = _item_list;
			_tmp45_ = gee_abstract_list_get ((GeeAbstractList*) _tmp44_, _item_index);
			item = (ObjectsProject*) _tmp45_;
			_tmp46_ = item;
			_tmp47_ = objects_project_get_parent_id (_tmp46_);
			_tmp48_ = _tmp47_;
			if (g_strcmp0 (_tmp48_, "") != 0) {
				ObjectsProject* project = NULL;
				ServicesStore* _tmp49_;
				ObjectsProject* _tmp50_;
				const gchar* _tmp51_;
				const gchar* _tmp52_;
				ObjectsProject* _tmp53_;
				ObjectsProject* _tmp54_;
				_tmp49_ = services_store_instance ();
				_tmp50_ = item;
				_tmp51_ = objects_project_get_parent_id (_tmp50_);
				_tmp52_ = _tmp51_;
				_tmp53_ = services_store_get_project (_tmp49_, _tmp52_);
				project = _tmp53_;
				_tmp54_ = project;
				if (_tmp54_ != NULL) {
					ObjectsProject* _tmp55_;
					ObjectsProject* _tmp56_;
					ObjectsProject* _tmp57_;
					ObjectsProject* _tmp58_;
					_tmp55_ = project;
					_tmp56_ = item;
					_tmp57_ = objects_project_add_subproject_if_not_exists (_tmp55_, _tmp56_);
					_tmp58_ = _tmp57_;
					_g_object_unref0 (_tmp58_);
				}
				_g_object_unref0 (project);
			} else {
				ServicesStore* _tmp59_;
				ObjectsProject* _tmp60_;
				_tmp59_ = services_store_instance ();
				_tmp60_ = item;
				services_store_insert_project (_tmp59_, _tmp60_);
			}
			_g_object_unref0 (item);
		}
	}
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp61_;
		GeeArrayList* _tmp62_;
		gint _item_size = 0;
		GeeArrayList* _tmp63_;
		gint _tmp64_;
		gint _tmp65_;
		gint _item_index = 0;
		_tmp61_ = objects_backup_get_sections (backup);
		_tmp62_ = _tmp61_;
		_item_list = _tmp62_;
		_tmp63_ = _item_list;
		_tmp64_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp63_);
		_tmp65_ = _tmp64_;
		_item_size = _tmp65_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp66_;
			gint _tmp67_;
			ObjectsSection* item = NULL;
			GeeArrayList* _tmp68_;
			gpointer _tmp69_;
			ObjectsProject* project = NULL;
			ServicesStore* _tmp70_;
			ObjectsSection* _tmp71_;
			const gchar* _tmp72_;
			const gchar* _tmp73_;
			ObjectsProject* _tmp74_;
			ObjectsProject* _tmp75_;
			_item_index = _item_index + 1;
			_tmp66_ = _item_index;
			_tmp67_ = _item_size;
			if (!(_tmp66_ < _tmp67_)) {
				break;
			}
			_tmp68_ = _item_list;
			_tmp69_ = gee_abstract_list_get ((GeeAbstractList*) _tmp68_, _item_index);
			item = (ObjectsSection*) _tmp69_;
			_tmp70_ = services_store_instance ();
			_tmp71_ = item;
			_tmp72_ = objects_section_get_project_id (_tmp71_);
			_tmp73_ = _tmp72_;
			_tmp74_ = services_store_get_project (_tmp70_, _tmp73_);
			project = _tmp74_;
			_tmp75_ = project;
			if (_tmp75_ != NULL) {
				ObjectsProject* _tmp76_;
				ObjectsSection* _tmp77_;
				ObjectsSection* _tmp78_;
				ObjectsSection* _tmp79_;
				_tmp76_ = project;
				_tmp77_ = item;
				_tmp78_ = objects_project_add_section_if_not_exists (_tmp76_, _tmp77_);
				_tmp79_ = _tmp78_;
				_g_object_unref0 (_tmp79_);
			}
			_g_object_unref0 (project);
			_g_object_unref0 (item);
		}
	}
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp80_;
		GeeArrayList* _tmp81_;
		gint _item_size = 0;
		GeeArrayList* _tmp82_;
		gint _tmp83_;
		gint _tmp84_;
		gint _item_index = 0;
		_tmp80_ = objects_backup_get_items (backup);
		_tmp81_ = _tmp80_;
		_item_list = _tmp81_;
		_tmp82_ = _item_list;
		_tmp83_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp82_);
		_tmp84_ = _tmp83_;
		_item_size = _tmp84_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp85_;
			gint _tmp86_;
			ObjectsItem* item = NULL;
			GeeArrayList* _tmp87_;
			gpointer _tmp88_;
			ObjectsItem* _tmp89_;
			gboolean _tmp90_;
			gboolean _tmp91_;
			_item_index = _item_index + 1;
			_tmp85_ = _item_index;
			_tmp86_ = _item_size;
			if (!(_tmp85_ < _tmp86_)) {
				break;
			}
			_tmp87_ = _item_list;
			_tmp88_ = gee_abstract_list_get ((GeeAbstractList*) _tmp87_, _item_index);
			item = (ObjectsItem*) _tmp88_;
			_tmp89_ = item;
			_tmp90_ = objects_item_get_has_parent (_tmp89_);
			_tmp91_ = _tmp90_;
			if (_tmp91_) {
				ObjectsItem* _item = NULL;
				ServicesStore* _tmp92_;
				ObjectsItem* _tmp93_;
				const gchar* _tmp94_;
				const gchar* _tmp95_;
				ObjectsItem* _tmp96_;
				ObjectsItem* _tmp97_;
				_tmp92_ = services_store_instance ();
				_tmp93_ = item;
				_tmp94_ = objects_item_get_parent_id (_tmp93_);
				_tmp95_ = _tmp94_;
				_tmp96_ = services_store_get_item (_tmp92_, _tmp95_);
				_item = _tmp96_;
				_tmp97_ = _item;
				if (_tmp97_ != NULL) {
					ObjectsItem* _tmp98_;
					ObjectsItem* _tmp99_;
					ObjectsItem* _tmp100_;
					ObjectsItem* _tmp101_;
					_tmp98_ = _item;
					_tmp99_ = item;
					_tmp100_ = objects_item_add_item_if_not_exists (_tmp98_, _tmp99_, TRUE);
					_tmp101_ = _tmp100_;
					_g_object_unref0 (_tmp101_);
				}
				_g_object_unref0 (_item);
			} else {
				ObjectsItem* _tmp102_;
				const gchar* _tmp103_;
				const gchar* _tmp104_;
				_tmp102_ = item;
				_tmp103_ = objects_item_get_section_id (_tmp102_);
				_tmp104_ = _tmp103_;
				if (g_strcmp0 (_tmp104_, "") != 0) {
					ObjectsSection* section = NULL;
					ServicesStore* _tmp105_;
					ObjectsItem* _tmp106_;
					const gchar* _tmp107_;
					const gchar* _tmp108_;
					ObjectsSection* _tmp109_;
					ObjectsSection* _tmp110_;
					_tmp105_ = services_store_instance ();
					_tmp106_ = item;
					_tmp107_ = objects_item_get_section_id (_tmp106_);
					_tmp108_ = _tmp107_;
					_tmp109_ = services_store_get_section (_tmp105_, _tmp108_);
					section = _tmp109_;
					_tmp110_ = section;
					if (_tmp110_ != NULL) {
						ObjectsSection* _tmp111_;
						ObjectsItem* _tmp112_;
						ObjectsItem* _tmp113_;
						ObjectsItem* _tmp114_;
						_tmp111_ = section;
						_tmp112_ = item;
						_tmp113_ = objects_section_add_item_if_not_exists (_tmp111_, _tmp112_, TRUE);
						_tmp114_ = _tmp113_;
						_g_object_unref0 (_tmp114_);
					}
					_g_object_unref0 (section);
				} else {
					ObjectsProject* project = NULL;
					ServicesStore* _tmp115_;
					ObjectsItem* _tmp116_;
					const gchar* _tmp117_;
					const gchar* _tmp118_;
					ObjectsProject* _tmp119_;
					ObjectsProject* _tmp120_;
					_tmp115_ = services_store_instance ();
					_tmp116_ = item;
					_tmp117_ = objects_item_get_project_id (_tmp116_);
					_tmp118_ = _tmp117_;
					_tmp119_ = services_store_get_project (_tmp115_, _tmp118_);
					project = _tmp119_;
					_tmp120_ = project;
					if (_tmp120_ != NULL) {
						ObjectsProject* _tmp121_;
						ObjectsItem* _tmp122_;
						ObjectsItem* _tmp123_;
						ObjectsItem* _tmp124_;
						_tmp121_ = project;
						_tmp122_ = item;
						_tmp123_ = objects_project_add_item_if_not_exists (_tmp121_, _tmp122_, TRUE);
						_tmp124_ = _tmp123_;
						_g_object_unref0 (_tmp124_);
					}
					_g_object_unref0 (project);
				}
			}
			_g_object_unref0 (item);
		}
	}
	services_backup_manager_show_message (self);
}

static void
__lambda361_ (ServicesBackupManager* self,
              const gchar* response)
{
	g_return_if_fail (response != NULL);
	services_backup_manager_restart_application (self);
}

static void
___lambda361__adw_alert_dialog_response (AdwAlertDialog* _sender,
                                         const gchar* response,
                                         gpointer self)
{
	__lambda361_ ((ServicesBackupManager*) self, response);
}

static void
services_backup_manager_show_message (ServicesBackupManager* self)
{
	AdwAlertDialog* dialog = NULL;
	AdwAlertDialog* _tmp0_;
	Planify* _tmp1_;
	MainWindow* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = (AdwAlertDialog*) adw_alert_dialog_new (_ ("Backup Successfully Imported"), _ ("Planify will restart to apply the changes"));
	g_object_ref_sink (_tmp0_);
	dialog = _tmp0_;
	adw_alert_dialog_add_response (dialog, "ok", _ ("Restart Now"));
	_tmp1_ = planify__instance;
	_tmp2_ = _tmp1_->main_window;
	adw_dialog_present ((AdwDialog*) dialog, (GtkWidget*) _tmp2_);
	g_signal_connect_object (dialog, "response", (GCallback) ___lambda361__adw_alert_dialog_response, self, 0);
	_g_object_unref0 (dialog);
}

static void
services_backup_manager_restart_application (ServicesBackupManager* self)
{
	Planify* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = planify__instance;
	planify_recreate_main_window (_tmp0_);
}

static void
services_backup_manager_add_filters (ServicesBackupManager* self,
                                     GtkFileDialog* file_dialog)
{
	GtkFileFilter* filter = NULL;
	GtkFileFilter* _tmp0_;
	GListStore* filters = NULL;
	GListStore* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file_dialog != NULL);
	_tmp0_ = gtk_file_filter_new ();
	filter = _tmp0_;
	gtk_file_filter_set_name (filter, _ ("Planify Backup Files"));
	gtk_file_filter_add_pattern (filter, "*.json");
	_tmp1_ = g_list_store_new (gtk_file_filter_get_type ());
	filters = _tmp1_;
	g_list_store_append (filters, (GObject*) filter);
	gtk_file_dialog_set_filters (file_dialog, (GListModel*) filters);
	gtk_file_dialog_set_default_filter (file_dialog, filter);
	_g_object_unref0 (filters);
	_g_object_unref0 (filter);
}

ServicesBackupManager*
services_backup_manager_construct (GType object_type)
{
	ServicesBackupManager * self = NULL;
	self = (ServicesBackupManager*) g_object_new (object_type, NULL);
	return self;
}

ServicesBackupManager*
services_backup_manager_new (void)
{
	return services_backup_manager_construct (SERVICES_TYPE_BACKUP_MANAGER);
}

GeeArrayList*
services_backup_manager_get_backups (ServicesBackupManager* self)
{
	GeeArrayList* result;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_backups;
	if (_tmp0_ == NULL) {
		GeeArrayList* _tmp1_;
		_tmp1_ = services_backup_manager_get_backups_collection (self);
		_g_object_unref0 (self->priv->_backups);
		self->priv->_backups = _tmp1_;
	}
	_tmp2_ = self->priv->_backups;
	result = _tmp2_;
	return result;
}

static GObject *
services_backup_manager_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ServicesBackupManager * self;
	JsonGenerator* _tmp0_;
	JsonGenerator* _tmp1_;
	JsonBuilder* _tmp2_;
	JsonParser* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	parent_class = G_OBJECT_CLASS (services_backup_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_TYPE_BACKUP_MANAGER, ServicesBackupManager);
	_tmp0_ = json_generator_new ();
	_g_object_unref0 (self->priv->generator);
	self->priv->generator = _tmp0_;
	_tmp1_ = self->priv->generator;
	json_generator_set_pretty (_tmp1_, TRUE);
	_tmp2_ = json_builder_new ();
	_g_object_unref0 (self->priv->builder);
	self->priv->builder = _tmp2_;
	_tmp3_ = json_parser_new ();
	_g_object_unref0 (self->priv->parser);
	self->priv->parser = _tmp3_;
	_tmp4_ = g_get_user_data_dir ();
	_tmp5_ = g_strconcat (_tmp4_, "/io.github.alainm23.planify/backups", NULL);
	_g_free0 (self->priv->path);
	self->priv->path = _tmp5_;
	return obj;
}

static void
services_backup_manager_class_init (ServicesBackupManagerClass * klass,
                                    gpointer klass_data)
{
	services_backup_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ServicesBackupManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_services_backup_manager_get_property;
	G_OBJECT_CLASS (klass)->constructor = services_backup_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = services_backup_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SERVICES_BACKUP_MANAGER_BACKUPS_PROPERTY, services_backup_manager_properties[SERVICES_BACKUP_MANAGER_BACKUPS_PROPERTY] = g_param_spec_object ("backups", "backups", "backups", GEE_TYPE_ARRAY_LIST, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	services_backup_manager_signals[SERVICES_BACKUP_MANAGER_BACKUP_ADDED_SIGNAL] = g_signal_new ("backup-added", SERVICES_TYPE_BACKUP_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, OBJECTS_TYPE_BACKUP);
}

static void
services_backup_manager_instance_init (ServicesBackupManager * self,
                                       gpointer klass)
{
	self->priv = services_backup_manager_get_instance_private (self);
	self->priv->_backups = NULL;
}

static void
services_backup_manager_finalize (GObject * obj)
{
	ServicesBackupManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_TYPE_BACKUP_MANAGER, ServicesBackupManager);
	_g_object_unref0 (self->priv->generator);
	_g_object_unref0 (self->priv->builder);
	_g_object_unref0 (self->priv->parser);
	_g_free0 (self->priv->path);
	_g_object_unref0 (self->priv->_backups);
	G_OBJECT_CLASS (services_backup_manager_parent_class)->finalize (obj);
}

static GType
services_backup_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ServicesBackupManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) services_backup_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ServicesBackupManager), 0, (GInstanceInitFunc) services_backup_manager_instance_init, NULL };
	GType services_backup_manager_type_id;
	services_backup_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "ServicesBackupManager", &g_define_type_info, 0);
	ServicesBackupManager_private_offset = g_type_add_instance_private (services_backup_manager_type_id, sizeof (ServicesBackupManagerPrivate));
	return services_backup_manager_type_id;
}

GType
services_backup_manager_get_type (void)
{
	static volatile gsize services_backup_manager_type_id__once = 0;
	if (g_once_init_enter (&services_backup_manager_type_id__once)) {
		GType services_backup_manager_type_id;
		services_backup_manager_type_id = services_backup_manager_get_type_once ();
		g_once_init_leave (&services_backup_manager_type_id__once, services_backup_manager_type_id);
	}
	return services_backup_manager_type_id__once;
}

static void
_vala_services_backup_manager_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	ServicesBackupManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SERVICES_TYPE_BACKUP_MANAGER, ServicesBackupManager);
	switch (property_id) {
		case SERVICES_BACKUP_MANAGER_BACKUPS_PROPERTY:
		g_value_set_object (value, services_backup_manager_get_backups (self));
		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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

