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

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libsoup/soup.h>
#include <handy.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>
#include <pango/pango.h>

#define TOOTLE_WIDGETS_TYPE_RICH_LABEL (tootle_widgets_rich_label_get_type ())
#define TOOTLE_WIDGETS_RICH_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabel))
#define TOOTLE_WIDGETS_RICH_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabelClass))
#define TOOTLE_WIDGETS_IS_RICH_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_WIDGETS_TYPE_RICH_LABEL))
#define TOOTLE_WIDGETS_IS_RICH_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_WIDGETS_TYPE_RICH_LABEL))
#define TOOTLE_WIDGETS_RICH_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabelClass))

typedef struct _TootleWidgetsRichLabel TootleWidgetsRichLabel;
typedef struct _TootleWidgetsRichLabelClass TootleWidgetsRichLabelClass;
typedef struct _TootleWidgetsRichLabelPrivate TootleWidgetsRichLabelPrivate;

#define TOOTLE_TYPE_ENTITY (tootle_entity_get_type ())
#define TOOTLE_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_ENTITY, TootleEntity))
#define TOOTLE_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_TYPE_ENTITY, TootleEntityClass))
#define TOOTLE_IS_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_ENTITY))
#define TOOTLE_IS_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_TYPE_ENTITY))
#define TOOTLE_ENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_TYPE_ENTITY, TootleEntityClass))

typedef struct _TootleEntity TootleEntity;
typedef struct _TootleEntityClass TootleEntityClass;

#define TOOTLE_API_TYPE_MENTION (tootle_api_mention_get_type ())
#define TOOTLE_API_MENTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_API_TYPE_MENTION, TootleAPIMention))
#define TOOTLE_API_MENTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_API_TYPE_MENTION, TootleAPIMentionClass))
#define TOOTLE_API_IS_MENTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_API_TYPE_MENTION))
#define TOOTLE_API_IS_MENTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_API_TYPE_MENTION))
#define TOOTLE_API_MENTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_API_TYPE_MENTION, TootleAPIMentionClass))

typedef struct _TootleAPIMention TootleAPIMention;
typedef struct _TootleAPIMentionClass TootleAPIMentionClass;
typedef enum  {
	TOOTLE_MARKUP_POLICY_DISALLOW,
	TOOTLE_MARKUP_POLICY_ALLOW,
	TOOTLE_MARKUP_POLICY_TRUST
} TootleMarkupPolicy;

