/* ConfigLabelList.c generated by valac, 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.
    © 2009 Michael Terry <mike@mterry.name>

    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 <gconf/gconf-client.h>
#include <stdlib.h>
#include <string.h>
#include <gconf/gconf.h>
#include <common.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <pango/pango.h>
#include <gdk/gdk.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_slist_free_g_free0(var) ((var == NULL) ? NULL : (var = (_g_slist_free_g_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _DejaDupConfigWidget {
	GtkEventBox parent_instance;
	DejaDupConfigWidgetPrivate * priv;
	GConfClient* client;
};

struct _DejaDupConfigWidgetClass {
	GtkEventBoxClass parent_class;
	void (*set_from_config) (DejaDupConfigWidget* self);
};

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

struct _DejaDupConfigLabelClass {
	DejaDupConfigWidgetClass parent_class;
};

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

struct _DejaDupConfigLabelListClass {
	DejaDupConfigLabelClass parent_class;
};


static gpointer deja_dup_config_label_list_parent_class = NULL;

GType deja_dup_config_widget_get_type (void);
GType deja_dup_config_label_get_type (void);
GType deja_dup_config_label_list_get_type (void);
enum  {
	DEJA_DUP_CONFIG_LABEL_LIST_DUMMY_PROPERTY
};
DejaDupConfigLabelList* deja_dup_config_label_list_new (const char* key);
DejaDupConfigLabelList* deja_dup_config_label_list_construct (GType object_type, const char* key);
const char* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
static void _g_slist_free_g_free (GSList* self);
static void deja_dup_config_label_list_real_set_from_config (DejaDupConfigWidget* base);
static void _lambda1_ (GdkRectangle* a, DejaDupConfigLabelList* self);
static void __lambda1__gtk_widget_size_allocate (GtkWidget* _sender, GdkRectangle* allocation, gpointer self);
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 char* key) {
	DejaDupConfigLabelList * self;
	g_return_val_if_fail (key != NULL, NULL);
	self = (DejaDupConfigLabelList*) g_object_new (object_type, "key", key, NULL);
	return self;
}


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


static void _g_slist_free_g_free (GSList* self) {
	g_slist_foreach (self, (GFunc) g_free, NULL);
	g_slist_free (self);
}


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) {
	DejaDupConfigLabelList * self;
	GError * _inner_error_;
	char* val;
	GSList* slist;
	GFile** _tmp3_;
	gint _list_size_;
	gint list_length1;
	gint _tmp2_;
	GFile** list;
	gint i;
	GFile* home;
	char* _tmp4_;
	GFile* _tmp5_;
	GFile* trash;
	self = (DejaDupConfigLabelList*) base;
	_inner_error_ = NULL;
	val = g_strdup ("");
	slist = NULL;
	{
		GSList* _tmp0_;
		GSList* _tmp1_;
		_tmp0_ = gconf_client_get_list (((DejaDupConfigWidget*) self)->client, deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self), GCONF_VALUE_STRING, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch11_g_error;
		}
		slist = (_tmp1_ = _tmp0_, __g_slist_free_g_free0 (slist), _tmp1_);
	}
	goto __finally11;
	__catch11_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			g_warning ("ConfigLabelList.vala:44: %s\n", e->message);
			_g_error_free0 (e);
			_g_free0 (val);
			__g_slist_free_g_free0 (slist);
			return;
		}
	}
	__finally11:
	if (_inner_error_ != NULL) {
		_g_free0 (val);
		__g_slist_free_g_free0 (slist);
		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;
	}
	list = (_tmp3_ = deja_dup_parse_dir_list (slist, &_tmp2_), list_length1 = _tmp2_, _list_size_ = list_length1, _tmp3_);
	i = 0;
	home = g_file_new_for_path (g_get_home_dir ());
	trash = (_tmp5_ = g_file_new_for_path (_tmp4_ = deja_dup_get_trash_path ()), _g_free0 (_tmp4_), _tmp5_);
	{
		GFile** f_collection;
		int f_collection_length1;
		int f_it;
		f_collection = list;
		f_collection_length1 = list_length1;
		for (f_it = 0; f_it < list_length1; f_it = f_it + 1) {
			GFile* f;
			f = _g_object_ref0 (f_collection[f_it]);
			{
				char* s;
				char* _tmp11_;
				s = NULL;
				if (g_file_equal (f, home)) {
					char* _tmp6_;
					s = (_tmp6_ = g_strdup (_ ("Home Folder")), _g_free0 (s), _tmp6_);
				} else {
					if (g_file_equal (f, trash)) {
						char* _tmp7_;
						s = (_tmp7_ = g_strdup (_ ("Trash")), _g_free0 (s), _tmp7_);
					} else {
						if (g_file_has_prefix (f, home)) {
							char* _tmp8_;
							s = (_tmp8_ = g_file_get_relative_path (home, f), _g_free0 (s), _tmp8_);
						} else {
							char* _tmp9_;
							s = (_tmp9_ = g_file_get_path (f), _g_free0 (s), _tmp9_);
						}
					}
				}
				if (i > 0) {
					char* _tmp10_;
					val = (_tmp10_ = g_strconcat (val, ", ", NULL), _g_free0 (val), _tmp10_);
				}
				val = (_tmp11_ = g_strconcat (val, s, NULL), _g_free0 (val), _tmp11_);
				i++;
				_g_object_unref0 (f);
				_g_free0 (s);
			}
		}
	}
	gtk_label_set_label (((DejaDupConfigLabel*) self)->label, val);
	_g_free0 (val);
	__g_slist_free_g_free0 (slist);
	list = (_vala_array_free (list, list_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (home);
	_g_object_unref0 (trash);
}


static void _lambda1_ (GdkRectangle* a, DejaDupConfigLabelList* self) {
	g_object_set ((GObject*) ((DejaDupConfigLabel*) self)->label, "width-request", (*a).width, NULL);
}


static void __lambda1__gtk_widget_size_allocate (GtkWidget* _sender, GdkRectangle* allocation, gpointer self) {
	_lambda1_ (allocation, self);
}


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 ((GObject*) ((DejaDupConfigLabel*) self)->label, "wrap", TRUE, "wrap-mode", PANGO_WRAP_WORD, NULL);
		g_signal_connect_object ((GtkWidget*) self, "size-allocate", (GCallback) __lambda1__gtk_widget_size_allocate, self, 0);
	}
	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;
	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);
}




