/* config-cache.c generated by valac 0.12.0, the Vala compiler
 * generated from config-cache.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 <ibus.h>
#include <stdlib.h>
#include <string.h>


#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;
typedef struct _IBusGucharmapConfigCachePrivate IBusGucharmapConfigCachePrivate;
#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_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _IBusGucharmapConfigCache {
	GObject parent_instance;
	IBusGucharmapConfigCachePrivate * priv;
};

struct _IBusGucharmapConfigCacheClass {
	GObjectClass parent_class;
};

struct _IBusGucharmapConfigCachePrivate {
	IBusConfig* config;
	gboolean dirty;
	gboolean loaded;
	gboolean _use_system_font;
	gchar* _font;
	gint _number_of_matches;
};


static gpointer ibus_gucharmap_config_cache_parent_class = NULL;

GType ibus_gucharmap_config_cache_get_type (void) G_GNUC_CONST;
#define IBUS_GUCHARMAP_CONFIG_CACHE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_GUCHARMAP_TYPE_CONFIG_CACHE, IBusGucharmapConfigCachePrivate))
enum  {
	IBUS_GUCHARMAP_CONFIG_CACHE_DUMMY_PROPERTY,
	IBUS_GUCHARMAP_CONFIG_CACHE_USE_SYSTEM_FONT,
	IBUS_GUCHARMAP_CONFIG_CACHE_FONT,
	IBUS_GUCHARMAP_CONFIG_CACHE_NUMBER_OF_MATCHES
};
#define IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION "engine/Gucharmap"
IBusGucharmapConfigCache* ibus_gucharmap_config_cache_new (IBusConfig* config);
IBusGucharmapConfigCache* ibus_gucharmap_config_cache_construct (GType object_type, IBusConfig* config);
static void _lambda0_ (IBusConfig* config, const gchar* section, const gchar* name, GVariant* value, IBusGucharmapConfigCache* self);
static void __lambda0__ibus_config_value_changed (IBusConfig* _sender, const gchar* p0, const gchar* p1, GVariant* p2, gpointer self);
static void ibus_gucharmap_config_cache_load (IBusGucharmapConfigCache* self);
void ibus_gucharmap_config_cache_save (IBusGucharmapConfigCache* self);
gboolean ibus_gucharmap_config_cache_get_use_system_font (IBusGucharmapConfigCache* self);
void ibus_gucharmap_config_cache_set_use_system_font (IBusGucharmapConfigCache* self, gboolean value);
const gchar* ibus_gucharmap_config_cache_get_font (IBusGucharmapConfigCache* self);
void ibus_gucharmap_config_cache_set_font (IBusGucharmapConfigCache* self, const gchar* value);
gint ibus_gucharmap_config_cache_get_number_of_matches (IBusGucharmapConfigCache* self);
void ibus_gucharmap_config_cache_set_number_of_matches (IBusGucharmapConfigCache* self, gint value);
static void ibus_gucharmap_config_cache_finalize (GObject* obj);
static void _vala_ibus_gucharmap_config_cache_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_ibus_gucharmap_config_cache_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


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


static void _lambda0_ (IBusConfig* config, const gchar* section, const gchar* name, GVariant* value, IBusGucharmapConfigCache* self) {
	g_return_if_fail (config != NULL);
	g_return_if_fail (section != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	self->priv->loaded = FALSE;
	g_signal_emit_by_name (self, "changed");
}


static void __lambda0__ibus_config_value_changed (IBusConfig* _sender, const gchar* p0, const gchar* p1, GVariant* p2, gpointer self) {
	_lambda0_ (_sender, p0, p1, p2, self);
}


IBusGucharmapConfigCache* ibus_gucharmap_config_cache_construct (GType object_type, IBusConfig* config) {
	IBusGucharmapConfigCache * self = NULL;
	IBusConfig* _tmp0_;
	g_return_val_if_fail (config != NULL, NULL);
	self = (IBusGucharmapConfigCache*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (config);
	_g_object_unref0 (self->priv->config);
	self->priv->config = _tmp0_;
	g_signal_connect_object (self->priv->config, "value-changed", (GCallback) __lambda0__ibus_config_value_changed, self, 0);
	return self;
}


IBusGucharmapConfigCache* ibus_gucharmap_config_cache_new (IBusConfig* config) {
	return ibus_gucharmap_config_cache_construct (IBUS_GUCHARMAP_TYPE_CONFIG_CACHE, config);
}


static void ibus_gucharmap_config_cache_load (IBusGucharmapConfigCache* self) {
	g_return_if_fail (self != NULL);
	if (!self->priv->loaded) {
		GVariant* value = NULL;
		GVariant* _tmp0_ = NULL;
		GVariant* _tmp2_ = NULL;
		GVariant* _tmp5_ = NULL;
		_tmp0_ = ibus_config_get_value (self->priv->config, IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION, "use_system_font");
		_g_variant_unref0 (value);
		value = _tmp0_;
		if (value != NULL) {
			gboolean _tmp1_;
			_tmp1_ = g_variant_get_boolean (value);
			self->priv->_use_system_font = _tmp1_;
		}
		_tmp2_ = ibus_config_get_value (self->priv->config, IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION, "font");
		_g_variant_unref0 (value);
		value = _tmp2_;
		if (value != NULL) {
			const gchar* _tmp3_ = NULL;
			gchar* _tmp4_;
			_tmp3_ = g_variant_get_string (value, NULL);
			_tmp4_ = g_strdup (_tmp3_);
			_g_free0 (self->priv->_font);
			self->priv->_font = _tmp4_;
		}
		_tmp5_ = ibus_config_get_value (self->priv->config, IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION, "number_of_matches");
		_g_variant_unref0 (value);
		value = _tmp5_;
		if (value != NULL) {
			gint32 _tmp6_;
			_tmp6_ = g_variant_get_int32 (value);
			self->priv->_number_of_matches = (gint) _tmp6_;
		}
		_g_variant_unref0 (value);
	}
}


void ibus_gucharmap_config_cache_save (IBusGucharmapConfigCache* self) {
	g_return_if_fail (self != NULL);
	if (self->priv->dirty) {
		GVariant* _tmp0_ = NULL;
		GVariant* _tmp1_;
		GVariant* _tmp2_ = NULL;
		GVariant* _tmp3_;
		GVariant* _tmp4_ = NULL;
		GVariant* _tmp5_;
		_tmp0_ = g_variant_new_boolean (self->priv->_use_system_font);
		_tmp1_ = g_variant_ref_sink (_tmp0_);
		ibus_config_set_value (self->priv->config, IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION, "use_system_font", _tmp1_);
		_g_variant_unref0 (_tmp1_);
		_tmp2_ = g_variant_new_string (self->priv->_font);
		_tmp3_ = g_variant_ref_sink (_tmp2_);
		ibus_config_set_value (self->priv->config, IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION, "font", _tmp3_);
		_g_variant_unref0 (_tmp3_);
		_tmp4_ = g_variant_new_int32 ((gint32) self->priv->_number_of_matches);
		_tmp5_ = g_variant_ref_sink (_tmp4_);
		ibus_config_set_value (self->priv->config, IBUS_GUCHARMAP_CONFIG_CACHE_CONFIG_SECTION, "number_of_matches", _tmp5_);
		_g_variant_unref0 (_tmp5_);
		self->priv->dirty = FALSE;
	}
}


gboolean ibus_gucharmap_config_cache_get_use_system_font (IBusGucharmapConfigCache* self) {
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (!self->priv->loaded) {
		ibus_gucharmap_config_cache_load (self);
	}
	result = self->priv->_use_system_font;
	return result;
}


void ibus_gucharmap_config_cache_set_use_system_font (IBusGucharmapConfigCache* self, gboolean value) {
	g_return_if_fail (self != NULL);
	if (value != self->priv->_use_system_font) {
		self->priv->dirty = TRUE;
		self->priv->_use_system_font = value;
	}
	g_object_notify ((GObject *) self, "use-system-font");
}


const gchar* ibus_gucharmap_config_cache_get_font (IBusGucharmapConfigCache* self) {
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (!self->priv->loaded) {
		ibus_gucharmap_config_cache_load (self);
	}
	result = self->priv->_font;
	return result;
}


void ibus_gucharmap_config_cache_set_font (IBusGucharmapConfigCache* self, const gchar* value) {
	g_return_if_fail (self != NULL);
	if (g_strcmp0 (value, self->priv->_font) != 0) {
		gchar* _tmp0_;
		self->priv->dirty = TRUE;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_font);
		self->priv->_font = _tmp0_;
	}
	g_object_notify ((GObject *) self, "font");
}


gint ibus_gucharmap_config_cache_get_number_of_matches (IBusGucharmapConfigCache* self) {
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	if (!self->priv->loaded) {
		ibus_gucharmap_config_cache_load (self);
	}
	result = self->priv->_number_of_matches;
	return result;
}


void ibus_gucharmap_config_cache_set_number_of_matches (IBusGucharmapConfigCache* self, gint value) {
	g_return_if_fail (self != NULL);
	if (value != self->priv->_number_of_matches) {
		self->priv->dirty = TRUE;
		self->priv->_number_of_matches = value;
	}
	g_object_notify ((GObject *) self, "number-of-matches");
}


static void ibus_gucharmap_config_cache_class_init (IBusGucharmapConfigCacheClass * klass) {
	ibus_gucharmap_config_cache_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (IBusGucharmapConfigCachePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_ibus_gucharmap_config_cache_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ibus_gucharmap_config_cache_set_property;
	G_OBJECT_CLASS (klass)->finalize = ibus_gucharmap_config_cache_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), IBUS_GUCHARMAP_CONFIG_CACHE_USE_SYSTEM_FONT, g_param_spec_boolean ("use-system-font", "use-system-font", "use-system-font", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), IBUS_GUCHARMAP_CONFIG_CACHE_FONT, g_param_spec_string ("font", "font", "font", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), IBUS_GUCHARMAP_CONFIG_CACHE_NUMBER_OF_MATCHES, g_param_spec_int ("number-of-matches", "number-of-matches", "number-of-matches", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_signal_new ("changed", IBUS_GUCHARMAP_TYPE_CONFIG_CACHE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void ibus_gucharmap_config_cache_instance_init (IBusGucharmapConfigCache * self) {
	gchar* _tmp0_;
	self->priv = IBUS_GUCHARMAP_CONFIG_CACHE_GET_PRIVATE (self);
	self->priv->dirty = FALSE;
	self->priv->loaded = FALSE;
	self->priv->_use_system_font = TRUE;
	_tmp0_ = g_strdup ("Sans 12");
	self->priv->_font = _tmp0_;
	self->priv->_number_of_matches = 100;
}


static void ibus_gucharmap_config_cache_finalize (GObject* obj) {
	IBusGucharmapConfigCache * self;
	self = IBUS_GUCHARMAP_CONFIG_CACHE (obj);
	_g_object_unref0 (self->priv->config);
	_g_free0 (self->priv->_font);
	G_OBJECT_CLASS (ibus_gucharmap_config_cache_parent_class)->finalize (obj);
}


GType ibus_gucharmap_config_cache_get_type (void) {
	static volatile gsize ibus_gucharmap_config_cache_type_id__volatile = 0;
	if (g_once_init_enter (&ibus_gucharmap_config_cache_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (IBusGucharmapConfigCacheClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ibus_gucharmap_config_cache_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IBusGucharmapConfigCache), 0, (GInstanceInitFunc) ibus_gucharmap_config_cache_instance_init, NULL };
		GType ibus_gucharmap_config_cache_type_id;
		ibus_gucharmap_config_cache_type_id = g_type_register_static (G_TYPE_OBJECT, "IBusGucharmapConfigCache", &g_define_type_info, 0);
		g_once_init_leave (&ibus_gucharmap_config_cache_type_id__volatile, ibus_gucharmap_config_cache_type_id);
	}
	return ibus_gucharmap_config_cache_type_id__volatile;
}


static void _vala_ibus_gucharmap_config_cache_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	IBusGucharmapConfigCache * self;
	self = IBUS_GUCHARMAP_CONFIG_CACHE (object);
	switch (property_id) {
		case IBUS_GUCHARMAP_CONFIG_CACHE_USE_SYSTEM_FONT:
		g_value_set_boolean (value, ibus_gucharmap_config_cache_get_use_system_font (self));
		break;
		case IBUS_GUCHARMAP_CONFIG_CACHE_FONT:
		g_value_set_string (value, ibus_gucharmap_config_cache_get_font (self));
		break;
		case IBUS_GUCHARMAP_CONFIG_CACHE_NUMBER_OF_MATCHES:
		g_value_set_int (value, ibus_gucharmap_config_cache_get_number_of_matches (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_ibus_gucharmap_config_cache_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	IBusGucharmapConfigCache * self;
	self = IBUS_GUCHARMAP_CONFIG_CACHE (object);
	switch (property_id) {
		case IBUS_GUCHARMAP_CONFIG_CACHE_USE_SYSTEM_FONT:
		ibus_gucharmap_config_cache_set_use_system_font (self, g_value_get_boolean (value));
		break;
		case IBUS_GUCHARMAP_CONFIG_CACHE_FONT:
		ibus_gucharmap_config_cache_set_font (self, g_value_get_string (value));
		break;
		case IBUS_GUCHARMAP_CONFIG_CACHE_NUMBER_OF_MATCHES:
		ibus_gucharmap_config_cache_set_number_of_matches (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



