/* utils.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from utils.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 3 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, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdio.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 LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS (ldefault_apps_ldefault_apps_signals_get_type ())
#define LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS, LDefaultAppsLDefaultAppsSignals))
#define LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS, LDefaultAppsLDefaultAppsSignalsClass))
#define LDEFAULT_APPS_IS_LDEFAULT_APPS_SIGNALS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS))
#define LDEFAULT_APPS_IS_LDEFAULT_APPS_SIGNALS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS))
#define LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS, LDefaultAppsLDefaultAppsSignalsClass))

typedef struct _LDefaultAppsLDefaultAppsSignals LDefaultAppsLDefaultAppsSignals;
typedef struct _LDefaultAppsLDefaultAppsSignalsClass LDefaultAppsLDefaultAppsSignalsClass;
typedef struct _LDefaultAppsLDefaultAppsSignalsPrivate LDefaultAppsLDefaultAppsSignalsPrivate;
enum  {
	LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_0_PROPERTY,
	LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_NUM_PROPERTIES
};
static GParamSpec* ldefault_apps_ldefault_apps_signals_properties[LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_NUM_PROPERTIES];
enum  {
	LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_UPDATE_UI_SIGNAL,
	LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_NUM_SIGNALS
};
static guint ldefault_apps_ldefault_apps_signals_signals[LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_NUM_SIGNALS] = {0};
#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 _g_free0(var) (var = (g_free (var), NULL))
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))

struct _LDefaultAppsLDefaultAppsSignals {
	GObject parent_instance;
	LDefaultAppsLDefaultAppsSignalsPrivate * priv;
};

struct _LDefaultAppsLDefaultAppsSignalsClass {
	GObjectClass parent_class;
};

static gpointer ldefault_apps_ldefault_apps_signals_parent_class = NULL;

VALA_EXTERN GType ldefault_apps_ldefault_apps_signals_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LDefaultAppsLDefaultAppsSignals, g_object_unref)
VALA_EXTERN LDefaultAppsLDefaultAppsSignals* ldefault_apps_ldefault_apps_signals_new (void);
VALA_EXTERN LDefaultAppsLDefaultAppsSignals* ldefault_apps_ldefault_apps_signals_construct (GType object_type);
static GType ldefault_apps_ldefault_apps_signals_get_type_once (void);
VALA_EXTERN GKeyFile* ldefault_apps_load_key_conf (const gchar* config_path_directory,
                                       const gchar* conf_name);

LDefaultAppsLDefaultAppsSignals*
ldefault_apps_ldefault_apps_signals_construct (GType object_type)
{
	LDefaultAppsLDefaultAppsSignals * self = NULL;
	self = (LDefaultAppsLDefaultAppsSignals*) g_object_new (object_type, NULL);
	return self;
}

LDefaultAppsLDefaultAppsSignals*
ldefault_apps_ldefault_apps_signals_new (void)
{
	return ldefault_apps_ldefault_apps_signals_construct (LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS);
}

static void
ldefault_apps_ldefault_apps_signals_class_init (LDefaultAppsLDefaultAppsSignalsClass * klass,
                                                gpointer klass_data)
{
	ldefault_apps_ldefault_apps_signals_parent_class = g_type_class_peek_parent (klass);
	ldefault_apps_ldefault_apps_signals_signals[LDEFAULT_APPS_LDEFAULT_APPS_SIGNALS_UPDATE_UI_SIGNAL] = g_signal_new ("update-ui", LDEFAULT_APPS_TYPE_LDEFAULT_APPS_SIGNALS, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
ldefault_apps_ldefault_apps_signals_instance_init (LDefaultAppsLDefaultAppsSignals * self,
                                                   gpointer klass)
{
}

static GType
ldefault_apps_ldefault_apps_signals_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LDefaultAppsLDefaultAppsSignalsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ldefault_apps_ldefault_apps_signals_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LDefaultAppsLDefaultAppsSignals), 0, (GInstanceInitFunc) ldefault_apps_ldefault_apps_signals_instance_init, NULL };
	GType ldefault_apps_ldefault_apps_signals_type_id;
	ldefault_apps_ldefault_apps_signals_type_id = g_type_register_static (G_TYPE_OBJECT, "LDefaultAppsLDefaultAppsSignals", &g_define_type_info, 0);
	return ldefault_apps_ldefault_apps_signals_type_id;
}

GType
ldefault_apps_ldefault_apps_signals_get_type (void)
{
	static volatile gsize ldefault_apps_ldefault_apps_signals_type_id__once = 0;
	if (g_once_init_enter (&ldefault_apps_ldefault_apps_signals_type_id__once)) {
		GType ldefault_apps_ldefault_apps_signals_type_id;
		ldefault_apps_ldefault_apps_signals_type_id = ldefault_apps_ldefault_apps_signals_get_type_once ();
		g_once_init_leave (&ldefault_apps_ldefault_apps_signals_type_id__once, ldefault_apps_ldefault_apps_signals_type_id);
	}
	return ldefault_apps_ldefault_apps_signals_type_id__once;
}

GKeyFile*
ldefault_apps_load_key_conf (const gchar* config_path_directory,
                             const gchar* conf_name)
{
	GKeyFile* kf = NULL;
	GKeyFile* _tmp0_;
	GFile* config_directory_file = NULL;
	GFile* _tmp1_;
	gchar* config_path = NULL;
	gchar* _tmp2_;
	GFile* config_file = NULL;
	const gchar* _tmp3_;
	GFile* _tmp4_;
	GFile* _tmp5_;
	GFile* _tmp10_;
	GError* _inner_error0_ = NULL;
	GKeyFile* result;
	g_return_val_if_fail (config_path_directory != NULL, NULL);
	g_return_val_if_fail (conf_name != NULL, NULL);
	_tmp0_ = g_key_file_new ();
	kf = _tmp0_;
	_tmp1_ = g_file_new_for_path (config_path_directory);
	config_directory_file = _tmp1_;
	g_message ("utils.vala:30: config_path_directory: %s", config_path_directory);
	_tmp2_ = g_build_filename (config_path_directory, conf_name, NULL);
	config_path = _tmp2_;
	_tmp3_ = config_path;
	_tmp4_ = g_file_new_for_path (_tmp3_);
	config_file = _tmp4_;
	_tmp5_ = config_directory_file;
	if (!g_file_query_exists (_tmp5_, NULL)) {
		{
			GFile* _tmp6_;
			_tmp6_ = config_directory_file;
			g_file_make_directory_with_parents (_tmp6_, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			FILE* _tmp7_;
			GError* _tmp8_;
			const gchar* _tmp9_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp7_ = stderr;
			_tmp8_ = e;
			_tmp9_ = _tmp8_->message;
			fprintf (_tmp7_, "Could not write settings: %s\n", _tmp9_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (config_file);
			_g_free0 (config_path);
			_g_object_unref0 (config_directory_file);
			_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 NULL;
		}
	}
	_tmp10_ = config_file;
	if (!g_file_query_exists (_tmp10_, NULL)) {
		{
			GFile* _tmp11_;
			GFileOutputStream* _tmp12_;
			GFileOutputStream* _tmp13_;
			_tmp11_ = config_file;
			_tmp12_ = g_file_create (_tmp11_, G_FILE_CREATE_PRIVATE, NULL, &_inner_error0_);
			_tmp13_ = _tmp12_;
			_g_object_unref0 (_tmp13_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
		}
		goto __finally1;
		__catch1_g_error:
		{
			GError* e = NULL;
			FILE* _tmp14_;
			GError* _tmp15_;
			const gchar* _tmp16_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp14_ = stderr;
			_tmp15_ = e;
			_tmp16_ = _tmp15_->message;
			fprintf (_tmp14_, "Could not write settings: %s\n", _tmp16_);
			_g_error_free0 (e);
		}
		__finally1:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (config_file);
			_g_free0 (config_path);
			_g_object_unref0 (config_directory_file);
			_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 NULL;
		}
	}
	{
		GKeyFile* _tmp17_;
		const gchar* _tmp18_;
		_tmp17_ = kf;
		_tmp18_ = config_path;
		g_key_file_load_from_file (_tmp17_, _tmp18_, G_KEY_FILE_NONE, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_KEY_FILE_ERROR) {
				goto __catch2_g_key_file_error;
			}
			if (_inner_error0_->domain == G_FILE_ERROR) {
				goto __catch2_g_file_error;
			}
			_g_object_unref0 (config_file);
			_g_free0 (config_path);
			_g_object_unref0 (config_directory_file);
			_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 NULL;
		}
	}
	goto __finally2;
	__catch2_g_key_file_error:
	{
		GError* err = NULL;
		GError* _tmp19_;
		const gchar* _tmp20_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp19_ = err;
		_tmp20_ = _tmp19_->message;
		g_warning ("utils.vala:65: %s", _tmp20_);
		_g_error_free0 (err);
	}
	goto __finally2;
	__catch2_g_file_error:
	{
		GError* err = NULL;
		GError* _tmp21_;
		const gchar* _tmp22_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp21_ = err;
		_tmp22_ = _tmp21_->message;
		g_warning ("utils.vala:69: %s", _tmp22_);
		_g_error_free0 (err);
	}
	__finally2:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (config_file);
		_g_free0 (config_path);
		_g_object_unref0 (config_directory_file);
		_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 NULL;
	}
	result = kf;
	_g_object_unref0 (config_file);
	_g_free0 (config_path);
	_g_object_unref0 (config_directory_file);
	return result;
}

