/* Page.c generated by valac 0.56.19, the Vala compiler
 * generated from Page.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 <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <sqlite3.h>
#include <stdio.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
#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 (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;
typedef struct _ENotesPagePrivate ENotesPagePrivate;
enum  {
	ENOTES_PAGE_0_PROPERTY,
	ENOTES_PAGE_NUM_PROPERTIES
};
static GParamSpec* enotes_page_properties[ENOTES_PAGE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_DATABASE_TABLE (database_table_get_type ())
#define DATABASE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DATABASE_TABLE, DatabaseTable))
#define DATABASE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DATABASE_TABLE, DatabaseTableClass))
#define IS_DATABASE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DATABASE_TABLE))
#define IS_DATABASE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DATABASE_TABLE))
#define DATABASE_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DATABASE_TABLE, DatabaseTableClass))

typedef struct _DatabaseTable DatabaseTable;
typedef struct _DatabaseTableClass DatabaseTableClass;
typedef struct _DatabaseTablePrivate DatabaseTablePrivate;

#define ENOTES_TYPE_PAGE_TABLE (enotes_page_table_get_type ())
#define ENOTES_PAGE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PAGE_TABLE, ENotesPageTable))
#define ENOTES_PAGE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PAGE_TABLE, ENotesPageTableClass))
#define ENOTES_IS_PAGE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PAGE_TABLE))
#define ENOTES_IS_PAGE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PAGE_TABLE))
#define ENOTES_PAGE_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PAGE_TABLE, ENotesPageTableClass))

typedef struct _ENotesPageTable ENotesPageTable;
typedef struct _ENotesPageTableClass ENotesPageTableClass;
typedef struct _ENotesPageTablePrivate ENotesPageTablePrivate;

#define TYPE_BL_MEMBER (bl_member_get_type ())
#define BL_MEMBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BL_MEMBER, BLMember))
#define BL_MEMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BL_MEMBER, BLMemberClass))
#define IS_BL_MEMBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BL_MEMBER))
#define IS_BL_MEMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BL_MEMBER))
#define BL_MEMBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BL_MEMBER, BLMemberClass))

typedef struct _BLMember BLMember;
typedef struct _BLMemberClass BLMemberClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _database_table_unref0(var) ((var == NULL) ? NULL : (var = (database_table_unref (var), NULL)))
#define _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))

#define ENOTES_TYPE_PLUGIN_MANAGER (enotes_plugin_manager_get_type ())
#define ENOTES_PLUGIN_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PLUGIN_MANAGER, ENotesPluginManager))
#define ENOTES_PLUGIN_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PLUGIN_MANAGER, ENotesPluginManagerClass))
#define ENOTES_IS_PLUGIN_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PLUGIN_MANAGER))
#define ENOTES_IS_PLUGIN_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PLUGIN_MANAGER))
#define ENOTES_PLUGIN_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PLUGIN_MANAGER, ENotesPluginManagerClass))

typedef struct _ENotesPluginManager ENotesPluginManager;
typedef struct _ENotesPluginManagerClass ENotesPluginManagerClass;
#define _bl_member_unref0(var) ((var == NULL) ? NULL : (var = (bl_member_unref (var), NULL)))

#define ENOTES_TYPE_IMAGE_TABLE (enotes_image_table_get_type ())
#define ENOTES_IMAGE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_IMAGE_TABLE, ENotesImageTable))
#define ENOTES_IMAGE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_IMAGE_TABLE, ENotesImageTableClass))
#define ENOTES_IS_IMAGE_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_IMAGE_TABLE))
#define ENOTES_IS_IMAGE_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_IMAGE_TABLE))
#define ENOTES_IMAGE_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_IMAGE_TABLE, ENotesImageTableClass))

typedef struct _ENotesImageTable ENotesImageTable;
typedef struct _ENotesImageTableClass ENotesImageTableClass;

#define ENOTES_TYPE_TAGS_TABLE (enotes_tags_table_get_type ())
#define ENOTES_TAGS_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_TAGS_TABLE, ENotesTagsTable))
#define ENOTES_TAGS_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_TAGS_TABLE, ENotesTagsTableClass))
#define ENOTES_IS_TAGS_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_TAGS_TABLE))
#define ENOTES_IS_TAGS_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_TAGS_TABLE))
#define ENOTES_TAGS_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_TAGS_TABLE, ENotesTagsTableClass))

typedef struct _ENotesTagsTable ENotesTagsTable;
typedef struct _ENotesTagsTableClass ENotesTagsTableClass;

#define ENOTES_TYPE_BOOKMARK_TABLE (enotes_bookmark_table_get_type ())
#define ENOTES_BOOKMARK_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_BOOKMARK_TABLE, ENotesBookmarkTable))
#define ENOTES_BOOKMARK_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_BOOKMARK_TABLE, ENotesBookmarkTableClass))
#define ENOTES_IS_BOOKMARK_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_BOOKMARK_TABLE))
#define ENOTES_IS_BOOKMARK_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_BOOKMARK_TABLE))
#define ENOTES_BOOKMARK_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_BOOKMARK_TABLE, ENotesBookmarkTableClass))

typedef struct _ENotesBookmarkTable ENotesBookmarkTable;
typedef struct _ENotesBookmarkTableClass ENotesBookmarkTableClass;
typedef struct _BLMemberPrivate BLMemberPrivate;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
enum  {
	ENOTES_PAGE_TABLE_PAGE_SAVED_SIGNAL,
	ENOTES_PAGE_TABLE_NUM_SIGNALS
};
static guint enotes_page_table_signals[ENOTES_PAGE_TABLE_NUM_SIGNALS] = {0};

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

struct _DatabaseTable {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DatabaseTablePrivate * priv;
	gchar* table_name;
};

struct _DatabaseTableClass {
	GTypeClass parent_class;
	void (*finalize) (DatabaseTable *self);
};

struct _ENotesPageTable {
	DatabaseTable parent_instance;
	ENotesPageTablePrivate * priv;
};

struct _ENotesPageTableClass {
	DatabaseTableClass parent_class;
};

struct _ENotesPageTablePrivate {
	GeeLinkedList* regex_complex_commands;
	BLMember** regex_simple_elements;
	gint regex_simple_elements_length1;
	gint _regex_simple_elements_size_;
	gboolean bold_state;
	gboolean italics_state;
};

struct _BLMember {
	GTypeInstance parent_instance;
	volatile int ref_count;
	BLMemberPrivate * priv;
	GRegex* reg;
	gchar* replace;
};

struct _BLMemberClass {
	GTypeClass parent_class;
	void (*finalize) (BLMember *self);
};

static gpointer enotes_page_parent_class = NULL;
static gint ENotesPageTable_private_offset;
static gpointer enotes_page_table_parent_class = NULL;
static ENotesPageTable* enotes_page_table_instance;
static ENotesPageTable* enotes_page_table_instance = NULL;

VALA_EXTERN GType enotes_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPage, g_object_unref)
VALA_EXTERN gboolean enotes_page_equals (ENotesPage* self,
                             ENotesPage* page);
VALA_EXTERN gchar* enotes_page_get_text (ENotesPage* self);
VALA_EXTERN ENotesPage* enotes_page_new (void);
VALA_EXTERN ENotesPage* enotes_page_construct (GType object_type);
static void enotes_page_finalize (GObject * obj);
static GType enotes_page_get_type_once (void);
VALA_EXTERN gpointer database_table_ref (gpointer instance);
VALA_EXTERN void database_table_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_database_table (const gchar* name,
                                       const gchar* nick,
                                       const gchar* blurb,
                                       GType object_type,
                                       GParamFlags flags);
VALA_EXTERN void value_set_database_table (GValue* value,
                               gpointer v_object);
VALA_EXTERN void value_take_database_table (GValue* value,
                                gpointer v_object);
VALA_EXTERN gpointer value_get_database_table (const GValue* value);
VALA_EXTERN GType database_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DatabaseTable, database_table_unref)
VALA_EXTERN GType enotes_page_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPageTable, database_table_unref)
VALA_EXTERN gpointer bl_member_ref (gpointer instance);
VALA_EXTERN void bl_member_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_bl_member (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags);
VALA_EXTERN void value_set_bl_member (GValue* value,
                          gpointer v_object);
VALA_EXTERN void value_take_bl_member (GValue* value,
                           gpointer v_object);
VALA_EXTERN gpointer value_get_bl_member (const GValue* value);
VALA_EXTERN GType bl_member_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BLMember, bl_member_unref)
VALA_EXTERN BLMember* bl_member_new (GRegex* reg,
                         const gchar* replace);
VALA_EXTERN BLMember* bl_member_construct (GType object_type,
                               GRegex* reg,
                               const gchar* replace);
VALA_EXTERN ENotesPageTable* enotes_page_table_get_instance (void);
static ENotesPageTable* enotes_page_table_new (void);
static ENotesPageTable* enotes_page_table_construct (GType object_type);
VALA_EXTERN DatabaseTable* database_table_construct (GType object_type);
VALA_EXTERN sqlite3_stmt* database_table_create_stmt (const gchar* data);
VALA_EXTERN void database_table_fatal (const gchar* op,
                           gint res);
VALA_EXTERN void database_table_set_table_name (DatabaseTable* self,
                                    const gchar* table_name);
VALA_EXTERN GType enotes_plugin_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPluginManager, g_object_unref)
VALA_EXTERN ENotesPluginManager* enotes_plugin_manager_get_instance (void);
VALA_EXTERN GeeList* enotes_plugin_manager_get_all_blacklist_members (ENotesPluginManager* self);
VALA_EXTERN ENotesPage* enotes_page_table_get_page (ENotesPageTable* self,
                                        gint64 page_id);
VALA_EXTERN void database_table_bind_int (sqlite3_stmt* stmt,
                              gint column,
                              gint64 data);
VALA_EXTERN void enotes_page_table_save_page (ENotesPageTable* self,
                                  ENotesPage* page);
static void enotes_page_table_load_page_info (ENotesPageTable* self,
                                       ENotesPage* page);
VALA_EXTERN void database_table_bind_text (sqlite3_stmt* stmt,
                               gint column,
                               const gchar* data);
VALA_EXTERN void enotes_page_table_move_to_notebook (ENotesPageTable* self,
                                         ENotesPage* page,
                                         gint64 notebook);
VALA_EXTERN void enotes_page_table_clear_cache_on (ENotesPageTable* self,
                                       gint64 id);
VALA_EXTERN ENotesPage* enotes_page_table_new_page (ENotesPageTable* self,
                                        gint64 notebook_id);
VALA_EXTERN gint64 database_table_last_insert_row (DatabaseTable* self);
VALA_EXTERN GeeArrayList* enotes_page_table_get_pages (ENotesPageTable* self,
                                           gint64 notebook_id);
VALA_EXTERN GeeArrayList* enotes_page_table_get_all_pages (ENotesPageTable* self);
VALA_EXTERN void enotes_page_table_delete_page (ENotesPageTable* self,
                                    gint64 id);
VALA_EXTERN GType enotes_image_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesImageTable, database_table_unref)
VALA_EXTERN ENotesImageTable* enotes_image_table_get_instance (void);
VALA_EXTERN void enotes_image_table_delete_all_from_page (ENotesImageTable* self,
                                              gint64 page_id);
VALA_EXTERN GType enotes_tags_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesTagsTable, database_table_unref)
VALA_EXTERN ENotesTagsTable* enotes_tags_table_get_instance (void);
VALA_EXTERN void enotes_tags_table_remove_tags_from_page (ENotesTagsTable* self,
                                              gint64 page_id);
VALA_EXTERN GType enotes_bookmark_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesBookmarkTable, database_table_unref)
VALA_EXTERN ENotesBookmarkTable* enotes_bookmark_table_get_instance (void);
VALA_EXTERN void enotes_bookmark_table_remove (ENotesBookmarkTable* self,
                                   gint64 page_id);
VALA_EXTERN gboolean enotes_page_table_is_bookmarked (ENotesPageTable* self);
static gchar* enotes_page_table_cleanup (ENotesPageTable* self,
                                  const gchar* line);
static gchar* enotes_page_table_convert (ENotesPageTable* self,
                                  const gchar* raw_content);
static gchar* enotes_page_table_replace (ENotesPageTable* self,
                                  const gchar* line_,
                                  const gchar* looking_for,
                                  const gchar* opening,
                                  const gchar* closing,
                                  gboolean* type_state);
VALA_EXTERN void enotes_page_table_reset_instance (void);
static void enotes_page_table_finalize (DatabaseTable * obj);
static GType enotes_page_table_get_type_once (void);
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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GRegex* _tmp_regex_0 = NULL;
static GRegex* _tmp_regex_1 = NULL;
static GRegex* _tmp_regex_2 = NULL;
static GRegex* _tmp_regex_3 = NULL;

gboolean
enotes_page_equals (ENotesPage* self,
                    ENotesPage* page)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (page != NULL, FALSE);
	result = self->id == page->id;
	return result;
}

gchar*
enotes_page_get_text (ENotesPage* self)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->data;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

ENotesPage*
enotes_page_construct (GType object_type)
{
	ENotesPage * self = NULL;
	self = (ENotesPage*) g_object_new (object_type, NULL);
	return self;
}

ENotesPage*
enotes_page_new (void)
{
	return enotes_page_construct (ENOTES_TYPE_PAGE);
}

static void
enotes_page_class_init (ENotesPageClass * klass,
                        gpointer klass_data)
{
	enotes_page_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = enotes_page_finalize;
}

static void
enotes_page_instance_init (ENotesPage * self,
                           gpointer klass)
{
	gchar* _tmp0_;
	self->id = (gint64) -1;
	self->notebook_id = (gint64) -1;
	self->new_page = FALSE;
	self->cache_changed = FALSE;
	_tmp0_ = g_strdup ("");
	self->full_path = _tmp0_;
}

static void
enotes_page_finalize (GObject * obj)
{
	ENotesPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_PAGE, ENotesPage);
	_g_free0 (self->name);
	_g_free0 (self->data);
	_g_free0 (self->subtitle);
	_g_free0 (self->html_cache);
	_g_free0 (self->full_path);
	G_OBJECT_CLASS (enotes_page_parent_class)->finalize (obj);
}

static GType
enotes_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesPageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesPage), 0, (GInstanceInitFunc) enotes_page_instance_init, NULL };
	GType enotes_page_type_id;
	enotes_page_type_id = g_type_register_static (G_TYPE_OBJECT, "ENotesPage", &g_define_type_info, 0);
	return enotes_page_type_id;
}

GType
enotes_page_get_type (void)
{
	static volatile gsize enotes_page_type_id__once = 0;
	if (g_once_init_enter (&enotes_page_type_id__once)) {
		GType enotes_page_type_id;
		enotes_page_type_id = enotes_page_get_type_once ();
		g_once_init_leave (&enotes_page_type_id__once, enotes_page_type_id);
	}
	return enotes_page_type_id__once;
}

static inline gpointer
enotes_page_table_get_instance_private (ENotesPageTable* self)
{
	return G_STRUCT_MEMBER_P (self, ENotesPageTable_private_offset);
}

static inline GRegex*
_thread_safe_regex_init (GRegex** re,
                         const gchar * pattern,
                         GRegexCompileFlags compile_flags)
{
	if (g_once_init_enter ((volatile gsize*) re)) {
		GRegex* val = g_regex_new (pattern, compile_flags, 0, NULL);
		g_once_init_leave ((volatile gsize*) re, (gsize) val);
	}
	return *re;
}

static gpointer
_database_table_ref0 (gpointer self)
{
	return self ? database_table_ref (self) : NULL;
}

ENotesPageTable*
enotes_page_table_get_instance (void)
{
	ENotesPageTable* _tmp0_;
	ENotesPageTable* _tmp2_;
	ENotesPageTable* _tmp3_;
	ENotesPageTable* result;
	_tmp0_ = enotes_page_table_instance;
	if (_tmp0_ == NULL) {
		ENotesPageTable* _tmp1_;
		_tmp1_ = enotes_page_table_new ();
		_database_table_unref0 (enotes_page_table_instance);
		enotes_page_table_instance = _tmp1_;
	}
	_tmp2_ = enotes_page_table_instance;
	_tmp3_ = _database_table_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

static ENotesPageTable*
enotes_page_table_construct (GType object_type)
{
	ENotesPageTable* self = NULL;
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	gint res = 0;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	sqlite3_stmt* _tmp3_;
	BLMember* link = NULL;
	BLMember* _tmp4_;
	BLMember* anchor = NULL;
	BLMember* _tmp5_;
	ENotesPluginManager* _tmp6_;
	ENotesPluginManager* _tmp7_;
	GeeList* _tmp8_;
	GeeLinkedList* _tmp9_;
	GeeLinkedList* _tmp10_;
	self = (ENotesPageTable*) database_table_construct (object_type);
	_tmp0_ = database_table_create_stmt ("CREATE TABLE IF NOT EXISTS Page (" "id INTEGER PRIMARY KEY AUTOINCREMENT, " "name TEXT NOT NULL DEFAULT '', " "data TEXT NOT NULL DEFAULT '', " "subtitle TEXT NOT NULL DEFAULT '', " "html_cache TEXT NOT NULL DEFAULT '', " "creation_date INTEGER," "modification_date INTEGER," "notebook_id INTEGER)");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	res = sqlite3_step (_tmp1_);
	if (res != SQLITE_DONE) {
		database_table_fatal ("create page table", res);
	}
	_tmp2_ = database_table_create_stmt ("CREATE INDEX IF NOT EXISTS NotebookIDIndex ON Page (notebook_id)");
	_sqlite3_finalize0 (stmt);
	stmt = _tmp2_;
	_tmp3_ = stmt;
	res = sqlite3_step (_tmp3_);
	if (res != SQLITE_DONE) {
		database_table_fatal ("create page table", res);
	}
	database_table_set_table_name ((DatabaseTable*) self, "Page");
	_tmp4_ = bl_member_new (_thread_safe_regex_init (&_tmp_regex_2, "\\[[\\p{L}\\d_\\.\\?\\/:\\=\\+&\\-'\" ]*\\]\\([\\p{L}\\d_\\.\\?\\/:\\=\\+&\\-'\"]*\\)", 0), "");
	link = _tmp4_;
	_tmp5_ = bl_member_new (_thread_safe_regex_init (&_tmp_regex_3, "\\[\\^\\d+\\]:?", 0), "");
	anchor = _tmp5_;
	_tmp6_ = enotes_plugin_manager_get_instance ();
	_tmp7_ = _tmp6_;
	_tmp8_ = enotes_plugin_manager_get_all_blacklist_members (_tmp7_);
	_g_object_unref0 (self->priv->regex_complex_commands);
	self->priv->regex_complex_commands = G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, GEE_TYPE_LINKED_LIST, GeeLinkedList);
	_g_object_unref0 (_tmp7_);
	_tmp9_ = self->priv->regex_complex_commands;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp9_, link);
	_tmp10_ = self->priv->regex_complex_commands;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, anchor);
	_bl_member_unref0 (anchor);
	_bl_member_unref0 (link);
	_sqlite3_finalize0 (stmt);
	return self;
}

static ENotesPageTable*
enotes_page_table_new (void)
{
	return enotes_page_table_construct (ENOTES_TYPE_PAGE_TABLE);
}

ENotesPage*
enotes_page_table_get_page (ENotesPageTable* self,
                            gint64 page_id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	ENotesPage* row = NULL;
	ENotesPage* _tmp3_;
	ENotesPage* _tmp4_;
	ENotesPage* _tmp5_;
	sqlite3_stmt* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	ENotesPage* _tmp9_;
	sqlite3_stmt* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	ENotesPage* _tmp13_;
	sqlite3_stmt* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	ENotesPage* _tmp17_;
	sqlite3_stmt* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	ENotesPage* _tmp21_;
	sqlite3_stmt* _tmp22_;
	ENotesPage* _tmp23_;
	sqlite3_stmt* _tmp24_;
	ENotesPage* _tmp25_;
	sqlite3_stmt* _tmp26_;
	ENotesPage* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT name, data, subtitle, html_cache, creation_date, modification_d" \
"ate, " "notebook_id " "FROM Page WHERE id = ?");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	database_table_bind_int (_tmp1_, 1, page_id);
	_tmp2_ = stmt;
	if (sqlite3_step (_tmp2_) != SQLITE_ROW) {
		result = NULL;
		_sqlite3_finalize0 (stmt);
		return result;
	}
	_tmp3_ = enotes_page_new ();
	row = _tmp3_;
	_tmp4_ = row;
	_tmp4_->id = page_id;
	_tmp5_ = row;
	_tmp6_ = stmt;
	_tmp7_ = (const gchar*) sqlite3_column_text (_tmp6_, 0);
	_tmp8_ = g_strdup (_tmp7_);
	_g_free0 (_tmp5_->name);
	_tmp5_->name = _tmp8_;
	_tmp9_ = row;
	_tmp10_ = stmt;
	_tmp11_ = (const gchar*) sqlite3_column_text (_tmp10_, 1);
	_tmp12_ = g_strdup (_tmp11_);
	_g_free0 (_tmp9_->data);
	_tmp9_->data = _tmp12_;
	_tmp13_ = row;
	_tmp14_ = stmt;
	_tmp15_ = (const gchar*) sqlite3_column_text (_tmp14_, 2);
	_tmp16_ = g_strdup (_tmp15_);
	_g_free0 (_tmp13_->subtitle);
	_tmp13_->subtitle = _tmp16_;
	_tmp17_ = row;
	_tmp18_ = stmt;
	_tmp19_ = (const gchar*) sqlite3_column_text (_tmp18_, 3);
	_tmp20_ = g_strdup (_tmp19_);
	_g_free0 (_tmp17_->html_cache);
	_tmp17_->html_cache = _tmp20_;
	_tmp21_ = row;
	_tmp22_ = stmt;
	_tmp21_->creation_date = sqlite3_column_int64 (_tmp22_, 4);
	_tmp23_ = row;
	_tmp24_ = stmt;
	_tmp23_->modification_date = sqlite3_column_int64 (_tmp24_, 5);
	_tmp25_ = row;
	_tmp26_ = stmt;
	_tmp25_->notebook_id = sqlite3_column_int64 (_tmp26_, 6);
	result = row;
	_sqlite3_finalize0 (stmt);
	return result;
}

void
enotes_page_table_save_page (ENotesPageTable* self,
                             ENotesPage* page)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (page != NULL);
	_tmp0_ = database_table_create_stmt ("UPDATE Page SET name = ?, subtitle = ?, data = ?, html_cache = ?, modi" \
"fication_date = CAST(strftime('%s', 'now') AS INT) WHERE id = ?");
	stmt = _tmp0_;
	enotes_page_table_load_page_info (self, page);
	_tmp1_ = page->name;
	database_table_bind_text (stmt, 1, _tmp1_);
	_tmp2_ = page->subtitle;
	database_table_bind_text (stmt, 2, _tmp2_);
	_tmp3_ = page->data;
	database_table_bind_text (stmt, 3, _tmp3_);
	_tmp4_ = page->html_cache;
	database_table_bind_text (stmt, 4, _tmp4_);
	database_table_bind_int (stmt, 5, page->id);
	sqlite3_step (stmt);
	g_signal_emit (self, enotes_page_table_signals[ENOTES_PAGE_TABLE_PAGE_SAVED_SIGNAL], 0, page);
	_sqlite3_finalize0 (stmt);
}

void
enotes_page_table_move_to_notebook (ENotesPageTable* self,
                                    ENotesPage* page,
                                    gint64 notebook)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (page != NULL);
	_tmp0_ = database_table_create_stmt ("UPDATE Page SET notebook_id = ?, modification_date = CAST(strftime('%s" \
"', 'now') AS INT) WHERE id = ?");
	stmt = _tmp0_;
	enotes_page_table_load_page_info (self, page);
	database_table_bind_int (stmt, 1, notebook);
	database_table_bind_int (stmt, 2, page->id);
	sqlite3_step (stmt);
	_sqlite3_finalize0 (stmt);
}

void
enotes_page_table_clear_cache_on (ENotesPageTable* self,
                                  gint64 id)
{
	sqlite3_stmt* stmt = NULL;
	FILE* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = stderr;
	fprintf (_tmp0_, "Clearing cache on: %d\n", (gint) id);
	if (id > ((gint64) 0)) {
		sqlite3_stmt* _tmp1_;
		sqlite3_stmt* _tmp2_;
		sqlite3_stmt* _tmp3_;
		sqlite3_stmt* _tmp4_;
		_tmp1_ = database_table_create_stmt ("UPDATE Page SET html_cache = ? WHERE notebook_id = ?");
		_sqlite3_finalize0 (stmt);
		stmt = _tmp1_;
		_tmp2_ = stmt;
		database_table_bind_text (_tmp2_, 1, "");
		_tmp3_ = stmt;
		database_table_bind_int (_tmp3_, 2, id);
		_tmp4_ = stmt;
		sqlite3_step (_tmp4_);
	} else {
		sqlite3_stmt* _tmp5_;
		sqlite3_stmt* _tmp6_;
		sqlite3_stmt* _tmp7_;
		_tmp5_ = database_table_create_stmt ("UPDATE Page SET html_cache = ?");
		_sqlite3_finalize0 (stmt);
		stmt = _tmp5_;
		_tmp6_ = stmt;
		database_table_bind_text (_tmp6_, 1, "");
		_tmp7_ = stmt;
		sqlite3_step (_tmp7_);
	}
	_sqlite3_finalize0 (stmt);
}

ENotesPage*
enotes_page_table_new_page (ENotesPageTable* self,
                            gint64 notebook_id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	ENotesPage* _tmp1_;
	ENotesPage* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("INSERT INTO Page (notebook_id, name, creation_date, modification_date)" \
" " "VALUES (?, ?, CAST(strftime('%s', 'now') AS INT), CAST(strftime('%s', " \
"'now') AS INT))");
	stmt = _tmp0_;
	database_table_bind_int (stmt, 1, notebook_id);
	database_table_bind_text (stmt, 2, _ ("New Page"));
	sqlite3_step (stmt);
	_tmp1_ = enotes_page_table_get_page (self, database_table_last_insert_row ((DatabaseTable*) self));
	result = _tmp1_;
	_sqlite3_finalize0 (stmt);
	return result;
}

GeeArrayList*
enotes_page_table_get_pages (ENotesPageTable* self,
                             gint64 notebook_id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	GeeArrayList* pages = NULL;
	GeeArrayList* _tmp2_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT id, name, subtitle, data FROM Page Where notebook_id = ?");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	database_table_bind_int (_tmp1_, 1, notebook_id);
	_tmp2_ = gee_array_list_new (ENOTES_TYPE_PAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	pages = _tmp2_;
	{
		gboolean _tmp3_ = FALSE;
		_tmp3_ = TRUE;
		while (TRUE) {
			gint res = 0;
			sqlite3_stmt* _tmp4_;
			ENotesPage* row = NULL;
			ENotesPage* _tmp5_;
			ENotesPage* _tmp6_;
			sqlite3_stmt* _tmp7_;
			ENotesPage* _tmp8_;
			sqlite3_stmt* _tmp9_;
			const gchar* _tmp10_;
			gchar* _tmp11_;
			ENotesPage* _tmp12_;
			sqlite3_stmt* _tmp13_;
			const gchar* _tmp14_;
			gchar* _tmp15_;
			ENotesPage* _tmp16_;
			sqlite3_stmt* _tmp17_;
			const gchar* _tmp18_;
			gchar* _tmp19_;
			GeeArrayList* _tmp20_;
			ENotesPage* _tmp21_;
			if (!_tmp3_) {
			}
			_tmp3_ = FALSE;
			_tmp4_ = stmt;
			res = sqlite3_step (_tmp4_);
			if (res == SQLITE_DONE) {
				break;
			} else {
				if (res != SQLITE_ROW) {
					database_table_fatal ("get_notebooks", res);
					break;
				}
			}
			_tmp5_ = enotes_page_new ();
			row = _tmp5_;
			_tmp6_ = row;
			_tmp7_ = stmt;
			_tmp6_->id = sqlite3_column_int64 (_tmp7_, 0);
			_tmp8_ = row;
			_tmp9_ = stmt;
			_tmp10_ = (const gchar*) sqlite3_column_text (_tmp9_, 1);
			_tmp11_ = g_strdup (_tmp10_);
			_g_free0 (_tmp8_->name);
			_tmp8_->name = _tmp11_;
			_tmp12_ = row;
			_tmp13_ = stmt;
			_tmp14_ = (const gchar*) sqlite3_column_text (_tmp13_, 2);
			_tmp15_ = g_strdup (_tmp14_);
			_g_free0 (_tmp12_->subtitle);
			_tmp12_->subtitle = _tmp15_;
			_tmp16_ = row;
			_tmp17_ = stmt;
			_tmp18_ = (const gchar*) sqlite3_column_text (_tmp17_, 3);
			_tmp19_ = g_strdup (_tmp18_);
			_g_free0 (_tmp16_->data);
			_tmp16_->data = _tmp19_;
			_tmp20_ = pages;
			_tmp21_ = row;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp20_, _tmp21_);
			_g_object_unref0 (row);
		}
	}
	result = pages;
	_sqlite3_finalize0 (stmt);
	return result;
}

GeeArrayList*
enotes_page_table_get_all_pages (ENotesPageTable* self)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	GeeArrayList* pages = NULL;
	GeeArrayList* _tmp1_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT id, name, subtitle, data FROM Page");
	stmt = _tmp0_;
	_tmp1_ = gee_array_list_new (ENOTES_TYPE_PAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	pages = _tmp1_;
	{
		gboolean _tmp2_ = FALSE;
		_tmp2_ = TRUE;
		while (TRUE) {
			gint res = 0;
			sqlite3_stmt* _tmp3_;
			ENotesPage* row = NULL;
			ENotesPage* _tmp4_;
			ENotesPage* _tmp5_;
			sqlite3_stmt* _tmp6_;
			ENotesPage* _tmp7_;
			sqlite3_stmt* _tmp8_;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			ENotesPage* _tmp11_;
			sqlite3_stmt* _tmp12_;
			const gchar* _tmp13_;
			gchar* _tmp14_;
			ENotesPage* _tmp15_;
			sqlite3_stmt* _tmp16_;
			const gchar* _tmp17_;
			gchar* _tmp18_;
			GeeArrayList* _tmp19_;
			ENotesPage* _tmp20_;
			if (!_tmp2_) {
			}
			_tmp2_ = FALSE;
			_tmp3_ = stmt;
			res = sqlite3_step (_tmp3_);
			if (res == SQLITE_DONE) {
				break;
			} else {
				if (res != SQLITE_ROW) {
					database_table_fatal ("get_notebooks", res);
					break;
				}
			}
			_tmp4_ = enotes_page_new ();
			row = _tmp4_;
			_tmp5_ = row;
			_tmp6_ = stmt;
			_tmp5_->id = sqlite3_column_int64 (_tmp6_, 0);
			_tmp7_ = row;
			_tmp8_ = stmt;
			_tmp9_ = (const gchar*) sqlite3_column_text (_tmp8_, 1);
			_tmp10_ = g_strdup (_tmp9_);
			_g_free0 (_tmp7_->name);
			_tmp7_->name = _tmp10_;
			_tmp11_ = row;
			_tmp12_ = stmt;
			_tmp13_ = (const gchar*) sqlite3_column_text (_tmp12_, 2);
			_tmp14_ = g_strdup (_tmp13_);
			_g_free0 (_tmp11_->subtitle);
			_tmp11_->subtitle = _tmp14_;
			_tmp15_ = row;
			_tmp16_ = stmt;
			_tmp17_ = (const gchar*) sqlite3_column_text (_tmp16_, 3);
			_tmp18_ = g_strdup (_tmp17_);
			_g_free0 (_tmp15_->data);
			_tmp15_->data = _tmp18_;
			_tmp19_ = pages;
			_tmp20_ = row;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp19_, _tmp20_);
			_g_object_unref0 (row);
		}
	}
	result = pages;
	_sqlite3_finalize0 (stmt);
	return result;
}

void
enotes_page_table_delete_page (ENotesPageTable* self,
                               gint64 id)
{
	ENotesImageTable* _tmp0_;
	ENotesImageTable* _tmp1_;
	ENotesTagsTable* _tmp2_;
	ENotesTagsTable* _tmp3_;
	ENotesBookmarkTable* _tmp4_;
	ENotesBookmarkTable* _tmp5_;
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = enotes_image_table_get_instance ();
	_tmp1_ = _tmp0_;
	enotes_image_table_delete_all_from_page (_tmp1_, id);
	_database_table_unref0 (_tmp1_);
	_tmp2_ = enotes_tags_table_get_instance ();
	_tmp3_ = _tmp2_;
	enotes_tags_table_remove_tags_from_page (_tmp3_, id);
	_database_table_unref0 (_tmp3_);
	_tmp4_ = enotes_bookmark_table_get_instance ();
	_tmp5_ = _tmp4_;
	enotes_bookmark_table_remove (_tmp5_, id);
	_database_table_unref0 (_tmp5_);
	_tmp6_ = database_table_create_stmt ("DELETE FROM Page WHERE id = ?");
	stmt = _tmp6_;
	database_table_bind_int (stmt, 1, id);
	sqlite3_step (stmt);
	_sqlite3_finalize0 (stmt);
}

gboolean
enotes_page_table_is_bookmarked (ENotesPageTable* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = FALSE;
	return result;
}

static void
enotes_page_table_load_page_info (ENotesPageTable* self,
                                  ENotesPage* page)
{
	gchar** lines = NULL;
	gint lines_length1 = 0;
	gint _lines_size_ = 0;
	const gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gchar* preview = NULL;
	gchar* _tmp3_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	const gchar* _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (page != NULL);
	_tmp0_ = page->data;
	_tmp2_ = _tmp1_ = g_strsplit (_tmp0_, "\n", 0);
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
	lines = _tmp2_;
	lines_length1 = _vala_array_length (_tmp1_);
	_lines_size_ = lines_length1;
	_tmp3_ = g_strdup ("");
	preview = _tmp3_;
	_tmp4_ = lines;
	_tmp4__length1 = lines_length1;
	if (_tmp4__length1 > 0) {
		const gchar* _tmp5_;
		_tmp5_ = page->name;
		if (g_strcmp0 (_tmp5_, _ ("New Page")) == 0) {
			gchar** _tmp6_;
			gint _tmp6__length1;
			const gchar* _tmp7_;
			gchar* _tmp8_;
			_tmp6_ = lines;
			_tmp6__length1 = lines_length1;
			_tmp7_ = _tmp6_[0];
			_tmp8_ = enotes_page_table_cleanup (self, _tmp7_);
			_g_free0 (page->name);
			page->name = _tmp8_;
		}
		{
			gint i = 0;
			i = 1;
			{
				gboolean _tmp9_ = FALSE;
				_tmp9_ = TRUE;
				while (TRUE) {
					gchar** _tmp11_;
					gint _tmp11__length1;
					gchar** _tmp12_;
					gint _tmp12__length1;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					const gchar* _tmp15_;
					if (!_tmp9_) {
						gint _tmp10_;
						_tmp10_ = i;
						i = _tmp10_ + 1;
					}
					_tmp9_ = FALSE;
					_tmp11_ = lines;
					_tmp11__length1 = lines_length1;
					if (!(i < _tmp11__length1)) {
						break;
					}
					_tmp12_ = lines;
					_tmp12__length1 = lines_length1;
					_tmp13_ = _tmp12_[i];
					_tmp14_ = enotes_page_table_cleanup (self, _tmp13_);
					_g_free0 (preview);
					preview = _tmp14_;
					_tmp15_ = preview;
					if (g_strcmp0 (_tmp15_, "") != 0) {
						break;
					}
				}
			}
		}
	} else {
		gchar** _tmp16_;
		gint _tmp16__length1;
		_tmp16_ = lines;
		_tmp16__length1 = lines_length1;
		if (_tmp16__length1 == 0) {
			gchar* _tmp17_;
			_tmp17_ = g_strdup (_ ("New Page"));
			_g_free0 (page->name);
			page->name = _tmp17_;
		}
	}
	_tmp18_ = preview;
	if (_tmp18_ != NULL) {
		const gchar* _tmp19_;
		gchar* _tmp20_;
		_tmp19_ = preview;
		_tmp20_ = enotes_page_table_convert (self, _tmp19_);
		_g_free0 (page->subtitle);
		page->subtitle = _tmp20_;
	} else {
		gchar* _tmp21_;
		_tmp21_ = g_strdup ("");
		_g_free0 (page->subtitle);
		page->subtitle = _tmp21_;
	}
	_g_free0 (preview);
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
}

static gpointer
_bl_member_ref0 (gpointer self)
{
	return self ? bl_member_ref (self) : NULL;
}

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

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

static gchar*
enotes_page_table_cleanup (ENotesPageTable* self,
                           const gchar* line)
{
	gchar* output = NULL;
	gchar* _tmp0_;
	const gchar* _tmp29_;
	gboolean _tmp32_ = FALSE;
	const gchar* _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (line != NULL, NULL);
	_tmp0_ = g_strdup (line);
	output = _tmp0_;
	{
		BLMember** _tmp17_;
		gint _tmp17__length1;
		{
			GeeLinkedList* _item_list = NULL;
			GeeLinkedList* _tmp1_;
			gint _item_size = 0;
			GeeLinkedList* _tmp2_;
			gint _tmp3_;
			gint _tmp4_;
			gint _item_index = 0;
			_tmp1_ = self->priv->regex_complex_commands;
			_item_list = _tmp1_;
			_tmp2_ = _item_list;
			_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
			_tmp4_ = _tmp3_;
			_item_size = _tmp4_;
			_item_index = -1;
			while (TRUE) {
				gint _tmp5_;
				gint _tmp6_;
				BLMember* item = NULL;
				GeeLinkedList* _tmp7_;
				gpointer _tmp8_;
				gchar* _tmp9_ = NULL;
				BLMember* _tmp10_;
				GRegex* _tmp11_;
				const gchar* _tmp12_;
				BLMember* _tmp13_;
				const gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				_item_index = _item_index + 1;
				_tmp5_ = _item_index;
				_tmp6_ = _item_size;
				if (!(_tmp5_ < _tmp6_)) {
					break;
				}
				_tmp7_ = _item_list;
				_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _item_index);
				item = (BLMember*) _tmp8_;
				_tmp10_ = item;
				_tmp11_ = _tmp10_->reg;
				_tmp12_ = output;
				_tmp13_ = item;
				_tmp14_ = _tmp13_->replace;
				_tmp15_ = g_regex_replace (_tmp11_, _tmp12_, (gssize) -1, 0, _tmp14_, 0, &_inner_error0_);
				_tmp9_ = _tmp15_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_bl_member_unref0 (item);
					if (_inner_error0_->domain == G_REGEX_ERROR) {
						goto __catch0_g_regex_error;
					}
					_g_free0 (output);
					g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return NULL;
				}
				_tmp16_ = _tmp9_;
				_tmp9_ = NULL;
				_g_free0 (output);
				output = _tmp16_;
				_g_free0 (_tmp9_);
				_bl_member_unref0 (item);
			}
		}
		_tmp17_ = self->priv->regex_simple_elements;
		_tmp17__length1 = self->priv->regex_simple_elements_length1;
		{
			BLMember** item_collection = NULL;
			gint item_collection_length1 = 0;
			gint _item_collection_size_ = 0;
			gint item_it = 0;
			item_collection = _tmp17_;
			item_collection_length1 = _tmp17__length1;
			for (item_it = 0; item_it < item_collection_length1; item_it = item_it + 1) {
				BLMember* _tmp18_;
				BLMember* item = NULL;
				_tmp18_ = _bl_member_ref0 (item_collection[item_it]);
				item = _tmp18_;
				{
					gchar* _tmp19_ = NULL;
					BLMember* _tmp20_;
					GRegex* _tmp21_;
					const gchar* _tmp22_;
					BLMember* _tmp23_;
					const gchar* _tmp24_;
					gchar* _tmp25_;
					gchar* _tmp26_;
					_tmp20_ = item;
					_tmp21_ = _tmp20_->reg;
					_tmp22_ = output;
					_tmp23_ = item;
					_tmp24_ = _tmp23_->replace;
					_tmp25_ = g_regex_replace (_tmp21_, _tmp22_, (gssize) -1, 0, _tmp24_, 0, &_inner_error0_);
					_tmp19_ = _tmp25_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_bl_member_unref0 (item);
						if (_inner_error0_->domain == G_REGEX_ERROR) {
							goto __catch0_g_regex_error;
						}
						_g_free0 (output);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
						g_clear_error (&_inner_error0_);
						return NULL;
					}
					_tmp26_ = _tmp19_;
					_tmp19_ = NULL;
					_g_free0 (output);
					output = _tmp26_;
					_g_free0 (_tmp19_);
					_bl_member_unref0 (item);
				}
			}
		}
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		gchar* _tmp27_;
		g_clear_error (&_inner_error0_);
		_tmp27_ = g_strdup ("");
		result = _tmp27_;
		_g_free0 (output);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (output);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	if (string_contains (line, "---")) {
		gchar* _tmp28_;
		_tmp28_ = g_strdup ("");
		result = _tmp28_;
		_g_free0 (output);
		return result;
	}
	_tmp29_ = output;
	if (string_contains (_tmp29_, "&")) {
		const gchar* _tmp30_;
		gchar* _tmp31_;
		_tmp30_ = output;
		_tmp31_ = string_replace (_tmp30_, "&", "&amp;");
		_g_free0 (output);
		output = _tmp31_;
	}
	_tmp33_ = output;
	_tmp34_ = strlen (_tmp33_);
	_tmp35_ = _tmp34_;
	if (_tmp35_ > 0) {
		const gchar* _tmp36_;
		_tmp36_ = output;
		_tmp32_ = string_get (_tmp36_, (glong) 0) == ' ';
	} else {
		_tmp32_ = FALSE;
	}
	if (_tmp32_) {
		const gchar* _tmp37_;
		const gchar* _tmp38_;
		gint _tmp39_;
		gint _tmp40_;
		gchar* _tmp41_;
		_tmp37_ = output;
		_tmp38_ = output;
		_tmp39_ = strlen (_tmp38_);
		_tmp40_ = _tmp39_;
		_tmp41_ = string_slice (_tmp37_, (glong) 1, (glong) _tmp40_);
		_g_free0 (output);
		output = _tmp41_;
	}
	result = output;
	return result;
}

static gchar*
enotes_page_table_convert (ENotesPageTable* self,
                           const gchar* raw_content)
{
	gboolean _tmp0_ = FALSE;
	gchar* line = NULL;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp6_;
	const gchar* _tmp9_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (raw_content != NULL, NULL);
	self->priv->bold_state = TRUE;
	self->priv->italics_state = TRUE;
	if (raw_content == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (raw_content, "") == 0;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("");
		result = _tmp1_;
		return result;
	}
	_tmp2_ = g_strdup (raw_content);
	line = _tmp2_;
	_tmp3_ = line;
	if (string_contains (_tmp3_, "	")) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = line;
		_tmp5_ = string_replace (_tmp4_, "	", "&nbsp;&nbsp;&nbsp;&nbsp;");
		_g_free0 (line);
		line = _tmp5_;
	}
	_tmp6_ = line;
	if (string_contains (_tmp6_, "**")) {
		const gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp7_ = line;
		_tmp8_ = enotes_page_table_replace (self, _tmp7_, "**", "<b>", "</b>", &self->priv->bold_state);
		_g_free0 (line);
		line = _tmp8_;
	}
	_tmp9_ = line;
	if (string_contains (_tmp9_, "_")) {
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp10_ = line;
		_tmp11_ = enotes_page_table_replace (self, _tmp10_, "_", "<i>", "</i>", &self->priv->italics_state);
		_g_free0 (line);
		line = _tmp11_;
	}
	result = line;
	return result;
}

static gchar*
enotes_page_table_replace (ENotesPageTable* self,
                           const gchar* line_,
                           const gchar* looking_for,
                           const gchar* opening,
                           const gchar* closing,
                           gboolean* type_state)
{
	gint chars = 0;
	gint _tmp0_;
	gint _tmp1_;
	gint replace_size = 0;
	gint _tmp2_;
	gint _tmp3_;
	gchar* line = NULL;
	gchar* _tmp4_;
	GString* final = NULL;
	GString* _tmp5_;
	GString* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (line_ != NULL, NULL);
	g_return_val_if_fail (looking_for != NULL, NULL);
	g_return_val_if_fail (opening != NULL, NULL);
	g_return_val_if_fail (closing != NULL, NULL);
	_tmp0_ = strlen (line_);
	_tmp1_ = _tmp0_;
	chars = _tmp1_;
	_tmp2_ = strlen (looking_for);
	_tmp3_ = _tmp2_;
	replace_size = _tmp3_;
	_tmp4_ = g_strconcat (line_, "     ", NULL);
	line = _tmp4_;
	_tmp5_ = g_string_new ("");
	final = _tmp5_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				const gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				gboolean _tmp11_;
				if (!_tmp6_) {
					gint _tmp7_;
					_tmp7_ = i;
					i = _tmp7_ + 1;
				}
				_tmp6_ = FALSE;
				if (!(i < chars)) {
					break;
				}
				_tmp8_ = line;
				_tmp9_ = string_slice (_tmp8_, (glong) i, (glong) (i + replace_size));
				_tmp10_ = _tmp9_;
				_tmp11_ = g_strcmp0 (_tmp10_, looking_for) == 0;
				_g_free0 (_tmp10_);
				if (_tmp11_) {
					if (*type_state) {
						GString* _tmp12_;
						*type_state = FALSE;
						_tmp12_ = final;
						g_string_append (_tmp12_, opening);
					} else {
						GString* _tmp13_;
						*type_state = TRUE;
						_tmp13_ = final;
						g_string_append (_tmp13_, closing);
					}
					i = (i + replace_size) - 1;
				} else {
					GString* _tmp14_;
					const gchar* _tmp15_;
					gchar* _tmp16_;
					gchar* _tmp17_;
					_tmp14_ = final;
					_tmp15_ = line;
					_tmp16_ = string_slice (_tmp15_, (glong) i, (glong) (i + 1));
					_tmp17_ = _tmp16_;
					g_string_append (_tmp14_, _tmp17_);
					_g_free0 (_tmp17_);
				}
			}
		}
	}
	_tmp18_ = final;
	_tmp19_ = _tmp18_->str;
	_tmp20_ = g_strdup (_tmp19_);
	result = _tmp20_;
	_g_string_free0 (final);
	_g_free0 (line);
	return result;
}

void
enotes_page_table_reset_instance (void)
{
	_database_table_unref0 (enotes_page_table_instance);
	enotes_page_table_instance = NULL;
}

static void
enotes_page_table_class_init (ENotesPageTableClass * klass,
                              gpointer klass_data)
{
	enotes_page_table_parent_class = g_type_class_peek_parent (klass);
	((DatabaseTableClass *) klass)->finalize = enotes_page_table_finalize;
	g_type_class_adjust_private_offset (klass, &ENotesPageTable_private_offset);
	enotes_page_table_signals[ENOTES_PAGE_TABLE_PAGE_SAVED_SIGNAL] = g_signal_new ("page-saved", ENOTES_TYPE_PAGE_TABLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, ENOTES_TYPE_PAGE);
}

static void
enotes_page_table_instance_init (ENotesPageTable * self,
                                 gpointer klass)
{
	GeeLinkedList* _tmp0_;
	BLMember* _tmp1_;
	BLMember* _tmp2_;
	BLMember** _tmp3_;
	self->priv = enotes_page_table_get_instance_private (self);
	_tmp0_ = gee_linked_list_new (TYPE_BL_MEMBER, (GBoxedCopyFunc) bl_member_ref, (GDestroyNotify) bl_member_unref, NULL, NULL, NULL);
	self->priv->regex_complex_commands = _tmp0_;
	_tmp1_ = bl_member_new (_thread_safe_regex_init (&_tmp_regex_0, "[#\\n\\t<>`]+", 0), "");
	_tmp2_ = bl_member_new (_thread_safe_regex_init (&_tmp_regex_1, "<br>", 0), "");
	_tmp3_ = g_new0 (BLMember*, 2 + 1);
	_tmp3_[0] = _tmp1_;
	_tmp3_[1] = _tmp2_;
	self->priv->regex_simple_elements = _tmp3_;
	self->priv->regex_simple_elements_length1 = 2;
	self->priv->_regex_simple_elements_size_ = self->priv->regex_simple_elements_length1;
}

static void
enotes_page_table_finalize (DatabaseTable * obj)
{
	ENotesPageTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_PAGE_TABLE, ENotesPageTable);
	_g_object_unref0 (self->priv->regex_complex_commands);
	self->priv->regex_simple_elements = (_vala_array_free (self->priv->regex_simple_elements, self->priv->regex_simple_elements_length1, (GDestroyNotify) bl_member_unref), NULL);
	DATABASE_TABLE_CLASS (enotes_page_table_parent_class)->finalize (obj);
}

static GType
enotes_page_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesPageTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_page_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesPageTable), 0, (GInstanceInitFunc) enotes_page_table_instance_init, NULL };
	GType enotes_page_table_type_id;
	enotes_page_table_type_id = g_type_register_static (TYPE_DATABASE_TABLE, "ENotesPageTable", &g_define_type_info, 0);
	ENotesPageTable_private_offset = g_type_add_instance_private (enotes_page_table_type_id, sizeof (ENotesPageTablePrivate));
	return enotes_page_table_type_id;
}

GType
enotes_page_table_get_type (void)
{
	static volatile gsize enotes_page_table_type_id__once = 0;
	if (g_once_init_enter (&enotes_page_table_type_id__once)) {
		GType enotes_page_table_type_id;
		enotes_page_table_type_id = enotes_page_table_get_type_once ();
		g_once_init_leave (&enotes_page_table_type_id__once, enotes_page_table_type_id);
	}
	return enotes_page_table_type_id__once;
}

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

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

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

