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

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

#include "ft_core.h"
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	FT_ACTION_MANAGER_0_PROPERTY,
	FT_ACTION_MANAGER_MODEL_PROPERTY,
	FT_ACTION_MANAGER_NUM_PROPERTIES
};
static GParamSpec* ft_action_manager_properties[FT_ACTION_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_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _ft_notification_unref0(var) ((var == NULL) ? NULL : (var = (ft_notification_unref (var), NULL)))
typedef struct _Block2Data Block2Data;

struct _FtActionManagerPrivate {
	FtActionListModel* _model;
	FtLogger* logger;
	FtNotificationBackend* notification_backend;
};

struct _Block2Data {
	int _ref_count_;
	FtActionManager* self;
	FtAction* action;
	FtCommandExecution* execution;
	gulong entry_id;
};

static gint FtActionManager_private_offset;
static gpointer ft_action_manager_parent_class = NULL;

static void ft_action_manager_foreach_action (FtActionManager* self,
                                       GFunc func,
                                       gpointer func_target);
static void ft_action_manager_bind_action (FtActionManager* self,
                                    FtAction* action);
static void ft_action_manager_on_action_notify_enabled (FtActionManager* self,
                                                 GObject* object,
                                                 GParamSpec* pspec);
static void _ft_action_manager_on_action_notify_enabled_g_object_notify (GObject* _sender,
                                                                  GParamSpec* pspec,
                                                                  gpointer self);
static void ft_action_manager_on_triggered (FtActionManager* self,
                                     FtEventAction* action,
                                     FtContext* context,
                                     FtCommandExecution* execution);
static void _ft_action_manager_on_triggered_ft_event_action_triggered (FtEventAction* _sender,
                                                                FtContext* context,
                                                                FtCommandExecution* execution,
                                                                gpointer self);
static void ft_action_manager_on_entered_condition (FtActionManager* self,
                                             FtConditionAction* action,
                                             FtContext* context,
                                             FtCommandExecution* execution);
static void _ft_action_manager_on_entered_condition_ft_condition_action_entered_condition (FtConditionAction* _sender,
                                                                                    FtContext* context,
                                                                                    FtCommandExecution* execution,
                                                                                    gpointer self);
static void ft_action_manager_on_exited_condition (FtActionManager* self,
                                            FtConditionAction* action,
                                            FtContext* context,
                                            FtCommandExecution* execution);
static void _ft_action_manager_on_exited_condition_ft_condition_action_exited_condition (FtConditionAction* _sender,
                                                                                  FtContext* context,
                                                                                  FtCommandExecution* execution,
                                                                                  gpointer self);
static void ft_action_manager_unbind_action (FtActionManager* self,
                                      FtAction* action);
static void ft_action_manager_bind_actions (FtActionManager* self);
static void __lambda81_ (FtActionManager* self,
                  FtAction* action);
static void ___lambda81__gfunc (gconstpointer data,
                         gpointer self);
static void ft_action_manager_unbind_actions (FtActionManager* self);
static void __lambda82_ (FtActionManager* self,
                  FtAction* action);
static void ___lambda82__gfunc (gconstpointer data,
                         gpointer self);
static void ft_action_manager_notify_action_failed (FtActionManager* self,
                                             FtAction* action,
                                             FtCommandExecution* execution,
                                             gulong entry_id);
static void ft_action_manager_watch_action_failed (FtActionManager* self,
                                            FtAction* action,
                                            FtCommandExecution* execution,
                                            gulong entry_id);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void ___lambda80_ (Block2Data* _data2_);
static void ____lambda80__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void ft_action_manager_on_action_added (FtActionManager* self,
                                        FtAction* action);
static void ft_action_manager_on_action_removed (FtActionManager* self,
                                          FtAction* action);
static void _ft_action_manager_on_action_added_ft_action_list_model_action_added (FtActionListModel* _sender,
                                                                           FtAction* action,
                                                                           gpointer self);
static void _ft_action_manager_on_action_removed_ft_action_list_model_action_removed (FtActionListModel* _sender,
                                                                               FtAction* action,
                                                                               gpointer self);
static void ft_action_manager_real_dispose (GObject* base);
static GObject * ft_action_manager_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static void ft_action_manager_finalize (GObject * obj);
static GType ft_action_manager_get_type_once (void);
static void _vala_ft_action_manager_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_ft_action_manager_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
ft_action_manager_get_instance_private (FtActionManager* self)
{
	return G_STRUCT_MEMBER_P (self, FtActionManager_private_offset);
}

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

static void
ft_action_manager_foreach_action (FtActionManager* self,
                                  GFunc func,
                                  gpointer func_target)
{
	FtActionListModel* _tmp0_;
	FtActionListModel* model = NULL;
	FtActionListModel* _tmp1_;
	FtActionListModel* _tmp2_;
	guint n_items = 0U;
	FtActionListModel* _tmp3_;
	guint _tmp4_;
	guint _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_model;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->_model;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	model = _tmp2_;
	_tmp3_ = model;
	_tmp4_ = ft_action_list_model_get_n_items (_tmp3_);
	_tmp5_ = _tmp4_;
	n_items = _tmp5_;
	{
		guint position = 0U;
		position = 0U;
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				FtActionListModel* _tmp8_;
				GObject* _tmp9_;
				FtAction* _tmp10_;
				if (!_tmp6_) {
					guint _tmp7_;
					_tmp7_ = position;
					position = _tmp7_ + 1;
				}
				_tmp6_ = FALSE;
				if (!(position < n_items)) {
					break;
				}
				_tmp8_ = model;
				_tmp9_ = g_list_model_get_item ((GListModel*) _tmp8_, position);
				_tmp10_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, FT_TYPE_ACTION, FtAction);
				func (_tmp10_, func_target);
				_g_object_unref0 (_tmp10_);
			}
		}
	}
	_g_object_unref0 (model);
}

