/* moonshot-utils.c generated by valac 0.28.0, the Vala compiler
 * generated from moonshot-utils.vala, do not modify */

/*
 * Copyright (c) 2011-2014, JANET(UK)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of JANET(UK) nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
*/

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdio.h>
#include <glib/gstdio.h>


#define TYPE_ID_CARD (id_card_get_type ())
#define ID_CARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ID_CARD, IdCard))
#define ID_CARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ID_CARD, IdCardClass))
#define IS_ID_CARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ID_CARD))
#define IS_ID_CARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ID_CARD))
#define ID_CARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ID_CARD, IdCardClass))

typedef struct _IdCard IdCard;
typedef struct _IdCardClass IdCardClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _fclose0(var) ((var == NULL) ? NULL : (var = (fclose (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))


extern gboolean gtk_available;
gboolean gtk_available = FALSE;

GdkPixbuf* find_icon_sized (const gchar* name, GtkIconSize icon_size);
GdkPixbuf* find_icon (const gchar* name, gint size);
GType id_card_get_type (void) G_GNUC_CONST;
GdkPixbuf* get_pixbuf (IdCard* id);
const gchar* GetUserName (void);
const gchar* GetFlatStoreUsersFilePath (void);
gboolean UserForcesFlatFileStore (void);


GdkPixbuf* find_icon_sized (const gchar* name, GtkIconSize icon_size) {
	GdkPixbuf* result = NULL;
	gint width = 0;
	gint height = 0;
	GtkIconSize _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	const gchar* _tmp3_ = NULL;
	GdkPixbuf* _tmp4_ = NULL;
#line 36 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	g_return_val_if_fail (name != NULL, NULL);
#line 39 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp0_ = icon_size;
#line 39 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	gtk_icon_size_lookup (_tmp0_, &_tmp1_, &_tmp2_);
#line 39 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	width = _tmp1_;
#line 39 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	height = _tmp2_;
#line 40 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp3_ = name;
#line 40 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp4_ = find_icon (_tmp3_, width);
#line 40 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	result = _tmp4_;
#line 40 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	return result;
#line 102 "moonshot-utils.c"
}


GdkPixbuf* get_pixbuf (IdCard* id) {
	GdkPixbuf* result = NULL;
	GdkPixbuf* _tmp0_ = NULL;
#line 50 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	g_return_val_if_fail (id != NULL, NULL);
#line 52 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp0_ = find_icon ("avatar-default", 48);
#line 52 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	result = _tmp0_;
#line 52 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	return result;
#line 117 "moonshot-utils.c"
}


static gpointer _g_object_ref0 (gpointer self) {
#line 73 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	return self ? g_object_ref (self) : NULL;
#line 124 "moonshot-utils.c"
}


GdkPixbuf* find_icon (const gchar* name, gint size) {
	GdkPixbuf* result = NULL;
	gboolean _tmp0_ = FALSE;
	GError * _inner_error_ = NULL;
#line 55 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	g_return_val_if_fail (name != NULL, NULL);
#line 57 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp0_ = gtk_available;
#line 57 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	if (!_tmp0_) {
#line 58 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		result = NULL;
#line 58 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		return result;
#line 142 "moonshot-utils.c"
	}
	{
		GtkIconTheme* icon_theme = NULL;
		GtkIconTheme* _tmp1_ = NULL;
		GtkIconTheme* _tmp2_ = NULL;
		GdkPixbuf* _tmp3_ = NULL;
		GtkIconTheme* _tmp4_ = NULL;
		const gchar* _tmp5_ = NULL;
		gint _tmp6_ = 0;
		GdkPixbuf* _tmp7_ = NULL;
		GdkPixbuf* _tmp8_ = NULL;
#line 73 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp1_ = gtk_icon_theme_get_default ();
#line 73 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp2_ = _g_object_ref0 (_tmp1_);
#line 73 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		icon_theme = _tmp2_;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp4_ = icon_theme;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp5_ = name;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp6_ = size;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp7_ = gtk_icon_theme_load_icon (_tmp4_, _tmp5_, _tmp6_, GTK_ICON_LOOKUP_FORCE_SIZE, &_inner_error_);
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp3_ = _tmp7_;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			_g_object_unref0 (icon_theme);
#line 174 "moonshot-utils.c"
			goto __catch10_g_error;
		}
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp8_ = _tmp3_;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp3_ = NULL;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		result = _tmp8_;
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_g_object_unref0 (_tmp3_);
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_g_object_unref0 (icon_theme);
#line 74 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		return result;
#line 189 "moonshot-utils.c"
	}
	goto __finally10;
	__catch10_g_error:
	{
		GError* e = NULL;
		FILE* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		GError* _tmp11_ = NULL;
		const gchar* _tmp12_ = NULL;
#line 59 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		e = _inner_error_;
#line 59 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_inner_error_ = NULL;
#line 79 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp9_ = stdout;
#line 79 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp10_ = name;
#line 79 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp11_ = e;
#line 79 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp12_ = _tmp11_->message;
#line 79 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		fprintf (_tmp9_, "Error loading icon '%s': %s\n", _tmp10_, _tmp12_);
#line 80 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		result = NULL;
#line 80 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_g_error_free0 (e);
#line 80 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		return result;
#line 219 "moonshot-utils.c"
	}
	__finally10:
#line 59 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	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);
#line 59 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	g_clear_error (&_inner_error_);
#line 59 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	return NULL;
#line 228 "moonshot-utils.c"
}


