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

#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <libsoup/soup.h>
#include <gdk/gdk.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 TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM (tuba_widgets_attachment_item_get_type ())
#define TUBA_WIDGETS_ATTACHMENT_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItem))
#define TUBA_WIDGETS_ATTACHMENT_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItemClass))
#define TUBA_WIDGETS_ATTACHMENT_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM))
#define TUBA_WIDGETS_ATTACHMENT_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM))
#define TUBA_WIDGETS_ATTACHMENT_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItemClass))

typedef struct _TubaWidgetsAttachmentItem TubaWidgetsAttachmentItem;
typedef struct _TubaWidgetsAttachmentItemClass TubaWidgetsAttachmentItemClass;
typedef struct _TubaWidgetsAttachmentItemPrivate TubaWidgetsAttachmentItemPrivate;

#define TUBA_TYPE_ENTITY (tuba_entity_get_type ())
#define TUBA_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_TYPE_ENTITY, TubaEntity))
#define TUBA_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_TYPE_ENTITY, TubaEntityClass))
#define TUBA_IS_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_TYPE_ENTITY))
#define TUBA_IS_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_TYPE_ENTITY))
#define TUBA_ENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_TYPE_ENTITY, TubaEntityClass))

typedef struct _TubaEntity TubaEntity;
typedef struct _TubaEntityClass TubaEntityClass;

#define TUBA_API_TYPE_ATTACHMENT (tuba_api_attachment_get_type ())
#define TUBA_API_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_API_TYPE_ATTACHMENT, TubaAPIAttachment))
#define TUBA_API_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_API_TYPE_ATTACHMENT, TubaAPIAttachmentClass))
#define TUBA_API_IS_ATTACHMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_API_TYPE_ATTACHMENT))
#define TUBA_API_IS_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_API_TYPE_ATTACHMENT))
#define TUBA_API_ATTACHMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_API_TYPE_ATTACHMENT, TubaAPIAttachmentClass))

typedef struct _TubaAPIAttachment TubaAPIAttachment;
typedef struct _TubaAPIAttachmentClass TubaAPIAttachmentClass;
typedef enum  {
	TUBA_ATTACHMENT_MEDIA_TYPE_IMAGE,
	TUBA_ATTACHMENT_MEDIA_TYPE_VIDEO,
	TUBA_ATTACHMENT_MEDIA_TYPE_GIFV,
	TUBA_ATTACHMENT_MEDIA_TYPE_AUDIO,
	TUBA_ATTACHMENT_MEDIA_TYPE_UNKNOWN
} TubaAttachmentMediaType;

#define TUBA_ATTACHMENT_TYPE_MEDIA_TYPE (tuba_attachment_media_type_get_type ())
enum  {
	TUBA_WIDGETS_ATTACHMENT_ITEM_0_PROPERTY,
	TUBA_WIDGETS_ATTACHMENT_ITEM_ENTITY_PROPERTY,
	TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_CLICK_CONTROLLER_PROPERTY,
	TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_LP_CONTROLLER_PROPERTY,
	TUBA_WIDGETS_ATTACHMENT_ITEM_CONTEXT_MENU_PROPERTY,
	TUBA_WIDGETS_ATTACHMENT_ITEM_MEDIA_KIND_PROPERTY,
	TUBA_WIDGETS_ATTACHMENT_ITEM_NUM_PROPERTIES
};
static GParamSpec* tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_NUM_PROPERTIES];
typedef void (*GSimpleActionActivateCallback) (GSimpleAction* action, GVariant* parameter, gpointer user_data);
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TUBA_TYPE_APPLICATION (tuba_application_get_type ())
#define TUBA_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_TYPE_APPLICATION, TubaApplication))
#define TUBA_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_TYPE_APPLICATION, TubaApplicationClass))
#define TUBA_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_TYPE_APPLICATION))
#define TUBA_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_TYPE_APPLICATION))
#define TUBA_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_TYPE_APPLICATION, TubaApplicationClass))

typedef struct _TubaApplication TubaApplication;
typedef struct _TubaApplicationClass TubaApplicationClass;
#define _g_free0(var) (var = (g_free (var), NULL))

#define TUBA_DIALOGS_TYPE_MAIN_WINDOW (tuba_dialogs_main_window_get_type ())
#define TUBA_DIALOGS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_DIALOGS_TYPE_MAIN_WINDOW, TubaDialogsMainWindow))
#define TUBA_DIALOGS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_DIALOGS_TYPE_MAIN_WINDOW, TubaDialogsMainWindowClass))
#define TUBA_DIALOGS_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_DIALOGS_TYPE_MAIN_WINDOW))
#define TUBA_DIALOGS_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_DIALOGS_TYPE_MAIN_WINDOW))
#define TUBA_DIALOGS_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_DIALOGS_TYPE_MAIN_WINDOW, TubaDialogsMainWindowClass))

typedef struct _TubaDialogsMainWindow TubaDialogsMainWindow;
typedef struct _TubaDialogsMainWindowClass TubaDialogsMainWindowClass;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _TubaWidgetsAttachmentItemSaveMediaAsData TubaWidgetsAttachmentItemSaveMediaAsData;

#define TUBA_TYPE_REQUEST_V2 (tuba_request_v2_get_type ())
#define TUBA_REQUEST_V2(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_TYPE_REQUEST_V2, TubaRequestV2))
#define TUBA_REQUEST_V2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_TYPE_REQUEST_V2, TubaRequestV2Class))
#define TUBA_IS_REQUEST_V2(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_TYPE_REQUEST_V2))
#define TUBA_IS_REQUEST_V2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_TYPE_REQUEST_V2))
#define TUBA_REQUEST_V2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_TYPE_REQUEST_V2, TubaRequestV2Class))

typedef struct _TubaRequestV2 TubaRequestV2;
typedef struct _TubaRequestV2Class TubaRequestV2Class;
typedef enum  {
	TUBA_REQUEST_V2_METHOD_GET,
	TUBA_REQUEST_V2_METHOD_POST,
	TUBA_REQUEST_V2_METHOD_PUT,
	TUBA_REQUEST_V2_METHOD_DELETE,
	TUBA_REQUEST_V2_METHOD_PATCH
} TubaRequestV2Method;

#define TUBA_REQUEST_V2_TYPE_METHOD (tuba_request_v2_method_get_type ())

#define TUBA_TYPE_OOPSIE (tuba_oopsie_get_type ())
typedef struct _TubaWidgetsAttachmentItemDownloadData TubaWidgetsAttachmentItemDownloadData;

#define TUBA_TYPE_SETTINGS (tuba_settings_get_type ())
#define TUBA_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_TYPE_SETTINGS, TubaSettings))
#define TUBA_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_TYPE_SETTINGS, TubaSettingsClass))
#define TUBA_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_TYPE_SETTINGS))
#define TUBA_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_TYPE_SETTINGS))
#define TUBA_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_TYPE_SETTINGS, TubaSettingsClass))

typedef struct _TubaSettings TubaSettings;
typedef struct _TubaSettingsClass TubaSettingsClass;
typedef struct _TubaWidgetsAttachmentItemOpenData TubaWidgetsAttachmentItemOpenData;

struct _TubaWidgetsAttachmentItem {
	AdwBin parent_instance;
	TubaWidgetsAttachmentItemPrivate * priv;
	GtkOverlay* overlay;
	GtkButton* button;
	GtkButton* alt_btn;
	gulong alt_btn_clicked_id;
	GSimpleAction* copy_media_simple_action;
};

struct _TubaWidgetsAttachmentItemClass {
	AdwBinClass parent_class;
	void (*copy_media) (TubaWidgetsAttachmentItem* self);
	void (*on_rebind) (TubaWidgetsAttachmentItem* self);
	void (*on_click) (TubaWidgetsAttachmentItem* self);
	void (*on_secondary_click) (TubaWidgetsAttachmentItem* self, gint n_press, gdouble x, gdouble y);
};

struct _TubaWidgetsAttachmentItemPrivate {
	TubaAPIAttachment* _entity;
	GtkGestureClick* _gesture_click_controller;
	GtkGestureLongPress* _gesture_lp_controller;
	GtkPopoverMenu* _context_menu;
	GSimpleActionGroup* actions;
	TubaAttachmentMediaType _media_kind;
};

struct _TubaWidgetsAttachmentItemSaveMediaAsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* url;
	GtkFileDialog* chooser;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GtkFileDialog* _tmp2_;
	GFile* file;
	TubaApplication* _tmp3_;
	TubaDialogsMainWindow* _tmp4_;
	TubaDialogsMainWindow* _tmp5_;
	GFile* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gboolean success;
	TubaApplication* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GVariant* _tmp13_;
	GVariant* _tmp14_;
	TubaApplication* _tmp15_;
	GError* e;
	GError* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	GError* _inner_error0_;
};