static void
_ft_action_manager_on_action_notify_enabled_g_object_notify (GObject* _sender,
                                                             GParamSpec* pspec,
                                                             gpointer self)
{
	ft_action_manager_on_action_notify_enabled ((FtActionManager*) self, _sender, pspec);
}

static void
_ft_action_manager_on_triggered_ft_event_action_triggered (FtEventAction* _sender,
                                                           FtContext* context,
                                                           FtCommandExecution* execution,
                                                           gpointer self)
{
	ft_action_manager_on_triggered ((FtActionManager*) self, _sender, context, execution);
}

static void
_ft_action_manager_on_entered_condition_ft_condition_action_entered_condition (FtConditionAction* _sender,
                                                                               FtContext* context,
                                                                               FtCommandExecution* execution,
                                                                               gpointer self)
{
	ft_action_manager_on_entered_condition ((FtActionManager*) self, _sender, context, execution);
}

static void
_ft_action_manager_on_exited_condition_ft_condition_action_exited_condition (FtConditionAction* _sender,
                                                                             FtContext* context,
                                                                             FtCommandExecution* execution,
                                                                             gpointer self)
{
	ft_action_manager_on_exited_condition ((FtActionManager*) self, _sender, context, execution);
}

static void
ft_action_manager_bind_action (FtActionManager* self,
                               FtAction* action)
{
	FtEventAction* event_action = NULL;
	FtEventAction* _tmp0_;
	FtEventAction* _tmp1_;
	FtConditionAction* condition_action = NULL;
	FtConditionAction* _tmp3_;
	FtConditionAction* _tmp4_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_signal_connect_object ((GObject*) action, "notify::enabled", (GCallback) _ft_action_manager_on_action_notify_enabled_g_object_notify, self, 0);
	_tmp0_ = _g_object_ref0 (FT_IS_EVENT_ACTION (action) ? ((FtEventAction*) action) : NULL);
	event_action = _tmp0_;
	_tmp1_ = event_action;
	if (_tmp1_ != NULL) {
		FtEventAction* _tmp2_;
		_tmp2_ = event_action;
		g_signal_connect_object (_tmp2_, "triggered", (GCallback) _ft_action_manager_on_triggered_ft_event_action_triggered, self, 0);
	}
	_tmp3_ = _g_object_ref0 (FT_IS_CONDITION_ACTION (action) ? ((FtConditionAction*) action) : NULL);
	condition_action = _tmp3_;
	_tmp4_ = condition_action;
	if (_tmp4_ != NULL) {
		FtConditionAction* _tmp5_;
		FtConditionAction* _tmp6_;
		_tmp5_ = condition_action;
		g_signal_connect_object (_tmp5_, "entered-condition", (GCallback) _ft_action_manager_on_entered_condition_ft_condition_action_entered_condition, self, 0);
		_tmp6_ = condition_action;
		g_signal_connect_object (_tmp6_, "exited-condition", (GCallback) _ft_action_manager_on_exited_condition_ft_condition_action_exited_condition, self, 0);
	}
	_tmp7_ = ft_action_get_enabled (action);
	_tmp8_ = _tmp7_;
	if (_tmp8_) {
		ft_action_bind (action);
	}
	_g_object_unref0 (condition_action);
	_g_object_unref0 (event_action);
}

