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

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

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

#define MPRIS_PLAYER_WRAPPER_REWIND_INTERVAL (10 * FT_INTERVAL_SECOND)
#define MPRIS_PLAYER_WRAPPER_DEBOUNCE_TIMEOUT ((guint) 100)
#define MPRIS_PLAYER_WRAPPER_TIMEOUT ((guint) 10000)
#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_PLAYER_WRAPPER_0_PROPERTY,
	MPRIS_PLAYER_WRAPPER_STATUS_PROPERTY,
	MPRIS_PLAYER_WRAPPER_CAN_PAUSE_PROPERTY,
	MPRIS_PLAYER_WRAPPER_NUM_PROPERTIES
};
static GParamSpec* mpris_player_wrapper_properties[MPRIS_PLAYER_WRAPPER_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_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _MprisPlayerWrapperInitData MprisPlayerWrapperInitData;
typedef struct _MprisPlayerWrapperPauseData MprisPlayerWrapperPauseData;
typedef struct _MprisPlayerWrapperResumeData MprisPlayerWrapperResumeData;
enum  {
	MPRIS_PLAYER_WRAPPER_STATUS_CHANGED_SIGNAL,
	MPRIS_PLAYER_WRAPPER_NUM_SIGNALS
};
static guint mpris_player_wrapper_signals[MPRIS_PLAYER_WRAPPER_NUM_SIGNALS] = {0};

struct _MprisPlayerWrapperPrivate {
	MprisPlaybackStatus _status;
	MprisPlayer* player_proxy;
	gint64 paused_timestamp;
	gchar* dbus_name;
	guint status_changed_id;
	guint timeout_id;
	guint emitted_status;
	MprisPlaybackStatus pending_status;
};

struct _MprisPlayerWrapperInitData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MprisPlayerWrapper* self;
	GCancellable* cancellable;
	MprisPlayer* _tmp0_;
	const gchar* _tmp1_;
	MprisPlayer* _tmp2_;
	MprisPlayer* _tmp3_;
	GDBusProxy* player_proxy;
	MprisPlayer* _tmp4_;
	GDBusProxy* _tmp5_;
	GDBusProxy* _tmp6_;
	GError* _error_;
	const gchar* _tmp7_;
	GError* _tmp8_;
	const gchar* _tmp9_;
	GError* _inner_error0_;
};

struct _MprisPlayerWrapperPauseData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MprisPlayerWrapper* self;
	gboolean result;
	MprisPlaybackStatus _tmp0_;
	MprisPlayer* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	MprisPlaybackStatus pending_status;
	gboolean _tmp4_;
	MprisPlayer* _tmp5_;
	MprisPlayer* _tmp6_;
	GError* _error_;
	const gchar* _tmp7_;
	GError* _tmp8_;
	const gchar* _tmp9_;
	GError* _inner_error0_;
};

struct _MprisPlayerWrapperResumeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	MprisPlayerWrapper* self;
	gboolean result;
	gboolean _tmp0_;
	gboolean _tmp1_;
	MprisPlayer* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gint64 pause_duration;
	gboolean _tmp5_;
	gboolean _tmp6_;
	MprisPlayer* _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	MprisPlayer* _tmp10_;
	GError* _error_;
	const gchar* _tmp11_;
	GError* _tmp12_;
	const gchar* _tmp13_;
	MprisPlayer* _tmp14_;
	MprisPlayer* _tmp15_;
	GError* _vala1__error_;
	const gchar* _tmp16_;
	GError* _tmp17_;
	const gchar* _tmp18_;
	GError* _inner_error0_;
};

static gint MprisPlayerWrapper_private_offset;
static gpointer mpris_player_wrapper_parent_class = NULL;
static GType mpris_player_wrapper_type_id = 0;

static void mpris_player_wrapper_status_changed (MprisPlayerWrapper* self,
                                          MprisPlaybackStatus status,
                                          MprisPlaybackStatus previous_status);
