/* add-keyserver-dialog.c generated by valac 0.56.1, the Vala compiler
 * generated from add-keyserver-dialog.vala, do not modify */

/*
 * Seahorse
 *
 * Copyright (C) 2004-2005 Stefan Walter
 * Copyright (C) 2017 Niels De Graef
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see
 * <http://www.gnu.org/licenses/>.
 */

#include "seahorse-common.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>

enum  {
	SEAHORSE_ADD_KEYSERVER_DIALOG_0_PROPERTY,
	SEAHORSE_ADD_KEYSERVER_DIALOG_NUM_PROPERTIES
};
static GParamSpec* seahorse_add_keyserver_dialog_properties[SEAHORSE_ADD_KEYSERVER_DIALOG_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)))

struct _SeahorseAddKeyserverDialogPrivate {
	gchar** keyserver_types;
	gint keyserver_types_length1;
	gint _keyserver_types_size_;
	GtkEntry* keyserver_host;
	GtkEntry* keyserver_port;
	GtkComboBoxText* keyserver_type;
	GtkBox* port_block;
};

static gint SeahorseAddKeyserverDialog_private_offset;
static gpointer seahorse_add_keyserver_dialog_parent_class = NULL;

static void __lambda10_ (SeahorseAddKeyserverDialog* self);
static void seahorse_add_keyserver_dialog_on_prefs_add_keyserver_uri_changed (SeahorseAddKeyserverDialog* self);
static void ___lambda10__gtk_combo_box_changed (GtkComboBox* _sender,
                                         gpointer self);
static void __lambda11_ (SeahorseAddKeyserverDialog* self);
static void ___lambda11__gtk_editable_changed (GtkEditable* _sender,
                                        gpointer self);
static void __lambda12_ (SeahorseAddKeyserverDialog* self);
static void ___lambda12__gtk_editable_changed (GtkEditable* _sender,
                                        gpointer self);
static void seahorse_add_keyserver_dialog_finalize (GObject * obj);
static GType seahorse_add_keyserver_dialog_get_type_once (void);
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 gssize _vala_array_length (gpointer array);

static inline gpointer
seahorse_add_keyserver_dialog_get_instance_private (SeahorseAddKeyserverDialog* self)
{
	return G_STRUCT_MEMBER_P (self, SeahorseAddKeyserverDialog_private_offset);
}

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

static void
__lambda10_ (SeahorseAddKeyserverDialog* self)
{
	seahorse_add_keyserver_dialog_on_prefs_add_keyserver_uri_changed (self);
}

static void
___lambda10__gtk_combo_box_changed (GtkComboBox* _sender,
                                    gpointer self)
{
	__lambda10_ ((SeahorseAddKeyserverDialog*) self);
}

static void
__lambda11_ (SeahorseAddKeyserverDialog* self)
{
	seahorse_add_keyserver_dialog_on_prefs_add_keyserver_uri_changed (self);
}

static void
___lambda11__gtk_editable_changed (GtkEditable* _sender,
                                   gpointer self)
{
	__lambda11_ ((SeahorseAddKeyserverDialog*) self);
}

static void
__lambda12_ (SeahorseAddKeyserverDialog* self)
{
	seahorse_add_keyserver_dialog_on_prefs_add_keyserver_uri_changed (self);
}

static void
___lambda12__gtk_editable_changed (GtkEditable* _sender,
                                   gpointer self)
{
	__lambda12_ ((SeahorseAddKeyserverDialog*) self);
}

