/* Notebook.c generated by valac 0.56.19, the Vala compiler
 * generated from Notebook.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 <gdk/gdk.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
#include <gee.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_NOTEBOOK (enotes_notebook_get_type ())
#define ENOTES_NOTEBOOK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_NOTEBOOK, ENotesNotebook))
#define ENOTES_NOTEBOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_NOTEBOOK, ENotesNotebookClass))
#define ENOTES_IS_NOTEBOOK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_NOTEBOOK))
#define ENOTES_IS_NOTEBOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_NOTEBOOK))
#define ENOTES_NOTEBOOK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_NOTEBOOK, ENotesNotebookClass))

typedef struct _ENotesNotebook ENotesNotebook;
typedef struct _ENotesNotebookClass ENotesNotebookClass;
typedef struct _ENotesNotebookPrivate ENotesNotebookPrivate;
enum  {
	ENOTES_NOTEBOOK_0_PROPERTY,
	ENOTES_NOTEBOOK_NUM_PROPERTIES
};
static GParamSpec* enotes_notebook_properties[ENOTES_NOTEBOOK_NUM_PROPERTIES];
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
enum  {
	ENOTES_NOTEBOOK_DESTROY_SIGNAL,
	ENOTES_NOTEBOOK_NUM_SIGNALS
};
static guint enotes_notebook_signals[ENOTES_NOTEBOOK_NUM_SIGNALS] = {0};

#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_NOTEBOOK_TABLE (enotes_notebook_table_get_type ())
#define ENOTES_NOTEBOOK_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_NOTEBOOK_TABLE, ENotesNotebookTable))
#define ENOTES_NOTEBOOK_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_NOTEBOOK_TABLE, ENotesNotebookTableClass))
#define ENOTES_IS_NOTEBOOK_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_NOTEBOOK_TABLE))
#define ENOTES_IS_NOTEBOOK_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_NOTEBOOK_TABLE))
#define ENOTES_NOTEBOOK_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_NOTEBOOK_TABLE, ENotesNotebookTableClass))

typedef struct _ENotesNotebookTable ENotesNotebookTable;
typedef struct _ENotesNotebookTableClass ENotesNotebookTableClass;
typedef struct _ENotesNotebookTablePrivate ENotesNotebookTablePrivate;
#define _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))
#define _database_table_unref0(var) ((var == NULL) ? NULL : (var = (database_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

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

#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_NOTEBOOK_TABLE_NOTEBOOK_ADDED_SIGNAL,
	ENOTES_NOTEBOOK_TABLE_NOTEBOOK_CHANGED_SIGNAL,
	ENOTES_NOTEBOOK_TABLE_NUM_SIGNALS
};
static guint enotes_notebook_table_signals[ENOTES_NOTEBOOK_TABLE_NUM_SIGNALS] = {0};

struct _ENotesNotebook {
	GObject parent_instance;
	ENotesNotebookPrivate * priv;
	gint64 id;
	gint64* parent_id;
	GdkRGBA rgb;
	gchar* name;
	gchar* css;
	gchar* stylesheet;
};

struct _ENotesNotebookClass {
	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 _ENotesNotebookTable {
	DatabaseTable parent_instance;
	ENotesNotebookTablePrivate * priv;
};

struct _ENotesNotebookTableClass {
	DatabaseTableClass parent_class;
};

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 gpointer enotes_notebook_parent_class = NULL;
static gpointer enotes_notebook_table_parent_class = NULL;
static ENotesNotebookTable* enotes_notebook_table_instance;
static ENotesNotebookTable* enotes_notebook_table_instance = NULL;

VALA_EXTERN GType enotes_notebook_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesNotebook, g_object_unref)
VALA_EXTERN ENotesNotebook* enotes_notebook_new (void);
VALA_EXTERN ENotesNotebook* enotes_notebook_construct (GType object_type);
static void enotes_notebook_finalize (GObject * obj);
static GType enotes_notebook_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_notebook_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesNotebookTable, database_table_unref)
static ENotesNotebookTable* enotes_notebook_table_new (void);
static ENotesNotebookTable* enotes_notebook_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 ENotesNotebookTable* enotes_notebook_table_get_instance (void);
VALA_EXTERN GeeArrayList* enotes_notebook_table_get_notebooks (ENotesNotebookTable* self);
static gint64* _int64_dup (gint64* self);
VALA_EXTERN ENotesNotebook* enotes_notebook_table_load_notebook_data (ENotesNotebookTable* self,
                                                          gint64 notebook_id);
VALA_EXTERN void database_table_bind_int (sqlite3_stmt* stmt,
                              gint column,
                              gint64 data);
VALA_EXTERN void enotes_notebook_table_save_notebook (ENotesNotebookTable* self,
                                          gint64 notebook_id,
                                          const gchar* name,
                                          GdkRGBA* rgb,
                                          const gchar* css,
                                          const gchar* stylesheet);
VALA_EXTERN void database_table_bind_text (sqlite3_stmt* stmt,
                               gint column,
                               const gchar* data);
VALA_EXTERN gint64 enotes_notebook_table_new_notebook (ENotesNotebookTable* self,
                                           gint64 parent,
                                           const gchar* name,
                                           GdkRGBA* rgb,
                                           const gchar* css,
                                           const gchar* stylesheet);
VALA_EXTERN gint64 database_table_last_insert_row (DatabaseTable* self);
VALA_EXTERN GType enotes_page_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPageTable, database_table_unref)
VALA_EXTERN ENotesPageTable* enotes_page_table_get_instance (void);
VALA_EXTERN GType enotes_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPage, g_object_unref)
VALA_EXTERN ENotesPage* enotes_page_table_new_page (ENotesPageTable* self,
                                        gint64 notebook_id);
VALA_EXTERN gchar* enotes_notebook_table_get_stylesheet_from_page (ENotesNotebookTable* self,
                                                       gint64 page_id);
VALA_EXTERN gchar* enotes_notebook_table_get_css_from_page (ENotesNotebookTable* self,
                                                gint64 page_id);
VALA_EXTERN void enotes_notebook_table_move_notebook (ENotesNotebookTable* self,
                                          ENotesNotebook* notebook,
                                          ENotesNotebook* parent_notebook);
VALA_EXTERN void enotes_notebook_table_delete_notebook (ENotesNotebookTable* self,
                                            gint64 id);
VALA_EXTERN GeeArrayList* enotes_page_table_get_pages (ENotesPageTable* self,
                                           gint64 notebook_id);
VALA_EXTERN void enotes_page_table_delete_page (ENotesPageTable* self,
                                    gint64 id);
VALA_EXTERN void enotes_notebook_table_reset_instance (void);
static void enotes_notebook_table_finalize (DatabaseTable * obj);
static GType enotes_notebook_table_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

ENotesNotebook*
enotes_notebook_construct (GType object_type)
{
	ENotesNotebook * self = NULL;
	self = (ENotesNotebook*) g_object_new (object_type, NULL);
	return self;
}

ENotesNotebook*
enotes_notebook_new (void)
{
	return enotes_notebook_construct (ENOTES_TYPE_NOTEBOOK);
}

static void
enotes_notebook_class_init (ENotesNotebookClass * klass,
                            gpointer klass_data)
{
	enotes_notebook_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = enotes_notebook_finalize;
	enotes_notebook_signals[ENOTES_NOTEBOOK_DESTROY_SIGNAL] = g_signal_new ("destroy", ENOTES_TYPE_NOTEBOOK, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
enotes_notebook_instance_init (ENotesNotebook * self,
                               gpointer klass)
{
}

static void
enotes_notebook_finalize (GObject * obj)
{
	ENotesNotebook * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_NOTEBOOK, ENotesNotebook);
	_g_free0 (self->parent_id);
	_g_free0 (self->name);
	_g_free0 (self->css);
	_g_free0 (self->stylesheet);
	G_OBJECT_CLASS (enotes_notebook_parent_class)->finalize (obj);
}

static GType
enotes_notebook_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesNotebookClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_notebook_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesNotebook), 0, (GInstanceInitFunc) enotes_notebook_instance_init, NULL };
	GType enotes_notebook_type_id;
	enotes_notebook_type_id = g_type_register_static (G_TYPE_OBJECT, "ENotesNotebook", &g_define_type_info, 0);
	return enotes_notebook_type_id;
}

GType
enotes_notebook_get_type (void)
{
	static volatile gsize enotes_notebook_type_id__once = 0;
	if (g_once_init_enter (&enotes_notebook_type_id__once)) {
		GType enotes_notebook_type_id;
		enotes_notebook_type_id = enotes_notebook_get_type_once ();
		g_once_init_leave (&enotes_notebook_type_id__once, enotes_notebook_type_id);
	}
	return enotes_notebook_type_id__once;
}

static ENotesNotebookTable*
enotes_notebook_table_construct (GType object_type)
{
	ENotesNotebookTable* self = NULL;
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	gint res = 0;
	sqlite3_stmt* _tmp1_;
	self = (ENotesNotebookTable*) database_table_construct (object_type);
	_tmp0_ = database_table_create_stmt ("CREATE TABLE IF NOT EXISTS Notebook (" "id INTEGER PRIMARY KEY AUTOINCREMENT, " "name TEXT NOT NULL, " "rgb TEXT," "CSS TEXT," "stylesheet TEXT," "parent_id INTEGER)");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	res = sqlite3_step (_tmp1_);
	if (res != SQLITE_DONE) {
		database_table_fatal ("create notebook table", res);
	}
	database_table_set_table_name ((DatabaseTable*) self, "Notebook");
	_sqlite3_finalize0 (stmt);
	return self;
}

static ENotesNotebookTable*
enotes_notebook_table_new (void)
{
	return enotes_notebook_table_construct (ENOTES_TYPE_NOTEBOOK_TABLE);
}

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

ENotesNotebookTable*
enotes_notebook_table_get_instance (void)
{
	ENotesNotebookTable* _tmp0_;
	ENotesNotebookTable* _tmp2_;
	ENotesNotebookTable* _tmp3_;
	ENotesNotebookTable* result;
	_tmp0_ = enotes_notebook_table_instance;
	if (_tmp0_ == NULL) {
		ENotesNotebookTable* _tmp1_;
		_tmp1_ = enotes_notebook_table_new ();
		_database_table_unref0 (enotes_notebook_table_instance);
		enotes_notebook_table_instance = _tmp1_;
	}
	_tmp2_ = enotes_notebook_table_instance;
	_tmp3_ = _database_table_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

static gint64*
_int64_dup (gint64* self)
{
	gint64* dup;
	dup = g_new0 (gint64, 1);
	memcpy (dup, self, sizeof (gint64));
	return dup;
}

static gpointer
__int64_dup0 (gpointer self)
{
	return self ? _int64_dup (self) : NULL;
}

GeeArrayList*
enotes_notebook_table_get_notebooks (ENotesNotebookTable* self)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	GeeArrayList* notebooks = NULL;
	GeeArrayList* _tmp1_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT id, name, rgb, parent_id, css, stylesheet FROM Notebook");
	stmt = _tmp0_;
	_tmp1_ = gee_array_list_new (ENOTES_TYPE_NOTEBOOK, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	notebooks = _tmp1_;
	{
		gboolean _tmp2_ = FALSE;
		_tmp2_ = TRUE;
		while (TRUE) {
			gint res = 0;
			sqlite3_stmt* _tmp3_;
			ENotesNotebook* row = NULL;
			ENotesNotebook* _tmp4_;
			ENotesNotebook* _tmp5_;
			sqlite3_stmt* _tmp6_;
			ENotesNotebook* _tmp7_;
			sqlite3_stmt* _tmp8_;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			GdkRGBA rgba = {0};
			GdkRGBA _tmp11_ = {0};
			sqlite3_stmt* _tmp12_;
			const gchar* _tmp13_;
			ENotesNotebook* _tmp14_;
			GdkRGBA _tmp15_;
			ENotesNotebook* _tmp16_;
			sqlite3_stmt* _tmp17_;
			gint64 _tmp18_;
			gint64* _tmp19_;
			ENotesNotebook* _tmp20_;
			sqlite3_stmt* _tmp21_;
			const gchar* _tmp22_;
			gchar* _tmp23_;
			ENotesNotebook* _tmp24_;
			sqlite3_stmt* _tmp25_;
			const gchar* _tmp26_;
			gchar* _tmp27_;
			GeeArrayList* _tmp28_;
			ENotesNotebook* _tmp29_;
			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_notebook_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_;
			rgba = _tmp11_;
			_tmp12_ = stmt;
			_tmp13_ = (const gchar*) sqlite3_column_text (_tmp12_, 2);
			gdk_rgba_parse (&rgba, _tmp13_);
			_tmp14_ = row;
			_tmp15_ = rgba;
			_tmp14_->rgb = _tmp15_;
			_tmp16_ = row;
			_tmp17_ = stmt;
			_tmp18_ = sqlite3_column_int64 (_tmp17_, 3);
			_tmp19_ = __int64_dup0 (&_tmp18_);
			_g_free0 (_tmp16_->parent_id);
			_tmp16_->parent_id = _tmp19_;
			_tmp20_ = row;
			_tmp21_ = stmt;
			_tmp22_ = (const gchar*) sqlite3_column_text (_tmp21_, 4);
			_tmp23_ = g_strdup (_tmp22_);
			_g_free0 (_tmp20_->css);
			_tmp20_->css = _tmp23_;
			_tmp24_ = row;
			_tmp25_ = stmt;
			_tmp26_ = (const gchar*) sqlite3_column_text (_tmp25_, 5);
			_tmp27_ = g_strdup (_tmp26_);
			_g_free0 (_tmp24_->stylesheet);
			_tmp24_->stylesheet = _tmp27_;
			_tmp28_ = notebooks;
			_tmp29_ = row;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp28_, _tmp29_);
			_g_object_unref0 (row);
		}
	}
	result = notebooks;
	_sqlite3_finalize0 (stmt);
	return result;
}

ENotesNotebook*
enotes_notebook_table_load_notebook_data (ENotesNotebookTable* self,
                                          gint64 notebook_id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	ENotesNotebook* row = NULL;
	ENotesNotebook* _tmp3_;
	ENotesNotebook* _tmp4_;
	ENotesNotebook* _tmp5_;
	sqlite3_stmt* _tmp6_;
	gint64 _tmp7_;
	gint64* _tmp8_;
	ENotesNotebook* _tmp9_;
	sqlite3_stmt* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	GdkRGBA rgba = {0};
	GdkRGBA _tmp13_ = {0};
	sqlite3_stmt* _tmp14_;
	const gchar* _tmp15_;
	ENotesNotebook* _tmp16_;
	GdkRGBA _tmp17_;
	ENotesNotebook* _tmp18_;
	sqlite3_stmt* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	ENotesNotebook* _tmp22_;
	sqlite3_stmt* _tmp23_;
	const gchar* _tmp24_;
	gchar* _tmp25_;
	ENotesNotebook* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT parent_id, name, rgb, css, stylesheet " "FROM Notebook WHERE id=?");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	database_table_bind_int (_tmp1_, 1, notebook_id);
	_tmp2_ = stmt;
	if (sqlite3_step (_tmp2_) != SQLITE_ROW) {
		result = NULL;
		_sqlite3_finalize0 (stmt);
		return result;
	}
	_tmp3_ = enotes_notebook_new ();
	row = _tmp3_;
	_tmp4_ = row;
	_tmp4_->id = notebook_id;
	_tmp5_ = row;
	_tmp6_ = stmt;
	_tmp7_ = (gint64) sqlite3_column_int (_tmp6_, 0);
	_tmp8_ = __int64_dup0 (&_tmp7_);
	_g_free0 (_tmp5_->parent_id);
	_tmp5_->parent_id = _tmp8_;
	_tmp9_ = row;
	_tmp10_ = stmt;
	_tmp11_ = (const gchar*) sqlite3_column_text (_tmp10_, 1);
	_tmp12_ = g_strdup (_tmp11_);
	_g_free0 (_tmp9_->name);
	_tmp9_->name = _tmp12_;
	rgba = _tmp13_;
	_tmp14_ = stmt;
	_tmp15_ = (const gchar*) sqlite3_column_text (_tmp14_, 2);
	gdk_rgba_parse (&rgba, _tmp15_);
	_tmp16_ = row;
	_tmp17_ = rgba;
	_tmp16_->rgb = _tmp17_;
	_tmp18_ = row;
	_tmp19_ = stmt;
	_tmp20_ = (const gchar*) sqlite3_column_text (_tmp19_, 3);
	_tmp21_ = g_strdup (_tmp20_);
	_g_free0 (_tmp18_->css);
	_tmp18_->css = _tmp21_;
	_tmp22_ = row;
	_tmp23_ = stmt;
	_tmp24_ = (const gchar*) sqlite3_column_text (_tmp23_, 4);
	_tmp25_ = g_strdup (_tmp24_);
	_g_free0 (_tmp22_->stylesheet);
	_tmp22_->stylesheet = _tmp25_;
	result = row;
	_sqlite3_finalize0 (stmt);
	return result;
}

void
enotes_notebook_table_save_notebook (ENotesNotebookTable* self,
                                     gint64 notebook_id,
                                     const gchar* name,
                                     GdkRGBA* rgb,
                                     const gchar* css,
                                     const gchar* stylesheet)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	ENotesNotebook* notebook = NULL;
	ENotesNotebook* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (rgb != NULL);
	g_return_if_fail (css != NULL);
	g_return_if_fail (stylesheet != NULL);
	_tmp0_ = database_table_create_stmt ("UPDATE Notebook SET name = ?, css = ?, stylesheet = ?, rgb =? WHERE id" \
" = ?");
	stmt = _tmp0_;
	database_table_bind_text (stmt, 1, name);
	database_table_bind_text (stmt, 2, css);
	database_table_bind_text (stmt, 3, stylesheet);
	_tmp1_ = gdk_rgba_to_string (rgb);
	_tmp2_ = _tmp1_;
	database_table_bind_text (stmt, 4, _tmp2_);
	_g_free0 (_tmp2_);
	database_table_bind_int (stmt, 5, notebook_id);
	sqlite3_step (stmt);
	_tmp3_ = enotes_notebook_table_load_notebook_data (self, notebook_id);
	notebook = _tmp3_;
	g_signal_emit (self, enotes_notebook_table_signals[ENOTES_NOTEBOOK_TABLE_NOTEBOOK_CHANGED_SIGNAL], 0, notebook);
	_g_object_unref0 (notebook);
	_sqlite3_finalize0 (stmt);
}

gint64
enotes_notebook_table_new_notebook (ENotesNotebookTable* self,
                                    gint64 parent,
                                    const gchar* name,
                                    GdkRGBA* rgb,
                                    const gchar* css,
                                    const gchar* stylesheet)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	sqlite3_stmt* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	sqlite3_stmt* _tmp6_;
	sqlite3_stmt* _tmp7_;
	gint res = 0;
	sqlite3_stmt* _tmp8_;
	gint64 last = 0LL;
	ENotesNotebook* notebook = NULL;
	ENotesNotebook* _tmp9_;
	ENotesPageTable* _tmp10_;
	ENotesPageTable* _tmp11_;
	ENotesNotebook* _tmp12_;
	ENotesPage* _tmp13_;
	ENotesPage* _tmp14_;
	ENotesNotebook* _tmp15_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	g_return_val_if_fail (name != NULL, -1LL);
	g_return_val_if_fail (rgb != NULL, -1LL);
	g_return_val_if_fail (css != NULL, -1LL);
	g_return_val_if_fail (stylesheet != NULL, -1LL);
	_tmp0_ = database_table_create_stmt ("INSERT INTO Notebook (name, parent_id, rgb, css, stylesheet) " "VALUES (?, ?, ?, ?, ?)");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	database_table_bind_text (_tmp1_, 1, name);
	_tmp2_ = stmt;
	database_table_bind_int (_tmp2_, 2, parent);
	_tmp3_ = stmt;
	_tmp4_ = gdk_rgba_to_string (rgb);
	_tmp5_ = _tmp4_;
	database_table_bind_text (_tmp3_, 3, _tmp5_);
	_g_free0 (_tmp5_);
	_tmp6_ = stmt;
	database_table_bind_text (_tmp6_, 4, css);
	_tmp7_ = stmt;
	database_table_bind_text (_tmp7_, 5, stylesheet);
	_tmp8_ = stmt;
	res = sqlite3_step (_tmp8_);
	if (res != SQLITE_DONE) {
		database_table_fatal ("Event create_from_row", res);
		result = (gint64) 0;
		_sqlite3_finalize0 (stmt);
		return result;
	}
	last = database_table_last_insert_row ((DatabaseTable*) self);
	_tmp9_ = enotes_notebook_table_load_notebook_data (self, last);
	notebook = _tmp9_;
	_tmp10_ = enotes_page_table_get_instance ();
	_tmp11_ = _tmp10_;
	_tmp12_ = notebook;
	_tmp13_ = enotes_page_table_new_page (_tmp11_, _tmp12_->id);
	_tmp14_ = _tmp13_;
	_g_object_unref0 (_tmp14_);
	_database_table_unref0 (_tmp11_);
	_tmp15_ = notebook;
	g_signal_emit (self, enotes_notebook_table_signals[ENOTES_NOTEBOOK_TABLE_NOTEBOOK_ADDED_SIGNAL], 0, _tmp15_);
	result = last;
	_g_object_unref0 (notebook);
	_sqlite3_finalize0 (stmt);
	return result;
}

gchar*
enotes_notebook_table_get_stylesheet_from_page (ENotesNotebookTable* self,
                                                gint64 page_id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	sqlite3_stmt* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT stylesheet FROM Notebook JOIN Page WHERE Page.id = ? AND Page.n" \
"otebook_id = Notebook.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_ = stmt;
	_tmp4_ = (const gchar*) sqlite3_column_text (_tmp3_, 0);
	_tmp5_ = g_strdup (_tmp4_);
	result = _tmp5_;
	_sqlite3_finalize0 (stmt);
	return result;
}

gchar*
enotes_notebook_table_get_css_from_page (ENotesNotebookTable* self,
                                         gint64 page_id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	sqlite3_stmt* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = database_table_create_stmt ("SELECT css FROM Notebook JOIN Page WHERE Page.id = ? AND Page.notebook" \
"_id = Notebook.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_ = stmt;
	_tmp4_ = (const gchar*) sqlite3_column_text (_tmp3_, 0);
	_tmp5_ = g_strdup (_tmp4_);
	result = _tmp5_;
	_sqlite3_finalize0 (stmt);
	return result;
}

void
enotes_notebook_table_move_notebook (ENotesNotebookTable* self,
                                     ENotesNotebook* notebook,
                                     ENotesNotebook* parent_notebook)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	gint64 _tmp1_ = 0LL;
	sqlite3_stmt* _tmp2_;
	sqlite3_stmt* _tmp3_;
	sqlite3_stmt* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (notebook != NULL);
	_tmp0_ = database_table_create_stmt ("UPDATE Notebook SET parent_id = ? WHERE id = ?");
	stmt = _tmp0_;
	if (parent_notebook != NULL) {
		_tmp1_ = parent_notebook->id;
	} else {
		_tmp1_ = (gint64) 0;
	}
	_tmp2_ = stmt;
	database_table_bind_int (_tmp2_, 1, _tmp1_);
	_tmp3_ = stmt;
	database_table_bind_int (_tmp3_, 2, notebook->id);
	_tmp4_ = stmt;
	sqlite3_step (_tmp4_);
	_sqlite3_finalize0 (stmt);
}

void
enotes_notebook_table_delete_notebook (ENotesNotebookTable* self,
                                       gint64 id)
{
	sqlite3_stmt* stmt = NULL;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	ENotesPageTable* page_table = NULL;
	ENotesPageTable* _tmp3_;
	GeeArrayList* pages = NULL;
	ENotesPageTable* _tmp4_;
	GeeArrayList* _tmp5_;
	sqlite3_stmt* _tmp16_;
	sqlite3_stmt* _tmp17_;
	sqlite3_stmt* _tmp18_;
	g_return_if_fail (self != NULL);
	_tmp0_ = database_table_create_stmt ("UPDATE Notebook SET parent_id = 0 WHERE parent_id = ?");
	stmt = _tmp0_;
	_tmp1_ = stmt;
	database_table_bind_int (_tmp1_, 1, id);
	_tmp2_ = stmt;
	sqlite3_step (_tmp2_);
	_tmp3_ = enotes_page_table_get_instance ();
	page_table = _tmp3_;
	_tmp4_ = page_table;
	_tmp5_ = enotes_page_table_get_pages (_tmp4_, id);
	pages = _tmp5_;
	{
		GeeArrayList* _page_list = NULL;
		GeeArrayList* _tmp6_;
		gint _page_size = 0;
		GeeArrayList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		gint _page_index = 0;
		_tmp6_ = pages;
		_page_list = _tmp6_;
		_tmp7_ = _page_list;
		_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_page_size = _tmp9_;
		_page_index = -1;
		while (TRUE) {
			gint _tmp10_;
			gint _tmp11_;
			ENotesPage* page = NULL;
			GeeArrayList* _tmp12_;
			gpointer _tmp13_;
			ENotesPageTable* _tmp14_;
			ENotesPage* _tmp15_;
			_page_index = _page_index + 1;
			_tmp10_ = _page_index;
			_tmp11_ = _page_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _page_list;
			_tmp13_ = gee_abstract_list_get ((GeeAbstractList*) _tmp12_, _page_index);
			page = (ENotesPage*) _tmp13_;
			_tmp14_ = page_table;
			_tmp15_ = page;
			enotes_page_table_delete_page (_tmp14_, _tmp15_->id);
			_g_object_unref0 (page);
		}
	}
	_tmp16_ = database_table_create_stmt ("DELETE FROM Notebook WHERE id = ?");
	_sqlite3_finalize0 (stmt);
	stmt = _tmp16_;
	_tmp17_ = stmt;
	database_table_bind_int (_tmp17_, 1, id);
	_tmp18_ = stmt;
	sqlite3_step (_tmp18_);
	_g_object_unref0 (pages);
	_database_table_unref0 (page_table);
	_sqlite3_finalize0 (stmt);
}

void
enotes_notebook_table_reset_instance (void)
{
	_database_table_unref0 (enotes_notebook_table_instance);
	enotes_notebook_table_instance = NULL;
}

static void
enotes_notebook_table_class_init (ENotesNotebookTableClass * klass,
                                  gpointer klass_data)
{
	enotes_notebook_table_parent_class = g_type_class_peek_parent (klass);
	((DatabaseTableClass *) klass)->finalize = enotes_notebook_table_finalize;
	enotes_notebook_table_signals[ENOTES_NOTEBOOK_TABLE_NOTEBOOK_ADDED_SIGNAL] = g_signal_new ("notebook-added", ENOTES_TYPE_NOTEBOOK_TABLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, ENOTES_TYPE_NOTEBOOK);
	enotes_notebook_table_signals[ENOTES_NOTEBOOK_TABLE_NOTEBOOK_CHANGED_SIGNAL] = g_signal_new ("notebook-changed", ENOTES_TYPE_NOTEBOOK_TABLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, ENOTES_TYPE_NOTEBOOK);
}

static void
enotes_notebook_table_instance_init (ENotesNotebookTable * self,
                                     gpointer klass)
{
}

static void
enotes_notebook_table_finalize (DatabaseTable * obj)
{
	ENotesNotebookTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_NOTEBOOK_TABLE, ENotesNotebookTable);
	DATABASE_TABLE_CLASS (enotes_notebook_table_parent_class)->finalize (obj);
}

static GType
enotes_notebook_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesNotebookTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_notebook_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesNotebookTable), 0, (GInstanceInitFunc) enotes_notebook_table_instance_init, NULL };
	GType enotes_notebook_table_type_id;
	enotes_notebook_table_type_id = g_type_register_static (TYPE_DATABASE_TABLE, "ENotesNotebookTable", &g_define_type_info, 0);
	return enotes_notebook_table_type_id;
}

GType
enotes_notebook_table_get_type (void)
{
	static volatile gsize enotes_notebook_table_type_id__once = 0;
	if (g_once_init_enter (&enotes_notebook_table_type_id__once)) {
		GType enotes_notebook_table_type_id;
		enotes_notebook_table_type_id = enotes_notebook_table_get_type_once ();
		g_once_init_leave (&enotes_notebook_table_type_id__once, enotes_notebook_table_type_id);
	}
	return enotes_notebook_table_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;
}