typedef enum  {
	TUBA_OOPSIE_USER,
	TUBA_OOPSIE_PARSING,
	TUBA_OOPSIE_INSTANCE,
	TUBA_OOPSIE_INTERNAL,
	TUBA_OOPSIE_HTTP_401 = 401,
	TUBA_OOPSIE_HTTP_403 = 403,
	TUBA_OOPSIE_HTTP_404 = 404,
	TUBA_OOPSIE_HTTP_410 = 410,
	TUBA_OOPSIE_HTTP_422 = 422,
	TUBA_OOPSIE_HTTP_429 = 429,
	TUBA_OOPSIE_HTTP_500 = 500,
	TUBA_OOPSIE_HTTP_503 = 503
} TubaOopsie;
#define TUBA_OOPSIE tuba_oopsie_quark ()

struct _TubaWidgetsAttachmentItemDownloadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* attachment_url;
	GFile* file;
	gboolean result;
	gboolean res;
	TubaRequestV2* req;
	TubaRequestV2* _tmp0_;
	GInputStream* data;
	TubaRequestV2* _tmp1_;
	GInputStream* _tmp2_;
	GFileOutputStream* stream;
	GFileOutputStream* _tmp3_;
	GFileOutputStream* _tmp4_;
	GInputStream* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	GError* e;
	GError* _tmp11_;
	const gchar* _tmp12_;
	GError* _vala1_e;
	GError* _tmp13_;
	const gchar* _tmp14_;
	GError* _inner_error0_;
};

struct _TubaWidgetsAttachmentItemOpenData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	TubaWidgetsAttachmentItem* self;
	const gchar* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	TubaAPIAttachment* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	TubaSettings* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	TubaAPIAttachment* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	TubaAPIAttachment* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	TubaAPIAttachment* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* path;
	gchar* _tmp18_;
	GError* e;
	TubaApplication* _tmp19_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GError* _inner_error0_;
};

static gint TubaWidgetsAttachmentItem_private_offset;
static gpointer tuba_widgets_attachment_item_parent_class = NULL;
VALA_EXTERN TubaApplication* tuba_app;
VALA_EXTERN TubaSettings* tuba_settings;

VALA_EXTERN GType tuba_widgets_attachment_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaWidgetsAttachmentItem, g_object_unref)
VALA_EXTERN GType tuba_entity_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaEntity, g_object_unref)
VALA_EXTERN GType tuba_api_attachment_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaAPIAttachment, g_object_unref)
VALA_EXTERN GType tuba_attachment_media_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void tuba_widgets_attachment_item_copy_media (TubaWidgetsAttachmentItem* self);
VALA_EXTERN void tuba_widgets_attachment_item_on_rebind (TubaWidgetsAttachmentItem* self);
VALA_EXTERN void tuba_widgets_attachment_item_on_click (TubaWidgetsAttachmentItem* self);
VALA_EXTERN void tuba_widgets_attachment_item_on_secondary_click (TubaWidgetsAttachmentItem* self,
                                                      gint n_press,
                                                      gdouble x,
                                                      gdouble y);
VALA_EXTERN GtkPopoverMenu* tuba_widgets_attachment_item_get_context_menu (TubaWidgetsAttachmentItem* self);
static void tuba_widgets_attachment_item_copy_url (TubaWidgetsAttachmentItem* self);
static void _tuba_widgets_attachment_item_copy_url_gsimple_action_activate_callback (GSimpleAction* action,
                                                                              GVariant* parameter,
                                                                              gpointer self);
static void tuba_widgets_attachment_item_open_in_browser (TubaWidgetsAttachmentItem* self);
static void _tuba_widgets_attachment_item_open_in_browser_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                     GVariant* parameter,
                                                                                     gpointer self);
static void tuba_widgets_attachment_item_save_as (TubaWidgetsAttachmentItem* self);
static void _tuba_widgets_attachment_item_save_as_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self);
VALA_EXTERN void tuba_utils_host_copy (const gchar* str);
VALA_EXTERN TubaAPIAttachment* tuba_widgets_attachment_item_get_entity (TubaWidgetsAttachmentItem* self);
VALA_EXTERN const gchar* tuba_api_attachment_get_url (TubaAPIAttachment* self);
VALA_EXTERN GType tuba_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaApplication, g_object_unref)
VALA_EXTERN void tuba_utils_host_open_url (const gchar* _uri,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gboolean tuba_utils_host_open_url_finish (GAsyncResult* _res_);
VALA_EXTERN void tuba_widgets_attachment_item_save_media_as (const gchar* url,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
VALA_EXTERN void tuba_widgets_attachment_item_save_media_as_finish (GAsyncResult* _res_);
static void tuba_widgets_attachment_item_save_media_as_data_free (gpointer _data);
static gboolean tuba_widgets_attachment_item_save_media_as_co (TubaWidgetsAttachmentItemSaveMediaAsData* _data_);
VALA_EXTERN GType tuba_dialogs_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaDialogsMainWindow, g_object_unref)
VALA_EXTERN TubaDialogsMainWindow* tuba_application_get_main_window (TubaApplication* self);
static void tuba_widgets_attachment_item_save_media_as_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static void tuba_widgets_attachment_item_download (const gchar* attachment_url,
                                            GFile* file,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
static gboolean tuba_widgets_attachment_item_download_finish (GAsyncResult* _res_);
static void tuba_widgets_attachment_item_download_data_free (gpointer _data);
static gboolean tuba_widgets_attachment_item_download_co (TubaWidgetsAttachmentItemDownloadData* _data_);
VALA_EXTERN GType tuba_request_v2_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaRequestV2, g_object_unref)
VALA_EXTERN GType tuba_request_v2_method_get_type (void) G_GNUC_CONST ;
VALA_EXTERN TubaRequestV2* tuba_request_v2_new (const gchar* url,
                                    TubaRequestV2Method method);
VALA_EXTERN TubaRequestV2* tuba_request_v2_construct (GType object_type,
                                          const gchar* url,
                                          TubaRequestV2Method method);
VALA_EXTERN void tuba_request_v2_exec (TubaRequestV2* self,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_);
VALA_EXTERN GQuark tuba_oopsie_quark (void);
VALA_EXTERN GType tuba_oopsie_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GInputStream* tuba_request_v2_exec_finish (TubaRequestV2* self,
                                           GAsyncResult* _res_,
                                           SoupMessageHeaders** response_headers,
                                           GError** error);
static void tuba_widgets_attachment_item_download_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static void tuba_widgets_attachment_item_on_alt_text_btn_clicked (TubaWidgetsAttachmentItem* self);
VALA_EXTERN const gchar* tuba_api_attachment_get_description (TubaAPIAttachment* self);
VALA_EXTERN const gchar* tuba_api_attachment_get_tuba_translated_alt_text (TubaAPIAttachment* self);
VALA_EXTERN AdwDialog* tuba_widgets_attachment_item_create_alt_text_dialog (TubaWidgetsAttachmentItem* self,
                                                                const gchar* alt_text,
                                                                gboolean show);
VALA_EXTERN void tuba_widgets_attachment_item_create_context_menu (TubaWidgetsAttachmentItem* self);
static GVariant* _variant_new52 (const gchar* value);
VALA_EXTERN void tuba_widgets_attachment_item_set_context_menu (TubaWidgetsAttachmentItem* self,
                                                    GtkPopoverMenu* value);
static void tuba_widgets_attachment_item_real_copy_media (TubaWidgetsAttachmentItem* self);
static void tuba_widgets_attachment_item_real_on_rebind (TubaWidgetsAttachmentItem* self);
VALA_EXTERN TubaAttachmentMediaType tuba_attachment_media_type_from_string (const gchar* media_type);
VALA_EXTERN const gchar* tuba_api_attachment_get_kind (TubaAPIAttachment* self);
VALA_EXTERN void tuba_widgets_attachment_item_set_media_kind (TubaWidgetsAttachmentItem* self,
                                                  TubaAttachmentMediaType value);
static void tuba_widgets_attachment_item_real_on_click (TubaWidgetsAttachmentItem* self);
VALA_EXTERN void tuba_widgets_attachment_item_open (TubaWidgetsAttachmentItem* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN void tuba_widgets_attachment_item_open_finish (TubaWidgetsAttachmentItem* self,
                                               GAsyncResult* _res_);
static void tuba_widgets_attachment_item_on_long_press (TubaWidgetsAttachmentItem* self,
                                                 gdouble x,
                                                 gdouble y);
static void tuba_widgets_attachment_item_real_on_secondary_click (TubaWidgetsAttachmentItem* self,
                                                           gint n_press,
                                                           gdouble x,
                                                           gdouble y);
VALA_EXTERN GtkGestureClick* tuba_widgets_attachment_item_get_gesture_click_controller (TubaWidgetsAttachmentItem* self);
VALA_EXTERN GtkGestureLongPress* tuba_widgets_attachment_item_get_gesture_lp_controller (TubaWidgetsAttachmentItem* self);
VALA_EXTERN gboolean tuba_dialogs_main_window_get_is_media_viewer_visible (TubaDialogsMainWindow* self);
static void tuba_widgets_attachment_item_open_data_free (gpointer _data);
static gboolean tuba_widgets_attachment_item_open_co (TubaWidgetsAttachmentItemOpenData* _data_);
VALA_EXTERN GType tuba_settings_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaSettings, g_object_unref)
VALA_EXTERN gboolean tuba_settings_get_fetch_remote_media_default (TubaSettings* self);
VALA_EXTERN const gchar* tuba_api_attachment_get_remote_url (TubaAPIAttachment* self);
VALA_EXTERN void tuba_utils_host_download (const gchar* url,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gchar* tuba_utils_host_download_finish (GAsyncResult* _res_,
                                        GError** error);
static void tuba_widgets_attachment_item_open_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
VALA_EXTERN TubaWidgetsAttachmentItem* tuba_widgets_attachment_item_new (void);
VALA_EXTERN TubaWidgetsAttachmentItem* tuba_widgets_attachment_item_construct (GType object_type);
VALA_EXTERN void tuba_widgets_attachment_item_set_entity (TubaWidgetsAttachmentItem* self,
                                              TubaAPIAttachment* value);
VALA_EXTERN void tuba_widgets_attachment_item_set_gesture_click_controller (TubaWidgetsAttachmentItem* self,
                                                                GtkGestureClick* value);
VALA_EXTERN void tuba_widgets_attachment_item_set_gesture_lp_controller (TubaWidgetsAttachmentItem* self,
                                                             GtkGestureLongPress* value);
VALA_EXTERN TubaAttachmentMediaType tuba_widgets_attachment_item_get_media_kind (TubaWidgetsAttachmentItem* self);
static GObject * tuba_widgets_attachment_item_constructor (GType type,
                                                    guint n_construct_properties,
                                                    GObjectConstructParam * construct_properties);
static void _tuba_widgets_attachment_item_copy_media_g_simple_action_activate (GSimpleAction* _sender,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void _tuba_widgets_attachment_item_on_rebind_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self);
static void _tuba_widgets_attachment_item_on_click_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static void _tuba_widgets_attachment_item_on_secondary_click_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                                                 gint n_press,
                                                                                 gdouble x,
                                                                                 gdouble y,
                                                                                 gpointer self);
static void _tuba_widgets_attachment_item_on_long_press_gtk_gesture_long_press_pressed (GtkGestureLongPress* _sender,
                                                                                 gdouble x,
                                                                                 gdouble y,
                                                                                 gpointer self);
static void _tuba_widgets_attachment_item_on_alt_text_btn_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                               gpointer self);
static void tuba_widgets_attachment_item_finalize (GObject * obj);
static GType tuba_widgets_attachment_item_get_type_once (void);
static void _vala_tuba_widgets_attachment_item_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec);
static void _vala_tuba_widgets_attachment_item_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static const GActionEntry TUBA_WIDGETS_ATTACHMENT_ITEM_ACTION_ENTRIES[3] = {{"copy-url", _tuba_widgets_attachment_item_copy_url_gsimple_action_activate_callback}, {"open-in-browser", _tuba_widgets_attachment_item_open_in_browser_gsimple_action_activate_callback}, {"save-as", _tuba_widgets_attachment_item_save_as_gsimple_action_activate_callback}};