static void
ft_action_manager_unbind_action (FtActionManager* self,
                                 FtAction* action)
{
	guint _tmp0_;
	GQuark _tmp1_;
	FtEventAction* event_action = NULL;
	FtEventAction* _tmp2_;
	FtEventAction* _tmp3_;
	FtConditionAction* condition_action = NULL;
	FtConditionAction* _tmp6_;
	FtConditionAction* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_signal_parse_name ("notify::enabled", G_TYPE_OBJECT, &_tmp0_, &_tmp1_, TRUE);
	g_signal_handlers_disconnect_matched ((GObject*) action, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, _tmp1_, NULL, (GCallback) _ft_action_manager_on_action_notify_enabled_g_object_notify, self);
	_tmp2_ = _g_object_ref0 (FT_IS_EVENT_ACTION (action) ? ((FtEventAction*) action) : NULL);
	event_action = _tmp2_;
	_tmp3_ = event_action;
	if (_tmp3_ != NULL) {
		FtEventAction* _tmp4_;
		guint _tmp5_;
		_tmp4_ = event_action;
		g_signal_parse_name ("triggered", FT_TYPE_EVENT_ACTION, &_tmp5_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp4_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _ft_action_manager_on_triggered_ft_event_action_triggered, self);
	}
	_tmp6_ = _g_object_ref0 (FT_IS_CONDITION_ACTION (action) ? ((FtConditionAction*) action) : NULL);
	condition_action = _tmp6_;
	_tmp7_ = condition_action;
	if (_tmp7_ != NULL) {
		FtConditionAction* _tmp8_;
		guint _tmp9_;
		FtConditionAction* _tmp10_;
		guint _tmp11_;
		_tmp8_ = condition_action;
		g_signal_parse_name ("entered-condition", FT_TYPE_CONDITION_ACTION, &_tmp9_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp8_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp9_, 0, NULL, (GCallback) _ft_action_manager_on_entered_condition_ft_condition_action_entered_condition, self);
		_tmp10_ = condition_action;
		g_signal_parse_name ("exited-condition", FT_TYPE_CONDITION_ACTION, &_tmp11_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp10_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp11_, 0, NULL, (GCallback) _ft_action_manager_on_exited_condition_ft_condition_action_exited_condition, self);
	}
	ft_action_unbind (action);
	_g_object_unref0 (condition_action);
	_g_object_unref0 (event_action);
}

static void
__lambda81_ (FtActionManager* self,
             FtAction* action)
{
	g_return_if_fail (action != NULL);
	ft_action_manager_bind_action (self, action);
}

static void
___lambda81__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda81_ ((FtActionManager*) self, (FtAction*) data);
}

static void
ft_action_manager_bind_actions (FtActionManager* self)
{
	g_return_if_fail (self != NULL);
	ft_action_manager_foreach_action (self, ___lambda81__gfunc, self);
}

static void
__lambda82_ (FtActionManager* self,
             FtAction* action)
{
	g_return_if_fail (action != NULL);
	ft_action_manager_unbind_action (self, action);
}

static void
___lambda82__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda82_ ((FtActionManager*) self, (FtAction*) data);
}

static void
ft_action_manager_unbind_actions (FtActionManager* self)
{
	g_return_if_fail (self != NULL);
	ft_action_manager_foreach_action (self, ___lambda82__gfunc, self);
}

/**
         * We don't notify about validation errors
         */
