/* rygel-ruih-icon-elem.c generated by valac 0.56.1, 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 "rygel-ruih.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <libxml/tree.h>
#include "rygel-core.h"
#include <glib/gi18n-lib.h>

#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"

#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 _IconElemPrivate {
	gchar* mime_type;
	gchar* width;
	gchar* height;
	gchar* depth;
	gchar* url;
};

static gint IconElem_private_offset;
static gpointer icon_elem_parent_class = NULL;

static gboolean icon_elem_real_match (UIListing* base,
                               GeeArrayList* protocols,
                               GeeArrayList* filters);
static gchar* icon_elem_real_to_ui_listing (UIListing* base,
                                     GeeArrayList* filters);
static void icon_elem_finalize (UIListing * obj);
static GType icon_elem_get_type_once (void);

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_error0_ = 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_;
			gchar* node_name = NULL;
			xmlNode* _tmp8_;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			const gchar* _tmp11_;
			const gchar* _tmp12_;
			GQuark _tmp14_ = 0U;
			static GQuark _tmp13_label0 = 0;
			static GQuark _tmp13_label1 = 0;
			static GQuark _tmp13_label2 = 0;
			static GQuark _tmp13_label3 = 0;
			static GQuark _tmp13_label4 = 0;
			_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;
			if (_tmp7_->type == XML_TEXT_NODE) {
				continue;
			}
			_tmp8_ = child_node;
			_tmp9_ = _tmp8_->name;
			_tmp10_ = g_strdup (_tmp9_);
			node_name = _tmp10_;
			_tmp11_ = node_name;
			_tmp12_ = _tmp11_;
			_tmp14_ = (NULL == _tmp12_) ? 0 : g_quark_from_string (_tmp12_);
			if (_tmp14_ == ((0 != _tmp13_label0) ? _tmp13_label0 : (_tmp13_label0 = g_quark_from_static_string (ICON_ELEM_MIMETYPE)))) {
				switch (0) {
					default:
					{
						xmlNode* _tmp15_;
						gchar* _tmp16_;
						_tmp15_ = child_node;
						_tmp16_ = (gchar*) xmlNodeGetContent (_tmp15_);
						_g_free0 (self->priv->mime_type);
						self->priv->mime_type = _tmp16_;
						break;
					}
				}
			} else if (_tmp14_ == ((0 != _tmp13_label1) ? _tmp13_label1 : (_tmp13_label1 = g_quark_from_static_string (ICON_ELEM_WIDTH)))) {
				switch (0) {
					default:
					{
						xmlNode* _tmp17_;
						gchar* _tmp18_;
						_tmp17_ = child_node;
						_tmp18_ = (gchar*) xmlNodeGetContent (_tmp17_);
						_g_free0 (self->priv->width);
						self->priv->width = _tmp18_;
						break;
					}
				}
			} else if (_tmp14_ == ((0 != _tmp13_label2) ? _tmp13_label2 : (_tmp13_label2 = g_quark_from_static_string (ICON_ELEM_HEIGHT)))) {
				switch (0) {
					default:
					{
						xmlNode* _tmp19_;
						gchar* _tmp20_;
						_tmp19_ = child_node;
						_tmp20_ = (gchar*) xmlNodeGetContent (_tmp19_);
						_g_free0 (self->priv->height);
						self->priv->height = _tmp20_;
						break;
					}
				}
			} else if (_tmp14_ == ((0 != _tmp13_label3) ? _tmp13_label3 : (_tmp13_label3 = g_quark_from_static_string (ICON_ELEM_DEPTH)))) {
				switch (0) {
					default:
					{
						xmlNode* _tmp21_;
						gchar* _tmp22_;
						_tmp21_ = child_node;
						_tmp22_ = (gchar*) xmlNodeGetContent (_tmp21_);
						_g_free0 (self->priv->depth);
						self->priv->depth = _tmp22_;
						break;
					}
				}
			} else if (_tmp14_ == ((0 != _tmp13_label4) ? _tmp13_label4 : (_tmp13_label4 = g_quark_from_static_string (ICON_ELEM_URL)))) {
				switch (0) {
					default:
					{
						xmlNode* _tmp23_;
						gchar* _tmp24_;
						_tmp23_ = child_node;
						_tmp24_ = (gchar*) xmlNodeGetContent (_tmp23_);
						_g_free0 (self->priv->url);
						self->priv->url = _tmp24_;
						break;
					}
				}
			} else {
				switch (0) {
					default:
					{
						gchar* msg = NULL;
						gchar* _tmp25_;
						const gchar* _tmp26_;
						const gchar* _tmp27_;
						gchar* _tmp28_;
						gchar* _tmp29_;
						GError* _tmp30_;
						GError* _tmp31_;
						_tmp25_ = g_strdup (_ ("Unable to parse Icon data — unexpected node: %s"));
						msg = _tmp25_;
						_tmp26_ = msg;
						_tmp27_ = node_name;
						_tmp28_ = g_strdup_printf (_tmp26_, _tmp27_);
						_tmp29_ = _tmp28_;
						_tmp30_ = g_error_new_literal (RYGEL_RUIH_SERVICE_ERROR, RYGEL_RUIH_SERVICE_ERROR_OPERATION_REJECTED, _tmp29_);
						_tmp31_ = _tmp30_;
						_g_free0 (_tmp29_);
						_inner_error0_ = _tmp31_;
						if (_inner_error0_->domain == RYGEL_RUIH_SERVICE_ERROR) {
							g_propagate_error (error, _inner_error0_);
							_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_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							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;
	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;
	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_;
	gchar* result;
	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,
                      gpointer klass_data)
{
	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,
                         gpointer klass)
{
	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);
}

static GType
icon_elem_get_type_once (void)
{
	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));
	return icon_elem_type_id;
}

GType
icon_elem_get_type (void)
{
	static volatile gsize icon_elem_type_id__once = 0;
	if (g_once_init_enter (&icon_elem_type_id__once)) {
		GType icon_elem_type_id;
		icon_elem_type_id = icon_elem_get_type_once ();
		g_once_init_leave (&icon_elem_type_id__once, icon_elem_type_id);
	}
	return icon_elem_type_id__once;
}

