/* rygel-ruih-icon-elem.c generated by valac 0.42.2, the Vala compiler
 * generated from rygel-ruih-icon-elem.vala, do not modify */

/*
 * Copyright (C) 2013  Cable Television Laboratories, Inc.
 *
 * Author: Neha Shanbhag <N.Shanbhag@cablelabs.com>
 * Contact: http://www.cablelabs.com/
 *
 * This file is part of Rygel.
 *
 * Rygel 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.
 *
 * Rygel 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


#include <glib.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/tree.h>
#include <rygel-core.h>
#include <glib/gi18n-lib.h>


#define TYPE_UI_LISTING (ui_listing_get_type ())
#define UI_LISTING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UI_LISTING, UIListing))
#define UI_LISTING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UI_LISTING, UIListingClass))
#define IS_UI_LISTING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UI_LISTING))
#define IS_UI_LISTING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UI_LISTING))
#define UI_LISTING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UI_LISTING, UIListingClass))

typedef struct _UIListing UIListing;
typedef struct _UIListingClass UIListingClass;
typedef struct _UIListingPrivate UIListingPrivate;

#define TYPE_PROTOCOL_ELEM (protocol_elem_get_type ())
#define PROTOCOL_ELEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROTOCOL_ELEM, ProtocolElem))
#define PROTOCOL_ELEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROTOCOL_ELEM, ProtocolElemClass))
#define IS_PROTOCOL_ELEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROTOCOL_ELEM))
#define IS_PROTOCOL_ELEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROTOCOL_ELEM))
#define PROTOCOL_ELEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROTOCOL_ELEM, ProtocolElemClass))

typedef struct _ProtocolElem ProtocolElem;
typedef struct _ProtocolElemClass ProtocolElemClass;

#define TYPE_FILTER_ENTRY (filter_entry_get_type ())
#define FILTER_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FILTER_ENTRY, FilterEntry))
#define FILTER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FILTER_ENTRY, FilterEntryClass))
#define IS_FILTER_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FILTER_ENTRY))
#define IS_FILTER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FILTER_ENTRY))
#define FILTER_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FILTER_ENTRY, FilterEntryClass))

typedef struct _FilterEntry FilterEntry;
typedef struct _FilterEntryClass FilterEntryClass;

#define TYPE_ICON_ELEM (icon_elem_get_type ())
#define ICON_ELEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ICON_ELEM, IconElem))
#define ICON_ELEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ICON_ELEM, IconElemClass))
#define IS_ICON_ELEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ICON_ELEM))
#define IS_ICON_ELEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ICON_ELEM))
#define ICON_ELEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ICON_ELEM, IconElemClass))

typedef struct _IconElem IconElem;
typedef struct _IconElemClass IconElemClass;
typedef struct _IconElemPrivate IconElemPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _rygel_xml_utils_iterator_unref0(var) ((var == NULL) ? NULL : (var = (rygel_xml_utils_iterator_unref (var), NULL)))
#define _ui_listing_unref0(var) ((var == NULL) ? NULL : (var = (ui_listing_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _UIListing {
	GTypeInstance parent_instance;
	volatile int ref_count;
	UIListingPrivate * priv;
};

struct _UIListingClass {
	GTypeClass parent_class;
	void (*finalize) (UIListing *self);
	gboolean (*match) (UIListing* self, GeeArrayList* protocols, GeeArrayList* filters);
	gchar* (*to_ui_listing) (UIListing* self, GeeArrayList* filters);
};

struct _IconElem {
	UIListing parent_instance;
	IconElemPrivate * priv;
};

struct _IconElemClass {
	UIListingClass parent_class;
};

struct _IconElemPrivate {
	gchar* mime_type;
	gchar* width;
	gchar* height;
	gchar* depth;
	gchar* url;
};

typedef enum  {
	RYGEL_RUIH_SERVICE_ERROR_OPERATION_REJECTED = 701,
	RYGEL_RUIH_SERVICE_ERROR_INVALID_FILTER = 702
} RygelRuihServiceError;
#define RYGEL_RUIH_SERVICE_ERROR rygel_ruih_service_error_quark ()

static gint IconElem_private_offset;
static gpointer icon_elem_parent_class = NULL;

gpointer ui_listing_ref (gpointer instance);
void ui_listing_unref (gpointer instance);
GParamSpec* param_spec_ui_listing (const gchar* name,
                                   const gchar* nick,
                                   const gchar* blurb,
                                   GType object_type,
                                   GParamFlags flags);
void value_set_ui_listing (GValue* value,
                           gpointer v_object);
void value_take_ui_listing (GValue* value,
                            gpointer v_object);
gpointer value_get_ui_listing (const GValue* value);
GType ui_listing_get_type (void) G_GNUC_CONST;
GType protocol_elem_get_type (void) G_GNUC_CONST;
gpointer filter_entry_ref (gpointer instance);
void filter_entry_unref (gpointer instance);
GParamSpec* param_spec_filter_entry (const gchar* name,
                                     const gchar* nick,
                                     const gchar* blurb,
                                     GType object_type,
                                     GParamFlags flags);
void value_set_filter_entry (GValue* value,
                             gpointer v_object);
void value_take_filter_entry (GValue* value,
                              gpointer v_object);
gpointer value_get_filter_entry (const GValue* value);
GType filter_entry_get_type (void) G_GNUC_CONST;
GType icon_elem_get_type (void) G_GNUC_CONST;
#define ICON_ELEM_MIMETYPE "mimetype"
#define ICON_ELEM_WIDTH "width"
#define ICON_ELEM_HEIGHT "height"
#define ICON_ELEM_DEPTH "depth"
#define ICON_ELEM_URL "url"
GQuark rygel_ruih_service_error_quark (void);
IconElem* icon_elem_new (xmlNode* node,
                         GError** error);
IconElem* icon_elem_construct (GType object_type,
                               xmlNode* node,
                               GError** error);
UIListing* ui_listing_construct (GType object_type);
static gboolean icon_elem_real_match (UIListing* base,
                               GeeArrayList* protocols,
                               GeeArrayList* filters);
static gchar* icon_elem_real_to_ui_listing (UIListing* base,
                                     GeeArrayList* filters);
gboolean ui_listing_filters_match (UIListing* self,
                                   GeeArrayList* filters,
                                   const gchar* name,
                                   const gchar* value);
#define UI_LISTING_ICON "icon"
gchar* ui_listing_to_xml (UIListing* self,
                          GeeHashMap* hash_map);
static void icon_elem_finalize (UIListing * obj);


static inline gpointer
icon_elem_get_instance_private (IconElem* self)
{
	return G_STRUCT_MEMBER_P (self, IconElem_private_offset);
}


IconElem*
icon_elem_construct (GType object_type,
                     xmlNode* node,
                     GError** error)
{
	IconElem* self = NULL;
	GError * _inner_error_ = NULL;
	self = (IconElem*) ui_listing_construct (object_type);
	{
		RygelXMLUtilsIterator* _child_node_it = NULL;
		RygelXMLUtilsChildIterator* _tmp0_;
		RygelXMLUtilsChildIterator* _tmp1_;
		RygelXMLUtilsIterator* _tmp2_;
		RygelXMLUtilsIterator* _tmp3_;
		_tmp0_ = rygel_xml_utils_child_iterator_new (node);
		_tmp1_ = _tmp0_;
		_tmp2_ = rygel_xml_utils_iterator_iterator ((RygelXMLUtilsIterator*) _tmp1_);
		_tmp3_ = _tmp2_;
		_rygel_xml_utils_iterator_unref0 (_tmp1_);
		_child_node_it = _tmp3_;
		while (TRUE) {
			RygelXMLUtilsIterator* _tmp4_;
			xmlNode* child_node = NULL;
			RygelXMLUtilsIterator* _tmp5_;
			xmlNode* _tmp6_;
			xmlNode* _tmp7_;
			xmlElementType _tmp8_;
			gchar* node_name = NULL;
			xmlNode* _tmp9_;
			const gchar* _tmp10_;
			gchar* _tmp11_;
			const gchar* _tmp12_;
			const gchar* _tmp13_;
			GQuark _tmp15_ = 0U;
			_tmp4_ = _child_node_it;
			if (!rygel_xml_utils_iterator_next (_tmp4_)) {
				break;
			}
			_tmp5_ = _child_node_it;
			_tmp6_ = rygel_xml_utils_iterator_get (_tmp5_);
			child_node = _tmp6_;
			_tmp7_ = child_node;
			_tmp8_ = _tmp7_->type;
			if (_tmp8_ == XML_TEXT_NODE) {
				continue;
			}
			_tmp9_ = child_node;
			_tmp10_ = _tmp9_->name;
			_tmp11_ = g_strdup (_tmp10_);
			node_name = _tmp11_;
			_tmp12_ = node_name;
			_tmp13_ = _tmp12_;
			_tmp15_ = (NULL == _tmp13_) ? 0 : g_quark_from_string (_tmp13_);
			if (_tmp15_ == g_quark_from_string (ICON_ELEM_MIMETYPE)) {
				switch (0) {
					default:
					{
						xmlNode* _tmp16_;
						gchar* _tmp17_;
						_tmp16_ = child_node;
						_tmp17_ = (gchar*) xmlNodeGetContent (_tmp16_);
						_g_free0 (self->priv->mime_type);
						self->priv->mime_type = _tmp17_;
						break;
					}
				}
			} else if (_tmp15_ == g_quark_from_string (ICON_ELEM_WIDTH)) {
				switch (0) {
					default:
					{
						xmlNode* _tmp18_;
						gchar* _tmp19_;
						_tmp18_ = child_node;
						_tmp19_ = (gchar*) xmlNodeGetContent (_tmp18_);
						_g_free0 (self->priv->width);
						self->priv->width = _tmp19_;
						break;
					}
				}
			} else if (_tmp15_ == g_quark_from_string (ICON_ELEM_HEIGHT)) {
				switch (0) {
					default:
					{
						xmlNode* _tmp20_;
						gchar* _tmp21_;
						_tmp20_ = child_node;
						_tmp21_ = (gchar*) xmlNodeGetContent (_tmp20_);
						_g_free0 (self->priv->height);
						self->priv->height = _tmp21_;
						break;
					}
				}
			} else if (_tmp15_ == g_quark_from_string (ICON_ELEM_DEPTH)) {
				switch (0) {
					default:
					{
						xmlNode* _tmp22_;
						gchar* _tmp23_;
						_tmp22_ = child_node;
						_tmp23_ = (gchar*) xmlNodeGetContent (_tmp22_);
						_g_free0 (self->priv->depth);
						self->priv->depth = _tmp23_;
						break;
					}
				}
			} else if (_tmp15_ == g_quark_from_string (ICON_ELEM_URL)) {
				switch (0) {
					default:
					{
						xmlNode* _tmp24_;
						gchar* _tmp25_;
						_tmp24_ = child_node;
						_tmp25_ = (gchar*) xmlNodeGetContent (_tmp24_);
						_g_free0 (self->priv->url);
						self->priv->url = _tmp25_;
						break;
					}
				}
			} else {
				switch (0) {
					default:
					{
						gchar* msg = NULL;
						gchar* _tmp26_;
						const gchar* _tmp27_;
						const gchar* _tmp28_;
						gchar* _tmp29_;
						gchar* _tmp30_;
						GError* _tmp31_;
						GError* _tmp32_;
						_tmp26_ = g_strdup (_ ("Unable to parse Icon data — unexpected node: %s"));
						msg = _tmp26_;
						_tmp27_ = msg;
						_tmp28_ = node_name;
						_tmp29_ = g_strdup_printf (_tmp27_, _tmp28_);
						_tmp30_ = _tmp29_;
						_tmp31_ = g_error_new_literal (RYGEL_RUIH_SERVICE_ERROR, RYGEL_RUIH_SERVICE_ERROR_OPERATION_REJECTED, _tmp30_);
						_tmp32_ = _tmp31_;
						_g_free0 (_tmp30_);
						_inner_error_ = _tmp32_;
						if (_inner_error_->domain == RYGEL_RUIH_SERVICE_ERROR) {
							g_propagate_error (error, _inner_error_);
							_g_free0 (msg);
							_g_free0 (node_name);
							_rygel_xml_utils_iterator_unref0 (_child_node_it);
							_ui_listing_unref0 (self);
							return NULL;
						} else {
							_g_free0 (msg);
							_g_free0 (node_name);
							_rygel_xml_utils_iterator_unref0 (_child_node_it);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
							g_clear_error (&_inner_error_);
							return NULL;
						}
						_g_free0 (msg);
					}
				}
			}
			_g_free0 (node_name);
		}
		_rygel_xml_utils_iterator_unref0 (_child_node_it);
	}
	return self;
}


IconElem*
icon_elem_new (xmlNode* node,
               GError** error)
{
	return icon_elem_construct (TYPE_ICON_ELEM, node, error);
}


static gboolean
icon_elem_real_match (UIListing* base,
                      GeeArrayList* protocols,
                      GeeArrayList* filters)
{
	IconElem * self;
	gboolean result = FALSE;
	self = (IconElem*) base;
	g_return_val_if_fail (filters != NULL, FALSE);
	result = TRUE;
	return result;
}


static gchar*
icon_elem_real_to_ui_listing (UIListing* base,
                              GeeArrayList* filters)
{
	IconElem * self;
	gchar* result = NULL;
	GeeHashMap* elements = NULL;
	GeeHashMap* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gboolean _tmp6_ = FALSE;
	const gchar* _tmp7_;
	gboolean _tmp11_ = FALSE;
	const gchar* _tmp12_;
	gboolean _tmp16_ = FALSE;
	const gchar* _tmp17_;
	gboolean _tmp21_ = FALSE;
	const gchar* _tmp22_;
	GeeHashMap* _tmp26_;
	gint _tmp27_;
	gint _tmp28_;
	gchar* _tmp39_;
	self = (IconElem*) base;
	g_return_val_if_fail (filters != NULL, NULL);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	elements = _tmp0_;
	_tmp2_ = self->priv->mime_type;
	if (_tmp2_ != NULL) {
		const gchar* _tmp3_;
		_tmp3_ = self->priv->mime_type;
		_tmp1_ = ui_listing_filters_match ((UIListing*) self, filters, UI_LISTING_ICON "@" ICON_ELEM_MIMETYPE, _tmp3_);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GeeHashMap* _tmp4_;
		const gchar* _tmp5_;
		_tmp4_ = elements;
		_tmp5_ = self->priv->mime_type;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp4_, ICON_ELEM_MIMETYPE, _tmp5_);
	}
	_tmp7_ = self->priv->width;
	if (_tmp7_ != NULL) {
		const gchar* _tmp8_;
		_tmp8_ = self->priv->width;
		_tmp6_ = ui_listing_filters_match ((UIListing*) self, filters, UI_LISTING_ICON "@" ICON_ELEM_WIDTH, _tmp8_);
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		GeeHashMap* _tmp9_;
		const gchar* _tmp10_;
		_tmp9_ = elements;
		_tmp10_ = self->priv->width;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp9_, ICON_ELEM_WIDTH, _tmp10_);
	}
	_tmp12_ = self->priv->height;
	if (_tmp12_ != NULL) {
		const gchar* _tmp13_;
		_tmp13_ = self->priv->height;
		_tmp11_ = ui_listing_filters_match ((UIListing*) self, filters, UI_LISTING_ICON "@" ICON_ELEM_HEIGHT, _tmp13_);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		GeeHashMap* _tmp14_;
		const gchar* _tmp15_;
		_tmp14_ = elements;
		_tmp15_ = self->priv->height;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp14_, ICON_ELEM_HEIGHT, _tmp15_);
	}
	_tmp17_ = self->priv->depth;
	if (_tmp17_ != NULL) {
		const gchar* _tmp18_;
		_tmp18_ = self->priv->depth;
		_tmp16_ = ui_listing_filters_match ((UIListing*) self, filters, UI_LISTING_ICON "@" ICON_ELEM_DEPTH, _tmp18_);
	} else {
		_tmp16_ = FALSE;
	}
	if (_tmp16_) {
		GeeHashMap* _tmp19_;
		const gchar* _tmp20_;
		_tmp19_ = elements;
		_tmp20_ = self->priv->depth;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp19_, ICON_ELEM_DEPTH, _tmp20_);
	}
	_tmp22_ = self->priv->url;
	if (_tmp22_ != NULL) {
		const gchar* _tmp23_;
		_tmp23_ = self->priv->url;
		_tmp21_ = ui_listing_filters_match ((UIListing*) self, filters, UI_LISTING_ICON "@" ICON_ELEM_URL, _tmp23_);
	} else {
		_tmp21_ = FALSE;
	}
	if (_tmp21_) {
		GeeHashMap* _tmp24_;
		const gchar* _tmp25_;
		_tmp24_ = elements;
		_tmp25_ = self->priv->url;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp24_, ICON_ELEM_URL, _tmp25_);
	}
	_tmp26_ = elements;
	_tmp27_ = gee_abstract_map_get_size ((GeeAbstractMap*) _tmp26_);
	_tmp28_ = _tmp27_;
	if (_tmp28_ > 0) {
		GString* sb = NULL;
		GString* _tmp29_;
		GString* _tmp30_;
		GString* _tmp31_;
		GeeHashMap* _tmp32_;
		gchar* _tmp33_;
		gchar* _tmp34_;
		GString* _tmp35_;
		GString* _tmp36_;
		const gchar* _tmp37_;
		gchar* _tmp38_;
		_tmp29_ = g_string_new ("");
		sb = _tmp29_;
		_tmp30_ = sb;
		g_string_append (_tmp30_, "<" UI_LISTING_ICON ">\n");
		_tmp31_ = sb;
		_tmp32_ = elements;
		_tmp33_ = ui_listing_to_xml ((UIListing*) self, _tmp32_);
		_tmp34_ = _tmp33_;
		g_string_append (_tmp31_, _tmp34_);
		_g_free0 (_tmp34_);
		_tmp35_ = sb;
		g_string_append (_tmp35_, "</" UI_LISTING_ICON ">\n");
		_tmp36_ = sb;
		_tmp37_ = _tmp36_->str;
		_tmp38_ = g_strdup (_tmp37_);
		result = _tmp38_;
		_g_string_free0 (sb);
		_g_object_unref0 (elements);
		return result;
	}
	_tmp39_ = g_strdup ("");
	result = _tmp39_;
	_g_object_unref0 (elements);
	return result;
}


static void
icon_elem_class_init (IconElemClass * klass)
{
	icon_elem_parent_class = g_type_class_peek_parent (klass);
	((UIListingClass *) klass)->finalize = icon_elem_finalize;
	g_type_class_adjust_private_offset (klass, &IconElem_private_offset);
	((UIListingClass *) klass)->match = (gboolean (*) (UIListing *, GeeArrayList*, GeeArrayList*)) icon_elem_real_match;
	((UIListingClass *) klass)->to_ui_listing = (gchar* (*) (UIListing *, GeeArrayList*)) icon_elem_real_to_ui_listing;
}


static void
icon_elem_instance_init (IconElem * self)
{
	self->priv = icon_elem_get_instance_private (self);
	self->priv->mime_type = NULL;
	self->priv->width = NULL;
	self->priv->height = NULL;
	self->priv->depth = NULL;
	self->priv->url = NULL;
}


static void
icon_elem_finalize (UIListing * obj)
{
	IconElem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ICON_ELEM, IconElem);
	_g_free0 (self->priv->mime_type);
	_g_free0 (self->priv->width);
	_g_free0 (self->priv->height);
	_g_free0 (self->priv->depth);
	_g_free0 (self->priv->url);
	UI_LISTING_CLASS (icon_elem_parent_class)->finalize (obj);
}


GType
icon_elem_get_type (void)
{
	static volatile gsize icon_elem_type_id__volatile = 0;
	if (g_once_init_enter (&icon_elem_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (IconElemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) icon_elem_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IconElem), 0, (GInstanceInitFunc) icon_elem_instance_init, NULL };
		GType icon_elem_type_id;
		icon_elem_type_id = g_type_register_static (TYPE_UI_LISTING, "IconElem", &g_define_type_info, 0);
		IconElem_private_offset = g_type_add_instance_private (icon_elem_type_id, sizeof (IconElemPrivate));
		g_once_init_leave (&icon_elem_type_id__volatile, icon_elem_type_id);
	}
	return icon_elem_type_id__volatile;
}



