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

#include <gtk/gtk.h>
#include <glib-object.h>
#include "libdino.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include "xmpp-vala.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DINO_UI_TYPE_ACCOUNT_COMBO_BOX (dino_ui_account_combo_box_get_type ())
#define DINO_UI_ACCOUNT_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_ACCOUNT_COMBO_BOX, DinoUiAccountComboBox))
#define DINO_UI_ACCOUNT_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_ACCOUNT_COMBO_BOX, DinoUiAccountComboBoxClass))
#define DINO_UI_IS_ACCOUNT_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_ACCOUNT_COMBO_BOX))
#define DINO_UI_IS_ACCOUNT_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_ACCOUNT_COMBO_BOX))
#define DINO_UI_ACCOUNT_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_ACCOUNT_COMBO_BOX, DinoUiAccountComboBoxClass))

typedef struct _DinoUiAccountComboBox DinoUiAccountComboBox;
typedef struct _DinoUiAccountComboBoxClass DinoUiAccountComboBoxClass;
typedef struct _DinoUiAccountComboBoxPrivate DinoUiAccountComboBoxPrivate;
enum  {
	DINO_UI_ACCOUNT_COMBO_BOX_0_PROPERTY,
	DINO_UI_ACCOUNT_COMBO_BOX_SELECTED_PROPERTY,
	DINO_UI_ACCOUNT_COMBO_BOX_NUM_PROPERTIES
};
static GParamSpec* dino_ui_account_combo_box_properties[DINO_UI_ACCOUNT_COMBO_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))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))

struct _DinoUiAccountComboBox {
	GtkComboBox parent_instance;
	DinoUiAccountComboBoxPrivate * priv;
};

struct _DinoUiAccountComboBoxClass {
	GtkComboBoxClass parent_class;
};

struct _DinoUiAccountComboBoxPrivate {
	DinoStreamInteractor* stream_interactor;
	GtkListStore* list_store;
};

static gint DinoUiAccountComboBox_private_offset;
static gpointer dino_ui_account_combo_box_parent_class = NULL;

VALA_EXTERN GType dino_ui_account_combo_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiAccountComboBox, g_object_unref)
VALA_EXTERN void dino_ui_account_combo_box_initialize (DinoUiAccountComboBox* self,
                                           DinoStreamInteractor* stream_interactor);
VALA_EXTERN DinoUiAccountComboBox* dino_ui_account_combo_box_new (void);
VALA_EXTERN DinoUiAccountComboBox* dino_ui_account_combo_box_construct (GType object_type);
VALA_EXTERN DinoEntitiesAccount* dino_ui_account_combo_box_get_selected (DinoUiAccountComboBox* self);
VALA_EXTERN void dino_ui_account_combo_box_set_selected (DinoUiAccountComboBox* self,
                                             DinoEntitiesAccount* value);
static void dino_ui_account_combo_box_finalize (GObject * obj);
static GType dino_ui_account_combo_box_get_type_once (void);
static void _vala_dino_ui_account_combo_box_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_dino_ui_account_combo_box_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_ui_account_combo_box_get_instance_private (DinoUiAccountComboBox* self)
{
	return G_STRUCT_MEMBER_P (self, DinoUiAccountComboBox_private_offset);
}

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