static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
ft_action_manager_notify_action_failed (FtActionManager* self,
                                        FtAction* action,
                                        FtCommandExecution* execution,
                                        gulong entry_id)
{
	const gchar* _tmp0_ = NULL;
	GError* _tmp1_;
	GError* _tmp2_;
	FtNotification* notification = NULL;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	FtNotification* _tmp10_;
	FtNotification* _tmp11_;
	gchar* _tmp12_;
	GVariant* _tmp13_;
	GVariant* _tmp14_;
	FtNotificationBackend* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_return_if_fail (execution != NULL);
	_tmp1_ = ft_job_get_error ((FtJob*) execution);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != NULL) {
		GError* _tmp3_;
		GError* _tmp4_;
		const gchar* _tmp5_;
		_tmp3_ = ft_job_get_error ((FtJob*) execution);
		_tmp4_ = _tmp3_;
		_tmp5_ = _tmp4_->message;
		_tmp0_ = _tmp5_;
	} else {
		_tmp0_ = "";
	}
	_tmp6_ = ft_action_get_display_name (action);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup_printf (_ ("Custom action \"%s\" has failed"), _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = ft_notification_new (_tmp9_, _tmp0_);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	notification = _tmp11_;
	_tmp12_ = g_strdup ("action-failed");
	_g_free0 (notification->event_id);
	notification->event_id = _tmp12_;
	_tmp13_ = g_variant_new_uint64 ((guint64) entry_id);
	g_variant_ref_sink (_tmp13_);
	_tmp14_ = _tmp13_;
	ft_notification_set_default_action_and_target_value (notification, "app.log", _tmp14_);
	_g_variant_unref0 (_tmp14_);
	_tmp15_ = self->priv->notification_backend;
	_tmp16_ = ft_action_get_uuid (action);
	_tmp17_ = _tmp16_;
	_tmp18_ = string_to_string (_tmp17_);
	_tmp19_ = g_strconcat ("action:", _tmp18_, NULL);
	_tmp20_ = _tmp19_;
	ft_notification_backend_interface_send_notification ((FtNotificationBackendInterface*) _tmp15_, _tmp20_, notification);
	_g_free0 (_tmp20_);
	_ft_notification_unref0 (notification);
}

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_)) {
		FtActionManager* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->action);
		_g_object_unref0 (_data2_->execution);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

static void
___lambda80_ (Block2Data* _data2_)
{
	FtActionManager* self;
	self = _data2_->self;
	ft_action_manager_notify_action_failed (self, _data2_->action, _data2_->execution, _data2_->entry_id);
}

static void
____lambda80__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	___lambda80_ (self);
}

static void
ft_action_manager_watch_action_failed (FtActionManager* self,
                                       FtAction* action,
                                       FtCommandExecution* execution,
                                       gulong entry_id)
{
	Block2Data* _data2_;
	FtAction* _tmp0_;
	FtCommandExecution* _tmp1_;
	GError* _tmp2_;
	GError* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (action);
	_g_object_unref0 (_data2_->action);
	_data2_->action = _tmp0_;
	_tmp1_ = _g_object_ref0 (execution);
	_g_object_unref0 (_data2_->execution);
	_data2_->execution = _tmp1_;
	_data2_->entry_id = entry_id;
	if (_data2_->execution == NULL) {
		block2_data_unref (_data2_);
		_data2_ = NULL;
		return;
	}
	_tmp2_ = ft_job_get_error ((FtJob*) _data2_->execution);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != NULL) {
		ft_action_manager_notify_action_failed (self, _data2_->action, _data2_->execution, _data2_->entry_id);
	} else {
		g_signal_connect_data ((GObject*) _data2_->execution, "notify::error", (GCallback) ____lambda80__g_object_notify, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	}
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static void
ft_action_manager_on_action_notify_enabled (FtActionManager* self,
                                            GObject* object,
                                            GParamSpec* pspec)
{
	FtAction* action = NULL;
	FtAction* _tmp0_;
	FtAction* _tmp1_;
	GSettings* _tmp2_;
	GSettings* _tmp3_;
	FtAction* _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	FtAction* _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_ACTION, FtAction));
	action = _tmp0_;
	_tmp1_ = action;
	_tmp2_ = ft_action_get_settings (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = action;
	_tmp5_ = ft_action_get_enabled (_tmp4_);
	_tmp6_ = _tmp5_;
	g_settings_set_boolean (_tmp3_, "enabled", _tmp6_);
	_tmp7_ = action;
	_tmp8_ = ft_action_get_enabled (_tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_) {
		FtAction* _tmp10_;
		_tmp10_ = action;
		ft_action_bind (_tmp10_);
	} else {
		FtAction* _tmp11_;
		_tmp11_ = action;
		ft_action_unbind (_tmp11_);
	}
	_g_object_unref0 (action);
}

static void
ft_action_manager_on_triggered (FtActionManager* self,
                                FtEventAction* action,
                                FtContext* context,
                                FtCommandExecution* execution)
{
	gulong entry_id = 0UL;
	FtLogger* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = self->priv->logger;
	entry_id = ft_logger_log_action_triggered (_tmp0_, action, context, execution);
	ft_action_manager_watch_action_failed (self, (FtAction*) action, execution, entry_id);
}

