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

#include <glib-object.h>
#include <gtk/gtk.h>
#include <adwaita.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.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 DC_TYPE_IMAGE_VIEWER (dc_image_viewer_get_type ())
#define DC_IMAGE_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_IMAGE_VIEWER, DcImageViewer))
#define DC_IMAGE_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_IMAGE_VIEWER, DcImageViewerClass))
#define DC_IS_IMAGE_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_IMAGE_VIEWER))
#define DC_IS_IMAGE_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_IMAGE_VIEWER))
#define DC_IMAGE_VIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_IMAGE_VIEWER, DcImageViewerClass))

typedef struct _DcImageViewer DcImageViewer;
typedef struct _DcImageViewerClass DcImageViewerClass;
typedef struct _DcImageViewerPrivate DcImageViewerPrivate;

#define DC_TYPE_WINDOW (dc_window_get_type ())
#define DC_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_WINDOW, DcWindow))
#define DC_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_WINDOW, DcWindowClass))
#define DC_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_WINDOW))
#define DC_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_WINDOW))
#define DC_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_WINDOW, DcWindowClass))

typedef struct _DcWindow DcWindow;
typedef struct _DcWindowClass DcWindowClass;
enum  {
	DC_IMAGE_VIEWER_0_PROPERTY,
	DC_IMAGE_VIEWER_WIDGET_PROPERTY,
	DC_IMAGE_VIEWER_VISIBLE_PROPERTY,
	DC_IMAGE_VIEWER_CURRENT_PATH_PROPERTY,
	DC_IMAGE_VIEWER_NUM_PROPERTIES
};
static GParamSpec* dc_image_viewer_properties[DC_IMAGE_VIEWER_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 _Block27Data Block27Data;

#define DC_TYPE_POPOVER_BUTTON (dc_popover_button_get_type ())
#define DC_POPOVER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_POPOVER_BUTTON, DcPopoverButton))
#define DC_POPOVER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_POPOVER_BUTTON, DcPopoverButtonClass))
#define DC_IS_POPOVER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_POPOVER_BUTTON))
#define DC_IS_POPOVER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_POPOVER_BUTTON))
#define DC_POPOVER_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_POPOVER_BUTTON, DcPopoverButtonClass))

typedef struct _DcPopoverButton DcPopoverButton;
typedef struct _DcPopoverButtonClass DcPopoverButtonClass;

struct _DcImageViewer {
	GObject parent_instance;
	DcImageViewerPrivate * priv;
};

struct _DcImageViewerClass {
	GObjectClass parent_class;
};

struct _DcImageViewerPrivate {
	GtkWidget* _widget;
	DcWindow* window;
	GtkPicture* picture;
	GtkButton* prev_btn;
	GtkButton* next_btn;
	gchar** paths;
	gint paths_length1;
	gint _paths_size_;
	gint index;
};

struct _Block27Data {
	int _ref_count_;
	DcImageViewer* self;
	gchar* path;
};

static gint DcImageViewer_private_offset;
static gpointer dc_image_viewer_parent_class = NULL;

VALA_EXTERN GType dc_image_viewer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcImageViewer, g_object_unref)
VALA_EXTERN GType dc_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWindow, g_object_unref)
VALA_EXTERN DcImageViewer* dc_image_viewer_new (void);
VALA_EXTERN DcImageViewer* dc_image_viewer_construct (GType object_type);
static void __lambda178_ (DcImageViewer* self);
static void dc_image_viewer_go_prev (DcImageViewer* self);
static void ___lambda178__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static void __lambda179_ (DcImageViewer* self);
static void dc_image_viewer_go_next (DcImageViewer* self);
static void ___lambda179__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static void dc_image_viewer_set_widget (DcImageViewer* self,
                                 GtkWidget* value);
static void __lambda180_ (DcImageViewer* self,
                   gint n,
                   gdouble x,
                   gdouble y);
VALA_EXTERN GtkWidget* dc_image_viewer_get_widget (DcImageViewer* self);
VALA_EXTERN void dc_image_viewer_hide (DcImageViewer* self);
static void ___lambda180__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                              gint n_press,
                                              gdouble x,
                                              gdouble y,
                                              gpointer self);
static void __lambda181_ (DcImageViewer* self,
                   gint n,
                   gdouble x,
                   gdouble y);
static void dc_image_viewer_show_menu (DcImageViewer* self,
                                gdouble x,
                                gdouble y);
static void ___lambda181__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                              gint n_press,
                                              gdouble x,
                                              gdouble y,
                                              gpointer self);
VALA_EXTERN void dc_image_viewer_set_window (DcImageViewer* self,
                                 DcWindow* w);
static void dc_image_viewer_toast (DcImageViewer* self,
                            const gchar* text);
