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

/*
 * SPDX-License-Identifier: LGPL-3.0-or-later
 * SPDX-FileCopyrightText: 2018 elementary, Inc. (https://elementary.io)
 */

#include "io.elementary.settings.printers.h"
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include "cups/cups.h"
#include <granite-7.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  {
	PRINTERS_REMOVE_DIALOG_0_PROPERTY,
	PRINTERS_REMOVE_DIALOG_PRINTER_PROPERTY,
	PRINTERS_REMOVE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* printers_remove_dialog_properties[PRINTERS_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))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _PrintersRemoveDialogPrivate {
	PrintersPrinter* _printer;
};

static gint PrintersRemoveDialog_private_offset;
static gpointer printers_remove_dialog_parent_class = NULL;

static void printers_remove_dialog_on_response (PrintersRemoveDialog* self,
                                         GtkDialog* source,
                                         gint response_id);
static GObject * printers_remove_dialog_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _printers_remove_dialog_on_response_gtk_dialog_response (GtkDialog* _sender,
                                                              gint response_id,
                                                              gpointer self);
static void printers_remove_dialog_finalize (GObject * obj);
static GType printers_remove_dialog_get_type_once (void);
static void _vala_printers_remove_dialog_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_printers_remove_dialog_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
printers_remove_dialog_get_instance_private (PrintersRemoveDialog* self)
{
	return G_STRUCT_MEMBER_P (self, PrintersRemoveDialog_private_offset);
}

