/* imap-email-flags.c generated by valac 0.56.3, the Vala compiler
 * generated from imap-email-flags.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-engine.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>

enum  {
	GEARY_IMAP_EMAIL_FLAGS_0_PROPERTY,
	GEARY_IMAP_EMAIL_FLAGS_MESSAGE_FLAGS_PROPERTY,
	GEARY_IMAP_EMAIL_FLAGS_NUM_PROPERTIES
};
static GParamSpec* geary_imap_email_flags_properties[GEARY_IMAP_EMAIL_FLAGS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GearyImapEmailFlagsPrivate {
	GearyImapMessageFlags* _message_flags;
};

static gint GearyImapEmailFlags_private_offset;
static gpointer geary_imap_email_flags_parent_class = NULL;

static void geary_imap_email_flags_set_message_flags (GearyImapEmailFlags* self,
                                               GearyImapMessageFlags* value);
static void geary_imap_email_flags_real_notify_added (GearyNamedFlags* base,
                                               GeeCollection* added);
VALA_EXTERN void geary_imap_message_flags_remove (GearyImapMessageFlags* self,
                                      GearyImapMessageFlag* flag);
VALA_EXTERN void geary_imap_message_flags_add (GearyImapMessageFlags* self,
                                   GearyImapMessageFlag* flag);
static void geary_imap_email_flags_real_notify_removed (GearyNamedFlags* base,
                                                 GeeCollection* removed);
static void geary_imap_email_flags_finalize (GObject * obj);
static GType geary_imap_email_flags_get_type_once (void);
static void _vala_geary_imap_email_flags_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_geary_imap_email_flags_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
geary_imap_email_flags_get_instance_private (GearyImapEmailFlags* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapEmailFlags_private_offset);
}

GearyImapMessageFlags*
geary_imap_email_flags_get_message_flags (GearyImapEmailFlags* self)
{
	GearyImapMessageFlags* result;
	GearyImapMessageFlags* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_EMAIL_FLAGS (self), NULL);
	_tmp0_ = self->priv->_message_flags;
	result = _tmp0_;
	return result;
}

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

static void
geary_imap_email_flags_set_message_flags (GearyImapEmailFlags* self,
                                          GearyImapMessageFlags* value)
{
	GearyImapMessageFlags* old_value;
	g_return_if_fail (GEARY_IMAP_IS_EMAIL_FLAGS (self));
	old_value = geary_imap_email_flags_get_message_flags (self);
	if (old_value != value) {
		GearyImapMessageFlags* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_message_flags);
		self->priv->_message_flags = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_email_flags_properties[GEARY_IMAP_EMAIL_FLAGS_MESSAGE_FLAGS_PROPERTY]);
	}
}

GearyImapEmailFlags*
geary_imap_email_flags_construct (GType object_type,
                                  GearyImapMessageFlags* flags)
{
	GearyImapEmailFlags * self = NULL;
	GearyImapMessageFlag* _tmp0_;
	GearyImapMessageFlag* _tmp1_;
	GearyImapMessageFlag* _tmp5_;
	GearyImapMessageFlag* _tmp6_;
	GearyImapMessageFlag* _tmp10_;
	GearyImapMessageFlag* _tmp11_;
	GearyImapMessageFlag* _tmp15_;
	GearyImapMessageFlag* _tmp16_;
	GearyImapMessageFlag* _tmp20_;
	GearyImapMessageFlag* _tmp21_;
	g_return_val_if_fail (GEARY_IMAP_IS_MESSAGE_FLAGS (flags), NULL);
	self = (GearyImapEmailFlags*) geary_email_flags_construct (object_type);
	geary_imap_email_flags_set_message_flags (self, flags);
	_tmp0_ = geary_imap_message_flag_get_SEEN ();
	_tmp1_ = _tmp0_;
	if (!geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (flags, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))) {
		GearyNamedFlag* _tmp2_;
		GearyNamedFlag* _tmp3_;
		GearyNamedFlag* _tmp4_;
		_tmp2_ = geary_email_flags_get_UNREAD ();
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp4_);
		_g_object_unref0 (_tmp4_);
	}
	_tmp5_ = geary_imap_message_flag_get_FLAGGED ();
	_tmp6_ = _tmp5_;
	if (geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (flags, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))) {
		GearyNamedFlag* _tmp7_;
		GearyNamedFlag* _tmp8_;
		GearyNamedFlag* _tmp9_;
		_tmp7_ = geary_email_flags_get_FLAGGED ();
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_;
		geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp9_);
		_g_object_unref0 (_tmp9_);
	}
	_tmp10_ = geary_imap_message_flag_get_LOAD_REMOTE_IMAGES ();
	_tmp11_ = _tmp10_;
	if (geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (flags, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))) {
		GearyNamedFlag* _tmp12_;
		GearyNamedFlag* _tmp13_;
		GearyNamedFlag* _tmp14_;
		_tmp12_ = geary_email_flags_get_LOAD_REMOTE_IMAGES ();
		_tmp13_ = _tmp12_;
		_tmp14_ = _tmp13_;
		geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp14_);
		_g_object_unref0 (_tmp14_);
	}
	_tmp15_ = geary_imap_message_flag_get_DRAFT ();
	_tmp16_ = _tmp15_;
	if (geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (flags, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))) {
		GearyNamedFlag* _tmp17_;
		GearyNamedFlag* _tmp18_;
		GearyNamedFlag* _tmp19_;
		_tmp17_ = geary_email_flags_get_DRAFT ();
		_tmp18_ = _tmp17_;
		_tmp19_ = _tmp18_;
		geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp19_);
		_g_object_unref0 (_tmp19_);
	}
	_tmp20_ = geary_imap_message_flag_get_DELETED ();
	_tmp21_ = _tmp20_;
	if (geary_imap_flags_contains (G_TYPE_CHECK_INSTANCE_CAST (flags, GEARY_IMAP_TYPE_FLAGS, GearyImapFlags), G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag))) {
		GearyNamedFlag* _tmp22_;
		GearyNamedFlag* _tmp23_;
		GearyNamedFlag* _tmp24_;
		_tmp22_ = geary_email_flags_get_DELETED ();
		_tmp23_ = _tmp22_;
		_tmp24_ = _tmp23_;
		geary_named_flags_add (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), _tmp24_);
		_g_object_unref0 (_tmp24_);
	}
	return self;
}

GearyImapEmailFlags*
geary_imap_email_flags_new (GearyImapMessageFlags* flags)
{
	return geary_imap_email_flags_construct (GEARY_IMAP_TYPE_EMAIL_FLAGS, flags);
}

/**
     * Converts a generic {@link Geary.EmailFlags} to IMAP's internal representation of them.
     *
     * If the Geary.EmailFlags cannot be cast to IMAP's version, they're created.
     */
