/* rygel-writable-user-config.c generated by valac 0.15.1.36-84b2b, the Vala compiler
 * generated from rygel-writable-user-config.vala, do not modify */

/*
 * Copyright (C) 2008-2011 Nokia Corporation.
 * Copyright (C) 2008,2009 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.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 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 program; 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 <rygel.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
#include <gee.h>
#include <gio/gio.h>
#include <config.h>


#define RYGEL_TYPE_WRITABLE_USER_CONFIG (rygel_writable_user_config_get_type ())
#define RYGEL_WRITABLE_USER_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_WRITABLE_USER_CONFIG, RygelWritableUserConfig))
#define RYGEL_WRITABLE_USER_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_WRITABLE_USER_CONFIG, RygelWritableUserConfigClass))
#define RYGEL_IS_WRITABLE_USER_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_WRITABLE_USER_CONFIG))
#define RYGEL_IS_WRITABLE_USER_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_WRITABLE_USER_CONFIG))
#define RYGEL_WRITABLE_USER_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_WRITABLE_USER_CONFIG, RygelWritableUserConfigClass))

typedef struct _RygelWritableUserConfig RygelWritableUserConfig;
typedef struct _RygelWritableUserConfigClass RygelWritableUserConfigClass;
typedef struct _RygelWritableUserConfigPrivate RygelWritableUserConfigPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _RygelWritableUserConfig {
	RygelUserConfig parent_instance;
	RygelWritableUserConfigPrivate * priv;
};

struct _RygelWritableUserConfigClass {
	RygelUserConfigClass parent_class;
};


static gpointer rygel_writable_user_config_parent_class = NULL;

GType rygel_writable_user_config_get_type (void) G_GNUC_CONST;
enum  {
	RYGEL_WRITABLE_USER_CONFIG_DUMMY_PROPERTY
};
#define RYGEL_WRITABLE_USER_CONFIG_RYGEL_SERVICE "org.gnome.Rygel1"
#define RYGEL_WRITABLE_USER_CONFIG_RYGEL_PATH "/org/gnome/Rygel1"
#define RYGEL_WRITABLE_USER_CONFIG_RYGEL_INTERFACE "org.gnome.Rygel1"
RygelWritableUserConfig* rygel_writable_user_config_new (GError** error);
RygelWritableUserConfig* rygel_writable_user_config_construct (GType object_type, GError** error);
void rygel_writable_user_config_set_upnp_enabled (RygelWritableUserConfig* self, gboolean value);
static void rygel_writable_user_config_enable_upnp (RygelWritableUserConfig* self, gboolean enable);
void rygel_writable_user_config_set_interface (RygelWritableUserConfig* self, const gchar* value);
void rygel_writable_user_config_set_string (RygelWritableUserConfig* self, const gchar* section, const gchar* key, const gchar* value);
void rygel_writable_user_config_set_port (RygelWritableUserConfig* self, gint value);
void rygel_writable_user_config_set_int (RygelWritableUserConfig* self, const gchar* section, const gchar* key, gint value);
void rygel_writable_user_config_set_transcoding (RygelWritableUserConfig* self, gboolean value);
void rygel_writable_user_config_set_bool (RygelWritableUserConfig* self, const gchar* section, const gchar* key, gboolean value);
void rygel_writable_user_config_set_mp3_transcoder (RygelWritableUserConfig* self, gboolean value);
void rygel_writable_user_config_set_mp2ts_transcoder (RygelWritableUserConfig* self, gboolean value);
void rygel_writable_user_config_set_lpcm_transcoder (RygelWritableUserConfig* self, gboolean value);
void rygel_writable_user_config_set_wmv_transcoder (RygelWritableUserConfig* self, gboolean value);
void rygel_writable_user_config_set_allow_upload (RygelWritableUserConfig* self, gboolean value, GError** error);
void rygel_writable_user_config_set_allow_deletion (RygelWritableUserConfig* self, gboolean value, GError** error);
void rygel_writable_user_config_save (RygelWritableUserConfig* self);
void rygel_writable_user_config_set_string_list (RygelWritableUserConfig* self, const gchar* section, const gchar* key, GeeArrayList* str_list);
static void rygel_writable_user_config_ensure_dir_exists (RygelWritableUserConfig* self, const gchar* dir_path, GError** error);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


RygelWritableUserConfig* rygel_writable_user_config_construct (GType object_type, GError** error) {
	RygelWritableUserConfig * self = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* path;
	GError * _inner_error_ = NULL;
	_tmp0_ = g_get_user_config_dir ();
	_tmp1_ = g_build_filename (_tmp0_, RYGEL_USER_CONFIG_CONFIG_FILE, NULL);
	path = _tmp1_;
	self = (RygelWritableUserConfig*) rygel_user_config_construct (object_type, path, &_inner_error_);
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (path);
		_g_object_unref0 (self);
		return NULL;
	}
	_g_free0 (path);
	return self;
}


RygelWritableUserConfig* rygel_writable_user_config_new (GError** error) {
	return rygel_writable_user_config_construct (RYGEL_TYPE_WRITABLE_USER_CONFIG, error);
}


void rygel_writable_user_config_set_upnp_enabled (RygelWritableUserConfig* self, gboolean value) {
	gboolean enabled;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	enabled = FALSE;
	{
		gboolean _tmp0_ = FALSE;
		gboolean _tmp1_;
		_tmp0_ = rygel_configuration_get_upnp_enabled ((RygelConfiguration*) self, &_inner_error_);
		_tmp1_ = _tmp0_;
		if (_inner_error_ != NULL) {
			goto __catch3_g_error;
		}
		enabled = _tmp1_;
	}
	goto __finally3;
	__catch3_g_error:
	{
		GError* err = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (err);
	}
	__finally3:
	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;
	}
	_tmp2_ = value;
	_tmp3_ = enabled;
	if (_tmp2_ != _tmp3_) {
		gboolean _tmp4_;
		_tmp4_ = value;
		rygel_writable_user_config_enable_upnp (self, _tmp4_);
	}
}


void rygel_writable_user_config_set_interface (RygelWritableUserConfig* self, const gchar* value) {
	gchar* iface = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = value;
		_tmp2_ = g_strdup (_tmp1_);
		_g_free0 (iface);
		iface = _tmp2_;
	} else {
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("");
		_g_free0 (iface);
		iface = _tmp3_;
	}
	_tmp4_ = iface;
	rygel_writable_user_config_set_string (self, "general", RYGEL_USER_CONFIG_IFACE_KEY, _tmp4_);
	_g_free0 (iface);
}


void rygel_writable_user_config_set_port (RygelWritableUserConfig* self, gint value) {
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_int (self, "general", RYGEL_USER_CONFIG_PORT_KEY, _tmp0_);
}


void rygel_writable_user_config_set_transcoding (RygelWritableUserConfig* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_TRANSCODING_KEY, _tmp0_);
}


void rygel_writable_user_config_set_mp3_transcoder (RygelWritableUserConfig* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_MP3_TRANSCODER_KEY, _tmp0_);
}


void rygel_writable_user_config_set_mp2ts_transcoder (RygelWritableUserConfig* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_MP2TS_TRANSCODER_KEY, _tmp0_);
}


void rygel_writable_user_config_set_lpcm_transcoder (RygelWritableUserConfig* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_LPCM_TRANSCODER_KEY, _tmp0_);
}


void rygel_writable_user_config_set_wmv_transcoder (RygelWritableUserConfig* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_WMV_TRANSCODER_KEY, _tmp0_);
}


void rygel_writable_user_config_set_allow_upload (RygelWritableUserConfig* self, gboolean value, GError** error) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_ALLOW_UPLOAD_KEY, _tmp0_);
}


void rygel_writable_user_config_set_allow_deletion (RygelWritableUserConfig* self, gboolean value, GError** error) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_ALLOW_DELETION_KEY, _tmp0_);
}


void rygel_writable_user_config_save (RygelWritableUserConfig* self) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* path;
	gsize length = 0UL;
	GKeyFile* _tmp2_;
	gsize _tmp3_ = 0UL;
	gchar* _tmp4_ = NULL;
	gchar* data;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_get_user_config_dir ();
	_tmp1_ = g_build_filename (_tmp0_, RYGEL_USER_CONFIG_CONFIG_FILE, NULL);
	path = _tmp1_;
	_tmp2_ = ((RygelUserConfig*) self)->key_file;
	_tmp4_ = g_key_file_to_data (_tmp2_, &_tmp3_, NULL);
	length = _tmp3_;
	data = _tmp4_;
	{
		g_file_set_contents (path, data, (gssize) ((glong) length), &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch4_g_file_error;
			}
			_g_free0 (data);
			_g_free0 (path);
			g_critical ("file %s: line %d: unexpected 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;
		}
	}
	goto __finally4;
	__catch4_g_file_error:
	{
		GError* err = NULL;
		const gchar* _tmp5_ = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = _ ("Failed to save configuration data to file '%s': %s");
		_tmp6_ = err;
		_tmp7_ = _tmp6_->message;
		g_critical (_tmp5_, path, _tmp7_);
		_g_error_free0 (err);
	}
	__finally4:
	if (_inner_error_ != NULL) {
		_g_free0 (data);
		_g_free0 (path);
		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_free0 (data);
	_g_free0 (path);
}


void rygel_writable_user_config_set_string (RygelWritableUserConfig* self, const gchar* section, const gchar* key, const gchar* value) {
	GKeyFile* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (section != NULL);
	g_return_if_fail (key != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = ((RygelUserConfig*) self)->key_file;
	_tmp1_ = section;
	_tmp2_ = key;
	_tmp3_ = value;
	g_key_file_set_string (_tmp0_, _tmp1_, _tmp2_, _tmp3_);
}


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


void rygel_writable_user_config_set_string_list (RygelWritableUserConfig* self, const gchar* section, const gchar* key, GeeArrayList* str_list) {
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gchar** _tmp3_ = NULL;
	gchar** strings;
	gint strings_length1;
	gint _strings_size_;
	gint i;
	GKeyFile* _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	gchar** _tmp24_;
	gint _tmp24__length1;
	g_return_if_fail (self != NULL);
	g_return_if_fail (section != NULL);
	g_return_if_fail (key != NULL);
	g_return_if_fail (str_list != NULL);
	_tmp0_ = str_list;
	_tmp1_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_new0 (gchar*, _tmp2_ + 1);
	strings = _tmp3_;
	strings_length1 = _tmp2_;
	_strings_size_ = strings_length1;
	i = 0;
	{
		GeeArrayList* _tmp4_;
		GeeArrayList* _tmp5_;
		GeeArrayList* _str_list;
		GeeArrayList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		gint _str_size;
		gint _str_index;
		_tmp4_ = str_list;
		_tmp5_ = _g_object_ref0 (_tmp4_);
		_str_list = _tmp5_;
		_tmp6_ = _str_list;
		_tmp7_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp6_);
		_tmp8_ = _tmp7_;
		_str_size = _tmp8_;
		_str_index = -1;
		while (TRUE) {
			gint _tmp9_;
			gint _tmp10_;
			gint _tmp11_;
			GeeArrayList* _tmp12_;
			gint _tmp13_;
			gpointer _tmp14_ = NULL;
			gchar* str;
			const gchar* _tmp15_;
			_tmp9_ = _str_index;
			_str_index = _tmp9_ + 1;
			_tmp10_ = _str_index;
			_tmp11_ = _str_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _str_list;
			_tmp13_ = _str_index;
			_tmp14_ = gee_abstract_list_get ((GeeAbstractList*) _tmp12_, _tmp13_);
			str = (gchar*) _tmp14_;
			_tmp15_ = str;
			if (g_strcmp0 (_tmp15_, "") != 0) {
				gchar** _tmp16_;
				gint _tmp16__length1;
				gint _tmp17_;
				const gchar* _tmp18_;
				gchar* _tmp19_;
				gchar* _tmp20_;
				_tmp16_ = strings;
				_tmp16__length1 = strings_length1;
				_tmp17_ = i;
				i = _tmp17_ + 1;
				_tmp18_ = str;
				_tmp19_ = g_strdup (_tmp18_);
				_g_free0 (_tmp16_[_tmp17_]);
				_tmp16_[_tmp17_] = _tmp19_;
				_tmp20_ = _tmp16_[_tmp17_];
			}
			_g_free0 (str);
		}
		_g_object_unref0 (_str_list);
	}
	_tmp21_ = ((RygelUserConfig*) self)->key_file;
	_tmp22_ = section;
	_tmp23_ = key;
	_tmp24_ = strings;
	_tmp24__length1 = strings_length1;
	g_key_file_set_string_list (_tmp21_, _tmp22_, _tmp23_, (const gchar* const*) _tmp24_, _tmp24__length1);
	strings = (_vala_array_free (strings, strings_length1, (GDestroyNotify) g_free), NULL);
}


void rygel_writable_user_config_set_int (RygelWritableUserConfig* self, const gchar* section, const gchar* key, gint value) {
	GKeyFile* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (section != NULL);
	g_return_if_fail (key != NULL);
	_tmp0_ = ((RygelUserConfig*) self)->key_file;
	_tmp1_ = section;
	_tmp2_ = key;
	_tmp3_ = value;
	g_key_file_set_integer (_tmp0_, _tmp1_, _tmp2_, _tmp3_);
}


void rygel_writable_user_config_set_bool (RygelWritableUserConfig* self, const gchar* section, const gchar* key, gboolean value) {
	GKeyFile* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (section != NULL);
	g_return_if_fail (key != NULL);
	_tmp0_ = ((RygelUserConfig*) self)->key_file;
	_tmp1_ = section;
	_tmp2_ = key;
	_tmp3_ = value;
	g_key_file_set_boolean (_tmp0_, _tmp1_, _tmp2_, _tmp3_);
}


static void rygel_writable_user_config_enable_upnp (RygelWritableUserConfig* self, gboolean enable) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		const gchar* _tmp0_ = NULL;
		gchar* _tmp1_;
		gchar* config_dir;
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		gchar* _tmp4_ = NULL;
		gchar* dest_dir;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_ = NULL;
		gchar* dest_path;
		const gchar* _tmp8_;
		GFile* _tmp9_ = NULL;
		GFile* dest;
		gboolean _tmp10_;
		_tmp0_ = g_get_user_config_dir ();
		_tmp1_ = g_strdup (_tmp0_);
		config_dir = _tmp1_;
		_tmp2_ = config_dir;
		rygel_writable_user_config_ensure_dir_exists (self, _tmp2_, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_free0 (config_dir);
			goto __catch5_g_error;
		}
		_tmp3_ = config_dir;
		_tmp4_ = g_build_filename (_tmp3_, "autostart", NULL);
		dest_dir = _tmp4_;
		_tmp5_ = dest_dir;
		rygel_writable_user_config_ensure_dir_exists (self, _tmp5_, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_free0 (dest_dir);
			_g_free0 (config_dir);
			goto __catch5_g_error;
		}
		_tmp6_ = dest_dir;
		_tmp7_ = g_build_filename (_tmp6_, "rygel.desktop", NULL);
		dest_path = _tmp7_;
		_tmp8_ = dest_path;
		_tmp9_ = g_file_new_for_path (_tmp8_);
		dest = _tmp9_;
		_tmp10_ = enable;
		if (_tmp10_) {
			GBusNameAppearedCallback a;
			void* a_target;
			GDestroyNotify a_target_destroy_notify;
			GBusNameVanishedCallback b;
			void* b_target;
			GDestroyNotify b_target_destroy_notify;
			GBusNameAppearedCallback _tmp11_;
			void* _tmp11__target;
			GDestroyNotify _tmp11__target_destroy_notify;
			GBusNameVanishedCallback _tmp12_;
			void* _tmp12__target;
			GDestroyNotify _tmp12__target_destroy_notify;
			gchar* _tmp13_ = NULL;
			gchar* source_path;
			a = NULL;
			a_target = NULL;
			a_target_destroy_notify = NULL;
			b = NULL;
			b_target = NULL;
			b_target_destroy_notify = NULL;
			_tmp11_ = a;
			_tmp11__target = a_target;
			_tmp11__target_destroy_notify = a_target_destroy_notify;
			a_target_destroy_notify = NULL;
			_tmp12_ = b;
			_tmp12__target = b_target;
			_tmp12__target_destroy_notify = b_target_destroy_notify;
			b_target_destroy_notify = NULL;
			g_bus_watch_name_with_closures (G_BUS_TYPE_SESSION, RYGEL_DBUS_INTERFACE_SERVICE_NAME, G_BUS_NAME_WATCHER_FLAGS_AUTO_START, (GClosure*) ((_tmp11_ == NULL) ? NULL : g_cclosure_new ((GCallback) _tmp11_, _tmp11__target, _tmp11__target_destroy_notify)), (GClosure*) ((_tmp12_ == NULL) ? NULL : g_cclosure_new ((GCallback) _tmp12_, _tmp12__target, _tmp12__target_destroy_notify)));
			_tmp13_ = g_build_filename (DESKTOP_DIR, "rygel.desktop", NULL);
			source_path = _tmp13_;
			{
				GFile* _tmp14_;
				const gchar* _tmp15_;
				_tmp14_ = dest;
				_tmp15_ = source_path;
				g_file_make_symbolic_link (_tmp14_, _tmp15_, NULL, &_inner_error_);
				if (_inner_error_ != NULL) {
					if (g_error_matches (_inner_error_, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
						goto __catch6_g_io_error_exists;
					}
					goto __finally6;
				}
			}
			goto __finally6;
			__catch6_g_io_error_exists:
			{
				GError* err = NULL;
				err = _inner_error_;
				_inner_error_ = NULL;
				_g_error_free0 (err);
			}
			__finally6:
			if (_inner_error_ != NULL) {
				_g_free0 (source_path);
				(b_target_destroy_notify == NULL) ? NULL : (b_target_destroy_notify (b_target), NULL);
				b = NULL;
				b_target = NULL;
				b_target_destroy_notify = NULL;
				(a_target_destroy_notify == NULL) ? NULL : (a_target_destroy_notify (a_target), NULL);
				a = NULL;
				a_target = NULL;
				a_target_destroy_notify = NULL;
				_g_object_unref0 (dest);
				_g_free0 (dest_path);
				_g_free0 (dest_dir);
				_g_free0 (config_dir);
				goto __catch5_g_error;
			}
			rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_UPNP_ENABLED_KEY, TRUE);
			_g_free0 (source_path);
			(b_target_destroy_notify == NULL) ? NULL : (b_target_destroy_notify (b_target), NULL);
			b = NULL;
			b_target = NULL;
			b_target_destroy_notify = NULL;
			(a_target_destroy_notify == NULL) ? NULL : (a_target_destroy_notify (a_target), NULL);
			a = NULL;
			a_target = NULL;
			a_target_destroy_notify = NULL;
		} else {
			gboolean _tmp16_ = FALSE;
			gboolean _tmp17_;
			_tmp16_ = rygel_configuration_get_upnp_enabled ((RygelConfiguration*) self, &_inner_error_);
			_tmp17_ = _tmp16_;
			if (_inner_error_ != NULL) {
				_g_object_unref0 (dest);
				_g_free0 (dest_path);
				_g_free0 (dest_dir);
				_g_free0 (config_dir);
				goto __catch5_g_error;
			}
			if (_tmp17_) {
				RygelDBusInterface* _tmp18_ = NULL;
				RygelDBusInterface* rygel_proxy;
				RygelDBusInterface* _tmp19_;
				_tmp18_ = g_initable_new (RYGEL_TYPE_DBUS_INTERFACE_PROXY, NULL, &_inner_error_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", RYGEL_DBUS_INTERFACE_SERVICE_NAME, "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", RYGEL_DBUS_INTERFACE_OBJECT_PATH, "g-interface-name", "org.gnome.Rygel1", NULL);
				rygel_proxy = (RygelDBusInterface*) _tmp18_;
				if (_inner_error_ != NULL) {
					_g_object_unref0 (dest);
					_g_free0 (dest_path);
					_g_free0 (dest_dir);
					_g_free0 (config_dir);
					goto __catch5_g_error;
				}
				_tmp19_ = rygel_proxy;
				rygel_dbus_interface_shutdown (_tmp19_, &_inner_error_);
				if (_inner_error_ != NULL) {
					_g_object_unref0 (rygel_proxy);
					_g_object_unref0 (dest);
					_g_free0 (dest_path);
					_g_free0 (dest_dir);
					_g_free0 (config_dir);
					goto __catch5_g_error;
				}
				_g_object_unref0 (rygel_proxy);
			}
			{
				GFile* _tmp20_;
				_tmp20_ = dest;
				g_file_delete (_tmp20_, NULL, &_inner_error_);
				if (_inner_error_ != NULL) {
					if (g_error_matches (_inner_error_, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
						goto __catch7_g_io_error_not_found;
					}
					goto __finally7;
				}
			}
			goto __finally7;
			__catch7_g_io_error_not_found:
			{
				GError* err = NULL;
				err = _inner_error_;
				_inner_error_ = NULL;
				_g_error_free0 (err);
			}
			__finally7:
			if (_inner_error_ != NULL) {
				_g_object_unref0 (dest);
				_g_free0 (dest_path);
				_g_free0 (dest_dir);
				_g_free0 (config_dir);
				goto __catch5_g_error;
			}
			rygel_writable_user_config_set_bool (self, "general", RYGEL_USER_CONFIG_UPNP_ENABLED_KEY, FALSE);
		}
		_g_object_unref0 (dest);
		_g_free0 (dest_path);
		_g_free0 (dest_dir);
		_g_free0 (config_dir);
	}
	goto __finally5;
	__catch5_g_error:
	{
		GError* err = NULL;
		gchar* message = NULL;
		gboolean _tmp21_;
		const gchar* _tmp26_;
		GError* _tmp27_;
		const gchar* _tmp28_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp21_ = enable;
		if (_tmp21_) {
			const gchar* _tmp22_ = NULL;
			gchar* _tmp23_;
			_tmp22_ = _ ("Failed to start Rygel service: %s");
			_tmp23_ = g_strdup (_tmp22_);
			_g_free0 (message);
			message = _tmp23_;
		} else {
			const gchar* _tmp24_ = NULL;
			gchar* _tmp25_;
			_tmp24_ = _ ("Failed to stop Rygel service: %s");
			_tmp25_ = g_strdup (_tmp24_);
			_g_free0 (message);
			message = _tmp25_;
		}
		_tmp26_ = message;
		_tmp27_ = err;
		_tmp28_ = _tmp27_->message;
		g_warning (_tmp26_, _tmp28_);
		_g_free0 (message);
		_g_error_free0 (err);
	}
	__finally5:
	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;
	}
}


static void rygel_writable_user_config_ensure_dir_exists (RygelWritableUserConfig* self, const gchar* dir_path, GError** error) {
	const gchar* _tmp0_;
	GFile* _tmp1_ = NULL;
	GFile* dir;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dir_path != NULL);
	_tmp0_ = dir_path;
	_tmp1_ = g_file_new_for_path (_tmp0_);
	dir = _tmp1_;
	{
		g_file_make_directory (dir, NULL, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (g_error_matches (_inner_error_, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
				goto __catch8_g_io_error_exists;
			}
			goto __finally8;
		}
	}
	goto __finally8;
	__catch8_g_io_error_exists:
	{
		GError* err = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (err);
	}
	__finally8:
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (dir);
		return;
	}
	_g_object_unref0 (dir);
}


static void rygel_writable_user_config_class_init (RygelWritableUserConfigClass * klass) {
	rygel_writable_user_config_parent_class = g_type_class_peek_parent (klass);
}


static void rygel_writable_user_config_instance_init (RygelWritableUserConfig * self) {
}


/**
 * Manages the user configuration for Rygel.
 */
GType rygel_writable_user_config_get_type (void) {
	static volatile gsize rygel_writable_user_config_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_writable_user_config_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelWritableUserConfigClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_writable_user_config_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelWritableUserConfig), 0, (GInstanceInitFunc) rygel_writable_user_config_instance_init, NULL };
		GType rygel_writable_user_config_type_id;
		rygel_writable_user_config_type_id = g_type_register_static (RYGEL_TYPE_USER_CONFIG, "RygelWritableUserConfig", &g_define_type_info, 0);
		g_once_init_leave (&rygel_writable_user_config_type_id__volatile, rygel_writable_user_config_type_id);
	}
	return rygel_writable_user_config_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