PrintersRemoveDialog*
printers_remove_dialog_construct (GType object_type,
                                  PrintersPrinter* printer)
{
	PrintersRemoveDialog * self = NULL;
	GThemedIcon* _tmp0_;
	GThemedIcon* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	g_return_val_if_fail (printer != NULL, NULL);
	_tmp0_ = (GThemedIcon*) g_themed_icon_new ("dialog-question");
	_tmp1_ = _tmp0_;
	_tmp2_ = printers_printer_get_info (printer);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf (_ ("Are You Sure You Want To Remove '%s'?"), _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = printers_printer_get_info (printer);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup_printf (_ ("By removing '%s' you'll lose all print history and configuration assoc" \
"iated with it."), _tmp7_);
	_tmp9_ = _tmp8_;
	self = (PrintersRemoveDialog*) g_object_new (object_type, "buttons", GTK_BUTTONS_CANCEL, "image-icon", _tmp1_, "modal", TRUE, "printer", printer, "primary-text", _tmp5_, "secondary-text", _tmp9_, NULL);
	_g_free0 (_tmp9_);
	_g_free0 (_tmp5_);
	_g_object_unref0 (_tmp1_);
	return self;
}

PrintersRemoveDialog*
printers_remove_dialog_new (PrintersPrinter* printer)
{
	return printers_remove_dialog_construct (PRINTERS_TYPE_REMOVE_DIALOG, printer);
}

static void
printers_remove_dialog_on_response (PrintersRemoveDialog* self,
                                    GtkDialog* source,
                                    gint response_id)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	if (response_id == 0) {
		{
			CupsPkHelper* _tmp0_;
			PrintersPrinter* _tmp1_;
			cups_dest_t _tmp2_;
			const gchar* _tmp3_;
			gchar* _tmp4_;
			gchar* _tmp5_;
			_tmp0_ = cups_get_pk_helper ();
			_tmp1_ = self->priv->_printer;
			_tmp2_ = _tmp1_->dest;
			_tmp3_ = _tmp2_.name;
			_tmp4_ = cups_pk_helper_printer_delete (_tmp0_, _tmp3_, &_inner_error0_);
			_tmp5_ = _tmp4_;
			_g_free0 (_tmp5_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp6_;
			const gchar* _tmp7_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp6_ = e;
			_tmp7_ = _tmp6_->message;
			g_critical ("RemoveDialog.vala:32: %s", _tmp7_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	gtk_window_destroy ((GtkWindow*) self);
}

PrintersPrinter*
printers_remove_dialog_get_printer (PrintersRemoveDialog* self)
{
	PrintersPrinter* result;
	PrintersPrinter* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_printer;
	result = _tmp0_;
	return result;
}

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

static void
printers_remove_dialog_set_printer (PrintersRemoveDialog* self,
                                    PrintersPrinter* value)
{
	PrintersPrinter* old_value;
	g_return_if_fail (self != NULL);
	old_value = printers_remove_dialog_get_printer (self);
	if (old_value != value) {
		PrintersPrinter* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_printer);
		self->priv->_printer = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, printers_remove_dialog_properties[PRINTERS_REMOVE_DIALOG_PRINTER_PROPERTY]);
	}
}

static void
_printers_remove_dialog_on_response_gtk_dialog_response (GtkDialog* _sender,
                                                         gint response_id,
                                                         gpointer self)
{
	printers_remove_dialog_on_response ((PrintersRemoveDialog*) self, _sender, response_id);
}

static GObject *
printers_remove_dialog_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PrintersRemoveDialog * self;
	GtkWidget* button = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	parent_class = G_OBJECT_CLASS (printers_remove_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PRINTERS_TYPE_REMOVE_DIALOG, PrintersRemoveDialog);
	_tmp0_ = granite_dialog_add_button ((GraniteDialog*) self, _ ("Remove"), 0);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	button = _tmp1_;
	_tmp2_ = button;
	gtk_widget_add_css_class (_tmp2_, GRANITE_STYLE_CLASS_DESTRUCTIVE_ACTION);
	g_signal_connect_object ((GtkDialog*) self, "response", (GCallback) _printers_remove_dialog_on_response_gtk_dialog_response, self, 0);
	_g_object_unref0 (button);
	return obj;
}

static void
printers_remove_dialog_class_init (PrintersRemoveDialogClass * klass,
                                   gpointer klass_data)
{
	printers_remove_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PrintersRemoveDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_printers_remove_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_printers_remove_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = printers_remove_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = printers_remove_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PRINTERS_REMOVE_DIALOG_PRINTER_PROPERTY, printers_remove_dialog_properties[PRINTERS_REMOVE_DIALOG_PRINTER_PROPERTY] = g_param_spec_object ("printer", "printer", "printer", PRINTERS_TYPE_PRINTER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
printers_remove_dialog_instance_init (PrintersRemoveDialog * self,
                                      gpointer klass)
{
	self->priv = printers_remove_dialog_get_instance_private (self);
}

static void
printers_remove_dialog_finalize (GObject * obj)
{
	PrintersRemoveDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PRINTERS_TYPE_REMOVE_DIALOG, PrintersRemoveDialog);
	_g_object_unref0 (self->priv->_printer);
	G_OBJECT_CLASS (printers_remove_dialog_parent_class)->finalize (obj);
}

static GType
printers_remove_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PrintersRemoveDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) printers_remove_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PrintersRemoveDialog), 0, (GInstanceInitFunc) printers_remove_dialog_instance_init, NULL };
	GType printers_remove_dialog_type_id;
	printers_remove_dialog_type_id = g_type_register_static (GRANITE_TYPE_MESSAGE_DIALOG, "PrintersRemoveDialog", &g_define_type_info, 0);
	PrintersRemoveDialog_private_offset = g_type_add_instance_private (printers_remove_dialog_type_id, sizeof (PrintersRemoveDialogPrivate));
	return printers_remove_dialog_type_id;
}

GType
printers_remove_dialog_get_type (void)
{
	static volatile gsize printers_remove_dialog_type_id__once = 0;
	if (g_once_init_enter (&printers_remove_dialog_type_id__once)) {
		GType printers_remove_dialog_type_id;
		printers_remove_dialog_type_id = printers_remove_dialog_get_type_once ();
		g_once_init_leave (&printers_remove_dialog_type_id__once, printers_remove_dialog_type_id);
	}
	return printers_remove_dialog_type_id__once;
}

static void
_vala_printers_remove_dialog_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	PrintersRemoveDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PRINTERS_TYPE_REMOVE_DIALOG, PrintersRemoveDialog);
	switch (property_id) {
		case PRINTERS_REMOVE_DIALOG_PRINTER_PROPERTY:
		g_value_set_object (value, printers_remove_dialog_get_printer (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_printers_remove_dialog_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	PrintersRemoveDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PRINTERS_TYPE_REMOVE_DIALOG, PrintersRemoveDialog);
	switch (property_id) {
		case PRINTERS_REMOVE_DIALOG_PRINTER_PROPERTY:
		printers_remove_dialog_set_printer (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

