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

/*
 * Copyright (c) 2026 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_plugin_mpris.h"
#include <gio/gio.h>
#include "ft_core.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include "ft_ui.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  {
	MPRIS_APPLICATION_EXTENSION_0_PROPERTY,
	MPRIS_APPLICATION_EXTENSION_NUM_PROPERTIES
};
static GParamSpec* mpris_application_extension_properties[MPRIS_APPLICATION_EXTENSION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef void (*MprisNameOwnerChangedFunc) (GDBusConnection* connection, const gchar* name, const gchar* old_owner, const gchar* new_owner, gpointer user_data);
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block1Data Block1Data;
typedef struct _Block2Data Block2Data;
typedef struct _Block3Data Block3Data;
typedef struct _Block4Data Block4Data;
typedef struct _Block5Data Block5Data;
typedef struct _Block6Data Block6Data;
typedef struct _Block7Data Block7Data;
typedef struct _Block8Data Block8Data;

struct _MprisApplicationExtensionPrivate {
	GSettings* settings;
	FtTimer* timer;
	FtSessionManager* session_manager;
	GCancellable* cancellable;
	GDBusConnection* connection;
	guint name_owner_changed_id;
	GHashTable* players;
	FtState effective_state;
	FtSoundManager* sound_manager;
	gboolean background_sound_inhibited;
};

struct _Block1Data {
	int _ref_count_;
	MprisApplicationExtension* self;
	GFunc func;
	gpointer func_target;
};

struct _Block2Data {
	int _ref_count_;
	MprisApplicationExtension* self;
	guint playing_count;
};

struct _Block3Data {
	int _ref_count_;
	MprisApplicationExtension* self;
	gboolean can_resume;
};

struct _Block4Data {
	int _ref_count_;
	MprisApplicationExtension* self;
	FtState assigned_state;
};

struct _Block5Data {
	int _ref_count_;
	Block4Data * _data4_;
	MprisPlayerWrapper* player;
};

struct _Block6Data {
	int _ref_count_;
	MprisApplicationExtension* self;
	gboolean can_resume;
	gboolean resuming;
	FtState assigned_state;
};

struct _Block7Data {
	int _ref_count_;
	Block6Data * _data6_;
	MprisPlayerWrapper* player;
};

struct _Block8Data {
	int _ref_count_;
	MprisApplicationExtension* self;
	FtState effective_state;
};

static gint MprisApplicationExtension_private_offset;
static gpointer mpris_application_extension_parent_class = NULL;
static GType mpris_application_extension_type_id = 0;

static void mpris_application_extension_init (MprisApplicationExtension* self,
                                       gint timeout);
VALA_EXTERN guint mpris_dbus_subscribe_name_owner_changed (GDBusConnection* connection,
                                               MprisNameOwnerChangedFunc func,
                                               gpointer func_target);
static void mpris_application_extension_on_name_owner_changed (MprisApplicationExtension* self,
                                                        GDBusConnection* connection,
                                                        const gchar* dbus_name,
                                                        const gchar* old_owner,
                                                        const gchar* new_owner);
static void _mpris_application_extension_on_name_owner_changed_mpris_name_owner_changed_func (GDBusConnection* connection,
                                                                                       const gchar* name,
                                                                                       const gchar* old_owner,
                                                                                       const gchar* new_owner,
                                                                                       gpointer self);
VALA_EXTERN gchar** mpris_list_dbus_names (GDBusConnection* connection,
                               gint timeout,
                               gint* result_length1);
static void mpris_application_extension_add_player (MprisApplicationExtension* self,
                                             const gchar* dbus_name);
static void mpris_application_extension_update_background_sound_inhibitor (MprisApplicationExtension* self);
static void mpris_application_extension_enable (MprisApplicationExtension* self);
static inline void mpris_application_extension_foreach_player (MprisApplicationExtension* self,
                                                 GFunc func,
                                                 gpointer func_target);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda7_ (Block1Data* _data1_,
                 const gchar* bus_name,
                 MprisPlayerWrapper* player);
static void ___lambda7__gh_func (gconstpointer key,
                          gconstpointer value,
                          gpointer self);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void __lambda8_ (Block2Data* _data2_,
                 MprisPlayerWrapper* player);
static void ___lambda8__gfunc (gconstpointer data,
                        gpointer self);
static void mpris_application_extension_on_timer_state_changed (MprisApplicationExtension* self,
                                                         const FtTimerState* current_state,
                                                         const FtTimerState* previous_state);
static void _mpris_application_extension_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                                 const FtTimerState* current_state,
                                                                                 const FtTimerState* previous_state,
                                                                                 gpointer self);
static void mpris_application_extension_disable (MprisApplicationExtension* self);
static void __lambda15_ (MprisApplicationExtension* self,
                  MprisPlayerWrapper* player);
static void ___lambda15__gfunc (gconstpointer data,
                         gpointer self);
static void mpris_application_extension_on_player_status_changed (MprisApplicationExtension* self,
                                                           MprisPlayerWrapper* player,
                                                           MprisPlaybackStatus status,
                                                           MprisPlaybackStatus previous_status);
static void _mpris_application_extension_on_player_status_changed_mpris_player_wrapper_status_changed (MprisPlayerWrapper* _sender,
                                                                                                MprisPlaybackStatus status,
                                                                                                MprisPlaybackStatus previous_status,
                                                                                                gpointer self);
static void mpris_application_extension_remove_player (MprisApplicationExtension* self,
                                                const gchar* dbus_name);
static gboolean mpris_application_extension_can_resume_playback (MprisApplicationExtension* self);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda12_ (Block3Data* _data3_,
                  MprisPlayerWrapper* player);
static void ___lambda12__gfunc (gconstpointer data,
                         gpointer self);
static void mpris_application_extension_pause_playback (MprisApplicationExtension* self,
                                                 FtState assigned_state);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void __lambda10_ (Block4Data* _data4_,
                  MprisPlayerWrapper* player);
static Block5Data* block5_data_ref (Block5Data* _data5_);
static void block5_data_unref (void * _userdata_);
static void __lambda11_ (Block5Data* _data5_,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda11__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void ___lambda10__gfunc (gconstpointer data,
                         gpointer self);
static void mpris_application_extension_resume_playback (MprisApplicationExtension* self,
                                                  FtState assigned_state);
static Block6Data* block6_data_ref (Block6Data* _data6_);
static void block6_data_unref (void * _userdata_);
static void __lambda13_ (Block6Data* _data6_,
                  MprisPlayerWrapper* player);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static void ___lambda14_ (Block7Data* _data7_,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda14__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void ___lambda13__gfunc (gconstpointer data,
                         gpointer self);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static void ___lambda9_ (Block8Data* _data8_,
                  MprisPlayerWrapper* player);
static void ____lambda9__gfunc (gconstpointer data,
                         gpointer self);
static void mpris_application_extension_on_settings_changed (MprisApplicationExtension* self,
                                                      GSettings* settings,
                                                      const gchar* key);
static void mpris_application_extension_real_dispose (GObject* base);
static void _mpris_application_extension_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                          const gchar* key,
                                                                          gpointer self);
static GObject * mpris_application_extension_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
static void _mpris_application_extension___lambda16_ (MprisApplicationExtension* self);
static void __mpris_application_extension___lambda16__g_application_shutdown (GApplication* _sender,
                                                                       gpointer self);
static void _mpris_application_extension____lambda17_ (MprisApplicationExtension* self);
static void __mpris_application_extension____lambda17__g_object_notify (GObject* _sender,
                                                                 GParamSpec* pspec,
                                                                 gpointer self);
static void mpris_application_extension_finalize (GObject * obj);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
mpris_application_extension_get_instance_private (MprisApplicationExtension* self)
{
	return G_STRUCT_MEMBER_P (self, MprisApplicationExtension_private_offset);
}

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

static void
_mpris_application_extension_on_name_owner_changed_mpris_name_owner_changed_func (GDBusConnection* connection,
                                                                                  const gchar* name,
                                                                                  const gchar* old_owner,
                                                                                  const gchar* new_owner,
                                                                                  gpointer self)
{
	mpris_application_extension_on_name_owner_changed ((MprisApplicationExtension*) self, connection, name, old_owner, new_owner);
}

static void
mpris_application_extension_init (MprisApplicationExtension* self,
                                  gint timeout)
{
	FtTimeBlock* current_time_block = NULL;
	FtTimer* _tmp0_;
	void* _tmp1_;
	void* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtState _tmp4_ = 0;
	gboolean _tmp5_ = FALSE;
	FtTimeBlock* _tmp6_;
	GDBusConnection* _tmp16_;
	GDBusConnection* _tmp17_;
	gint _tmp18_ = 0;
	gchar** _tmp19_;
	FtSoundManager* _tmp23_;
	GSettings* _tmp24_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timer;
	_tmp1_ = ft_timer_get_user_data (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, FT_TYPE_TIME_BLOCK) ? ((FtTimeBlock*) _tmp2_) : NULL);
	current_time_block = _tmp3_;
	_tmp6_ = current_time_block;
	if (_tmp6_ != NULL) {
		FtTimer* _tmp7_;
		_tmp7_ = self->priv->timer;
		_tmp5_ = ft_timer_is_started (_tmp7_);
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		FtTimeBlock* _tmp8_;
		FtState _tmp9_;
		FtState _tmp10_;
		_tmp8_ = current_time_block;
		_tmp9_ = ft_time_block_get_state (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp4_ = _tmp10_;
	} else {
		_tmp4_ = FT_STATE_STOPPED;
	}
	self->priv->effective_state = _tmp4_;
	{
		GDBusConnection* _tmp11_ = NULL;
		GDBusConnection* _tmp12_;
		GDBusConnection* _tmp13_;
		_tmp12_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_);
		_tmp11_ = _tmp12_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp13_ = _tmp11_;
		_tmp11_ = NULL;
		_g_object_unref0 (self->priv->connection);
		self->priv->connection = _tmp13_;
		_g_object_unref0 (_tmp11_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp14_;
		const gchar* _tmp15_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp14_ = _error_;
		_tmp15_ = _tmp14_->message;
		g_warning ("application-extension.vala:56: Error while obtaining D-Bus connection:" \
" %s", _tmp15_);
		_g_error_free0 (_error_);
		_g_object_unref0 (current_time_block);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (current_time_block);
		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;
	}
	_tmp16_ = self->priv->connection;
	self->priv->name_owner_changed_id = mpris_dbus_subscribe_name_owner_changed (_tmp16_, _mpris_application_extension_on_name_owner_changed_mpris_name_owner_changed_func, self);
	_tmp17_ = self->priv->connection;
	_tmp19_ = mpris_list_dbus_names (_tmp17_, timeout, &_tmp18_);
	{
		gchar** dbus_name_collection = NULL;
		gint dbus_name_collection_length1 = 0;
		gint _dbus_name_collection_size_ = 0;
		gint dbus_name_it = 0;
		dbus_name_collection = _tmp19_;
		dbus_name_collection_length1 = _tmp18_;
		for (dbus_name_it = 0; dbus_name_it < dbus_name_collection_length1; dbus_name_it = dbus_name_it + 1) {
			gchar* _tmp20_;
			gchar* dbus_name = NULL;
			_tmp20_ = g_strdup (dbus_name_collection[dbus_name_it]);
			dbus_name = _tmp20_;
			{
				const gchar* _tmp21_;
				_tmp21_ = dbus_name;
				if (g_str_has_prefix (_tmp21_, MPRIS_DBUS_NAME_PREFIX)) {
					const gchar* _tmp22_;
					_tmp22_ = dbus_name;
					mpris_application_extension_add_player (self, _tmp22_);
				}
				_g_free0 (dbus_name);
			}
		}
		dbus_name_collection = (_vala_array_free (dbus_name_collection, dbus_name_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp23_ = ft_sound_manager_new ();
	_g_object_unref0 (self->priv->sound_manager);
	self->priv->sound_manager = _tmp23_;
	mpris_application_extension_update_background_sound_inhibitor (self);
	_tmp24_ = self->priv->settings;
	if (g_settings_get_boolean (_tmp24_, "control-media-playback")) {
		mpris_application_extension_enable (self);
	}
	_g_object_unref0 (current_time_block);
}

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_)) {
		MprisApplicationExtension* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
__lambda7_ (Block1Data* _data1_,
            const gchar* bus_name,
            MprisPlayerWrapper* player)
{
	MprisApplicationExtension* self;
	self = _data1_->self;
	g_return_if_fail (bus_name != NULL);
	g_return_if_fail (player != NULL);
	_data1_->func (player, _data1_->func_target);
}

static void
___lambda7__gh_func (gconstpointer key,
                     gconstpointer value,
                     gpointer self)
{
	__lambda7_ (self, (const gchar*) key, (MprisPlayerWrapper*) value);
}

static inline void
mpris_application_extension_foreach_player (MprisApplicationExtension* self,
                                            GFunc func,
                                            gpointer func_target)
{
	Block1Data* _data1_;
	GHashTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_data1_->func = func;
	_data1_->func_target = func_target;
	_tmp0_ = self->priv->players;
	g_hash_table_foreach (_tmp0_, ___lambda7__gh_func, _data1_);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

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

static void
__lambda8_ (Block2Data* _data2_,
            MprisPlayerWrapper* player)
{
	MprisApplicationExtension* self;
	MprisPlaybackStatus _tmp0_;
	MprisPlaybackStatus _tmp1_;
	self = _data2_->self;
	g_return_if_fail (player != NULL);
	_tmp0_ = mpris_player_wrapper_get_status (player);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == MPRIS_PLAYBACK_STATUS_PLAYING) {
		guint _tmp2_;
		_tmp2_ = _data2_->playing_count;
		_data2_->playing_count = _tmp2_ + 1;
	}
}

static void
___lambda8__gfunc (gconstpointer data,
                   gpointer self)
{
	__lambda8_ (self, (MprisPlayerWrapper*) data);
}

static void
mpris_application_extension_update_background_sound_inhibitor (MprisApplicationExtension* self)
{
	Block2Data* _data2_;
	FtSoundManager* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (self != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = self->priv->sound_manager;
	if (_tmp0_ == NULL) {
		block2_data_unref (_data2_);
		_data2_ = NULL;
		return;
	}
	_data2_->playing_count = 0U;
	mpris_application_extension_foreach_player (self, ___lambda8__gfunc, _data2_);
	if (_data2_->playing_count > ((guint) 0)) {
		_tmp1_ = !self->priv->background_sound_inhibited;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		FtSoundManager* _tmp2_;
		self->priv->background_sound_inhibited = TRUE;
		_tmp2_ = self->priv->sound_manager;
		ft_sound_manager_inhibit_background_sound (_tmp2_);
	}
	if (_data2_->playing_count == ((guint) 0)) {
		_tmp3_ = self->priv->background_sound_inhibited;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		FtSoundManager* _tmp4_;
		self->priv->background_sound_inhibited = FALSE;
		_tmp4_ = self->priv->sound_manager;
		ft_sound_manager_uninhibit_background_sound (_tmp4_);
	}
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static void
_mpris_application_extension_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                            const FtTimerState* current_state,
                                                                            const FtTimerState* previous_state,
                                                                            gpointer self)
{
	mpris_application_extension_on_timer_state_changed ((MprisApplicationExtension*) self, current_state, previous_state);
}

static void
mpris_application_extension_enable (MprisApplicationExtension* self)
{
	FtTimer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timer;
	g_signal_connect_object (_tmp0_, "state-changed", (GCallback) _mpris_application_extension_on_timer_state_changed_ft_timer_state_changed, self, 0);
}

static void
__lambda15_ (MprisApplicationExtension* self,
             MprisPlayerWrapper* player)
{
	g_return_if_fail (player != NULL);
	player->auto_paused = FALSE;
}

static void
___lambda15__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda15_ ((MprisApplicationExtension*) self, (MprisPlayerWrapper*) data);
}

static void
mpris_application_extension_disable (MprisApplicationExtension* self)
{
	FtTimer* _tmp0_;
	guint _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timer;
	g_signal_parse_name ("state-changed", FT_TYPE_TIMER, &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp0_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _mpris_application_extension_on_timer_state_changed_ft_timer_state_changed, self);
	mpris_application_extension_foreach_player (self, ___lambda15__gfunc, self);
}

static void
_mpris_application_extension_on_player_status_changed_mpris_player_wrapper_status_changed (MprisPlayerWrapper* _sender,
                                                                                           MprisPlaybackStatus status,
                                                                                           MprisPlaybackStatus previous_status,
                                                                                           gpointer self)
{
	mpris_application_extension_on_player_status_changed ((MprisApplicationExtension*) self, _sender, status, previous_status);
}

static void
mpris_application_extension_add_player (MprisApplicationExtension* self,
                                        const gchar* dbus_name)
{
	GHashTable* _tmp0_;
	MprisPlayerWrapper* player = NULL;
	GCancellable* _tmp1_;
	MprisPlayerWrapper* _tmp2_;
	MprisPlayerWrapper* _tmp3_;
	GHashTable* _tmp4_;
	gchar* _tmp5_;
	MprisPlayerWrapper* _tmp6_;
	MprisPlayerWrapper* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dbus_name != NULL);
	_tmp0_ = self->priv->players;
	if (g_hash_table_contains (_tmp0_, dbus_name)) {
		return;
	}
	_tmp1_ = self->priv->cancellable;
	_tmp2_ = mpris_player_wrapper_new (dbus_name, _tmp1_);
	player = _tmp2_;
	_tmp3_ = player;
	g_signal_connect_object (_tmp3_, "status-changed", (GCallback) _mpris_application_extension_on_player_status_changed_mpris_player_wrapper_status_changed, self, 0);
	_tmp4_ = self->priv->players;
	_tmp5_ = g_strdup (dbus_name);
	_tmp6_ = player;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	g_hash_table_insert (_tmp4_, _tmp5_, _tmp7_);
	mpris_application_extension_update_background_sound_inhibitor (self);
	_g_object_unref0 (player);
}

static void
mpris_application_extension_remove_player (MprisApplicationExtension* self,
                                           const gchar* dbus_name)
{
	MprisPlayerWrapper* player = NULL;
	GHashTable* _tmp0_;
	gconstpointer _tmp1_;
	MprisPlayerWrapper* _tmp2_;
	MprisPlayerWrapper* _tmp3_;
	MprisPlayerWrapper* _tmp4_;
	guint _tmp5_;
	GHashTable* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dbus_name != NULL);
	_tmp0_ = self->priv->players;
	_tmp1_ = g_hash_table_lookup (_tmp0_, dbus_name);
	_tmp2_ = _g_object_ref0 ((MprisPlayerWrapper*) _tmp1_);
	player = _tmp2_;
	_tmp3_ = player;
	if (_tmp3_ == NULL) {
		_g_object_unref0 (player);
		return;
	}
	_tmp4_ = player;
	g_signal_parse_name ("status-changed", MPRIS_TYPE_PLAYER_WRAPPER, &_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) _mpris_application_extension_on_player_status_changed_mpris_player_wrapper_status_changed, self);
	_tmp6_ = self->priv->players;
	g_hash_table_remove (_tmp6_, dbus_name);
	mpris_application_extension_update_background_sound_inhibitor (self);
	_g_object_unref0 (player);
}

/**
         * Do not auto-resume playback if there's other media playing.
         *
         * TODO: detect videocall
         */