static gchar* g_file_stream_read_line (FILE* self) {
	gchar* result = NULL;
	gint c = 0;
	GString* ret = NULL;
	GString* _tmp7_ = NULL;
#line 3171 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
	g_return_val_if_fail (self != NULL, NULL);
#line 3173 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
	ret = NULL;
#line 3174 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
	while (TRUE) {
#line 243 "moonshot-utils.c"
		gint _tmp0_ = 0;
		gint _tmp1_ = 0;
		GString* _tmp2_ = NULL;
		gint _tmp4_ = 0;
		GString* _tmp5_ = NULL;
		gint _tmp6_ = 0;
#line 3174 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp0_ = fgetc (self);
#line 3174 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		c = _tmp0_;
#line 3174 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp1_ = c;
#line 3174 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		if (!(_tmp1_ != EOF)) {
#line 3174 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
			break;
#line 260 "moonshot-utils.c"
		}
#line 3175 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp2_ = ret;
#line 3175 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		if (_tmp2_ == NULL) {
#line 266 "moonshot-utils.c"
			GString* _tmp3_ = NULL;
#line 3176 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
			_tmp3_ = g_string_new ("");
#line 3176 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
			_g_string_free0 (ret);
#line 3176 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
			ret = _tmp3_;
#line 274 "moonshot-utils.c"
		}
#line 3178 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp4_ = c;
#line 3178 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		if (_tmp4_ == ((gint) '\n')) {
#line 3179 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
			break;
#line 282 "moonshot-utils.c"
		}
#line 3181 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp5_ = ret;
#line 3181 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp6_ = c;
#line 3181 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		g_string_append_c ((GString*) _tmp5_, (gchar) _tmp6_);
#line 290 "moonshot-utils.c"
	}
#line 3183 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
	_tmp7_ = ret;
#line 3183 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
	if (_tmp7_ == NULL) {
#line 3184 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		result = NULL;
#line 3184 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_g_string_free0 (ret);
#line 3184 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		return result;
#line 302 "moonshot-utils.c"
	} else {
		GString* _tmp8_ = NULL;
		const gchar* _tmp9_ = NULL;
		gchar* _tmp10_ = NULL;
#line 3186 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp8_ = ret;
#line 3186 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp9_ = ((GString*) _tmp8_)->str;
#line 3186 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_tmp10_ = g_strdup (_tmp9_);
#line 3186 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		result = _tmp10_;
#line 3186 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		_g_string_free0 (ret);
#line 3186 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
		return result;
#line 319 "moonshot-utils.c"
	}
#line 3171 "/usr/share/vala-0.28/vapi/glib-2.0.vapi"
	_g_string_free0 (ret);
#line 323 "moonshot-utils.c"
}


gboolean UserForcesFlatFileStore (void) {
	gboolean result = FALSE;
	gchar* username = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* flatstore_users_filename = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	FILE* flatstore_users = NULL;
	const gchar* _tmp4_ = NULL;
	FILE* _tmp5_ = NULL;
	FILE* _tmp6_ = NULL;
	gchar* flatstore_username = NULL;
#line 89 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp0_ = GetUserName ();
#line 89 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp1_ = g_strdup (_tmp0_);
#line 89 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	username = _tmp1_;
#line 90 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp2_ = GetFlatStoreUsersFilePath ();
#line 90 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp3_ = g_strdup (_tmp2_);
#line 90 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	flatstore_users_filename = _tmp3_;
#line 91 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp4_ = flatstore_users_filename;
#line 91 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp5_ = g_fopen (_tmp4_, "r");
#line 91 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	flatstore_users = _tmp5_;
#line 92 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_tmp6_ = flatstore_users;
#line 92 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	if (_tmp6_ == NULL) {
#line 93 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		result = FALSE;
#line 93 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_fclose0 (flatstore_users);
#line 93 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_g_free0 (flatstore_users_filename);
#line 93 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_g_free0 (username);
#line 93 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		return result;
#line 372 "moonshot-utils.c"
	}
#line 95 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	flatstore_username = NULL;
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	while (TRUE) {
#line 378 "moonshot-utils.c"
		FILE* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		const gchar* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp7_ = flatstore_users;
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp8_ = g_file_stream_read_line (_tmp7_);
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_g_free0 (flatstore_username);
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		flatstore_username = _tmp8_;
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp9_ = flatstore_username;
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		if (!(_tmp9_ != NULL)) {
#line 96 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			break;
#line 398 "moonshot-utils.c"
		}
#line 97 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp10_ = username;
#line 97 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		_tmp11_ = flatstore_username;
#line 97 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
		if (g_strcmp0 (_tmp10_, _tmp11_) == 0) {
#line 98 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			result = TRUE;
#line 98 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			_g_free0 (flatstore_username);
#line 98 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			_fclose0 (flatstore_users);
#line 98 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			_g_free0 (flatstore_users_filename);
#line 98 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			_g_free0 (username);
#line 98 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
			return result;
#line 418 "moonshot-utils.c"
		}
	}
#line 101 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	result = FALSE;
#line 101 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_g_free0 (flatstore_username);
#line 101 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_fclose0 (flatstore_users);
#line 101 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_g_free0 (flatstore_users_filename);
#line 101 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	_g_free0 (username);
#line 101 "/home/hartmans/moonshot/moonshot/ui/src/moonshot-utils.vala"
	return result;
#line 433 "moonshot-utils.c"
}



