/* LidCloseActionComboBox.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from LidCloseActionComboBox.vala, do not modify */

/*
 * Copyright 2011-2018 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 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 <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <polkit/polkit.h>
#include <gio/gio.h>
#include <unistd.h>
#include "power.h"
#include <glib/gi18n-lib.h>

#define POWER_LID_CLOSE_ACTION_COMBO_BOX_HANDLE_LID_SWITCH_DOCKED_KEY "HandleLidSwitchDocked"
#define POWER_LID_CLOSE_ACTION_COMBO_BOX_HANDLE_LID_SWITCH_KEY "HandleLidSwitch"
#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

#define POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX (power_lid_close_action_combo_box_get_type ())
#define POWER_LID_CLOSE_ACTION_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBox))
#define POWER_LID_CLOSE_ACTION_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBoxClass))
#define POWER_IS_LID_CLOSE_ACTION_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX))
#define POWER_IS_LID_CLOSE_ACTION_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX))
#define POWER_LID_CLOSE_ACTION_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBoxClass))

typedef struct _PowerLidCloseActionComboBox PowerLidCloseActionComboBox;
typedef struct _PowerLidCloseActionComboBoxClass PowerLidCloseActionComboBoxClass;
typedef struct _PowerLidCloseActionComboBoxPrivate PowerLidCloseActionComboBoxPrivate;
enum  {
	POWER_LID_CLOSE_ACTION_COMBO_BOX_0_PROPERTY,
	POWER_LID_CLOSE_ACTION_COMBO_BOX_DOCK_PROPERTY,
	POWER_LID_CLOSE_ACTION_COMBO_BOX_NUM_PROPERTIES
};
static GParamSpec* power_lid_close_action_combo_box_properties[POWER_LID_CLOSE_ACTION_COMBO_BOX_NUM_PROPERTIES];
#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)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _PowerLidCloseActionComboBoxSetActiveWithPermissionData PowerLidCloseActionComboBoxSetActiveWithPermissionData;

struct _PowerLidCloseActionComboBox {
	GtkWidget parent_instance;
	PowerLidCloseActionComboBoxPrivate * priv;
};

struct _PowerLidCloseActionComboBoxClass {
	GtkWidgetClass parent_class;
};

struct _PowerLidCloseActionComboBoxPrivate {
	gboolean _dock;
	GtkDropDown* dropdown;
	guint previous_active;
};

struct _PowerLidCloseActionComboBoxSetActiveWithPermissionData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PowerLidCloseActionComboBox* self;
	guint index_;
	gboolean result;
	PolkitPermission* _tmp0_;
	PolkitPermission* _tmp1_;
	PolkitUnixProcess* _tmp2_;
	PolkitUnixProcess* _tmp3_;
	PolkitPermission* _tmp4_;
	PolkitPermission* _tmp5_;
	PolkitPermission* _tmp6_;
	GError* e;
	GError* _tmp7_;
	const gchar* _tmp8_;
	PolkitPermission* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	PolkitPermission* _tmp12_;
	GError* _vala1_e;
	GError* _tmp13_;
	const gchar* _tmp14_;
	GtkDropDown* _tmp15_;
	guint _tmp16_;
	guint _tmp17_;
	GtkDropDown* _tmp18_;
	PowerLogindHelperIface* helper;
	PowerLogindHelperIface* _tmp19_;
	PowerLogindHelperIface* _tmp20_;
	PowerLogindHelperIface* _tmp21_;
	PowerLogindHelperAction action;
	gboolean _tmp22_;
	PowerLogindHelperIface* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	PowerLogindHelperIface* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	GError* _vala2_e;
	GError* _tmp29_;
	const gchar* _tmp30_;
	GError* _inner_error0_;
};

static gint PowerLidCloseActionComboBox_private_offset;
static gpointer power_lid_close_action_combo_box_parent_class = NULL;
static PolkitPermission* power_lid_close_action_combo_box_permission;
static PolkitPermission* power_lid_close_action_combo_box_permission = NULL;

VALA_EXTERN GType power_lid_close_action_combo_box_get_type (void) G_GNUC_CONST ;
VALA_EXTERN PowerLidCloseActionComboBox* power_lid_close_action_combo_box_new (gboolean dock);
VALA_EXTERN PowerLidCloseActionComboBox* power_lid_close_action_combo_box_construct (GType object_type,
                                                                         gboolean dock);
static void power_lid_close_action_combo_box_set_active_with_permission_data_free (gpointer _data);
static void power_lid_close_action_combo_box_set_active_with_permission (PowerLidCloseActionComboBox* self,
                                                                  guint index_,
                                                                  GAsyncReadyCallback _callback_,
                                                                  gpointer _user_data_);
static gboolean power_lid_close_action_combo_box_set_active_with_permission_finish (PowerLidCloseActionComboBox* self,
                                                                             GAsyncResult* _res_);
static gboolean power_lid_close_action_combo_box_set_active_with_permission_co (PowerLidCloseActionComboBoxSetActiveWithPermissionData* _data_);
static void power_lid_close_action_combo_box_set_active_with_permission_ready (GObject* source_object,
                                                                        GAsyncResult* _res_,
                                                                        gpointer _user_data_);
static PowerLogindHelperAction power_lid_close_action_combo_box_get_action (PowerLidCloseActionComboBox* self);
VALA_EXTERN gboolean power_lid_close_action_combo_box_get_dock (PowerLidCloseActionComboBox* self);
static void power_lid_close_action_combo_box_on_changed (PowerLidCloseActionComboBox* self);
static void __lambda10_ (PowerLidCloseActionComboBox* self,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda10__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void power_lid_close_action_combo_box_update_current_action (PowerLidCloseActionComboBox* self);
static void power_lid_close_action_combo_box_set_active_item (PowerLidCloseActionComboBox* self,
                                                       PowerLogindHelperAction action);
static void power_lid_close_action_combo_box_set_dock (PowerLidCloseActionComboBox* self,
                                                gboolean value);
static GObject * power_lid_close_action_combo_box_constructor (GType type,
                                                        guint n_construct_properties,
                                                        GObjectConstructParam * construct_properties);
static void _power_lid_close_action_combo_box_on_changed_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void power_lid_close_action_combo_box_finalize (GObject * obj);
static GType power_lid_close_action_combo_box_get_type_once (void);
static void _vala_power_lid_close_action_combo_box_get_property (GObject * object,
                                                          guint property_id,
                                                          GValue * value,
                                                          GParamSpec * pspec);
static void _vala_power_lid_close_action_combo_box_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
power_lid_close_action_combo_box_get_instance_private (PowerLidCloseActionComboBox* self)
{
	return G_STRUCT_MEMBER_P (self, PowerLidCloseActionComboBox_private_offset);
}

PowerLidCloseActionComboBox*
power_lid_close_action_combo_box_construct (GType object_type,
                                            gboolean dock)
{
	PowerLidCloseActionComboBox * self = NULL;
	self = (PowerLidCloseActionComboBox*) g_object_new (object_type, "dock", dock, NULL);
	return self;
}

PowerLidCloseActionComboBox*
power_lid_close_action_combo_box_new (gboolean dock)
{
	return power_lid_close_action_combo_box_construct (POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, dock);
}

static void
power_lid_close_action_combo_box_set_active_with_permission_data_free (gpointer _data)
{
	PowerLidCloseActionComboBoxSetActiveWithPermissionData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PowerLidCloseActionComboBoxSetActiveWithPermissionData, _data_);
}

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

static void
power_lid_close_action_combo_box_set_active_with_permission (PowerLidCloseActionComboBox* self,
                                                             guint index_,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_)
{
	PowerLidCloseActionComboBoxSetActiveWithPermissionData* _data_;
	PowerLidCloseActionComboBox* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (PowerLidCloseActionComboBoxSetActiveWithPermissionData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, power_lid_close_action_combo_box_set_active_with_permission_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->index_ = index_;
	power_lid_close_action_combo_box_set_active_with_permission_co (_data_);
}

static gboolean
power_lid_close_action_combo_box_set_active_with_permission_finish (PowerLidCloseActionComboBox* self,
                                                                    GAsyncResult* _res_)
{
	gboolean result;
	PowerLidCloseActionComboBoxSetActiveWithPermissionData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
power_lid_close_action_combo_box_set_active_with_permission_ready (GObject* source_object,
                                                                   GAsyncResult* _res_,
                                                                   gpointer _user_data_)
{
	PowerLidCloseActionComboBoxSetActiveWithPermissionData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	power_lid_close_action_combo_box_set_active_with_permission_co (_data_);
}

static gboolean
power_lid_close_action_combo_box_set_active_with_permission_co (PowerLidCloseActionComboBoxSetActiveWithPermissionData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = power_lid_close_action_combo_box_permission;
	if (_data_->_tmp0_ == NULL) {
		{
			_data_->_tmp2_ = (PolkitUnixProcess*) polkit_unix_process_new ((gint) getpid ());
			_data_->_tmp3_ = _data_->_tmp2_;
			_data_->_state_ = 1;
			polkit_permission_new ("io.elementary.settings.power.administration", (PolkitSubject*) _data_->_tmp3_, NULL, power_lid_close_action_combo_box_set_active_with_permission_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp4_ = polkit_permission_new_finish (_data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp5_ = _data_->_tmp4_;
			_g_object_unref0 (_data_->_tmp3_);
			_data_->_tmp1_ = _data_->_tmp5_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->_tmp6_ = _data_->_tmp1_;
			_data_->_tmp1_ = NULL;
			_g_object_unref0 (power_lid_close_action_combo_box_permission);
			power_lid_close_action_combo_box_permission = _data_->_tmp6_;
			_g_object_unref0 (_data_->_tmp1_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp7_ = _data_->e;
			_data_->_tmp8_ = _data_->_tmp7_->message;
			g_critical ("LidCloseActionComboBox.vala:73: %s", _data_->_tmp8_);
			_data_->result = FALSE;
			_g_error_free0 (_data_->e);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp9_ = power_lid_close_action_combo_box_permission;
	_data_->_tmp10_ = g_permission_get_allowed ((GPermission*) _data_->_tmp9_);
	_data_->_tmp11_ = _data_->_tmp10_;
	if (!_data_->_tmp11_) {
		{
			_data_->_tmp12_ = power_lid_close_action_combo_box_permission;
			_data_->_state_ = 2;
			g_permission_acquire_async ((GPermission*) _data_->_tmp12_, NULL, power_lid_close_action_combo_box_set_active_with_permission_ready, _data_);
			return FALSE;
			_state_2:
			g_permission_acquire_finish ((GPermission*) _data_->_tmp12_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
		}
		goto __finally1;
		__catch1_g_error:
		{
			_data_->_vala1_e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp13_ = _data_->_vala1_e;
			_data_->_tmp14_ = _data_->_tmp13_->message;
			g_warning ("LidCloseActionComboBox.vala:82: %s", _data_->_tmp14_);
			_data_->result = FALSE;
			_g_error_free0 (_data_->_vala1_e);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp15_ = _data_->self->priv->dropdown;
	_data_->_tmp16_ = gtk_drop_down_get_selected (_data_->_tmp15_);
	_data_->_tmp17_ = _data_->_tmp16_;
	_data_->self->priv->previous_active = _data_->_tmp17_;
	_data_->_tmp18_ = _data_->self->priv->dropdown;
	gtk_drop_down_set_selected (_data_->_tmp18_, _data_->index_);
	_data_->_tmp19_ = power_logind_helper_get_logind_helper ();
	_data_->_tmp20_ = _g_object_ref0 (_data_->_tmp19_);
	_data_->helper = _data_->_tmp20_;
	_data_->_tmp21_ = _data_->helper;
	if (_data_->_tmp21_ == NULL) {
		_data_->result = FALSE;
		_g_object_unref0 (_data_->helper);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->action = power_lid_close_action_combo_box_get_action (_data_->self);
	{
		_data_->_tmp22_ = _data_->self->priv->_dock;
		if (_data_->_tmp22_) {
			_data_->_tmp23_ = _data_->helper;
			_data_->_tmp24_ = power_logind_helper_action_to_string (_data_->action);
			_data_->_tmp25_ = _data_->_tmp24_;
			power_logind_helper_iface_set_key (_data_->_tmp23_, POWER_LID_CLOSE_ACTION_COMBO_BOX_HANDLE_LID_SWITCH_DOCKED_KEY, _data_->_tmp25_, &_data_->_inner_error0_);
			_g_free0 (_data_->_tmp25_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch2_g_error;
			}
		} else {
			_data_->_tmp26_ = _data_->helper;
			_data_->_tmp27_ = power_logind_helper_action_to_string (_data_->action);
			_data_->_tmp28_ = _data_->_tmp27_;
			power_logind_helper_iface_set_key (_data_->_tmp26_, POWER_LID_CLOSE_ACTION_COMBO_BOX_HANDLE_LID_SWITCH_KEY, _data_->_tmp28_, &_data_->_inner_error0_);
			_g_free0 (_data_->_tmp28_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch2_g_error;
			}
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		_data_->_vala2_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp29_ = _data_->_vala2_e;
		_data_->_tmp30_ = _data_->_tmp29_->message;
		g_warning ("LidCloseActionComboBox.vala:103: %s", _data_->_tmp30_);
		_g_error_free0 (_data_->_vala2_e);
	}
	__finally2:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->helper);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = TRUE;
	_g_object_unref0 (_data_->helper);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
__lambda10_ (PowerLidCloseActionComboBox* self,
             GObject* obj,
             GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	if (!power_lid_close_action_combo_box_set_active_with_permission_finish (self, res)) {
		GtkDropDown* _tmp0_;
		_tmp0_ = self->priv->dropdown;
		gtk_drop_down_set_selected (_tmp0_, self->priv->previous_active);
	}
}

static void
___lambda10__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda10_ ((PowerLidCloseActionComboBox*) self, source_object, res);
	g_object_unref (self);
}

static void
power_lid_close_action_combo_box_on_changed (PowerLidCloseActionComboBox* self)
{
	GtkDropDown* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	GtkDropDown* _tmp3_;
	guint _tmp4_;
	guint _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->dropdown;
	_tmp1_ = gtk_drop_down_get_selected (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == self->priv->previous_active) {
		return;
	}
	_tmp3_ = self->priv->dropdown;
	_tmp4_ = gtk_drop_down_get_selected (_tmp3_);
	_tmp5_ = _tmp4_;
	power_lid_close_action_combo_box_set_active_with_permission (self, _tmp5_, ___lambda10__gasync_ready_callback, g_object_ref (self));
}

static void
power_lid_close_action_combo_box_update_current_action (PowerLidCloseActionComboBox* self)
{
	PowerLogindHelperIface* helper = NULL;
	PowerLogindHelperIface* _tmp0_;
	PowerLogindHelperIface* _tmp1_;
	PowerLogindHelperIface* _tmp2_;
	PowerLogindHelperAction action = 0;
	gboolean _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = power_logind_helper_get_logind_helper ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	helper = _tmp1_;
	_tmp2_ = helper;
	if (_tmp2_ == NULL) {
		_g_object_unref0 (helper);
		return;
	}
	_tmp3_ = self->priv->_dock;
	if (_tmp3_) {
		{
			gchar* val = NULL;
			PowerLogindHelperIface* _tmp4_;
			gchar* _tmp5_;
			const gchar* _tmp6_;
			_tmp4_ = helper;
			_tmp5_ = power_logind_helper_iface_get_key (_tmp4_, POWER_LID_CLOSE_ACTION_COMBO_BOX_HANDLE_LID_SWITCH_DOCKED_KEY, &_inner_error0_);
			val = _tmp5_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp6_ = val;
			action = power_logind_helper_action_from_string (_tmp6_);
			_g_free0 (val);
		}
		goto __finally0;
		__catch0_g_error:
		{
			g_clear_error (&_inner_error0_);
			action = POWER_LOGIND_HELPER_ACTION_IGNORE;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (helper);
			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;
		}
	} else {
		{
			gchar* val = NULL;
			PowerLogindHelperIface* _tmp7_;
			gchar* _tmp8_;
			const gchar* _tmp9_;
			_tmp7_ = helper;
			_tmp8_ = power_logind_helper_iface_get_key (_tmp7_, POWER_LID_CLOSE_ACTION_COMBO_BOX_HANDLE_LID_SWITCH_KEY, &_inner_error0_);
			val = _tmp8_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			_tmp9_ = val;
			action = power_logind_helper_action_from_string (_tmp9_);
			_g_free0 (val);
		}
		goto __finally1;
		__catch1_g_error:
		{
			g_clear_error (&_inner_error0_);
			action = POWER_LOGIND_HELPER_ACTION_SUSPEND;
		}
		__finally1:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (helper);
			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;
		}
	}
	power_lid_close_action_combo_box_set_active_item (self, action);
	_g_object_unref0 (helper);
}

static PowerLogindHelperAction
power_lid_close_action_combo_box_get_action (PowerLidCloseActionComboBox* self)
{
	GtkDropDown* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	PowerLogindHelperAction result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->dropdown;
	_tmp1_ = gtk_drop_down_get_selected (_tmp0_);
	_tmp2_ = _tmp1_;
	switch (_tmp2_) {
		case 0:
		{
			result = POWER_LOGIND_HELPER_ACTION_SUSPEND;
			return result;
		}
		case 1:
		{
			result = POWER_LOGIND_HELPER_ACTION_POWEROFF;
			return result;
		}
		case 2:
		{
			result = POWER_LOGIND_HELPER_ACTION_LOCK;
			return result;
		}
		case 3:
		{
			result = POWER_LOGIND_HELPER_ACTION_HALT;
			return result;
		}
		case 4:
		{
			result = POWER_LOGIND_HELPER_ACTION_IGNORE;
			return result;
		}
		default:
		{
			result = POWER_LOGIND_HELPER_ACTION_UNKNOWN;
			return result;
		}
	}
}

static void
power_lid_close_action_combo_box_set_active_item (PowerLidCloseActionComboBox* self,
                                                  PowerLogindHelperAction action)
{
	g_return_if_fail (self != NULL);
	switch (action) {
		case POWER_LOGIND_HELPER_ACTION_SUSPEND:
		{
			GtkDropDown* _tmp0_;
			_tmp0_ = self->priv->dropdown;
			gtk_drop_down_set_selected (_tmp0_, (guint) 0);
			break;
		}
		case POWER_LOGIND_HELPER_ACTION_POWEROFF:
		{
			GtkDropDown* _tmp1_;
			_tmp1_ = self->priv->dropdown;
			gtk_drop_down_set_selected (_tmp1_, (guint) 1);
			break;
		}
		case POWER_LOGIND_HELPER_ACTION_LOCK:
		{
			GtkDropDown* _tmp2_;
			_tmp2_ = self->priv->dropdown;
			gtk_drop_down_set_selected (_tmp2_, (guint) 2);
			break;
		}
		case POWER_LOGIND_HELPER_ACTION_HALT:
		{
			GtkDropDown* _tmp3_;
			_tmp3_ = self->priv->dropdown;
			gtk_drop_down_set_selected (_tmp3_, (guint) 3);
			break;
		}
		case POWER_LOGIND_HELPER_ACTION_IGNORE:
		{
			GtkDropDown* _tmp4_;
			_tmp4_ = self->priv->dropdown;
			gtk_drop_down_set_selected (_tmp4_, (guint) 4);
			break;
		}
		default:
		{
			break;
		}
	}
}

gboolean
power_lid_close_action_combo_box_get_dock (PowerLidCloseActionComboBox* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_dock;
	return result;
}

static void
power_lid_close_action_combo_box_set_dock (PowerLidCloseActionComboBox* self,
                                           gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = power_lid_close_action_combo_box_get_dock (self);
	if (old_value != value) {
		self->priv->_dock = value;
		g_object_notify_by_pspec ((GObject *) self, power_lid_close_action_combo_box_properties[POWER_LID_CLOSE_ACTION_COMBO_BOX_DOCK_PROPERTY]);
	}
}

static void
_power_lid_close_action_combo_box_on_changed_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	power_lid_close_action_combo_box_on_changed ((PowerLidCloseActionComboBox*) self);
}

static GObject *
power_lid_close_action_combo_box_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PowerLidCloseActionComboBox * self;
	GtkDropDown* _tmp0_ = NULL;
	GtkDropDown* _tmp1_;
	PowerLogindHelperIface* helper = NULL;
	PowerLogindHelperIface* _tmp2_;
	PowerLogindHelperIface* _tmp3_;
	gboolean _tmp4_ = FALSE;
	PowerLogindHelperIface* _tmp5_;
	GtkDropDown* _tmp26_;
	guint _tmp27_;
	guint _tmp28_;
	GtkDropDown* _tmp29_;
	parent_class = G_OBJECT_CLASS (power_lid_close_action_combo_box_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBox);
	_tmp0_ = (GtkDropDown*) gtk_drop_down_new (NULL, NULL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp0_, TRUE);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->dropdown);
	self->priv->dropdown = _tmp0_;
	_tmp1_ = self->priv->dropdown;
	gtk_widget_set_parent ((GtkWidget*) _tmp1_, (GtkWidget*) self);
	_tmp2_ = power_logind_helper_get_logind_helper ();
	_tmp3_ = _g_object_ref0 (_tmp2_);
	helper = _tmp3_;
	_tmp5_ = helper;
	if (_tmp5_ != NULL) {
		PowerLogindHelperIface* _tmp6_;
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp6_ = helper;
		_tmp7_ = power_logind_helper_iface_get_present (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		GtkDropDown* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar** _tmp15_;
		gchar** _tmp16_;
		gint _tmp16__length1;
		GtkStringList* _tmp17_;
		GtkStringList* _tmp18_;
		_tmp9_ = self->priv->dropdown;
		_tmp10_ = g_strdup (_ ("Suspend"));
		_tmp11_ = g_strdup (_ ("Shutdown"));
		_tmp12_ = g_strdup (_ ("Lock"));
		_tmp13_ = g_strdup (_ ("Halt"));
		_tmp14_ = g_strdup (_ ("Do nothing"));
		_tmp15_ = g_new0 (gchar*, 5 + 1);
		_tmp15_[0] = _tmp10_;
		_tmp15_[1] = _tmp11_;
		_tmp15_[2] = _tmp12_;
		_tmp15_[3] = _tmp13_;
		_tmp15_[4] = _tmp14_;
		_tmp16_ = _tmp15_;
		_tmp16__length1 = 5;
		_tmp17_ = gtk_string_list_new (_tmp16_);
		_tmp18_ = _tmp17_;
		gtk_drop_down_set_model (_tmp9_, (GListModel*) _tmp18_);
		_g_object_unref0 (_tmp18_);
		_tmp16_ = (_vala_array_free (_tmp16_, _tmp16__length1, (GDestroyNotify) g_free), NULL);
	} else {
		GtkDropDown* _tmp19_;
		gchar* _tmp20_;
		gchar** _tmp21_;
		gchar** _tmp22_;
		gint _tmp22__length1;
		GtkStringList* _tmp23_;
		GtkStringList* _tmp24_;
		GtkDropDown* _tmp25_;
		_tmp19_ = self->priv->dropdown;
		_tmp20_ = g_strdup (_ ("Not supported"));
		_tmp21_ = g_new0 (gchar*, 1 + 1);
		_tmp21_[0] = _tmp20_;
		_tmp22_ = _tmp21_;
		_tmp22__length1 = 1;
		_tmp23_ = gtk_string_list_new (_tmp22_);
		_tmp24_ = _tmp23_;
		gtk_drop_down_set_model (_tmp19_, (GListModel*) _tmp24_);
		_g_object_unref0 (_tmp24_);
		_tmp22_ = (_vala_array_free (_tmp22_, _tmp22__length1, (GDestroyNotify) g_free), NULL);
		_tmp25_ = self->priv->dropdown;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp25_, FALSE);
	}
	power_lid_close_action_combo_box_update_current_action (self);
	_tmp26_ = self->priv->dropdown;
	_tmp27_ = gtk_drop_down_get_selected (_tmp26_);
	_tmp28_ = _tmp27_;
	self->priv->previous_active = _tmp28_;
	_tmp29_ = self->priv->dropdown;
	g_signal_connect_object ((GObject*) _tmp29_, "notify::selected", (GCallback) _power_lid_close_action_combo_box_on_changed_g_object_notify, self, 0);
	_g_object_unref0 (helper);
	return obj;
}

static void
power_lid_close_action_combo_box_class_init (PowerLidCloseActionComboBoxClass * klass,
                                             gpointer klass_data)
{
	power_lid_close_action_combo_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PowerLidCloseActionComboBox_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_power_lid_close_action_combo_box_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_power_lid_close_action_combo_box_set_property;
	G_OBJECT_CLASS (klass)->constructor = power_lid_close_action_combo_box_constructor;
	G_OBJECT_CLASS (klass)->finalize = power_lid_close_action_combo_box_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), POWER_LID_CLOSE_ACTION_COMBO_BOX_DOCK_PROPERTY, power_lid_close_action_combo_box_properties[POWER_LID_CLOSE_ACTION_COMBO_BOX_DOCK_PROPERTY] = g_param_spec_boolean ("dock", "dock", "dock", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	gtk_widget_class_set_layout_manager_type (GTK_WIDGET_CLASS (klass), gtk_bin_layout_get_type ());
}

static void
power_lid_close_action_combo_box_instance_init (PowerLidCloseActionComboBox * self,
                                                gpointer klass)
{
	self->priv = power_lid_close_action_combo_box_get_instance_private (self);
}

static void
power_lid_close_action_combo_box_finalize (GObject * obj)
{
	PowerLidCloseActionComboBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBox);
	while (TRUE) {
		GtkWidget* _tmp0_;
		GtkWidget* _tmp1_;
		_tmp0_ = gtk_widget_get_last_child ((GtkWidget*) self);
		if (!(_tmp0_ != NULL)) {
			break;
		}
		_tmp1_ = gtk_widget_get_last_child ((GtkWidget*) self);
		gtk_widget_unparent (_tmp1_);
	}
	_g_object_unref0 (self->priv->dropdown);
	G_OBJECT_CLASS (power_lid_close_action_combo_box_parent_class)->finalize (obj);
}

static GType
power_lid_close_action_combo_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PowerLidCloseActionComboBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) power_lid_close_action_combo_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PowerLidCloseActionComboBox), 0, (GInstanceInitFunc) power_lid_close_action_combo_box_instance_init, NULL };
	GType power_lid_close_action_combo_box_type_id;
	power_lid_close_action_combo_box_type_id = g_type_register_static (gtk_widget_get_type (), "PowerLidCloseActionComboBox", &g_define_type_info, 0);
	PowerLidCloseActionComboBox_private_offset = g_type_add_instance_private (power_lid_close_action_combo_box_type_id, sizeof (PowerLidCloseActionComboBoxPrivate));
	return power_lid_close_action_combo_box_type_id;
}

GType
power_lid_close_action_combo_box_get_type (void)
{
	static volatile gsize power_lid_close_action_combo_box_type_id__once = 0;
	if (g_once_init_enter (&power_lid_close_action_combo_box_type_id__once)) {
		GType power_lid_close_action_combo_box_type_id;
		power_lid_close_action_combo_box_type_id = power_lid_close_action_combo_box_get_type_once ();
		g_once_init_leave (&power_lid_close_action_combo_box_type_id__once, power_lid_close_action_combo_box_type_id);
	}
	return power_lid_close_action_combo_box_type_id__once;
}

static void
_vala_power_lid_close_action_combo_box_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec)
{
	PowerLidCloseActionComboBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBox);
	switch (property_id) {
		case POWER_LID_CLOSE_ACTION_COMBO_BOX_DOCK_PROPERTY:
		g_value_set_boolean (value, power_lid_close_action_combo_box_get_dock (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_power_lid_close_action_combo_box_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec)
{
	PowerLidCloseActionComboBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, POWER_TYPE_LID_CLOSE_ACTION_COMBO_BOX, PowerLidCloseActionComboBox);
	switch (property_id) {
		case POWER_LID_CLOSE_ACTION_COMBO_BOX_DOCK_PROPERTY:
		power_lid_close_action_combo_box_set_dock (self, g_value_get_boolean (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);
}

