/* scannable-group.c generated by valac 0.32.0.49-00a57, the Vala compiler
 * generated from scannable-group.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <gee.h>


#define CARIBOU_TYPE_ISCANNABLE_GROUP (caribou_iscannable_group_get_type ())
#define CARIBOU_ISCANNABLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CARIBOU_TYPE_ISCANNABLE_GROUP, CaribouIScannableGroup))
#define CARIBOU_IS_ISCANNABLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CARIBOU_TYPE_ISCANNABLE_GROUP))
#define CARIBOU_ISCANNABLE_GROUP_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CARIBOU_TYPE_ISCANNABLE_GROUP, CaribouIScannableGroupIface))

typedef struct _CaribouIScannableGroup CaribouIScannableGroup;
typedef struct _CaribouIScannableGroupIface CaribouIScannableGroupIface;

#define CARIBOU_TYPE_ISCANNABLE_ITEM (caribou_iscannable_item_get_type ())
#define CARIBOU_ISCANNABLE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CARIBOU_TYPE_ISCANNABLE_ITEM, CaribouIScannableItem))
#define CARIBOU_IS_ISCANNABLE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CARIBOU_TYPE_ISCANNABLE_ITEM))
#define CARIBOU_ISCANNABLE_ITEM_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CARIBOU_TYPE_ISCANNABLE_ITEM, CaribouIScannableItemIface))

typedef struct _CaribouIScannableItem CaribouIScannableItem;
typedef struct _CaribouIScannableItemIface CaribouIScannableItemIface;

#define CARIBOU_TYPE_SCAN_GROUPING (caribou_scan_grouping_get_type ())

#define CARIBOU_TYPE_SCANNABLE_GROUP (caribou_scannable_group_get_type ())
#define CARIBOU_SCANNABLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroup))
#define CARIBOU_SCANNABLE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroupClass))
#define CARIBOU_IS_SCANNABLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CARIBOU_TYPE_SCANNABLE_GROUP))
#define CARIBOU_IS_SCANNABLE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CARIBOU_TYPE_SCANNABLE_GROUP))
#define CARIBOU_SCANNABLE_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroupClass))

typedef struct _CaribouScannableGroup CaribouScannableGroup;
typedef struct _CaribouScannableGroupClass CaribouScannableGroupClass;
typedef struct _CaribouScannableGroupPrivate CaribouScannableGroupPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _CaribouIScannableItemIface {
	GTypeInterface parent_iface;
	gboolean (*get_scan_stepping) (CaribouIScannableItem* self);
	void (*set_scan_stepping) (CaribouIScannableItem* self, gboolean value);
	gboolean (*get_scan_selected) (CaribouIScannableItem* self);
	void (*set_scan_selected) (CaribouIScannableItem* self, gboolean value);
};

typedef enum  {
	CARIBOU_SCAN_GROUPING_NONE,
	CARIBOU_SCAN_GROUPING_SUBGROUPS,
	CARIBOU_SCAN_GROUPING_ROWS,
	CARIBOU_SCAN_GROUPING_LINEAR
} CaribouScanGrouping;

struct _CaribouIScannableGroupIface {
	GTypeInterface parent_iface;
	CaribouIScannableItem* (*child_select) (CaribouIScannableGroup* self);
	void (*scan_reset) (CaribouIScannableGroup* self);
	CaribouIScannableItem** (*get_scan_children) (CaribouIScannableGroup* self, int* result_length1);
	CaribouIScannableItem* (*child_step) (CaribouIScannableGroup* self, gint cycles);
	CaribouIScannableItem** (*get_step_path) (CaribouIScannableGroup* self, int* result_length1);
	CaribouIScannableItem** (*get_selected_path) (CaribouIScannableGroup* self, int* result_length1);
	CaribouScanGrouping (*get_scan_grouping) (CaribouIScannableGroup* self);
	void (*set_scan_grouping) (CaribouIScannableGroup* self, CaribouScanGrouping value);
};

struct _CaribouScannableGroup {
	GObject parent_instance;
	CaribouScannableGroupPrivate * priv;
};

struct _CaribouScannableGroupClass {
	GObjectClass parent_class;
	CaribouIScannableItem** (*get_scan_children) (CaribouScannableGroup* self, int* result_length1);
	CaribouIScannableItem* (*child_select) (CaribouScannableGroup* self);
};

struct _CaribouScannableGroupPrivate {
	GeeLinkedList* _step_path;
	GeeLinkedList* _selected_path;
	gint _cycle_count;
	CaribouScanGrouping _scan_grouping;
	gint _scan_child_index;
};


static gpointer caribou_scannable_group_parent_class = NULL;
static CaribouIScannableGroupIface* caribou_scannable_group_caribou_iscannable_group_parent_iface = NULL;

GType caribou_iscannable_item_get_type (void) G_GNUC_CONST;
GType caribou_scan_grouping_get_type (void) G_GNUC_CONST;
GType caribou_iscannable_group_get_type (void) G_GNUC_CONST;
GType caribou_scannable_group_get_type (void) G_GNUC_CONST;
#define CARIBOU_SCANNABLE_GROUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroupPrivate))
enum  {
	CARIBOU_SCANNABLE_GROUP_DUMMY_PROPERTY,
	CARIBOU_SCANNABLE_GROUP_SCAN_GROUPING
};
CaribouIScannableItem** caribou_scannable_group_get_scan_children (CaribouScannableGroup* self, int* result_length1);
static CaribouIScannableItem** caribou_scannable_group_real_get_scan_children (CaribouScannableGroup* self, int* result_length1);
static CaribouIScannableItem** caribou_scannable_group_real_get_step_path (CaribouIScannableGroup* base, int* result_length1);
static CaribouIScannableItem** caribou_scannable_group_real_get_selected_path (CaribouIScannableGroup* base, int* result_length1);
static void caribou_scannable_group_add_to_step_path (CaribouScannableGroup* self, CaribouIScannableItem* item);
static void caribou_scannable_group_add_to_selected_path (CaribouScannableGroup* self, CaribouIScannableItem* item);
static CaribouIScannableItem* caribou_scannable_group_get_stepping_child (CaribouScannableGroup* self);
static gint caribou_scannable_group_get_scan_child_index (CaribouScannableGroup* self);
static CaribouIScannableItem* caribou_scannable_group_get_single_child (CaribouScannableGroup* self, CaribouIScannableItem* item);
CaribouIScannableItem* caribou_scannable_group_child_select (CaribouScannableGroup* self);
static CaribouIScannableItem* caribou_scannable_group_real_child_select (CaribouScannableGroup* self);
CaribouIScannableItem* caribou_iscannable_group_child_select (CaribouIScannableGroup* self);
void caribou_iscannable_item_set_scan_selected (CaribouIScannableItem* self, gboolean value);
static void caribou_scannable_group_set_scan_child_index (CaribouScannableGroup* self, gint value);
static void caribou_scannable_group_real_scan_reset (CaribouIScannableGroup* base);
void caribou_iscannable_item_set_scan_stepping (CaribouIScannableItem* self, gboolean value);
void caribou_iscannable_group_scan_reset (CaribouIScannableGroup* self);
static CaribouIScannableItem* caribou_scannable_group_real_child_step (CaribouIScannableGroup* base, gint cycles);
CaribouIScannableItem* caribou_iscannable_group_child_step (CaribouIScannableGroup* self, gint cycles);
CaribouScannableGroup* caribou_scannable_group_construct (GType object_type);
void caribou_iscannable_group_set_scan_grouping (CaribouIScannableGroup* self, CaribouScanGrouping value);
static GObject * caribou_scannable_group_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void caribou_scannable_group_finalize (GObject* obj);
CaribouScanGrouping caribou_iscannable_group_get_scan_grouping (CaribouIScannableGroup* self);
static void _vala_caribou_scannable_group_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_caribou_scannable_group_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static CaribouIScannableItem** caribou_scannable_group_real_get_scan_children (CaribouScannableGroup* self, int* result_length1) {
	g_critical ("Type `%s' does not implement abstract method `caribou_scannable_group_get_scan_children'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}


CaribouIScannableItem** caribou_scannable_group_get_scan_children (CaribouScannableGroup* self, int* result_length1) {
	g_return_val_if_fail (self != NULL, NULL);
	return CARIBOU_SCANNABLE_GROUP_GET_CLASS (self)->get_scan_children (self, result_length1);
}


static CaribouIScannableItem** caribou_scannable_group_real_get_step_path (CaribouIScannableGroup* base, int* result_length1) {
	CaribouScannableGroup * self;
	CaribouIScannableItem** result = NULL;
	GeeLinkedList* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gpointer* _tmp2_ = NULL;
	CaribouIScannableItem** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	self = (CaribouScannableGroup*) base;
	_tmp0_ = self->priv->_step_path;
	_tmp2_ = gee_collection_to_array ((GeeCollection*) _tmp0_, &_tmp1_);
	_tmp3_ = (CaribouIScannableItem**) _tmp2_;
	_tmp3__length1 = (_tmp1_ * sizeof (CaribouIScannableItem*)) / sizeof (CaribouIScannableItem*);
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}


static CaribouIScannableItem** caribou_scannable_group_real_get_selected_path (CaribouIScannableGroup* base, int* result_length1) {
	CaribouScannableGroup * self;
	CaribouIScannableItem** result = NULL;
	GeeLinkedList* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gpointer* _tmp2_ = NULL;
	CaribouIScannableItem** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	self = (CaribouScannableGroup*) base;
	_tmp0_ = self->priv->_selected_path;
	_tmp2_ = gee_collection_to_array ((GeeCollection*) _tmp0_, &_tmp1_);
	_tmp3_ = (CaribouIScannableItem**) _tmp2_;
	_tmp3__length1 = (_tmp1_ * sizeof (CaribouIScannableItem*)) / sizeof (CaribouIScannableItem*);
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}


static void caribou_scannable_group_add_to_step_path (CaribouScannableGroup* self, CaribouIScannableItem* item) {
	GeeLinkedList* _tmp0_ = NULL;
	CaribouIScannableItem* _tmp1_ = NULL;
	GeeLinkedList* _tmp2_ = NULL;
	gpointer _tmp3_ = NULL;
	CaribouIScannableItem* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->_step_path;
	_tmp1_ = item;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, _tmp1_);
	_tmp2_ = self->priv->_step_path;
	_tmp3_ = gee_deque_peek_tail ((GeeDeque*) _tmp2_);
	_tmp4_ = (CaribouIScannableItem*) _tmp3_;
	g_signal_emit_by_name ((CaribouIScannableGroup*) self, "step-item-changed", _tmp4_);
	_g_object_unref0 (_tmp4_);
}


static void caribou_scannable_group_add_to_selected_path (CaribouScannableGroup* self, CaribouIScannableItem* item) {
	GeeLinkedList* _tmp0_ = NULL;
	CaribouIScannableItem* _tmp1_ = NULL;
	GeeLinkedList* _tmp2_ = NULL;
	gpointer _tmp3_ = NULL;
	CaribouIScannableItem* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->_selected_path;
	_tmp1_ = item;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, _tmp1_);
	_tmp2_ = self->priv->_selected_path;
	_tmp3_ = gee_deque_peek_tail ((GeeDeque*) _tmp2_);
	_tmp4_ = (CaribouIScannableItem*) _tmp3_;
	g_signal_emit_by_name ((CaribouIScannableGroup*) self, "selected-item-changed", _tmp4_);
	_g_object_unref0 (_tmp4_);
}


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


static CaribouIScannableItem* caribou_scannable_group_get_stepping_child (CaribouScannableGroup* self) {
	CaribouIScannableItem* result = NULL;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	CaribouIScannableItem** _tmp2_ = NULL;
	CaribouIScannableItem** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	gint _tmp4_ = 0;
	CaribouIScannableItem* _tmp5_ = NULL;
	CaribouIScannableItem* _tmp6_ = NULL;
	CaribouIScannableItem* _tmp7_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_scan_child_index;
	if (_tmp0_ < 0) {
		result = NULL;
		return result;
	}
	_tmp2_ = caribou_scannable_group_get_scan_children (self, &_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp3__length1 = _tmp1_;
	_tmp4_ = self->priv->_scan_child_index;
	_tmp5_ = _tmp3_[_tmp4_];
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_object_unref), NULL);
	result = _tmp7_;
	return result;
}


static CaribouIScannableItem* caribou_scannable_group_get_single_child (CaribouScannableGroup* self, CaribouIScannableItem* item) {
	CaribouIScannableItem* result = NULL;
	CaribouIScannableItem* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = item;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, CARIBOU_TYPE_SCANNABLE_GROUP)) {
		CaribouIScannableItem** children = NULL;
		CaribouIScannableItem* _tmp1_ = NULL;
		gint _tmp2_ = 0;
		CaribouIScannableItem** _tmp3_ = NULL;
		gint children_length1 = 0;
		gint _children_size_ = 0;
		CaribouIScannableItem** _tmp4_ = NULL;
		gint _tmp4__length1 = 0;
		_tmp1_ = item;
		_tmp3_ = caribou_scannable_group_get_scan_children (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, CARIBOU_TYPE_SCANNABLE_GROUP) ? ((CaribouScannableGroup*) _tmp1_) : NULL, &_tmp2_);
		children = _tmp3_;
		children_length1 = _tmp2_;
		_children_size_ = children_length1;
		_tmp4_ = children;
		_tmp4__length1 = children_length1;
		if (_tmp4__length1 == 1) {
			CaribouIScannableItem** _tmp5_ = NULL;
			gint _tmp5__length1 = 0;
			CaribouIScannableItem* _tmp6_ = NULL;
			CaribouIScannableItem* _tmp7_ = NULL;
			_tmp5_ = children;
			_tmp5__length1 = children_length1;
			_tmp6_ = _tmp5_[0];
			_tmp7_ = _g_object_ref0 (_tmp6_);
			result = _tmp7_;
			children = (_vala_array_free (children, children_length1, (GDestroyNotify) g_object_unref), NULL);
			return result;
		}
		children = (_vala_array_free (children, children_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	result = NULL;
	return result;
}


static CaribouIScannableItem* caribou_scannable_group_real_child_select (CaribouScannableGroup* self) {
	CaribouIScannableItem* result = NULL;
	CaribouIScannableItem* step_child = NULL;
	CaribouIScannableItem* _tmp0_ = NULL;
	CaribouIScannableItem* selected_leaf = NULL;
	GeeLinkedList* _tmp1_ = NULL;
	gpointer _tmp2_ = NULL;
	CaribouIScannableItem* _tmp3_ = NULL;
	GeeLinkedList* _tmp19_ = NULL;
	gpointer _tmp20_ = NULL;
	_tmp0_ = caribou_scannable_group_get_stepping_child (self);
	step_child = _tmp0_;
	_tmp1_ = self->priv->_selected_path;
	_tmp2_ = gee_deque_peek_tail ((GeeDeque*) _tmp1_);
	selected_leaf = (CaribouIScannableItem*) _tmp2_;
	_tmp3_ = selected_leaf;
	if (_tmp3_ != NULL) {
		CaribouIScannableItem* _tmp4_ = NULL;
		CaribouIScannableItem* _tmp5_ = NULL;
		CaribouIScannableItem* _tmp6_ = NULL;
		CaribouIScannableItem* _tmp7_ = NULL;
		_tmp4_ = selected_leaf;
		_vala_assert (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, CARIBOU_TYPE_ISCANNABLE_GROUP), "selected_leaf is IScannableGroup");
		_tmp5_ = selected_leaf;
		_tmp6_ = caribou_iscannable_group_child_select (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, CARIBOU_TYPE_ISCANNABLE_GROUP, CaribouIScannableGroup));
		_tmp7_ = _tmp6_;
		caribou_scannable_group_add_to_selected_path (self, _tmp7_);
		_g_object_unref0 (_tmp7_);
	} else {
		CaribouIScannableItem* _tmp8_ = NULL;
		_tmp8_ = step_child;
		if (_tmp8_ != NULL) {
			CaribouIScannableItem* _tmp9_ = NULL;
			CaribouIScannableItem* _tmp10_ = NULL;
			_tmp9_ = step_child;
			caribou_iscannable_item_set_scan_selected (_tmp9_, TRUE);
			_tmp10_ = step_child;
			caribou_scannable_group_add_to_selected_path (self, _tmp10_);
			caribou_scannable_group_set_scan_child_index (self, -1);
			{
				CaribouIScannableItem* child = NULL;
				CaribouIScannableItem* _tmp11_ = NULL;
				CaribouIScannableItem* _tmp12_ = NULL;
				_tmp11_ = step_child;
				_tmp12_ = caribou_scannable_group_get_single_child (self, _tmp11_);
				child = _tmp12_;
				{
					gboolean _tmp13_ = FALSE;
					_tmp13_ = TRUE;
					while (TRUE) {
						CaribouIScannableItem* _tmp16_ = NULL;
						CaribouIScannableItem* _tmp17_ = NULL;
						CaribouIScannableItem* _tmp18_ = NULL;
						if (!_tmp13_) {
							CaribouIScannableItem* _tmp14_ = NULL;
							CaribouIScannableItem* _tmp15_ = NULL;
							_tmp14_ = child;
							_tmp15_ = caribou_scannable_group_get_single_child (self, _tmp14_);
							_g_object_unref0 (child);
							child = _tmp15_;
						}
						_tmp13_ = FALSE;
						_tmp16_ = child;
						if (!(_tmp16_ != NULL)) {
							break;
						}
						_tmp17_ = child;
						caribou_iscannable_item_set_scan_selected (_tmp17_, TRUE);
						_tmp18_ = child;
						caribou_scannable_group_add_to_selected_path (self, _tmp18_);
					}
				}
				_g_object_unref0 (child);
			}
		}
	}
	_tmp19_ = self->priv->_selected_path;
	_tmp20_ = gee_deque_peek_tail ((GeeDeque*) _tmp19_);
	result = (CaribouIScannableItem*) _tmp20_;
	_g_object_unref0 (selected_leaf);
	_g_object_unref0 (step_child);
	return result;
}


CaribouIScannableItem* caribou_scannable_group_child_select (CaribouScannableGroup* self) {
	g_return_val_if_fail (self != NULL, NULL);
	return CARIBOU_SCANNABLE_GROUP_GET_CLASS (self)->child_select (self);
}


static void caribou_scannable_group_real_scan_reset (CaribouIScannableGroup* base) {
	CaribouScannableGroup * self;
	GeeLinkedList* _tmp0_ = NULL;
	GeeLinkedList* _tmp1_ = NULL;
	gint _tmp2_ = 0;
	CaribouIScannableItem** _tmp3_ = NULL;
	self = (CaribouScannableGroup*) base;
	_tmp0_ = self->priv->_selected_path;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	_tmp1_ = self->priv->_step_path;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp1_);
	caribou_scannable_group_set_scan_child_index (self, -1);
	_tmp3_ = caribou_scannable_group_get_scan_children (self, &_tmp2_);
	{
		CaribouIScannableItem** item_collection = NULL;
		gint item_collection_length1 = 0;
		gint _item_collection_size_ = 0;
		gint item_it = 0;
		item_collection = _tmp3_;
		item_collection_length1 = _tmp2_;
		for (item_it = 0; item_it < _tmp2_; item_it = item_it + 1) {
			CaribouIScannableItem* _tmp4_ = NULL;
			CaribouIScannableItem* item = NULL;
			_tmp4_ = _g_object_ref0 (item_collection[item_it]);
			item = _tmp4_;
			{
				CaribouIScannableItem* _tmp5_ = NULL;
				CaribouIScannableItem* _tmp6_ = NULL;
				CaribouIScannableItem* _tmp7_ = NULL;
				_tmp5_ = item;
				caribou_iscannable_item_set_scan_stepping (_tmp5_, FALSE);
				_tmp6_ = item;
				caribou_iscannable_item_set_scan_selected (_tmp6_, FALSE);
				_tmp7_ = item;
				if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, CARIBOU_TYPE_ISCANNABLE_GROUP)) {
					CaribouIScannableItem* _tmp8_ = NULL;
					_tmp8_ = item;
					caribou_iscannable_group_scan_reset (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, CARIBOU_TYPE_ISCANNABLE_GROUP, CaribouIScannableGroup));
				}
				_g_object_unref0 (item);
			}
		}
		item_collection = (_vala_array_free (item_collection, item_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	g_signal_emit_by_name ((CaribouIScannableGroup*) self, "scan-cleared");
}


static CaribouIScannableItem* caribou_scannable_group_real_child_step (CaribouIScannableGroup* base, gint cycles) {
	CaribouScannableGroup * self;
	CaribouIScannableItem* result = NULL;
	CaribouIScannableItem* step_child = NULL;
	CaribouIScannableItem* _tmp0_ = NULL;
	CaribouIScannableItem* selected_leaf = NULL;
	GeeLinkedList* _tmp1_ = NULL;
	gpointer _tmp2_ = NULL;
	CaribouIScannableItem* _tmp3_ = NULL;
	GeeLinkedList* _tmp33_ = NULL;
	gpointer _tmp34_ = NULL;
	self = (CaribouScannableGroup*) base;
	_tmp0_ = caribou_scannable_group_get_stepping_child (self);
	step_child = _tmp0_;
	_tmp1_ = self->priv->_selected_path;
	_tmp2_ = gee_deque_peek_tail ((GeeDeque*) _tmp1_);
	selected_leaf = (CaribouIScannableItem*) _tmp2_;
	_tmp3_ = selected_leaf;
	if (_tmp3_ != NULL) {
		CaribouIScannableItem* _tmp4_ = NULL;
		CaribouIScannableItem* _tmp5_ = NULL;
		CaribouIScannableItem* _tmp9_ = NULL;
		_tmp4_ = step_child;
		_vala_assert (_tmp4_ == NULL, "step_child == null");
		_tmp5_ = selected_leaf;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, CARIBOU_TYPE_ISCANNABLE_GROUP)) {
			CaribouIScannableItem* _tmp6_ = NULL;
			gint _tmp7_ = 0;
			CaribouIScannableItem* _tmp8_ = NULL;
			_tmp6_ = selected_leaf;
			_tmp7_ = cycles;
			_tmp8_ = caribou_iscannable_group_child_step (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, CARIBOU_TYPE_ISCANNABLE_GROUP, CaribouIScannableGroup), _tmp7_);
			_g_object_unref0 (step_child);
			step_child = _tmp8_;
		}
		_tmp9_ = step_child;
		if (_tmp9_ != NULL) {
			CaribouIScannableItem* _tmp10_ = NULL;
			_tmp10_ = step_child;
			caribou_scannable_group_add_to_step_path (self, _tmp10_);
		} else {
			GeeLinkedList* _tmp11_ = NULL;
			_tmp11_ = self->priv->_step_path;
			gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp11_);
		}
	} else {
		gboolean _tmp12_ = FALSE;
		CaribouIScannableItem* _tmp13_ = NULL;
		_tmp13_ = step_child;
		if (_tmp13_ != NULL) {
			_tmp12_ = TRUE;
		} else {
			gint _tmp14_ = 0;
			_tmp14_ = self->priv->_scan_child_index;
			_tmp12_ = _tmp14_ == -1;
		}
		if (_tmp12_) {
			CaribouIScannableItem* _tmp15_ = NULL;
			CaribouIScannableItem** children = NULL;
			gint _tmp16_ = 0;
			CaribouIScannableItem** _tmp17_ = NULL;
			gint children_length1 = 0;
			gint _children_size_ = 0;
			gint _tmp18_ = 0;
			gint _tmp19_ = 0;
			CaribouIScannableItem** _tmp20_ = NULL;
			gint _tmp20__length1 = 0;
			gint _tmp22_ = 0;
			gint _tmp23_ = 0;
			_tmp15_ = selected_leaf;
			_vala_assert (_tmp15_ == NULL, "selected_leaf == null");
			_tmp17_ = caribou_scannable_group_get_scan_children (self, &_tmp16_);
			children = _tmp17_;
			children_length1 = _tmp16_;
			_children_size_ = children_length1;
			_tmp18_ = self->priv->_scan_child_index;
			if (_tmp18_ == -1) {
				self->priv->_cycle_count = 0;
			}
			_tmp19_ = self->priv->_scan_child_index;
			_tmp20_ = children;
			_tmp20__length1 = children_length1;
			if (_tmp19_ == (_tmp20__length1 - 1)) {
				gint _tmp21_ = 0;
				caribou_scannable_group_set_scan_child_index (self, -1);
				_tmp21_ = self->priv->_cycle_count;
				self->priv->_cycle_count = _tmp21_ + 1;
			}
			_tmp22_ = self->priv->_cycle_count;
			_tmp23_ = cycles;
			if (_tmp22_ < _tmp23_) {
				CaribouIScannableItem* _tmp24_ = NULL;
				CaribouIScannableItem** _tmp26_ = NULL;
				gint _tmp26__length1 = 0;
				gint _tmp27_ = 0;
				CaribouIScannableItem* _tmp28_ = NULL;
				CaribouIScannableItem* _tmp29_ = NULL;
				CaribouIScannableItem* _tmp30_ = NULL;
				CaribouIScannableItem* _tmp31_ = NULL;
				_tmp24_ = step_child;
				if (_tmp24_ != NULL) {
					CaribouIScannableItem* _tmp25_ = NULL;
					_tmp25_ = step_child;
					caribou_iscannable_item_set_scan_stepping (_tmp25_, FALSE);
				}
				_tmp26_ = children;
				_tmp26__length1 = children_length1;
				_tmp27_ = self->priv->_scan_child_index;
				caribou_scannable_group_set_scan_child_index (self, _tmp27_ + 1);
				_tmp28_ = _tmp26_[_tmp27_ + 1];
				_tmp29_ = _g_object_ref0 (_tmp28_);
				_g_object_unref0 (step_child);
				step_child = _tmp29_;
				_tmp30_ = step_child;
				caribou_iscannable_item_set_scan_stepping (_tmp30_, TRUE);
				_tmp31_ = step_child;
				caribou_scannable_group_add_to_step_path (self, _tmp31_);
			} else {
				GeeLinkedList* _tmp32_ = NULL;
				_tmp32_ = self->priv->_step_path;
				gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp32_);
			}
			children = (_vala_array_free (children, children_length1, (GDestroyNotify) g_object_unref), NULL);
		} else {
			g_warn_if_reached ();
		}
	}
	_tmp33_ = self->priv->_step_path;
	_tmp34_ = gee_deque_peek_tail ((GeeDeque*) _tmp33_);
	result = (CaribouIScannableItem*) _tmp34_;
	_g_object_unref0 (selected_leaf);
	_g_object_unref0 (step_child);
	return result;
}


CaribouScannableGroup* caribou_scannable_group_construct (GType object_type) {
	CaribouScannableGroup * self = NULL;
	self = (CaribouScannableGroup*) g_object_new (object_type, NULL);
	return self;
}


static CaribouScanGrouping caribou_scannable_group_real_get_scan_grouping (CaribouIScannableGroup* base) {
	CaribouScanGrouping result;
	CaribouScannableGroup* self;
	CaribouScanGrouping _tmp0_ = 0;
	self = (CaribouScannableGroup*) base;
	_tmp0_ = self->priv->_scan_grouping;
	result = _tmp0_;
	return result;
}


static void caribou_scannable_group_real_set_scan_grouping (CaribouIScannableGroup* base, CaribouScanGrouping value) {
	CaribouScannableGroup* self;
	CaribouScanGrouping _tmp0_ = 0;
	gint _tmp1_ = 0;
	CaribouIScannableItem** _tmp2_ = NULL;
	self = (CaribouScannableGroup*) base;
	_tmp0_ = value;
	self->priv->_scan_grouping = _tmp0_;
	_tmp2_ = caribou_scannable_group_get_scan_children (self, &_tmp1_);
	{
		CaribouIScannableItem** item_collection = NULL;
		gint item_collection_length1 = 0;
		gint _item_collection_size_ = 0;
		gint item_it = 0;
		item_collection = _tmp2_;
		item_collection_length1 = _tmp1_;
		for (item_it = 0; item_it < _tmp1_; item_it = item_it + 1) {
			CaribouIScannableItem* _tmp3_ = NULL;
			CaribouIScannableItem* item = NULL;
			_tmp3_ = _g_object_ref0 (item_collection[item_it]);
			item = _tmp3_;
			{
				CaribouIScannableItem* _tmp4_ = NULL;
				_tmp4_ = item;
				if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, CARIBOU_TYPE_ISCANNABLE_GROUP)) {
					CaribouIScannableItem* _tmp5_ = NULL;
					CaribouScanGrouping _tmp6_ = 0;
					_tmp5_ = item;
					_tmp6_ = value;
					caribou_iscannable_group_set_scan_grouping (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, CARIBOU_TYPE_ISCANNABLE_GROUP, CaribouIScannableGroup), _tmp6_);
				}
				_g_object_unref0 (item);
			}
		}
		item_collection = (_vala_array_free (item_collection, item_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	g_object_notify ((GObject *) self, "scan-grouping");
}


static gint caribou_scannable_group_get_scan_child_index (CaribouScannableGroup* self) {
	gint result;
	gint _tmp0_ = 0;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_scan_child_index;
	result = _tmp0_;
	return result;
}


static void caribou_scannable_group_set_scan_child_index (CaribouScannableGroup* self, gint value) {
	gint _tmp0_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_scan_child_index = _tmp0_;
}


static GObject * caribou_scannable_group_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	CaribouScannableGroup * self;
	GeeLinkedList* _tmp0_ = NULL;
	GeeLinkedList* _tmp1_ = NULL;
	parent_class = G_OBJECT_CLASS (caribou_scannable_group_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroup);
	_tmp0_ = gee_linked_list_new (CARIBOU_TYPE_ISCANNABLE_ITEM, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->_step_path);
	self->priv->_step_path = _tmp0_;
	_tmp1_ = gee_linked_list_new (CARIBOU_TYPE_ISCANNABLE_ITEM, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->_selected_path);
	self->priv->_selected_path = _tmp1_;
	return obj;
}


static void caribou_scannable_group_class_init (CaribouScannableGroupClass * klass) {
	caribou_scannable_group_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (CaribouScannableGroupPrivate));
	((CaribouScannableGroupClass *) klass)->get_scan_children = caribou_scannable_group_real_get_scan_children;
	((CaribouScannableGroupClass *) klass)->child_select = caribou_scannable_group_real_child_select;
	G_OBJECT_CLASS (klass)->get_property = _vala_caribou_scannable_group_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_caribou_scannable_group_set_property;
	G_OBJECT_CLASS (klass)->constructor = caribou_scannable_group_constructor;
	G_OBJECT_CLASS (klass)->finalize = caribou_scannable_group_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CARIBOU_SCANNABLE_GROUP_SCAN_GROUPING, g_param_spec_enum ("scan-grouping", "scan-grouping", "scan-grouping", CARIBOU_TYPE_SCAN_GROUPING, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void caribou_scannable_group_caribou_iscannable_group_interface_init (CaribouIScannableGroupIface * iface) {
	caribou_scannable_group_caribou_iscannable_group_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_scan_children = (CaribouIScannableItem** (*)(CaribouIScannableGroup*, int*)) caribou_scannable_group_get_scan_children;
	iface->get_step_path = (CaribouIScannableItem** (*)(CaribouIScannableGroup*, int*)) caribou_scannable_group_real_get_step_path;
	iface->get_selected_path = (CaribouIScannableItem** (*)(CaribouIScannableGroup*, int*)) caribou_scannable_group_real_get_selected_path;
	iface->child_select = (CaribouIScannableItem* (*)(CaribouIScannableGroup*)) caribou_scannable_group_child_select;
	iface->scan_reset = (void (*)(CaribouIScannableGroup*)) caribou_scannable_group_real_scan_reset;
	iface->child_step = (CaribouIScannableItem* (*)(CaribouIScannableGroup*, gint)) caribou_scannable_group_real_child_step;
	iface->get_scan_grouping = caribou_scannable_group_real_get_scan_grouping;
	iface->set_scan_grouping = caribou_scannable_group_real_set_scan_grouping;
}


static void caribou_scannable_group_instance_init (CaribouScannableGroup * self) {
	self->priv = CARIBOU_SCANNABLE_GROUP_GET_PRIVATE (self);
	self->priv->_scan_child_index = -1;
}


static void caribou_scannable_group_finalize (GObject* obj) {
	CaribouScannableGroup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroup);
	_g_object_unref0 (self->priv->_step_path);
	_g_object_unref0 (self->priv->_selected_path);
	G_OBJECT_CLASS (caribou_scannable_group_parent_class)->finalize (obj);
}


/**
     * Base abstract class that implements scanning mode containers.
     */
