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

/*
* Copyright 2021 elementary, Inc. (https://elementary.io)
*
* 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 3 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/

#include "pantheon-desktop.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <float.h>
#include <math.h>
#include <handy.h>
#include <gdk/gdk.h>

#define PANTHEON_SHELL_TEXT_DYSLEXIA_KEY "dyslexia-friendly-support"
#define PANTHEON_SHELL_TEXT_FONT_KEY "font-name"
#define PANTHEON_SHELL_TEXT_DOCUMENT_FONT_KEY "document-font-name"
#define PANTHEON_SHELL_TEXT_MONOSPACE_FONT_KEY "monospace-font-name"
#define PANTHEON_SHELL_TEXT_OD_REG_FONT "OpenDyslexic Regular 9"
#define PANTHEON_SHELL_TEXT_OD_DOC_FONT "OpenDyslexic Regular 10"
#define PANTHEON_SHELL_TEXT_OD_MON_FONT "OpenDyslexicMono Regular 10"

enum  {
	PANTHEON_SHELL_TEXT_0_PROPERTY,
	PANTHEON_SHELL_TEXT_NUM_PROPERTIES
};
static GParamSpec* pantheon_shell_text_properties[PANTHEON_SHELL_TEXT_NUM_PROPERTIES];
typedef struct _Block4Data Block4Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _PantheonShellTextPrivate {
	guint scale_timeout;
};

struct _Block4Data {
	int _ref_count_;
	PantheonShellText* self;
	GtkAdjustment* size_adjustment;
	GtkSwitch* dyslexia_font_switch;
	GSettings* interface_settings;
};

static gint PantheonShellText_private_offset;
static gpointer pantheon_shell_text_parent_class = NULL;

static GObject * pantheon_shell_text_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void _pantheon_shell_text___lambda32_ (Block4Data* _data4_);
static gboolean __lambda33_ (Block4Data* _data4_);
static gboolean ___lambda33__gsource_func (gpointer self);
static void __pantheon_shell_text___lambda32__gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                     gpointer self);
static gboolean _pantheon_shell_text___lambda34_ (Block4Data* _data4_);
static gboolean __pantheon_shell_text___lambda34__gtk_switch_state_set (GtkSwitch* _sender,
                                                                 gboolean state,
                                                                 gpointer self);
static void pantheon_shell_text_finalize (GObject * obj);
static GType pantheon_shell_text_get_type_once (void);

static inline gpointer
pantheon_shell_text_get_instance_private (PantheonShellText* self)
{
	return G_STRUCT_MEMBER_P (self, PantheonShellText_private_offset);
}

PantheonShellText*
pantheon_shell_text_construct (GType object_type)
{
	PantheonShellText * self = NULL;
	self = (PantheonShellText*) g_object_new (object_type, NULL);
	return self;
}

PantheonShellText*
pantheon_shell_text_new (void)
{
	return pantheon_shell_text_construct (PANTHEON_SHELL_TYPE_TEXT);
}

static Block4Data*
block4_data_ref (Block4Data* _data4_)
{
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}

static void
block4_data_unref (void * _userdata_)
{
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		PantheonShellText* self;
		self = _data4_->self;
		_g_object_unref0 (_data4_->interface_settings);
		_g_object_unref0 (_data4_->dyslexia_font_switch);
		_g_object_unref0 (_data4_->size_adjustment);
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}

static gboolean
__lambda33_ (Block4Data* _data4_)
{
	PantheonShellText* self;
	GSettings* _tmp0_;
	GtkAdjustment* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	gboolean result;
	self = _data4_->self;
	self->priv->scale_timeout = (guint) 0;
	_tmp0_ = _data4_->interface_settings;
	_tmp1_ = _data4_->size_adjustment;
	_tmp2_ = gtk_adjustment_get_value (_tmp1_);
	_tmp3_ = _tmp2_;
	g_settings_set_double (_tmp0_, "text-scaling-factor", _tmp3_);
	result = FALSE;
	return result;
}

static gboolean
___lambda33__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda33_ (self);
	return result;
}

static void
_pantheon_shell_text___lambda32_ (Block4Data* _data4_)
{
	PantheonShellText* self;
	self = _data4_->self;
	if (self->priv->scale_timeout != ((guint) 0)) {
		g_source_remove (self->priv->scale_timeout);
	}
	self->priv->scale_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 300, ___lambda33__gsource_func, block4_data_ref (_data4_), block4_data_unref);
}

static void
__pantheon_shell_text___lambda32__gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                gpointer self)
{
	_pantheon_shell_text___lambda32_ (self);
}

static gboolean
_pantheon_shell_text___lambda34_ (Block4Data* _data4_)
{
	PantheonShellText* self;
	GtkSwitch* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	self = _data4_->self;
	_tmp0_ = _data4_->dyslexia_font_switch;
	_tmp1_ = gtk_switch_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GSettings* _tmp3_;
		GSettings* _tmp4_;
		GSettings* _tmp5_;
		_tmp3_ = _data4_->interface_settings;
		g_settings_set_string (_tmp3_, PANTHEON_SHELL_TEXT_FONT_KEY, PANTHEON_SHELL_TEXT_OD_REG_FONT);
		_tmp4_ = _data4_->interface_settings;
		g_settings_set_string (_tmp4_, PANTHEON_SHELL_TEXT_DOCUMENT_FONT_KEY, PANTHEON_SHELL_TEXT_OD_DOC_FONT);
		_tmp5_ = _data4_->interface_settings;
		g_settings_set_string (_tmp5_, PANTHEON_SHELL_TEXT_MONOSPACE_FONT_KEY, PANTHEON_SHELL_TEXT_OD_MON_FONT);
	} else {
		GSettings* _tmp6_;
		GSettings* _tmp7_;
		GSettings* _tmp8_;
		_tmp6_ = _data4_->interface_settings;
		g_settings_reset (_tmp6_, PANTHEON_SHELL_TEXT_FONT_KEY);
		_tmp7_ = _data4_->interface_settings;
		g_settings_reset (_tmp7_, PANTHEON_SHELL_TEXT_DOCUMENT_FONT_KEY);
		_tmp8_ = _data4_->interface_settings;
		g_settings_reset (_tmp8_, PANTHEON_SHELL_TEXT_MONOSPACE_FONT_KEY);
	}
	result = GDK_EVENT_PROPAGATE;
	return result;
}

static gboolean
__pantheon_shell_text___lambda34__gtk_switch_state_set (GtkSwitch* _sender,
                                                        gboolean state,
                                                        gpointer self)
{
	gboolean result;
	result = _pantheon_shell_text___lambda34_ (self);
	return result;
}

static GObject *
pantheon_shell_text_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PantheonShellText * self;
	Block4Data* _data4_;
	GtkLabel* size_label = NULL;
	GtkLabel* _tmp0_ = NULL;
	GtkAdjustment* _tmp1_;
	GtkScale* size_scale = NULL;
	GtkAdjustment* _tmp2_;
	GtkScale* _tmp3_ = NULL;
	GtkScale* _tmp4_;
	GtkScale* _tmp5_;
	GtkSpinButton* size_spinbutton = NULL;
	GtkAdjustment* _tmp6_;
	GtkSpinButton* _tmp7_;
	GtkLabel* dyslexia_font_label = NULL;
	GtkLabel* _tmp8_ = NULL;
	GtkSwitch* _tmp9_ = NULL;
	GtkLabel* dyslexia_font_description_label = NULL;
	GtkLabel* _tmp10_ = NULL;
	GtkLabel* _tmp11_;
	GtkStyleContext* _tmp12_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp13_ = NULL;
	GtkGrid* _tmp14_;
	GtkLabel* _tmp15_;
	GtkGrid* _tmp16_;
	GtkScale* _tmp17_;
	GtkGrid* _tmp18_;
	GtkSpinButton* _tmp19_;
	GtkGrid* _tmp20_;
	GtkLabel* _tmp21_;
	GtkGrid* _tmp22_;
	GtkSwitch* _tmp23_;
	GtkGrid* _tmp24_;
	GtkLabel* _tmp25_;
	HdyClamp* clamp = NULL;
	HdyClamp* _tmp26_;
	HdyClamp* _tmp27_;
	GtkGrid* _tmp28_;
	HdyClamp* _tmp29_;
	GSettings* _tmp30_;
	GSettings* _tmp31_;
	GtkAdjustment* _tmp32_;
	GtkAdjustment* _tmp33_;
	gchar* interface_font = NULL;
	GSettings* _tmp34_;
	gchar* _tmp35_;
	gchar* document_font = NULL;
	GSettings* _tmp36_;
	gchar* _tmp37_;
	gchar* monospace_font = NULL;
	GSettings* _tmp38_;
	gchar* _tmp39_;
	gboolean _tmp40_ = FALSE;
	gboolean _tmp41_ = FALSE;
	const gchar* _tmp42_;
	GtkSwitch* _tmp45_;
	GtkSwitch* _tmp46_;
	parent_class = G_OBJECT_CLASS (pantheon_shell_text_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PANTHEON_SHELL_TYPE_TEXT, PantheonShellText);
	_data4_ = g_slice_new0 (Block4Data);
	_data4_->_ref_count_ = 1;
	_data4_->self = g_object_ref (self);
	_tmp0_ = (GtkLabel*) gtk_label_new (_ ("Size:"));
	gtk_widget_set_halign ((GtkWidget*) _tmp0_, GTK_ALIGN_END);
	g_object_ref_sink (_tmp0_);
	size_label = _tmp0_;
	_tmp1_ = gtk_adjustment_new ((gdouble) -1, 0.75, 1.5, 0.05, (gdouble) 0, (gdouble) 0);
	g_object_ref_sink (_tmp1_);
	_data4_->size_adjustment = _tmp1_;
	_tmp2_ = _data4_->size_adjustment;
	_tmp3_ = (GtkScale*) gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, _tmp2_);
	gtk_scale_set_draw_value (_tmp3_, FALSE);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp3_, TRUE);
	g_object_ref_sink (_tmp3_);
	size_scale = _tmp3_;
	_tmp4_ = size_scale;
	gtk_scale_add_mark (_tmp4_, (gdouble) 1, GTK_POS_TOP, NULL);
	_tmp5_ = size_scale;
	gtk_scale_add_mark (_tmp5_, 1.25, GTK_POS_TOP, NULL);
	_tmp6_ = _data4_->size_adjustment;
	_tmp7_ = (GtkSpinButton*) gtk_spin_button_new (_tmp6_, 0.25, (guint) 2);
	g_object_ref_sink (_tmp7_);
	size_spinbutton = _tmp7_;
	_tmp8_ = (GtkLabel*) gtk_label_new (_ ("Dyslexia-friendly:"));
	gtk_widget_set_halign ((GtkWidget*) _tmp8_, GTK_ALIGN_END);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp8_, 18);
	g_object_ref_sink (_tmp8_);
	dyslexia_font_label = _tmp8_;
	_tmp9_ = (GtkSwitch*) gtk_switch_new ();
	gtk_widget_set_halign ((GtkWidget*) _tmp9_, GTK_ALIGN_START);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp9_, 18);
	g_object_ref_sink (_tmp9_);
	_data4_->dyslexia_font_switch = _tmp9_;
	_tmp10_ = (GtkLabel*) gtk_label_new (_ ("Bottom-heavy shapes and increased character spacing can help improve l" \
"egibility and reading speed."));
	g_object_set (_tmp10_, "wrap", TRUE, NULL);
	gtk_label_set_xalign (_tmp10_, (gfloat) 0);
	g_object_ref_sink (_tmp10_);
	dyslexia_font_description_label = _tmp10_;
	_tmp11_ = dyslexia_font_description_label;
	_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) _tmp11_);
	gtk_style_context_add_class (_tmp12_, GTK_STYLE_CLASS_DIM_LABEL);
	_tmp13_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_spacing (_tmp13_, 12);
	gtk_grid_set_row_spacing (_tmp13_, 6);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp13_, 12);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp13_, 12);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp13_, 24);
	g_object_ref_sink (_tmp13_);
	grid = _tmp13_;
	_tmp14_ = grid;
	_tmp15_ = size_label;
	gtk_grid_attach (_tmp14_, (GtkWidget*) _tmp15_, 0, 0, 1, 1);
	_tmp16_ = grid;
	_tmp17_ = size_scale;
	gtk_grid_attach (_tmp16_, (GtkWidget*) _tmp17_, 1, 0, 1, 1);
	_tmp18_ = grid;
	_tmp19_ = size_spinbutton;
	gtk_grid_attach (_tmp18_, (GtkWidget*) _tmp19_, 2, 0, 1, 1);
	_tmp20_ = grid;
	_tmp21_ = dyslexia_font_label;
	gtk_grid_attach (_tmp20_, (GtkWidget*) _tmp21_, 0, 1, 1, 1);
	_tmp22_ = grid;
	_tmp23_ = _data4_->dyslexia_font_switch;
	gtk_grid_attach (_tmp22_, (GtkWidget*) _tmp23_, 1, 1, 1, 1);
	_tmp24_ = grid;
	_tmp25_ = dyslexia_font_description_label;
	gtk_grid_attach (_tmp24_, (GtkWidget*) _tmp25_, 1, 2, 2, 1);
	_tmp26_ = (HdyClamp*) hdy_clamp_new ();
	g_object_ref_sink (_tmp26_);
	clamp = _tmp26_;
	_tmp27_ = clamp;
	_tmp28_ = grid;
	gtk_container_add ((GtkContainer*) _tmp27_, (GtkWidget*) _tmp28_);
	_tmp29_ = clamp;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp29_);
	_tmp30_ = g_settings_new ("org.gnome.desktop.interface");
	_data4_->interface_settings = _tmp30_;
	_tmp31_ = _data4_->interface_settings;
	_tmp32_ = _data4_->size_adjustment;
	g_settings_bind (_tmp31_, "text-scaling-factor", (GObject*) _tmp32_, "value", G_SETTINGS_BIND_GET);
	_tmp33_ = _data4_->size_adjustment;
	g_signal_connect_data (_tmp33_, "value-changed", (GCallback) __pantheon_shell_text___lambda32__gtk_adjustment_value_changed, block4_data_ref (_data4_), (GClosureNotify) block4_data_unref, 0);
	_tmp34_ = _data4_->interface_settings;
	_tmp35_ = g_settings_get_string (_tmp34_, PANTHEON_SHELL_TEXT_FONT_KEY);
	interface_font = _tmp35_;
	_tmp36_ = _data4_->interface_settings;
	_tmp37_ = g_settings_get_string (_tmp36_, PANTHEON_SHELL_TEXT_DOCUMENT_FONT_KEY);
	document_font = _tmp37_;
	_tmp38_ = _data4_->interface_settings;
	_tmp39_ = g_settings_get_string (_tmp38_, PANTHEON_SHELL_TEXT_MONOSPACE_FONT_KEY);
	monospace_font = _tmp39_;
	_tmp42_ = interface_font;
	if (g_strcmp0 (_tmp42_, PANTHEON_SHELL_TEXT_OD_REG_FONT) == 0) {
		_tmp41_ = TRUE;
	} else {
		const gchar* _tmp43_;
		_tmp43_ = document_font;
		_tmp41_ = g_strcmp0 (_tmp43_, PANTHEON_SHELL_TEXT_OD_DOC_FONT) == 0;
	}
	if (_tmp41_) {
		_tmp40_ = TRUE;
	} else {
		const gchar* _tmp44_;
		_tmp44_ = monospace_font;
		_tmp40_ = g_strcmp0 (_tmp44_, PANTHEON_SHELL_TEXT_OD_MON_FONT) == 0;
	}
	_tmp45_ = _data4_->dyslexia_font_switch;
	gtk_switch_set_active (_tmp45_, _tmp40_);
	_tmp46_ = _data4_->dyslexia_font_switch;
	g_signal_connect_data (_tmp46_, "state-set", (GCallback) __pantheon_shell_text___lambda34__gtk_switch_state_set, block4_data_ref (_data4_), (GClosureNotify) block4_data_unref, 0);
	_g_free0 (monospace_font);
	_g_free0 (document_font);
	_g_free0 (interface_font);
	_g_object_unref0 (clamp);
	_g_object_unref0 (grid);
	_g_object_unref0 (dyslexia_font_description_label);
	_g_object_unref0 (dyslexia_font_label);
	_g_object_unref0 (size_spinbutton);
	_g_object_unref0 (size_scale);
	_g_object_unref0 (size_label);
	block4_data_unref (_data4_);
	_data4_ = NULL;
	return obj;
}

static void
pantheon_shell_text_class_init (PantheonShellTextClass * klass,
                                gpointer klass_data)
{
	pantheon_shell_text_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PantheonShellText_private_offset);
	G_OBJECT_CLASS (klass)->constructor = pantheon_shell_text_constructor;
	G_OBJECT_CLASS (klass)->finalize = pantheon_shell_text_finalize;
}

static void
pantheon_shell_text_instance_init (PantheonShellText * self,
                                   gpointer klass)
{
	self->priv = pantheon_shell_text_get_instance_private (self);
}

static void
pantheon_shell_text_finalize (GObject * obj)
{
	PantheonShellText * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PANTHEON_SHELL_TYPE_TEXT, PantheonShellText);
	G_OBJECT_CLASS (pantheon_shell_text_parent_class)->finalize (obj);
}

static GType
pantheon_shell_text_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PantheonShellTextClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pantheon_shell_text_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PantheonShellText), 0, (GInstanceInitFunc) pantheon_shell_text_instance_init, NULL };
	GType pantheon_shell_text_type_id;
	pantheon_shell_text_type_id = g_type_register_static (gtk_box_get_type (), "PantheonShellText", &g_define_type_info, 0);
	PantheonShellText_private_offset = g_type_add_instance_private (pantheon_shell_text_type_id, sizeof (PantheonShellTextPrivate));
	return pantheon_shell_text_type_id;
}

GType
pantheon_shell_text_get_type (void)
{
	static volatile gsize pantheon_shell_text_type_id__once = 0;
	if (g_once_init_enter (&pantheon_shell_text_type_id__once)) {
		GType pantheon_shell_text_type_id;
		pantheon_shell_text_type_id = pantheon_shell_text_get_type_once ();
		g_once_init_leave (&pantheon_shell_text_type_id__once, pantheon_shell_text_type_id);
	}
	return pantheon_shell_text_type_id__once;
}