static inline gpointer
tuba_widgets_attachment_item_get_instance_private (TubaWidgetsAttachmentItem* self)
{
	return G_STRUCT_MEMBER_P (self, TubaWidgetsAttachmentItem_private_offset);
}

static void
_tuba_widgets_attachment_item_copy_url_gsimple_action_activate_callback (GSimpleAction* action,
                                                                         GVariant* parameter,
                                                                         gpointer self)
{
	tuba_widgets_attachment_item_copy_url ((TubaWidgetsAttachmentItem*) self);
}

static void
_tuba_widgets_attachment_item_open_in_browser_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                GVariant* parameter,
                                                                                gpointer self)
{
	tuba_widgets_attachment_item_open_in_browser ((TubaWidgetsAttachmentItem*) self);
}

static void
_tuba_widgets_attachment_item_save_as_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self)
{
	tuba_widgets_attachment_item_save_as ((TubaWidgetsAttachmentItem*) self);
}

static void
tuba_widgets_attachment_item_copy_url (TubaWidgetsAttachmentItem* self)
{
	TubaAPIAttachment* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	TubaApplication* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_entity;
	_tmp1_ = tuba_api_attachment_get_url (_tmp0_);
	_tmp2_ = _tmp1_;
	tuba_utils_host_copy (_tmp2_);
	_tmp3_ = tuba_app;
	g_signal_emit_by_name (_tmp3_, "toast", _ ("Copied attachment url to clipboard"), (guint) 5, NULL, NULL, NULL);
}

static void
tuba_widgets_attachment_item_open_in_browser (TubaWidgetsAttachmentItem* self)
{
	TubaAPIAttachment* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_entity;
	_tmp1_ = tuba_api_attachment_get_url (_tmp0_);
	_tmp2_ = _tmp1_;
	tuba_utils_host_open_url (_tmp2_, NULL, NULL);
}

static void
tuba_widgets_attachment_item_save_as (TubaWidgetsAttachmentItem* self)
{
	TubaAPIAttachment* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_entity;
	_tmp1_ = tuba_api_attachment_get_url (_tmp0_);
	_tmp2_ = _tmp1_;
	tuba_widgets_attachment_item_save_media_as (_tmp2_, NULL, NULL);
}

static void
tuba_widgets_attachment_item_save_media_as_data_free (gpointer _data)
{
	TubaWidgetsAttachmentItemSaveMediaAsData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	g_slice_free (TubaWidgetsAttachmentItemSaveMediaAsData, _data_);
}

void
tuba_widgets_attachment_item_save_media_as (const gchar* url,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	TubaWidgetsAttachmentItemSaveMediaAsData* _data_;
	gchar* _tmp0_;
	g_return_if_fail (url != NULL);
	_data_ = g_slice_new0 (TubaWidgetsAttachmentItemSaveMediaAsData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, tuba_widgets_attachment_item_save_media_as_data_free);
	_tmp0_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp0_;
	tuba_widgets_attachment_item_save_media_as_co (_data_);
}

void
tuba_widgets_attachment_item_save_media_as_finish (GAsyncResult* _res_)
{
	TubaWidgetsAttachmentItemSaveMediaAsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
tuba_widgets_attachment_item_save_media_as_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	TubaWidgetsAttachmentItemSaveMediaAsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	tuba_widgets_attachment_item_save_media_as_co (_data_);
}

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

