/* os-downloader.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from os-downloader.vala, do not modify */

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

#include <handy.h>
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <osinfo/osinfo.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define BOXES_TYPE_OS_DOWNLOADER (boxes_os_downloader_get_type ())
#define BOXES_OS_DOWNLOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_OS_DOWNLOADER, BoxesOsDownloader))
#define BOXES_OS_DOWNLOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_OS_DOWNLOADER, BoxesOsDownloaderClass))
#define BOXES_IS_OS_DOWNLOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_OS_DOWNLOADER))
#define BOXES_IS_OS_DOWNLOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_OS_DOWNLOADER))
#define BOXES_OS_DOWNLOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_OS_DOWNLOADER, BoxesOsDownloaderClass))

typedef struct _BoxesOsDownloader BoxesOsDownloader;
typedef struct _BoxesOsDownloaderClass BoxesOsDownloaderClass;
typedef struct _BoxesOsDownloaderPrivate BoxesOsDownloaderPrivate;

#define BOXES_TYPE_OS_DATABASE (boxes_os_database_get_type ())
#define BOXES_OS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_OS_DATABASE, BoxesOSDatabase))
#define BOXES_OS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_OS_DATABASE, BoxesOSDatabaseClass))
#define BOXES_IS_OS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_OS_DATABASE))
#define BOXES_IS_OS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_OS_DATABASE))
#define BOXES_OS_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_OS_DATABASE, BoxesOSDatabaseClass))

typedef struct _BoxesOSDatabase BoxesOSDatabase;
typedef struct _BoxesOSDatabaseClass BoxesOSDatabaseClass;
enum  {
	BOXES_OS_DOWNLOADER_0_PROPERTY,
	BOXES_OS_DOWNLOADER_NUM_PROPERTIES
};
static GParamSpec* boxes_os_downloader_properties[BOXES_OS_DOWNLOADER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define BOXES_TYPE_APP_WINDOW (boxes_app_window_get_type ())
#define BOXES_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_APP_WINDOW, BoxesAppWindow))
#define BOXES_APP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_APP_WINDOW, BoxesAppWindowClass))
#define BOXES_IS_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_APP_WINDOW))
#define BOXES_IS_APP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_APP_WINDOW))
#define BOXES_APP_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_APP_WINDOW, BoxesAppWindowClass))

typedef struct _BoxesAppWindow BoxesAppWindow;
typedef struct _BoxesAppWindowClass BoxesAppWindowClass;

#define BOXES_TYPE_ASSISTANT_MEDIA_ENTRY (boxes_assistant_media_entry_get_type ())
#define BOXES_ASSISTANT_MEDIA_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_ASSISTANT_MEDIA_ENTRY, BoxesAssistantMediaEntry))
#define BOXES_ASSISTANT_MEDIA_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_ASSISTANT_MEDIA_ENTRY, BoxesAssistantMediaEntryClass))
#define BOXES_IS_ASSISTANT_MEDIA_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_ASSISTANT_MEDIA_ENTRY))
#define BOXES_IS_ASSISTANT_MEDIA_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_ASSISTANT_MEDIA_ENTRY))
#define BOXES_ASSISTANT_MEDIA_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_ASSISTANT_MEDIA_ENTRY, BoxesAssistantMediaEntryClass))

typedef struct _BoxesAssistantMediaEntry BoxesAssistantMediaEntry;
typedef struct _BoxesAssistantMediaEntryClass BoxesAssistantMediaEntryClass;

#define BOXES_TYPE_ASSISTANT_DOWNLOADABLE_ENTRY (boxes_assistant_downloadable_entry_get_type ())
#define BOXES_ASSISTANT_DOWNLOADABLE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_ASSISTANT_DOWNLOADABLE_ENTRY, BoxesAssistantDownloadableEntry))
#define BOXES_ASSISTANT_DOWNLOADABLE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_ASSISTANT_DOWNLOADABLE_ENTRY, BoxesAssistantDownloadableEntryClass))
#define BOXES_IS_ASSISTANT_DOWNLOADABLE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_ASSISTANT_DOWNLOADABLE_ENTRY))
#define BOXES_IS_ASSISTANT_DOWNLOADABLE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_ASSISTANT_DOWNLOADABLE_ENTRY))
#define BOXES_ASSISTANT_DOWNLOADABLE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_ASSISTANT_DOWNLOADABLE_ENTRY, BoxesAssistantDownloadableEntryClass))

typedef struct _BoxesAssistantDownloadableEntry BoxesAssistantDownloadableEntry;
typedef struct _BoxesAssistantDownloadableEntryClass BoxesAssistantDownloadableEntryClass;

#define BOXES_TYPE_MEDIA_MANAGER (boxes_media_manager_get_type ())
#define BOXES_MEDIA_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_MEDIA_MANAGER, BoxesMediaManager))
#define BOXES_MEDIA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_MEDIA_MANAGER, BoxesMediaManagerClass))
#define BOXES_IS_MEDIA_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_MEDIA_MANAGER))
#define BOXES_IS_MEDIA_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_MEDIA_MANAGER))
#define BOXES_MEDIA_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_MEDIA_MANAGER, BoxesMediaManagerClass))

typedef struct _BoxesMediaManager BoxesMediaManager;
typedef struct _BoxesMediaManagerClass BoxesMediaManagerClass;

#define BOXES_TYPE_OS_DATABASE_ERROR (boxes_os_database_error_get_type ())
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _BoxesOsDownloaderPopulateData BoxesOsDownloaderPopulateData;
typedef struct _BoxesAssistantMediaEntryPrivate BoxesAssistantMediaEntryPrivate;

#define BOXES_TYPE_INSTALLER_MEDIA (boxes_installer_media_get_type ())
#define BOXES_INSTALLER_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMedia))
#define BOXES_INSTALLER_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMediaClass))
#define BOXES_IS_INSTALLER_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_INSTALLER_MEDIA))
#define BOXES_IS_INSTALLER_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_INSTALLER_MEDIA))
#define BOXES_INSTALLER_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMediaClass))

typedef struct _BoxesInstallerMedia BoxesInstallerMedia;
typedef struct _BoxesInstallerMediaClass BoxesInstallerMediaClass;
typedef struct _BoxesAssistantDownloadableEntryPrivate BoxesAssistantDownloadableEntryPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))