VALA_EXTERN void dc_window_show_toast (DcWindow* self,
                           const gchar* message);
VALA_EXTERN void dc_image_viewer_show_list (DcImageViewer* self,
                                gchar** image_paths,
                                gint image_paths_length1,
                                gint start_index);
static gchar** _vala_array_dup8 (gchar** self,
                          gssize length);
static gboolean dc_image_viewer_load_current (DcImageViewer* self);
VALA_EXTERN void dc_image_viewer_replace_list (DcImageViewer* self,
                                   gchar** image_paths,
                                   gint image_paths_length1);
static gchar** _vala_array_dup9 (gchar** self,
                          gssize length);
static void dc_image_viewer_update_nav_buttons (DcImageViewer* self);
VALA_EXTERN gboolean dc_image_viewer_handle_key (DcImageViewer* self,
                                     guint keyval);
static Block27Data* block27_data_ref (Block27Data* _data27_);
static void block27_data_unref (void * _userdata_);
VALA_EXTERN GType dc_popover_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcPopoverButton, g_object_unref)
VALA_EXTERN DcPopoverButton* dc_popover_button_new (GtkPopover* popover,
                                        const gchar* label,
                                        gboolean destructive,
                                        gboolean hexpand);
VALA_EXTERN DcPopoverButton* dc_popover_button_construct (GType object_type,
                                              GtkPopover* popover,
                                              const gchar* label,
                                              gboolean destructive,
                                              gboolean hexpand);
static void __lambda182_ (Block27Data* _data27_);
VALA_EXTERN void dc_window_save_attachment (DcWindow* self,
                                const gchar* src_path,
                                const gchar* name,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
VALA_EXTERN void dc_window_save_attachment_finish (DcWindow* self,
                                       GAsyncResult* _res_);
static void ___lambda182__dc_popover_button_selected (DcPopoverButton* _sender,
                                               gpointer self);
VALA_EXTERN void dc_unparent_on_close (GtkPopover* popover);
VALA_EXTERN gboolean dc_image_viewer_get_visible (DcImageViewer* self);
VALA_EXTERN const gchar* dc_image_viewer_get_current_path (DcImageViewer* self);
static void dc_image_viewer_finalize (GObject * obj);
static GType dc_image_viewer_get_type_once (void);
static void _vala_dc_image_viewer_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec);
static void _vala_dc_image_viewer_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_image_viewer_get_instance_private (DcImageViewer* self)
{
	return G_STRUCT_MEMBER_P (self, DcImageViewer_private_offset);
}

static void
__lambda178_ (DcImageViewer* self)
{
	dc_image_viewer_go_prev (self);
}

static void
___lambda178__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda178_ ((DcImageViewer*) self);
}

static void
__lambda179_ (DcImageViewer* self)
{
	dc_image_viewer_go_next (self);
}

static void
___lambda179__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda179_ ((DcImageViewer*) self);
}

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

static void
__lambda180_ (DcImageViewer* self,
              gint n,
              gdouble x,
              gdouble y)
{
	GtkWidget* picked = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	_tmp0_ = self->priv->_widget;
	_tmp1_ = gtk_widget_pick (_tmp0_, x, y, GTK_PICK_DEFAULT);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	picked = _tmp2_;
	{
		GtkWidget* w = NULL;
		GtkWidget* _tmp3_;
		GtkWidget* _tmp4_;
		_tmp3_ = picked;
		_tmp4_ = _g_object_ref0 (_tmp3_);
		w = _tmp4_;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				GtkWidget* _tmp9_;
				gboolean _tmp10_ = FALSE;
				GtkWidget* _tmp11_;
				GtkButton* _tmp12_;
				if (!_tmp5_) {
					GtkWidget* _tmp6_;
					GtkWidget* _tmp7_;
					GtkWidget* _tmp8_;
					_tmp6_ = w;
					_tmp7_ = gtk_widget_get_parent (_tmp6_);
					_tmp8_ = _g_object_ref0 (_tmp7_);
					_g_object_unref0 (w);
					w = _tmp8_;
				}
				_tmp5_ = FALSE;
				_tmp9_ = w;
				if (!(_tmp9_ != NULL)) {
					break;
				}
				_tmp11_ = w;
				_tmp12_ = self->priv->prev_btn;
				if (_tmp11_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, gtk_widget_get_type (), GtkWidget)) {
					_tmp10_ = TRUE;
				} else {
					GtkWidget* _tmp13_;
					GtkButton* _tmp14_;
					_tmp13_ = w;
					_tmp14_ = self->priv->next_btn;
					_tmp10_ = _tmp13_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, gtk_widget_get_type (), GtkWidget);
				}
				if (_tmp10_) {
					_g_object_unref0 (w);
					_g_object_unref0 (picked);
					return;
				}
			}
		}
		_g_object_unref0 (w);
	}
	dc_image_viewer_hide (self);
	_g_object_unref0 (picked);
}