static gboolean
tuba_widgets_attachment_item_save_media_as_co (TubaWidgetsAttachmentItemSaveMediaAsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup (_ ("Save Attachment"));
	_data_->_tmp1_ = g_path_get_basename (_data_->url);
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = gtk_file_dialog_new ();
	gtk_file_dialog_set_title (_data_->_tmp2_, _data_->_tmp0_);
	_g_free0 (_data_->_tmp0_);
	gtk_file_dialog_set_modal (_data_->_tmp2_, TRUE);
	gtk_file_dialog_set_initial_name (_data_->_tmp2_, _data_->_tmp1_);
	_g_free0 (_data_->_tmp1_);
	_data_->chooser = _data_->_tmp2_;
	{
		_data_->_tmp3_ = tuba_app;
		_data_->_tmp4_ = tuba_application_get_main_window (_data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_state_ = 1;
		gtk_file_dialog_save (_data_->chooser, (GtkWindow*) _data_->_tmp5_, NULL, tuba_widgets_attachment_item_save_media_as_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = gtk_file_dialog_save_finish (_data_->chooser, _data_->_res_, &_data_->_inner_error0_);
		_data_->file = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (_data_->file != NULL) {
			_data_->_tmp7_ = string_to_string (_data_->url);
			_data_->_tmp8_ = g_strconcat ("Downloading file: ", _data_->_tmp7_, "…", NULL);
			_data_->_tmp9_ = _data_->_tmp8_;
			g_debug ("Item.vala:44: %s", _data_->_tmp9_);
			_g_free0 (_data_->_tmp9_);
			_data_->_state_ = 2;
			tuba_widgets_attachment_item_download (_data_->url, _data_->file, tuba_widgets_attachment_item_save_media_as_ready, _data_);
			return FALSE;
			_state_2:
			_data_->success = tuba_widgets_attachment_item_download_finish (_data_->_res_);
			if (_data_->success) {
				_data_->_tmp10_ = tuba_app;
				_data_->_tmp11_ = g_file_get_path (_data_->file);
				_data_->_tmp12_ = _data_->_tmp11_;
				_data_->_tmp13_ = g_variant_new_string (_data_->_tmp12_);
				g_variant_ref_sink (_data_->_tmp13_);
				_data_->_tmp14_ = _data_->_tmp13_;
				g_signal_emit_by_name (_data_->_tmp10_, "toast", _ ("Saved Media"), (guint) 5, "app.open-containing-folder", _data_->_tmp14_, _ ("Open Folder"));
				_g_variant_unref0 (_data_->_tmp14_);
				_g_free0 (_data_->_tmp12_);
			} else {
				_data_->_tmp15_ = tuba_app;
				g_signal_emit_by_name (_data_->_tmp15_, "toast", _ ("Couldn't Save Media"), (guint) 5, NULL, NULL, NULL);
			}
		}
		_g_object_unref0 (_data_->file);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp16_ = _data_->e;
		_data_->_tmp17_ = _data_->_tmp16_->message;
		_data_->_tmp18_ = string_to_string (_data_->_tmp17_);
		_data_->_tmp19_ = g_strconcat ("Couldn't get the result of FileDialog for attachment: ", _data_->_tmp18_, NULL);
		_data_->_tmp20_ = _data_->_tmp19_;
		g_warning ("Item.vala:63: %s", _data_->_tmp20_);
		_g_free0 (_data_->_tmp20_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->chooser);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->chooser);
	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
tuba_widgets_attachment_item_download_data_free (gpointer _data)
{
	TubaWidgetsAttachmentItemDownloadData* _data_;
	_data_ = _data;
	_g_free0 (_data_->attachment_url);
	_g_object_unref0 (_data_->file);
	g_slice_free (TubaWidgetsAttachmentItemDownloadData, _data_);
}

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

static void
tuba_widgets_attachment_item_download (const gchar* attachment_url,
                                       GFile* file,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	TubaWidgetsAttachmentItemDownloadData* _data_;
	gchar* _tmp0_;
	GFile* _tmp1_;
	g_return_if_fail (attachment_url != NULL);
	g_return_if_fail (file != NULL);
	_data_ = g_slice_new0 (TubaWidgetsAttachmentItemDownloadData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, tuba_widgets_attachment_item_download_data_free);
	_tmp0_ = g_strdup (attachment_url);
	_g_free0 (_data_->attachment_url);
	_data_->attachment_url = _tmp0_;
	_tmp1_ = _g_object_ref0 (file);
	_g_object_unref0 (_data_->file);
	_data_->file = _tmp1_;
	tuba_widgets_attachment_item_download_co (_data_);
}

static gboolean
tuba_widgets_attachment_item_download_finish (GAsyncResult* _res_)
{
	gboolean result;
	TubaWidgetsAttachmentItemDownloadData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
tuba_widgets_attachment_item_download_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	TubaWidgetsAttachmentItemDownloadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	tuba_widgets_attachment_item_download_co (_data_);
}

static gboolean
tuba_widgets_attachment_item_download_co (TubaWidgetsAttachmentItemDownloadData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->res = FALSE;
	{
		_data_->_tmp0_ = tuba_request_v2_new (_data_->attachment_url, TUBA_REQUEST_V2_METHOD_GET);
		_data_->req = _data_->_tmp0_;
		_data_->_tmp1_ = _data_->req;
		_data_->_state_ = 1;
		tuba_request_v2_exec (_data_->_tmp1_, tuba_widgets_attachment_item_download_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp2_ = tuba_request_v2_exec_finish (_data_->_tmp1_, _data_->_res_, NULL, &_data_->_inner_error0_);
		_data_->data = _data_->_tmp2_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->req);
			goto __catch0_g_error;
		}
		_data_->_tmp3_ = g_file_replace (_data_->file, NULL, FALSE, G_FILE_CREATE_PRIVATE, NULL, &_data_->_inner_error0_);
		_data_->stream = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->data);
			_g_object_unref0 (_data_->req);
			goto __catch0_g_error;
		}
		{
			_data_->_tmp4_ = _data_->stream;
			_data_->_tmp5_ = _data_->data;
			g_output_stream_splice ((GOutputStream*) _data_->_tmp4_, _data_->_tmp5_, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (_data_->_inner_error0_->domain == G_IO_ERROR) {
					goto __catch1_g_io_error;
				}
				_g_object_unref0 (_data_->stream);
				_g_object_unref0 (_data_->data);
				_g_object_unref0 (_data_->req);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp6_ = g_file_get_path (_data_->file);
			_data_->_tmp7_ = _data_->_tmp6_;
			_data_->_tmp8_ = string_to_string (_data_->_tmp7_);
			_data_->_tmp9_ = g_strconcat ("   OK: File written to: ", _data_->_tmp8_, NULL);
			_data_->_tmp10_ = _data_->_tmp9_;
			g_debug ("Item.vala:76: %s", _data_->_tmp10_);
			_g_free0 (_data_->_tmp10_);
			_g_free0 (_data_->_tmp7_);
			_data_->res = TRUE;
		}
		goto __finally1;
		__catch1_g_io_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp11_ = _data_->e;
			_data_->_tmp12_ = _data_->_tmp11_->message;
			g_warning ("Item.vala:79: %s", _data_->_tmp12_);
			_g_error_free0 (_data_->e);
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->stream);
			_g_object_unref0 (_data_->data);
			_g_object_unref0 (_data_->req);
			goto __catch0_g_error;
		}
		_g_object_unref0 (_data_->stream);
		_g_object_unref0 (_data_->data);
		_g_object_unref0 (_data_->req);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp13_ = _data_->_vala1_e;
		_data_->_tmp14_ = _data_->_tmp13_->message;
		g_warning ("Item.vala:83: %s", _data_->_tmp14_);
		_g_error_free0 (_data_->_vala1_e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->res;
	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
tuba_widgets_attachment_item_on_alt_text_btn_clicked (TubaWidgetsAttachmentItem* self)
{
	gboolean _tmp0_ = FALSE;
	TubaAPIAttachment* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_entity;
	if (_tmp1_ != NULL) {
		TubaAPIAttachment* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp2_ = self->priv->_entity;
		_tmp3_ = tuba_api_attachment_get_description (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		const gchar* _tmp5_ = NULL;
		TubaAPIAttachment* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		AdwDialog* _tmp15_;
		AdwDialog* _tmp16_;
		_tmp6_ = self->priv->_entity;
		_tmp7_ = tuba_api_attachment_get_tuba_translated_alt_text (_tmp6_);
		_tmp8_ = _tmp7_;
		if (_tmp8_ == NULL) {
			TubaAPIAttachment* _tmp9_;
			const gchar* _tmp10_;
			const gchar* _tmp11_;
			_tmp9_ = self->priv->_entity;
			_tmp10_ = tuba_api_attachment_get_description (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp5_ = _tmp11_;
		} else {
			TubaAPIAttachment* _tmp12_;
			const gchar* _tmp13_;
			const gchar* _tmp14_;
			_tmp12_ = self->priv->_entity;
			_tmp13_ = tuba_api_attachment_get_tuba_translated_alt_text (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp5_ = _tmp14_;
		}
		_tmp15_ = tuba_widgets_attachment_item_create_alt_text_dialog (self, _tmp5_, TRUE);
		_tmp16_ = _tmp15_;
		_g_object_unref0 (_tmp16_);
	}
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

AdwDialog*
tuba_widgets_attachment_item_create_alt_text_dialog (TubaWidgetsAttachmentItem* self,
                                                     const gchar* alt_text,
                                                     gboolean show)
{
	GtkTextView* alt_label = NULL;
	GtkTextView* _tmp0_ = NULL;
	GtkTextView* _tmp1_;
	GtkTextView* _tmp2_;
	GtkTextBuffer* _tmp3_;
	GtkTextBuffer* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GtkScrolledWindow* scrolledwindow = NULL;
	GtkTextView* _tmp7_;
	GtkWidget* _tmp8_;
	GtkScrolledWindow* _tmp9_ = NULL;
	AdwToolbarView* toolbar_view = NULL;
	AdwToolbarView* _tmp10_;
	AdwHeaderBar* headerbar = NULL;
	AdwHeaderBar* _tmp11_;
	AdwDialog* window = NULL;
	gchar* _tmp12_;
	AdwToolbarView* _tmp13_;
	GtkWidget* _tmp14_;
	AdwDialog* _tmp15_ = NULL;
	AdwToolbarView* _tmp16_;
	AdwHeaderBar* _tmp17_;
	AdwToolbarView* _tmp18_;
	GtkScrolledWindow* _tmp19_;
	AdwDialog* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (alt_text != NULL, NULL);
	_tmp0_ = (GtkTextView*) gtk_text_view_new ();
	gtk_text_view_set_bottom_margin (_tmp0_, 6);
	gtk_text_view_set_top_margin (_tmp0_, 6);
	gtk_text_view_set_left_margin (_tmp0_, 12);
	gtk_text_view_set_right_margin (_tmp0_, 12);
	gtk_text_view_set_wrap_mode (_tmp0_, GTK_WRAP_WORD_CHAR);
	gtk_text_view_set_editable (_tmp0_, FALSE);
	g_object_ref_sink (_tmp0_);
	alt_label = _tmp0_;
	_tmp1_ = alt_label;
	gtk_widget_remove_css_class ((GtkWidget*) _tmp1_, "view");
	_tmp2_ = alt_label;
	_tmp3_ = gtk_text_view_get_buffer (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = string_strip (alt_text);
	_tmp6_ = _tmp5_;
	g_object_set (_tmp4_, "text", _tmp6_, NULL);
	_g_free0 (_tmp6_);
	_tmp7_ = alt_label;
	_tmp8_ = _g_object_ref0 ((GtkWidget*) _tmp7_);
	_tmp9_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	gtk_scrolled_window_set_child (_tmp9_, _tmp8_);
	_g_object_unref0 (_tmp8_);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp9_, TRUE);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp9_, TRUE);
	g_object_ref_sink (_tmp9_);
	scrolledwindow = _tmp9_;
	_tmp10_ = (AdwToolbarView*) adw_toolbar_view_new ();
	g_object_ref_sink (_tmp10_);
	toolbar_view = _tmp10_;
	_tmp11_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp11_);
	headerbar = _tmp11_;
	_tmp12_ = g_strdup (_ ("Alternative Text"));
	_tmp13_ = toolbar_view;
	_tmp14_ = _g_object_ref0 ((GtkWidget*) _tmp13_);
	_tmp15_ = adw_dialog_new ();
	adw_dialog_set_title (_tmp15_, _tmp12_);
	_g_free0 (_tmp12_);
	adw_dialog_set_child (_tmp15_, _tmp14_);
	_g_object_unref0 (_tmp14_);
	adw_dialog_set_content_width (_tmp15_, 400);
	adw_dialog_set_content_height (_tmp15_, 300);
	g_object_ref_sink (_tmp15_);
	window = _tmp15_;
	_tmp16_ = toolbar_view;
	_tmp17_ = headerbar;
	adw_toolbar_view_add_top_bar (_tmp16_, (GtkWidget*) _tmp17_);
	_tmp18_ = toolbar_view;
	_tmp19_ = scrolledwindow;
	adw_toolbar_view_set_content (_tmp18_, (GtkWidget*) _tmp19_);
	if (show) {
		AdwDialog* _tmp20_;
		TubaApplication* _tmp21_;
		TubaDialogsMainWindow* _tmp22_;
		TubaDialogsMainWindow* _tmp23_;
		_tmp20_ = window;
		_tmp21_ = tuba_app;
		_tmp22_ = tuba_application_get_main_window (_tmp21_);
		_tmp23_ = _tmp22_;
		adw_dialog_present (_tmp20_, (GtkWidget*) _tmp23_);
	}
	result = window;
	_g_object_unref0 (headerbar);
	_g_object_unref0 (toolbar_view);
	_g_object_unref0 (scrolledwindow);
	_g_object_unref0 (alt_label);
	return result;
}

static GVariant*
_variant_new52 (const gchar* value)
{
	return g_variant_ref_sink (g_variant_new_string (value));
}

void
tuba_widgets_attachment_item_create_context_menu (TubaWidgetsAttachmentItem* self)
{
	GMenu* menu_model = NULL;
	GMenu* _tmp0_;
	GMenuItem* copy_media_menu_item = NULL;
	GMenuItem* _tmp1_;
	GVariant* _tmp2_;
	GtkPopoverMenu* _tmp3_ = NULL;
	GtkPopoverMenu* _tmp4_;
	GtkPopoverMenu* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_menu_new ();
	menu_model = _tmp0_;
	g_menu_append (menu_model, _ ("Open in Browser"), "attachment.open-in-browser");
	g_menu_append (menu_model, _ ("Copy URL"), "attachment.copy-url");
	g_menu_append (menu_model, _ ("Save Media…"), "attachment.save-as");
	_tmp1_ = g_menu_item_new (_ ("Copy Media"), "attachment.copy-media");
	copy_media_menu_item = _tmp1_;
	_tmp2_ = _variant_new52 ("action-disabled");
	g_menu_item_set_attribute_value (copy_media_menu_item, "hidden-when", _tmp2_);
	_g_variant_unref0 (_tmp2_);
	g_menu_append_item (menu_model, copy_media_menu_item);
	_tmp3_ = (GtkPopoverMenu*) gtk_popover_menu_new_from_model ((GMenuModel*) menu_model);
	gtk_popover_set_has_arrow ((GtkPopover*) _tmp3_, FALSE);
	gtk_widget_set_halign ((GtkWidget*) _tmp3_, GTK_ALIGN_START);
	g_object_ref_sink (_tmp3_);
	_tmp4_ = _tmp3_;
	tuba_widgets_attachment_item_set_context_menu (self, _tmp4_);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = self->priv->_context_menu;
	gtk_widget_set_parent ((GtkWidget*) _tmp5_, (GtkWidget*) self);
	_g_object_unref0 (copy_media_menu_item);
	_g_object_unref0 (menu_model);
}

static void
tuba_widgets_attachment_item_real_copy_media (TubaWidgetsAttachmentItem* self)
{
}

void
tuba_widgets_attachment_item_copy_media (TubaWidgetsAttachmentItem* self)
{
	TubaWidgetsAttachmentItemClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_WIDGETS_ATTACHMENT_ITEM_GET_CLASS (self);
	if (_klass_->copy_media) {
		_klass_->copy_media (self);
	}
}

static void
tuba_widgets_attachment_item_real_on_rebind (TubaWidgetsAttachmentItem* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	TubaAPIAttachment* _tmp2_;
	GtkButton* _tmp9_;
	TubaAPIAttachment* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	_tmp2_ = self->priv->_entity;
	if (_tmp2_ != NULL) {
		TubaAPIAttachment* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		_tmp3_ = self->priv->_entity;
		_tmp4_ = tuba_api_attachment_get_description (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		TubaAPIAttachment* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		_tmp6_ = self->priv->_entity;
		_tmp7_ = tuba_api_attachment_get_description (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp0_ = g_strcmp0 (_tmp8_, "") != 0;
	} else {
		_tmp0_ = FALSE;
	}
	_tmp9_ = self->alt_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp9_, _tmp0_);
	_tmp10_ = self->priv->_entity;
	_tmp11_ = tuba_api_attachment_get_kind (_tmp10_);
	_tmp12_ = _tmp11_;
	tuba_widgets_attachment_item_set_media_kind (self, tuba_attachment_media_type_from_string (_tmp12_));
}

void
tuba_widgets_attachment_item_on_rebind (TubaWidgetsAttachmentItem* self)
{
	TubaWidgetsAttachmentItemClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_WIDGETS_ATTACHMENT_ITEM_GET_CLASS (self);
	if (_klass_->on_rebind) {
		_klass_->on_rebind (self);
	}
}

static void
tuba_widgets_attachment_item_real_on_click (TubaWidgetsAttachmentItem* self)
{
	tuba_widgets_attachment_item_open (self, NULL, NULL);
}

void
tuba_widgets_attachment_item_on_click (TubaWidgetsAttachmentItem* self)
{
	TubaWidgetsAttachmentItemClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_WIDGETS_ATTACHMENT_ITEM_GET_CLASS (self);
	if (_klass_->on_click) {
		_klass_->on_click (self);
	}
}

static void
tuba_widgets_attachment_item_on_long_press (TubaWidgetsAttachmentItem* self,
                                            gdouble x,
                                            gdouble y)
{
	g_return_if_fail (self != NULL);
	tuba_widgets_attachment_item_on_secondary_click (self, 1, x, y);
}

static void
tuba_widgets_attachment_item_real_on_secondary_click (TubaWidgetsAttachmentItem* self,
                                                      gint n_press,
                                                      gdouble x,
                                                      gdouble y)
{
	GtkGestureClick* _tmp0_;
	GtkGestureLongPress* _tmp1_;
	TubaApplication* _tmp2_;
	TubaDialogsMainWindow* _tmp3_;
	TubaDialogsMainWindow* _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	GdkRectangle rectangle = {0};
	GdkRectangle _tmp7_ = {0};
	GtkPopoverMenu* _tmp8_;
	GdkRectangle _tmp9_;
	GtkPopoverMenu* _tmp10_;
	_tmp0_ = self->priv->_gesture_click_controller;
	gtk_gesture_set_state ((GtkGesture*) _tmp0_, GTK_EVENT_SEQUENCE_CLAIMED);
	_tmp1_ = self->priv->_gesture_lp_controller;
	gtk_gesture_set_state ((GtkGesture*) _tmp1_, GTK_EVENT_SEQUENCE_CLAIMED);
	_tmp2_ = tuba_app;
	_tmp3_ = tuba_application_get_main_window (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = tuba_dialogs_main_window_get_is_media_viewer_visible (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_) {
		return;
	}
	_tmp7_.x = (gint) x;
	_tmp7_.y = (gint) y;
	_tmp7_.width = 0;
	_tmp7_.height = 0;
	rectangle = _tmp7_;
	_tmp8_ = self->priv->_context_menu;
	_tmp9_ = rectangle;
	gtk_popover_set_pointing_to ((GtkPopover*) _tmp8_, &_tmp9_);
	_tmp10_ = self->priv->_context_menu;
	gtk_popover_popup ((GtkPopover*) _tmp10_);
}

void
tuba_widgets_attachment_item_on_secondary_click (TubaWidgetsAttachmentItem* self,
                                                 gint n_press,
                                                 gdouble x,
                                                 gdouble y)
{
	TubaWidgetsAttachmentItemClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = TUBA_WIDGETS_ATTACHMENT_ITEM_GET_CLASS (self);
	if (_klass_->on_secondary_click) {
		_klass_->on_secondary_click (self, n_press, x, y);
	}
}

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

void
tuba_widgets_attachment_item_open (TubaWidgetsAttachmentItem* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	TubaWidgetsAttachmentItemOpenData* _data_;
	TubaWidgetsAttachmentItem* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (TubaWidgetsAttachmentItemOpenData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, tuba_widgets_attachment_item_open_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	tuba_widgets_attachment_item_open_co (_data_);
}

void
tuba_widgets_attachment_item_open_finish (TubaWidgetsAttachmentItem* self,
                                          GAsyncResult* _res_)
{
	TubaWidgetsAttachmentItemOpenData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
tuba_widgets_attachment_item_open_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	TubaWidgetsAttachmentItemOpenData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	tuba_widgets_attachment_item_open_co (_data_);
}

static gboolean
tuba_widgets_attachment_item_open_co (TubaWidgetsAttachmentItemOpenData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp3_ = _data_->self->priv->_entity;
		_data_->_tmp4_ = tuba_api_attachment_get_kind (_data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		if (g_strcmp0 (_data_->_tmp5_, "unknown") == 0) {
			_data_->_tmp6_ = tuba_settings;
			_data_->_tmp7_ = tuba_settings_get_fetch_remote_media_default (_data_->_tmp6_);
			_data_->_tmp8_ = _data_->_tmp7_;
			_data_->_tmp2_ = _data_->_tmp8_;
		} else {
			_data_->_tmp2_ = FALSE;
		}
		if (_data_->_tmp2_) {
			_data_->_tmp9_ = _data_->self->priv->_entity;
			_data_->_tmp10_ = tuba_api_attachment_get_remote_url (_data_->_tmp9_);
			_data_->_tmp11_ = _data_->_tmp10_;
			_data_->_tmp1_ = _data_->_tmp11_ != NULL;
		} else {
			_data_->_tmp1_ = FALSE;
		}
		if (_data_->_tmp1_) {
			_data_->_tmp12_ = _data_->self->priv->_entity;
			_data_->_tmp13_ = tuba_api_attachment_get_remote_url (_data_->_tmp12_);
			_data_->_tmp14_ = _data_->_tmp13_;
			_data_->_tmp0_ = _data_->_tmp14_;
		} else {
			_data_->_tmp15_ = _data_->self->priv->_entity;
			_data_->_tmp16_ = tuba_api_attachment_get_url (_data_->_tmp15_);
			_data_->_tmp17_ = _data_->_tmp16_;
			_data_->_tmp0_ = _data_->_tmp17_;
		}
		_data_->_state_ = 1;
		tuba_utils_host_download (_data_->_tmp0_, tuba_widgets_attachment_item_open_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp18_ = tuba_utils_host_download_finish (_data_->_res_, &_data_->_inner_error0_);
		_data_->path = _data_->_tmp18_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_state_ = 2;
		tuba_utils_host_open_url (_data_->path, tuba_widgets_attachment_item_open_ready, _data_);
		return FALSE;
		_state_2:
		tuba_utils_host_open_url_finish (_data_->_res_);
		_g_free0 (_data_->path);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp19_ = tuba_app;
		_data_->_tmp20_ = _data_->e;
		_data_->_tmp21_ = _data_->_tmp20_->message;
		_data_->_tmp22_ = g_strdup_printf ("%s: %s", _ ("Error"), _data_->_tmp21_);
		_data_->_tmp23_ = _data_->_tmp22_;
		g_signal_emit_by_name (_data_->_tmp19_, "toast", _data_->_tmp23_, (guint) 5, NULL, NULL, NULL);
		_g_free0 (_data_->_tmp23_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	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;
}

TubaWidgetsAttachmentItem*
tuba_widgets_attachment_item_construct (GType object_type)
{
	TubaWidgetsAttachmentItem * self = NULL;
	self = (TubaWidgetsAttachmentItem*) g_object_new (object_type, NULL);
	return self;
}

TubaWidgetsAttachmentItem*
tuba_widgets_attachment_item_new (void)
{
	return tuba_widgets_attachment_item_construct (TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM);
}

TubaAPIAttachment*
tuba_widgets_attachment_item_get_entity (TubaWidgetsAttachmentItem* self)
{
	TubaAPIAttachment* result;
	TubaAPIAttachment* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_entity;
	result = _tmp0_;
	return result;
}

void
tuba_widgets_attachment_item_set_entity (TubaWidgetsAttachmentItem* self,
                                         TubaAPIAttachment* value)
{
	TubaAPIAttachment* old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_widgets_attachment_item_get_entity (self);
	if (old_value != value) {
		TubaAPIAttachment* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_entity);
		self->priv->_entity = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_ENTITY_PROPERTY]);
	}
}

GtkGestureClick*
tuba_widgets_attachment_item_get_gesture_click_controller (TubaWidgetsAttachmentItem* self)
{
	GtkGestureClick* result;
	GtkGestureClick* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_gesture_click_controller;
	result = _tmp0_;
	return result;
}

void
tuba_widgets_attachment_item_set_gesture_click_controller (TubaWidgetsAttachmentItem* self,
                                                           GtkGestureClick* value)
{
	GtkGestureClick* old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_widgets_attachment_item_get_gesture_click_controller (self);
	if (old_value != value) {
		GtkGestureClick* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_gesture_click_controller);
		self->priv->_gesture_click_controller = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_CLICK_CONTROLLER_PROPERTY]);
	}
}

GtkGestureLongPress*
tuba_widgets_attachment_item_get_gesture_lp_controller (TubaWidgetsAttachmentItem* self)
{
	GtkGestureLongPress* result;
	GtkGestureLongPress* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_gesture_lp_controller;
	result = _tmp0_;
	return result;
}

void
tuba_widgets_attachment_item_set_gesture_lp_controller (TubaWidgetsAttachmentItem* self,
                                                        GtkGestureLongPress* value)
{
	GtkGestureLongPress* old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_widgets_attachment_item_get_gesture_lp_controller (self);
	if (old_value != value) {
		GtkGestureLongPress* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_gesture_lp_controller);
		self->priv->_gesture_lp_controller = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_LP_CONTROLLER_PROPERTY]);
	}
}

GtkPopoverMenu*
tuba_widgets_attachment_item_get_context_menu (TubaWidgetsAttachmentItem* self)
{
	GtkPopoverMenu* result;
	GtkPopoverMenu* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_context_menu;
	result = _tmp0_;
	return result;
}

void
tuba_widgets_attachment_item_set_context_menu (TubaWidgetsAttachmentItem* self,
                                               GtkPopoverMenu* value)
{
	GtkPopoverMenu* old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_widgets_attachment_item_get_context_menu (self);
	if (old_value != value) {
		GtkPopoverMenu* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_context_menu);
		self->priv->_context_menu = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_CONTEXT_MENU_PROPERTY]);
	}
}

