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

#include <gtk/gtk.h>
#include <glib-object.h>
#include "libdino.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include "dino_i18n.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DINO_UI_TYPE_FILE_DEFAULT_WIDGET (dino_ui_file_default_widget_get_type ())
#define DINO_UI_FILE_DEFAULT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_UI_TYPE_FILE_DEFAULT_WIDGET, DinoUiFileDefaultWidget))
#define DINO_UI_FILE_DEFAULT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_UI_TYPE_FILE_DEFAULT_WIDGET, DinoUiFileDefaultWidgetClass))
#define DINO_UI_IS_FILE_DEFAULT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_UI_TYPE_FILE_DEFAULT_WIDGET))
#define DINO_UI_IS_FILE_DEFAULT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_UI_TYPE_FILE_DEFAULT_WIDGET))
#define DINO_UI_FILE_DEFAULT_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_UI_TYPE_FILE_DEFAULT_WIDGET, DinoUiFileDefaultWidgetClass))

typedef struct _DinoUiFileDefaultWidget DinoUiFileDefaultWidget;
typedef struct _DinoUiFileDefaultWidgetClass DinoUiFileDefaultWidgetClass;
typedef struct _DinoUiFileDefaultWidgetPrivate DinoUiFileDefaultWidgetPrivate;
enum  {
	DINO_UI_FILE_DEFAULT_WIDGET_0_PROPERTY,
	DINO_UI_FILE_DEFAULT_WIDGET_NUM_PROPERTIES
};
static GParamSpec* dino_ui_file_default_widget_properties[DINO_UI_FILE_DEFAULT_WIDGET_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	DINO_UI_FILE_DEFAULT_WIDGET_CLICKED_SIGNAL,
	DINO_UI_FILE_DEFAULT_WIDGET_NUM_SIGNALS
};
static guint dino_ui_file_default_widget_signals[DINO_UI_FILE_DEFAULT_WIDGET_NUM_SIGNALS] = {0};

struct _DinoUiFileDefaultWidget {
	GtkBox parent_instance;
	DinoUiFileDefaultWidgetPrivate * priv;
	GtkStack* image_stack;
	GtkLabel* name_label;
	GtkLabel* mime_label;
	GtkImage* content_type_image;
	GtkSpinner* spinner;
	GtkMenuButton* file_menu;
};

struct _DinoUiFileDefaultWidgetClass {
	GtkBoxClass parent_class;
};

struct _DinoUiFileDefaultWidgetPrivate {
	DinoEntitiesFileTransferState state;
};

static gint DinoUiFileDefaultWidget_private_offset;
static gpointer dino_ui_file_default_widget_parent_class = NULL;

VALA_EXTERN GType dino_ui_file_default_widget_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DinoUiFileDefaultWidget, g_object_unref)
VALA_EXTERN void dino_ui_file_default_widget_init_updating_file_info (DinoUiFileDefaultWidget* self);
static void dino_ui_file_default_widget_on_pointer_entered_event (DinoUiFileDefaultWidget* self);
static void _dino_ui_file_default_widget_on_pointer_entered_event_gtk_event_controller_motion_enter (GtkEventControllerMotion* _sender,
                                                                                              gdouble x,
                                                                                              gdouble y,
                                                                                              gpointer self);
static void dino_ui_file_default_widget_on_pointer_left_event (DinoUiFileDefaultWidget* self);
static void _dino_ui_file_default_widget_on_pointer_left_event_gtk_event_controller_motion_leave (GtkEventControllerMotion* _sender,
                                                                                           gpointer self);
static void __lambda38_ (DinoUiFileDefaultWidget* self,
                  gint n_press,
                  gdouble x,
                  gdouble y);
static void ___lambda38__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                             gint n_press,
                                             gdouble x,
                                             gdouble y,
                                             gpointer self);
VALA_EXTERN void dino_ui_file_default_widget_set_static_file_info (DinoUiFileDefaultWidget* self,
                                                       const gchar* mime_type);
static gchar* dino_ui_file_default_widget_get_file_icon_name (const gchar* mime_type);
VALA_EXTERN void dino_ui_file_default_widget_update_file_info (DinoUiFileDefaultWidget* self,
                                                   const gchar* mime_type,
                                                   DinoEntitiesFileTransferState state,
                                                   gboolean direction,
                                                   gint64 size,
                                                   gint64 transferred_bytes);
