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

/*
 * SPDX-License-Identifier: LGPL-3.0-or-later
 * SPDX-FileCopyrightText: 2023 elementary, Inc. (https://elementary.io)
 *                         2015 Adam Bieńkowski
 */

#include "screentime-limits.h"
#include <gtk/gtk.h>
#include <act/act.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <switchboard.h>
#include <glib-object.h>
#include <gio/gio.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  {
	PC_MAIN_BOX_0_PROPERTY,
	PC_MAIN_BOX_NUM_PROPERTIES
};
static GParamSpec* pc_main_box_properties[PC_MAIN_BOX_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))
typedef struct _Block1Data Block1Data;
#define _g_settings_schema_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_unref (var), NULL)))

struct _PCMainBoxPrivate {
	GtkStack* stack;
};

struct _Block1Data {
	int _ref_count_;
	PCMainBox* self;
	ActUserManager* user_manager;
};

static gint PCMainBox_private_offset;
static gpointer pc_main_box_parent_class = NULL;

static void pc_main_box_add_user (PCMainBox* self,
                           ActUser* user);
static void pc_main_box_update_user (PCMainBox* self,
                              ActUser* user);
static void pc_main_box_remove_user (PCMainBox* self,
                              ActUser* user);
static GObject * pc_main_box_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void _pc_main_box_add_user_act_user_manager_user_added (ActUserManager* _sender,
                                                        ActUser* user,
                                                        gpointer self);
static void _pc_main_box_update_user_act_user_manager_user_changed (ActUserManager* _sender,
                                                             ActUser* user,
                                                             gpointer self);
static void _pc_main_box_remove_user_act_user_manager_user_removed (ActUserManager* _sender,
                                                             ActUser* user,
                                                             gpointer self);
static void _pc_main_box____lambda22_ (PCMainBox* self,
                                ActUser* user);
static void __pc_main_box____lambda22__gfunc (gconstpointer data,
                                       gpointer self);
static void _pc_main_box____lambda23_ (Block1Data* _data1_);
static void __lambda24_ (PCMainBox* self,
                  ActUser* user);
static void ___lambda24__gfunc (gconstpointer data,
                         gpointer self);
static void __pc_main_box____lambda23__g_object_notify (GObject* _sender,
                                                 GParamSpec* pspec,
                                                 gpointer self);
static void pc_main_box_finalize (GObject * obj);
static GType pc_main_box_get_type_once (void);

static inline gpointer
pc_main_box_get_instance_private (PCMainBox* self)
{
	return G_STRUCT_MEMBER_P (self, PCMainBox_private_offset);
}

