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

#include <glib-object.h>
#include <gtk/gtk.h>
#include "libdino.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include "dino_i18n.h"
#include <gee.h>
#include <adwaita.h>
#include "xmpp-vala.h"
#include <gobject/gvaluecollector.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DINO_UI_TYPE_ENCRYPTION_BUTTON (dino_ui_encryption_button_get_type ())
#define DINO_UI_ENCRYPTION_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_ENCRYPTION_BUTTON, DinoUiEncryptionButton))
#define DINO_UI_ENCRYPTION_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_ENCRYPTION_BUTTON, DinoUiEncryptionButtonClass))
#define DINO_UI_IS_ENCRYPTION_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_ENCRYPTION_BUTTON))
#define DINO_UI_IS_ENCRYPTION_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_ENCRYPTION_BUTTON))
#define DINO_UI_ENCRYPTION_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_ENCRYPTION_BUTTON, DinoUiEncryptionButtonClass))

typedef struct _DinoUiEncryptionButton DinoUiEncryptionButton;
typedef struct _DinoUiEncryptionButtonClass DinoUiEncryptionButtonClass;
typedef struct _DinoUiEncryptionButtonPrivate DinoUiEncryptionButtonPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

#define DINO_UI_TYPE_APPLICATION (dino_ui_application_get_type ())
#define DINO_UI_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_APPLICATION, DinoUiApplication))
#define DINO_UI_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_APPLICATION, DinoUiApplicationClass))
#define DINO_UI_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_APPLICATION))
#define DINO_UI_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_APPLICATION))
#define DINO_UI_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_APPLICATION, DinoUiApplicationClass))

typedef struct _DinoUiApplication DinoUiApplication;
typedef struct _DinoUiApplicationClass DinoUiApplicationClass;
typedef struct _DinoUiParamSpecEncryptionButton DinoUiParamSpecEncryptionButton;
enum  {
	DINO_UI_ENCRYPTION_BUTTON_ENCRYPTION_CHANGED_SIGNAL,
	DINO_UI_ENCRYPTION_BUTTON_NUM_SIGNALS
};
static guint dino_ui_encryption_button_signals[DINO_UI_ENCRYPTION_BUTTON_NUM_SIGNALS] = {0};

struct _DinoUiEncryptionButton {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DinoUiEncryptionButtonPrivate * priv;
};

struct _DinoUiEncryptionButtonClass {
	GTypeClass parent_class;
	void (*finalize) (DinoUiEncryptionButton *self);
};

struct _DinoUiEncryptionButtonPrivate {
	GtkMenuButton* menu_button;
	DinoEntitiesConversation* conversation;
	gchar* current_icon;
	DinoStreamInteractor* stream_interactor;
	GSimpleAction* action;
	gulong conversation_encryption_handler_id;
};

struct _DinoUiParamSpecEncryptionButton {
	GParamSpec parent_instance;
};

static gint DinoUiEncryptionButton_private_offset;
static gpointer dino_ui_encryption_button_parent_class = NULL;

VALA_EXTERN gpointer dino_ui_encryption_button_ref (gpointer instance);
VALA_EXTERN void dino_ui_encryption_button_unref (gpointer instance);
VALA_EXTERN GParamSpec* dino_ui_param_spec_encryption_button (const gchar* name,
                                                  const gchar* nick,
                                                  const gchar* blurb,
                                                  GType object_type,
                                                  GParamFlags flags);
VALA_EXTERN void dino_ui_value_set_encryption_button (GValue* value,
                                          gpointer v_object);
VALA_EXTERN void dino_ui_value_take_encryption_button (GValue* value,
                                           gpointer v_object);
VALA_EXTERN gpointer dino_ui_value_get_encryption_button (const GValue* value);
VALA_EXTERN GType dino_ui_encryption_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiEncryptionButton, dino_ui_encryption_button_unref)
VALA_EXTERN DinoUiEncryptionButton* dino_ui_encryption_button_new (DinoStreamInteractor* stream_interactor,
                                                       GtkMenuButton* menu_button);
