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

/*
 *  Copyright (C) 2009-2010 Michael J. Chudobiak.
 *
 *  This file is part of moserial.
 *
 *  moserial 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.
 *
 *  moserial 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 moserial.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <config.h>
#include <stdio.h>

#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define MOSERIAL_TYPE_MAIN (moserial_main_get_type ())
#define MOSERIAL_MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOSERIAL_TYPE_MAIN, moserialMain))
#define MOSERIAL_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOSERIAL_TYPE_MAIN, moserialMainClass))
#define MOSERIAL_IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOSERIAL_TYPE_MAIN))
#define MOSERIAL_IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOSERIAL_TYPE_MAIN))
#define MOSERIAL_MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOSERIAL_TYPE_MAIN, moserialMainClass))

typedef struct _moserialMain moserialMain;
typedef struct _moserialMainClass moserialMainClass;
typedef struct _moserialMainPrivate moserialMainPrivate;
enum  {
	MOSERIAL_MAIN_0_PROPERTY,
	MOSERIAL_MAIN_NUM_PROPERTIES
};
static GParamSpec* moserial_main_properties[MOSERIAL_MAIN_NUM_PROPERTIES];

#define MOSERIAL_TYPE_MAIN_WINDOW (moserial_main_window_get_type ())
#define MOSERIAL_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOSERIAL_TYPE_MAIN_WINDOW, moserialMainWindow))
#define MOSERIAL_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOSERIAL_TYPE_MAIN_WINDOW, moserialMainWindowClass))
#define MOSERIAL_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOSERIAL_TYPE_MAIN_WINDOW))
#define MOSERIAL_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOSERIAL_TYPE_MAIN_WINDOW))
#define MOSERIAL_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOSERIAL_TYPE_MAIN_WINDOW, moserialMainWindowClass))

typedef struct _moserialMainWindow moserialMainWindow;
typedef struct _moserialMainWindowClass moserialMainWindowClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#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)))

struct _moserialMain {
	GObject parent_instance;
	moserialMainPrivate * priv;
};

struct _moserialMainClass {
	GObjectClass parent_class;
};

static gpointer moserial_main_parent_class = NULL;
static gchar* moserial_main_profileFilename;
static gchar* moserial_main_profileFilename = NULL;

VALA_EXTERN GType moserial_main_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (moserialMain, g_object_unref)
VALA_EXTERN void moserial_main_run (moserialMain* self);
VALA_EXTERN GType moserial_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (moserialMainWindow, g_object_unref)
VALA_EXTERN moserialMainWindow* moserial_main_window_new (const gchar* profileFilename);
VALA_EXTERN moserialMainWindow* moserial_main_window_construct (GType object_type,
                                                    const gchar* profileFilename);
VALA_EXTERN void moserial_main_window_showWindow (moserialMainWindow* self);
static gint moserial_main_main (gchar** args,
                         gint args_length1);
VALA_EXTERN moserialMain* moserial_main_new (void);
VALA_EXTERN moserialMain* moserial_main_construct (GType object_type);
static void moserial_main_finalize (GObject * obj);
static GType moserial_main_get_type_once (void);

static const GOptionEntry MOSERIAL_MAIN_options[2] = {{"profile", 'p', (gint) 0, G_OPTION_ARG_FILENAME, &moserial_main_profileFilename, N_ ("Profile file to load"), "foo.conf"}, {NULL}};

void
moserial_main_run (moserialMain* self)
{
	moserialMainWindow* mainWindow = NULL;
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	const gchar* _tmp7_;
	moserialMainWindow* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp1_ = moserial_main_profileFilename;
	if (!(_tmp1_ == NULL)) {
		const gchar* _tmp2_;
		_tmp2_ = moserial_main_profileFilename;
		_tmp0_ = !g_path_is_absolute (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp3_;
		gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp3_ = g_get_current_dir ();
		_tmp4_ = _tmp3_;
		_tmp5_ = moserial_main_profileFilename;
		_tmp6_ = g_build_filename (_tmp4_, _tmp5_, NULL);
		_g_free0 (moserial_main_profileFilename);
		moserial_main_profileFilename = _tmp6_;
		_g_free0 (_tmp4_);
	}
	_tmp7_ = moserial_main_profileFilename;
	_tmp8_ = moserial_main_window_new (_tmp7_);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (mainWindow);
	mainWindow = _tmp8_;
	moserial_main_window_showWindow (mainWindow);
	_g_object_unref0 (mainWindow);
}

static gint
moserial_main_main (gchar** args,
                    gint args_length1)
{
	GOptionContext* context = NULL;
	GOptionContext* _tmp0_;
	GOptionGroup* _tmp1_;
	GError* _inner_error0_ = NULL;
	gint result = 0;
	gtk_init ((gint*) (&args_length1), &args);
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = g_option_context_new (_ ("- moserial serial terminal"));
	_g_option_context_free0 (context);
	context = _tmp0_;
	g_option_context_add_main_entries (context, MOSERIAL_MAIN_options, NULL);
	_tmp1_ = gtk_get_option_group (TRUE);
	g_option_context_add_group (context, _tmp1_);
	{
		gboolean _tmp2_ = FALSE;
		gboolean _tmp3_;
		_tmp3_ = g_option_context_parse (context, (gint*) (&args_length1), &args, &_inner_error0_);
		_tmp2_ = _tmp3_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint _tmp4_ = -1;
			if (_inner_error0_->domain == G_OPTION_ERROR) {
				goto __catch0_g_option_error;
			}
			_g_option_context_free0 (context);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp4_;
		}
		if (!_tmp2_) {
			FILE* _tmp5_;
			const gchar* _tmp6_;
			_tmp5_ = stdout;
			_tmp6_ = args[0];
			fprintf (_tmp5_, _ ("Run '%s --help' to see a full list of available command line options.\n"), _tmp6_);
		} else {
			moserialMain* app = NULL;
			moserialMain* _tmp7_;
			moserialMain* _tmp8_;
			_tmp7_ = moserial_main_new ();
			app = _tmp7_;
			_tmp8_ = app;
			moserial_main_run (_tmp8_);
			gtk_main ();
			_g_object_unref0 (app);
		}
	}
	goto __finally0;
	__catch0_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp9_;
		GError* _tmp10_;
		const gchar* _tmp11_;
		FILE* _tmp12_;
		const gchar* _tmp13_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp9_ = stdout;
		_tmp10_ = e;
		_tmp11_ = _tmp10_->message;
		fprintf (_tmp9_, "%s\n", _tmp11_);
		_tmp12_ = stdout;
		_tmp13_ = args[0];
		fprintf (_tmp12_, _ ("Run '%s --help' to see a full list of available command line options.\n"), _tmp13_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp14_ = -1;
		_g_option_context_free0 (context);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp14_;
	}
	result = 0;
	_g_option_context_free0 (context);
	return result;
}

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

moserialMain*
moserial_main_construct (GType object_type)
{
	moserialMain * self = NULL;
	self = (moserialMain*) g_object_new (object_type, NULL);
	return self;
}

moserialMain*
moserial_main_new (void)
{
	return moserial_main_construct (MOSERIAL_TYPE_MAIN);
}

static void
moserial_main_class_init (moserialMainClass * klass,
                          gpointer klass_data)
{
	moserial_main_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = moserial_main_finalize;
}

static void
moserial_main_instance_init (moserialMain * self,
                             gpointer klass)
{
}

static void
moserial_main_finalize (GObject * obj)
{
	moserialMain * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MOSERIAL_TYPE_MAIN, moserialMain);
	G_OBJECT_CLASS (moserial_main_parent_class)->finalize (obj);
}

static GType
moserial_main_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (moserialMainClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) moserial_main_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (moserialMain), 0, (GInstanceInitFunc) moserial_main_instance_init, NULL };
	GType moserial_main_type_id;
	moserial_main_type_id = g_type_register_static (G_TYPE_OBJECT, "moserialMain", &g_define_type_info, 0);
	return moserial_main_type_id;
}

GType
moserial_main_get_type (void)
{
	static volatile gsize moserial_main_type_id__volatile = 0;
	if (g_once_init_enter (&moserial_main_type_id__volatile)) {
		GType moserial_main_type_id;
		moserial_main_type_id = moserial_main_get_type_once ();
		g_once_init_leave (&moserial_main_type_id__volatile, moserial_main_type_id);
	}
	return moserial_main_type_id__volatile;
}