static void mpris_player_wrapper_init (MprisPlayerWrapper* self,
                                GCancellable* cancellable,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
static void mpris_player_wrapper_init_finish (MprisPlayerWrapper* self,
                                       GAsyncResult* _res_);
static void __lambda5_ (MprisPlayerWrapper* self,
                 GObject* obj,
                 GAsyncResult* res);
static void ___lambda5__gasync_ready_callback (GObject* source_object,
                                        GAsyncResult* res,
                                        gpointer self);
static void mpris_player_wrapper_init_data_free (gpointer _data);
static gboolean mpris_player_wrapper_init_co (MprisPlayerWrapperInitData* _data_);
static void mpris_player_wrapper_init_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_);
static void mpris_player_wrapper_on_properties_changed (MprisPlayerWrapper* self,
                                                 GVariant* changed_properties,
                                                 gchar** invalidated_properties,
                                                 gint invalidated_properties_length1);
static void _mpris_player_wrapper_on_properties_changed_g_dbus_proxy_g_properties_changed (GDBusProxy* _sender,
                                                                                    GVariant* changed_properties,
                                                                                    gchar** invalidated_properties,
                                                                                    gpointer self);
static void mpris_player_wrapper_update_properties (MprisPlayerWrapper* self);
static gboolean ____lambda4_ (MprisPlayerWrapper* self);
static gboolean _____lambda4__gsource_func (gpointer self);
static gboolean mpris_player_wrapper_on_timeout (MprisPlayerWrapper* self);
static void mpris_player_wrapper_pause_data_free (gpointer _data);
static gboolean mpris_player_wrapper_pause_co (MprisPlayerWrapperPauseData* _data_);
static gboolean _mpris_player_wrapper_on_timeout_gsource_func (gpointer self);
static void mpris_player_wrapper_pause_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
static void mpris_player_wrapper_resume_data_free (gpointer _data);
static gboolean mpris_player_wrapper_resume_co (MprisPlayerWrapperResumeData* _data_);
static void mpris_player_wrapper_resume_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_);
static void mpris_player_wrapper_real_dispose (GObject* base);
static void g_cclosure_user_marshal_VOID__ENUM_ENUM (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data);
static void mpris_player_wrapper_finalize (GObject * obj);
static void _vala_mpris_player_wrapper_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static gssize _vala_array_length (gpointer array);

static inline gpointer
mpris_player_wrapper_get_instance_private (MprisPlayerWrapper* self)
{
	return G_STRUCT_MEMBER_P (self, MprisPlayerWrapper_private_offset);
}

static void
__lambda5_ (MprisPlayerWrapper* self,
            GObject* obj,
            GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	mpris_player_wrapper_init_finish (self, res);
}

static void
___lambda5__gasync_ready_callback (GObject* source_object,
                                   GAsyncResult* res,
                                   gpointer self)
{
	__lambda5_ ((MprisPlayerWrapper*) self, source_object, res);
	g_object_unref (self);
}