#define TOOTLE_TYPE_MARKUP_POLICY (tootle_markup_policy_get_type ())
enum  {
	TOOTLE_WIDGETS_RICH_LABEL_0_PROPERTY,
	TOOTLE_WIDGETS_RICH_LABEL_MARKUP_PROPERTY,
	TOOTLE_WIDGETS_RICH_LABEL_TEXT_PROPERTY,
	TOOTLE_WIDGETS_RICH_LABEL_NUM_PROPERTIES
};
static GParamSpec* tootle_widgets_rich_label_properties[TOOTLE_WIDGETS_RICH_LABEL_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _Block23Data Block23Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TOOTLE_TYPE_WIDGETIZABLE (tootle_widgetizable_get_type ())
#define TOOTLE_WIDGETIZABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_WIDGETIZABLE, TootleWidgetizable))
#define TOOTLE_IS_WIDGETIZABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_WIDGETIZABLE))
#define TOOTLE_WIDGETIZABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TOOTLE_TYPE_WIDGETIZABLE, TootleWidgetizableIface))

typedef struct _TootleWidgetizable TootleWidgetizable;
typedef struct _TootleWidgetizableIface TootleWidgetizableIface;

#define TOOTLE_API_TYPE_ACCOUNT (tootle_api_account_get_type ())
#define TOOTLE_API_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_API_TYPE_ACCOUNT, TootleAPIAccount))
#define TOOTLE_API_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_API_TYPE_ACCOUNT, TootleAPIAccountClass))
#define TOOTLE_API_IS_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_API_TYPE_ACCOUNT))
#define TOOTLE_API_IS_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_API_TYPE_ACCOUNT))
#define TOOTLE_API_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_API_TYPE_ACCOUNT, TootleAPIAccountClass))

typedef struct _TootleAPIAccount TootleAPIAccount;
typedef struct _TootleAPIAccountClass TootleAPIAccountClass;

#define TOOTLE_TYPE_INSTANCE_ACCOUNT (tootle_instance_account_get_type ())
#define TOOTLE_INSTANCE_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_INSTANCE_ACCOUNT, TootleInstanceAccount))
#define TOOTLE_INSTANCE_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_TYPE_INSTANCE_ACCOUNT, TootleInstanceAccountClass))
#define TOOTLE_IS_INSTANCE_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_INSTANCE_ACCOUNT))
#define TOOTLE_IS_INSTANCE_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_TYPE_INSTANCE_ACCOUNT))
#define TOOTLE_INSTANCE_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_TYPE_INSTANCE_ACCOUNT, TootleInstanceAccountClass))

typedef struct _TootleInstanceAccount TootleInstanceAccount;
typedef struct _TootleInstanceAccountClass TootleInstanceAccountClass;

#define TOOTLE_DIALOGS_TYPE_MAIN_WINDOW (tootle_dialogs_main_window_get_type ())
#define TOOTLE_DIALOGS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW, TootleDialogsMainWindow))
#define TOOTLE_DIALOGS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW, TootleDialogsMainWindowClass))
#define TOOTLE_DIALOGS_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW))
#define TOOTLE_DIALOGS_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW))
#define TOOTLE_DIALOGS_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW, TootleDialogsMainWindowClass))

typedef struct _TootleDialogsMainWindow TootleDialogsMainWindow;
typedef struct _TootleDialogsMainWindowClass TootleDialogsMainWindowClass;

#define TOOTLE_VIEWS_TYPE_BASE (tootle_views_base_get_type ())
#define TOOTLE_VIEWS_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_VIEWS_TYPE_BASE, TootleViewsBase))
#define TOOTLE_VIEWS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_VIEWS_TYPE_BASE, TootleViewsBaseClass))
#define TOOTLE_VIEWS_IS_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_VIEWS_TYPE_BASE))
#define TOOTLE_VIEWS_IS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_VIEWS_TYPE_BASE))
#define TOOTLE_VIEWS_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_VIEWS_TYPE_BASE, TootleViewsBaseClass))

typedef struct _TootleViewsBase TootleViewsBase;
typedef struct _TootleViewsBaseClass TootleViewsBaseClass;

#define TOOTLE_VIEWS_TYPE_TIMELINE (tootle_views_timeline_get_type ())
#define TOOTLE_VIEWS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_VIEWS_TYPE_TIMELINE, TootleViewsTimeline))
#define TOOTLE_VIEWS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_VIEWS_TYPE_TIMELINE, TootleViewsTimelineClass))
#define TOOTLE_VIEWS_IS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_VIEWS_TYPE_TIMELINE))
#define TOOTLE_VIEWS_IS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_VIEWS_TYPE_TIMELINE))
#define TOOTLE_VIEWS_TIMELINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_VIEWS_TYPE_TIMELINE, TootleViewsTimelineClass))

typedef struct _TootleViewsTimeline TootleViewsTimeline;
typedef struct _TootleViewsTimelineClass TootleViewsTimelineClass;

#define TOOTLE_VIEWS_TYPE_HASHTAG (tootle_views_hashtag_get_type ())
#define TOOTLE_VIEWS_HASHTAG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_VIEWS_TYPE_HASHTAG, TootleViewsHashtag))
#define TOOTLE_VIEWS_HASHTAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_VIEWS_TYPE_HASHTAG, TootleViewsHashtagClass))
#define TOOTLE_VIEWS_IS_HASHTAG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_VIEWS_TYPE_HASHTAG))
#define TOOTLE_VIEWS_IS_HASHTAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_VIEWS_TYPE_HASHTAG))
#define TOOTLE_VIEWS_HASHTAG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_VIEWS_TYPE_HASHTAG, TootleViewsHashtagClass))

typedef struct _TootleViewsHashtag TootleViewsHashtag;
typedef struct _TootleViewsHashtagClass TootleViewsHashtagClass;

#define TOOTLE_TYPE_SETTINGS (tootle_settings_get_type ())
#define TOOTLE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_SETTINGS, TootleSettings))
#define TOOTLE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_TYPE_SETTINGS, TootleSettingsClass))
#define TOOTLE_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_SETTINGS))
#define TOOTLE_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_TYPE_SETTINGS))
#define TOOTLE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_TYPE_SETTINGS, TootleSettingsClass))

typedef struct _TootleSettings TootleSettings;
typedef struct _TootleSettingsClass TootleSettingsClass;

#define TOOTLE_TYPE_ACCOUNTS (tootle_accounts_get_type ())
#define TOOTLE_ACCOUNTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_ACCOUNTS, TootleAccounts))
#define TOOTLE_ACCOUNTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_TYPE_ACCOUNTS, TootleAccountsClass))
#define TOOTLE_IS_ACCOUNTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_ACCOUNTS))
#define TOOTLE_IS_ACCOUNTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_TYPE_ACCOUNTS))
#define TOOTLE_ACCOUNTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_TYPE_ACCOUNTS, TootleAccountsClass))

typedef struct _TootleAccounts TootleAccounts;
typedef struct _TootleAccountsClass TootleAccountsClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _TootleWidgetsRichLabel {
	GtkLabel parent_instance;
	TootleWidgetsRichLabelPrivate * priv;
	GeeArrayList* mentions;
};

struct _TootleWidgetsRichLabelClass {
	GtkLabelClass parent_class;
};

struct _TootleWidgetsRichLabelPrivate {
	TootleMarkupPolicy _markup;
};

struct _Block23Data {
	int _ref_count_;
	TootleWidgetsRichLabel* self;
	gchar* url;
};

typedef enum  {
	TOOTLE_OOPSIE_USER,
	TOOTLE_OOPSIE_PARSING,
	TOOTLE_OOPSIE_INSTANCE,
	TOOTLE_OOPSIE_INTERNAL
} TootleOopsie;
#define TOOTLE_OOPSIE tootle_oopsie_quark ()
struct _TootleWidgetizableIface {
	GTypeInterface parent_iface;
	GtkWidget* (*to_widget) (TootleWidgetizable* self, GError** error);
	void (*open) (TootleWidgetizable* self);
	void (*resolve_open) (TootleWidgetizable* self, TootleInstanceAccount* account);
};

static gint TootleWidgetsRichLabel_private_offset;
static gpointer tootle_widgets_rich_label_parent_class = NULL;
extern TootleDialogsMainWindow* tootle_window;
extern TootleSettings* tootle_settings;
extern TootleAccounts* tootle_accounts;

GType tootle_widgets_rich_label_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleWidgetsRichLabel, g_object_unref)
GType tootle_entity_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleEntity, g_object_unref)
GType tootle_api_mention_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleAPIMention, g_object_unref)
GType tootle_markup_policy_get_type (void) G_GNUC_CONST ;
TootleWidgetsRichLabel* tootle_widgets_rich_label_new (const gchar* text);
TootleWidgetsRichLabel* tootle_widgets_rich_label_construct (GType object_type,
                                                             const gchar* text);
