/* folder-popover.c generated by valac 0.56.19, 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-46.0.h"
#include <gtk/gtk.h>
#include "geary-engine.h"
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gee.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

enum  {
	FOLDER_POPOVER_0_PROPERTY,
	FOLDER_POPOVER_ACCOUNT_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)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	FOLDER_POPOVER_COPY_CONVERSATION_SIGNAL,
	FOLDER_POPOVER_MOVE_CONVERSATION_SIGNAL,
	FOLDER_POPOVER_NUM_SIGNALS
};
static guint folder_popover_signals[FOLDER_POPOVER_NUM_SIGNALS] = {0};

struct _FolderPopoverPrivate {
	GtkSearchEntry* search_entry;
	GtkListBox* list_box;
	GtkSwitch* move_switch;
	GearyAccount* _account;
	gint filtered_folder_count;
};

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 __lambda130_ (FolderPopover* self);
static void ___lambda130__gtk_widget_show (GtkWidget* _sender,
                                    gpointer self);
static void __lambda131_ (FolderPopover* self);
static void folder_popover_invalidate_filter (FolderPopover* self);
static void ___lambda131__gtk_widget_hide (GtkWidget* _sender,
                                    gpointer self);
static void folder_popover_add_folder (FolderPopover* self,
                                ApplicationFolderContext* context,
                                GeeHashMap* map);
static void folder_popover_on_map (FolderPopover* self,
                            GtkWidget* widget);
static void _folder_popover_on_map_gtk_widget_map (GtkWidget* _sender,
                                            gpointer self);
static void folder_popover_on_unmap (FolderPopover* self,
                              GtkWidget* widget);
static void __lambda132_ (FolderPopover* self,
                   GtkWidget* row);
static void ___lambda132__gtk_callback (GtkWidget* widget,
                                 gpointer self);
static void _folder_popover_on_unmap_gtk_widget_unmap (GtkWidget* _sender,
                                                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 void _vala_folder_popover_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec);
static void _vala_folder_popover_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec);

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

GearyAccount*
folder_popover_get_account (FolderPopover* self)
{
	GearyAccount* result;
	GearyAccount* _tmp0_;
	g_return_val_if_fail (IS_FOLDER_POPOVER (self), NULL);
	_tmp0_ = self->priv->_account;
	result = _tmp0_;
	return result;
}

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

void
folder_popover_set_account (FolderPopover* self,
                            GearyAccount* value)
{
	GearyAccount* old_value;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	old_value = folder_popover_get_account (self);
	if (old_value != value) {
		GearyAccount* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_account);
		self->priv->_account = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, folder_popover_properties[FOLDER_POPOVER_ACCOUNT_PROPERTY]);
	}
}

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
__lambda130_ (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
___lambda130__gtk_widget_show (GtkWidget* _sender,
                               gpointer self)
{
	__lambda130_ ((FolderPopover*) self);
}

static void
__lambda131_ (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
___lambda131__gtk_widget_hide (GtkWidget* _sender,
                               gpointer self)
{
	__lambda131_ ((FolderPopover*) self);
}

FolderPopover*
folder_popover_construct (GType object_type,
                          ApplicationConfiguration* config)
{
	FolderPopover * self = NULL;
	GtkListBox* _tmp0_;
	GtkListBox* _tmp1_;
	GtkSwitch* _tmp2_;
	g_return_val_if_fail (APPLICATION_IS_CONFIGURATION (config), NULL);
	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) ___lambda130__gtk_widget_show, self, 0);
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), "hide", (GCallback) ___lambda131__gtk_widget_hide, self, 0);
	_tmp2_ = self->priv->move_switch;
	application_configuration_bind (config, "move-messages-on-tag", G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, G_TYPE_OBJECT, GObject), "active", G_SETTINGS_BIND_DEFAULT);
	return self;
}

FolderPopover*
folder_popover_new (ApplicationConfiguration* config)
{
	return folder_popover_construct (TYPE_FOLDER_POPOVER, config);
}

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

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static void
folder_popover_on_map (FolderPopover* self,
                       GtkWidget* widget)
{
	GeeCollection* folders = NULL;
	GearyAccount* _tmp0_;
	GeeCollection* _tmp1_;
	GeeHashMap* map = NULL;
	GeeHashMap* _tmp2_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (widget, gtk_widget_get_type ()));
	_tmp0_ = self->priv->_account;
	_tmp1_ = geary_account_list_folders (_tmp0_);
	folders = _tmp1_;
	_tmp2_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	map = _tmp2_;
	{
		GeeIterator* _folder_it = NULL;
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_;
		_tmp3_ = folders;
		_tmp4_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp4_;
		while (TRUE) {
			GeeIterator* _tmp5_;
			GearyFolder* folder = NULL;
			GeeIterator* _tmp6_;
			gpointer _tmp7_;
			ApplicationFolderContext* context = NULL;
			GearyFolder* _tmp8_;
			ApplicationFolderContext* _tmp9_;
			GearyFolder* _tmp10_;
			GearyFolderSpecialUse _tmp11_;
			GearyFolderSpecialUse _tmp12_;
			GeeHashMap* _tmp13_;
			GearyFolder* _tmp14_;
			GearyFolderPath* _tmp15_;
			GearyFolderPath* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			ApplicationFolderContext* _tmp21_;
			const gchar* _tmp22_;
			const gchar* _tmp23_;
			_tmp5_ = _folder_it;
			if (!gee_iterator_next (_tmp5_)) {
				break;
			}
			_tmp6_ = _folder_it;
			_tmp7_ = gee_iterator_get (_tmp6_);
			folder = (GearyFolder*) _tmp7_;
			_tmp8_ = folder;
			_tmp9_ = application_folder_context_new (_tmp8_);
			context = _tmp9_;
			_tmp10_ = folder;
			_tmp11_ = geary_folder_get_used_as (_tmp10_);
			_tmp12_ = _tmp11_;
			if (_tmp12_ == GEARY_FOLDER_SPECIAL_USE_NONE) {
				_g_object_unref0 (context);
				_g_object_unref0 (folder);
				continue;
			}
			_tmp13_ = map;
			_tmp14_ = folder;
			_tmp15_ = geary_folder_get_path (_tmp14_);
			_tmp16_ = _tmp15_;
			_tmp17_ = geary_folder_path_to_string (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = string_substring (_tmp18_, (glong) 1, (glong) -1);
			_tmp20_ = _tmp19_;
			_tmp21_ = context;
			_tmp22_ = application_folder_context_get_display_name (_tmp21_);
			_tmp23_ = _tmp22_;
			gee_abstract_map_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, GEE_TYPE_ABSTRACT_MAP, GeeAbstractMap), _tmp20_, _tmp23_);
			_g_free0 (_tmp20_);
			_g_free0 (_tmp18_);
			_g_object_unref0 (context);
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
	{
		GeeIterator* _folder_it = NULL;
		GeeCollection* _tmp24_;
		GeeIterator* _tmp25_;
		_tmp24_ = folders;
		_tmp25_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp25_;
		while (TRUE) {
			GeeIterator* _tmp26_;
			GearyFolder* folder = NULL;
			GeeIterator* _tmp27_;
			gpointer _tmp28_;
			ApplicationFolderContext* context = NULL;
			GearyFolder* _tmp29_;
			ApplicationFolderContext* _tmp30_;
			ApplicationFolderContext* _tmp31_;
			GeeHashMap* _tmp32_;
			_tmp26_ = _folder_it;
			if (!gee_iterator_next (_tmp26_)) {
				break;
			}
			_tmp27_ = _folder_it;
			_tmp28_ = gee_iterator_get (_tmp27_);
			folder = (GearyFolder*) _tmp28_;
			_tmp29_ = folder;
			_tmp30_ = application_folder_context_new (_tmp29_);
			context = _tmp30_;
			_tmp31_ = context;
			_tmp32_ = map;
			folder_popover_add_folder (self, _tmp31_, _tmp32_);
			_g_object_unref0 (context);
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
	_g_object_unref0 (map);
	_g_object_unref0 (folders);
}

static void
_folder_popover_on_map_gtk_widget_map (GtkWidget* _sender,
                                       gpointer self)
{
	folder_popover_on_map ((FolderPopover*) self, _sender);
}

static void
__lambda132_ (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
___lambda132__gtk_callback (GtkWidget* widget,
                            gpointer self)
{
	__lambda132_ ((FolderPopover*) self, widget);
}

static void
folder_popover_on_unmap (FolderPopover* self,
                         GtkWidget* widget)
{
	GtkListBox* _tmp0_;
	g_return_if_fail (IS_FOLDER_POPOVER (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (widget, gtk_widget_get_type ()));
	_tmp0_ = self->priv->list_box;
	gtk_container_foreach (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_container_get_type (), GtkContainer), ___lambda132__gtk_callback, self);
}

static void
_folder_popover_on_unmap_gtk_widget_unmap (GtkWidget* _sender,
                                           gpointer self)
{
	folder_popover_on_unmap ((FolderPopover*) self, _sender);
}

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_;
		GtkSwitch* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_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_ = self->priv->move_switch;
		_tmp3_ = gtk_switch_get_active (_tmp2_);
		_tmp4_ = _tmp3_;
		if (_tmp4_) {
			GearyFolder* _tmp5_;
			_tmp5_ = folder;
			g_signal_emit (self, folder_popover_signals[FOLDER_POPOVER_MOVE_CONVERSATION_SIGNAL], 0, _tmp5_);
		} else {
			GearyFolder* _tmp6_;
			_tmp6_ = folder;
			g_signal_emit (self, folder_popover_signals[FOLDER_POPOVER_COPY_CONVERSATION_SIGNAL], 0, _tmp6_);
		}
		_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), -1);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row1, gtk_list_box_row_get_type ()), -1);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (row2, gtk_list_box_row_get_type ()), -1);
	_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)->get_property = _vala_folder_popover_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_folder_popover_set_property;
	G_OBJECT_CLASS (klass)->finalize = folder_popover_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLDER_POPOVER_ACCOUNT_PROPERTY, folder_popover_properties[FOLDER_POPOVER_ACCOUNT_PROPERTY] = g_param_spec_object ("account", "account", "account", GEARY_TYPE_ACCOUNT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Geary/folder-popover.ui");
	folder_popover_signals[FOLDER_POPOVER_COPY_CONVERSATION_SIGNAL] = g_signal_new ("copy-conversation", TYPE_FOLDER_POPOVER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GEARY_TYPE_FOLDER);
	folder_popover_signals[FOLDER_POPOVER_MOVE_CONVERSATION_SIGNAL] = g_signal_new ("move-conversation", 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_child_full (GTK_WIDGET_CLASS (klass), "move_switch", FALSE, FolderPopover_private_offset + G_STRUCT_OFFSET (FolderPopoverPrivate, move_switch));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_map", G_CALLBACK(_folder_popover_on_map_gtk_widget_map));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_unmap", G_CALLBACK(_folder_popover_on_unmap_gtk_widget_unmap));
	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_unref0 (self->priv->_account);
	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;
}

static void
_vala_folder_popover_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec)
{
	FolderPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FOLDER_POPOVER, FolderPopover);
	switch (property_id) {
		case FOLDER_POPOVER_ACCOUNT_PROPERTY:
		g_value_set_object (value, folder_popover_get_account (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_folder_popover_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec)
{
	FolderPopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FOLDER_POPOVER, FolderPopover);
	switch (property_id) {
		case FOLDER_POPOVER_ACCOUNT_PROPERTY:
		folder_popover_set_account (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

