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


#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>


#define TYPE_PREFERENCES (preferences_get_type ())
#define PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PREFERENCES, Preferences))
#define PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PREFERENCES, PreferencesClass))
#define IS_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PREFERENCES))
#define IS_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PREFERENCES))
#define PREFERENCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PREFERENCES, PreferencesClass))

typedef struct _Preferences Preferences;
typedef struct _PreferencesClass PreferencesClass;
typedef struct _PreferencesPrivate PreferencesPrivate;

#define TYPE_SETTINGS_CACHE (settings_cache_get_type ())
#define SETTINGS_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SETTINGS_CACHE, SettingsCache))
#define SETTINGS_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SETTINGS_CACHE, SettingsCacheClass))
#define IS_SETTINGS_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SETTINGS_CACHE))
#define IS_SETTINGS_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SETTINGS_CACHE))
#define SETTINGS_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SETTINGS_CACHE, SettingsCacheClass))

typedef struct _SettingsCache SettingsCache;
typedef struct _SettingsCacheClass SettingsCacheClass;

#define TYPE_COLOR_MAPPER (color_mapper_get_type ())
#define COLOR_MAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COLOR_MAPPER, ColorMapper))
#define COLOR_MAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COLOR_MAPPER, ColorMapperClass))
#define IS_COLOR_MAPPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COLOR_MAPPER))
#define IS_COLOR_MAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COLOR_MAPPER))
#define COLOR_MAPPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_COLOR_MAPPER, ColorMapperClass))

typedef struct _ColorMapper ColorMapper;
typedef struct _ColorMapperClass ColorMapperClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block2Data Block2Data;
typedef struct _Block3Data Block3Data;

struct _Preferences {
	GObject parent_instance;
	PreferencesPrivate * priv;
};

struct _PreferencesClass {
	GObjectClass parent_class;
};

struct _PreferencesPrivate {
	SettingsCache* settingscache;
	GSettings* prefsettings;
	GtkDialog* preferences;
	GtkBuilder* builder;
	GtkComboBox* colorschemes;
	gboolean colorschemeignoresignals;
	ColorMapper* _colormapper;
};

typedef void (*PreferencesColorForeachFunc) (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, void* user_data);
struct _Block2Data {
	int _ref_count_;
	Preferences * self;
	gchar* colorscheme;
};

struct _Block3Data {
	int _ref_count_;
	Preferences * self;
	gchar* colorscheme;
	gboolean custom;
};


static gpointer preferences_parent_class = NULL;

GType preferences_get_type (void) G_GNUC_CONST;
GType settings_cache_get_type (void) G_GNUC_CONST;
GType color_mapper_get_type (void) G_GNUC_CONST;
#define PREFERENCES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_PREFERENCES, PreferencesPrivate))
enum  {
	PREFERENCES_DUMMY_PROPERTY,
	PREFERENCES_COLORMAPPER
};
Preferences* preferences_new (ColorMapper* colormapper);
Preferences* preferences_construct (GType object_type, ColorMapper* colormapper);
void preferences_show (Preferences* self);
GObject* utils_get_ui (const gchar* objectid, GObject* signalhandlers, gchar** additional, int additional_length1, GtkBuilder** builder);
gchar* color_mapper_schemelabel (const gchar* name);
static gboolean _vala_string_array_contains (const gchar** stack, int stack_length, const gchar* needle);
GSettings* settings_cache_graphsettings (SettingsCache* self, const gchar* graphid);
static void preferences_colorgsettings_foreach (Preferences* self, PreferencesColorForeachFunc callback, void* callback_target);
static void __lambda17_ (Preferences* self, GSettings* settings, const gchar* key, GObject* widget, const gchar* name);
gboolean utils_get_settings_rgba (GValue* value, GVariant* variant, void* user_data);
static gboolean _utils_get_settings_rgba_gsettings_bind_get_mapping (GValue* value, GVariant* variant, void* user_data);
GVariant* utils_set_settings_rgba (GValue* value, const GVariantType* expected_type, void* user_data);
static void __lambda18_ (void);
static void ___lambda18__gdestroy_notify (void* data);
static void ___lambda17__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self);
static void preferences_update_activecolorscheme (Preferences* self);
void preferences_on_preferencesdialog_destroy (GtkWidget* source, Preferences* self);
void preferences_on_preferencesdialog_response (GtkDialog* source, gint response, Preferences* self);
void preferences_on_colorbutton_clicked (GtkButton* button, Preferences* self);
ColorMapper* preferences_get_colormapper (Preferences* self);
void color_mapper_add_palette (ColorMapper* self, GtkColorChooser* chooser);
void preferences_on_colorschemes_changed (GtkComboBox* widget, Preferences* self);
void color_mapper_set_color_scheme (ColorMapper* self, const gchar* value);
void preferences_restore_colorscheme (Preferences* self);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
const gchar* color_mapper_get_color_scheme (ColorMapper* self);
static void __lambda20_ (Block2Data* _data2_, GSettings* settings, const gchar* key, GObject* widget, const gchar* name);
static void ___lambda20__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda19_ (Block3Data* _data3_, GSettings* settings, const gchar* key, GObject* widget, const gchar* name);
static void ___lambda19__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self);
GSettings* settings_cache_tracesettings (SettingsCache* self, const gchar* graphid, const gchar* traceid);
static void preferences_set_colormapper (Preferences* self, ColorMapper* value);
static GObject * preferences_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
SettingsCache* settings_cache_new (void);
SettingsCache* settings_cache_construct (GType object_type);
GSettings* settings_cache_generalsettings (SettingsCache* self);
static void _preferences___lambda21_ (Preferences* self, GSettings* settings, const gchar* key, GObject* widget, const gchar* name);
static void _preferences_update_activecolorscheme_g_settings_changed (GSettings* _sender, const gchar* key, gpointer self);
static void __preferences___lambda21__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self);
static void preferences_finalize (GObject* obj);
static void _vala_preferences_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_preferences_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
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);
static gint _vala_array_length (gpointer array);