GearyImapEmailFlags*
geary_imap_email_flags_from_api_email_flags (GearyEmailFlags* api_flags)
{
	GearyImapEmailFlags* imap_flags = NULL;
	GearyImapEmailFlags* _tmp0_;
	GearyImapEmailFlags* _tmp1_;
	GeeList* msg_flags_add = NULL;
	GeeList* msg_flags_remove = NULL;
	GeeList* _tmp2_ = NULL;
	GeeList* _tmp3_ = NULL;
	GeeArrayList* msg_flags = NULL;
	GeeArrayList* _tmp4_;
	GeeArrayList* _tmp28_;
	GearyImapMessageFlags* _tmp29_;
	GearyImapMessageFlags* _tmp30_;
	GearyImapEmailFlags* _tmp31_;
	GearyImapEmailFlags* _tmp32_;
	GearyImapEmailFlags* result;
	g_return_val_if_fail (GEARY_IS_EMAIL_FLAGS (api_flags), NULL);
	_tmp0_ = _g_object_ref0 (GEARY_IMAP_IS_EMAIL_FLAGS (api_flags) ? ((GearyImapEmailFlags*) api_flags) : NULL);
	imap_flags = _tmp0_;
	_tmp1_ = imap_flags;
	if (_tmp1_ != NULL) {
		result = imap_flags;
		return result;
	}
	geary_imap_message_flag_from_email_flags (api_flags, NULL, &_tmp2_, &_tmp3_);
	_g_object_unref0 (msg_flags_add);
	msg_flags_add = _tmp2_;
	_g_object_unref0 (msg_flags_remove);
	msg_flags_remove = _tmp3_;
	_tmp4_ = gee_array_list_new (GEARY_IMAP_TYPE_MESSAGE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	msg_flags = _tmp4_;
	{
		GeeList* _mf_list = NULL;
		GeeList* _tmp5_;
		gint _mf_size = 0;
		GeeList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		gint _mf_index = 0;
		_tmp5_ = msg_flags_add;
		_mf_list = _tmp5_;
		_tmp6_ = _mf_list;
		_tmp7_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp8_ = _tmp7_;
		_mf_size = _tmp8_;
		_mf_index = -1;
		while (TRUE) {
			gint _tmp9_;
			gint _tmp10_;
			GearyImapMessageFlag* mf = NULL;
			GeeList* _tmp11_;
			gpointer _tmp12_;
			GeeArrayList* _tmp13_;
			GearyImapMessageFlag* _tmp14_;
			_mf_index = _mf_index + 1;
			_tmp9_ = _mf_index;
			_tmp10_ = _mf_size;
			if (!(_tmp9_ < _tmp10_)) {
				break;
			}
			_tmp11_ = _mf_list;
			_tmp12_ = gee_list_get (_tmp11_, _mf_index);
			mf = (GearyImapMessageFlag*) _tmp12_;
			_tmp13_ = msg_flags;
			_tmp14_ = mf;
			gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp14_);
			_g_object_unref0 (mf);
		}
	}
	if (!geary_email_flags_is_unread (api_flags)) {
		GeeArrayList* _tmp15_;
		GearyImapMessageFlag* _tmp16_;
		GearyImapMessageFlag* _tmp17_;
		_tmp15_ = msg_flags;
		_tmp16_ = geary_imap_message_flag_get_SEEN ();
		_tmp17_ = _tmp16_;
		gee_abstract_collection_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp17_);
	}
	{
		GeeList* _mf_list = NULL;
		GeeList* _tmp18_;
		gint _mf_size = 0;
		GeeList* _tmp19_;
		gint _tmp20_;
		gint _tmp21_;
		gint _mf_index = 0;
		_tmp18_ = msg_flags_remove;
		_mf_list = _tmp18_;
		_tmp19_ = _mf_list;
		_tmp20_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp21_ = _tmp20_;
		_mf_size = _tmp21_;
		_mf_index = -1;
		while (TRUE) {
			gint _tmp22_;
			gint _tmp23_;
			GearyImapMessageFlag* mf = NULL;
			GeeList* _tmp24_;
			gpointer _tmp25_;
			GeeArrayList* _tmp26_;
			GearyImapMessageFlag* _tmp27_;
			_mf_index = _mf_index + 1;
			_tmp22_ = _mf_index;
			_tmp23_ = _mf_size;
			if (!(_tmp22_ < _tmp23_)) {
				break;
			}
			_tmp24_ = _mf_list;
			_tmp25_ = gee_list_get (_tmp24_, _mf_index);
			mf = (GearyImapMessageFlag*) _tmp25_;
			_tmp26_ = msg_flags;
			_tmp27_ = mf;
			gee_abstract_collection_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp26_, GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection), _tmp27_);
			_g_object_unref0 (mf);
		}
	}
	_tmp28_ = msg_flags;
	_tmp29_ = geary_imap_message_flags_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp30_ = _tmp29_;
	_tmp31_ = geary_imap_email_flags_new (_tmp30_);
	_tmp32_ = _tmp31_;
	_g_object_unref0 (_tmp30_);
	result = _tmp32_;
	_g_object_unref0 (msg_flags);
	_g_object_unref0 (msg_flags_remove);
	_g_object_unref0 (msg_flags_add);
	_g_object_unref0 (imap_flags);
	return result;
}