GType caribou_scannable_group_get_type (void) {
	static volatile gsize caribou_scannable_group_type_id__volatile = 0;
	if (g_once_init_enter (&caribou_scannable_group_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (CaribouScannableGroupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) caribou_scannable_group_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CaribouScannableGroup), 0, (GInstanceInitFunc) caribou_scannable_group_instance_init, NULL };
		static const GInterfaceInfo caribou_iscannable_group_info = { (GInterfaceInitFunc) caribou_scannable_group_caribou_iscannable_group_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType caribou_scannable_group_type_id;
		caribou_scannable_group_type_id = g_type_register_static (G_TYPE_OBJECT, "CaribouScannableGroup", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
		g_type_add_interface_static (caribou_scannable_group_type_id, CARIBOU_TYPE_ISCANNABLE_GROUP, &caribou_iscannable_group_info);
		g_once_init_leave (&caribou_scannable_group_type_id__volatile, caribou_scannable_group_type_id);
	}
	return caribou_scannable_group_type_id__volatile;
}


static void _vala_caribou_scannable_group_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	CaribouScannableGroup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroup);
	switch (property_id) {
		case CARIBOU_SCANNABLE_GROUP_SCAN_GROUPING:
		g_value_set_enum (value, caribou_iscannable_group_get_scan_grouping ((CaribouIScannableGroup*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_caribou_scannable_group_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	CaribouScannableGroup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CARIBOU_TYPE_SCANNABLE_GROUP, CaribouScannableGroup);
	switch (property_id) {
		case CARIBOU_SCANNABLE_GROUP_SCAN_GROUPING:
		caribou_iscannable_group_set_scan_grouping ((CaribouIScannableGroup*) self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