#define BOXES_TYPE_RHEL_DOWNLOAD_DIALOG (boxes_rhel_download_dialog_get_type ())
#define BOXES_RHEL_DOWNLOAD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_RHEL_DOWNLOAD_DIALOG, BoxesRHELDownloadDialog))
#define BOXES_RHEL_DOWNLOAD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_RHEL_DOWNLOAD_DIALOG, BoxesRHELDownloadDialogClass))
#define BOXES_IS_RHEL_DOWNLOAD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_RHEL_DOWNLOAD_DIALOG))
#define BOXES_IS_RHEL_DOWNLOAD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_RHEL_DOWNLOAD_DIALOG))
#define BOXES_RHEL_DOWNLOAD_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_RHEL_DOWNLOAD_DIALOG, BoxesRHELDownloadDialogClass))

typedef struct _BoxesRHELDownloadDialog BoxesRHELDownloadDialog;
typedef struct _BoxesRHELDownloadDialogClass BoxesRHELDownloadDialogClass;

#define BOXES_TYPE_DOWNLOADS_HUB (boxes_downloads_hub_get_type ())
#define BOXES_DOWNLOADS_HUB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_DOWNLOADS_HUB, BoxesDownloadsHub))
#define BOXES_DOWNLOADS_HUB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_DOWNLOADS_HUB, BoxesDownloadsHubClass))
#define BOXES_IS_DOWNLOADS_HUB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_DOWNLOADS_HUB))
#define BOXES_IS_DOWNLOADS_HUB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_DOWNLOADS_HUB))
#define BOXES_DOWNLOADS_HUB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_DOWNLOADS_HUB, BoxesDownloadsHubClass))

typedef struct _BoxesDownloadsHub BoxesDownloadsHub;
typedef struct _BoxesDownloadsHubClass BoxesDownloadsHubClass;
typedef struct _BoxesOsDownloaderOnOsEntryActivatedData BoxesOsDownloaderOnOsEntryActivatedData;

