/* url-details.c generated by valac 0.17.2.19-5f50d, the Vala compiler
 * generated from url-details.vala, do not modify */

/*
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2011 Philip Withnall
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Marco Barisione <marco.barisione@collabora.co.uk>
 *       Travis Reitter <travis.reitter@collabora.co.uk>
 *       Philip Withnall <philip@tecnocode.co.uk>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>


#define FOLKS_TYPE_ABSTRACT_FIELD_DETAILS (folks_abstract_field_details_get_type ())
#define FOLKS_ABSTRACT_FIELD_DETAILS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, FolksAbstractFieldDetails))
#define FOLKS_ABSTRACT_FIELD_DETAILS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, FolksAbstractFieldDetailsClass))
#define FOLKS_IS_ABSTRACT_FIELD_DETAILS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_ABSTRACT_FIELD_DETAILS))
#define FOLKS_IS_ABSTRACT_FIELD_DETAILS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_TYPE_ABSTRACT_FIELD_DETAILS))
#define FOLKS_ABSTRACT_FIELD_DETAILS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, FolksAbstractFieldDetailsClass))

typedef struct _FolksAbstractFieldDetails FolksAbstractFieldDetails;
typedef struct _FolksAbstractFieldDetailsClass FolksAbstractFieldDetailsClass;
typedef struct _FolksAbstractFieldDetailsPrivate FolksAbstractFieldDetailsPrivate;

#define FOLKS_TYPE_URL_FIELD_DETAILS (folks_url_field_details_get_type ())
#define FOLKS_URL_FIELD_DETAILS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_URL_FIELD_DETAILS, FolksUrlFieldDetails))
#define FOLKS_URL_FIELD_DETAILS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_TYPE_URL_FIELD_DETAILS, FolksUrlFieldDetailsClass))
#define FOLKS_IS_URL_FIELD_DETAILS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_URL_FIELD_DETAILS))
#define FOLKS_IS_URL_FIELD_DETAILS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_TYPE_URL_FIELD_DETAILS))
#define FOLKS_URL_FIELD_DETAILS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_TYPE_URL_FIELD_DETAILS, FolksUrlFieldDetailsClass))

typedef struct _FolksUrlFieldDetails FolksUrlFieldDetails;
typedef struct _FolksUrlFieldDetailsClass FolksUrlFieldDetailsClass;
typedef struct _FolksUrlFieldDetailsPrivate FolksUrlFieldDetailsPrivate;

#define FOLKS_TYPE_URL_DETAILS (folks_url_details_get_type ())
#define FOLKS_URL_DETAILS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_URL_DETAILS, FolksUrlDetails))
#define FOLKS_IS_URL_DETAILS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_URL_DETAILS))
#define FOLKS_URL_DETAILS_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), FOLKS_TYPE_URL_DETAILS, FolksUrlDetailsIface))

typedef struct _FolksUrlDetails FolksUrlDetails;
typedef struct _FolksUrlDetailsIface FolksUrlDetailsIface;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _FolksUrlDetailsChangeUrlsData FolksUrlDetailsChangeUrlsData;

struct _FolksAbstractFieldDetails {
	GObject parent_instance;
	FolksAbstractFieldDetailsPrivate * priv;
};

struct _FolksAbstractFieldDetailsClass {
	GObjectClass parent_class;
	gboolean (*equal) (FolksAbstractFieldDetails* self, FolksAbstractFieldDetails* that);
	gboolean (*parameters_equal) (FolksAbstractFieldDetails* self, FolksAbstractFieldDetails* that);
	gboolean (*values_equal) (FolksAbstractFieldDetails* self, FolksAbstractFieldDetails* that);
	guint (*hash) (FolksAbstractFieldDetails* self);
	gconstpointer (*get_value) (FolksAbstractFieldDetails* self);
	void (*set_value) (FolksAbstractFieldDetails* self, gconstpointer value);
	const gchar* (*get_id) (FolksAbstractFieldDetails* self);
	void (*set_id) (FolksAbstractFieldDetails* self, const gchar* value);
	GeeMultiMap* (*get_parameters) (FolksAbstractFieldDetails* self);
	void (*set_parameters) (FolksAbstractFieldDetails* self, GeeMultiMap* value);
};

struct _FolksUrlFieldDetails {
	FolksAbstractFieldDetails parent_instance;
	FolksUrlFieldDetailsPrivate * priv;
};

struct _FolksUrlFieldDetailsClass {
	FolksAbstractFieldDetailsClass parent_class;
};

typedef enum  {
	FOLKS_PROPERTY_ERROR_NOT_WRITEABLE,
	FOLKS_PROPERTY_ERROR_INVALID_VALUE,
	FOLKS_PROPERTY_ERROR_UNKNOWN_ERROR
} FolksPropertyError;
#define FOLKS_PROPERTY_ERROR folks_property_error_quark ()
struct _FolksUrlDetailsIface {
	GTypeInterface parent_iface;
	void (*change_urls) (FolksUrlDetails* self, GeeSet* urls, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*change_urls_finish) (FolksUrlDetails* self, GAsyncResult* _res_, GError** error);
	GeeSet* (*get_urls) (FolksUrlDetails* self);
	void (*set_urls) (FolksUrlDetails* self, GeeSet* value);
};

struct _FolksUrlDetailsChangeUrlsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	FolksUrlDetails* self;
	GeeSet* urls;
	const gchar* _tmp0_;
	GError* _tmp1_;
	GError * _inner_error_;
};


static gpointer folks_url_field_details_parent_class = NULL;

GType folks_abstract_field_details_get_type (void) G_GNUC_CONST;
GType folks_url_field_details_get_type (void) G_GNUC_CONST;
enum  {
	FOLKS_URL_FIELD_DETAILS_DUMMY_PROPERTY
};
#define FOLKS_URL_FIELD_DETAILS_PARAM_TYPE_HOME_PAGE "x-home-page"
#define FOLKS_URL_FIELD_DETAILS_PARAM_TYPE_BLOG "x-blog"
#define FOLKS_URL_FIELD_DETAILS_PARAM_TYPE_PROFILE "x-profile"
#define FOLKS_URL_FIELD_DETAILS_PARAM_TYPE_FTP "x-ftp"
FolksUrlFieldDetails* folks_url_field_details_new (const gchar* value, GeeMultiMap* parameters);
FolksUrlFieldDetails* folks_url_field_details_construct (GType object_type, const gchar* value, GeeMultiMap* parameters);
static gboolean folks_url_field_details_real_equal (FolksAbstractFieldDetails* base, FolksAbstractFieldDetails* that);
gboolean folks_abstract_field_details_equal (FolksAbstractFieldDetails* self, FolksAbstractFieldDetails* that);
static guint folks_url_field_details_real_hash (FolksAbstractFieldDetails* base);
guint folks_abstract_field_details_hash (FolksAbstractFieldDetails* self);
GQuark folks_property_error_quark (void);
GType folks_url_details_get_type (void) G_GNUC_CONST;
static void folks_url_details_real_change_urls_data_free (gpointer _data);
static void folks_url_details_real_change_urls (FolksUrlDetails* self, GeeSet* urls, GAsyncReadyCallback _callback_, gpointer _user_data_);
void folks_url_details_change_urls (FolksUrlDetails* self, GeeSet* urls, GAsyncReadyCallback _callback_, gpointer _user_data_);
void folks_url_details_change_urls_finish (FolksUrlDetails* self, GAsyncResult* _res_, GError** error);
static gboolean folks_url_details_real_change_urls_co (FolksUrlDetailsChangeUrlsData* _data_);
GeeSet* folks_url_details_get_urls (FolksUrlDetails* self);
void folks_url_details_set_urls (FolksUrlDetails* self, GeeSet* value);


/**
   * Create a new UrlFieldDetails.
   *
   * @param value the value of the field, a non-empty URI
   * @param parameters initial parameters. See
   * {@link AbstractFieldDetails.parameters}. A `null` value is equivalent to a
   * empty map of parameters.
   *
   * @return a new UrlFieldDetails
   *
   * @since 0.6.0
   */