static void
ft_action_manager_on_entered_condition (FtActionManager* self,
                                        FtConditionAction* action,
                                        FtContext* context,
                                        FtCommandExecution* execution)
{
	gulong entry_id = 0UL;
	FtLogger* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = self->priv->logger;
	entry_id = ft_logger_log_action_entered_condition (_tmp0_, action, context, execution);
	ft_action_manager_watch_action_failed (self, (FtAction*) action, execution, entry_id);
}

static void
ft_action_manager_on_exited_condition (FtActionManager* self,
                                       FtConditionAction* action,
                                       FtContext* context,
                                       FtCommandExecution* execution)
{
	gulong entry_id = 0UL;
	FtLogger* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = self->priv->logger;
	entry_id = ft_logger_log_action_exited_condition (_tmp0_, action, context, execution);
	ft_action_manager_watch_action_failed (self, (FtAction*) action, execution, entry_id);
}

static void
ft_action_manager_on_action_added (FtActionManager* self,
                                   FtAction* action)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	ft_action_manager_bind_action (self, action);
}

static void
ft_action_manager_on_action_removed (FtActionManager* self,
                                     FtAction* action)
{
	FtNotificationBackend* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	ft_action_manager_unbind_action (self, action);
	_tmp0_ = self->priv->notification_backend;
	_tmp1_ = ft_action_get_uuid (action);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_to_string (_tmp2_);
	_tmp4_ = g_strconcat ("action:", _tmp3_, NULL);
	_tmp5_ = _tmp4_;
	ft_notification_backend_interface_withdraw_notification ((FtNotificationBackendInterface*) _tmp0_, _tmp5_);
	_g_free0 (_tmp5_);
}

static void
_ft_action_manager_on_action_added_ft_action_list_model_action_added (FtActionListModel* _sender,
                                                                      FtAction* action,
                                                                      gpointer self)
{
	ft_action_manager_on_action_added ((FtActionManager*) self, action);
}

static void
_ft_action_manager_on_action_removed_ft_action_list_model_action_removed (FtActionListModel* _sender,
                                                                          FtAction* action,
                                                                          gpointer self)
{
	ft_action_manager_on_action_removed ((FtActionManager*) self, action);
}

void
ft_action_manager_destroy (FtActionManager* self)
{
	FtActionListModel* _tmp0_;
	g_return_if_fail (self != NULL);
	ft_action_manager_unbind_actions (self);
	_tmp0_ = self->priv->_model;
	if (_tmp0_ != NULL) {
		FtActionListModel* _tmp1_;
		guint _tmp2_;
		FtActionListModel* _tmp3_;
		guint _tmp4_;
		_tmp1_ = self->priv->_model;
		g_signal_parse_name ("action-added", FT_TYPE_ACTION_LIST_MODEL, &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _ft_action_manager_on_action_added_ft_action_list_model_action_added, self);
		_tmp3_ = self->priv->_model;
		g_signal_parse_name ("action-removed", FT_TYPE_ACTION_LIST_MODEL, &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _ft_action_manager_on_action_removed_ft_action_list_model_action_removed, self);
	}
}

static void
ft_action_manager_real_dispose (GObject* base)
{
	FtActionManager * self;
	self = (FtActionManager*) base;
	ft_action_manager_destroy (self);
	_g_object_unref0 (self->priv->logger);
	self->priv->logger = NULL;
	_g_object_unref0 (self->priv->notification_backend);
	self->priv->notification_backend = NULL;
	G_OBJECT_CLASS (ft_action_manager_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

FtActionManager*
ft_action_manager_construct (GType object_type)
{
	FtActionManager * self = NULL;
	self = (FtActionManager*) g_object_new (object_type, NULL);
	return self;
}

FtActionManager*
ft_action_manager_new (void)
{
	return ft_action_manager_construct (FT_TYPE_ACTION_MANAGER);
}

FtActionListModel*
ft_action_manager_get_model (FtActionManager* self)
{
	FtActionListModel* result;
	FtActionListModel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_model;
	result = _tmp0_;
	return result;
}

static void
ft_action_manager_set_model (FtActionManager* self,
                             FtActionListModel* value)
{
	FtActionListModel* old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_action_manager_get_model (self);
	if (old_value != value) {
		FtActionListModel* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_model);
		self->priv->_model = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, ft_action_manager_properties[FT_ACTION_MANAGER_MODEL_PROPERTY]);
	}
}