gchar* tootle_widgets_rich_label_escape_entities (const gchar* content);
gchar* tootle_widgets_rich_label_restore_entities (const gchar* content);
static gboolean tootle_widgets_rich_label_real_activate_link (GtkLabel* base,
                                                       const gchar* url);
static Block23Data* block23_data_ref (Block23Data* _data23_);
static void block23_data_unref (void * _userdata_);
static gboolean ___lambda94_ (Block23Data* _data23_,
                       TootleAPIMention* mention);
const gchar* tootle_api_mention_get_url (TootleAPIMention* self);
GQuark tootle_oopsie_quark (void);
GType tootle_api_account_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleAPIAccount, g_object_unref)
GType tootle_instance_account_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleInstanceAccount, g_object_unref)
GType tootle_widgetizable_get_type (void) G_GNUC_CONST ;
void tootle_widgetizable_open (TootleWidgetizable* self);
static gboolean ____lambda94__gee_forall_func (gpointer g,
                                        gpointer self);
GType tootle_dialogs_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleDialogsMainWindow, g_object_unref)
GType tootle_views_base_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleViewsBase, g_object_unref)
TootleViewsBase* tootle_dialogs_main_window_open_view (TootleDialogsMainWindow* self,
                                                       TootleViewsBase* view);
TootleViewsHashtag* tootle_views_hashtag_new (const gchar* tag);
TootleViewsHashtag* tootle_views_hashtag_construct (GType object_type,
                                                    const gchar* tag);