void
dino_ui_account_combo_box_initialize (DinoUiAccountComboBox* self,
                                      DinoStreamInteractor* stream_interactor)
{
	DinoStreamInteractor* _tmp0_;
	GtkCellRendererText* renderer = NULL;
	GtkCellRendererText* _tmp1_;
	GtkCellRendererText* _tmp2_;
	GtkCellRendererText* _tmp3_;
	GtkTreeIter iter = {0};
	GtkListStore* _tmp23_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream_interactor != NULL);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	_tmp1_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp1_);
	renderer = _tmp1_;
	_tmp2_ = renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) self, (GtkCellRenderer*) _tmp2_, TRUE);
	_tmp3_ = renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) self, (GtkCellRenderer*) _tmp3_, "text", 0);
	{
		GeeArrayList* _account_list = NULL;
		GeeArrayList* _tmp4_;
		gint _account_size = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _account_index = 0;
		_tmp4_ = dino_stream_interactor_get_accounts (stream_interactor);
		_account_list = _tmp4_;
		_tmp5_ = _account_list;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_account_size = _tmp7_;
		_account_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			DinoEntitiesAccount* account = NULL;
			GeeArrayList* _tmp10_;
			gpointer _tmp11_;
			GtkListStore* _tmp12_;
			GtkTreeIter _tmp13_ = {0};
			GtkListStore* _tmp14_;
			GtkTreeIter _tmp15_;
			DinoEntitiesAccount* _tmp16_;
			XmppJid* _tmp17_;
			XmppJid* _tmp18_;
			XmppJid* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			DinoEntitiesAccount* _tmp22_;
			_account_index = _account_index + 1;
			_tmp8_ = _account_index;
			_tmp9_ = _account_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _account_list;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _account_index);
			account = (DinoEntitiesAccount*) _tmp11_;
			_tmp12_ = self->priv->list_store;
			gtk_list_store_append (_tmp12_, &_tmp13_);
			iter = _tmp13_;
			_tmp14_ = self->priv->list_store;
			_tmp15_ = iter;
			_tmp16_ = account;
			_tmp17_ = dino_entities_account_get_bare_jid (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = _tmp18_;
			_tmp20_ = xmpp_jid_to_string (_tmp19_);
			_tmp21_ = _tmp20_;
			_tmp22_ = account;
			gtk_list_store_set (_tmp14_, &_tmp15_, 0, _tmp21_, 1, _tmp22_, -1);
			_g_free0 (_tmp21_);
			_xmpp_jid_unref0 (_tmp19_);
			_g_object_unref0 (account);
		}
		_g_object_unref0 (_account_list);
	}
	_tmp23_ = self->priv->list_store;
	gtk_combo_box_set_model ((GtkComboBox*) self, (GtkTreeModel*) _tmp23_);
	gtk_combo_box_set_active ((GtkComboBox*) self, 0);
	_g_object_unref0 (renderer);
}

DinoUiAccountComboBox*
dino_ui_account_combo_box_construct (GType object_type)
{
	DinoUiAccountComboBox * self = NULL;
	self = (DinoUiAccountComboBox*) g_object_new (object_type, NULL);
	return self;
}

DinoUiAccountComboBox*
dino_ui_account_combo_box_new (void)
{
	return dino_ui_account_combo_box_construct (DINO_UI_TYPE_ACCOUNT_COMBO_BOX);
}

DinoEntitiesAccount*
dino_ui_account_combo_box_get_selected (DinoUiAccountComboBox* self)
{
	DinoEntitiesAccount* result;
	GtkTreeIter selected = {0};
	GtkTreeIter _tmp0_ = {0};
	gboolean _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = gtk_combo_box_get_active_iter ((GtkComboBox*) self, &_tmp0_);
	selected = _tmp0_;
	if (_tmp1_) {
		GValue value = {0};
		GtkListStore* _tmp2_;
		GtkTreeIter _tmp3_;
		GValue _tmp4_ = {0};
		GValue _tmp5_;
		_tmp2_ = self->priv->list_store;
		_tmp3_ = selected;
		gtk_tree_model_get_value ((GtkTreeModel*) _tmp2_, &_tmp3_, 1, &_tmp4_);
		G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
		value = _tmp4_;
		_tmp5_ = value;
		result = g_value_get_object (&_tmp5_);
		G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
		return result;
	}
	result = NULL;
	return result;
}

void
dino_ui_account_combo_box_set_selected (DinoUiAccountComboBox* self,
                                        DinoEntitiesAccount* value)
{
	GtkTreeIter iter = {0};
	GtkListStore* _tmp0_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->list_store;
	_tmp2_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp0_, &_tmp1_);
	iter = _tmp1_;
	if (_tmp2_) {
		gint i = 0;
		i = 0;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				GValue val = {0};
				GtkListStore* _tmp6_;
				GtkTreeIter _tmp7_;
				GValue _tmp8_ = {0};
				DinoEntitiesAccount* account = NULL;
				GValue _tmp9_;
				DinoEntitiesAccount* _tmp10_;
				gboolean _tmp11_ = FALSE;
				DinoEntitiesAccount* _tmp12_;
				gint _tmp14_;
				if (!_tmp3_) {
					GtkListStore* _tmp4_;
					gboolean _tmp5_;
					_tmp4_ = self->priv->list_store;
					_tmp5_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp4_, &iter);
					if (!_tmp5_) {
						break;
					}
				}
				_tmp3_ = FALSE;
				_tmp6_ = self->priv->list_store;
				_tmp7_ = iter;
				gtk_tree_model_get_value ((GtkTreeModel*) _tmp6_, &_tmp7_, 1, &_tmp8_);
				G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL;
				val = _tmp8_;
				_tmp9_ = val;
				_tmp10_ = _g_object_ref0 (g_value_get_object (&_tmp9_));
				account = _tmp10_;
				_tmp12_ = account;
				if (_tmp12_ != NULL) {
					DinoEntitiesAccount* _tmp13_;
					_tmp13_ = account;
					_tmp11_ = dino_entities_account_equals (_tmp13_, value);
				} else {
					_tmp11_ = FALSE;
				}
				if (_tmp11_) {
					gtk_combo_box_set_active ((GtkComboBox*) self, i);
					_g_object_unref0 (account);
					G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL;
					break;
				}
				_tmp14_ = i;
				i = _tmp14_ + 1;
				_g_object_unref0 (account);
				G_IS_VALUE (&val) ? (g_value_unset (&val), NULL) : NULL;
			}
		}
	}
	g_object_notify_by_pspec ((GObject *) self, dino_ui_account_combo_box_properties[DINO_UI_ACCOUNT_COMBO_BOX_SELECTED_PROPERTY]);
}