struct _BoxesOsDownloader {
	HdyPreferencesWindow parent_instance;
	BoxesOsDownloaderPrivate * priv;
};

struct _BoxesOsDownloaderClass {
	HdyPreferencesWindowClass parent_class;
};

struct _BoxesOsDownloaderPrivate {
	BoxesOSDatabase* os_db;
	HdyPreferencesGroup* recommended_downloads;
	HdyPreferencesGroup* all_downloads;
};

typedef enum  {
	BOXES_OS_DATABASE_ERROR_NON_BOOTABLE,
	BOXES_OS_DATABASE_ERROR_DB_LOADING_FAILED,
	BOXES_OS_DATABASE_ERROR_UNKNOWN_OS_ID,
	BOXES_OS_DATABASE_ERROR_UNKNOWN_MEDIA_ID
} BoxesOSDatabaseError;
#define BOXES_OS_DATABASE_ERROR boxes_os_database_error_quark ()

struct _BoxesOsDownloaderPopulateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	BoxesOsDownloader* self;
	GList* _tmp0_;
	GList* media_collection;
	GList* media_it;
	OsinfoMedia* _tmp1_;
	OsinfoMedia* media;
	OsinfoMedia* _tmp2_;
	HdyPreferencesGroup* _tmp3_;
	OsinfoMedia* _tmp4_;
	BoxesAssistantDownloadableEntry* _tmp5_;
	BoxesAssistantDownloadableEntry* _tmp6_;
	BoxesMediaManager* manager;
	BoxesMediaManager* _tmp7_;
	GList* os_list;
	BoxesMediaManager* _tmp8_;
	BoxesOSDatabase* _tmp9_;
	BoxesOSDatabase* _tmp10_;
	GList* _tmp11_;
	GList* _tmp12_;
	GList* _vala1_media_collection;
	GList* _vala1_media_it;
	OsinfoMedia* _tmp13_;
	OsinfoMedia* _vala1_media;
	OsinfoMedia* _tmp14_;
	HdyPreferencesGroup* _tmp15_;
	OsinfoMedia* _tmp16_;
	BoxesAssistantDownloadableEntry* _tmp17_;
	BoxesAssistantDownloadableEntry* _tmp18_;
	GError* _error_;
	GError* _tmp19_;
	const gchar* _tmp20_;
	GError* _inner_error0_;
};

struct _BoxesAssistantMediaEntry {
	HdyActionRow parent_instance;
	BoxesAssistantMediaEntryPrivate * priv;
	BoxesInstallerMedia* media;
	GtkImage* media_image;
};

struct _BoxesAssistantMediaEntryClass {
	HdyActionRowClass parent_class;
};

struct _BoxesAssistantDownloadableEntry {
	BoxesAssistantMediaEntry parent_instance;
	BoxesAssistantDownloadableEntryPrivate * priv;
	OsinfoOs* os;
	gchar* url;
};

struct _BoxesAssistantDownloadableEntryClass {
	BoxesAssistantMediaEntryClass parent_class;
};

struct _BoxesOsDownloaderOnOsEntryActivatedData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	BoxesOsDownloader* self;
	HdyActionRow* row;
	BoxesAssistantDownloadableEntry* entry;
	BoxesAssistantDownloadableEntry* _tmp0_;
	BoxesAssistantDownloadableEntry* _tmp1_;
	OsinfoOs* _tmp2_;
	BoxesAssistantDownloadableEntry* _tmp3_;
	OsinfoOs* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gboolean _tmp8_;
	BoxesAssistantDownloadableEntry* _tmp9_;
	BoxesRHELDownloadDialog* _tmp10_;
	BoxesRHELDownloadDialog* _tmp11_;
	BoxesDownloadsHub* _tmp12_;
	BoxesDownloadsHub* _tmp13_;
	BoxesAssistantDownloadableEntry* _tmp14_;
};

static gint BoxesOsDownloader_private_offset;
static gpointer boxes_os_downloader_parent_class = NULL;