static void
___lambda180__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                         gint n_press,
                                         gdouble x,
                                         gdouble y,
                                         gpointer self)
{
	__lambda180_ ((DcImageViewer*) self, n_press, x, y);
}

static void
__lambda181_ (DcImageViewer* self,
              gint n,
              gdouble x,
              gdouble y)
{
	dc_image_viewer_show_menu (self, x, y);
}

static void
___lambda181__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                         gint n_press,
                                         gdouble x,
                                         gdouble y,
                                         gpointer self)
{
	__lambda181_ ((DcImageViewer*) self, n_press, x, y);
}

DcImageViewer*
dc_image_viewer_construct (GType object_type)
{
	DcImageViewer * self = NULL;
	GtkPicture* _tmp0_;
	GtkPicture* _tmp1_;
	GtkPicture* _tmp2_;
	GtkPicture* _tmp3_;
	GtkOverlay* overlay = NULL;
	GtkOverlay* _tmp4_;
	GtkPicture* _tmp5_;
	GtkButton* _tmp6_;
	GtkButton* _tmp7_;
	GtkButton* _tmp8_;
	GtkButton* _tmp9_;
	GtkButton* _tmp10_;
	GtkButton* _tmp11_;
	GtkButton* _tmp12_;
	GtkButton* _tmp13_;
	GtkButton* _tmp14_;
	GtkButton* _tmp15_;
	GtkButton* _tmp16_;
	GtkButton* _tmp17_;
	GtkButton* _tmp18_;
	GtkButton* _tmp19_;
	GtkButton* _tmp20_;
	GtkButton* _tmp21_;
	GtkButton* _tmp22_;
	GtkButton* _tmp23_;
	GtkButton* _tmp24_;
	GtkButton* _tmp25_;
	GtkGestureClick* click = NULL;
	GtkGestureClick* _tmp26_;
	GtkWidget* _tmp27_;
	GtkEventController* _tmp28_;
	GtkGestureClick* right_click = NULL;
	GtkGestureClick* _tmp29_;
	GtkWidget* _tmp30_;
	GtkEventController* _tmp31_;
	self = (DcImageViewer*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkPicture*) gtk_picture_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->picture);
	self->priv->picture = _tmp0_;
	_tmp1_ = self->priv->picture;
	gtk_picture_set_content_fit (_tmp1_, GTK_CONTENT_FIT_CONTAIN);
	_tmp2_ = self->priv->picture;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp2_, TRUE);
	_tmp3_ = self->priv->picture;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp3_, TRUE);
	_tmp4_ = (GtkOverlay*) gtk_overlay_new ();
	g_object_ref_sink (_tmp4_);
	overlay = _tmp4_;
	gtk_widget_add_css_class ((GtkWidget*) overlay, "image-viewer-overlay");
	gtk_widget_set_hexpand ((GtkWidget*) overlay, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) overlay, TRUE);
	_tmp5_ = self->priv->picture;
	gtk_overlay_set_child (overlay, (GtkWidget*) _tmp5_);
	gtk_widget_set_focusable ((GtkWidget*) overlay, TRUE);
	gtk_widget_set_can_focus ((GtkWidget*) overlay, TRUE);
	gtk_widget_set_visible ((GtkWidget*) overlay, FALSE);
	_tmp6_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->prev_btn);
	self->priv->prev_btn = _tmp6_;
	_tmp7_ = self->priv->prev_btn;
	gtk_button_set_icon_name (_tmp7_, "go-previous-symbolic");
	_tmp8_ = self->priv->prev_btn;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, "circular");
	_tmp9_ = self->priv->prev_btn;
	gtk_widget_add_css_class ((GtkWidget*) _tmp9_, "osd");
	_tmp10_ = self->priv->prev_btn;
	gtk_widget_set_halign ((GtkWidget*) _tmp10_, GTK_ALIGN_START);
	_tmp11_ = self->priv->prev_btn;
	gtk_widget_set_valign ((GtkWidget*) _tmp11_, GTK_ALIGN_CENTER);
	_tmp12_ = self->priv->prev_btn;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp12_, 12);
	_tmp13_ = self->priv->prev_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp13_, FALSE);
	_tmp14_ = self->priv->prev_btn;
	g_signal_connect_object (_tmp14_, "clicked", (GCallback) ___lambda178__gtk_button_clicked, self, 0);
	_tmp15_ = self->priv->prev_btn;
	gtk_overlay_add_overlay (overlay, (GtkWidget*) _tmp15_);
	_tmp16_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->priv->next_btn);
	self->priv->next_btn = _tmp16_;
	_tmp17_ = self->priv->next_btn;
	gtk_button_set_icon_name (_tmp17_, "go-next-symbolic");
	_tmp18_ = self->priv->next_btn;
	gtk_widget_add_css_class ((GtkWidget*) _tmp18_, "circular");
	_tmp19_ = self->priv->next_btn;
	gtk_widget_add_css_class ((GtkWidget*) _tmp19_, "osd");
	_tmp20_ = self->priv->next_btn;
	gtk_widget_set_halign ((GtkWidget*) _tmp20_, GTK_ALIGN_END);
	_tmp21_ = self->priv->next_btn;
	gtk_widget_set_valign ((GtkWidget*) _tmp21_, GTK_ALIGN_CENTER);
	_tmp22_ = self->priv->next_btn;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp22_, 12);
	_tmp23_ = self->priv->next_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp23_, FALSE);
	_tmp24_ = self->priv->next_btn;
	g_signal_connect_object (_tmp24_, "clicked", (GCallback) ___lambda179__gtk_button_clicked, self, 0);
	_tmp25_ = self->priv->next_btn;
	gtk_overlay_add_overlay (overlay, (GtkWidget*) _tmp25_);
	dc_image_viewer_set_widget (self, (GtkWidget*) overlay);
	_tmp26_ = (GtkGestureClick*) gtk_gesture_click_new ();
	click = _tmp26_;
	gtk_gesture_single_set_button ((GtkGestureSingle*) click, (guint) 1);
	g_signal_connect_object (click, "pressed", (GCallback) ___lambda180__gtk_gesture_click_pressed, self, 0);
	_tmp27_ = self->priv->_widget;
	_tmp28_ = _g_object_ref0 ((GtkEventController*) click);
	gtk_widget_add_controller (_tmp27_, _tmp28_);
	_tmp29_ = (GtkGestureClick*) gtk_gesture_click_new ();
	right_click = _tmp29_;
	gtk_gesture_single_set_button ((GtkGestureSingle*) right_click, (guint) 3);
	g_signal_connect_object (right_click, "pressed", (GCallback) ___lambda181__gtk_gesture_click_pressed, self, 0);
	_tmp30_ = self->priv->_widget;
	_tmp31_ = _g_object_ref0 ((GtkEventController*) right_click);
	gtk_widget_add_controller (_tmp30_, _tmp31_);
	_g_object_unref0 (right_click);
	_g_object_unref0 (click);
	_g_object_unref0 (overlay);
	return self;
}