TubaAttachmentMediaType
tuba_widgets_attachment_item_get_media_kind (TubaWidgetsAttachmentItem* self)
{
	TubaAttachmentMediaType result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_media_kind;
	return result;
}

void
tuba_widgets_attachment_item_set_media_kind (TubaWidgetsAttachmentItem* self,
                                             TubaAttachmentMediaType value)
{
	TubaAttachmentMediaType old_value;
	g_return_if_fail (self != NULL);
	old_value = tuba_widgets_attachment_item_get_media_kind (self);
	if (old_value != value) {
		self->priv->_media_kind = value;
		g_object_notify_by_pspec ((GObject *) self, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_MEDIA_KIND_PROPERTY]);
	}
}

static void
_tuba_widgets_attachment_item_copy_media_g_simple_action_activate (GSimpleAction* _sender,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	tuba_widgets_attachment_item_copy_media ((TubaWidgetsAttachmentItem*) self);
}

static void
_tuba_widgets_attachment_item_on_rebind_g_object_notify (GObject* _sender,
                                                         GParamSpec* pspec,
                                                         gpointer self)
{
	tuba_widgets_attachment_item_on_rebind ((TubaWidgetsAttachmentItem*) self);
}

static void
_tuba_widgets_attachment_item_on_click_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	tuba_widgets_attachment_item_on_click ((TubaWidgetsAttachmentItem*) self);
}

