/* notification-badge.c generated by valac 0.56.19, the Vala compiler
 * generated from notification-badge.vala, do not modify */

/*
 * Copyright © 2016 Software Freedom Conservancy Inc.
 * Copyright © 2019-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 "notification-badge.h"
#include <glib-object.h>
#include <glib.h>
#include <libpeas.h>
#include "geary-client-46.0.h"
#include <gio/gio.h>
#include "geary-engine.h"
#include <stdlib.h>
#include <string.h>
#include <gee.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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	PLUGIN_NOTIFICATION_BADGE_0_PROPERTY,
	PLUGIN_NOTIFICATION_BADGE_NOTIFICATIONS_PROPERTY,
	PLUGIN_NOTIFICATION_BADGE_FOLDERS_PROPERTY,
	PLUGIN_NOTIFICATION_BADGE_CLIENT_APPLICATION_PROPERTY,
	PLUGIN_NOTIFICATION_BADGE_CLIENT_PLUGINS_PROPERTY,
	PLUGIN_NOTIFICATION_BADGE_NUM_PROPERTIES
};
static GParamSpec* plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _PluginNotificationBadgeActivateData PluginNotificationBadgeActivateData;
typedef struct _PluginNotificationBadgeDeactivateData PluginNotificationBadgeDeactivateData;

struct _PluginNotificationBadgePrivate {
	PluginNotificationContext* _notifications;
	PluginFolderContext* _folders;
	ApplicationClient* _client_application;
	ApplicationPluginManager* _client_plugins;
	UnityLauncherEntry* entry;
};

struct _PluginNotificationBadgeActivateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginNotificationBadge* self;
	gboolean is_startup;
	GDBusConnection* connection;
	ApplicationClient* _tmp0_;
	ApplicationClient* _tmp1_;
	GDBusConnection* _tmp2_;
	GDBusConnection* _tmp3_;
	gchar* path;
	ApplicationClient* _tmp4_;
	ApplicationClient* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gboolean _tmp8_;
	GDBusConnection* _tmp9_;
	const gchar* _tmp10_;
	GError* _tmp11_;
	UnityLauncherEntry* _tmp12_;
	GDBusConnection* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	UnityLauncherEntry* _tmp17_;
	UnityLauncherEntry* _tmp18_;
	UnityLauncherEntry* _tmp19_;
	PluginFolderStore* folder_store;
	PluginFolderContext* _tmp20_;
	PluginFolderContext* _tmp21_;
	PluginFolderStore* _tmp22_;
	PluginFolderStore* _tmp23_;
	PluginFolderStore* _tmp24_;
	PluginFolderStore* _tmp25_;
	PluginFolderStore* _tmp26_;
	GeeCollection* _tmp27_;
	GeeCollection* _tmp28_;
	PluginNotificationContext* _tmp29_;
	PluginNotificationContext* _tmp30_;
	GError* _inner_error0_;
};

struct _PluginNotificationBadgeDeactivateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	PluginNotificationBadge* self;
	gboolean is_shutdown;
	PluginNotificationContext* _tmp0_;
	PluginNotificationContext* _tmp1_;
	guint _tmp2_;
	GQuark _tmp3_;
};

static gint PluginNotificationBadge_private_offset;
static gpointer plugin_notification_badge_parent_class = NULL;
static PluginNotificationExtensionIface * plugin_notification_badge_plugin_notification_extension_parent_iface = NULL;
static PluginFolderExtensionIface * plugin_notification_badge_plugin_folder_extension_parent_iface = NULL;
static PluginTrustedExtensionIface * plugin_notification_badge_plugin_trusted_extension_parent_iface = NULL;
static GType plugin_notification_badge_type_id = 0;

GType unity_launcher_entry_register_type (GTypeModule * module);
GType unity_launcher_entry_entry_register_type (GTypeModule * module);
static void plugin_notification_badge_real_activate_data_free (gpointer _data);
static void plugin_notification_badge_real_activate (PluginPluginBase* base,
                                              gboolean is_startup,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_);
static gboolean plugin_notification_badge_real_activate_co (PluginNotificationBadgeActivateData* _data_);
static void plugin_notification_badge_activate_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void __lambda4_ (PluginNotificationBadge* self,
                 GeeCollection* folders);
static void plugin_notification_badge_check_folders (PluginNotificationBadge* self,
                                              GeeCollection* folders);
static void ___lambda4__plugin_folder_store_folders_available (PluginFolderStore* _sender,
                                                        GeeCollection* available,
                                                        gpointer self);
static void __lambda5_ (PluginNotificationBadge* self,
                 GeeCollection* folders);
static void ___lambda5__plugin_folder_store_folders_unavailable (PluginFolderStore* _sender,
                                                          GeeCollection* unavailable,
                                                          gpointer self);
static void __lambda6_ (PluginNotificationBadge* self,
                 GeeCollection* folders);
static void ___lambda6__plugin_folder_store_folders_type_changed (PluginFolderStore* _sender,
                                                           GeeCollection* changed,
                                                           gpointer self);
static void plugin_notification_badge_on_total_changed (PluginNotificationBadge* self);
static void _plugin_notification_badge_on_total_changed_g_object_notify (GObject* _sender,
                                                                  GParamSpec* pspec,
                                                                  gpointer self);
static void plugin_notification_badge_update_count (PluginNotificationBadge* self);
static void plugin_notification_badge_real_deactivate_data_free (gpointer _data);
static void plugin_notification_badge_real_deactivate (PluginPluginBase* base,
                                                gboolean is_shutdown,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static gboolean plugin_notification_badge_real_deactivate_co (PluginNotificationBadgeDeactivateData* _data_);
static gboolean _vala_geary_folder_special_use_array_contains (GearyFolderSpecialUse * stack,
                                                        gssize stack_length,
                                                        const GearyFolderSpecialUse needle);
static void plugin_notification_badge_finalize (GObject * obj);
static void _vala_plugin_notification_badge_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_plugin_notification_badge_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static const GearyFolderSpecialUse PLUGIN_NOTIFICATION_BADGE_MONITORED_TYPES[2] = {GEARY_FOLDER_SPECIAL_USE_INBOX, GEARY_FOLDER_SPECIAL_USE_NONE};

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

void
peas_register_types (GTypeModule* module)
{
	PeasObjectModule* obj = NULL;
	PeasObjectModule* _tmp0_;
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (module, g_type_module_get_type ()));
	plugin_notification_badge_register_type (module);
	unity_launcher_entry_register_type (module);
	unity_launcher_entry_entry_register_type (module);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (module, peas_object_module_get_type ()) ? ((PeasObjectModule*) module) : NULL);
	obj = _tmp0_;
	peas_object_module_register_extension_type (obj, PLUGIN_TYPE_PLUGIN_BASE, PLUGIN_TYPE_NOTIFICATION_BADGE);
	_g_object_unref0 (obj);
}

static inline gpointer
plugin_notification_badge_get_instance_private (PluginNotificationBadge* self)
{
	return G_STRUCT_MEMBER_P (self, PluginNotificationBadge_private_offset);
}

static PluginNotificationContext*
plugin_notification_badge_real_get_notifications (PluginNotificationExtension* base)
{
	PluginNotificationContext* result;
	PluginNotificationBadge* self;
	PluginNotificationContext* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_tmp0_ = self->priv->_notifications;
	result = _tmp0_;
	return result;
}

static void
plugin_notification_badge_real_set_notifications (PluginNotificationExtension* base,
                                                  PluginNotificationContext* value)
{
	PluginNotificationBadge* self;
	PluginNotificationContext* old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	old_value = plugin_notification_badge_real_get_notifications (base);
	if (old_value != value) {
		PluginNotificationContext* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_notifications);
		self->priv->_notifications = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_NOTIFICATIONS_PROPERTY]);
	}
}

static PluginFolderContext*
plugin_notification_badge_real_get_folders (PluginFolderExtension* base)
{
	PluginFolderContext* result;
	PluginNotificationBadge* self;
	PluginFolderContext* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_tmp0_ = self->priv->_folders;
	result = _tmp0_;
	return result;
}

static void
plugin_notification_badge_real_set_folders (PluginFolderExtension* base,
                                            PluginFolderContext* value)
{
	PluginNotificationBadge* self;
	PluginFolderContext* old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	old_value = plugin_notification_badge_real_get_folders (base);
	if (old_value != value) {
		PluginFolderContext* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_folders);
		self->priv->_folders = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_FOLDERS_PROPERTY]);
	}
}

static ApplicationClient*
plugin_notification_badge_real_get_client_application (PluginTrustedExtension* base)
{
	ApplicationClient* result;
	PluginNotificationBadge* self;
	ApplicationClient* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_tmp0_ = self->priv->_client_application;
	result = _tmp0_;
	return result;
}

static void
plugin_notification_badge_real_set_client_application (PluginTrustedExtension* base,
                                                       ApplicationClient* value)
{
	PluginNotificationBadge* self;
	ApplicationClient* old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	old_value = plugin_notification_badge_real_get_client_application (base);
	if (old_value != value) {
		ApplicationClient* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_client_application);
		self->priv->_client_application = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_CLIENT_APPLICATION_PROPERTY]);
	}
}

static ApplicationPluginManager*
plugin_notification_badge_real_get_client_plugins (PluginTrustedExtension* base)
{
	ApplicationPluginManager* result;
	PluginNotificationBadge* self;
	ApplicationPluginManager* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_tmp0_ = self->priv->_client_plugins;
	result = _tmp0_;
	return result;
}

static void
plugin_notification_badge_real_set_client_plugins (PluginTrustedExtension* base,
                                                   ApplicationPluginManager* value)
{
	PluginNotificationBadge* self;
	ApplicationPluginManager* old_value;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	old_value = plugin_notification_badge_real_get_client_plugins (base);
	if (old_value != value) {
		ApplicationPluginManager* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_client_plugins);
		self->priv->_client_plugins = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_CLIENT_PLUGINS_PROPERTY]);
	}
}

static void
plugin_notification_badge_real_activate_data_free (gpointer _data)
{
	PluginNotificationBadgeActivateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PluginNotificationBadgeActivateData, _data_);
}

static void
plugin_notification_badge_real_activate (PluginPluginBase* base,
                                         gboolean is_startup,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_)
{
	PluginNotificationBadge * self;
	PluginNotificationBadgeActivateData* _data_;
	PluginNotificationBadge* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_data_ = g_slice_new0 (PluginNotificationBadgeActivateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_notification_badge_real_activate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->is_startup = is_startup;
	plugin_notification_badge_real_activate_co (_data_);
}

static void
plugin_notification_badge_activate_finish (PluginPluginBase* base,
                                           GAsyncResult* _res_,
                                           GError** error)
{
	PluginNotificationBadgeActivateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
plugin_notification_badge_activate_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	PluginNotificationBadgeActivateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	plugin_notification_badge_real_activate_co (_data_);
}

static void
__lambda4_ (PluginNotificationBadge* self,
            GeeCollection* folders)
{
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folders, GEE_TYPE_COLLECTION));
	plugin_notification_badge_check_folders (self, folders);
}

static void
___lambda4__plugin_folder_store_folders_available (PluginFolderStore* _sender,
                                                   GeeCollection* available,
                                                   gpointer self)
{
	__lambda4_ ((PluginNotificationBadge*) self, available);
}

static void
__lambda5_ (PluginNotificationBadge* self,
            GeeCollection* folders)
{
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folders, GEE_TYPE_COLLECTION));
	plugin_notification_badge_check_folders (self, folders);
}

static void
___lambda5__plugin_folder_store_folders_unavailable (PluginFolderStore* _sender,
                                                     GeeCollection* unavailable,
                                                     gpointer self)
{
	__lambda5_ ((PluginNotificationBadge*) self, unavailable);
}

static void
__lambda6_ (PluginNotificationBadge* self,
            GeeCollection* folders)
{
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folders, GEE_TYPE_COLLECTION));
	plugin_notification_badge_check_folders (self, folders);
}

static void
___lambda6__plugin_folder_store_folders_type_changed (PluginFolderStore* _sender,
                                                      GeeCollection* changed,
                                                      gpointer self)
{
	__lambda6_ ((PluginNotificationBadge*) self, changed);
}

static void
_plugin_notification_badge_on_total_changed_g_object_notify (GObject* _sender,
                                                             GParamSpec* pspec,
                                                             gpointer self)
{
	plugin_notification_badge_on_total_changed ((PluginNotificationBadge*) self);
}

static gboolean
plugin_notification_badge_real_activate_co (PluginNotificationBadgeActivateData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = plugin_trusted_extension_get_client_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_TRUSTED_EXTENSION, PluginTrustedExtension));
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = g_application_get_dbus_connection (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, g_application_get_type (), GApplication));
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp2_);
	_data_->connection = _data_->_tmp3_;
	_data_->_tmp4_ = plugin_trusted_extension_get_client_application (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_TRUSTED_EXTENSION, PluginTrustedExtension));
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_tmp6_ = g_application_get_dbus_object_path (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp5_, g_application_get_type (), GApplication));
	_data_->_tmp7_ = g_strdup (_data_->_tmp6_);
	_data_->path = _data_->_tmp7_;
	_data_->_tmp9_ = _data_->connection;
	if (_data_->_tmp9_ == NULL) {
		_data_->_tmp8_ = TRUE;
	} else {
		_data_->_tmp10_ = _data_->path;
		_data_->_tmp8_ = _data_->_tmp10_ == NULL;
	}
	if (_data_->_tmp8_) {
		_data_->_tmp11_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "Application does not have a DBus connection or path");
		_data_->_inner_error0_ = _data_->_tmp11_;
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->path);
		_g_object_unref0 (_data_->connection);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = _data_->connection;
	_data_->_tmp14_ = _data_->path;
	_data_->_tmp15_ = g_strconcat (_data_->_tmp14_, "/plugin/notificationbadge", NULL);
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = unity_launcher_entry_new (_data_->_tmp13_, _data_->_tmp16_, APPLICATION_CLIENT_APP_ID ".desktop", &_data_->_inner_error0_);
	_data_->_tmp18_ = _data_->_tmp17_;
	_g_free0 (_data_->_tmp16_);
	_data_->_tmp12_ = _data_->_tmp18_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->path);
		_g_object_unref0 (_data_->connection);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp19_ = _data_->_tmp12_;
	_data_->_tmp12_ = NULL;
	_g_object_unref0 (_data_->self->priv->entry);
	_data_->self->priv->entry = _data_->_tmp19_;
	_data_->_tmp20_ = plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension));
	_data_->_tmp21_ = _data_->_tmp20_;
	_data_->_state_ = 1;
	plugin_folder_context_get_folder_store (_data_->_tmp21_, plugin_notification_badge_activate_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp22_ = plugin_folder_context_get_folder_store_finish (_data_->_tmp21_, _data_->_res_, &_data_->_inner_error0_);
	_data_->folder_store = _data_->_tmp22_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->_tmp12_);
		_g_free0 (_data_->path);
		_g_object_unref0 (_data_->connection);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp23_ = _data_->folder_store;
	g_signal_connect_object (_data_->_tmp23_, "folders-available", (GCallback) ___lambda4__plugin_folder_store_folders_available, _data_->self, 0);
	_data_->_tmp24_ = _data_->folder_store;
	g_signal_connect_object (_data_->_tmp24_, "folders-unavailable", (GCallback) ___lambda5__plugin_folder_store_folders_unavailable, _data_->self, 0);
	_data_->_tmp25_ = _data_->folder_store;
	g_signal_connect_object (_data_->_tmp25_, "folders-type-changed", (GCallback) ___lambda6__plugin_folder_store_folders_type_changed, _data_->self, 0);
	_data_->_tmp26_ = _data_->folder_store;
	_data_->_tmp27_ = plugin_folder_store_get_folders (_data_->_tmp26_);
	_data_->_tmp28_ = _data_->_tmp27_;
	plugin_notification_badge_check_folders (_data_->self, _data_->_tmp28_);
	_g_object_unref0 (_data_->_tmp28_);
	_data_->_tmp29_ = plugin_notification_extension_get_notifications (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension));
	_data_->_tmp30_ = _data_->_tmp29_;
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp30_, G_TYPE_OBJECT, GObject), "notify::total-new-messages", (GCallback) _plugin_notification_badge_on_total_changed_g_object_notify, _data_->self, 0);
	plugin_notification_badge_update_count (_data_->self);
	_g_object_unref0 (_data_->folder_store);
	_g_object_unref0 (_data_->_tmp12_);
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->connection);
	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
plugin_notification_badge_real_deactivate_data_free (gpointer _data)
{
	PluginNotificationBadgeDeactivateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PluginNotificationBadgeDeactivateData, _data_);
}

static void
plugin_notification_badge_real_deactivate (PluginPluginBase* base,
                                           gboolean is_shutdown,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	PluginNotificationBadge * self;
	PluginNotificationBadgeDeactivateData* _data_;
	PluginNotificationBadge* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_data_ = g_slice_new0 (PluginNotificationBadgeDeactivateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, plugin_notification_badge_real_deactivate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->is_shutdown = is_shutdown;
	plugin_notification_badge_real_deactivate_co (_data_);
}

static void
plugin_notification_badge_deactivate_finish (PluginPluginBase* base,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	PluginNotificationBadgeDeactivateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
plugin_notification_badge_real_deactivate_co (PluginNotificationBadgeDeactivateData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = plugin_notification_extension_get_notifications (G_TYPE_CHECK_INSTANCE_CAST (_data_->self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension));
	_data_->_tmp1_ = _data_->_tmp0_;
	g_signal_parse_name ("notify::total-new-messages", G_TYPE_OBJECT, &_data_->_tmp2_, &_data_->_tmp3_, TRUE);
	g_signal_handlers_disconnect_matched (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, G_TYPE_OBJECT, GObject), G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp2_, _data_->_tmp3_, NULL, (GCallback) _plugin_notification_badge_on_total_changed_g_object_notify, _data_->self);
	_g_object_unref0 (_data_->self->priv->entry);
	_data_->self->priv->entry = NULL;
	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 gboolean
_vala_geary_folder_special_use_array_contains (GearyFolderSpecialUse * stack,
                                               gssize stack_length,
                                               const GearyFolderSpecialUse needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (needle == stack[i]) {
			return TRUE;
		}
	}
	return FALSE;
}

static void
plugin_notification_badge_check_folders (PluginNotificationBadge* self,
                                         GeeCollection* folders)
{
	g_return_if_fail (PLUGIN_IS_NOTIFICATION_BADGE (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (folders, GEE_TYPE_COLLECTION));
	{
		GeeIterator* _folder_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (folders, GEE_TYPE_ITERABLE, GeeIterable));
		_folder_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			PluginFolder* folder = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			PluginFolder* _tmp4_;
			GearyFolderSpecialUse _tmp5_;
			GearyFolderSpecialUse _tmp6_;
			_tmp1_ = _folder_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _folder_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			folder = (PluginFolder*) _tmp3_;
			_tmp4_ = folder;
			_tmp5_ = plugin_folder_get_used_as (_tmp4_);
			_tmp6_ = _tmp5_;
			if (_vala_geary_folder_special_use_array_contains (PLUGIN_NOTIFICATION_BADGE_MONITORED_TYPES, G_N_ELEMENTS (PLUGIN_NOTIFICATION_BADGE_MONITORED_TYPES), _tmp6_)) {
				PluginNotificationContext* _tmp7_;
				PluginNotificationContext* _tmp8_;
				PluginFolder* _tmp9_;
				_tmp7_ = plugin_notification_extension_get_notifications (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension));
				_tmp8_ = _tmp7_;
				_tmp9_ = folder;
				plugin_notification_context_start_monitoring_folder (_tmp8_, _tmp9_);
			} else {
				PluginNotificationContext* _tmp10_;
				PluginNotificationContext* _tmp11_;
				PluginFolder* _tmp12_;
				_tmp10_ = plugin_notification_extension_get_notifications (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension));
				_tmp11_ = _tmp10_;
				_tmp12_ = folder;
				plugin_notification_context_stop_monitoring_folder (_tmp11_, _tmp12_);
			}
			_g_object_unref0 (folder);
		}
		_g_object_unref0 (_folder_it);
	}
}

static void
plugin_notification_badge_update_count (PluginNotificationBadge* self)
{
	UnityLauncherEntry* _tmp0_;
	g_return_if_fail (PLUGIN_IS_NOTIFICATION_BADGE (self));
	_tmp0_ = self->priv->entry;
	if (_tmp0_ != NULL) {
		gint count = 0;
		PluginNotificationContext* _tmp1_;
		PluginNotificationContext* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		_tmp1_ = plugin_notification_extension_get_notifications (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension));
		_tmp2_ = _tmp1_;
		_tmp3_ = plugin_notification_context_get_total_new_messages (_tmp2_);
		_tmp4_ = _tmp3_;
		count = _tmp4_;
		if (count > 0) {
			UnityLauncherEntry* _tmp5_;
			_tmp5_ = self->priv->entry;
			unity_launcher_entry_set_count (_tmp5_, (gint64) count);
		} else {
			UnityLauncherEntry* _tmp6_;
			_tmp6_ = self->priv->entry;
			unity_launcher_entry_clear_count (_tmp6_);
		}
	}
}

static void
plugin_notification_badge_on_total_changed (PluginNotificationBadge* self)
{
	g_return_if_fail (PLUGIN_IS_NOTIFICATION_BADGE (self));
	plugin_notification_badge_update_count (self);
}

PluginNotificationBadge*
plugin_notification_badge_construct (GType object_type)
{
	PluginNotificationBadge * self = NULL;
	self = (PluginNotificationBadge*) plugin_plugin_base_construct (object_type);
	return self;
}

PluginNotificationBadge*
plugin_notification_badge_new (void)
{
	return plugin_notification_badge_construct (PLUGIN_TYPE_NOTIFICATION_BADGE);
}

static void
plugin_notification_badge_class_init (PluginNotificationBadgeClass * klass,
                                      gpointer klass_data)
{
	plugin_notification_badge_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PluginNotificationBadge_private_offset);
	((PluginPluginBaseClass *) klass)->activate = (void (*) (PluginPluginBase*, gboolean, GAsyncReadyCallback, gpointer)) plugin_notification_badge_real_activate;
	((PluginPluginBaseClass *) klass)->activate_finish = (void (*) (PluginPluginBase*, GAsyncResult*, GError**)) plugin_notification_badge_activate_finish;
	((PluginPluginBaseClass *) klass)->deactivate = (void (*) (PluginPluginBase*, gboolean, GAsyncReadyCallback, gpointer)) plugin_notification_badge_real_deactivate;
	((PluginPluginBaseClass *) klass)->deactivate_finish = (void (*) (PluginPluginBase*, GAsyncResult*, GError**)) plugin_notification_badge_deactivate_finish;
	G_OBJECT_CLASS (klass)->get_property = _vala_plugin_notification_badge_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_plugin_notification_badge_set_property;
	G_OBJECT_CLASS (klass)->finalize = plugin_notification_badge_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PLUGIN_NOTIFICATION_BADGE_NOTIFICATIONS_PROPERTY, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_NOTIFICATIONS_PROPERTY] = g_param_spec_object ("notifications", "notifications", "notifications", PLUGIN_TYPE_NOTIFICATION_CONTEXT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PLUGIN_NOTIFICATION_BADGE_FOLDERS_PROPERTY, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_FOLDERS_PROPERTY] = g_param_spec_object ("folders", "folders", "folders", PLUGIN_TYPE_FOLDER_CONTEXT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PLUGIN_NOTIFICATION_BADGE_CLIENT_APPLICATION_PROPERTY, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_CLIENT_APPLICATION_PROPERTY] = g_param_spec_object ("client-application", "client-application", "client-application", APPLICATION_TYPE_CLIENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PLUGIN_NOTIFICATION_BADGE_CLIENT_PLUGINS_PROPERTY, plugin_notification_badge_properties[PLUGIN_NOTIFICATION_BADGE_CLIENT_PLUGINS_PROPERTY] = g_param_spec_object ("client-plugins", "client-plugins", "client-plugins", APPLICATION_TYPE_PLUGIN_MANAGER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
plugin_notification_badge_plugin_notification_extension_interface_init (PluginNotificationExtensionIface * iface,
                                                                        gpointer iface_data)
{
	plugin_notification_badge_plugin_notification_extension_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_notifications = plugin_notification_badge_real_get_notifications;
	iface->set_notifications = plugin_notification_badge_real_set_notifications;
}

static void
plugin_notification_badge_plugin_folder_extension_interface_init (PluginFolderExtensionIface * iface,
                                                                  gpointer iface_data)
{
	plugin_notification_badge_plugin_folder_extension_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_folders = plugin_notification_badge_real_get_folders;
	iface->set_folders = plugin_notification_badge_real_set_folders;
}

static void
plugin_notification_badge_plugin_trusted_extension_interface_init (PluginTrustedExtensionIface * iface,
                                                                   gpointer iface_data)
{
	plugin_notification_badge_plugin_trusted_extension_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_client_application = plugin_notification_badge_real_get_client_application;
	iface->set_client_application = plugin_notification_badge_real_set_client_application;
	iface->get_client_plugins = plugin_notification_badge_real_get_client_plugins;
	iface->set_client_plugins = plugin_notification_badge_real_set_client_plugins;
}

static void
plugin_notification_badge_instance_init (PluginNotificationBadge * self,
                                         gpointer klass)
{
	self->priv = plugin_notification_badge_get_instance_private (self);
	self->priv->entry = NULL;
}

static void
plugin_notification_badge_finalize (GObject * obj)
{
	PluginNotificationBadge * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	_g_object_unref0 (self->priv->_notifications);
	_g_object_unref0 (self->priv->_folders);
	_g_object_unref0 (self->priv->_client_application);
	_g_object_unref0 (self->priv->_client_plugins);
	_g_object_unref0 (self->priv->entry);
	G_OBJECT_CLASS (plugin_notification_badge_parent_class)->finalize (obj);
}

/** Updates Unity application badge with total new message count. */
GType
plugin_notification_badge_get_type (void)
{
	return plugin_notification_badge_type_id;
}