static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		MprisApplicationExtension* self;
		self = _data3_->self;
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static void
__lambda12_ (Block3Data* _data3_,
             MprisPlayerWrapper* player)
{
	MprisApplicationExtension* self;
	gboolean _tmp0_ = FALSE;
	MprisPlaybackStatus _tmp1_;
	MprisPlaybackStatus _tmp2_;
	self = _data3_->self;
	g_return_if_fail (player != NULL);
	_tmp1_ = mpris_player_wrapper_get_status (player);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == MPRIS_PLAYBACK_STATUS_PLAYING) {
		_tmp0_ = !mpris_player_wrapper_is_pausing (player);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		_data3_->can_resume = FALSE;
	}
}

static void
___lambda12__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda12_ (self, (MprisPlayerWrapper*) data);
}

static gboolean
mpris_application_extension_can_resume_playback (MprisApplicationExtension* self)
{
	Block3Data* _data3_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->self = g_object_ref (self);
	_data3_->can_resume = TRUE;
	mpris_application_extension_foreach_player (self, ___lambda12__gfunc, _data3_);
	result = _data3_->can_resume;
	block3_data_unref (_data3_);
	_data3_ = NULL;
	return result;
}

static Block4Data*
block4_data_ref (Block4Data* _data4_)
{
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}

