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

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>

#define TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER (tootle_widgets_visibility_popover_get_type ())
#define TOOTLE_WIDGETS_VISIBILITY_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopover))
#define TOOTLE_WIDGETS_VISIBILITY_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopoverClass))
#define TOOTLE_WIDGETS_IS_VISIBILITY_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER))
#define TOOTLE_WIDGETS_IS_VISIBILITY_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER))
#define TOOTLE_WIDGETS_VISIBILITY_POPOVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopoverClass))

typedef struct _TootleWidgetsVisibilityPopover TootleWidgetsVisibilityPopover;
typedef struct _TootleWidgetsVisibilityPopoverClass TootleWidgetsVisibilityPopoverClass;
typedef struct _TootleWidgetsVisibilityPopoverPrivate TootleWidgetsVisibilityPopoverPrivate;
typedef enum  {
	TOOTLE_API_VISIBILITY_PUBLIC,
	TOOTLE_API_VISIBILITY_UNLISTED,
	TOOTLE_API_VISIBILITY_PRIVATE,
	TOOTLE_API_VISIBILITY_DIRECT
} TootleAPIVisibility;

#define TOOTLE_API_TYPE_VISIBILITY (tootle_api_visibility_get_type ())
enum  {
	TOOTLE_WIDGETS_VISIBILITY_POPOVER_0_PROPERTY,
	TOOTLE_WIDGETS_VISIBILITY_POPOVER_SELECTED_PROPERTY,
	TOOTLE_WIDGETS_VISIBILITY_POPOVER_NUM_PROPERTIES
};
static GParamSpec* tootle_widgets_visibility_popover_properties[TOOTLE_WIDGETS_VISIBILITY_POPOVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block26Data Block26Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _TootleWidgetsVisibilityPopover {
	GtkPopover parent_instance;
	TootleWidgetsVisibilityPopoverPrivate * priv;
};

struct _TootleWidgetsVisibilityPopoverClass {
	GtkPopoverClass parent_class;
};

struct _TootleWidgetsVisibilityPopoverPrivate {
	TootleAPIVisibility _selected;
	GtkRadioButton* group_owner;
	GtkMenuButton* button;
};

struct _Block26Data {
	int _ref_count_;
	TootleWidgetsVisibilityPopover* self;
	TootleAPIVisibility item;
};

static gint TootleWidgetsVisibilityPopover_private_offset;
static gpointer tootle_widgets_visibility_popover_parent_class = NULL;

GType tootle_widgets_visibility_popover_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleWidgetsVisibilityPopover, g_object_unref)
GType tootle_api_visibility_get_type (void) G_GNUC_CONST ;
TootleWidgetsVisibilityPopover* tootle_widgets_visibility_popover_new_with_button (GtkMenuButton* w);
TootleWidgetsVisibilityPopover* tootle_widgets_visibility_popover_construct_with_button (GType object_type,
                                                                                         GtkMenuButton* w);
void tootle_widgets_visibility_popover_invalidate (TootleWidgetsVisibilityPopover* self);
static void __lambda56_ (TootleWidgetsVisibilityPopover* self,
                  GtkRadioButton* w);
TootleAPIVisibility tootle_widgets_visibility_popover_get_selected (TootleWidgetsVisibilityPopover* self);
static void ___lambda56__gfunc (gconstpointer data,
                         gpointer self);
TootleWidgetsVisibilityPopover* tootle_widgets_visibility_popover_new (void);
TootleWidgetsVisibilityPopover* tootle_widgets_visibility_popover_construct (GType object_type);
void tootle_widgets_visibility_popover_set_selected (TootleWidgetsVisibilityPopover* self,
                                                     TootleAPIVisibility value);
static GObject * tootle_widgets_visibility_popover_constructor (GType type,
                                                         guint n_construct_properties,
                                                         GObjectConstructParam * construct_properties);
TootleAPIVisibility* tootle_api_visibility_all (gint* result_length1);
static Block26Data* block26_data_ref (Block26Data* _data26_);
static void block26_data_unref (void * _userdata_);
static void _tootle_widgets_visibility_popover_____lambda57_ (Block26Data* _data26_);
static void __tootle_widgets_visibility_popover_____lambda57__gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                  gpointer self);
gchar* tootle_api_visibility_get_name (TootleAPIVisibility self);
gchar* tootle_api_visibility_get_desc (TootleAPIVisibility self);
static void tootle_widgets_visibility_popover_finalize (GObject * obj);
static GType tootle_widgets_visibility_popover_get_type_once (void);
static void _vala_tootle_widgets_visibility_popover_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec);
static void _vala_tootle_widgets_visibility_popover_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
tootle_widgets_visibility_popover_get_instance_private (TootleWidgetsVisibilityPopover* self)
{
	return G_STRUCT_MEMBER_P (self, TootleWidgetsVisibilityPopover_private_offset);
}

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

