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

/* 
 *      Copyright 2012 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.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define LXSESSION_TYPE_CONFFILES_OBJECT (lxsession_conffiles_object_get_type ())
#define LXSESSION_CONFFILES_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LXSESSION_TYPE_CONFFILES_OBJECT, LxsessionConffilesObject))
#define LXSESSION_CONFFILES_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LXSESSION_TYPE_CONFFILES_OBJECT, LxsessionConffilesObjectClass))
#define LXSESSION_IS_CONFFILES_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LXSESSION_TYPE_CONFFILES_OBJECT))
#define LXSESSION_IS_CONFFILES_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LXSESSION_TYPE_CONFFILES_OBJECT))
#define LXSESSION_CONFFILES_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LXSESSION_TYPE_CONFFILES_OBJECT, LxsessionConffilesObjectClass))

typedef struct _LxsessionConffilesObject LxsessionConffilesObject;
typedef struct _LxsessionConffilesObjectClass LxsessionConffilesObjectClass;
typedef struct _LxsessionConffilesObjectPrivate LxsessionConffilesObjectPrivate;
#define _g_key_file_free0(var) ((var == NULL) ? NULL : (var = (g_key_file_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define LXSESSION_TYPE_LXSESSION_CONFIG (lxsession_lxsession_config_get_type ())
#define LXSESSION_LXSESSION_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LXSESSION_TYPE_LXSESSION_CONFIG, LxsessionLxsessionConfig))
#define LXSESSION_LXSESSION_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LXSESSION_TYPE_LXSESSION_CONFIG, LxsessionLxsessionConfigClass))
#define LXSESSION_IS_LXSESSION_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LXSESSION_TYPE_LXSESSION_CONFIG))
#define LXSESSION_IS_LXSESSION_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LXSESSION_TYPE_LXSESSION_CONFIG))
#define LXSESSION_LXSESSION_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LXSESSION_TYPE_LXSESSION_CONFIG, LxsessionLxsessionConfigClass))

typedef struct _LxsessionLxsessionConfig LxsessionLxsessionConfig;
typedef struct _LxsessionLxsessionConfigClass LxsessionLxsessionConfigClass;

#define LXSESSION_TYPE_LXSESSION_CONFIG_KEY_FILE (lxsession_lxsession_config_key_file_get_type ())
#define LXSESSION_LXSESSION_CONFIG_KEY_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LXSESSION_TYPE_LXSESSION_CONFIG_KEY_FILE, LxsessionLxsessionConfigKeyFile))
#define LXSESSION_LXSESSION_CONFIG_KEY_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LXSESSION_TYPE_LXSESSION_CONFIG_KEY_FILE, LxsessionLxsessionConfigKeyFileClass))
#define LXSESSION_IS_LXSESSION_CONFIG_KEY_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LXSESSION_TYPE_LXSESSION_CONFIG_KEY_FILE))
#define LXSESSION_IS_LXSESSION_CONFIG_KEY_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LXSESSION_TYPE_LXSESSION_CONFIG_KEY_FILE))
#define LXSESSION_LXSESSION_CONFIG_KEY_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LXSESSION_TYPE_LXSESSION_CONFIG_KEY_FILE, LxsessionLxsessionConfigKeyFileClass))

typedef struct _LxsessionLxsessionConfigKeyFile LxsessionLxsessionConfigKeyFile;
typedef struct _LxsessionLxsessionConfigKeyFileClass LxsessionLxsessionConfigKeyFileClass;
#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)))

struct _LxsessionConffilesObject {
	GObject parent_instance;
	LxsessionConffilesObjectPrivate * priv;
	GKeyFile* kf;
	gchar* Openbox_dest;
	gchar* Qt_dest;
	gchar* Leafpad_dest;
	gchar* Lxterminal_dest;
	gchar* XScreensaver_dest;
	gchar* libfm_dest;
	gchar* cairo_dock_dest;
};

struct _LxsessionConffilesObjectClass {
	GObjectClass parent_class;
};


static gpointer lxsession_conffiles_object_parent_class = NULL;
extern LxsessionLxsessionConfigKeyFile* lxsession_global_settings;

GType lxsession_conffiles_object_get_type (void) G_GNUC_CONST;
enum  {
	LXSESSION_CONFFILES_OBJECT_DUMMY_PROPERTY
};
LxsessionConffilesObject* lxsession_conffiles_object_new (const gchar* conffiles_conf);
LxsessionConffilesObject* lxsession_conffiles_object_construct (GType object_type, const gchar* conffiles_conf);
GKeyFile* lxsession_load_keyfile (const gchar* config_path);
GType lxsession_lxsession_config_get_type (void) G_GNUC_CONST;
GType lxsession_lxsession_config_key_file_get_type (void) G_GNUC_CONST;
gchar* lxsession_lxsession_config_get_item_string (LxsessionLxsessionConfig* self, const gchar* categorie, const gchar* key1, const gchar* key2);
void lxsession_conffiles_object_copy_file (LxsessionConffilesObject* self, const gchar* source_path, const gchar* dest_path);
gchar* lxsession_conffiles_object_load_source_path (LxsessionConffilesObject* self, const gchar* config_type);
void lxsession_conffiles_object_copy_conf (LxsessionConffilesObject* self, const gchar* config_type, const gchar* dest_path);
void lxsession_conffiles_object_apply (LxsessionConffilesObject* self);
static void lxsession_conffiles_object_finalize (GObject* obj);


LxsessionConffilesObject* lxsession_conffiles_object_construct (GType object_type, const gchar* conffiles_conf) {
	LxsessionConffilesObject * self = NULL;
	const gchar* _tmp0_ = NULL;
	GKeyFile* _tmp1_ = NULL;
	LxsessionLxsessionConfigKeyFile* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gboolean _tmp5_ = FALSE;
	g_return_val_if_fail (conffiles_conf != NULL, NULL);
	self = (LxsessionConffilesObject*) g_object_new (object_type, NULL);
	_tmp0_ = conffiles_conf;
	_tmp1_ = lxsession_load_keyfile (_tmp0_);
	_g_key_file_free0 (self->kf);
	self->kf = _tmp1_;
	_tmp2_ = lxsession_global_settings;
	_tmp3_ = lxsession_lxsession_config_get_item_string ((LxsessionLxsessionConfig*) _tmp2_, "Session", "windows_manager", "command");
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strcmp0 (_tmp4_, "openbox") == 0;
	_g_free0 (_tmp4_);
	if (_tmp5_) {
		LxsessionLxsessionConfigKeyFile* _tmp6_ = NULL;
		gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gboolean _tmp9_ = FALSE;
		_tmp6_ = lxsession_global_settings;
		_tmp7_ = lxsession_lxsession_config_get_item_string ((LxsessionLxsessionConfig*) _tmp6_, "Session", "windows_manager", "session");
		_tmp8_ = _tmp7_;
		_tmp9_ = g_strcmp0 (_tmp8_, "LXDE") == 0;
		_g_free0 (_tmp8_);
		if (_tmp9_) {
			const gchar* _tmp10_ = NULL;
			gchar* _tmp11_ = NULL;
			_tmp10_ = g_get_user_config_dir ();
			_tmp11_ = g_build_filename (_tmp10_, "openbox", "lxde-rc.xml", NULL);
			_g_free0 (self->Openbox_dest);
			self->Openbox_dest = _tmp11_;
		} else {
			LxsessionLxsessionConfigKeyFile* _tmp12_ = NULL;
			gchar* _tmp13_ = NULL;
			gchar* _tmp14_ = NULL;
			gboolean _tmp15_ = FALSE;
			_tmp12_ = lxsession_global_settings;
			_tmp13_ = lxsession_lxsession_config_get_item_string ((LxsessionLxsessionConfig*) _tmp12_, "Session", "windows_manager", "session");
			_tmp14_ = _tmp13_;
			_tmp15_ = g_strcmp0 (_tmp14_, "Lubuntu") == 0;
			_g_free0 (_tmp14_);
			if (_tmp15_) {
				const gchar* _tmp16_ = NULL;
				gchar* _tmp17_ = NULL;
				_tmp16_ = g_get_user_config_dir ();
				_tmp17_ = g_build_filename (_tmp16_, "openbox", "lubuntu-rc.xml", NULL);
				_g_free0 (self->Openbox_dest);
				self->Openbox_dest = _tmp17_;
			}
		}
	} else {
		const gchar* _tmp18_ = NULL;
		gchar* _tmp19_ = NULL;
		_tmp18_ = g_get_user_config_dir ();
		_tmp19_ = g_build_filename (_tmp18_, "openbox", "lxde-rc.xml", NULL);
		_g_free0 (self->Openbox_dest);
		self->Openbox_dest = _tmp19_;
	}
	return self;
}


LxsessionConffilesObject* lxsession_conffiles_object_new (const gchar* conffiles_conf) {
	return lxsession_conffiles_object_construct (LXSESSION_TYPE_CONFFILES_OBJECT, conffiles_conf);
}


void lxsession_conffiles_object_copy_file (LxsessionConffilesObject* self, const gchar* source_path, const gchar* dest_path) {
	GFile* source_file = NULL;
	const gchar* _tmp0_ = NULL;
	GFile* _tmp1_ = NULL;
	GFile* dest_file = NULL;
	const gchar* _tmp2_ = NULL;
	GFile* _tmp3_ = NULL;
	GFile* dest_directory = NULL;
	GFile* _tmp4_ = NULL;
	GFile* _tmp5_ = NULL;
	GFile* _tmp6_ = NULL;
	gboolean _tmp7_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source_path != NULL);
	g_return_if_fail (dest_path != NULL);
	_tmp0_ = source_path;
	_tmp1_ = g_file_new_for_path (_tmp0_);
	source_file = _tmp1_;
	_tmp2_ = dest_path;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	dest_file = _tmp3_;
	_tmp4_ = dest_file;
	_tmp5_ = g_file_get_parent (_tmp4_);
	dest_directory = _tmp5_;
	_tmp6_ = dest_file;
	_tmp7_ = g_file_query_exists (_tmp6_, NULL);
	if (!_tmp7_) {
		GFile* _tmp8_ = NULL;
		gboolean _tmp9_ = FALSE;
		_tmp8_ = dest_directory;
		_tmp9_ = g_file_query_exists (_tmp8_, NULL);
		if (!_tmp9_) {
			{
				GFile* _tmp10_ = NULL;
				_tmp10_ = dest_directory;
				g_file_make_directory_with_parents (_tmp10_, NULL, &_inner_error_);
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					goto __catch19_g_error;
				}
			}
			goto __finally19;
			__catch19_g_error:
			{
				GError* err = NULL;
				GError* _tmp11_ = NULL;
				const gchar* _tmp12_ = NULL;
				err = _inner_error_;
				_inner_error_ = NULL;
				_tmp11_ = err;
				_tmp12_ = _tmp11_->message;
				g_message ("conffiles.vala:73: %s", _tmp12_);
				_g_error_free0 (err);
			}
			__finally19:
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				_g_object_unref0 (dest_directory);
				_g_object_unref0 (dest_file);
				_g_object_unref0 (source_file);
				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;
			}
		}
		{
			GFile* _tmp13_ = NULL;
			GFile* _tmp14_ = NULL;
			_tmp13_ = source_file;
			_tmp14_ = dest_file;
			g_file_copy (_tmp13_, _tmp14_, G_FILE_COPY_NONE, NULL, NULL, NULL, &_inner_error_);
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				goto __catch20_g_error;
			}
		}
		goto __finally20;
		__catch20_g_error:
		{
			GError* err = NULL;
			GError* _tmp15_ = NULL;
			const gchar* _tmp16_ = NULL;
			err = _inner_error_;
			_inner_error_ = NULL;
			_tmp15_ = err;
			_tmp16_ = _tmp15_->message;
			g_message ("conffiles.vala:83: %s", _tmp16_);
			_g_error_free0 (err);
		}
		__finally20:
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_object_unref0 (dest_directory);
			_g_object_unref0 (dest_file);
			_g_object_unref0 (source_file);
			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;
		}
	}
	_g_object_unref0 (dest_directory);
	_g_object_unref0 (dest_file);
	_g_object_unref0 (source_file);
}


gchar* lxsession_conffiles_object_load_source_path (LxsessionConffilesObject* self, const gchar* config_type) {
	gchar* result = NULL;
	gchar* source = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (config_type != NULL, NULL);
	{
		gchar* _tmp0_ = NULL;
		GKeyFile* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		_tmp1_ = self->kf;
		_tmp2_ = config_type;
		_tmp3_ = g_key_file_get_value (_tmp1_, _tmp2_, "source", &_inner_error_);
		_tmp0_ = _tmp3_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_KEY_FILE_ERROR) {
				goto __catch21_g_key_file_error;
			}
			_g_free0 (source);
			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 NULL;
		}
		_tmp4_ = _tmp0_;
		_tmp0_ = NULL;
		_g_free0 (source);
		source = _tmp4_;
		result = source;
		_g_free0 (_tmp0_);
		return result;
	}
	goto __finally21;
	__catch21_g_key_file_error:
	{
		GError* err = NULL;
		GError* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		gchar* _tmp7_ = NULL;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = err;
		_tmp6_ = _tmp5_->message;
		g_message ("conffiles.vala:97: %s", _tmp6_);
		_tmp7_ = g_strdup ("");
		result = _tmp7_;
		_g_error_free0 (err);
		_g_free0 (source);
		return result;
	}
	__finally21:
	_g_free0 (source);
	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 NULL;
}


void lxsession_conffiles_object_copy_conf (LxsessionConffilesObject* self, const gchar* config_type, const gchar* dest_path) {
	GKeyFile* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (config_type != NULL);
	g_return_if_fail (dest_path != NULL);
	_tmp0_ = self->kf;
	_tmp1_ = config_type;
	_tmp2_ = g_key_file_has_group (_tmp0_, _tmp1_);
	if (_tmp2_) {
		const gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		_tmp3_ = config_type;
		_tmp4_ = lxsession_conffiles_object_load_source_path (self, _tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = dest_path;
		lxsession_conffiles_object_copy_file (self, _tmp5_, _tmp6_);
		_g_free0 (_tmp5_);
	}
}


void lxsession_conffiles_object_apply (LxsessionConffilesObject* self) {
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->Openbox_dest;
	lxsession_conffiles_object_copy_conf (self, "Openbox", _tmp0_);
	_tmp1_ = self->Qt_dest;
	lxsession_conffiles_object_copy_conf (self, "Qt", _tmp1_);
	_tmp2_ = self->Leafpad_dest;
	lxsession_conffiles_object_copy_conf (self, "Leafpad", _tmp2_);
	_tmp3_ = self->Lxterminal_dest;
	lxsession_conffiles_object_copy_conf (self, "Lxterminal", _tmp3_);
	_tmp4_ = self->XScreensaver_dest;
	lxsession_conffiles_object_copy_conf (self, "XScreensaver", _tmp4_);
	_tmp5_ = self->libfm_dest;
	lxsession_conffiles_object_copy_conf (self, "libfm", _tmp5_);
	_tmp6_ = self->cairo_dock_dest;
	lxsession_conffiles_object_copy_conf (self, "cairo-dock", _tmp6_);
}


static void lxsession_conffiles_object_class_init (LxsessionConffilesObjectClass * klass) {
	lxsession_conffiles_object_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = lxsession_conffiles_object_finalize;
}


static void lxsession_conffiles_object_instance_init (LxsessionConffilesObject * self) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	const gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	_tmp0_ = g_get_user_config_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "Trolltech.conf", NULL);
	self->Qt_dest = _tmp1_;
	_tmp2_ = g_get_user_config_dir ();
	_tmp3_ = g_build_filename (_tmp2_, "leafpad", "leafpadrc", NULL);
	self->Leafpad_dest = _tmp3_;
	_tmp4_ = g_get_user_config_dir ();
	_tmp5_ = g_build_filename (_tmp4_, "lxterminal", "lxterminal.conf", NULL);
	self->Lxterminal_dest = _tmp5_;
	_tmp6_ = g_get_home_dir ();
	_tmp7_ = g_build_filename (_tmp6_, ".xscreensaver", NULL);
	self->XScreensaver_dest = _tmp7_;
	_tmp8_ = g_get_user_config_dir ();
	_tmp9_ = g_build_filename (_tmp8_, "libfm", "libfm.conf", NULL);
	self->libfm_dest = _tmp9_;
	_tmp10_ = g_get_user_config_dir ();
	_tmp11_ = g_build_filename (_tmp10_, "cairo-dock", "cairo-dock.conf", NULL);
	self->cairo_dock_dest = _tmp11_;
}


static void lxsession_conffiles_object_finalize (GObject* obj) {
	LxsessionConffilesObject * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, LXSESSION_TYPE_CONFFILES_OBJECT, LxsessionConffilesObject);
	_g_key_file_free0 (self->kf);
	_g_free0 (self->Openbox_dest);
	_g_free0 (self->Qt_dest);
	_g_free0 (self->Leafpad_dest);
	_g_free0 (self->Lxterminal_dest);
	_g_free0 (self->XScreensaver_dest);
	_g_free0 (self->libfm_dest);
	_g_free0 (self->cairo_dock_dest);
	G_OBJECT_CLASS (lxsession_conffiles_object_parent_class)->finalize (obj);
}


GType lxsession_conffiles_object_get_type (void) {
	static volatile gsize lxsession_conffiles_object_type_id__volatile = 0;
	if (g_once_init_enter (&lxsession_conffiles_object_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (LxsessionConffilesObjectClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) lxsession_conffiles_object_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LxsessionConffilesObject), 0, (GInstanceInitFunc) lxsession_conffiles_object_instance_init, NULL };
		GType lxsession_conffiles_object_type_id;
		lxsession_conffiles_object_type_id = g_type_register_static (G_TYPE_OBJECT, "LxsessionConffilesObject", &g_define_type_info, 0);
		g_once_init_leave (&lxsession_conffiles_object_type_id__volatile, lxsession_conffiles_object_type_id);
	}
	return lxsession_conffiles_object_type_id__volatile;
}



