/* quit-process-dialog.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from quit-process-dialog.vala, do not modify */

/* quit-process-dialog.vala
 *
 * Copyright (C) 2017 Red Hat, Inc.
 * Copyright (C) 2023 Markus Göllnitz
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Felipe Borges <felipeborges@gnome.org>
 *          Petr Štětka <pstetka@redhat.com>
 *          Markus Göllnitz <camelcasenick@bewares.it>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <signal.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
#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 USAGE_TYPE_QUIT_PROCESS_DIALOG (usage_quit_process_dialog_get_type ())
#define USAGE_QUIT_PROCESS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_QUIT_PROCESS_DIALOG, UsageQuitProcessDialog))
#define USAGE_QUIT_PROCESS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_QUIT_PROCESS_DIALOG, UsageQuitProcessDialogClass))
#define USAGE_IS_QUIT_PROCESS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_QUIT_PROCESS_DIALOG))
#define USAGE_IS_QUIT_PROCESS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_QUIT_PROCESS_DIALOG))
#define USAGE_QUIT_PROCESS_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_QUIT_PROCESS_DIALOG, UsageQuitProcessDialogClass))

typedef struct _UsageQuitProcessDialog UsageQuitProcessDialog;
typedef struct _UsageQuitProcessDialogClass UsageQuitProcessDialogClass;
typedef struct _UsageQuitProcessDialogPrivate UsageQuitProcessDialogPrivate;

#define USAGE_TYPE_APP_ITEM (usage_app_item_get_type ())
#define USAGE_APP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_APP_ITEM, UsageAppItem))
#define USAGE_APP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_APP_ITEM, UsageAppItemClass))
#define USAGE_IS_APP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_APP_ITEM))
#define USAGE_IS_APP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_APP_ITEM))
#define USAGE_APP_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_APP_ITEM, UsageAppItemClass))

typedef struct _UsageAppItem UsageAppItem;
typedef struct _UsageAppItemClass UsageAppItemClass;
enum  {
	USAGE_QUIT_PROCESS_DIALOG_0_PROPERTY,
	USAGE_QUIT_PROCESS_DIALOG_NUM_PROPERTIES
};
static GParamSpec* usage_quit_process_dialog_properties[USAGE_QUIT_PROCESS_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 _UsageQuitProcessDialog {
	AdwAlertDialog parent_instance;
	UsageQuitProcessDialogPrivate * priv;
};

struct _UsageQuitProcessDialogClass {
	AdwAlertDialogClass parent_class;
};

struct _UsageQuitProcessDialogPrivate {
	UsageAppItem* app;
};

static gint UsageQuitProcessDialog_private_offset;
static gpointer usage_quit_process_dialog_parent_class = NULL;

VALA_EXTERN GType usage_quit_process_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageQuitProcessDialog, g_object_unref)
VALA_EXTERN GType usage_app_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageAppItem, g_object_unref)
VALA_EXTERN UsageQuitProcessDialog* usage_quit_process_dialog_new (UsageAppItem* app);
VALA_EXTERN UsageQuitProcessDialog* usage_quit_process_dialog_construct (GType object_type,
                                                             UsageAppItem* app);
VALA_EXTERN const gchar* usage_app_item_get_display_name (UsageAppItem* self);
VALA_EXTERN void usage_quit_process_dialog_responded (UsageQuitProcessDialog* self,
                                          AdwAlertDialog* dialog,
                                          const gchar* response_type);
VALA_EXTERN void usage_app_item_kill (UsageAppItem* self,
                          int* sig);
static void _usage_quit_process_dialog_responded_adw_alert_dialog_response (AdwAlertDialog* _sender,
                                                                     const gchar* response,
                                                                     gpointer self);
static void usage_quit_process_dialog_finalize (GObject * obj);
static GType usage_quit_process_dialog_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
usage_quit_process_dialog_get_instance_private (UsageQuitProcessDialog* self)
{
	return G_STRUCT_MEMBER_P (self, UsageQuitProcessDialog_private_offset);
}

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

UsageQuitProcessDialog*
usage_quit_process_dialog_construct (GType object_type,
                                     UsageAppItem* app)
{
	UsageQuitProcessDialog * self = NULL;
	UsageAppItem* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	g_return_val_if_fail (app != NULL, NULL);
	self = (UsageQuitProcessDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (app);
	_g_object_unref0 (self->priv->app);
	self->priv->app = _tmp0_;
	_tmp1_ = adw_alert_dialog_get_heading ((AdwAlertDialog*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = usage_app_item_get_display_name (app);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strdup_printf (_tmp2_, _tmp4_);
	_tmp6_ = _tmp5_;
	adw_alert_dialog_set_heading ((AdwAlertDialog*) self, _tmp6_);
	_g_free0 (_tmp6_);
	return self;
}

UsageQuitProcessDialog*
usage_quit_process_dialog_new (UsageAppItem* app)
{
	return usage_quit_process_dialog_construct (USAGE_TYPE_QUIT_PROCESS_DIALOG, app);
}

void
usage_quit_process_dialog_responded (UsageQuitProcessDialog* self,
                                     AdwAlertDialog* dialog,
                                     const gchar* response_type)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dialog != NULL);
	g_return_if_fail (response_type != NULL);
	_tmp0_ = response_type;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("quit")))) {
		switch (0) {
			default:
			{
				UsageAppItem* _tmp3_;
				int _tmp4_;
				_tmp3_ = self->priv->app;
				_tmp4_ = SIGTERM;
				usage_app_item_kill (_tmp3_, &_tmp4_);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
	g_signal_emit_by_name ((GtkWidget*) self, "destroy");
}

static void
_usage_quit_process_dialog_responded_adw_alert_dialog_response (AdwAlertDialog* _sender,
                                                                const gchar* response,
                                                                gpointer self)
{
	usage_quit_process_dialog_responded ((UsageQuitProcessDialog*) self, _sender, response);
}

static void
usage_quit_process_dialog_class_init (UsageQuitProcessDialogClass * klass,
                                      gpointer klass_data)
{
	usage_quit_process_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UsageQuitProcessDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = usage_quit_process_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Usage/ui/quit-process-dialog.ui");
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "responded", G_CALLBACK(_usage_quit_process_dialog_responded_adw_alert_dialog_response));
}

static void
usage_quit_process_dialog_instance_init (UsageQuitProcessDialog * self,
                                         gpointer klass)
{
	self->priv = usage_quit_process_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
usage_quit_process_dialog_finalize (GObject * obj)
{
	UsageQuitProcessDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, USAGE_TYPE_QUIT_PROCESS_DIALOG, UsageQuitProcessDialog);
	_g_object_unref0 (self->priv->app);
	G_OBJECT_CLASS (usage_quit_process_dialog_parent_class)->finalize (obj);
}

static GType
usage_quit_process_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UsageQuitProcessDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) usage_quit_process_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UsageQuitProcessDialog), 0, (GInstanceInitFunc) usage_quit_process_dialog_instance_init, NULL };
	GType usage_quit_process_dialog_type_id;
	usage_quit_process_dialog_type_id = g_type_register_static (adw_alert_dialog_get_type (), "UsageQuitProcessDialog", &g_define_type_info, 0);
	UsageQuitProcessDialog_private_offset = g_type_add_instance_private (usage_quit_process_dialog_type_id, sizeof (UsageQuitProcessDialogPrivate));
	return usage_quit_process_dialog_type_id;
}

GType
usage_quit_process_dialog_get_type (void)
{
	static volatile gsize usage_quit_process_dialog_type_id__once = 0;
	if (g_once_init_enter (&usage_quit_process_dialog_type_id__once)) {
		GType usage_quit_process_dialog_type_id;
		usage_quit_process_dialog_type_id = usage_quit_process_dialog_get_type_once ();
		g_once_init_leave (&usage_quit_process_dialog_type_id__once, usage_quit_process_dialog_type_id);
	}
	return usage_quit_process_dialog_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

