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

/*
Copyright (C) 2014 Johan Mattsson

This library is free software; you can redistribute it and/or modify 
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation; either version 3 of the 
License, or (at your option) any later version.

This library 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 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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

enum  {
	BIRD_FONT_PREVIEW_TOOLS_0_PROPERTY,
	BIRD_FONT_PREVIEW_TOOLS_NUM_PROPERTIES
};
static GParamSpec* bird_font_preview_tools_properties[BIRD_FONT_PREVIEW_TOOLS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_source_unref0(var) ((var == NULL) ? NULL : (var = (g_source_unref (var), NULL)))

static gpointer bird_font_preview_tools_parent_class = NULL;

static void __lambda212_ (BirdFontPreviewTools* self,
                   BirdFontTool* _self_);
static void ___lambda212__bird_font_tool_select_action (BirdFontTool* _sender,
                                                 BirdFontTool* selected,
                                                 gpointer self);
static void __lambda214_ (BirdFontPreviewTools* self,
                   BirdFontTool* _self_);
static void ___lambda214__bird_font_tool_select_action (BirdFontTool* _sender,
                                                 BirdFontTool* selected,
                                                 gpointer self);
static void __lambda215_ (BirdFontPreviewTools* self,
                   BirdFontTool* _self_);
static void ___lambda215__bird_font_tool_select_action (BirdFontTool* _sender,
                                                 BirdFontTool* selected,
                                                 gpointer self);
static void bird_font_preview_tools_signal_preview_updated (void);
static void _bird_font_preview_tools_signal_preview_updated_bird_font_export_callback_file_exported (BirdFontExportCallback* _sender,
                                                                                              gpointer self);
static gboolean __lambda213_ (void);
static gboolean ___lambda213__gsource_func (gpointer self);
static GeeArrayList* bird_font_preview_tools_real_get_expanders (BirdFontToolCollection* base);
static GeeArrayList* bird_font_preview_tools_real_get_displays (BirdFontToolCollection* base);
static void bird_font_preview_tools_finalize (GObject * obj);
static GType bird_font_preview_tools_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
__lambda212_ (BirdFontPreviewTools* self,
              BirdFontTool* _self_)
{
	g_return_if_fail (_self_ != NULL);
	bird_font_preview_tools_update_preview ();
}

static void
___lambda212__bird_font_tool_select_action (BirdFontTool* _sender,
                                            BirdFontTool* selected,
                                            gpointer self)
{
	__lambda212_ ((BirdFontPreviewTools*) self, selected);
}

static void
__lambda214_ (BirdFontPreviewTools* self,
              BirdFontTool* _self_)
{
	g_return_if_fail (_self_ != NULL);
	bird_font_menu_tab_export_fonts_in_background ();
}

static void
___lambda214__bird_font_tool_select_action (BirdFontTool* _sender,
                                            BirdFontTool* selected,
                                            gpointer self)
{
	__lambda214_ ((BirdFontPreviewTools*) self, selected);
}

static void
__lambda215_ (BirdFontPreviewTools* self,
              BirdFontTool* _self_)
{
	g_return_if_fail (_self_ != NULL);
	bird_font_preview_tools_generate_html_document ();
}

static void
___lambda215__bird_font_tool_select_action (BirdFontTool* _sender,
                                            BirdFontTool* selected,
                                            gpointer self)
{
	__lambda215_ ((BirdFontPreviewTools*) self, selected);
}

BirdFontPreviewTools*
bird_font_preview_tools_construct (GType object_type)
{
	BirdFontPreviewTools * self = NULL;
	BirdFontExpander* webview_tools = NULL;
	BirdFontExpander* _tmp0_;
	BirdFontExpander* font_name = NULL;
	BirdFontExpander* _tmp1_;
	BirdFontFontName* _tmp2_;
	BirdFontFontName* _tmp3_;
	BirdFontTool* update_webview_button = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	BirdFontTool* _tmp6_;
	BirdFontTool* _tmp7_;
	BirdFontTool* export_fonts_button = NULL;
	gchar* _tmp8_;
	gchar* _tmp9_;
	BirdFontTool* _tmp10_;
	BirdFontTool* _tmp11_;
	BirdFontTool* generate_html_button = NULL;
	gchar* _tmp12_;
	gchar* _tmp13_;
	BirdFontTool* _tmp14_;
	BirdFontTool* _tmp15_;
	GeeArrayList* _tmp16_;
	GeeArrayList* _tmp17_;
	self = (BirdFontPreviewTools*) bird_font_tool_collection_construct (object_type);
	_tmp0_ = bird_font_expander_new (NULL);
	webview_tools = _tmp0_;
	_tmp1_ = bird_font_expander_new (NULL);
	font_name = _tmp1_;
	_tmp2_ = bird_font_font_name_new (NULL, "");
	_tmp3_ = _tmp2_;
	bird_font_expander_add_tool (font_name, (BirdFontTool*) _tmp3_, -1);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = bird_font_t_ ("Reload webview");
	_tmp5_ = _tmp4_;
	_tmp6_ = bird_font_tool_new ("update_webview", _tmp5_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	update_webview_button = _tmp7_;
	g_signal_connect_object (update_webview_button, "select-action", (GCallback) ___lambda212__bird_font_tool_select_action, self, 0);
	bird_font_expander_add_tool (webview_tools, update_webview_button, -1);
	_tmp8_ = bird_font_t_ ("Export fonts");
	_tmp9_ = _tmp8_;
	_tmp10_ = bird_font_tool_new ("export_fonts", _tmp9_);
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	export_fonts_button = _tmp11_;
	g_signal_connect_object (export_fonts_button, "select-action", (GCallback) ___lambda214__bird_font_tool_select_action, self, 0);
	bird_font_expander_add_tool (webview_tools, export_fonts_button, -1);
	_tmp12_ = bird_font_t_ ("Generate html document");
	_tmp13_ = _tmp12_;
	_tmp14_ = bird_font_tool_new ("generate_html_document", _tmp13_);
	_tmp15_ = _tmp14_;
	_g_free0 (_tmp13_);
	generate_html_button = _tmp15_;
	g_signal_connect_object (generate_html_button, "select-action", (GCallback) ___lambda215__bird_font_tool_select_action, self, 0);
	bird_font_expander_add_tool (webview_tools, generate_html_button, -1);
	_tmp16_ = self->expanders;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, font_name);
	_tmp17_ = self->expanders;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp17_, webview_tools);
	_g_object_unref0 (generate_html_button);
	_g_object_unref0 (export_fonts_button);
	_g_object_unref0 (update_webview_button);
	_g_object_unref0 (font_name);
	_g_object_unref0 (webview_tools);
	return self;
}

BirdFontPreviewTools*
bird_font_preview_tools_new (void)
{
	return bird_font_preview_tools_construct (BIRD_FONT_TYPE_PREVIEW_TOOLS);
}

/** Export fonts and update html canvas. */
static void
_bird_font_preview_tools_signal_preview_updated_bird_font_export_callback_file_exported (BirdFontExportCallback* _sender,
                                                                                         gpointer self)
{
	bird_font_preview_tools_signal_preview_updated ();
}