SeahorseAddKeyserverDialog*
seahorse_add_keyserver_dialog_construct (GType object_type,
                                         GtkWindow* parent)
{
	SeahorseAddKeyserverDialog * self = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp2_;
	GtkBox* content = NULL;
	GObject* _tmp6_;
	GtkBox* _tmp7_;
	GtkBox* _tmp8_;
	GtkBox* _tmp9_;
	GObject* _tmp10_;
	GtkEntry* _tmp11_;
	GObject* _tmp12_;
	GtkEntry* _tmp13_;
	GObject* _tmp14_;
	GtkComboBoxText* _tmp15_;
	GObject* _tmp16_;
	GtkBox* _tmp17_;
	GtkComboBoxText* _tmp18_;
	GtkEntry* _tmp19_;
	GtkEntry* _tmp20_;
	gchar** _tmp21_;
	gint _tmp21__length1;
	GtkComboBoxText* _tmp29_;
	GtkComboBoxText* _tmp30_;
	GtkButton* save_button = NULL;
	GtkWidget* _tmp31_;
	GtkButton* _tmp32_;
	GtkStyleContext* _tmp33_;
	GError* _inner_error0_ = NULL;
	self = (SeahorseAddKeyserverDialog*) g_object_new (object_type, "title", _ ("Add Key Server"), "transient-for", parent, "modal", TRUE, "window-position", GTK_WIN_POS_CENTER_ON_PARENT, "default-width", 400, "use-header-bar", 1, NULL);
	_tmp1_ = _tmp0_ = seahorse_server_category_get_types ();
	self->priv->keyserver_types = (_vala_array_free (self->priv->keyserver_types, self->priv->keyserver_types_length1, (GDestroyNotify) g_free), NULL);
	self->priv->keyserver_types = _tmp1_;
	self->priv->keyserver_types_length1 = _vala_array_length (_tmp0_);
	self->priv->_keyserver_types_size_ = self->priv->keyserver_types_length1;
	_tmp2_ = gtk_builder_new ();
	builder = _tmp2_;
	{
		gchar* path = NULL;
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("/org/gnome/Seahorse/seahorse-add-keyserver.ui");
		path = _tmp3_;
		gtk_builder_add_from_resource (builder, path, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (path);
			goto __catch0_g_error;
		}
		_g_free0 (path);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = err;
		_tmp5_ = _tmp4_->message;
		g_critical ("add-keyserver-dialog.vala:47: %s", _tmp5_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (builder);
		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 NULL;
	}
	_tmp6_ = gtk_builder_get_object (builder, "add-keyserver");
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_box_get_type (), GtkBox));
	content = _tmp7_;
	_tmp8_ = gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp9_ = content;
	gtk_container_add ((GtkContainer*) _tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = gtk_builder_get_object (builder, "keyserver-host");
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, gtk_entry_get_type (), GtkEntry));
	_g_object_unref0 (self->priv->keyserver_host);
	self->priv->keyserver_host = _tmp11_;
	_tmp12_ = gtk_builder_get_object (builder, "keyserver-port");
	_tmp13_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, gtk_entry_get_type (), GtkEntry));
	_g_object_unref0 (self->priv->keyserver_port);
	self->priv->keyserver_port = _tmp13_;
	_tmp14_ = gtk_builder_get_object (builder, "keyserver-type");
	_tmp15_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, gtk_combo_box_text_get_type (), GtkComboBoxText));
	_g_object_unref0 (self->priv->keyserver_type);
	self->priv->keyserver_type = _tmp15_;
	_tmp16_ = gtk_builder_get_object (builder, "port-block");
	_tmp17_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, gtk_box_get_type (), GtkBox));
	_g_object_unref0 (self->priv->port_block);
	self->priv->port_block = _tmp17_;
	_tmp18_ = self->priv->keyserver_type;
	g_signal_connect_object ((GtkComboBox*) _tmp18_, "changed", (GCallback) ___lambda10__gtk_combo_box_changed, self, 0);
	_tmp19_ = self->priv->keyserver_host;
	g_signal_connect_object ((GtkEditable*) _tmp19_, "changed", (GCallback) ___lambda11__gtk_editable_changed, self, 0);
	_tmp20_ = self->priv->keyserver_port;
	g_signal_connect_object ((GtkEditable*) _tmp20_, "changed", (GCallback) ___lambda12__gtk_editable_changed, self, 0);
	_tmp21_ = self->priv->keyserver_types;
	_tmp21__length1 = self->priv->keyserver_types_length1;
	{
		gchar** type_collection = NULL;
		gint type_collection_length1 = 0;
		gint _type_collection_size_ = 0;
		gint type_it = 0;
		type_collection = _tmp21_;
		type_collection_length1 = _tmp21__length1;
		for (type_it = 0; type_it < type_collection_length1; type_it = type_it + 1) {
			gchar* _tmp22_;
			gchar* type = NULL;
			_tmp22_ = g_strdup (type_collection[type_it]);
			type = _tmp22_;
			{
				SeahorseServerCategory* category = NULL;
				const gchar* _tmp23_;
				SeahorseServerCategory* _tmp24_;
				GtkComboBoxText* _tmp25_;
				SeahorseServerCategory* _tmp26_;
				const gchar* _tmp27_;
				const gchar* _tmp28_;
				_tmp23_ = type;
				_tmp24_ = seahorse_server_category_find_category (_tmp23_);
				category = _tmp24_;
				_tmp25_ = self->priv->keyserver_type;
				_tmp26_ = category;
				_tmp27_ = seahorse_server_category_get_description (_tmp26_);
				_tmp28_ = _tmp27_;
				gtk_combo_box_text_append_text (_tmp25_, _tmp28_);
				_g_free0 (type);
			}
		}
	}
	_tmp29_ = self->priv->keyserver_type;
	gtk_combo_box_text_append_text (_tmp29_, _ ("Custom"));
	_tmp30_ = self->priv->keyserver_type;
	gtk_combo_box_set_active ((GtkComboBox*) _tmp30_, 0);
	gtk_dialog_add_button ((GtkDialog*) self, _ ("Cancel"), (gint) GTK_RESPONSE_CANCEL);
	_tmp31_ = gtk_dialog_add_button ((GtkDialog*) self, _ ("Save"), (gint) GTK_RESPONSE_OK);
	_tmp32_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, gtk_button_get_type (), GtkButton));
	save_button = _tmp32_;
	_tmp33_ = gtk_widget_get_style_context ((GtkWidget*) save_button);
	gtk_style_context_add_class (_tmp33_, "suggested-action");
	gtk_widget_show ((GtkWidget*) self);
	_g_object_unref0 (save_button);
	_g_object_unref0 (content);
	_g_object_unref0 (builder);
	return self;
}

