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


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


#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;
typedef struct _SettingsCachePrivate SettingsCachePrivate;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _SettingsCache {
	GObject parent_instance;
	SettingsCachePrivate * priv;
};

struct _SettingsCacheClass {
	GObjectClass parent_class;
};

struct _SettingsCachePrivate {
	GHashTable* cached;
};


static gpointer settings_cache_parent_class = NULL;

GType settings_cache_get_type (void) G_GNUC_CONST;
#define SETTINGS_CACHE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_SETTINGS_CACHE, SettingsCachePrivate))
enum  {
	SETTINGS_CACHE_DUMMY_PROPERTY
};
static GSettings* settings_cache_settings (SettingsCache* self, const gchar* key, const gchar* path);
GList* settings_cache_cachedsettings (SettingsCache* self);
GSettings* settings_cache_generalsettings (SettingsCache* self);
GSettings* settings_cache_graphsettings (SettingsCache* self, const gchar* graphid);
static gboolean _vala_string_array_contains (const gchar** stack, int stack_length, const gchar* needle);
GSettings* settings_cache_tracesettings (SettingsCache* self, const gchar* graphid, const gchar* traceid);
SettingsCache* settings_cache_new (void);
SettingsCache* settings_cache_construct (GType object_type);
static void settings_cache_finalize (GObject* obj);

const gchar* SETTINGS_CACHE_presetgraphids[6] = {"cpu", "mem", "net", "load", "swap", "disk"};

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


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 GSettings* settings_cache_settings (SettingsCache* self, const gchar* key, const gchar* path) {
	GSettings* result = NULL;
	GSettings* _result_ = NULL;
	GHashTable* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gconstpointer _tmp2_ = NULL;
	GSettings* _tmp3_ = NULL;
	GSettings* _tmp4_ = NULL;
	g_return_val_if_fail (IS_SETTINGS_CACHE (self), NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = self->priv->cached;
	_tmp1_ = key;
	_tmp2_ = g_hash_table_lookup (_tmp0_, _tmp1_);
	_tmp3_ = _g_object_ref0 ((GSettings*) _tmp2_);
	_result_ = _tmp3_;
	_tmp4_ = _result_;
	if (_tmp4_ == NULL) {
		GSettings* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		GSettings* _tmp12_ = NULL;
		GSettings* _tmp13_ = NULL;
		gchar* _tmp14_ = NULL;
		const gchar* _tmp15_ = NULL;
		GHashTable* _tmp23_ = NULL;
		const gchar* _tmp24_ = NULL;
		gchar* _tmp25_ = NULL;
		GSettings* _tmp26_ = NULL;
		GSettings* _tmp27_ = NULL;
		_tmp6_ = path;
		if (_tmp6_ == NULL) {
			const gchar* _tmp7_ = NULL;
			GSettings* _tmp8_ = NULL;
			_tmp7_ = key;
			_tmp8_ = g_settings_new (_tmp7_);
			_g_object_unref0 (_tmp5_);
			_tmp5_ = _tmp8_;
		} else {
			const gchar* _tmp9_ = NULL;
			const gchar* _tmp10_ = NULL;
			GSettings* _tmp11_ = NULL;
			_tmp9_ = key;
			_tmp10_ = path;
			_tmp11_ = g_settings_new_with_path (_tmp9_, _tmp10_);
			_g_object_unref0 (_tmp5_);
			_tmp5_ = _tmp11_;
		}
		_tmp12_ = _tmp5_;
		_tmp13_ = _g_object_ref0 (_tmp12_);
		_g_object_unref0 (_result_);
		_result_ = _tmp13_;
		_tmp15_ = path;
		if (_tmp15_ == NULL) {
			const gchar* _tmp16_ = NULL;
			gchar* _tmp17_ = NULL;
			_tmp16_ = key;
			_tmp17_ = g_strdup (_tmp16_);
			_g_free0 (_tmp14_);
			_tmp14_ = _tmp17_;
		} else {
			const gchar* _tmp18_ = NULL;
			const gchar* _tmp19_ = NULL;
			const gchar* _tmp20_ = NULL;
			const gchar* _tmp21_ = NULL;
			gchar* _tmp22_ = NULL;
			_tmp18_ = key;
			_tmp19_ = string_to_string (_tmp18_);
			_tmp20_ = path;
			_tmp21_ = string_to_string (_tmp20_);
			_tmp22_ = g_strconcat (_tmp19_, ":", _tmp21_, NULL);
			_g_free0 (_tmp14_);
			_tmp14_ = _tmp22_;
		}
		_tmp23_ = self->priv->cached;
		_tmp24_ = _tmp14_;
		_tmp25_ = g_strdup (_tmp24_);
		_tmp26_ = _result_;
		_tmp27_ = _g_object_ref0 (_tmp26_);
		g_hash_table_insert (_tmp23_, _tmp25_, _tmp27_);
		_g_free0 (_tmp14_);
		_g_object_unref0 (_tmp5_);
	}
	result = _result_;
	return result;
}


GList* settings_cache_cachedsettings (SettingsCache* self) {
	GList* result = NULL;
	GHashTable* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	g_return_val_if_fail (IS_SETTINGS_CACHE (self), NULL);
	_tmp0_ = self->priv->cached;
	_tmp1_ = g_hash_table_get_values (_tmp0_);
	result = _tmp1_;
	return result;
}


GSettings* settings_cache_generalsettings (SettingsCache* self) {
	GSettings* result = NULL;
	GSettings* _tmp0_ = NULL;
	g_return_val_if_fail (IS_SETTINGS_CACHE (self), NULL);
	_tmp0_ = settings_cache_settings (self, "de.mh21.indicator-multiload.general", NULL);
	result = _tmp0_;
	return result;
}


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


GSettings* settings_cache_graphsettings (SettingsCache* self, const gchar* graphid) {
	GSettings* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	GSettings* _tmp11_ = NULL;
	GSettings* _tmp12_ = NULL;
	g_return_val_if_fail (IS_SETTINGS_CACHE (self), NULL);
	g_return_val_if_fail (graphid != NULL, NULL);
	_tmp0_ = graphid;
	if (_vala_string_array_contains (SETTINGS_CACHE_presetgraphids, G_N_ELEMENTS (SETTINGS_CACHE_presetgraphids), _tmp0_)) {
		const gchar* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		GSettings* _tmp5_ = NULL;
		GSettings* _tmp6_ = NULL;
		_tmp1_ = graphid;
		_tmp2_ = string_to_string (_tmp1_);
		_tmp3_ = g_strconcat ("de.mh21.indicator-multiload.graphs.", _tmp2_, NULL);
		_tmp4_ = _tmp3_;
		_tmp5_ = settings_cache_settings (self, _tmp4_, NULL);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		result = _tmp6_;
		return result;
	}
	_tmp7_ = graphid;
	_tmp8_ = string_to_string (_tmp7_);
	_tmp9_ = g_strconcat ("/apps/indicators/multiload/graphs/", _tmp8_, "/", NULL);
	_tmp10_ = _tmp9_;
	_tmp11_ = settings_cache_settings (self, "de.mh21.indicator-multiload.graph", _tmp10_);
	_tmp12_ = _tmp11_;
	_g_free0 (_tmp10_);
	result = _tmp12_;
	return result;
}


GSettings* settings_cache_tracesettings (SettingsCache* self, const gchar* graphid, const gchar* traceid) {
	GSettings* result = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	const gchar* _tmp9_ = NULL;
	const gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_ = NULL;
	GSettings* _tmp13_ = NULL;
	GSettings* _tmp14_ = NULL;
	g_return_val_if_fail (IS_SETTINGS_CACHE (self), NULL);
	g_return_val_if_fail (graphid != NULL, NULL);
	g_return_val_if_fail (traceid != NULL, NULL);
	_tmp0_ = graphid;
	if (_vala_string_array_contains (SETTINGS_CACHE_presetgraphids, G_N_ELEMENTS (SETTINGS_CACHE_presetgraphids), _tmp0_)) {
		const gchar* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		GSettings* _tmp5_ = NULL;
		GSettings* _tmp6_ = NULL;
		_tmp1_ = traceid;
		_tmp2_ = string_to_string (_tmp1_);
		_tmp3_ = g_strconcat ("de.mh21.indicator-multiload.traces.", _tmp2_, NULL);
		_tmp4_ = _tmp3_;
		_tmp5_ = settings_cache_settings (self, _tmp4_, NULL);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		result = _tmp6_;
		return result;
	}
	_tmp7_ = graphid;
	_tmp8_ = string_to_string (_tmp7_);
	_tmp9_ = traceid;
	_tmp10_ = string_to_string (_tmp9_);
	_tmp11_ = g_strconcat ("/apps/indicators/multiload/graphs/", _tmp8_, "/", _tmp10_, "/", NULL);
	_tmp12_ = _tmp11_;
	_tmp13_ = settings_cache_settings (self, "de.mh21.indicator-multiload.trace", _tmp12_);
	_tmp14_ = _tmp13_;
	_g_free0 (_tmp12_);
	result = _tmp14_;
	return result;
}


SettingsCache* settings_cache_construct (GType object_type) {
	SettingsCache * self = NULL;
	self = (SettingsCache*) g_object_new (object_type, NULL);
	return self;
}


SettingsCache* settings_cache_new (void) {
	return settings_cache_construct (TYPE_SETTINGS_CACHE);
}


static void settings_cache_class_init (SettingsCacheClass * klass) {
	settings_cache_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (SettingsCachePrivate));
	G_OBJECT_CLASS (klass)->finalize = settings_cache_finalize;
}


