Пример #1
0
gdouble
go_conf_load_double (GOConfNode *node, gchar const *key,
		     gdouble minima, gdouble maxima, gdouble default_val)
{
        gdouble res = -1;
	GVariant *val = NULL;
	if (node) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			val = go_conf_get (node, key, G_VARIANT_TYPE_DOUBLE);
		else if (node->key)
			val = go_conf_get (node, node->key, G_VARIANT_TYPE_DOUBLE);
	}
	if (val == NULL) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		val = real_node? go_conf_get (real_node, real_node->key, G_VARIANT_TYPE_DOUBLE): NULL;
		go_conf_free_node (real_node);
	}
	if (val != NULL) {
		res = g_variant_get_double (val);
		g_variant_unref (val);
		if (res < minima || maxima < res) {
			g_warning ("Invalid value '%g' for %s.  If should be >= %g and <= %g",
				   res, key, minima, maxima);
			val = NULL;
		}
	} else {
		d (g_warning ("Using default value '%g'", default_val));
		return default_val;
	}
	return res;
}
Пример #2
0
GSList *
go_conf_load_str_list (GOConfNode *node, gchar const *key)
{
	char **strs = NULL, **ptr;
	GSList *list = NULL;

	if (node) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			strs = g_settings_get_strv (node->settings, key);
		else if (node->key)
			strs = g_settings_get_strv (node->settings, node->key);
	}
	if (strs == NULL) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		strs = real_node? g_settings_get_strv (node->settings, real_node->key): NULL;
		go_conf_free_node (real_node);
	}
	if (strs) {
		for (ptr = strs; *ptr; ptr++)
			list = g_slist_prepend (list, g_strdup (*ptr));
		g_strfreev (strs);
	}

	return list;
}
Пример #3
0
gboolean
go_conf_load_bool (GOConfNode *node, gchar const *key, gboolean default_val)
{
	gboolean res;
	GVariant *val = NULL;
	if (node) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			val = go_conf_get (node, key, G_VARIANT_TYPE_BOOLEAN);
		else if (node->key)
			val = go_conf_get (node, node->key, G_VARIANT_TYPE_BOOLEAN);
	}
	if (val == NULL) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		val = real_node? go_conf_get (real_node, real_node->key, G_VARIANT_TYPE_BOOLEAN): NULL;
		go_conf_free_node (real_node);
	}

	if (val != NULL) {
		res = g_variant_get_boolean (val);
		g_variant_unref (val);
	} else {
		d (g_warning ("Using default value '%s'", default_val ? "true" : "false"));
		return default_val;
	}
	return res;
}
Пример #4
0
gchar *
go_conf_get_string (GOConfNode *node, gchar const *key)
{
	GOConfNode *real_node = go_conf_get_node (node, key);
	gchar *res = (real_node)? g_settings_get_string (real_node->settings, real_node->key): NULL;
	go_conf_free_node (real_node);
	return res;
}
Пример #5
0
gdouble
go_conf_get_double (GOConfNode *node, gchar const *key)
{
	GOConfNode *real_node = go_conf_get_node (node, key);
	gdouble res = (real_node)? g_settings_get_double (real_node->settings, real_node->key): 0.;
	go_conf_free_node (real_node);
	return res;
}
Пример #6
0
gint
go_conf_get_int	(GOConfNode *node, gchar const *key)
{
	GOConfNode *real_node = go_conf_get_node (node, key);
	gint res = (real_node)? g_settings_get_int (real_node->settings, real_node->key): 0;
	go_conf_free_node (real_node);
	return res;
}
Пример #7
0
void
go_conf_set_string (GOConfNode *node, gchar const *key, gchar const *str)
{
	GOConfNode *real_node = go_conf_get_node (node, key);
	if (!real_node) {
		d (g_warning ("Unable to set key '%s'", key));
		return;
	}
	g_settings_set_string (real_node->settings, real_node->key, str);
	go_conf_free_node (real_node);
}
Пример #8
0
gchar *
go_conf_load_string (GOConfNode *node, gchar const *key)
{
	char *res = NULL;
	if (node) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			res = g_settings_get_string (node->settings, key);
		else if (node->key)
			res = g_settings_get_string (node->settings, node->key);
	}
	if (res == NULL) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		res = (real_node)? g_settings_get_string (real_node->settings, real_node->key): NULL;
		go_conf_free_node (real_node);
	}
	return res;
}
Пример #9
0
GOConfNode *
go_conf_get_node (GOConfNode *parent, gchar const *key)
{
	GOConfNode *node;
	char *formatted;

	g_return_val_if_fail (parent || key, NULL);

	formatted = go_conf_format_id (key);
	node = g_new0 (GOConfNode, 1);
	node->ref_count = 1;
	if (parent) {
		if (key && !parent->key) {
			node->path = g_strconcat (parent->path, "/", key, NULL);
			node->id = g_strconcat (parent->id, ".", formatted, NULL);
		} else {
			node->path = g_strdup (parent->path);
			node->id = g_strdup (parent->id);
			node->key = g_strdup (key? key: parent->key);
		}
	} else {
		if (key[0] == '/') {
			node->path = g_strdup (key);
			node->id = g_strconcat ("org.gnome", formatted, NULL);
		} else {
			node->path = g_strconcat ("/apps/", key, NULL);
			node->id = g_strconcat ("org.gnome.", formatted, NULL);
		}
	}
	node->settings = g_hash_table_lookup (installed_schemas, node->id)? g_settings_new (node->id): NULL;
	g_free (formatted);
	if (!node->settings) {
		char *last_dot = strrchr (node->id, '.');
		*last_dot = 0;
		node->settings = g_hash_table_lookup (installed_schemas, node->id)? g_settings_new (node->id): NULL;
		if (node->settings) {
			g_free (node->key);
			node->key = g_strdup (last_dot + 1);
		} else {
			go_conf_free_node (node);
			node = NULL;
		}
	}
	return node;
}
Пример #10
0
gboolean
go_conf_get_bool (GOConfNode *node, gchar const *key)
{
	gboolean res, failed = node == NULL;
	if (!failed) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			res = g_settings_get_boolean (node->settings, key);
		else if (node->key)
			res = g_settings_get_boolean (node->settings, node->key);
		else
			failed = TRUE;
	}
	if (failed) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		res = (real_node)? g_settings_get_boolean (real_node->settings, real_node->key): FALSE;
		go_conf_free_node (real_node);
	}
	return res;
}
Пример #11
0
void
go_conf_set_str_list (GOConfNode *node, gchar const *key, GSList *list)
{
	GOConfNode *real_node = go_conf_get_node (node, key);
	gssize n = g_slist_length (list);
	char const ** strs;
	GSList *ptr = list;
	unsigned i = 0;

	if (!real_node) {
		d (g_warning ("Unable to set key '%s'", key));
		return;
	}
	strs = g_new (char const*, n + 1);
	for (; ptr; ptr = ptr->next)
		strs[i++] = (char const *) ptr->data;
	strs[n] = NULL;
	g_settings_set_strv (real_node->settings, real_node->key, strs);
	g_free (strs);
	go_conf_free_node (real_node);
}
Пример #12
0
gchar *
go_conf_get_value_as_str (GOConfNode *node, gchar const *key)
{
	gchar *value_string;
	GVariant *value = NULL;

	if (node) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			value = g_settings_get_value (node->settings, key);
		else if (node->key)
			value = g_settings_get_value (node->settings, node->key);
	}
	if (value == NULL) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		value = real_node? g_settings_get_value (real_node->settings, real_node->key): NULL;
		go_conf_free_node (real_node);
	}
	switch (g_variant_classify (value)) {
	case 's':
		value_string = g_strdup (g_variant_get_string (value, NULL));
		break;
	case 'i':
		value_string = g_strdup_printf ("%i", g_variant_get_int32 (value));
		break;
	case 'd':
		value_string = g_strdup_printf ("%f", g_variant_get_double (value));
		break;
	case 'b':
		value_string = g_strdup (go_locale_boolean_name (g_variant_get_boolean (value)));
		break;
	default:
		value_string = g_strdup ("ERROR FIXME");
		break;
	}

	return value_string;
}