/* downloader.c generated by valac 0.17.5.2-8558, the Vala compiler
 * generated from downloader.vala, do not modify */

/* This file is part of GNOME Boxes. License: LGPLv2+*/

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <osinfo/osinfo.h>
#include <libcommon.h>
#include <gdk-pixbuf/gdk-pixbuf.h>


#define BOXES_TYPE_DOWNLOADER (boxes_downloader_get_type ())
#define BOXES_DOWNLOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_DOWNLOADER, BoxesDownloader))
#define BOXES_DOWNLOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_DOWNLOADER, BoxesDownloaderClass))
#define BOXES_IS_DOWNLOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_DOWNLOADER))
#define BOXES_IS_DOWNLOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_DOWNLOADER))
#define BOXES_DOWNLOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_DOWNLOADER, BoxesDownloaderClass))

typedef struct _BoxesDownloader BoxesDownloader;
typedef struct _BoxesDownloaderClass BoxesDownloaderClass;
typedef struct _BoxesDownloaderPrivate BoxesDownloaderPrivate;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#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)))
typedef struct _BoxesDownloaderDownloadData BoxesDownloaderDownloadData;
typedef struct _BoxesDownloaderFetchOsLogoData BoxesDownloaderFetchOsLogoData;
typedef struct _Block51Data Block51Data;
typedef struct _BoxesDownloaderAwaitDownloadData BoxesDownloaderAwaitDownloadData;

struct _BoxesDownloader {
	GObject parent_instance;
	BoxesDownloaderPrivate * priv;
};

struct _BoxesDownloaderClass {
	GObjectClass parent_class;
};

struct _BoxesDownloaderPrivate {
	GHashTable* downloads;
};

struct _BoxesDownloaderDownloadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesDownloader* self;
	GFile* remote_file;
	gchar* cached_path;
	GFile* result;
	GFile* _tmp0_;
	gchar* _tmp1_;
	gchar* uri;
	GHashTable* _tmp2_;
	const gchar* _tmp3_;
	gboolean _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	GFile* _tmp7_;
	GFile* _tmp8_;
	const gchar* _tmp9_;
	GFile* _tmp10_;
	GFile* cached_file;
	GFile* _tmp11_;
	gboolean _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	GHashTable* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	GFile* _tmp19_;
	GFile* _tmp20_;
	GFile* _tmp21_;
	GFile* _tmp22_;
	GError* _error_;
	const gchar* _tmp23_;
	GFile* _tmp24_;
	GError* _tmp25_;
	GError* _tmp26_;
	GError* _tmp27_;
	GHashTable* _tmp28_;
	const gchar* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	GFile* _tmp33_;
	GError * _inner_error_;
};

struct _BoxesDownloaderFetchOsLogoData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	GtkImage* image;
	OsinfoOs* os;
	gint size;
	OsinfoOs* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	OsinfoOs* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	OsinfoOs* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	OsinfoOs* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	GFile* _tmp12_;
	GFile* remote_file;
	GFile* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* cached_path;
	BoxesDownloader* _tmp18_;
	BoxesDownloader* _tmp19_;
	GFile* _tmp20_;
	const gchar* _tmp21_;
	GFile* _tmp22_;
	GFile* _tmp23_;
	GFile* cached_file;
	GFile* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	gint _tmp27_;
	gint _tmp28_;
	GdkPixbuf* _tmp29_;
	GdkPixbuf* _tmp30_;
	GdkPixbuf* pixbuf;
	GtkImage* _tmp31_;
	GdkPixbuf* _tmp32_;
	GError* _error_;
	OsinfoOs* _tmp33_;
	const gchar* _tmp34_;
	const gchar* _tmp35_;
	GError* _tmp36_;
	const gchar* _tmp37_;
	OsinfoOs* _tmp38_;
	OsinfoProductList* _tmp39_;
	OsinfoProductList* derived;
	OsinfoProductList* _tmp40_;
	gint _tmp41_;
	OsinfoProductList* _tmp42_;
	OsinfoEntity* _tmp43_;
	OsinfoOs* _tmp44_;
	OsinfoOs* parent;
	GtkImage* _tmp45_;
	OsinfoOs* _tmp46_;
	gint _tmp47_;
	GError * _inner_error_;
};