static void dino_ui_file_default_widget_on_pointer_left (DinoUiFileDefaultWidget* self);
static void _dino_ui_file_default_widget_on_pointer_left_gtk_popover_closed (GtkPopover* _sender,
                                                                      gpointer self);
VALA_EXTERN gchar* dino_ui_file_default_widget_get_size_string (gint64 size);
VALA_EXTERN DinoUiFileDefaultWidget* dino_ui_file_default_widget_new (void);
VALA_EXTERN DinoUiFileDefaultWidget* dino_ui_file_default_widget_construct (GType object_type);
static void dino_ui_file_default_widget_finalize (GObject * obj);
static GType dino_ui_file_default_widget_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_ui_file_default_widget_get_instance_private (DinoUiFileDefaultWidget* self)
{
	return G_STRUCT_MEMBER_P (self, DinoUiFileDefaultWidget_private_offset);
}

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

static void
_dino_ui_file_default_widget_on_pointer_entered_event_gtk_event_controller_motion_enter (GtkEventControllerMotion* _sender,
                                                                                         gdouble x,
                                                                                         gdouble y,
                                                                                         gpointer self)
{
	dino_ui_file_default_widget_on_pointer_entered_event ((DinoUiFileDefaultWidget*) self);
}

static void
_dino_ui_file_default_widget_on_pointer_left_event_gtk_event_controller_motion_leave (GtkEventControllerMotion* _sender,
                                                                                      gpointer self)
{
	dino_ui_file_default_widget_on_pointer_left_event ((DinoUiFileDefaultWidget*) self);
}

static void
__lambda38_ (DinoUiFileDefaultWidget* self,
             gint n_press,
             gdouble x,
             gdouble y)
{
	gdouble x_button = 0.0;
	gdouble y_button = 0.0;
	GtkMenuButton* _tmp0_;
	gdouble _tmp1_ = 0.0;
	gdouble _tmp2_ = 0.0;
	GtkMenuButton* _tmp3_;
	_tmp0_ = self->file_menu;
	gtk_widget_translate_coordinates ((GtkWidget*) self, (GtkWidget*) _tmp0_, x, y, &_tmp1_, &_tmp2_);
	x_button = _tmp1_;
	y_button = _tmp2_;
	_tmp3_ = self->file_menu;
	if (gtk_widget_contains ((GtkWidget*) _tmp3_, x_button, y_button)) {
		return;
	}
	g_signal_emit (self, dino_ui_file_default_widget_signals[DINO_UI_FILE_DEFAULT_WIDGET_CLICKED_SIGNAL], 0);
}

static void
___lambda38__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                        gint n_press,
                                        gdouble x,
                                        gdouble y,
                                        gpointer self)
{
	__lambda38_ ((DinoUiFileDefaultWidget*) self, n_press, x, y);
}

void
dino_ui_file_default_widget_init_updating_file_info (DinoUiFileDefaultWidget* self)
{
	GtkEventControllerMotion* this_motion_events = NULL;
	GtkEventControllerMotion* _tmp0_;
	GtkEventController* _tmp1_;
	GtkGestureClick* gesture_click_controller = NULL;
	GtkGestureClick* _tmp2_;
	GtkEventController* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = (GtkEventControllerMotion*) gtk_event_controller_motion_new ();
	this_motion_events = _tmp0_;
	_tmp1_ = _g_object_ref0 ((GtkEventController*) this_motion_events);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp1_);
	g_signal_connect_object (this_motion_events, "enter", (GCallback) _dino_ui_file_default_widget_on_pointer_entered_event_gtk_event_controller_motion_enter, self, 0);
	g_signal_connect_object (this_motion_events, "leave", (GCallback) _dino_ui_file_default_widget_on_pointer_left_event_gtk_event_controller_motion_leave, self, 0);
	_tmp2_ = (GtkGestureClick*) gtk_gesture_click_new ();
	gesture_click_controller = _tmp2_;
	gtk_gesture_single_set_button ((GtkGestureSingle*) gesture_click_controller, (guint) 1);
	_tmp3_ = _g_object_ref0 ((GtkEventController*) gesture_click_controller);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp3_);
	g_signal_connect_object (gesture_click_controller, "pressed", (GCallback) ___lambda38__gtk_gesture_click_pressed, self, 0);
	_g_object_unref0 (gesture_click_controller);
	_g_object_unref0 (this_motion_events);
}