static void
block4_data_unref (void * _userdata_)
{
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		MprisApplicationExtension* self;
		self = _data4_->self;
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}

static Block5Data*
block5_data_ref (Block5Data* _data5_)
{
	g_atomic_int_inc (&_data5_->_ref_count_);
	return _data5_;
}

static void
block5_data_unref (void * _userdata_)
{
	Block5Data* _data5_;
	_data5_ = (Block5Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
		MprisApplicationExtension* self;
		self = _data5_->_data4_->self;
		_g_object_unref0 (_data5_->player);
		block4_data_unref (_data5_->_data4_);
		_data5_->_data4_ = NULL;
		g_slice_free (Block5Data, _data5_);
	}
}

static void
__lambda11_ (Block5Data* _data5_,
             GObject* obj,
             GAsyncResult* res)
{
	Block4Data* _data4_;
	MprisApplicationExtension* self;
	_data4_ = _data5_->_data4_;
	self = _data4_->self;
	g_return_if_fail (res != NULL);
	if (mpris_player_wrapper_pause_finish (_data5_->player, res)) {
		_data5_->player->auto_paused = TRUE;
	}
}

static void
___lambda11__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda11_ (self, source_object, res);
	block5_data_unref (self);
}

static void
__lambda10_ (Block4Data* _data4_,
             MprisPlayerWrapper* player)
{
	MprisApplicationExtension* self;
	Block5Data* _data5_;
	MprisPlayerWrapper* _tmp0_;
	gboolean _tmp1_ = FALSE;
	MprisPlaybackStatus _tmp2_;
	MprisPlaybackStatus _tmp3_;
	self = _data4_->self;
	g_return_if_fail (player != NULL);
	_data5_ = g_slice_new0 (Block5Data);
	_data5_->_ref_count_ = 1;
	_data5_->_data4_ = block4_data_ref (_data4_);
	_tmp0_ = _g_object_ref0 (player);
	_g_object_unref0 (_data5_->player);
	_data5_->player = _tmp0_;
	_tmp2_ = mpris_player_wrapper_get_status (_data5_->player);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != MPRIS_PLAYBACK_STATUS_PLAYING) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = _data5_->player->associated_state != _data4_->assigned_state;
	}
	if (_tmp1_) {
		block5_data_unref (_data5_);
		_data5_ = NULL;
		return;
	}
	mpris_player_wrapper_pause (_data5_->player, ___lambda11__gasync_ready_callback, block5_data_ref (_data5_));
	block5_data_unref (_data5_);
	_data5_ = NULL;
}

