/* IndicatorBar.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from IndicatorBar.vala, do not modify */

/*
 * Copyright (c) 2011-2015 Wingpanel Developers (http://launchpad.net/wingpanel)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gee.h>
#include <glib.h>
#include "wingpanel.h"
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR (wingpanel_widgets_indicator_bar_get_type ())
#define WINGPANEL_WIDGETS_INDICATOR_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR, WingpanelWidgetsIndicatorBar))
#define WINGPANEL_WIDGETS_INDICATOR_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR, WingpanelWidgetsIndicatorBarClass))
#define WINGPANEL_WIDGETS_IS_INDICATOR_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR))
#define WINGPANEL_WIDGETS_IS_INDICATOR_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR))
#define WINGPANEL_WIDGETS_INDICATOR_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR, WingpanelWidgetsIndicatorBarClass))

typedef struct _WingpanelWidgetsIndicatorBar WingpanelWidgetsIndicatorBar;
typedef struct _WingpanelWidgetsIndicatorBarClass WingpanelWidgetsIndicatorBarClass;
typedef struct _WingpanelWidgetsIndicatorBarPrivate WingpanelWidgetsIndicatorBarPrivate;

#define WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY (wingpanel_widgets_indicator_entry_get_type ())
#define WINGPANEL_WIDGETS_INDICATOR_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY, WingpanelWidgetsIndicatorEntry))
#define WINGPANEL_WIDGETS_INDICATOR_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY, WingpanelWidgetsIndicatorEntryClass))
#define WINGPANEL_WIDGETS_IS_INDICATOR_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY))
#define WINGPANEL_WIDGETS_IS_INDICATOR_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY))
#define WINGPANEL_WIDGETS_INDICATOR_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY, WingpanelWidgetsIndicatorEntryClass))

typedef struct _WingpanelWidgetsIndicatorEntry WingpanelWidgetsIndicatorEntry;
typedef struct _WingpanelWidgetsIndicatorEntryClass WingpanelWidgetsIndicatorEntryClass;

#define WINGPANEL_SERVICES_TYPE_INDICATOR_SORTER (wingpanel_services_indicator_sorter_get_type ())
#define WINGPANEL_SERVICES_INDICATOR_SORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINGPANEL_SERVICES_TYPE_INDICATOR_SORTER, WingpanelServicesIndicatorSorter))
#define WINGPANEL_SERVICES_INDICATOR_SORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WINGPANEL_SERVICES_TYPE_INDICATOR_SORTER, WingpanelServicesIndicatorSorterClass))
#define WINGPANEL_SERVICES_IS_INDICATOR_SORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINGPANEL_SERVICES_TYPE_INDICATOR_SORTER))
#define WINGPANEL_SERVICES_IS_INDICATOR_SORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WINGPANEL_SERVICES_TYPE_INDICATOR_SORTER))
#define WINGPANEL_SERVICES_INDICATOR_SORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WINGPANEL_SERVICES_TYPE_INDICATOR_SORTER, WingpanelServicesIndicatorSorterClass))

typedef struct _WingpanelServicesIndicatorSorter WingpanelServicesIndicatorSorter;
typedef struct _WingpanelServicesIndicatorSorterClass WingpanelServicesIndicatorSorterClass;
enum  {
	WINGPANEL_WIDGETS_INDICATOR_BAR_0_PROPERTY,
	WINGPANEL_WIDGETS_INDICATOR_BAR_NUM_PROPERTIES
};
static GParamSpec* wingpanel_widgets_indicator_bar_properties[WINGPANEL_WIDGETS_INDICATOR_BAR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _WingpanelWidgetsIndicatorEntryPrivate WingpanelWidgetsIndicatorEntryPrivate;

struct _WingpanelWidgetsIndicatorBar {
	GtkBox parent_instance;
	WingpanelWidgetsIndicatorBarPrivate * priv;
};

struct _WingpanelWidgetsIndicatorBarClass {
	GtkBoxClass parent_class;
};

struct _WingpanelWidgetsIndicatorBarPrivate {
	GeeList* sorted_items;
	WingpanelServicesIndicatorSorter* sorter;
};

struct _WingpanelWidgetsIndicatorEntry {
	GtkEventBox parent_instance;
	WingpanelWidgetsIndicatorEntryPrivate * priv;
	WingpanelWidgetsIndicatorBar* indicator_bar;
};

struct _WingpanelWidgetsIndicatorEntryClass {
	GtkEventBoxClass parent_class;
};

static gint WingpanelWidgetsIndicatorBar_private_offset;
static gpointer wingpanel_widgets_indicator_bar_parent_class = NULL;

VALA_EXTERN GType wingpanel_widgets_indicator_bar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WingpanelWidgetsIndicatorBar, g_object_unref)
VALA_EXTERN GType wingpanel_widgets_indicator_entry_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WingpanelWidgetsIndicatorEntry, g_object_unref)
VALA_EXTERN GType wingpanel_services_indicator_sorter_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WingpanelServicesIndicatorSorter, g_object_unref)
VALA_EXTERN WingpanelServicesIndicatorSorter* wingpanel_services_indicator_sorter_new (void);
VALA_EXTERN WingpanelServicesIndicatorSorter* wingpanel_services_indicator_sorter_construct (GType object_type);
VALA_EXTERN void wingpanel_widgets_indicator_bar_insert_sorted (WingpanelWidgetsIndicatorBar* self,
                                                    WingpanelWidgetsIndicatorEntry* item);
VALA_EXTERN gint wingpanel_services_indicator_sorter_compare_func (WingpanelServicesIndicatorSorter* self,
                                                       WingpanelWidgetsIndicatorEntry* a,
                                                       WingpanelWidgetsIndicatorEntry* b);
static gint _wingpanel_services_indicator_sorter_compare_func_gcompare_data_func (gconstpointer a,
                                                                           gconstpointer b,
                                                                           gpointer self);
VALA_EXTERN WingpanelIndicator* wingpanel_widgets_indicator_entry_get_base_indicator (WingpanelWidgetsIndicatorEntry* self);
VALA_EXTERN void wingpanel_widgets_indicator_bar_remove_indicator (WingpanelWidgetsIndicatorBar* self,
                                                       WingpanelIndicator* indicator);
VALA_EXTERN WingpanelWidgetsIndicatorBar* wingpanel_widgets_indicator_bar_new (void);
VALA_EXTERN WingpanelWidgetsIndicatorBar* wingpanel_widgets_indicator_bar_construct (GType object_type);
static GObject * wingpanel_widgets_indicator_bar_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static void wingpanel_widgets_indicator_bar_finalize (GObject * obj);
static GType wingpanel_widgets_indicator_bar_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
wingpanel_widgets_indicator_bar_get_instance_private (WingpanelWidgetsIndicatorBar* self)
{
	return G_STRUCT_MEMBER_P (self, WingpanelWidgetsIndicatorBar_private_offset);
}

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

static gint
_wingpanel_services_indicator_sorter_compare_func_gcompare_data_func (gconstpointer a,
                                                                      gconstpointer b,
                                                                      gpointer self)
{
	gint result;
	result = wingpanel_services_indicator_sorter_compare_func ((WingpanelServicesIndicatorSorter*) self, (WingpanelWidgetsIndicatorEntry*) a, (WingpanelWidgetsIndicatorEntry*) b);
	return result;
}

void
wingpanel_widgets_indicator_bar_insert_sorted (WingpanelWidgetsIndicatorBar* self,
                                               WingpanelWidgetsIndicatorEntry* item)
{
	WingpanelWidgetsIndicatorBar* _tmp0_;
	GeeList* _tmp1_;
	WingpanelIndicator* _tmp5_;
	WingpanelIndicator* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = _g_object_ref0 (self);
	_g_object_unref0 (item->indicator_bar);
	item->indicator_bar = _tmp0_;
	_tmp1_ = self->priv->sorted_items;
	if (!gee_collection_contains ((GeeCollection*) _tmp1_, item)) {
		GeeList* _tmp2_;
		GeeList* _tmp3_;
		WingpanelServicesIndicatorSorter* _tmp4_;
		_tmp2_ = self->priv->sorted_items;
		gee_collection_add ((GeeCollection*) _tmp2_, item);
		_tmp3_ = self->priv->sorted_items;
		_tmp4_ = self->priv->sorter;
		gee_list_sort (_tmp3_, _wingpanel_services_indicator_sorter_compare_func_gcompare_data_func, g_object_ref (_tmp4_), g_object_unref);
	}
	_tmp5_ = wingpanel_widgets_indicator_entry_get_base_indicator (item);
	_tmp6_ = _tmp5_;
	_tmp7_ = wingpanel_indicator_get_visible (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp8_) {
		gint index = 0;
		GtkContainer* _tmp24_;
		index = 0;
		{
			GeeList* _i_list = NULL;
			GeeList* _tmp9_;
			gint _i_size = 0;
			GeeList* _tmp10_;
			gint _tmp11_;
			gint _tmp12_;
			gint _i_index = 0;
			_tmp9_ = self->priv->sorted_items;
			_i_list = _tmp9_;
			_tmp10_ = _i_list;
			_tmp11_ = gee_collection_get_size ((GeeCollection*) _tmp10_);
			_tmp12_ = _tmp11_;
			_i_size = _tmp12_;
			_i_index = -1;
			while (TRUE) {
				gint _tmp13_;
				gint _tmp14_;
				WingpanelWidgetsIndicatorEntry* i = NULL;
				GeeList* _tmp15_;
				gpointer _tmp16_;
				WingpanelWidgetsIndicatorEntry* _tmp17_;
				WingpanelWidgetsIndicatorEntry* _tmp18_;
				WingpanelIndicator* _tmp19_;
				WingpanelIndicator* _tmp20_;
				gboolean _tmp21_;
				gboolean _tmp22_;
				_i_index = _i_index + 1;
				_tmp13_ = _i_index;
				_tmp14_ = _i_size;
				if (!(_tmp13_ < _tmp14_)) {
					break;
				}
				_tmp15_ = _i_list;
				_tmp16_ = gee_list_get (_tmp15_, _i_index);
				i = (WingpanelWidgetsIndicatorEntry*) _tmp16_;
				_tmp17_ = i;
				if (_tmp17_ == item) {
					_g_object_unref0 (i);
					break;
				}
				_tmp18_ = i;
				_tmp19_ = wingpanel_widgets_indicator_entry_get_base_indicator (_tmp18_);
				_tmp20_ = _tmp19_;
				_tmp21_ = wingpanel_indicator_get_visible (_tmp20_);
				_tmp22_ = _tmp21_;
				if (_tmp22_) {
					gint _tmp23_;
					_tmp23_ = index;
					index = _tmp23_ + 1;
				}
				_g_object_unref0 (i);
			}
		}
		_tmp24_ = gtk_widget_get_parent ((GtkWidget*) item);
		if (_tmp24_ != G_TYPE_CHECK_INSTANCE_CAST (self, gtk_container_get_type (), GtkContainer)) {
			gtk_container_add ((GtkContainer*) self, (GtkWidget*) item);
			gtk_box_reorder_child ((GtkBox*) self, (GtkWidget*) item, index);
		}
	}
}

void
wingpanel_widgets_indicator_bar_remove_indicator (WingpanelWidgetsIndicatorBar* self,
                                                  WingpanelIndicator* indicator)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (indicator != NULL);
	{
		GeeList* _entry_list = NULL;
		GeeList* _tmp0_;
		gint _entry_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _entry_index = 0;
		_tmp0_ = self->priv->sorted_items;
		_entry_list = _tmp0_;
		_tmp1_ = _entry_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_entry_size = _tmp3_;
		_entry_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			WingpanelWidgetsIndicatorEntry* entry = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			WingpanelWidgetsIndicatorEntry* _tmp8_;
			WingpanelIndicator* _tmp9_;
			WingpanelIndicator* _tmp10_;
			const gchar* _tmp11_;
			const gchar* _tmp12_;
			const gchar* _tmp13_;
			const gchar* _tmp14_;
			_entry_index = _entry_index + 1;
			_tmp4_ = _entry_index;
			_tmp5_ = _entry_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _entry_list;
			_tmp7_ = gee_list_get (_tmp6_, _entry_index);
			entry = (WingpanelWidgetsIndicatorEntry*) _tmp7_;
			_tmp8_ = entry;
			_tmp9_ = wingpanel_widgets_indicator_entry_get_base_indicator (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp11_ = wingpanel_indicator_get_code_name (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = wingpanel_indicator_get_code_name (indicator);
			_tmp14_ = _tmp13_;
			if (g_strcmp0 (_tmp12_, _tmp14_) == 0) {
				GeeList* _tmp15_;
				WingpanelWidgetsIndicatorEntry* _tmp16_;
				WingpanelWidgetsIndicatorEntry* _tmp17_;
				_tmp15_ = self->priv->sorted_items;
				_tmp16_ = entry;
				gee_collection_remove ((GeeCollection*) _tmp15_, _tmp16_);
				_tmp17_ = entry;
				gtk_container_remove ((GtkContainer*) self, (GtkWidget*) _tmp17_);
			}
			_g_object_unref0 (entry);
		}
	}
}

WingpanelWidgetsIndicatorBar*
wingpanel_widgets_indicator_bar_construct (GType object_type)
{
	WingpanelWidgetsIndicatorBar * self = NULL;
	self = (WingpanelWidgetsIndicatorBar*) g_object_new (object_type, NULL);
	return self;
}

WingpanelWidgetsIndicatorBar*
wingpanel_widgets_indicator_bar_new (void)
{
	return wingpanel_widgets_indicator_bar_construct (WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR);
}

static GObject *
wingpanel_widgets_indicator_bar_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WingpanelWidgetsIndicatorBar * self;
	GeeArrayList* _tmp0_;
	parent_class = G_OBJECT_CLASS (wingpanel_widgets_indicator_bar_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR, WingpanelWidgetsIndicatorBar);
	_tmp0_ = gee_array_list_new (WINGPANEL_WIDGETS_TYPE_INDICATOR_ENTRY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->sorted_items);
	self->priv->sorted_items = (GeeList*) _tmp0_;
	return obj;
}

static void
wingpanel_widgets_indicator_bar_class_init (WingpanelWidgetsIndicatorBarClass * klass,
                                            gpointer klass_data)
{
	wingpanel_widgets_indicator_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WingpanelWidgetsIndicatorBar_private_offset);
	G_OBJECT_CLASS (klass)->constructor = wingpanel_widgets_indicator_bar_constructor;
	G_OBJECT_CLASS (klass)->finalize = wingpanel_widgets_indicator_bar_finalize;
}

static void
wingpanel_widgets_indicator_bar_instance_init (WingpanelWidgetsIndicatorBar * self,
                                               gpointer klass)
{
	WingpanelServicesIndicatorSorter* _tmp0_;
	self->priv = wingpanel_widgets_indicator_bar_get_instance_private (self);
	_tmp0_ = wingpanel_services_indicator_sorter_new ();
	self->priv->sorter = _tmp0_;
}

static void
wingpanel_widgets_indicator_bar_finalize (GObject * obj)
{
	WingpanelWidgetsIndicatorBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WINGPANEL_WIDGETS_TYPE_INDICATOR_BAR, WingpanelWidgetsIndicatorBar);
	_g_object_unref0 (self->priv->sorted_items);
	_g_object_unref0 (self->priv->sorter);
	G_OBJECT_CLASS (wingpanel_widgets_indicator_bar_parent_class)->finalize (obj);
}

static GType
wingpanel_widgets_indicator_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WingpanelWidgetsIndicatorBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wingpanel_widgets_indicator_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WingpanelWidgetsIndicatorBar), 0, (GInstanceInitFunc) wingpanel_widgets_indicator_bar_instance_init, NULL };
	GType wingpanel_widgets_indicator_bar_type_id;
	wingpanel_widgets_indicator_bar_type_id = g_type_register_static (gtk_box_get_type (), "WingpanelWidgetsIndicatorBar", &g_define_type_info, 0);
	WingpanelWidgetsIndicatorBar_private_offset = g_type_add_instance_private (wingpanel_widgets_indicator_bar_type_id, sizeof (WingpanelWidgetsIndicatorBarPrivate));
	return wingpanel_widgets_indicator_bar_type_id;
}

GType
wingpanel_widgets_indicator_bar_get_type (void)
{
	static volatile gsize wingpanel_widgets_indicator_bar_type_id__once = 0;
	if (g_once_init_enter (&wingpanel_widgets_indicator_bar_type_id__once)) {
		GType wingpanel_widgets_indicator_bar_type_id;
		wingpanel_widgets_indicator_bar_type_id = wingpanel_widgets_indicator_bar_get_type_once ();
		g_once_init_leave (&wingpanel_widgets_indicator_bar_type_id__once, wingpanel_widgets_indicator_bar_type_id);
	}
	return wingpanel_widgets_indicator_bar_type_id__once;
}

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

