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

#include <glib-object.h>
#include <poppler.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gio/gio.h>

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

#define PDFPC_TYPE_ACTION_MAPPING (pdfpc_action_mapping_get_type ())
#define PDFPC_ACTION_MAPPING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMapping))
#define PDFPC_ACTION_MAPPING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMappingClass))
#define PDFPC_IS_ACTION_MAPPING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_ACTION_MAPPING))
#define PDFPC_IS_ACTION_MAPPING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_ACTION_MAPPING))
#define PDFPC_ACTION_MAPPING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMappingClass))

typedef struct _pdfpcActionMapping pdfpcActionMapping;
typedef struct _pdfpcActionMappingClass pdfpcActionMappingClass;
typedef struct _pdfpcActionMappingPrivate pdfpcActionMappingPrivate;

#define PDFPC_TYPE_PRESENTATION_CONTROLLER (pdfpc_presentation_controller_get_type ())
#define PDFPC_PRESENTATION_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_PRESENTATION_CONTROLLER, pdfpcPresentationController))
#define PDFPC_PRESENTATION_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_PRESENTATION_CONTROLLER, pdfpcPresentationControllerClass))
#define PDFPC_IS_PRESENTATION_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_PRESENTATION_CONTROLLER))
#define PDFPC_IS_PRESENTATION_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_PRESENTATION_CONTROLLER))
#define PDFPC_PRESENTATION_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_PRESENTATION_CONTROLLER, pdfpcPresentationControllerClass))

typedef struct _pdfpcPresentationController pdfpcPresentationController;
typedef struct _pdfpcPresentationControllerClass pdfpcPresentationControllerClass;
typedef enum  {
	PDFPC_ACTION_MAPPING_ACTION_TYPE_LINK,
	PDFPC_ACTION_MAPPING_ACTION_TYPE_MOVIE
} pdfpcActionMappingActionType;

#define PDFPC_ACTION_MAPPING_TYPE_ACTION_TYPE (pdfpc_action_mapping_action_type_get_type ())

#define PDFPC_TYPE_LINK_ACTION (pdfpc_link_action_get_type ())
#define PDFPC_LINK_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_LINK_ACTION, pdfpcLinkAction))
#define PDFPC_LINK_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_LINK_ACTION, pdfpcLinkActionClass))
#define PDFPC_IS_LINK_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_LINK_ACTION))
#define PDFPC_IS_LINK_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_LINK_ACTION))
#define PDFPC_LINK_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_LINK_ACTION, pdfpcLinkActionClass))

typedef struct _pdfpcLinkAction pdfpcLinkAction;
typedef struct _pdfpcLinkActionClass pdfpcLinkActionClass;
typedef struct _pdfpcLinkActionPrivate pdfpcLinkActionPrivate;
enum  {
	PDFPC_LINK_ACTION_0_PROPERTY,
	PDFPC_LINK_ACTION_NUM_PROPERTIES
};
static GParamSpec* pdfpc_link_action_properties[PDFPC_LINK_ACTION_NUM_PROPERTIES];
#define __vala_PopplerAction_free0(var) ((var == NULL) ? NULL : (var = (_vala_PopplerAction_free (var), NULL)))

#define PDFPC_TYPE_CONTROLLED_MOVIE (pdfpc_controlled_movie_get_type ())
#define PDFPC_CONTROLLED_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_CONTROLLED_MOVIE, pdfpcControlledMovie))
#define PDFPC_CONTROLLED_MOVIE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_CONTROLLED_MOVIE, pdfpcControlledMovieClass))
#define PDFPC_IS_CONTROLLED_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_CONTROLLED_MOVIE))
#define PDFPC_IS_CONTROLLED_MOVIE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_CONTROLLED_MOVIE))
#define PDFPC_CONTROLLED_MOVIE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_CONTROLLED_MOVIE, pdfpcControlledMovieClass))

typedef struct _pdfpcControlledMovie pdfpcControlledMovie;
typedef struct _pdfpcControlledMovieClass pdfpcControlledMovieClass;
#define _g_free0(var) (var = (g_free (var), NULL))