FolksUrlFieldDetails* folks_url_field_details_construct (GType object_type, const gchar* value, GeeMultiMap* parameters) {
	FolksUrlFieldDetails * self = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GeeMultiMap* _tmp2_;
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = value;
	if (g_strcmp0 (_tmp0_, "") == 0) {
		g_warning ("url-details.vala:91: Empty URI passed to UrlFieldDetails.");
	}
	_tmp1_ = value;
	_tmp2_ = parameters;
	self = (FolksUrlFieldDetails*) g_object_new (object_type, "t_type", G_TYPE_STRING, "t_dup_func", (GBoxedCopyFunc) g_strdup, "t_destroy_func", g_free, "value", _tmp1_, "parameters", _tmp2_, NULL);
	return self;
}


FolksUrlFieldDetails* folks_url_field_details_new (const gchar* value, GeeMultiMap* parameters) {
	return folks_url_field_details_construct (FOLKS_TYPE_URL_FIELD_DETAILS, value, parameters);
}


/**
   * {@inheritDoc}
   *
   * @since 0.6.0
   */
static gboolean folks_url_field_details_real_equal (FolksAbstractFieldDetails* base, FolksAbstractFieldDetails* that) {
	FolksUrlFieldDetails * self;
	gboolean result = FALSE;
	FolksAbstractFieldDetails* _tmp0_;
	gboolean _tmp1_ = FALSE;
	self = (FolksUrlFieldDetails*) base;
	g_return_val_if_fail (that != NULL, FALSE);
	_tmp0_ = that;
	_tmp1_ = FOLKS_ABSTRACT_FIELD_DETAILS_CLASS (folks_url_field_details_parent_class)->equal (G_TYPE_CHECK_INSTANCE_CAST (self, FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, FolksAbstractFieldDetails), _tmp0_);
	result = _tmp1_;
	return result;
}