void
dino_ui_file_default_widget_set_static_file_info (DinoUiFileDefaultWidget* self,
                                                  const gchar* mime_type)
{
	GtkSpinner* _tmp0_;
	GtkStack* _tmp1_;
	GtkImage* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_ = NULL;
	GtkLabel* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->spinner;
	gtk_spinner_stop (_tmp0_);
	_tmp1_ = self->image_stack;
	gtk_stack_set_visible_child_name (_tmp1_, "content_type_image");
	_tmp2_ = self->content_type_image;
	_tmp3_ = dino_ui_file_default_widget_get_file_icon_name (mime_type);
	_tmp4_ = _tmp3_;
	g_object_set (_tmp2_, "icon-name", _tmp4_, NULL);
	_g_free0 (_tmp4_);
	if (mime_type != NULL) {
		gchar* _tmp6_;
		_tmp6_ = g_content_type_get_description (mime_type);
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp6_;
	} else {
		_g_free0 (_tmp5_);
		_tmp5_ = NULL;
	}
	_tmp7_ = self->mime_label;
	gtk_label_set_label (_tmp7_, _tmp5_);
	_g_free0 (_tmp5_);
}

static void
_dino_ui_file_default_widget_on_pointer_left_gtk_popover_closed (GtkPopover* _sender,
                                                                 gpointer self)
{
	dino_ui_file_default_widget_on_pointer_left ((DinoUiFileDefaultWidget*) self);
}