VALA_EXTERN GType boxes_os_downloader_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesOsDownloader, g_object_unref)
VALA_EXTERN GType boxes_os_database_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesOSDatabase, g_object_unref)
VALA_EXTERN BoxesOSDatabase* boxes_os_database_new (void);
VALA_EXTERN BoxesOSDatabase* boxes_os_database_construct (GType object_type);
VALA_EXTERN GType boxes_app_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesAppWindow, g_object_unref)
VALA_EXTERN BoxesOsDownloader* boxes_os_downloader_new (BoxesAppWindow* window);
VALA_EXTERN BoxesOsDownloader* boxes_os_downloader_construct (GType object_type,
                                                  BoxesAppWindow* window);
static void boxes_os_downloader_populate (BoxesOsDownloader* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
static void boxes_os_downloader_populate_finish (BoxesOsDownloader* self,
                                          GAsyncResult* _res_);
VALA_EXTERN GType boxes_assistant_media_entry_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesAssistantMediaEntry, g_object_unref)
VALA_EXTERN GType boxes_assistant_downloadable_entry_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesAssistantDownloadableEntry, g_object_unref)
static BoxesAssistantDownloadableEntry* boxes_os_downloader_create_entry_from_media (BoxesOsDownloader* self,
                                                                              OsinfoMedia* media);
VALA_EXTERN BoxesAssistantDownloadableEntry* boxes_assistant_downloadable_entry_new_from_osinfo (OsinfoMedia* media);
VALA_EXTERN BoxesAssistantDownloadableEntry* boxes_assistant_downloadable_entry_construct_from_osinfo (GType object_type,
                                                                                           OsinfoMedia* media);
static void boxes_os_downloader_on_os_entry_activated (BoxesOsDownloader* self,
                                                HdyActionRow* row,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static void boxes_os_downloader_on_os_entry_activated_finish (BoxesOsDownloader* self,
                                                       GAsyncResult* _res_);
static void _boxes_os_downloader_on_os_entry_activated_hdy_action_row_activated (HdyActionRow* _sender,
                                                                          gpointer self);
static void boxes_os_downloader_populate_data_free (gpointer _data);
static gboolean boxes_os_downloader_populate_co (BoxesOsDownloaderPopulateData* _data_);
VALA_EXTERN void boxes_fetch_recommended_downloads_from_net (GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN GList* boxes_fetch_recommended_downloads_from_net_finish (GAsyncResult* _res_);
static void boxes_os_downloader_populate_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
VALA_EXTERN GType boxes_media_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesMediaManager, g_object_unref)
VALA_EXTERN BoxesMediaManager* boxes_media_manager_get_default (void);
VALA_EXTERN BoxesOSDatabase* boxes_media_manager_get_os_db (BoxesMediaManager* self);
VALA_EXTERN void boxes_os_database_list_downloadable_oses (BoxesOSDatabase* self,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
VALA_EXTERN GQuark boxes_os_database_error_quark (void);
VALA_EXTERN GType boxes_os_database_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GList* boxes_os_database_list_downloadable_oses_finish (BoxesOSDatabase* self,
                                                        GAsyncResult* _res_,
                                                        GError** error);
static void boxes_os_downloader_on_os_entry_activated_data_free (gpointer _data);
static gboolean boxes_os_downloader_on_os_entry_activated_co (BoxesOsDownloaderOnOsEntryActivatedData* _data_);
VALA_EXTERN GType boxes_installer_media_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesInstallerMedia, g_object_unref)
VALA_EXTERN BoxesRHELDownloadDialog* boxes_rhel_download_dialog_new (BoxesAssistantDownloadableEntry* entry);
VALA_EXTERN BoxesRHELDownloadDialog* boxes_rhel_download_dialog_construct (GType object_type,
                                                               BoxesAssistantDownloadableEntry* entry);
VALA_EXTERN GType boxes_rhel_download_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesRHELDownloadDialog, g_object_unref)
VALA_EXTERN GType boxes_downloads_hub_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesDownloadsHub, g_object_unref)
VALA_EXTERN BoxesDownloadsHub* boxes_downloads_hub_get_default (void);
VALA_EXTERN void boxes_downloads_hub_add_item (BoxesDownloadsHub* self,
                                   BoxesAssistantDownloadableEntry* entry);
static GObject * boxes_os_downloader_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
VALA_EXTERN void boxes_os_database_load (BoxesOSDatabase* self,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_);
VALA_EXTERN void boxes_os_database_load_finish (BoxesOSDatabase* self,
                                    GAsyncResult* _res_);
