/* ConfigLabelLocation.c generated by valac, the Vala compiler
 * generated from ConfigLabelLocation.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 <common.h>
#include <gio/gio.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_LOCATION (deja_dup_config_label_location_get_type ())
#define DEJA_DUP_CONFIG_LABEL_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION, DejaDupConfigLabelLocation))
#define DEJA_DUP_CONFIG_LABEL_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION, DejaDupConfigLabelLocationClass))
#define DEJA_DUP_IS_CONFIG_LABEL_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION))
#define DEJA_DUP_IS_CONFIG_LABEL_LOCATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION))
#define DEJA_DUP_CONFIG_LABEL_LOCATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION, DejaDupConfigLabelLocationClass))

typedef struct _DejaDupConfigLabelLocation DejaDupConfigLabelLocation;
typedef struct _DejaDupConfigLabelLocationClass DejaDupConfigLabelLocationClass;
typedef struct _DejaDupConfigLabelLocationPrivate DejaDupConfigLabelLocationPrivate;
#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_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (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 _DejaDupConfigLabelLocation {
	DejaDupConfigLabel parent_instance;
	DejaDupConfigLabelLocationPrivate * priv;
};

struct _DejaDupConfigLabelLocationClass {
	DejaDupConfigLabelClass parent_class;
};

struct _DejaDupConfigLabelLocationPrivate {
	gboolean _is_s3;
	GtkImage* img;
};


static gpointer deja_dup_config_label_location_parent_class = NULL;

GType deja_dup_config_widget_get_type (void);
GType deja_dup_config_label_get_type (void);
GType deja_dup_config_label_location_get_type (void);
#define DEJA_DUP_CONFIG_LABEL_LOCATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION, DejaDupConfigLabelLocationPrivate))
enum  {
	DEJA_DUP_CONFIG_LABEL_LOCATION_DUMMY_PROPERTY,
	DEJA_DUP_CONFIG_LABEL_LOCATION_IS_S3
};
DejaDupConfigLabel* deja_dup_config_label_new (const char* key);
DejaDupConfigLabel* deja_dup_config_label_construct (GType object_type, const char* key);
DejaDupConfigLabelLocation* deja_dup_config_label_location_new (void);
DejaDupConfigLabelLocation* deja_dup_config_label_location_construct (GType object_type);
static void deja_dup_config_label_location_set_is_s3 (DejaDupConfigLabelLocation* self, gboolean value);
static void deja_dup_config_label_location_real_set_from_config (DejaDupConfigWidget* base);
gboolean deja_dup_config_label_location_get_is_s3 (DejaDupConfigLabelLocation* self);
void deja_dup_config_widget_watch_key (DejaDupConfigWidget* self, const char* key);
void deja_dup_config_widget_set_from_config (DejaDupConfigWidget* self);
static GObject * deja_dup_config_label_location_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void deja_dup_config_label_location_finalize (GObject* obj);
static void deja_dup_config_label_location_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void deja_dup_config_label_location_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static int _vala_strcmp0 (const char * str1, const char * str2);



DejaDupConfigLabelLocation* deja_dup_config_label_location_construct (GType object_type) {
	DejaDupConfigLabelLocation * self;
	self = (DejaDupConfigLabelLocation*) deja_dup_config_label_construct (object_type, NULL);
	return self;
}


DejaDupConfigLabelLocation* deja_dup_config_label_location_new (void) {
	return deja_dup_config_label_location_construct (DEJA_DUP_TYPE_CONFIG_LABEL_LOCATION);
}


static void deja_dup_config_label_location_real_set_from_config (DejaDupConfigWidget* base) {
	DejaDupConfigLabelLocation * self;
	GError * _inner_error_;
	char* _tmp0_;
	self = (DejaDupConfigLabelLocation*) base;
	_inner_error_ = NULL;
	gtk_label_set_label (((DejaDupConfigLabel*) self)->label, _tmp0_ = deja_dup_get_location_desc ());
	_g_free0 (_tmp0_);
	if (self->priv->img != NULL) {
		GIcon* icon;
		icon = NULL;
		{
			DejaDupBackend* _tmp1_;
			GIcon* _tmp3_;
			DejaDupBackend* _tmp2_;
			_tmp1_ = deja_dup_backend_get_default (&_inner_error_);
			if (_inner_error_ != NULL) {
				goto __catch12_g_error;
			}
			icon = (_tmp3_ = deja_dup_backend_get_icon (_tmp2_ = _tmp1_), _g_object_unref0 (icon), _tmp3_);
			_g_object_unref0 (_tmp2_);
		}
		goto __finally12;
		__catch12_g_error:
		{
			GError * e;
			e = _inner_error_;
			_inner_error_ = NULL;
			{
				_g_error_free0 (e);
			}
		}
		__finally12:
		if (_inner_error_ != NULL) {
			_g_object_unref0 (icon);
			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;
		}
		if (icon == NULL) {
			gtk_image_set_from_icon_name (self->priv->img, "folder", GTK_ICON_SIZE_MENU);
		} else {
			gtk_image_set_from_gicon (self->priv->img, icon, GTK_ICON_SIZE_MENU);
		}
		_g_object_unref0 (icon);
	}
	deja_dup_config_label_location_set_is_s3 (self, FALSE);
	{
		char* _tmp4_;
		char* _tmp5_;
		_tmp4_ = gconf_client_get_string (((DejaDupConfigWidget*) self)->client, DEJA_DUP_BACKEND_KEY, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch13_g_error;
		}
		deja_dup_config_label_location_set_is_s3 (self, _vala_strcmp0 (_tmp5_ = _tmp4_, "s3") == 0);
		_g_free0 (_tmp5_);
	}
	goto __finally13;
	__catch13_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			g_warning ("ConfigLabelLocation.vala:64: %s\n", e->message);
			_g_error_free0 (e);
		}
	}
	__finally13:
	if (_inner_error_ != NULL) {
		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;
	}
}


gboolean deja_dup_config_label_location_get_is_s3 (DejaDupConfigLabelLocation* self) {
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_is_s3;
	return result;
}


static void deja_dup_config_label_location_set_is_s3 (DejaDupConfigLabelLocation* self, gboolean value) {
	g_return_if_fail (self != NULL);
	self->priv->_is_s3 = value;
	g_object_notify ((GObject *) self, "is-s3");
}


static GObject * deja_dup_config_label_location_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	DejaDupConfigLabelLocation * self;
	parent_class = G_OBJECT_CLASS (deja_dup_config_label_location_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = DEJA_DUP_CONFIG_LABEL_LOCATION (obj);
	{
		GtkImage* _tmp0_;
		self->priv->img = (_tmp0_ = g_object_ref_sink ((GtkImage*) gtk_image_new_from_icon_name ("folder", GTK_ICON_SIZE_MENU)), _g_object_unref0 (self->priv->img), _tmp0_);
		gtk_box_pack_start ((GtkBox*) ((DejaDupConfigLabel*) self)->hbox, (GtkWidget*) self->priv->img, FALSE, FALSE, (guint) 0);
		gtk_box_reorder_child ((GtkBox*) ((DejaDupConfigLabel*) self)->hbox, (GtkWidget*) self->priv->img, 0);
		deja_dup_config_widget_watch_key ((DejaDupConfigWidget*) self, DEJA_DUP_BACKEND_KEY);
		deja_dup_config_widget_watch_key ((DejaDupConfigWidget*) self, DEJA_DUP_FILE_ROOT_KEY);
		deja_dup_config_widget_watch_key ((DejaDupConfigWidget*) self, DEJA_DUP_S3_ROOT_KEY);
		deja_dup_config_widget_set_from_config ((DejaDupConfigWidget*) self);
	}
	return obj;
}


static void deja_dup_config_label_location_class_init (DejaDupConfigLabelLocationClass * klass) {
	deja_dup_config_label_location_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DejaDupConfigLabelLocationPrivate));
	DEJA_DUP_CONFIG_WIDGET_CLASS (klass)->set_from_config = deja_dup_config_label_location_real_set_from_config;
	G_OBJECT_CLASS (klass)->get_property = deja_dup_config_label_location_get_property;
	G_OBJECT_CLASS (klass)->set_property = deja_dup_config_label_location_set_property;
	G_OBJECT_CLASS (klass)->constructor = deja_dup_config_label_location_constructor;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_config_label_location_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_CONFIG_LABEL_LOCATION_IS_S3, g_param_spec_boolean ("is-s3", "is-s3", "is-s3", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static void deja_dup_config_label_location_instance_init (DejaDupConfigLabelLocation * self) {
	self->priv = DEJA_DUP_CONFIG_LABEL_LOCATION_GET_PRIVATE (self);
}


static void deja_dup_config_label_location_finalize (GObject* obj) {
	DejaDupConfigLabelLocation * self;
	self = DEJA_DUP_CONFIG_LABEL_LOCATION (obj);
	_g_object_unref0 (self->priv->img);
	G_OBJECT_CLASS (deja_dup_config_label_location_parent_class)->finalize (obj);
}


GType deja_dup_config_label_location_get_type (void) {
	static volatile gsize deja_dup_config_label_location_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_config_label_location_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupConfigLabelLocationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_config_label_location_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupConfigLabelLocation), 0, (GInstanceInitFunc) deja_dup_config_label_location_instance_init, NULL };
		GType deja_dup_config_label_location_type_id;
		deja_dup_config_label_location_type_id = g_type_register_static (DEJA_DUP_TYPE_CONFIG_LABEL, "DejaDupConfigLabelLocation", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_config_label_location_type_id__volatile, deja_dup_config_label_location_type_id);
	}
	return deja_dup_config_label_location_type_id__volatile;
}


static void deja_dup_config_label_location_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DejaDupConfigLabelLocation * self;
	self = DEJA_DUP_CONFIG_LABEL_LOCATION (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_LABEL_LOCATION_IS_S3:
		g_value_set_boolean (value, deja_dup_config_label_location_get_is_s3 (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void deja_dup_config_label_location_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DejaDupConfigLabelLocation * self;
	self = DEJA_DUP_CONFIG_LABEL_LOCATION (object);
	switch (property_id) {
		case DEJA_DUP_CONFIG_LABEL_LOCATION_IS_S3:
		deja_dup_config_label_location_set_is_s3 (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static int _vala_strcmp0 (const char * str1, const char * str2) {
	if (str1 == NULL) {
		return -(str1 != str2);
	}
	if (str2 == NULL) {
		return str1 != str2;
	}
	return strcmp (str1, str2);
}




