1
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
#include <gconf/gconf-client.h>
10
static GConfClient *gconf_client = NULL;
16
gconf_client = gconf_client_get_default ();
20
go_conf_shutdown (void)
23
g_object_unref (G_OBJECT (gconf_client));
29
go_conf_get_real_key (GOConfNode const *key, gchar const *subkey)
31
return key ? g_strconcat ((key)->path, "/", subkey, NULL) :
36
go_conf_get_node (GOConfNode *parent, gchar const *key)
40
node = g_new (GOConfNode, 1);
41
gconf_client = gconf_client;
44
node->path = g_strconcat ("/apps/", key, NULL);
45
gconf_client_add_dir (gconf_client, node->path,
46
GCONF_CLIENT_PRELOAD_RECURSIVE,
50
node->path = go_conf_get_real_key (parent, key);
56
go_conf_free_node (GOConfNode *node)
60
gconf_client_remove_dir (gconf_client, node->path, NULL);
67
go_conf_sync (GOConfNode *node)
69
gconf_client_suggest_sync (gconf_client, NULL);
73
go_conf_set_bool (GOConfNode *node, gchar const *key, gboolean val)
75
gchar *real_key = go_conf_get_real_key (node, key);
76
gconf_client_set_bool (gconf_client, real_key, val, NULL);
81
go_conf_set_int (GOConfNode *node, gchar const *key, gint val)
83
gchar *real_key = go_conf_get_real_key (node, key);
84
gconf_client_set_int (gconf_client, real_key, val, NULL);
89
go_conf_set_double (GOConfNode *node, gchar const *key, gnm_float val)
91
gchar *real_key = go_conf_get_real_key (node, key);
92
gconf_client_set_float (gconf_client, real_key, val, NULL);
97
go_conf_set_string (GOConfNode *node, gchar const *key, gchar const *str)
99
gchar *real_key = go_conf_get_real_key (node, key);
100
gconf_client_set_string (gconf_client, real_key, str, NULL);
105
go_conf_set_str_list (GOConfNode *node, gchar const *key, GSList *list)
107
gchar *real_key = go_conf_get_real_key (node, key);
108
gconf_client_set_list (gconf_client, real_key,
109
GCONF_VALUE_STRING, list, NULL);
114
go_conf_get (GOConfNode *node, gchar const *key, GConfValueType t)
120
real_key = go_conf_get_real_key (node, key);
121
val = gconf_client_get (gconf_client, real_key, &err);
124
d (g_warning ("Unable to load key '%s' : because %s",
125
real_key, err->message));
131
d (g_warning ("Unable to load key '%s'", real_key));
136
if (val->type != t) {
137
#if 1 /* gconf_value_type_to_string is internal */
138
g_warning ("Expected `%d' got `%d' for key %s",
139
t, val->type, real_key);
141
g_warning ("Expected `%s' got `%s' for key %s",
142
gconf_value_type_to_string (t),
143
gconf_value_type_to_string (val->type),
147
gconf_value_free (val);
156
go_conf_load_bool (GOConfNode *node, gchar const *key, gboolean default_val)
159
GConfValue *val = go_conf_get (node, key, GCONF_VALUE_BOOL);
162
res = gconf_value_get_bool (val);
163
gconf_value_free (val);
165
d (g_warning ("Using default value '%s'", default_val ? "true" : "false"));
172
go_conf_load_int (GOConfNode *node, gchar const *key, gint minima, gint maxima, gint default_val)
175
GConfValue *val = go_conf_get (node, key, GCONF_VALUE_INT);
178
res = gconf_value_get_int (val);
179
gconf_value_free (val);
180
if (res < minima || maxima < res) {
181
g_warning ("Invalid value '%d' for %s. If should be >= %d and <= %d",
182
res, key, minima, maxima);
187
d (g_warning ("Using default value '%d'", default_val));
194
go_conf_load_double (GOConfNode *node, gchar const *key,
195
gdouble minima, gdouble maxima, gdouble default_val)
198
GConfValue *val = go_conf_get (node, key, GCONF_VALUE_FLOAT);
201
res = gconf_value_get_float (val);
202
gconf_value_free (val);
203
if (res < minima || maxima < res) {
204
g_warning ("Invalid value '%g' for %s. If should be >= %g and <= %g",
205
res, key, minima, maxima);
210
d (g_warning ("Using default value '%g'", default_val));
217
go_conf_load_string (GOConfNode *node, gchar const *key)
221
gchar *real_key = go_conf_get_real_key (node, key);
222
val = gconf_client_get_string (gconf_client, real_key, NULL);
229
go_conf_load_str_list (GOConfNode *node, gchar const *key)
233
gchar *real_key = go_conf_get_real_key (node, key);
234
list = gconf_client_get_list (gconf_client, real_key,
235
GCONF_VALUE_STRING, NULL);
242
get_schema (GOConfNode *node, gchar const *key)
244
gchar *schema_key = g_strconcat (
245
"/schemas", node->path, "/", key, NULL);
246
GConfSchema *schema = gconf_client_get_schema (
247
gconf_client, schema_key, NULL);
253
go_conf_get_short_desc (GOConfNode *node, gchar const *key)
255
GConfSchema *schema = get_schema (node, key);
257
if (schema != NULL) {
258
gchar *desc = g_strdup (gconf_schema_get_short_desc (schema));
259
gconf_schema_free (schema);
266
go_conf_get_long_desc (GOConfNode *node, gchar const *key)
268
GConfSchema *schema = get_schema (node, key);
270
if (schema != NULL) {
271
gchar *desc = g_strdup (gconf_schema_get_long_desc (schema));
272
gconf_schema_free (schema);
279
go_conf_get_type (GOConfNode *node, gchar const *key)
281
GConfSchema *schema = get_schema (node, key);
284
switch (gconf_schema_get_type (schema)) {
285
case GCONF_VALUE_STRING: t = G_TYPE_STRING; break;
286
case GCONF_VALUE_FLOAT: t = G_TYPE_FLOAT; break;
287
case GCONF_VALUE_INT: t = G_TYPE_INT; break;
288
case GCONF_VALUE_BOOL: t = G_TYPE_BOOLEAN; break;
294
gconf_schema_free (schema);
299
go_conf_get_value_as_str (GOConfNode *node, gchar const *key)
303
switch (go_conf_get_type (node, key)) {
305
value_string = go_conf_get_string (node, key);
308
value_string = g_strdup_printf ("%i", go_conf_get_int (node, key));
311
value_string = g_strdup_printf ("%f", go_conf_get_double (node, key));
314
value_string = g_strdup (go_locale_boolean_name (go_conf_get_bool (node, key)));
317
value_string = g_strdup ("ERROR FIXME");
324
go_conf_get_bool (GOConfNode *node, gchar const *key)
329
real_key = go_conf_get_real_key (node, key);
330
val = gconf_client_get_bool (gconf_client, real_key, NULL);
337
go_conf_get_int (GOConfNode *node, gchar const *key)
342
real_key = go_conf_get_real_key (node, key);
343
val = gconf_client_get_int (gconf_client, real_key, NULL);
350
go_conf_get_double (GOConfNode *node, gchar const *key)
355
real_key = go_conf_get_real_key (node, key);
356
val = gconf_client_get_float (gconf_client, real_key, NULL);
363
go_conf_get_string (GOConfNode *node, gchar const *key)
365
gchar *real_key = go_conf_get_real_key (node, key);
366
gchar *res = gconf_client_get_string (gconf_client, real_key, NULL);
373
go_conf_get_str_list (GOConfNode *node, gchar const *key)
375
return go_conf_load_str_list (node, key);
379
go_conf_set_value_from_str (GOConfNode *node, gchar const *key, gchar const *val_str)
381
switch (go_conf_get_type (node, key)) {
383
go_conf_set_string (node, key, val_str);
386
GODateConventions const *conv = NULL; /* workbook_date_conv (state->wb); */
387
GnmValue *value = format_match_number (val_str, NULL, conv);
389
gnm_float the_float = value_get_as_float (value);
390
go_conf_set_double (node, key, the_float);
393
value_release (value);
397
GODateConventions const *conv = NULL; /* workbook_date_conv (state->wb); */
398
GnmValue *value = format_match_number (val_str, NULL, conv);
400
gint the_int = value_get_as_int (value);
401
go_conf_set_int (node, key, the_int);
404
value_release (value);
407
case G_TYPE_BOOLEAN: {
408
GODateConventions const *conv = NULL; /* workbook_date_conv (state->wb); */
409
GnmValue *value = format_match_number (val_str, NULL, conv);
410
gboolean err, the_bool;
413
the_bool = value_get_as_bool (value, &err);
414
go_conf_set_bool (node, key, the_bool);
417
value_release (value);
421
g_warning ("Unsupported gconf type in preference dialog");
428
go_conf_remove_monitor (guint monitor_id)
430
gconf_client_notify_remove (gconf_client,
431
GPOINTER_TO_INT (monitor_id));
435
GOConfMonitorFunc monitor;
440
cb_key_changed (GConfClient *client, guint cnxn_id,
441
GConfEntry *entry, GOConfClosure *close)
443
close->monitor (NULL, gconf_entry_get_key (entry), close->data);
447
go_conf_add_monitor (GOConfNode *node, gchar const *key,
448
GOConfMonitorFunc monitor, gpointer data)
451
GOConfClosure *close = g_new0 (GOConfClosure, 1);
454
close->monitor = monitor;
456
real_key = go_conf_get_real_key (node, key);
457
ret = gconf_client_notify_add (gconf_client, real_key,
458
(GConfClientNotifyFunc) cb_key_changed, close, g_free, NULL);