static void
geary_imap_email_flags_real_notify_added (GearyNamedFlags* base,
                                          GeeCollection* added)
{
	GearyImapEmailFlags * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_EMAIL_FLAGS, GearyImapEmailFlags);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (added, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _flag_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (added, GEE_TYPE_ITERABLE, GeeIterable));
		_flag_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyNamedFlag* flag = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyNamedFlag* _tmp4_;
			GearyNamedFlag* _tmp5_;
			GearyNamedFlag* _tmp6_;
			GearyNamedFlag* _tmp7_;
			gboolean _tmp8_;
			GearyNamedFlag* _tmp12_;
			GearyNamedFlag* _tmp13_;
			GearyNamedFlag* _tmp14_;
			GearyNamedFlag* _tmp15_;
			gboolean _tmp16_;
			GearyNamedFlag* _tmp20_;
			GearyNamedFlag* _tmp21_;
			GearyNamedFlag* _tmp22_;
			GearyNamedFlag* _tmp23_;
			gboolean _tmp24_;
			GearyNamedFlag* _tmp28_;
			GearyNamedFlag* _tmp29_;
			GearyNamedFlag* _tmp30_;
			GearyNamedFlag* _tmp31_;
			gboolean _tmp32_;
			GearyNamedFlag* _tmp36_;
			GearyNamedFlag* _tmp37_;
			GearyNamedFlag* _tmp38_;
			GearyNamedFlag* _tmp39_;
			gboolean _tmp40_;
			_tmp1_ = _flag_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _flag_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			flag = (GearyNamedFlag*) _tmp3_;
			_tmp4_ = flag;
			_tmp5_ = geary_email_flags_get_UNREAD ();
			_tmp6_ = _tmp5_;
			_tmp7_ = _tmp6_;
			_tmp8_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_HASHABLE, GeeHashable), _tmp7_);
			_g_object_unref0 (_tmp7_);
			if (_tmp8_) {
				GearyImapMessageFlags* _tmp9_;
				GearyImapMessageFlag* _tmp10_;
				GearyImapMessageFlag* _tmp11_;
				_tmp9_ = self->priv->_message_flags;
				_tmp10_ = geary_imap_message_flag_get_SEEN ();
				_tmp11_ = _tmp10_;
				geary_imap_message_flags_remove (_tmp9_, _tmp11_);
			}
			_tmp12_ = flag;
			_tmp13_ = geary_email_flags_get_FLAGGED ();
			_tmp14_ = _tmp13_;
			_tmp15_ = _tmp14_;
			_tmp16_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_HASHABLE, GeeHashable), _tmp15_);
			_g_object_unref0 (_tmp15_);
			if (_tmp16_) {
				GearyImapMessageFlags* _tmp17_;
				GearyImapMessageFlag* _tmp18_;
				GearyImapMessageFlag* _tmp19_;
				_tmp17_ = self->priv->_message_flags;
				_tmp18_ = geary_imap_message_flag_get_FLAGGED ();
				_tmp19_ = _tmp18_;
				geary_imap_message_flags_add (_tmp17_, _tmp19_);
			}
			_tmp20_ = flag;
			_tmp21_ = geary_email_flags_get_LOAD_REMOTE_IMAGES ();
			_tmp22_ = _tmp21_;
			_tmp23_ = _tmp22_;
			_tmp24_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEE_TYPE_HASHABLE, GeeHashable), _tmp23_);
			_g_object_unref0 (_tmp23_);
			if (_tmp24_) {
				GearyImapMessageFlags* _tmp25_;
				GearyImapMessageFlag* _tmp26_;
				GearyImapMessageFlag* _tmp27_;
				_tmp25_ = self->priv->_message_flags;
				_tmp26_ = geary_imap_message_flag_get_LOAD_REMOTE_IMAGES ();
				_tmp27_ = _tmp26_;
				geary_imap_message_flags_add (_tmp25_, _tmp27_);
			}
			_tmp28_ = flag;
			_tmp29_ = geary_email_flags_get_DRAFT ();
			_tmp30_ = _tmp29_;
			_tmp31_ = _tmp30_;
			_tmp32_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, GEE_TYPE_HASHABLE, GeeHashable), _tmp31_);
			_g_object_unref0 (_tmp31_);
			if (_tmp32_) {
				GearyImapMessageFlags* _tmp33_;
				GearyImapMessageFlag* _tmp34_;
				GearyImapMessageFlag* _tmp35_;
				_tmp33_ = self->priv->_message_flags;
				_tmp34_ = geary_imap_message_flag_get_DRAFT ();
				_tmp35_ = _tmp34_;
				geary_imap_message_flags_add (_tmp33_, _tmp35_);
			}
			_tmp36_ = flag;
			_tmp37_ = geary_email_flags_get_DELETED ();
			_tmp38_ = _tmp37_;
			_tmp39_ = _tmp38_;
			_tmp40_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, GEE_TYPE_HASHABLE, GeeHashable), _tmp39_);
			_g_object_unref0 (_tmp39_);
			if (_tmp40_) {
				GearyImapMessageFlags* _tmp41_;
				GearyImapMessageFlag* _tmp42_;
				GearyImapMessageFlag* _tmp43_;
				_tmp41_ = self->priv->_message_flags;
				_tmp42_ = geary_imap_message_flag_get_DELETED ();
				_tmp43_ = _tmp42_;
				geary_imap_message_flags_add (_tmp41_, _tmp43_);
			}
			_g_object_unref0 (flag);
		}
		_g_object_unref0 (_flag_it);
	}
	GEARY_NAMED_FLAGS_CLASS (geary_imap_email_flags_parent_class)->notify_added (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_EMAIL_FLAGS, GearyEmailFlags), GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), added);
}

