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

/*
* Copyright (c) 2011-2016 Felipe Escoto (https://github.com/Philip-Scott/Notes-up)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authored by: Felipe Escoto <felescoto95@hotmail.com>
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <float.h>
#include <math.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 ENOTES_TYPE_PAGE_ITEM (enotes_page_item_get_type ())
#define ENOTES_PAGE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PAGE_ITEM, ENotesPageItem))
#define ENOTES_PAGE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PAGE_ITEM, ENotesPageItemClass))
#define ENOTES_IS_PAGE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PAGE_ITEM))
#define ENOTES_IS_PAGE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PAGE_ITEM))
#define ENOTES_PAGE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PAGE_ITEM, ENotesPageItemClass))

typedef struct _ENotesPageItem ENotesPageItem;
typedef struct _ENotesPageItemClass ENotesPageItemClass;
typedef struct _ENotesPageItemPrivate ENotesPageItemPrivate;

#define ENOTES_TYPE_PAGE (enotes_page_get_type ())
#define ENOTES_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PAGE, ENotesPage))
#define ENOTES_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PAGE, ENotesPageClass))
#define ENOTES_IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PAGE))
#define ENOTES_IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PAGE))
#define ENOTES_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PAGE, ENotesPageClass))

typedef struct _ENotesPage ENotesPage;
typedef struct _ENotesPageClass ENotesPageClass;
enum  {
	ENOTES_PAGE_ITEM_0_PROPERTY,
	ENOTES_PAGE_ITEM_PAGE_PROPERTY,
	ENOTES_PAGE_ITEM_NUM_PROPERTIES
};
static GParamSpec* enotes_page_item_properties[ENOTES_PAGE_ITEM_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define ENOTES_TYPE_TRASH (enotes_trash_get_type ())
#define ENOTES_TRASH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_TRASH, ENotesTrash))
#define ENOTES_TRASH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_TRASH, ENotesTrashClass))
#define ENOTES_IS_TRASH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_TRASH))
#define ENOTES_IS_TRASH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_TRASH))
#define ENOTES_TRASH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_TRASH, ENotesTrashClass))

typedef struct _ENotesTrash ENotesTrash;
typedef struct _ENotesTrashClass ENotesTrashClass;
typedef struct _ENotesPagePrivate ENotesPagePrivate;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ENotesPageItem {
	GtkListBoxRow parent_instance;
	ENotesPageItemPrivate * priv;
};

struct _ENotesPageItemClass {
	GtkListBoxRowClass parent_class;
};

struct _ENotesPageItemPrivate {
	ENotesPage* _page;
	GtkGrid* grid;
	GtkLabel* title_label;
	GtkLabel* preview_label;
};

struct _ENotesPage {
	GObject parent_instance;
	ENotesPagePrivate * priv;
	gint64 id;
	gint64 notebook_id;
	gchar* name;
	gchar* data;
	gchar* subtitle;
	gchar* html_cache;
	gint64 creation_date;
	gint64 modification_date;
	gboolean new_page;
	gboolean cache_changed;
	gchar* full_path;
};

struct _ENotesPageClass {
	GObjectClass parent_class;
};

static gint ENotesPageItem_private_offset;
static gpointer enotes_page_item_parent_class = NULL;
static ENotesTrash* enotes_page_item_trash_instance;
static ENotesTrash* enotes_page_item_trash_instance = NULL;

VALA_EXTERN GType enotes_page_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPageItem, g_object_unref)
VALA_EXTERN GType enotes_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPage, g_object_unref)
VALA_EXTERN GType enotes_trash_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesTrash, g_object_unref)
VALA_EXTERN ENotesPageItem* enotes_page_item_new (ENotesPage* page);
VALA_EXTERN ENotesPageItem* enotes_page_item_construct (GType object_type,
                                            ENotesPage* page);
VALA_EXTERN void enotes_page_item_load_data (ENotesPageItem* self);
VALA_EXTERN ENotesPage* enotes_page_item_get_page (ENotesPageItem* self);
VALA_EXTERN gboolean enotes_trash_is_page_trashed (ENotesTrash* self,
                                       ENotesPage* to_check);
VALA_EXTERN void enotes_page_item_set_page (ENotesPageItem* self,
                                ENotesPage* value);
static GObject * enotes_page_item_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
VALA_EXTERN ENotesTrash* enotes_trash_get_instance (void);
static void enotes_page_item_finalize (GObject * obj);
static GType enotes_page_item_get_type_once (void);
static void _vala_enotes_page_item_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_enotes_page_item_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
enotes_page_item_get_instance_private (ENotesPageItem* self)
{
	return G_STRUCT_MEMBER_P (self, ENotesPageItem_private_offset);
}

ENotesPageItem*
enotes_page_item_construct (GType object_type,
                            ENotesPage* page)
{
	ENotesPageItem * self = NULL;
	g_return_val_if_fail (page != NULL, NULL);
	self = (ENotesPageItem*) g_object_new (object_type, "page", page, NULL);
	return self;
}

ENotesPageItem*
enotes_page_item_new (ENotesPage* page)
{
	return enotes_page_item_construct (ENOTES_TYPE_PAGE_ITEM, page);
}

void
enotes_page_item_load_data (ENotesPageItem* self)
{
	GtkLabel* _tmp0_;
	ENotesPage* _tmp1_;
	const gchar* _tmp2_;
	GtkLabel* _tmp3_;
	ENotesPage* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GtkLabel* _tmp10_;
	ENotesTrash* _tmp11_;
	ENotesPage* _tmp12_;
	GtkLabel* _tmp13_;
	GtkLabel* _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->preview_label;
	_tmp1_ = self->priv->_page;
	_tmp2_ = _tmp1_->subtitle;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_tmp3_ = self->priv->title_label;
	_tmp4_ = self->priv->_page;
	_tmp5_ = _tmp4_->name;
	_tmp6_ = g_strconcat ("<b>", _tmp5_, NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strconcat (_tmp7_, "</b>", NULL);
	_tmp9_ = _tmp8_;
	gtk_label_set_label (_tmp3_, _tmp9_);
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
	_tmp10_ = self->priv->title_label;
	_tmp11_ = enotes_page_item_trash_instance;
	_tmp12_ = self->priv->_page;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp10_, !enotes_trash_is_page_trashed (_tmp11_, _tmp12_));
	_tmp13_ = self->priv->preview_label;
	_tmp14_ = self->priv->title_label;
	_tmp15_ = gtk_widget_get_sensitive ((GtkWidget*) _tmp14_);
	_tmp16_ = _tmp15_;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp13_, _tmp16_);
}

ENotesPage*
enotes_page_item_get_page (ENotesPageItem* self)
{
	ENotesPage* result;
	ENotesPage* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_page;
	result = _tmp0_;
	return result;
}

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

void
enotes_page_item_set_page (ENotesPageItem* self,
                           ENotesPage* value)
{
	ENotesPage* old_value;
	g_return_if_fail (self != NULL);
	old_value = enotes_page_item_get_page (self);
	if (old_value != value) {
		ENotesPage* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_page);
		self->priv->_page = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, enotes_page_item_properties[ENOTES_PAGE_ITEM_PAGE_PROPERTY]);
	}
}

static GObject *
enotes_page_item_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ENotesPageItem * self;
	GtkGrid* _tmp0_;
	GtkGrid* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_;
	GtkLabel* _tmp5_;
	GtkStyleContext* _tmp6_;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	GtkLabel* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* _tmp11_;
	GtkLabel* _tmp12_;
	GtkLabel* _tmp13_;
	GtkLabel* _tmp14_;
	GtkLabel* _tmp15_;
	GtkLabel* _tmp16_;
	GtkLabel* _tmp17_;
	GtkLabel* _tmp18_;
	GtkLabel* _tmp19_;
	GtkLabel* _tmp20_;
	GtkLabel* _tmp21_;
	GtkLabel* _tmp22_;
	GtkLabel* _tmp23_;
	GtkSeparator* separator = NULL;
	GtkSeparator* _tmp24_;
	GtkSeparator* _tmp25_;
	GtkGrid* _tmp26_;
	GtkGrid* _tmp27_;
	GtkLabel* _tmp28_;
	GtkGrid* _tmp29_;
	GtkLabel* _tmp30_;
	GtkGrid* _tmp31_;
	GtkSeparator* _tmp32_;
	parent_class = G_OBJECT_CLASS (enotes_page_item_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_PAGE_ITEM, ENotesPageItem);
	gtk_list_box_row_set_activatable ((GtkListBoxRow*) self, TRUE);
	_tmp0_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->grid);
	self->priv->grid = _tmp0_;
	_tmp1_ = self->priv->grid;
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp1_, GTK_ORIENTATION_VERTICAL);
	_tmp2_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->title_label);
	self->priv->title_label = _tmp2_;
	_tmp3_ = self->priv->title_label;
	gtk_label_set_use_markup (_tmp3_, TRUE);
	_tmp4_ = self->priv->title_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp4_, GTK_ALIGN_START);
	_tmp5_ = self->priv->title_label;
	_tmp6_ = gtk_widget_get_style_context ((GtkWidget*) _tmp5_);
	gtk_style_context_add_class (_tmp6_, "h3");
	_tmp7_ = self->priv->title_label;
	gtk_label_set_ellipsize (_tmp7_, PANGO_ELLIPSIZE_END);
	_tmp8_ = self->priv->title_label;
	g_object_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, gtk_misc_get_type (), GtkMisc), "xalign", (gfloat) 0, NULL);
	_tmp9_ = self->priv->title_label;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp9_, 9);
	_tmp10_ = self->priv->title_label;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp10_, 10);
	_tmp11_ = self->priv->title_label;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp11_, 10);
	_tmp12_ = self->priv->title_label;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp12_, 9);
	_tmp13_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp13_);
	_g_object_unref0 (self->priv->preview_label);
	self->priv->preview_label = _tmp13_;
	_tmp14_ = self->priv->preview_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp14_, GTK_ALIGN_START);
	_tmp15_ = self->priv->preview_label;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp15_, 0);
	_tmp16_ = self->priv->preview_label;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp16_, 10);
	_tmp17_ = self->priv->preview_label;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp17_, 10);
	_tmp18_ = self->priv->preview_label;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp18_, 9);
	_tmp19_ = self->priv->preview_label;
	gtk_label_set_use_markup (_tmp19_, TRUE);
	_tmp20_ = self->priv->preview_label;
	gtk_label_set_line_wrap (_tmp20_, TRUE);
	_tmp21_ = self->priv->preview_label;
	gtk_label_set_ellipsize (_tmp21_, PANGO_ELLIPSIZE_END);
	_tmp22_ = self->priv->preview_label;
	g_object_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp22_, gtk_misc_get_type (), GtkMisc), "xalign", (gfloat) 0, NULL);
	_tmp23_ = self->priv->preview_label;
	gtk_label_set_lines (_tmp23_, 3);
	_tmp24_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp24_);
	separator = _tmp24_;
	_tmp25_ = separator;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp25_, TRUE);
	_tmp26_ = self->priv->grid;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp26_);
	_tmp27_ = self->priv->grid;
	_tmp28_ = self->priv->title_label;
	gtk_container_add ((GtkContainer*) _tmp27_, (GtkWidget*) _tmp28_);
	_tmp29_ = self->priv->grid;
	_tmp30_ = self->priv->preview_label;
	gtk_container_add ((GtkContainer*) _tmp29_, (GtkWidget*) _tmp30_);
	_tmp31_ = self->priv->grid;
	_tmp32_ = separator;
	gtk_container_add ((GtkContainer*) _tmp31_, (GtkWidget*) _tmp32_);
	enotes_page_item_load_data (self);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (separator);
	return obj;
}

static void
enotes_page_item_class_init (ENotesPageItemClass * klass,
                             gpointer klass_data)
{
	ENotesTrash* _tmp0_;
	enotes_page_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ENotesPageItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_enotes_page_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_enotes_page_item_set_property;
	G_OBJECT_CLASS (klass)->constructor = enotes_page_item_constructor;
	G_OBJECT_CLASS (klass)->finalize = enotes_page_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), ENOTES_PAGE_ITEM_PAGE_PROPERTY, enotes_page_item_properties[ENOTES_PAGE_ITEM_PAGE_PROPERTY] = g_param_spec_object ("page", "page", "page", ENOTES_TYPE_PAGE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	_tmp0_ = enotes_trash_get_instance ();
	_g_object_unref0 (enotes_page_item_trash_instance);
	enotes_page_item_trash_instance = _tmp0_;
}

static void
enotes_page_item_instance_init (ENotesPageItem * self,
                                gpointer klass)
{
	self->priv = enotes_page_item_get_instance_private (self);
}

static void
enotes_page_item_finalize (GObject * obj)
{
	ENotesPageItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_PAGE_ITEM, ENotesPageItem);
	_g_object_unref0 (self->priv->_page);
	_g_object_unref0 (self->priv->grid);
	_g_object_unref0 (self->priv->title_label);
	_g_object_unref0 (self->priv->preview_label);
	G_OBJECT_CLASS (enotes_page_item_parent_class)->finalize (obj);
}

static GType
enotes_page_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesPageItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_page_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesPageItem), 0, (GInstanceInitFunc) enotes_page_item_instance_init, NULL };
	GType enotes_page_item_type_id;
	enotes_page_item_type_id = g_type_register_static (gtk_list_box_row_get_type (), "ENotesPageItem", &g_define_type_info, 0);
	ENotesPageItem_private_offset = g_type_add_instance_private (enotes_page_item_type_id, sizeof (ENotesPageItemPrivate));
	return enotes_page_item_type_id;
}

GType
enotes_page_item_get_type (void)
{
	static volatile gsize enotes_page_item_type_id__once = 0;
	if (g_once_init_enter (&enotes_page_item_type_id__once)) {
		GType enotes_page_item_type_id;
		enotes_page_item_type_id = enotes_page_item_get_type_once ();
		g_once_init_leave (&enotes_page_item_type_id__once, enotes_page_item_type_id);
	}
	return enotes_page_item_type_id__once;
}

static void
_vala_enotes_page_item_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	ENotesPageItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, ENOTES_TYPE_PAGE_ITEM, ENotesPageItem);
	switch (property_id) {
		case ENOTES_PAGE_ITEM_PAGE_PROPERTY:
		g_value_set_object (value, enotes_page_item_get_page (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_enotes_page_item_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	ENotesPageItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, ENOTES_TYPE_PAGE_ITEM, ENotesPageItem);
	switch (property_id) {
		case ENOTES_PAGE_ITEM_PAGE_PROPERTY:
		enotes_page_item_set_page (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;
}

