/* dpapview.c generated by valac 0.14.2, the Vala compiler
 * generated from dpapview.vala, do not modify */

/*   FILE: dpapviewer.vala -- View DPAP data
 * AUTHOR: W. Michael Petullo <mike@flyn.org>
 *   DATE: 24 November 2010
 *
 * Copyright (c) 2010 W. Michael Petullo <new@flyn.org>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <glib.h>
#include <glib-object.h>
#include <libdmapsharing/dmap.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#include <glib/gstdio.h>
#include <unistd.h>
#include <stdio.h>
#include <gobject/gvaluecollector.h>


#define TYPE_DPAP_VIEWER (dpap_viewer_get_type ())
#define DPAP_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DPAP_VIEWER, DPAPViewer))
#define DPAP_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DPAP_VIEWER, DPAPViewerClass))
#define IS_DPAP_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DPAP_VIEWER))
#define IS_DPAP_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DPAP_VIEWER))
#define DPAP_VIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DPAP_VIEWER, DPAPViewerClass))

typedef struct _DPAPViewer DPAPViewer;
typedef struct _DPAPViewerClass DPAPViewerClass;
typedef struct _DPAPViewerPrivate DPAPViewerPrivate;

#define TYPE_VALA_DMAP_DB (vala_dmap_db_get_type ())
#define VALA_DMAP_DB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_DMAP_DB, ValaDMAPDb))
#define VALA_DMAP_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_DMAP_DB, ValaDMAPDbClass))
#define IS_VALA_DMAP_DB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_DMAP_DB))
#define IS_VALA_DMAP_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_DMAP_DB))
#define VALA_DMAP_DB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_DMAP_DB, ValaDMAPDbClass))

typedef struct _ValaDMAPDb ValaDMAPDb;
typedef struct _ValaDMAPDbClass ValaDMAPDbClass;

#define TYPE_VALA_DPAP_RECORD_FACTORY (vala_dpap_record_factory_get_type ())
#define VALA_DPAP_RECORD_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_DPAP_RECORD_FACTORY, ValaDPAPRecordFactory))
#define VALA_DPAP_RECORD_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_DPAP_RECORD_FACTORY, ValaDPAPRecordFactoryClass))
#define IS_VALA_DPAP_RECORD_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_DPAP_RECORD_FACTORY))
#define IS_VALA_DPAP_RECORD_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_DPAP_RECORD_FACTORY))
#define VALA_DPAP_RECORD_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_DPAP_RECORD_FACTORY, ValaDPAPRecordFactoryClass))

typedef struct _ValaDPAPRecordFactory ValaDPAPRecordFactory;
typedef struct _ValaDPAPRecordFactoryClass ValaDPAPRecordFactoryClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_VALA_DPAP_RECORD (vala_dpap_record_get_type ())
#define VALA_DPAP_RECORD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_DPAP_RECORD, ValaDPAPRecord))
#define VALA_DPAP_RECORD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_DPAP_RECORD, ValaDPAPRecordClass))
#define IS_VALA_DPAP_RECORD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_DPAP_RECORD))
#define IS_VALA_DPAP_RECORD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_DPAP_RECORD))
#define VALA_DPAP_RECORD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_DPAP_RECORD, ValaDPAPRecordClass))

typedef struct _ValaDPAPRecord ValaDPAPRecord;
typedef struct _ValaDPAPRecordClass ValaDPAPRecordClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _dpap_viewer_unref0(var) ((var == NULL) ? NULL : (var = (dpap_viewer_unref (var), NULL)))
typedef struct _ParamSpecDPAPViewer ParamSpecDPAPViewer;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _DPAPViewer {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DPAPViewerPrivate * priv;
};

struct _DPAPViewerClass {
	GTypeClass parent_class;
	void (*finalize) (DPAPViewer *self);
};

struct _DPAPViewerPrivate {
	DMAPMdnsBrowser* browser;
	DMAPConnection* connection;
	GtkListStore* liststore;
	ValaDMAPDb* db;
	ValaDPAPRecordFactory* factory;
};

struct _ParamSpecDPAPViewer {
	GParamSpec parent_instance;
};


static gpointer dpap_viewer_parent_class = NULL;

gpointer dpap_viewer_ref (gpointer instance);
void dpap_viewer_unref (gpointer instance);
GParamSpec* param_spec_dpap_viewer (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_dpap_viewer (GValue* value, gpointer v_object);
void value_take_dpap_viewer (GValue* value, gpointer v_object);
gpointer value_get_dpap_viewer (const GValue* value);
GType dpap_viewer_get_type (void) G_GNUC_CONST;
GType vala_dmap_db_get_type (void) G_GNUC_CONST;
GType vala_dpap_record_factory_get_type (void) G_GNUC_CONST;
#define DPAP_VIEWER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DPAP_VIEWER, DPAPViewerPrivate))
enum  {
	DPAP_VIEWER_DUMMY_PROPERTY
};
static gboolean dpap_viewer_connected_cb (DPAPViewer* self, DMAPConnection* connection, gboolean _result_, const gchar* reason);
static void __lambda0_ (DPAPViewer* self, gconstpointer k, gconstpointer v);
GType vala_dpap_record_get_type (void) G_GNUC_CONST;
GByteArray* vala_dpap_record_get_thumbnail (ValaDPAPRecord* self);
const gchar* vala_dpap_record_get_filename (ValaDPAPRecord* self);
static void ___lambda0__gh_func (gconstpointer key, gconstpointer value, gpointer self);
static void dpap_viewer_service_added_cb (DPAPViewer* self, DMAPMdnsBrowserService* service);
static gboolean _dpap_viewer_connected_cb_dmap_connection_callback (DMAPConnection* connection, gboolean _result_, const gchar* reason, gpointer self);
DPAPViewer* dpap_viewer_new (GtkBuilder* builder, GError** error);
DPAPViewer* dpap_viewer_construct (GType object_type, GtkBuilder* builder, GError** error);
ValaDMAPDb* vala_dmap_db_new (void);
ValaDMAPDb* vala_dmap_db_construct (GType object_type);
ValaDPAPRecordFactory* vala_dpap_record_factory_new (void);
ValaDPAPRecordFactory* vala_dpap_record_factory_construct (GType object_type);
static void _dpap_viewer_service_added_cb_dmap_mdns_browser_service_added (DMAPMdnsBrowser* _sender, void* service, gpointer self);
static void dpap_viewer_finalize (DPAPViewer* obj);
gint _vala_main (gchar** args, int args_length1);


static void __lambda0_ (DPAPViewer* self, gconstpointer k, gconstpointer v) {
	GdkPixbuf* pixbuf;
	gconstpointer _tmp0_;
	GByteArray* _tmp1_;
	GByteArray* _tmp2_;
	GtkTreeIter iter = {0};
	GtkListStore* _tmp15_;
	GtkTreeIter _tmp16_ = {0};
	GtkListStore* _tmp17_;
	GtkTreeIter _tmp18_;
	GdkPixbuf* _tmp19_;
	gconstpointer _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	GError * _inner_error_ = NULL;
	pixbuf = NULL;
	_tmp0_ = v;
	_tmp1_ = vala_dpap_record_get_thumbnail (VALA_DPAP_RECORD (_tmp0_));
	_tmp2_ = _tmp1_;
	if (_tmp2_ != NULL) {
		gchar* path = NULL;
		gchar* _tmp3_ = NULL;
		gint _tmp4_ = 0;
		gint fd;
		const gchar* _tmp5_;
		gconstpointer _tmp6_;
		GByteArray* _tmp7_;
		GByteArray* _tmp8_;
		guint8* _tmp9_;
		gint _tmp9__length1;
		gint _tmp10_;
		const gchar* _tmp11_;
		GdkPixbuf* _tmp12_;
		GdkPixbuf* _tmp13_;
		const gchar* _tmp14_;
		_tmp4_ = g_file_open_tmp ("dpapview.XXXXXX", &_tmp3_, &_inner_error_);
		_g_free0 (path);
		path = _tmp3_;
		fd = _tmp4_;
		if (_inner_error_ != NULL) {
			_g_free0 (path);
			_g_object_unref0 (pixbuf);
			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;
		}
		_tmp5_ = path;
		_tmp6_ = v;
		_tmp7_ = vala_dpap_record_get_thumbnail (VALA_DPAP_RECORD (_tmp6_));
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_->data;
		_tmp9__length1 = (gint) _tmp8_->len;
		g_file_set_contents (_tmp5_, (const char*) _tmp9_, (size_t) _tmp9__length1, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_free0 (path);
			_g_object_unref0 (pixbuf);
			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;
		}
		_tmp10_ = fd;
		close (_tmp10_);
		_tmp11_ = path;
		_tmp12_ = gdk_pixbuf_new_from_file (_tmp11_, &_inner_error_);
		_tmp13_ = _tmp12_;
		if (_inner_error_ != NULL) {
			_g_free0 (path);
			_g_object_unref0 (pixbuf);
			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;
		}
		_g_object_unref0 (pixbuf);
		pixbuf = _tmp13_;
		_tmp14_ = path;
		g_unlink (_tmp14_);
		_g_free0 (path);
	}
	_tmp15_ = self->priv->liststore;
	gtk_list_store_append (_tmp15_, &_tmp16_);
	iter = _tmp16_;
	_tmp17_ = self->priv->liststore;
	_tmp18_ = iter;
	_tmp19_ = pixbuf;
	_tmp20_ = v;
	_tmp21_ = vala_dpap_record_get_filename (VALA_DPAP_RECORD (_tmp20_));
	_tmp22_ = _tmp21_;
	gtk_list_store_set (_tmp17_, &_tmp18_, 0, _tmp19_, 1, _tmp22_, -1);
	_g_object_unref0 (pixbuf);
}


static void ___lambda0__gh_func (gconstpointer key, gconstpointer value, gpointer self) {
	__lambda0_ (self, key, value);
}


static gboolean dpap_viewer_connected_cb (DPAPViewer* self, DMAPConnection* connection, gboolean _result_, const gchar* reason) {
	gboolean result = FALSE;
	ValaDMAPDb* _tmp0_;
	gint64 _tmp1_ = 0LL;
	ValaDMAPDb* _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (connection != NULL, FALSE);
	_tmp0_ = self->priv->db;
	_tmp1_ = dmap_db_count ((DMAPDb*) _tmp0_);
	g_debug ("dpapview.vala:31: %lld entries\n", _tmp1_);
	_tmp2_ = self->priv->db;
	dmap_db_foreach ((DMAPDb*) _tmp2_, ___lambda0__gh_func, self);
	result = TRUE;
	return result;
}


static gboolean _dpap_viewer_connected_cb_dmap_connection_callback (DMAPConnection* connection, gboolean _result_, const gchar* reason, gpointer self) {
	gboolean result;
	result = dpap_viewer_connected_cb (self, connection, _result_, reason);
	return result;
}


static void dpap_viewer_service_added_cb (DPAPViewer* self, DMAPMdnsBrowserService* service) {
	DMAPMdnsBrowserService* _tmp0_;
	const gchar* _tmp1_;
	DMAPMdnsBrowserService* _tmp2_;
	const gchar* _tmp3_;
	DMAPMdnsBrowserService* _tmp4_;
	guint _tmp5_;
	ValaDMAPDb* _tmp6_;
	ValaDPAPRecordFactory* _tmp7_;
	DPAPConnection* _tmp8_;
	DMAPConnection* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = service;
	_tmp1_ = _tmp0_->service_name;
	_tmp2_ = service;
	_tmp3_ = _tmp2_->host;
	_tmp4_ = service;
	_tmp5_ = _tmp4_->port;
	_tmp6_ = self->priv->db;
	_tmp7_ = self->priv->factory;
	_tmp8_ = dpap_connection_new (_tmp1_, _tmp3_, _tmp5_, (DMAPDb*) _tmp6_, (DMAPRecordFactory*) _tmp7_);
	_g_object_unref0 (self->priv->connection);
	self->priv->connection = DMAP_CONNECTION (_tmp8_);
	_tmp9_ = self->priv->connection;
	dmap_connection_connect (_tmp9_, _dpap_viewer_connected_cb_dmap_connection_callback, self);
}


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


static void _dpap_viewer_service_added_cb_dmap_mdns_browser_service_added (DMAPMdnsBrowser* _sender, void* service, gpointer self) {
	dpap_viewer_service_added_cb (self, service);
}


DPAPViewer* dpap_viewer_construct (GType object_type, GtkBuilder* builder, GError** error) {
	DPAPViewer* self = NULL;
	GtkBuilder* _tmp0_;
	GtkBuilder* _tmp1_;
	GObject* _tmp2_ = NULL;
	GtkWidget* _tmp3_;
	GtkWidget* widget;
	GtkBuilder* _tmp4_;
	GObject* _tmp5_ = NULL;
	GtkIconView* _tmp6_;
	GtkIconView* iconview;
	GtkBuilder* _tmp7_;
	GObject* _tmp8_ = NULL;
	GtkListStore* _tmp9_;
	ValaDMAPDb* _tmp10_;
	ValaDPAPRecordFactory* _tmp11_;
	DMAPMdnsBrowser* _tmp12_;
	DMAPMdnsBrowser* _tmp13_;
	DMAPMdnsBrowser* _tmp14_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (builder != NULL, NULL);
	self = (DPAPViewer*) g_type_create_instance (object_type);
	_tmp0_ = builder;
	gtk_builder_connect_signals (_tmp0_, self);
	_tmp1_ = builder;
	_tmp2_ = gtk_builder_get_object (_tmp1_, "window");
	_tmp3_ = _g_object_ref0 (GTK_IS_WIDGET (_tmp2_) ? ((GtkWidget*) _tmp2_) : NULL);
	widget = _tmp3_;
	_tmp4_ = builder;
	_tmp5_ = gtk_builder_get_object (_tmp4_, "iconview");
	_tmp6_ = _g_object_ref0 (GTK_IS_ICON_VIEW (_tmp5_) ? ((GtkIconView*) _tmp5_) : NULL);
	iconview = _tmp6_;
	_tmp7_ = builder;
	_tmp8_ = gtk_builder_get_object (_tmp7_, "liststore");
	_tmp9_ = _g_object_ref0 (GTK_IS_LIST_STORE (_tmp8_) ? ((GtkListStore*) _tmp8_) : NULL);
	_g_object_unref0 (self->priv->liststore);
	self->priv->liststore = _tmp9_;
	_tmp10_ = vala_dmap_db_new ();
	_g_object_unref0 (self->priv->db);
	self->priv->db = _tmp10_;
	_tmp11_ = vala_dpap_record_factory_new ();
	_g_object_unref0 (self->priv->factory);
	self->priv->factory = _tmp11_;
	gtk_icon_view_set_pixbuf_column (iconview, 0);
	gtk_icon_view_set_text_column (iconview, 1);
	gtk_widget_show_all (widget);
	_tmp12_ = dmap_mdns_browser_new (DMAP_MDNS_BROWSER_SERVICE_TYPE_DPAP);
	_g_object_unref0 (self->priv->browser);
	self->priv->browser = _tmp12_;
	_tmp13_ = self->priv->browser;
	g_signal_connect (_tmp13_, "service-added", (GCallback) _dpap_viewer_service_added_cb_dmap_mdns_browser_service_added, self);
	_tmp14_ = self->priv->browser;
	dmap_mdns_browser_start (_tmp14_, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (iconview);
		_g_object_unref0 (widget);
		_dpap_viewer_unref0 (self);
		return NULL;
	}
	_g_object_unref0 (iconview);
	_g_object_unref0 (widget);
	return self;
}


DPAPViewer* dpap_viewer_new (GtkBuilder* builder, GError** error) {
	return dpap_viewer_construct (TYPE_DPAP_VIEWER, builder, error);
}


static void value_dpap_viewer_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_dpap_viewer_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		dpap_viewer_unref (value->data[0].v_pointer);
	}
}


static void value_dpap_viewer_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dpap_viewer_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_dpap_viewer_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_dpap_viewer_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		DPAPViewer* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dpap_viewer_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_dpap_viewer_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	DPAPViewer** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dpap_viewer_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_dpap_viewer (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecDPAPViewer* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_DPAP_VIEWER), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer value_get_dpap_viewer (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DPAP_VIEWER), NULL);
	return value->data[0].v_pointer;
}


void value_set_dpap_viewer (GValue* value, gpointer v_object) {
	DPAPViewer* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DPAP_VIEWER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_DPAP_VIEWER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dpap_viewer_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dpap_viewer_unref (old);
	}
}


void value_take_dpap_viewer (GValue* value, gpointer v_object) {
	DPAPViewer* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DPAP_VIEWER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_DPAP_VIEWER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dpap_viewer_unref (old);
	}
}


static void dpap_viewer_class_init (DPAPViewerClass * klass) {
	dpap_viewer_parent_class = g_type_class_peek_parent (klass);
	DPAP_VIEWER_CLASS (klass)->finalize = dpap_viewer_finalize;
	g_type_class_add_private (klass, sizeof (DPAPViewerPrivate));
}


static void dpap_viewer_instance_init (DPAPViewer * self) {
	self->priv = DPAP_VIEWER_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void dpap_viewer_finalize (DPAPViewer* obj) {
	DPAPViewer * self;
	self = DPAP_VIEWER (obj);
	_g_object_unref0 (self->priv->browser);
	_g_object_unref0 (self->priv->connection);
	_g_object_unref0 (self->priv->liststore);
	_g_object_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->factory);
}


GType dpap_viewer_get_type (void) {
	static volatile gsize dpap_viewer_type_id__volatile = 0;
	if (g_once_init_enter (&dpap_viewer_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_dpap_viewer_init, value_dpap_viewer_free_value, value_dpap_viewer_copy_value, value_dpap_viewer_peek_pointer, "p", value_dpap_viewer_collect_value, "p", value_dpap_viewer_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (DPAPViewerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dpap_viewer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DPAPViewer), 0, (GInstanceInitFunc) dpap_viewer_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType dpap_viewer_type_id;
		dpap_viewer_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DPAPViewer", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&dpap_viewer_type_id__volatile, dpap_viewer_type_id);
	}
	return dpap_viewer_type_id__volatile;
}


gpointer dpap_viewer_ref (gpointer instance) {
	DPAPViewer* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void dpap_viewer_unref (gpointer instance) {
	DPAPViewer* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DPAP_VIEWER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GError * _inner_error_ = NULL;
	gtk_init (&args_length1, &args);
	{
		GtkBuilder* _tmp0_;
		GtkBuilder* builder;
		GtkBuilder* _tmp1_;
		GtkBuilder* _tmp2_;
		DPAPViewer* _tmp3_;
		DPAPViewer* dpapviewer;
		_tmp0_ = gtk_builder_new ();
		builder = _tmp0_;
		_tmp1_ = builder;
		gtk_builder_add_from_file (_tmp1_, "tests/dpapview.ui", &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (builder);
			goto __catch0_g_error;
		}
		_tmp2_ = builder;
		_tmp3_ = dpap_viewer_new (_tmp2_, &_inner_error_);
		dpapviewer = _tmp3_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (builder);
			goto __catch0_g_error;
		}
		gtk_main ();
		_dpap_viewer_unref0 (dpapviewer);
		_g_object_unref0 (builder);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		FILE* _tmp4_;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = stderr;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		fprintf (_tmp4_, "Error: %s\n", _tmp6_);
		result = 1;
		_g_error_free0 (e);
		return result;
	}
	__finally0:
	if (_inner_error_ != NULL) {
		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 0;
	}
	result = 0;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



