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

/*
* Copyright 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 <gtk/gtk.h>
#include <adwaita.h>
#include <act/act.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
#include <granite-7.h>
#include <pango/pango.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_USER_ITEM_0_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_USER_PROPERTY,
	SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_NUM_PROPERTIES
};
static GParamSpec* switchboard_plug_user_accounts_widgets_user_item_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_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 _SwitchboardPlugUserAccountsWidgetsUserItemPrivate {
	GtkRevealer* description_revealer;
	AdwAvatar* avatar;
	GtkLabel* full_name_label;
	GtkLabel* username_label;
	GtkRevealer* lock_revealer;
	ActUser* _user;
};

static gint SwitchboardPlugUserAccountsWidgetsUserItem_private_offset;
static gpointer switchboard_plug_user_accounts_widgets_user_item_parent_class = NULL;

static void switchboard_plug_user_accounts_widgets_user_item_update (SwitchboardPlugUserAccountsWidgetsUserItem* self);
static GObject * switchboard_plug_user_accounts_widgets_user_item_constructor (GType type,
                                                                        guint n_construct_properties,
                                                                        GObjectConstructParam * construct_properties);
static void _switchboard_plug_user_accounts_widgets_user_item_update_act_user_changed (ActUser* _sender,
                                                                                gpointer self);
static void switchboard_plug_user_accounts_widgets_user_item_finalize (GObject * obj);
static GType switchboard_plug_user_accounts_widgets_user_item_get_type_once (void);
static void _vala_switchboard_plug_user_accounts_widgets_user_item_get_property (GObject * object,
                                                                          guint property_id,
                                                                          GValue * value,
                                                                          GParamSpec * pspec);
static void _vala_switchboard_plug_user_accounts_widgets_user_item_set_property (GObject * object,
                                                                          guint property_id,
                                                                          const GValue * value,
                                                                          GParamSpec * pspec);

static inline gpointer
switchboard_plug_user_accounts_widgets_user_item_get_instance_private (SwitchboardPlugUserAccountsWidgetsUserItem* self)
{
	return G_STRUCT_MEMBER_P (self, SwitchboardPlugUserAccountsWidgetsUserItem_private_offset);
}

SwitchboardPlugUserAccountsWidgetsUserItem*
switchboard_plug_user_accounts_widgets_user_item_construct (GType object_type,
                                                            ActUser* user)
{
	SwitchboardPlugUserAccountsWidgetsUserItem * self = NULL;
	g_return_val_if_fail (user != NULL, NULL);
	self = (SwitchboardPlugUserAccountsWidgetsUserItem*) g_object_new (object_type, "user", user, NULL);
	return self;
}

SwitchboardPlugUserAccountsWidgetsUserItem*
switchboard_plug_user_accounts_widgets_user_item_new (ActUser* user)
{
	return switchboard_plug_user_accounts_widgets_user_item_construct (SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_USER_ITEM, user);
}

static void
switchboard_plug_user_accounts_widgets_user_item_update (SwitchboardPlugUserAccountsWidgetsUserItem* self)
{
	GFile* user_icon_file = NULL;
	ActUser* _tmp0_;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GtkLabel* _tmp7_;
	ActUser* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	AdwAvatar* _tmp11_;
	ActUser* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	GtkRevealer* _tmp15_;
	ActUser* _tmp16_;
	gboolean _tmp17_;
	gboolean _tmp18_;
	GtkLabel* _tmp19_;
	ActUser* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	ActUser* _tmp23_;
	gint _tmp24_;
	gint _tmp25_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_user;
	_tmp1_ = act_user_get_icon_file (_tmp0_);
	_tmp2_ = g_file_new_for_path (_tmp1_);
	user_icon_file = _tmp2_;
	{
		GdkTexture* _tmp3_ = NULL;
		GdkTexture* _tmp4_;
		AdwAvatar* _tmp5_;
		_tmp4_ = gdk_texture_new_from_file (user_icon_file, &_inner_error0_);
		_tmp3_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp5_ = self->priv->avatar;
		adw_avatar_set_custom_image (_tmp5_, (GdkPaintable*) _tmp3_);
		_g_object_unref0 (_tmp3_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		AdwAvatar* _tmp6_;
		g_clear_error (&_inner_error0_);
		_tmp6_ = self->priv->avatar;
		adw_avatar_set_custom_image (_tmp6_, NULL);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (user_icon_file);
		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;
	}
	_tmp7_ = self->priv->full_name_label;
	_tmp8_ = self->priv->_user;
	_tmp9_ = act_user_get_real_name (_tmp8_);
	_tmp10_ = _tmp9_;
	gtk_label_set_label (_tmp7_, _tmp10_);
	_tmp11_ = self->priv->avatar;
	_tmp12_ = self->priv->_user;
	_tmp13_ = act_user_get_real_name (_tmp12_);
	_tmp14_ = _tmp13_;
	adw_avatar_set_text (_tmp11_, _tmp14_);
	_tmp15_ = self->priv->lock_revealer;
	_tmp16_ = self->priv->_user;
	_tmp17_ = act_user_get_locked (_tmp16_);
	_tmp18_ = _tmp17_;
	gtk_revealer_set_reveal_child (_tmp15_, _tmp18_);
	_tmp19_ = self->priv->username_label;
	_tmp20_ = self->priv->_user;
	_tmp21_ = act_user_get_user_name (_tmp20_);
	_tmp22_ = _tmp21_;
	gtk_label_set_label (_tmp19_, _tmp22_);
	_tmp23_ = self->priv->_user;
	_tmp24_ = act_user_get_account_type (_tmp23_);
	_tmp25_ = _tmp24_;
	if (_tmp25_ == ((gint) ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)) {
		GtkLabel* _tmp26_;
		GtkLabel* _tmp27_;
		const gchar* _tmp28_;
		const gchar* _tmp29_;
		gchar* _tmp30_;
		gchar* _tmp31_;
		gchar* _tmp32_;
		gchar* _tmp33_;
		_tmp26_ = self->priv->username_label;
		_tmp27_ = self->priv->username_label;
		_tmp28_ = gtk_label_get_label (_tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = g_strdup_printf (" (%s)", _ ("Administrator"));
		_tmp31_ = _tmp30_;
		_tmp32_ = g_strconcat (_tmp29_, _tmp31_, NULL);
		_tmp33_ = _tmp32_;
		gtk_label_set_label (_tmp27_, _tmp33_);
		_g_free0 (_tmp33_);
		_g_free0 (_tmp31_);
	}
	_g_object_unref0 (user_icon_file);
}

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

static void
switchboard_plug_user_accounts_widgets_user_item_set_user (SwitchboardPlugUserAccountsWidgetsUserItem* self,
                                                           ActUser* value)
{
	ActUser* old_value;
	g_return_if_fail (self != NULL);
	old_value = switchboard_plug_user_accounts_widgets_user_item_get_user (self);
	if (old_value != value) {
		self->priv->_user = value;
		g_object_notify_by_pspec ((GObject *) self, switchboard_plug_user_accounts_widgets_user_item_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_USER_PROPERTY]);
	}
}

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

static void
_switchboard_plug_user_accounts_widgets_user_item_update_act_user_changed (ActUser* _sender,
                                                                           gpointer self)
{
	switchboard_plug_user_accounts_widgets_user_item_update ((SwitchboardPlugUserAccountsWidgetsUserItem*) self);
}

static GObject *
switchboard_plug_user_accounts_widgets_user_item_constructor (GType type,
                                                              guint n_construct_properties,
                                                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SwitchboardPlugUserAccountsWidgetsUserItem * self;
	GtkLabel* _tmp0_ = NULL;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_ = NULL;
	GtkLabel* _tmp3_;
	ActUser* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	AdwAvatar* _tmp7_;
	GtkImage* lock_image = NULL;
	GtkImage* _tmp8_ = NULL;
	GtkImage* _tmp9_;
	GtkWidget* _tmp10_;
	GtkRevealer* _tmp11_ = NULL;
	GtkOverlay* overlay = NULL;
	AdwAvatar* _tmp12_;
	GtkWidget* _tmp13_;
	GtkOverlay* _tmp14_ = NULL;
	GtkOverlay* _tmp15_;
	GtkRevealer* _tmp16_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp17_;
	GtkGrid* _tmp18_;
	GtkOverlay* _tmp19_;
	GtkGrid* _tmp20_;
	GtkLabel* _tmp21_;
	GtkGrid* _tmp22_;
	GtkLabel* _tmp23_;
	GtkGrid* _tmp24_;
	SwitchboardPlugUserAccountsWidgetsUserItem* weak_this = NULL;
	ActUser* _tmp25_;
	SwitchboardPlugUserAccountsWidgetsUserItem* _tmp26_;
	parent_class = G_OBJECT_CLASS (switchboard_plug_user_accounts_widgets_user_item_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_USER_ITEM, SwitchboardPlugUserAccountsWidgetsUserItem);
	_tmp0_ = (GtkLabel*) gtk_label_new ("");
	gtk_widget_set_halign ((GtkWidget*) _tmp0_, GTK_ALIGN_START);
	gtk_widget_set_valign ((GtkWidget*) _tmp0_, GTK_ALIGN_END);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->full_name_label);
	self->priv->full_name_label = _tmp0_;
	_tmp1_ = self->priv->full_name_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, GRANITE_STYLE_CLASS_H3_LABEL);
	_tmp2_ = (GtkLabel*) gtk_label_new ("");
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_START);
	gtk_widget_set_valign ((GtkWidget*) _tmp2_, GTK_ALIGN_START);
	gtk_label_set_ellipsize (_tmp2_, PANGO_ELLIPSIZE_END);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->username_label);
	self->priv->username_label = _tmp2_;
	_tmp3_ = self->priv->username_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp3_, GRANITE_STYLE_CLASS_SMALL_LABEL);
	_tmp4_ = self->priv->_user;
	_tmp5_ = act_user_get_real_name (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = (AdwAvatar*) adw_avatar_new (32, _tmp6_, TRUE);
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->avatar);
	self->priv->avatar = _tmp7_;
	_tmp8_ = (GtkImage*) gtk_image_new_from_icon_name ("locked");
	gtk_widget_set_halign ((GtkWidget*) _tmp8_, GTK_ALIGN_END);
	gtk_widget_set_valign ((GtkWidget*) _tmp8_, GTK_ALIGN_END);
	gtk_image_set_pixel_size (_tmp8_, 24);
	g_object_ref_sink (_tmp8_);
	lock_image = _tmp8_;
	_tmp9_ = lock_image;
	_tmp10_ = _g_object_ref0 ((GtkWidget*) _tmp9_);
	_tmp11_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_child (_tmp11_, _tmp10_);
	_g_object_unref0 (_tmp10_);
	gtk_revealer_set_transition_type (_tmp11_, GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
	g_object_ref_sink (_tmp11_);
	_g_object_unref0 (self->priv->lock_revealer);
	self->priv->lock_revealer = _tmp11_;
	_tmp12_ = self->priv->avatar;
	_tmp13_ = _g_object_ref0 ((GtkWidget*) _tmp12_);
	_tmp14_ = (GtkOverlay*) gtk_overlay_new ();
	gtk_overlay_set_child (_tmp14_, _tmp13_);
	_g_object_unref0 (_tmp13_);
	g_object_ref_sink (_tmp14_);
	overlay = _tmp14_;
	_tmp15_ = overlay;
	_tmp16_ = self->priv->lock_revealer;
	gtk_overlay_add_overlay (_tmp15_, (GtkWidget*) _tmp16_);
	_tmp17_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp17_);
	grid = _tmp17_;
	_tmp18_ = grid;
	_tmp19_ = overlay;
	gtk_grid_attach (_tmp18_, (GtkWidget*) _tmp19_, 0, 0, 1, 2);
	_tmp20_ = grid;
	_tmp21_ = self->priv->full_name_label;
	gtk_grid_attach (_tmp20_, (GtkWidget*) _tmp21_, 1, 0, 1, 1);
	_tmp22_ = grid;
	_tmp23_ = self->priv->username_label;
	gtk_grid_attach (_tmp22_, (GtkWidget*) _tmp23_, 1, 1, 1, 1);
	switchboard_plug_user_accounts_widgets_user_item_update (self);
	_tmp24_ = grid;
	gtk_list_box_row_set_child ((GtkListBoxRow*) self, (GtkWidget*) _tmp24_);
	weak_this = self;
	_tmp25_ = self->priv->_user;
	_tmp26_ = weak_this;
	g_signal_connect_object (_tmp25_, "changed", (GCallback) _switchboard_plug_user_accounts_widgets_user_item_update_act_user_changed, _tmp26_, 0);
	_g_object_unref0 (grid);
	_g_object_unref0 (overlay);
	_g_object_unref0 (lock_image);
	return obj;
}

static void
switchboard_plug_user_accounts_widgets_user_item_class_init (SwitchboardPlugUserAccountsWidgetsUserItemClass * klass,
                                                             gpointer klass_data)
{
	switchboard_plug_user_accounts_widgets_user_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SwitchboardPlugUserAccountsWidgetsUserItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_switchboard_plug_user_accounts_widgets_user_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_switchboard_plug_user_accounts_widgets_user_item_set_property;
	G_OBJECT_CLASS (klass)->constructor = switchboard_plug_user_accounts_widgets_user_item_constructor;
	G_OBJECT_CLASS (klass)->finalize = switchboard_plug_user_accounts_widgets_user_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_USER_PROPERTY, switchboard_plug_user_accounts_widgets_user_item_properties[SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_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));
}

static void
switchboard_plug_user_accounts_widgets_user_item_instance_init (SwitchboardPlugUserAccountsWidgetsUserItem * self,
                                                                gpointer klass)
{
	self->priv = switchboard_plug_user_accounts_widgets_user_item_get_instance_private (self);
}

static void
switchboard_plug_user_accounts_widgets_user_item_finalize (GObject * obj)
{
	SwitchboardPlugUserAccountsWidgetsUserItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_USER_ITEM, SwitchboardPlugUserAccountsWidgetsUserItem);
	_g_object_unref0 (self->priv->description_revealer);
	_g_object_unref0 (self->priv->avatar);
	_g_object_unref0 (self->priv->full_name_label);
	_g_object_unref0 (self->priv->username_label);
	_g_object_unref0 (self->priv->lock_revealer);
	G_OBJECT_CLASS (switchboard_plug_user_accounts_widgets_user_item_parent_class)->finalize (obj);
}

static GType
switchboard_plug_user_accounts_widgets_user_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SwitchboardPlugUserAccountsWidgetsUserItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) switchboard_plug_user_accounts_widgets_user_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwitchboardPlugUserAccountsWidgetsUserItem), 0, (GInstanceInitFunc) switchboard_plug_user_accounts_widgets_user_item_instance_init, NULL };
	GType switchboard_plug_user_accounts_widgets_user_item_type_id;
	switchboard_plug_user_accounts_widgets_user_item_type_id = g_type_register_static (gtk_list_box_row_get_type (), "SwitchboardPlugUserAccountsWidgetsUserItem", &g_define_type_info, 0);
	SwitchboardPlugUserAccountsWidgetsUserItem_private_offset = g_type_add_instance_private (switchboard_plug_user_accounts_widgets_user_item_type_id, sizeof (SwitchboardPlugUserAccountsWidgetsUserItemPrivate));
	return switchboard_plug_user_accounts_widgets_user_item_type_id;
}

GType
switchboard_plug_user_accounts_widgets_user_item_get_type (void)
{
	static volatile gsize switchboard_plug_user_accounts_widgets_user_item_type_id__once = 0;
	if (g_once_init_enter (&switchboard_plug_user_accounts_widgets_user_item_type_id__once)) {
		GType switchboard_plug_user_accounts_widgets_user_item_type_id;
		switchboard_plug_user_accounts_widgets_user_item_type_id = switchboard_plug_user_accounts_widgets_user_item_get_type_once ();
		g_once_init_leave (&switchboard_plug_user_accounts_widgets_user_item_type_id__once, switchboard_plug_user_accounts_widgets_user_item_type_id);
	}
	return switchboard_plug_user_accounts_widgets_user_item_type_id__once;
}

static void
_vala_switchboard_plug_user_accounts_widgets_user_item_get_property (GObject * object,
                                                                     guint property_id,
                                                                     GValue * value,
                                                                     GParamSpec * pspec)
{
	SwitchboardPlugUserAccountsWidgetsUserItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_USER_ITEM, SwitchboardPlugUserAccountsWidgetsUserItem);
	switch (property_id) {
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_USER_PROPERTY:
		g_value_set_object (value, switchboard_plug_user_accounts_widgets_user_item_get_user (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_switchboard_plug_user_accounts_widgets_user_item_set_property (GObject * object,
                                                                     guint property_id,
                                                                     const GValue * value,
                                                                     GParamSpec * pspec)
{
	SwitchboardPlugUserAccountsWidgetsUserItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_TYPE_USER_ITEM, SwitchboardPlugUserAccountsWidgetsUserItem);
	switch (property_id) {
		case SWITCHBOARD_PLUG_USER_ACCOUNTS_WIDGETS_USER_ITEM_USER_PROPERTY:
		switchboard_plug_user_accounts_widgets_user_item_set_user (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