static void
_tuba_widgets_attachment_item_on_secondary_click_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                                            gint n_press,
                                                                            gdouble x,
                                                                            gdouble y,
                                                                            gpointer self)
{
	tuba_widgets_attachment_item_on_secondary_click ((TubaWidgetsAttachmentItem*) self, n_press, x, y);
}

static void
_tuba_widgets_attachment_item_on_long_press_gtk_gesture_long_press_pressed (GtkGestureLongPress* _sender,
                                                                            gdouble x,
                                                                            gdouble y,
                                                                            gpointer self)
{
	tuba_widgets_attachment_item_on_long_press ((TubaWidgetsAttachmentItem*) self, x, y);
}

static void
_tuba_widgets_attachment_item_on_alt_text_btn_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                          gpointer self)
{
	tuba_widgets_attachment_item_on_alt_text_btn_clicked ((TubaWidgetsAttachmentItem*) self);
}

static GObject *
tuba_widgets_attachment_item_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	TubaWidgetsAttachmentItem * self;
	GSimpleActionGroup* _tmp0_;
	GSimpleActionGroup* _tmp1_;
	GSimpleAction* _tmp2_;
	GSimpleAction* _tmp3_;
	GSimpleActionGroup* _tmp4_;
	GSimpleAction* _tmp5_;
	GSimpleActionGroup* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar** _tmp10_;
	GtkButton* _tmp11_ = NULL;
	GtkButton* _tmp12_;
	GtkGestureClick* _tmp13_;
	GtkGestureClick* _tmp14_;
	GtkGestureLongPress* _tmp15_;
	GtkGestureLongPress* _tmp16_;
	GtkGestureClick* _tmp17_;
	GtkEventController* _tmp18_;
	GtkGestureLongPress* _tmp19_;
	GtkEventController* _tmp20_;
	GtkGestureClick* _tmp21_;
	GtkGestureLongPress* _tmp22_;
	GtkGestureLongPress* _tmp23_;
	GtkGestureClick* _tmp24_;
	GtkGestureLongPress* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gchar** _tmp29_;
	gchar* _tmp30_;
	gchar** _tmp31_;
	GtkButton* _tmp32_ = NULL;
	GtkButton* _tmp33_;
	gulong _tmp34_;
	gchar* _tmp35_;
	gchar** _tmp36_;
	GtkOverlay* _tmp37_ = NULL;
	GtkOverlay* _tmp38_;
	GtkButton* _tmp39_;
	GtkOverlay* _tmp40_;
	GtkButton* _tmp41_;
	GtkOverlay* _tmp42_;
	parent_class = G_OBJECT_CLASS (tuba_widgets_attachment_item_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItem);
	g_object_set ((GtkWidget*) self, "height-request", 164, NULL);
	_tmp0_ = g_simple_action_group_new ();
	_g_object_unref0 (self->priv->actions);
	self->priv->actions = _tmp0_;
	_tmp1_ = self->priv->actions;
	g_action_map_add_action_entries ((GActionMap*) _tmp1_, TUBA_WIDGETS_ATTACHMENT_ITEM_ACTION_ENTRIES, (gint) G_N_ELEMENTS (TUBA_WIDGETS_ATTACHMENT_ITEM_ACTION_ENTRIES), self);
	_tmp2_ = g_simple_action_new ("copy-media", NULL);
	_g_object_unref0 (self->copy_media_simple_action);
	self->copy_media_simple_action = _tmp2_;
	_tmp3_ = self->copy_media_simple_action;
	g_signal_connect_object (_tmp3_, "activate", (GCallback) _tuba_widgets_attachment_item_copy_media_g_simple_action_activate, self, 0);
	_tmp4_ = self->priv->actions;
	_tmp5_ = self->copy_media_simple_action;
	g_action_map_add_action ((GActionMap*) _tmp4_, (GAction*) _tmp5_);
	_tmp6_ = self->priv->actions;
	gtk_widget_insert_action_group ((GtkWidget*) self, "attachment", (GActionGroup*) _tmp6_);
	g_signal_connect_object ((GObject*) self, "notify::entity", (GCallback) _tuba_widgets_attachment_item_on_rebind_g_object_notify, self, 0);
	gtk_widget_add_css_class ((GtkWidget*) self, "flat");
	_tmp7_ = g_strdup ("frame");
	_tmp8_ = g_strdup ("no-padding");
	_tmp9_ = g_strdup ("attachment-picture");
	_tmp10_ = g_new0 (gchar*, 3 + 1);
	_tmp10_[0] = _tmp7_;
	_tmp10_[1] = _tmp8_;
	_tmp10_[2] = _tmp9_;
	_tmp11_ = (GtkButton*) gtk_button_new ();
	gtk_widget_set_css_classes ((GtkWidget*) _tmp11_, _tmp10_);
	_tmp10_ = (_vala_array_free (_tmp10_, 3, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_overflow ((GtkWidget*) _tmp11_, GTK_OVERFLOW_HIDDEN);
	g_object_ref_sink (_tmp11_);
	_g_object_unref0 (self->button);
	self->button = _tmp11_;
	_tmp12_ = self->button;
	g_signal_connect_object (_tmp12_, "clicked", (GCallback) _tuba_widgets_attachment_item_on_click_gtk_button_clicked, self, 0);
	tuba_widgets_attachment_item_create_context_menu (self);
	_tmp13_ = (GtkGestureClick*) gtk_gesture_click_new ();
	_tmp14_ = _tmp13_;
	tuba_widgets_attachment_item_set_gesture_click_controller (self, _tmp14_);
	_g_object_unref0 (_tmp14_);
	_tmp15_ = (GtkGestureLongPress*) gtk_gesture_long_press_new ();
	_tmp16_ = _tmp15_;
	tuba_widgets_attachment_item_set_gesture_lp_controller (self, _tmp16_);
	_g_object_unref0 (_tmp16_);
	_tmp17_ = self->priv->_gesture_click_controller;
	_tmp18_ = _g_object_ref0 ((GtkEventController*) _tmp17_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp18_);
	_tmp19_ = self->priv->_gesture_lp_controller;
	_tmp20_ = _g_object_ref0 ((GtkEventController*) _tmp19_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp20_);
	_tmp21_ = self->priv->_gesture_click_controller;
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp21_, (guint) GDK_BUTTON_SECONDARY);
	_tmp22_ = self->priv->_gesture_lp_controller;
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp22_, (guint) GDK_BUTTON_PRIMARY);
	_tmp23_ = self->priv->_gesture_lp_controller;
	gtk_gesture_single_set_touch_only ((GtkGestureSingle*) _tmp23_, TRUE);
	_tmp24_ = self->priv->_gesture_click_controller;
	g_signal_connect_object (_tmp24_, "pressed", (GCallback) _tuba_widgets_attachment_item_on_secondary_click_gtk_gesture_click_pressed, self, 0);
	_tmp25_ = self->priv->_gesture_lp_controller;
	g_signal_connect_object (_tmp25_, "pressed", (GCallback) _tuba_widgets_attachment_item_on_long_press_gtk_gesture_long_press_pressed, self, 0);
	_tmp26_ = g_strdup (_ ("View Alt Text"));
	_tmp27_ = g_strdup ("heading");
	_tmp28_ = g_strdup ("flat");
	_tmp29_ = g_new0 (gchar*, 2 + 1);
	_tmp29_[0] = _tmp27_;
	_tmp29_[1] = _tmp28_;
	_tmp30_ = g_strdup ("ttl-status-badge");
	_tmp31_ = g_new0 (gchar*, 1 + 1);
	_tmp31_[0] = _tmp30_;
	_tmp32_ = (GtkButton*) gtk_button_new_with_label ("ALT");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp32_, _tmp26_);
	_g_free0 (_tmp26_);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp32_, _tmp29_);
	_tmp29_ = (_vala_array_free (_tmp29_, 2, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_valign ((GtkWidget*) _tmp32_, GTK_ALIGN_END);
	gtk_widget_set_halign ((GtkWidget*) _tmp32_, GTK_ALIGN_START);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp32_, _tmp31_);
	_tmp31_ = (_vala_array_free (_tmp31_, 1, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp32_);
	_g_object_unref0 (self->alt_btn);
	self->alt_btn = _tmp32_;
	_tmp33_ = self->alt_btn;
	_tmp34_ = g_signal_connect_object (_tmp33_, "clicked", (GCallback) _tuba_widgets_attachment_item_on_alt_text_btn_clicked_gtk_button_clicked, self, 0);
	self->alt_btn_clicked_id = _tmp34_;
	_tmp35_ = g_strdup ("attachment");
	_tmp36_ = g_new0 (gchar*, 1 + 1);
	_tmp36_[0] = _tmp35_;
	_tmp37_ = (GtkOverlay*) gtk_overlay_new ();
	gtk_widget_set_css_classes ((GtkWidget*) _tmp37_, _tmp36_);
	_tmp36_ = (_vala_array_free (_tmp36_, 1, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp37_);
	_g_object_unref0 (self->overlay);
	self->overlay = _tmp37_;
	_tmp38_ = self->overlay;
	_tmp39_ = self->button;
	gtk_overlay_set_child (_tmp38_, (GtkWidget*) _tmp39_);
	_tmp40_ = self->overlay;
	_tmp41_ = self->alt_btn;
	gtk_overlay_add_overlay (_tmp40_, (GtkWidget*) _tmp41_);
	_tmp42_ = self->overlay;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp42_);
	return obj;
}

static void
tuba_widgets_attachment_item_class_init (TubaWidgetsAttachmentItemClass * klass,
                                         gpointer klass_data)
{
	tuba_widgets_attachment_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &TubaWidgetsAttachmentItem_private_offset);
	((TubaWidgetsAttachmentItemClass *) klass)->copy_media = (void (*) (TubaWidgetsAttachmentItem*)) tuba_widgets_attachment_item_real_copy_media;
	((TubaWidgetsAttachmentItemClass *) klass)->on_rebind = (void (*) (TubaWidgetsAttachmentItem*)) tuba_widgets_attachment_item_real_on_rebind;
	((TubaWidgetsAttachmentItemClass *) klass)->on_click = (void (*) (TubaWidgetsAttachmentItem*)) tuba_widgets_attachment_item_real_on_click;
	((TubaWidgetsAttachmentItemClass *) klass)->on_secondary_click = (void (*) (TubaWidgetsAttachmentItem*, gint, gdouble, gdouble)) tuba_widgets_attachment_item_real_on_secondary_click;
	G_OBJECT_CLASS (klass)->get_property = _vala_tuba_widgets_attachment_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_tuba_widgets_attachment_item_set_property;
	G_OBJECT_CLASS (klass)->constructor = tuba_widgets_attachment_item_constructor;
	G_OBJECT_CLASS (klass)->finalize = tuba_widgets_attachment_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_WIDGETS_ATTACHMENT_ITEM_ENTITY_PROPERTY, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_ENTITY_PROPERTY] = g_param_spec_object ("entity", "entity", "entity", TUBA_API_TYPE_ATTACHMENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_CLICK_CONTROLLER_PROPERTY, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_CLICK_CONTROLLER_PROPERTY] = g_param_spec_object ("gesture-click-controller", "gesture-click-controller", "gesture-click-controller", gtk_gesture_click_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_LP_CONTROLLER_PROPERTY, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_LP_CONTROLLER_PROPERTY] = g_param_spec_object ("gesture-lp-controller", "gesture-lp-controller", "gesture-lp-controller", gtk_gesture_long_press_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_WIDGETS_ATTACHMENT_ITEM_CONTEXT_MENU_PROPERTY, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_CONTEXT_MENU_PROPERTY] = g_param_spec_object ("context-menu", "context-menu", "context-menu", gtk_popover_menu_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TUBA_WIDGETS_ATTACHMENT_ITEM_MEDIA_KIND_PROPERTY, tuba_widgets_attachment_item_properties[TUBA_WIDGETS_ATTACHMENT_ITEM_MEDIA_KIND_PROPERTY] = g_param_spec_enum ("media-kind", "media-kind", "media-kind", TUBA_ATTACHMENT_TYPE_MEDIA_TYPE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
tuba_widgets_attachment_item_instance_init (TubaWidgetsAttachmentItem * self,
                                            gpointer klass)
{
	self->priv = tuba_widgets_attachment_item_get_instance_private (self);
	self->priv->_entity = NULL;
}

static void
tuba_widgets_attachment_item_finalize (GObject * obj)
{
	TubaWidgetsAttachmentItem * self;
	GtkPopoverMenu* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItem);
	g_debug ("Item.vala:141: Destroying Attachment.Item widget");
	_tmp0_ = self->priv->_context_menu;
	gtk_widget_unparent ((GtkWidget*) _tmp0_);
	_g_object_unref0 (self->priv->_entity);
	_g_object_unref0 (self->priv->_gesture_click_controller);
	_g_object_unref0 (self->priv->_gesture_lp_controller);
	_g_object_unref0 (self->priv->_context_menu);
	_g_object_unref0 (self->priv->actions);
	_g_object_unref0 (self->overlay);
	_g_object_unref0 (self->button);
	_g_object_unref0 (self->alt_btn);
	_g_object_unref0 (self->copy_media_simple_action);
	G_OBJECT_CLASS (tuba_widgets_attachment_item_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
tuba_widgets_attachment_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TubaWidgetsAttachmentItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tuba_widgets_attachment_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TubaWidgetsAttachmentItem), 0, (GInstanceInitFunc) tuba_widgets_attachment_item_instance_init, NULL };
	GType tuba_widgets_attachment_item_type_id;
	tuba_widgets_attachment_item_type_id = g_type_register_static (adw_bin_get_type (), "TubaWidgetsAttachmentItem", &g_define_type_info, G_TYPE_FLAG_NONE);
	TubaWidgetsAttachmentItem_private_offset = g_type_add_instance_private (tuba_widgets_attachment_item_type_id, sizeof (TubaWidgetsAttachmentItemPrivate));
	return tuba_widgets_attachment_item_type_id;
}