/**
   * {@inheritDoc}
   *
   * @since 0.6.0
   */
static guint folks_url_field_details_real_hash (FolksAbstractFieldDetails* base) {
	FolksUrlFieldDetails * self;
	guint result = 0U;
	guint _tmp0_ = 0U;
	self = (FolksUrlFieldDetails*) base;
	_tmp0_ = FOLKS_ABSTRACT_FIELD_DETAILS_CLASS (folks_url_field_details_parent_class)->hash (G_TYPE_CHECK_INSTANCE_CAST (self, FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, FolksAbstractFieldDetails));
	result = _tmp0_;
	return result;
}


static void folks_url_field_details_class_init (FolksUrlFieldDetailsClass * klass) {
	folks_url_field_details_parent_class = g_type_class_peek_parent (klass);
	FOLKS_ABSTRACT_FIELD_DETAILS_CLASS (klass)->equal = folks_url_field_details_real_equal;
	FOLKS_ABSTRACT_FIELD_DETAILS_CLASS (klass)->hash = folks_url_field_details_real_hash;
}


static void folks_url_field_details_instance_init (FolksUrlFieldDetails * self) {
}


/**
 * Object representing a URL that can have some parameters associated with it.
 *
 * See {@link Folks.AbstractFieldDetails} for details on common parameter names
 * and values.
 *
 * @since 0.6.0
 */
GType folks_url_field_details_get_type (void) {
	static volatile gsize folks_url_field_details_type_id__volatile = 0;
	if (g_once_init_enter (&folks_url_field_details_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FolksUrlFieldDetailsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folks_url_field_details_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolksUrlFieldDetails), 0, (GInstanceInitFunc) folks_url_field_details_instance_init, NULL };
		GType folks_url_field_details_type_id;
		folks_url_field_details_type_id = g_type_register_static (FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, "FolksUrlFieldDetails", &g_define_type_info, 0);
		g_once_init_leave (&folks_url_field_details_type_id__volatile, folks_url_field_details_type_id);
	}
	return folks_url_field_details_type_id__volatile;
}


