/* Main.c generated by valac 0.38.4, 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.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <config.h>
#include <stdio.h>


#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;

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

static const GOptionEntry MOSERIAL_MAIN_options[2] = {{"profile", 'p', 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* _tmp8_;
	moserialMainWindow* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp1_ = moserial_main_profileFilename;
	if (!(_tmp1_ == NULL)) {
		const gchar* _tmp2_;
		gboolean _tmp3_;
		_tmp2_ = moserial_main_profileFilename;
		_tmp3_ = g_path_is_absolute (_tmp2_);
		_tmp0_ = !_tmp3_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp4_;
		gchar* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp4_ = g_get_current_dir ();
		_tmp5_ = _tmp4_;
		_tmp6_ = moserial_main_profileFilename;
		_tmp7_ = g_build_filename (_tmp5_, _tmp6_, NULL);
		_g_free0 (moserial_main_profileFilename);
		moserial_main_profileFilename = _tmp7_;
		_g_free0 (_tmp5_);
	}
	_tmp8_ = moserial_main_profileFilename;
	_tmp9_ = moserial_main_window_new (_tmp8_);
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (mainWindow);
	mainWindow = _tmp9_;
	moserial_main_window_showWindow (mainWindow);
	_g_object_unref0 (mainWindow);
}


gint moserial_main_main (gchar** args, int args_length1) {
	gint result = 0;
	GOptionContext* context = NULL;
	GOptionContext* _tmp0_;
	GOptionGroup* _tmp1_;
	GError * _inner_error_ = NULL;
	gtk_init (&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, &args_length1, &args, &_inner_error_);
		_tmp2_ = _tmp3_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			gint _tmp4_ = 0;
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch6_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 _tmp4_;
		}
		if (!_tmp2_) {
			FILE* _tmp5_;
			gchar** _tmp6_;
			gint _tmp6__length1;
			const gchar* _tmp7_;
			_tmp5_ = stdout;
			_tmp6_ = args;
			_tmp6__length1 = args_length1;
			_tmp7_ = _tmp6_[0];
			fprintf (_tmp5_, _ ("Run '%s --help' to see a full list of available command line options.\n"), _tmp7_);
		} else {
			moserialMain* app = NULL;
			moserialMain* _tmp8_;
			moserialMain* _tmp9_;
			_tmp8_ = moserial_main_new ();
			app = _tmp8_;
			_tmp9_ = app;
			moserial_main_run (_tmp9_);
			gtk_main ();
			_g_object_unref0 (app);
		}
	}
	goto __finally6;
	__catch6_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp10_;
		GError* _tmp11_;
		const gchar* _tmp12_;
		FILE* _tmp13_;
		gchar** _tmp14_;
		gint _tmp14__length1;
		const gchar* _tmp15_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp10_ = stdout;
		_tmp11_ = e;
		_tmp12_ = _tmp11_->message;
		fprintf (_tmp10_, "%s\n", _tmp12_);
		_tmp13_ = stdout;
		_tmp14_ = args;
		_tmp14__length1 = args_length1;
		_tmp15_ = _tmp14_[0];
		fprintf (_tmp13_, _ ("Run '%s --help' to see a full list of available command line options.\n"), _tmp15_);
		_g_error_free0 (e);
	}
	__finally6:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gint _tmp16_ = 0;
		_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 _tmp16_;
	}
	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) {
	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) {
}


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);
}


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)) {
		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);
		g_once_init_leave (&moserial_main_type_id__volatile, moserial_main_type_id);
	}
	return moserial_main_type_id__volatile;
}