#define PDFPC_METADATA_TYPE_PDF (pdfpc_metadata_pdf_get_type ())
#define PDFPC_METADATA_PDF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_METADATA_TYPE_PDF, pdfpcMetadataPdf))
#define PDFPC_METADATA_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_METADATA_TYPE_PDF, pdfpcMetadataPdfClass))
#define PDFPC_METADATA_IS_PDF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_METADATA_TYPE_PDF))
#define PDFPC_METADATA_IS_PDF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_METADATA_TYPE_PDF))
#define PDFPC_METADATA_PDF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_METADATA_TYPE_PDF, pdfpcMetadataPdfClass))

typedef struct _pdfpcMetadataPdf pdfpcMetadataPdf;
typedef struct _pdfpcMetadataPdfClass pdfpcMetadataPdfClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _pdfpcActionMapping {
	GObject parent_instance;
	pdfpcActionMappingPrivate * priv;
	pdfpcActionMappingActionType type;
	PopplerRectangle area;
	pdfpcPresentationController* controller;
};

struct _pdfpcActionMappingClass {
	GObjectClass parent_class;
	void (*init) (pdfpcActionMapping* self, PopplerRectangle* area, pdfpcPresentationController* controller);
	pdfpcActionMapping* (*new_from_link_mapping) (pdfpcActionMapping* self, PopplerLinkMapping* mapping, pdfpcPresentationController* controller);
	pdfpcActionMapping* (*new_from_annot_mapping) (pdfpcActionMapping* self, PopplerAnnotMapping* mapping, pdfpcPresentationController* controller);
	void (*on_mouse_enter) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventMotion* event);
	void (*on_mouse_leave) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventMotion* event);
	gboolean (*on_button_press) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventButton* event);
	gboolean (*on_button_release) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventButton* event);
	gboolean (*on_mouse_move) (pdfpcActionMapping* self, GtkWidget* widget, GdkEventMotion* event);
	gboolean (*is_sensitive) (pdfpcActionMapping* self);
	void (*on_freeze) (pdfpcActionMapping* self, gboolean frozen);
	void (*deactivate) (pdfpcActionMapping* self);
};

struct _pdfpcLinkAction {
	pdfpcActionMapping parent_instance;
	pdfpcLinkActionPrivate * priv;
	PopplerAction* action;
};

struct _pdfpcLinkActionClass {
	pdfpcActionMappingClass parent_class;
};

static gpointer pdfpc_link_action_parent_class = NULL;

VALA_EXTERN GType pdfpc_action_mapping_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcActionMapping, g_object_unref)
VALA_EXTERN GType pdfpc_presentation_controller_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcPresentationController, g_object_unref)
VALA_EXTERN GType pdfpc_action_mapping_action_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType pdfpc_link_action_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcLinkAction, g_object_unref)
VALA_EXTERN pdfpcActionMapping* pdfpc_action_mapping_new_from_link_mapping (pdfpcActionMapping* self,
                                                                PopplerLinkMapping* mapping,
                                                                pdfpcPresentationController* controller);
VALA_EXTERN void pdfpc_action_mapping_on_mouse_enter (pdfpcActionMapping* self,
                                          GtkWidget* widget,
                                          GdkEventMotion* event);
VALA_EXTERN gboolean pdfpc_action_mapping_on_button_press (pdfpcActionMapping* self,
                                               GtkWidget* widget,
                                               GdkEventButton* event);
static void _vala_PopplerAction_free (PopplerAction* self);
VALA_EXTERN pdfpcLinkAction* pdfpc_link_action_new (void);
VALA_EXTERN pdfpcLinkAction* pdfpc_link_action_construct (GType object_type);
VALA_EXTERN pdfpcActionMapping* pdfpc_action_mapping_construct (GType object_type);
VALA_EXTERN void pdfpc_link_action_init (pdfpcLinkAction* self,
                             PopplerLinkMapping* mapping,
                             pdfpcPresentationController* controller);
VALA_EXTERN void pdfpc_action_mapping_init (pdfpcActionMapping* self,
                                PopplerRectangle* area,
                                pdfpcPresentationController* controller);