struct _Block51Data {
	int _ref_count_;
	BoxesDownloader * self;
	GFile* downloaded_file;
	GError* download_error;
	GSourceFunc callback;
	gpointer callback_target;
	GDestroyNotify callback_target_destroy_notify;
	gchar* uri;
	gpointer _async_data_;
};

struct _BoxesDownloaderAwaitDownloadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesDownloader* self;
	gchar* uri;
	gchar* cached_path;
	GFile* result;
	Block51Data* _data51_;
	const gchar* _tmp0_;
	gulong _tmp1_;
	gulong downloaded_id;
	gulong _tmp2_;
	gulong downloaded_failed_id;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	GError* _tmp5_;
	GFile* cached_file;
	gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gboolean _tmp9_;
	const gchar* _tmp10_;
	GFile* _tmp11_;
	GFile* _tmp12_;
	GFile* _tmp13_;
	GError * _inner_error_;
};


static gpointer boxes_downloader_parent_class = NULL;
static BoxesDownloader* boxes_downloader_downloader;
static BoxesDownloader* boxes_downloader_downloader = NULL;

GType boxes_downloader_get_type (void) G_GNUC_CONST;
#define BOXES_DOWNLOADER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BOXES_TYPE_DOWNLOADER, BoxesDownloaderPrivate))
enum  {
	BOXES_DOWNLOADER_DUMMY_PROPERTY
};
BoxesDownloader* boxes_downloader_get_instance (void);
static BoxesDownloader* boxes_downloader_new (void);
static BoxesDownloader* boxes_downloader_construct (GType object_type);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
static void boxes_downloader_download_data_free (gpointer _data);
void boxes_downloader_download (BoxesDownloader* self, GFile* remote_file, const gchar* cached_path, GAsyncReadyCallback _callback_, gpointer _user_data_);
GFile* boxes_downloader_download_finish (BoxesDownloader* self, GAsyncResult* _res_, GError** error);
static gboolean boxes_downloader_download_co (BoxesDownloaderDownloadData* _data_);
static void boxes_downloader_await_download (BoxesDownloader* self, const gchar* uri, const gchar* cached_path, GAsyncReadyCallback _callback_, gpointer _user_data_);
static GFile* boxes_downloader_await_download_finish (BoxesDownloader* self, GAsyncResult* _res_, GError** error);
static void boxes_downloader_download_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void boxes_downloader_fetch_os_logo_data_free (gpointer _data);
void boxes_downloader_fetch_os_logo (GtkImage* image, OsinfoOs* os, gint size, GAsyncReadyCallback _callback_, gpointer _user_data_);
void boxes_downloader_fetch_os_logo_finish (GAsyncResult* _res_);
static gboolean boxes_downloader_fetch_os_logo_co (BoxesDownloaderFetchOsLogoData* _data_);
static void boxes_downloader_fetch_os_logo_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void boxes_downloader_await_download_data_free (gpointer _data);
static gboolean boxes_downloader_await_download_co (BoxesDownloaderAwaitDownloadData* _data_);
static Block51Data* block51_data_ref (Block51Data* _data51_);
static void block51_data_unref (void * _userdata_);
static gboolean _boxes_downloader_await_download_co_gsource_func (gpointer self);
static void __lambda120_ (Block51Data* _data51_, BoxesDownloader* downloader, const gchar* downloaded_uri, GFile* file);
static void ___lambda120__boxes_downloader_downloaded (BoxesDownloader* _sender, const gchar* uri, GFile* cached_file, gpointer self);
static void __lambda121_ (Block51Data* _data51_, BoxesDownloader* downloader, const gchar* downloaded_uri, GFile* file, GError* _error_);
static void ___lambda121__boxes_downloader_download_failed (BoxesDownloader* _sender, const gchar* uri, GFile* cached_file, GError* _error_, gpointer self);
static void boxes_downloader_await_download_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void g_cclosure_user_marshal_VOID__STRING_OBJECT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__STRING_OBJECT_POINTER (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void boxes_downloader_finalize (GObject* obj);


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


BoxesDownloader* boxes_downloader_get_instance (void) {
	BoxesDownloader* result = NULL;
	BoxesDownloader* _tmp0_;
	BoxesDownloader* _tmp2_;
	BoxesDownloader* _tmp3_;
	_tmp0_ = boxes_downloader_downloader;
	if (_tmp0_ == NULL) {
		BoxesDownloader* _tmp1_;
		_tmp1_ = boxes_downloader_new ();
		_g_object_unref0 (boxes_downloader_downloader);
		boxes_downloader_downloader = _tmp1_;
	}
	_tmp2_ = boxes_downloader_downloader;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


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


static BoxesDownloader* boxes_downloader_construct (GType object_type) {
	BoxesDownloader * self = NULL;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	self = (BoxesDownloader*) g_object_new (object_type, NULL);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->downloads);
	self->priv->downloads = _tmp2_;
	return self;
}


static BoxesDownloader* boxes_downloader_new (void) {
	return boxes_downloader_construct (BOXES_TYPE_DOWNLOADER);
}


static void boxes_downloader_download_data_free (gpointer _data) {
	BoxesDownloaderDownloadData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->remote_file);
	_g_free0 (_data_->cached_path);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesDownloaderDownloadData, _data_);
}


