/* rygel-media-pref-section.c generated by valac 0.42.2, the Vala compiler
 * generated from rygel-media-pref-section.vala, do not modify */

/*
 * Copyright (C) 2009 Nokia Corporation.
 *
 * 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.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 <rygel-core.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gtk/gtk.h>
#include <gio/gio.h>


#define RYGEL_TYPE_PREFERENCES_SECTION (rygel_preferences_section_get_type ())
#define RYGEL_PREFERENCES_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_PREFERENCES_SECTION, RygelPreferencesSection))
#define RYGEL_PREFERENCES_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_PREFERENCES_SECTION, RygelPreferencesSectionClass))
#define RYGEL_IS_PREFERENCES_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_PREFERENCES_SECTION))
#define RYGEL_IS_PREFERENCES_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_PREFERENCES_SECTION))
#define RYGEL_PREFERENCES_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_PREFERENCES_SECTION, RygelPreferencesSectionClass))

typedef struct _RygelPreferencesSection RygelPreferencesSection;
typedef struct _RygelPreferencesSectionClass RygelPreferencesSectionClass;
typedef struct _RygelPreferencesSectionPrivate RygelPreferencesSectionPrivate;

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

#define RYGEL_TYPE_MEDIA_PREF_SECTION (rygel_media_pref_section_get_type ())
#define RYGEL_MEDIA_PREF_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_PREF_SECTION, RygelMediaPrefSection))
#define RYGEL_MEDIA_PREF_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MEDIA_PREF_SECTION, RygelMediaPrefSectionClass))
#define RYGEL_IS_MEDIA_PREF_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_PREF_SECTION))
#define RYGEL_IS_MEDIA_PREF_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MEDIA_PREF_SECTION))
#define RYGEL_MEDIA_PREF_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MEDIA_PREF_SECTION, RygelMediaPrefSectionClass))

typedef struct _RygelMediaPrefSection RygelMediaPrefSection;
typedef struct _RygelMediaPrefSectionClass RygelMediaPrefSectionClass;
typedef struct _RygelMediaPrefSectionPrivate RygelMediaPrefSectionPrivate;
enum  {
	RYGEL_MEDIA_PREF_SECTION_0_PROPERTY,
	RYGEL_MEDIA_PREF_SECTION_NUM_PROPERTIES
};
static GParamSpec* rygel_media_pref_section_properties[RYGEL_MEDIA_PREF_SECTION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define __vala_GtkTreeRowReference_free0(var) ((var == NULL) ? NULL : (var = (_vala_GtkTreeRowReference_free (var), NULL)))
#define __vala_GtkTreePath_free0(var) ((var == NULL) ? NULL : (var = (_vala_GtkTreePath_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _RygelPreferencesSection {
	GObject parent_instance;
	RygelPreferencesSectionPrivate * priv;
	RygelWritableUserConfig* config;
	gchar* name;
};

struct _RygelPreferencesSectionClass {
	GObjectClass parent_class;
	void (*save) (RygelPreferencesSection* self);
	void (*set_sensitivity) (RygelPreferencesSection* self, gboolean sensitivity);
};

struct _RygelMediaPrefSection {
	RygelPreferencesSection parent_instance;
	RygelMediaPrefSectionPrivate * priv;
};

struct _RygelMediaPrefSectionClass {
	RygelPreferencesSectionClass parent_class;
};

struct _RygelMediaPrefSectionPrivate {
	GeeArrayList* widgets;
	GtkTreeView* treeview;
	GtkListStore* liststore;
	GtkTreeSelection* tree_selection;
	GtkFileChooserDialog* dialog;
	GtkToolButton* remove_button;
};


static gint RygelMediaPrefSection_private_offset;
static gpointer rygel_media_pref_section_parent_class = NULL;

GType rygel_preferences_section_get_type (void) G_GNUC_CONST;
GType rygel_writable_user_config_get_type (void) G_GNUC_CONST;
GType rygel_media_pref_section_get_type (void) G_GNUC_CONST;
#define RYGEL_MEDIA_PREF_SECTION_NAME "MediaExport"
#define RYGEL_MEDIA_PREF_SECTION_URIS_KEY "uris"
#define RYGEL_MEDIA_PREF_SECTION_URIS_TEXTVIEW RYGEL_MEDIA_PREF_SECTION_URIS_KEY "-treeview"
#define RYGEL_MEDIA_PREF_SECTION_URIS_LISTSTORE RYGEL_MEDIA_PREF_SECTION_URIS_KEY "-liststore"
#define RYGEL_MEDIA_PREF_SECTION_URIS_DIALOG RYGEL_MEDIA_PREF_SECTION_URIS_KEY "-dialog"
#define RYGEL_MEDIA_PREF_SECTION_ADD_BUTTON "add-button"
#define RYGEL_MEDIA_PREF_SECTION_REMOVE_BUTTON "remove-button"
#define RYGEL_MEDIA_PREF_SECTION_TREE_SELECTION "treeview-selection"
RygelMediaPrefSection* rygel_media_pref_section_new (GtkBuilder* builder,
                                                     RygelWritableUserConfig* config);
RygelMediaPrefSection* rygel_media_pref_section_construct (GType object_type,
                                                           GtkBuilder* builder,
                                                           RygelWritableUserConfig* config);
RygelPreferencesSection* rygel_preferences_section_construct (GType object_type,
                                                              RygelWritableUserConfig* config,
                                                              const gchar* name);
static gchar* rygel_media_pref_section_get_real_uri (RygelMediaPrefSection* self,
                                              const gchar* uri);
static void rygel_media_pref_section_on_add_button_clicked (RygelMediaPrefSection* self,
                                                     GtkToolButton* button);
static void _rygel_media_pref_section_on_add_button_clicked_gtk_tool_button_clicked (GtkToolButton* _sender,
                                                                              gpointer self);
static void rygel_media_pref_section_on_remove_button_clicked (RygelMediaPrefSection* self,
                                                        GtkToolButton* button);
static void _rygel_media_pref_section_on_remove_button_clicked_gtk_tool_button_clicked (GtkToolButton* _sender,
                                                                                 gpointer self);
static void rygel_media_pref_section_on_tree_selection_changed (RygelMediaPrefSection* self);
static void _rygel_media_pref_section_on_tree_selection_changed_gtk_tree_selection_changed (GtkTreeSelection* _sender,
                                                                                     gpointer self);
static void rygel_media_pref_section_real_save (RygelPreferencesSection* base);
static gchar* rygel_media_pref_section_uri_to_magic_variable (RygelMediaPrefSection* self,
                                                       const gchar* uri);
void rygel_writable_user_config_set_string_list (RygelWritableUserConfig* self,
                                                 const gchar* section,
                                                 const gchar* key,
                                                 GeeArrayList* str_list);
static void rygel_media_pref_section_real_set_sensitivity (RygelPreferencesSection* base,
                                                    gboolean sensitivity);
static void _g_object_unref0_ (gpointer var);
static inline void _g_slist_free__g_object_unref0_ (GSList* self);
static GtkTreeRowReference* _vala_GtkTreeRowReference_copy (GtkTreeRowReference* self);
static void _vala_GtkTreeRowReference_free (GtkTreeRowReference* self);
static GtkTreePath* _vala_GtkTreePath_copy (GtkTreePath* self);
static void _vala_GtkTreePath_free (GtkTreePath* self);
static void __vala_GtkTreePath_free0_ (gpointer var);
static inline void _g_list_free___vala_GtkTreePath_free0_ (GList* self);
static void rygel_media_pref_section_finalize (GObject * obj);


static inline gpointer
rygel_media_pref_section_get_instance_private (RygelMediaPrefSection* self)
{
	return G_STRUCT_MEMBER_P (self, RygelMediaPrefSection_private_offset);
}


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


static void
_rygel_media_pref_section_on_add_button_clicked_gtk_tool_button_clicked (GtkToolButton* _sender,
                                                                         gpointer self)
{
	rygel_media_pref_section_on_add_button_clicked ((RygelMediaPrefSection*) self, _sender);
}


static void
_rygel_media_pref_section_on_remove_button_clicked_gtk_tool_button_clicked (GtkToolButton* _sender,
                                                                            gpointer self)
{
	rygel_media_pref_section_on_remove_button_clicked ((RygelMediaPrefSection*) self, _sender);
}


static void
_rygel_media_pref_section_on_tree_selection_changed_gtk_tree_selection_changed (GtkTreeSelection* _sender,
                                                                                gpointer self)
{
	rygel_media_pref_section_on_tree_selection_changed ((RygelMediaPrefSection*) self);
}


RygelMediaPrefSection*
rygel_media_pref_section_construct (GType object_type,
                                    GtkBuilder* builder,
                                    RygelWritableUserConfig* config)
{
	RygelMediaPrefSection * self = NULL;
	GeeArrayList* _tmp0_;
	GObject* _tmp1_;
	GtkTreeView* _tmp2_;
	GtkTreeView* _tmp3_;
	GObject* _tmp4_;
	GtkListStore* _tmp5_;
	GtkListStore* _tmp6_;
	GObject* _tmp7_;
	GtkTreeSelection* _tmp8_;
	GtkTreeSelection* _tmp9_;
	GObject* _tmp10_;
	GtkFileChooserDialog* _tmp11_;
	GtkFileChooserDialog* _tmp12_;
	GeeArrayList* _tmp13_;
	GtkTreeView* _tmp14_;
	GtkFileChooserDialog* _tmp35_;
	const gchar* _tmp36_;
	GtkFileChooserDialog* _tmp37_;
	GtkToolButton* add_button = NULL;
	GObject* _tmp38_;
	GtkToolButton* _tmp39_;
	GeeArrayList* _tmp40_;
	GObject* _tmp41_;
	GtkToolButton* _tmp42_;
	GtkToolButton* _tmp43_;
	GeeArrayList* _tmp44_;
	GtkToolButton* _tmp45_;
	GtkTreeSelection* _tmp46_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (builder != NULL, NULL);
	g_return_val_if_fail (config != NULL, NULL);
	self = (RygelMediaPrefSection*) rygel_preferences_section_construct (object_type, config, RYGEL_MEDIA_PREF_SECTION_NAME);
	_tmp0_ = gee_array_list_new (gtk_widget_get_type (), (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->widgets);
	self->priv->widgets = _tmp0_;
	_tmp1_ = gtk_builder_get_object (builder, RYGEL_MEDIA_PREF_SECTION_URIS_TEXTVIEW);
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_tree_view_get_type (), GtkTreeView));
	_g_object_unref0 (self->priv->treeview);
	self->priv->treeview = _tmp2_;
	_tmp3_ = self->priv->treeview;
	_vala_assert (_tmp3_ != NULL, "this.treeview != null");
	_tmp4_ = gtk_builder_get_object (builder, RYGEL_MEDIA_PREF_SECTION_URIS_LISTSTORE);
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_list_store_get_type (), GtkListStore));
	_g_object_unref0 (self->priv->liststore);
	self->priv->liststore = _tmp5_;
	_tmp6_ = self->priv->liststore;
	_vala_assert (_tmp6_ != NULL, "this.liststore != null");
	_tmp7_ = gtk_builder_get_object (builder, RYGEL_MEDIA_PREF_SECTION_TREE_SELECTION);
	_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, gtk_tree_selection_get_type ()) ? ((GtkTreeSelection*) _tmp7_) : NULL);
	_g_object_unref0 (self->priv->tree_selection);
	self->priv->tree_selection = _tmp8_;
	_tmp9_ = self->priv->tree_selection;
	_vala_assert (_tmp9_ != NULL, "this.tree_selection != null");
	_tmp10_ = gtk_builder_get_object (builder, RYGEL_MEDIA_PREF_SECTION_URIS_DIALOG);
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, gtk_file_chooser_dialog_get_type (), GtkFileChooserDialog));
	_g_object_unref0 (self->priv->dialog);
	self->priv->dialog = _tmp11_;
	_tmp12_ = self->priv->dialog;
	_vala_assert (_tmp12_ != NULL, "this.dialog != null");
	_tmp13_ = self->priv->widgets;
	_tmp14_ = self->priv->treeview;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp13_, (GtkWidget*) _tmp14_);
	{
		GeeArrayList* uris = NULL;
		const gchar* _tmp15_;
		GeeArrayList* _tmp16_;
		_tmp15_ = ((RygelPreferencesSection*) self)->name;
		_tmp16_ = rygel_configuration_get_string_list ((RygelConfiguration*) config, _tmp15_, RYGEL_MEDIA_PREF_SECTION_URIS_KEY, &_inner_error_);
		uris = _tmp16_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch1_g_error;
		}
		{
			GeeArrayList* _uri_list = NULL;
			GeeArrayList* _tmp17_;
			GeeArrayList* _tmp18_;
			gint _uri_size = 0;
			GeeArrayList* _tmp19_;
			gint _tmp20_;
			gint _tmp21_;
			gint _uri_index = 0;
			_tmp17_ = uris;
			_tmp18_ = _g_object_ref0 (_tmp17_);
			_uri_list = _tmp18_;
			_tmp19_ = _uri_list;
			_tmp20_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp19_);
			_tmp21_ = _tmp20_;
			_uri_size = _tmp21_;
			_uri_index = -1;
			while (TRUE) {
				gint _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				gchar* uri = NULL;
				GeeArrayList* _tmp25_;
				gint _tmp26_;
				gpointer _tmp27_;
				gchar* real_uri = NULL;
				const gchar* _tmp28_;
				gchar* _tmp29_;
				GtkTreeIter iter = {0};
				GtkListStore* _tmp30_;
				GtkTreeIter _tmp31_ = {0};
				GtkListStore* _tmp32_;
				GtkTreeIter _tmp33_;
				const gchar* _tmp34_;
				_tmp22_ = _uri_index;
				_uri_index = _tmp22_ + 1;
				_tmp23_ = _uri_index;
				_tmp24_ = _uri_size;
				if (!(_tmp23_ < _tmp24_)) {
					break;
				}
				_tmp25_ = _uri_list;
				_tmp26_ = _uri_index;
				_tmp27_ = gee_abstract_list_get ((GeeAbstractList*) _tmp25_, _tmp26_);
				uri = (gchar*) _tmp27_;
				_tmp28_ = uri;
				_tmp29_ = rygel_media_pref_section_get_real_uri (self, _tmp28_);
				real_uri = _tmp29_;
				_tmp30_ = self->priv->liststore;
				gtk_list_store_append (_tmp30_, &_tmp31_);
				iter = _tmp31_;
				_tmp32_ = self->priv->liststore;
				_tmp33_ = iter;
				_tmp34_ = real_uri;
				gtk_list_store_set (_tmp32_, &_tmp33_, 0, _tmp34_, -1, -1);
				_g_free0 (real_uri);
				_g_free0 (uri);
			}
			_g_object_unref0 (_uri_list);
		}
		_g_object_unref0 (uris);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* err = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (err);
	}
	__finally1:
	if (G_UNLIKELY (_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 NULL;
	}
	_tmp35_ = self->priv->dialog;
	_tmp36_ = g_get_home_dir ();
	gtk_file_chooser_set_current_folder ((GtkFileChooser*) _tmp35_, _tmp36_);
	_tmp37_ = self->priv->dialog;
	gtk_file_chooser_set_show_hidden ((GtkFileChooser*) _tmp37_, FALSE);
	_tmp38_ = gtk_builder_get_object (builder, RYGEL_MEDIA_PREF_SECTION_ADD_BUTTON);
	_tmp39_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp38_, gtk_tool_button_get_type ()) ? ((GtkToolButton*) _tmp38_) : NULL);
	add_button = _tmp39_;
	g_signal_connect_object (add_button, "clicked", (GCallback) _rygel_media_pref_section_on_add_button_clicked_gtk_tool_button_clicked, self, 0);
	_tmp40_ = self->priv->widgets;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp40_, (GtkWidget*) add_button);
	_tmp41_ = gtk_builder_get_object (builder, RYGEL_MEDIA_PREF_SECTION_REMOVE_BUTTON);
	_tmp42_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp41_, gtk_tool_button_get_type ()) ? ((GtkToolButton*) _tmp41_) : NULL);
	_g_object_unref0 (self->priv->remove_button);
	self->priv->remove_button = _tmp42_;
	_tmp43_ = self->priv->remove_button;
	g_signal_connect_object (_tmp43_, "clicked", (GCallback) _rygel_media_pref_section_on_remove_button_clicked_gtk_tool_button_clicked, self, 0);
	_tmp44_ = self->priv->widgets;
	_tmp45_ = self->priv->remove_button;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp44_, (GtkWidget*) _tmp45_);
	rygel_media_pref_section_on_tree_selection_changed (self);
	_tmp46_ = self->priv->tree_selection;
	g_signal_connect_object (_tmp46_, "changed", (GCallback) _rygel_media_pref_section_on_tree_selection_changed_gtk_tree_selection_changed, self, 0);
	_g_object_unref0 (add_button);
	return self;
}


RygelMediaPrefSection*
rygel_media_pref_section_new (GtkBuilder* builder,
                              RygelWritableUserConfig* config)
{
	return rygel_media_pref_section_construct (RYGEL_TYPE_MEDIA_PREF_SECTION, builder, config);
}


static void
rygel_media_pref_section_real_save (RygelPreferencesSection* base)
{
	RygelMediaPrefSection * self;
	GtkTreeIter iter = {0};
	GeeArrayList* uri_list = NULL;
	GeeArrayList* _tmp0_;
	GtkListStore* _tmp1_;
	GtkTreeIter _tmp2_ = {0};
	gboolean _tmp3_;
	RygelWritableUserConfig* _tmp13_;
	const gchar* _tmp14_;
	GeeArrayList* _tmp15_;
	self = (RygelMediaPrefSection*) base;
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	uri_list = _tmp0_;
	_tmp1_ = self->priv->liststore;
	_tmp3_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp1_, &_tmp2_);
	iter = _tmp2_;
	if (_tmp3_) {
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gchar* uri = NULL;
				GtkListStore* _tmp7_;
				GtkTreeIter _tmp8_;
				const gchar* _tmp9_;
				gchar* _tmp10_;
				GeeArrayList* _tmp11_;
				const gchar* _tmp12_;
				if (!_tmp4_) {
					GtkListStore* _tmp5_;
					gboolean _tmp6_;
					_tmp5_ = self->priv->liststore;
					_tmp6_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp5_, &iter);
					if (!_tmp6_) {
						break;
					}
				}
				_tmp4_ = FALSE;
				_tmp7_ = self->priv->liststore;
				_tmp8_ = iter;
				gtk_tree_model_get ((GtkTreeModel*) _tmp7_, &_tmp8_, 0, &uri, -1, -1);
				_tmp9_ = uri;
				_tmp10_ = rygel_media_pref_section_uri_to_magic_variable (self, _tmp9_);
				_g_free0 (uri);
				uri = _tmp10_;
				_tmp11_ = uri_list;
				_tmp12_ = uri;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp11_, _tmp12_);
				_g_free0 (uri);
			}
		}
	}
	_tmp13_ = ((RygelPreferencesSection*) self)->config;
	_tmp14_ = ((RygelPreferencesSection*) self)->name;
	_tmp15_ = uri_list;
	rygel_writable_user_config_set_string_list (_tmp13_, _tmp14_, RYGEL_MEDIA_PREF_SECTION_URIS_KEY, _tmp15_);
	_g_object_unref0 (uri_list);
}


static void
rygel_media_pref_section_real_set_sensitivity (RygelPreferencesSection* base,
                                               gboolean sensitivity)
{
	RygelMediaPrefSection * self;
	self = (RygelMediaPrefSection*) base;
	{
		GeeArrayList* _widget_list = NULL;
		GeeArrayList* _tmp0_;
		GeeArrayList* _tmp1_;
		gint _widget_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _widget_index = 0;
		_tmp0_ = self->priv->widgets;
		_tmp1_ = _g_object_ref0 (_tmp0_);
		_widget_list = _tmp1_;
		_tmp2_ = _widget_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_widget_size = _tmp4_;
		_widget_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			gint _tmp7_;
			GtkWidget* widget = NULL;
			GeeArrayList* _tmp8_;
			gint _tmp9_;
			gpointer _tmp10_;
			GtkWidget* _tmp11_;
			_tmp5_ = _widget_index;
			_widget_index = _tmp5_ + 1;
			_tmp6_ = _widget_index;
			_tmp7_ = _widget_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _widget_list;
			_tmp9_ = _widget_index;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _tmp9_);
			widget = (GtkWidget*) _tmp10_;
			_tmp11_ = widget;
			gtk_widget_set_sensitive (_tmp11_, sensitivity);
			_g_object_unref0 (widget);
		}
		_g_object_unref0 (_widget_list);
	}
	if (sensitivity) {
		rygel_media_pref_section_on_tree_selection_changed (self);
	}
}


static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static inline void
_g_slist_free__g_object_unref0_ (GSList* self)
{
	g_slist_free_full (self, (GDestroyNotify) _g_object_unref0_);
}


static void
rygel_media_pref_section_on_add_button_clicked (RygelMediaPrefSection* self,
                                                GtkToolButton* button)
{
	GtkFileChooserDialog* _tmp0_;
	GtkFileChooserDialog* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = self->priv->dialog;
	if (gtk_dialog_run ((GtkDialog*) _tmp0_) == ((gint) GTK_RESPONSE_OK)) {
		GtkTreeIter iter = {0};
		GSList* dirs = NULL;
		GtkFileChooserDialog* _tmp1_;
		GSList* _tmp2_;
		GSList* _tmp3_;
		_tmp1_ = self->priv->dialog;
		_tmp2_ = gtk_file_chooser_get_files ((GtkFileChooser*) _tmp1_);
		dirs = _tmp2_;
		_tmp3_ = dirs;
		{
			GSList* dir_collection = NULL;
			GSList* dir_it = NULL;
			dir_collection = _tmp3_;
			for (dir_it = dir_collection; dir_it != NULL; dir_it = dir_it->next) {
				GFile* _tmp4_;
				GFile* dir = NULL;
				_tmp4_ = _g_object_ref0 ((GFile*) dir_it->data);
				dir = _tmp4_;
				{
					gchar* path = NULL;
					GFile* _tmp5_;
					gchar* _tmp6_;
					const gchar* _tmp7_;
					GtkListStore* _tmp10_;
					GtkTreeIter _tmp11_ = {0};
					GtkListStore* _tmp12_;
					GtkTreeIter _tmp13_;
					const gchar* _tmp14_;
					_tmp5_ = dir;
					_tmp6_ = g_file_get_path (_tmp5_);
					path = _tmp6_;
					_tmp7_ = path;
					if (_tmp7_ == NULL) {
						GFile* _tmp8_;
						gchar* _tmp9_;
						_tmp8_ = dir;
						_tmp9_ = g_file_get_uri (_tmp8_);
						_g_free0 (path);
						path = _tmp9_;
					}
					_tmp10_ = self->priv->liststore;
					gtk_list_store_append (_tmp10_, &_tmp11_);
					iter = _tmp11_;
					_tmp12_ = self->priv->liststore;
					_tmp13_ = iter;
					_tmp14_ = path;
					gtk_list_store_set (_tmp12_, &_tmp13_, 0, _tmp14_, -1, -1);
					_g_free0 (path);
					_g_object_unref0 (dir);
				}
			}
		}
		(dirs == NULL) ? NULL : (dirs = (_g_slist_free__g_object_unref0_ (dirs), NULL));
	}
	_tmp15_ = self->priv->dialog;
	gtk_widget_hide ((GtkWidget*) _tmp15_);
}


static GtkTreeRowReference*
_vala_GtkTreeRowReference_copy (GtkTreeRowReference* self)
{
	return g_boxed_copy (gtk_tree_row_reference_get_type (), self);
}


static void
_vala_GtkTreeRowReference_free (GtkTreeRowReference* self)
{
	g_boxed_free (gtk_tree_row_reference_get_type (), self);
}


static GtkTreePath*
_vala_GtkTreePath_copy (GtkTreePath* self)
{
	return g_boxed_copy (gtk_tree_path_get_type (), self);
}


static gpointer
__vala_GtkTreePath_copy0 (gpointer self)
{
	return self ? _vala_GtkTreePath_copy (self) : NULL;
}


static void
_vala_GtkTreePath_free (GtkTreePath* self)
{
	g_boxed_free (gtk_tree_path_get_type (), self);
}


static void
__vala_GtkTreePath_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (_vala_GtkTreePath_free (var), NULL));
}


static inline void
_g_list_free___vala_GtkTreePath_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) __vala_GtkTreePath_free0_);
}


static void
rygel_media_pref_section_on_remove_button_clicked (RygelMediaPrefSection* self,
                                                   GtkToolButton* button)
{
	GtkTreeSelection* selection = NULL;
	GtkTreeView* _tmp0_;
	GtkTreeSelection* _tmp1_;
	GtkTreeSelection* _tmp2_;
	GList* rows = NULL;
	GtkTreeSelection* _tmp3_;
	GList* _tmp4_;
	GeeArrayList* row_refs = NULL;
	GeeArrayList* _tmp5_;
	GList* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = self->priv->treeview;
	_tmp1_ = gtk_tree_view_get_selection (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	selection = _tmp2_;
	_tmp3_ = selection;
	_tmp4_ = gtk_tree_selection_get_selected_rows (_tmp3_, NULL);
	rows = _tmp4_;
	_tmp5_ = gee_array_list_new (gtk_tree_row_reference_get_type (), (GBoxedCopyFunc) _vala_GtkTreeRowReference_copy, (GDestroyNotify) _vala_GtkTreeRowReference_free, NULL, NULL, NULL);
	row_refs = _tmp5_;
	_tmp6_ = rows;
	{
		GList* row_collection = NULL;
		GList* row_it = NULL;
		row_collection = _tmp6_;
		for (row_it = row_collection; row_it != NULL; row_it = row_it->next) {
			GtkTreePath* _tmp7_;
			GtkTreePath* row = NULL;
			_tmp7_ = __vala_GtkTreePath_copy0 ((GtkTreePath*) row_it->data);
			row = _tmp7_;
			{
				GeeArrayList* _tmp8_;
				GtkListStore* _tmp9_;
				GtkTreePath* _tmp10_;
				GtkTreeRowReference* _tmp11_;
				GtkTreeRowReference* _tmp12_;
				_tmp8_ = row_refs;
				_tmp9_ = self->priv->liststore;
				_tmp10_ = row;
				_tmp11_ = gtk_tree_row_reference_new ((GtkTreeModel*) _tmp9_, _tmp10_);
				_tmp12_ = _tmp11_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp8_, _tmp12_);
				__vala_GtkTreeRowReference_free0 (_tmp12_);
				__vala_GtkTreePath_free0 (row);
			}
		}
	}
	{
		GeeArrayList* _row_ref_list = NULL;
		GeeArrayList* _tmp13_;
		GeeArrayList* _tmp14_;
		gint _row_ref_size = 0;
		GeeArrayList* _tmp15_;
		gint _tmp16_;
		gint _tmp17_;
		gint _row_ref_index = 0;
		_tmp13_ = row_refs;
		_tmp14_ = _g_object_ref0 (_tmp13_);
		_row_ref_list = _tmp14_;
		_tmp15_ = _row_ref_list;
		_tmp16_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp15_);
		_tmp17_ = _tmp16_;
		_row_ref_size = _tmp17_;
		_row_ref_index = -1;
		while (TRUE) {
			gint _tmp18_;
			gint _tmp19_;
			gint _tmp20_;
			GtkTreeRowReference* row_ref = NULL;
			GeeArrayList* _tmp21_;
			gint _tmp22_;
			gpointer _tmp23_;
			GtkTreeIter iter = {0};
			GtkTreePath* path = NULL;
			GtkTreeRowReference* _tmp24_;
			GtkTreePath* _tmp25_;
			GtkListStore* _tmp26_;
			GtkTreePath* _tmp27_;
			GtkTreeIter _tmp28_ = {0};
			GtkListStore* _tmp29_;
			_tmp18_ = _row_ref_index;
			_row_ref_index = _tmp18_ + 1;
			_tmp19_ = _row_ref_index;
			_tmp20_ = _row_ref_size;
			if (!(_tmp19_ < _tmp20_)) {
				break;
			}
			_tmp21_ = _row_ref_list;
			_tmp22_ = _row_ref_index;
			_tmp23_ = gee_abstract_list_get ((GeeAbstractList*) _tmp21_, _tmp22_);
			row_ref = (GtkTreeRowReference*) _tmp23_;
			_tmp24_ = row_ref;
			_tmp25_ = gtk_tree_row_reference_get_path (_tmp24_);
			path = _tmp25_;
			_tmp26_ = self->priv->liststore;
			_tmp27_ = path;
			gtk_tree_model_get_iter ((GtkTreeModel*) _tmp26_, &_tmp28_, _tmp27_);
			iter = _tmp28_;
			_tmp29_ = self->priv->liststore;
			gtk_list_store_remove (_tmp29_, &iter);
			__vala_GtkTreePath_free0 (path);
			__vala_GtkTreeRowReference_free0 (row_ref);
		}
		_g_object_unref0 (_row_ref_list);
	}
	_g_object_unref0 (row_refs);
	(rows == NULL) ? NULL : (rows = (_g_list_free___vala_GtkTreePath_free0_ (rows), NULL));
	_g_object_unref0 (selection);
}


static gchar*
rygel_media_pref_section_get_real_uri (RygelMediaPrefSection* self,
                                       const gchar* uri)
{
	gchar* result = NULL;
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("@MUSIC@")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp3_;
				gchar* _tmp4_;
				_tmp3_ = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
				_tmp4_ = g_strdup (_tmp3_);
				result = _tmp4_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("@VIDEOS@")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp5_;
				gchar* _tmp6_;
				_tmp5_ = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
				_tmp6_ = g_strdup (_tmp5_);
				result = _tmp6_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("@PICTURES@")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp7_;
				gchar* _tmp8_;
				_tmp7_ = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
				_tmp8_ = g_strdup (_tmp7_);
				result = _tmp8_;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				gchar* _tmp9_;
				_tmp9_ = g_strdup (uri);
				result = _tmp9_;
				return result;
			}
		}
	}
}


static gchar*
rygel_media_pref_section_uri_to_magic_variable (RygelMediaPrefSection* self,
                                                const gchar* uri)
{
	gchar* result = NULL;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
	if (g_strcmp0 (uri, _tmp0_) == 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("@MUSIC@");
		result = _tmp1_;
		return result;
	} else {
		const gchar* _tmp2_;
		_tmp2_ = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
		if (g_strcmp0 (uri, _tmp2_) == 0) {
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("@VIDEOS@");
			result = _tmp3_;
			return result;
		} else {
			const gchar* _tmp4_;
			_tmp4_ = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
			if (g_strcmp0 (uri, _tmp4_) == 0) {
				gchar* _tmp5_;
				_tmp5_ = g_strdup ("@PICTURES@");
				result = _tmp5_;
				return result;
			} else {
				gchar* _tmp6_;
				_tmp6_ = g_strdup (uri);
				result = _tmp6_;
				return result;
			}
		}
	}
}


static void
rygel_media_pref_section_on_tree_selection_changed (RygelMediaPrefSection* self)
{
	GtkTreeSelection* _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->tree_selection;
	_tmp1_ = gtk_tree_selection_get_selected (_tmp0_, NULL, NULL);
	if (_tmp1_) {
		GtkToolButton* _tmp2_;
		_tmp2_ = self->priv->remove_button;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp2_, TRUE);
	} else {
		GtkToolButton* _tmp3_;
		_tmp3_ = self->priv->remove_button;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp3_, FALSE);
	}
}


static void
rygel_media_pref_section_class_init (RygelMediaPrefSectionClass * klass)
{
	rygel_media_pref_section_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelMediaPrefSection_private_offset);
	((RygelPreferencesSectionClass *) klass)->save = (void (*) (RygelPreferencesSection *)) rygel_media_pref_section_real_save;
	((RygelPreferencesSectionClass *) klass)->set_sensitivity = (void (*) (RygelPreferencesSection *, gboolean)) rygel_media_pref_section_real_set_sensitivity;
	G_OBJECT_CLASS (klass)->finalize = rygel_media_pref_section_finalize;
}


static void
rygel_media_pref_section_instance_init (RygelMediaPrefSection * self)
{
	self->priv = rygel_media_pref_section_get_instance_private (self);
}


static void
rygel_media_pref_section_finalize (GObject * obj)
{
	RygelMediaPrefSection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_MEDIA_PREF_SECTION, RygelMediaPrefSection);
	_g_object_unref0 (self->priv->widgets);
	_g_object_unref0 (self->priv->treeview);
	_g_object_unref0 (self->priv->liststore);
	_g_object_unref0 (self->priv->tree_selection);
	_g_object_unref0 (self->priv->dialog);
	_g_object_unref0 (self->priv->remove_button);
	G_OBJECT_CLASS (rygel_media_pref_section_parent_class)->finalize (obj);
}


GType
rygel_media_pref_section_get_type (void)
{
	static volatile gsize rygel_media_pref_section_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_pref_section_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelMediaPrefSectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_pref_section_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaPrefSection), 0, (GInstanceInitFunc) rygel_media_pref_section_instance_init, NULL };
		GType rygel_media_pref_section_type_id;
		rygel_media_pref_section_type_id = g_type_register_static (RYGEL_TYPE_PREFERENCES_SECTION, "RygelMediaPrefSection", &g_define_type_info, 0);
		RygelMediaPrefSection_private_offset = g_type_add_instance_private (rygel_media_pref_section_type_id, sizeof (RygelMediaPrefSectionPrivate));
		g_once_init_leave (&rygel_media_pref_section_type_id__volatile, rygel_media_pref_section_type_id);
	}
	return rygel_media_pref_section_type_id__volatile;
}