extern const gchar* COLOR_MAPPER_colorschemes[4];
extern const gchar* SETTINGS_CACHE_presetgraphids[6];

Preferences* preferences_construct (GType object_type, ColorMapper* colormapper) {
	Preferences * self = NULL;
	ColorMapper* _tmp0_ = NULL;
	g_return_val_if_fail (IS_COLOR_MAPPER (colormapper), NULL);
	_tmp0_ = colormapper;
	self = (Preferences*) g_object_new (object_type, "colormapper", _tmp0_, NULL);
	return self;
}


Preferences* preferences_new (ColorMapper* colormapper) {
	return preferences_construct (TYPE_PREFERENCES, colormapper);
}


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


static gboolean _vala_string_array_contains (const gchar** stack, int stack_length, const gchar* needle) {
	int i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static gboolean _utils_get_settings_rgba_gsettings_bind_get_mapping (GValue* value, GVariant* variant, void* user_data) {
	gboolean result;
	result = utils_get_settings_rgba (value, variant, user_data);
	return result;
}


static void __lambda18_ (void) {
}


static void ___lambda18__gdestroy_notify (void* data) {
	__lambda18_ ();
}


static void __lambda17_ (Preferences* self, GSettings* settings, const gchar* key, GObject* widget, const gchar* name) {
	GSettings* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GObject* _tmp2_ = NULL;
	g_return_if_fail (G_IS_SETTINGS (settings));
	g_return_if_fail (key != NULL);
	g_return_if_fail ((widget == NULL) || G_IS_OBJECT (widget));
	g_return_if_fail (name != NULL);
	_tmp0_ = settings;
	_tmp1_ = key;
	_tmp2_ = widget;
	g_settings_bind_with_mapping (_tmp0_, _tmp1_, _tmp2_, "rgba", G_SETTINGS_BIND_DEFAULT, _utils_get_settings_rgba_gsettings_bind_get_mapping, (GSettingsBindSetMapping) utils_set_settings_rgba, NULL, ___lambda18__gdestroy_notify);
}


static void ___lambda17__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self) {
	__lambda17_ (self, settings, key, widget, name);
}