DcImageViewer*
dc_image_viewer_new (void)
{
	return dc_image_viewer_construct (DC_TYPE_IMAGE_VIEWER);
}

void
dc_image_viewer_set_window (DcImageViewer* self,
                            DcWindow* w)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	self->priv->window = w;
}

static void
dc_image_viewer_toast (DcImageViewer* self,
                       const gchar* text)
{
	DcWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = self->priv->window;
	if (_tmp0_ != NULL) {
		DcWindow* _tmp1_;
		_tmp1_ = self->priv->window;
		dc_window_show_toast (_tmp1_, text);
	}
}

static gchar**
_vala_array_dup8 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

void
dc_image_viewer_show_list (DcImageViewer* self,
                           gchar** image_paths,
                           gint image_paths_length1,
                           gint start_index)
{
	gboolean _tmp0_ = FALSE;
	gchar** _tmp1_;
	gint _tmp1__length1;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	g_return_if_fail (self != NULL);
	if (image_paths_length1 == 0) {
		return;
	}
	if (start_index < 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = start_index >= image_paths_length1;
	}
	if (_tmp0_) {
		start_index = 0;
	}
	_tmp1_ = (image_paths != NULL) ? _vala_array_dup8 (image_paths, image_paths_length1) : image_paths;
	_tmp1__length1 = image_paths_length1;
	self->priv->paths = (_vala_array_free (self->priv->paths, self->priv->paths_length1, (GDestroyNotify) g_free), NULL);
	self->priv->paths = _tmp1_;
	self->priv->paths_length1 = _tmp1__length1;
	self->priv->_paths_size_ = self->priv->paths_length1;
	self->priv->index = start_index;
	if (!dc_image_viewer_load_current (self)) {
		return;
	}
	_tmp2_ = self->priv->_widget;
	gtk_widget_set_visible (_tmp2_, TRUE);
	_tmp3_ = self->priv->_widget;
	gtk_widget_grab_focus (_tmp3_);
}

/**
         * Swaps the navigation list without disturbing what is on screen:
         * the entry matching the currently shown path becomes the new
         * position. Used once the full chat media list arrives after the
         * viewer was opened from the (partially loaded) conversation.
         */
static gchar**
_vala_array_dup9 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