void
bird_font_preview_tools_update_preview (void)
{
	BirdFontExportCallback* _tmp0_;
	BirdFontExportCallback* _tmp1_;
	BirdFontExportCallback* _tmp2_;
	BirdFontExportCallback* _tmp3_;
	_tmp0_ = bird_font_export_callback_new ();
	_g_object_unref0 (bird_font_menu_tab_export_callback);
	bird_font_menu_tab_export_callback = _tmp0_;
	_tmp1_ = bird_font_menu_tab_export_callback;
	_tmp1_->preview = TRUE;
	_tmp2_ = bird_font_menu_tab_export_callback;
	g_signal_connect (_tmp2_, "file-exported", (GCallback) _bird_font_preview_tools_signal_preview_updated_bird_font_export_callback_file_exported, NULL);
	_tmp3_ = bird_font_menu_tab_export_callback;
	bird_font_export_callback_export_fonts_in_background (_tmp3_);
}

static gboolean
__lambda213_ (void)
{
	const gchar* _tmp0_;
	gboolean result;
	if (!bird_font_preview_has_html_document ()) {
		bird_font_preview_generate_html_document ();
	}
	_tmp0_ = bird_font_export_tool_error_message;
	if (_tmp0_ == NULL) {
		BirdFontTabBar* _tmp1_;
		_tmp1_ = bird_font_main_window_tabs;
		bird_font_tab_bar_select_tab_name (_tmp1_, "Preview");
	}
	result = FALSE;
	return result;
}