static void
geary_imap_email_flags_real_notify_removed (GearyNamedFlags* base,
                                            GeeCollection* removed)
{
	GearyImapEmailFlags * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_EMAIL_FLAGS, GearyImapEmailFlags);
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (removed, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _flag_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (removed, GEE_TYPE_ITERABLE, GeeIterable));
		_flag_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			GearyNamedFlag* flag = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			GearyNamedFlag* _tmp4_;
			GearyNamedFlag* _tmp5_;
			GearyNamedFlag* _tmp6_;
			GearyNamedFlag* _tmp7_;
			gboolean _tmp8_;
			GearyNamedFlag* _tmp12_;
			GearyNamedFlag* _tmp13_;
			GearyNamedFlag* _tmp14_;
			GearyNamedFlag* _tmp15_;
			gboolean _tmp16_;
			GearyNamedFlag* _tmp20_;
			GearyNamedFlag* _tmp21_;
			GearyNamedFlag* _tmp22_;
			GearyNamedFlag* _tmp23_;
			gboolean _tmp24_;
			GearyNamedFlag* _tmp28_;
			GearyNamedFlag* _tmp29_;
			GearyNamedFlag* _tmp30_;
			GearyNamedFlag* _tmp31_;
			gboolean _tmp32_;
			GearyNamedFlag* _tmp36_;
			GearyNamedFlag* _tmp37_;
			GearyNamedFlag* _tmp38_;
			GearyNamedFlag* _tmp39_;
			gboolean _tmp40_;
			_tmp1_ = _flag_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _flag_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			flag = (GearyNamedFlag*) _tmp3_;
			_tmp4_ = flag;
			_tmp5_ = geary_email_flags_get_UNREAD ();
			_tmp6_ = _tmp5_;
			_tmp7_ = _tmp6_;
			_tmp8_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_HASHABLE, GeeHashable), _tmp7_);
			_g_object_unref0 (_tmp7_);
			if (_tmp8_) {
				GearyImapMessageFlags* _tmp9_;
				GearyImapMessageFlag* _tmp10_;
				GearyImapMessageFlag* _tmp11_;
				_tmp9_ = self->priv->_message_flags;
				_tmp10_ = geary_imap_message_flag_get_SEEN ();
				_tmp11_ = _tmp10_;
				geary_imap_message_flags_add (_tmp9_, _tmp11_);
			}
			_tmp12_ = flag;
			_tmp13_ = geary_email_flags_get_FLAGGED ();
			_tmp14_ = _tmp13_;
			_tmp15_ = _tmp14_;
			_tmp16_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, GEE_TYPE_HASHABLE, GeeHashable), _tmp15_);
			_g_object_unref0 (_tmp15_);
			if (_tmp16_) {
				GearyImapMessageFlags* _tmp17_;
				GearyImapMessageFlag* _tmp18_;
				GearyImapMessageFlag* _tmp19_;
				_tmp17_ = self->priv->_message_flags;
				_tmp18_ = geary_imap_message_flag_get_FLAGGED ();
				_tmp19_ = _tmp18_;
				geary_imap_message_flags_remove (_tmp17_, _tmp19_);
			}
			_tmp20_ = flag;
			_tmp21_ = geary_email_flags_get_LOAD_REMOTE_IMAGES ();
			_tmp22_ = _tmp21_;
			_tmp23_ = _tmp22_;
			_tmp24_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEE_TYPE_HASHABLE, GeeHashable), _tmp23_);
			_g_object_unref0 (_tmp23_);
			if (_tmp24_) {
				GearyImapMessageFlags* _tmp25_;
				GearyImapMessageFlag* _tmp26_;
				GearyImapMessageFlag* _tmp27_;
				_tmp25_ = self->priv->_message_flags;
				_tmp26_ = geary_imap_message_flag_get_LOAD_REMOTE_IMAGES ();
				_tmp27_ = _tmp26_;
				geary_imap_message_flags_remove (_tmp25_, _tmp27_);
			}
			_tmp28_ = flag;
			_tmp29_ = geary_email_flags_get_DRAFT ();
			_tmp30_ = _tmp29_;
			_tmp31_ = _tmp30_;
			_tmp32_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, GEE_TYPE_HASHABLE, GeeHashable), _tmp31_);
			_g_object_unref0 (_tmp31_);
			if (_tmp32_) {
				GearyImapMessageFlags* _tmp33_;
				GearyImapMessageFlag* _tmp34_;
				GearyImapMessageFlag* _tmp35_;
				_tmp33_ = self->priv->_message_flags;
				_tmp34_ = geary_imap_message_flag_get_DRAFT ();
				_tmp35_ = _tmp34_;
				geary_imap_message_flags_remove (_tmp33_, _tmp35_);
			}
			_tmp36_ = flag;
			_tmp37_ = geary_email_flags_get_DELETED ();
			_tmp38_ = _tmp37_;
			_tmp39_ = _tmp38_;
			_tmp40_ = gee_hashable_equal_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, GEE_TYPE_HASHABLE, GeeHashable), _tmp39_);
			_g_object_unref0 (_tmp39_);
			if (_tmp40_) {
				GearyImapMessageFlags* _tmp41_;
				GearyImapMessageFlag* _tmp42_;
				GearyImapMessageFlag* _tmp43_;
				_tmp41_ = self->priv->_message_flags;
				_tmp42_ = geary_imap_message_flag_get_DELETED ();
				_tmp43_ = _tmp42_;
				geary_imap_message_flags_remove (_tmp41_, _tmp43_);
			}
			_g_object_unref0 (flag);
		}
		_g_object_unref0 (_flag_it);
	}
	GEARY_NAMED_FLAGS_CLASS (geary_imap_email_flags_parent_class)->notify_removed (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_EMAIL_FLAGS, GearyEmailFlags), GEARY_TYPE_NAMED_FLAGS, GearyNamedFlags), removed);
}

