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

/*
 * Copyright © 2020 Michael Gratton <mike@vee.net>
 *
 * 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-engine.h"
#include "geary-client-43.0.h"
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>

#define APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT (application_folder_plugin_context_get_type ())
#define APPLICATION_FOLDER_PLUGIN_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext))
#define APPLICATION_FOLDER_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContextClass))
#define APPLICATION_IS_FOLDER_PLUGIN_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT))
#define APPLICATION_IS_FOLDER_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT))
#define APPLICATION_FOLDER_PLUGIN_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContextClass))

typedef struct _ApplicationFolderPluginContext ApplicationFolderPluginContext;
typedef struct _ApplicationFolderPluginContextClass ApplicationFolderPluginContextClass;
typedef struct _ApplicationFolderPluginContextPrivate ApplicationFolderPluginContextPrivate;

#define APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_GLOBALS (application_plugin_manager_plugin_globals_get_type ())
#define APPLICATION_PLUGIN_MANAGER_PLUGIN_GLOBALS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_GLOBALS, ApplicationPluginManagerPluginGlobals))
#define APPLICATION_PLUGIN_MANAGER_PLUGIN_GLOBALS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_GLOBALS, ApplicationPluginManagerPluginGlobalsClass))
#define APPLICATION_PLUGIN_MANAGER_IS_PLUGIN_GLOBALS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_GLOBALS))
#define APPLICATION_PLUGIN_MANAGER_IS_PLUGIN_GLOBALS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_GLOBALS))
#define APPLICATION_PLUGIN_MANAGER_PLUGIN_GLOBALS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_GLOBALS, ApplicationPluginManagerPluginGlobalsClass))

typedef struct _ApplicationPluginManagerPluginGlobals ApplicationPluginManagerPluginGlobals;
typedef struct _ApplicationPluginManagerPluginGlobalsClass ApplicationPluginManagerPluginGlobalsClass;

#define APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_CONTEXT (application_plugin_manager_plugin_context_get_type ())
#define APPLICATION_PLUGIN_MANAGER_PLUGIN_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_CONTEXT, ApplicationPluginManagerPluginContext))
#define APPLICATION_PLUGIN_MANAGER_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_CONTEXT, ApplicationPluginManagerPluginContextClass))
#define APPLICATION_PLUGIN_MANAGER_IS_PLUGIN_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_CONTEXT))
#define APPLICATION_PLUGIN_MANAGER_IS_PLUGIN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_CONTEXT))
#define APPLICATION_PLUGIN_MANAGER_PLUGIN_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APPLICATION_PLUGIN_MANAGER_TYPE_PLUGIN_CONTEXT, ApplicationPluginManagerPluginContextClass))

typedef struct _ApplicationPluginManagerPluginContext ApplicationPluginManagerPluginContext;
typedef struct _ApplicationPluginManagerPluginContextClass ApplicationPluginManagerPluginContextClass;
enum  {
	APPLICATION_FOLDER_PLUGIN_CONTEXT_0_PROPERTY,
	APPLICATION_FOLDER_PLUGIN_CONTEXT_NUM_PROPERTIES
};
static GParamSpec* application_folder_plugin_context_properties[APPLICATION_FOLDER_PLUGIN_CONTEXT_NUM_PROPERTIES];
#define _application_plugin_manager_plugin_globals_unref0(var) ((var == NULL) ? NULL : (var = (application_plugin_manager_plugin_globals_unref (var), NULL)))
#define _application_plugin_manager_plugin_context_unref0(var) ((var == NULL) ? NULL : (var = (application_plugin_manager_plugin_context_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define APPLICATION_TYPE_FOLDER_STORE_FACTORY (application_folder_store_factory_get_type ())
#define APPLICATION_FOLDER_STORE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APPLICATION_TYPE_FOLDER_STORE_FACTORY, ApplicationFolderStoreFactory))
#define APPLICATION_FOLDER_STORE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APPLICATION_TYPE_FOLDER_STORE_FACTORY, ApplicationFolderStoreFactoryClass))
#define APPLICATION_IS_FOLDER_STORE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APPLICATION_TYPE_FOLDER_STORE_FACTORY))
#define APPLICATION_IS_FOLDER_STORE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APPLICATION_TYPE_FOLDER_STORE_FACTORY))
#define APPLICATION_FOLDER_STORE_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APPLICATION_TYPE_FOLDER_STORE_FACTORY, ApplicationFolderStoreFactoryClass))

typedef struct _ApplicationFolderStoreFactory ApplicationFolderStoreFactory;
typedef struct _ApplicationFolderStoreFactoryClass ApplicationFolderStoreFactoryClass;
typedef struct _ApplicationFolderPluginContextGetFolderStoreData ApplicationFolderPluginContextGetFolderStoreData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _ApplicationFolderPluginContext {
	GearyBaseObject parent_instance;
	ApplicationFolderPluginContextPrivate * priv;
};

struct _ApplicationFolderPluginContextClass {
	GearyBaseObjectClass parent_class;
};

struct _ApplicationFolderPluginContextPrivate {
	ApplicationClient* application;
	ApplicationPluginManagerPluginGlobals* globals;
	ApplicationPluginManagerPluginContext* plugin;
	PluginFolderStore* folders;
};

struct _ApplicationFolderPluginContextGetFolderStoreData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ApplicationFolderPluginContext* self;
	PluginFolderStore* result;
	PluginFolderStore* _tmp0_;
	PluginFolderStore* _tmp1_;
};

static gint ApplicationFolderPluginContext_private_offset;
static gpointer application_folder_plugin_context_parent_class = NULL;
static PluginFolderContextIface * application_folder_plugin_context_plugin_folder_context_parent_iface = NULL;

VALA_EXTERN GType application_folder_plugin_context_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gpointer application_plugin_manager_plugin_globals_ref (gpointer instance);
VALA_EXTERN void application_plugin_manager_plugin_globals_unref (gpointer instance);
VALA_EXTERN GParamSpec* application_plugin_manager_param_spec_plugin_globals (const gchar* name,
                                                                  const gchar* nick,
                                                                  const gchar* blurb,
                                                                  GType object_type,
                                                                  GParamFlags flags);
VALA_EXTERN void application_plugin_manager_value_set_plugin_globals (GValue* value,
                                                          gpointer v_object);
VALA_EXTERN void application_plugin_manager_value_take_plugin_globals (GValue* value,
                                                           gpointer v_object);
VALA_EXTERN gpointer application_plugin_manager_value_get_plugin_globals (const GValue* value);
VALA_EXTERN GType application_plugin_manager_plugin_globals_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gpointer application_plugin_manager_plugin_context_ref (gpointer instance);
VALA_EXTERN void application_plugin_manager_plugin_context_unref (gpointer instance);
VALA_EXTERN GParamSpec* application_plugin_manager_param_spec_plugin_context (const gchar* name,
                                                                  const gchar* nick,
                                                                  const gchar* blurb,
                                                                  GType object_type,
                                                                  GParamFlags flags);
VALA_EXTERN void application_plugin_manager_value_set_plugin_context (GValue* value,
                                                          gpointer v_object);
VALA_EXTERN void application_plugin_manager_value_take_plugin_context (GValue* value,
                                                           gpointer v_object);
VALA_EXTERN gpointer application_plugin_manager_value_get_plugin_context (const GValue* value);
VALA_EXTERN GType application_plugin_manager_plugin_context_get_type (void) G_GNUC_CONST ;
VALA_EXTERN ApplicationFolderPluginContext* application_folder_plugin_context_new (ApplicationClient* application,
                                                                       ApplicationPluginManagerPluginGlobals* globals,
                                                                       ApplicationPluginManagerPluginContext* plugin);
VALA_EXTERN ApplicationFolderPluginContext* application_folder_plugin_context_construct (GType object_type,
                                                                             ApplicationClient* application,
                                                                             ApplicationPluginManagerPluginGlobals* globals,
                                                                             ApplicationPluginManagerPluginContext* plugin);
VALA_EXTERN GType application_folder_store_factory_get_type (void) G_GNUC_CONST ;
VALA_EXTERN ApplicationFolderStoreFactory* application_plugin_manager_plugin_globals_get_folders (ApplicationPluginManagerPluginGlobals* self);
VALA_EXTERN PluginFolderStore* application_folder_store_factory_new_folder_store (ApplicationFolderStoreFactory* self);
static void application_folder_plugin_context_real_get_folder_store_data_free (gpointer _data);
static void application_folder_plugin_context_real_get_folder_store (PluginFolderContext* base,
                                                              GAsyncReadyCallback _callback_,
                                                              gpointer _user_data_);
static gboolean application_folder_plugin_context_real_get_folder_store_co (ApplicationFolderPluginContextGetFolderStoreData* _data_);
static void application_folder_plugin_context_real_add_folder_info_bar (PluginFolderContext* base,
                                                                 PluginFolder* selected,
                                                                 PluginInfoBar* info_bar,
                                                                 guint priority);
VALA_EXTERN GearyFolder* application_folder_store_factory_to_engine_folder (ApplicationFolderStoreFactory* self,
                                                                PluginFolder* plugin);
VALA_EXTERN const gchar* application_plugin_manager_plugin_context_get_action_group_name (ApplicationPluginManagerPluginContext* self);
static void application_folder_plugin_context_real_remove_folder_info_bar (PluginFolderContext* base,
                                                                    PluginFolder* selected,
                                                                    PluginInfoBar* info_bar);
static void application_folder_plugin_context_real_register_folder_used_as (PluginFolderContext* base,
                                                                     PluginFolder* target,
                                                                     const gchar* name,
                                                                     const gchar* icon_name,
                                                                     GError** error);
VALA_EXTERN ApplicationFolderContext* application_folder_store_factory_to_folder_context (ApplicationFolderStoreFactory* self,
                                                                              PluginFolder* plugin);
static void application_folder_plugin_context_real_unregister_folder_used_as (PluginFolderContext* base,
                                                                       PluginFolder* target,
                                                                       GError** error);
VALA_EXTERN void application_folder_plugin_context_destroy (ApplicationFolderPluginContext* self);
VALA_EXTERN void application_folder_store_factory_destroy_folder_store (ApplicationFolderStoreFactory* self,
                                                            PluginFolderStore* plugin);
static void application_folder_plugin_context_finalize (GObject * obj);
static GType application_folder_plugin_context_get_type_once (void);

static inline gpointer
application_folder_plugin_context_get_instance_private (ApplicationFolderPluginContext* self)
{
	return G_STRUCT_MEMBER_P (self, ApplicationFolderPluginContext_private_offset);
}

static gpointer
_application_plugin_manager_plugin_globals_ref0 (gpointer self)
{
	return self ? application_plugin_manager_plugin_globals_ref (self) : NULL;
}

static gpointer
_application_plugin_manager_plugin_context_ref0 (gpointer self)
{
	return self ? application_plugin_manager_plugin_context_ref (self) : NULL;
}

ApplicationFolderPluginContext*
application_folder_plugin_context_construct (GType object_type,
                                             ApplicationClient* application,
                                             ApplicationPluginManagerPluginGlobals* globals,
                                             ApplicationPluginManagerPluginContext* plugin)
{
	ApplicationFolderPluginContext * self = NULL;
	ApplicationPluginManagerPluginGlobals* _tmp0_;
	ApplicationPluginManagerPluginContext* _tmp1_;
	ApplicationFolderStoreFactory* _tmp2_;
	ApplicationFolderStoreFactory* _tmp3_;
	PluginFolderStore* _tmp4_;
	g_return_val_if_fail (APPLICATION_IS_CLIENT (application), NULL);
	g_return_val_if_fail (APPLICATION_PLUGIN_MANAGER_IS_PLUGIN_GLOBALS (globals), NULL);
	g_return_val_if_fail (APPLICATION_PLUGIN_MANAGER_IS_PLUGIN_CONTEXT (plugin), NULL);
	self = (ApplicationFolderPluginContext*) geary_base_object_construct (object_type);
	self->priv->application = application;
	_tmp0_ = _application_plugin_manager_plugin_globals_ref0 (globals);
	_application_plugin_manager_plugin_globals_unref0 (self->priv->globals);
	self->priv->globals = _tmp0_;
	_tmp1_ = _application_plugin_manager_plugin_context_ref0 (plugin);
	_application_plugin_manager_plugin_context_unref0 (self->priv->plugin);
	self->priv->plugin = _tmp1_;
	_tmp2_ = application_plugin_manager_plugin_globals_get_folders (globals);
	_tmp3_ = _tmp2_;
	_tmp4_ = application_folder_store_factory_new_folder_store (_tmp3_);
	_g_object_unref0 (self->priv->folders);
	self->priv->folders = _tmp4_;
	return self;
}

ApplicationFolderPluginContext*
application_folder_plugin_context_new (ApplicationClient* application,
                                       ApplicationPluginManagerPluginGlobals* globals,
                                       ApplicationPluginManagerPluginContext* plugin)
{
	return application_folder_plugin_context_construct (APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, application, globals, plugin);
}

static void
application_folder_plugin_context_real_get_folder_store_data_free (gpointer _data)
{
	ApplicationFolderPluginContextGetFolderStoreData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ApplicationFolderPluginContextGetFolderStoreData, _data_);
}

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

static void
application_folder_plugin_context_real_get_folder_store (PluginFolderContext* base,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_)
{
	ApplicationFolderPluginContext * self;
	ApplicationFolderPluginContextGetFolderStoreData* _data_;
	ApplicationFolderPluginContext* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext);
	_data_ = g_slice_new0 (ApplicationFolderPluginContextGetFolderStoreData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, application_folder_plugin_context_real_get_folder_store_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	application_folder_plugin_context_real_get_folder_store_co (_data_);
}

static PluginFolderStore*
application_folder_plugin_context_get_folder_store_finish (PluginFolderContext* base,
                                                           GAsyncResult* _res_,
                                                           GError** error)
{
	PluginFolderStore* result;
	ApplicationFolderPluginContextGetFolderStoreData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
application_folder_plugin_context_real_get_folder_store_co (ApplicationFolderPluginContextGetFolderStoreData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->folders;
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->result = _data_->_tmp1_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
application_folder_plugin_context_real_add_folder_info_bar (PluginFolderContext* base,
                                                            PluginFolder* selected,
                                                            PluginInfoBar* info_bar,
                                                            guint priority)
{
	ApplicationFolderPluginContext * self;
	GearyFolder* folder = NULL;
	ApplicationPluginManagerPluginGlobals* _tmp0_;
	ApplicationFolderStoreFactory* _tmp1_;
	ApplicationFolderStoreFactory* _tmp2_;
	GearyFolder* _tmp3_;
	GearyFolder* _tmp4_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext);
	g_return_if_fail (PLUGIN_IS_FOLDER (selected));
	g_return_if_fail (PLUGIN_IS_INFO_BAR (info_bar));
	_tmp0_ = self->priv->globals;
	_tmp1_ = application_plugin_manager_plugin_globals_get_folders (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = application_folder_store_factory_to_engine_folder (_tmp2_, selected);
	folder = _tmp3_;
	_tmp4_ = folder;
	if (_tmp4_ != NULL) {
		{
			GeeIterator* _main_it = NULL;
			ApplicationClient* _tmp5_;
			GeeCollection* _tmp6_;
			GeeCollection* _tmp7_;
			GeeIterator* _tmp8_;
			GeeIterator* _tmp9_;
			_tmp5_ = self->priv->application;
			_tmp6_ = application_client_get_main_windows (_tmp5_);
			_tmp7_ = _tmp6_;
			_tmp8_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_ITERABLE, GeeIterable));
			_tmp9_ = _tmp8_;
			_g_object_unref0 (_tmp7_);
			_main_it = _tmp9_;
			while (TRUE) {
				GeeIterator* _tmp10_;
				ApplicationMainWindow* main = NULL;
				GeeIterator* _tmp11_;
				gpointer _tmp12_;
				ApplicationMainWindow* _tmp13_;
				GearyFolder* _tmp14_;
				GearyFolder* _tmp15_;
				GearyFolder* _tmp16_;
				_tmp10_ = _main_it;
				if (!gee_iterator_next (_tmp10_)) {
					break;
				}
				_tmp11_ = _main_it;
				_tmp12_ = gee_iterator_get (_tmp11_);
				main = (ApplicationMainWindow*) _tmp12_;
				_tmp13_ = main;
				_tmp14_ = application_main_window_get_selected_folder (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp16_ = folder;
				if (_tmp15_ == _tmp16_) {
					ApplicationMainWindow* _tmp17_;
					ComponentsInfoBarStack* _tmp18_;
					ComponentsInfoBarStack* _tmp19_;
					ApplicationPluginManagerPluginContext* _tmp20_;
					const gchar* _tmp21_;
					const gchar* _tmp22_;
					ComponentsInfoBar* _tmp23_;
					ComponentsInfoBar* _tmp24_;
					_tmp17_ = main;
					_tmp18_ = application_main_window_get_conversation_list_info_bars (_tmp17_);
					_tmp19_ = _tmp18_;
					_tmp20_ = self->priv->plugin;
					_tmp21_ = application_plugin_manager_plugin_context_get_action_group_name (_tmp20_);
					_tmp22_ = _tmp21_;
					_tmp23_ = components_info_bar_new_for_plugin (info_bar, _tmp22_, (gint) priority);
					g_object_ref_sink (_tmp23_);
					_tmp24_ = _tmp23_;
					components_info_bar_stack_add (_tmp19_, _tmp24_);
					_g_object_unref0 (_tmp24_);
				}
				_g_object_unref0 (main);
			}
			_g_object_unref0 (_main_it);
		}
	}
	_g_object_unref0 (folder);
}

static void
application_folder_plugin_context_real_remove_folder_info_bar (PluginFolderContext* base,
                                                               PluginFolder* selected,
                                                               PluginInfoBar* info_bar)
{
	ApplicationFolderPluginContext * self;
	GearyFolder* folder = NULL;
	ApplicationPluginManagerPluginGlobals* _tmp0_;
	ApplicationFolderStoreFactory* _tmp1_;
	ApplicationFolderStoreFactory* _tmp2_;
	GearyFolder* _tmp3_;
	GearyFolder* _tmp4_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext);
	g_return_if_fail (PLUGIN_IS_FOLDER (selected));
	g_return_if_fail (PLUGIN_IS_INFO_BAR (info_bar));
	_tmp0_ = self->priv->globals;
	_tmp1_ = application_plugin_manager_plugin_globals_get_folders (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = application_folder_store_factory_to_engine_folder (_tmp2_, selected);
	folder = _tmp3_;
	_tmp4_ = folder;
	if (_tmp4_ != NULL) {
		{
			GeeIterator* _main_it = NULL;
			ApplicationClient* _tmp5_;
			GeeCollection* _tmp6_;
			GeeCollection* _tmp7_;
			GeeIterator* _tmp8_;
			GeeIterator* _tmp9_;
			_tmp5_ = self->priv->application;
			_tmp6_ = application_client_get_main_windows (_tmp5_);
			_tmp7_ = _tmp6_;
			_tmp8_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GEE_TYPE_ITERABLE, GeeIterable));
			_tmp9_ = _tmp8_;
			_g_object_unref0 (_tmp7_);
			_main_it = _tmp9_;
			while (TRUE) {
				GeeIterator* _tmp10_;
				ApplicationMainWindow* main = NULL;
				GeeIterator* _tmp11_;
				gpointer _tmp12_;
				ApplicationMainWindow* _tmp13_;
				GearyFolder* _tmp14_;
				GearyFolder* _tmp15_;
				GearyFolder* _tmp16_;
				_tmp10_ = _main_it;
				if (!gee_iterator_next (_tmp10_)) {
					break;
				}
				_tmp11_ = _main_it;
				_tmp12_ = gee_iterator_get (_tmp11_);
				main = (ApplicationMainWindow*) _tmp12_;
				_tmp13_ = main;
				_tmp14_ = application_main_window_get_selected_folder (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp16_ = folder;
				if (_tmp15_ == _tmp16_) {
				}
				_g_object_unref0 (main);
			}
			_g_object_unref0 (_main_it);
		}
	}
	_g_object_unref0 (folder);
}

static void
application_folder_plugin_context_real_register_folder_used_as (PluginFolderContext* base,
                                                                PluginFolder* target,
                                                                const gchar* name,
                                                                const gchar* icon_name,
                                                                GError** error)
{
	ApplicationFolderPluginContext * self;
	ApplicationFolderContext* context = NULL;
	ApplicationPluginManagerPluginGlobals* _tmp0_;
	ApplicationFolderStoreFactory* _tmp1_;
	ApplicationFolderStoreFactory* _tmp2_;
	ApplicationFolderContext* _tmp3_;
	ApplicationFolderContext* _tmp4_;
	GError* _inner_error0_ = NULL;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext);
	g_return_if_fail (PLUGIN_IS_FOLDER (target));
	g_return_if_fail (name != NULL);
	g_return_if_fail (icon_name != NULL);
	_tmp0_ = self->priv->globals;
	_tmp1_ = application_plugin_manager_plugin_globals_get_folders (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = application_folder_store_factory_to_folder_context (_tmp2_, target);
	context = _tmp3_;
	_tmp4_ = context;
	if (_tmp4_ != NULL) {
		ApplicationFolderContext* _tmp11_;
		ApplicationFolderContext* _tmp12_;
		{
			ApplicationFolderContext* _tmp5_;
			GearyFolder* _tmp6_;
			GearyFolder* _tmp7_;
			_tmp5_ = context;
			_tmp6_ = application_folder_context_get_folder (_tmp5_);
			_tmp7_ = _tmp6_;
			geary_folder_set_used_as_custom (_tmp7_, TRUE, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GEARY_ENGINE_ERROR) {
					goto __catch0_geary_engine_error;
				}
				_g_object_unref0 (context);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		goto __finally0;
		__catch0_geary_engine_error:
		{
			GError* err = NULL;
			GError* _tmp8_;
			const gchar* _tmp9_;
			GError* _tmp10_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp8_ = err;
			_tmp9_ = _tmp8_->message;
			_tmp10_ = g_error_new (PLUGIN_ERROR, PLUGIN_ERROR_NOT_SUPPORTED, "Failed to register folder use: %s", _tmp9_);
			_inner_error0_ = _tmp10_;
			_g_error_free0 (err);
			goto __finally0;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == PLUGIN_ERROR) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (context);
				return;
			} else {
				_g_object_unref0 (context);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		_tmp11_ = context;
		application_folder_context_set_display_name (_tmp11_, name);
		_tmp12_ = context;
		application_folder_context_set_icon_name (_tmp12_, icon_name);
	}
	_g_object_unref0 (context);
}

static void
application_folder_plugin_context_real_unregister_folder_used_as (PluginFolderContext* base,
                                                                  PluginFolder* target,
                                                                  GError** error)
{
	ApplicationFolderPluginContext * self;
	ApplicationFolderContext* context = NULL;
	ApplicationPluginManagerPluginGlobals* _tmp0_;
	ApplicationFolderStoreFactory* _tmp1_;
	ApplicationFolderStoreFactory* _tmp2_;
	ApplicationFolderContext* _tmp3_;
	ApplicationFolderContext* _tmp4_;
	GError* _inner_error0_ = NULL;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext);
	g_return_if_fail (PLUGIN_IS_FOLDER (target));
	_tmp0_ = self->priv->globals;
	_tmp1_ = application_plugin_manager_plugin_globals_get_folders (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = application_folder_store_factory_to_folder_context (_tmp2_, target);
	context = _tmp3_;
	_tmp4_ = context;
	if (_tmp4_ != NULL) {
		{
			ApplicationFolderContext* _tmp5_;
			GearyFolder* _tmp6_;
			GearyFolder* _tmp7_;
			_tmp5_ = context;
			_tmp6_ = application_folder_context_get_folder (_tmp5_);
			_tmp7_ = _tmp6_;
			geary_folder_set_used_as_custom (_tmp7_, FALSE, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == GEARY_ENGINE_ERROR) {
					goto __catch0_geary_engine_error;
				}
				_g_object_unref0 (context);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
		goto __finally0;
		__catch0_geary_engine_error:
		{
			GError* err = NULL;
			GError* _tmp8_;
			const gchar* _tmp9_;
			GError* _tmp10_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp8_ = err;
			_tmp9_ = _tmp8_->message;
			_tmp10_ = g_error_new (PLUGIN_ERROR, PLUGIN_ERROR_NOT_SUPPORTED, "Failed to unregister folder use: %s", _tmp9_);
			_inner_error0_ = _tmp10_;
			_g_error_free0 (err);
			goto __finally0;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == PLUGIN_ERROR) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (context);
				return;
			} else {
				_g_object_unref0 (context);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
		}
	}
	_g_object_unref0 (context);
}

void
application_folder_plugin_context_destroy (ApplicationFolderPluginContext* self)
{
	ApplicationPluginManagerPluginGlobals* _tmp0_;
	ApplicationFolderStoreFactory* _tmp1_;
	ApplicationFolderStoreFactory* _tmp2_;
	PluginFolderStore* _tmp3_;
	g_return_if_fail (APPLICATION_IS_FOLDER_PLUGIN_CONTEXT (self));
	_tmp0_ = self->priv->globals;
	_tmp1_ = application_plugin_manager_plugin_globals_get_folders (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->folders;
	application_folder_store_factory_destroy_folder_store (_tmp2_, _tmp3_);
}

static void
application_folder_plugin_context_class_init (ApplicationFolderPluginContextClass * klass,
                                              gpointer klass_data)
{
	application_folder_plugin_context_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ApplicationFolderPluginContext_private_offset);
	G_OBJECT_CLASS (klass)->finalize = application_folder_plugin_context_finalize;
}

static void
application_folder_plugin_context_plugin_folder_context_interface_init (PluginFolderContextIface * iface,
                                                                        gpointer iface_data)
{
	application_folder_plugin_context_plugin_folder_context_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_folder_store = (void (*) (PluginFolderContext*, GAsyncReadyCallback, gpointer)) application_folder_plugin_context_real_get_folder_store;
	iface->get_folder_store_finish = (PluginFolderStore* (*) (PluginFolderContext*, GAsyncResult*, GError**)) application_folder_plugin_context_get_folder_store_finish;
	iface->add_folder_info_bar = (void (*) (PluginFolderContext*, PluginFolder*, PluginInfoBar*, guint)) application_folder_plugin_context_real_add_folder_info_bar;
	iface->remove_folder_info_bar = (void (*) (PluginFolderContext*, PluginFolder*, PluginInfoBar*)) application_folder_plugin_context_real_remove_folder_info_bar;
	iface->register_folder_used_as = (void (*) (PluginFolderContext*, PluginFolder*, const gchar*, const gchar*, GError**)) application_folder_plugin_context_real_register_folder_used_as;
	iface->unregister_folder_used_as = (void (*) (PluginFolderContext*, PluginFolder*, GError**)) application_folder_plugin_context_real_unregister_folder_used_as;
}

static void
application_folder_plugin_context_instance_init (ApplicationFolderPluginContext * self,
                                                 gpointer klass)
{
	self->priv = application_folder_plugin_context_get_instance_private (self);
}

static void
application_folder_plugin_context_finalize (GObject * obj)
{
	ApplicationFolderPluginContext * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, APPLICATION_TYPE_FOLDER_PLUGIN_CONTEXT, ApplicationFolderPluginContext);
	_application_plugin_manager_plugin_globals_unref0 (self->priv->globals);
	_application_plugin_manager_plugin_context_unref0 (self->priv->plugin);
	_g_object_unref0 (self->priv->folders);
	G_OBJECT_CLASS (application_folder_plugin_context_parent_class)->finalize (obj);
}

/**
 * Implementation of the folder plugin extension context.
 */