static void boxes_os_downloader_finalize (GObject * obj);
static GType boxes_os_downloader_get_type_once (void);

static inline gpointer
boxes_os_downloader_get_instance_private (BoxesOsDownloader* self)
{
	return G_STRUCT_MEMBER_P (self, BoxesOsDownloader_private_offset);
}

BoxesOsDownloader*
boxes_os_downloader_construct (GType object_type,
                               BoxesAppWindow* window)
{
	BoxesOsDownloader * self = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	self = (BoxesOsDownloader*) g_object_new (object_type, NULL);
	gtk_window_set_transient_for ((GtkWindow*) self, (GtkWindow*) window);
	boxes_os_downloader_populate (self, NULL, NULL);
	return self;
}

BoxesOsDownloader*
boxes_os_downloader_new (BoxesAppWindow* window)
{
	return boxes_os_downloader_construct (BOXES_TYPE_OS_DOWNLOADER, window);
}

static void
_boxes_os_downloader_on_os_entry_activated_hdy_action_row_activated (HdyActionRow* _sender,
                                                                     gpointer self)
{
	boxes_os_downloader_on_os_entry_activated ((BoxesOsDownloader*) self, _sender, NULL, NULL);
}

static BoxesAssistantDownloadableEntry*
boxes_os_downloader_create_entry_from_media (BoxesOsDownloader* self,
                                             OsinfoMedia* media)
{
	BoxesAssistantDownloadableEntry* entry = NULL;
	BoxesAssistantDownloadableEntry* _tmp0_;
	BoxesAssistantDownloadableEntry* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (media != NULL, NULL);
	_tmp0_ = boxes_assistant_downloadable_entry_new_from_osinfo (media);
	g_object_ref_sink (_tmp0_);
	entry = _tmp0_;
	g_signal_connect_object ((HdyActionRow*) entry, "activated", (GCallback) _boxes_os_downloader_on_os_entry_activated_hdy_action_row_activated, self, 0);
	result = entry;
	return result;
}

static void
boxes_os_downloader_populate_data_free (gpointer _data)
{
	BoxesOsDownloaderPopulateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesOsDownloaderPopulateData, _data_);
}

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