static void
___lambda10__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda10_ (self, (MprisPlayerWrapper*) data);
}

static void
mpris_application_extension_pause_playback (MprisApplicationExtension* self,
                                            FtState assigned_state)
{
	Block4Data* _data4_;
	g_return_if_fail (self != NULL);
	_data4_ = g_slice_new0 (Block4Data);
	_data4_->_ref_count_ = 1;
	_data4_->self = g_object_ref (self);
	_data4_->assigned_state = assigned_state;
	mpris_application_extension_foreach_player (self, ___lambda10__gfunc, _data4_);
	block4_data_unref (_data4_);
	_data4_ = NULL;
}

static Block6Data*
block6_data_ref (Block6Data* _data6_)
{
	g_atomic_int_inc (&_data6_->_ref_count_);
	return _data6_;
}

static void
block6_data_unref (void * _userdata_)
{
	Block6Data* _data6_;
	_data6_ = (Block6Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data6_->_ref_count_)) {
		MprisApplicationExtension* self;
		self = _data6_->self;
		_g_object_unref0 (self);
		g_slice_free (Block6Data, _data6_);
	}
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		MprisApplicationExtension* self;
		self = _data7_->_data6_->self;
		_g_object_unref0 (_data7_->player);
		block6_data_unref (_data7_->_data6_);
		_data7_->_data6_ = NULL;
		g_slice_free (Block7Data, _data7_);
	}
}