TootleWidgetsVisibilityPopover*
tootle_widgets_visibility_popover_construct_with_button (GType object_type,
                                                         GtkMenuButton* w)
{
	TootleWidgetsVisibilityPopover * self = NULL;
	GtkMenuButton* _tmp0_;
	GtkMenuButton* _tmp1_;
	g_return_val_if_fail (w != NULL, NULL);
	self = (TootleWidgetsVisibilityPopover*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (w);
	_g_object_unref0 (self->priv->button);
	self->priv->button = _tmp0_;
	_tmp1_ = self->priv->button;
	gtk_menu_button_set_popover (_tmp1_, (GtkPopover*) self);
	return self;
}

TootleWidgetsVisibilityPopover*
tootle_widgets_visibility_popover_new_with_button (GtkMenuButton* w)
{
	return tootle_widgets_visibility_popover_construct_with_button (TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, w);
}

static void
__lambda56_ (TootleWidgetsVisibilityPopover* self,
             GtkRadioButton* w)
{
	gint i = 0;
	gconstpointer _tmp0_;
	TootleAPIVisibility _tmp1_;
	g_return_if_fail (w != NULL);
	_tmp0_ = g_object_get_data ((GObject*) w, "i");
	i = (gint) ((gintptr) _tmp0_);
	_tmp1_ = self->priv->_selected;
	if (i == ((gint) _tmp1_)) {
		gtk_toggle_button_set_active ((GtkToggleButton*) w, TRUE);
	}
}

static void
___lambda56__gfunc (gconstpointer data,
                    gpointer self)
{
	__lambda56_ ((TootleWidgetsVisibilityPopover*) self, (GtkRadioButton*) data);
}

void
tootle_widgets_visibility_popover_invalidate (TootleWidgetsVisibilityPopover* self)
{
	GSList* group = NULL;
	GtkRadioButton* _tmp0_;
	GSList* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->group_owner;
	_tmp1_ = gtk_radio_button_get_group (_tmp0_);
	group = _tmp1_;
	g_slist_foreach (group, ___lambda56__gfunc, self);
}

TootleWidgetsVisibilityPopover*
tootle_widgets_visibility_popover_construct (GType object_type)
{
	TootleWidgetsVisibilityPopover * self = NULL;
	self = (TootleWidgetsVisibilityPopover*) g_object_new (object_type, NULL);
	return self;
}

TootleWidgetsVisibilityPopover*
tootle_widgets_visibility_popover_new (void)
{
	return tootle_widgets_visibility_popover_construct (TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER);
}

TootleAPIVisibility
tootle_widgets_visibility_popover_get_selected (TootleWidgetsVisibilityPopover* self)
{
	TootleAPIVisibility result;
	TootleAPIVisibility _tmp0_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_selected;
	result = _tmp0_;
	return result;
}

void
tootle_widgets_visibility_popover_set_selected (TootleWidgetsVisibilityPopover* self,
                                                TootleAPIVisibility value)
{
	TootleAPIVisibility old_value;
	g_return_if_fail (self != NULL);
	old_value = tootle_widgets_visibility_popover_get_selected (self);
	if (old_value != value) {
		self->priv->_selected = value;
		g_object_notify_by_pspec ((GObject *) self, tootle_widgets_visibility_popover_properties[TOOTLE_WIDGETS_VISIBILITY_POPOVER_SELECTED_PROPERTY]);
	}
}

static Block26Data*
block26_data_ref (Block26Data* _data26_)
{
	g_atomic_int_inc (&_data26_->_ref_count_);
	return _data26_;
}

static void
block26_data_unref (void * _userdata_)
{
	Block26Data* _data26_;
	_data26_ = (Block26Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data26_->_ref_count_)) {
		TootleWidgetsVisibilityPopover* self;
		self = _data26_->self;
		_g_object_unref0 (self);
		g_slice_free (Block26Data, _data26_);
	}
}

static void
_tootle_widgets_visibility_popover_____lambda57_ (Block26Data* _data26_)
{
	TootleWidgetsVisibilityPopover* self;
	TootleAPIVisibility _tmp0_;
	self = _data26_->self;
	_tmp0_ = _data26_->item;
	tootle_widgets_visibility_popover_set_selected (self, _tmp0_);
	gtk_popover_popdown ((GtkPopover*) self);
}