GType tootle_views_timeline_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleViewsTimeline, g_object_unref)
GType tootle_views_hashtag_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleViewsHashtag, g_object_unref)
GType tootle_settings_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleSettings, g_object_unref)
gboolean tootle_settings_get_aggressive_resolving (TootleSettings* self);
gboolean tootle_desktop_open_uri (const gchar* _uri);
GType tootle_accounts_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleAccounts, g_object_unref)
TootleInstanceAccount* tootle_accounts_get_active (TootleAccounts* self);
void tootle_instance_account_resolve (TootleInstanceAccount* self,
                                      const gchar* url,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
TootleEntity* tootle_instance_account_resolve_finish (TootleInstanceAccount* self,
                                                      GAsyncResult* _res_,
                                                      GError** error);
static void ___lambda95_ (Block23Data* _data23_,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda95__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
TootleMarkupPolicy tootle_widgets_rich_label_get_markup (TootleWidgetsRichLabel* self);
void tootle_widgets_rich_label_set_markup (TootleWidgetsRichLabel* self,
                                           TootleMarkupPolicy value);
void tootle_markup_policy_apply (TootleMarkupPolicy self,
                                 TootleWidgetsRichLabel* w);
const gchar* tootle_widgets_rich_label_get_text (TootleWidgetsRichLabel* self);
void tootle_widgets_rich_label_set_text (TootleWidgetsRichLabel* self,
                                         const gchar* value);
gchar* tootle_markup_policy_process (TootleMarkupPolicy self,
                                     const gchar* input);
static GObject * tootle_widgets_rich_label_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void tootle_widgets_rich_label_finalize (GObject * obj);
static GType tootle_widgets_rich_label_get_type_once (void);
static void _vala_tootle_widgets_rich_label_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_tootle_widgets_rich_label_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gint array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gint array_length,
                       GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
tootle_widgets_rich_label_get_instance_private (TootleWidgetsRichLabel* self)
{
	return G_STRUCT_MEMBER_P (self, TootleWidgetsRichLabel_private_offset);
}

TootleWidgetsRichLabel*
tootle_widgets_rich_label_construct (GType object_type,
                                     const gchar* text)
{
	TootleWidgetsRichLabel * self = NULL;
	g_return_val_if_fail (text != NULL, NULL);
	self = (TootleWidgetsRichLabel*) g_object_new (object_type, NULL);
	gtk_label_set_label ((GtkLabel*) self, text);
	return self;
}

TootleWidgetsRichLabel*
tootle_widgets_rich_label_new (const gchar* text)
{
	return tootle_widgets_rich_label_construct (TOOTLE_WIDGETS_TYPE_RICH_LABEL, text);
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			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 NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			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 NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	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 NULL;
}

gchar*
tootle_widgets_rich_label_escape_entities (const gchar* content)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result = NULL;
	g_return_val_if_fail (content != NULL, NULL);
	_tmp0_ = string_replace (content, "&nbsp;", " ");
	_tmp1_ = _tmp0_;
	_tmp2_ = string_replace (_tmp1_, "'", "&apos;");
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	result = _tmp3_;
	return result;
}

gchar*
tootle_widgets_rich_label_restore_entities (const gchar* content)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* result = NULL;
	g_return_val_if_fail (content != NULL, NULL);
	_tmp0_ = string_replace (content, "&amp;", "&");
	_tmp1_ = _tmp0_;
	_tmp2_ = string_replace (_tmp1_, "&lt;", "<");
	_tmp3_ = _tmp2_;
	_tmp4_ = string_replace (_tmp3_, "&gt;", ">");
	_tmp5_ = _tmp4_;
	_tmp6_ = string_replace (_tmp5_, "&apos;", "'");
	_tmp7_ = _tmp6_;
	_tmp8_ = string_replace (_tmp7_, "&quot;", "\"");
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp9_;
	return result;
}

static Block23Data*
block23_data_ref (Block23Data* _data23_)
{
	g_atomic_int_inc (&_data23_->_ref_count_);
	return _data23_;
}

static void
block23_data_unref (void * _userdata_)
{
	Block23Data* _data23_;
	_data23_ = (Block23Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data23_->_ref_count_)) {
		TootleWidgetsRichLabel* self;
		self = _data23_->self;
		_g_free0 (_data23_->url);
		_g_object_unref0 (self);
		g_slice_free (Block23Data, _data23_);
	}
}