VALA_EXTERN DinoUiEncryptionButton* dino_ui_encryption_button_construct (GType object_type,
                                                             DinoStreamInteractor* stream_interactor,
                                                             GtkMenuButton* menu_button);
VALA_EXTERN GType dino_ui_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiApplication, g_object_unref)
static gint __lambda5_ (DinoUiEncryptionButton* self,
                 DinoPluginsEncryptionListEntry* a,
                 DinoPluginsEncryptionListEntry* b);
static gint ___lambda5__gcompare_data_func (gconstpointer a,
                                     gconstpointer b,
                                     gpointer self);
static void __lambda6_ (DinoUiEncryptionButton* self,
                 GVariant* parameter);
static void ___lambda6__g_simple_action_activate (GSimpleAction* _sender,
                                           GVariant* parameter,
                                           gpointer self);
static void __lambda7_ (DinoUiEncryptionButton* self,
                 DinoEntitiesAccount* account,
                 XmppJid* muc_jid);
static void dino_ui_encryption_button_update_visibility (DinoUiEncryptionButton* self);
static void ___lambda7__dino_muc_manager_room_info_updated (DinoMucManager* _sender,
                                                     DinoEntitiesAccount* account,
                                                     XmppJid* muc_jid,
                                                     gpointer self);
static void dino_ui_encryption_button_update_encryption_menu_state (DinoUiEncryptionButton* self);
static void dino_ui_encryption_button_set_icon (DinoUiEncryptionButton* self,
                                         const gchar* icon);
static void dino_ui_encryption_button_update_encryption_menu_icon (DinoUiEncryptionButton* self);
VALA_EXTERN void dino_ui_encryption_button_set_conversation (DinoUiEncryptionButton* self,
                                                 DinoEntitiesConversation* conversation);
static void __lambda8_ (DinoUiEncryptionButton* self);
static void ___lambda8__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static void dino_ui_encryption_button_finalize (DinoUiEncryptionButton * obj);
static GType dino_ui_encryption_button_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_ui_encryption_button_get_instance_private (DinoUiEncryptionButton* self)
{
	return G_STRUCT_MEMBER_P (self, DinoUiEncryptionButton_private_offset);
}

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

static gint
__lambda5_ (DinoUiEncryptionButton* self,
            DinoPluginsEncryptionListEntry* a,
            DinoPluginsEncryptionListEntry* b)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = dino_plugins_encryption_list_entry_get_name (b);
	_tmp1_ = _tmp0_;
	_tmp2_ = dino_plugins_encryption_list_entry_get_name (a);
	_tmp3_ = _tmp2_;
	result = g_utf8_collate (_tmp1_, _tmp3_);
	return result;
}

static gint
___lambda5__gcompare_data_func (gconstpointer a,
                                gconstpointer b,
                                gpointer self)
{
	gint result;
	result = __lambda5_ ((DinoUiEncryptionButton*) self, (DinoPluginsEncryptionListEntry*) a, (DinoPluginsEncryptionListEntry*) b);
	return result;
}

static void
__lambda6_ (DinoUiEncryptionButton* self,
            GVariant* parameter)
{
	GSimpleAction* _tmp0_;
	DinoEntitiesConversation* _tmp1_;
	DinoEntitiesConversation* _tmp2_;
	DinoEntitiesEncryption _tmp3_;
	DinoEntitiesEncryption _tmp4_;
	_tmp0_ = self->priv->action;
	g_simple_action_set_state (_tmp0_, parameter);
	_tmp1_ = self->priv->conversation;
	dino_entities_conversation_set_encryption (_tmp1_, (DinoEntitiesEncryption) g_variant_get_int32 (parameter));
	_tmp2_ = self->priv->conversation;
	_tmp3_ = dino_entities_conversation_get_encryption (_tmp2_);
	_tmp4_ = _tmp3_;
	g_signal_emit (self, dino_ui_encryption_button_signals[DINO_UI_ENCRYPTION_BUTTON_ENCRYPTION_CHANGED_SIGNAL], 0, _tmp4_);
}

