/* snapshot-row.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from snapshot-row.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include "gnome-games.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GAMES_TYPE_SNAPSHOT_ROW (games_snapshot_row_get_type ())
#define GAMES_SNAPSHOT_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SNAPSHOT_ROW, GamesSnapshotRow))
#define GAMES_SNAPSHOT_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SNAPSHOT_ROW, GamesSnapshotRowClass))
#define GAMES_IS_SNAPSHOT_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SNAPSHOT_ROW))
#define GAMES_IS_SNAPSHOT_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SNAPSHOT_ROW))
#define GAMES_SNAPSHOT_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SNAPSHOT_ROW, GamesSnapshotRowClass))

typedef struct _GamesSnapshotRow GamesSnapshotRow;
typedef struct _GamesSnapshotRowClass GamesSnapshotRowClass;
typedef struct _GamesSnapshotRowPrivate GamesSnapshotRowPrivate;

#define GAMES_TYPE_SNAPSHOT_THUMBNAIL (games_snapshot_thumbnail_get_type ())
#define GAMES_SNAPSHOT_THUMBNAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SNAPSHOT_THUMBNAIL, GamesSnapshotThumbnail))
#define GAMES_SNAPSHOT_THUMBNAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SNAPSHOT_THUMBNAIL, GamesSnapshotThumbnailClass))
#define GAMES_IS_SNAPSHOT_THUMBNAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SNAPSHOT_THUMBNAIL))
#define GAMES_IS_SNAPSHOT_THUMBNAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SNAPSHOT_THUMBNAIL))
#define GAMES_SNAPSHOT_THUMBNAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SNAPSHOT_THUMBNAIL, GamesSnapshotThumbnailClass))

typedef struct _GamesSnapshotThumbnail GamesSnapshotThumbnail;
typedef struct _GamesSnapshotThumbnailClass GamesSnapshotThumbnailClass;
enum  {
	GAMES_SNAPSHOT_ROW_0_PROPERTY,
	GAMES_SNAPSHOT_ROW_SNAPSHOT_PROPERTY,
	GAMES_SNAPSHOT_ROW_NUM_PROPERTIES
};
static GParamSpec* games_snapshot_row_properties[GAMES_SNAPSHOT_ROW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_time_zone_unref0(var) ((var == NULL) ? NULL : (var = (g_time_zone_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesSnapshotRow {
	GtkListBoxRow parent_instance;
	GamesSnapshotRowPrivate * priv;
};

struct _GamesSnapshotRowClass {
	GtkListBoxRowClass parent_class;
};

struct _GamesSnapshotRowPrivate {
	GamesSnapshotThumbnail* thumbnail;
	GtkLabel* name_label;
	GtkLabel* date_label;
	GtkRevealer* revealer;
	GamesSnapshot* _snapshot;
};

static gint GamesSnapshotRow_private_offset;
static gpointer games_snapshot_row_parent_class = NULL;

VALA_EXTERN GType games_snapshot_row_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_snapshot_thumbnail_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesSnapshotRow* games_snapshot_row_new (GamesSnapshot* snapshot);
VALA_EXTERN GamesSnapshotRow* games_snapshot_row_construct (GType object_type,
                                                GamesSnapshot* snapshot);
VALA_EXTERN void games_snapshot_row_set_name (GamesSnapshotRow* self,
                                  const gchar* name);
VALA_EXTERN GamesSnapshot* games_snapshot_row_get_snapshot (GamesSnapshotRow* self);
VALA_EXTERN void games_snapshot_row_reveal (GamesSnapshotRow* self);
VALA_EXTERN void games_snapshot_row_remove_animated (GamesSnapshotRow* self);
static void __lambda57_ (GamesSnapshotRow* self);
static void ___lambda57__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static gchar* games_snapshot_row_get_date_format (GamesSnapshotRow* self,
                                           GDateTime* date);
VALA_EXTERN void games_snapshot_row_set_snapshot (GamesSnapshotRow* self,
                                      GamesSnapshot* value);
VALA_EXTERN void games_snapshot_thumbnail_set_snapshot (GamesSnapshotThumbnail* self,
                                            GamesSnapshot* value);
static void games_snapshot_row_finalize (GObject * obj);
static GType games_snapshot_row_get_type_once (void);
static void _vala_games_snapshot_row_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_games_snapshot_row_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_snapshot_row_get_instance_private (GamesSnapshotRow* self)
{
	return G_STRUCT_MEMBER_P (self, GamesSnapshotRow_private_offset);
}

GamesSnapshotRow*
games_snapshot_row_construct (GType object_type,
                              GamesSnapshot* snapshot)
{
	GamesSnapshotRow * self = NULL;
	g_return_val_if_fail (snapshot != NULL, NULL);
	self = (GamesSnapshotRow*) g_object_new (object_type, "snapshot", snapshot, NULL);
	return self;
}

GamesSnapshotRow*
games_snapshot_row_new (GamesSnapshot* snapshot)
{
	return games_snapshot_row_construct (GAMES_TYPE_SNAPSHOT_ROW, snapshot);
}

void
games_snapshot_row_set_name (GamesSnapshotRow* self,
                             const gchar* name)
{
	GtkLabel* _tmp0_;
	GamesSnapshot* _tmp1_;
	GamesSnapshot* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = self->priv->name_label;
	gtk_label_set_label (_tmp0_, name);
	_tmp1_ = games_snapshot_row_get_snapshot (self);
	_tmp2_ = _tmp1_;
	games_snapshot_set_name (_tmp2_, name);
	{
		GamesSnapshot* _tmp3_;
		GamesSnapshot* _tmp4_;
		_tmp3_ = games_snapshot_row_get_snapshot (self);
		_tmp4_ = _tmp3_;
		games_snapshot_write_metadata (_tmp4_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_critical ("snapshot-row.vala:45: Couldn't update snapshot name: %s", _tmp6_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

void
games_snapshot_row_reveal (GamesSnapshotRow* self)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->revealer;
	gtk_revealer_set_reveal_child (_tmp0_, TRUE);
}

static void
__lambda57_ (GamesSnapshotRow* self)
{
	GtkContainer* _tmp0_;
	_tmp0_ = gtk_widget_get_parent ((GtkWidget*) self);
	gtk_container_remove (_tmp0_, (GtkWidget*) self);
}

static void
___lambda57__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda57_ ((GamesSnapshotRow*) self);
}

void
games_snapshot_row_remove_animated (GamesSnapshotRow* self)
{
	GtkRevealer* _tmp0_;
	GtkRevealer* _tmp1_;
	g_return_if_fail (self != NULL);
	gtk_list_box_row_set_selectable ((GtkListBoxRow*) self, FALSE);
	_tmp0_ = self->priv->revealer;
	g_signal_connect_object ((GObject*) _tmp0_, "notify::child-revealed", (GCallback) ___lambda57__g_object_notify, self, 0);
	_tmp1_ = self->priv->revealer;
	gtk_revealer_set_reveal_child (_tmp1_, FALSE);
}

static gchar*
games_snapshot_row_get_date_format (GamesSnapshotRow* self,
                                    GDateTime* date)
{
	GDateTime* date_midnight = NULL;
	GDateTime* _tmp0_;
	GDateTime* now = NULL;
	GTimeZone* _tmp1_;
	GTimeZone* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* today_midnight = NULL;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	GTimeSpan days_ago = 0LL;
	GDateTime* _tmp9_;
	GDateTime* _tmp10_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = g_date_time_new_local (g_date_time_get_year (date), g_date_time_get_month (date), g_date_time_get_day_of_month (date), 0, 0, (gdouble) 0);
	date_midnight = _tmp0_;
	_tmp1_ = g_time_zone_new_local ();
	_tmp2_ = _tmp1_;
	_tmp3_ = g_date_time_new_now (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_time_zone_unref0 (_tmp2_);
	now = _tmp4_;
	_tmp5_ = now;
	_tmp6_ = now;
	_tmp7_ = now;
	_tmp8_ = g_date_time_new_local (g_date_time_get_year (_tmp5_), g_date_time_get_month (_tmp6_), g_date_time_get_day_of_month (_tmp7_), 0, 0, (gdouble) 0);
	today_midnight = _tmp8_;
	_tmp9_ = today_midnight;
	_tmp10_ = date_midnight;
	days_ago = g_date_time_difference (_tmp9_, _tmp10_) / G_TIME_SPAN_DAY;
	if (days_ago == ((GTimeSpan) 0)) {
		gchar* _tmp11_;
		_tmp11_ = g_strdup (_ ("%X"));
		result = _tmp11_;
		_g_date_time_unref0 (today_midnight);
		_g_date_time_unref0 (now);
		_g_date_time_unref0 (date_midnight);
		return result;
	} else {
		if (days_ago == ((GTimeSpan) 1)) {
			gchar* _tmp12_;
			_tmp12_ = g_strdup (_ ("Yesterday %X"));
			result = _tmp12_;
			_g_date_time_unref0 (today_midnight);
			_g_date_time_unref0 (now);
			_g_date_time_unref0 (date_midnight);
			return result;
		} else {
			gboolean _tmp13_ = FALSE;
			if (days_ago > ((GTimeSpan) 1)) {
				_tmp13_ = days_ago < ((GTimeSpan) 7);
			} else {
				_tmp13_ = FALSE;
			}
			if (_tmp13_) {
				gchar* _tmp14_;
				_tmp14_ = g_strdup (_ ("%a %X"));
				result = _tmp14_;
				_g_date_time_unref0 (today_midnight);
				_g_date_time_unref0 (now);
				_g_date_time_unref0 (date_midnight);
				return result;
			} else {
				GDateTime* _tmp15_;
				_tmp15_ = now;
				if (g_date_time_get_year (date) == g_date_time_get_year (_tmp15_)) {
					gchar* _tmp16_;
					_tmp16_ = g_strdup (_ ("%-e %b %X"));
					result = _tmp16_;
					_g_date_time_unref0 (today_midnight);
					_g_date_time_unref0 (now);
					_g_date_time_unref0 (date_midnight);
					return result;
				} else {
					gchar* _tmp17_;
					_tmp17_ = g_strdup (_ ("%-e %b %Y %X"));
					result = _tmp17_;
					_g_date_time_unref0 (today_midnight);
					_g_date_time_unref0 (now);
					_g_date_time_unref0 (date_midnight);
					return result;
				}
			}
		}
	}
}

GamesSnapshot*
games_snapshot_row_get_snapshot (GamesSnapshotRow* self)
{
	GamesSnapshot* result;
	GamesSnapshot* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_snapshot;
	result = _tmp0_;
	return result;
}

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

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

void
games_snapshot_row_set_snapshot (GamesSnapshotRow* self,
                                 GamesSnapshot* value)
{
	GamesSnapshot* _tmp0_;
	GamesSnapshot* _tmp1_;
	GamesSnapshot* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	GDateTime* creation_date = NULL;
	GamesSnapshot* _tmp11_;
	GamesSnapshot* _tmp12_;
	GDateTime* _tmp13_;
	GDateTime* _tmp14_;
	GDateTime* _tmp15_;
	gchar* date_format = NULL;
	gchar* _tmp16_;
	GtkLabel* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	GamesSnapshotThumbnail* _tmp20_;
	GamesSnapshot* _tmp21_;
	GamesSnapshot* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_snapshot);
	self->priv->_snapshot = _tmp0_;
	_tmp1_ = games_snapshot_row_get_snapshot (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = games_snapshot_get_is_automatic (_tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_) {
		GtkLabel* _tmp5_;
		_tmp5_ = self->priv->name_label;
		gtk_label_set_label (_tmp5_, _ ("Autosave"));
	} else {
		GtkLabel* _tmp6_;
		GamesSnapshot* _tmp7_;
		GamesSnapshot* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		_tmp6_ = self->priv->name_label;
		_tmp7_ = games_snapshot_row_get_snapshot (self);
		_tmp8_ = _tmp7_;
		_tmp9_ = games_snapshot_get_name (_tmp8_);
		_tmp10_ = _tmp9_;
		gtk_label_set_label (_tmp6_, _tmp10_);
	}
	_tmp11_ = games_snapshot_row_get_snapshot (self);
	_tmp12_ = _tmp11_;
	_tmp13_ = games_snapshot_get_creation_date (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _g_date_time_ref0 (_tmp14_);
	creation_date = _tmp15_;
	_tmp16_ = games_snapshot_row_get_date_format (self, creation_date);
	date_format = _tmp16_;
	_tmp17_ = self->priv->date_label;
	_tmp18_ = g_date_time_format (creation_date, date_format);
	_tmp19_ = _tmp18_;
	gtk_label_set_label (_tmp17_, _tmp19_);
	_g_free0 (_tmp19_);
	_tmp20_ = self->priv->thumbnail;
	_tmp21_ = games_snapshot_row_get_snapshot (self);
	_tmp22_ = _tmp21_;
	games_snapshot_thumbnail_set_snapshot (_tmp20_, _tmp22_);
	_g_free0 (date_format);
	_g_date_time_unref0 (creation_date);
	g_object_notify_by_pspec ((GObject *) self, games_snapshot_row_properties[GAMES_SNAPSHOT_ROW_SNAPSHOT_PROPERTY]);
}

static void
games_snapshot_row_class_init (GamesSnapshotRowClass * klass,
                               gpointer klass_data)
{
	games_snapshot_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesSnapshotRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_games_snapshot_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_snapshot_row_set_property;
	G_OBJECT_CLASS (klass)->finalize = games_snapshot_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_SNAPSHOT_ROW_SNAPSHOT_PROPERTY, games_snapshot_row_properties[GAMES_SNAPSHOT_ROW_SNAPSHOT_PROPERTY] = g_param_spec_object ("snapshot", "snapshot", "snapshot", GAMES_TYPE_SNAPSHOT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/ui/snapshot-row.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "thumbnail", FALSE, GamesSnapshotRow_private_offset + G_STRUCT_OFFSET (GamesSnapshotRowPrivate, thumbnail));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "name_label", FALSE, GamesSnapshotRow_private_offset + G_STRUCT_OFFSET (GamesSnapshotRowPrivate, name_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "date_label", FALSE, GamesSnapshotRow_private_offset + G_STRUCT_OFFSET (GamesSnapshotRowPrivate, date_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "revealer", FALSE, GamesSnapshotRow_private_offset + G_STRUCT_OFFSET (GamesSnapshotRowPrivate, revealer));
}

static void
games_snapshot_row_instance_init (GamesSnapshotRow * self,
                                  gpointer klass)
{
	self->priv = games_snapshot_row_get_instance_private (self);
	g_type_ensure (GAMES_TYPE_SNAPSHOT_THUMBNAIL);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
games_snapshot_row_finalize (GObject * obj)
{
	GamesSnapshotRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_SNAPSHOT_ROW, GamesSnapshotRow);
	_g_object_unref0 (self->priv->_snapshot);
	G_OBJECT_CLASS (games_snapshot_row_parent_class)->finalize (obj);
}

static GType
games_snapshot_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesSnapshotRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_snapshot_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesSnapshotRow), 0, (GInstanceInitFunc) games_snapshot_row_instance_init, NULL };
	GType games_snapshot_row_type_id;
	games_snapshot_row_type_id = g_type_register_static (gtk_list_box_row_get_type (), "GamesSnapshotRow", &g_define_type_info, 0);
	GamesSnapshotRow_private_offset = g_type_add_instance_private (games_snapshot_row_type_id, sizeof (GamesSnapshotRowPrivate));
	return games_snapshot_row_type_id;
}

GType
games_snapshot_row_get_type (void)
{
	static volatile gsize games_snapshot_row_type_id__once = 0;
	if (g_once_init_enter (&games_snapshot_row_type_id__once)) {
		GType games_snapshot_row_type_id;
		games_snapshot_row_type_id = games_snapshot_row_get_type_once ();
		g_once_init_leave (&games_snapshot_row_type_id__once, games_snapshot_row_type_id);
	}
	return games_snapshot_row_type_id__once;
}

static void
_vala_games_snapshot_row_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	GamesSnapshotRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_SNAPSHOT_ROW, GamesSnapshotRow);
	switch (property_id) {
		case GAMES_SNAPSHOT_ROW_SNAPSHOT_PROPERTY:
		g_value_set_object (value, games_snapshot_row_get_snapshot (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_games_snapshot_row_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	GamesSnapshotRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_SNAPSHOT_ROW, GamesSnapshotRow);
	switch (property_id) {
		case GAMES_SNAPSHOT_ROW_SNAPSHOT_PROPERTY:
		games_snapshot_row_set_snapshot (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