static gboolean
___lambda94_ (Block23Data* _data23_,
              TootleAPIMention* mention)
{
	TootleWidgetsRichLabel* self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gboolean result = FALSE;
	self = _data23_->self;
	g_return_val_if_fail (mention != NULL, FALSE);
	_tmp0_ = tootle_api_mention_get_url (mention);
	_tmp1_ = _tmp0_;
	if (g_strcmp0 (_data23_->url, _tmp1_) == 0) {
		tootle_widgetizable_open ((TootleWidgetizable*) mention);
	}
	result = TRUE;
	_g_object_unref0 (mention);
	return result;
}

static gboolean
____lambda94__gee_forall_func (gpointer g,
                               gpointer self)
{
	gboolean result;
	result = ___lambda94_ (self, (TootleAPIMention*) g);
	return result;
}

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

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
___lambda95_ (Block23Data* _data23_,
              GObject* obj,
              GAsyncResult* res)
{
	TootleWidgetsRichLabel* self;
	GError* _inner_error0_ = NULL;
	self = _data23_->self;
	g_return_if_fail (res != NULL);
	{
		TootleEntity* _tmp0_ = NULL;
		TootleAccounts* _tmp1_;
		TootleInstanceAccount* _tmp2_;
		TootleInstanceAccount* _tmp3_;
		TootleEntity* _tmp4_;
		_tmp1_ = tootle_accounts;
		_tmp2_ = tootle_accounts_get_active (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = tootle_instance_account_resolve_finish (_tmp3_, res, &_inner_error0_);
		_tmp0_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		tootle_widgetizable_open ((TootleWidgetizable*) _tmp0_);
		_g_object_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		GError* _tmp8_;
		const gchar* _tmp9_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = string_to_string (_data23_->url);
		_tmp6_ = g_strconcat ("Failed to resolve URL \"", _tmp5_, "\":", NULL);
		_tmp7_ = _tmp6_;
		g_warning ("RichLabel.vala:81: %s", _tmp7_);
		_g_free0 (_tmp7_);
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		g_warning ("RichLabel.vala:82: %s", _tmp9_);
		tootle_desktop_open_uri (_data23_->url);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

static void
____lambda95__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda95_ (self, source_object, res);
	block23_data_unref (self);
}

static gboolean
tootle_widgets_rich_label_real_activate_link (GtkLabel* base,
                                              const gchar* url)
{
	TootleWidgetsRichLabel * self;
	Block23Data* _data23_;
	gchar* _tmp0_;
	GeeArrayList* _tmp1_;
	gboolean _tmp17_ = FALSE;
	TootleSettings* _tmp18_;
	gboolean _tmp19_;
	gboolean _tmp20_;
	gboolean resolve = FALSE;
	gboolean result = FALSE;
	self = (TootleWidgetsRichLabel*) base;
	g_return_val_if_fail (url != NULL, FALSE);
	_data23_ = g_slice_new0 (Block23Data);
	_data23_->_ref_count_ = 1;
	_data23_->self = g_object_ref (self);
	_tmp0_ = g_strdup (url);
	_g_free0 (_data23_->url);
	_data23_->url = _tmp0_;
	_tmp1_ = self->mentions;
	if (_tmp1_ != NULL) {
		GeeArrayList* _tmp2_;
		_tmp2_ = self->mentions;
		gee_abstract_collection_foreach ((GeeAbstractCollection*) _tmp2_, ____lambda94__gee_forall_func, _data23_);
	}
	if (string_contains (_data23_->url, "/tags/")) {
		gchar* encoded = NULL;
		gchar** _tmp3_;
		gchar** _tmp4_;
		gchar** _tmp5_;
		gint _tmp5__length1;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* tag = NULL;
		const gchar* _tmp9_;
		gchar* _tmp10_;
		TootleDialogsMainWindow* _tmp11_;
		const gchar* _tmp12_;
		TootleViewsHashtag* _tmp13_;
		TootleViewsHashtag* _tmp14_;
		TootleViewsBase* _tmp15_;
		TootleViewsBase* _tmp16_;
		_tmp4_ = _tmp3_ = g_strsplit (_data23_->url, "/tags/", 0);
		_tmp5_ = _tmp4_;
		_tmp5__length1 = _vala_array_length (_tmp3_);
		_tmp6_ = _tmp5_[1];
		_tmp7_ = g_strdup (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL);
		encoded = _tmp8_;
		_tmp9_ = encoded;
		_tmp10_ = soup_uri_decode (_tmp9_);
		tag = _tmp10_;
		_tmp11_ = tootle_window;
		_tmp12_ = tag;
		_tmp13_ = tootle_views_hashtag_new (_tmp12_);
		g_object_ref_sink (_tmp13_);
		_tmp14_ = _tmp13_;
		_tmp15_ = tootle_dialogs_main_window_open_view (_tmp11_, (TootleViewsBase*) _tmp14_);
		_tmp16_ = _tmp15_;
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (_tmp14_);
		result = TRUE;
		_g_free0 (tag);
		_g_free0 (encoded);
		block23_data_unref (_data23_);
		_data23_ = NULL;
		return result;
	}
	_tmp18_ = tootle_settings;
	_tmp19_ = tootle_settings_get_aggressive_resolving (_tmp18_);
	_tmp20_ = _tmp19_;
	if (_tmp20_) {
		_tmp17_ = TRUE;
	} else {
		_tmp17_ = string_contains (_data23_->url, "@");
	}
	resolve = _tmp17_;
	if (!resolve) {
		tootle_desktop_open_uri (_data23_->url);
	} else {
		TootleAccounts* _tmp21_;
		TootleInstanceAccount* _tmp22_;
		TootleInstanceAccount* _tmp23_;
		_tmp21_ = tootle_accounts;
		_tmp22_ = tootle_accounts_get_active (_tmp21_);
		_tmp23_ = _tmp22_;
		tootle_instance_account_resolve (_tmp23_, _data23_->url, ____lambda95__gasync_ready_callback, block23_data_ref (_data23_));
	}
	result = TRUE;
	block23_data_unref (_data23_);
	_data23_ = NULL;
	return result;
}

TootleMarkupPolicy
tootle_widgets_rich_label_get_markup (TootleWidgetsRichLabel* self)
{
	TootleMarkupPolicy result;
	TootleMarkupPolicy _tmp0_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_markup;
	result = _tmp0_;
	return result;
}

void
tootle_widgets_rich_label_set_markup (TootleWidgetsRichLabel* self,
                                      TootleMarkupPolicy value)
{
	TootleMarkupPolicy _tmp0_;
	g_return_if_fail (self != NULL);
	self->priv->_markup = value;
	_tmp0_ = self->priv->_markup;
	tootle_markup_policy_apply (_tmp0_, self);
	g_object_notify_by_pspec ((GObject *) self, tootle_widgets_rich_label_properties[TOOTLE_WIDGETS_RICH_LABEL_MARKUP_PROPERTY]);
}

const gchar*
tootle_widgets_rich_label_get_text (TootleWidgetsRichLabel* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gtk_label_get_label ((GtkLabel*) self);
	_tmp1_ = _tmp0_;
	result = _tmp1_;
	return result;
}

void
tootle_widgets_rich_label_set_text (TootleWidgetsRichLabel* self,
                                    const gchar* value)
{
	TootleMarkupPolicy _tmp0_;
	TootleMarkupPolicy _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = tootle_widgets_rich_label_get_markup (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = tootle_markup_policy_process (_tmp1_, value);
	_tmp3_ = _tmp2_;
	gtk_label_set_label ((GtkLabel*) self, _tmp3_);
	_g_free0 (_tmp3_);
	g_object_notify_by_pspec ((GObject *) self, tootle_widgets_rich_label_properties[TOOTLE_WIDGETS_RICH_LABEL_TEXT_PROPERTY]);
}

static GObject *
tootle_widgets_rich_label_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	TootleWidgetsRichLabel * self;
	parent_class = G_OBJECT_CLASS (tootle_widgets_rich_label_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabel);
	gtk_label_set_xalign ((GtkLabel*) self, (gfloat) 0);
	g_object_set ((GtkLabel*) self, "wrap-mode", PANGO_WRAP_WORD_CHAR, NULL);
	gtk_label_set_justify ((GtkLabel*) self, GTK_JUSTIFY_LEFT);
	gtk_label_set_single_line_mode ((GtkLabel*) self, FALSE);
	gtk_label_set_line_wrap ((GtkLabel*) self, TRUE);
	return obj;
}

static void
tootle_widgets_rich_label_class_init (TootleWidgetsRichLabelClass * klass,
                                      gpointer klass_data)
{
	tootle_widgets_rich_label_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &TootleWidgetsRichLabel_private_offset);
	((GtkLabelClass *) klass)->activate_link = (gboolean (*) (GtkLabel*, const gchar*)) tootle_widgets_rich_label_real_activate_link;
	G_OBJECT_CLASS (klass)->get_property = _vala_tootle_widgets_rich_label_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_tootle_widgets_rich_label_set_property;
	G_OBJECT_CLASS (klass)->constructor = tootle_widgets_rich_label_constructor;
	G_OBJECT_CLASS (klass)->finalize = tootle_widgets_rich_label_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TOOTLE_WIDGETS_RICH_LABEL_MARKUP_PROPERTY, tootle_widgets_rich_label_properties[TOOTLE_WIDGETS_RICH_LABEL_MARKUP_PROPERTY] = g_param_spec_enum ("markup", "markup", "markup", TOOTLE_TYPE_MARKUP_POLICY, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TOOTLE_WIDGETS_RICH_LABEL_TEXT_PROPERTY, tootle_widgets_rich_label_properties[TOOTLE_WIDGETS_RICH_LABEL_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
tootle_widgets_rich_label_instance_init (TootleWidgetsRichLabel * self,
                                         gpointer klass)
{
	self->priv = tootle_widgets_rich_label_get_instance_private (self);
	self->priv->_markup = TOOTLE_MARKUP_POLICY_DISALLOW;
}

static void
tootle_widgets_rich_label_finalize (GObject * obj)
{
	TootleWidgetsRichLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabel);
	G_OBJECT_CLASS (tootle_widgets_rich_label_parent_class)->finalize (obj);
}

static GType
tootle_widgets_rich_label_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TootleWidgetsRichLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tootle_widgets_rich_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TootleWidgetsRichLabel), 0, (GInstanceInitFunc) tootle_widgets_rich_label_instance_init, NULL };
	GType tootle_widgets_rich_label_type_id;
	tootle_widgets_rich_label_type_id = g_type_register_static (gtk_label_get_type (), "TootleWidgetsRichLabel", &g_define_type_info, 0);
	TootleWidgetsRichLabel_private_offset = g_type_add_instance_private (tootle_widgets_rich_label_type_id, sizeof (TootleWidgetsRichLabelPrivate));
	return tootle_widgets_rich_label_type_id;
}

