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

/* -*- mode: vala; indent-tabs-mode: nil -*-*/
/* Copyright (C) 2011  Daiki Ueno*/
/* Copyright (C) 2011  Red Hat, Inc.*/
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA*/
/* 02110-1301, USA.*/

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <ibus.h>
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>


#define IBUS_GUCHARMAP_TYPE_SETUP (ibus_gucharmap_setup_get_type ())
#define IBUS_GUCHARMAP_SETUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_GUCHARMAP_TYPE_SETUP, IBusGucharmapSetup))
#define IBUS_GUCHARMAP_SETUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_GUCHARMAP_TYPE_SETUP, IBusGucharmapSetupClass))
#define IBUS_GUCHARMAP_IS_SETUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_GUCHARMAP_TYPE_SETUP))
#define IBUS_GUCHARMAP_IS_SETUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_GUCHARMAP_TYPE_SETUP))
#define IBUS_GUCHARMAP_SETUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_GUCHARMAP_TYPE_SETUP, IBusGucharmapSetupClass))

typedef struct _IBusGucharmapSetup IBusGucharmapSetup;
typedef struct _IBusGucharmapSetupClass IBusGucharmapSetupClass;
typedef struct _IBusGucharmapSetupPrivate IBusGucharmapSetupPrivate;

#define IBUS_GUCHARMAP_TYPE_CONFIG_CACHE (ibus_gucharmap_config_cache_get_type ())
#define IBUS_GUCHARMAP_CONFIG_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_GUCHARMAP_TYPE_CONFIG_CACHE, IBusGucharmapConfigCache))
#define IBUS_GUCHARMAP_CONFIG_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_GUCHARMAP_TYPE_CONFIG_CACHE, IBusGucharmapConfigCacheClass))
#define IBUS_GUCHARMAP_IS_CONFIG_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_GUCHARMAP_TYPE_CONFIG_CACHE))
#define IBUS_GUCHARMAP_IS_CONFIG_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_GUCHARMAP_TYPE_CONFIG_CACHE))
#define IBUS_GUCHARMAP_CONFIG_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_GUCHARMAP_TYPE_CONFIG_CACHE, IBusGucharmapConfigCacheClass))

typedef struct _IBusGucharmapConfigCache IBusGucharmapConfigCache;
typedef struct _IBusGucharmapConfigCacheClass IBusGucharmapConfigCacheClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _IBusGucharmapSetup {
	GObject parent_instance;
	IBusGucharmapSetupPrivate * priv;
};

struct _IBusGucharmapSetupClass {
	GObjectClass parent_class;
};

struct _IBusGucharmapSetupPrivate {
	IBusGucharmapConfigCache* config;
	GtkDialog* dialog;
	GtkCheckButton* use_system_font_checkbutton;
	GtkFontButton* fontbutton;
	GtkSpinButton* number_of_matches_spinbutton;
};


static gpointer ibus_gucharmap_setup_parent_class = NULL;

GType ibus_gucharmap_setup_get_type (void) G_GNUC_CONST;
GType ibus_gucharmap_config_cache_get_type (void) G_GNUC_CONST;
#define IBUS_GUCHARMAP_SETUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_GUCHARMAP_TYPE_SETUP, IBusGucharmapSetupPrivate))
enum  {
	IBUS_GUCHARMAP_SETUP_DUMMY_PROPERTY
};
IBusGucharmapSetup* ibus_gucharmap_setup_new (IBusConfig* _config);
IBusGucharmapSetup* ibus_gucharmap_setup_construct (GType object_type, IBusConfig* _config);
static void _lambda1_ (GtkToggleButton* checkbutton, IBusGucharmapSetup* self);
static void __lambda1__gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self);
IBusGucharmapConfigCache* ibus_gucharmap_config_cache_new (IBusConfig* config);
IBusGucharmapConfigCache* ibus_gucharmap_config_cache_construct (GType object_type, IBusConfig* config);
static void ibus_gucharmap_setup_load_config (IBusGucharmapSetup* self);
static void _ibus_gucharmap_setup_load_config_ibus_gucharmap_config_cache_changed (IBusGucharmapConfigCache* _sender, gpointer self);
gboolean ibus_gucharmap_config_cache_get_use_system_font (IBusGucharmapConfigCache* self);
const gchar* ibus_gucharmap_config_cache_get_font (IBusGucharmapConfigCache* self);
gint ibus_gucharmap_config_cache_get_number_of_matches (IBusGucharmapConfigCache* self);
void ibus_gucharmap_setup_run (IBusGucharmapSetup* self);
void ibus_gucharmap_config_cache_set_use_system_font (IBusGucharmapConfigCache* self, gboolean value);
void ibus_gucharmap_config_cache_set_font (IBusGucharmapConfigCache* self, const gchar* value);
void ibus_gucharmap_config_cache_set_number_of_matches (IBusGucharmapConfigCache* self, gint value);
void ibus_gucharmap_config_cache_save (IBusGucharmapConfigCache* self);
static void ibus_gucharmap_setup_finalize (GObject* obj);


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