VALA_EXTERN GType pdfpc_controlled_movie_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcControlledMovie, g_object_unref)
VALA_EXTERN pdfpcControlledMovie* pdfpc_link_action_find_controlled_movie (pdfpcLinkAction* self,
                                                               PopplerMovie* movie);
VALA_EXTERN gint pdfpc_presentation_controller_get_current_slide_number (pdfpcPresentationController* self);
VALA_EXTERN GType pdfpc_metadata_pdf_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcMetadataPdf, g_object_unref)
VALA_EXTERN pdfpcMetadataPdf* pdfpc_presentation_controller_get_metadata (pdfpcPresentationController* self);
VALA_EXTERN GeeList* pdfpc_metadata_pdf_get_action_mapping (pdfpcMetadataPdf* self,
                                                gint page_num);
VALA_EXTERN const gchar* pdfpc_controlled_movie_get_filename (pdfpcControlledMovie* self);
static pdfpcActionMapping* pdfpc_link_action_real_new_from_link_mapping (pdfpcActionMapping* base,
                                                                  PopplerLinkMapping* mapping,
                                                                  pdfpcPresentationController* controller);
static void pdfpc_link_action_real_on_mouse_enter (pdfpcActionMapping* base,
                                            GtkWidget* widget,
                                            GdkEventMotion* event);
static void pdfpc_link_action_launch_for_uri (pdfpcLinkAction* self,
                                       const gchar* uri,
                                       GError** error);
VALA_EXTERN gchar* pdfpc_presentation_controller_get_pdf_fname (pdfpcPresentationController* self);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static gboolean pdfpc_link_action_real_on_button_press (pdfpcActionMapping* base,
                                                 GtkWidget* widget,
                                                 GdkEventButton* event);
VALA_EXTERN gint pdfpc_metadata_pdf_find_dest (pdfpcMetadataPdf* self,
                                   PopplerDest* dest);
VALA_EXTERN void pdfpc_presentation_controller_switch_to_slide_number (pdfpcPresentationController* self,
                                                           gint slide_number,
                                                           gboolean skip_history);
VALA_EXTERN void pdfpc_controlled_movie_pause (pdfpcControlledMovie* self);
VALA_EXTERN void pdfpc_controlled_movie_rewind (pdfpcControlledMovie* self);
VALA_EXTERN void pdfpc_controlled_movie_play (pdfpcControlledMovie* self);
static void pdfpc_link_action_finalize (GObject * obj);
static GType pdfpc_link_action_get_type_once (void);

static void
_vala_PopplerAction_free (PopplerAction* self)
{
	g_boxed_free (poppler_action_get_type (), self);
}

/**
         * Base constructor does nothing except assigning the type.
         */
pdfpcLinkAction*
pdfpc_link_action_construct (GType object_type)
{
	pdfpcLinkAction * self = NULL;
	self = (pdfpcLinkAction*) pdfpc_action_mapping_construct (object_type);
	((pdfpcActionMapping*) self)->type = PDFPC_ACTION_MAPPING_ACTION_TYPE_LINK;
	return self;
}

pdfpcLinkAction*
pdfpc_link_action_new (void)
{
	return pdfpc_link_action_construct (PDFPC_TYPE_LINK_ACTION);
}

/**
         * Initializer.
         */
void
pdfpc_link_action_init (pdfpcLinkAction* self,
                        PopplerLinkMapping* mapping,
                        pdfpcPresentationController* controller)
{
	PopplerRectangle _tmp0_;
	PopplerAction* _tmp1_;
	PopplerAction* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (mapping != NULL);
	g_return_if_fail (controller != NULL);
	_tmp0_ = mapping->area;
	PDFPC_ACTION_MAPPING_CLASS (pdfpc_link_action_parent_class)->init (G_TYPE_CHECK_INSTANCE_CAST (self, PDFPC_TYPE_ACTION_MAPPING, pdfpcActionMapping), &_tmp0_, controller);
	_tmp1_ = mapping->action;
	_tmp2_ = poppler_action_copy (_tmp1_);
	__vala_PopplerAction_free0 (self->action);
	self->action = _tmp2_;
}