static void
boxes_os_downloader_populate (BoxesOsDownloader* self,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	BoxesOsDownloaderPopulateData* _data_;
	BoxesOsDownloader* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (BoxesOsDownloaderPopulateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, boxes_os_downloader_populate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	boxes_os_downloader_populate_co (_data_);
}

static void
boxes_os_downloader_populate_finish (BoxesOsDownloader* self,
                                     GAsyncResult* _res_)
{
	BoxesOsDownloaderPopulateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
boxes_os_downloader_populate_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_)
{
	BoxesOsDownloaderPopulateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_os_downloader_populate_co (_data_);
}

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

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static gboolean
boxes_os_downloader_populate_co (BoxesOsDownloaderPopulateData* _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_->_state_ = 1;
	boxes_fetch_recommended_downloads_from_net (boxes_os_downloader_populate_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = boxes_fetch_recommended_downloads_from_net_finish (_data_->_res_);
	{
		_data_->media_collection = _data_->_tmp0_;
		for (_data_->media_it = _data_->media_collection; _data_->media_it != NULL; _data_->media_it = _data_->media_it->next) {
			_data_->_tmp1_ = _g_object_ref0 ((OsinfoMedia*) _data_->media_it->data);
			_data_->media = _data_->_tmp1_;
			{
				_data_->_tmp2_ = _data_->media;
				if (_data_->_tmp2_ != NULL) {
					_data_->_tmp3_ = _data_->self->priv->recommended_downloads;
					_data_->_tmp4_ = _data_->media;
					_data_->_tmp5_ = boxes_os_downloader_create_entry_from_media (_data_->self, _data_->_tmp4_);
					_data_->_tmp6_ = _data_->_tmp5_;
					gtk_container_add ((GtkContainer*) _data_->_tmp3_, (GtkWidget*) _data_->_tmp6_);
					_g_object_unref0 (_data_->_tmp6_);
				}
				_g_object_unref0 (_data_->media);
			}
		}
		(_data_->media_collection == NULL) ? NULL : (_data_->media_collection = (_g_list_free__g_object_unref0_ (_data_->media_collection), NULL));
	}
	{
		_data_->_tmp7_ = boxes_media_manager_get_default ();
		_data_->manager = _data_->_tmp7_;
		_data_->_tmp8_ = _data_->manager;
		_data_->_tmp9_ = boxes_media_manager_get_os_db (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_state_ = 2;
		boxes_os_database_list_downloadable_oses (_data_->_tmp10_, boxes_os_downloader_populate_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp11_ = boxes_os_database_list_downloadable_oses_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
		_data_->os_list = _data_->_tmp11_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->manager);
			goto __catch0_g_error;
		}
		_data_->_tmp12_ = _data_->os_list;
		{
			_data_->_vala1_media_collection = _data_->_tmp12_;
			for (_data_->_vala1_media_it = _data_->_vala1_media_collection; _data_->_vala1_media_it != NULL; _data_->_vala1_media_it = _data_->_vala1_media_it->next) {
				_data_->_tmp13_ = _g_object_ref0 ((OsinfoMedia*) _data_->_vala1_media_it->data);
				_data_->_vala1_media = _data_->_tmp13_;
				{
					_data_->_tmp14_ = _data_->_vala1_media;
					if (_data_->_tmp14_ != NULL) {
						_data_->_tmp15_ = _data_->self->priv->all_downloads;
						_data_->_tmp16_ = _data_->_vala1_media;
						_data_->_tmp17_ = boxes_os_downloader_create_entry_from_media (_data_->self, _data_->_tmp16_);
						_data_->_tmp18_ = _data_->_tmp17_;
						gtk_container_add ((GtkContainer*) _data_->_tmp15_, (GtkWidget*) _data_->_tmp18_);
						_g_object_unref0 (_data_->_tmp18_);
					}
					_g_object_unref0 (_data_->_vala1_media);
				}
			}
		}
		(_data_->os_list == NULL) ? NULL : (_data_->os_list = (_g_list_free__g_object_unref0_ (_data_->os_list), NULL));
		_g_object_unref0 (_data_->manager);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp19_ = _data_->_error_;
		_data_->_tmp20_ = _data_->_tmp19_->message;
		g_warning ("os-downloader.vala:46: Failed to obtain list of downloadable OSes: %s", _data_->_tmp20_);
		_g_error_free0 (_data_->_error_);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
boxes_os_downloader_on_os_entry_activated_data_free (gpointer _data)
{
	BoxesOsDownloaderOnOsEntryActivatedData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->row);
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesOsDownloaderOnOsEntryActivatedData, _data_);
}

static void
boxes_os_downloader_on_os_entry_activated (BoxesOsDownloader* self,
                                           HdyActionRow* row,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	BoxesOsDownloaderOnOsEntryActivatedData* _data_;
	BoxesOsDownloader* _tmp0_;
	HdyActionRow* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_data_ = g_slice_new0 (BoxesOsDownloaderOnOsEntryActivatedData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, boxes_os_downloader_on_os_entry_activated_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (row);
	_g_object_unref0 (_data_->row);
	_data_->row = _tmp1_;
	boxes_os_downloader_on_os_entry_activated_co (_data_);
}

static void
boxes_os_downloader_on_os_entry_activated_finish (BoxesOsDownloader* self,
                                                  GAsyncResult* _res_)
{
	BoxesOsDownloaderOnOsEntryActivatedData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static gboolean
boxes_os_downloader_on_os_entry_activated_co (BoxesOsDownloaderOnOsEntryActivatedData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _g_object_ref0 (BOXES_IS_ASSISTANT_DOWNLOADABLE_ENTRY (_data_->row) ? ((BoxesAssistantDownloadableEntry*) _data_->row) : NULL);
	_data_->entry = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->entry;
	_data_->_tmp2_ = _data_->_tmp1_->os;
	if (_data_->_tmp2_ == NULL) {
		_g_object_unref0 (_data_->entry);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	gtk_widget_hide ((GtkWidget*) _data_->self);
	_data_->_tmp3_ = _data_->entry;
	_data_->_tmp4_ = _data_->_tmp3_->os;
	g_object_get ((OsinfoEntity*) _data_->_tmp4_, "id", &_data_->_tmp5_, NULL);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = g_str_has_prefix (_data_->_tmp7_, "http://redhat.com/rhel/");
	_g_free0 (_data_->_tmp7_);
	if (_data_->_tmp8_) {
		_data_->_tmp9_ = _data_->entry;
		_data_->_tmp10_ = boxes_rhel_download_dialog_new (_data_->_tmp9_);
		g_object_ref_sink (_data_->_tmp10_);
		_data_->_tmp11_ = _data_->_tmp10_;
		gtk_dialog_run ((GtkDialog*) _data_->_tmp11_);
		_g_object_unref0 (_data_->_tmp11_);
	} else {
		_data_->_tmp12_ = boxes_downloads_hub_get_default ();
		_data_->_tmp13_ = _data_->_tmp12_;
		_data_->_tmp14_ = _data_->entry;
		boxes_downloads_hub_add_item (_data_->_tmp13_, _data_->_tmp14_);
		_g_object_unref0 (_data_->_tmp13_);
	}
	gtk_window_close ((GtkWindow*) _data_->self);
	_g_object_unref0 (_data_->entry);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static GObject *
boxes_os_downloader_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	BoxesOsDownloader * self;
	BoxesOSDatabase* _tmp0_;
	parent_class = G_OBJECT_CLASS (boxes_os_downloader_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BOXES_TYPE_OS_DOWNLOADER, BoxesOsDownloader);
	_tmp0_ = self->priv->os_db;
	boxes_os_database_load (_tmp0_, NULL, NULL);
	return obj;
}

static void
boxes_os_downloader_class_init (BoxesOsDownloaderClass * klass,
                                gpointer klass_data)
{
	boxes_os_downloader_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BoxesOsDownloader_private_offset);
	G_OBJECT_CLASS (klass)->constructor = boxes_os_downloader_constructor;
	G_OBJECT_CLASS (klass)->finalize = boxes_os_downloader_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Boxes/ui/assistant/os-downloader.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recommended_downloads", FALSE, BoxesOsDownloader_private_offset + G_STRUCT_OFFSET (BoxesOsDownloaderPrivate, recommended_downloads));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "all_downloads", FALSE, BoxesOsDownloader_private_offset + G_STRUCT_OFFSET (BoxesOsDownloaderPrivate, all_downloads));
}

static void
boxes_os_downloader_instance_init (BoxesOsDownloader * self,
                                   gpointer klass)
{
	BoxesOSDatabase* _tmp0_;
	self->priv = boxes_os_downloader_get_instance_private (self);
	_tmp0_ = boxes_os_database_new ();
	self->priv->os_db = _tmp0_;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
boxes_os_downloader_finalize (GObject * obj)
{
	BoxesOsDownloader * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BOXES_TYPE_OS_DOWNLOADER, BoxesOsDownloader);
	_g_object_unref0 (self->priv->os_db);
	G_OBJECT_CLASS (boxes_os_downloader_parent_class)->finalize (obj);
}

static GType
boxes_os_downloader_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BoxesOsDownloaderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_os_downloader_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesOsDownloader), 0, (GInstanceInitFunc) boxes_os_downloader_instance_init, NULL };
	GType boxes_os_downloader_type_id;
	boxes_os_downloader_type_id = g_type_register_static (hdy_preferences_window_get_type (), "BoxesOsDownloader", &g_define_type_info, 0);
	BoxesOsDownloader_private_offset = g_type_add_instance_private (boxes_os_downloader_type_id, sizeof (BoxesOsDownloaderPrivate));
	return boxes_os_downloader_type_id;
}

GType
boxes_os_downloader_get_type (void)
{
	static volatile gsize boxes_os_downloader_type_id__once = 0;
	if (g_once_init_enter (&boxes_os_downloader_type_id__once)) {
		GType boxes_os_downloader_type_id;
		boxes_os_downloader_type_id = boxes_os_downloader_get_type_once ();
		g_once_init_leave (&boxes_os_downloader_type_id__once, boxes_os_downloader_type_id);
	}
	return boxes_os_downloader_type_id__once;
}