static void folks_url_details_real_change_urls_data_free (gpointer _data) {
	FolksUrlDetailsChangeUrlsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->urls);
	_g_object_unref0 (_data_->self);
	g_slice_free (FolksUrlDetailsChangeUrlsData, _data_);
}


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


static void folks_url_details_real_change_urls (FolksUrlDetails* self, GeeSet* urls, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FolksUrlDetailsChangeUrlsData* _data_;
	FolksUrlDetails* _tmp0_;
	GeeSet* _tmp1_;
	GeeSet* _tmp2_;
	_data_ = g_slice_new0 (FolksUrlDetailsChangeUrlsData);
	_data_->_async_result = g_simple_async_result_new (NULL, _callback_, _user_data_, folks_url_details_real_change_urls);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, folks_url_details_real_change_urls_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = urls;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data_->urls = _tmp2_;
	folks_url_details_real_change_urls_co (_data_);
}


static void folks_url_details_real_change_urls_finish (FolksUrlDetails* self, GAsyncResult* _res_, GError** error) {
	FolksUrlDetailsChangeUrlsData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


/**
   * Change the contact's URLs.
   *
   * It's preferred to call this rather than setting {@link UrlDetails.urls}
   * directly, as this method gives error notification and will only return once
   * the URLs have been written to the relevant backing store (or the
   * operation's failed).
   *
   * @param urls the set of URLs
   * @throws PropertyError if setting the URLs failed
   * @since 0.6.2
   */
static gboolean folks_url_details_real_change_urls_co (FolksUrlDetailsChangeUrlsData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = _ ("URLs are not writeable on this contact.");
	_data_->_tmp1_ = g_error_new_literal (FOLKS_PROPERTY_ERROR, FOLKS_PROPERTY_ERROR_NOT_WRITEABLE, _data_->_tmp0_);
	_data_->_inner_error_ = _data_->_tmp1_;
	if (_data_->_inner_error_->domain == FOLKS_PROPERTY_ERROR) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	} else {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


void folks_url_details_change_urls (FolksUrlDetails* self, GeeSet* urls, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FOLKS_URL_DETAILS_GET_INTERFACE (self)->change_urls (self, urls, _callback_, _user_data_);
}


void folks_url_details_change_urls_finish (FolksUrlDetails* self, GAsyncResult* _res_, GError** error) {
	FOLKS_URL_DETAILS_GET_INTERFACE (self)->change_urls_finish (self, _res_, error);
}


GeeSet* folks_url_details_get_urls (FolksUrlDetails* self) {
	g_return_val_if_fail (self != NULL, NULL);
	return FOLKS_URL_DETAILS_GET_INTERFACE (self)->get_urls (self);
}


void folks_url_details_set_urls (FolksUrlDetails* self, GeeSet* value) {
	g_return_if_fail (self != NULL);
	FOLKS_URL_DETAILS_GET_INTERFACE (self)->set_urls (self, value);
}


static void folks_url_details_base_init (FolksUrlDetailsIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
		/**
		   * The websites of the contact.
		   *
		   * A list or websites associated to the contact.
		   *
		   * @since 0.5.1
		   */
		g_object_interface_install_property (iface, g_param_spec_object ("urls", "urls", "urls", GEE_TYPE_SET, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
		iface->change_urls = folks_url_details_real_change_urls;
		iface->change_urls_finish = folks_url_details_real_change_urls_finish;
	}
}


/**
 * Associates a list of URLs with a contact.
 *
 * @since 0.3.5
 */
GType folks_url_details_get_type (void) {
	static volatile gsize folks_url_details_type_id__volatile = 0;
	if (g_once_init_enter (&folks_url_details_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FolksUrlDetailsIface), (GBaseInitFunc) folks_url_details_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType folks_url_details_type_id;
		folks_url_details_type_id = g_type_register_static (G_TYPE_INTERFACE, "FolksUrlDetails", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (folks_url_details_type_id, G_TYPE_OBJECT);
		g_once_init_leave (&folks_url_details_type_id__volatile, folks_url_details_type_id);
	}
	return folks_url_details_type_id__volatile;
}