GType
tootle_widgets_rich_label_get_type (void)
{
	static volatile gsize tootle_widgets_rich_label_type_id__volatile = 0;
	if (g_once_init_enter (&tootle_widgets_rich_label_type_id__volatile)) {
		GType tootle_widgets_rich_label_type_id;
		tootle_widgets_rich_label_type_id = tootle_widgets_rich_label_get_type_once ();
		g_once_init_leave (&tootle_widgets_rich_label_type_id__volatile, tootle_widgets_rich_label_type_id);
	}
	return tootle_widgets_rich_label_type_id__volatile;
}

static void
_vala_tootle_widgets_rich_label_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	TootleWidgetsRichLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabel);
	switch (property_id) {
		case TOOTLE_WIDGETS_RICH_LABEL_MARKUP_PROPERTY:
		g_value_set_enum (value, tootle_widgets_rich_label_get_markup (self));
		break;
		case TOOTLE_WIDGETS_RICH_LABEL_TEXT_PROPERTY:
		g_value_set_string (value, tootle_widgets_rich_label_get_text (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_tootle_widgets_rich_label_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	TootleWidgetsRichLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TOOTLE_WIDGETS_TYPE_RICH_LABEL, TootleWidgetsRichLabel);
	switch (property_id) {
		case TOOTLE_WIDGETS_RICH_LABEL_MARKUP_PROPERTY:
		tootle_widgets_rich_label_set_markup (self, g_value_get_enum (value));
		break;
		case TOOTLE_WIDGETS_RICH_LABEL_TEXT_PROPERTY:
		tootle_widgets_rich_label_set_text (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gint array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gint i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gint array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gint
_vala_array_length (gpointer array)
{
	gint length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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;
}