static gboolean
___lambda213__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda213_ ();
	return result;
}

static void
bird_font_preview_tools_signal_preview_updated (void)
{
	GSource* idle = NULL;
	GSource* _tmp0_;
	_tmp0_ = g_idle_source_new ();
	idle = _tmp0_;
	g_source_set_callback (idle, ___lambda213__gsource_func, NULL, NULL);
	g_source_attach (idle, NULL);
	_g_source_unref0 (idle);
}

/** Generate the preview document. */
void
bird_font_preview_tools_generate_html_document (void)
{
	bird_font_preview_delete_html_document ();
	bird_font_preview_generate_html_document ();
}

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

static GeeArrayList*
bird_font_preview_tools_real_get_expanders (BirdFontToolCollection* base)
{
	BirdFontPreviewTools * self;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* result;
	self = (BirdFontPreviewTools*) base;
	_tmp0_ = self->expanders;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static GeeArrayList*
bird_font_preview_tools_real_get_displays (BirdFontToolCollection* base)
{
	BirdFontPreviewTools * self;
	GeeArrayList* d = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* result;
	self = (BirdFontPreviewTools*) base;
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	d = _tmp0_;
	gee_abstract_collection_add ((GeeAbstractCollection*) d, "Preview");
	result = d;
	return result;
}

static void
bird_font_preview_tools_class_init (BirdFontPreviewToolsClass * klass,
                                    gpointer klass_data)
{
	bird_font_preview_tools_parent_class = g_type_class_peek_parent (klass);
	((BirdFontToolCollectionClass *) klass)->get_expanders = (GeeArrayList* (*) (BirdFontToolCollection*)) bird_font_preview_tools_real_get_expanders;
	((BirdFontToolCollectionClass *) klass)->get_displays = (GeeArrayList* (*) (BirdFontToolCollection*)) bird_font_preview_tools_real_get_displays;
	G_OBJECT_CLASS (klass)->finalize = bird_font_preview_tools_finalize;
}

static void
bird_font_preview_tools_instance_init (BirdFontPreviewTools * self,
                                       gpointer klass)
{
	GeeArrayList* _tmp0_;
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_EXPANDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->expanders = _tmp0_;
}

static void
bird_font_preview_tools_finalize (GObject * obj)
{
	BirdFontPreviewTools * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_PREVIEW_TOOLS, BirdFontPreviewTools);
	_g_object_unref0 (self->expanders);
	_g_object_unref0 (self->classes);
	G_OBJECT_CLASS (bird_font_preview_tools_parent_class)->finalize (obj);
}

static GType
bird_font_preview_tools_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontPreviewToolsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_preview_tools_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontPreviewTools), 0, (GInstanceInitFunc) bird_font_preview_tools_instance_init, NULL };
	GType bird_font_preview_tools_type_id;
	bird_font_preview_tools_type_id = g_type_register_static (BIRD_FONT_TYPE_TOOL_COLLECTION, "BirdFontPreviewTools", &g_define_type_info, 0);
	return bird_font_preview_tools_type_id;
}

GType
bird_font_preview_tools_get_type (void)
{
	static volatile gsize bird_font_preview_tools_type_id__once = 0;
	if (g_once_init_enter (&bird_font_preview_tools_type_id__once)) {
		GType bird_font_preview_tools_type_id;
		bird_font_preview_tools_type_id = bird_font_preview_tools_get_type_once ();
		g_once_init_leave (&bird_font_preview_tools_type_id__once, bird_font_preview_tools_type_id);
	}
	return bird_font_preview_tools_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;
}

