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

/*
 * Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2018 Michael Gratton <mike@vee.net>.
 *
 * 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 <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#define GEARY_IMAP_TYPE_FOLDER (geary_imap_folder_get_type ())
#define GEARY_IMAP_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_IMAP_TYPE_FOLDER, GearyImapFolder))
#define GEARY_IMAP_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_IMAP_TYPE_FOLDER, GearyImapFolderClass))
#define GEARY_IMAP_IS_FOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_IMAP_TYPE_FOLDER))
#define GEARY_IMAP_IS_FOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_IMAP_TYPE_FOLDER))
#define GEARY_IMAP_FOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_IMAP_TYPE_FOLDER, GearyImapFolderClass))

typedef struct _GearyImapFolder GearyImapFolder;
typedef struct _GearyImapFolderClass GearyImapFolderClass;
typedef struct _GearyImapFolderPrivate GearyImapFolderPrivate;
enum  {
	GEARY_IMAP_FOLDER_0_PROPERTY,
	GEARY_IMAP_FOLDER_PATH_PROPERTY,
	GEARY_IMAP_FOLDER_PROPERTIES_PROPERTY,
	GEARY_IMAP_FOLDER_NUM_PROPERTIES
};
static GParamSpec* geary_imap_folder_properties[GEARY_IMAP_FOLDER_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))

struct _GearyImapFolder {
	GearyBaseObject parent_instance;
	GearyImapFolderPrivate * priv;
};

struct _GearyImapFolderClass {
	GearyBaseObjectClass parent_class;
};

struct _GearyImapFolderPrivate {
	GearyFolderPath* _path;
	GearyImapFolderProperties* _properties;
};

static gint GearyImapFolder_private_offset;
static gpointer geary_imap_folder_parent_class = NULL;

VALA_EXTERN GType geary_imap_folder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyFolderPath* geary_imap_folder_get_path (GearyImapFolder* self);
static void geary_imap_folder_set_path (GearyImapFolder* self,
                                 GearyFolderPath* value);
VALA_EXTERN GearyImapFolderProperties* geary_imap_folder_get_properties (GearyImapFolder* self);
static void geary_imap_folder_set_properties (GearyImapFolder* self,
                                       GearyImapFolderProperties* value);
VALA_EXTERN GearyImapFolder* geary_imap_folder_new (GearyFolderPath* path,
                                        GearyImapFolderProperties* properties);
VALA_EXTERN GearyImapFolder* geary_imap_folder_construct (GType object_type,
                                              GearyFolderPath* path,
                                              GearyImapFolderProperties* properties);
VALA_EXTERN gchar* geary_imap_folder_to_string (GearyImapFolder* self);
static void geary_imap_folder_finalize (GObject * obj);
static GType geary_imap_folder_get_type_once (void);
static void _vala_geary_imap_folder_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_geary_imap_folder_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
geary_imap_folder_get_instance_private (GearyImapFolder* self)
{
	return G_STRUCT_MEMBER_P (self, GearyImapFolder_private_offset);
}

GearyFolderPath*
geary_imap_folder_get_path (GearyImapFolder* self)
{
	GearyFolderPath* result;
	GearyFolderPath* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->_path;
	result = _tmp0_;
	return result;
}

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

static void
geary_imap_folder_set_path (GearyImapFolder* self,
                            GearyFolderPath* value)
{
	GearyFolderPath* old_value;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER (self));
	old_value = geary_imap_folder_get_path (self);
	if (old_value != value) {
		GearyFolderPath* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_path);
		self->priv->_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_folder_properties[GEARY_IMAP_FOLDER_PATH_PROPERTY]);
	}
}

GearyImapFolderProperties*
geary_imap_folder_get_properties (GearyImapFolder* self)
{
	GearyImapFolderProperties* result;
	GearyImapFolderProperties* _tmp0_;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->_properties;
	result = _tmp0_;
	return result;
}

static void
geary_imap_folder_set_properties (GearyImapFolder* self,
                                  GearyImapFolderProperties* value)
{
	GearyImapFolderProperties* old_value;
	g_return_if_fail (GEARY_IMAP_IS_FOLDER (self));
	old_value = geary_imap_folder_get_properties (self);
	if (old_value != value) {
		GearyImapFolderProperties* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_properties);
		self->priv->_properties = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_imap_folder_properties[GEARY_IMAP_FOLDER_PROPERTIES_PROPERTY]);
	}
}

GearyImapFolder*
geary_imap_folder_construct (GType object_type,
                             GearyFolderPath* path,
                             GearyImapFolderProperties* properties)
{
	GearyImapFolder * self = NULL;
	g_return_val_if_fail (GEARY_IS_FOLDER_PATH (path), NULL);
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER_PROPERTIES (properties), NULL);
	self = (GearyImapFolder*) geary_base_object_construct (object_type);
	geary_imap_folder_set_path (self, path);
	geary_imap_folder_set_properties (self, properties);
	return self;
}

GearyImapFolder*
geary_imap_folder_new (GearyFolderPath* path,
                       GearyImapFolderProperties* properties)
{
	return geary_imap_folder_construct (GEARY_IMAP_TYPE_FOLDER, path, properties);
}

gchar*
geary_imap_folder_to_string (GearyImapFolder* self)
{
	GearyFolderPath* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (GEARY_IMAP_IS_FOLDER (self), NULL);
	_tmp0_ = self->priv->_path;
	_tmp1_ = geary_folder_path_to_string (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf ("Imap.Folder(%s)", _tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	result = _tmp4_;
	return result;
}

static void
geary_imap_folder_class_init (GearyImapFolderClass * klass,
                              gpointer klass_data)
{
	geary_imap_folder_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyImapFolder_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_imap_folder_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_imap_folder_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_imap_folder_finalize;
	/** The full path to this folder. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_FOLDER_PATH_PROPERTY, geary_imap_folder_properties[GEARY_IMAP_FOLDER_PATH_PROPERTY] = g_param_spec_object ("path", "path", "path", GEARY_TYPE_FOLDER_PATH, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** IMAP properties reported by the server. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_IMAP_FOLDER_PROPERTIES_PROPERTY, geary_imap_folder_properties[GEARY_IMAP_FOLDER_PROPERTIES_PROPERTY] = g_param_spec_object ("properties", "properties", "properties", GEARY_IMAP_TYPE_FOLDER_PROPERTIES, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_imap_folder_instance_init (GearyImapFolder * self,
                                 gpointer klass)
{
	self->priv = geary_imap_folder_get_instance_private (self);
}

static void
geary_imap_folder_finalize (GObject * obj)
{
	GearyImapFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_IMAP_TYPE_FOLDER, GearyImapFolder);
	_g_object_unref0 (self->priv->_path);
	_g_object_unref0 (self->priv->_properties);
	G_OBJECT_CLASS (geary_imap_folder_parent_class)->finalize (obj);
}

/**
 * Represents a mailbox on an IMAP server.
 *
 * Everything we can glean from an IMAP LIST for a specific folder is
 * encapsulated here. Any information requires the folder to be
 * selected, and hence there is no other information about
 * non-selectable folders that can be obtained.
 *
 * Note the mailbox name is not represented since that may differ
 * based on the client session being used to connect to the server.
 */
 G_GNUC_NO_INLINE static GType