void
dc_image_viewer_replace_list (DcImageViewer* self,
                              gchar** image_paths,
                              gint image_paths_length1)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GtkWidget* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gchar* current = NULL;
	gchar** _tmp6_;
	gint _tmp6__length1;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gint found = 0;
	gchar** _tmp13_;
	gint _tmp13__length1;
	g_return_if_fail (self != NULL);
	_tmp2_ = self->priv->_widget;
	_tmp3_ = gtk_widget_get_visible (_tmp2_);
	_tmp4_ = _tmp3_;
	if (!_tmp4_) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = self->priv->index < 0;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gchar** _tmp5_;
		gint _tmp5__length1;
		_tmp5_ = self->priv->paths;
		_tmp5__length1 = self->priv->paths_length1;
		_tmp0_ = self->priv->index >= _tmp5__length1;
	}
	if (_tmp0_) {
		return;
	}
	_tmp6_ = self->priv->paths;
	_tmp6__length1 = self->priv->paths_length1;
	_tmp7_ = _tmp6_[self->priv->index];
	_tmp8_ = g_strdup (_tmp7_);
	current = _tmp8_;
	found = -1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp9_ = FALSE;
			_tmp9_ = TRUE;
			while (TRUE) {
				const gchar* _tmp11_;
				const gchar* _tmp12_;
				if (!_tmp9_) {
					gint _tmp10_;
					_tmp10_ = i;
					i = _tmp10_ + 1;
				}
				_tmp9_ = FALSE;
				if (!(i < image_paths_length1)) {
					break;
				}
				_tmp11_ = image_paths[i];
				_tmp12_ = current;
				if (g_strcmp0 (_tmp11_, _tmp12_) == 0) {
					found = i;
					break;
				}
			}
		}
	}
	if (found < 0) {
		_g_free0 (current);
		return;
	}
	_tmp13_ = (image_paths != NULL) ? _vala_array_dup9 (image_paths, image_paths_length1) : image_paths;
	_tmp13__length1 = image_paths_length1;
	self->priv->paths = (_vala_array_free (self->priv->paths, self->priv->paths_length1, (GDestroyNotify) g_free), NULL);
	self->priv->paths = _tmp13_;
	self->priv->paths_length1 = _tmp13__length1;
	self->priv->_paths_size_ = self->priv->paths_length1;
	self->priv->index = found;
	dc_image_viewer_update_nav_buttons (self);
	_g_free0 (current);
}

void
dc_image_viewer_hide (DcImageViewer* self)
{
	GtkWidget* _tmp0_;
	GtkPicture* _tmp1_;
	gchar** _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_widget;
	gtk_widget_set_visible (_tmp0_, FALSE);
	_tmp1_ = self->priv->picture;
	gtk_picture_set_paintable (_tmp1_, NULL);
	_tmp2_ = g_new0 (gchar*, 0 + 1);
	self->priv->paths = (_vala_array_free (self->priv->paths, self->priv->paths_length1, (GDestroyNotify) g_free), NULL);
	self->priv->paths = _tmp2_;
	self->priv->paths_length1 = 0;
	self->priv->_paths_size_ = self->priv->paths_length1;
	self->priv->index = -1;
	dc_image_viewer_update_nav_buttons (self);
}

/**
         * Called by Window's key handler while the viewer is visible.
         * Returns true if the event was handled by the viewer (either
         * navigation or closing). Any non-navigation key closes.
         */
gboolean
dc_image_viewer_handle_key (DcImageViewer* self,
                            guint keyval)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	switch (keyval) {
		case GDK_KEY_Left:
		case GDK_KEY_h:
		case GDK_KEY_H:
		case GDK_KEY_k:
		case GDK_KEY_K:
		case GDK_KEY_Up:
		{
			dc_image_viewer_go_prev (self);
			result = TRUE;
			return result;
		}
		case GDK_KEY_Right:
		case GDK_KEY_l:
		case GDK_KEY_L:
		case GDK_KEY_j:
		case GDK_KEY_J:
		case GDK_KEY_Down:
		{
			dc_image_viewer_go_next (self);
			result = TRUE;
			return result;
		}
		default:
		break;
	}
	dc_image_viewer_hide (self);
	result = TRUE;
	return result;
}

static void
dc_image_viewer_go_prev (DcImageViewer* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	if (self->priv->index <= 0) {
		return;
	}
	_tmp0_ = self->priv->index;
	self->priv->index = _tmp0_ - 1;
	dc_image_viewer_load_current (self);
}

