/* DefaultPaths.c generated by valac 0.54.3, the Vala compiler
 * generated from DefaultPaths.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 <stdlib.h>
#include <string.h>
#include <glib.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 TYPE_DEFAULT_PATHS (default_paths_get_type ())
#define DEFAULT_PATHS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DEFAULT_PATHS, DefaultPaths))
#define DEFAULT_PATHS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DEFAULT_PATHS, DefaultPathsClass))
#define IS_DEFAULT_PATHS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DEFAULT_PATHS))
#define IS_DEFAULT_PATHS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DEFAULT_PATHS))
#define DEFAULT_PATHS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DEFAULT_PATHS, DefaultPathsClass))

typedef struct _DefaultPaths DefaultPaths;
typedef struct _DefaultPathsClass DefaultPathsClass;
typedef struct _DefaultPathsPrivate DefaultPathsPrivate;
enum  {
	DEFAULT_PATHS_0_PROPERTY,
	DEFAULT_PATHS_RECORD_TO_PROPERTY,
	DEFAULT_PATHS_RECEIVE_TO_PROPERTY,
	DEFAULT_PATHS_SEND_FROM_PROPERTY,
	DEFAULT_PATHS_NUM_PROPERTIES
};
static GParamSpec* default_paths_properties[DEFAULT_PATHS_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_PROFILE (profile_get_type ())
#define PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROFILE, Profile))
#define PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROFILE, ProfileClass))
#define IS_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROFILE))
#define IS_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROFILE))
#define PROFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROFILE, ProfileClass))

typedef struct _Profile Profile;
typedef struct _ProfileClass ProfileClass;

struct _DefaultPaths {
	GObject parent_instance;
	DefaultPathsPrivate * priv;
};

struct _DefaultPathsClass {
	GObjectClass parent_class;
};

struct _DefaultPathsPrivate {
	gchar* _recordTo;
	gchar* _receiveTo;
	gchar* _sendFrom;
};

static gint DefaultPaths_private_offset;
static gpointer default_paths_parent_class = NULL;

VALA_EXTERN GType default_paths_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DefaultPaths, g_object_unref)
VALA_EXTERN DefaultPaths* default_paths_new (const gchar* RecordTo,
                                 const gchar* ReceiveTo,
                                 const gchar* SendFrom);
VALA_EXTERN DefaultPaths* default_paths_construct (GType object_type,
                                       const gchar* RecordTo,
                                       const gchar* ReceiveTo,
                                       const gchar* SendFrom);
VALA_EXTERN void default_paths_set_recordTo (DefaultPaths* self,
                                 const gchar* value);
VALA_EXTERN void default_paths_set_receiveTo (DefaultPaths* self,
                                  const gchar* value);
VALA_EXTERN void default_paths_set_sendFrom (DefaultPaths* self,
                                 const gchar* value);
VALA_EXTERN GType profile_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Profile, g_object_unref)
VALA_EXTERN void default_paths_saveToProfile (DefaultPaths* self,
                                  Profile* profile);
VALA_EXTERN const gchar* default_paths_get_recordTo (DefaultPaths* self);
VALA_EXTERN void profile_setString (Profile* self,
                        const gchar* group,
                        const gchar* key,
                        const gchar* new_val);
VALA_EXTERN const gchar* default_paths_get_receiveTo (DefaultPaths* self);
VALA_EXTERN const gchar* default_paths_get_sendFrom (DefaultPaths* self);
VALA_EXTERN DefaultPaths* default_paths_loadFromProfile (Profile* profile);
VALA_EXTERN gchar* default_paths_getPath (Profile* profile,
                              const gchar* group,
                              const gchar* key);
VALA_EXTERN gchar* profile_getString (Profile* self,
                          const gchar* group,
                          const gchar* key);
VALA_EXTERN gboolean mo_utils_fileExists (const gchar* path);
static void default_paths_finalize (GObject * obj);
static GType default_paths_get_type_once (void);
static void _vala_default_paths_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec);
static void _vala_default_paths_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
default_paths_get_instance_private (DefaultPaths* self)
{
	return G_STRUCT_MEMBER_P (self, DefaultPaths_private_offset);
}

DefaultPaths*
default_paths_construct (GType object_type,
                         const gchar* RecordTo,
                         const gchar* ReceiveTo,
                         const gchar* SendFrom)
{
	DefaultPaths * self = NULL;
	self = (DefaultPaths*) g_object_new (object_type, NULL);
	default_paths_set_recordTo (self, RecordTo);
	default_paths_set_receiveTo (self, ReceiveTo);
	default_paths_set_sendFrom (self, SendFrom);
	return self;
}

DefaultPaths*
default_paths_new (const gchar* RecordTo,
                   const gchar* ReceiveTo,
                   const gchar* SendFrom)
{
	return default_paths_construct (TYPE_DEFAULT_PATHS, RecordTo, ReceiveTo, SendFrom);
}

void
default_paths_saveToProfile (DefaultPaths* self,
                             Profile* profile)
{
	const gchar* _tmp0_;
	const gchar* _tmp2_;
	const gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (profile != NULL);
	_tmp0_ = self->priv->_recordTo;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = self->priv->_recordTo;
		profile_setString (profile, "paths", "last_record_path", _tmp1_);
	}
	_tmp2_ = self->priv->_receiveTo;
	if (_tmp2_ != NULL) {
		const gchar* _tmp3_;
		_tmp3_ = self->priv->_receiveTo;
		profile_setString (profile, "paths", "last_receive_path", _tmp3_);
	}
	_tmp4_ = self->priv->_sendFrom;
	if (_tmp4_ != NULL) {
		const gchar* _tmp5_;
		_tmp5_ = self->priv->_sendFrom;
		profile_setString (profile, "paths", "last_send_path", _tmp5_);
	}
}

DefaultPaths*
default_paths_loadFromProfile (Profile* profile)
{
	gchar* RecordTo = NULL;
	gchar* ReceiveTo = NULL;
	gchar* SendFrom = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	DefaultPaths* _tmp6_;
	DefaultPaths* result = NULL;
	g_return_val_if_fail (profile != NULL, NULL);
	RecordTo = NULL;
	ReceiveTo = NULL;
	SendFrom = NULL;
	_tmp0_ = default_paths_getPath (profile, "paths", "last_record_path");
	_g_free0 (RecordTo);
	RecordTo = _tmp0_;
	_tmp1_ = default_paths_getPath (profile, "paths", "last_receive_path");
	_g_free0 (ReceiveTo);
	ReceiveTo = _tmp1_;
	_tmp2_ = default_paths_getPath (profile, "paths", "last_send_path");
	_g_free0 (SendFrom);
	SendFrom = _tmp2_;
	_tmp3_ = RecordTo;
	_tmp4_ = ReceiveTo;
	_tmp5_ = SendFrom;
	_tmp6_ = default_paths_new (_tmp3_, _tmp4_, _tmp5_);
	result = _tmp6_;
	_g_free0 (SendFrom);
	_g_free0 (ReceiveTo);
	_g_free0 (RecordTo);
	return result;
}

gchar*
default_paths_getPath (Profile* profile,
                       const gchar* group,
                       const gchar* key)
{
	gchar* path = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gchar* result = NULL;
	g_return_val_if_fail (profile != NULL, NULL);
	g_return_val_if_fail (group != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	path = NULL;
	_tmp0_ = profile_getString (profile, group, key);
	_g_free0 (path);
	path = _tmp0_;
	_tmp2_ = path;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_;
		_tmp3_ = path;
		_tmp1_ = !mo_utils_fileExists (_tmp3_);
	}
	if (_tmp1_) {
		result = NULL;
		_g_free0 (path);
		return result;
	}
	result = path;
	return result;
}

const gchar*
default_paths_get_recordTo (DefaultPaths* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_recordTo;
	result = _tmp0_;
	return result;
}

void
default_paths_set_recordTo (DefaultPaths* self,
                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = default_paths_get_recordTo (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_recordTo);
		self->priv->_recordTo = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, default_paths_properties[DEFAULT_PATHS_RECORD_TO_PROPERTY]);
	}
}

const gchar*
default_paths_get_receiveTo (DefaultPaths* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_receiveTo;
	result = _tmp0_;
	return result;
}

void
default_paths_set_receiveTo (DefaultPaths* self,
                             const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = default_paths_get_receiveTo (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_receiveTo);
		self->priv->_receiveTo = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, default_paths_properties[DEFAULT_PATHS_RECEIVE_TO_PROPERTY]);
	}
}

const gchar*
default_paths_get_sendFrom (DefaultPaths* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_sendFrom;
	result = _tmp0_;
	return result;
}

void
default_paths_set_sendFrom (DefaultPaths* self,
                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = default_paths_get_sendFrom (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_sendFrom);
		self->priv->_sendFrom = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, default_paths_properties[DEFAULT_PATHS_SEND_FROM_PROPERTY]);
	}
}

static void
default_paths_class_init (DefaultPathsClass * klass,
                          gpointer klass_data)
{
	default_paths_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DefaultPaths_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_default_paths_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_default_paths_set_property;
	G_OBJECT_CLASS (klass)->finalize = default_paths_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEFAULT_PATHS_RECORD_TO_PROPERTY, default_paths_properties[DEFAULT_PATHS_RECORD_TO_PROPERTY] = g_param_spec_string ("recordTo", "recordTo", "recordTo", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEFAULT_PATHS_RECEIVE_TO_PROPERTY, default_paths_properties[DEFAULT_PATHS_RECEIVE_TO_PROPERTY] = g_param_spec_string ("receiveTo", "receiveTo", "receiveTo", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEFAULT_PATHS_SEND_FROM_PROPERTY, default_paths_properties[DEFAULT_PATHS_SEND_FROM_PROPERTY] = g_param_spec_string ("sendFrom", "sendFrom", "sendFrom", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
default_paths_instance_init (DefaultPaths * self,
                             gpointer klass)
{
	self->priv = default_paths_get_instance_private (self);
}

static void
default_paths_finalize (GObject * obj)
{
	DefaultPaths * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DEFAULT_PATHS, DefaultPaths);
	_g_free0 (self->priv->_recordTo);
	_g_free0 (self->priv->_receiveTo);
	_g_free0 (self->priv->_sendFrom);
	G_OBJECT_CLASS (default_paths_parent_class)->finalize (obj);
}

static GType
default_paths_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DefaultPathsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) default_paths_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DefaultPaths), 0, (GInstanceInitFunc) default_paths_instance_init, NULL };
	GType default_paths_type_id;
	default_paths_type_id = g_type_register_static (G_TYPE_OBJECT, "DefaultPaths", &g_define_type_info, 0);
	DefaultPaths_private_offset = g_type_add_instance_private (default_paths_type_id, sizeof (DefaultPathsPrivate));
	return default_paths_type_id;
}

GType
default_paths_get_type (void)
{
	static volatile gsize default_paths_type_id__volatile = 0;
	if (g_once_init_enter (&default_paths_type_id__volatile)) {
		GType default_paths_type_id;
		default_paths_type_id = default_paths_get_type_once ();
		g_once_init_leave (&default_paths_type_id__volatile, default_paths_type_id);
	}
	return default_paths_type_id__volatile;
}

static void
_vala_default_paths_get_property (GObject * object,
                                  guint property_id,
                                  GValue * value,
                                  GParamSpec * pspec)
{
	DefaultPaths * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_DEFAULT_PATHS, DefaultPaths);
	switch (property_id) {
		case DEFAULT_PATHS_RECORD_TO_PROPERTY:
		g_value_set_string (value, default_paths_get_recordTo (self));
		break;
		case DEFAULT_PATHS_RECEIVE_TO_PROPERTY:
		g_value_set_string (value, default_paths_get_receiveTo (self));
		break;
		case DEFAULT_PATHS_SEND_FROM_PROPERTY:
		g_value_set_string (value, default_paths_get_sendFrom (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_default_paths_set_property (GObject * object,
                                  guint property_id,
                                  const GValue * value,
                                  GParamSpec * pspec)
{
	DefaultPaths * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_DEFAULT_PATHS, DefaultPaths);
	switch (property_id) {
		case DEFAULT_PATHS_RECORD_TO_PROPERTY:
		default_paths_set_recordTo (self, g_value_get_string (value));
		break;
		case DEFAULT_PATHS_RECEIVE_TO_PROPERTY:
		default_paths_set_receiveTo (self, g_value_get_string (value));
		break;
		case DEFAULT_PATHS_SEND_FROM_PROPERTY:
		default_paths_set_sendFrom (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