static void
___lambda6__g_simple_action_activate (GSimpleAction* _sender,
                                      GVariant* parameter,
                                      gpointer self)
{
	__lambda6_ ((DinoUiEncryptionButton*) self, parameter);
}

static void
__lambda7_ (DinoUiEncryptionButton* self,
            DinoEntitiesAccount* account,
            XmppJid* muc_jid)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	DinoEntitiesConversation* _tmp2_;
	g_return_if_fail (account != NULL);
	g_return_if_fail (muc_jid != NULL);
	_tmp2_ = self->priv->conversation;
	if (_tmp2_ != NULL) {
		DinoEntitiesConversation* _tmp3_;
		DinoEntitiesAccount* _tmp4_;
		DinoEntitiesAccount* _tmp5_;
		_tmp3_ = self->priv->conversation;
		_tmp4_ = dino_entities_conversation_get_account (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = dino_entities_account_equals (_tmp5_, account);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		DinoEntitiesConversation* _tmp6_;
		XmppJid* _tmp7_;
		XmppJid* _tmp8_;
		_tmp6_ = self->priv->conversation;
		_tmp7_ = dino_entities_conversation_get_counterpart (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp0_ = xmpp_jid_equals (_tmp8_, muc_jid);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		dino_ui_encryption_button_update_visibility (self);
	}
}

static void
___lambda7__dino_muc_manager_room_info_updated (DinoMucManager* _sender,
                                                DinoEntitiesAccount* account,
                                                XmppJid* muc_jid,
                                                gpointer self)
{
	__lambda7_ ((DinoUiEncryptionButton*) self, account, muc_jid);
}

DinoUiEncryptionButton*
dino_ui_encryption_button_construct (GType object_type,
                                     DinoStreamInteractor* stream_interactor,
                                     GtkMenuButton* menu_button)
{
	DinoUiEncryptionButton* self = NULL;
	DinoStreamInteractor* _tmp0_;
	GtkMenuButton* _tmp1_;
	GMenu* menu_model = NULL;
	GMenu* _tmp2_;
	GMenuItem* unencrypted_item = NULL;
	const gchar* _tmp3_;
	GMenuItem* _tmp4_;
	GMenuItem* _tmp5_;
	GVariant* _tmp6_;
	GVariant* _tmp7_;
	GMenu* _tmp8_;
	GMenuItem* _tmp9_;
	GeeArrayList* encryption_entries = NULL;
	GeeArrayList* _tmp10_;
	DinoUiApplication* app = NULL;
	GApplication* _tmp11_;
	DinoUiApplication* _tmp12_;
	GeeArrayList* _tmp13_;
	DinoUiApplication* _tmp14_;
	DinoPluginsRegistry* _tmp15_;
	DinoPluginsRegistry* _tmp16_;
	GeeHashMap* _tmp17_;
	GeeCollection* _tmp18_;
	GeeCollection* _tmp19_;
	GeeCollection* _tmp20_;
	GeeArrayList* _tmp21_;
	GSimpleActionGroup* action_group = NULL;
	GSimpleActionGroup* _tmp42_;
	const GVariantType* _tmp43_;
	GVariant* _tmp44_;
	GVariant* _tmp45_;
	GSimpleAction* _tmp46_;
	GSimpleAction* _tmp47_;
	GSimpleAction* _tmp48_;
	GtkPopoverMenu* popover_menu = NULL;
	GMenu* _tmp49_;
	GtkPopoverMenu* _tmp50_;
	DinoModuleIdentity* _tmp51_;
	gpointer _tmp52_;
	DinoMucManager* _tmp53_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (menu_button != NULL, NULL);
	self = (DinoUiEncryptionButton*) g_type_create_instance (object_type);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	_tmp1_ = _g_object_ref0 (menu_button);
	_g_object_unref0 (self->priv->menu_button);
	self->priv->menu_button = _tmp1_;
	_tmp2_ = g_menu_new ();
	menu_model = _tmp2_;
	_tmp3_ = dino_gettext ("Unencrypted");
	_tmp4_ = g_menu_item_new (_tmp3_, "enc.encryption");
	unencrypted_item = _tmp4_;
	_tmp5_ = unencrypted_item;
	_tmp6_ = g_variant_new_int32 ((gint32) DINO_ENTITIES_ENCRYPTION_NONE);
	g_variant_ref_sink (_tmp6_);
	_tmp7_ = _tmp6_;
	g_menu_item_set_action_and_target_value (_tmp5_, "enc.encryption", _tmp7_);
	_g_variant_unref0 (_tmp7_);
	_tmp8_ = menu_model;
	_tmp9_ = unencrypted_item;
	g_menu_append_item (_tmp8_, _tmp9_);
	_tmp10_ = gee_array_list_new (DINO_PLUGINS_TYPE_ENCRYPTION_LIST_ENTRY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	encryption_entries = _tmp10_;
	_tmp11_ = g_application_get_default ();
	_tmp12_ = _g_object_ref0 (DINO_UI_IS_APPLICATION (_tmp11_) ? ((DinoUiApplication*) _tmp11_) : NULL);
	app = _tmp12_;
	_tmp13_ = encryption_entries;
	_tmp14_ = app;
	_tmp15_ = dino_application_get_plugin_registry ((DinoApplication*) _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = _tmp16_->encryption_list_entries;
	_tmp18_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = _tmp19_;
	gee_array_list_add_all (_tmp13_, _tmp20_);
	_g_object_unref0 (_tmp20_);
	_tmp21_ = encryption_entries;
	gee_list_sort ((GeeList*) _tmp21_, ___lambda5__gcompare_data_func, dino_ui_encryption_button_ref (self), dino_ui_encryption_button_unref);
	{
		GeeArrayList* _e_list = NULL;
		GeeArrayList* _tmp22_;
		gint _e_size = 0;
		GeeArrayList* _tmp23_;
		gint _tmp24_;
		gint _tmp25_;
		gint _e_index = 0;
		_tmp22_ = encryption_entries;
		_e_list = _tmp22_;
		_tmp23_ = _e_list;
		_tmp24_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp23_);
		_tmp25_ = _tmp24_;
		_e_size = _tmp25_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp26_;
			gint _tmp27_;
			DinoPluginsEncryptionListEntry* e = NULL;
			GeeArrayList* _tmp28_;
			gpointer _tmp29_;
			GMenuItem* item = NULL;
			DinoPluginsEncryptionListEntry* _tmp30_;
			const gchar* _tmp31_;
			const gchar* _tmp32_;
			GMenuItem* _tmp33_;
			GMenuItem* _tmp34_;
			DinoPluginsEncryptionListEntry* _tmp35_;
			DinoEntitiesEncryption _tmp36_;
			DinoEntitiesEncryption _tmp37_;
			GVariant* _tmp38_;
			GVariant* _tmp39_;
			GMenu* _tmp40_;
			GMenuItem* _tmp41_;
			_e_index = _e_index + 1;
			_tmp26_ = _e_index;
			_tmp27_ = _e_size;
			if (!(_tmp26_ < _tmp27_)) {
				break;
			}
			_tmp28_ = _e_list;
			_tmp29_ = gee_abstract_list_get ((GeeAbstractList*) _tmp28_, _e_index);
			e = (DinoPluginsEncryptionListEntry*) _tmp29_;
			_tmp30_ = e;
			_tmp31_ = dino_plugins_encryption_list_entry_get_name (_tmp30_);
			_tmp32_ = _tmp31_;
			_tmp33_ = g_menu_item_new (_tmp32_, "enc.encryption");
			item = _tmp33_;
			_tmp34_ = item;
			_tmp35_ = e;
			_tmp36_ = dino_plugins_encryption_list_entry_get_encryption (_tmp35_);
			_tmp37_ = _tmp36_;
			_tmp38_ = g_variant_new_int32 ((gint32) _tmp37_);
			g_variant_ref_sink (_tmp38_);
			_tmp39_ = _tmp38_;
			g_menu_item_set_action_and_target_value (_tmp34_, "enc.encryption", _tmp39_);
			_g_variant_unref0 (_tmp39_);
			_tmp40_ = menu_model;
			_tmp41_ = item;
			g_menu_append_item (_tmp40_, _tmp41_);
			_g_object_unref0 (item);
			_g_object_unref0 (e);
		}
	}
	_tmp42_ = g_simple_action_group_new ();
	action_group = _tmp42_;
	_tmp43_ = G_VARIANT_TYPE_INT32;
	_tmp44_ = g_variant_new_int32 ((gint32) DINO_ENTITIES_ENCRYPTION_NONE);
	g_variant_ref_sink (_tmp44_);
	_tmp45_ = _tmp44_;
	_tmp46_ = g_simple_action_new_stateful ("encryption", _tmp43_, _tmp45_);
	_g_object_unref0 (self->priv->action);
	self->priv->action = _tmp46_;
	_g_variant_unref0 (_tmp45_);
	_tmp47_ = self->priv->action;
	g_signal_connect (_tmp47_, "activate", (GCallback) ___lambda6__g_simple_action_activate, self);
	_tmp48_ = self->priv->action;
	g_simple_action_group_insert (action_group, (GAction*) _tmp48_);
	gtk_widget_insert_action_group ((GtkWidget*) menu_button, "enc", (GActionGroup*) action_group);
	_tmp49_ = menu_model;
	_tmp50_ = (GtkPopoverMenu*) gtk_popover_menu_new_from_model ((GMenuModel*) _tmp49_);
	g_object_ref_sink (_tmp50_);
	popover_menu = _tmp50_;
	gtk_menu_button_set_popover (menu_button, (GtkPopover*) popover_menu);
	_tmp51_ = dino_muc_manager_IDENTITY;
	_tmp52_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp51_);
	_tmp53_ = (DinoMucManager*) _tmp52_;
	g_signal_connect (_tmp53_, "room-info-updated", (GCallback) ___lambda7__dino_muc_manager_room_info_updated, self);
	_g_object_unref0 (_tmp53_);
	_g_object_unref0 (popover_menu);
	_g_object_unref0 (action_group);
	_g_object_unref0 (app);
	_g_object_unref0 (encryption_entries);
	_g_object_unref0 (unencrypted_item);
	_g_object_unref0 (menu_model);
	return self;
}

