/* ConfigDelete.c generated by valac 0.12.1, the Vala compiler
 * generated from ConfigDelete.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 <glib/gi18n-lib.h>
#include <config.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_CHOICE (deja_dup_config_choice_get_type ())
#define DEJA_DUP_CONFIG_CHOICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_CHOICE, DejaDupConfigChoice))
#define DEJA_DUP_CONFIG_CHOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_CHOICE, DejaDupConfigChoiceClass))
#define DEJA_DUP_IS_CONFIG_CHOICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_CHOICE))
#define DEJA_DUP_IS_CONFIG_CHOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_CHOICE))
#define DEJA_DUP_CONFIG_CHOICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_CHOICE, DejaDupConfigChoiceClass))

typedef struct _DejaDupConfigChoice DejaDupConfigChoice;
typedef struct _DejaDupConfigChoiceClass DejaDupConfigChoiceClass;
typedef struct _DejaDupConfigChoicePrivate DejaDupConfigChoicePrivate;

#define DEJA_DUP_TYPE_CONFIG_DELETE (deja_dup_config_delete_get_type ())
#define DEJA_DUP_CONFIG_DELETE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_DELETE, DejaDupConfigDelete))
#define DEJA_DUP_CONFIG_DELETE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_DELETE, DejaDupConfigDeleteClass))
#define DEJA_DUP_IS_CONFIG_DELETE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_DELETE))
#define DEJA_DUP_IS_CONFIG_DELETE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_DELETE))
#define DEJA_DUP_CONFIG_DELETE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_DELETE, DejaDupConfigDeleteClass))

typedef struct _DejaDupConfigDelete DejaDupConfigDelete;
typedef struct _DejaDupConfigDeleteClass DejaDupConfigDeleteClass;
typedef struct _DejaDupConfigDeletePrivate DejaDupConfigDeletePrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_GValue_free0(var) ((var == NULL) ? NULL : (var = (_vala_GValue_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _DejaDupConfigDeleteSetFromConfigData DejaDupConfigDeleteSetFromConfigData;

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 _DejaDupConfigChoice {
	DejaDupConfigWidget parent_instance;
	DejaDupConfigChoicePrivate * priv;
	GtkComboBox* combo;
	gchar* default_val;
	gint settings_col;
};

struct _DejaDupConfigChoiceClass {
	DejaDupConfigWidgetClass parent_class;
	void (*handle_changed) (DejaDupConfigChoice* self);
};

struct _DejaDupConfigDelete {
	DejaDupConfigChoice parent_instance;
	DejaDupConfigDeletePrivate * priv;
};

struct _DejaDupConfigDeleteClass {
	DejaDupConfigChoiceClass parent_class;
};

struct _DejaDupConfigDeleteSetFromConfigData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	DejaDupConfigDelete* self;
	const gchar* _tmp0_;
	gint _tmp1_;
	gint confval;
	gboolean valid;
	GtkTreeIter iter;
	GtkTreeModel* _tmp2_;
	GtkTreeIter _tmp3_;
	gboolean _tmp4_;
	GValue val;
	GtkTreeModel* _tmp5_;
	GValue _tmp6_;
	gint _tmp7_;
	gint intval;
	GtkTreeModel* _tmp8_;
	gboolean _tmp9_;
	GtkTreeModel* _tmp10_;
	GtkListStore* _tmp11_;
	GtkListStore* store;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	GtkTreeIter _tmp15_;
};


static gpointer deja_dup_config_delete_parent_class = NULL;
extern gint deja_dup_config_delete_FOREVER;
gint deja_dup_config_delete_FOREVER = 0;

GType deja_dup_config_widget_get_type (void) G_GNUC_CONST;
GType deja_dup_config_choice_get_type (void) G_GNUC_CONST;
GType deja_dup_config_delete_get_type (void) G_GNUC_CONST;
enum  {
	DEJA_DUP_CONFIG_DELETE_DUMMY_PROPERTY
};
#define DEJA_DUP_CONFIG_DELETE_WEEKLY 7
#define DEJA_DUP_CONFIG_DELETE_MONTHLY 28
#define DEJA_DUP_CONFIG_DELETE_BIMONTHLY (28 * 2)
#define DEJA_DUP_CONFIG_DELETE_TRIMONTHLY (28 * 3)
#define DEJA_DUP_CONFIG_DELETE_SEMIANNUALLY (365 / 2)
#define DEJA_DUP_CONFIG_DELETE_ANNUALLY 365
DejaDupConfigDelete* deja_dup_config_delete_new (const gchar* key, const gchar* ns);
DejaDupConfigDelete* deja_dup_config_delete_construct (GType object_type, const gchar* key, const gchar* ns);
static void deja_dup_config_delete_real_handle_changed (DejaDupConfigChoice* base);
GValue* deja_dup_config_choice_get_current_value (DejaDupConfigChoice* self);
const gchar* deja_dup_config_widget_get_key (DejaDupConfigWidget* self);
static void _vala_GValue_free (GValue* self);
static void deja_dup_config_delete_real_set_from_config_data_free (gpointer _data);
static void deja_dup_config_delete_real_set_from_config (DejaDupConfigWidget* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean deja_dup_config_delete_real_set_from_config_co (DejaDupConfigDeleteSetFromConfigData* data);
static GObject * deja_dup_config_delete_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
void deja_dup_config_choice_init (DejaDupConfigChoice* self, GtkTreeModel* model, gint settings_col);
static void deja_dup_config_delete_finalize (GObject* obj);


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


DejaDupConfigDelete* deja_dup_config_delete_new (const gchar* key, const gchar* ns) {
	return deja_dup_config_delete_construct (DEJA_DUP_TYPE_CONFIG_DELETE, key, ns);
}


static void _vala_GValue_free (GValue* self) {
	g_value_unset (self);
	g_free (self);
}


static void deja_dup_config_delete_real_handle_changed (DejaDupConfigChoice* base) {
	DejaDupConfigDelete * self;
	GValue* _tmp0_ = NULL;
	GValue* val;
	gint _tmp1_ = 0;
	gint intval;
	const gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	self = (DejaDupConfigDelete*) base;
	_tmp0_ = deja_dup_config_choice_get_current_value ((DejaDupConfigChoice*) self);
	val = _tmp0_;
	if (val == NULL) {
		_tmp1_ = 0;
	} else {
		gint _tmp2_;
		_tmp2_ = g_value_get_int (val);
		_tmp1_ = _tmp2_;
	}
	intval = _tmp1_;
	if (intval == G_MAXINT) {
		intval = 0;
	}
	_tmp3_ = deja_dup_config_widget_get_key ((DejaDupConfigWidget*) self);
	deja_dup_simple_settings_set_int (((DejaDupConfigWidget*) self)->settings, _tmp3_, intval);
	_tmp4_ = g_strdup_printf ("%i", intval);
	_tmp5_ = _tmp4_;
	g_signal_emit_by_name ((DejaDupConfigChoice*) self, "choice-changed", _tmp5_);
	_g_free0 (_tmp5_);
	__vala_GValue_free0 (val);
}


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


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


static void deja_dup_config_delete_real_set_from_config (DejaDupConfigWidget* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	DejaDupConfigDelete * self;
	DejaDupConfigDeleteSetFromConfigData* _data_;
	self = (DejaDupConfigDelete*) base;
	_data_ = g_slice_new0 (DejaDupConfigDeleteSetFromConfigData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, deja_dup_config_delete_real_set_from_config);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, deja_dup_config_delete_real_set_from_config_data_free);
	_data_->self = _g_object_ref0 (self);
	deja_dup_config_delete_real_set_from_config_co (_data_);
}


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


static gboolean deja_dup_config_delete_real_set_from_config_co (DejaDupConfigDeleteSetFromConfigData* data) {
	switch (data->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	data->_tmp0_ = NULL;
	data->_tmp0_ = deja_dup_config_widget_get_key ((DejaDupConfigWidget*) data->self);
	data->_tmp1_ = g_settings_get_int ((GSettings*) ((DejaDupConfigWidget*) data->self)->settings, data->_tmp0_);
	data->confval = data->_tmp1_;
	if (data->confval <= 0) {
		data->confval = G_MAXINT;
	}
	data->_tmp2_ = NULL;
	data->_tmp2_ = gtk_combo_box_get_model (((DejaDupConfigChoice*) data->self)->combo);
	memset (&data->_tmp3_, 0, sizeof (GtkTreeIter));
	data->_tmp4_ = gtk_tree_model_get_iter_first (data->_tmp2_, &data->_tmp3_);
	data->iter = data->_tmp3_;
	data->valid = data->_tmp4_;
	while (TRUE) {
		if (!data->valid) {
			break;
		}
		data->_tmp5_ = NULL;
		data->_tmp5_ = gtk_combo_box_get_model (((DejaDupConfigChoice*) data->self)->combo);
		memset (&data->_tmp6_, 0, sizeof (GValue));
		gtk_tree_model_get_value (data->_tmp5_, &data->iter, ((DejaDupConfigChoice*) data->self)->settings_col, &data->_tmp6_);
		G_IS_VALUE (&data->val) ? (g_value_unset (&data->val), NULL) : NULL;
		data->val = data->_tmp6_;
		data->_tmp7_ = g_value_get_int (&data->val);
		data->intval = data->_tmp7_;
		if (data->intval == data->confval) {
			gtk_combo_box_set_active_iter (((DejaDupConfigChoice*) data->self)->combo, &data->iter);
			G_IS_VALUE (&data->val) ? (g_value_unset (&data->val), NULL) : NULL;
			break;
		}
		data->_tmp8_ = NULL;
		data->_tmp8_ = gtk_combo_box_get_model (((DejaDupConfigChoice*) data->self)->combo);
		data->_tmp9_ = gtk_tree_model_iter_next (data->_tmp8_, &data->iter);
		data->valid = data->_tmp9_;
		G_IS_VALUE (&data->val) ? (g_value_unset (&data->val), NULL) : NULL;
	}
	if (!data->valid) {
		data->_tmp10_ = NULL;
		data->_tmp10_ = gtk_combo_box_get_model (((DejaDupConfigChoice*) data->self)->combo);
		data->_tmp11_ = _g_object_ref0 (GTK_LIST_STORE (data->_tmp10_));
		data->store = data->_tmp11_;
		data->_tmp12_ = NULL;
		data->_tmp12_ = g_dngettext (GETTEXT_PACKAGE, "At least %d day", "At least %d days", (gulong) data->confval);
		data->_tmp13_ = NULL;
		data->_tmp13_ = g_strdup_printf (data->_tmp12_, data->confval);
		data->_tmp14_ = data->_tmp13_;
		memset (&data->_tmp15_, 0, sizeof (GtkTreeIter));
		gtk_list_store_insert_with_values (data->store, &data->_tmp15_, 0, 0, data->_tmp14_, 1, data->confval, -1);
		data->iter = data->_tmp15_;
		_g_free0 (data->_tmp14_);
		gtk_combo_box_set_active_iter (((DejaDupConfigChoice*) data->self)->combo, &data->iter);
		_g_object_unref0 (data->store);
	}
	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_delete_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupConfigDelete * self;
	GtkListStore* _tmp0_ = NULL;
	GtkListStore* store;
	GtkTreeIter iter = {0};
	gint i;
	gint _tmp1_;
	const gchar* _tmp2_ = NULL;
	GtkTreeIter _tmp3_ = {0};
	gint _tmp4_;
	const gchar* _tmp5_ = NULL;
	GtkTreeIter _tmp6_ = {0};
	gint _tmp7_;
	const gchar* _tmp8_ = NULL;
	GtkTreeIter _tmp9_ = {0};
	gint _tmp10_;
	const gchar* _tmp11_ = NULL;
	GtkTreeIter _tmp12_ = {0};
	gint _tmp13_;
	const gchar* _tmp14_ = NULL;
	GtkTreeIter _tmp15_ = {0};
	gint _tmp16_;
	const gchar* _tmp17_ = NULL;
	GtkTreeIter _tmp18_ = {0};
	gint _tmp19_;
	const gchar* _tmp20_ = NULL;
	GtkTreeIter _tmp21_ = {0};
	parent_class = G_OBJECT_CLASS (deja_dup_config_delete_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_CONFIG_DELETE (obj);
	_tmp0_ = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
	store = _tmp0_;
	i = 0;
	_tmp1_ = i;
	i = _tmp1_ + 1;
	_tmp2_ = _ ("At least a week");
	gtk_list_store_insert_with_values (store, &_tmp3_, _tmp1_, 0, _tmp2_, 1, DEJA_DUP_CONFIG_DELETE_WEEKLY, -1);
	iter = _tmp3_;
	_tmp4_ = i;
	i = _tmp4_ + 1;
	_tmp5_ = _ ("At least a month");
	gtk_list_store_insert_with_values (store, &_tmp6_, _tmp4_, 0, _tmp5_, 1, DEJA_DUP_CONFIG_DELETE_MONTHLY, -1);
	iter = _tmp6_;
	_tmp7_ = i;
	i = _tmp7_ + 1;
	_tmp8_ = _ ("At least two months");
	gtk_list_store_insert_with_values (store, &_tmp9_, _tmp7_, 0, _tmp8_, 1, DEJA_DUP_CONFIG_DELETE_BIMONTHLY, -1);
	iter = _tmp9_;
	_tmp10_ = i;
	i = _tmp10_ + 1;
	_tmp11_ = _ ("At least three months");
	gtk_list_store_insert_with_values (store, &_tmp12_, _tmp10_, 0, _tmp11_, 1, DEJA_DUP_CONFIG_DELETE_TRIMONTHLY, -1);
	iter = _tmp12_;
	_tmp13_ = i;
	i = _tmp13_ + 1;
	_tmp14_ = _ ("At least six months");
	gtk_list_store_insert_with_values (store, &_tmp15_, _tmp13_, 0, _tmp14_, 1, DEJA_DUP_CONFIG_DELETE_SEMIANNUALLY, -1);
	iter = _tmp15_;
	_tmp16_ = i;
	i = _tmp16_ + 1;
	_tmp17_ = _ ("At least a year");
	gtk_list_store_insert_with_values (store, &_tmp18_, _tmp16_, 0, _tmp17_, 1, DEJA_DUP_CONFIG_DELETE_ANNUALLY, -1);
	iter = _tmp18_;
	_tmp19_ = i;
	i = _tmp19_ + 1;
	_tmp20_ = _ ("Forever");
	gtk_list_store_insert_with_values (store, &_tmp21_, _tmp19_, 0, _tmp20_, 1, deja_dup_config_delete_FOREVER, -1);
	iter = _tmp21_;
	gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable*) store, 1, GTK_SORT_ASCENDING);
	deja_dup_config_choice_init ((DejaDupConfigChoice*) self, (GtkTreeModel*) store, 1);
	_g_object_unref0 (store);
	return obj;
}


static void deja_dup_config_delete_class_init (DejaDupConfigDeleteClass * klass) {
	deja_dup_config_delete_parent_class = g_type_class_peek_parent (klass);
	DEJA_DUP_CONFIG_CHOICE_CLASS (klass)->handle_changed = deja_dup_config_delete_real_handle_changed;
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config = deja_dup_config_delete_real_set_from_config;
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config_finish = deja_dup_config_delete_real_set_from_config_finish;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_config_delete_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_config_delete_finalize;
	deja_dup_config_delete_FOREVER = G_MAXINT;
}


static void deja_dup_config_delete_instance_init (DejaDupConfigDelete * self) {
}


static void deja_dup_config_delete_finalize (GObject* obj) {
	DejaDupConfigDelete * self;
	self = DEJA_DUP_CONFIG_DELETE (obj);
	G_OBJECT_CLASS (deja_dup_config_delete_parent_class)->finalize (obj);
}


GType deja_dup_config_delete_get_type (void) {
	static volatile gsize deja_dup_config_delete_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_config_delete_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigDeleteClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_delete_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigDelete), 0, (GInstanceInitFunc) deja_dup_config_delete_instance_init, NULL };
		GType deja_dup_config_delete_type_id;
		deja_dup_config_delete_type_id = g_type_register_static (DEJA_DUP_TYPE_CONFIG_CHOICE, "DejaDupConfigDelete", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_config_delete_type_id__volatile, deja_dup_config_delete_type_id);
	}
	return deja_dup_config_delete_type_id__volatile;
}