static void
dino_ui_account_combo_box_class_init (DinoUiAccountComboBoxClass * klass,
                                      gpointer klass_data)
{
	dino_ui_account_combo_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoUiAccountComboBox_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_ui_account_combo_box_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dino_ui_account_combo_box_set_property;
	G_OBJECT_CLASS (klass)->finalize = dino_ui_account_combo_box_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_UI_ACCOUNT_COMBO_BOX_SELECTED_PROPERTY, dino_ui_account_combo_box_properties[DINO_UI_ACCOUNT_COMBO_BOX_SELECTED_PROPERTY] = g_param_spec_object ("selected", "selected", "selected", DINO_ENTITIES_TYPE_ACCOUNT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
dino_ui_account_combo_box_instance_init (DinoUiAccountComboBox * self,
                                         gpointer klass)
{
	GtkListStore* _tmp0_;
	self->priv = dino_ui_account_combo_box_get_instance_private (self);
	_tmp0_ = gtk_list_store_new (2, G_TYPE_STRING, DINO_ENTITIES_TYPE_ACCOUNT, -1);
	self->priv->list_store = _tmp0_;
}

static void
dino_ui_account_combo_box_finalize (GObject * obj)
{
	DinoUiAccountComboBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_UI_TYPE_ACCOUNT_COMBO_BOX, DinoUiAccountComboBox);
	_g_object_unref0 (self->priv->stream_interactor);
	_g_object_unref0 (self->priv->list_store);
	G_OBJECT_CLASS (dino_ui_account_combo_box_parent_class)->finalize (obj);
}

static GType
dino_ui_account_combo_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoUiAccountComboBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_ui_account_combo_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUiAccountComboBox), 0, (GInstanceInitFunc) dino_ui_account_combo_box_instance_init, NULL };
	GType dino_ui_account_combo_box_type_id;
	dino_ui_account_combo_box_type_id = g_type_register_static (gtk_combo_box_get_type (), "DinoUiAccountComboBox", &g_define_type_info, 0);
	DinoUiAccountComboBox_private_offset = g_type_add_instance_private (dino_ui_account_combo_box_type_id, sizeof (DinoUiAccountComboBoxPrivate));
	return dino_ui_account_combo_box_type_id;
}

GType
dino_ui_account_combo_box_get_type (void)
{
	static volatile gsize dino_ui_account_combo_box_type_id__once = 0;
	if (g_once_init_enter (&dino_ui_account_combo_box_type_id__once)) {
		GType dino_ui_account_combo_box_type_id;
		dino_ui_account_combo_box_type_id = dino_ui_account_combo_box_get_type_once ();
		g_once_init_leave (&dino_ui_account_combo_box_type_id__once, dino_ui_account_combo_box_type_id);
	}
	return dino_ui_account_combo_box_type_id__once;
}

static void
_vala_dino_ui_account_combo_box_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	DinoUiAccountComboBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_UI_TYPE_ACCOUNT_COMBO_BOX, DinoUiAccountComboBox);
	switch (property_id) {
		case DINO_UI_ACCOUNT_COMBO_BOX_SELECTED_PROPERTY:
		g_value_set_object (value, dino_ui_account_combo_box_get_selected (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dino_ui_account_combo_box_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	DinoUiAccountComboBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_UI_TYPE_ACCOUNT_COMBO_BOX, DinoUiAccountComboBox);
	switch (property_id) {
		case DINO_UI_ACCOUNT_COMBO_BOX_SELECTED_PROPERTY:
		dino_ui_account_combo_box_set_selected (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