/**
         * Find movie on the current slide by its filename; there seems to be
         * no better way with the current Glib Poppler bindings.
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

pdfpcControlledMovie*
pdfpc_link_action_find_controlled_movie (pdfpcLinkAction* self,
                                         PopplerMovie* movie)
{
	gchar* filename = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gint page_num = 0;
	pdfpcPresentationController* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	pdfpcMetadataPdf* metadata = NULL;
	pdfpcPresentationController* _tmp6_;
	pdfpcMetadataPdf* _tmp7_;
	pdfpcMetadataPdf* _tmp8_;
	pdfpcMetadataPdf* _tmp9_;
	GeeList* mappings = NULL;
	pdfpcMetadataPdf* _tmp10_;
	GeeList* _tmp11_;
	GeeList* _tmp12_;
	pdfpcControlledMovie* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (movie != NULL, NULL);
	_tmp0_ = poppler_movie_get_filename (movie);
	_tmp1_ = g_strdup (_tmp0_);
	filename = _tmp1_;
	_tmp2_ = filename;
	if (_tmp2_ == NULL) {
		result = NULL;
		_g_free0 (filename);
		return result;
	}
	_tmp3_ = ((pdfpcActionMapping*) self)->controller;
	_tmp4_ = pdfpc_presentation_controller_get_current_slide_number (_tmp3_);
	_tmp5_ = _tmp4_;
	page_num = _tmp5_;
	_tmp6_ = ((pdfpcActionMapping*) self)->controller;
	_tmp7_ = pdfpc_presentation_controller_get_metadata (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	metadata = _tmp9_;
	_tmp10_ = metadata;
	_tmp11_ = pdfpc_metadata_pdf_get_action_mapping (_tmp10_, page_num);
	_tmp12_ = _g_object_ref0 (_tmp11_);
	mappings = _tmp12_;
	{
		GeeList* _mapping_list = NULL;
		GeeList* _tmp13_;
		gint _mapping_size = 0;
		GeeList* _tmp14_;
		gint _tmp15_;
		gint _tmp16_;
		gint _mapping_index = 0;
		_tmp13_ = mappings;
		_mapping_list = _tmp13_;
		_tmp14_ = _mapping_list;
		_tmp15_ = gee_collection_get_size ((GeeCollection*) _tmp14_);
		_tmp16_ = _tmp15_;
		_mapping_size = _tmp16_;
		_mapping_index = -1;
		while (TRUE) {
			gint _tmp17_;
			gint _tmp18_;
			pdfpcActionMapping* mapping = NULL;
			GeeList* _tmp19_;
			gpointer _tmp20_;
			pdfpcActionMapping* _tmp21_;
			_mapping_index = _mapping_index + 1;
			_tmp17_ = _mapping_index;
			_tmp18_ = _mapping_size;
			if (!(_tmp17_ < _tmp18_)) {
				break;
			}
			_tmp19_ = _mapping_list;
			_tmp20_ = gee_list_get (_tmp19_, _mapping_index);
			mapping = (pdfpcActionMapping*) _tmp20_;
			_tmp21_ = mapping;
			if (_tmp21_->type == PDFPC_ACTION_MAPPING_ACTION_TYPE_MOVIE) {
				pdfpcControlledMovie* cmovie = NULL;
				pdfpcActionMapping* _tmp22_;
				pdfpcControlledMovie* _tmp23_;
				pdfpcControlledMovie* _tmp24_;
				const gchar* _tmp25_;
				const gchar* _tmp26_;
				const gchar* _tmp27_;
				_tmp22_ = mapping;
				_tmp23_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp22_, PDFPC_TYPE_CONTROLLED_MOVIE, pdfpcControlledMovie));
				cmovie = _tmp23_;
				_tmp24_ = cmovie;
				_tmp25_ = pdfpc_controlled_movie_get_filename (_tmp24_);
				_tmp26_ = _tmp25_;
				_tmp27_ = filename;
				if (g_strcmp0 (_tmp26_, _tmp27_) == 0) {
					result = cmovie;
					_g_object_unref0 (mapping);
					_g_object_unref0 (mappings);
					_g_object_unref0 (metadata);
					_g_free0 (filename);
					return result;
				}
				_g_object_unref0 (cmovie);
			}
			_g_object_unref0 (mapping);
		}
	}
	result = NULL;
	_g_object_unref0 (mappings);
	_g_object_unref0 (metadata);
	_g_free0 (filename);
	return result;
}

/**
         * Create from the LinkMapping if the link is an internal link to a named
         * destination inside the PDF file.
         */