geary_imap_folder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapFolderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_folder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapFolder), 0, (GInstanceInitFunc) geary_imap_folder_instance_init, NULL };
	GType geary_imap_folder_type_id;
	geary_imap_folder_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyImapFolder", &g_define_type_info, 0);
	GearyImapFolder_private_offset = g_type_add_instance_private (geary_imap_folder_type_id, sizeof (GearyImapFolderPrivate));
	return geary_imap_folder_type_id;
}

GType
geary_imap_folder_get_type (void)
{
	static gsize geary_imap_folder_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_folder_type_id__once)) {
		GType geary_imap_folder_type_id;
		geary_imap_folder_type_id = geary_imap_folder_get_type_once ();
		g_once_init_leave (&geary_imap_folder_type_id__once, geary_imap_folder_type_id);
	}
	return geary_imap_folder_type_id__once;
}

static void
_vala_geary_imap_folder_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	GearyImapFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_FOLDER, GearyImapFolder);
	switch (property_id) {
		case GEARY_IMAP_FOLDER_PATH_PROPERTY:
		g_value_set_object (value, geary_imap_folder_get_path (self));
		break;
		case GEARY_IMAP_FOLDER_PROPERTIES_PROPERTY:
		g_value_set_object (value, geary_imap_folder_get_properties (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_imap_folder_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	GearyImapFolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_IMAP_TYPE_FOLDER, GearyImapFolder);
	switch (property_id) {
		case GEARY_IMAP_FOLDER_PATH_PROPERTY:
		geary_imap_folder_set_path (self, g_value_get_object (value));
		break;
		case GEARY_IMAP_FOLDER_PROPERTIES_PROPERTY:
		geary_imap_folder_set_properties (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