SeahorseAddKeyserverDialog*
seahorse_add_keyserver_dialog_new (GtkWindow* parent)
{
	return seahorse_add_keyserver_dialog_construct (SEAHORSE_TYPE_ADD_KEYSERVER_DIALOG, parent);
}

gchar*
seahorse_add_keyserver_dialog_calculate_keyserver_uri (SeahorseAddKeyserverDialog* self)
{
	gchar* scheme = NULL;
	gint active = 0;
	GtkComboBoxText* _tmp0_;
	gint i = 0;
	gboolean _tmp1_ = FALSE;
	gchar* host = NULL;
	GtkEntry* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gboolean _tmp21_ = FALSE;
	const gchar* _tmp22_;
	const gchar* _tmp24_;
	gchar* port = NULL;
	GtkEntry* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	const gchar* _tmp33_;
	gchar* uri = NULL;
	const gchar* _tmp34_;
	const gchar* _tmp35_;
	gchar* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp43_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	scheme = NULL;
	_tmp0_ = self->priv->keyserver_type;
	active = gtk_combo_box_get_active ((GtkComboBox*) _tmp0_);
	if (active >= 0) {
		gchar** _tmp2_;
		gint _tmp2__length1;
		_tmp2_ = self->priv->keyserver_types;
		_tmp2__length1 = self->priv->keyserver_types_length1;
		_tmp1_ = _tmp2_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		gboolean _tmp8_ = FALSE;
		gboolean _tmp9_ = FALSE;
		{
			gboolean _tmp3_ = FALSE;
			i = 0;
			_tmp3_ = TRUE;
			while (TRUE) {
				gboolean _tmp5_ = FALSE;
				gchar** _tmp6_;
				gint _tmp6__length1;
				const gchar* _tmp7_;
				if (!_tmp3_) {
					gint _tmp4_;
					_tmp4_ = i;
					i = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp6_ = self->priv->keyserver_types;
				_tmp6__length1 = self->priv->keyserver_types_length1;
				_tmp7_ = _tmp6_[i];
				if (_tmp7_ != NULL) {
					_tmp5_ = i < active;
				} else {
					_tmp5_ = FALSE;
				}
				if (!_tmp5_) {
					break;
				}
			}
		}
		if (i == active) {
			gchar** _tmp10_;
			gint _tmp10__length1;
			const gchar* _tmp11_;
			_tmp10_ = self->priv->keyserver_types;
			_tmp10__length1 = self->priv->keyserver_types_length1;
			_tmp11_ = _tmp10_[active];
			_tmp9_ = _tmp11_ != NULL;
		} else {
			_tmp9_ = FALSE;
		}
		if (_tmp9_) {
			gchar** _tmp12_;
			gint _tmp12__length1;
			const gchar* _tmp13_;
			_tmp12_ = self->priv->keyserver_types;
			_tmp12__length1 = self->priv->keyserver_types_length1;
			_tmp13_ = _tmp12_[active];
			_tmp8_ = g_strcmp0 (_tmp13_, "") != 0;
		} else {
			_tmp8_ = FALSE;
		}
		if (_tmp8_) {
			gchar** _tmp14_;
			gint _tmp14__length1;
			const gchar* _tmp15_;
			gchar* _tmp16_;
			_tmp14_ = self->priv->keyserver_types;
			_tmp14__length1 = self->priv->keyserver_types_length1;
			_tmp15_ = _tmp14_[active];
			_tmp16_ = g_strdup (_tmp15_);
			_g_free0 (scheme);
			scheme = _tmp16_;
		}
	}
	_tmp17_ = self->priv->keyserver_host;
	_tmp18_ = gtk_entry_get_text (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strdup (_tmp19_);
	host = _tmp20_;
	_tmp22_ = host;
	if (_tmp22_ == NULL) {
		_tmp21_ = TRUE;
	} else {
		const gchar* _tmp23_;
		_tmp23_ = host;
		_tmp21_ = g_strcmp0 (_tmp23_, "") == 0;
	}
	if (_tmp21_) {
		result = NULL;
		_g_free0 (host);
		_g_free0 (scheme);
		return result;
	}
	_tmp24_ = scheme;
	if (_tmp24_ == NULL) {
		const gchar* _tmp25_ = NULL;
		const gchar* _tmp26_;
		gchar* _tmp28_;
		_tmp26_ = host;
		if (seahorse_server_category_is_valid_uri (_tmp26_)) {
			const gchar* _tmp27_;
			_tmp27_ = host;
			_tmp25_ = _tmp27_;
		} else {
			_tmp25_ = NULL;
		}
		_tmp28_ = g_strdup (_tmp25_);
		result = _tmp28_;
		_g_free0 (host);
		_g_free0 (scheme);
		return result;
	}
	_tmp29_ = self->priv->keyserver_port;
	_tmp30_ = gtk_entry_get_text (_tmp29_);
	_tmp31_ = _tmp30_;
	_tmp32_ = g_strdup (_tmp31_);
	port = _tmp32_;
	_tmp33_ = port;
	if (g_strcmp0 (_tmp33_, "") == 0) {
		_g_free0 (port);
		port = NULL;
	}
	_tmp34_ = scheme;
	_tmp35_ = host;
	_tmp36_ = g_strdup_printf ("%s://%s", _tmp34_, _tmp35_);
	uri = _tmp36_;
	_tmp37_ = port;
	if (_tmp37_ != NULL) {
		const gchar* _tmp38_;
		const gchar* _tmp39_;
		gchar* _tmp40_;
		gchar* _tmp41_;
		gchar* _tmp42_;
		_tmp38_ = uri;
		_tmp39_ = port;
		_tmp40_ = g_strdup_printf (":%s", _tmp39_);
		_tmp41_ = _tmp40_;
		_tmp42_ = g_strconcat (_tmp38_, _tmp41_, NULL);
		_g_free0 (uri);
		uri = _tmp42_;
		_g_free0 (_tmp41_);
	}
	_tmp43_ = uri;
	if (!seahorse_server_category_is_valid_uri (_tmp43_)) {
		_g_free0 (uri);
		uri = NULL;
	}
	result = uri;
	_g_free0 (port);
	_g_free0 (host);
	_g_free0 (scheme);
	return result;
}

static void
seahorse_add_keyserver_dialog_on_prefs_add_keyserver_uri_changed (SeahorseAddKeyserverDialog* self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint active = 0;
	GtkComboBoxText* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = seahorse_add_keyserver_dialog_calculate_keyserver_uri (self);
	_tmp1_ = _tmp0_;
	gtk_dialog_set_response_sensitive ((GtkDialog*) self, (gint) GTK_RESPONSE_OK, _tmp1_ != NULL);
	_g_free0 (_tmp1_);
	_tmp2_ = self->priv->keyserver_type;
	active = gtk_combo_box_get_active ((GtkComboBox*) _tmp2_);
	if (active > -1) {
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		gchar** _tmp5_;
		gint _tmp5__length1;
		GtkBox* _tmp10_;
		_tmp5_ = self->priv->keyserver_types;
		_tmp5__length1 = self->priv->keyserver_types_length1;
		if (_tmp5_ != NULL) {
			gchar** _tmp6_;
			gint _tmp6__length1;
			const gchar* _tmp7_;
			_tmp6_ = self->priv->keyserver_types;
			_tmp6__length1 = self->priv->keyserver_types_length1;
			_tmp7_ = _tmp6_[active];
			_tmp4_ = _tmp7_ != NULL;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			gchar** _tmp8_;
			gint _tmp8__length1;
			const gchar* _tmp9_;
			_tmp8_ = self->priv->keyserver_types;
			_tmp8__length1 = self->priv->keyserver_types_length1;
			_tmp9_ = _tmp8_[active];
			_tmp3_ = g_strcmp0 (_tmp9_, "") != 0;
		} else {
			_tmp3_ = FALSE;
		}
		_tmp10_ = self->priv->port_block;
		gtk_widget_set_visible ((GtkWidget*) _tmp10_, _tmp3_);
	}
}

static void
seahorse_add_keyserver_dialog_class_init (SeahorseAddKeyserverDialogClass * klass,
                                          gpointer klass_data)
{
	seahorse_add_keyserver_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SeahorseAddKeyserverDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = seahorse_add_keyserver_dialog_finalize;
}

static void
seahorse_add_keyserver_dialog_instance_init (SeahorseAddKeyserverDialog * self,
                                             gpointer klass)
{
	self->priv = seahorse_add_keyserver_dialog_get_instance_private (self);
}

static void
seahorse_add_keyserver_dialog_finalize (GObject * obj)
{
	SeahorseAddKeyserverDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_TYPE_ADD_KEYSERVER_DIALOG, SeahorseAddKeyserverDialog);
	self->priv->keyserver_types = (_vala_array_free (self->priv->keyserver_types, self->priv->keyserver_types_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->keyserver_host);
	_g_object_unref0 (self->priv->keyserver_port);
	_g_object_unref0 (self->priv->keyserver_type);
	_g_object_unref0 (self->priv->port_block);
	G_OBJECT_CLASS (seahorse_add_keyserver_dialog_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
seahorse_add_keyserver_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseAddKeyserverDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_add_keyserver_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseAddKeyserverDialog), 0, (GInstanceInitFunc) seahorse_add_keyserver_dialog_instance_init, NULL };
	GType seahorse_add_keyserver_dialog_type_id;
	seahorse_add_keyserver_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "SeahorseAddKeyserverDialog", &g_define_type_info, 0);
	SeahorseAddKeyserverDialog_private_offset = g_type_add_instance_private (seahorse_add_keyserver_dialog_type_id, sizeof (SeahorseAddKeyserverDialogPrivate));
	return seahorse_add_keyserver_dialog_type_id;
}

GType
seahorse_add_keyserver_dialog_get_type (void)
{
	static volatile gsize seahorse_add_keyserver_dialog_type_id__once = 0;
	if (g_once_init_enter (&seahorse_add_keyserver_dialog_type_id__once)) {
		GType seahorse_add_keyserver_dialog_type_id;
		seahorse_add_keyserver_dialog_type_id = seahorse_add_keyserver_dialog_get_type_once ();
		g_once_init_leave (&seahorse_add_keyserver_dialog_type_id__once, seahorse_add_keyserver_dialog_type_id);
	}
	return seahorse_add_keyserver_dialog_type_id__once;
}

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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