static GType
application_folder_plugin_context_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ApplicationFolderPluginContextClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) application_folder_plugin_context_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ApplicationFolderPluginContext), 0, (GInstanceInitFunc) application_folder_plugin_context_instance_init, NULL };
	static const GInterfaceInfo plugin_folder_context_info = { (GInterfaceInitFunc) application_folder_plugin_context_plugin_folder_context_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType application_folder_plugin_context_type_id;
	application_folder_plugin_context_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "ApplicationFolderPluginContext", &g_define_type_info, 0);
	g_type_add_interface_static (application_folder_plugin_context_type_id, PLUGIN_TYPE_FOLDER_CONTEXT, &plugin_folder_context_info);
	ApplicationFolderPluginContext_private_offset = g_type_add_instance_private (application_folder_plugin_context_type_id, sizeof (ApplicationFolderPluginContextPrivate));
	return application_folder_plugin_context_type_id;
}

GType
application_folder_plugin_context_get_type (void)
{
	static volatile gsize application_folder_plugin_context_type_id__once = 0;
	if (g_once_init_enter (&application_folder_plugin_context_type_id__once)) {
		GType application_folder_plugin_context_type_id;
		application_folder_plugin_context_type_id = application_folder_plugin_context_get_type_once ();
		g_once_init_leave (&application_folder_plugin_context_type_id__once, application_folder_plugin_context_type_id);
	}
	return application_folder_plugin_context_type_id__once;
}

