/* folder-popover.c generated by valac 0.56.3, the Vala compiler
 * generated from folder-popover.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-client-43.0.h"
#include <gtk/gtk.h>
#include <glib.h>
#include "geary-engine.h"
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>

enum  {
	FOLDER_POPOVER_0_PROPERTY,
	FOLDER_POPOVER_NUM_PROPERTIES
};
static GParamSpec* folder_popover_properties[FOLDER_POPOVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block62Data Block62Data;
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	FOLDER_POPOVER_FOLDER_SELECTED_SIGNAL,
	FOLDER_POPOVER_NUM_SIGNALS
};
static guint folder_popover_signals[FOLDER_POPOVER_NUM_SIGNALS] = {0};

struct _FolderPopoverPrivate {
	GtkSearchEntry* search_entry;
	GtkListBox* list_box;
	gint filtered_folder_count;
};

struct _Block62Data {
	int _ref_count_;
	FolderPopover* self;
	GtkListBoxRow* _result_;
	GearyFolder* folder;
};

static gint FolderPopover_private_offset;
static gpointer folder_popover_parent_class = NULL;

static gboolean folder_popover_row_filter (FolderPopover* self,
                                    GtkListBoxRow* row);
static gboolean _folder_popover_row_filter_gtk_list_box_filter_func (GtkListBoxRow* row,
                                                              gpointer self);
static gint folder_popover_row_sort (FolderPopover* self,
                              GtkListBoxRow* row1,
                              GtkListBoxRow* row2);
static gint _folder_popover_row_sort_gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                      GtkListBoxRow* row2,
                                                      gpointer self);
static void __lambda59_ (FolderPopover* self);
static void ___lambda59__gtk_widget_show (GtkWidget* _sender,
                                   gpointer self);
static void __lambda60_ (FolderPopover* self);
static void folder_popover_invalidate_filter (FolderPopover* self);
static void ___lambda60__gtk_widget_hide (GtkWidget* _sender,
                                   gpointer self);
static Block62Data* block62_data_ref (Block62Data* _data62_);
static void block62_data_unref (void * _userdata_);
static void __lambda61_ (Block62Data* _data62_,
                  GtkWidget* row);
static void ___lambda61__gtk_callback (GtkWidget* widget,
                                gpointer self);
static void __lambda62_ (FolderPopover* self,
                  GtkWidget* row);
static void ___lambda62__gtk_callback (GtkWidget* widget,
                                gpointer self);
static void folder_popover_on_row_activated (FolderPopover* self,
                                      GtkListBoxRow* row);
static void _folder_popover_on_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                  GtkListBoxRow* row,
                                                                  gpointer self);
static void folder_popover_on_search_entry_activate (FolderPopover* self);
static void _folder_popover_on_search_entry_activate_gtk_entry_activate (GtkEntry* _sender,
                                                                  gpointer self);
static void folder_popover_on_search_entry_search_changed (FolderPopover* self);
static void _folder_popover_on_search_entry_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                                     gpointer self);
static void folder_popover_finalize (GObject * obj);
static GType folder_popover_get_type_once (void);

static inline gpointer
folder_popover_get_instance_private (FolderPopover* self)
{
	return G_STRUCT_MEMBER_P (self, FolderPopover_private_offset);
}

static gboolean
_folder_popover_row_filter_gtk_list_box_filter_func (GtkListBoxRow* row,
                                                     gpointer self)
{
	gboolean result;
	result = folder_popover_row_filter ((FolderPopover*) self, row);
	return result;
}

static gint
_folder_popover_row_sort_gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                 GtkListBoxRow* row2,
                                                 gpointer self)
{
	gint result;
	result = folder_popover_row_sort ((FolderPopover*) self, row1, row2);
	return result;
}

static void
__lambda59_ (FolderPopover* self)
{
	GtkSearchEntry* _tmp0_;
	_tmp0_ = self->priv->search_entry;
	gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget));
}

static void
___lambda59__gtk_widget_show (GtkWidget* _sender,
                              gpointer self)
{
	__lambda59_ ((FolderPopover*) self);
}

static void
__lambda60_ (FolderPopover* self)
{
	GtkSearchEntry* _tmp0_;
	_tmp0_ = self->priv->search_entry;
	gtk_entry_set_text (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_entry_get_type (), GtkEntry), "");
	folder_popover_invalidate_filter (self);
}

static void
___lambda60__gtk_widget_hide (GtkWidget* _sender,
                              gpointer self)
{
	__lambda60_ ((FolderPopover*) self);
}

FolderPopover*
folder_popover_construct (GType object_type)
{
	FolderPopover * self = NULL;
	GtkListBox* _tmp0_;
	GtkListBox* _tmp1_;
	self = (FolderPopover*) g_object_new (object_type, NULL);
	_tmp0_ = self->priv->list_box;
	gtk_list_box_set_filter_func (_tmp0_, _folder_popover_row_filter_gtk_list_box_filter_func, g_object_ref (self), g_object_unref);
	_tmp1_ = self->priv->list_box;
	gtk_list_box_set_sort_func (_tmp1_, _folder_popover_row_sort_gtk_list_box_sort_func, g_object_ref (self), g_object_unref);
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), "show", (GCallback) ___lambda59__gtk_widget_show, self, 0);
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), "hide", (GCallback) ___lambda60__gtk_widget_hide, self, 0);
	return self;
}

FolderPopover*
folder_popover_new (void)
{
	return folder_popover_construct (TYPE_FOLDER_POPOVER);
}

gboolean
folder_popover_has_folder (FolderPopover* self,
                           GearyFolder* folder)
{
	GtkListBoxRow* _tmp0_;
	GtkListBoxRow* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (IS_FOLDER_POPOVER (self), FALSE);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folder, GEARY_TYPE_FOLDER), FALSE);
	_tmp0_ = folder_popover_get_row_with_folder (self, folder);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_object_unref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

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

void
folder_popover_add_folder (FolderPopover* self,
                           ApplicationFolderContext* context,
                           GeeHashMap* map)
{
	GearyFolder* folder = NULL;
	GearyFolder* _tmp0_;
	GearyFolder* _tmp1_;
	GearyFolder* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GearyFolder* _tmp4_;
	gboolean _tmp10_ = FALSE;
	GearyFolder* _tmp11_;
	GearyFolderProperties* _tmp12_;
	GearyFolderProperties* _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_;
	GearyFolder* _tmp21_;
	GearyAccount* _tmp22_;
	GearyAccount* _tmp23_;
	GearyAccountInformation* _tmp24_;
	GearyAccountInformation* _tmp25_;
	GearyServiceProvider _tmp26_;
	GearyServiceProvider _tmp27_;
	GearyFolder* _tmp31_;
	GearyFolderSpecialUse _tmp32_;
	GearyFolderSpecialUse _tmp33_;
	FolderPopoverRow* row = NULL;
	FolderPopoverRow* _tmp34_;
	FolderPopoverRow* _tmp35_;
	GtkListBox* _tmp36_;
	FolderPopoverRow* _tmp37_;
	GtkListBox* _tmp38_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	g_return_if_fail (APPLICATION_IS_FOLDER_CONTEXT (context));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (map, GEE_TYPE_HASH_MAP));
	_tmp0_ = application_folder_context_get_folder (context);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	folder = _tmp2_;
	_tmp4_ = folder;
	if (folder_popover_has_folder (self, _tmp4_)) {
		_tmp3_ = TRUE;
	} else {
		GearyFolder* _tmp5_;
		GearyFolderProperties* _tmp6_;
		GearyFolderProperties* _tmp7_;
		GearyTrillian _tmp8_;
		GearyTrillian _tmp9_;
		_tmp5_ = folder;
		_tmp6_ = geary_folder_get_properties (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = geary_folder_properties_get_is_openable (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp3_ = geary_trillian_is_impossible (_tmp9_);
	}
	if (_tmp3_) {
		_g_object_unref0 (folder);
		return;
	}
	_tmp11_ = folder;
	_tmp12_ = geary_folder_get_properties (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = geary_folder_properties_get_is_local_only (_tmp13_);
	_tmp15_ = _tmp14_;
	if (_tmp15_) {
		_tmp10_ = TRUE;
	} else {
		GearyFolder* _tmp16_;
		GearyFolderProperties* _tmp17_;
		GearyFolderProperties* _tmp18_;
		gboolean _tmp19_;
		gboolean _tmp20_;
		_tmp16_ = folder;
		_tmp17_ = geary_folder_get_properties (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = geary_folder_properties_get_is_virtual (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp10_ = _tmp20_;
	}
	if (_tmp10_) {
		_g_object_unref0 (folder);
		return;
	}
	_tmp21_ = folder;
	_tmp22_ = geary_folder_get_account (_tmp21_);
	_tmp23_ = _tmp22_;
	_tmp24_ = geary_account_get_information (_tmp23_);
	_tmp25_ = _tmp24_;
	_tmp26_ = geary_account_information_get_service_provider (_tmp25_);
	_tmp27_ = _tmp26_;
	switch (_tmp27_) {
		case GEARY_SERVICE_PROVIDER_GMAIL:
		{
			GearyFolder* _tmp28_;
			GearyFolderSpecialUse _tmp29_;
			GearyFolderSpecialUse _tmp30_;
			_tmp28_ = folder;
			_tmp29_ = geary_folder_get_used_as (_tmp28_);
			_tmp30_ = _tmp29_;
			if (_tmp30_ == GEARY_FOLDER_SPECIAL_USE_DRAFTS) {
				_g_object_unref0 (folder);
				return;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	_tmp31_ = folder;
	_tmp32_ = geary_folder_get_used_as (_tmp31_);
	_tmp33_ = _tmp32_;
	switch (_tmp33_) {
		case GEARY_FOLDER_SPECIAL_USE_ARCHIVE:
		case GEARY_FOLDER_SPECIAL_USE_TRASH:
		case GEARY_FOLDER_SPECIAL_USE_JUNK:
		{
			_g_object_unref0 (folder);
			return;
		}
		default:
		{
			break;
		}
	}
	_tmp34_ = folder_popover_row_new (context, map);
	g_object_ref_sink (_tmp34_);
	row = _tmp34_;
	_tmp35_ = row;
	gtk_widget_show (G_TYPE_CHECK_INSTANCE_CAST (_tmp35_, gtk_widget_get_type (), GtkWidget));
	_tmp36_ = self->priv->list_box;
	_tmp37_ = row;
	gtk_container_add (G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, gtk_container_get_type (), GtkContainer), G_TYPE_CHECK_INSTANCE_CAST (_tmp37_, gtk_widget_get_type (), GtkWidget));
	_tmp38_ = self->priv->list_box;
	gtk_list_box_invalidate_sort (_tmp38_);
	_g_object_unref0 (row);
	_g_object_unref0 (folder);
}

void
folder_popover_enable_disable_folder (FolderPopover* self,
                                      GearyFolder* folder,
                                      gboolean visible)
{
	GtkListBoxRow* row = NULL;
	GtkListBoxRow* _tmp0_;
	GtkListBoxRow* _tmp1_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folder, GEARY_TYPE_FOLDER));
	_tmp0_ = folder_popover_get_row_with_folder (self, folder);
	row = _tmp0_;
	_tmp1_ = row;
	if (_tmp1_ != NULL) {
		GtkListBoxRow* _tmp2_;
		_tmp2_ = row;
		gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_widget_get_type (), GtkWidget), visible);
	}
	_g_object_unref0 (row);
}

void
folder_popover_remove_folder (FolderPopover* self,
                              GearyFolder* folder)
{
	GtkListBoxRow* row = NULL;
	GtkListBoxRow* _tmp0_;
	GtkListBoxRow* _tmp1_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folder, GEARY_TYPE_FOLDER));
	_tmp0_ = folder_popover_get_row_with_folder (self, folder);
	row = _tmp0_;
	_tmp1_ = row;
	if (_tmp1_ != NULL) {
		GtkListBox* _tmp2_;
		GtkListBoxRow* _tmp3_;
		_tmp2_ = self->priv->list_box;
		_tmp3_ = row;
		gtk_container_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_container_get_type (), GtkContainer), G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_widget_get_type (), GtkWidget));
	}
	_g_object_unref0 (row);
}

static Block62Data*
block62_data_ref (Block62Data* _data62_)
{
	g_atomic_int_inc (&_data62_->_ref_count_);
	return _data62_;
}

static void
block62_data_unref (void * _userdata_)
{
	Block62Data* _data62_;
	_data62_ = (Block62Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data62_->_ref_count_)) {
		FolderPopover* self;
		self = _data62_->self;
		_g_object_unref0 (_data62_->_result_);
		_g_object_unref0 (_data62_->folder);
		_g_object_unref0 (self);
		g_slice_free (Block62Data, _data62_);
	}
}

static void
__lambda61_ (Block62Data* _data62_,
             GtkWidget* row)
{
	FolderPopover* self;
	gconstpointer _tmp0_;
	self = _data62_->self;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row, gtk_widget_get_type ()));
	_tmp0_ = g_object_get_data (G_TYPE_CHECK_INSTANCE_CAST (row, G_TYPE_OBJECT, GObject), "folder");
	if (((GearyFolder*) _tmp0_) == _data62_->folder) {
		GtkListBoxRow* _tmp1_;
		_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (row, gtk_list_box_row_get_type ()) ? ((GtkListBoxRow*) row) : NULL);
		_g_object_unref0 (_data62_->_result_);
		_data62_->_result_ = _tmp1_;
	}
}

static void
___lambda61__gtk_callback (GtkWidget* widget,
                           gpointer self)
{
	__lambda61_ (self, widget);
}

GtkListBoxRow*
folder_popover_get_row_with_folder (FolderPopover* self,
                                    GearyFolder* folder)
{
	Block62Data* _data62_;
	GearyFolder* _tmp0_;
	GtkListBox* _tmp1_;
	GtkListBoxRow* _tmp2_;
	GtkListBoxRow* result;
	g_return_val_if_fail (IS_FOLDER_POPOVER (self), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folder, GEARY_TYPE_FOLDER), NULL);
	_data62_ = g_slice_new0 (Block62Data);
	_data62_->_ref_count_ = 1;
	_data62_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (folder);
	_g_object_unref0 (_data62_->folder);
	_data62_->folder = _tmp0_;
	_data62_->_result_ = NULL;
	_tmp1_ = self->priv->list_box;
	gtk_container_foreach (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_container_get_type (), GtkContainer), ___lambda61__gtk_callback, _data62_);
	_tmp2_ = _g_object_ref0 (_data62_->_result_);
	result = _tmp2_;
	block62_data_unref (_data62_);
	_data62_ = NULL;
	return result;
}

static void
__lambda62_ (FolderPopover* self,
             GtkWidget* row)
{
	GtkListBox* _tmp0_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row, gtk_widget_get_type ()));
	_tmp0_ = self->priv->list_box;
	gtk_container_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_container_get_type (), GtkContainer), row);
}

static void
___lambda62__gtk_callback (GtkWidget* widget,
                           gpointer self)
{
	__lambda62_ ((FolderPopover*) self, widget);
}

void
folder_popover_clear (FolderPopover* self)
{
	GtkListBox* _tmp0_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	_tmp0_ = self->priv->list_box;
	gtk_container_foreach (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_container_get_type (), GtkContainer), ___lambda62__gtk_callback, self);
}

static void
folder_popover_on_row_activated (FolderPopover* self,
                                 GtkListBoxRow* row)
{
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	g_return_if_fail ((row == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (row, gtk_list_box_row_get_type ()));
	if (row != NULL) {
		GearyFolder* folder = NULL;
		gconstpointer _tmp0_;
		GearyFolder* _tmp1_;
		GearyFolder* _tmp2_;
		_tmp0_ = g_object_get_data (G_TYPE_CHECK_INSTANCE_CAST (row, G_TYPE_OBJECT, GObject), "folder");
		_tmp1_ = _g_object_ref0 ((GearyFolder*) _tmp0_);
		folder = _tmp1_;
		_tmp2_ = folder;
		g_signal_emit (self, folder_popover_signals[FOLDER_POPOVER_FOLDER_SELECTED_SIGNAL], 0, _tmp2_);
		_g_object_unref0 (folder);
	}
	gtk_widget_hide (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

static void
_folder_popover_on_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                             GtkListBoxRow* row,
                                                             gpointer self)
{
	folder_popover_on_row_activated ((FolderPopover*) self, row);
}

static void
folder_popover_on_search_entry_activate (FolderPopover* self)
{
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	if (self->priv->filtered_folder_count == 1) {
		GtkListBoxRow* row = NULL;
		GtkListBox* _tmp0_;
		GtkListBoxRow* _tmp1_;
		GtkListBoxRow* _tmp2_;
		GtkListBoxRow* _tmp3_;
		_tmp0_ = self->priv->list_box;
		_tmp1_ = gtk_list_box_get_row_at_y (_tmp0_, 0);
		_tmp2_ = _g_object_ref0 (_tmp1_);
		row = _tmp2_;
		_tmp3_ = row;
		if (_tmp3_ != NULL) {
			GtkListBoxRow* _tmp4_;
			_tmp4_ = row;
			folder_popover_on_row_activated (self, _tmp4_);
		}
		_g_object_unref0 (row);
	} else {
		if (self->priv->filtered_folder_count > 0) {
			GtkListBox* _tmp5_;
			GtkListBoxRow* _tmp6_;
			_tmp5_ = self->priv->list_box;
			_tmp6_ = gtk_list_box_get_row_at_y (_tmp5_, 0);
			gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_widget_get_type (), GtkWidget));
		}
	}
}

static void
_folder_popover_on_search_entry_activate_gtk_entry_activate (GtkEntry* _sender,
                                                             gpointer self)
{
	folder_popover_on_search_entry_activate ((FolderPopover*) self);
}

static void
folder_popover_on_search_entry_search_changed (FolderPopover* self)
{
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	folder_popover_invalidate_filter (self);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_entry_get_text (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_entry_get_type (), GtkEntry));
	if (g_strcmp0 (_tmp1_, "") != 0) {
		GtkListBox* _tmp2_;
		_tmp2_ = self->priv->list_box;
		gtk_list_box_unselect_all (_tmp2_);
	}
}

static void
_folder_popover_on_search_entry_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                                gpointer self)
{
	folder_popover_on_search_entry_search_changed ((FolderPopover*) self);
}

static void
folder_popover_invalidate_filter (FolderPopover* self)
{
	GtkListBox* _tmp0_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	self->priv->filtered_folder_count = 0;
	_tmp0_ = self->priv->list_box;
	gtk_list_box_invalidate_filter (_tmp0_);
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gboolean
folder_popover_row_filter (FolderPopover* self,
                           GtkListBoxRow* row)
{
	GearyFolder* folder = NULL;
	gconstpointer _tmp0_;
	GearyFolder* _tmp1_;
	GearyFolder* _tmp2_;
	GearyFolderPath* _tmp3_;
	GearyFolderPath* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GtkSearchEntry* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gboolean _tmp14_;
	gboolean result;
	g_return_val_if_fail (IS_FOLDER_POPOVER (self), FALSE);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row, gtk_list_box_row_get_type ()), FALSE);
	_tmp0_ = g_object_get_data (G_TYPE_CHECK_INSTANCE_CAST (row, G_TYPE_OBJECT, GObject), "folder");
	_tmp1_ = _g_object_ref0 ((GearyFolder*) _tmp0_);
	folder = _tmp1_;
	_tmp2_ = folder;
	_tmp3_ = geary_folder_get_path (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = geary_folder_path_to_string (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_utf8_strdown (_tmp6_, (gssize) -1);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->priv->search_entry;
	_tmp10_ = gtk_entry_get_text (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, gtk_entry_get_type (), GtkEntry));
	_tmp11_ = _tmp10_;
	_tmp12_ = g_utf8_strdown (_tmp11_, (gssize) -1);
	_tmp13_ = _tmp12_;
	_tmp14_ = string_contains (_tmp8_, _tmp13_);
	_g_free0 (_tmp13_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp6_);
	if (_tmp14_) {
		gint _tmp15_;
		_tmp15_ = self->priv->filtered_folder_count;
		self->priv->filtered_folder_count = _tmp15_ + 1;
		result = TRUE;
		_g_object_unref0 (folder);
		return result;
	}
	result = FALSE;
	_g_object_unref0 (folder);
	return result;
}

static gint
folder_popover_row_sort (FolderPopover* self,
                         GtkListBoxRow* row1,
                         GtkListBoxRow* row2)
{
	GearyFolder* folder1 = NULL;
	gconstpointer _tmp0_;
	GearyFolder* _tmp1_;
	GearyFolder* folder2 = NULL;
	gconstpointer _tmp2_;
	GearyFolder* _tmp3_;
	gboolean _tmp4_ = FALSE;
	GearyFolder* _tmp5_;
	GearyFolderSpecialUse _tmp6_;
	GearyFolderSpecialUse _tmp7_;
	gint result;
	g_return_val_if_fail (IS_FOLDER_POPOVER (self), 0);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row1, gtk_list_box_row_get_type ()), 0);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row2, gtk_list_box_row_get_type ()), 0);
	_tmp0_ = g_object_get_data (G_TYPE_CHECK_INSTANCE_CAST (row1, G_TYPE_OBJECT, GObject), "folder");
	_tmp1_ = _g_object_ref0 ((GearyFolder*) _tmp0_);
	folder1 = _tmp1_;
	_tmp2_ = g_object_get_data (G_TYPE_CHECK_INSTANCE_CAST (row2, G_TYPE_OBJECT, GObject), "folder");
	_tmp3_ = _g_object_ref0 ((GearyFolder*) _tmp2_);
	folder2 = _tmp3_;
	_tmp5_ = folder1;
	_tmp6_ = geary_folder_get_used_as (_tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp7_ != GEARY_FOLDER_SPECIAL_USE_NONE) {
		GearyFolder* _tmp8_;
		GearyFolderSpecialUse _tmp9_;
		GearyFolderSpecialUse _tmp10_;
		_tmp8_ = folder2;
		_tmp9_ = geary_folder_get_used_as (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp4_ = _tmp10_ == GEARY_FOLDER_SPECIAL_USE_NONE;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		result = -1;
		_g_object_unref0 (folder2);
		_g_object_unref0 (folder1);
		return result;
	} else {
		gboolean _tmp11_ = FALSE;
		GearyFolder* _tmp12_;
		GearyFolderSpecialUse _tmp13_;
		GearyFolderSpecialUse _tmp14_;
		_tmp12_ = folder1;
		_tmp13_ = geary_folder_get_used_as (_tmp12_);
		_tmp14_ = _tmp13_;
		if (_tmp14_ == GEARY_FOLDER_SPECIAL_USE_NONE) {
			GearyFolder* _tmp15_;
			GearyFolderSpecialUse _tmp16_;
			GearyFolderSpecialUse _tmp17_;
			_tmp15_ = folder2;
			_tmp16_ = geary_folder_get_used_as (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp11_ = _tmp17_ != GEARY_FOLDER_SPECIAL_USE_NONE;
		} else {
			_tmp11_ = FALSE;
		}
		if (_tmp11_) {
			result = 1;
			_g_object_unref0 (folder2);
			_g_object_unref0 (folder1);
			return result;
		} else {
			GearyFolder* _tmp18_;
			GearyFolderPath* _tmp19_;
			GearyFolderPath* _tmp20_;
			GearyFolder* _tmp21_;
			GearyFolderPath* _tmp22_;
			GearyFolderPath* _tmp23_;
			_tmp18_ = folder1;
			_tmp19_ = geary_folder_get_path (_tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = folder2;
			_tmp22_ = geary_folder_get_path (_tmp21_);
			_tmp23_ = _tmp22_;
			result = gee_comparable_compare_to (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GEE_TYPE_COMPARABLE, GeeComparable), _tmp23_);
			_g_object_unref0 (folder2);
			_g_object_unref0 (folder1);
			return result;
		}
	}
}

static void
folder_popover_class_init (FolderPopoverClass * klass,
                           gpointer klass_data)
{
	folder_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FolderPopover_private_offset);
	G_OBJECT_CLASS (klass)->finalize = folder_popover_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Geary/folder-popover.ui");
	folder_popover_signals[FOLDER_POPOVER_FOLDER_SELECTED_SIGNAL] = g_signal_new ("folder-selected", TYPE_FOLDER_POPOVER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_TYPE_FOLDER);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "search_entry", FALSE, FolderPopover_private_offset + G_STRUCT_OFFSET (FolderPopoverPrivate, search_entry));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "list_box", FALSE, FolderPopover_private_offset + G_STRUCT_OFFSET (FolderPopoverPrivate, list_box));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_row_activated", G_CALLBACK(_folder_popover_on_row_activated_gtk_list_box_row_activated));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_search_entry_activate", G_CALLBACK(_folder_popover_on_search_entry_activate_gtk_entry_activate));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_search_entry_search_changed", G_CALLBACK(_folder_popover_on_search_entry_search_changed_gtk_search_entry_search_changed));
}

static void
folder_popover_instance_init (FolderPopover * self,
                              gpointer klass)
{
	self->priv = folder_popover_get_instance_private (self);
	self->priv->filtered_folder_count = 0;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
folder_popover_finalize (GObject * obj)
{
	FolderPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOLDER_POPOVER, FolderPopover);
	G_OBJECT_CLASS (folder_popover_parent_class)->finalize (obj);
}

static GType
folder_popover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FolderPopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folder_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolderPopover), 0, (GInstanceInitFunc) folder_popover_instance_init, NULL };
	GType folder_popover_type_id;
	folder_popover_type_id = g_type_register_static (gtk_popover_get_type (), "FolderPopover", &g_define_type_info, 0);
	FolderPopover_private_offset = g_type_add_instance_private (folder_popover_type_id, sizeof (FolderPopoverPrivate));
	return folder_popover_type_id;
}

GType
folder_popover_get_type (void)
{
	static volatile gsize folder_popover_type_id__once = 0;
	if (g_once_init_enter (&folder_popover_type_id__once)) {
		GType folder_popover_type_id;
		folder_popover_type_id = folder_popover_get_type_once ();
		g_once_init_leave (&folder_popover_type_id__once, folder_popover_type_id);
	}
	return folder_popover_type_id__once;
}