static void
__tootle_widgets_visibility_popover_____lambda57__gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                             gpointer self)
{
	_tootle_widgets_visibility_popover_____lambda57_ (self);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static GObject *
tootle_widgets_visibility_popover_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	TootleWidgetsVisibilityPopover * self;
	GtkBox* box = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	gint i = 0;
	gint _tmp4_ = 0;
	TootleAPIVisibility* _tmp5_;
	GtkBox* _tmp34_;
	parent_class = G_OBJECT_CLASS (tootle_widgets_visibility_popover_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopover);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp0_);
	box = _tmp0_;
	_tmp1_ = box;
	g_object_set ((GtkWidget*) _tmp1_, "margin", 12, NULL);
	_tmp2_ = box;
	gtk_widget_show ((GtkWidget*) _tmp2_);
	_tmp3_ = box;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp3_);
	i = 0;
	_tmp5_ = tootle_api_visibility_all (&_tmp4_);
	{
		TootleAPIVisibility* item_collection = NULL;
		gint item_collection_length1 = 0;
		gint _item_collection_size_ = 0;
		gint item_it = 0;
		item_collection = _tmp5_;
		item_collection_length1 = _tmp4_;
		for (item_it = 0; item_it < item_collection_length1; item_it = item_it + 1) {
			TootleAPIVisibility item = 0;
			item = item_collection[item_it];
			{
				Block26Data* _data26_;
				GtkRadioButton* radio = NULL;
				GtkRadioButton* _tmp6_;
				GtkRadioButton* _tmp7_;
				GtkRadioButton* _tmp8_;
				TootleAPIVisibility _tmp9_;
				GtkRadioButton* _tmp10_;
				GtkBox* _tmp13_;
				GtkRadioButton* _tmp14_;
				GtkRadioButton* _tmp15_;
				GtkLabel* label = NULL;
				TootleAPIVisibility _tmp16_;
				gchar* _tmp17_;
				gchar* _tmp18_;
				const gchar* _tmp19_;
				TootleAPIVisibility _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				const gchar* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				GtkLabel* _tmp26_;
				GtkLabel* _tmp27_;
				GtkLabel* _tmp28_;
				GtkLabel* _tmp29_;
				GtkLabel* _tmp30_;
				GtkRadioButton* _tmp31_;
				GtkLabel* _tmp32_;
				gint _tmp33_;
				_data26_ = g_slice_new0 (Block26Data);
				_data26_->_ref_count_ = 1;
				_data26_->self = g_object_ref (self);
				_data26_->item = item;
				_tmp6_ = self->priv->group_owner;
				_tmp7_ = (GtkRadioButton*) gtk_radio_button_new_from_widget (_tmp6_);
				g_object_ref_sink (_tmp7_);
				radio = _tmp7_;
				_tmp8_ = radio;
				_tmp9_ = _data26_->item;
				g_object_set_data_full ((GObject*) _tmp8_, "i", (gpointer) ((gintptr) _tmp9_), NULL);
				_tmp10_ = self->priv->group_owner;
				if (_tmp10_ == NULL) {
					GtkRadioButton* _tmp11_;
					GtkRadioButton* _tmp12_;
					_tmp11_ = radio;
					_tmp12_ = _g_object_ref0 (_tmp11_);
					_g_object_unref0 (self->priv->group_owner);
					self->priv->group_owner = _tmp12_;
				}
				_tmp13_ = box;
				_tmp14_ = radio;
				gtk_box_pack_start (_tmp13_, (GtkWidget*) _tmp14_, TRUE, TRUE, (guint) 0);
				_tmp15_ = radio;
				g_signal_connect_data ((GtkToggleButton*) _tmp15_, "toggled", (GCallback) __tootle_widgets_visibility_popover_____lambda57__gtk_toggle_button_toggled, block26_data_ref (_data26_), (GClosureNotify) block26_data_unref, 0);
				_tmp16_ = _data26_->item;
				_tmp17_ = tootle_api_visibility_get_name (_tmp16_);
				_tmp18_ = _tmp17_;
				_tmp19_ = string_to_string (_tmp18_);
				_tmp20_ = _data26_->item;
				_tmp21_ = tootle_api_visibility_get_desc (_tmp20_);
				_tmp22_ = _tmp21_;
				_tmp23_ = string_to_string (_tmp22_);
				_tmp24_ = g_strconcat ("<b>", _tmp19_, "</b>\n", _tmp23_, NULL);
				_tmp25_ = _tmp24_;
				_tmp26_ = (GtkLabel*) gtk_label_new (_tmp25_);
				g_object_ref_sink (_tmp26_);
				_tmp27_ = _tmp26_;
				_g_free0 (_tmp25_);
				_g_free0 (_tmp22_);
				_g_free0 (_tmp18_);
				label = _tmp27_;
				_tmp28_ = label;
				gtk_label_set_use_markup (_tmp28_, TRUE);
				_tmp29_ = label;
				gtk_label_set_xalign (_tmp29_, (gfloat) 0);
				_tmp30_ = label;
				gtk_widget_set_margin_start ((GtkWidget*) _tmp30_, 8);
				_tmp31_ = radio;
				_tmp32_ = label;
				gtk_container_add ((GtkContainer*) _tmp31_, (GtkWidget*) _tmp32_);
				_tmp33_ = i;
				i = _tmp33_ + 1;
				_g_object_unref0 (label);
				_g_object_unref0 (radio);
				block26_data_unref (_data26_);
				_data26_ = NULL;
			}
		}
		item_collection = (g_free (item_collection), NULL);
	}
	_tmp34_ = box;
	gtk_widget_show_all ((GtkWidget*) _tmp34_);
	_g_object_unref0 (box);
	return obj;
}