void
dino_ui_file_default_widget_update_file_info (DinoUiFileDefaultWidget* self,
                                              const gchar* mime_type,
                                              DinoEntitiesFileTransferState state,
                                              gboolean direction,
                                              gint64 size,
                                              gint64 transferred_bytes)
{
	GtkSpinner* _tmp0_;
	GtkImage* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_ = NULL;
	gchar* mime_description = NULL;
	gchar* _tmp6_;
	g_return_if_fail (self != NULL);
	self->priv->state = state;
	_tmp0_ = self->spinner;
	gtk_spinner_stop (_tmp0_);
	_tmp1_ = self->content_type_image;
	_tmp2_ = dino_ui_file_default_widget_get_file_icon_name (mime_type);
	_tmp3_ = _tmp2_;
	g_object_set (_tmp1_, "icon-name", _tmp3_, NULL);
	_g_free0 (_tmp3_);
	if (mime_type != NULL) {
		gchar* _tmp5_;
		_tmp5_ = g_content_type_get_description (mime_type);
		_g_free0 (_tmp4_);
		_tmp4_ = _tmp5_;
	} else {
		_g_free0 (_tmp4_);
		_tmp4_ = NULL;
	}
	_tmp6_ = _tmp4_;
	_tmp4_ = NULL;
	mime_description = _tmp6_;
	switch (state) {
		case DINO_ENTITIES_FILE_TRANSFER_STATE_COMPLETE:
		{
			GtkLabel* _tmp7_;
			const gchar* _tmp8_;
			GtkStack* _tmp9_;
			GMenu* menu_model = NULL;
			GMenu* _tmp10_;
			GMenu* _tmp11_;
			const gchar* _tmp12_;
			GMenu* _tmp13_;
			const gchar* _tmp14_;
			GtkPopoverMenu* popover_menu = NULL;
			GMenu* _tmp15_;
			GtkPopoverMenu* _tmp16_;
			GtkMenuButton* _tmp17_;
			GtkPopoverMenu* _tmp18_;
			GtkPopoverMenu* _tmp19_;
			_tmp7_ = self->mime_label;
			_tmp8_ = mime_description;
			gtk_label_set_label (_tmp7_, _tmp8_);
			_tmp9_ = self->image_stack;
			gtk_stack_set_visible_child_name (_tmp9_, "content_type_image");
			_tmp10_ = g_menu_new ();
			menu_model = _tmp10_;
			_tmp11_ = menu_model;
			_tmp12_ = dino_gettext ("Open");
			g_menu_append (_tmp11_, _tmp12_, "file.open");
			_tmp13_ = menu_model;
			_tmp14_ = dino_gettext ("Save as…");
			g_menu_append (_tmp13_, _tmp14_, "file.save_as");
			_tmp15_ = menu_model;
			_tmp16_ = (GtkPopoverMenu*) gtk_popover_menu_new_from_model ((GMenuModel*) _tmp15_);
			g_object_ref_sink (_tmp16_);
			popover_menu = _tmp16_;
			_tmp17_ = self->file_menu;
			_tmp18_ = popover_menu;
			gtk_menu_button_set_popover (_tmp17_, (GtkPopover*) _tmp18_);
			_tmp19_ = popover_menu;
			g_signal_connect_object ((GtkPopover*) _tmp19_, "closed", (GCallback) _dino_ui_file_default_widget_on_pointer_left_gtk_popover_closed, self, 0);
			_g_object_unref0 (popover_menu);
			_g_object_unref0 (menu_model);
			break;
		}
		case DINO_ENTITIES_FILE_TRANSFER_STATE_IN_PROGRESS:
		{
			GtkSpinner* _tmp38_;
			GtkStack* _tmp39_;
			GMenu* menu_model = NULL;
			GMenu* _tmp40_;
			GMenu* _tmp41_;
			const gchar* _tmp42_;
			GtkPopoverMenu* popover_menu = NULL;
			GMenu* _tmp43_;
			GtkPopoverMenu* _tmp44_;
			GtkMenuButton* _tmp45_;
			GtkPopoverMenu* _tmp46_;
			GtkPopoverMenu* _tmp47_;
			if (direction == DINO_ENTITIES_FILE_TRANSFER_DIRECTION_RECEIVED) {
				if (size > ((gint64) 0)) {
					gint64 progress = 0LL;
					GtkLabel* _tmp20_;
					const gchar* _tmp21_;
					gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					progress = (transferred_bytes * 100) / size;
					_tmp20_ = self->mime_label;
					_tmp21_ = dino_gettext ("Downloading %s… (%u%%)");
					_tmp22_ = dino_ui_file_default_widget_get_size_string (size);
					_tmp23_ = _tmp22_;
					_tmp24_ = g_strdup_printf (_tmp21_, _tmp23_, progress);
					_tmp25_ = _tmp24_;
					gtk_label_set_label (_tmp20_, _tmp25_);
					_g_free0 (_tmp25_);
					_g_free0 (_tmp23_);
				} else {
					GtkLabel* _tmp26_;
					const gchar* _tmp27_;
					gchar* _tmp28_;
					gchar* _tmp29_;
					gchar* _tmp30_;
					gchar* _tmp31_;
					_tmp26_ = self->mime_label;
					_tmp27_ = dino_gettext ("Downloading %s…");
					_tmp28_ = dino_ui_file_default_widget_get_size_string (size);
					_tmp29_ = _tmp28_;
					_tmp30_ = g_strdup_printf (_tmp27_, _tmp29_);
					_tmp31_ = _tmp30_;
					gtk_label_set_label (_tmp26_, _tmp31_);
					_g_free0 (_tmp31_);
					_g_free0 (_tmp29_);
				}
			} else {
				gint64 progress = 0LL;
				GtkLabel* _tmp32_;
				const gchar* _tmp33_;
				gchar* _tmp34_;
				gchar* _tmp35_;
				gchar* _tmp36_;
				gchar* _tmp37_;
				progress = (transferred_bytes * 100) / size;
				_tmp32_ = self->mime_label;
				_tmp33_ = dino_gettext ("Uploading %s… (%u%%)");
				_tmp34_ = dino_ui_file_default_widget_get_size_string (size);
				_tmp35_ = _tmp34_;
				_tmp36_ = g_strdup_printf (_tmp33_, _tmp35_, progress);
				_tmp37_ = _tmp36_;
				gtk_label_set_label (_tmp32_, _tmp37_);
				_g_free0 (_tmp37_);
				_g_free0 (_tmp35_);
			}
			_tmp38_ = self->spinner;
			gtk_spinner_start (_tmp38_);
			_tmp39_ = self->image_stack;
			gtk_stack_set_visible_child_name (_tmp39_, "spinner");
			_tmp40_ = g_menu_new ();
			menu_model = _tmp40_;
			_tmp41_ = menu_model;
			_tmp42_ = dino_gettext ("Cancel");
			g_menu_append (_tmp41_, _tmp42_, "file.cancel_download");
			_tmp43_ = menu_model;
			_tmp44_ = (GtkPopoverMenu*) gtk_popover_menu_new_from_model ((GMenuModel*) _tmp43_);
			g_object_ref_sink (_tmp44_);
			popover_menu = _tmp44_;
			_tmp45_ = self->file_menu;
			_tmp46_ = popover_menu;
			gtk_menu_button_set_popover (_tmp45_, (GtkPopover*) _tmp46_);
			_tmp47_ = popover_menu;
			g_signal_connect_object ((GtkPopover*) _tmp47_, "closed", (GCallback) _dino_ui_file_default_widget_on_pointer_left_gtk_popover_closed, self, 0);
			_g_object_unref0 (popover_menu);
			_g_object_unref0 (menu_model);
			break;
		}
		case DINO_ENTITIES_FILE_TRANSFER_STATE_NOT_STARTED:
		{
			const gchar* _tmp48_;
			GtkStack* _tmp64_;
			_tmp48_ = mime_description;
			if (_tmp48_ != NULL) {
				GtkLabel* _tmp49_;
				const gchar* _tmp50_;
				const gchar* _tmp51_;
				gchar* _tmp52_;
				gchar* _tmp53_;
				gchar* _tmp54_;
				gchar* _tmp55_;
				_tmp49_ = self->mime_label;
				_tmp50_ = dino_gettext ("%s offered: %s");
				_tmp51_ = mime_description;
				_tmp52_ = dino_ui_file_default_widget_get_size_string (size);
				_tmp53_ = _tmp52_;
				_tmp54_ = g_strdup_printf (_tmp50_, _tmp51_, _tmp53_);
				_tmp55_ = _tmp54_;
				gtk_label_set_label (_tmp49_, _tmp55_);
				_g_free0 (_tmp55_);
				_g_free0 (_tmp53_);
			} else {
				if (size != ((gint64) -1)) {
					GtkLabel* _tmp56_;
					const gchar* _tmp57_;
					gchar* _tmp58_;
					gchar* _tmp59_;
					gchar* _tmp60_;
					gchar* _tmp61_;
					_tmp56_ = self->mime_label;
					_tmp57_ = dino_gettext ("File offered: %s");
					_tmp58_ = dino_ui_file_default_widget_get_size_string (size);
					_tmp59_ = _tmp58_;
					_tmp60_ = g_strdup_printf (_tmp57_, _tmp59_);
					_tmp61_ = _tmp60_;
					gtk_label_set_label (_tmp56_, _tmp61_);
					_g_free0 (_tmp61_);
					_g_free0 (_tmp59_);
				} else {
					GtkLabel* _tmp62_;
					const gchar* _tmp63_;
					_tmp62_ = self->mime_label;
					_tmp63_ = dino_gettext ("File offered");
					gtk_label_set_label (_tmp62_, _tmp63_);
				}
			}
			_tmp64_ = self->image_stack;
			gtk_stack_set_visible_child_name (_tmp64_, "content_type_image");
			break;
		}
		case DINO_ENTITIES_FILE_TRANSFER_STATE_FAILED:
		{
			GtkLabel* _tmp65_;
			GtkLabel* _tmp66_;
			const gchar* _tmp67_;
			gchar* _tmp68_;
			gchar* _tmp69_;
			gchar* _tmp70_;
			gchar* _tmp71_;
			GtkStack* _tmp72_;
			_tmp65_ = self->mime_label;
			gtk_label_set_use_markup (_tmp65_, TRUE);
			_tmp66_ = self->mime_label;
			_tmp67_ = dino_gettext ("File transfer failed");
			_tmp68_ = g_strconcat ("<span foreground=\"#f44336\">", _tmp67_, NULL);
			_tmp69_ = _tmp68_;
			_tmp70_ = g_strconcat (_tmp69_, "</span>", NULL);
			_tmp71_ = _tmp70_;
			gtk_label_set_label (_tmp66_, _tmp71_);
			_g_free0 (_tmp71_);
			_g_free0 (_tmp69_);
			_tmp72_ = self->image_stack;
			gtk_stack_set_visible_child_name (_tmp72_, "content_type_image");
			break;
		}
		default:
		break;
	}
	_g_free0 (mime_description);
	_g_free0 (_tmp4_);
}