DinoUiEncryptionButton*
dino_ui_encryption_button_new (DinoStreamInteractor* stream_interactor,
                               GtkMenuButton* menu_button)
{
	return dino_ui_encryption_button_construct (DINO_UI_TYPE_ENCRYPTION_BUTTON, stream_interactor, menu_button);
}

static void
dino_ui_encryption_button_update_encryption_menu_state (DinoUiEncryptionButton* self)
{
	GSimpleAction* _tmp0_;
	DinoEntitiesConversation* _tmp1_;
	DinoEntitiesEncryption _tmp2_;
	DinoEntitiesEncryption _tmp3_;
	GVariant* _tmp4_;
	GVariant* _tmp5_;
	GSimpleAction* _tmp6_;
	DinoEntitiesConversation* _tmp7_;
	DinoEntitiesEncryption _tmp8_;
	DinoEntitiesEncryption _tmp9_;
	GVariant* _tmp10_;
	GVariant* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->action;
	_tmp1_ = self->priv->conversation;
	_tmp2_ = dino_entities_conversation_get_encryption (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_variant_new_int32 ((gint32) _tmp3_);
	g_variant_ref_sink (_tmp4_);
	_tmp5_ = _tmp4_;
	g_simple_action_set_state (_tmp0_, _tmp5_);
	_g_variant_unref0 (_tmp5_);
	_tmp6_ = self->priv->action;
	_tmp7_ = self->priv->conversation;
	_tmp8_ = dino_entities_conversation_get_encryption (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_variant_new_int32 ((gint32) _tmp9_);
	g_variant_ref_sink (_tmp10_);
	_tmp11_ = _tmp10_;
	g_signal_emit_by_name (_tmp6_, "change-state", _tmp11_);
	_g_variant_unref0 (_tmp11_);
}

static void
dino_ui_encryption_button_set_icon (DinoUiEncryptionButton* self,
                                    const gchar* icon)
{
	const gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (icon != NULL);
	_tmp0_ = self->priv->current_icon;
	if (g_strcmp0 (icon, _tmp0_) != 0) {
		GtkMenuButton* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = self->priv->menu_button;
		gtk_menu_button_set_icon_name (_tmp1_, icon);
		_tmp2_ = g_strdup (icon);
		_g_free0 (self->priv->current_icon);
		self->priv->current_icon = _tmp2_;
	}
}

static void
dino_ui_encryption_button_update_encryption_menu_icon (DinoUiEncryptionButton* self)
{
	const gchar* _tmp0_ = NULL;
	DinoEntitiesConversation* _tmp1_;
	DinoEntitiesEncryption _tmp2_;
	DinoEntitiesEncryption _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->conversation;
	_tmp2_ = dino_entities_conversation_get_encryption (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == DINO_ENTITIES_ENCRYPTION_NONE) {
		_tmp0_ = "changes-allow-symbolic";
	} else {
		_tmp0_ = "changes-prevent-symbolic";
	}
	dino_ui_encryption_button_set_icon (self, _tmp0_);
}

static void
dino_ui_encryption_button_update_visibility (DinoUiEncryptionButton* self)
{
	DinoEntitiesConversation* _tmp0_;
	DinoEntitiesEncryption _tmp1_;
	DinoEntitiesEncryption _tmp2_;
	DinoEntitiesConversation* _tmp4_;
	DinoEntitiesConversationType _tmp5_;
	DinoEntitiesConversationType _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->conversation;
	_tmp1_ = dino_entities_conversation_get_encryption (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != DINO_ENTITIES_ENCRYPTION_NONE) {
		GtkMenuButton* _tmp3_;
		_tmp3_ = self->priv->menu_button;
		gtk_widget_set_visible ((GtkWidget*) _tmp3_, TRUE);
		return;
	}
	_tmp4_ = self->priv->conversation;
	_tmp5_ = dino_entities_conversation_get_type_ (_tmp4_);
	_tmp6_ = _tmp5_;
	switch (_tmp6_) {
		case DINO_ENTITIES_CONVERSATION_TYPE_CHAT:
		{
			GtkMenuButton* _tmp7_;
			_tmp7_ = self->priv->menu_button;
			gtk_widget_set_visible ((GtkWidget*) _tmp7_, TRUE);
			break;
		}
		case DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT_PM:
		{
			GtkMenuButton* _tmp8_;
			_tmp8_ = self->priv->menu_button;
			gtk_widget_set_visible ((GtkWidget*) _tmp8_, FALSE);
			break;
		}
		case DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT:
		{
			GtkMenuButton* _tmp9_;
			DinoStreamInteractor* _tmp10_;
			DinoModuleIdentity* _tmp11_;
			gpointer _tmp12_;
			DinoMucManager* _tmp13_;
			DinoEntitiesConversation* _tmp14_;
			DinoEntitiesAccount* _tmp15_;
			DinoEntitiesAccount* _tmp16_;
			DinoEntitiesConversation* _tmp17_;
			XmppJid* _tmp18_;
			XmppJid* _tmp19_;
			_tmp9_ = self->priv->menu_button;
			_tmp10_ = self->priv->stream_interactor;
			_tmp11_ = dino_muc_manager_IDENTITY;
			_tmp12_ = dino_stream_interactor_get_module (_tmp10_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
			_tmp13_ = (DinoMucManager*) _tmp12_;
			_tmp14_ = self->priv->conversation;
			_tmp15_ = dino_entities_conversation_get_account (_tmp14_);
			_tmp16_ = _tmp15_;
			_tmp17_ = self->priv->conversation;
			_tmp18_ = dino_entities_conversation_get_counterpart (_tmp17_);
			_tmp19_ = _tmp18_;
			gtk_widget_set_visible ((GtkWidget*) _tmp9_, dino_muc_manager_is_private_room (_tmp13_, _tmp16_, _tmp19_));
			_g_object_unref0 (_tmp13_);
			break;
		}
		default:
		break;
	}
}

static void
__lambda8_ (DinoUiEncryptionButton* self)
{
	dino_ui_encryption_button_update_encryption_menu_state (self);
	dino_ui_encryption_button_update_encryption_menu_icon (self);
}

static void
___lambda8__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda8_ ((DinoUiEncryptionButton*) self);
}

void
dino_ui_encryption_button_set_conversation (DinoUiEncryptionButton* self,
                                            DinoEntitiesConversation* conversation)
{
	gboolean _tmp0_ = FALSE;
	DinoEntitiesConversation* _tmp3_;
	DinoEntitiesConversation* _tmp4_;
	DinoEntitiesEncryption _tmp5_;
	DinoEntitiesEncryption _tmp6_;
	gulong _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	if (self->priv->conversation_encryption_handler_id != ((gulong) -1)) {
		DinoEntitiesConversation* _tmp1_;
		_tmp1_ = self->priv->conversation;
		_tmp0_ = _tmp1_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		DinoEntitiesConversation* _tmp2_;
		_tmp2_ = self->priv->conversation;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->conversation_encryption_handler_id);
	}
	_tmp3_ = _g_object_ref0 (conversation);
	_g_object_unref0 (self->priv->conversation);
	self->priv->conversation = _tmp3_;
	dino_ui_encryption_button_update_encryption_menu_state (self);
	dino_ui_encryption_button_update_encryption_menu_icon (self);
	dino_ui_encryption_button_update_visibility (self);
	_tmp4_ = self->priv->conversation;
	_tmp5_ = dino_entities_conversation_get_encryption (_tmp4_);
	_tmp6_ = _tmp5_;
	g_signal_emit (self, dino_ui_encryption_button_signals[DINO_UI_ENCRYPTION_BUTTON_ENCRYPTION_CHANGED_SIGNAL], 0, _tmp6_);
	_tmp7_ = g_signal_connect ((GObject*) conversation, "notify::encryption", (GCallback) ___lambda8__g_object_notify, self);
	self->priv->conversation_encryption_handler_id = _tmp7_;
}

static void
dino_ui_value_encryption_button_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dino_ui_value_encryption_button_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dino_ui_encryption_button_unref (value->data[0].v_pointer);
	}
}

