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

/*
 * This file is part of budgie-desktop
 *
 * Copyright (C) 2015-2016 Solus Project
 *
 * 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.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>


#define TYPE_PLACES_SECTION (places_section_get_type ())
#define PLACES_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLACES_SECTION, PlacesSection))
#define PLACES_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLACES_SECTION, PlacesSectionClass))
#define IS_PLACES_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLACES_SECTION))
#define IS_PLACES_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLACES_SECTION))
#define PLACES_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLACES_SECTION, PlacesSectionClass))

typedef struct _PlacesSection PlacesSection;
typedef struct _PlacesSectionClass PlacesSectionClass;
typedef struct _PlacesSectionPrivate PlacesSectionPrivate;
#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_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))

#define TYPE_LIST_ITEM (list_item_get_type ())
#define LIST_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LIST_ITEM, ListItem))
#define LIST_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LIST_ITEM, ListItemClass))
#define IS_LIST_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LIST_ITEM))
#define IS_LIST_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LIST_ITEM))
#define LIST_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LIST_ITEM, ListItemClass))

typedef struct _ListItem ListItem;
typedef struct _ListItemClass ListItemClass;

#define TYPE_PLACE_ITEM (place_item_get_type ())
#define PLACE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLACE_ITEM, PlaceItem))
#define PLACE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLACE_ITEM, PlaceItemClass))
#define IS_PLACE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLACE_ITEM))
#define IS_PLACE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLACE_ITEM))
#define PLACE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLACE_ITEM, PlaceItemClass))

typedef struct _PlaceItem PlaceItem;
typedef struct _PlaceItemClass PlaceItemClass;

struct _PlacesSection {
	GtkBox parent_instance;
	PlacesSectionPrivate * priv;
	gchar* expanded_by;
};

struct _PlacesSectionClass {
	GtkBoxClass parent_class;
};

struct _PlacesSectionPrivate {
	GtkListBox* listbox;
	GtkRevealer* revealer;
	GtkButton* toggler_button;
	GtkImage* arrow_right;
	GtkImage* arrow_down;
};


static gpointer places_section_parent_class = NULL;
static GType places_section_type_id = 0;

GType places_section_get_type (void) G_GNUC_CONST;
GType places_section_register_type (GTypeModule * module);
#define PLACES_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_PLACES_SECTION, PlacesSectionPrivate))
enum  {
	PLACES_SECTION_DUMMY_PROPERTY
};
PlacesSection* places_section_new (void);
PlacesSection* places_section_construct (GType object_type);
static void places_section_toggle_revealer (PlacesSection* self);
static void _places_section_toggle_revealer_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void places_section_expand_revealer (PlacesSection* self);
static void places_section_contract_revealer (PlacesSection* self);
void places_section_clear (PlacesSection* self);
GType list_item_get_type (void) G_GNUC_CONST;
GType list_item_register_type (GTypeModule * module);
GType place_item_get_type (void) G_GNUC_CONST;
GType place_item_register_type (GTypeModule * module);
void places_section_add_item (PlacesSection* self, PlaceItem* item);
void places_section_reveal (PlacesSection* self, gboolean state);
static void places_section_finalize (GObject* obj);


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


static void _places_section_toggle_revealer_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	places_section_toggle_revealer ((PlacesSection*) self);
}


PlacesSection* places_section_construct (GType object_type) {
	PlacesSection * self = NULL;
	GtkBox* header_box = NULL;
	GtkBox* _tmp0_ = NULL;
	GtkStyleContext* _tmp1_ = NULL;
	GtkImage* header_icon = NULL;
	GtkImage* _tmp2_ = NULL;
	GtkLabel* header_label = NULL;
	const gchar* _tmp3_ = NULL;
	GtkLabel* _tmp4_ = NULL;
	GtkButton* _tmp5_ = NULL;
	GtkButton* _tmp6_ = NULL;
	GtkButton* _tmp7_ = NULL;
	GtkButton* _tmp8_ = NULL;
	GtkRevealer* _tmp9_ = NULL;
	GtkListBox* _tmp10_ = NULL;
	GtkListBox* _tmp11_ = NULL;
	GtkStyleContext* _tmp12_ = NULL;
	GtkListBox* _tmp13_ = NULL;
	GtkRevealer* _tmp14_ = NULL;
	GtkListBox* _tmp15_ = NULL;
	GtkButton* _tmp16_ = NULL;
	GtkWidget* _tmp17_ = NULL;
	GtkWidget* _tmp18_ = NULL;
	GtkImage* _tmp19_ = NULL;
	GtkImage* _tmp20_ = NULL;
	GtkButton* _tmp21_ = NULL;
	GtkRevealer* _tmp22_ = NULL;
	self = (PlacesSection*) g_object_new (object_type, "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 0, NULL);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
	g_object_ref_sink (_tmp0_);
	header_box = _tmp0_;
	_tmp1_ = gtk_widget_get_style_context ((GtkWidget*) header_box);
	gtk_style_context_add_class (_tmp1_, "places-section-header");
	_tmp2_ = (GtkImage*) gtk_image_new_from_icon_name ("folder-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp2_);
	header_icon = _tmp2_;
	gtk_widget_set_margin_start ((GtkWidget*) header_icon, 3);
	gtk_box_pack_start (header_box, (GtkWidget*) header_icon, FALSE, FALSE, (guint) 0);
	_tmp3_ = _ ("Places");
	_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
	g_object_ref_sink (_tmp4_);
	header_label = _tmp4_;
	gtk_widget_set_halign ((GtkWidget*) header_label, GTK_ALIGN_START);
	gtk_box_pack_start (header_box, (GtkWidget*) header_label, TRUE, TRUE, (guint) 0);
	_tmp5_ = (GtkButton*) gtk_button_new_from_icon_name ("pan-end-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->toggler_button);
	self->priv->toggler_button = _tmp5_;
	_tmp6_ = self->priv->toggler_button;
	gtk_button_set_relief (_tmp6_, GTK_RELIEF_NONE);
	_tmp7_ = self->priv->toggler_button;
	gtk_widget_set_can_focus ((GtkWidget*) _tmp7_, FALSE);
	_tmp8_ = self->priv->toggler_button;
	gtk_box_pack_start (header_box, (GtkWidget*) _tmp8_, FALSE, FALSE, (guint) 0);
	_tmp9_ = (GtkRevealer*) gtk_revealer_new ();
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (self->priv->revealer);
	self->priv->revealer = _tmp9_;
	_tmp10_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp10_);
	_g_object_unref0 (self->priv->listbox);
	self->priv->listbox = _tmp10_;
	_tmp11_ = self->priv->listbox;
	_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) _tmp11_);
	gtk_style_context_add_class (_tmp12_, "places-list");
	_tmp13_ = self->priv->listbox;
	gtk_list_box_set_selection_mode (_tmp13_, GTK_SELECTION_NONE);
	_tmp14_ = self->priv->revealer;
	_tmp15_ = self->priv->listbox;
	gtk_container_add ((GtkContainer*) _tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = self->priv->toggler_button;
	_tmp17_ = gtk_button_get_image (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp18_, gtk_image_get_type ()) ? ((GtkImage*) _tmp18_) : NULL);
	_g_object_unref0 (self->priv->arrow_right);
	self->priv->arrow_right = _tmp19_;
	_tmp20_ = (GtkImage*) gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp20_);
	_g_object_unref0 (self->priv->arrow_down);
	self->priv->arrow_down = _tmp20_;
	_tmp21_ = self->priv->toggler_button;
	g_signal_connect_object (_tmp21_, "clicked", (GCallback) _places_section_toggle_revealer_gtk_button_clicked, self, 0);
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) header_box, FALSE, FALSE, (guint) 0);
	_tmp22_ = self->priv->revealer;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp22_, FALSE, FALSE, (guint) 0);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (header_label);
	_g_object_unref0 (header_icon);
	_g_object_unref0 (header_box);
	return self;
}


PlacesSection* places_section_new (void) {
	return places_section_construct (TYPE_PLACES_SECTION);
}


static void places_section_toggle_revealer (PlacesSection* self) {
	gchar* _tmp0_ = NULL;
	GtkRevealer* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup ("user");
	_g_free0 (self->expanded_by);
	self->expanded_by = _tmp0_;
	_tmp1_ = self->priv->revealer;
	_tmp2_ = gtk_revealer_get_child_revealed (_tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		places_section_expand_revealer (self);
	} else {
		places_section_contract_revealer (self);
	}
}


static void places_section_expand_revealer (PlacesSection* self) {
	GtkRevealer* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->revealer;
	_tmp1_ = gtk_revealer_get_child_revealed (_tmp0_);
	if (!_tmp1_) {
		GtkRevealer* _tmp2_ = NULL;
		GtkButton* _tmp3_ = NULL;
		GtkImage* _tmp4_ = NULL;
		_tmp2_ = self->priv->revealer;
		gtk_revealer_set_reveal_child (_tmp2_, TRUE);
		_tmp3_ = self->priv->toggler_button;
		_tmp4_ = self->priv->arrow_down;
		gtk_button_set_image (_tmp3_, (GtkWidget*) _tmp4_);
	}
}


static void places_section_contract_revealer (PlacesSection* self) {
	GtkRevealer* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->revealer;
	_tmp1_ = gtk_revealer_get_child_revealed (_tmp0_);
	if (_tmp1_) {
		GtkRevealer* _tmp2_ = NULL;
		GtkButton* _tmp3_ = NULL;
		GtkImage* _tmp4_ = NULL;
		_tmp2_ = self->priv->revealer;
		gtk_revealer_set_reveal_child (_tmp2_, FALSE);
		_tmp3_ = self->priv->toggler_button;
		_tmp4_ = self->priv->arrow_right;
		gtk_button_set_image (_tmp3_, (GtkWidget*) _tmp4_);
	}
}


void places_section_clear (PlacesSection* self) {
	GtkListBox* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->listbox;
	_tmp1_ = gtk_container_get_children ((GtkContainer*) _tmp0_);
	{
		GList* item_collection = NULL;
		GList* item_it = NULL;
		item_collection = _tmp1_;
		for (item_it = item_collection; item_it != NULL; item_it = item_it->next) {
			GtkWidget* _tmp2_ = NULL;
			GtkWidget* item = NULL;
			_tmp2_ = _g_object_ref0 ((GtkWidget*) item_it->data);
			item = _tmp2_;
			{
				GtkWidget* _tmp3_ = NULL;
				_tmp3_ = item;
				gtk_widget_destroy (_tmp3_);
				_g_object_unref0 (item);
			}
		}
		_g_list_free0 (item_collection);
	}
}


void places_section_add_item (PlacesSection* self, PlaceItem* item) {
	GtkListBox* _tmp0_ = NULL;
	PlaceItem* _tmp1_ = NULL;
	PlaceItem* _tmp2_ = NULL;
	GtkContainer* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->listbox;
	_tmp1_ = item;
	gtk_container_add ((GtkContainer*) _tmp0_, (GtkWidget*) _tmp1_);
	_tmp2_ = item;
	_tmp3_ = (GtkContainer*) gtk_widget_get_parent ((GtkWidget*) _tmp2_);
	gtk_widget_set_can_focus ((GtkWidget*) _tmp3_, FALSE);
}


void places_section_reveal (PlacesSection* self, gboolean state) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = state;
	if (_tmp0_) {
		GtkRevealer* _tmp1_ = NULL;
		gboolean _tmp2_ = FALSE;
		_tmp1_ = self->priv->revealer;
		_tmp2_ = gtk_revealer_get_child_revealed (_tmp1_);
		if (!_tmp2_) {
			gchar* _tmp3_ = NULL;
			_tmp3_ = g_strdup ("code");
			_g_free0 (self->expanded_by);
			self->expanded_by = _tmp3_;
		}
		places_section_expand_revealer (self);
	} else {
		places_section_contract_revealer (self);
	}
}


static void places_section_class_init (PlacesSectionClass * klass) {
	places_section_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (PlacesSectionPrivate));
	G_OBJECT_CLASS (klass)->finalize = places_section_finalize;
}


static void places_section_instance_init (PlacesSection * self) {
	self->priv = PLACES_SECTION_GET_PRIVATE (self);
}


static void places_section_finalize (GObject* obj) {
	PlacesSection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PLACES_SECTION, PlacesSection);
	_g_object_unref0 (self->priv->listbox);
	_g_object_unref0 (self->priv->revealer);
	_g_object_unref0 (self->priv->toggler_button);
	_g_object_unref0 (self->priv->arrow_right);
	_g_object_unref0 (self->priv->arrow_down);
	_g_free0 (self->expanded_by);
	G_OBJECT_CLASS (places_section_parent_class)->finalize (obj);
}


GType places_section_get_type (void) {
	return places_section_type_id;
}


GType places_section_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (PlacesSectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) places_section_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlacesSection), 0, (GInstanceInitFunc) places_section_instance_init, NULL };
	places_section_type_id = g_type_module_register_type (module, gtk_box_get_type (), "PlacesSection", &g_define_type_info, 0);
	return places_section_type_id;
}



