/* tools-remove-dialog.c generated by valac 0.56.19, the Vala compiler
 * generated from tools-remove-dialog.vala, do not modify */

#include "protonplus_core.h"
#include <glib-object.h>
#include <glib.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gtk/gtk.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

enum  {
	PROTON_PLUS_WIDGETS_TOOLS_REMOVE_DIALOG_0_PROPERTY,
	PROTON_PLUS_WIDGETS_TOOLS_REMOVE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* proton_plus_widgets_tools_remove_dialog_properties[PROTON_PLUS_WIDGETS_TOOLS_REMOVE_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ProtonPlusWidgetsToolsRemoveDialogPrivate {
	ProtonPlusServicesInstallJob* job;
};

static gint ProtonPlusWidgetsToolsRemoveDialog_private_offset;
static gpointer proton_plus_widgets_tools_remove_dialog_parent_class = NULL;

static void proton_plus_widgets_tools_remove_dialog_response_changed (ProtonPlusWidgetsToolsRemoveDialog* self,
                                                               const gchar* response);
static void _proton_plus_widgets_tools_remove_dialog_response_changed_adw_alert_dialog_response (AdwAlertDialog* _sender,
                                                                                          const gchar* response,
                                                                                          gpointer self);
static void __lambda43_ (ProtonPlusWidgetsToolsRemoveDialog* self,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda43__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void proton_plus_widgets_tools_remove_dialog_finalize (GObject * obj);
static GType proton_plus_widgets_tools_remove_dialog_get_type_once (void);

static inline gpointer
proton_plus_widgets_tools_remove_dialog_get_instance_private (ProtonPlusWidgetsToolsRemoveDialog* self)
{
	return G_STRUCT_MEMBER_P (self, ProtonPlusWidgetsToolsRemoveDialog_private_offset);
}

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

static void
_proton_plus_widgets_tools_remove_dialog_response_changed_adw_alert_dialog_response (AdwAlertDialog* _sender,
                                                                                     const gchar* response,
                                                                                     gpointer self)
{
	proton_plus_widgets_tools_remove_dialog_response_changed ((ProtonPlusWidgetsToolsRemoveDialog*) self, response);
}

ProtonPlusWidgetsToolsRemoveDialog*
proton_plus_widgets_tools_remove_dialog_construct (GType object_type,
                                                   ProtonPlusServicesInstallJob* job)
{
	ProtonPlusWidgetsToolsRemoveDialog * self = NULL;
	ProtonPlusServicesInstallJob* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* body = NULL;
	gchar* _tmp6_;
	ProtonPlusModelsTool* _tmp7_;
	ProtonPlusModelsTool* _tmp8_;
	ProtonPlusModelsGroup* _tmp9_;
	ProtonPlusModelsGroup* _tmp10_;
	ProtonPlusModelsLauncher* _tmp11_;
	ProtonPlusModelsLauncher* _tmp12_;
	const gchar* _tmp27_;
	g_return_val_if_fail (job != NULL, NULL);
	self = (ProtonPlusWidgetsToolsRemoveDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (job);
	_g_object_unref0 (self->priv->job);
	self->priv->job = _tmp0_;
	_tmp1_ = proton_plus_services_install_job_get_title (job);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf (_ ("Delete %s?"), _tmp3_);
	_tmp5_ = _tmp4_;
	adw_alert_dialog_set_heading ((AdwAlertDialog*) self, _tmp5_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_tmp6_ = g_strdup (_ ("It will be permanently deleted."));
	body = _tmp6_;
	_tmp7_ = proton_plus_services_install_job_get_tool (job);
	_tmp8_ = _tmp7_;
	_tmp9_ = proton_plus_models_tool_get_group (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = proton_plus_models_group_get_launcher (_tmp10_);
	_tmp12_ = _tmp11_;
	if (PROTON_PLUS_MODELS_LAUNCHERS_IS_STEAM (_tmp12_)) {
		ProtonPlusModelsLaunchersSteam* steam_launcher = NULL;
		ProtonPlusModelsTool* _tmp13_;
		ProtonPlusModelsTool* _tmp14_;
		ProtonPlusModelsGroup* _tmp15_;
		ProtonPlusModelsGroup* _tmp16_;
		ProtonPlusModelsLauncher* _tmp17_;
		ProtonPlusModelsLauncher* _tmp18_;
		ProtonPlusModelsLaunchersSteam* _tmp19_;
		gchar* tool_name = NULL;
		gchar* _tmp20_;
		gint usage_count = 0;
		ProtonPlusModelsLaunchersSteam* _tmp21_;
		const gchar* _tmp22_;
		_tmp13_ = proton_plus_services_install_job_get_tool (job);
		_tmp14_ = _tmp13_;
		_tmp15_ = proton_plus_models_tool_get_group (_tmp14_);
		_tmp16_ = _tmp15_;
		_tmp17_ = proton_plus_models_group_get_launcher (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp18_, PROTON_PLUS_MODELS_LAUNCHERS_TYPE_STEAM, ProtonPlusModelsLaunchersSteam));
		steam_launcher = _tmp19_;
		_tmp20_ = proton_plus_services_install_job_get_usage_identifier (job);
		tool_name = _tmp20_;
		_tmp21_ = steam_launcher;
		_tmp22_ = tool_name;
		usage_count = proton_plus_models_launcher_get_compatibility_tool_usage_count ((ProtonPlusModelsLauncher*) _tmp21_, _tmp22_);
		if (usage_count > 0) {
			gchar* usage_text = NULL;
			gchar* _tmp23_;
			const gchar* _tmp24_;
			const gchar* _tmp25_;
			gchar* _tmp26_;
			_tmp23_ = g_strdup_printf (ngettext ("Used by %i game.", "Used by %i games.", (gulong) usage_count), usage_count);
			usage_text = _tmp23_;
			_tmp24_ = usage_text;
			_tmp25_ = body;
			_tmp26_ = g_strdup_printf ("%s\n\n%s", _tmp24_, _tmp25_);
			_g_free0 (body);
			body = _tmp26_;
			_g_free0 (usage_text);
		}
		_g_free0 (tool_name);
		_g_object_unref0 (steam_launcher);
	}
	_tmp27_ = body;
	adw_alert_dialog_set_body ((AdwAlertDialog*) self, _tmp27_);
	adw_alert_dialog_add_response ((AdwAlertDialog*) self, "cancel", _ ("Cancel"));
	adw_alert_dialog_add_response ((AdwAlertDialog*) self, "delete", _ ("Delete"));
	adw_alert_dialog_set_response_appearance ((AdwAlertDialog*) self, "cancel", ADW_RESPONSE_DEFAULT);
	adw_alert_dialog_set_response_appearance ((AdwAlertDialog*) self, "delete", ADW_RESPONSE_DESTRUCTIVE);
	adw_alert_dialog_set_default_response ((AdwAlertDialog*) self, "cancel");
	adw_alert_dialog_set_close_response ((AdwAlertDialog*) self, "cancel");
	g_signal_connect_object ((AdwAlertDialog*) self, "response", (GCallback) _proton_plus_widgets_tools_remove_dialog_response_changed_adw_alert_dialog_response, self, 0);
	_g_free0 (body);
	return self;
}

ProtonPlusWidgetsToolsRemoveDialog*
proton_plus_widgets_tools_remove_dialog_new (ProtonPlusServicesInstallJob* job)
{
	return proton_plus_widgets_tools_remove_dialog_construct (PROTON_PLUS_WIDGETS_TOOLS_TYPE_REMOVE_DIALOG, job);
}

static void
__lambda43_ (ProtonPlusWidgetsToolsRemoveDialog* self,
             GObject* obj,
             GAsyncResult* res)
{
	ProtonPlusReturnCode code = 0;
	ProtonPlusServicesInstallJob* _tmp0_;
	g_return_if_fail (res != NULL);
	_tmp0_ = self->priv->job;
	code = proton_plus_services_install_job_remove_finish (_tmp0_, res);
	if (code != PROTON_PLUS_RETURN_CODE_RUNNER_REMOVED) {
		gchar* _tmp1_ = NULL;
		ProtonPlusServicesInstallJob* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		ProtonPlusWidgetsMainErrorDialog* dialog = NULL;
		ProtonPlusServicesInstallJob* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		ProtonPlusWidgetsMainErrorDialog* _tmp13_;
		ProtonPlusWidgetsMainErrorDialog* _tmp14_;
		ProtonPlusWidgetsMainErrorDialog* _tmp15_;
		GApplication* _tmp16_;
		GtkWindow* _tmp17_;
		GtkWindow* _tmp18_;
		_tmp2_ = self->priv->job;
		_tmp3_ = proton_plus_services_install_job_get_error_message (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_strdup (_tmp4_);
		_tmp1_ = _tmp5_;
		if (_tmp1_ == NULL) {
			gchar* _tmp6_;
			_tmp6_ = proton_plus_get_return_code_message (code);
			_g_free0 (_tmp1_);
			_tmp1_ = _tmp6_;
		}
		_tmp7_ = self->priv->job;
		_tmp8_ = proton_plus_services_install_job_get_title (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		_tmp11_ = g_strdup_printf (_ ("Failed to Delete %s"), _tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = proton_plus_widgets_main_error_dialog_new (_tmp12_, _ ("ProtonPlus encountered an issue while trying to remove this compatibil" \
"ity tool from your system."), _tmp1_);
		g_object_ref_sink (_tmp13_);
		_tmp14_ = _tmp13_;
		_g_free0 (_tmp12_);
		_g_free0 (_tmp10_);
		dialog = _tmp14_;
		_tmp15_ = dialog;
		_tmp16_ = g_application_get_default ();
		_tmp17_ = gtk_application_get_active_window (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, gtk_application_get_type (), GtkApplication));
		_tmp18_ = _tmp17_;
		proton_plus_widgets_window_present_dialog_for_controller ((AdwDialog*) _tmp15_, (GtkWidget*) _tmp18_);
		_g_object_unref0 (dialog);
		_g_free0 (_tmp1_);
	}
}

static void
___lambda43__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda43_ ((ProtonPlusWidgetsToolsRemoveDialog*) self, source_object, res);
	g_object_unref (self);
}

static void
proton_plus_widgets_tools_remove_dialog_response_changed (ProtonPlusWidgetsToolsRemoveDialog* self,
                                                          const gchar* response)
{
	ProtonPlusServicesInstallJob* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (response != NULL);
	if (g_strcmp0 (response, "delete") != 0) {
		return;
	}
	_tmp0_ = self->priv->job;
	proton_plus_services_install_job_remove (_tmp0_, TRUE, ___lambda43__gasync_ready_callback, g_object_ref (self));
}

static void
proton_plus_widgets_tools_remove_dialog_class_init (ProtonPlusWidgetsToolsRemoveDialogClass * klass,
                                                    gpointer klass_data)
{
	proton_plus_widgets_tools_remove_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ProtonPlusWidgetsToolsRemoveDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = proton_plus_widgets_tools_remove_dialog_finalize;
}

static void
proton_plus_widgets_tools_remove_dialog_instance_init (ProtonPlusWidgetsToolsRemoveDialog * self,
                                                       gpointer klass)
{
	self->priv = proton_plus_widgets_tools_remove_dialog_get_instance_private (self);
}

static void
proton_plus_widgets_tools_remove_dialog_finalize (GObject * obj)
{
	ProtonPlusWidgetsToolsRemoveDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_WIDGETS_TOOLS_TYPE_REMOVE_DIALOG, ProtonPlusWidgetsToolsRemoveDialog);
	_g_object_unref0 (self->priv->job);
	G_OBJECT_CLASS (proton_plus_widgets_tools_remove_dialog_parent_class)->finalize (obj);
}

static GType
proton_plus_widgets_tools_remove_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusWidgetsToolsRemoveDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_widgets_tools_remove_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusWidgetsToolsRemoveDialog), 0, (GInstanceInitFunc) proton_plus_widgets_tools_remove_dialog_instance_init, NULL };
	GType proton_plus_widgets_tools_remove_dialog_type_id;
	proton_plus_widgets_tools_remove_dialog_type_id = g_type_register_static (adw_alert_dialog_get_type (), "ProtonPlusWidgetsToolsRemoveDialog", &g_define_type_info, 0);
	ProtonPlusWidgetsToolsRemoveDialog_private_offset = g_type_add_instance_private (proton_plus_widgets_tools_remove_dialog_type_id, sizeof (ProtonPlusWidgetsToolsRemoveDialogPrivate));
	return proton_plus_widgets_tools_remove_dialog_type_id;
}

GType
proton_plus_widgets_tools_remove_dialog_get_type (void)
{
	static volatile gsize proton_plus_widgets_tools_remove_dialog_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_widgets_tools_remove_dialog_type_id__once)) {
		GType proton_plus_widgets_tools_remove_dialog_type_id;
		proton_plus_widgets_tools_remove_dialog_type_id = proton_plus_widgets_tools_remove_dialog_get_type_once ();
		g_once_init_leave (&proton_plus_widgets_tools_remove_dialog_type_id__once, proton_plus_widgets_tools_remove_dialog_type_id);
	}
	return proton_plus_widgets_tools_remove_dialog_type_id__once;
}

