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

/*
 * Copyright (C) 2009,2011 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 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-core.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libgupnp/gupnp.h>
#include <libgssdp/gssdp.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_NETWORK_PREF_SECTION (rygel_network_pref_section_get_type ())
#define RYGEL_NETWORK_PREF_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_NETWORK_PREF_SECTION, RygelNetworkPrefSection))
#define RYGEL_NETWORK_PREF_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_NETWORK_PREF_SECTION, RygelNetworkPrefSectionClass))
#define RYGEL_IS_NETWORK_PREF_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_NETWORK_PREF_SECTION))
#define RYGEL_IS_NETWORK_PREF_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_NETWORK_PREF_SECTION))
#define RYGEL_NETWORK_PREF_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_NETWORK_PREF_SECTION, RygelNetworkPrefSectionClass))

typedef struct _RygelNetworkPrefSection RygelNetworkPrefSection;
typedef struct _RygelNetworkPrefSectionClass RygelNetworkPrefSectionClass;
typedef struct _RygelNetworkPrefSectionPrivate RygelNetworkPrefSectionPrivate;
#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_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (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 _RygelNetworkPrefSection {
	RygelPreferencesSection parent_instance;
	RygelNetworkPrefSectionPrivate * priv;
};

struct _RygelNetworkPrefSectionClass {
	RygelPreferencesSectionClass parent_class;
};

struct _RygelNetworkPrefSectionPrivate {
	GtkComboBoxText* iface_entry;
	GUPnPContextManager* context_manager;
};


static gpointer rygel_network_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_network_pref_section_get_type (void) G_GNUC_CONST;
#define RYGEL_NETWORK_PREF_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_NETWORK_PREF_SECTION, RygelNetworkPrefSectionPrivate))
enum  {
	RYGEL_NETWORK_PREF_SECTION_DUMMY_PROPERTY
};
#define RYGEL_NETWORK_PREF_SECTION_IFACE_ENTRY "iface-entry"
RygelNetworkPrefSection* rygel_network_pref_section_new (GtkBuilder* builder, RygelWritableUserConfig* config, GError** error);
RygelNetworkPrefSection* rygel_network_pref_section_construct (GType object_type, GtkBuilder* builder, RygelWritableUserConfig* config, GError** error);
RygelPreferencesSection* rygel_preferences_section_construct (GType object_type, RygelWritableUserConfig* config, const gchar* name);
static void rygel_network_pref_section_on_context_available (RygelNetworkPrefSection* self, GUPnPContextManager* manager, GUPnPContext* context);
static void _rygel_network_pref_section_on_context_available_gupnp_context_manager_context_available (GUPnPContextManager* _sender, GUPnPContext* p0, gpointer self);
static void rygel_network_pref_section_on_context_unavailable (RygelNetworkPrefSection* self, GUPnPContextManager* manager, GUPnPContext* context);
static void _rygel_network_pref_section_on_context_unavailable_gupnp_context_manager_context_unavailable (GUPnPContextManager* _sender, GUPnPContext* p0, gpointer self);
static void rygel_network_pref_section_real_save (RygelPreferencesSection* base);
void rygel_writable_user_config_set_interface (RygelWritableUserConfig* self, const gchar* value);
static void rygel_network_pref_section_real_set_sensitivity (RygelPreferencesSection* base, gboolean sensitivity);
static gboolean rygel_network_pref_section_find_interface (RygelNetworkPrefSection* self, const gchar* iface, GtkTreeIter* iter);
static void rygel_network_pref_section_finalize (GObject* obj);


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


static void _rygel_network_pref_section_on_context_available_gupnp_context_manager_context_available (GUPnPContextManager* _sender, GUPnPContext* p0, gpointer self) {
	rygel_network_pref_section_on_context_available (self, _sender, p0);
}


static void _rygel_network_pref_section_on_context_unavailable_gupnp_context_manager_context_unavailable (GUPnPContextManager* _sender, GUPnPContext* p0, gpointer self) {
	rygel_network_pref_section_on_context_unavailable (self, _sender, p0);
}


RygelNetworkPrefSection* rygel_network_pref_section_construct (GType object_type, GtkBuilder* builder, RygelWritableUserConfig* config, GError** error) {
	RygelNetworkPrefSection * self = NULL;
	RygelWritableUserConfig* _tmp0_;
	GtkBuilder* _tmp1_;
	GObject* _tmp2_ = NULL;
	GtkComboBoxText* _tmp3_;
	GtkComboBoxText* _tmp4_;
	GUPnPContextManager* _tmp5_;
	GUPnPContextManager* _tmp12_;
	GUPnPContextManager* _tmp13_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (builder != NULL, NULL);
	g_return_val_if_fail (config != NULL, NULL);
	_tmp0_ = config;
	self = (RygelNetworkPrefSection*) rygel_preferences_section_construct (object_type, _tmp0_, "general");
	_tmp1_ = builder;
	_tmp2_ = gtk_builder_get_object (_tmp1_, RYGEL_NETWORK_PREF_SECTION_IFACE_ENTRY);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GTK_TYPE_COMBO_BOX_TEXT, GtkComboBoxText));
	_g_object_unref0 (self->priv->iface_entry);
	self->priv->iface_entry = _tmp3_;
	_tmp4_ = self->priv->iface_entry;
	_vala_assert (_tmp4_ != NULL, "this.iface_entry != null");
	_tmp5_ = gupnp_context_manager_new (NULL, (guint) 0);
	_g_object_unref0 (self->priv->context_manager);
	self->priv->context_manager = _tmp5_;
	{
		RygelWritableUserConfig* _tmp6_;
		gchar* _tmp7_ = NULL;
		gchar* _tmp8_;
		GtkComboBoxText* _tmp9_;
		gchar* _tmp10_;
		GtkComboBoxText* _tmp11_;
		_tmp6_ = config;
		_tmp7_ = rygel_configuration_get_interface ((RygelConfiguration*) _tmp6_, &_inner_error_);
		_tmp8_ = _tmp7_;
		if (_inner_error_ != NULL) {
			goto __catch8_g_error;
		}
		_tmp9_ = self->priv->iface_entry;
		_tmp10_ = _tmp8_;
		gtk_combo_box_text_append_text (_tmp9_, _tmp10_);
		_g_free0 (_tmp10_);
		_tmp11_ = self->priv->iface_entry;
		gtk_combo_box_set_active ((GtkComboBox*) _tmp11_, 0);
	}
	goto __finally8;
	__catch8_g_error:
	{
		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 (self);
		return NULL;
	}
	_tmp12_ = self->priv->context_manager;
	g_signal_connect_object (_tmp12_, "context-available", (GCallback) _rygel_network_pref_section_on_context_available_gupnp_context_manager_context_available, self, 0);
	_tmp13_ = self->priv->context_manager;
	g_signal_connect_object (_tmp13_, "context-unavailable", (GCallback) _rygel_network_pref_section_on_context_unavailable_gupnp_context_manager_context_unavailable, self, 0);
	return self;
}


RygelNetworkPrefSection* rygel_network_pref_section_new (GtkBuilder* builder, RygelWritableUserConfig* config, GError** error) {
	return rygel_network_pref_section_construct (RYGEL_TYPE_NETWORK_PREF_SECTION, builder, config, error);
}


static void rygel_network_pref_section_real_save (RygelPreferencesSection* base) {
	RygelNetworkPrefSection * self;
	GtkComboBoxText* _tmp0_;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* iface;
	GtkComboBoxText* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	RygelWritableUserConfig* _tmp7_;
	const gchar* _tmp8_;
	self = (RygelNetworkPrefSection*) base;
	_tmp0_ = self->priv->iface_entry;
	_tmp1_ = gtk_combo_box_text_get_active_text (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	iface = _tmp2_;
	_tmp3_ = self->priv->iface_entry;
	_tmp4_ = gtk_combo_box_get_active ((GtkComboBox*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ <= 0) {
		gchar* _tmp6_;
		_tmp6_ = g_strdup ("");
		_g_free0 (iface);
		iface = _tmp6_;
	}
	_tmp7_ = ((RygelPreferencesSection*) self)->config;
	_tmp8_ = iface;
	rygel_writable_user_config_set_interface (_tmp7_, _tmp8_);
	_g_free0 (iface);
}


static void rygel_network_pref_section_real_set_sensitivity (RygelPreferencesSection* base, gboolean sensitivity) {
	RygelNetworkPrefSection * self;
	GtkComboBoxText* _tmp0_;
	gboolean _tmp1_;
	self = (RygelNetworkPrefSection*) base;
	_tmp0_ = self->priv->iface_entry;
	_tmp1_ = sensitivity;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, _tmp1_);
}


static void rygel_network_pref_section_on_context_available (RygelNetworkPrefSection* self, GUPnPContextManager* manager, GUPnPContext* context) {
	GtkTreeIter iter = {0};
	GUPnPContext* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (manager != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = context;
	_tmp1_ = gssdp_client_get_interface ((GSSDPClient*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp4_ = rygel_network_pref_section_find_interface (self, _tmp2_, &_tmp3_);
	iter = _tmp3_;
	if (!_tmp4_) {
		GtkComboBoxText* _tmp5_;
		GUPnPContext* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		_tmp5_ = self->priv->iface_entry;
		_tmp6_ = context;
		_tmp7_ = gssdp_client_get_interface ((GSSDPClient*) _tmp6_);
		_tmp8_ = _tmp7_;
		gtk_combo_box_text_append_text (_tmp5_, _tmp8_);
	}
}


static void rygel_network_pref_section_on_context_unavailable (RygelNetworkPrefSection* self, GUPnPContextManager* manager, GUPnPContext* context) {
	GtkTreeIter iter = {0};
	GUPnPContext* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (manager != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = context;
	_tmp1_ = gssdp_client_get_interface ((GSSDPClient*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp4_ = rygel_network_pref_section_find_interface (self, _tmp2_, &_tmp3_);
	iter = _tmp3_;
	if (_tmp4_) {
		GtkComboBoxText* _tmp5_;
		GtkTreeModel* _tmp6_;
		GtkTreeModel* _tmp7_;
		GtkListStore* _tmp8_;
		GtkListStore* list_store;
		GtkListStore* _tmp9_;
		GtkTreeIter _tmp10_;
		_tmp5_ = self->priv->iface_entry;
		_tmp6_ = gtk_combo_box_get_model ((GtkComboBox*) _tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, GTK_TYPE_LIST_STORE) ? ((GtkListStore*) _tmp7_) : NULL);
		list_store = _tmp8_;
		_tmp9_ = list_store;
		_tmp10_ = iter;
		gtk_list_store_remove (_tmp9_, &_tmp10_);
		_g_object_unref0 (list_store);
	}
}


static gboolean rygel_network_pref_section_find_interface (RygelNetworkPrefSection* self, const gchar* iface, GtkTreeIter* iter) {
	GtkTreeIter _vala_iter = {0};
	gboolean result = FALSE;
	GtkComboBoxText* _tmp0_;
	GtkTreeModel* _tmp1_;
	GtkTreeModel* _tmp2_;
	GtkTreeModel* _tmp3_;
	GtkTreeModel* model;
	GtkTreeModel* _tmp4_;
	GtkTreeIter _tmp5_ = {0};
	gboolean _tmp6_ = FALSE;
	gboolean more;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (iface != NULL, FALSE);
	_tmp0_ = self->priv->iface_entry;
	_tmp1_ = gtk_combo_box_get_model ((GtkComboBox*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	model = _tmp3_;
	_tmp4_ = model;
	_tmp6_ = gtk_tree_model_get_iter_first (_tmp4_, &_tmp5_);
	_vala_iter = _tmp5_;
	more = _tmp6_;
	while (TRUE) {
		gboolean _tmp7_;
		GtkTreeModel* _tmp8_;
		GtkTreeIter _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		GtkTreeModel* _tmp12_;
		gboolean _tmp13_ = FALSE;
		_tmp7_ = more;
		if (!_tmp7_) {
			break;
		}
		_tmp8_ = model;
		_tmp9_ = _vala_iter;
		gtk_tree_model_get (_tmp8_, &_tmp9_, 0, &((RygelPreferencesSection*) self)->name, -1, -1);
		_tmp10_ = ((RygelPreferencesSection*) self)->name;
		_tmp11_ = iface;
		if (g_strcmp0 (_tmp10_, _tmp11_) == 0) {
			break;
		}
		_tmp12_ = model;
		_tmp13_ = gtk_tree_model_iter_next (_tmp12_, &_vala_iter);
		more = _tmp13_;
	}
	result = more;
	_g_object_unref0 (model);
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}


static void rygel_network_pref_section_class_init (RygelNetworkPrefSectionClass * klass) {
	rygel_network_pref_section_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelNetworkPrefSectionPrivate));
	RYGEL_PREFERENCES_SECTION_CLASS (klass)->save = rygel_network_pref_section_real_save;
	RYGEL_PREFERENCES_SECTION_CLASS (klass)->set_sensitivity = rygel_network_pref_section_real_set_sensitivity;
	G_OBJECT_CLASS (klass)->finalize = rygel_network_pref_section_finalize;
}


static void rygel_network_pref_section_instance_init (RygelNetworkPrefSection * self) {
	self->priv = RYGEL_NETWORK_PREF_SECTION_GET_PRIVATE (self);
}


static void rygel_network_pref_section_finalize (GObject* obj) {
	RygelNetworkPrefSection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_NETWORK_PREF_SECTION, RygelNetworkPrefSection);
	_g_object_unref0 (self->priv->iface_entry);
	_g_object_unref0 (self->priv->context_manager);
	G_OBJECT_CLASS (rygel_network_pref_section_parent_class)->finalize (obj);
}


GType rygel_network_pref_section_get_type (void) {
	static volatile gsize rygel_network_pref_section_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_network_pref_section_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelNetworkPrefSectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_network_pref_section_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelNetworkPrefSection), 0, (GInstanceInitFunc) rygel_network_pref_section_instance_init, NULL };
		GType rygel_network_pref_section_type_id;
		rygel_network_pref_section_type_id = g_type_register_static (RYGEL_TYPE_PREFERENCES_SECTION, "RygelNetworkPrefSection", &g_define_type_info, 0);
		g_once_init_leave (&rygel_network_pref_section_type_id__volatile, rygel_network_pref_section_type_id);
	}
	return rygel_network_pref_section_type_id__volatile;
}