static void
dino_ui_file_default_widget_on_pointer_entered_event (DinoUiFileDefaultWidget* self)
{
	GtkImage* _tmp0_;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	gtk_widget_set_cursor_from_name ((GtkWidget*) self, "pointer");
	_tmp0_ = self->content_type_image;
	gtk_widget_set_opacity ((GtkWidget*) _tmp0_, 0.7);
	if (self->priv->state == DINO_ENTITIES_FILE_TRANSFER_STATE_NOT_STARTED) {
		GtkStack* _tmp1_;
		_tmp1_ = self->image_stack;
		gtk_stack_set_visible_child_name (_tmp1_, "download_image");
	}
	if (self->priv->state == DINO_ENTITIES_FILE_TRANSFER_STATE_COMPLETE) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = self->priv->state == DINO_ENTITIES_FILE_TRANSFER_STATE_IN_PROGRESS;
	}
	if (_tmp2_) {
		GtkMenuButton* _tmp3_;
		_tmp3_ = self->file_menu;
		gtk_widget_set_opacity ((GtkWidget*) _tmp3_, (gdouble) 1);
	}
}

static void
dino_ui_file_default_widget_on_pointer_left_event (DinoUiFileDefaultWidget* self)
{
	gboolean _tmp0_ = FALSE;
	GtkMenuButton* _tmp1_;
	GtkPopover* _tmp2_;
	GtkPopover* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->file_menu;
	_tmp2_ = gtk_menu_button_get_popover (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ != NULL) {
		GtkMenuButton* _tmp4_;
		GtkPopover* _tmp5_;
		GtkPopover* _tmp6_;
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp4_ = self->file_menu;
		_tmp5_ = gtk_menu_button_get_popover (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = gtk_widget_get_visible ((GtkWidget*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp0_ = _tmp8_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	gtk_widget_set_cursor ((GtkWidget*) self, NULL);
	dino_ui_file_default_widget_on_pointer_left (self);
}

static void
dino_ui_file_default_widget_on_pointer_left (DinoUiFileDefaultWidget* self)
{
	GtkImage* _tmp0_;
	GtkMenuButton* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->content_type_image;
	gtk_widget_set_opacity ((GtkWidget*) _tmp0_, 0.5);
	if (self->priv->state == DINO_ENTITIES_FILE_TRANSFER_STATE_NOT_STARTED) {
		GtkStack* _tmp1_;
		_tmp1_ = self->image_stack;
		gtk_stack_set_visible_child_name (_tmp1_, "content_type_image");
	}
	_tmp2_ = self->file_menu;
	gtk_widget_set_opacity ((GtkWidget*) _tmp2_, (gdouble) 0);
}

static gchar*
dino_ui_file_default_widget_get_file_icon_name (const gchar* mime_type)
{
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* generic_icon_name = NULL;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	GQuark _tmp8_ = 0U;
	static GQuark _tmp7_label0 = 0;
	static GQuark _tmp7_label1 = 0;
	static GQuark _tmp7_label2 = 0;
	static GQuark _tmp7_label3 = 0;
	static GQuark _tmp7_label4 = 0;
	static GQuark _tmp7_label5 = 0;
	static GQuark _tmp7_label6 = 0;
	gchar* result;
	if (mime_type == NULL) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("dino-file-symbolic");
		result = _tmp0_;
		return result;
	}
	_tmp2_ = g_content_type_get_generic_icon_name (mime_type);
	_tmp1_ = _tmp2_;
	if (_tmp1_ == NULL) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("");
		_g_free0 (_tmp1_);
		_tmp1_ = _tmp3_;
	}
	_tmp4_ = _tmp1_;
	_tmp1_ = NULL;
	generic_icon_name = _tmp4_;
	_tmp5_ = generic_icon_name;
	_tmp6_ = _tmp5_;
	_tmp8_ = (NULL == _tmp6_) ? 0 : g_quark_from_string (_tmp6_);
	if (_tmp8_ == ((0 != _tmp7_label0) ? _tmp7_label0 : (_tmp7_label0 = g_quark_from_static_string ("audio-x-generic")))) {
		switch (0) {
			default:
			{
				gchar* _tmp9_;
				_tmp9_ = g_strdup ("dino-file-music-symbolic");
				result = _tmp9_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else if (_tmp8_ == ((0 != _tmp7_label1) ? _tmp7_label1 : (_tmp7_label1 = g_quark_from_static_string ("image-x-generic")))) {
		switch (0) {
			default:
			{
				gchar* _tmp10_;
				_tmp10_ = g_strdup ("dino-file-image-symbolic");
				result = _tmp10_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else if (_tmp8_ == ((0 != _tmp7_label2) ? _tmp7_label2 : (_tmp7_label2 = g_quark_from_static_string ("text-x-generic")))) {
		switch (0) {
			default:
			{
				gchar* _tmp11_;
				_tmp11_ = g_strdup ("dino-file-document-symbolic");
				result = _tmp11_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else if (_tmp8_ == ((0 != _tmp7_label3) ? _tmp7_label3 : (_tmp7_label3 = g_quark_from_static_string ("text-x-generic-template")))) {
		switch (0) {
			default:
			{
				gchar* _tmp12_;
				_tmp12_ = g_strdup ("dino-file-document-symbolic");
				result = _tmp12_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else if (_tmp8_ == ((0 != _tmp7_label4) ? _tmp7_label4 : (_tmp7_label4 = g_quark_from_static_string ("video-x-generic")))) {
		switch (0) {
			default:
			{
				gchar* _tmp13_;
				_tmp13_ = g_strdup ("dino-file-video-symbolic");
				result = _tmp13_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else if (_tmp8_ == ((0 != _tmp7_label5) ? _tmp7_label5 : (_tmp7_label5 = g_quark_from_static_string ("x-office-document")))) {
		switch (0) {
			default:
			{
				gchar* _tmp14_;
				_tmp14_ = g_strdup ("dino-file-document-symbolic");
				result = _tmp14_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else if (_tmp8_ == ((0 != _tmp7_label6) ? _tmp7_label6 : (_tmp7_label6 = g_quark_from_static_string ("x-office-spreadsheet")))) {
		switch (0) {
			default:
			{
				gchar* _tmp15_;
				_tmp15_ = g_strdup ("dino-file-table-symbolic");
				result = _tmp15_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				gchar* _tmp16_;
				_tmp16_ = g_strdup ("dino-file-symbolic");
				result = _tmp16_;
				_g_free0 (generic_icon_name);
				_g_free0 (_tmp1_);
				return result;
			}
		}
	}
}

gchar*
dino_ui_file_default_widget_get_size_string (gint64 size)
{
	gchar* result;
	if (size < ((gint64) 1024)) {
		gchar* _tmp0_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp0_ = g_strdup_printf ("%" G_GINT64_FORMAT, size);
		_tmp1_ = _tmp0_;
		_tmp2_ = g_strconcat (_tmp1_, " B", NULL);
		_tmp3_ = _tmp2_;
		_g_free0 (_tmp1_);
		result = _tmp3_;
		return result;
	} else {
		if (size < ((gint64) (1000 * 1000))) {
			gchar* _tmp4_;
			gchar* _tmp5_;
			gchar* _tmp6_;
			gchar* _tmp7_;
			_tmp4_ = g_strdup_printf ("%" G_GINT64_FORMAT, size / 1000);
			_tmp5_ = _tmp4_;
			_tmp6_ = g_strconcat (_tmp5_, " kB", NULL);
			_tmp7_ = _tmp6_;
			_g_free0 (_tmp5_);
			result = _tmp7_;
			return result;
		} else {
			if (size < ((gint64) ((1000 * 1000) * 1000))) {
				gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				gchar* _tmp11_;
				_tmp8_ = g_strdup_printf ("%" G_GINT64_FORMAT, (size / 1000) / 1000);
				_tmp9_ = _tmp8_;
				_tmp10_ = g_strconcat (_tmp9_, " MB", NULL);
				_tmp11_ = _tmp10_;
				_g_free0 (_tmp9_);
				result = _tmp11_;
				return result;
			} else {
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				_tmp12_ = g_strdup_printf ("%" G_GINT64_FORMAT, ((size / 1000) / 1000) / 1000);
				_tmp13_ = _tmp12_;
				_tmp14_ = g_strconcat (_tmp13_, " GB", NULL);
				_tmp15_ = _tmp14_;
				_g_free0 (_tmp13_);
				result = _tmp15_;
				return result;
			}
		}
	}
}

DinoUiFileDefaultWidget*
dino_ui_file_default_widget_construct (GType object_type)
{
	DinoUiFileDefaultWidget * self = NULL;
	self = (DinoUiFileDefaultWidget*) g_object_new (object_type, NULL);
	return self;
}

DinoUiFileDefaultWidget*
dino_ui_file_default_widget_new (void)
{
	return dino_ui_file_default_widget_construct (DINO_UI_TYPE_FILE_DEFAULT_WIDGET);
}

static void
dino_ui_file_default_widget_class_init (DinoUiFileDefaultWidgetClass * klass,
                                        gpointer klass_data)
{
	dino_ui_file_default_widget_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoUiFileDefaultWidget_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_ui_file_default_widget_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/im/dino/Dino/file_default_widget.ui");
	dino_ui_file_default_widget_signals[DINO_UI_FILE_DEFAULT_WIDGET_CLICKED_SIGNAL] = g_signal_new ("clicked", DINO_UI_TYPE_FILE_DEFAULT_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "image_stack", FALSE, G_STRUCT_OFFSET (DinoUiFileDefaultWidget, image_stack));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "name_label", FALSE, G_STRUCT_OFFSET (DinoUiFileDefaultWidget, name_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "mime_label", FALSE, G_STRUCT_OFFSET (DinoUiFileDefaultWidget, mime_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "content_type_image", FALSE, G_STRUCT_OFFSET (DinoUiFileDefaultWidget, content_type_image));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "spinner", FALSE, G_STRUCT_OFFSET (DinoUiFileDefaultWidget, spinner));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "file_menu", FALSE, G_STRUCT_OFFSET (DinoUiFileDefaultWidget, file_menu));
}

static void
dino_ui_file_default_widget_instance_init (DinoUiFileDefaultWidget * self,
                                           gpointer klass)
{
	self->priv = dino_ui_file_default_widget_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
dino_ui_file_default_widget_finalize (GObject * obj)
{
	DinoUiFileDefaultWidget * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_UI_TYPE_FILE_DEFAULT_WIDGET, DinoUiFileDefaultWidget);
	G_OBJECT_CLASS (dino_ui_file_default_widget_parent_class)->finalize (obj);
}

static GType
dino_ui_file_default_widget_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoUiFileDefaultWidgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_ui_file_default_widget_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoUiFileDefaultWidget), 0, (GInstanceInitFunc) dino_ui_file_default_widget_instance_init, NULL };
	GType dino_ui_file_default_widget_type_id;
	dino_ui_file_default_widget_type_id = g_type_register_static (gtk_box_get_type (), "DinoUiFileDefaultWidget", &g_define_type_info, 0);
	DinoUiFileDefaultWidget_private_offset = g_type_add_instance_private (dino_ui_file_default_widget_type_id, sizeof (DinoUiFileDefaultWidgetPrivate));
	return dino_ui_file_default_widget_type_id;
}

GType
dino_ui_file_default_widget_get_type (void)
{
	static volatile gsize dino_ui_file_default_widget_type_id__once = 0;
	if (g_once_init_enter (&dino_ui_file_default_widget_type_id__once)) {
		GType dino_ui_file_default_widget_type_id;
		dino_ui_file_default_widget_type_id = dino_ui_file_default_widget_get_type_once ();
		g_once_init_leave (&dino_ui_file_default_widget_type_id__once, dino_ui_file_default_widget_type_id);
	}
	return dino_ui_file_default_widget_type_id__once;
}

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

