/* contacts-type-combo.c generated by valac 0.56.0, the Vala compiler
 * generated from contacts-type-combo.vala, do not modify */

/*
 * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <adwaita.h>
#include <glib-object.h>
#include "contacts.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <folks/folks.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>

#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 CONTACTS_TYPE_TYPECOMBO_ROW (contacts_typecombo_row_get_type ())
#define CONTACTS_TYPECOMBO_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_TYPECOMBO_ROW, ContactsTypeComboRow))
#define CONTACTS_TYPECOMBO_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_TYPECOMBO_ROW, ContactsTypeComboRowClass))
#define CONTACTS_IS_TYPECOMBO_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_TYPECOMBO_ROW))
#define CONTACTS_IS_TYPECOMBO_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_TYPECOMBO_ROW))
#define CONTACTS_TYPECOMBO_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_TYPECOMBO_ROW, ContactsTypeComboRowClass))

typedef struct _ContactsTypeComboRow ContactsTypeComboRow;
typedef struct _ContactsTypeComboRowClass ContactsTypeComboRowClass;
typedef struct _ContactsTypeComboRowPrivate ContactsTypeComboRowPrivate;
enum  {
	CONTACTS_TYPECOMBO_ROW_0_PROPERTY,
	CONTACTS_TYPECOMBO_ROW_SELECTED_DESCRIPTOR_PROPERTY,
	CONTACTS_TYPECOMBO_ROW_TYPE_SET_PROPERTY,
	CONTACTS_TYPECOMBO_ROW_NUM_PROPERTIES
};
static GParamSpec* contacts_typecombo_row_properties[CONTACTS_TYPECOMBO_ROW_NUM_PROPERTIES];
#define _gtk_expression_unref0(var) ((var == NULL) ? NULL : (var = (gtk_expression_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _ContactsTypeComboRow {
	AdwComboRow parent_instance;
	ContactsTypeComboRowPrivate * priv;
};

struct _ContactsTypeComboRowClass {
	AdwComboRowClass parent_class;
};

static gpointer contacts_typecombo_row_parent_class = NULL;

VALA_EXTERN GType contacts_typecombo_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ContactsTypeComboRow, g_object_unref)
VALA_EXTERN ContactsTypeComboRow* contacts_typecombo_row_new (ContactsTypeSet* type_set);
VALA_EXTERN ContactsTypeComboRow* contacts_typecombo_row_construct (GType object_type,
                                                        ContactsTypeSet* type_set);
VALA_EXTERN void contacts_typecombo_row_set_selected_from_field_details (ContactsTypeComboRow* self,
                                                             FolksAbstractFieldDetails* details);
VALA_EXTERN ContactsTypeSet* contacts_typecombo_row_get_type_set (ContactsTypeComboRow* self);
VALA_EXTERN void contacts_typecombo_row_set_selected_from_vcard_type (ContactsTypeComboRow* self,
                                                          const gchar* type);
VALA_EXTERN ContactsTypeDescriptor* contacts_typecombo_row_get_selected_descriptor (ContactsTypeComboRow* self);
static GType contacts_typecombo_row_get_type_once (void);
static void _vala_contacts_typecombo_row_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);

/**
   * Creates a TypeComboRow for the given TypeSet.
   */
ContactsTypeComboRow*
contacts_typecombo_row_construct (GType object_type,
                                  ContactsTypeSet* type_set)
{
	ContactsTypeComboRow * self = NULL;
	GtkPropertyExpression* _tmp0_;
	GtkPropertyExpression* _tmp1_;
	g_return_val_if_fail (type_set != NULL, NULL);
	_tmp0_ = (GtkPropertyExpression*) gtk_property_expression_new (CONTACTS_TYPE_TYPEDESCRIPTOR, NULL, "display-name");
	_tmp1_ = _tmp0_;
	self = (ContactsTypeComboRow*) g_object_new (object_type, "model", type_set, "expression", _tmp1_, NULL);
	_gtk_expression_unref0 (_tmp1_);
	return self;
}

ContactsTypeComboRow*
contacts_typecombo_row_new (ContactsTypeSet* type_set)
{
	return contacts_typecombo_row_construct (CONTACTS_TYPE_TYPECOMBO_ROW, type_set);
}

/**
   * Sets the value to the type of the given {@link Folks.AbstractFieldDetails}.
   */
void
contacts_typecombo_row_set_selected_from_field_details (ContactsTypeComboRow* self,
                                                        FolksAbstractFieldDetails* details)
{
	guint position = 0U;
	ContactsTypeSet* _tmp0_;
	ContactsTypeSet* _tmp1_;
	guint _tmp2_ = 0U;
	ContactsTypeDescriptor* _tmp3_;
	ContactsTypeDescriptor* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (details != NULL);
	position = (guint) 0;
	_tmp0_ = contacts_typecombo_row_get_type_set (self);
	_tmp1_ = _tmp0_;
	_tmp3_ = contacts_typeset_lookup_by_field_details (_tmp1_, details, &_tmp2_);
	position = _tmp2_;
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp4_);
	adw_combo_row_set_selected ((AdwComboRow*) self, position);
}