static pdfpcActionMapping*
pdfpc_link_action_real_new_from_link_mapping (pdfpcActionMapping* base,
                                              PopplerLinkMapping* mapping,
                                              pdfpcPresentationController* controller)
{
	pdfpcLinkAction * self;
	PopplerAction* _tmp0_;
	pdfpcActionMapping* result;
	self = (pdfpcLinkAction*) base;
	g_return_val_if_fail (mapping != NULL, NULL);
	g_return_val_if_fail (controller != NULL, NULL);
	_tmp0_ = mapping->action;
	switch (_tmp0_->type) {
		case POPPLER_ACTION_URI:
		{
			pdfpcLinkAction* new_obj = NULL;
			pdfpcLinkAction* _tmp1_;
			pdfpcLinkAction* _tmp2_;
			pdfpcLinkAction* _tmp3_;
			pdfpcActionMapping* _tmp4_;
			_tmp1_ = pdfpc_link_action_new ();
			new_obj = _tmp1_;
			_tmp2_ = new_obj;
			pdfpc_link_action_init (_tmp2_, mapping, controller);
			_tmp3_ = new_obj;
			_tmp4_ = _g_object_ref0 (PDFPC_IS_ACTION_MAPPING (_tmp3_) ? ((pdfpcActionMapping*) _tmp3_) : NULL);
			result = _tmp4_;
			_g_object_unref0 (new_obj);
			return result;
		}
		case POPPLER_ACTION_GOTO_DEST:
		{
			PopplerActionGotoDest* goto_action = NULL;
			PopplerAction* _tmp5_;
			PopplerActionGotoDest* _tmp6_;
			PopplerDest* _tmp7_;
			_tmp5_ = mapping->action;
			goto_action = (PopplerActionGotoDest*) _tmp5_;
			_tmp6_ = goto_action;
			_tmp7_ = (*_tmp6_).dest;
			if (_tmp7_->type == POPPLER_DEST_NAMED) {
				pdfpcLinkAction* new_obj = NULL;
				pdfpcLinkAction* _tmp8_;
				pdfpcLinkAction* _tmp9_;
				pdfpcLinkAction* _tmp10_;
				pdfpcActionMapping* _tmp11_;
				_tmp8_ = pdfpc_link_action_new ();
				new_obj = _tmp8_;
				_tmp9_ = new_obj;
				pdfpc_link_action_init (_tmp9_, mapping, controller);
				_tmp10_ = new_obj;
				_tmp11_ = _g_object_ref0 (PDFPC_IS_ACTION_MAPPING (_tmp10_) ? ((pdfpcActionMapping*) _tmp10_) : NULL);
				result = _tmp11_;
				_g_object_unref0 (new_obj);
				return result;
			}
			break;
		}
		case POPPLER_ACTION_MOVIE:
		{
			PopplerActionMovie* movie_action = NULL;
			PopplerAction* _tmp12_;
			PopplerMovie* movie = NULL;
			PopplerActionMovie* _tmp13_;
			PopplerMovie* _tmp14_;
			PopplerMovie* _tmp15_;
			PopplerMovie* _tmp16_;
			_tmp12_ = mapping->action;
			movie_action = (PopplerActionMovie*) _tmp12_;
			_tmp13_ = movie_action;
			_tmp14_ = (*_tmp13_).movie;
			_tmp15_ = _g_object_ref0 (_tmp14_);
			movie = _tmp15_;
			_tmp16_ = movie;
			if (_tmp16_ != NULL) {
				pdfpcLinkAction* new_obj = NULL;
				pdfpcLinkAction* _tmp17_;
				pdfpcLinkAction* _tmp18_;
				pdfpcLinkAction* _tmp19_;
				pdfpcActionMapping* _tmp20_;
				_tmp17_ = pdfpc_link_action_new ();
				new_obj = _tmp17_;
				_tmp18_ = new_obj;
				pdfpc_link_action_init (_tmp18_, mapping, controller);
				_tmp19_ = new_obj;
				_tmp20_ = _g_object_ref0 (PDFPC_IS_ACTION_MAPPING (_tmp19_) ? ((pdfpcActionMapping*) _tmp19_) : NULL);
				result = _tmp20_;
				_g_object_unref0 (new_obj);
				_g_object_unref0 (movie);
				return result;
			}
			_g_object_unref0 (movie);
			break;
		}
		default:
		{
			break;
		}
	}
	result = NULL;
	return result;
}