static void
___lambda14_ (Block7Data* _data7_,
              GObject* obj,
              GAsyncResult* res)
{
	Block6Data* _data6_;
	MprisApplicationExtension* self;
	_data6_ = _data7_->_data6_;
	self = _data6_->self;
	g_return_if_fail (res != NULL);
	if (mpris_player_wrapper_resume_finish (_data7_->player, res)) {
		_data7_->player->auto_paused = FALSE;
	}
}

static void
____lambda14__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda14_ (self, source_object, res);
	block7_data_unref (self);
}

static void
__lambda13_ (Block6Data* _data6_,
             MprisPlayerWrapper* player)
{
	MprisApplicationExtension* self;
	Block7Data* _data7_;
	MprisPlayerWrapper* _tmp0_;
	gboolean _tmp1_ = FALSE;
	self = _data6_->self;
	g_return_if_fail (player != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->_data6_ = block6_data_ref (_data6_);
	_tmp0_ = _g_object_ref0 (player);
	_g_object_unref0 (_data7_->player);
	_data7_->player = _tmp0_;
	if (!_data7_->player->auto_paused) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = _data7_->player->associated_state != _data6_->assigned_state;
	}
	if (_tmp1_) {
		block7_data_unref (_data7_);
		_data7_ = NULL;
		return;
	}
	if (_data6_->can_resume) {
		mpris_player_wrapper_resume (_data7_->player, ____lambda14__gasync_ready_callback, block7_data_ref (_data7_));
		_data6_->resuming = TRUE;
	} else {
		_data7_->player->auto_paused = FALSE;
	}
	block7_data_unref (_data7_);
	_data7_ = NULL;
}

static void
___lambda13__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda13_ (self, (MprisPlayerWrapper*) data);
}

static void
mpris_application_extension_resume_playback (MprisApplicationExtension* self,
                                             FtState assigned_state)
{
	Block6Data* _data6_;
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	_data6_ = g_slice_new0 (Block6Data);
	_data6_->_ref_count_ = 1;
	_data6_->self = g_object_ref (self);
	_data6_->assigned_state = assigned_state;
	_data6_->can_resume = mpris_application_extension_can_resume_playback (self);
	_data6_->resuming = FALSE;
	mpris_application_extension_foreach_player (self, ___lambda13__gfunc, _data6_);
	if (_data6_->resuming) {
		_tmp0_ = !self->priv->background_sound_inhibited;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		FtSoundManager* _tmp1_;
		self->priv->background_sound_inhibited = TRUE;
		_tmp1_ = self->priv->sound_manager;
		ft_sound_manager_inhibit_background_sound (_tmp1_);
	}
	block6_data_unref (_data6_);
	_data6_ = NULL;
}

static void
mpris_application_extension_on_name_owner_changed (MprisApplicationExtension* self,
                                                   GDBusConnection* connection,
                                                   const gchar* dbus_name,
                                                   const gchar* old_owner,
                                                   const gchar* new_owner)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	g_return_if_fail (dbus_name != NULL);
	g_return_if_fail (old_owner != NULL);
	g_return_if_fail (new_owner != NULL);
	if (!g_str_has_prefix (dbus_name, MPRIS_DBUS_NAME_PREFIX)) {
		return;
	}
	if (g_strcmp0 (old_owner, "") != 0) {
		mpris_application_extension_remove_player (self, dbus_name);
	}
	if (g_strcmp0 (new_owner, "") != 0) {
		mpris_application_extension_add_player (self, dbus_name);
	}
}