MprisPlayerWrapper*
mpris_player_wrapper_construct (GType object_type,
                                const gchar* dbus_name,
                                GCancellable* cancellable)
{
	MprisPlayerWrapper * self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (dbus_name != NULL, NULL);
	g_return_val_if_fail (cancellable != NULL, NULL);
	self = (MprisPlayerWrapper*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (dbus_name);
	_g_free0 (self->priv->dbus_name);
	self->priv->dbus_name = _tmp0_;
	mpris_player_wrapper_init (self, cancellable, ___lambda5__gasync_ready_callback, g_object_ref (self));
	return self;
}

MprisPlayerWrapper*
mpris_player_wrapper_new (const gchar* dbus_name,
                          GCancellable* cancellable)
{
	return mpris_player_wrapper_construct (MPRIS_TYPE_PLAYER_WRAPPER, dbus_name, cancellable);
}

static void
mpris_player_wrapper_init_data_free (gpointer _data)
{
	MprisPlayerWrapperInitData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (MprisPlayerWrapperInitData, _data_);
}

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

static void
mpris_player_wrapper_init (MprisPlayerWrapper* self,
                           GCancellable* cancellable,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_)
{
	MprisPlayerWrapperInitData* _data_;
	MprisPlayerWrapper* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (cancellable != NULL);
	_data_ = g_slice_new0 (MprisPlayerWrapperInitData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mpris_player_wrapper_init_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	mpris_player_wrapper_init_co (_data_);
}

static void
mpris_player_wrapper_init_finish (MprisPlayerWrapper* self,
                                  GAsyncResult* _res_)
{
	MprisPlayerWrapperInitData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
mpris_player_wrapper_init_ready (GObject* source_object,
                                 GAsyncResult* _res_,
                                 gpointer _user_data_)
{
	MprisPlayerWrapperInitData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mpris_player_wrapper_init_co (_data_);
}

static void
_mpris_player_wrapper_on_properties_changed_g_dbus_proxy_g_properties_changed (GDBusProxy* _sender,
                                                                               GVariant* changed_properties,
                                                                               gchar** invalidated_properties,
                                                                               gpointer self)
{
	mpris_player_wrapper_on_properties_changed ((MprisPlayerWrapper*) self, changed_properties, invalidated_properties, _vala_array_length (invalidated_properties));
}

static gboolean
mpris_player_wrapper_init_co (MprisPlayerWrapperInitData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp1_ = _data_->self->priv->dbus_name;
		_data_->_state_ = 1;
		g_async_initable_new_async (MPRIS_TYPE_PLAYER_PROXY, 0, _data_->cancellable, mpris_player_wrapper_init_ready, _data_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, "g-name", _data_->_tmp1_, "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/mpris/MediaPlayer2", "g-interface-name", "org.mpris.MediaPlayer2.Player", NULL);
		return FALSE;
		_state_1:
		_data_->_tmp2_ = (MprisPlayer*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp0_ = (MprisPlayer*) _data_->_tmp2_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp3_ = _data_->_tmp0_;
		_data_->_tmp0_ = NULL;
		_g_object_unref0 (_data_->self->priv->player_proxy);
		_data_->self->priv->player_proxy = _data_->_tmp3_;
		_data_->_tmp4_ = _data_->self->priv->player_proxy;
		_data_->_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, g_dbus_proxy_get_type (), GDBusProxy));
		_data_->player_proxy = _data_->_tmp5_;
		_data_->_tmp6_ = _data_->player_proxy;
		g_signal_connect_object (_data_->_tmp6_, "g-properties-changed", (GCallback) _mpris_player_wrapper_on_properties_changed_g_dbus_proxy_g_properties_changed, _data_->self, 0);
		mpris_player_wrapper_update_properties (_data_->self);
		_g_object_unref0 (_data_->player_proxy);
		_g_object_unref0 (_data_->_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		if (g_cancellable_is_cancelled (_data_->cancellable)) {
			_g_error_free0 (_data_->_error_);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp7_ = _data_->self->priv->dbus_name;
		_data_->_tmp8_ = _data_->_error_;
		_data_->_tmp9_ = _data_->_tmp8_->message;
		g_warning ("player-wrapper.vala:75: Failed to initialize player %s: %s", _data_->_tmp7_, _data_->_tmp9_);
		_g_error_free0 (_data_->_error_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != 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;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gboolean
____lambda4_ (MprisPlayerWrapper* self)
{
	gboolean result;
	self->priv->status_changed_id = (guint) 0;
	if (((guint) self->priv->_status) != self->priv->emitted_status) {
		g_signal_emit (self, mpris_player_wrapper_signals[MPRIS_PLAYER_WRAPPER_STATUS_CHANGED_SIGNAL], 0, self->priv->_status, self->priv->emitted_status);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
_____lambda4__gsource_func (gpointer self)
{
	gboolean result;
	result = ____lambda4_ ((MprisPlayerWrapper*) self);
	return result;
}

static void
mpris_player_wrapper_update_properties (MprisPlayerWrapper* self)
{
	MprisPlaybackStatus status = 0;
	MprisPlayer* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	MprisPlaybackStatus _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->player_proxy;
	_tmp1_ = mpris_player_get_playback_status (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = mpris_playback_status_from_string (_tmp3_);
	_g_free0 (_tmp3_);
	status = _tmp4_;
	if (self->priv->_status != status) {
		MprisPlaybackStatus previous_status = 0;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		previous_status = self->priv->_status;
		self->priv->_status = status;
		g_object_notify ((GObject*) self, "status");
		if (self->priv->status_changed_id != ((guint) 0)) {
			g_source_remove (self->priv->status_changed_id);
			self->priv->status_changed_id = (guint) 0;
		}
		if (status == MPRIS_PLAYBACK_STATUS_PAUSED) {
			_tmp6_ = previous_status == MPRIS_PLAYBACK_STATUS_PLAYING;
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			_tmp5_ = self->priv->pending_status != MPRIS_PLAYBACK_STATUS_PAUSED;
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			self->priv->status_changed_id = g_timeout_add_full (G_PRIORITY_DEFAULT, MPRIS_PLAYER_WRAPPER_DEBOUNCE_TIMEOUT, _____lambda4__gsource_func, g_object_ref (self), g_object_unref);
		} else {
			if (((guint) status) != self->priv->emitted_status) {
				g_signal_emit (self, mpris_player_wrapper_signals[MPRIS_PLAYER_WRAPPER_STATUS_CHANGED_SIGNAL], 0, status, self->priv->emitted_status);
			}
		}
	}
}

static void
mpris_player_wrapper_on_properties_changed (MprisPlayerWrapper* self,
                                            GVariant* changed_properties,
                                            gchar** invalidated_properties,
                                            gint invalidated_properties_length1)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (changed_properties != NULL);
	mpris_player_wrapper_update_properties (self);
}

static gboolean
mpris_player_wrapper_on_timeout (MprisPlayerWrapper* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	self->priv->timeout_id = (guint) 0;
	self->priv->pending_status = MPRIS_PLAYBACK_STATUS_UNKNOWN;
	if (((guint) self->priv->_status) != self->priv->emitted_status) {
		g_signal_emit (self, mpris_player_wrapper_signals[MPRIS_PLAYER_WRAPPER_STATUS_CHANGED_SIGNAL], 0, self->priv->_status, self->priv->emitted_status);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

gboolean
mpris_player_wrapper_is_pausing (MprisPlayerWrapper* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (self->priv->pending_status == MPRIS_PLAYBACK_STATUS_PAUSED) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->pending_status == MPRIS_PLAYBACK_STATUS_STOPPED;
	}
	result = _tmp0_;
	return result;
}

gboolean
mpris_player_wrapper_is_resuming (MprisPlayerWrapper* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->pending_status == MPRIS_PLAYBACK_STATUS_PLAYING;
	return result;
}

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

void
mpris_player_wrapper_pause (MprisPlayerWrapper* self,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	MprisPlayerWrapperPauseData* _data_;
	MprisPlayerWrapper* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (MprisPlayerWrapperPauseData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mpris_player_wrapper_pause_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	mpris_player_wrapper_pause_co (_data_);
}

gboolean
mpris_player_wrapper_pause_finish (MprisPlayerWrapper* self,
                                   GAsyncResult* _res_)
{
	gboolean result;
	MprisPlayerWrapperPauseData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

/**
         * Returns `true` when status changed due to call.
         */
static gboolean
_mpris_player_wrapper_on_timeout_gsource_func (gpointer self)
{
	gboolean result;
	result = mpris_player_wrapper_on_timeout ((MprisPlayerWrapper*) self);
	return result;
}

static void
mpris_player_wrapper_pause_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	MprisPlayerWrapperPauseData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mpris_player_wrapper_pause_co (_data_);
}

static gboolean
mpris_player_wrapper_pause_co (MprisPlayerWrapperPauseData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = _data_->self->priv->player_proxy;
	_data_->_tmp2_ = mpris_player_get_can_pause (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	if (_data_->_tmp3_) {
		_data_->_tmp0_ = MPRIS_PLAYBACK_STATUS_PAUSED;
	} else {
		_data_->_tmp0_ = MPRIS_PLAYBACK_STATUS_STOPPED;
	}
	_data_->pending_status = _data_->_tmp0_;
	if (_data_->self->priv->_status == _data_->pending_status) {
		_data_->_tmp4_ = _data_->self->priv->pending_status == MPRIS_PLAYBACK_STATUS_UNKNOWN;
	} else {
		_data_->_tmp4_ = FALSE;
	}
	if (_data_->_tmp4_) {
		_data_->result = FALSE;
		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;
	}
	if (_data_->self->priv->pending_status == _data_->pending_status) {
		_data_->result = TRUE;
		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;
	}
	if (_data_->self->priv->timeout_id != ((guint) 0)) {
		g_source_remove (_data_->self->priv->timeout_id);
		_data_->self->priv->timeout_id = (guint) 0;
	}
	_data_->self->priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, MPRIS_PLAYER_WRAPPER_TIMEOUT, _mpris_player_wrapper_on_timeout_gsource_func, g_object_ref (_data_->self), g_object_unref);
	_data_->self->priv->pending_status = _data_->pending_status;
	_data_->self->priv->paused_timestamp = g_get_monotonic_time ();
	{
		if (_data_->pending_status != MPRIS_PLAYBACK_STATUS_STOPPED) {
			_data_->_tmp5_ = _data_->self->priv->player_proxy;
			_data_->_state_ = 1;
			mpris_player_pause (_data_->_tmp5_, mpris_player_wrapper_pause_ready, _data_);
			return FALSE;
			_state_1:
			mpris_player_pause_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		} else {
			_data_->_tmp6_ = _data_->self->priv->player_proxy;
			_data_->_state_ = 2;
			mpris_player_play_pause (_data_->_tmp6_, mpris_player_wrapper_pause_ready, _data_);
			return FALSE;
			_state_2:
			mpris_player_play_pause_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp7_ = _data_->self->priv->dbus_name;
		_data_->_tmp8_ = _data_->_error_;
		_data_->_tmp9_ = _data_->_tmp8_->message;
		g_warning ("player-wrapper.vala:185: Failed to pause player %s: %s", _data_->_tmp7_, _data_->_tmp9_);
		if (_data_->self->priv->timeout_id != ((guint) 0)) {
			g_source_remove (_data_->self->priv->timeout_id);
			mpris_player_wrapper_on_timeout (_data_->self);
		}
		_data_->result = FALSE;
		_g_error_free0 (_data_->_error_);
		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:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = TRUE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
mpris_player_wrapper_resume (MprisPlayerWrapper* self,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_)
{
	MprisPlayerWrapperResumeData* _data_;
	MprisPlayerWrapper* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (MprisPlayerWrapperResumeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, mpris_player_wrapper_resume_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	mpris_player_wrapper_resume_co (_data_);
}

gboolean
mpris_player_wrapper_resume_finish (MprisPlayerWrapper* self,
                                    GAsyncResult* _res_)
{
	gboolean result;
	MprisPlayerWrapperResumeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

/**
         * Returns `true` when status changed due to call.
         */
static void
mpris_player_wrapper_resume_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_)
{
	MprisPlayerWrapperResumeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	mpris_player_wrapper_resume_co (_data_);
}

static gboolean
mpris_player_wrapper_resume_co (MprisPlayerWrapperResumeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->_status == MPRIS_PLAYBACK_STATUS_PLAYING) {
		_data_->_tmp0_ = _data_->self->priv->pending_status == MPRIS_PLAYBACK_STATUS_UNKNOWN;
	} else {
		_data_->_tmp0_ = FALSE;
	}
	if (_data_->_tmp0_) {
		_data_->result = FALSE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->self->priv->player_proxy;
	_data_->_tmp3_ = mpris_player_get_can_play (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	if (!_data_->_tmp4_) {
		_data_->_tmp1_ = TRUE;
	} else {
		_data_->_tmp1_ = ft_timestamp_is_undefined (_data_->self->priv->paused_timestamp);
	}
	if (_data_->_tmp1_) {
		_data_->result = FALSE;
		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;
	}
	if (_data_->self->priv->pending_status == MPRIS_PLAYBACK_STATUS_PLAYING) {
		_data_->result = TRUE;
		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;
	}
	if (_data_->self->priv->timeout_id != ((guint) 0)) {
		g_source_remove (_data_->self->priv->timeout_id);
		_data_->self->priv->timeout_id = (guint) 0;
	}
	_data_->self->priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, MPRIS_PLAYER_WRAPPER_TIMEOUT, _mpris_player_wrapper_on_timeout_gsource_func, g_object_ref (_data_->self), g_object_unref);
	_data_->pause_duration = g_get_monotonic_time () - _data_->self->priv->paused_timestamp;
	if (_data_->pause_duration >= FT_INTERVAL_MINUTE) {
		_data_->_tmp6_ = _data_->self->priv->_status == MPRIS_PLAYBACK_STATUS_PAUSED;
	} else {
		_data_->_tmp6_ = FALSE;
	}
	if (_data_->_tmp6_) {
		_data_->_tmp7_ = _data_->self->priv->player_proxy;
		_data_->_tmp8_ = mpris_player_get_can_seek (_data_->_tmp7_);
		_data_->_tmp9_ = _data_->_tmp8_;
		_data_->_tmp5_ = _data_->_tmp9_;
	} else {
		_data_->_tmp5_ = FALSE;
	}
	if (_data_->_tmp5_) {
		{
			_data_->_tmp10_ = _data_->self->priv->player_proxy;
			_data_->_state_ = 1;
			mpris_player_seek (_data_->_tmp10_, (-MPRIS_PLAYER_WRAPPER_REWIND_INTERVAL) / FT_INTERVAL_MICROSECOND, mpris_player_wrapper_resume_ready, _data_);
			return FALSE;
			_state_1:
			mpris_player_seek_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->_error_ = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp11_ = _data_->self->priv->dbus_name;
			_data_->_tmp12_ = _data_->_error_;
			_data_->_tmp13_ = _data_->_tmp12_->message;
			g_debug ("player-wrapper.vala:234: Failed to rewind player %s: %s", _data_->_tmp11_, _data_->_tmp13_);
			_g_error_free0 (_data_->_error_);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	{
		_data_->self->priv->pending_status = MPRIS_PLAYBACK_STATUS_PLAYING;
		_data_->self->priv->paused_timestamp = FT_TIMESTAMP_UNDEFINED;
		if (_data_->self->priv->_status != MPRIS_PLAYBACK_STATUS_STOPPED) {
			_data_->_tmp14_ = _data_->self->priv->player_proxy;
			_data_->_state_ = 2;
			mpris_player_play (_data_->_tmp14_, mpris_player_wrapper_resume_ready, _data_);
			return FALSE;
			_state_2:
			mpris_player_play_finish (_data_->_tmp14_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
		} else {
			_data_->_tmp15_ = _data_->self->priv->player_proxy;
			_data_->_state_ = 3;
			mpris_player_play_pause (_data_->_tmp15_, mpris_player_wrapper_resume_ready, _data_);
			return FALSE;
			_state_3:
			mpris_player_play_pause_finish (_data_->_tmp15_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1__error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp16_ = _data_->self->priv->dbus_name;
		_data_->_tmp17_ = _data_->_vala1__error_;
		_data_->_tmp18_ = _data_->_tmp17_->message;
		g_warning ("player-wrapper.vala:250: Failed to resume player %s: %s", _data_->_tmp16_, _data_->_tmp18_);
		if (_data_->self->priv->timeout_id != ((guint) 0)) {
			g_source_remove (_data_->self->priv->timeout_id);
			mpris_player_wrapper_on_timeout (_data_->self);
		}
		_data_->result = FALSE;
		_g_error_free0 (_data_->_vala1__error_);
		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;
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = TRUE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
mpris_player_wrapper_real_dispose (GObject* base)
{
	MprisPlayerWrapper * self;
	MprisPlayer* _tmp0_;
	self = (MprisPlayerWrapper*) base;
	if (self->priv->status_changed_id != ((guint) 0)) {
		g_source_remove (self->priv->status_changed_id);
		self->priv->status_changed_id = (guint) 0;
	}
	if (self->priv->timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
	}
	_tmp0_ = self->priv->player_proxy;
	if (_tmp0_ != NULL) {
		GDBusProxy* player_proxy = NULL;
		MprisPlayer* _tmp1_;
		GDBusProxy* _tmp2_;
		GDBusProxy* _tmp3_;
		guint _tmp4_;
		_tmp1_ = self->priv->player_proxy;
		_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, g_dbus_proxy_get_type (), GDBusProxy));
		player_proxy = _tmp2_;
		_tmp3_ = player_proxy;
		g_signal_parse_name ("g-properties-changed", g_dbus_proxy_get_type (), &_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) _mpris_player_wrapper_on_properties_changed_g_dbus_proxy_g_properties_changed, self);
		_g_object_unref0 (self->priv->player_proxy);
		self->priv->player_proxy = NULL;
		_g_object_unref0 (player_proxy);
	}
	G_OBJECT_CLASS (mpris_player_wrapper_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

MprisPlaybackStatus
mpris_player_wrapper_get_status (MprisPlayerWrapper* self)
{
	MprisPlaybackStatus result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_status;
	return result;
}

gboolean
mpris_player_wrapper_get_can_pause (MprisPlayerWrapper* self)
{
	gboolean result;
	gboolean _tmp0_ = FALSE;
	MprisPlayer* _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->player_proxy;
	if (_tmp1_ != NULL) {
		MprisPlayer* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = self->priv->player_proxy;
		_tmp3_ = mpris_player_get_can_pause (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
mpris_player_wrapper_real_status_changed (MprisPlayerWrapper* self,
                                          MprisPlaybackStatus status,
                                          MprisPlaybackStatus previous_status)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	self->priv->emitted_status = (guint) status;
	if (status == self->priv->pending_status) {
		_tmp0_ = self->priv->timeout_id != ((guint) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
		self->priv->pending_status = MPRIS_PLAYBACK_STATUS_UNKNOWN;
	}
}

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

static void
mpris_player_wrapper_class_init (MprisPlayerWrapperClass * klass,
                                 gpointer klass_data)
{
	mpris_player_wrapper_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MprisPlayerWrapper_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) mpris_player_wrapper_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_mpris_player_wrapper_get_property;
	G_OBJECT_CLASS (klass)->finalize = mpris_player_wrapper_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MPRIS_PLAYER_WRAPPER_STATUS_PROPERTY, mpris_player_wrapper_properties[MPRIS_PLAYER_WRAPPER_STATUS_PROPERTY] = g_param_spec_enum ("status", "status", "status", MPRIS_TYPE_PLAYBACK_STATUS, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), MPRIS_PLAYER_WRAPPER_CAN_PAUSE_PROPERTY, mpris_player_wrapper_properties[MPRIS_PLAYER_WRAPPER_CAN_PAUSE_PROPERTY] = g_param_spec_boolean ("can-pause", "can-pause", "can-pause", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	mpris_player_wrapper_signals[MPRIS_PLAYER_WRAPPER_STATUS_CHANGED_SIGNAL] = g_signal_new_class_handler ("status-changed", MPRIS_TYPE_PLAYER_WRAPPER, G_SIGNAL_RUN_LAST, (GCallback) mpris_player_wrapper_real_status_changed, NULL, NULL, g_cclosure_user_marshal_VOID__ENUM_ENUM, G_TYPE_NONE, 2, MPRIS_TYPE_PLAYBACK_STATUS, MPRIS_TYPE_PLAYBACK_STATUS);
}

static void
mpris_player_wrapper_instance_init (MprisPlayerWrapper * self,
                                    gpointer klass)
{
	self->priv = mpris_player_wrapper_get_instance_private (self);
	self->priv->_status = MPRIS_PLAYBACK_STATUS_UNKNOWN;
	self->priv->player_proxy = NULL;
	self->priv->paused_timestamp = FT_TIMESTAMP_UNDEFINED;
	self->priv->status_changed_id = (guint) 0;
	self->priv->timeout_id = 0U;
	self->priv->emitted_status = (guint) MPRIS_PLAYBACK_STATUS_UNKNOWN;
	self->priv->pending_status = MPRIS_PLAYBACK_STATUS_UNKNOWN;
	self->associated_state = FT_STATE_STOPPED;
	self->auto_paused = FALSE;
}

static void
mpris_player_wrapper_finalize (GObject * obj)
{
	MprisPlayerWrapper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MPRIS_TYPE_PLAYER_WRAPPER, MprisPlayerWrapper);
	_g_object_unref0 (self->priv->player_proxy);
	_g_free0 (self->priv->dbus_name);
	G_OBJECT_CLASS (mpris_player_wrapper_parent_class)->finalize (obj);
}

GType
mpris_player_wrapper_get_type (void)
{
	return mpris_player_wrapper_type_id;
}

GType
mpris_player_wrapper_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (MprisPlayerWrapperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mpris_player_wrapper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MprisPlayerWrapper), 0, (GInstanceInitFunc) mpris_player_wrapper_instance_init, NULL };
	mpris_player_wrapper_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "MprisPlayerWrapper", &g_define_type_info, 0);
	MprisPlayerWrapper_private_offset = sizeof (MprisPlayerWrapperPrivate);
	return mpris_player_wrapper_type_id;
}

static void
_vala_mpris_player_wrapper_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	MprisPlayerWrapper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MPRIS_TYPE_PLAYER_WRAPPER, MprisPlayerWrapper);
	switch (property_id) {
		case MPRIS_PLAYER_WRAPPER_STATUS_PROPERTY:
		g_value_set_enum (value, mpris_player_wrapper_get_status (self));
		break;
		case MPRIS_PLAYER_WRAPPER_CAN_PAUSE_PROPERTY:
		g_value_set_boolean (value, mpris_player_wrapper_get_can_pause (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