static void
pdfpc_link_action_real_on_mouse_enter (pdfpcActionMapping* base,
                                       GtkWidget* widget,
                                       GdkEventMotion* event)
{
	pdfpcLinkAction * self;
	GdkWindow* _tmp0_;
	GdkDisplay* _tmp1_;
	GdkCursor* _tmp2_;
	GdkCursor* _tmp3_;
	self = (pdfpcLinkAction*) base;
	g_return_if_fail (widget != NULL);
	g_return_if_fail (event != NULL);
	_tmp0_ = event->window;
	_tmp1_ = gdk_display_get_default ();
	_tmp2_ = gdk_cursor_new_from_name (_tmp1_, "hand2");
	_tmp3_ = _tmp2_;
	gdk_window_set_cursor (_tmp0_, _tmp3_);
	_g_object_unref0 (_tmp3_);
}

/**
         * Launch an application, trying to cover all corner cases.
         */
static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static void
pdfpc_link_action_launch_for_uri (pdfpcLinkAction* self,
                                  const gchar* uri,
                                  GError** error)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	_tmp0_ = g_uri_parse_scheme (uri);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		g_app_info_launch_default_for_uri (uri, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			return;
		}
	} else {
		gboolean uncertain = FALSE;
		gchar* ctype = NULL;
		gboolean _tmp3_ = FALSE;
		gchar* _tmp4_;
		GAppInfo* appinfo = NULL;
		const gchar* _tmp5_;
		GAppInfo* _tmp6_;
		gchar* path = NULL;
		GList* list = NULL;
		const gchar* _tmp14_;
		GFile* _tmp15_;
		GAppInfo* _tmp16_;
		GList* _tmp17_;
		_tmp4_ = g_content_type_guess (uri, NULL, (gsize) 0, &_tmp3_);
		uncertain = _tmp3_;
		ctype = _tmp4_;
		_tmp5_ = ctype;
		_tmp6_ = g_app_info_get_default_for_type (_tmp5_, FALSE);
		appinfo = _tmp6_;
		if (g_path_is_absolute (uri)) {
			gchar* _tmp7_;
			_tmp7_ = g_strdup (uri);
			_g_free0 (path);
			path = _tmp7_;
		} else {
			gchar* pdf_fname = NULL;
			pdfpcPresentationController* _tmp8_;
			gchar* _tmp9_;
			gchar* dirname = NULL;
			const gchar* _tmp10_;
			gchar* _tmp11_;
			const gchar* _tmp12_;
			gchar* _tmp13_;
			_tmp8_ = ((pdfpcActionMapping*) self)->controller;
			_tmp9_ = pdfpc_presentation_controller_get_pdf_fname (_tmp8_);
			pdf_fname = _tmp9_;
			_tmp10_ = pdf_fname;
			_tmp11_ = g_path_get_dirname (_tmp10_);
			dirname = _tmp11_;
			_tmp12_ = dirname;
			_tmp13_ = g_build_filename (_tmp12_, uri, NULL);
			_g_free0 (path);
			path = _tmp13_;
			_g_free0 (dirname);
			_g_free0 (pdf_fname);
		}
		list = NULL;
		_tmp14_ = path;
		_tmp15_ = g_file_new_for_path (_tmp14_);
		list = g_list_append (list, _tmp15_);
		_tmp16_ = appinfo;
		_tmp17_ = list;
		g_app_info_launch (_tmp16_, _tmp17_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			(list == NULL) ? NULL : (list = (_g_list_free__g_object_unref0_ (list), NULL));
			_g_free0 (path);
			_g_object_unref0 (appinfo);
			_g_free0 (ctype);
			return;
		}
		(list == NULL) ? NULL : (list = (_g_list_free__g_object_unref0_ (list), NULL));
		_g_free0 (path);
		_g_object_unref0 (appinfo);
		_g_free0 (ctype);
	}
}