static void
mpris_application_extension_on_player_status_changed (MprisApplicationExtension* self,
                                                      MprisPlayerWrapper* player,
                                                      MprisPlaybackStatus status,
                                                      MprisPlaybackStatus previous_status)
{
	FtTimeBlock* current_time_block = NULL;
	FtTimer* _tmp0_;
	void* _tmp1_;
	void* _tmp2_;
	FtTimeBlock* _tmp3_;
	gboolean _tmp4_ = FALSE;
	FtTimeBlock* _tmp5_;
	gboolean is_waiting_for_activity = FALSE;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (player != NULL);
	_tmp0_ = self->priv->timer;
	_tmp1_ = ft_timer_get_user_data (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, FT_TYPE_TIME_BLOCK) ? ((FtTimeBlock*) _tmp2_) : NULL);
	current_time_block = _tmp3_;
	_tmp5_ = current_time_block;
	if (_tmp5_ != NULL) {
		FtTimer* _tmp6_;
		_tmp6_ = self->priv->timer;
		_tmp4_ = !ft_timer_is_started (_tmp6_);
	} else {
		_tmp4_ = FALSE;
	}
	is_waiting_for_activity = _tmp4_;
	mpris_application_extension_update_background_sound_inhibitor (self);
	if (status == MPRIS_PLAYBACK_STATUS_PLAYING) {
		_tmp9_ = is_waiting_for_activity;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		_tmp8_ = player->auto_paused;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		_tmp7_ = player->associated_state == FT_STATE_POMODORO;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		FtTimerActionGroup* timer_action_group = NULL;
		FtTimerActionGroup* _tmp10_;
		FtTimerActionGroup* _tmp11_;
		_tmp10_ = ft_timer_action_group_new ();
		timer_action_group = _tmp10_;
		_tmp11_ = timer_action_group;
		g_action_group_activate_action ((GActionGroup*) _tmp11_, "start", NULL);
		_g_object_unref0 (timer_action_group);
	} else {
		gboolean _tmp12_ = FALSE;
		if (status == MPRIS_PLAYBACK_STATUS_PLAYING) {
			_tmp12_ = TRUE;
		} else {
			_tmp12_ = previous_status == MPRIS_PLAYBACK_STATUS_UNKNOWN;
		}
		if (_tmp12_) {
			FtState _tmp13_ = 0;
			gboolean _tmp14_ = FALSE;
			FtState effective_state = 0;
			if (is_waiting_for_activity) {
				_tmp14_ = status == MPRIS_PLAYBACK_STATUS_PLAYING;
			} else {
				_tmp14_ = FALSE;
			}
			if (_tmp14_) {
				FtTimeBlock* _tmp15_;
				FtState _tmp16_;
				FtState _tmp17_;
				_tmp15_ = current_time_block;
				_tmp16_ = ft_time_block_get_state (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp13_ = _tmp17_;
			} else {
				_tmp13_ = self->priv->effective_state;
			}
			effective_state = _tmp13_;
			player->associated_state = effective_state;
			player->auto_paused = FALSE;
		} else {
			gboolean _tmp18_ = FALSE;
			gboolean _tmp19_ = FALSE;
			if (previous_status == MPRIS_PLAYBACK_STATUS_PLAYING) {
				FtTimeBlock* _tmp20_;
				_tmp20_ = current_time_block;
				_tmp19_ = _tmp20_ != NULL;
			} else {
				_tmp19_ = FALSE;
			}
			if (_tmp19_) {
				FtSessionManager* _tmp21_;
				gboolean _tmp22_;
				gboolean _tmp23_;
				_tmp21_ = self->priv->session_manager;
				_tmp22_ = ft_session_manager_get_lockscreen_active (_tmp21_);
				_tmp23_ = _tmp22_;
				_tmp18_ = _tmp23_;
			} else {
				_tmp18_ = FALSE;
			}
			if (_tmp18_) {
				player->auto_paused = TRUE;
			}
		}
	}
	_g_object_unref0 (current_time_block);
}

static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		MprisApplicationExtension* self;
		self = _data8_->self;
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

static void
___lambda9_ (Block8Data* _data8_,
             MprisPlayerWrapper* player)
{
	MprisApplicationExtension* self;
	MprisPlaybackStatus _tmp0_;
	MprisPlaybackStatus _tmp1_;
	self = _data8_->self;
	g_return_if_fail (player != NULL);
	player->auto_paused = FALSE;
	_tmp0_ = mpris_player_wrapper_get_status (player);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == MPRIS_PLAYBACK_STATUS_PLAYING) {
		player->associated_state = _data8_->effective_state;
	}
}

static void
____lambda9__gfunc (gconstpointer data,
                    gpointer self)
{
	___lambda9_ (self, (MprisPlayerWrapper*) data);
}

