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

/*
 * Copyright (c) 2011-2017 elementary LLC. (http://launchpad.net/wingpanel)
 *
 * 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 2 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 "session.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <act/act.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.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  {
	SESSION_WIDGETS_USER_LIST_BOX_0_PROPERTY,
	SESSION_WIDGETS_USER_LIST_BOX_NUM_PROPERTIES
};
static GParamSpec* session_widgets_user_list_box_properties[SESSION_WIDGETS_USER_LIST_BOX_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	SESSION_WIDGETS_USER_LIST_BOX_CLOSE_SIGNAL,
	SESSION_WIDGETS_USER_LIST_BOX_SWITCH_TO_GUEST_SIGNAL,
	SESSION_WIDGETS_USER_LIST_BOX_SWITCH_TO_USER_SIGNAL,
	SESSION_WIDGETS_USER_LIST_BOX_NUM_SIGNALS
};
static guint session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_NUM_SIGNALS] = {0};

static gpointer session_widgets_user_list_box_parent_class = NULL;

static void session_widgets_user_list_box_real_row_activated (GtkListBox* base,
                                                       GtkListBoxRow* row);
static GObject * session_widgets_user_list_box_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties);
static gint _session_widgets_user_list_box_sort_func_gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                                      GtkListBoxRow* row2,
                                                                      gpointer self);
static GType session_widgets_user_list_box_get_type_once (void);

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

static void
session_widgets_user_list_box_real_row_activated (GtkListBox* base,
                                                  GtkListBoxRow* row)
{
	SessionWidgetsUserListBox * self;
	SessionWidgetsUserbox* userbox = NULL;
	SessionWidgetsUserbox* _tmp0_;
	SessionWidgetsUserbox* _tmp1_;
	SessionWidgetsUserbox* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	self = (SessionWidgetsUserListBox*) base;
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (row, SESSION_WIDGETS_TYPE_USERBOX, SessionWidgetsUserbox));
	userbox = _tmp0_;
	_tmp1_ = userbox;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (userbox);
		return;
	}
	g_signal_emit (self, session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_CLOSE_SIGNAL], 0);
	_tmp2_ = userbox;
	_tmp3_ = session_widgets_userbox_get_is_guest (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_) {
		g_signal_emit (self, session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_SWITCH_TO_GUEST_SIGNAL], 0);
	} else {
		ActUser* user = NULL;
		SessionWidgetsUserbox* _tmp5_;
		ActUser* _tmp6_;
		ActUser* _tmp7_;
		ActUser* _tmp8_;
		ActUser* _tmp9_;
		_tmp5_ = userbox;
		_tmp6_ = session_widgets_userbox_get_user (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _g_object_ref0 (_tmp7_);
		user = _tmp8_;
		_tmp9_ = user;
		if (_tmp9_ != NULL) {
			ActUser* _tmp10_;
			const gchar* _tmp11_;
			_tmp10_ = user;
			_tmp11_ = act_user_get_user_name (_tmp10_);
			g_signal_emit (self, session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_SWITCH_TO_USER_SIGNAL], 0, _tmp11_);
		}
		_g_object_unref0 (user);
	}
	_g_object_unref0 (userbox);
}

gint
session_widgets_user_list_box_sort_func (SessionWidgetsUserListBox* self,
                                         GtkListBoxRow* row1,
                                         GtkListBoxRow* row2)
{
	SessionWidgetsUserbox* userbox1 = NULL;
	SessionWidgetsUserbox* _tmp0_;
	SessionWidgetsUserbox* userbox2 = NULL;
	SessionWidgetsUserbox* _tmp1_;
	SessionWidgetsUserbox* _tmp2_;
	UserState _tmp3_;
	UserState _tmp4_;
	gboolean _tmp8_ = FALSE;
	SessionWidgetsUserbox* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (row1 != NULL, -1);
	g_return_val_if_fail (row2 != NULL, -1);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (row1, SESSION_WIDGETS_TYPE_USERBOX, SessionWidgetsUserbox));
	userbox1 = _tmp0_;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (row2, SESSION_WIDGETS_TYPE_USERBOX, SessionWidgetsUserbox));
	userbox2 = _tmp1_;
	_tmp2_ = userbox1;
	_tmp3_ = session_widgets_userbox_get_state (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ == USER_STATE_ACTIVE) {
		result = -1;
		_g_object_unref0 (userbox2);
		_g_object_unref0 (userbox1);
		return result;
	} else {
		SessionWidgetsUserbox* _tmp5_;
		UserState _tmp6_;
		UserState _tmp7_;
		_tmp5_ = userbox2;
		_tmp6_ = session_widgets_userbox_get_state (_tmp5_);
		_tmp7_ = _tmp6_;
		if (_tmp7_ == USER_STATE_ACTIVE) {
			result = 1;
			_g_object_unref0 (userbox2);
			_g_object_unref0 (userbox1);
			return result;
		}
	}
	_tmp9_ = userbox1;
	_tmp10_ = session_widgets_userbox_get_is_guest (_tmp9_);
	_tmp11_ = _tmp10_;
	if (_tmp11_) {
		SessionWidgetsUserbox* _tmp12_;
		gboolean _tmp13_;
		gboolean _tmp14_;
		_tmp12_ = userbox2;
		_tmp13_ = session_widgets_userbox_get_is_guest (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp8_ = !_tmp14_;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		result = 1;
		_g_object_unref0 (userbox2);
		_g_object_unref0 (userbox1);
		return result;
	} else {
		gboolean _tmp15_ = FALSE;
		SessionWidgetsUserbox* _tmp16_;
		gboolean _tmp17_;
		gboolean _tmp18_;
		_tmp16_ = userbox1;
		_tmp17_ = session_widgets_userbox_get_is_guest (_tmp16_);
		_tmp18_ = _tmp17_;
		if (!_tmp18_) {
			SessionWidgetsUserbox* _tmp19_;
			gboolean _tmp20_;
			gboolean _tmp21_;
			_tmp19_ = userbox2;
			_tmp20_ = session_widgets_userbox_get_is_guest (_tmp19_);
			_tmp21_ = _tmp20_;
			_tmp15_ = _tmp21_;
		} else {
			_tmp15_ = FALSE;
		}
		if (_tmp15_) {
			result = -1;
			_g_object_unref0 (userbox2);
			_g_object_unref0 (userbox1);
			return result;
		}
	}
	result = 0;
	_g_object_unref0 (userbox2);
	_g_object_unref0 (userbox1);
	return result;
}

SessionWidgetsUserListBox*
session_widgets_user_list_box_construct (GType object_type)
{
	SessionWidgetsUserListBox * self = NULL;
	self = (SessionWidgetsUserListBox*) g_object_new (object_type, NULL);
	return self;
}

SessionWidgetsUserListBox*
session_widgets_user_list_box_new (void)
{
	return session_widgets_user_list_box_construct (SESSION_WIDGETS_TYPE_USER_LIST_BOX);
}

static gint
_session_widgets_user_list_box_sort_func_gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                                 GtkListBoxRow* row2,
                                                                 gpointer self)
{
	gint result;
	result = session_widgets_user_list_box_sort_func ((SessionWidgetsUserListBox*) self, row1, row2);
	return result;
}

static GObject *
session_widgets_user_list_box_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SessionWidgetsUserListBox * self;
	parent_class = G_OBJECT_CLASS (session_widgets_user_list_box_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SESSION_WIDGETS_TYPE_USER_LIST_BOX, SessionWidgetsUserListBox);
	gtk_list_box_set_sort_func ((GtkListBox*) self, _session_widgets_user_list_box_sort_func_gtk_list_box_sort_func, g_object_ref (self), g_object_unref);
	gtk_list_box_set_activate_on_single_click ((GtkListBox*) self, TRUE);
	return obj;
}

static void
session_widgets_user_list_box_class_init (SessionWidgetsUserListBoxClass * klass,
                                          gpointer klass_data)
{
	session_widgets_user_list_box_parent_class = g_type_class_peek_parent (klass);
	((GtkListBoxClass *) klass)->row_activated = (void (*) (GtkListBox*, GtkListBoxRow*)) session_widgets_user_list_box_real_row_activated;
	G_OBJECT_CLASS (klass)->constructor = session_widgets_user_list_box_constructor;
	session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_CLOSE_SIGNAL] = g_signal_new ("close", SESSION_WIDGETS_TYPE_USER_LIST_BOX, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_SWITCH_TO_GUEST_SIGNAL] = g_signal_new ("switch-to-guest", SESSION_WIDGETS_TYPE_USER_LIST_BOX, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	session_widgets_user_list_box_signals[SESSION_WIDGETS_USER_LIST_BOX_SWITCH_TO_USER_SIGNAL] = g_signal_new ("switch-to-user", SESSION_WIDGETS_TYPE_USER_LIST_BOX, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
session_widgets_user_list_box_instance_init (SessionWidgetsUserListBox * self,
                                             gpointer klass)
{
}

static GType
session_widgets_user_list_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SessionWidgetsUserListBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) session_widgets_user_list_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SessionWidgetsUserListBox), 0, (GInstanceInitFunc) session_widgets_user_list_box_instance_init, NULL };
	GType session_widgets_user_list_box_type_id;
	session_widgets_user_list_box_type_id = g_type_register_static (gtk_list_box_get_type (), "SessionWidgetsUserListBox", &g_define_type_info, 0);
	return session_widgets_user_list_box_type_id;
}

GType
session_widgets_user_list_box_get_type (void)
{
	static volatile gsize session_widgets_user_list_box_type_id__once = 0;
	if (g_once_init_enter (&session_widgets_user_list_box_type_id__once)) {
		GType session_widgets_user_list_box_type_id;
		session_widgets_user_list_box_type_id = session_widgets_user_list_box_get_type_once ();
		g_once_init_leave (&session_widgets_user_list_box_type_id__once, session_widgets_user_list_box_type_id);
	}
	return session_widgets_user_list_box_type_id__once;
}