void preferences_show (Preferences* self) {
	GtkDialog* _tmp0_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar** _tmp5_ = NULL;
	gchar** _tmp6_ = NULL;
	gint _tmp6__length1 = 0;
	GtkBuilder* _tmp7_ = NULL;
	GObject* _tmp8_ = NULL;
	GtkDialog* _tmp9_ = NULL;
	GtkDialog* _tmp10_ = NULL;
	GtkBuilder* _tmp11_ = NULL;
	GObject* _tmp12_ = NULL;
	GtkListStore* schemestore = NULL;
	GtkBuilder* _tmp13_ = NULL;
	GObject* _tmp14_ = NULL;
	GtkListStore* _tmp15_ = NULL;
	GtkListStore* _tmp21_ = NULL;
	const gchar* _tmp22_ = NULL;
	GSettings* _tmp23_ = NULL;
	gchar** _tmp24_ = NULL;
	gchar** _tmp25_ = NULL;
	GSettings* _tmp38_ = NULL;
	GtkBuilder* _tmp39_ = NULL;
	GObject* _tmp40_ = NULL;
	GSettings* _tmp41_ = NULL;
	GtkBuilder* _tmp42_ = NULL;
	GObject* _tmp43_ = NULL;
	GSettings* _tmp44_ = NULL;
	GtkBuilder* _tmp45_ = NULL;
	GObject* _tmp46_ = NULL;
	GtkDialog* _tmp47_ = NULL;
	g_return_if_fail (IS_PREFERENCES (self));
	_tmp0_ = self->priv->preferences;
	if (_tmp0_ != NULL) {
		GtkDialog* _tmp1_ = NULL;
		_tmp1_ = self->priv->preferences;
		gtk_window_present (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GTK_TYPE_WINDOW, GtkWindow));
		return;
	}
	_tmp2_ = g_strdup ("widthadjustment");
	_tmp3_ = g_strdup ("speedadjustment");
	_tmp4_ = g_strdup ("schemestore");
	_tmp5_ = g_new0 (gchar*, 3 + 1);
	_tmp5_[0] = _tmp2_;
	_tmp5_[1] = _tmp3_;
	_tmp5_[2] = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp6__length1 = 3;
	_tmp8_ = utils_get_ui ("preferencesdialog", G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject), _tmp6_, 3, &_tmp7_);
	_g_object_unref0 (self->priv->builder);
	self->priv->builder = _tmp7_;
	_tmp9_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp8_, GTK_TYPE_DIALOG) ? ((GtkDialog*) _tmp8_) : NULL;
	if (_tmp9_ == NULL) {
		_g_object_unref0 (_tmp8_);
	}
	_g_object_unref0 (self->priv->preferences);
	self->priv->preferences = _tmp9_;
	_tmp6_ = (_vala_array_free (_tmp6_, _tmp6__length1, (GDestroyNotify) g_free), NULL);
	_tmp10_ = self->priv->preferences;
	g_return_if_fail (_tmp10_ != NULL);
	_tmp11_ = self->priv->builder;
	_tmp12_ = gtk_builder_get_object (_tmp11_, "colorschemes");
	self->priv->colorschemes = G_TYPE_CHECK_INSTANCE_TYPE (_tmp12_, GTK_TYPE_COMBO_BOX) ? ((GtkComboBox*) _tmp12_) : NULL;
	_tmp13_ = self->priv->builder;
	_tmp14_ = gtk_builder_get_object (_tmp13_, "schemestore");
	_tmp15_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp14_, GTK_TYPE_LIST_STORE) ? ((GtkListStore*) _tmp14_) : NULL);
	schemestore = _tmp15_;
	{
		const gchar** colorscheme_collection = NULL;
		gint colorscheme_collection_length1 = 0;
		gint _colorscheme_collection_size_ = 0;
		gint colorscheme_it = 0;
		colorscheme_collection = COLOR_MAPPER_colorschemes;
		colorscheme_collection_length1 = G_N_ELEMENTS (COLOR_MAPPER_colorschemes);
		for (colorscheme_it = 0; colorscheme_it < G_N_ELEMENTS (COLOR_MAPPER_colorschemes); colorscheme_it = colorscheme_it + 1) {
			const gchar* colorscheme = NULL;
			colorscheme = colorscheme_collection[colorscheme_it];
			{
				GtkListStore* _tmp16_ = NULL;
				const gchar* _tmp17_ = NULL;
				gchar* _tmp18_ = NULL;
				gchar* _tmp19_ = NULL;
				const gchar* _tmp20_ = NULL;
				_tmp16_ = schemestore;
				_tmp17_ = colorscheme;
				_tmp18_ = color_mapper_schemelabel (_tmp17_);
				_tmp19_ = _tmp18_;
				_tmp20_ = colorscheme;
				gtk_list_store_insert_with_values (_tmp16_, NULL, -1, 0, _tmp19_, 1, _tmp20_, -1);
				_g_free0 (_tmp19_);
			}
		}
	}
	_tmp21_ = schemestore;
	_tmp22_ = _ ("Custom");
	gtk_list_store_insert_with_values (_tmp21_, NULL, -1, 0, _tmp22_, 1, "custom", -1);
	_tmp23_ = self->priv->prefsettings;
	_tmp25_ = _tmp24_ = g_settings_get_strv (_tmp23_, "graphs");
	{
		gchar** graphid_collection = NULL;
		gint graphid_collection_length1 = 0;
		gint _graphid_collection_size_ = 0;
		gint graphid_it = 0;
		graphid_collection = _tmp25_;
		graphid_collection_length1 = _vala_array_length (_tmp24_);
		for (graphid_it = 0; graphid_it < _vala_array_length (_tmp24_); graphid_it = graphid_it + 1) {
			gchar* _tmp26_ = NULL;
			gchar* graphid = NULL;
			_tmp26_ = g_strdup (graphid_collection[graphid_it]);
			graphid = _tmp26_;
			{
				const gchar* _tmp27_ = NULL;
				GSettings* graphsettings = NULL;
				SettingsCache* _tmp28_ = NULL;
				const gchar* _tmp29_ = NULL;
				GSettings* _tmp30_ = NULL;
				GSettings* _tmp31_ = NULL;
				GtkBuilder* _tmp32_ = NULL;
				const gchar* _tmp33_ = NULL;
				const gchar* _tmp34_ = NULL;
				gchar* _tmp35_ = NULL;
				gchar* _tmp36_ = NULL;
				GObject* _tmp37_ = NULL;
				_tmp27_ = graphid;
				if (!_vala_string_array_contains (SETTINGS_CACHE_presetgraphids, G_N_ELEMENTS (SETTINGS_CACHE_presetgraphids), _tmp27_)) {
					_g_free0 (graphid);
					continue;
				}
				_tmp28_ = self->priv->settingscache;
				_tmp29_ = graphid;
				_tmp30_ = settings_cache_graphsettings (_tmp28_, _tmp29_);
				graphsettings = _tmp30_;
				_tmp31_ = graphsettings;
				_tmp32_ = self->priv->builder;
				_tmp33_ = graphid;
				_tmp34_ = string_to_string (_tmp33_);
				_tmp35_ = g_strconcat (_tmp34_, "-enabled", NULL);
				_tmp36_ = _tmp35_;
				_tmp37_ = gtk_builder_get_object (_tmp32_, _tmp36_);
				g_settings_bind (_tmp31_, "enabled", _tmp37_, "active", G_SETTINGS_BIND_DEFAULT);
				_g_free0 (_tmp36_);
				_g_object_unref0 (graphsettings);
				_g_free0 (graphid);
			}
		}
		graphid_collection = (_vala_array_free (graphid_collection, graphid_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	preferences_colorgsettings_foreach (self, ___lambda17__preferences_color_foreach_func, self);
	_tmp38_ = self->priv->prefsettings;
	_tmp39_ = self->priv->builder;
	_tmp40_ = gtk_builder_get_object (_tmp39_, "width");
	g_settings_bind (_tmp38_, "width", _tmp40_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp41_ = self->priv->prefsettings;
	_tmp42_ = self->priv->builder;
	_tmp43_ = gtk_builder_get_object (_tmp42_, "speed");
	g_settings_bind (_tmp41_, "speed", _tmp43_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp44_ = self->priv->prefsettings;
	_tmp45_ = self->priv->builder;
	_tmp46_ = gtk_builder_get_object (_tmp45_, "autostart");
	g_settings_bind (_tmp44_, "autostart", _tmp46_, "active", G_SETTINGS_BIND_DEFAULT);
	preferences_update_activecolorscheme (self);
	_tmp47_ = self->priv->preferences;
	gtk_widget_show_all (G_TYPE_CHECK_INSTANCE_CAST (_tmp47_, GTK_TYPE_WIDGET, GtkWidget));
	_g_object_unref0 (schemestore);
}


void preferences_on_preferencesdialog_destroy (GtkWidget* source, Preferences* self) {
	g_return_if_fail (IS_PREFERENCES (self));
	g_return_if_fail (GTK_IS_WIDGET (source));
	_g_object_unref0 (self->priv->preferences);
	self->priv->preferences = NULL;
	_g_object_unref0 (self->priv->builder);
	self->priv->builder = NULL;
}


void preferences_on_preferencesdialog_response (GtkDialog* source, gint response, Preferences* self) {
	gint _tmp0_ = 0;
	g_return_if_fail (IS_PREFERENCES (self));
	g_return_if_fail (GTK_IS_DIALOG (source));
	_tmp0_ = response;
	switch (_tmp0_) {
		case 0:
		{
			GtkDialog* _tmp1_ = NULL;
			_tmp1_ = source;
			gtk_widget_destroy (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, GTK_TYPE_WIDGET, GtkWidget));
			return;
		}
		case 1:
		{
			g_signal_emit_by_name (self, "advancedpreferences-show");
			return;
		}
		case 2:
		{
			g_signal_emit_by_name (self, "menupreferences-show");
			return;
		}
		case 3:
		{
			g_signal_emit_by_name (self, "indicatorpreferences-show");
			return;
		}
		default:
		break;
	}
}


void preferences_on_colorbutton_clicked (GtkButton* button, Preferences* self) {
	ColorMapper* _tmp0_ = NULL;
	GtkButton* _tmp1_ = NULL;
	g_return_if_fail (IS_PREFERENCES (self));
	g_return_if_fail (GTK_IS_BUTTON (button));
	_tmp0_ = self->priv->_colormapper;
	_tmp1_ = button;
	color_mapper_add_palette (_tmp0_, G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, GTK_TYPE_COLOR_CHOOSER) ? ((GtkColorChooser*) _tmp1_) : NULL);
}


void preferences_on_colorschemes_changed (GtkComboBox* widget, Preferences* self) {
	gboolean _tmp0_ = FALSE;
	gchar* colorscheme = NULL;
	GtkComboBox* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	ColorMapper* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	g_return_if_fail (IS_PREFERENCES (self));
	g_return_if_fail (GTK_IS_COMBO_BOX (widget));
	_tmp0_ = self->priv->colorschemeignoresignals;
	if (_tmp0_) {
		return;
	}
	_tmp1_ = self->priv->colorschemes;
	_tmp2_ = gtk_combo_box_get_active_id (_tmp1_);
	_tmp3_ = g_strdup (_tmp2_);
	colorscheme = _tmp3_;
	_tmp4_ = colorscheme;
	if (g_strcmp0 (_tmp4_, "custom") == 0) {
		_g_free0 (colorscheme);
		return;
	}
	_tmp5_ = self->priv->_colormapper;
	_tmp6_ = colorscheme;
	color_mapper_set_color_scheme (_tmp5_, _tmp6_);
	preferences_restore_colorscheme (self);
	_g_free0 (colorscheme);
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		Preferences * self;
		self = _data2_->self;
		_g_free0 (_data2_->colorscheme);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static void __lambda20_ (Block2Data* _data2_, GSettings* settings, const gchar* key, GObject* widget, const gchar* name) {
	Preferences * self;
	GSettings* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	self = _data2_->self;
	g_return_if_fail (G_IS_SETTINGS (settings));
	g_return_if_fail (key != NULL);
	g_return_if_fail ((widget == NULL) || G_IS_OBJECT (widget));
	g_return_if_fail (name != NULL);
	_tmp0_ = settings;
	_tmp1_ = key;
	_tmp2_ = _data2_->colorscheme;
	_tmp3_ = g_strconcat (_tmp2_, ":", NULL);
	_tmp4_ = _tmp3_;
	_tmp5_ = name;
	_tmp6_ = g_strconcat (_tmp4_, _tmp5_, NULL);
	_tmp7_ = _tmp6_;
	g_settings_set_string (_tmp0_, _tmp1_, _tmp7_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp4_);
}


static void ___lambda20__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self) {
	__lambda20_ (self, settings, key, widget, name);
}


void preferences_restore_colorscheme (Preferences* self) {
	Block2Data* _data2_;
	ColorMapper* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	GtkDialog* _tmp5_ = NULL;
	gboolean _tmp9_ = FALSE;
	g_return_if_fail (IS_PREFERENCES (self));
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = self->priv->_colormapper;
	_tmp1_ = color_mapper_get_color_scheme (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	_data2_->colorscheme = _tmp3_;
	self->priv->colorschemeignoresignals = TRUE;
	preferences_colorgsettings_foreach (self, ___lambda20__preferences_color_foreach_func, _data2_);
	_tmp5_ = self->priv->preferences;
	if (_tmp5_ != NULL) {
		GtkComboBox* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gboolean _tmp8_ = FALSE;
		_tmp6_ = self->priv->colorschemes;
		_tmp7_ = _data2_->colorscheme;
		_tmp8_ = gtk_combo_box_set_active_id (_tmp6_, _tmp7_);
		_tmp4_ = !_tmp8_;
	} else {
		_tmp4_ = FALSE;
	}
	_tmp9_ = _tmp4_;
	if (_tmp9_) {
		GtkComboBox* _tmp10_ = NULL;
		_tmp10_ = self->priv->colorschemes;
		gtk_combo_box_set_active_id (_tmp10_, "custom");
	}
	self->priv->colorschemeignoresignals = FALSE;
	block2_data_unref (_data2_);
	_data2_ = NULL;
}


static Block3Data* block3_data_ref (Block3Data* _data3_) {
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}


static void block3_data_unref (void * _userdata_) {
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		Preferences * self;
		self = _data3_->self;
		_g_free0 (_data3_->colorscheme);
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}


static void __lambda19_ (Block3Data* _data3_, GSettings* settings, const gchar* key, GObject* widget, const gchar* name) {
	Preferences * self;
	gboolean _tmp0_ = FALSE;
	GSettings* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	self = _data3_->self;
	g_return_if_fail (G_IS_SETTINGS (settings));
	g_return_if_fail (key != NULL);
	g_return_if_fail ((widget == NULL) || G_IS_OBJECT (widget));
	g_return_if_fail (name != NULL);
	_tmp0_ = _data3_->custom;
	_tmp1_ = settings;
	_tmp2_ = key;
	_tmp3_ = g_settings_get_string (_tmp1_, _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _data3_->colorscheme;
	_tmp6_ = g_strconcat (_tmp5_, ":", NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = name;
	_tmp9_ = g_strconcat (_tmp7_, _tmp8_, NULL);
	_tmp10_ = _tmp9_;
	_data3_->custom = _tmp0_ | (g_strcmp0 (_tmp4_, _tmp10_) != 0);
	_g_free0 (_tmp10_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp4_);
}


static void ___lambda19__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self) {
	__lambda19_ (self, settings, key, widget, name);
}


static void preferences_update_activecolorscheme (Preferences* self) {
	Block3Data* _data3_;
	gboolean _tmp0_ = FALSE;
	GtkDialog* _tmp1_ = NULL;
	gboolean _tmp3_ = FALSE;
	ColorMapper* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp13_ = FALSE;
	g_return_if_fail (IS_PREFERENCES (self));
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->self = g_object_ref (self);
	_tmp1_ = self->priv->preferences;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp2_ = FALSE;
		_tmp2_ = self->priv->colorschemeignoresignals;
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	if (_tmp3_) {
		block3_data_unref (_data3_);
		_data3_ = NULL;
		return;
	}
	_tmp4_ = self->priv->_colormapper;
	_tmp5_ = color_mapper_get_color_scheme (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strdup (_tmp6_);
	_data3_->colorscheme = _tmp7_;
	_data3_->custom = FALSE;
	preferences_colorgsettings_foreach (self, ___lambda19__preferences_color_foreach_func, _data3_);
	self->priv->colorschemeignoresignals = TRUE;
	_tmp9_ = _data3_->custom;
	if (_tmp9_) {
		_tmp8_ = TRUE;
	} else {
		GtkComboBox* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
		gboolean _tmp12_ = FALSE;
		_tmp10_ = self->priv->colorschemes;
		_tmp11_ = _data3_->colorscheme;
		_tmp12_ = gtk_combo_box_set_active_id (_tmp10_, _tmp11_);
		_tmp8_ = !_tmp12_;
	}
	_tmp13_ = _tmp8_;
	if (_tmp13_) {
		GtkComboBox* _tmp14_ = NULL;
		_tmp14_ = self->priv->colorschemes;
		gtk_combo_box_set_active_id (_tmp14_, "custom");
	}
	self->priv->colorschemeignoresignals = FALSE;
	block3_data_unref (_data3_);
	_data3_ = NULL;
}


static void preferences_colorgsettings_foreach (Preferences* self, PreferencesColorForeachFunc callback, void* callback_target) {
	GSettings* _tmp0_ = NULL;
	gchar** _tmp1_ = NULL;
	gchar** _tmp2_ = NULL;
	GObject* _tmp30_ = NULL;
	GtkBuilder* _tmp31_ = NULL;
	GObject* widget = NULL;
	GObject* _tmp34_ = NULL;
	GObject* _tmp35_ = NULL;
	PreferencesColorForeachFunc _tmp36_ = NULL;
	void* _tmp36__target = NULL;
	GSettings* _tmp37_ = NULL;
	g_return_if_fail (IS_PREFERENCES (self));
	_tmp0_ = self->priv->prefsettings;
	_tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "graphs");
	{
		gchar** graphid_collection = NULL;
		gint graphid_collection_length1 = 0;
		gint _graphid_collection_size_ = 0;
		gint graphid_it = 0;
		graphid_collection = _tmp2_;
		graphid_collection_length1 = _vala_array_length (_tmp1_);
		for (graphid_it = 0; graphid_it < _vala_array_length (_tmp1_); graphid_it = graphid_it + 1) {
			gchar* _tmp3_ = NULL;
			gchar* graphid = NULL;
			_tmp3_ = g_strdup (graphid_collection[graphid_it]);
			graphid = _tmp3_;
			{
				const gchar* _tmp4_ = NULL;
				GSettings* graphsettings = NULL;
				SettingsCache* _tmp5_ = NULL;
				const gchar* _tmp6_ = NULL;
				GSettings* _tmp7_ = NULL;
				GSettings* _tmp8_ = NULL;
				gchar** _tmp9_ = NULL;
				gchar** _tmp10_ = NULL;
				_tmp4_ = graphid;
				if (!_vala_string_array_contains (SETTINGS_CACHE_presetgraphids, G_N_ELEMENTS (SETTINGS_CACHE_presetgraphids), _tmp4_)) {
					_g_free0 (graphid);
					continue;
				}
				_tmp5_ = self->priv->settingscache;
				_tmp6_ = graphid;
				_tmp7_ = settings_cache_graphsettings (_tmp5_, _tmp6_);
				graphsettings = _tmp7_;
				_tmp8_ = graphsettings;
				_tmp10_ = _tmp9_ = g_settings_get_strv (_tmp8_, "traces");
				{
					gchar** traceid_collection = NULL;
					gint traceid_collection_length1 = 0;
					gint _traceid_collection_size_ = 0;
					gint traceid_it = 0;
					traceid_collection = _tmp10_;
					traceid_collection_length1 = _vala_array_length (_tmp9_);
					for (traceid_it = 0; traceid_it < _vala_array_length (_tmp9_); traceid_it = traceid_it + 1) {
						gchar* _tmp11_ = NULL;
						gchar* traceid = NULL;
						_tmp11_ = g_strdup (traceid_collection[traceid_it]);
						traceid = _tmp11_;
						{
							GSettings* tracesettings = NULL;
							SettingsCache* _tmp12_ = NULL;
							const gchar* _tmp13_ = NULL;
							const gchar* _tmp14_ = NULL;
							GSettings* _tmp15_ = NULL;
							GObject* _tmp16_ = NULL;
							GtkBuilder* _tmp17_ = NULL;
							GObject* widget = NULL;
							GObject* _tmp24_ = NULL;
							GObject* _tmp25_ = NULL;
							PreferencesColorForeachFunc _tmp26_ = NULL;
							void* _tmp26__target = NULL;
							GSettings* _tmp27_ = NULL;
							GObject* _tmp28_ = NULL;
							const gchar* _tmp29_ = NULL;
							_tmp12_ = self->priv->settingscache;
							_tmp13_ = graphid;
							_tmp14_ = traceid;
							_tmp15_ = settings_cache_tracesettings (_tmp12_, _tmp13_, _tmp14_);
							tracesettings = _tmp15_;
							_tmp17_ = self->priv->builder;
							if (_tmp17_ == NULL) {
								_tmp16_ = NULL;
							} else {
								GtkBuilder* _tmp18_ = NULL;
								const gchar* _tmp19_ = NULL;
								const gchar* _tmp20_ = NULL;
								gchar* _tmp21_ = NULL;
								gchar* _tmp22_ = NULL;
								GObject* _tmp23_ = NULL;
								_tmp18_ = self->priv->builder;
								_tmp19_ = traceid;
								_tmp20_ = string_to_string (_tmp19_);
								_tmp21_ = g_strconcat (_tmp20_, "-color", NULL);
								_tmp22_ = _tmp21_;
								_tmp23_ = gtk_builder_get_object (_tmp18_, _tmp22_);
								_tmp16_ = _tmp23_;
								_g_free0 (_tmp22_);
							}
							_tmp24_ = _tmp16_;
							_tmp25_ = _g_object_ref0 (_tmp24_);
							widget = _tmp25_;
							_tmp26_ = callback;
							_tmp26__target = callback_target;
							_tmp27_ = tracesettings;
							_tmp28_ = widget;
							_tmp29_ = traceid;
							_tmp26_ (_tmp27_, "color", _tmp28_, _tmp29_, _tmp26__target);
							_g_object_unref0 (widget);
							_g_object_unref0 (tracesettings);
							_g_free0 (traceid);
						}
					}
					traceid_collection = (_vala_array_free (traceid_collection, traceid_collection_length1, (GDestroyNotify) g_free), NULL);
				}
				_g_object_unref0 (graphsettings);
				_g_free0 (graphid);
			}
		}
		graphid_collection = (_vala_array_free (graphid_collection, graphid_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp31_ = self->priv->builder;
	if (_tmp31_ == NULL) {
		_tmp30_ = NULL;
	} else {
		GtkBuilder* _tmp32_ = NULL;
		GObject* _tmp33_ = NULL;
		_tmp32_ = self->priv->builder;
		_tmp33_ = gtk_builder_get_object (_tmp32_, "background-color");
		_tmp30_ = _tmp33_;
	}
	_tmp34_ = _tmp30_;
	_tmp35_ = _g_object_ref0 (_tmp34_);
	widget = _tmp35_;
	_tmp36_ = callback;
	_tmp36__target = callback_target;
	_tmp37_ = self->priv->prefsettings;
	_tmp36_ (_tmp37_, "background-color", widget, "background", _tmp36__target);
	_g_object_unref0 (widget);
}


ColorMapper* preferences_get_colormapper (Preferences* self) {
	ColorMapper* result;
	ColorMapper* _tmp0_ = NULL;
	g_return_val_if_fail (IS_PREFERENCES (self), NULL);
	_tmp0_ = self->priv->_colormapper;
	result = _tmp0_;
	return result;
}


static void preferences_set_colormapper (Preferences* self, ColorMapper* value) {
	ColorMapper* _tmp0_ = NULL;
	ColorMapper* _tmp1_ = NULL;
	g_return_if_fail (IS_PREFERENCES (self));
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_colormapper);
	self->priv->_colormapper = _tmp1_;
	g_object_notify ((GObject *) self, "colormapper");
}


static void _preferences_update_activecolorscheme_g_settings_changed (GSettings* _sender, const gchar* key, gpointer self) {
	preferences_update_activecolorscheme (self);
}


static void _preferences___lambda21_ (Preferences* self, GSettings* settings, const gchar* key, GObject* widget, const gchar* name) {
	GSettings* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	g_return_if_fail (G_IS_SETTINGS (settings));
	g_return_if_fail (key != NULL);
	g_return_if_fail ((widget == NULL) || G_IS_OBJECT (widget));
	g_return_if_fail (name != NULL);
	_tmp0_ = settings;
	_tmp1_ = key;
	_tmp2_ = g_strconcat ("changed::", _tmp1_, NULL);
	g_signal_connect_object (_tmp0_, _tmp2_, (GCallback) _preferences_update_activecolorscheme_g_settings_changed, self, 0);
	_g_free0 (_tmp2_);
}


static void __preferences___lambda21__preferences_color_foreach_func (GSettings* settings, const gchar* key, GObject* widget, const gchar* name, gpointer self) {
	_preferences___lambda21_ (self, settings, key, widget, name);
}


static GObject * preferences_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	Preferences * self;
	SettingsCache* _tmp0_ = NULL;
	SettingsCache* _tmp1_ = NULL;
	GSettings* _tmp2_ = NULL;
	parent_class = G_OBJECT_CLASS (preferences_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PREFERENCES, Preferences);
	_tmp0_ = settings_cache_new ();
	_g_object_unref0 (self->priv->settingscache);
	self->priv->settingscache = _tmp0_;
	_tmp1_ = self->priv->settingscache;
	_tmp2_ = settings_cache_generalsettings (_tmp1_);
	_g_object_unref0 (self->priv->prefsettings);
	self->priv->prefsettings = _tmp2_;
	preferences_colorgsettings_foreach (self, __preferences___lambda21__preferences_color_foreach_func, self);
	return obj;
}


static void preferences_class_init (PreferencesClass * klass) {
	preferences_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (PreferencesPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_preferences_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_preferences_set_property;
	G_OBJECT_CLASS (klass)->constructor = preferences_constructor;
	G_OBJECT_CLASS (klass)->finalize = preferences_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PREFERENCES_COLORMAPPER, g_param_spec_object ("colormapper", "colormapper", "colormapper", TYPE_COLOR_MAPPER, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_signal_new ("advancedpreferences_show", TYPE_PREFERENCES, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	g_signal_new ("menupreferences_show", TYPE_PREFERENCES, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	g_signal_new ("indicatorpreferences_show", TYPE_PREFERENCES, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void preferences_instance_init (Preferences * self) {
	self->priv = PREFERENCES_GET_PRIVATE (self);
}


static void preferences_finalize (GObject* obj) {
	Preferences * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PREFERENCES, Preferences);
	_g_object_unref0 (self->priv->settingscache);
	_g_object_unref0 (self->priv->prefsettings);
	_g_object_unref0 (self->priv->preferences);
	_g_object_unref0 (self->priv->builder);
	_g_object_unref0 (self->priv->_colormapper);
	G_OBJECT_CLASS (preferences_parent_class)->finalize (obj);
}


/******************************************************************************
 * Copyright (C) 2011-2013  Michael Hofmann <mh21@mh21.de>                    *
 *                                                                            *
 * This program 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.                                        *
 *                                                                            *
 * This program 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 this program; if not, write to the Free Software Foundation, Inc.,    *
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                *
 ******************************************************************************/
GType preferences_get_type (void) {
	static volatile gsize preferences_type_id__volatile = 0;
	if (g_once_init_enter (&preferences_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PreferencesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) preferences_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Preferences), 0, (GInstanceInitFunc) preferences_instance_init, NULL };
		GType preferences_type_id;
		preferences_type_id = g_type_register_static (G_TYPE_OBJECT, "Preferences", &g_define_type_info, 0);
		g_once_init_leave (&preferences_type_id__volatile, preferences_type_id);
	}
	return preferences_type_id__volatile;
}


static void _vala_preferences_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	Preferences * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PREFERENCES, Preferences);
	switch (property_id) {
		case PREFERENCES_COLORMAPPER:
		g_value_set_object (value, preferences_get_colormapper (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_preferences_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	Preferences * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PREFERENCES, Preferences);
	switch (property_id) {
		case PREFERENCES_COLORMAPPER:
		preferences_set_colormapper (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


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);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