static void
mpris_application_extension_on_timer_state_changed (MprisApplicationExtension* self,
                                                    const FtTimerState* current_state,
                                                    const FtTimerState* previous_state)
{
	Block8Data* _data8_;
	FtTimeBlock* current_time_block = NULL;
	FtTimerState _tmp0_;
	void* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* previous_time_block = NULL;
	FtTimerState _tmp3_;
	void* _tmp4_;
	FtTimeBlock* _tmp5_;
	FtState _tmp6_ = 0;
	FtTimeBlock* _tmp7_;
	gboolean is_paused = FALSE;
	FtState previous_effective_state = 0;
	gboolean previous_is_paused = FALSE;
	gboolean _tmp11_ = FALSE;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp17_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = g_object_ref (self);
	_tmp0_ = *current_state;
	_tmp1_ = _tmp0_.user_data;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, FT_TYPE_TIME_BLOCK) ? ((FtTimeBlock*) _tmp1_) : NULL);
	current_time_block = _tmp2_;
	_tmp3_ = *previous_state;
	_tmp4_ = _tmp3_.user_data;
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, FT_TYPE_TIME_BLOCK) ? ((FtTimeBlock*) _tmp4_) : NULL);
	previous_time_block = _tmp5_;
	_tmp7_ = current_time_block;
	if (_tmp7_ != NULL) {
		FtTimeBlock* _tmp8_;
		FtState _tmp9_;
		FtState _tmp10_;
		_tmp8_ = current_time_block;
		_tmp9_ = ft_time_block_get_state (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp6_ = _tmp10_;
	} else {
		_tmp6_ = FT_STATE_STOPPED;
	}
	_data8_->effective_state = _tmp6_;
	is_paused = ft_timer_state_is_paused (current_state);
	previous_effective_state = self->priv->effective_state;
	previous_is_paused = ft_timer_state_is_paused (previous_state);
	if (_data8_->effective_state != FT_STATE_STOPPED) {
		_tmp12_ = !ft_timer_state_is_started (current_state);
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		FtTimeBlock* _tmp13_;
		_tmp13_ = previous_time_block;
		_tmp11_ = _tmp13_ != NULL;
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		FtTimeBlock* _tmp14_;
		FtState _tmp15_;
		FtState _tmp16_;
		_tmp14_ = previous_time_block;
		_tmp15_ = ft_time_block_get_state (_tmp14_);
		_tmp16_ = _tmp15_;
		_data8_->effective_state = _tmp16_;
	}
	if (ft_state_is_break (_data8_->effective_state)) {
		_data8_->effective_state = FT_STATE_BREAK;
	}
	self->priv->effective_state = _data8_->effective_state;
	if (_data8_->effective_state == FT_STATE_STOPPED) {
		_tmp17_ = previous_effective_state != FT_STATE_POMODORO;
	} else {
		_tmp17_ = FALSE;
	}
	if (_tmp17_) {
		_g_object_unref0 (previous_time_block);
		_g_object_unref0 (current_time_block);
		block8_data_unref (_data8_);
		_data8_ = NULL;
		return;
	}
	if (previous_effective_state == FT_STATE_STOPPED) {
		mpris_application_extension_foreach_player (self, ____lambda9__gfunc, _data8_);
	}
	if (_data8_->effective_state != previous_effective_state) {
		gboolean _tmp18_ = FALSE;
		gboolean _tmp19_ = FALSE;
		mpris_application_extension_pause_playback (self, previous_effective_state);
		if (_data8_->effective_state == FT_STATE_POMODORO) {
			_tmp19_ = previous_effective_state == FT_STATE_BREAK;
		} else {
			_tmp19_ = FALSE;
		}
		if (_tmp19_) {
			_tmp18_ = !is_paused;
		} else {
			_tmp18_ = FALSE;
		}
		if (_tmp18_) {
			mpris_application_extension_resume_playback (self, _data8_->effective_state);
		}
	} else {
		if (is_paused != previous_is_paused) {
			if (is_paused) {
				mpris_application_extension_pause_playback (self, _data8_->effective_state);
			} else {
				mpris_application_extension_resume_playback (self, _data8_->effective_state);
			}
		}
	}
	_g_object_unref0 (previous_time_block);
	_g_object_unref0 (current_time_block);
	block8_data_unref (_data8_);
	_data8_ = NULL;
}

static void
mpris_application_extension_on_settings_changed (MprisApplicationExtension* self,
                                                 GSettings* settings,
                                                 const gchar* key)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (settings != NULL);
	g_return_if_fail (key != NULL);
	_tmp0_ = key;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("control-media-playback")))) {
		switch (0) {
			default:
			{
				if (g_settings_get_boolean (settings, key)) {
					mpris_application_extension_enable (self);
				} else {
					mpris_application_extension_disable (self);
				}
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
}

static void
_mpris_application_extension_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                     const gchar* key,
                                                                     gpointer self)
{
	mpris_application_extension_on_settings_changed ((MprisApplicationExtension*) self, _sender, key);
}

static void
mpris_application_extension_real_dispose (GObject* base)
{
	MprisApplicationExtension * self;
	GCancellable* _tmp0_;
	gboolean _tmp2_ = FALSE;
	GSettings* _tmp5_;
	FtTimer* _tmp8_;
	self = (MprisApplicationExtension*) base;
	_tmp0_ = self->priv->cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		_tmp1_ = self->priv->cancellable;
		g_cancellable_cancel (_tmp1_);
		_g_object_unref0 (self->priv->cancellable);
		self->priv->cancellable = NULL;
	}
	if (self->priv->name_owner_changed_id != ((guint) 0)) {
		GDBusConnection* _tmp3_;
		_tmp3_ = self->priv->connection;
		_tmp2_ = _tmp3_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GDBusConnection* _tmp4_;
		_tmp4_ = self->priv->connection;
		g_dbus_connection_signal_unsubscribe (_tmp4_, self->priv->name_owner_changed_id);
		self->priv->name_owner_changed_id = (guint) 0;
	}
	_tmp5_ = self->priv->settings;
	if (_tmp5_ != NULL) {
		GSettings* _tmp6_;
		guint _tmp7_;
		_tmp6_ = self->priv->settings;
		g_signal_parse_name ("changed", g_settings_get_type (), &_tmp7_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp6_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp7_, 0, NULL, (GCallback) _mpris_application_extension_on_settings_changed_g_settings_changed, self);
		_g_object_unref0 (self->priv->settings);
		self->priv->settings = NULL;
	}
	_tmp8_ = self->priv->timer;
	if (_tmp8_ != NULL) {
		FtTimer* _tmp9_;
		guint _tmp10_;
		_tmp9_ = self->priv->timer;
		g_signal_parse_name ("state-changed", FT_TYPE_TIMER, &_tmp10_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp9_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp10_, 0, NULL, (GCallback) _mpris_application_extension_on_timer_state_changed_ft_timer_state_changed, self);
		_g_object_unref0 (self->priv->timer);
		self->priv->timer = NULL;
	}
	if (self->priv->background_sound_inhibited) {
		FtSoundManager* _tmp11_;
		self->priv->background_sound_inhibited = FALSE;
		_tmp11_ = self->priv->sound_manager;
		ft_sound_manager_uninhibit_background_sound (_tmp11_);
	}
	_g_object_unref0 (self->priv->connection);
	self->priv->connection = NULL;
	_g_hash_table_unref0 (self->priv->players);
	self->priv->players = NULL;
	_g_object_unref0 (self->priv->sound_manager);
	self->priv->sound_manager = NULL;
	_g_object_unref0 (self->priv->session_manager);
	self->priv->session_manager = NULL;
	G_OBJECT_CLASS (mpris_application_extension_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_APPLICATION_EXTENSION, FtApplicationExtension));
}