static void
dino_ui_value_encryption_button_copy_value (const GValue* src_value,
                                            GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dino_ui_encryption_button_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dino_ui_value_encryption_button_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dino_ui_value_encryption_button_collect_value (GValue* value,
                                               guint n_collect_values,
                                               GTypeCValue* collect_values,
                                               guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DinoUiEncryptionButton * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dino_ui_encryption_button_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dino_ui_value_encryption_button_lcopy_value (const GValue* value,
                                             guint n_collect_values,
                                             GTypeCValue* collect_values,
                                             guint collect_flags)
{
	DinoUiEncryptionButton ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dino_ui_encryption_button_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dino_ui_param_spec_encryption_button (const gchar* name,
                                      const gchar* nick,
                                      const gchar* blurb,
                                      GType object_type,
                                      GParamFlags flags)
{
	DinoUiParamSpecEncryptionButton* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DINO_UI_TYPE_ENCRYPTION_BUTTON), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dino_ui_value_get_encryption_button (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_UI_TYPE_ENCRYPTION_BUTTON), NULL);
	return value->data[0].v_pointer;
}

void
dino_ui_value_set_encryption_button (GValue* value,
                                     gpointer v_object)
{
	DinoUiEncryptionButton * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_UI_TYPE_ENCRYPTION_BUTTON));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_UI_TYPE_ENCRYPTION_BUTTON));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dino_ui_encryption_button_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_ui_encryption_button_unref (old);
	}
}

