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

/*
* Copyright 2014-2020 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 <act/act.h>
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <polkit/polkit.h>
#include <glib/gstdio.h>
#include <float.h>
#include <math.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_WIDGETS_AVATAR_POPOVER_0_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_USER_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_UTILS_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_NUM_PROPERTIES
};
static GParamSpec* switchboard_plug_user_accounts_widgets_avatar_popover_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _switchboard_plug_user_accounts_user_utils_unref0(var) ((var == NULL) ? NULL : (var = (switchboard_plug_user_accounts_user_utils_unref (var), NULL)))
typedef struct _Block7Data Block7Data;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _SwitchboardPlugUserAccountsWidgetsAvatarPopoverPrivate {
	ActUser* _user;
	SwitchboardPlugUserAccountsUserUtils* _utils;
};

struct _Block7Data {
	int _ref_count_;
	SwitchboardPlugUserAccountsWidgetsAvatarPopover* self;
	GtkFileChooserNative* file_dialog;
};

static gint SwitchboardPlugUserAccountsWidgetsAvatarPopover_private_offset;
static gpointer switchboard_plug_user_accounts_widgets_avatar_popover_parent_class = NULL;

static void switchboard_plug_user_accounts_widgets_avatar_popover_select_from_file (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static void __lambda8_ (Block7Data* _data7_,
                 gint response);
static void switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self,
                                                                          GdkPixbuf* new_pixbuf);
static void _switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar_switchboard_plug_user_accounts_dialogs_avatar_dialog_request_avatar_change (SwitchboardPlugUserAccountsDialogsAvatarDialog* _sender,
                                                                                                                                                      GdkPixbuf* pixbuf,
                                                                                                                                                      gpointer self);
static void ___lambda8__gtk_native_dialog_response (GtkNativeDialog* _sender,
                                             gint response_id,
                                             gpointer self);
static GObject * switchboard_plug_user_accounts_widgets_avatar_popover_constructor (GType type,
                                                                             guint n_construct_properties,
                                                                             GObjectConstructParam * construct_properties);
static void _switchboard_plug_user_accounts_widgets_avatar_popover___lambda9_ (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self);
static void __switchboard_plug_user_accounts_widgets_avatar_popover___lambda9__gtk_button_clicked (GtkButton* _sender,
                                                                                            gpointer self);
static void _switchboard_plug_user_accounts_widgets_avatar_popover_select_from_file_gtk_button_clicked (GtkButton* _sender,
                                                                                                 gpointer self);
static void switchboard_plug_user_accounts_widgets_avatar_popover_finalize (GObject * obj);
static GType switchboard_plug_user_accounts_widgets_avatar_popover_get_type_once (void);
static void _vala_switchboard_plug_user_accounts_widgets_avatar_popover_get_property (GObject * object,
                                                                               guint property_id,
                                                                               GValue * value,
                                                                               GParamSpec * pspec);
static void _vala_switchboard_plug_user_accounts_widgets_avatar_popover_set_property (GObject * object,
                                                                               guint property_id,
                                                                               const GValue * value,
                                                                               GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
switchboard_plug_user_accounts_widgets_avatar_popover_get_instance_private (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self)
{
	return G_STRUCT_MEMBER_P (self, SwitchboardPlugUserAccountsWidgetsAvatarPopover_private_offset);
}

SwitchboardPlugUserAccountsWidgetsAvatarPopover*
switchboard_plug_user_accounts_widgets_avatar_popover_construct (GType object_type,
                                                                 ActUser* user,
                                                                 SwitchboardPlugUserAccountsUserUtils* utils)
{
	SwitchboardPlugUserAccountsWidgetsAvatarPopover * self = NULL;
	g_return_val_if_fail (user != NULL, NULL);
	g_return_val_if_fail (utils != NULL, NULL);
	self = (SwitchboardPlugUserAccountsWidgetsAvatarPopover*) g_object_new (object_type, "user", user, "utils", utils, NULL);
	return self;
}

SwitchboardPlugUserAccountsWidgetsAvatarPopover*
switchboard_plug_user_accounts_widgets_avatar_popover_new (ActUser* user,
                                                           SwitchboardPlugUserAccountsUserUtils* utils)
{
	return switchboard_plug_user_accounts_widgets_avatar_popover_construct (SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_AVATAR_POPOVER, user, utils);
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		SwitchboardPlugUserAccountsWidgetsAvatarPopover* self;
		self = _data7_->self;
		_g_object_unref0 (_data7_->file_dialog);
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

static void
_switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar_switchboard_plug_user_accounts_dialogs_avatar_dialog_request_avatar_change (SwitchboardPlugUserAccountsDialogsAvatarDialog* _sender,
                                                                                                                                                 GdkPixbuf* pixbuf,
                                                                                                                                                 gpointer self)
{
	switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar ((SwitchboardPlugUserAccountsWidgetsAvatarPopover*) self, pixbuf);
}

static void
__lambda8_ (Block7Data* _data7_,
            gint response)
{
	SwitchboardPlugUserAccountsWidgetsAvatarPopover* self;
	self = _data7_->self;
	if (response == ((gint) GTK_RESPONSE_ACCEPT)) {
		gchar* path = NULL;
		GFile* _tmp0_;
		GFile* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		SwitchboardPlugUserAccountsDialogsAvatarDialog* avatar_dialog = NULL;
		const gchar* _tmp4_;
		SwitchboardPlugUserAccountsDialogsAvatarDialog* _tmp5_;
		SwitchboardPlugUserAccountsDialogsAvatarDialog* _tmp6_;
		SwitchboardPlugUserAccountsDialogsAvatarDialog* _tmp7_;
		_tmp0_ = gtk_file_chooser_get_file ((GtkFileChooser*) _data7_->file_dialog);
		_tmp1_ = _tmp0_;
		_tmp2_ = g_file_get_path (_tmp1_);
		_tmp3_ = _tmp2_;
		_g_object_unref0 (_tmp1_);
		path = _tmp3_;
		_tmp4_ = path;
		_tmp5_ = switchboard_plug_user_accounts_dialogs_avatar_dialog_new (_tmp4_);
		g_object_ref_sink (_tmp5_);
		avatar_dialog = _tmp5_;
		_tmp6_ = avatar_dialog;
		g_signal_connect_object (_tmp6_, "request-avatar-change", (GCallback) _switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar_switchboard_plug_user_accounts_dialogs_avatar_dialog_request_avatar_change, self, 0);
		_tmp7_ = avatar_dialog;
		gtk_window_present ((GtkWindow*) _tmp7_);
		gtk_native_dialog_hide ((GtkNativeDialog*) _data7_->file_dialog);
		_g_object_unref0 (avatar_dialog);
		_g_free0 (path);
	}
	gtk_native_dialog_destroy ((GtkNativeDialog*) _data7_->file_dialog);
}

static void
___lambda8__gtk_native_dialog_response (GtkNativeDialog* _sender,
                                        gint response_id,
                                        gpointer self)
{
	__lambda8_ (self, response_id);
}

static void
switchboard_plug_user_accounts_widgets_avatar_popover_select_from_file (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self)
{
	Block7Data* _data7_;
	GtkFileFilter* filter = NULL;
	GtkFileFilter* _tmp0_;
	GApplication* _tmp1_;
	GtkWindow* _tmp2_;
	GtkWindow* _tmp3_;
	GtkFileChooserNative* _tmp4_;
	g_return_if_fail (self != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->self = g_object_ref (self);
	gtk_popover_popdown ((GtkPopover*) self);
	_tmp0_ = gtk_file_filter_new ();
	filter = _tmp0_;
	gtk_file_filter_set_name (filter, _ ("Images"));
	gtk_file_filter_add_mime_type (filter, "image/jpeg");
	gtk_file_filter_add_mime_type (filter, "image/jpg");
	gtk_file_filter_add_mime_type (filter, "image/png");
	_tmp1_ = g_application_get_default ();
	_tmp2_ = gtk_application_get_active_window (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_application_get_type (), GtkApplication));
	_tmp3_ = _tmp2_;
	_tmp4_ = gtk_file_chooser_native_new (_ ("Select an image"), _tmp3_, GTK_FILE_CHOOSER_ACTION_OPEN, _ ("Open"), _ ("Cancel"));
	_data7_->file_dialog = _tmp4_;
	gtk_file_chooser_set_filter ((GtkFileChooser*) _data7_->file_dialog, filter);
	g_signal_connect_data ((GtkNativeDialog*) _data7_->file_dialog, "response", (GCallback) ___lambda8__gtk_native_dialog_response, block7_data_ref (_data7_), (GClosureNotify) block7_data_unref, 0);
	gtk_native_dialog_show ((GtkNativeDialog*) _data7_->file_dialog);
	_g_object_unref0 (filter);
	block7_data_unref (_data7_);
	_data7_ = NULL;
}

static void
switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self,
                                                                     GdkPixbuf* new_pixbuf)
{
	ActUser* _tmp0_;
	ActUser* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = switchboard_plug_user_accounts_get_current_user ();
	_tmp1_ = self->priv->_user;
	if (_tmp0_ != _tmp1_) {
		PolkitPermission* permission = NULL;
		PolkitPermission* _tmp2_;
		PolkitPermission* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp2_ = switchboard_plug_user_accounts_get_permission ();
		permission = _tmp2_;
		_tmp3_ = permission;
		_tmp4_ = g_permission_get_allowed ((GPermission*) _tmp3_);
		_tmp5_ = _tmp4_;
		if (!_tmp5_) {
			{
				PolkitPermission* _tmp6_;
				_tmp6_ = permission;
				g_permission_acquire ((GPermission*) _tmp6_, NULL, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* e = NULL;
				GError* _tmp7_;
				const gchar* _tmp8_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp7_ = e;
				_tmp8_ = _tmp7_->message;
				g_critical ("AvatarPopover.vala:112: %s", _tmp8_);
				_g_error_free0 (e);
				_g_object_unref0 (permission);
				return;
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (permission);
				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;
			}
		}
		_g_object_unref0 (permission);
	}
	if (new_pixbuf != NULL) {
		gchar* path = NULL;
		const gchar* _tmp9_;
		gchar* _tmp10_;
		gint i = 0;
		_tmp9_ = g_get_tmp_dir ();
		_tmp10_ = g_build_filename (_tmp9_, "user-icon-0", NULL);
		path = _tmp10_;
		i = 0;
		while (TRUE) {
			const gchar* _tmp11_;
			const gchar* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			gint _tmp16_;
			_tmp11_ = path;
			if (!g_file_test (_tmp11_, G_FILE_TEST_EXISTS)) {
				break;
			}
			_tmp12_ = g_get_tmp_dir ();
			_tmp13_ = g_strdup_printf ("user-icon-%d", i);
			_tmp14_ = _tmp13_;
			_tmp15_ = g_build_filename (_tmp12_, _tmp14_, NULL);
			_g_free0 (path);
			path = _tmp15_;
			_g_free0 (_tmp14_);
			_tmp16_ = i;
			i = _tmp16_ + 1;
		}
		{
			const gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			const gchar* _tmp20_;
			gchar** _tmp21_;
			gchar** _tmp22_;
			gint _tmp22__length1;
			gchar** _tmp23_;
			gchar** _tmp24_;
			gint _tmp24__length1;
			ActUser* _tmp25_;
			const gchar* _tmp26_;
			const gchar* _tmp27_;
			gchar* _tmp28_;
			gchar* _tmp29_;
			ActUser* _tmp30_;
			const gchar* _tmp31_;
			_tmp17_ = path;
			_tmp18_ = g_strdup_printf ("Saving temporary avatar file to %s", _tmp17_);
			_tmp19_ = _tmp18_;
			g_debug ("AvatarPopover.vala:126: %s", _tmp19_);
			_g_free0 (_tmp19_);
			_tmp20_ = path;
			_tmp21_ = g_new0 (gchar*, 0 + 1);
			_tmp22_ = _tmp21_;
			_tmp22__length1 = 0;
			_tmp23_ = g_new0 (gchar*, 0 + 1);
			_tmp24_ = _tmp23_;
			_tmp24__length1 = 0;
			gdk_pixbuf_savev (new_pixbuf, _tmp20_, "png", _tmp22_, _tmp24_, &_inner_error0_);
			_tmp24_ = (_vala_array_free (_tmp24_, _tmp24__length1, (GDestroyNotify) g_free), NULL);
			_tmp22_ = (_vala_array_free (_tmp22_, _tmp22__length1, (GDestroyNotify) g_free), NULL);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			_tmp25_ = self->priv->_user;
			_tmp26_ = act_user_get_user_name (_tmp25_);
			_tmp27_ = path;
			_tmp28_ = g_strdup_printf ("Setting avatar icon file for %s from temporary file %s", _tmp26_, _tmp27_);
			_tmp29_ = _tmp28_;
			g_debug ("AvatarPopover.vala:128: %s", _tmp29_);
			_g_free0 (_tmp29_);
			_tmp30_ = self->priv->_user;
			_tmp31_ = path;
			act_user_set_icon_file (_tmp30_, _tmp31_);
		}
		goto __finally1;
		__catch1_g_error:
		{
			GError* e = NULL;
			GError* _tmp32_;
			const gchar* _tmp33_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp32_ = e;
			_tmp33_ = _tmp32_->message;
			g_critical ("AvatarPopover.vala:131: %s", _tmp33_);
			_g_error_free0 (e);
		}
		__finally1:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (path);
			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;
		}
		_g_free0 (path);
	} else {
		ActUser* _tmp34_;
		const gchar* _tmp35_;
		gchar* _tmp36_;
		gchar* _tmp37_;
		ActUser* _tmp38_;
		_tmp34_ = self->priv->_user;
		_tmp35_ = act_user_get_user_name (_tmp34_);
		_tmp36_ = g_strdup_printf ("Setting no avatar icon file for %s", _tmp35_);
		_tmp37_ = _tmp36_;
		g_debug ("AvatarPopover.vala:134: %s", _tmp37_);
		_g_free0 (_tmp37_);
		_tmp38_ = self->priv->_user;
		act_user_set_icon_file (_tmp38_, "");
	}
}

ActUser*
switchboard_plug_user_accounts_widgets_avatar_popover_get_user (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self)
{
	ActUser* result;
	ActUser* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_user;
	result = _tmp0_;
	return result;
}

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

static void
switchboard_plug_user_accounts_widgets_avatar_popover_set_user (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self,
                                                                ActUser* value)
{
	ActUser* old_value;
	g_return_if_fail (self != NULL);
	old_value = switchboard_plug_user_accounts_widgets_avatar_popover_get_user (self);
	if (old_value != value) {
		ActUser* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_user);
		self->priv->_user = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, switchboard_plug_user_accounts_widgets_avatar_popover_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_USER_PROPERTY]);
	}
}

SwitchboardPlugUserAccountsUserUtils*
switchboard_plug_user_accounts_widgets_avatar_popover_get_utils (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self)
{
	SwitchboardPlugUserAccountsUserUtils* result;
	SwitchboardPlugUserAccountsUserUtils* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_utils;
	result = _tmp0_;
	return result;
}

static gpointer
_switchboard_plug_user_accounts_user_utils_ref0 (gpointer self)
{
	return self ? switchboard_plug_user_accounts_user_utils_ref (self) : NULL;
}

static void
switchboard_plug_user_accounts_widgets_avatar_popover_set_utils (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self,
                                                                 SwitchboardPlugUserAccountsUserUtils* value)
{
	SwitchboardPlugUserAccountsUserUtils* old_value;
	g_return_if_fail (self != NULL);
	old_value = switchboard_plug_user_accounts_widgets_avatar_popover_get_utils (self);
	if (old_value != value) {
		SwitchboardPlugUserAccountsUserUtils* _tmp0_;
		_tmp0_ = _switchboard_plug_user_accounts_user_utils_ref0 (value);
		_switchboard_plug_user_accounts_user_utils_unref0 (self->priv->_utils);
		self->priv->_utils = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, switchboard_plug_user_accounts_widgets_avatar_popover_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_UTILS_PROPERTY]);
	}
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static void
_switchboard_plug_user_accounts_widgets_avatar_popover___lambda9_ (SwitchboardPlugUserAccountsWidgetsAvatarPopover* self)
{
	gtk_popover_popdown ((GtkPopover*) self);
	switchboard_plug_user_accounts_widgets_avatar_popover_change_avatar (self, NULL);
}

static void
__switchboard_plug_user_accounts_widgets_avatar_popover___lambda9__gtk_button_clicked (GtkButton* _sender,
                                                                                       gpointer self)
{
	_switchboard_plug_user_accounts_widgets_avatar_popover___lambda9_ ((SwitchboardPlugUserAccountsWidgetsAvatarPopover*) self);
}

static void
_switchboard_plug_user_accounts_widgets_avatar_popover_select_from_file_gtk_button_clicked (GtkButton* _sender,
                                                                                            gpointer self)
{
	switchboard_plug_user_accounts_widgets_avatar_popover_select_from_file ((SwitchboardPlugUserAccountsWidgetsAvatarPopover*) self);
}

static GObject *
switchboard_plug_user_accounts_widgets_avatar_popover_constructor (GType type,
                                                                   guint n_construct_properties,
                                                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SwitchboardPlugUserAccountsWidgetsAvatarPopover * self;
	GtkLabel* remove_button_label = NULL;
	GtkLabel* _tmp0_ = NULL;
	GtkButton* remove_button = NULL;
	GtkLabel* _tmp1_;
	GtkWidget* _tmp2_;
	GtkButton* _tmp3_ = NULL;
	GtkButton* _tmp4_;
	GtkButton* _tmp5_;
	GtkButton* select_button = NULL;
	GtkLabel* _tmp6_ = NULL;
	GtkButton* _tmp7_ = NULL;
	GtkButton* _tmp8_;
	GtkButton* _tmp9_;
	GtkBox* button_box = NULL;
	GtkBox* _tmp10_;
	GtkBox* _tmp11_;
	GtkButton* _tmp12_;
	GtkBox* _tmp13_;
	GtkButton* _tmp14_;
	GtkBox* _tmp15_;
	ActUser* _tmp16_;
	const gchar* _tmp17_;
	GtkButton* _tmp20_;
	GtkButton* _tmp21_;
	parent_class = G_OBJECT_CLASS (switchboard_plug_user_accounts_widgets_avatar_popover_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_AVATAR_POPOVER, SwitchboardPlugUserAccountsWidgetsAvatarPopover);
	_tmp0_ = (GtkLabel*) gtk_label_new (_ ("Remove"));
	gtk_label_set_xalign (_tmp0_, (gfloat) 0);
	g_object_ref_sink (_tmp0_);
	remove_button_label = _tmp0_;
	_tmp1_ = remove_button_label;
	_tmp2_ = _g_object_ref0 ((GtkWidget*) _tmp1_);
	_tmp3_ = (GtkButton*) gtk_button_new ();
	gtk_button_set_child (_tmp3_, _tmp2_);
	_g_object_unref0 (_tmp2_);
	g_object_ref_sink (_tmp3_);
	remove_button = _tmp3_;
	_tmp4_ = remove_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp4_, GRANITE_STYLE_CLASS_MENUITEM);
	_tmp5_ = remove_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp5_, GRANITE_STYLE_CLASS_DESTRUCTIVE_ACTION);
	_tmp6_ = (GtkLabel*) gtk_label_new (_ ("Set from File…"));
	gtk_label_set_xalign (_tmp6_, (gfloat) 0);
	g_object_ref_sink (_tmp6_);
	_tmp7_ = (GtkButton*) gtk_button_new ();
	gtk_button_set_child (_tmp7_, (GtkWidget*) _tmp6_);
	_g_object_unref0 (_tmp6_);
	g_object_ref_sink (_tmp7_);
	select_button = _tmp7_;
	_tmp8_ = select_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, GRANITE_STYLE_CLASS_MENUITEM);
	_tmp9_ = select_button;
	gtk_widget_grab_focus ((GtkWidget*) _tmp9_);
	_tmp10_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp10_);
	button_box = _tmp10_;
	_tmp11_ = button_box;
	_tmp12_ = remove_button;
	gtk_box_append (_tmp11_, (GtkWidget*) _tmp12_);
	_tmp13_ = button_box;
	_tmp14_ = select_button;
	gtk_box_append (_tmp13_, (GtkWidget*) _tmp14_);
	gtk_popover_set_autohide ((GtkPopover*) self, TRUE);
	_tmp15_ = button_box;
	gtk_popover_set_child ((GtkPopover*) self, (GtkWidget*) _tmp15_);
	_tmp16_ = self->priv->_user;
	_tmp17_ = act_user_get_icon_file (_tmp16_);
	if (string_contains (_tmp17_, ".face")) {
		GtkButton* _tmp18_;
		_tmp18_ = remove_button;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp18_, FALSE);
	} else {
		GtkButton* _tmp19_;
		_tmp19_ = remove_button;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp19_, TRUE);
	}
	_tmp20_ = remove_button;
	g_signal_connect_object (_tmp20_, "clicked", (GCallback) __switchboard_plug_user_accounts_widgets_avatar_popover___lambda9__gtk_button_clicked, self, 0);
	_tmp21_ = select_button;
	g_signal_connect_object (_tmp21_, "clicked", (GCallback) _switchboard_plug_user_accounts_widgets_avatar_popover_select_from_file_gtk_button_clicked, self, 0);
	_g_object_unref0 (button_box);
	_g_object_unref0 (select_button);
	_g_object_unref0 (remove_button);
	_g_object_unref0 (remove_button_label);
	return obj;
}

static void
switchboard_plug_user_accounts_widgets_avatar_popover_class_init (SwitchboardPlugUserAccountsWidgetsAvatarPopoverClass * klass,
                                                                  gpointer klass_data)
{
	switchboard_plug_user_accounts_widgets_avatar_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SwitchboardPlugUserAccountsWidgetsAvatarPopover_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_switchboard_plug_user_accounts_widgets_avatar_popover_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_switchboard_plug_user_accounts_widgets_avatar_popover_set_property;
	G_OBJECT_CLASS (klass)->constructor = switchboard_plug_user_accounts_widgets_avatar_popover_constructor;
	G_OBJECT_CLASS (klass)->finalize = switchboard_plug_user_accounts_widgets_avatar_popover_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_USER_PROPERTY, switchboard_plug_user_accounts_widgets_avatar_popover_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_USER_PROPERTY] = g_param_spec_object ("user", "user", "user", act_user_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_UTILS_PROPERTY, switchboard_plug_user_accounts_widgets_avatar_popover_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_UTILS_PROPERTY] = switchboard_plug_user_accounts_param_spec_user_utils ("utils", "utils", "utils", SWITCHBOARD_PLUG_USER_ACCOUNTS_TYPE_USER_UTILS, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
switchboard_plug_user_accounts_widgets_avatar_popover_instance_init (SwitchboardPlugUserAccountsWidgetsAvatarPopover * self,
                                                                     gpointer klass)
{
	self->priv = switchboard_plug_user_accounts_widgets_avatar_popover_get_instance_private (self);
}

static void
switchboard_plug_user_accounts_widgets_avatar_popover_finalize (GObject * obj)
{
	SwitchboardPlugUserAccountsWidgetsAvatarPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_AVATAR_POPOVER, SwitchboardPlugUserAccountsWidgetsAvatarPopover);
	_g_object_unref0 (self->priv->_user);
	_switchboard_plug_user_accounts_user_utils_unref0 (self->priv->_utils);
	G_OBJECT_CLASS (switchboard_plug_user_accounts_widgets_avatar_popover_parent_class)->finalize (obj);
}

static GType
switchboard_plug_user_accounts_widgets_avatar_popover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SwitchboardPlugUserAccountsWidgetsAvatarPopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) switchboard_plug_user_accounts_widgets_avatar_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwitchboardPlugUserAccountsWidgetsAvatarPopover), 0, (GInstanceInitFunc) switchboard_plug_user_accounts_widgets_avatar_popover_instance_init, NULL };
	GType switchboard_plug_user_accounts_widgets_avatar_popover_type_id;
	switchboard_plug_user_accounts_widgets_avatar_popover_type_id = g_type_register_static (gtk_popover_get_type (), "SwitchboardPlugUserAccountsWidgetsAvatarPopover", &g_define_type_info, 0);
	SwitchboardPlugUserAccountsWidgetsAvatarPopover_private_offset = g_type_add_instance_private (switchboard_plug_user_accounts_widgets_avatar_popover_type_id, sizeof (SwitchboardPlugUserAccountsWidgetsAvatarPopoverPrivate));
	return switchboard_plug_user_accounts_widgets_avatar_popover_type_id;
}

GType
switchboard_plug_user_accounts_widgets_avatar_popover_get_type (void)
{
	static volatile gsize switchboard_plug_user_accounts_widgets_avatar_popover_type_id__once = 0;
	if (g_once_init_enter (&switchboard_plug_user_accounts_widgets_avatar_popover_type_id__once)) {
		GType switchboard_plug_user_accounts_widgets_avatar_popover_type_id;
		switchboard_plug_user_accounts_widgets_avatar_popover_type_id = switchboard_plug_user_accounts_widgets_avatar_popover_get_type_once ();
		g_once_init_leave (&switchboard_plug_user_accounts_widgets_avatar_popover_type_id__once, switchboard_plug_user_accounts_widgets_avatar_popover_type_id);
	}
	return switchboard_plug_user_accounts_widgets_avatar_popover_type_id__once;
}

static void
_vala_switchboard_plug_user_accounts_widgets_avatar_popover_get_property (GObject * object,
                                                                          guint property_id,
                                                                          GValue * value,
                                                                          GParamSpec * pspec)
{
	SwitchboardPlugUserAccountsWidgetsAvatarPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_AVATAR_POPOVER, SwitchboardPlugUserAccountsWidgetsAvatarPopover);
	switch (property_id) {
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_USER_PROPERTY:
		g_value_set_object (value, switchboard_plug_user_accounts_widgets_avatar_popover_get_user (self));
		break;
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_UTILS_PROPERTY:
		switchboard_plug_user_accounts_value_set_user_utils (value, switchboard_plug_user_accounts_widgets_avatar_popover_get_utils (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_switchboard_plug_user_accounts_widgets_avatar_popover_set_property (GObject * object,
                                                                          guint property_id,
                                                                          const GValue * value,
                                                                          GParamSpec * pspec)
{
	SwitchboardPlugUserAccountsWidgetsAvatarPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_AVATAR_POPOVER, SwitchboardPlugUserAccountsWidgetsAvatarPopover);
	switch (property_id) {
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_USER_PROPERTY:
		switchboard_plug_user_accounts_widgets_avatar_popover_set_user (self, g_value_get_object (value));
		break;
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_AVATAR_POPOVER_UTILS_PROPERTY:
		switchboard_plug_user_accounts_widgets_avatar_popover_set_utils (self, switchboard_plug_user_accounts_value_get_user_utils (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