/**
         * Goto the link's destination on left clicks.
         */
static gboolean
pdfpc_link_action_real_on_button_press (pdfpcActionMapping* base,
                                        GtkWidget* widget,
                                        GdkEventButton* event)
{
	pdfpcLinkAction * self;
	PopplerAction* _tmp0_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (pdfpcLinkAction*) base;
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	if (event->button != ((guint) 1)) {
		result = FALSE;
		return result;
	}
	_tmp0_ = self->action;
	switch (_tmp0_->type) {
		case POPPLER_ACTION_URI:
		{
			{
				PopplerAction* _tmp1_;
				PopplerActionUri _tmp2_;
				const gchar* _tmp3_;
				_tmp1_ = self->action;
				_tmp2_ = _tmp1_->uri;
				_tmp3_ = _tmp2_.uri;
				pdfpc_link_action_launch_for_uri (self, _tmp3_, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* e = NULL;
				GError* _tmp4_;
				const gchar* _tmp5_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp4_ = e;
				_tmp5_ = _tmp4_->message;
				g_printerr ("%s\n", _tmp5_);
				result = TRUE;
				_g_error_free0 (e);
				return result;
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp6_ = FALSE;
				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 _tmp6_;
			}
			break;
		}
		case POPPLER_ACTION_GOTO_DEST:
		{
			PopplerActionGotoDest* action = NULL;
			PopplerAction* _tmp7_;
			pdfpcMetadataPdf* metadata = NULL;
			pdfpcPresentationController* _tmp8_;
			pdfpcMetadataPdf* _tmp9_;
			pdfpcMetadataPdf* _tmp10_;
			pdfpcMetadataPdf* _tmp11_;
			gint slide_number = 0;
			pdfpcMetadataPdf* _tmp12_;
			PopplerActionGotoDest* _tmp13_;
			PopplerDest* _tmp14_;
			pdfpcPresentationController* _tmp15_;
			_tmp7_ = self->action;
			action = (PopplerActionGotoDest*) _tmp7_;
			_tmp8_ = ((pdfpcActionMapping*) self)->controller;
			_tmp9_ = pdfpc_presentation_controller_get_metadata (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = _g_object_ref0 (_tmp10_);
			metadata = _tmp11_;
			_tmp12_ = metadata;
			_tmp13_ = action;
			_tmp14_ = (*_tmp13_).dest;
			slide_number = pdfpc_metadata_pdf_find_dest (_tmp12_, _tmp14_);
			_tmp15_ = ((pdfpcActionMapping*) self)->controller;
			pdfpc_presentation_controller_switch_to_slide_number (_tmp15_, slide_number, FALSE);
			_g_object_unref0 (metadata);
			break;
		}
		case POPPLER_ACTION_MOVIE:
		{
			PopplerActionMovie* action = NULL;
			PopplerAction* _tmp16_;
			PopplerMovie* movie = NULL;
			PopplerActionMovie* _tmp17_;
			PopplerMovie* _tmp18_;
			PopplerMovie* _tmp19_;
			PopplerMovie* _tmp20_;
			_tmp16_ = self->action;
			action = (PopplerActionMovie*) _tmp16_;
			_tmp17_ = action;
			_tmp18_ = (*_tmp17_).movie;
			_tmp19_ = _g_object_ref0 (_tmp18_);
			movie = _tmp19_;
			_tmp20_ = movie;
			if (_tmp20_ != NULL) {
				pdfpcControlledMovie* controlled_movie = NULL;
				PopplerMovie* _tmp21_;
				pdfpcControlledMovie* _tmp22_;
				pdfpcControlledMovie* _tmp23_;
				_tmp21_ = movie;
				_tmp22_ = pdfpc_link_action_find_controlled_movie (self, _tmp21_);
				controlled_movie = _tmp22_;
				_tmp23_ = controlled_movie;
				if (_tmp23_ != NULL) {
					PopplerActionMovie* _tmp24_;
					_tmp24_ = action;
					switch ((*_tmp24_).operation) {
						case POPPLER_ACTION_MOVIE_PAUSE:
						{
							pdfpcControlledMovie* _tmp25_;
							_tmp25_ = controlled_movie;
							pdfpc_controlled_movie_pause (_tmp25_);
							break;
						}
						case POPPLER_ACTION_MOVIE_PLAY:
						{
							pdfpcControlledMovie* _tmp26_;
							pdfpcControlledMovie* _tmp27_;
							_tmp26_ = controlled_movie;
							pdfpc_controlled_movie_rewind (_tmp26_);
							_tmp27_ = controlled_movie;
							pdfpc_controlled_movie_play (_tmp27_);
							break;
						}
						case POPPLER_ACTION_MOVIE_RESUME:
						{
							pdfpcControlledMovie* _tmp28_;
							_tmp28_ = controlled_movie;
							pdfpc_controlled_movie_play (_tmp28_);
							break;
						}
						case POPPLER_ACTION_MOVIE_STOP:
						{
							pdfpcControlledMovie* _tmp29_;
							pdfpcControlledMovie* _tmp30_;
							_tmp29_ = controlled_movie;
							pdfpc_controlled_movie_pause (_tmp29_);
							_tmp30_ = controlled_movie;
							pdfpc_controlled_movie_rewind (_tmp30_);
							break;
						}
						default:
						break;
					}
				}
				_g_object_unref0 (controlled_movie);
			}
			_g_object_unref0 (movie);
			break;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
	result = TRUE;
	return result;
}

static void
pdfpc_link_action_class_init (pdfpcLinkActionClass * klass,
                              gpointer klass_data)
{
	pdfpc_link_action_parent_class = g_type_class_peek_parent (klass);
	((pdfpcActionMappingClass *) klass)->new_from_link_mapping = (pdfpcActionMapping* (*) (pdfpcActionMapping*, PopplerLinkMapping*, pdfpcPresentationController*)) pdfpc_link_action_real_new_from_link_mapping;
	((pdfpcActionMappingClass *) klass)->on_mouse_enter = (void (*) (pdfpcActionMapping*, GtkWidget*, GdkEventMotion*)) pdfpc_link_action_real_on_mouse_enter;
	((pdfpcActionMappingClass *) klass)->on_button_press = (gboolean (*) (pdfpcActionMapping*, GtkWidget*, GdkEventButton*)) pdfpc_link_action_real_on_button_press;
	G_OBJECT_CLASS (klass)->finalize = pdfpc_link_action_finalize;
}

static void
pdfpc_link_action_instance_init (pdfpcLinkAction * self,
                                 gpointer klass)
{
}

static void
pdfpc_link_action_finalize (GObject * obj)
{
	pdfpcLinkAction * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PDFPC_TYPE_LINK_ACTION, pdfpcLinkAction);
	__vala_PopplerAction_free0 (self->action);
	G_OBJECT_CLASS (pdfpc_link_action_parent_class)->finalize (obj);
}

/**
     * Action for internal links in the PDF file.
     */
static GType
pdfpc_link_action_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (pdfpcLinkActionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pdfpc_link_action_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (pdfpcLinkAction), 0, (GInstanceInitFunc) pdfpc_link_action_instance_init, NULL };
	GType pdfpc_link_action_type_id;
	pdfpc_link_action_type_id = g_type_register_static (PDFPC_TYPE_ACTION_MAPPING, "pdfpcLinkAction", &g_define_type_info, 0);
	return pdfpc_link_action_type_id;
}

GType
pdfpc_link_action_get_type (void)
{
	static volatile gsize pdfpc_link_action_type_id__once = 0;
	if (g_once_init_enter (&pdfpc_link_action_type_id__once)) {
		GType pdfpc_link_action_type_id;
		pdfpc_link_action_type_id = pdfpc_link_action_get_type_once ();
		g_once_init_leave (&pdfpc_link_action_type_id__once, pdfpc_link_action_type_id);
	}
	return pdfpc_link_action_type_id__once;
}

