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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    For copyright information, see AUTHORS.

    Déjà Dup 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.

    Déjà Dup 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 Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <common.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>


#define DEJA_DUP_TYPE_CONFIG_WIDGET (deja_dup_config_widget_get_type ())
#define DEJA_DUP_CONFIG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidget))
#define DEJA_DUP_CONFIG_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetClass))
#define DEJA_DUP_IS_CONFIG_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET))
#define DEJA_DUP_IS_CONFIG_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_WIDGET))
#define DEJA_DUP_CONFIG_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_WIDGET, DejaDupConfigWidgetClass))

typedef struct _DejaDupConfigWidget DejaDupConfigWidget;
typedef struct _DejaDupConfigWidgetClass DejaDupConfigWidgetClass;
typedef struct _DejaDupConfigWidgetPrivate DejaDupConfigWidgetPrivate;

#define DEJA_DUP_TYPE_CONFIG_LABEL (deja_dup_config_label_get_type ())
#define DEJA_DUP_CONFIG_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_LABEL, DejaDupConfigLabel))
#define DEJA_DUP_CONFIG_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_LABEL, DejaDupConfigLabelClass))
#define DEJA_DUP_IS_CONFIG_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_LABEL))
#define DEJA_DUP_IS_CONFIG_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_LABEL))
#define DEJA_DUP_CONFIG_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_LABEL, DejaDupConfigLabelClass))

typedef struct _DejaDupConfigLabel DejaDupConfigLabel;
typedef struct _DejaDupConfigLabelClass DejaDupConfigLabelClass;
typedef struct _DejaDupConfigLabelPrivate DejaDupConfigLabelPrivate;

#define DEJA_DUP_TYPE_CONFIG_LABEL_LIST (deja_dup_config_label_list_get_type ())
#define DEJA_DUP_CONFIG_LABEL_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_LABEL_LIST, DejaDupConfigLabelList))
#define DEJA_DUP_CONFIG_LABEL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_LABEL_LIST, DejaDupConfigLabelListClass))
#define DEJA_DUP_IS_CONFIG_LABEL_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_LABEL_LIST))
#define DEJA_DUP_IS_CONFIG_LABEL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_LABEL_LIST))
#define DEJA_DUP_CONFIG_LABEL_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_LABEL_LIST, DejaDupConfigLabelListClass))

typedef struct _DejaDupConfigLabelList DejaDupConfigLabelList;
typedef struct _DejaDupConfigLabelListClass DejaDupConfigLabelListClass;
typedef struct _DejaDupConfigLabelListPrivate DejaDupConfigLabelListPrivate;
#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_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
typedef struct _DejaDupConfigLabelListSetFromConfigData DejaDupConfigLabelListSetFromConfigData;

struct _DejaDupConfigWidget {
	GtkEventBox parent_instance;
	DejaDupConfigWidgetPrivate * priv;
	gboolean syncing;
	DejaDupSimpleSettings* settings;
	GList* all_settings;
};

struct _DejaDupConfigWidgetClass {
	GtkEventBoxClass parent_class;
	void (*set_from_config) (DejaDupConfigWidget* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*set_from_config_finish) (DejaDupConfigWidget* self, GAsyncResult* _res_);
};

struct _DejaDupConfigLabel {
	DejaDupConfigWidget parent_instance;
	DejaDupConfigLabelPrivate * priv;
	GtkBox* hbox;
	GtkLabel* label;
};

struct _DejaDupConfigLabelClass {
	DejaDupConfigWidgetClass parent_class;
	void (*fill_box) (DejaDupConfigLabel* self);
};

struct _DejaDupConfigLabelList {
	DejaDupConfigLabel parent_instance;
	DejaDupConfigLabelListPrivate * priv;
};

struct _DejaDupConfigLabelListClass {
	DejaDupConfigLabelClass parent_class;
};

struct _DejaDupConfigLabelListSetFromConfigData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	DejaDupConfigLabelList* self;
	gchar* val;
	const gchar* _tmp0_;
	GVariant* _tmp1_;
	GVariant* slist_val;
	size_t _tmp2_;
	const gchar** _tmp3_;
	const gchar** slist;
	gint slist_length1;
	gint _slist_size_;
	gint _tmp4_;
	GFile** _tmp5_;
	GFile** list;
	gint list_length1;
	gint _list_size_;
	GFile** f_collection;
	int f_collection_length1;
	int f_it;
	GFile* _tmp6_;
	GFile* f;
	gchar* _tmp7_;
	gchar* s;
	gboolean _tmp8_;
	gint _tmp9_;
	gboolean _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	const gchar* _tmp16_;
};


static gpointer deja_dup_config_label_list_parent_class = NULL;