GType
plugin_notification_badge_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (PluginNotificationBadgeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) plugin_notification_badge_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PluginNotificationBadge), 0, (GInstanceInitFunc) plugin_notification_badge_instance_init, NULL };
	static const GInterfaceInfo plugin_notification_extension_info = { (GInterfaceInitFunc) plugin_notification_badge_plugin_notification_extension_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo plugin_folder_extension_info = { (GInterfaceInitFunc) plugin_notification_badge_plugin_folder_extension_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo plugin_trusted_extension_info = { (GInterfaceInitFunc) plugin_notification_badge_plugin_trusted_extension_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	plugin_notification_badge_type_id = g_type_module_register_type (module, PLUGIN_TYPE_PLUGIN_BASE, "PluginNotificationBadge", &g_define_type_info, 0);
	g_type_module_add_interface (module, plugin_notification_badge_type_id, PLUGIN_TYPE_NOTIFICATION_EXTENSION, &plugin_notification_extension_info);
	g_type_module_add_interface (module, plugin_notification_badge_type_id, PLUGIN_TYPE_FOLDER_EXTENSION, &plugin_folder_extension_info);
	g_type_module_add_interface (module, plugin_notification_badge_type_id, PLUGIN_TYPE_TRUSTED_EXTENSION, &plugin_trusted_extension_info);
	PluginNotificationBadge_private_offset = sizeof (PluginNotificationBadgePrivate);
	return plugin_notification_badge_type_id;
}

static void
_vala_plugin_notification_badge_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	PluginNotificationBadge * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	switch (property_id) {
		case PLUGIN_NOTIFICATION_BADGE_NOTIFICATIONS_PROPERTY:
		g_value_set_object (value, plugin_notification_extension_get_notifications (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension)));
		break;
		case PLUGIN_NOTIFICATION_BADGE_FOLDERS_PROPERTY:
		g_value_set_object (value, plugin_folder_extension_get_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension)));
		break;
		case PLUGIN_NOTIFICATION_BADGE_CLIENT_APPLICATION_PROPERTY:
		g_value_set_object (value, plugin_trusted_extension_get_client_application (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_TRUSTED_EXTENSION, PluginTrustedExtension)));
		break;
		case PLUGIN_NOTIFICATION_BADGE_CLIENT_PLUGINS_PROPERTY:
		g_value_set_object (value, plugin_trusted_extension_get_client_plugins (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_TRUSTED_EXTENSION, PluginTrustedExtension)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_plugin_notification_badge_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	PluginNotificationBadge * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PLUGIN_TYPE_NOTIFICATION_BADGE, PluginNotificationBadge);
	switch (property_id) {
		case PLUGIN_NOTIFICATION_BADGE_NOTIFICATIONS_PROPERTY:
		plugin_notification_extension_set_notifications (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_NOTIFICATION_EXTENSION, PluginNotificationExtension), g_value_get_object (value));
		break;
		case PLUGIN_NOTIFICATION_BADGE_FOLDERS_PROPERTY:
		plugin_folder_extension_set_folders (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_FOLDER_EXTENSION, PluginFolderExtension), g_value_get_object (value));
		break;
		case PLUGIN_NOTIFICATION_BADGE_CLIENT_APPLICATION_PROPERTY:
		plugin_trusted_extension_set_client_application (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_TRUSTED_EXTENSION, PluginTrustedExtension), g_value_get_object (value));
		break;
		case PLUGIN_NOTIFICATION_BADGE_CLIENT_PLUGINS_PROPERTY:
		plugin_trusted_extension_set_client_plugins (G_TYPE_CHECK_INSTANCE_CAST (self, PLUGIN_TYPE_TRUSTED_EXTENSION, PluginTrustedExtension), g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