static void
dc_image_viewer_go_next (DcImageViewer* self)
{
	gboolean _tmp0_ = FALSE;
	gint _tmp2_;
	g_return_if_fail (self != NULL);
	if (self->priv->index < 0) {
		_tmp0_ = TRUE;
	} else {
		gchar** _tmp1_;
		gint _tmp1__length1;
		_tmp1_ = self->priv->paths;
		_tmp1__length1 = self->priv->paths_length1;
		_tmp0_ = self->priv->index >= (_tmp1__length1 - 1);
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = self->priv->index;
	self->priv->index = _tmp2_ + 1;
	dc_image_viewer_load_current (self);
}

static gboolean
dc_image_viewer_load_current (DcImageViewer* self)
{
	gboolean _tmp0_ = FALSE;
	gchar* path = NULL;
	gchar** _tmp2_;
	gint _tmp2__length1;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gboolean _tmp13_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (self->priv->index < 0) {
		_tmp0_ = TRUE;
	} else {
		gchar** _tmp1_;
		gint _tmp1__length1;
		_tmp1_ = self->priv->paths;
		_tmp1__length1 = self->priv->paths_length1;
		_tmp0_ = self->priv->index >= _tmp1__length1;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp2_ = self->priv->paths;
	_tmp2__length1 = self->priv->paths_length1;
	_tmp3_ = _tmp2_[self->priv->index];
	_tmp4_ = g_strdup (_tmp3_);
	path = _tmp4_;
	{
		GdkTexture* texture = NULL;
		const gchar* _tmp5_;
		GdkTexture* _tmp6_;
		GtkPicture* _tmp7_;
		GdkTexture* _tmp8_;
		_tmp5_ = path;
		_tmp6_ = gdk_texture_new_from_filename (_tmp5_, &_inner_error0_);
		texture = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp7_ = self->priv->picture;
		_tmp8_ = texture;
		gtk_picture_set_paintable (_tmp7_, (GdkPaintable*) _tmp8_);
		dc_image_viewer_update_nav_buttons (self);
		result = TRUE;
		_g_object_unref0 (texture);
		_g_free0 (path);
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp9_ = e;
		_tmp10_ = _tmp9_->message;
		_tmp11_ = g_strconcat ("Cannot open image: ", _tmp10_, NULL);
		_tmp12_ = _tmp11_;
		dc_image_viewer_toast (self, _tmp12_);
		_g_free0 (_tmp12_);
		result = FALSE;
		_g_error_free0 (e);
		_g_free0 (path);
		return result;
	}
	__finally0:
	_g_free0 (path);
	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 _tmp13_;
}

static void
dc_image_viewer_update_nav_buttons (DcImageViewer* self)
{
	GtkButton* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GtkButton* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->prev_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp0_, self->priv->index > 0);
	if (self->priv->index >= 0) {
		gchar** _tmp2_;
		gint _tmp2__length1;
		_tmp2_ = self->priv->paths;
		_tmp2__length1 = self->priv->paths_length1;
		_tmp1_ = self->priv->index < (_tmp2__length1 - 1);
	} else {
		_tmp1_ = FALSE;
	}
	_tmp3_ = self->priv->next_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp3_, _tmp1_);
}

static Block27Data*
block27_data_ref (Block27Data* _data27_)
{
	g_atomic_int_inc (&_data27_->_ref_count_);
	return _data27_;
}

static void
block27_data_unref (void * _userdata_)
{
	Block27Data* _data27_;
	_data27_ = (Block27Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data27_->_ref_count_)) {
		DcImageViewer* self;
		self = _data27_->self;
		_g_free0 (_data27_->path);
		_g_object_unref0 (self);
		g_slice_free (Block27Data, _data27_);
	}
}

static void
__lambda182_ (Block27Data* _data27_)
{
	DcImageViewer* self;
	DcWindow* _tmp0_;
	self = _data27_->self;
	_tmp0_ = self->priv->window;
	if (_tmp0_ != NULL) {
		DcWindow* _tmp1_;
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp1_ = self->priv->window;
		_tmp2_ = _data27_->path;
		_tmp3_ = _data27_->path;
		_tmp4_ = g_path_get_basename (_tmp3_);
		_tmp5_ = _tmp4_;
		dc_window_save_attachment (_tmp1_, _tmp2_, _tmp5_, NULL, NULL);
		_g_free0 (_tmp5_);
	}
}

static void
___lambda182__dc_popover_button_selected (DcPopoverButton* _sender,
                                          gpointer self)
{
	__lambda182_ (self);
}