GType deja_dup_config_widget_get_type (void) G_GNUC_CONST;
GType deja_dup_config_label_get_type (void) G_GNUC_CONST;
GType deja_dup_config_label_list_get_type (void) G_GNUC_CONST;
enum  {
	DEJA_DUP_CONFIG_LABEL_LIST_DUMMY_PROPERTY
};
DejaDupConfigLabelList* deja_dup_config_label_list_new (const gchar* key, const gchar* ns);
DejaDupConfigLabelList* deja_dup_config_label_list_construct (GType object_type, const gchar* key, const gchar* ns);
static void deja_dup_config_label_list_real_set_from_config_data_free (gpointer _data);
static void deja_dup_config_label_list_real_set_from_config (DejaDupConfigWidget* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean deja_dup_config_label_list_real_set_from_config_co (DejaDupConfigLabelListSetFromConfigData* data);
const gchar* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
static void deja_dup_config_label_list_set_from_config_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static GObject * deja_dup_config_label_list_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


DejaDupConfigLabelList* deja_dup_config_label_list_construct (GType object_type, const gchar* key, const gchar* ns) {
	DejaDupConfigLabelList * self = NULL;
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (ns != NULL, NULL);
	self = (DejaDupConfigLabelList*) g_object_new (object_type, "key", key, "ns", ns, NULL);
	return self;
}


DejaDupConfigLabelList* deja_dup_config_label_list_new (const gchar* key, const gchar* ns) {
	return deja_dup_config_label_list_construct (DEJA_DUP_TYPE_CONFIG_LABEL_LIST, key, ns);
}


static void deja_dup_config_label_list_real_set_from_config_data_free (gpointer _data) {
	DejaDupConfigLabelListSetFromConfigData* data;
	data = _data;
	_g_object_unref0 (data->self);
	g_slice_free (DejaDupConfigLabelListSetFromConfigData, data);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void deja_dup_config_label_list_real_set_from_config (DejaDupConfigWidget* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DejaDupConfigLabelList * self;
	DejaDupConfigLabelListSetFromConfigData* _data_;
	self = (DejaDupConfigLabelList*) base;
	_data_ = g_slice_new0 (DejaDupConfigLabelListSetFromConfigData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, deja_dup_config_label_list_real_set_from_config);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, deja_dup_config_label_list_real_set_from_config_data_free);
	_data_->self = _g_object_ref0 (self);
	deja_dup_config_label_list_real_set_from_config_co (_data_);
}


static void deja_dup_config_label_list_real_set_from_config_finish (DejaDupConfigWidget* base, GAsyncResult* _res_) {
	DejaDupConfigLabelListSetFromConfigData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void deja_dup_config_label_list_set_from_config_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	DejaDupConfigLabelListSetFromConfigData* data;
	data = _user_data_;
	data->_source_object_ = source_object;
	data->_res_ = _res_;
	deja_dup_config_label_list_real_set_from_config_co (data);
}


static gchar* string_splice (const gchar* self, glong start, glong end, const gchar* str) {
	gchar* result = NULL;
	gint _tmp0_;
	glong string_length;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gsize str_size = 0UL;
	gint _tmp4_;
	void* _tmp5_ = NULL;
	const gchar* _result_;
	gchar* dest;
	const gchar* _tmp6_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	string_length = (glong) _tmp0_;
	if (start < 0) {
		start = string_length + start;
	}
	if (end < 0) {
		end = string_length + end;
	}
	if (start >= 0) {
		_tmp1_ = start <= string_length;
	} else {
		_tmp1_ = FALSE;
	}
	g_return_val_if_fail (_tmp1_, NULL);
	if (end >= 0) {
		_tmp2_ = end <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	if (str == NULL) {
		str_size = (gsize) 0;
	} else {
		gint _tmp3_;
		_tmp3_ = strlen (str);
		str_size = (gsize) _tmp3_;
	}
	_tmp4_ = strlen (self);
	_tmp5_ = g_malloc0 (((_tmp4_ - (end - start)) + str_size) + 1);
	_result_ = _tmp5_;
	dest = (gchar*) _result_;
	memcpy (dest, self, (gsize) start);
	dest = dest + start;
	memcpy (dest, str, str_size);
	dest = dest + str_size;
	memcpy (dest, ((gchar*) self) + end, (gsize) (string_length - end));
	_tmp6_ = _result_;
	_result_ = NULL;
	result = (gchar*) _tmp6_;
	return result;
}


static gboolean deja_dup_config_label_list_real_set_from_config_co (DejaDupConfigLabelListSetFromConfigData* data) {
	switch (data->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	data->val = NULL;
	data->_tmp0_ = NULL;
	data->_tmp0_ = deja_dup_config_widget_get_key ((DejaDupConfigWidget*) data->self);
	data->_tmp1_ = NULL;
	data->_tmp1_ = g_settings_get_value ((GSettings*) ((DejaDupConfigWidget*) data->self)->settings, data->_tmp0_);
	data->slist_val = data->_tmp1_;
	data->_tmp3_ = NULL;
	data->_tmp3_ = g_variant_get_strv (data->slist_val, &data->_tmp2_);
	data->slist = data->_tmp3_;
	data->slist_length1 = data->_tmp2_;
	data->_slist_size_ = data->_tmp2_;
	data->_tmp5_ = NULL;
	data->_tmp5_ = deja_dup_parse_dir_list (data->slist, data->slist_length1, &data->_tmp4_);
	data->list = data->_tmp5_;
	data->list_length1 = data->_tmp4_;
	data->_list_size_ = data->_tmp4_;
	{
		data->f_collection = data->list;
		data->f_collection_length1 = data->list_length1;
		for (data->f_it = 0; data->f_it < data->list_length1; data->f_it = data->f_it + 1) {
			data->_tmp6_ = _g_object_ref0 (data->f_collection[data->f_it]);
			data->f = data->_tmp6_;
			{
				data->_state_ = 1;
				deja_dup_get_nickname (data->f, deja_dup_config_label_list_set_from_config_ready, data);
				return FALSE;
				_state_1:
				data->_tmp7_ = NULL;
				data->_tmp7_ = deja_dup_get_nickname_finish (data->_res_);
				data->s = data->_tmp7_;
				data->_tmp9_ = strlen (data->s);
				if (data->_tmp9_ > 1) {
					data->_tmp10_ = g_str_has_prefix (data->s, ".");
					data->_tmp8_ = data->_tmp10_;
				} else {
					data->_tmp8_ = FALSE;
				}
				if (data->_tmp8_) {
					data->_tmp11_ = NULL;
					data->_tmp11_ = string_splice (data->s, (glong) 0, (glong) 1, "․\xE2\x81\xA0");
					_g_free0 (data->s);
					data->s = data->_tmp11_;
				}
				if (data->val != NULL) {
					data->_tmp12_ = NULL;
					data->_tmp12_ = g_strdup_printf (", %s", data->s);
					data->_tmp13_ = data->_tmp12_;
					data->_tmp14_ = g_strconcat (data->val, data->_tmp13_, NULL);
					_g_free0 (data->val);
					data->val = data->_tmp14_;
					_g_free0 (data->_tmp13_);
				} else {
					data->_tmp15_ = g_strdup (data->s);
					_g_free0 (data->val);
					data->val = data->_tmp15_;
				}
				_g_free0 (data->s);
				_g_object_unref0 (data->f);
			}
		}
	}
	if (data->val == NULL) {
		data->_tmp16_ = "";
	} else {
		data->_tmp16_ = data->val;
	}
	gtk_label_set_label (((DejaDupConfigLabel*) data->self)->label, data->_tmp16_);
	data->list = (_vala_array_free (data->list, data->list_length1, (GDestroyNotify) g_object_unref), NULL);
	data->slist = (g_free (data->slist), NULL);
	_g_variant_unref0 (data->slist_val);
	_g_free0 (data->val);
	if (data->_state_ == 0) {
		g_simple_async_result_complete_in_idle (data->_async_result);
	} else {
		g_simple_async_result_complete (data->_async_result);
	}
	g_object_unref (data->_async_result);
	return FALSE;
}


static GObject * deja_dup_config_label_list_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupConfigLabelList * self;
	parent_class = G_OBJECT_CLASS (deja_dup_config_label_list_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_CONFIG_LABEL_LIST (obj);
	g_object_set (((DejaDupConfigLabel*) self)->label, "wrap", TRUE, NULL);
	gtk_label_set_max_width_chars (((DejaDupConfigLabel*) self)->label, 30);
	gtk_label_set_ellipsize (((DejaDupConfigLabel*) self)->label, PANGO_ELLIPSIZE_END);
	return obj;
}


static void deja_dup_config_label_list_class_init (DejaDupConfigLabelListClass * klass) {
	deja_dup_config_label_list_parent_class = g_type_class_peek_parent (klass);
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config = deja_dup_config_label_list_real_set_from_config;
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config_finish = deja_dup_config_label_list_real_set_from_config_finish;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_config_label_list_constructor;
}


static void deja_dup_config_label_list_instance_init (DejaDupConfigLabelList * self) {
}


GType deja_dup_config_label_list_get_type (void) {
	static volatile gsize deja_dup_config_label_list_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_config_label_list_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigLabelListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_label_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigLabelList), 0, (GInstanceInitFunc) deja_dup_config_label_list_instance_init, NULL };
		GType deja_dup_config_label_list_type_id;
		deja_dup_config_label_list_type_id = g_type_register_static (DEJA_DUP_TYPE_CONFIG_LABEL, "DejaDupConfigLabelList", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_config_label_list_type_id__volatile, deja_dup_config_label_list_type_id);
	}
	return deja_dup_config_label_list_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