void
dino_ui_value_take_encryption_button (GValue* value,
                                      gpointer v_object)
{
	DinoUiEncryptionButton * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_UI_TYPE_ENCRYPTION_BUTTON));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_UI_TYPE_ENCRYPTION_BUTTON));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_ui_encryption_button_unref (old);
	}
}

static void
dino_ui_encryption_button_class_init (DinoUiEncryptionButtonClass * klass,
                                      gpointer klass_data)
{
	dino_ui_encryption_button_parent_class = g_type_class_peek_parent (klass);
	((DinoUiEncryptionButtonClass *) klass)->finalize = dino_ui_encryption_button_finalize;
	g_type_class_adjust_private_offset (klass, &DinoUiEncryptionButton_private_offset);
	dino_ui_encryption_button_signals[DINO_UI_ENCRYPTION_BUTTON_ENCRYPTION_CHANGED_SIGNAL] = g_signal_new ("encryption-changed", DINO_UI_TYPE_ENCRYPTION_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__ENUM, G_TYPE_NONE, 1, DINO_ENTITIES_TYPE_ENCRYPTION);
}

static void
dino_ui_encryption_button_instance_init (DinoUiEncryptionButton * self,
                                         gpointer klass)
{
	self->priv = dino_ui_encryption_button_get_instance_private (self);
	self->priv->conversation_encryption_handler_id = (gulong) -1;
	self->ref_count = 1;
}