static void _lambda1_ (GtkToggleButton* checkbutton, IBusGucharmapSetup* self) {
	gboolean _tmp0_;
	g_return_if_fail (checkbutton != NULL);
	_tmp0_ = gtk_toggle_button_get_active (checkbutton);
	gtk_widget_set_sensitive ((GtkWidget*) self->priv->fontbutton, !_tmp0_);
}


static void __lambda1__gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
	_lambda1_ (_sender, self);
}


static void _ibus_gucharmap_setup_load_config_ibus_gucharmap_config_cache_changed (IBusGucharmapConfigCache* _sender, gpointer self) {
	ibus_gucharmap_setup_load_config (self);
}


IBusGucharmapSetup* ibus_gucharmap_setup_construct (GType object_type, IBusConfig* _config) {
	IBusGucharmapSetup * self = NULL;
	GtkBuilder* _tmp0_ = NULL;
	GtkBuilder* builder;
	GObject* _tmp1_ = NULL;
	GObject* _tmp2_;
	GObject* object;
	GtkDialog* _tmp3_;
	GObject* _tmp4_ = NULL;
	GObject* _tmp5_;
	GtkFontButton* _tmp6_;
	GObject* _tmp7_ = NULL;
	GObject* _tmp8_;
	GtkCheckButton* _tmp9_;
	GObject* _tmp10_ = NULL;
	GObject* _tmp11_;
	GtkSpinButton* _tmp12_;
	IBusGucharmapConfigCache* _tmp13_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (_config != NULL, NULL);
	self = (IBusGucharmapSetup*) g_object_new (object_type, NULL);
	_tmp0_ = gtk_builder_new ();
	builder = _tmp0_;
	gtk_builder_set_translation_domain (builder, "ibus-gucharmap");
	gtk_builder_add_from_file (builder, SETUPDIR "/ibus-gucharmap-preferences.ui", &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (builder);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp1_ = gtk_builder_get_object (builder, "dialog");
	_tmp2_ = _g_object_ref0 (_tmp1_);
	object = _tmp2_;
	_tmp3_ = _g_object_ref0 (GTK_DIALOG (object));
	_g_object_unref0 (self->priv->dialog);
	self->priv->dialog = _tmp3_;
	_tmp4_ = gtk_builder_get_object (builder, "fontbutton");
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_g_object_unref0 (object);
	object = _tmp5_;
	_tmp6_ = _g_object_ref0 (GTK_FONT_BUTTON (object));
	_g_object_unref0 (self->priv->fontbutton);
	self->priv->fontbutton = _tmp6_;
	_tmp7_ = gtk_builder_get_object (builder, "use_system_font_checkbutton");
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (object);
	object = _tmp8_;
	_tmp9_ = _g_object_ref0 (GTK_CHECK_BUTTON (object));
	_g_object_unref0 (self->priv->use_system_font_checkbutton);
	self->priv->use_system_font_checkbutton = _tmp9_;
	_tmp10_ = gtk_builder_get_object (builder, "number_of_matches_spinbutton");
	_tmp11_ = _g_object_ref0 (_tmp10_);
	_g_object_unref0 (object);
	object = _tmp11_;
	_tmp12_ = _g_object_ref0 (GTK_SPIN_BUTTON (object));
	_g_object_unref0 (self->priv->number_of_matches_spinbutton);
	self->priv->number_of_matches_spinbutton = _tmp12_;
	g_signal_connect_object ((GtkToggleButton*) self->priv->use_system_font_checkbutton, "toggled", (GCallback) __lambda1__gtk_toggle_button_toggled, self, 0);
	_tmp13_ = ibus_gucharmap_config_cache_new (_config);
	_g_object_unref0 (self->priv->config);
	self->priv->config = _tmp13_;
	ibus_gucharmap_setup_load_config (self);
	g_signal_connect_object (self->priv->config, "changed", (GCallback) _ibus_gucharmap_setup_load_config_ibus_gucharmap_config_cache_changed, self, 0);
	_g_object_unref0 (object);
	_g_object_unref0 (builder);
	return self;
}


IBusGucharmapSetup* ibus_gucharmap_setup_new (IBusConfig* _config) {
	return ibus_gucharmap_setup_construct (IBUS_GUCHARMAP_TYPE_SETUP, _config);
}


static void ibus_gucharmap_setup_load_config (IBusGucharmapSetup* self) {
	gboolean _tmp0_;
	const gchar* _tmp1_ = NULL;
	gint _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ibus_gucharmap_config_cache_get_use_system_font (self->priv->config);
	gtk_toggle_button_set_active ((GtkToggleButton*) self->priv->use_system_font_checkbutton, _tmp0_);
	_tmp1_ = ibus_gucharmap_config_cache_get_font (self->priv->config);
	gtk_font_button_set_font_name (self->priv->fontbutton, _tmp1_);
	_tmp2_ = ibus_gucharmap_config_cache_get_number_of_matches (self->priv->config);
	gtk_spin_button_set_value (self->priv->number_of_matches_spinbutton, (gdouble) _tmp2_);
}


void ibus_gucharmap_setup_run (IBusGucharmapSetup* self) {
	gboolean _tmp0_;
	const gchar* _tmp1_ = NULL;
	gdouble _tmp2_;
	g_return_if_fail (self != NULL);
	gtk_dialog_run (self->priv->dialog);
	_tmp0_ = gtk_toggle_button_get_active ((GtkToggleButton*) self->priv->use_system_font_checkbutton);
	ibus_gucharmap_config_cache_set_use_system_font (self->priv->config, _tmp0_);
	_tmp1_ = gtk_font_button_get_font_name (self->priv->fontbutton);
	ibus_gucharmap_config_cache_set_font (self->priv->config, _tmp1_);
	_tmp2_ = gtk_spin_button_get_value (self->priv->number_of_matches_spinbutton);
	ibus_gucharmap_config_cache_set_number_of_matches (self->priv->config, (gint) ((gint32) _tmp2_));
	ibus_gucharmap_config_cache_save (self->priv->config);
}


static void ibus_gucharmap_setup_class_init (IBusGucharmapSetupClass * klass) {
	ibus_gucharmap_setup_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (IBusGucharmapSetupPrivate));
	G_OBJECT_CLASS (klass)->finalize = ibus_gucharmap_setup_finalize;
}