void boxes_downloader_download (BoxesDownloader* self, GFile* remote_file, const gchar* cached_path, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesDownloaderDownloadData* _data_;
	BoxesDownloader* _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	_data_ = g_slice_new0 (BoxesDownloaderDownloadData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, boxes_downloader_download);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_downloader_download_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = remote_file;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data_->remote_file = _tmp2_;
	_tmp3_ = cached_path;
	_tmp4_ = g_strdup (_tmp3_);
	_data_->cached_path = _tmp4_;
	boxes_downloader_download_co (_data_);
}


GFile* boxes_downloader_download_finish (BoxesDownloader* self, GAsyncResult* _res_, GError** error) {
	GFile* result;
	BoxesDownloaderDownloadData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void boxes_downloader_download_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesDownloaderDownloadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_downloader_download_co (_data_);
}


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


static gboolean boxes_downloader_download_co (BoxesDownloaderDownloadData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->remote_file;
	_data_->_tmp1_ = NULL;
	_data_->_tmp1_ = g_file_get_uri (_data_->_tmp0_);
	_data_->uri = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->self->priv->downloads;
	_data_->_tmp3_ = _data_->uri;
	_data_->_tmp4_ = FALSE;
	_data_->_tmp4_ = g_hash_table_contains (_data_->_tmp2_, _data_->_tmp3_);
	if (_data_->_tmp4_) {
		_data_->_tmp5_ = _data_->uri;
		_data_->_tmp6_ = _data_->cached_path;
		_data_->_state_ = 1;
		boxes_downloader_await_download (_data_->self, _data_->_tmp5_, _data_->_tmp6_, boxes_downloader_download_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp7_ = NULL;
		_data_->_tmp7_ = boxes_downloader_await_download_finish (_data_->self, _data_->_res_, &_data_->_inner_error_);
		_data_->_tmp8_ = _data_->_tmp7_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_free0 (_data_->uri);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->result = _data_->_tmp8_;
		_g_free0 (_data_->uri);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp9_ = _data_->cached_path;
	_data_->_tmp10_ = NULL;
	_data_->_tmp10_ = g_file_new_for_path (_data_->_tmp9_);
	_data_->cached_file = _data_->_tmp10_;
	_data_->_tmp11_ = _data_->cached_file;
	_data_->_tmp12_ = FALSE;
	_data_->_tmp12_ = g_file_query_exists (_data_->_tmp11_, NULL);
	if (_data_->_tmp12_) {
		_data_->_tmp13_ = _data_->uri;
		_data_->_tmp14_ = _data_->cached_path;
		g_debug ("downloader.vala:31: '%s' already available locally at '%s'. Not downlo" \
"ading.", _data_->_tmp13_, _data_->_tmp14_);
		_data_->result = _data_->cached_file;
		_g_free0 (_data_->uri);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp15_ = _data_->uri;
	g_debug ("downloader.vala:35: Downloading '%s'...", _data_->_tmp15_);
	_data_->_tmp16_ = _data_->self->priv->downloads;
	_data_->_tmp17_ = _data_->uri;
	_data_->_tmp18_ = g_strdup (_data_->_tmp17_);
	_data_->_tmp19_ = _data_->cached_file;
	_data_->_tmp20_ = _g_object_ref0 (_data_->_tmp19_);
	g_hash_table_insert (_data_->_tmp16_, _data_->_tmp18_, _data_->_tmp20_);
	{
		_data_->_tmp21_ = _data_->remote_file;
		_data_->_tmp22_ = _data_->cached_file;
		_data_->_state_ = 2;
		g_file_copy_async (_data_->_tmp21_, _data_->_tmp22_, G_FILE_COPY_NONE, G_PRIORITY_DEFAULT, NULL, NULL, NULL, boxes_downloader_download_ready, _data_);
		return FALSE;
		_state_2:
		g_file_copy_finish (_data_->_tmp21_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			goto __catch84_g_error;
		}
	}
	goto __finally84;
	__catch84_g_error:
	{
		_data_->_error_ = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp23_ = _data_->uri;
		_data_->_tmp24_ = _data_->cached_file;
		_data_->_tmp25_ = _data_->_error_;
		g_signal_emit_by_name (_data_->self, "download-failed", _data_->_tmp23_, _data_->_tmp24_, _data_->_tmp25_);
		_data_->_tmp26_ = _data_->_error_;
		_data_->_tmp27_ = _g_error_copy0 (_data_->_tmp26_);
		_data_->_inner_error_ = _data_->_tmp27_;
		_g_error_free0 (_data_->_error_);
		goto __finally84;
	}
	__finally84:
	{
		_data_->_tmp28_ = _data_->self->priv->downloads;
		_data_->_tmp29_ = _data_->uri;
		g_hash_table_remove (_data_->_tmp28_, _data_->_tmp29_);
	}
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_object_unref0 (_data_->cached_file);
		_g_free0 (_data_->uri);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp30_ = _data_->uri;
	_data_->_tmp31_ = _data_->cached_path;
	g_debug ("downloader.vala:48: Downloaded '%s' and its now locally available at '" \
"%s'.", _data_->_tmp30_, _data_->_tmp31_);
	_data_->_tmp32_ = _data_->uri;
	_data_->_tmp33_ = _data_->cached_file;
	g_signal_emit_by_name (_data_->self, "downloaded", _data_->_tmp32_, _data_->_tmp33_);
	_data_->result = _data_->cached_file;
	_g_free0 (_data_->uri);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->cached_file);
	_g_free0 (_data_->uri);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_downloader_fetch_os_logo_data_free (gpointer _data) {
	BoxesDownloaderFetchOsLogoData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->image);
	_g_object_unref0 (_data_->os);
	g_slice_free (BoxesDownloaderFetchOsLogoData, _data_);
}


void boxes_downloader_fetch_os_logo (GtkImage* image, OsinfoOs* os, gint size, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesDownloaderFetchOsLogoData* _data_;
	GtkImage* _tmp0_;
	GtkImage* _tmp1_;
	OsinfoOs* _tmp2_;
	OsinfoOs* _tmp3_;
	gint _tmp4_;
	_data_ = g_slice_new0 (BoxesDownloaderFetchOsLogoData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, boxes_downloader_fetch_os_logo);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_downloader_fetch_os_logo_data_free);
	_tmp0_ = image;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data_->image = _tmp1_;
	_tmp2_ = os;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_data_->os = _tmp3_;
	_tmp4_ = size;
	_data_->size = _tmp4_;
	boxes_downloader_fetch_os_logo_co (_data_);
}


void boxes_downloader_fetch_os_logo_finish (GAsyncResult* _res_) {
	BoxesDownloaderFetchOsLogoData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void boxes_downloader_fetch_os_logo_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesDownloaderFetchOsLogoData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_downloader_fetch_os_logo_co (_data_);
}


static gboolean boxes_downloader_fetch_os_logo_co (BoxesDownloaderFetchOsLogoData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->os;
	_data_->_tmp1_ = osinfo_product_get_logo ((OsinfoProduct*) _data_->_tmp0_);
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_ != NULL) {
		_data_->_tmp3_ = _data_->os;
		_data_->_tmp4_ = osinfo_product_get_name ((OsinfoProduct*) _data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = _data_->os;
		_data_->_tmp7_ = osinfo_product_get_logo ((OsinfoProduct*) _data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		g_debug ("downloader.vala:56: %s has logo '%s'.", _data_->_tmp5_, _data_->_tmp8_);
		_data_->_tmp9_ = _data_->os;
		_data_->_tmp10_ = osinfo_product_get_logo ((OsinfoProduct*) _data_->_tmp9_);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = NULL;
		_data_->_tmp12_ = g_file_new_for_uri (_data_->_tmp11_);
		_data_->remote_file = _data_->_tmp12_;
		_data_->_tmp13_ = _data_->remote_file;
		_data_->_tmp14_ = NULL;
		_data_->_tmp14_ = g_file_get_basename (_data_->_tmp13_);
		_data_->_tmp15_ = _data_->_tmp14_;
		_data_->_tmp16_ = NULL;
		_data_->_tmp16_ = boxes_get_logo_cache (_data_->_tmp15_);
		_data_->_tmp17_ = _data_->_tmp16_;
		_g_free0 (_data_->_tmp15_);
		_data_->cached_path = _data_->_tmp17_;
		{
			_data_->_tmp18_ = NULL;
			_data_->_tmp18_ = boxes_downloader_get_instance ();
			_data_->_tmp19_ = _data_->_tmp18_;
			_data_->_tmp20_ = _data_->remote_file;
			_data_->_tmp21_ = _data_->cached_path;
			_data_->_state_ = 1;
			boxes_downloader_download (_data_->_tmp19_, _data_->_tmp20_, _data_->_tmp21_, boxes_downloader_fetch_os_logo_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp22_ = NULL;
			_data_->_tmp22_ = boxes_downloader_download_finish (_data_->_tmp19_, _data_->_res_, &_data_->_inner_error_);
			_data_->_tmp23_ = _data_->_tmp22_;
			_g_object_unref0 (_data_->_tmp19_);
			_data_->cached_file = _data_->_tmp23_;
			if (_data_->_inner_error_ != NULL) {
				goto __catch85_g_error;
			}
			_data_->_tmp24_ = _data_->cached_file;
			_data_->_tmp25_ = NULL;
			_data_->_tmp25_ = g_file_get_path (_data_->_tmp24_);
			_data_->_tmp26_ = _data_->_tmp25_;
			_data_->_tmp27_ = _data_->size;
			_data_->_tmp28_ = _data_->size;
			_data_->_tmp29_ = gdk_pixbuf_new_from_file_at_size (_data_->_tmp26_, _data_->_tmp27_, _data_->_tmp28_, &_data_->_inner_error_);
			_data_->_tmp30_ = _data_->_tmp29_;
			_g_free0 (_data_->_tmp26_);
			_data_->pixbuf = _data_->_tmp30_;
			if (_data_->_inner_error_ != NULL) {
				_g_object_unref0 (_data_->cached_file);
				goto __catch85_g_error;
			}
			_data_->_tmp31_ = _data_->image;
			_data_->_tmp32_ = _data_->pixbuf;
			gtk_image_set_from_pixbuf (_data_->_tmp31_, _data_->_tmp32_);
			_g_object_unref0 (_data_->pixbuf);
			_g_object_unref0 (_data_->cached_file);
		}
		goto __finally85;
		__catch85_g_error:
		{
			_data_->_error_ = _data_->_inner_error_;
			_data_->_inner_error_ = NULL;
			_data_->_tmp33_ = _data_->os;
			_data_->_tmp34_ = osinfo_product_get_logo ((OsinfoProduct*) _data_->_tmp33_);
			_data_->_tmp35_ = _data_->_tmp34_;
			_data_->_tmp36_ = _data_->_error_;
			_data_->_tmp37_ = _data_->_tmp36_->message;
			g_warning ("downloader.vala:65: Error loading logo file '%s': %s", _data_->_tmp35_, _data_->_tmp37_);
			_g_error_free0 (_data_->_error_);
		}
		__finally85:
		if (_data_->_inner_error_ != NULL) {
			_g_free0 (_data_->cached_path);
			_g_object_unref0 (_data_->remote_file);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
		_g_free0 (_data_->cached_path);
		_g_object_unref0 (_data_->remote_file);
	} else {
		_data_->_tmp38_ = _data_->os;
		_data_->_tmp39_ = NULL;
		_data_->_tmp39_ = osinfo_product_get_related ((OsinfoProduct*) _data_->_tmp38_, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
		_data_->derived = _data_->_tmp39_;
		_data_->_tmp40_ = _data_->derived;
		_data_->_tmp41_ = 0;
		_data_->_tmp41_ = osinfo_list_get_length ((OsinfoList*) _data_->_tmp40_);
		if (_data_->_tmp41_ > 0) {
			_data_->_tmp42_ = _data_->derived;
			_data_->_tmp43_ = NULL;
			_data_->_tmp43_ = osinfo_list_get_nth ((OsinfoList*) _data_->_tmp42_, 0);
			_data_->_tmp44_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp43_, osinfo_os_get_type ()) ? ((OsinfoOs*) _data_->_tmp43_) : NULL);
			_data_->parent = _data_->_tmp44_;
			_data_->_tmp45_ = _data_->image;
			_data_->_tmp46_ = _data_->parent;
			_data_->_tmp47_ = _data_->size;
			_data_->_state_ = 2;
			boxes_downloader_fetch_os_logo (_data_->_tmp45_, _data_->_tmp46_, _data_->_tmp47_, boxes_downloader_fetch_os_logo_ready, _data_);
			return FALSE;
			_state_2:
			boxes_downloader_fetch_os_logo_finish (_data_->_res_);
			_g_object_unref0 (_data_->parent);
		}
		_g_object_unref0 (_data_->derived);
	}
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_downloader_await_download_data_free (gpointer _data) {
	BoxesDownloaderAwaitDownloadData* _data_;
	_data_ = _data;
	_g_free0 (_data_->cached_path);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesDownloaderAwaitDownloadData, _data_);
}


static void boxes_downloader_await_download (BoxesDownloader* self, const gchar* uri, const gchar* cached_path, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesDownloaderAwaitDownloadData* _data_;
	BoxesDownloader* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	_data_ = g_slice_new0 (BoxesDownloaderAwaitDownloadData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, boxes_downloader_await_download);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_downloader_await_download_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = uri;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->uri = _tmp2_;
	_tmp3_ = cached_path;
	_tmp4_ = g_strdup (_tmp3_);
	_data_->cached_path = _tmp4_;
	boxes_downloader_await_download_co (_data_);
}


static GFile* boxes_downloader_await_download_finish (BoxesDownloader* self, GAsyncResult* _res_, GError** error) {
	GFile* result;
	BoxesDownloaderAwaitDownloadData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static Block51Data* block51_data_ref (Block51Data* _data51_) {
	g_atomic_int_inc (&_data51_->_ref_count_);
	return _data51_;
}


static void block51_data_unref (void * _userdata_) {
	Block51Data* _data51_;
	_data51_ = (Block51Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data51_->_ref_count_)) {
		BoxesDownloader * self;
		self = _data51_->self;
		(_data51_->callback_target_destroy_notify == NULL) ? NULL : (_data51_->callback_target_destroy_notify (_data51_->callback_target), NULL);
		_data51_->callback = NULL;
		_data51_->callback_target = NULL;
		_data51_->callback_target_destroy_notify = NULL;
		_g_error_free0 (_data51_->download_error);
		_g_object_unref0 (_data51_->downloaded_file);
		_g_free0 (_data51_->uri);
		_g_object_unref0 (self);
		g_slice_free (Block51Data, _data51_);
	}
}


static gboolean _boxes_downloader_await_download_co_gsource_func (gpointer self) {
	gboolean result;
	result = boxes_downloader_await_download_co (self);
	return result;
}


static void __lambda120_ (Block51Data* _data51_, BoxesDownloader* downloader, const gchar* downloaded_uri, GFile* file) {
	BoxesDownloader * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp3_;
	self = _data51_->self;
	g_return_if_fail (downloader != NULL);
	g_return_if_fail (downloaded_uri != NULL);
	g_return_if_fail (file != NULL);
	_tmp0_ = downloaded_uri;
	_tmp1_ = _data51_->uri;
	if (g_strcmp0 (_tmp0_, _tmp1_) != 0) {
		return;
	}
	_tmp2_ = file;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 (_data51_->downloaded_file);
	_data51_->downloaded_file = _tmp3_;
	_data51_->callback (_data51_->callback_target);
}


static void ___lambda120__boxes_downloader_downloaded (BoxesDownloader* _sender, const gchar* uri, GFile* cached_file, gpointer self) {
	__lambda120_ (self, _sender, uri, cached_file);
}


static void __lambda121_ (Block51Data* _data51_, BoxesDownloader* downloader, const gchar* downloaded_uri, GFile* file, GError* _error_) {
	BoxesDownloader * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GError* _tmp2_;
	GError* _tmp3_;
	self = _data51_->self;
	g_return_if_fail (downloader != NULL);
	g_return_if_fail (downloaded_uri != NULL);
	g_return_if_fail (file != NULL);
	_tmp0_ = downloaded_uri;
	_tmp1_ = _data51_->uri;
	if (g_strcmp0 (_tmp0_, _tmp1_) != 0) {
		return;
	}
	_tmp2_ = _error_;
	_tmp3_ = _g_error_copy0 (_tmp2_);
	_g_error_free0 (_data51_->download_error);
	_data51_->download_error = _tmp3_;
	_data51_->callback (_data51_->callback_target);
}


static void ___lambda121__boxes_downloader_download_failed (BoxesDownloader* _sender, const gchar* uri, GFile* cached_file, GError* _error_, gpointer self) {
	__lambda121_ (self, _sender, uri, cached_file, _error_);
}


static void boxes_downloader_await_download_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesDownloaderAwaitDownloadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_downloader_await_download_co (_data_);
}


static gboolean boxes_downloader_await_download_co (BoxesDownloaderAwaitDownloadData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data51_ = g_slice_new0 (Block51Data);
	_data_->_data51_->_ref_count_ = 1;
	_data_->_data51_->self = g_object_ref (_data_->self);
	_data_->_tmp0_ = _data_->uri;
	_data_->_data51_->uri = _data_->_tmp0_;
	_data_->_data51_->_async_data_ = _data_;
	_data_->_data51_->downloaded_file = NULL;
	_data_->_data51_->download_error = NULL;
	_data_->_data51_->callback = _boxes_downloader_await_download_co_gsource_func;
	_data_->_data51_->callback_target = _data_;
	_data_->_data51_->callback_target_destroy_notify = NULL;
	_data_->_tmp1_ = 0UL;
	_data_->_tmp1_ = g_signal_connect_data (_data_->self, "downloaded", (GCallback) ___lambda120__boxes_downloader_downloaded, block51_data_ref (_data_->_data51_), (GClosureNotify) block51_data_unref, 0);
	_data_->downloaded_id = _data_->_tmp1_;
	_data_->_tmp2_ = 0UL;
	_data_->_tmp2_ = g_signal_connect_data (_data_->self, "download-failed", (GCallback) ___lambda121__boxes_downloader_download_failed, block51_data_ref (_data_->_data51_), (GClosureNotify) block51_data_unref, 0);
	_data_->downloaded_failed_id = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->_data51_->uri;
	g_debug ("downloader.vala:98: '%s' already being downloaded. Waiting for downloa" \
"d to complete..", _data_->_tmp3_);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	_data_->_tmp4_ = _data_->_data51_->uri;
	g_debug ("downloader.vala:100: Finished waiting for '%s' to download.", _data_->_tmp4_);
	g_signal_handler_disconnect ((GObject*) _data_->self, _data_->downloaded_id);
	g_signal_handler_disconnect ((GObject*) _data_->self, _data_->downloaded_failed_id);
	if (_data_->_data51_->download_error != NULL) {
		_data_->_tmp5_ = _g_error_copy0 (_data_->_data51_->download_error);
		_data_->_inner_error_ = _data_->_tmp5_;
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		block51_data_unref (_data_->_data51_);
		_data_->_data51_ = NULL;
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = NULL;
	_data_->_tmp6_ = g_file_get_path (_data_->_data51_->downloaded_file);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = _data_->cached_path;
	_data_->_tmp9_ = g_strcmp0 (_data_->_tmp7_, _data_->_tmp8_) != 0;
	_g_free0 (_data_->_tmp7_);
	if (_data_->_tmp9_) {
		_data_->_tmp10_ = _data_->cached_path;
		_data_->_tmp11_ = NULL;
		_data_->_tmp11_ = g_file_new_for_path (_data_->_tmp10_);
		_g_object_unref0 (_data_->cached_file);
		_data_->cached_file = _data_->_tmp11_;
		_data_->_tmp12_ = _data_->cached_file;
		_data_->_state_ = 2;
		g_file_copy_async (_data_->_data51_->downloaded_file, _data_->_tmp12_, G_FILE_COPY_OVERWRITE, G_PRIORITY_DEFAULT, NULL, NULL, NULL, boxes_downloader_await_download_ready, _data_);
		return FALSE;
		_state_2:
		g_file_copy_finish (_data_->_data51_->downloaded_file, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->cached_file);
			block51_data_unref (_data_->_data51_);
			_data_->_data51_ = NULL;
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	} else {
		_data_->_tmp13_ = _g_object_ref0 (_data_->_data51_->downloaded_file);
		_g_object_unref0 (_data_->cached_file);
		_data_->cached_file = _data_->_tmp13_;
	}
	_data_->result = _data_->cached_file;
	block51_data_unref (_data_->_data51_);
	_data_->_data51_ = NULL;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->cached_file);
	block51_data_unref (_data_->_data51_);
	_data_->_data51_ = NULL;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void g_cclosure_user_marshal_VOID__STRING_OBJECT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__STRING_OBJECT) (gpointer data1, const char* arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__STRING_OBJECT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__STRING_OBJECT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_string (param_values + 1), g_value_get_object (param_values + 2), data2);
}


static void g_cclosure_user_marshal_VOID__STRING_OBJECT_POINTER (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__STRING_OBJECT_POINTER) (gpointer data1, const char* arg_1, gpointer arg_2, gpointer arg_3, gpointer data2);
	register GMarshalFunc_VOID__STRING_OBJECT_POINTER callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__STRING_OBJECT_POINTER) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_string (param_values + 1), g_value_get_object (param_values + 2), g_value_get_pointer (param_values + 3), data2);
}


