/* App.c generated by valac 0.56.19, the Vala compiler
 * generated from App.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 <adwaita.h>
#include <glib-object.h>
#include <libportal/portal.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "planify.h"
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
#include <libportal-gtk4/portal-gtk4.h>
#include <glib/gstdio.h>
#include <locale.h>

#define BUILD_APPLICATION_ID "io.github.alainm23.planify"
#define BUILD_VERSION "4.19.5"
#define BUILD_INSTALL_PREFIX "/usr"
#define BUILD_GETTEXT_PACKAGE "io.github.alainm23.planify"
#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 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;
enum  {
	PLANIFY_0_PROPERTY,
	PLANIFY_NUM_PROPERTIES
};
static GParamSpec* planify_properties[PLANIFY_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_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define __vala_XdpParent_free0(var) ((var == NULL) ? NULL : (var = (_vala_XdpParent_free (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _PlanifyAskForBackgroundData PlanifyAskForBackgroundData;
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _Block2Data Block2Data;

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

struct _PlanifyClass {
	AdwApplicationClass parent_class;
};

struct _PlanifyPrivate {
	XdpPortal* portal;
};

struct _Block1Data {
	int _ref_count_;
	Planify* self;
	ObjectsItem* item;
};

struct _PlanifyAskForBackgroundData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	Planify* self;
	XdpBackgroundFlags flags;
	gboolean result;
	gboolean run_in_background;
	ServicesSettings* _tmp0_;
	ServicesSettings* _tmp1_;
	GSettings* _tmp2_;
	gboolean _tmp3_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gint __tmp4__size_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar** _tmp7_;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gchar** daemon_command;
	gchar** _tmp10_;
	gint _tmp10__length1;
	gint daemon_command_length1;
	gint _daemon_command_size_;
	XdpPortal* _tmp11_;
	XdpPortal* _tmp12_;
	gchar* reason;
	gchar* _tmp13_;
	GPtrArray* command;
	gchar** _tmp14_;
	gint _tmp14__length1;
	GPtrArray* _tmp15_;
	gchar** _tmp16_;
	gint _tmp16__length1;
	gchar** arg_collection;
	gint arg_collection_length1;
	gint _arg_collection_size_;
	gint arg_it;
	const gchar* arg;
	GPtrArray* _tmp17_;
	const gchar* _tmp18_;
	XdpParent* window;
	GtkWindow* _tmp19_;
	GtkWindow* _tmp20_;
	XdpParent* _tmp21_;
	gboolean _tmp22_;
	XdpPortal* _tmp23_;
	const gchar* _tmp24_;
	GPtrArray* _tmp25_;
	GPtrArray* _tmp26_;
	GError* e;
	GError* _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	GError* _tmp31_;
	GError* _inner_error0_;
};

struct _Block2Data {
	int _ref_count_;
	Planify* self;
	ObjectsItem* item;
};

static gint Planify_private_offset;
static gpointer planify_parent_class = NULL;
static gboolean planify_n_version;
static gboolean planify_clear_database;
static gboolean planify_show_log_path;
static gboolean planify_run_in_background;
static gchar* planify_lang;
VALA_EXTERN Planify* planify__instance;
Planify* planify__instance = NULL;
static gboolean planify_run_in_background = FALSE;
static gboolean planify_n_version = FALSE;
static gboolean planify_clear_database = FALSE;
static gboolean planify_show_log_path = FALSE;
static gchar* planify_lang = NULL;

VALA_EXTERN GType planify_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Planify, g_object_unref)
VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
VALA_EXTERN Planify* planify_new (void);
VALA_EXTERN Planify* planify_construct (GType object_type);
static void planify_real_open (GApplication* base,
                        GFile** files,
                        gint files_length1,
                        const gchar* hint);
static void planify_handle_uri (Planify* self,
                         const gchar* uri);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean ______lambda988_ (Block1Data* _data1_);
static gboolean _______lambda988__gsource_func (gpointer self);
static void planify_real_activate (GApplication* base);
VALA_EXTERN MainWindow* main_window_new (Planify* application);
VALA_EXTERN MainWindow* main_window_construct (GType object_type,
                                   Planify* application);
static void planify_build_shortcuts (Planify* self);
static void planify_ask_for_background_data_free (gpointer _data);
VALA_EXTERN void planify_ask_for_background (Planify* self,
                                 XdpBackgroundFlags flags,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_);
VALA_EXTERN gboolean planify_ask_for_background_finish (Planify* self,
                                            GAsyncResult* _res_);
static gboolean planify_ask_for_background_co (PlanifyAskForBackgroundData* _data_);
static void planify_ask_for_background_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
static void _vala_XdpParent_free (XdpParent* self);
VALA_EXTERN void planify_create_dir_with_parents (Planify* self,
                                      const gchar* dir);
VALA_EXTERN void planify_recreate_main_window (Planify* self);
static void planify_snooze_item (Planify* self,
                          const gchar* item_id,
                          gint minutes);
static void __lambda362_ (Planify* self,
                   GVariant* parameter);
VALA_EXTERN Planify* planify_get_instance (void);
VALA_EXTERN void main_window_view_item (MainWindow* self,
                            const gchar* id);
static void ___lambda362__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static void __lambda363_ (Planify* self,
                   GVariant* parameter);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void ____lambda364_ (Block2Data* _data2_,
                     GObject* obj,
                     GAsyncResult* res);
static void _____lambda364__gasync_ready_callback (GObject* source_object,
                                            GAsyncResult* res,
                                            gpointer self);
static void ___lambda363__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static void __lambda365_ (Planify* self,
                   GVariant* parameter);
static void ___lambda365__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static void __lambda366_ (Planify* self,
                   GVariant* parameter);
static void ___lambda366__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static void __lambda367_ (Planify* self,
                   GVariant* parameter);
static void ___lambda367__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static gint planify_main (gchar** args,
                   gint args_length1);
static GObject * planify_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties);
static void planify_finalize (GObject * obj);
static GType planify_get_type_once (void);
static void _vala_planify_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 const GOptionEntry PLANIFY_OPTIONS[6] = {{"version", 'v', (gint) 0, G_OPTION_ARG_NONE, &planify_n_version, "Display version number", NULL}, {"reset", 'r', (gint) 0, G_OPTION_ARG_NONE, &planify_clear_database, "Reset Planify", NULL}, {"log-path", (gchar) 0, (gint) 0, G_OPTION_ARG_NONE, &planify_show_log_path, "Print the log file path", NULL}, {"background", 'b', (gint) 0, G_OPTION_ARG_NONE, &planify_run_in_background, "Run the Application in background", NULL}, {"lang", 'l', (gint) 0, G_OPTION_ARG_STRING, &planify_lang, "Open Planify in a specific language", "LANG"}, {NULL}};

static inline gpointer
planify_get_instance_private (Planify* self)
{
	return G_STRUCT_MEMBER_P (self, Planify_private_offset);
}

Planify*
planify_construct (GType object_type)
{
	Planify * self = NULL;
	self = (Planify*) g_object_new (object_type, "application-id", BUILD_APPLICATION_ID, "flags", G_APPLICATION_HANDLES_OPEN, NULL);
	return self;
}

Planify*
planify_new (void)
{
	return planify_construct (TYPE_PLANIFY);
}

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

static void
planify_real_open (GApplication* base,
                   GFile** files,
                   gint files_length1,
                   const gchar* hint)
{
	Planify * self;
	self = (Planify*) base;
	g_return_if_fail (hint != NULL);
	g_application_activate ((GApplication*) self);
	{
		GFile** file_collection = NULL;
		gint file_collection_length1 = 0;
		gint _file_collection_size_ = 0;
		gint file_it = 0;
		file_collection = files;
		file_collection_length1 = files_length1;
		for (file_it = 0; file_it < file_collection_length1; file_it = file_it + 1) {
			GFile* _tmp0_;
			GFile* file = NULL;
			_tmp0_ = _g_object_ref0 (file_collection[file_it]);
			file = _tmp0_;
			{
				gchar* uri = NULL;
				GFile* _tmp1_;
				gchar* _tmp2_;
				const gchar* _tmp3_;
				_tmp1_ = file;
				_tmp2_ = g_file_get_uri (_tmp1_);
				uri = _tmp2_;
				_tmp3_ = uri;
				if (g_str_has_prefix (_tmp3_, "planify://")) {
					const gchar* _tmp4_;
					_tmp4_ = uri;
					planify_handle_uri (self, _tmp4_);
				}
				_g_free0 (uri);
				_g_object_unref0 (file);
			}
		}
	}
}

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

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		Planify* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->item);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static gboolean
______lambda988_ (Block1Data* _data1_)
{
	Planify* self;
	ServicesEventBus* _tmp0_;
	ServicesEventBus* _tmp1_;
	ObjectsItem* _tmp2_;
	gboolean result;
	self = _data1_->self;
	_tmp0_ = services_event_bus_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _data1_->item;
	g_signal_emit_by_name (_tmp1_, "open-item", _tmp2_);
	_g_object_unref0 (_tmp1_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
_______lambda988__gsource_func (gpointer self)
{
	gboolean result;
	result = ______lambda988_ (self);
	return result;
}

static void
planify_handle_uri (Planify* self,
                    const gchar* uri)
{
	gchar** parts = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gint parts_length1;
	gint _parts_size_;
	gchar* path = NULL;
	gchar** _tmp5_;
	gint _tmp5__length1;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	_tmp0_ = string_replace (uri, "planify://", "");
	_tmp1_ = _tmp0_;
	_tmp3_ = _tmp2_ = g_strsplit (_tmp1_, "?", 2);
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _vala_array_length (_tmp2_);
	_g_free0 (_tmp1_);
	parts = _tmp4_;
	parts_length1 = _tmp4__length1;
	_parts_size_ = parts_length1;
	_tmp5_ = parts;
	_tmp5__length1 = parts_length1;
	_tmp6_ = _tmp5_[0];
	_tmp7_ = g_strdup (_tmp6_);
	path = _tmp7_;
	_tmp8_ = path;
	if (g_str_has_prefix (_tmp8_, "auth")) {
		ServicesEventBus* _tmp9_;
		ServicesEventBus* _tmp10_;
		_tmp9_ = services_event_bus_get_default ();
		_tmp10_ = _tmp9_;
		g_signal_emit_by_name (_tmp10_, "oauth-callback", uri);
		_g_object_unref0 (_tmp10_);
	} else {
		const gchar* _tmp11_;
		_tmp11_ = path;
		if (g_str_has_prefix (_tmp11_, "project/")) {
			gchar* project_id = NULL;
			const gchar* _tmp12_;
			gchar* _tmp13_;
			ServicesEventBus* _tmp14_;
			ServicesEventBus* _tmp15_;
			const gchar* _tmp16_;
			_tmp12_ = path;
			_tmp13_ = string_substring (_tmp12_, (glong) 8, (glong) -1);
			project_id = _tmp13_;
			_tmp14_ = services_event_bus_get_default ();
			_tmp15_ = _tmp14_;
			_tmp16_ = project_id;
			g_signal_emit_by_name (_tmp15_, "pane-selected", PANE_TYPE_PROJECT, _tmp16_);
			_g_object_unref0 (_tmp15_);
			_g_free0 (project_id);
		} else {
			const gchar* _tmp17_;
			_tmp17_ = path;
			if (g_str_has_prefix (_tmp17_, "item/")) {
				Block1Data* _data1_;
				gchar* item_id = NULL;
				const gchar* _tmp18_;
				gchar* _tmp19_;
				ServicesStore* _tmp20_;
				const gchar* _tmp21_;
				ObjectsItem* _tmp22_;
				ObjectsItem* _tmp23_;
				_data1_ = g_slice_new0 (Block1Data);
				_data1_->_ref_count_ = 1;
				_data1_->self = g_object_ref (self);
				_tmp18_ = path;
				_tmp19_ = string_substring (_tmp18_, (glong) 5, (glong) -1);
				item_id = _tmp19_;
				_tmp20_ = services_store_instance ();
				_tmp21_ = item_id;
				_tmp22_ = services_store_get_item (_tmp20_, _tmp21_);
				_data1_->item = _tmp22_;
				_tmp23_ = _data1_->item;
				if (_tmp23_ != NULL) {
					ServicesEventBus* _tmp24_;
					ServicesEventBus* _tmp25_;
					ObjectsItem* _tmp26_;
					const gchar* _tmp27_;
					const gchar* _tmp28_;
					_tmp24_ = services_event_bus_get_default ();
					_tmp25_ = _tmp24_;
					_tmp26_ = _data1_->item;
					_tmp27_ = objects_item_get_project_id (_tmp26_);
					_tmp28_ = _tmp27_;
					g_signal_emit_by_name (_tmp25_, "pane-selected", PANE_TYPE_PROJECT, _tmp28_);
					_g_object_unref0 (_tmp25_);
					g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 275, _______lambda988__gsource_func, block1_data_ref (_data1_), block1_data_unref);
				}
				_g_free0 (item_id);
				block1_data_unref (_data1_);
				_data1_ = NULL;
			}
		}
	}
	_g_free0 (path);
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
}

static gchar*
g_file_stream_read_line (FILE* self)
{
	gint c = 0;
	GString* ret = NULL;
	GString* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	ret = NULL;
	while (TRUE) {
		GString* _tmp0_;
		GString* _tmp2_;
		c = fgetc (self);
		if (!(c != EOF)) {
			break;
		}
		_tmp0_ = ret;
		if (_tmp0_ == NULL) {
			GString* _tmp1_;
			_tmp1_ = g_string_new ("");
			_g_string_free0 (ret);
			ret = _tmp1_;
		}
		if (c == ((gint) '\n')) {
			break;
		}
		_tmp2_ = ret;
		g_string_append_c ((GString*) _tmp2_, (gchar) c);
	}
	_tmp3_ = ret;
	if (_tmp3_ == NULL) {
		result = NULL;
		_g_string_free0 (ret);
		return result;
	} else {
		GString* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = ret;
		_tmp5_ = ((GString*) _tmp4_)->str;
		((GString*) _tmp4_)->str = NULL;
		result = _tmp5_;
		_g_string_free0 (ret);
		return result;
	}
}

static void
planify_real_activate (GApplication* base)
{
	Planify * self;
	const gchar* _tmp0_;
	MainWindow* _tmp24_;
	MainWindow* _tmp26_;
	ServicesSettings* _tmp27_;
	ServicesSettings* _tmp28_;
	GSettings* _tmp29_;
	MainWindow* _tmp30_;
	ServicesSettings* _tmp31_;
	ServicesSettings* _tmp32_;
	GSettings* _tmp33_;
	MainWindow* _tmp34_;
	ServicesSettings* _tmp35_;
	ServicesSettings* _tmp36_;
	GSettings* _tmp37_;
	gboolean _tmp38_;
	ServicesSettings* _tmp41_;
	ServicesSettings* _tmp42_;
	GSettings* _tmp43_;
	MainWindow* _tmp44_;
	GtkCssProvider* provider = NULL;
	GtkCssProvider* _tmp45_;
	GtkCssProvider* _tmp46_;
	GdkDisplay* _tmp47_;
	GtkCssProvider* _tmp48_;
	Util* _tmp49_;
	Util* _tmp50_;
	Util* _tmp51_;
	Util* _tmp52_;
	self = (Planify*) base;
	_tmp0_ = planify_lang;
	if (g_strcmp0 (_tmp0_, "") != 0) {
		const gchar* _tmp1_;
		_tmp1_ = planify_lang;
		g_setenv ("LANGUAGE", _tmp1_, TRUE);
	}
	if (planify_n_version) {
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = g_strdup_printf ("%s\n", BUILD_VERSION);
		_tmp3_ = _tmp2_;
		g_debug ("App.vala:117: %s", _tmp3_);
		_g_free0 (_tmp3_);
		return;
	}
	if (planify_show_log_path) {
		FILE* _tmp4_;
		ServicesLogService* _tmp5_;
		ServicesLogService* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp4_ = stdout;
		_tmp5_ = services_log_service_get_default ();
		_tmp6_ = _tmp5_;
		_tmp7_ = services_log_service_get_log_path (_tmp6_);
		_tmp8_ = _tmp7_;
		fprintf (_tmp4_, "%s\n", _tmp8_);
		_g_free0 (_tmp8_);
		_g_object_unref0 (_tmp6_);
		return;
	}
	if (planify_clear_database) {
		FILE* _tmp9_;
		gchar* option = NULL;
		FILE* _tmp10_;
		gchar* _tmp11_;
		gboolean _tmp12_ = FALSE;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gboolean _tmp16_;
		_tmp9_ = stdout;
		fprintf (_tmp9_, "Are you sure you want to reset all? (y/n): ");
		_tmp10_ = stdin;
		_tmp11_ = g_file_stream_read_line (_tmp10_);
		option = _tmp11_;
		_tmp13_ = option;
		_tmp14_ = g_utf8_strdown (_tmp13_, (gssize) -1);
		_tmp15_ = _tmp14_;
		_tmp16_ = g_strcmp0 (_tmp15_, "y") == 0;
		_g_free0 (_tmp15_);
		if (_tmp16_) {
			_tmp12_ = TRUE;
		} else {
			const gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			_tmp17_ = option;
			_tmp18_ = g_utf8_strdown (_tmp17_, (gssize) -1);
			_tmp19_ = _tmp18_;
			_tmp12_ = g_strcmp0 (_tmp19_, "yes") == 0;
			_g_free0 (_tmp19_);
		}
		if (_tmp12_) {
			ServicesDatabase* _tmp20_;
			ServicesDatabase* _tmp21_;
			ServicesSettings* _tmp22_;
			ServicesSettings* _tmp23_;
			_tmp20_ = services_database_get_default ();
			_tmp21_ = _tmp20_;
			services_database_clear_database (_tmp21_);
			_g_object_unref0 (_tmp21_);
			_tmp22_ = services_settings_get_default ();
			_tmp23_ = _tmp22_;
			services_settings_reset_settings (_tmp23_);
			_g_object_unref0 (_tmp23_);
			_g_free0 (option);
			return;
		}
		_g_free0 (option);
	}
	_tmp24_ = self->main_window;
	if (_tmp24_ != NULL) {
		MainWindow* _tmp25_;
		_tmp25_ = self->main_window;
		gtk_window_present ((GtkWindow*) _tmp25_);
		return;
	}
	_tmp26_ = main_window_new (self);
	g_object_ref_sink (_tmp26_);
	_g_object_unref0 (self->main_window);
	self->main_window = _tmp26_;
	_tmp27_ = services_settings_get_default ();
	_tmp28_ = _tmp27_;
	_tmp29_ = _tmp28_->settings;
	_tmp30_ = self->main_window;
	g_settings_bind (_tmp29_, "window-height", (GObject*) _tmp30_, "default-height", G_SETTINGS_BIND_DEFAULT);
	_g_object_unref0 (_tmp28_);
	_tmp31_ = services_settings_get_default ();
	_tmp32_ = _tmp31_;
	_tmp33_ = _tmp32_->settings;
	_tmp34_ = self->main_window;
	g_settings_bind (_tmp33_, "window-width", (GObject*) _tmp34_, "default-width", G_SETTINGS_BIND_DEFAULT);
	_g_object_unref0 (_tmp32_);
	_tmp35_ = services_settings_get_default ();
	_tmp36_ = _tmp35_;
	_tmp37_ = _tmp36_->settings;
	_tmp38_ = g_settings_get_boolean (_tmp37_, "window-maximized");
	_g_object_unref0 (_tmp36_);
	if (_tmp38_) {
		MainWindow* _tmp39_;
		_tmp39_ = self->main_window;
		gtk_window_maximize ((GtkWindow*) _tmp39_);
	}
	if (!planify_run_in_background) {
		MainWindow* _tmp40_;
		_tmp40_ = self->main_window;
		gtk_widget_show ((GtkWidget*) _tmp40_);
	}
	_tmp41_ = services_settings_get_default ();
	_tmp42_ = _tmp41_;
	_tmp43_ = _tmp42_->settings;
	_tmp44_ = self->main_window;
	g_settings_bind (_tmp43_, "window-maximized", (GObject*) _tmp44_, "maximized", G_SETTINGS_BIND_SET);
	_g_object_unref0 (_tmp42_);
	_tmp45_ = gtk_css_provider_new ();
	provider = _tmp45_;
	_tmp46_ = provider;
	gtk_css_provider_load_from_resource (_tmp46_, "/io/github/alainm23/planify/index.css");
	_tmp47_ = gdk_display_get_default ();
	_tmp48_ = provider;
	gtk_style_context_add_provider_for_display (_tmp47_, (GtkStyleProvider*) _tmp48_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_tmp49_ = util_get_default ();
	_tmp50_ = _tmp49_;
	util_update_theme (_tmp50_);
	_g_object_unref0 (_tmp50_);
	_tmp51_ = util_get_default ();
	_tmp52_ = _tmp51_;
	util_update_font_scale (_tmp52_);
	_g_object_unref0 (_tmp52_);
	planify_build_shortcuts (self);
	_g_object_unref0 (provider);
}

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

void
planify_ask_for_background (Planify* self,
                            XdpBackgroundFlags flags,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	PlanifyAskForBackgroundData* _data_;
	Planify* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (PlanifyAskForBackgroundData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, planify_ask_for_background_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->flags = flags;
	planify_ask_for_background_co (_data_);
}

gboolean
planify_ask_for_background_finish (Planify* self,
                                   GAsyncResult* _res_)
{
	gboolean result;
	PlanifyAskForBackgroundData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static gpointer
_g_ptr_array_ref0 (gpointer self)
{
	return self ? g_ptr_array_ref (self) : NULL;
}

static void
planify_ask_for_background_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	PlanifyAskForBackgroundData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	planify_ask_for_background_co (_data_);
}

static void
_vala_XdpParent_free (XdpParent* self)
{
	g_boxed_free (xdp_parent_get_type (), self);
}

static gboolean
planify_ask_for_background_co (PlanifyAskForBackgroundData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = services_settings_get_default ();
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _data_->_tmp1_->settings;
	_data_->_tmp3_ = g_settings_get_boolean (_data_->_tmp2_, "run-in-background");
	_g_object_unref0 (_data_->_tmp1_);
	_data_->run_in_background = _data_->_tmp3_;
	_data_->_tmp4__length1 = 0;
	_data_->__tmp4__size_ = 0;
	if (_data_->run_in_background) {
		_data_->_tmp5_ = g_strdup (BUILD_APPLICATION_ID);
		_data_->_tmp6_ = g_strdup ("--background");
		_data_->_tmp7_ = g_new0 (gchar*, 2 + 1);
		_data_->_tmp7_[0] = _data_->_tmp5_;
		_data_->_tmp7_[1] = _data_->_tmp6_;
		_data_->_tmp4_ = (_vala_array_free (_data_->_tmp4_, _data_->_tmp4__length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp4_ = _data_->_tmp7_;
		_data_->_tmp4__length1 = 2;
		_data_->__tmp4__size_ = _data_->_tmp4__length1;
	} else {
		_data_->_tmp8_ = g_strdup (BUILD_APPLICATION_ID);
		_data_->_tmp9_ = g_new0 (gchar*, 1 + 1);
		_data_->_tmp9_[0] = _data_->_tmp8_;
		_data_->_tmp4_ = (_vala_array_free (_data_->_tmp4_, _data_->_tmp4__length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp4_ = _data_->_tmp9_;
		_data_->_tmp4__length1 = 1;
		_data_->__tmp4__size_ = _data_->_tmp4__length1;
	}
	_data_->_tmp10_ = _data_->_tmp4_;
	_data_->_tmp10__length1 = _data_->_tmp4__length1;
	_data_->_tmp4_ = NULL;
	_data_->_tmp4__length1 = 0;
	_data_->daemon_command = _data_->_tmp10_;
	_data_->daemon_command_length1 = _data_->_tmp10__length1;
	_data_->_daemon_command_size_ = _data_->daemon_command_length1;
	_data_->_tmp11_ = _data_->self->priv->portal;
	if (_data_->_tmp11_ == NULL) {
		_data_->_tmp12_ = xdp_portal_new ();
		_g_object_unref0 (_data_->self->priv->portal);
		_data_->self->priv->portal = _data_->_tmp12_;
	}
	_data_->_tmp13_ = g_strdup (_ ("Planify will automatically start when this device turns on " "and run when its window is closed so that it can send to-do notificati" \
"ons."));
	_data_->reason = _data_->_tmp13_;
	_data_->_tmp14_ = _data_->daemon_command;
	_data_->_tmp14__length1 = _data_->daemon_command_length1;
	_data_->_tmp15_ = g_ptr_array_new_full ((guint) _data_->_tmp14__length1, NULL);
	_data_->command = _data_->_tmp15_;
	_data_->_tmp16_ = _data_->daemon_command;
	_data_->_tmp16__length1 = _data_->daemon_command_length1;
	{
		_data_->arg_collection_length1 = 0;
		_data_->_arg_collection_size_ = 0;
		_data_->arg_collection = _data_->_tmp16_;
		_data_->arg_collection_length1 = _data_->_tmp16__length1;
		for (_data_->arg_it = 0; _data_->arg_it < _data_->arg_collection_length1; _data_->arg_it = _data_->arg_it + 1) {
			_data_->arg = _data_->arg_collection[_data_->arg_it];
			{
				_data_->_tmp17_ = _data_->command;
				_data_->_tmp18_ = _data_->arg;
				g_ptr_array_add (_data_->_tmp17_, _data_->_tmp18_);
			}
		}
	}
	_data_->_tmp19_ = gtk_application_get_active_window ((GtkApplication*) _data_->self);
	_data_->_tmp20_ = _data_->_tmp19_;
	_data_->_tmp21_ = xdp_parent_new_gtk (_data_->_tmp20_);
	_data_->window = _data_->_tmp21_;
	{
		_data_->_tmp23_ = _data_->self->priv->portal;
		_data_->_tmp24_ = _data_->reason;
		_data_->_tmp25_ = _data_->command;
		_data_->_tmp26_ = _g_ptr_array_ref0 (_data_->_tmp25_);
		_data_->_state_ = 1;
		xdp_portal_request_background (_data_->_tmp23_, _data_->window, _data_->_tmp24_, _data_->_tmp26_, _data_->flags, NULL, planify_ask_for_background_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp22_ = xdp_portal_request_background_finish (_data_->_tmp23_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->result = _data_->_tmp22_;
		__vala_XdpParent_free0 (_data_->window);
		_g_ptr_array_unref0 (_data_->command);
		_g_free0 (_data_->reason);
		_data_->daemon_command = (_vala_array_free (_data_->daemon_command, _data_->daemon_command_length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp4_ = (_vala_array_free (_data_->_tmp4_, _data_->_tmp4__length1, (GDestroyNotify) g_free), 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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp27_ = _data_->e;
		_data_->_tmp28_ = _data_->_tmp27_->message;
		_data_->_tmp29_ = g_strdup_printf ("Error during portal request: %s", _data_->_tmp28_);
		_data_->_tmp30_ = _data_->_tmp29_;
		g_debug ("App.vala:194: %s", _data_->_tmp30_);
		_g_free0 (_data_->_tmp30_);
		_data_->_tmp31_ = _data_->e;
		_data_->result = g_error_matches (_data_->_tmp31_, G_IO_ERROR, G_IO_ERROR_FAILED);
		_g_error_free0 (_data_->e);
		__vala_XdpParent_free0 (_data_->window);
		_g_ptr_array_unref0 (_data_->command);
		_g_free0 (_data_->reason);
		_data_->daemon_command = (_vala_array_free (_data_->daemon_command, _data_->daemon_command_length1, (GDestroyNotify) g_free), NULL);
		_data_->_tmp4_ = (_vala_array_free (_data_->_tmp4_, _data_->_tmp4__length1, (GDestroyNotify) g_free), 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;
	}
	__finally0:
	__vala_XdpParent_free0 (_data_->window);
	_g_ptr_array_unref0 (_data_->command);
	_g_free0 (_data_->reason);
	_data_->daemon_command = (_vala_array_free (_data_->daemon_command, _data_->daemon_command_length1, (GDestroyNotify) g_free), NULL);
	_data_->_tmp4_ = (_vala_array_free (_data_->_tmp4_, _data_->_tmp4__length1, (GDestroyNotify) g_free), 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;
}

void
planify_create_dir_with_parents (Planify* self,
                                 const gchar* dir)
{
	gchar* path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	GFile* tmp = NULL;
	const gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dir != NULL);
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_strconcat (_tmp0_, dir, NULL);
	path = _tmp1_;
	_tmp2_ = path;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	tmp = _tmp3_;
	_tmp4_ = tmp;
	if (g_file_query_file_type (_tmp4_, 0, NULL) != G_FILE_TYPE_DIRECTORY) {
		const gchar* _tmp5_;
		_tmp5_ = path;
		g_mkdir_with_parents (_tmp5_, 0775);
	}
	_g_object_unref0 (tmp);
	_g_free0 (path);
}

void
planify_recreate_main_window (Planify* self)
{
	MainWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->main_window;
	if (_tmp0_ != NULL) {
		MainWindow* _tmp1_;
		_tmp1_ = self->main_window;
		gtk_window_destroy ((GtkWindow*) _tmp1_);
		_g_object_unref0 (self->main_window);
		self->main_window = NULL;
	}
	g_application_activate ((GApplication*) self);
}

static void
planify_snooze_item (Planify* self,
                     const gchar* item_id,
                     gint minutes)
{
	ObjectsItem* item = NULL;
	ServicesStore* _tmp0_;
	ObjectsItem* _tmp1_;
	ObjectsItem* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item_id != NULL);
	_tmp0_ = services_store_instance ();
	_tmp1_ = services_store_get_item (_tmp0_, item_id);
	item = _tmp1_;
	_tmp2_ = item;
	if (_tmp2_ != NULL) {
		GDateTime* datetime = NULL;
		GDateTime* _tmp3_;
		GDateTime* _tmp4_;
		GDateTime* _tmp5_;
		GDateTime* _tmp6_;
		ObjectsReminder* reminder = NULL;
		ObjectsReminder* _tmp7_;
		ObjectsReminder* _tmp8_;
		ObjectsDueDate* _tmp9_;
		ObjectsDueDate* _tmp10_;
		GDateTime* _tmp11_;
		GDateTime* _tmp12_;
		GDateTime* _tmp13_;
		GDateTime* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		ObjectsItem* _tmp17_;
		ObjectsReminder* _tmp18_;
		_tmp3_ = g_date_time_new_now_local ();
		_tmp4_ = _tmp3_;
		_tmp5_ = g_date_time_add_minutes (_tmp4_, minutes);
		_tmp6_ = _tmp5_;
		_g_date_time_unref0 (_tmp4_);
		datetime = _tmp6_;
		_tmp7_ = objects_reminder_new ();
		reminder = _tmp7_;
		_tmp8_ = reminder;
		_tmp9_ = objects_reminder_get_due (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = datetime;
		_tmp12_ = datetime;
		_tmp13_ = utils_datetime_get_datetime_no_seconds (_tmp11_, _tmp12_);
		_tmp14_ = _tmp13_;
		_tmp15_ = utils_datetime_get_todoist_datetime_format (_tmp14_);
		_tmp16_ = _tmp15_;
		objects_due_date_set_date (_tmp10_, _tmp16_);
		_g_free0 (_tmp16_);
		_g_date_time_unref0 (_tmp14_);
		_tmp17_ = item;
		_tmp18_ = reminder;
		objects_item_add_reminder (_tmp17_, _tmp18_);
		_g_object_unref0 (reminder);
		_g_date_time_unref0 (datetime);
	}
	_g_object_unref0 (item);
}

static void
__lambda362_ (Planify* self,
              GVariant* parameter)
{
	Planify* _tmp0_;
	Planify* _tmp1_;
	MainWindow* _tmp2_;
	const gchar* _tmp3_;
	_tmp0_ = planify_get_instance ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_->main_window;
	_tmp3_ = g_variant_get_string (parameter, NULL);
	main_window_view_item (_tmp2_, _tmp3_);
	g_application_activate ((GApplication*) self);
}

static void
___lambda362__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda362_ ((Planify*) self, parameter);
}

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		Planify* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->item);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

static void
____lambda364_ (Block2Data* _data2_,
                GObject* obj,
                GAsyncResult* res)
{
	Planify* self;
	ObjectsItem* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	self = _data2_->self;
	g_return_if_fail (res != NULL);
	_tmp0_ = _data2_->item;
	_tmp1_ = objects_item_update_next_recurrency_finish (_tmp0_, res);
	_tmp2_ = _tmp1_;
	_g_date_time_unref0 (_tmp2_);
}

static void
_____lambda364__gasync_ready_callback (GObject* source_object,
                                       GAsyncResult* res,
                                       gpointer self)
{
	____lambda364_ (self, source_object, res);
	block2_data_unref (self);
}

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

static void
__lambda363_ (Planify* self,
              GVariant* parameter)
{
	Block2Data* _data2_;
	ServicesStore* _tmp0_;
	const gchar* _tmp1_;
	ObjectsItem* _tmp2_;
	ObjectsItem* _tmp3_;
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = services_store_instance ();
	_tmp1_ = g_variant_get_string (parameter, NULL);
	_tmp2_ = services_store_get_item (_tmp0_, _tmp1_);
	_data2_->item = _tmp2_;
	_tmp3_ = _data2_->item;
	if (_tmp3_ != NULL) {
		gboolean _tmp4_ = FALSE;
		ObjectsItem* _tmp5_;
		ObjectsDueDate* _tmp6_;
		ObjectsDueDate* _tmp7_;
		gboolean _tmp8_;
		gboolean _tmp9_;
		_tmp5_ = _data2_->item;
		_tmp6_ = objects_item_get_due (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = objects_due_date_get_is_recurring (_tmp7_);
		_tmp9_ = _tmp8_;
		if (_tmp9_) {
			ObjectsItem* _tmp10_;
			ObjectsDueDate* _tmp11_;
			ObjectsDueDate* _tmp12_;
			gboolean _tmp13_;
			gboolean _tmp14_;
			_tmp10_ = _data2_->item;
			_tmp11_ = objects_item_get_due (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = objects_due_date_get_is_recurrency_end (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp4_ = !_tmp14_;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			ObjectsItem* _tmp15_;
			_tmp15_ = _data2_->item;
			objects_item_update_next_recurrency (_tmp15_, _____lambda364__gasync_ready_callback, block2_data_ref (_data2_));
		} else {
			ObjectsItem* _tmp16_;
			ObjectsItem* _tmp17_;
			GDateTime* _tmp18_;
			GDateTime* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			ServicesStore* _tmp22_;
			ObjectsItem* _tmp23_;
			_tmp16_ = _data2_->item;
			objects_item_set_checked (_tmp16_, TRUE);
			_tmp17_ = _data2_->item;
			_tmp18_ = g_date_time_new_now_local ();
			_tmp19_ = _tmp18_;
			_tmp20_ = g_date_time_to_string (_tmp19_);
			_tmp21_ = _tmp20_;
			objects_item_set_completed_at (_tmp17_, _tmp21_);
			_g_free0 (_tmp21_);
			_g_date_time_unref0 (_tmp19_);
			_tmp22_ = services_store_instance ();
			_tmp23_ = _data2_->item;
			services_store_complete_item (_tmp22_, _tmp23_, FALSE, TRUE);
		}
	}
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static void
___lambda363__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda363_ ((Planify*) self, parameter);
}

static void
__lambda365_ (Planify* self,
              GVariant* parameter)
{
	const gchar* _tmp0_;
	_tmp0_ = g_variant_get_string (parameter, NULL);
	planify_snooze_item (self, _tmp0_, 10);
}

static void
___lambda365__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda365_ ((Planify*) self, parameter);
}

static void
__lambda366_ (Planify* self,
              GVariant* parameter)
{
	const gchar* _tmp0_;
	_tmp0_ = g_variant_get_string (parameter, NULL);
	planify_snooze_item (self, _tmp0_, 30);
}

static void
___lambda366__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda366_ ((Planify*) self, parameter);
}

static void
__lambda367_ (Planify* self,
              GVariant* parameter)
{
	const gchar* _tmp0_;
	_tmp0_ = g_variant_get_string (parameter, NULL);
	planify_snooze_item (self, _tmp0_, 60);
}

static void
___lambda367__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda367_ ((Planify*) self, parameter);
}

static void
planify_build_shortcuts (Planify* self)
{
	GSimpleAction* show_item = NULL;
	const GVariantType* _tmp0_;
	GSimpleAction* _tmp1_;
	GSimpleAction* complete = NULL;
	const GVariantType* _tmp2_;
	GSimpleAction* _tmp3_;
	GSimpleAction* snooze_10 = NULL;
	const GVariantType* _tmp4_;
	GSimpleAction* _tmp5_;
	GSimpleAction* snooze_30 = NULL;
	const GVariantType* _tmp6_;
	GSimpleAction* _tmp7_;
	GSimpleAction* snooze_60 = NULL;
	const GVariantType* _tmp8_;
	GSimpleAction* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = G_VARIANT_TYPE_STRING;
	_tmp1_ = g_simple_action_new ("show-item", _tmp0_);
	show_item = _tmp1_;
	g_signal_connect_object (show_item, "activate", (GCallback) ___lambda362__g_simple_action_activate, self, 0);
	_tmp2_ = G_VARIANT_TYPE_STRING;
	_tmp3_ = g_simple_action_new ("complete", _tmp2_);
	complete = _tmp3_;
	g_signal_connect_object (complete, "activate", (GCallback) ___lambda363__g_simple_action_activate, self, 0);
	_tmp4_ = G_VARIANT_TYPE_STRING;
	_tmp5_ = g_simple_action_new ("snooze-10", _tmp4_);
	snooze_10 = _tmp5_;
	g_signal_connect_object (snooze_10, "activate", (GCallback) ___lambda365__g_simple_action_activate, self, 0);
	_tmp6_ = G_VARIANT_TYPE_STRING;
	_tmp7_ = g_simple_action_new ("snooze-30", _tmp6_);
	snooze_30 = _tmp7_;
	g_signal_connect_object (snooze_30, "activate", (GCallback) ___lambda366__g_simple_action_activate, self, 0);
	_tmp8_ = G_VARIANT_TYPE_STRING;
	_tmp9_ = g_simple_action_new ("snooze-60", _tmp8_);
	snooze_60 = _tmp9_;
	g_signal_connect_object (snooze_60, "activate", (GCallback) ___lambda367__g_simple_action_activate, self, 0);
	g_action_map_add_action ((GActionMap*) self, (GAction*) show_item);
	g_action_map_add_action ((GActionMap*) self, (GAction*) complete);
	g_action_map_add_action ((GActionMap*) self, (GAction*) snooze_10);
	g_action_map_add_action ((GActionMap*) self, (GAction*) snooze_30);
	g_action_map_add_action ((GActionMap*) self, (GAction*) snooze_60);
	_g_object_unref0 (snooze_60);
	_g_object_unref0 (snooze_30);
	_g_object_unref0 (snooze_10);
	_g_object_unref0 (complete);
	_g_object_unref0 (show_item);
}

static gint
planify_main (gchar** args,
              gint args_length1)
{
	Planify* app = NULL;
	Planify* _tmp0_;
	Planify* _tmp1_;
	Planify* _tmp2_;
	gint result;
	_tmp0_ = planify_get_instance ();
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	app = _tmp2_;
	result = g_application_run ((GApplication*) app, (gint) args_length1, args);
	_g_object_unref0 (app);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return planify_main (argv, argc);
}

Planify*
planify_get_instance (void)
{
	Planify* result;
	Planify* _tmp0_;
	Planify* _tmp2_;
	_tmp0_ = planify__instance;
	if (_tmp0_ == NULL) {
		Planify* _tmp1_;
		_tmp1_ = planify_new ();
		_g_object_unref0 (planify__instance);
		planify__instance = _tmp1_;
	}
	_tmp2_ = planify__instance;
	result = _tmp2_;
	return result;
}

static GObject *
planify_constructor (GType type,
                     guint n_construct_properties,
                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	Planify * self;
	gchar* langpack_dir = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	parent_class = G_OBJECT_CLASS (planify_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PLANIFY, Planify);
	setlocale (LC_ALL, "");
	_tmp0_ = g_build_filename (BUILD_INSTALL_PREFIX, "share", "locale", NULL);
	langpack_dir = _tmp0_;
	_tmp1_ = langpack_dir;
	bindtextdomain (BUILD_GETTEXT_PACKAGE, _tmp1_);
	bind_textdomain_codeset (BUILD_GETTEXT_PACKAGE, "UTF-8");
	textdomain (BUILD_GETTEXT_PACKAGE);
	g_application_add_main_option_entries ((GApplication*) self, PLANIFY_OPTIONS);
	planify_create_dir_with_parents (self, "/io.github.alainm23.planify");
	planify_create_dir_with_parents (self, "/io.github.alainm23.planify/backups");
	_g_free0 (langpack_dir);
	return obj;
}

static void
planify_class_init (PlanifyClass * klass,
                    gpointer klass_data)
{
	gchar* _tmp0_;
	planify_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &Planify_private_offset);
	((GApplicationClass *) klass)->open = (void (*) (GApplication*, GFile**, gint, const gchar*)) planify_real_open;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) planify_real_activate;
	G_OBJECT_CLASS (klass)->get_property = _vala_planify_get_property;
	G_OBJECT_CLASS (klass)->constructor = planify_constructor;
	G_OBJECT_CLASS (klass)->finalize = planify_finalize;
	_tmp0_ = g_strdup ("");
	planify_lang = _tmp0_;
}

static void
planify_instance_init (Planify * self,
                       gpointer klass)
{
	self->priv = planify_get_instance_private (self);
	self->priv->portal = NULL;
}

static void
planify_finalize (GObject * obj)
{
	Planify * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PLANIFY, Planify);
	g_debug ("App.vala:63: Destroying Planify\n");
	_g_object_unref0 (self->main_window);
	_g_object_unref0 (self->priv->portal);
	G_OBJECT_CLASS (planify_parent_class)->finalize (obj);
}

static GType
planify_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PlanifyClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) planify_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Planify), 0, (GInstanceInitFunc) planify_instance_init, NULL };
	GType planify_type_id;
	planify_type_id = g_type_register_static (adw_application_get_type (), "Planify", &g_define_type_info, 0);
	Planify_private_offset = g_type_add_instance_private (planify_type_id, sizeof (PlanifyPrivate));
	return planify_type_id;
}

GType
planify_get_type (void)
{
	static volatile gsize planify_type_id__once = 0;
	if (g_once_init_enter (&planify_type_id__once)) {
		GType planify_type_id;
		planify_type_id = planify_get_type_once ();
		g_once_init_leave (&planify_type_id__once, planify_type_id);
	}
	return planify_type_id__once;
}

static void
_vala_planify_get_property (GObject * object,
                            guint property_id,
                            GValue * value,
                            GParamSpec * pspec)
{
	Planify * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PLANIFY, Planify);
	switch (property_id) {
		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;
}