static void settings_cache_instance_init (SettingsCache * self) {
	GHashFunc _tmp0_ = NULL;
	GEqualFunc _tmp1_ = NULL;
	GDestroyNotify _tmp2_ = NULL;
	GDestroyNotify _tmp3_ = NULL;
	GHashTable* _tmp4_ = NULL;
	self->priv = SETTINGS_CACHE_GET_PRIVATE (self);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_free;
	_tmp3_ = g_object_unref;
	_tmp4_ = g_hash_table_new_full (_tmp0_, _tmp1_, _tmp2_, _tmp3_);
	self->priv->cached = _tmp4_;
}


static void settings_cache_finalize (GObject* obj) {
	SettingsCache * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SETTINGS_CACHE, SettingsCache);
	_g_hash_table_unref0 (self->priv->cached);
	G_OBJECT_CLASS (settings_cache_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 settings_cache_get_type (void) {
	static volatile gsize settings_cache_type_id__volatile = 0;
	if (g_once_init_enter (&settings_cache_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SettingsCacheClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) settings_cache_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SettingsCache), 0, (GInstanceInitFunc) settings_cache_instance_init, NULL };
		GType settings_cache_type_id;
		settings_cache_type_id = g_type_register_static (G_TYPE_OBJECT, "SettingsCache", &g_define_type_info, 0);
		g_once_init_leave (&settings_cache_type_id__volatile, settings_cache_type_id);
	}
	return settings_cache_type_id__volatile;
}