static void
geary_imap_email_flags_class_init (GearyImapEmailFlagsClass * klass,
                                   gpointer klass_data)
{
	geary_imap_email_flags_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapEmailFlags_private_offset);
	((GearyNamedFlagsClass *) klass)->notify_added = (void (*) (GearyNamedFlags*, GeeCollection*)) geary_imap_email_flags_real_notify_added;
	((GearyNamedFlagsClass *) klass)->notify_removed = (void (*) (GearyNamedFlags*, GeeCollection*)) geary_imap_email_flags_real_notify_removed;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_email_flags_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_email_flags_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_email_flags_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_EMAIL_FLAGS_MESSAGE_FLAGS_PROPERTY, geary_imap_email_flags_properties[GEARY_IMAP_EMAIL_FLAGS_MESSAGE_FLAGS_PROPERTY] = g_param_spec_object ("message-flags", "message-flags", "message-flags", GEARY_IMAP_TYPE_MESSAGE_FLAGS, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_imap_email_flags_instance_init (GearyImapEmailFlags * self,
                                      gpointer klass)
{
	self->priv = geary_imap_email_flags_get_instance_private (self);
}

static void
geary_imap_email_flags_finalize (GObject * obj)
{
	GearyImapEmailFlags * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_TYPE_EMAIL_FLAGS, GearyImapEmailFlags);
	_g_object_unref0 (self->priv->_message_flags);
	G_OBJECT_CLASS (geary_imap_email_flags_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_imap_email_flags_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapEmailFlagsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_email_flags_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapEmailFlags), 0, (GInstanceInitFunc) geary_imap_email_flags_instance_init, NULL };
	GType geary_imap_email_flags_type_id;
	geary_imap_email_flags_type_id = g_type_register_static (GEARY_TYPE_EMAIL_FLAGS, "GearyImapEmailFlags", &g_define_type_info, 0);
	GearyImapEmailFlags_private_offset = g_type_add_instance_private (geary_imap_email_flags_type_id, sizeof (GearyImapEmailFlagsPrivate));
	return geary_imap_email_flags_type_id;
}

GType
geary_imap_email_flags_get_type (void)
{
	static gsize geary_imap_email_flags_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_email_flags_type_id__once)) {
		GType geary_imap_email_flags_type_id;
		geary_imap_email_flags_type_id = geary_imap_email_flags_get_type_once ();
		g_once_init_leave (&geary_imap_email_flags_type_id__once, geary_imap_email_flags_type_id);
	}
	return geary_imap_email_flags_type_id__once;
}

static void
_vala_geary_imap_email_flags_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	GearyImapEmailFlags * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_EMAIL_FLAGS, GearyImapEmailFlags);
	switch (property_id) {
		case GEARY_IMAP_EMAIL_FLAGS_MESSAGE_FLAGS_PROPERTY:
		g_value_set_object (value, geary_imap_email_flags_get_message_flags (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_email_flags_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	GearyImapEmailFlags * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_EMAIL_FLAGS, GearyImapEmailFlags);
	switch (property_id) {
		case GEARY_IMAP_EMAIL_FLAGS_MESSAGE_FLAGS_PROPERTY:
		geary_imap_email_flags_set_message_flags (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