MprisApplicationExtension*
mpris_application_extension_construct (GType object_type)
{
	MprisApplicationExtension * self = NULL;
	self = (MprisApplicationExtension*) ft_application_extension_construct (object_type);
	return self;
}

MprisApplicationExtension*
mpris_application_extension_new (void)
{
	return mpris_application_extension_construct (MPRIS_TYPE_APPLICATION_EXTENSION);
}

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

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

static void
_mpris_application_extension___lambda16_ (MprisApplicationExtension* self)
{
	mpris_application_extension_disable (self);
}

static void
__mpris_application_extension___lambda16__g_application_shutdown (GApplication* _sender,
                                                                  gpointer self)
{
	_mpris_application_extension___lambda16_ ((MprisApplicationExtension*) self);
}

static void
_mpris_application_extension____lambda17_ (MprisApplicationExtension* self)
{
	mpris_application_extension_init (self, -1);
}

static void
__mpris_application_extension____lambda17__g_object_notify (GObject* _sender,
                                                            GParamSpec* pspec,
                                                            gpointer self)
{
	_mpris_application_extension____lambda17_ ((MprisApplicationExtension*) self);
}

static GObject *
mpris_application_extension_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	MprisApplicationExtension * self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	GCancellable* _tmp3_;
	FtTimer* _tmp4_;
	FtTimer* _tmp5_;
	FtSessionManager* _tmp6_;
	FtSessionManager* _tmp7_;
	GSettings* _tmp8_;
	GSettings* _tmp9_;
	FtApplication* application = NULL;
	FtApplication* _tmp10_;
	FtApplication* _tmp11_;
	FtApplication* _tmp12_;
	FtApplication* _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_;
	parent_class = G_OBJECT_CLASS (mpris_application_extension_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MPRIS_TYPE_APPLICATION_EXTENSION, MprisApplicationExtension);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->players);
	self->priv->players = _tmp2_;
	_tmp3_ = g_cancellable_new ();
	_g_object_unref0 (self->priv->cancellable);
	self->priv->cancellable = _tmp3_;
	_tmp4_ = ft_timer_get_default ();
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_g_object_unref0 (self->priv->timer);
	self->priv->timer = _tmp5_;
	_tmp6_ = ft_session_manager_get_default ();
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_g_object_unref0 (self->priv->session_manager);
	self->priv->session_manager = _tmp7_;
	_tmp8_ = g_settings_new ("io.github.focustimerhq.FocusTimer.plugins.mpris");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp8_;
	_tmp9_ = self->priv->settings;
	g_signal_connect_object (_tmp9_, "changed", (GCallback) _mpris_application_extension_on_settings_changed_g_settings_changed, self, 0);
	_tmp10_ = ft_application_get_default ();
	_tmp11_ = _g_object_ref0 (_tmp10_);
	application = _tmp11_;
	_tmp12_ = application;
	g_signal_connect_object ((GApplication*) _tmp12_, "shutdown", (GCallback) __mpris_application_extension___lambda16__g_application_shutdown, self, 0);
	_tmp13_ = application;
	_tmp14_ = ft_application_get_ready (_tmp13_);
	_tmp15_ = _tmp14_;
	if (_tmp15_) {
		mpris_application_extension_init (self, -1);
	} else {
		FtApplication* _tmp16_;
		_tmp16_ = application;
		g_signal_connect_object ((GObject*) _tmp16_, "notify::ready", (GCallback) __mpris_application_extension____lambda17__g_object_notify, self, 0);
	}
	_g_object_unref0 (application);
	return obj;
}

static void
mpris_application_extension_class_init (MprisApplicationExtensionClass * klass,
                                        gpointer klass_data)
{
	mpris_application_extension_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MprisApplicationExtension_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) mpris_application_extension_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = mpris_application_extension_constructor;
	G_OBJECT_CLASS (klass)->finalize = mpris_application_extension_finalize;
}

static void
mpris_application_extension_instance_init (MprisApplicationExtension * self,
                                           gpointer klass)
{
	self->priv = mpris_application_extension_get_instance_private (self);
	self->priv->settings = NULL;
	self->priv->timer = NULL;
	self->priv->session_manager = NULL;
	self->priv->cancellable = NULL;
	self->priv->connection = NULL;
	self->priv->name_owner_changed_id = (guint) 0;
	self->priv->players = NULL;
	self->priv->effective_state = FT_STATE_STOPPED;
	self->priv->sound_manager = NULL;
	self->priv->background_sound_inhibited = FALSE;
}

static void
mpris_application_extension_finalize (GObject * obj)
{
	MprisApplicationExtension * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MPRIS_TYPE_APPLICATION_EXTENSION, MprisApplicationExtension);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->timer);
	_g_object_unref0 (self->priv->session_manager);
	_g_object_unref0 (self->priv->cancellable);
	_g_object_unref0 (self->priv->connection);
	_g_hash_table_unref0 (self->priv->players);
	_g_object_unref0 (self->priv->sound_manager);
	G_OBJECT_CLASS (mpris_application_extension_parent_class)->finalize (obj);
}

GType
mpris_application_extension_get_type (void)
{
	return mpris_application_extension_type_id;
}

GType
mpris_application_extension_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (MprisApplicationExtensionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mpris_application_extension_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MprisApplicationExtension), 0, (GInstanceInitFunc) mpris_application_extension_instance_init, NULL };
	mpris_application_extension_type_id = g_type_module_register_type (module, FT_TYPE_APPLICATION_EXTENSION, "MprisApplicationExtension", &g_define_type_info, 0);
	MprisApplicationExtension_private_offset = sizeof (MprisApplicationExtensionPrivate);
	return mpris_application_extension_type_id;
}

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