static void
tootle_widgets_visibility_popover_class_init (TootleWidgetsVisibilityPopoverClass * klass,
                                              gpointer klass_data)
{
	tootle_widgets_visibility_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &TootleWidgetsVisibilityPopover_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_tootle_widgets_visibility_popover_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_tootle_widgets_visibility_popover_set_property;
	G_OBJECT_CLASS (klass)->constructor = tootle_widgets_visibility_popover_constructor;
	G_OBJECT_CLASS (klass)->finalize = tootle_widgets_visibility_popover_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TOOTLE_WIDGETS_VISIBILITY_POPOVER_SELECTED_PROPERTY, tootle_widgets_visibility_popover_properties[TOOTLE_WIDGETS_VISIBILITY_POPOVER_SELECTED_PROPERTY] = g_param_spec_enum ("selected", "selected", "selected", TOOTLE_API_TYPE_VISIBILITY, TOOTLE_API_VISIBILITY_PUBLIC, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
tootle_widgets_visibility_popover_instance_init (TootleWidgetsVisibilityPopover * self,
                                                 gpointer klass)
{
	self->priv = tootle_widgets_visibility_popover_get_instance_private (self);
	self->priv->_selected = TOOTLE_API_VISIBILITY_PUBLIC;
}

static void
tootle_widgets_visibility_popover_finalize (GObject * obj)
{
	TootleWidgetsVisibilityPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopover);
	_g_object_unref0 (self->priv->group_owner);
	_g_object_unref0 (self->priv->button);
	G_OBJECT_CLASS (tootle_widgets_visibility_popover_parent_class)->finalize (obj);
}

static GType
tootle_widgets_visibility_popover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TootleWidgetsVisibilityPopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tootle_widgets_visibility_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TootleWidgetsVisibilityPopover), 0, (GInstanceInitFunc) tootle_widgets_visibility_popover_instance_init, NULL };
	GType tootle_widgets_visibility_popover_type_id;
	tootle_widgets_visibility_popover_type_id = g_type_register_static (gtk_popover_get_type (), "TootleWidgetsVisibilityPopover", &g_define_type_info, 0);
	TootleWidgetsVisibilityPopover_private_offset = g_type_add_instance_private (tootle_widgets_visibility_popover_type_id, sizeof (TootleWidgetsVisibilityPopoverPrivate));
	return tootle_widgets_visibility_popover_type_id;
}

GType
tootle_widgets_visibility_popover_get_type (void)
{
	static volatile gsize tootle_widgets_visibility_popover_type_id__volatile = 0;
	if (g_once_init_enter (&tootle_widgets_visibility_popover_type_id__volatile)) {
		GType tootle_widgets_visibility_popover_type_id;
		tootle_widgets_visibility_popover_type_id = tootle_widgets_visibility_popover_get_type_once ();
		g_once_init_leave (&tootle_widgets_visibility_popover_type_id__volatile, tootle_widgets_visibility_popover_type_id);
	}
	return tootle_widgets_visibility_popover_type_id__volatile;
}

static void
_vala_tootle_widgets_visibility_popover_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec)
{
	TootleWidgetsVisibilityPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopover);
	switch (property_id) {
		case TOOTLE_WIDGETS_VISIBILITY_POPOVER_SELECTED_PROPERTY:
		g_value_set_enum (value, tootle_widgets_visibility_popover_get_selected (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_tootle_widgets_visibility_popover_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec)
{
	TootleWidgetsVisibilityPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TOOTLE_WIDGETS_TYPE_VISIBILITY_POPOVER, TootleWidgetsVisibilityPopover);
	switch (property_id) {
		case TOOTLE_WIDGETS_VISIBILITY_POPOVER_SELECTED_PROPERTY:
		tootle_widgets_visibility_popover_set_selected (self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