static GObject *
ft_action_manager_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	static GWeakRef FtActionManager_singleton__ref;
	static GMutex FtActionManager_singleton__lock;
	FtActionManager * self;
	FtActionListModel* _tmp0_;
	FtActionListModel* _tmp1_;
	FtActionListModel* _tmp2_;
	FtActionListModel* _tmp3_;
	FtLogger* _tmp4_;
	FtNotificationBackend* _tmp5_;
	g_mutex_lock (&FtActionManager_singleton__lock);
	obj = g_weak_ref_get (&FtActionManager_singleton__ref);
	if (obj != NULL) {
		g_mutex_unlock (&FtActionManager_singleton__lock);
		return obj;
	}
	parent_class = G_OBJECT_CLASS (ft_action_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_ACTION_MANAGER, FtActionManager);
	_tmp0_ = ft_action_list_model_new ();
	_tmp1_ = _tmp0_;
	ft_action_manager_set_model (self, _tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = self->priv->_model;
	g_signal_connect_object (_tmp2_, "action-added", (GCallback) _ft_action_manager_on_action_added_ft_action_list_model_action_added, self, 0);
	_tmp3_ = self->priv->_model;
	g_signal_connect_object (_tmp3_, "action-removed", (GCallback) _ft_action_manager_on_action_removed_ft_action_list_model_action_removed, self, 0);
	_tmp4_ = ft_logger_new ();
	_g_object_unref0 (self->priv->logger);
	self->priv->logger = _tmp4_;
	_tmp5_ = ft_notification_backend_new ();
	_g_object_unref0 (self->priv->notification_backend);
	self->priv->notification_backend = _tmp5_;
	ft_action_manager_bind_actions (self);
	g_weak_ref_set (&FtActionManager_singleton__ref, obj);
	g_mutex_unlock (&FtActionManager_singleton__lock);
	return obj;
}

static void
ft_action_manager_class_init (FtActionManagerClass * klass,
                              gpointer klass_data)
{
	ft_action_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtActionManager_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_action_manager_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_action_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_action_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_action_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_action_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_ACTION_MANAGER_MODEL_PROPERTY, ft_action_manager_properties[FT_ACTION_MANAGER_MODEL_PROPERTY] = g_param_spec_object ("model", "model", "model", FT_TYPE_ACTION_LIST_MODEL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
ft_action_manager_instance_init (FtActionManager * self,
                                 gpointer klass)
{
	self->priv = ft_action_manager_get_instance_private (self);
	self->priv->logger = NULL;
	self->priv->notification_backend = NULL;
}

static void
ft_action_manager_finalize (GObject * obj)
{
	FtActionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_ACTION_MANAGER, FtActionManager);
	_g_object_unref0 (self->priv->_model);
	_g_object_unref0 (self->priv->logger);
	_g_object_unref0 (self->priv->notification_backend);
	G_OBJECT_CLASS (ft_action_manager_parent_class)->finalize (obj);
}

/**
     * Glue together actions storage with event bus and logger (for things related to actions).
     */
static GType
ft_action_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtActionManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_action_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtActionManager), 0, (GInstanceInitFunc) ft_action_manager_instance_init, NULL };
	GType ft_action_manager_type_id;
	ft_action_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "FtActionManager", &g_define_type_info, 0);
	FtActionManager_private_offset = g_type_add_instance_private (ft_action_manager_type_id, sizeof (FtActionManagerPrivate));
	return ft_action_manager_type_id;
}

GType
ft_action_manager_get_type (void)
{
	static volatile gsize ft_action_manager_type_id__once = 0;
	if (g_once_init_enter (&ft_action_manager_type_id__once)) {
		GType ft_action_manager_type_id;
		ft_action_manager_type_id = ft_action_manager_get_type_once ();
		g_once_init_leave (&ft_action_manager_type_id__once, ft_action_manager_type_id);
	}
	return ft_action_manager_type_id__once;
}

static void
_vala_ft_action_manager_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	FtActionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_ACTION_MANAGER, FtActionManager);
	switch (property_id) {
		case FT_ACTION_MANAGER_MODEL_PROPERTY:
		g_value_set_object (value, ft_action_manager_get_model (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_action_manager_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	FtActionManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_ACTION_MANAGER, FtActionManager);
	switch (property_id) {
		case FT_ACTION_MANAGER_MODEL_PROPERTY:
		ft_action_manager_set_model (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