static void
dc_image_viewer_show_menu (DcImageViewer* self,
                           gdouble x,
                           gdouble y)
{
	Block27Data* _data27_;
	gboolean _tmp0_ = FALSE;
	gchar** _tmp2_;
	gint _tmp2__length1;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	GtkPopover* popover = NULL;
	GtkPopover* _tmp5_;
	GtkBox* vbox = NULL;
	GtkBox* _tmp6_;
	GtkBox* _tmp7_;
	GtkBox* _tmp8_;
	GtkBox* _tmp9_;
	GtkBox* _tmp10_;
	DcPopoverButton* save_btn = NULL;
	GtkPopover* _tmp11_;
	DcPopoverButton* _tmp12_;
	DcPopoverButton* _tmp13_;
	GtkBox* _tmp14_;
	DcPopoverButton* _tmp15_;
	GtkPopover* _tmp16_;
	GtkBox* _tmp17_;
	GtkPopover* _tmp18_;
	GtkWidget* _tmp19_;
	GtkPopover* _tmp20_;
	GdkRectangle _tmp21_ = {0};
	GtkPopover* _tmp22_;
	GtkPopover* _tmp23_;
	g_return_if_fail (self != NULL);
	_data27_ = g_slice_new0 (Block27Data);
	_data27_->_ref_count_ = 1;
	_data27_->self = g_object_ref (self);
	if (self->priv->index < 0) {
		_tmp0_ = TRUE;
	} else {
		gchar** _tmp1_;
		gint _tmp1__length1;
		_tmp1_ = self->priv->paths;
		_tmp1__length1 = self->priv->paths_length1;
		_tmp0_ = self->priv->index >= _tmp1__length1;
	}
	if (_tmp0_) {
		block27_data_unref (_data27_);
		_data27_ = NULL;
		return;
	}
	_tmp2_ = self->priv->paths;
	_tmp2__length1 = self->priv->paths_length1;
	_tmp3_ = _tmp2_[self->priv->index];
	_tmp4_ = g_strdup (_tmp3_);
	_data27_->path = _tmp4_;
	_tmp5_ = (GtkPopover*) gtk_popover_new ();
	g_object_ref_sink (_tmp5_);
	popover = _tmp5_;
	_tmp6_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
	g_object_ref_sink (_tmp6_);
	vbox = _tmp6_;
	_tmp7_ = vbox;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp7_, 4);
	_tmp8_ = vbox;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp8_, 4);
	_tmp9_ = vbox;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp9_, 4);
	_tmp10_ = vbox;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp10_, 4);
	_tmp11_ = popover;
	_tmp12_ = dc_popover_button_new (_tmp11_, "Save image", FALSE, FALSE);
	g_object_ref_sink (_tmp12_);
	save_btn = _tmp12_;
	_tmp13_ = save_btn;
	g_signal_connect_data (_tmp13_, "selected", (GCallback) ___lambda182__dc_popover_button_selected, block27_data_ref (_data27_), (GClosureNotify) block27_data_unref, 0);
	_tmp14_ = vbox;
	_tmp15_ = save_btn;
	gtk_box_append (_tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = popover;
	_tmp17_ = vbox;
	gtk_popover_set_child (_tmp16_, (GtkWidget*) _tmp17_);
	_tmp18_ = popover;
	_tmp19_ = self->priv->_widget;
	gtk_widget_set_parent ((GtkWidget*) _tmp18_, _tmp19_);
	_tmp20_ = popover;
	_tmp21_.x = (gint) x;
	_tmp21_.y = (gint) y;
	_tmp21_.width = 1;
	_tmp21_.height = 1;
	gtk_popover_set_pointing_to (_tmp20_, &_tmp21_);
	_tmp22_ = popover;
	dc_unparent_on_close (_tmp22_);
	_tmp23_ = popover;
	gtk_popover_popup (_tmp23_);
	_g_object_unref0 (save_btn);
	_g_object_unref0 (vbox);
	_g_object_unref0 (popover);
	block27_data_unref (_data27_);
	_data27_ = NULL;
}

GtkWidget*
dc_image_viewer_get_widget (DcImageViewer* self)
{
	GtkWidget* result;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_widget;
	result = _tmp0_;
	return result;
}

static void
dc_image_viewer_set_widget (DcImageViewer* self,
                            GtkWidget* value)
{
	GtkWidget* old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_image_viewer_get_widget (self);
	if (old_value != value) {
		GtkWidget* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_widget);
		self->priv->_widget = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dc_image_viewer_properties[DC_IMAGE_VIEWER_WIDGET_PROPERTY]);
	}
}

