/* monitor-events.c generated by valac 0.20.1, the Vala compiler
 * generated from monitor-events.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include "zeitgeist-datamodel.h"
#include "zeitgeist.h"

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))



void on_events_inserted (ZeitgeistTimeRange* tr, ZeitgeistResultSet* events);
gint _vala_main (void);
static void _g_object_unref0_ (gpointer var);
static void _on_events_inserted_zeitgeist_monitor_events_inserted (ZeitgeistMonitor* _sender, ZeitgeistTimeRange* time_range, ZeitgeistResultSet* events, gpointer self);


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


void on_events_inserted (ZeitgeistTimeRange* tr, ZeitgeistResultSet* events) {
	ZeitgeistResultSet* _tmp0_;
	guint _tmp1_ = 0U;
	g_return_if_fail (tr != NULL);
	g_return_if_fail (events != NULL);
	_tmp0_ = events;
	_tmp1_ = zeitgeist_result_set_size (_tmp0_);
	g_message ("monitor-events.vala:3: %u events inserted", _tmp1_);
	{
		ZeitgeistResultSet* _tmp2_;
		ZeitgeistResultSet* _tmp3_ = NULL;
		ZeitgeistResultSet* _event_it;
		ZeitgeistEvent* event = NULL;
		_tmp2_ = events;
		_tmp3_ = zeitgeist_result_set_iterator (_tmp2_);
		_event_it = _tmp3_;
		while (TRUE) {
			ZeitgeistResultSet* _tmp4_;
			ZeitgeistEvent* _tmp5_ = NULL;
			ZeitgeistEvent* _tmp6_;
			_tmp4_ = _event_it;
			_tmp5_ = zeitgeist_result_set_next_value (_tmp4_);
			_g_object_unref0 (event);
			event = _tmp5_;
			_tmp6_ = event;
			if (!(_tmp6_ != NULL)) {
				break;
			}
			{
				gint i;
				i = 0;
				{
					gboolean _tmp7_;
					_tmp7_ = TRUE;
					while (TRUE) {
						gboolean _tmp8_;
						gint _tmp10_;
						ZeitgeistEvent* _tmp11_;
						gint _tmp12_ = 0;
						ZeitgeistEvent* _tmp13_;
						GPtrArray* _tmp14_;
						GPtrArray* _tmp15_;
						gint _tmp16_;
						gconstpointer _tmp17_ = NULL;
						ZeitgeistSubject* _tmp18_;
						ZeitgeistSubject* subject;
						ZeitgeistSubject* _tmp19_;
						const gchar* _tmp20_;
						const gchar* _tmp21_;
						_tmp8_ = _tmp7_;
						if (!_tmp8_) {
							gint _tmp9_;
							_tmp9_ = i;
							i = _tmp9_ + 1;
						}
						_tmp7_ = FALSE;
						_tmp10_ = i;
						_tmp11_ = event;
						_tmp12_ = zeitgeist_event_num_subjects (_tmp11_);
						if (!(_tmp10_ < _tmp12_)) {
							break;
						}
						_tmp13_ = event;
						_tmp14_ = zeitgeist_event_get_subjects (_tmp13_);
						_tmp15_ = _tmp14_;
						_tmp16_ = i;
						_tmp17_ = g_ptr_array_index (_tmp15_, (guint) _tmp16_);
						_tmp18_ = _g_object_ref0 ((ZeitgeistSubject*) _tmp17_);
						subject = _tmp18_;
						_tmp19_ = subject;
						_tmp20_ = zeitgeist_subject_get_uri (_tmp19_);
						_tmp21_ = _tmp20_;
						g_message ("monitor-events.vala:10:  * %s", _tmp21_);
						_g_object_unref0 (subject);
					}
				}
			}
		}
		_g_object_unref0 (event);
		_g_object_unref0 (_event_it);
	}
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static gpointer _g_ptr_array_ref0 (gpointer self) {
	return self ? g_ptr_array_ref (self) : NULL;
}


static void _on_events_inserted_zeitgeist_monitor_events_inserted (ZeitgeistMonitor* _sender, ZeitgeistTimeRange* time_range, ZeitgeistResultSet* events, gpointer self) {
	on_events_inserted (time_range, events);
}


gint _vala_main (void) {
	gint result = 0;
	GMainLoop* _tmp0_;
	GMainLoop* loop;
	ZeitgeistTimeRange* _tmp1_;
	ZeitgeistTimeRange* time_range;
	GPtrArray* _tmp2_;
	GPtrArray* template;
	GPtrArray* _tmp3_;
	ZeitgeistMonitor* _tmp4_;
	ZeitgeistMonitor* monitor;
	ZeitgeistLog* _tmp5_;
	ZeitgeistLog* log;
	GError * _inner_error_ = NULL;
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	loop = _tmp0_;
	_tmp1_ = zeitgeist_time_range_new_anytime ();
	time_range = _tmp1_;
	_tmp2_ = g_ptr_array_new_with_free_func (_g_object_unref0_);
	template = _tmp2_;
	_tmp3_ = _g_ptr_array_ref0 (template);
	_tmp4_ = zeitgeist_monitor_new (time_range, _tmp3_);
	monitor = _tmp4_;
	_tmp5_ = zeitgeist_log_new ();
	log = _tmp5_;
	g_signal_connect (monitor, "events-inserted", (GCallback) _on_events_inserted_zeitgeist_monitor_events_inserted, NULL);
	zeitgeist_log_install_monitor (log, monitor, &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (log);
		_g_object_unref0 (monitor);
		_g_ptr_array_unref0 (template);
		_g_object_unref0 (time_range);
		_g_main_loop_unref0 (loop);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	g_main_loop_run (loop);
	result = 0;
	_g_object_unref0 (log);
	_g_object_unref0 (monitor);
	_g_ptr_array_unref0 (template);
	_g_object_unref0 (time_range);
	_g_main_loop_unref0 (loop);
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main ();
}



