/* TempDevice.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from TempDevice.vala, do not modify */

/*-
 * Copyright (c) 2015-2018 elementary LLC. (https://elementary.io)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 3 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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.
 *
 * Authored by: Corentin Noël <corentin@elementary.io>
 */

#include "io.elementary.settings.printers.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	PRINTERS_TEMP_DEVICE_0_PROPERTY,
	PRINTERS_TEMP_DEVICE_NUM_PROPERTIES
};
static GParamSpec* printers_temp_device_properties[PRINTERS_TEMP_DEVICE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer printers_temp_device_parent_class = NULL;

static void printers_temp_device_finalize (GObject * obj);
static GType printers_temp_device_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

PrintersTempDevice*
printers_temp_device_construct (GType object_type)
{
	PrintersTempDevice * self = NULL;
	self = (PrintersTempDevice*) g_object_new (object_type, NULL);
	return self;
}

PrintersTempDevice*
printers_temp_device_new (void)
{
	return printers_temp_device_construct (PRINTERS_TYPE_TEMP_DEVICE);
}

gchar*
printers_temp_device_get_make_from_id (PrintersTempDevice* self)
{
	const gchar* _tmp0_;
	gchar** attrs = NULL;
	const gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint attrs_length1;
	gint _attrs_size_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->device_id;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp1_ = self->device_id;
	_tmp3_ = _tmp2_ = g_strsplit (_tmp1_, ";", 0);
	attrs = _tmp3_;
	attrs_length1 = _vala_array_length (_tmp2_);
	_attrs_size_ = attrs_length1;
	_tmp4_ = attrs;
	_tmp4__length1 = attrs_length1;
	{
		gchar** attr_collection = NULL;
		gint attr_collection_length1 = 0;
		gint _attr_collection_size_ = 0;
		gint attr_it = 0;
		attr_collection = _tmp4_;
		attr_collection_length1 = _tmp4__length1;
		for (attr_it = 0; attr_it < attr_collection_length1; attr_it = attr_it + 1) {
			gchar* _tmp5_;
			gchar* attr = NULL;
			_tmp5_ = g_strdup (attr_collection[attr_it]);
			attr = _tmp5_;
			{
				gchar** keyval = NULL;
				const gchar* _tmp6_;
				gchar** _tmp7_;
				gchar** _tmp8_;
				gint keyval_length1;
				gint _keyval_size_;
				gchar** _tmp9_;
				gint _tmp9__length1;
				gchar** _tmp10_;
				gint _tmp10__length1;
				const gchar* _tmp11_;
				_tmp6_ = attr;
				_tmp8_ = _tmp7_ = g_strsplit (_tmp6_, ":", 2);
				keyval = _tmp8_;
				keyval_length1 = _vala_array_length (_tmp7_);
				_keyval_size_ = keyval_length1;
				_tmp9_ = keyval;
				_tmp9__length1 = keyval_length1;
				if (_tmp9__length1 < 2) {
					keyval = (_vala_array_free (keyval, keyval_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (attr);
					continue;
				}
				_tmp10_ = keyval;
				_tmp10__length1 = keyval_length1;
				_tmp11_ = _tmp10_[0];
				if (g_strcmp0 (_tmp11_, "MFG") == 0) {
					gchar** _tmp12_;
					gint _tmp12__length1;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					_tmp12_ = keyval;
					_tmp12__length1 = keyval_length1;
					_tmp13_ = _tmp12_[1];
					_tmp14_ = g_strdup (_tmp13_);
					result = _tmp14_;
					keyval = (_vala_array_free (keyval, keyval_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (attr);
					attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				keyval = (_vala_array_free (keyval, keyval_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (attr);
			}
		}
	}
	result = NULL;
	attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

gchar*
printers_temp_device_get_model_from_id (PrintersTempDevice* self)
{
	const gchar* _tmp0_;
	gchar** attrs = NULL;
	const gchar* _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint attrs_length1;
	gint _attrs_size_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->device_id;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp1_ = self->device_id;
	_tmp3_ = _tmp2_ = g_strsplit (_tmp1_, ";", 0);
	attrs = _tmp3_;
	attrs_length1 = _vala_array_length (_tmp2_);
	_attrs_size_ = attrs_length1;
	_tmp4_ = attrs;
	_tmp4__length1 = attrs_length1;
	{
		gchar** attr_collection = NULL;
		gint attr_collection_length1 = 0;
		gint _attr_collection_size_ = 0;
		gint attr_it = 0;
		attr_collection = _tmp4_;
		attr_collection_length1 = _tmp4__length1;
		for (attr_it = 0; attr_it < attr_collection_length1; attr_it = attr_it + 1) {
			gchar* _tmp5_;
			gchar* attr = NULL;
			_tmp5_ = g_strdup (attr_collection[attr_it]);
			attr = _tmp5_;
			{
				gchar** keyval = NULL;
				const gchar* _tmp6_;
				gchar** _tmp7_;
				gchar** _tmp8_;
				gint keyval_length1;
				gint _keyval_size_;
				gchar** _tmp9_;
				gint _tmp9__length1;
				gchar** _tmp10_;
				gint _tmp10__length1;
				const gchar* _tmp11_;
				_tmp6_ = attr;
				_tmp8_ = _tmp7_ = g_strsplit (_tmp6_, ":", 2);
				keyval = _tmp8_;
				keyval_length1 = _vala_array_length (_tmp7_);
				_keyval_size_ = keyval_length1;
				_tmp9_ = keyval;
				_tmp9__length1 = keyval_length1;
				if (_tmp9__length1 < 2) {
					keyval = (_vala_array_free (keyval, keyval_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (attr);
					continue;
				}
				_tmp10_ = keyval;
				_tmp10__length1 = keyval_length1;
				_tmp11_ = _tmp10_[0];
				if (g_strcmp0 (_tmp11_, "MDL") == 0) {
					gchar** _tmp12_;
					gint _tmp12__length1;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					_tmp12_ = keyval;
					_tmp12__length1 = keyval_length1;
					_tmp13_ = _tmp12_[1];
					_tmp14_ = g_strdup (_tmp13_);
					result = _tmp14_;
					keyval = (_vala_array_free (keyval, keyval_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (attr);
					attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				keyval = (_vala_array_free (keyval, keyval_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (attr);
			}
		}
	}
	result = NULL;
	attrs = (_vala_array_free (attrs, attrs_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static void
printers_temp_device_class_init (PrintersTempDeviceClass * klass,
                                 gpointer klass_data)
{
	printers_temp_device_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = printers_temp_device_finalize;
}

static void
printers_temp_device_instance_init (PrintersTempDevice * self,
                                    gpointer klass)
{
	self->device_make_and_model = NULL;
	self->device_class = NULL;
	self->device_uri = NULL;
	self->device_info = NULL;
	self->device_id = NULL;
}

static void
printers_temp_device_finalize (GObject * obj)
{
	PrintersTempDevice * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PRINTERS_TYPE_TEMP_DEVICE, PrintersTempDevice);
	_g_free0 (self->device_make_and_model);
	_g_free0 (self->device_class);
	_g_free0 (self->device_uri);
	_g_free0 (self->device_info);
	_g_free0 (self->device_id);
	G_OBJECT_CLASS (printers_temp_device_parent_class)->finalize (obj);
}

static GType
printers_temp_device_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PrintersTempDeviceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) printers_temp_device_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PrintersTempDevice), 0, (GInstanceInitFunc) printers_temp_device_instance_init, NULL };
	GType printers_temp_device_type_id;
	printers_temp_device_type_id = g_type_register_static (G_TYPE_OBJECT, "PrintersTempDevice", &g_define_type_info, 0);
	return printers_temp_device_type_id;
}

GType
printers_temp_device_get_type (void)
{
	static volatile gsize printers_temp_device_type_id__once = 0;
	if (g_once_init_enter (&printers_temp_device_type_id__once)) {
		GType printers_temp_device_type_id;
		printers_temp_device_type_id = printers_temp_device_get_type_once ();
		g_once_init_leave (&printers_temp_device_type_id__once, printers_temp_device_type_id);
	}
	return printers_temp_device_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