static void boxes_downloader_class_init (BoxesDownloaderClass * klass) {
	boxes_downloader_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (BoxesDownloaderPrivate));
	G_OBJECT_CLASS (klass)->finalize = boxes_downloader_finalize;
	g_signal_new ("downloaded", BOXES_TYPE_DOWNLOADER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_OBJECT, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_FILE);
	g_signal_new ("download_failed", BOXES_TYPE_DOWNLOADER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_OBJECT_POINTER, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_FILE, G_TYPE_POINTER);
}


static void boxes_downloader_instance_init (BoxesDownloader * self) {
	self->priv = BOXES_DOWNLOADER_GET_PRIVATE (self);
}


static void boxes_downloader_finalize (GObject* obj) {
	BoxesDownloader * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BOXES_TYPE_DOWNLOADER, BoxesDownloader);
	_g_hash_table_unref0 (self->priv->downloads);
	G_OBJECT_CLASS (boxes_downloader_parent_class)->finalize (obj);
}


GType boxes_downloader_get_type (void) {
	static volatile gsize boxes_downloader_type_id__volatile = 0;
	if (g_once_init_enter (&boxes_downloader_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BoxesDownloaderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_downloader_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesDownloader), 0, (GInstanceInitFunc) boxes_downloader_instance_init, NULL };
		GType boxes_downloader_type_id;
		boxes_downloader_type_id = g_type_register_static (G_TYPE_OBJECT, "BoxesDownloader", &g_define_type_info, 0);
		g_once_init_leave (&boxes_downloader_type_id__volatile, boxes_downloader_type_id);
	}
	return boxes_downloader_type_id__volatile;
}