GType
tuba_widgets_attachment_item_get_type (void)
{
	static GType tuba_widgets_attachment_item_type_id__once = 0;
	if (g_once_init_enter_pointer (&tuba_widgets_attachment_item_type_id__once)) {
		GType tuba_widgets_attachment_item_type_id;
		tuba_widgets_attachment_item_type_id = tuba_widgets_attachment_item_get_type_once ();
		g_once_init_leave_pointer (&tuba_widgets_attachment_item_type_id__once, tuba_widgets_attachment_item_type_id);
	}
	return tuba_widgets_attachment_item_type_id__once;
}

static void
_vala_tuba_widgets_attachment_item_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec)
{
	TubaWidgetsAttachmentItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItem);
	switch (property_id) {
		case TUBA_WIDGETS_ATTACHMENT_ITEM_ENTITY_PROPERTY:
		g_value_set_object (value, tuba_widgets_attachment_item_get_entity (self));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_CLICK_CONTROLLER_PROPERTY:
		g_value_set_object (value, tuba_widgets_attachment_item_get_gesture_click_controller (self));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_LP_CONTROLLER_PROPERTY:
		g_value_set_object (value, tuba_widgets_attachment_item_get_gesture_lp_controller (self));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_CONTEXT_MENU_PROPERTY:
		g_value_set_object (value, tuba_widgets_attachment_item_get_context_menu (self));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_MEDIA_KIND_PROPERTY:
		g_value_set_enum (value, tuba_widgets_attachment_item_get_media_kind (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_tuba_widgets_attachment_item_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec)
{
	TubaWidgetsAttachmentItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TUBA_WIDGETS_ATTACHMENT_TYPE_ITEM, TubaWidgetsAttachmentItem);
	switch (property_id) {
		case TUBA_WIDGETS_ATTACHMENT_ITEM_ENTITY_PROPERTY:
		tuba_widgets_attachment_item_set_entity (self, g_value_get_object (value));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_CLICK_CONTROLLER_PROPERTY:
		tuba_widgets_attachment_item_set_gesture_click_controller (self, g_value_get_object (value));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_GESTURE_LP_CONTROLLER_PROPERTY:
		tuba_widgets_attachment_item_set_gesture_lp_controller (self, g_value_get_object (value));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_CONTEXT_MENU_PROPERTY:
		tuba_widgets_attachment_item_set_context_menu (self, g_value_get_object (value));
		break;
		case TUBA_WIDGETS_ATTACHMENT_ITEM_MEDIA_KIND_PROPERTY:
		tuba_widgets_attachment_item_set_media_kind (self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize 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,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