static void ibus_gucharmap_setup_instance_init (IBusGucharmapSetup * self) {
	self->priv = IBUS_GUCHARMAP_SETUP_GET_PRIVATE (self);
}


static void ibus_gucharmap_setup_finalize (GObject* obj) {
	IBusGucharmapSetup * self;
	self = IBUS_GUCHARMAP_SETUP (obj);
	_g_object_unref0 (self->priv->config);
	_g_object_unref0 (self->priv->dialog);
	_g_object_unref0 (self->priv->use_system_font_checkbutton);
	_g_object_unref0 (self->priv->fontbutton);
	_g_object_unref0 (self->priv->number_of_matches_spinbutton);
	G_OBJECT_CLASS (ibus_gucharmap_setup_parent_class)->finalize (obj);
}


GType ibus_gucharmap_setup_get_type (void) {
	static volatile gsize ibus_gucharmap_setup_type_id__volatile = 0;
	if (g_once_init_enter (&ibus_gucharmap_setup_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (IBusGucharmapSetupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ibus_gucharmap_setup_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IBusGucharmapSetup), 0, (GInstanceInitFunc) ibus_gucharmap_setup_instance_init, NULL };
		GType ibus_gucharmap_setup_type_id;
		ibus_gucharmap_setup_type_id = g_type_register_static (G_TYPE_OBJECT, "IBusGucharmapSetup", &g_define_type_info, 0);
		g_once_init_leave (&ibus_gucharmap_setup_type_id__volatile, ibus_gucharmap_setup_type_id);
	}
	return ibus_gucharmap_setup_type_id__volatile;
}