static void
pc_main_box_add_user (PCMainBox* self,
                      ActUser* user)
{
	GtkStack* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GtkWidget* _tmp5_;
	gboolean _tmp6_;
	PCWidgetsControlPage* page = NULL;
	PCWidgetsControlPage* _tmp7_;
	GtkStack* _tmp8_;
	PCWidgetsControlPage* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	PCWidgetsControlPage* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (user != NULL);
	_tmp0_ = self->priv->stack;
	_tmp1_ = act_user_get_uid (user);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf ("%i", _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = gtk_stack_get_child_by_name (_tmp0_, _tmp4_);
	_tmp6_ = _tmp5_ != NULL;
	_g_free0 (_tmp4_);
	if (_tmp6_) {
		return;
	}
	_tmp7_ = pc_widgets_control_page_new (user);
	g_object_ref_sink (_tmp7_);
	page = _tmp7_;
	_tmp8_ = self->priv->stack;
	_tmp9_ = page;
	_tmp10_ = act_user_get_uid (user);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strdup_printf ("%i", _tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = page;
	_tmp15_ = switchboard_settings_page_get_title ((SwitchboardSettingsPage*) _tmp14_);
	_tmp16_ = _tmp15_;
	gtk_stack_add_titled (_tmp8_, (GtkWidget*) _tmp9_, _tmp13_, _tmp16_);
	_g_free0 (_tmp13_);
	_g_object_unref0 (page);
}

static void
pc_main_box_update_user (PCMainBox* self,
                         ActUser* user)
{
	GtkStack* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GtkWidget* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (user != NULL);
	_tmp0_ = self->priv->stack;
	_tmp1_ = act_user_get_uid (user);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf ("%i", _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = gtk_stack_get_child_by_name (_tmp0_, _tmp4_);
	pc_widgets_control_page_update_user (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, PC_WIDGETS_TYPE_CONTROL_PAGE, PCWidgetsControlPage));
	_g_free0 (_tmp4_);
}

static void
pc_main_box_remove_user (PCMainBox* self,
                         ActUser* user)
{
	GtkStack* _tmp0_;
	GtkStack* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GtkWidget* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (user != NULL);
	_tmp0_ = self->priv->stack;
	_tmp1_ = self->priv->stack;
	_tmp2_ = act_user_get_uid (user);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf ("%i", _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = gtk_stack_get_child_by_name (_tmp1_, _tmp5_);
	gtk_stack_remove (_tmp0_, _tmp6_);
	_g_free0 (_tmp5_);
}

PCMainBox*
pc_main_box_construct (GType object_type)
{
	PCMainBox * self = NULL;
	self = (PCMainBox*) g_object_new (object_type, NULL);
	return self;
}

PCMainBox*
pc_main_box_new (void)
{
	return pc_main_box_construct (PC_TYPE_MAIN_BOX);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		PCMainBox* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

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

static void
_pc_main_box_add_user_act_user_manager_user_added (ActUserManager* _sender,
                                                   ActUser* user,
                                                   gpointer self)
{
	pc_main_box_add_user ((PCMainBox*) self, user);
}

static void
_pc_main_box_update_user_act_user_manager_user_changed (ActUserManager* _sender,
                                                        ActUser* user,
                                                        gpointer self)
{
	pc_main_box_update_user ((PCMainBox*) self, user);
}

static void
_pc_main_box_remove_user_act_user_manager_user_removed (ActUserManager* _sender,
                                                        ActUser* user,
                                                        gpointer self)
{
	pc_main_box_remove_user ((PCMainBox*) self, user);
}

static void
_pc_main_box____lambda22_ (PCMainBox* self,
                           ActUser* user)
{
	g_return_if_fail (user != NULL);
	pc_main_box_add_user (self, user);
}

static void
__pc_main_box____lambda22__gfunc (gconstpointer data,
                                  gpointer self)
{
	_pc_main_box____lambda22_ ((PCMainBox*) self, (ActUser*) data);
}

static void
__lambda24_ (PCMainBox* self,
             ActUser* user)
{
	g_return_if_fail (user != NULL);
	pc_main_box_add_user (self, user);
}

static void
___lambda24__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda24_ ((PCMainBox*) self, (ActUser*) data);
}

static void
_pc_main_box____lambda23_ (Block1Data* _data1_)
{
	PCMainBox* self;
	ActUserManager* _tmp0_;
	GSList* _tmp1_;
	GSList* _tmp2_;
	self = _data1_->self;
	_tmp0_ = _data1_->user_manager;
	_tmp1_ = act_user_manager_list_users (_tmp0_);
	_tmp2_ = _tmp1_;
	g_slist_foreach (_tmp2_, ___lambda24__gfunc, self);
	(_tmp2_ == NULL) ? NULL : (_tmp2_ = (g_slist_free (_tmp2_), NULL));
}

static void
__pc_main_box____lambda23__g_object_notify (GObject* _sender,
                                            GParamSpec* pspec,
                                            gpointer self)
{
	_pc_main_box____lambda23_ (self);
}

static GObject *
pc_main_box_constructor (GType type,
                         guint n_construct_properties,
                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PCMainBox * self;
	Block1Data* _data1_;
	GtkStack* _tmp0_;
	SwitchboardSettingsSidebar* sidebar = NULL;
	GtkStack* _tmp1_;
	SwitchboardSettingsSidebar* _tmp2_ = NULL;
	GtkPaned* paned = NULL;
	SwitchboardSettingsSidebar* _tmp3_;
	GtkWidget* _tmp4_;
	GtkStack* _tmp5_;
	GtkWidget* _tmp6_;
	GtkPaned* _tmp7_ = NULL;
	GSettingsSchema* sss = NULL;
	GSettingsSchemaSource* _tmp8_;
	GSettingsSchema* _tmp9_;
	gboolean _tmp10_ = FALSE;
	GSettingsSchema* _tmp11_;
	GtkPaned* _tmp16_;
	ActUserManager* _tmp17_;
	ActUserManager* _tmp18_;
	ActUserManager* _tmp19_;
	ActUserManager* _tmp20_;
	ActUserManager* _tmp21_;
	gboolean _tmp22_;
	gboolean _tmp23_;
	parent_class = G_OBJECT_CLASS (pc_main_box_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PC_TYPE_MAIN_BOX, PCMainBox);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = (GtkStack*) gtk_stack_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->stack);
	self->priv->stack = _tmp0_;
	_tmp1_ = self->priv->stack;
	_tmp2_ = switchboard_settings_sidebar_new (_tmp1_);
	switchboard_settings_sidebar_set_show_title_buttons (_tmp2_, TRUE);
	g_object_ref_sink (_tmp2_);
	sidebar = _tmp2_;
	_tmp3_ = sidebar;
	_tmp4_ = _g_object_ref0 ((GtkWidget*) _tmp3_);
	_tmp5_ = self->priv->stack;
	_tmp6_ = _g_object_ref0 ((GtkWidget*) _tmp5_);
	_tmp7_ = (GtkPaned*) gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
	gtk_paned_set_start_child (_tmp7_, _tmp4_);
	_g_object_unref0 (_tmp4_);
	gtk_paned_set_end_child (_tmp7_, _tmp6_);
	_g_object_unref0 (_tmp6_);
	gtk_paned_set_shrink_start_child (_tmp7_, FALSE);
	gtk_paned_set_shrink_end_child (_tmp7_, FALSE);
	gtk_paned_set_resize_start_child (_tmp7_, FALSE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp7_, TRUE);
	g_object_ref_sink (_tmp7_);
	paned = _tmp7_;
	_tmp8_ = g_settings_schema_source_get_default ();
	_tmp9_ = g_settings_schema_source_lookup (_tmp8_, "io.elementary.settings", TRUE);
	sss = _tmp9_;
	_tmp11_ = sss;
	if (_tmp11_ != NULL) {
		GSettingsSchema* _tmp12_;
		_tmp12_ = sss;
		_tmp10_ = g_settings_schema_has_key (_tmp12_, "sidebar-position");
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		GSettings* settings = NULL;
		GSettings* _tmp13_;
		GSettings* _tmp14_;
		GtkPaned* _tmp15_;
		_tmp13_ = g_settings_new ("io.elementary.settings");
		settings = _tmp13_;
		_tmp14_ = settings;
		_tmp15_ = paned;
		g_settings_bind (_tmp14_, "sidebar-position", (GObject*) _tmp15_, "position", G_SETTINGS_BIND_DEFAULT);
		_g_object_unref0 (settings);
	}
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	_tmp16_ = paned;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp16_);
	_tmp17_ = act_user_manager_get_default ();
	_data1_->user_manager = _tmp17_;
	_tmp18_ = _data1_->user_manager;
	g_signal_connect_object (_tmp18_, "user-added", (GCallback) _pc_main_box_add_user_act_user_manager_user_added, self, 0);
	_tmp19_ = _data1_->user_manager;
	g_signal_connect_object (_tmp19_, "user-changed", (GCallback) _pc_main_box_update_user_act_user_manager_user_changed, self, 0);
	_tmp20_ = _data1_->user_manager;
	g_signal_connect_object (_tmp20_, "user-removed", (GCallback) _pc_main_box_remove_user_act_user_manager_user_removed, self, 0);
	_tmp21_ = _data1_->user_manager;
	g_object_get (_tmp21_, "is-loaded", &_tmp22_, NULL);
	_tmp23_ = _tmp22_;
	if (_tmp23_) {
		ActUserManager* _tmp24_;
		GSList* _tmp25_;
		GSList* _tmp26_;
		_tmp24_ = _data1_->user_manager;
		_tmp25_ = act_user_manager_list_users (_tmp24_);
		_tmp26_ = _tmp25_;
		g_slist_foreach (_tmp26_, __pc_main_box____lambda22__gfunc, self);
		(_tmp26_ == NULL) ? NULL : (_tmp26_ = (g_slist_free (_tmp26_), NULL));
	} else {
		ActUserManager* _tmp27_;
		_tmp27_ = _data1_->user_manager;
		g_signal_connect_data ((GObject*) _tmp27_, "notify::is-loaded", (GCallback) __pc_main_box____lambda23__g_object_notify, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	}
	_g_settings_schema_unref0 (sss);
	_g_object_unref0 (paned);
	_g_object_unref0 (sidebar);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return obj;
}

static void
pc_main_box_class_init (PCMainBoxClass * klass,
                        gpointer klass_data)
{
	pc_main_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PCMainBox_private_offset);
	G_OBJECT_CLASS (klass)->constructor = pc_main_box_constructor;
	G_OBJECT_CLASS (klass)->finalize = pc_main_box_finalize;
}

static void
pc_main_box_instance_init (PCMainBox * self,
                           gpointer klass)
{
	self->priv = pc_main_box_get_instance_private (self);
}

static void
pc_main_box_finalize (GObject * obj)
{
	PCMainBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PC_TYPE_MAIN_BOX, PCMainBox);
	_g_object_unref0 (self->priv->stack);
	G_OBJECT_CLASS (pc_main_box_parent_class)->finalize (obj);
}

static GType
pc_main_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PCMainBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pc_main_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PCMainBox), 0, (GInstanceInitFunc) pc_main_box_instance_init, NULL };
	GType pc_main_box_type_id;
	pc_main_box_type_id = g_type_register_static (gtk_box_get_type (), "PCMainBox", &g_define_type_info, 0);
	PCMainBox_private_offset = g_type_add_instance_private (pc_main_box_type_id, sizeof (PCMainBoxPrivate));
	return pc_main_box_type_id;
}

GType
pc_main_box_get_type (void)
{
	static volatile gsize pc_main_box_type_id__once = 0;
	if (g_once_init_enter (&pc_main_box_type_id__once)) {
		GType pc_main_box_type_id;
		pc_main_box_type_id = pc_main_box_get_type_once ();
		g_once_init_leave (&pc_main_box_type_id__once, pc_main_box_type_id);
	}
	return pc_main_box_type_id__once;
}

