/* AvatarDialog.c generated by valac 0.56.19, the Vala compiler
 * generated from AvatarDialog.vala, do not modify */

/*
* Copyright (c) 2014-2019 elementary, Inc. (https://elementary.io)
*
* 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include "useraccounts.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.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  {
	SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_0_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_PIXBUF_PATH_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_NUM_PROPERTIES
};
static GParamSpec* switchboard_plug_user_accounts_dialogs_avatar_dialog_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
enum  {
	SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_REQUEST_AVATAR_CHANGE_SIGNAL,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_NUM_SIGNALS
};
static guint switchboard_plug_user_accounts_dialogs_avatar_dialog_signals[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_NUM_SIGNALS] = {0};

struct _SwitchboardPlugUserAccountsDialogsAvatarDialogPrivate {
	gchar* _pixbuf_path;
	SwitchboardPlugUserAccountsWidgetsCropView* cropview;
};

static gint SwitchboardPlugUserAccountsDialogsAvatarDialog_private_offset;
static gpointer switchboard_plug_user_accounts_dialogs_avatar_dialog_parent_class = NULL;

static void switchboard_plug_user_accounts_dialogs_avatar_dialog_on_response (SwitchboardPlugUserAccountsDialogsAvatarDialog* self,
                                                                       GtkDialog* source,
                                                                       gint response_id);
static GObject * switchboard_plug_user_accounts_dialogs_avatar_dialog_constructor (GType type,
                                                                            guint n_construct_properties,
                                                                            GObjectConstructParam * construct_properties);
static void _switchboard_plug_user_accounts_dialogs_avatar_dialog_on_response_gtk_dialog_response (GtkDialog* _sender,
                                                                                            gint response_id,
                                                                                            gpointer self);
static void switchboard_plug_user_accounts_dialogs_avatar_dialog_finalize (GObject * obj);
static GType switchboard_plug_user_accounts_dialogs_avatar_dialog_get_type_once (void);
static void _vala_switchboard_plug_user_accounts_dialogs_avatar_dialog_get_property (GObject * object,
                                                                              guint property_id,
                                                                              GValue * value,
                                                                              GParamSpec * pspec);
static void _vala_switchboard_plug_user_accounts_dialogs_avatar_dialog_set_property (GObject * object,
                                                                              guint property_id,
                                                                              const GValue * value,
                                                                              GParamSpec * pspec);

static inline gpointer
switchboard_plug_user_accounts_dialogs_avatar_dialog_get_instance_private (SwitchboardPlugUserAccountsDialogsAvatarDialog* self)
{
	return G_STRUCT_MEMBER_P (self, SwitchboardPlugUserAccountsDialogsAvatarDialog_private_offset);
}

SwitchboardPlugUserAccountsDialogsAvatarDialog*
switchboard_plug_user_accounts_dialogs_avatar_dialog_construct (GType object_type,
                                                                const gchar* pixbuf_path)
{
	SwitchboardPlugUserAccountsDialogsAvatarDialog * self = NULL;
	GThemedIcon* _tmp0_;
	GThemedIcon* _tmp1_;
	g_return_val_if_fail (pixbuf_path != NULL, NULL);
	_tmp0_ = (GThemedIcon*) g_themed_icon_new ("image-crop");
	_tmp1_ = _tmp0_;
	self = (SwitchboardPlugUserAccountsDialogsAvatarDialog*) g_object_new (object_type, "image-icon", _tmp1_, "primary-text", _ ("Crop & Position"), "secondary-text", _ ("Choose the part of the image to use as an avatar."), "pixbuf-path", pixbuf_path, "buttons", GTK_BUTTONS_CANCEL, NULL);
	_g_object_unref0 (_tmp1_);
	return self;
}

SwitchboardPlugUserAccountsDialogsAvatarDialog*
switchboard_plug_user_accounts_dialogs_avatar_dialog_new (const gchar* pixbuf_path)
{
	return switchboard_plug_user_accounts_dialogs_avatar_dialog_construct (SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_TYPE_AVATAR_DIALOG, pixbuf_path);
}

static void
switchboard_plug_user_accounts_dialogs_avatar_dialog_on_response (SwitchboardPlugUserAccountsDialogsAvatarDialog* self,
                                                                  GtkDialog* source,
                                                                  gint response_id)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	if (response_id == ((gint) GTK_RESPONSE_OK)) {
		GdkPixbuf* pixbuf = NULL;
		SwitchboardPlugUserAccountsWidgetsCropView* _tmp0_;
		GdkPixbuf* _tmp1_;
		GdkPixbuf* _tmp2_;
		_tmp0_ = self->priv->cropview;
		_tmp1_ = switchboard_plug_user_accounts_widgets_crop_view_get_selection (_tmp0_);
		pixbuf = _tmp1_;
		_tmp2_ = pixbuf;
		if (gdk_pixbuf_get_width (_tmp2_) > 200) {
			GdkPixbuf* _tmp3_;
			GdkPixbuf* _tmp4_;
			GdkPixbuf* _tmp5_;
			_tmp3_ = pixbuf;
			_tmp4_ = gdk_pixbuf_scale_simple (_tmp3_, 200, 200, GDK_INTERP_BILINEAR);
			_tmp5_ = _tmp4_;
			g_signal_emit (self, switchboard_plug_user_accounts_dialogs_avatar_dialog_signals[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_REQUEST_AVATAR_CHANGE_SIGNAL], 0, _tmp5_);
			_g_object_unref0 (_tmp5_);
		} else {
			GdkPixbuf* _tmp6_;
			_tmp6_ = pixbuf;
			g_signal_emit (self, switchboard_plug_user_accounts_dialogs_avatar_dialog_signals[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_REQUEST_AVATAR_CHANGE_SIGNAL], 0, _tmp6_);
		}
		_g_object_unref0 (pixbuf);
	}
	gtk_window_destroy ((GtkWindow*) self);
}

const gchar*
switchboard_plug_user_accounts_dialogs_avatar_dialog_get_pixbuf_path (SwitchboardPlugUserAccountsDialogsAvatarDialog* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_pixbuf_path;
	result = _tmp0_;
	return result;
}

static void
switchboard_plug_user_accounts_dialogs_avatar_dialog_set_pixbuf_path (SwitchboardPlugUserAccountsDialogsAvatarDialog* self,
                                                                      const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = switchboard_plug_user_accounts_dialogs_avatar_dialog_get_pixbuf_path (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_pixbuf_path);
		self->priv->_pixbuf_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, switchboard_plug_user_accounts_dialogs_avatar_dialog_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_PIXBUF_PATH_PROPERTY]);
	}
}

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

static void
_switchboard_plug_user_accounts_dialogs_avatar_dialog_on_response_gtk_dialog_response (GtkDialog* _sender,
                                                                                       gint response_id,
                                                                                       gpointer self)
{
	switchboard_plug_user_accounts_dialogs_avatar_dialog_on_response ((SwitchboardPlugUserAccountsDialogsAvatarDialog*) self, _sender, response_id);
}

static GObject *
switchboard_plug_user_accounts_dialogs_avatar_dialog_constructor (GType type,
                                                                  guint n_construct_properties,
                                                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SwitchboardPlugUserAccountsDialogsAvatarDialog * self;
	GtkWidget* button_change = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (switchboard_plug_user_accounts_dialogs_avatar_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_TYPE_AVATAR_DIALOG, SwitchboardPlugUserAccountsDialogsAvatarDialog);
	_tmp0_ = granite_dialog_add_button ((GraniteDialog*) self, _ ("Change Avatar"), (gint) GTK_RESPONSE_OK);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	button_change = _tmp1_;
	_tmp2_ = button_change;
	gtk_widget_add_css_class (_tmp2_, GRANITE_STYLE_CLASS_SUGGESTED_ACTION);
	g_signal_connect_object ((GtkDialog*) self, "response", (GCallback) _switchboard_plug_user_accounts_dialogs_avatar_dialog_on_response_gtk_dialog_response, self, 0);
	{
		GdkPixbuf* _tmp3_ = NULL;
		const gchar* _tmp4_;
		GdkPixbuf* _tmp5_;
		GdkPixbuf* pixbuf = NULL;
		GdkPixbuf* _tmp6_;
		GdkPixbuf* _tmp7_;
		SwitchboardPlugUserAccountsWidgetsCropView* _tmp8_;
		SwitchboardPlugUserAccountsWidgetsCropView* _tmp9_;
		SwitchboardPlugUserAccountsWidgetsCropView* _tmp10_;
		GtkBox* _tmp11_;
		GtkBox* _tmp12_;
		SwitchboardPlugUserAccountsWidgetsCropView* _tmp13_;
		_tmp4_ = self->priv->_pixbuf_path;
		_tmp5_ = gdk_pixbuf_new_from_file (_tmp4_, &_inner_error0_);
		_tmp3_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp6_ = gdk_pixbuf_apply_embedded_orientation (_tmp3_);
		pixbuf = _tmp6_;
		_tmp7_ = pixbuf;
		_tmp8_ = switchboard_plug_user_accounts_widgets_crop_view_new (_tmp7_, 400);
		g_object_ref_sink (_tmp8_);
		_g_object_unref0 (self->priv->cropview);
		self->priv->cropview = _tmp8_;
		_tmp9_ = self->priv->cropview;
		gtk_widget_add_css_class ((GtkWidget*) _tmp9_, GRANITE_STYLE_CLASS_CARD);
		_tmp10_ = self->priv->cropview;
		gtk_widget_add_css_class ((GtkWidget*) _tmp10_, GRANITE_STYLE_CLASS_CHECKERBOARD);
		_tmp11_ = granite_message_dialog_get_custom_bin ((GraniteMessageDialog*) self);
		_tmp12_ = _tmp11_;
		_tmp13_ = self->priv->cropview;
		gtk_box_append (_tmp12_, (GtkWidget*) _tmp13_);
		_g_object_unref0 (pixbuf);
		_g_object_unref0 (_tmp3_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp14_;
		const gchar* _tmp15_;
		GtkWidget* _tmp16_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp14_ = e;
		_tmp15_ = _tmp14_->message;
		g_critical ("AvatarDialog.vala:52: %s", _tmp15_);
		_tmp16_ = button_change;
		gtk_widget_set_sensitive (_tmp16_, FALSE);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (button_change);
		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_);
	}
	_g_object_unref0 (button_change);
	return obj;
}

static void
switchboard_plug_user_accounts_dialogs_avatar_dialog_class_init (SwitchboardPlugUserAccountsDialogsAvatarDialogClass * klass,
                                                                 gpointer klass_data)
{
	switchboard_plug_user_accounts_dialogs_avatar_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SwitchboardPlugUserAccountsDialogsAvatarDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_switchboard_plug_user_accounts_dialogs_avatar_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_switchboard_plug_user_accounts_dialogs_avatar_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = switchboard_plug_user_accounts_dialogs_avatar_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = switchboard_plug_user_accounts_dialogs_avatar_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_PIXBUF_PATH_PROPERTY, switchboard_plug_user_accounts_dialogs_avatar_dialog_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_PIXBUF_PATH_PROPERTY] = g_param_spec_string ("pixbuf-path", "pixbuf-path", "pixbuf-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	switchboard_plug_user_accounts_dialogs_avatar_dialog_signals[SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_REQUEST_AVATAR_CHANGE_SIGNAL] = g_signal_new ("request-avatar-change", SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_TYPE_AVATAR_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, gdk_pixbuf_get_type ());
}

static void
switchboard_plug_user_accounts_dialogs_avatar_dialog_instance_init (SwitchboardPlugUserAccountsDialogsAvatarDialog * self,
                                                                    gpointer klass)
{
	self->priv = switchboard_plug_user_accounts_dialogs_avatar_dialog_get_instance_private (self);
}

static void
switchboard_plug_user_accounts_dialogs_avatar_dialog_finalize (GObject * obj)
{
	SwitchboardPlugUserAccountsDialogsAvatarDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_TYPE_AVATAR_DIALOG, SwitchboardPlugUserAccountsDialogsAvatarDialog);
	_g_free0 (self->priv->_pixbuf_path);
	_g_object_unref0 (self->priv->cropview);
	G_OBJECT_CLASS (switchboard_plug_user_accounts_dialogs_avatar_dialog_parent_class)->finalize (obj);
}

static GType
switchboard_plug_user_accounts_dialogs_avatar_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SwitchboardPlugUserAccountsDialogsAvatarDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) switchboard_plug_user_accounts_dialogs_avatar_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwitchboardPlugUserAccountsDialogsAvatarDialog), 0, (GInstanceInitFunc) switchboard_plug_user_accounts_dialogs_avatar_dialog_instance_init, NULL };
	GType switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id;
	switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id = g_type_register_static (GRANITE_TYPE_MESSAGE_DIALOG, "SwitchboardPlugUserAccountsDialogsAvatarDialog", &g_define_type_info, 0);
	SwitchboardPlugUserAccountsDialogsAvatarDialog_private_offset = g_type_add_instance_private (switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id, sizeof (SwitchboardPlugUserAccountsDialogsAvatarDialogPrivate));
	return switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id;
}

GType
switchboard_plug_user_accounts_dialogs_avatar_dialog_get_type (void)
{
	static volatile gsize switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id__once = 0;
	if (g_once_init_enter (&switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id__once)) {
		GType switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id;
		switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id = switchboard_plug_user_accounts_dialogs_avatar_dialog_get_type_once ();
		g_once_init_leave (&switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id__once, switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id);
	}
	return switchboard_plug_user_accounts_dialogs_avatar_dialog_type_id__once;
}

static void
_vala_switchboard_plug_user_accounts_dialogs_avatar_dialog_get_property (GObject * object,
                                                                         guint property_id,
                                                                         GValue * value,
                                                                         GParamSpec * pspec)
{
	SwitchboardPlugUserAccountsDialogsAvatarDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_TYPE_AVATAR_DIALOG, SwitchboardPlugUserAccountsDialogsAvatarDialog);
	switch (property_id) {
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_PIXBUF_PATH_PROPERTY:
		g_value_set_string (value, switchboard_plug_user_accounts_dialogs_avatar_dialog_get_pixbuf_path (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_switchboard_plug_user_accounts_dialogs_avatar_dialog_set_property (GObject * object,
                                                                         guint property_id,
                                                                         const GValue * value,
                                                                         GParamSpec * pspec)
{
	SwitchboardPlugUserAccountsDialogsAvatarDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_TYPE_AVATAR_DIALOG, SwitchboardPlugUserAccountsDialogsAvatarDialog);
	switch (property_id) {
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_DIALOGS_AVATAR_DIALOG_PIXBUF_PATH_PROPERTY:
		switchboard_plug_user_accounts_dialogs_avatar_dialog_set_pixbuf_path (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