/**
   * Sets the value to the type that best matches the given vcard type
   * (for example "HOME" or "WORK").
   */
void
contacts_typecombo_row_set_selected_from_vcard_type (ContactsTypeComboRow* self,
                                                     const gchar* type)
{
	guint position = 0U;
	ContactsTypeSet* _tmp0_;
	ContactsTypeSet* _tmp1_;
	guint _tmp2_ = 0U;
	g_return_if_fail (self != NULL);
	g_return_if_fail (type != NULL);
	position = (guint) 0;
	_tmp0_ = contacts_typecombo_row_get_type_set (self);
	_tmp1_ = _tmp0_;
	contacts_typeset_lookup_by_vcard_type (_tmp1_, type, &_tmp2_);
	position = _tmp2_;
	adw_combo_row_set_selected ((AdwComboRow*) self, position);
}

ContactsTypeDescriptor*
contacts_typecombo_row_get_selected_descriptor (ContactsTypeComboRow* self)
{
	ContactsTypeDescriptor* result;
	GObject* _tmp0_;
	GObject* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = adw_combo_row_get_selected_item ((AdwComboRow*) self);
	_tmp1_ = _tmp0_;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, CONTACTS_TYPE_TYPEDESCRIPTOR, ContactsTypeDescriptor);
	return result;
}

ContactsTypeSet*
contacts_typecombo_row_get_type_set (ContactsTypeComboRow* self)
{
	ContactsTypeSet* result;
	GListModel* _tmp0_;
	GListModel* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = adw_combo_row_get_model ((AdwComboRow*) self);
	_tmp1_ = _tmp0_;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, CONTACTS_TYPE_TYPESET, ContactsTypeSet);
	return result;
}

static void
contacts_typecombo_row_class_init (ContactsTypeComboRowClass * klass,
                                   gpointer klass_data)
{
	contacts_typecombo_row_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_typecombo_row_get_property;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_TYPECOMBO_ROW_SELECTED_DESCRIPTOR_PROPERTY, contacts_typecombo_row_properties[CONTACTS_TYPECOMBO_ROW_SELECTED_DESCRIPTOR_PROPERTY] = g_param_spec_object ("selected-descriptor", "selected-descriptor", "selected-descriptor", CONTACTS_TYPE_TYPEDESCRIPTOR, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_TYPECOMBO_ROW_TYPE_SET_PROPERTY, contacts_typecombo_row_properties[CONTACTS_TYPECOMBO_ROW_TYPE_SET_PROPERTY] = g_param_spec_object ("type-set", "type-set", "type-set", CONTACTS_TYPE_TYPESET, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
contacts_typecombo_row_instance_init (ContactsTypeComboRow * self,
                                      gpointer klass)
{
}

/**
 * The TypeComboRow is a widget that fills itself with the types of a certain
 * category (using {@link Contacts.TypeSet}). For example, it allows the user
 * to choose between "Personal", "Home" and "Work" for email addresses,
 * together with all the custom labels it has encountered since then.
 */
 G_GNUC_NO_INLINE static GType
contacts_typecombo_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsTypeComboRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_typecombo_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsTypeComboRow), 0, (GInstanceInitFunc) contacts_typecombo_row_instance_init, NULL };
	GType contacts_typecombo_row_type_id;
	contacts_typecombo_row_type_id = g_type_register_static (adw_combo_row_get_type (), "ContactsTypeComboRow", &g_define_type_info, 0);
	return contacts_typecombo_row_type_id;
}

GType
contacts_typecombo_row_get_type (void)
{
	static volatile gsize contacts_typecombo_row_type_id__once = 0;
	if (g_once_init_enter (&contacts_typecombo_row_type_id__once)) {
		GType contacts_typecombo_row_type_id;
		contacts_typecombo_row_type_id = contacts_typecombo_row_get_type_once ();
		g_once_init_leave (&contacts_typecombo_row_type_id__once, contacts_typecombo_row_type_id);
	}
	return contacts_typecombo_row_type_id__once;
}

static void
_vala_contacts_typecombo_row_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	ContactsTypeComboRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_TYPECOMBO_ROW, ContactsTypeComboRow);
	switch (property_id) {
		case CONTACTS_TYPECOMBO_ROW_SELECTED_DESCRIPTOR_PROPERTY:
		g_value_set_object (value, contacts_typecombo_row_get_selected_descriptor (self));
		break;
		case CONTACTS_TYPECOMBO_ROW_TYPE_SET_PROPERTY:
		g_value_set_object (value, contacts_typecombo_row_get_type_set (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

