/* main.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from main.vala, do not modify */

/* 
 *      Copyright 2013 Julien Lavergne <gilir@ubuntu.com>
 *
 *      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-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <lxsettings-daemon/settings-daemon.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#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 TYPE_MAIN (main_get_type ())
#define MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN, Main))
#define MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN, MainClass))
#define IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN))
#define IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN))
#define MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN, MainClass))

typedef struct _Main Main;
typedef struct _MainClass MainClass;
typedef struct _MainPrivate MainPrivate;
enum  {
	MAIN_0_PROPERTY,
	MAIN_NUM_PROPERTIES
};
static GParamSpec* main_properties[MAIN_NUM_PROPERTIES];
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _Main {
	GObject parent_instance;
	MainPrivate * priv;
};

struct _MainClass {
	GObjectClass parent_class;
};

static gpointer main_parent_class = NULL;
static gchar* main_file;
static gboolean main_persistent;
static gboolean main_persistent = FALSE;
static gchar* main_file = NULL;

VALA_EXTERN GType main_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Main, g_object_unref)
static gint main_main (gchar** args,
                gint args_length1);
VALA_EXTERN Main* main_new (void);
VALA_EXTERN Main* main_construct (GType object_type);
static void main_finalize (GObject * obj);
static GType main_get_type_once (void);

static const GOptionEntry MAIN_option_entries[3] = {{"file", 'f', (gint) 0, G_OPTION_ARG_STRING, &main_file, "path of the configuration file", "NAME"}, {"persistent", 'p', (gint) 0, G_OPTION_ARG_NONE, &main_persistent, "reload configuration on file change", NULL}, {NULL}};

static gint
main_main (gchar** args,
           gint args_length1)
{
	const gchar* _tmp0_;
	GError* _inner_error0_ = NULL;
	gint result;
	_tmp0_ = main_file;
	if (_tmp0_ == NULL) {
		g_critical ("main.vala:34: Error, you need to specify a configuration file using -f" \
" argument. Exit");
		result = -1;
		return result;
	} else {
		GKeyFile* kf = NULL;
		GKeyFile* _tmp1_;
		GKeyFile* _tmp10_;
		_tmp1_ = g_key_file_new ();
		kf = _tmp1_;
		{
			GKeyFile* _tmp2_;
			const gchar* _tmp3_;
			_tmp2_ = kf;
			_tmp3_ = main_file;
			g_key_file_load_from_file (_tmp2_, _tmp3_, G_KEY_FILE_NONE, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gint _tmp4_ = -1;
				if (_inner_error0_->domain == G_KEY_FILE_ERROR) {
					goto __catch0_g_key_file_error;
				}
				if (_inner_error0_->domain == G_FILE_ERROR) {
					goto __catch0_g_file_error;
				}
				_g_key_file_unref0 (kf);
				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_;
			}
		}
		goto __finally0;
		__catch0_g_key_file_error:
		{
			GError* err = NULL;
			GError* _tmp5_;
			const gchar* _tmp6_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp5_ = err;
			_tmp6_ = _tmp5_->message;
			g_warning ("main.vala:47: %s", _tmp6_);
			g_critical ("main.vala:48: Problem when loading the configuration file. Exit");
			result = -1;
			_g_error_free0 (err);
			_g_key_file_unref0 (kf);
			return result;
		}
		goto __finally0;
		__catch0_g_file_error:
		{
			GError* err = NULL;
			GError* _tmp7_;
			const gchar* _tmp8_;
			err = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp7_ = err;
			_tmp8_ = _tmp7_->message;
			g_warning ("main.vala:53: %s", _tmp8_);
			g_critical ("main.vala:54: Problem when loading the configuration file. Exit");
			result = -1;
			_g_error_free0 (err);
			_g_key_file_unref0 (kf);
			return result;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint _tmp9_ = -1;
			_g_key_file_unref0 (kf);
			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 _tmp9_;
		}
		_tmp10_ = kf;
		settings_daemon_start (_tmp10_);
		if (main_persistent == FALSE) {
			result = 0;
			_g_key_file_unref0 (kf);
			return result;
		} else {
			result = 0;
			_g_key_file_unref0 (kf);
			return result;
		}
		_g_key_file_unref0 (kf);
	}
}

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

Main*
main_construct (GType object_type)
{
	Main * self = NULL;
	self = (Main*) g_object_new (object_type, NULL);
	return self;
}

Main*
main_new (void)
{
	return main_construct (TYPE_MAIN);
}

static void
main_class_init (MainClass * klass,
                 gpointer klass_data)
{
	main_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = main_finalize;
}

static void
main_instance_init (Main * self,
                    gpointer klass)
{
}

static void
main_finalize (GObject * obj)
{
	Main * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MAIN, Main);
	G_OBJECT_CLASS (main_parent_class)->finalize (obj);
}

static GType
main_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MainClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) main_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Main), 0, (GInstanceInitFunc) main_instance_init, NULL };
	GType main_type_id;
	main_type_id = g_type_register_static (G_TYPE_OBJECT, "Main", &g_define_type_info, 0);
	return main_type_id;
}

GType
main_get_type (void)
{
	static volatile gsize main_type_id__once = 0;
	if (g_once_init_enter (&main_type_id__once)) {
		GType main_type_id;
		main_type_id = main_get_type_once ();
		g_once_init_leave (&main_type_id__once, main_type_id);
	}
	return main_type_id__once;
}