static void
dino_ui_encryption_button_finalize (DinoUiEncryptionButton * obj)
{
	DinoUiEncryptionButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_UI_TYPE_ENCRYPTION_BUTTON, DinoUiEncryptionButton);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->menu_button);
	_g_object_unref0 (self->priv->conversation);
	_g_free0 (self->priv->current_icon);
	_g_object_unref0 (self->priv->stream_interactor);
	_g_object_unref0 (self->priv->action);
}

static GType
dino_ui_encryption_button_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_ui_value_encryption_button_init, dino_ui_value_encryption_button_free_value, dino_ui_value_encryption_button_copy_value, dino_ui_value_encryption_button_peek_pointer, "p", dino_ui_value_encryption_button_collect_value, "p", dino_ui_value_encryption_button_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoUiEncryptionButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_ui_encryption_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUiEncryptionButton), 0, (GInstanceInitFunc) dino_ui_encryption_button_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dino_ui_encryption_button_type_id;
	dino_ui_encryption_button_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoUiEncryptionButton", &g_define_type_info, &g_define_type_fundamental_info, 0);
	DinoUiEncryptionButton_private_offset = g_type_add_instance_private (dino_ui_encryption_button_type_id, sizeof (DinoUiEncryptionButtonPrivate));
	return dino_ui_encryption_button_type_id;
}

GType
dino_ui_encryption_button_get_type (void)
{
	static volatile gsize dino_ui_encryption_button_type_id__once = 0;
	if (g_once_init_enter (&dino_ui_encryption_button_type_id__once)) {
		GType dino_ui_encryption_button_type_id;
		dino_ui_encryption_button_type_id = dino_ui_encryption_button_get_type_once ();
		g_once_init_leave (&dino_ui_encryption_button_type_id__once, dino_ui_encryption_button_type_id);
	}
	return dino_ui_encryption_button_type_id__once;
}

gpointer
dino_ui_encryption_button_ref (gpointer instance)
{
	DinoUiEncryptionButton * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dino_ui_encryption_button_unref (gpointer instance)
{
	DinoUiEncryptionButton * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_UI_ENCRYPTION_BUTTON_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

