/* engine-main.c generated by valac 0.12.0, the Vala compiler
 * generated from engine-main.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 <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <glib/gi18n-lib.h>
#include <config.h>
#include <gtk/gtk.h>
#include <ibus.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;
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define IBUS_GUCHARMAP_TYPE_ENGINE (ibus_gucharmap_engine_get_type ())
#define IBUS_GUCHARMAP_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_GUCHARMAP_TYPE_ENGINE, IBusGucharmapEngine))
#define IBUS_GUCHARMAP_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_GUCHARMAP_TYPE_ENGINE, IBusGucharmapEngineClass))
#define IBUS_GUCHARMAP_IS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_GUCHARMAP_TYPE_ENGINE))
#define IBUS_GUCHARMAP_IS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_GUCHARMAP_TYPE_ENGINE))
#define IBUS_GUCHARMAP_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_GUCHARMAP_TYPE_ENGINE, IBusGucharmapEngineClass))

typedef struct _IBusGucharmapEngine IBusGucharmapEngine;
typedef struct _IBusGucharmapEngineClass IBusGucharmapEngineClass;


extern gboolean ibus_gucharmap_ibus;
gboolean ibus_gucharmap_ibus = FALSE;
extern IBusGucharmapConfigCache* ibus_gucharmap_config;
IBusGucharmapConfigCache* ibus_gucharmap_config = NULL;

GType ibus_gucharmap_config_cache_get_type (void) G_GNUC_CONST;
gint ibus_gucharmap_main (gchar** args, int args_length1);
static void _lambda2_ (void);
static void __lambda2__ibus_bus_disconnected (IBusBus* _sender, gpointer self);
IBusGucharmapConfigCache* ibus_gucharmap_config_cache_new (IBusConfig* config);
IBusGucharmapConfigCache* ibus_gucharmap_config_cache_construct (GType object_type, IBusConfig* config);
GType ibus_gucharmap_engine_get_type (void) G_GNUC_CONST;

const GOptionEntry IBUS_GUCHARMAP_options[2] = {{"ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus_gucharmap_ibus, "Component is executed by IBus", NULL}, {NULL}};

static void _lambda2_ (void) {
	ibus_quit ();
}


static void __lambda2__ibus_bus_disconnected (IBusBus* _sender, gpointer self) {
	_lambda2_ ();
}


gint ibus_gucharmap_main (gchar** args, int args_length1) {
	gint result = 0;
	GOptionContext* _tmp0_ = NULL;
	GOptionContext* context;
	IBusBus* _tmp1_ = NULL;
	IBusBus* bus;
	IBusConfig* _tmp2_ = NULL;
	IBusGucharmapConfigCache* _tmp3_ = NULL;
	GDBusConnection* _tmp4_ = NULL;
	IBusFactory* _tmp5_ = NULL;
	IBusFactory* factory;
	GError * _inner_error_ = NULL;
	_tmp0_ = g_option_context_new ("- ibus gucharmap");
	context = _tmp0_;
	g_option_context_add_main_entries (context, IBUS_GUCHARMAP_options, "ibus-gucharmap");
	g_option_context_parse (context, &args_length1, &args, &_inner_error_);
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == G_OPTION_ERROR) {
			goto __catch1_g_option_error;
		}
		_g_option_context_free0 (context);
		g_critical ("file %s: line %d: unexpected 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 0;
	}
	goto __finally1;
	__catch1_g_option_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		fprintf (stderr, "%s\n", e->message);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (context);
		return result;
	}
	__finally1:
	if (_inner_error_ != NULL) {
		_g_option_context_free0 (context);
		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 0;
	}
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	gtk_init (&args_length1, &args);
	ibus_init ();
	_tmp1_ = ibus_bus_new ();
	bus = g_object_ref_sink (_tmp1_);
	g_signal_connect (bus, "disconnected", (GCallback) __lambda2__ibus_bus_disconnected, NULL);
	_tmp2_ = ibus_bus_get_config (bus);
	_tmp3_ = ibus_gucharmap_config_cache_new (_tmp2_);
	_g_object_unref0 (ibus_gucharmap_config);
	ibus_gucharmap_config = _tmp3_;
	_tmp4_ = ibus_bus_get_connection (bus);
	_tmp5_ = ibus_factory_new (_tmp4_);
	factory = g_object_ref_sink (_tmp5_);
	ibus_factory_add_engine (factory, "gucharmap", IBUS_GUCHARMAP_TYPE_ENGINE);
	if (ibus_gucharmap_ibus) {
		ibus_bus_request_name (bus, "org.freedesktop.IBus.Gucharmap", (guint) 0);
	} else {
		IBusComponent* _tmp6_ = NULL;
		IBusComponent* component;
		IBusEngineDesc* _tmp7_ = NULL;
		IBusEngineDesc* engine;
		_tmp6_ = ibus_component_new ("org.freedesktop.IBus.Gucharmap", "Gucharmap", VERSION, "GPL", "Daiki Ueno <ueno@unixuser.org>", "http://code.google.com/p/ibus/", "", "ibus-gucharmap");
		component = g_object_ref_sink (_tmp6_);
		_tmp7_ = ibus_engine_desc_new ("gucharmap", "Unicode (Gucharmap)", "Unicode input method using Gucharmap", "other", "GPL", "Daiki Ueno <ueno@unixuser.org>", "accessories-character-map", "us");
		engine = g_object_ref_sink (_tmp7_);
		ibus_component_add_engine (component, engine);
		ibus_bus_register_component (bus, component);
		_g_object_unref0 (engine);
		_g_object_unref0 (component);
	}
	ibus_main ();
	result = 0;
	_g_object_unref0 (factory);
	_g_object_unref0 (bus);
	_g_option_context_free0 (context);
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return ibus_gucharmap_main (argv, argc);
}



