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

/*  This file is part of corebird, a Gtk+ linux Twitter client.
 *  Copyright (C) 2013 Timm Bäder
 *
 *  corebird 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  corebird 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 corebird.  If not, see <http://www.gnu.org/licenses/>.
 */

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


#define TYPE_COLLECT (collect_get_type ())
#define COLLECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COLLECT, Collect))
#define COLLECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COLLECT, CollectClass))
#define IS_COLLECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COLLECT))
#define IS_COLLECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COLLECT))
#define COLLECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_COLLECT, CollectClass))

typedef struct _Collect Collect;
typedef struct _CollectClass CollectClass;
typedef struct _CollectPrivate CollectPrivate;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _Collect {
	GObject parent_instance;
	CollectPrivate * priv;
};

struct _CollectClass {
	GObjectClass parent_class;
};

struct _CollectPrivate {
	gint cur;
	gint max;
	GError* error;
};


static gpointer collect_parent_class = NULL;

GType collect_get_type (void) G_GNUC_CONST;
#define COLLECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_COLLECT, CollectPrivate))
enum  {
	COLLECT_DUMMY_PROPERTY
};
Collect* collect_new (gint max);
Collect* collect_construct (GType object_type, gint max);
void collect_emit (Collect* self, GError* _error_);
static void collect_finalize (GObject* obj);


Collect* collect_construct (GType object_type, gint max) {
	Collect * self = NULL;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	_tmp0_ = max;
	g_return_val_if_fail (_tmp0_ >= 0, NULL);
	self = (Collect*) g_object_new (object_type, NULL);
	_tmp1_ = max;
	self->priv->max = _tmp1_;
	return self;
}


Collect* collect_new (gint max) {
	return collect_construct (TYPE_COLLECT, max);
}


static gpointer _g_error_copy0 (gpointer self) {
	return self ? g_error_copy (self) : NULL;
}


void collect_emit (Collect* self, GError* _error_) {
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	GError* _tmp2_ = NULL;
	GError* _tmp3_ = NULL;
	gint _tmp7_ = 0;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	g_return_if_fail (IS_COLLECT (self));
	_tmp0_ = self->priv->cur;
	_tmp1_ = self->priv->max;
	g_return_if_fail (_tmp0_ < _tmp1_);
	_tmp2_ = self->priv->error;
	if (_tmp2_ != NULL) {
		return;
	}
	_tmp3_ = _error_;
	if (_tmp3_ != NULL) {
		GError* _tmp4_ = NULL;
		GError* _tmp5_ = NULL;
		GError* _tmp6_ = NULL;
		_tmp4_ = _error_;
		g_signal_emit_by_name (self, "finished", _tmp4_);
		_tmp5_ = _error_;
		_tmp6_ = _g_error_copy0 (_tmp5_);
		_g_error_free0 (self->priv->error);
		self->priv->error = _tmp6_;
		return;
	}
	_tmp7_ = self->priv->cur;
	self->priv->cur = _tmp7_ + 1;
	_tmp8_ = self->priv->cur;
	_tmp9_ = self->priv->max;
	if (_tmp8_ == _tmp9_) {
		g_signal_emit_by_name (self, "finished", NULL);
	}
}


static void collect_class_init (CollectClass * klass) {
	collect_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (CollectPrivate));
	G_OBJECT_CLASS (klass)->finalize = collect_finalize;
	g_signal_new ("finished", TYPE_COLLECT, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
}


static void collect_instance_init (Collect * self) {
	self->priv = COLLECT_GET_PRIVATE (self);
	self->priv->cur = 0;
	self->priv->error = NULL;
}


static void collect_finalize (GObject* obj) {
	Collect * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_COLLECT, Collect);
	_g_error_free0 (self->priv->error);
	G_OBJECT_CLASS (collect_parent_class)->finalize (obj);
}


GType collect_get_type (void) {
	static volatile gsize collect_type_id__volatile = 0;
	if (g_once_init_enter (&collect_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (CollectClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) collect_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Collect), 0, (GInstanceInitFunc) collect_instance_init, NULL };
		GType collect_type_id;
		collect_type_id = g_type_register_static (G_TYPE_OBJECT, "Collect", &g_define_type_info, 0);
		g_once_init_leave (&collect_type_id__volatile, collect_type_id);
	}
	return collect_type_id__volatile;
}