gboolean
dc_image_viewer_get_visible (DcImageViewer* self)
{
	gboolean result;
	GtkWidget* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_widget;
	_tmp1_ = gtk_widget_get_visible (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

const gchar*
dc_image_viewer_get_current_path (DcImageViewer* self)
{
	const gchar* result;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GtkWidget* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gchar** _tmp6_;
	gint _tmp6__length1;
	const gchar* _tmp7_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp2_ = self->priv->_widget;
	_tmp3_ = gtk_widget_get_visible (_tmp2_);
	_tmp4_ = _tmp3_;
	if (!_tmp4_) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = self->priv->index < 0;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gchar** _tmp5_;
		gint _tmp5__length1;
		_tmp5_ = self->priv->paths;
		_tmp5__length1 = self->priv->paths_length1;
		_tmp0_ = self->priv->index >= _tmp5__length1;
	}
	if (_tmp0_) {
		result = NULL;
		return result;
	}
	_tmp6_ = self->priv->paths;
	_tmp6__length1 = self->priv->paths_length1;
	_tmp7_ = _tmp6_[self->priv->index];
	result = _tmp7_;
	return result;
}

static void
dc_image_viewer_class_init (DcImageViewerClass * klass,
                            gpointer klass_data)
{
	dc_image_viewer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcImageViewer_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_image_viewer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_image_viewer_set_property;
	G_OBJECT_CLASS (klass)->finalize = dc_image_viewer_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_IMAGE_VIEWER_WIDGET_PROPERTY, dc_image_viewer_properties[DC_IMAGE_VIEWER_WIDGET_PROPERTY] = g_param_spec_object ("widget", "widget", "widget", gtk_widget_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_IMAGE_VIEWER_VISIBLE_PROPERTY, dc_image_viewer_properties[DC_IMAGE_VIEWER_VISIBLE_PROPERTY] = g_param_spec_boolean ("visible", "visible", "visible", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Path of the image currently on screen, or null when hidden. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_IMAGE_VIEWER_CURRENT_PATH_PROPERTY, dc_image_viewer_properties[DC_IMAGE_VIEWER_CURRENT_PATH_PROPERTY] = g_param_spec_string ("current-path", "current-path", "current-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
dc_image_viewer_instance_init (DcImageViewer * self,
                               gpointer klass)
{
	gchar** _tmp0_;
	self->priv = dc_image_viewer_get_instance_private (self);
	self->priv->window = NULL;
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->priv->paths = _tmp0_;
	self->priv->paths_length1 = 0;
	self->priv->_paths_size_ = self->priv->paths_length1;
	self->priv->index = -1;
}

static void
dc_image_viewer_finalize (GObject * obj)
{
	DcImageViewer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_IMAGE_VIEWER, DcImageViewer);
	_g_object_unref0 (self->priv->_widget);
	_g_object_unref0 (self->priv->picture);
	_g_object_unref0 (self->priv->prev_btn);
	_g_object_unref0 (self->priv->next_btn);
	self->priv->paths = (_vala_array_free (self->priv->paths, self->priv->paths_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (dc_image_viewer_parent_class)->finalize (obj);
}

/**
     * Fullscreen image overlay shown on top of the conversation.
     * Supports navigating prev/next image in the current conversation
     * via arrow keys, hjkl, or the floating circular buttons.
     * Any other key or click closes the viewer.
     */
static GType
dc_image_viewer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcImageViewerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_image_viewer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcImageViewer), 0, (GInstanceInitFunc) dc_image_viewer_instance_init, NULL };
	GType dc_image_viewer_type_id;
	dc_image_viewer_type_id = g_type_register_static (G_TYPE_OBJECT, "DcImageViewer", &g_define_type_info, 0);
	DcImageViewer_private_offset = g_type_add_instance_private (dc_image_viewer_type_id, sizeof (DcImageViewerPrivate));
	return dc_image_viewer_type_id;
}

GType
dc_image_viewer_get_type (void)
{
	static volatile gsize dc_image_viewer_type_id__once = 0;
	if (g_once_init_enter (&dc_image_viewer_type_id__once)) {
		GType dc_image_viewer_type_id;
		dc_image_viewer_type_id = dc_image_viewer_get_type_once ();
		g_once_init_leave (&dc_image_viewer_type_id__once, dc_image_viewer_type_id);
	}
	return dc_image_viewer_type_id__once;
}

static void
_vala_dc_image_viewer_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec)
{
	DcImageViewer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_IMAGE_VIEWER, DcImageViewer);
	switch (property_id) {
		case DC_IMAGE_VIEWER_WIDGET_PROPERTY:
		g_value_set_object (value, dc_image_viewer_get_widget (self));
		break;
		case DC_IMAGE_VIEWER_VISIBLE_PROPERTY:
		g_value_set_boolean (value, dc_image_viewer_get_visible (self));
		break;
		case DC_IMAGE_VIEWER_CURRENT_PATH_PROPERTY:
		g_value_set_string (value, dc_image_viewer_get_current_path (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_image_viewer_set_property (GObject * object,
                                    guint property_id,
                                    const GValue * value,
                                    GParamSpec * pspec)
{
	DcImageViewer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_IMAGE_VIEWER, DcImageViewer);
	switch (property_id) {
		case DC_IMAGE_VIEWER_WIDGET_PROPERTY:
		dc_image_viewer_set_widget (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

